Sub topic 1
Starting Point: How a Single Coding Agent Works
Prerequisites
Assume you can use a terminal, read basic Python, and work with Git branches. You should also understand that an agent has a limited context window: the amount of conversation, code, and tool output it can consider at once.
The Single-Agent Loop
A coding agent repeats a simple loop:
- Read your request and the current context.
- Choose an action, such as reading a file or running a test.
- Call a tool.
- Inspect the tool's observation.
- Update its plan and continue.
This works well for a focused change. The agent can keep the problem, relevant files, and test results in one context.
def agent_loop(request, tools):
context = [request]
while True:
action = choose_action(context, tools)
if action == "done":
return summarize(context)
observation = tools.run(action)
context.append(observation)The loop becomes harder to manage as the task grows.
Why Long Tasks Strain One Context Window
A long task adds requirements, file contents, command output, failed attempts, and design decisions. Older details may be truncated or become difficult for the model to use accurately. Repeating the same investigation also increases cost and latency.
A single agent can lose track of which files it changed or accept a local fix that breaks another part of the system. Splitting independent work reduces the amount each agent must remember.
What a Subagent Is
A subagent is a separate agent instance started by a parent agent, often called the orchestrator. It receives a focused task and its own context. It does not automatically see the parent's conversation or assumptions.
Context Isolation
Context isolation keeps investigations separate. The parent sends a brief, and the subagent returns a summary, patch, or test result. The parent retains the decision-making context without carrying every intermediate tool output.
A useful brief states the goal, relevant context, allowed scope, constraints, completion check, and expected response.
Breaking Work into Units
Delegate units that have clear boundaries and few dependencies. For example, update documentation and add tests can run independently if both rely on an already-defined interface. A database migration and code that depends on its new schema should usually run sequentially.
Ask whether each unit has its own files, checks, and definition of done. If not, refine the unit before delegating it.
Exercise
Should documentation and test updates always run in parallel?
Show answer
No. Run them in parallel only when they do not depend on each other's changes or results.