Anatomy of an Agent
Treating agents as just a prompt misses tool routing, recovery, and observability — demos break in production.
Brain judges, senses perceive, hands act, notebook remembers, manager orchestrates policy.
Visual Workflows
Start here — scroll inside each diagram frame to explore, then use + / − to zoom up to 200% if needed.
Scroll inside the frame to explore · use + / − to zoom up to 200%
Data Flow Through Layers
Scroll inside the frame to explore · use + / − to zoom up to 200%
One iteration: senses feed brain, brain selects hands, hands update memory.
Key Takeaways
- 1.Brain = LLM plus system prompt and planning strategy.
- 2.Senses = inputs from user, files, webhooks.
- 3.Hands = tool registry with schemas and permissions.
- 4.Memory = working buffer plus vector long-term store.
- 5.Nervous system = runtime, retries, routing, HITL.
Real Example
Scenario
Cursor-style coding agent: Brain = Claude with repo rules; Senses = open files + terminal stderr; Hands = `write_file`, `run_tests`, `grep`; Memory = repo index + session buffer; Runtime = 12-step cap, retry on test failure, LangSmith trace.
What you would do
Brain reads failing test output (Senses) and chooses `write_file` then `run_tests` (Hands). Memory stores the last failing assertion so the retry does not repeat the same edit. Runtime stops at 12 steps or escalates to the user. Monitor: tools per successful fix and invalid file paths suggested by the brain.
Practice Task
Pick a non-coding agent (support, research, or ops). Fill a 5-row table — Brain / Senses / Hands / Memory / Runtime — with one concrete item per row for that agent.
Code Walkthrough
Highlighted lines show where Anatomy of an Agent happens in the code.
1from typing import TypedDict # import dependencies2
3class AgentState(TypedDict): # define a data structure or component4 messages: list # Brain input (Senses)5 tool_results: list # Observations from Hands6 repo_index: dict # Long-term Memory7 step: int # Runtime counter8 max_steps: int # Runtime limit9
10state: AgentState = {11 "messages": [{"role": "user", "content": "Fix the failing auth test"}],12 "tool_results": [],13 "repo_index": {"files": ["auth.py", "test_auth.py"]},14 "step": 0,15 "max_steps": 12,16}17
18while state["step"] < state["max_steps"]: # key line for Anatomy of an Agent19 # Brain: LLM picks tool from registry (Hands)20 action = "run_tests" # e.g. from tool_calls21 observation = {"passed": False, "stderr": "AssertionError: 401"}22 state["tool_results"].append(observation)23 state["step"] += 1Cheat Sheet
Quick recap
quick ref- •5 layers: brain senses hands memory runtime
- •Each layer independently testable
- •Tool registry = schemas + permissions
- •Memory tiers: working short long episodic
- •Runtime handles retries and HITL
Common Mistakes
- ✕Skipping evaluation for Anatomy of an Agent before production
- ✕No logging or tracing around anatomy of an agent steps
- ✕Ignoring cost and latency implications
