Skip to slide
012 / 221

CH 01 · Anatomy of an AI Agent · 12/12

Read as one page

Read 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.

  1. smolagents, src/smolagents/memory.py. The whole memory model of a working agent in about 200 lines: AgentMemory and 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 in agents.py, just above the summary_mode=True call.
  2. Hermes Agent, agent/turn_iteration_prep.py. The budget check in front of each iteration of the main tool loop. A turn in codex_app_server mode, which hands the whole turn to a subprocess, returns before that loop. Look for _budget_grace_call, then find where it is set in agent/turn_truncation.py and work out why a fallback model needs one call past the budget.
  3. pi, packages/ai/src/api/. Provider adapters plus a few shared helpers. Open openai-responses.ts and bedrock-converse-stream.ts next to the Anthropic file and find export const stream in each. List what differs (request shape, event parsing, whether retryProviderRequest is used at all) and what stays identical (the StreamFunction signature).
  4. 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.