Skip to content
agent2agent
Understanding AI Agents

How AI Agents Think: Planning, Memory, and Tool Use Explained

AI agents think through a repeating observe-think-act loop, using chain-of-thought reasoning to plan which tool to call next and memory systems to avoid starting from scratch each step.

By Nora LinJune 1, 20257 min read

A language model on its own predicts tokens. An AI agent does something qualitatively different: it reasons about a goal, chooses an action, observes the outcome, and updates its plan — sometimes hundreds of times before finishing a task. Understanding **how ai agents think** is essential if you want to build reliable ones or even just evaluate the ones you're using.

Quick answer

AI agents think via the ReAct pattern: Reason about what to do, Act by calling a tool, then Observe the result and repeat. Chain-of-thought lets the model plan step-by-step. Memory stores earlier results so the agent doesn't forget what it already learned. The loop terminates when the agent judges the goal is met.

What is the ReAct pattern and why does it matter?

ReAct — short for Reason + Act — is the foundational framework published by Yao et al. at Google and Princeton (2022) that showed language models perform dramatically better on multi-step tasks when they interleave reasoning traces with actions, compared to acting without explicit reasoning. In benchmark tests across HotpotQA, FEVER, and ALFWorld, ReAct agents outperformed pure chain-of-thought and pure action baselines by meaningful margins.

In practice, each step of the loop looks like this in the model's output stream:

  1. Thought: I need to find the current population of Tokyo to answer the user's question. I'll search for it.
  2. Action: search("Tokyo population 2024")
  3. Observation: Tokyo metropolitan area population is approximately 37.4 million as of 2024.
  4. Thought: I have the number. The user's question is answered. I can stop.
  5. Final Answer: Tokyo's metropolitan population is approximately 37.4 million.

The reasoning step is not decoration — it makes the agent's tool selection dramatically more accurate and gives the system a natural place to catch its own mistakes before committing to an action.

The ReAct loop: each cycle produces a Thought, an Action (tool call), and an Observation that feeds the next Thought.

How do agents use chain-of-thought to plan?

Chain-of-thought (CoT) prompting asks the model to show its work — to write out intermediate reasoning before committing to a conclusion. For agents, CoT serves as the planning layer. Before calling any tool, the agent narrates its intentions: 'I have three sub-tasks here. I'll handle them in order: first get the data, then calculate the metric, then format the report.'

More sophisticated agents use Plan-and-Execute: the model first generates a complete task list, then executes each step, revisiting the plan when new information changes the picture. This is more reliable for tasks with 10+ steps because the agent commits to a structure rather than improvising at every turn. LangGraph supports this pattern natively through its graph-based state machine.

When planning breaks down

Planning fails most often in three situations: the goal is ambiguous (the model plans for the wrong objective), the model over-estimates its own knowledge (it skips a tool call it should make), or the plan is too rigid (new information contradicts step 3 but the agent plows ahead anyway). Defensive agent design adds a replanning step after every N actions or after any unexpected observation.

How does an agent decide which tool to call?

Tool selection happens inside the reasoning step. The model reads its tool schema — a list of available functions with names, descriptions, and parameter types — and picks the tool whose description best matches what it needs next. This means the quality of a tool's description is as important as the tool's actual implementation.

A poorly described tool gets ignored or misused. A rule of thumb: write tool descriptions the way you'd explain a function to a new engineer. Include what the tool does, what inputs it expects, what it returns, and when NOT to use it. For example:

  • Bad: `search(query)` — searches the web.
  • Good: `web_search(query: str) -> str` — performs a live web search and returns the top 5 result snippets. Use when you need current information not in your training data. Do not use for mathematical calculations or code execution.

What are the types of memory an agent can use?

Memory is the component that most distinguishes a capable agent from a brittle one. There are four types worth knowing:

Short-term Long-term
The four memory layers in an AI agent: in-context (fastest, limited), working memory (structured scratch-pad), episodic (event log), and semantic (vector store retrieval).

In-context memory

This is the agent's active working memory — everything in the current token window. It's fast, but token limits mean it can't hold more than a few dozen tool call results before older information gets pushed out. Most agents manage this by summarizing or truncating older turns.

Working / scratch-pad memory

A structured data store the agent writes to and reads from within a session — for example, a JSON object tracking which sub-tasks are done. LangGraph agents store this in the graph state object, which persists across nodes.

