CH 01 · Anatomy of an AI Agent · 12/12
Read as one pageRead the source yourself
The slides above quoted about a hundred lines from four codebases. Here is a short reading tour, in order, that takes each part further than a slide can.
- smolagents,
src/smolagents/memory.py. The whole memory model of a working agent in about 200 lines:AgentMemoryand its step records (TaskStep,ActionStep,PlanningStep,SystemPromptStep). Look for which steps return no messages in summary mode. The comment that says why a plan is dropped is inagents.py, just above thesummary_mode=Truecall. - Hermes Agent,
agent/turn_iteration_prep.py. The budget check in front of each iteration of the main tool loop. A turn incodex_app_servermode, which hands the whole turn to a subprocess, returns before that loop. Look for_budget_grace_call, then find where it is set inagent/turn_truncation.pyand work out why a fallback model needs one call past the budget. - pi,
packages/ai/src/api/. Provider adapters plus a few shared helpers. Openopenai-responses.tsandbedrock-converse-stream.tsnext to the Anthropic file and findexport const streamin each. List what differs (request shape, event parsing, whetherretryProviderRequestis used at all) and what stays identical (theStreamFunctionsignature). - OpenClaw,
src/gateway/auth-rate-limit.ts. The limiter behind the auth slide. It tracks at most 10,000 entries by default, one per scope plus address. Look for what it evicts when that table is full, and why it never evicts an active lockout.
Exercise: clone smolagents, build a ToolCallingAgent with any model you can access, and give it a task that needs two tool calls. After the run, print agent.write_memory_to_messages() and label every message with the ActionStep field it came from. Then pick one of the four repos and write a six-row table, one row each for the model, the loop, the tools, the context, memory, and the surrounding system. In each row, name the file and the function that implements that part.
Finished this idea?
Your learning progress stays in this browser.