AI agents
AI agents
Say this
An agent is an LLM in a loop with tools. It gets a goal, decides the next action, the application runs that tool and returns the result, and the model decides again until the goal is done or a limit is hit. The difference from a workflow is who decides the steps: in a workflow my code fixes the order; in an agent the model chooses. I use the simplest one that works, because every extra step the model decides is another place to fail, cost and wait. The parts are the model, the tools, memory, a stop rule, guardrails, and tracing so I can see every step.
- Goal from the user
- 1Model: think, choose the next actiontool_call {"name": "search_products", "arguments": {...}}
- 2App: validate, check permission, runside effects (pay, send, create) → a human confirms first
- 3Observation back into the contextonly the fields the model needs
- 4Done?Yes → answerNo → back to step 1until max steps, budget or timeout
Chatbot, workflow, agent
Tools
Memory
Planning
Stop rules and guardrails
Evaluation and tracing
| Pattern | Who decides the steps | Use it when |
|---|---|---|
| Single call | nobody, one answer | the task fits in one prompt |
| Workflow (chain, router) | my code | the steps are known in advance |
| Single agent with tools | the model, in a loop | the steps depend on what it finds |
| Multi-agent (orchestrator and workers) | a lead model hands sub-tasks to others | big tasks that split into independent parts; costs much more |
Example project
- ZargarShop is an agent: during the call Gemini decides when to search the catalog and when to create the order, depending on what the customer says. The catalog tools only read, the order tool can only insert, and staff review every order.
- Tez is deliberately not an agent: the model writes one JSON plan, and my code executes it in DuckDB. A fixed workflow is more reliable for numbers, and there is no loop to run away.
If they push
- MCP: Model Context Protocol, a standard way for a server to offer tools and data to any compatible AI app, so a tool is written once and reused.
- Prompt injection through tools: a web page or document can contain instructions. Treat tool results as data, keep tools least-privilege, and confirm side effects with the user.
- Frameworks: LangGraph, CrewAI, OpenAI Agents SDK, Claude Agent SDK. A plain loop is enough for small agents and easier to debug.
- Cost and latency: each step is a model call; cache the system prompt, use a smaller model for easy steps, and stop early.
Trap questions
- "Is every LLM with tools an agent?" No. One tool call in a fixed flow is a workflow; an agent loops and chooses.
- "Are more agents better?" Usually not. More agents means more cost, more hand-offs and more places to fail. Start with one.
- "How do you stop an infinite loop?" A hard maximum on steps and budget, detecting repeated identical calls, and a fallback answer.
Be honest
"My production agent is ZargarShop's phone agent. I haven't run a long multi-agent system in production; for numbers I chose a fixed workflow in Tez on purpose."
Questions about this chapter?
The course, homework review and the other five books are in Uzbek. Questions in English are welcome on Telegram.