By Abhijith N M · Reviewed 24 October 2026 · Editorial standards
An agent spent nine turns on a missing delivery. It searched the ticket archive, read four policy pages and fetched two carrier scans. On turn ten it asked the user for the order id it had been given on turn one. The id was still in the conversation. It had been pushed out of the context window.
A larger window bought three more turns and the same outcome, because every search result was pasted in full. The fix was to stop carrying raw tool output and give the noisy work to a subagent.
Working context is everything in the window on this turn: the system prompt, the conversation, the tool definitions and the latest results. It is the only memory the model reasons over, and it is the one that overflows.
Durable memory is what survives the session: files, a database row, or a memory file the agent reads at the start and appends to. A memory file is a convention, not a model feature. You write the code that loads it, and you own what it contains.
Trace memory is the record for humans: the messages, tool calls and stop reasons you log. The model never reads it. It is how you debug a run and prove what happened.
| Memory | Where it lives | What goes wrong |
|---|---|---|
| Working context | The current window | It fills up and the early facts fall out |
| Durable memory | Files or a database | Stale or wrong facts get loaded as truth |
| Trace memory | Logs and traces | Too little detail to explain a bad answer |
A subagent is a separate loop with its own context window and its own tool set. The parent gives it a task brief and receives one compact result. The child's searches, dead ends and raw pages never enter the parent window.
That is the trade: a second model call and some latency, in exchange for a clean parent context and a narrower permission boundary. Use a subagent for noisy exploration and for parallel research.
The supervisor stays thin. It plans, delegates, checks the returned facts and writes the answer. If it starts searching itself, the isolation is gone and you paid for two loops.
A good brief has five parts: the goal, the facts the child cannot look up, the constraints, the stop condition, and the shape of the answer you want back. Without a stop condition, a child can loop as happily as a parent.
The child returns a short, structured result with its sources: facts, not prose. If the parent needs the reasoning, ask for three bullets, not the full transcript.
One rule keeps this honest: the parent cites what the child returned. If it cannot point to the line, the fact is not in the system, and a child that invented a source is caught.
def brief(parent_notes, budget_chars=400):
"""Send facts and a goal, not the whole parent conversation."""
lines = [f"- {note}" for note in parent_notes]
text = "Goal: confirm the refund and cite the policy.\n" + "\n".join(lines)
return text[:budget_chars]
def merge(parent, summaries):
"""Add one compact message per child, never the child transcript."""
return parent + [{"role": "user", "content": text} for text in summaries]
NOTES = [
"order A17 status=delivered on 2026-11-02",
"customer C-88 tier=gold, two prior claims",
"refund limit 100 USD, no human approval needed",
]
PARENT = [{"role": "user", "content": "Where is order A17?"}]
CHILDREN = [
"carrier: last scan 2026-11-02, no exception code",
"policy: gold tier refund allowed up to 100 USD",
]
handoff = brief(NOTES)
print(handoff)
print("facts in the brief:", len(handoff.splitlines()) - 1)
print("transcript after merge:", len(merge(PARENT, CHILDREN)), "messages")Isolation moves tokens, it does not delete them. A child may burn 40,000 tokens on search while the parent pays for one 200-token summary, which is a good trade when the parent needs the conclusion.
Budget the boundary: give each child a token or turn cap and a maximum summary length, and decide what the parent keeps. Without caps, five children in parallel can cost more than one careful parent loop.
Abstraction frameworks package the loop, the tool schema and the handoff. They do not change the mechanics from step 12, and the exam expects you to see through the abstraction to the messages underneath.
| Framework | Shape | What it gives you |
|---|---|---|
| Strands Agents | Model-driven agent with tools and handoffs | A compact way to define tools and let the model direct the flow |
| LangGraph | Graph of nodes and edges over explicit state | Checkpointing, resumable runs and a visible graph |
| PydanticAI | Typed agent with validated outputs | Pydantic models for inputs, outputs and dependencies |
Pick a framework for the parts you would otherwise write badly: state handling, retries, typed outputs and tracing.
Trace one delegation in your own system, or in the snippet.
Key takeaways
Working context overflows; durable memory and traces exist so it does not have to hold everything.
A subagent is a separate loop with its own window and tools; it returns a summary, not a transcript.
Send a brief with a goal, facts, constraints and a stop condition, and require citations in the result.
Isolation moves tokens rather than removing them; cap each child and each summary.
Frameworks such as Strands, LangGraph and PydanticAI package the loop; they do not replace knowing it.
Written and edited by the nexGenCoders team. Spotted a mistake? Tell us and we will fix it.
Don't lose this lesson
Create a free account to save your progress, keep your streak, and work toward a shareable certificate.