Skip to the workspace
Pebellslearn by building
The Agent Loop  ›  Lesson

Acting — How Tools Get Invoked

Acting / Tool Invocation 12 minWhen an agent acts, the model writes a structured tool call and the application validates it, runs the real function and returns the result to the model as a new message.

ai agents / Acting — How Tools Get Invoked

Explore each scene at your own pace.

01 · The rule

The rule

Acting — How Tools Get Invoked

Tripmate has decided its next step: search trains from Pune to Jaipur for Thursday night. But a language model can only produce text. It cannot open a connection to a railway website. So how does a decision become an action?

The rule

The model writes a request; your code does the deed.

A tool is a function your program offers to the model, described by a name, a purpose and the inputs it takes. When the model wants to act, it does not run anything. It writes a structured tool call — which tool, with which arguments:

{
  "tool": "search_trains",
  "arguments": { "from": "Pune", "to": "Jaipur", "date": "2026-10-15", "class": "sleeper" }
}

Your program then does four things:

  1. Reads the call and checks the tool name exists.
  2. Validates the arguments — right types, allowed values, permission to act.
  3. Runs the real function, such as an API request to a timetable service.
  4. Returns the result to the model as a new message, so the next turn can use it.

Many model providers support this directly: you pass tool descriptions with the request, and the model's reply can contain tool calls in a fixed format instead of plain text. The exact field names differ between providers, but the shape is the same everywhere.

Scene 1 of 5
Hover to wake the cannons. Drag to move, or use arrow keys when focused. Press Enter to fire a shot.