Agents & Tool-Use Loops
When an LLM can call functions, it becomes a worker, not a chatbot.
An agent is an LLM in a loop. Instead of producing one answer and stopping, the model can call tools — functions you define — observe the results, and decide what to do next. Repeat until the task is done.
ReAct Loop: Thought → Action → Observation
The model reasons, calls a tool, reads the result, repeats — until it emits a final answer.
The ReAct loop
The canonical pattern, ReAct (Reasoning + Acting): Thought → Action → Observation → repeat until final answer.
User: Weather in Paris and Tokyo?
Model: I need both.
Action: get_weather("Paris") → { temp: 14, conditions: "rainy" }
Action: get_weather("Tokyo") → { temp: 22, conditions: "clear" }
Model: Paris is 14°C and rainy. Tokyo is 22°C and clear.
Defining good tools
A tool is a function with a JSON-schema'd signature. Good tool design: one job per tool, descriptive names (search_customer_orders not query_db), clear parameter descriptions with examples, helpful error strings the model can react to, and 5–15 tools total (beyond 30, models lose track).
The orchestration layer
Real-world agents need orchestration the LLM doesn't provide: retry logic, cost limits (agents can spiral; cap total spend), step limits (prevent infinite loops), timeouts per call, logging + replay for debugging, and human-in-the-loop for irreversible actions. Frameworks like LangGraph, OpenAI Agents SDK, and Inngest handle this.
Single-agent vs multi-agent
- Single agent — one LLM with many tools. Simple, reliable. Default choice.
- Multi-agent — multiple LLMs with specialised roles. More powerful for complex tasks, far harder to debug.
Most production "agents" are single-agent. Multi-agent gets oversold.
What kills agents in production
- Tool errors the model can't recover from — always return diagnostic strings, not stack traces.
- Context window blowup — every observation adds tokens; use summarisation for old turns.
- Confidently wrong tool calls — model passes
order_id="ORD-{customer_id}"literally; always validate inputs.
Use agents where the alternative is many manual steps or a custom workflow engine.