What is an AI Agent
Gen AI · AI Agents & Tool Use
Theory
An AI agent is a system built around an LLM that works in a loop: it plans, takes an action by calling a tool (search, run code, query a database, edit a file), observes the result and decides what to do next, until it judges the goal complete or hits a limit. A plain chatbot gives one reply from what it already knows; an agent can go and find out, check its work and change course based on real results.
This loop underlies coding assistants that read a codebase, run tests and fix failures, research assistants that search several sources, and workflow automation. The cost is more time and more model calls per task, plus real risk, because the agent now acts rather than just writes. Good agents have clear goals, limited tools, step limits and human approval for risky actions.
Why we use it
Many real tasks need several steps and fresh information: look something up, compute, check, then act. An agent automates that multi-step work instead of a person copying results between tools.
When to use it
Use an agent when the steps are not known in advance and depend on intermediate results. If the steps are fixed and predictable, a simple scripted pipeline or a single prompt is cheaper, faster and easier to test.
How it works
- User gives the agent a goal
- Agent plans the next step
- Agent calls a tool with arguments
- Agent observes the tool result
- Goal done or step limit hit? Yes: Write the final answer. No: Loop back and plan the next step.
- Return the result to the user
Example
Goal: "Find the current weather in Tokyo and email it to me."
Step 1 (think): "I need to check the weather, then send an email."
Step 2 (act): calls get_weather(city="Tokyo") → returns "22°C, cloudy"
Step 3 (observe): reads the result
Step 4 (act): calls send_email(to="user@example.com", body="Tokyo: 22°C, cloudy")
Step 5: reports back "Done — sent!"Key points
- Core loop: plan, act (call a tool), observe, repeat
- Differs from a chatbot because it can take actions and use live results
- Each loop step is another model call: more cost and latency
- Set step limits, least-privilege tools and approvals for risky actions
- Use a fixed pipeline instead when the steps are always the same