Episodic memory

A log of past events: 'At step 4, I searched for X and got an empty result.' Episodic memory prevents the agent from repeating the same failed action in the same session. It can also persist across sessions so the agent doesn't retry strategies it already knows don't work.

Semantic (vector store) memory

Long-term facts stored as embeddings in a vector database. The agent retrieves relevant chunks via similarity search before each step. This allows agents to work with knowledge bases far larger than any token window — millions of documents — by fetching only what's relevant to the current reasoning step.

Why do agents sometimes loop or hallucinate?

Looping happens when the agent's termination condition is too weak. If the model doesn't confidently recognize that the goal is met, it keeps generating new actions. Common fixes: add an explicit 'FINAL ANSWER' token the runtime watches for, set a hard step-count ceiling, or include a separate evaluator agent that checks whether the goal is satisfied after each round.

Hallucination in agents is subtler than in a plain chatbot. The agent may hallucinate a tool call (invoking a function that doesn't exist), hallucinate tool output (inventing the result of a search it didn't run), or hallucinate a planning step (claiming to have done step 3 when it skipped it). The fix is strict tool call validation — the runtime should reject any tool invocation whose schema doesn't match and return an error observation, forcing the agent to self-correct.

For a deeper look at the memory side of this problem, AI Agent Memory Systems goes into implementation detail for each memory type.

Frequently asked questions

What is the ReAct pattern in AI agents?
ReAct (Reason + Act) is a prompting strategy where the agent alternates between writing a reasoning trace and calling a tool. The reasoning step makes tool selection more accurate and gives the agent a chance to catch its own mistakes before acting. It was introduced in a 2022 paper by Yao et al. and is now the default approach in most agent frameworks.
How does chain-of-thought help an AI agent plan?
Chain-of-thought prompting asks the model to write out intermediate steps before committing to a decision. For agents, this acts as a planning layer — the model narrates what it intends to do and why, which catches logical errors before they become tool calls. The written plan also gives the runtime a log to debug when something goes wrong.
What limits an AI agent's memory?
In-context memory is limited by the model's token window — typically 8k to 200k tokens depending on the model. Beyond that, agents need external memory stores. Even with long-context models, performance often degrades on information buried in the middle of a very long context (the 'lost in the middle' problem), making retrieval-augmented memory a better choice for large knowledge bases.
Why do AI agents get stuck in loops?
Agents loop when their termination condition is unclear or the model lacks confidence that the goal is met. A weak system prompt that doesn't define what 'done' looks like, or a goal that is ambiguous, are the most common causes. Adding a hard step ceiling (e.g., max 20 iterations), a distinct FINAL_ANSWER token, or a separate evaluator agent are the standard mitigations.
Can an agent recover from a bad tool call?
Yes, if the runtime returns the error as an observation rather than crashing. Well-designed agent loops treat tool errors as data: the error message is injected as the next observation and the agent reasons about how to recover — retry with different parameters, switch to a different tool, or escalate to the user. This requires explicit error handling in the agent scaffold, not just in the tool itself.
Nora Lin

Written by

Nora Lin

Senior AI Research Analyst & Technical Reviewer

Nora researches AI agent capabilities, safety, and practical deployment patterns. She reviews every guide on agent2agent to ensure technical accuracy and current best practices.

This article is for educational purposes only. It does not constitute professional software, legal, or financial advice. Read our full disclaimer.

Related articles

Understanding AI Agents

What Is an AI Agent? The Complete Guide

AI agents are programs that perceive their environment, plan a sequence of steps, use tools to act, and loop back until a goal is achieved — unlike a one-shot LLM call that just predicts the next token.

Marcus Reid·9 min read
Understanding AI Agents

AI Agents vs Chatbots: Key Differences That Actually Matter

Chatbots answer; AI agents act. Chatbots are stateless and single-turn; agents are stateful and multi-step. The line blurs when chatbots get tools, but the core architectural difference still shapes what each is good for.

Marcus Reid·6 min read
Building & Developing Agents

How to Build Your First AI Agent: A Step-by-Step Guide

You can build a working AI agent in an afternoon: install LangGraph, define a state schema, write two nodes (reason and act), attach a real tool like web search, wire the edges, and run the loop. This guide shows every step.

Nora Lin·10 min read