Micro Agent

An AI agent that writes code for you

README

AI Shell logo

An AI agent that writes and fixes code for you.

Demo

Micro Agent


Point Micro Agent at a file and a test (or screenshot), and it will write code for you until your tests pass or it more closely matches your design screenshot.

Why?


LLMs are great at giving you broken code, and it can take repeat iteration to get that code to work as expected.

So why do this manually when AI can handle not just the generation but also the iteration and fixing?

Why a "micro" agent?


AI agents are cool, but general-purpose coding agents rarely work as hoped or promised. They tend to go haywire with compounding errors. Think of your Roomba getting stuck under a table, x1000.

The idea of a micro agent is to

1. Create a definitive test case that can give clear feedback if the code works as intended or not, and
2. Iterate on code until all test cases pass

What this project is not


This project is not trying to be an end-to-end developer. AI agents are not capable enough to reliably try to be that yet (or probably very soon). This project won't install modules, read and write multiple files, or do anything else that is highly likely to cause havoc when it inevitably fails.

It's a micro agent. It's small, focused, and does one thing as well as possible: write a test, then produce code that passes that test.

Installation


Micro Agent requires Node.js v14 or later.


  1. ```bash
  2. npm install -g @builder.io/micro-agent
  3. ```

Getting Started


The best way to get started is to run Micro Agent in interactive mode, where it will ask you questions about the code it generates and use your feedback to improve the code it generates.

  1. ```bash
  2. micro-agent
  3. ```

Look at that, you're now a test-driven developer. You're welcome.

Running Manually


Add an OpenAI API key


Micro Agent uses the OpenAI API to generate code. You need to add your API key to the CLI:

  1. ```bash
  2. micro-agent config set OPENAI_KEY=<your token>
  3. ```

Unit test matching


Demo

To run the Micro Agent on a file in unit test matching mode, you need to provide a test script that will run after each code generation attempt. For instance:

  1. ```bash
  2. micro-agent ./file-to-edit.ts -t "npm test"
  3. ```

This will run the Micro Agent on the file ./file-to-edit.ts running npm test and will write code until the tests pass.

The above assumes the following file structure:

  1. ```bash
  2. some-folder
  3. file-to-edit.ts
  4. file-to-edit.test.ts # test file. if you need a different path, use the -f argument
  5. file-to-edit.prompt.md # optional prompt file. if you need a different path, use the -p argument
  6. ```

By default, Micro Agent assumes you have a test file with the same name as the editing file but with .test.ts appended, such as ./file-to-edit.test.ts for the above examples.

If this is not the case, you can specify the test file with the `-f` flag. You can also add a prompt to help guide the code generation, either at a file located at `.prompt.md` like `./file-to-edit.prompt.md` or by specifying the prompt file with the `-p`. For instance:

  1. ```bash
  2. micro-agent ./file-to-edit.ts -t "npm test" -f ./file-to-edit.spec.ts -p ./path-to-prompt.prompt.md
  3. ```