How AI agents work
An AI agent is a language model in a loop. It plans, calls tools, reads the results and decides what to do next until the goal is met or a limit is reached.
- 1
Start from a goal
An agent gets a goal instead of a single question. A language model sits at the center and decides what to do next.
- 2
Make a plan
The model breaks the goal into steps it can act on.
- 3
Call a tool
To act, the model writes a structured tool call, like a search with parameters. Your code runs the tool and returns the result.
- 4
Observe and decide again
Each result goes back into the model's context. It picks the next action, and the loop continues.
- 5
Stop when done
The loop ends when the goal is met or a limit is hit. Limits on steps, cost and permissions keep agents safe.
Start from a goal
An agent gets a goal instead of a single question. A language model sits at the center and decides what to do next.
Make a plan
The model breaks the goal into steps it can act on.
Call a tool
To act, the model writes a structured tool call, like a search with parameters. Your code runs the tool and returns the result.
Observe and decide again
Each result goes back into the model's context. It picks the next action, and the loop continues.
Stop when done
The loop ends when the goal is met or a limit is hit. Limits on steps, cost and permissions keep agents safe.
In short
- The model never runs anything itself. It proposes tool calls and your code executes them, which is where permissions belong.
- Many failures come from unclear tools: names, descriptions and error messages matter as much as the prompt.
- Cap the loop with a step and cost budget, and log every call so you can replay what happened.
- For simple tasks a single call beats an agent. Use the loop when the next step depends on what the last one found.