Skip to content
AI Agents Tutorial

The Anatomy of an AI Agent: Tools, Memory and Planning

An agent is more than a chatbot with a system prompt. Breaking it into tools, memory and planning makes building one much less mysterious.

A Alex Morgan Updated 3 min read

A chatbot answers; an agent acts. An AI agent is a loop in which a language model decides what to do next, calls a tool to do it, reads the result and decides again. That loop only becomes useful with three supporting pieces: tools that give the model real abilities, memory that gives it context beyond the current message, and planning that keeps its actions pointed at a goal instead of wandering.

Tools: the model's hands

A model on its own can only produce text. Tools extend it with actions: searching a database, calling an API, running code, sending email or browsing a page. Each tool is exposed as a function with a name, a description and a typed schema for its arguments. The model does not run the tool; it requests a call and your code executes it and returns the result. The quality of the description decides whether the model reaches for the right tool at the right moment.

  • Describe each tool's purpose and when to use it.
  • Define strict argument schemas so calls are parseable.
  • Return results as plain structured text the model can read.
  • Keep the tool list small; too many options confuse the model.

Memory: short-term and long-term

Agents need two kinds of memory. Short-term memory is the running conversation, including every tool result, that the model sees on each turn. Long-term memory persists across sessions, stored as embeddings in a vector database and retrieved when relevant. A support agent, for example, recalls that a customer already tried reinstalling the app. Without retrieval, the agent forgets everything the moment a session ends.

  • Conversation history is short-term memory.
  • Tool results must be appended back into the history.
  • Embeddings plus vector search give retrievable long-term memory.
  • Summarise long histories to protect the context window.

Planning: choosing the next step

Given a goal, a capable model can propose a plan, but plans break the moment a tool returns an unexpected result. Robust agents plan in small steps: observe the current state, pick one action, execute, observe again. Some frameworks ask the model to write an explicit plan and update it as evidence arrives; others simply let the loop react one step at a time. Either way you need guardrails: a maximum number of steps and a stopping rule for when the goal is met.

A reference architecture to copy

Frameworks such as LangChain provide the scaffolding, but the architecture underneath is consistent and worth understanding on its own. Define your tools with clear schemas. Store long-term knowledge as embeddings. Maintain a working context that includes the goal, the history and the latest tool results. Then run a bounded loop in which the model chooses between answering and calling a tool. Add a confirmation gate before any irreversible action, and log every step for debugging.

  • Define tools with descriptions and strict schemas.
  • Index persistent knowledge with embeddings and retrieval.
  • Run a bounded model-tool loop with step limits.
  • Confirm before irreversible actions and log everything.

Key takeaways

  • An agent is a decision loop: the model picks an action, your code runs it, the result feeds back.
  • Tools give the model abilities beyond generating text.
  • Memory splits into the live conversation and retrievable long-term knowledge.
  • Planning works best as short reactive steps with clear guardrails.
A

Written by

Alex Morgan

Alex has spent a decade building software and five years writing about it. At AIComets they focus on prompt engineering, AI agents and honest product testing.

More articles by Alex Morgan →

Comments

Leave a comment

Comments are moderated and will appear once approved.