Skip to main content
Mujtaba Farooq logoMujtaba
Back to BlogAI Agents

How AI Agents Actually Work: Planning, Tools, and Memory

Jan 23, 20263 min read
Share:

The Core Loop

Strip away the framework-specific terminology and almost every AI agent runs the same loop: observe the current state, decide on an action, take the action, observe the result, repeat until the goal is met or a stopping condition is hit. This is sometimes called the ReAct pattern (Reason + Act), and it's the conceptual backbone of agentic systems regardless of which library implements it.

Piece One: Planning

Planning is where the LLM decides what to do next based on the goal and everything it has observed so far. For simple agents, this might be a single reasoning step per action. For complex tasks, the agent might first generate a multi-step plan, then execute each step, re-planning if something doesn't go as expected.

A critical design decision is how much planning happens upfront versus how much is decided step-by-step. Upfront planning is more predictable but brittle if reality doesn't match the plan. Step-by-step planning adapts better but is harder to predict and debug.

Piece Two: Tools

Tools are how an agent affects the world beyond generating text. A tool might be a function that queries a database, calls a third-party API, sends an email, or executes code. The LLM is given a description of each available tool — what it does, what inputs it expects — and decides which tool to call and with what arguments, based on the current step in its plan.

Why tool design matters more than model choice

In practice, the quality of an agent often depends more on how well its tools are designed than on which LLM powers it. A tool that returns a clean, structured response is far easier for the model to use correctly than one that returns a wall of unstructured text. Tool descriptions that are ambiguous lead to the agent calling the wrong tool or passing malformed arguments.

Piece Three: Memory

Memory lets an agent avoid repeating itself and build on prior steps within a task. There are two practical kinds:

  • Short-term (working) memory — the running context of the current task: what's been tried, what the results were
  • Long-term memory — information that persists across sessions, often stored in a vector database and retrieved when relevant (this overlaps with RAG)

Most production agents only need solid short-term memory. Long-term memory adds real value for agents that need to remember a specific user's history or preferences across many separate interactions, but it also adds real complexity — retrieval quality becomes a new failure point.

Putting It Together: A Walkthrough

Take an agent tasked with "find the three best candidates for this role from our applicant database." It plans: first, query the database for applicants matching the role; second, score each against the job requirements; third, rank and return the top three. It calls a database tool to fetch applicants, reasons over each one's resume text, calls a scoring tool or scores them directly via the LLM, and returns the ranked result. If the database query returns zero results, the planning step adapts — maybe it broadens the search criteria and tries again.

Why This Architecture Matters for Reliability

Understanding these three pieces separately is what lets you debug an agent that's misbehaving. If it's calling the wrong tools, that's a tool description or planning problem. If it's repeating actions it already tried, that's a memory problem. If it's making reasonable individual decisions but the overall task still fails, that's often a planning architecture problem — the agent needs better visibility into its own progress toward the goal.

Mujtaba Farooq

Mujtaba

Senior Full-Stack Software Engineer with 7+ years of experience building scalable FinTech and SaaS platforms.

AI AgentsAgentic AILLM