A minimal (200+ lines of code) version of a code agent, suitable for learning its principles.
- Input user intent
- Use a simple system prompt to tell the LLM that you are a code agent and inform the LLM of the current working directory.
- Then enter the agent loop (iterative loop). The LLM, based on the user intent and system prompt, provides the first round of output. The output may be text, i.e., the result of the agent's execution. Alternatively, it may output a JSON file called by a tool, which is then passed to a function execution method. The execution result and the generated JSON are then concatenated into a message for the next loop.
List of tools the agent can operate on: line-by-line read, write, edit, glob (search by regular expression), grep, and the system bash. Each tool has a prompt and an invocation method.
This can be understood as a minimal version of Claude Code.