Skip to content
All patterns
Agents

Agent system

An LLM with tools that can decide, act and observe in a loop until a task is complete.

How an agent decides, acts and observes in a loop
1 / 4Decide

Step 1 of 4

Decide

The model reads the task and everything seen so far, then either picks a tool with arguments, such as search_orders(id=1042), or decides it can answer.

The loop ends only when the model answers instead of calling another tool.

User
Agent
Tools
APIs
Response
clientservicemodeldatabaseagentexternal
Explanation

The agent receives a task, reasons about which tool to call, executes the tool, observes the result, and loops until it can produce a final answer. This is the ReAct pattern.

Components
LLM with function callingTool definitions (schemas)Tool execution layerAgent loop / orchestratorMemory / state
When to use
  • Multi-step research tasks
  • Tasks requiring external data or actions
  • Workflows where the steps depend on intermediate results
When NOT to use
  • When the steps are fixed (use a deterministic workflow)
  • When latency or cost budget is tight
  • High-stakes actions without human approval
Failure modes
  • Infinite loops / tool thrashing
  • Hallucinated tool arguments
  • Premature termination
  • Tool errors cascading
  • Cost blowouts from unconstrained loops
  • Prompt injection via tool outputs
Production checklist
  • Max iteration limit
  • Per-run cost budget
  • Tool argument validation
  • Tool output sanitisation
  • Trace logging of every step
  • Human-in-the-loop for destructive actions
  • Timeout per tool call
  • Fallback to deterministic path on failure