· 8 min read
Understanding the Architecture of an Open Source Coding Agent
By T. Vargas
- guides
An open source coding agent is usually an LLM wrapped in a control system that can inspect a repository, choose tools, make changes, run commands, and use the results to decide what to do next. If you understand the loop around the model—not just the model itself—you can debug agents, choose better tools, and build smaller versions that actually work.
This matters because the visible interaction is deceptively simple: you ask for a feature, then files change. Behind that interaction, the agent is continually assembling context, requesting actions, observing outcomes, updating its working state, and eventually deciding whether it has finished.
Start with the agent loop, not the model
The most useful mental model is a loop: observe, reason, act, observe again. The language model handles the reasoning step, but it does not directly edit files or execute shell commands. An agent runtime sits around it and translates structured model output into real operations.
Imagine you ask an agent to fix a failing test. First, it observes the task and some repository context. Then it reasons that it needs the test output, asks to run the test command, reads the failure, opens the relevant files, proposes an edit, applies it, reruns the test, and checks whether the result matches the request. Each tool result becomes new input for the next model call.
That loop is why an agent can recover from an incorrect first guess. A plain chat completion may confidently suggest a patch. An agent can try the patch, see a compiler error, and revise it. It can still fail, of course, but it has a feedback channel that ordinary code generation does not.
Map the five parts of a coding agent
When you read an agent codebase, look for these five components. They may be named differently, but nearly every practical coding agent has versions of them.
- The model provider: code that sends messages to an LLM and receives text or structured tool calls. This layer may support local models, hosted APIs, model routing, retries, token limits, and streaming.
- The orchestrator: the control loop that decides when to call the model, executes approved tool calls, adds results back into context, and stops when the task is complete or a budget is exhausted.
- The tool layer: well-defined functions for reading files, searching code, editing files, running commands, browsing documentation, talking to issue trackers, or invoking MCP servers.
- State and context management: the system that tracks conversation history, tool results, selected files, task plans, token budgets, checkpoints, and sometimes durable session data.
- Safety and user interaction: permission prompts, sandboxing, command allowlists or denylists, diff previews, approval policies, and the UI or CLI that keeps the human in control.
You can use this map immediately when comparing projects. If an agent feels unreliable, ask which component is weak. Is the model poor at tool use? Is the context manager stuffing in irrelevant files? Are tools ambiguous? Is the orchestrator letting the model loop forever? “The agent is bad” is rarely specific enough to fix anything.
Tool definitions are the agent’s real API
Tools are often exposed to the model as schemas: a name, a description, and typed arguments. A file-reading tool might accept a path and line range; a shell tool might accept a command and working directory. The model does not need to know how subprocesses work. It needs to know when a tool is appropriate and how to call it correctly.
This makes tool design a major engineering task. A vague tool such as run_anything invites dangerous or low-quality behavior. Smaller tools provide better boundaries: read_file, search_files, apply_patch, run_tests, and get_git_diff give the model clearer choices and give the runtime clearer places to enforce policy.
If you are building an agent, start with fewer tools than you think you need. Give each tool a narrow purpose, structured arguments, useful error messages, and predictable output. Then test whether the model selects the right tool on realistic tasks before adding another integration.
Context is a budget, not a scrapbook
A coding agent cannot send an entire large repository to the model on every turn. Even when a model has a huge context window, unnecessary context costs money, slows inference, and makes the model more likely to follow irrelevant clues.
Good agents retrieve context gradually. They begin with the user request, repository instructions, and perhaps a compact directory view. From there, they search for symbols, open specific files, inspect test failures, and retain only the material needed for the current decision. Some systems summarize old steps or compress tool output when the conversation gets long.
You can evaluate an agent’s context strategy by watching its transcript. Does it inspect the relevant code before editing? Does it reread the same giant file repeatedly? Does it notice project-specific instructions? Does it carry failed command output forward? Those behaviors reveal more than a benchmark score about how it will behave in a real repository.
Edits need a verification path
The edit mechanism is normally simpler than it appears. An agent may write a whole file, apply a unified diff, replace an exact string, or use a structured patch format. The hard part is not producing bytes; it is ensuring the change landed in the intended place and did not break something nearby.
That is why mature agent workflows pair editing with verification. After a change, the runtime should make it easy to inspect the diff, format code, run targeted tests, run type checks, and report failures back to the model. The model should not be trusted to declare success merely because it emitted a plausible patch.
For your own workflow, require at least one concrete check for every meaningful change. A narrow unit test is usually better than immediately launching a slow full-suite run. If the task changes an API boundary, add a type check or integration test as a second signal.
Permissions turn a demo into a usable developer tool
An agent with unrestricted shell access can delete files, expose secrets, modify configuration, install packages, or send data over the network. Even a capable model can misunderstand a request, so permission architecture is part of product quality, not an optional security feature.
Useful controls include asking before writes or commands, showing patches before they are applied, restricting operations to a workspace, requiring confirmation for destructive commands, and isolating execution in a container or sandbox. Different teams will choose different defaults, but the key is that the model should not silently expand its authority.
When you run an open source agent locally, inspect its permissions before judging its intelligence. Find out whether commands execute automatically, where it stores credentials, whether it can access the network, and how to reset or review a session. A conservative permission mode is usually the right place to start.
Build a tiny agent to make the architecture click
You do not need a full IDE extension or a fleet of subagents to learn this. Build a small command-line loop with one model, three tools—read file, write patch, run a test command—and a hard limit of perhaps ten tool iterations. Log every prompt, tool call, result, and changed file.
That prototype will teach you the important lessons quickly: models need precise tool descriptions, command output needs trimming, repository instructions matter, and stopping conditions are harder than they sound. Once the basic loop is observable and safe, add search, git diff inspection, persistent sessions, or a planner only when a real task demonstrates the need.
Open source coding agents become much less mysterious once you see them as ordinary software systems with an LLM inside the decision loop. Treat the model as one component with imperfect judgment, then make the surrounding architecture observable, constrained, and testable—the same way you would design any other system allowed to change production code.