Anatomy of an Agent: Brain, Tools, Memory
Let's open the agent up and look inside
Think of an agent like a worker at a desk : they have a brain (to think), tools on the desk (phone, calculator), a notebook (memory), and a goal pinned on the wall. Let's meet each part.
Key points
- Brain = the LLM that reasons.
- Tools = actions it can take.
- Memory = what it remembers across steps.
- Loop = the controller that ties it all together.
The full picture of an agent
┌───────────────────────────┐ GOAL ──────►│ THE AGENT │ │ │ │ ┌──────────────────┐ │ │ │ 🧠 BRAIN (LLM) │ │ │ │ thinks & decides│ │ │ └───────┬──────────┘ │ │ │ decides │ ┌───────────┼───────────┼───────────┐ │ ▼ │ ▼ │ │ ┌──────────┐ │ ┌──────────┐ │ │ │ 📓 MEMORY │◄────►│ │ 🛠️ TOOLS │ │ │ │ remembers│ │ │ act on │ │ │ │ context │ │ │ the world│ │ │ └──────────┘ │ └────┬─────┘ │ │ │ │ results │ │ └──────────┼────────────┘ │ ▼ │ ✅ ANSWER ─────────────┘
The 4 building blocks
- Brain (LLM) — Reads the goal + history and decides the next action or final answer. Example: "I don't know the price yet, so I should call the search tool."
- Tools — Concrete functions the agent can invoke to do real work. Example: search(query), calculator(expr), book_flight(details)
- Memory — Stores results and context so the agent doesn't forget mid-task or across sessions. Example: Short-term: this conversation. Long-term: your saved preferences.
- Control Loop — The code that runs Think → Act → Observe repeatedly and decides when to stop. Example: A while-loop with a max-steps safety limit.
Two kinds of memory (very important)
Beginners often miss that agents have two kinds of memory:
- Short-term memory: the current task's steps and tool results (lives in the prompt / context window).
- Long-term memory: facts saved to a database or vector store that the agent can recall later (e.g., 'the user prefers window seats').
We'll dedicate a whole pattern to memory later.
How a single step flows through the parts
Step N: ┌────────┐ reads ┌────────┐ picks ┌────────┐ │ MEMORY │ ───────► │ BRAIN │ ───────► │ TOOL │ └────────┘ └────────┘ └───┬────┘ ▲ │ │ writes result back │ └───────────────────────────────────────┘ (then Step N+1 begins)
▶ Try it: brain + tools + memory + a capped loop
Try changing MAX_STEPS, or add a new tool to the agent dict.
agent = {"brain": "LLM", "tools": ["search", "calc"], "memory": []}
def do_step(thought):
agent["memory"].append(thought) # write to memory
return f"completed: {thought}"
MAX_STEPS = 3 # always cap the loop!
for i in range(MAX_STEPS):
print(do_step(f"step {i + 1}"))
print("\nFinal memory:", agent["memory"])
Anatomy mistakes
| Mistake | Consequence | Fix |
|---|---|---|
| Stuffing everything into the prompt forever. | You blow past the context window; the agent forgets early steps. | Summarise old steps or move facts into long-term memory. |
| No max-step limit on the loop. | The agent can loop forever and burn money. | Always cap the loop (e.g., 10 steps) and handle the limit gracefully. |
| Giving the agent too many tools at once. | It gets confused about which tool to pick. | Give the smallest useful set of clearly-described tools. |
Anatomy cheat-sheet
- Brain decides, Tools do, Memory remembers, Loop repeats.
- Two memories: short-term (context) and long-term (database).
- Always cap the loop and keep the tool list small and well-described.
Key takeaways
- Every agent = Brain (LLM) + Tools + Memory + a Control Loop.
- The brain only decides; tools perform actions; memory keeps context.
- Agents have short-term (context) and long-term (database) memory.
- Always cap the loop and keep tools minimal and clearly described.
Frequently Asked Questions
What is Anatomy of an Agent: Brain, Tools, Memory?
Think of an agent like a worker at a desk : they have a brain (to think), tools on the desk (phone, calculator), a notebook (memory), and a goal pinned on the wall. Let's meet each part.
How does Anatomy of an Agent: Brain, Tools, Memory work?
┌───────────────────────────┐ GOAL ──────►│ THE AGENT │ │ │ │ ┌──────────────────┐ │ │ │ 🧠 BRAIN (LLM) │ │ │ │ thinks & decides│ │ │ └───────┬──────────┘ │ │ │ decides │ ┌───────────┼───────────┼───────────┐ │ ▼ │ ▼ │ │ ┌──────────┐ │ ┌──────────┐ │ │ │ 📓 MEMORY │◄────►│ │ 🛠️ TOOLS │ │ │ │ remembers│ │ │ act on │ │ │…
What are the key takeaways about Anatomy of an Agent: Brain, Tools, Memory?
Every agent = Brain (LLM) + Tools + Memory + a Control Loop. The brain only decides; tools perform actions; memory keeps context. Agents have short-term (context) and long-term (database) memory. Always cap the loop and keep tools minimal and clearly described.
Related topics
Practice this on DevInterviewMaster
Read the full Anatomy of an Agent: Brain, Tools, Memory breakdown with interactive demos, quizzes, and Hinglish notes.
800+ system-design, LLD, coding, and design-pattern topics. Unlock everything with Pro (₹499, one-time) or Ultimate (₹999, one-time) — lifetime access, no subscription.