Skip to main content
The execute() function is the primary way your agent responds to users. It starts an AI loop that iterates until the model reaches a conclusion. On each iteration, the model can read the conversation, call tools, and generate code. The loop ends when the model sends a message to the user (and waits for a reply), triggers an exit, or hits the iteration limit (which defaults to 10 and is configurable). The await resolves once the loop finishes.
Under the hood, execute() is powered by LLMz.

Basic usage

The model reads the full conversation transcript, follows your instructions, and responds. If tools are available, it can call them before responding.

Instructions

Pass instructions into the instructions field to tell the model how to behave. They can be a static string or a function that returns a string:
Instructions are evaluated fresh on each execution. Use a function when you need dynamic behavior based on state, time, or other context.

Knowledge

Pass knowledge bases into the knowledge field to give the model access to your documents:
The model automatically searches the knowledge bases when it needs information. Results include citations that trace back to the source documents.
For more information on defining knowledge bases, check out the Knowledge base documentation.

Tools

Give the model functions it can call by passing them into the tools field:
The model decides when to call a tool based on the conversation. For a full guide on defining tools, see Define Tools.

Exits

Pass in exits to let the model end execution with a structured result:

Model override

You can override the default model for a specific execution:
You can also pass an array for fallback:
The default model is set in agent.config.ts under defaultModels.autonomous. You can also browse and change models from the dev console under Settings > LLM Config.

Temperature and reasoning

To control the model’s temperature and reasoning effort, use the temperature and reasoningEffort props:

Iterations

The model can loop multiple times in a single execution (e.g., call a tool, read the result, call another tool, then respond). The iterations prop controls the maximum number of loops:
The number of iterations defaults to 10 and is clamped between 1 and 100.

Cancellation

Pass an AbortSignal to cancel execution mid-loop. Useful when the caller needs to bail out (e.g. a timeout or the user navigating away):

Mode

Execution runs in chat mode by default, where the model sends messages to the user. You can switch to worker mode for background processing:
In worker mode, the model executes without sending messages to the conversation.

Hooks

Hooks let you observe and intercept execution at key moments:

Debugging execution

To see exactly what happened during an execution (which tools were called, what the model generated, how many iterations it took, and any errors), see Debug with logs and traces.
Traces view in dev console
Last modified on April 27, 2026