ModelRefs / What are AI Agents? — Tutorial
What are AI Agents? — Tutorial
The ReAct loop, tool use, planning, and why agents fail — a practical introduction. Covers Agents vs chatbots, Why agents fail and how to handle it.
Overview
The ReAct loop, tool use, planning, and why agents fail — a practical introduction
Level: Advanced. Estimated reading time: 25 minutes.
Agents vs chatbots
A chatbot responds to one message. An agent pursues a goal across multiple steps, using tools to interact with the world.
An agent has four components: 1. LLM core: the reasoning engine that decides what to do next 2. Tools: functions the LLM can call (web search, code execution, file read/write, API calls) 3. Memory: context from the current conversation + optionally a persistent memory store 4. Planning loop: the repeated cycle of Observe → Think → Act
The ReAct (Reasoning + Acting) pattern: the LLM interleaves reasoning ("I need to find the current stock price") with actions (call_tool: web_search("AAPL stock price")) and observations (tool returns: "AAPL: $213.50"), until it has enough information to answer.
This loop can run for dozens of steps. The agent stops when it decides it has accomplished the goal, or when a maximum step limit is reached.
Why agents fail and how to handle it
The main failure modes:
Tool errors: the API returns an error, a file doesn't exist, a web search returns no results. Well-designed agents retry with slightly different inputs or gracefully inform the user.
Hallucinated tool calls: the LLM invents tool parameters or calls non-existent tools. Strict JSON schema validation and enforcing tool definitions prevents this.
Infinite loops: the agent repeats the same actions without progress. Hard step limits (max_turns=20) and progress detection (did the last N steps make progress?) are essential.
Context overflow: a long chain of tool calls fills the context window. Summarise or truncate earlier turns.
Planning horizon: agents degrade on tasks requiring 10+ steps. Breaking tasks into subgoals with a planning step helps (Plan → Execute → Verify → Next subgoal).
Continue your research
Use these connected ModelRefs sections to compare alternatives, inspect implementation paths, and review the evidence and governance boundaries relevant to What are AI Agents? — Tutorial.