AI agents — LLMs that autonomously use tools, reason over results, and loop until they complete a goal — are the most exciting and the most fragile systems I've built. When they work, they feel like magic. When they fail, they fail in expensive and bizarre ways.
The ReAct Pattern
ReAct (Reasoning + Acting) is the most battle-tested agent pattern. The model alternates between Thought (internal reasoning), Action (tool call), and Observation (tool result) until it reaches a Final Answer. This structure forces the model to reason before acting — dramatically reducing hallucinated tool calls.
Thought: I need to find the current price of BTC/USD.
Action: search_web("Bitcoin USD price today")
Observation: Bitcoin is trading at $67,240 as of 14:32 UTC.
Thought: I have the information. I can now respond.
Final Answer: Bitcoin is currently trading at $67,240 USD.Tool Design Is Agent Design
The quality of an agent is almost entirely determined by the quality of its tools. Each tool needs a precise, unambiguous description — the model uses this to decide when and how to call it. Vague descriptions lead to wrong tool selection, which compounds across loops.
- Keep tools narrow and composable — one tool, one job
- Return structured data (JSON), not raw text the model has to parse
- Add explicit error messages that help the model self-correct
- Include example inputs and outputs in your tool descriptions
The Loop Failure Modes
Infinite loops are your biggest enemy. An agent that can't find an answer will often keep trying — racking up API costs and never terminating. Always implement: (1) a max_iterations guard, (2) a stop sequence that triggers on 'I cannot find this information', and (3) a timeout on the entire agent run.
Memory: Short-Term vs. Long-Term
In-context memory (stuffing conversation history into the prompt) works until it doesn't — context windows fill up fast in multi-step tasks. For agents that need to remember across sessions, use a vector store for long-term memory with semantic retrieval, and keep only the most recent N turns in-context.
An agent that reliably completes 80% of tasks is more valuable than one that attempts 100% and fails unpredictably. Build for reliability first.
Production Monitoring
Log every thought, action, and observation. Use tools like LangSmith, Helicone, or a custom OpenTelemetry trace to capture full agent runs. Track: total token cost per run, number of iterations, tool call success rate, and final answer quality via LLM-as-judge. Alert on anomalies.
