llm

Sends one of the agent's prompts to a large language model and returns the model's answer. With functions or mcp set, the model can call tools, and the command runs the tool loop for you.

Fields

FieldTypeDefaultDescription
onErrorcommand blockCommands to run if this command raises an uncaught error.
profilerequiredstringThe LLM profile, which defines the vendor, model and call parameters.
promptrequiredstringThe name of one of the agent's prompts. Its history is kept under this name.
functionslist of nameFunctions the LLM may call as tools.
mcplist of stringMCP tools used in this LLM call. Each element should be in the form MCP_NAME.TOOL_NAME.
vendorToolslist of string or integer or number or boolean or list of SafeJsonValue or object of string → SafeJsonValueTools provided by the vendor and executed on the vendor side. Passed unchanged to the LLM provider.
maxToolCallLoopsinteger10The maximum number of tool-calling rounds.
timeoutinteger60LLM timeout in seconds. This timeout applies separately to each call during multi-step tool calling.
outputFormat"default" | "structured""default"'default' or 'structured'. With 'structured', the LLM must call a function named in 'functions', and the function is not run: the result is a dict keyed by the function's name, holding the arguments the LLM passed, for example result['facts']['country'] for a function 'facts' with an argument 'country'.
streamOutputbooleanfalseStreams the LLM's text and image output to the user. Off by default.

Result

By default the result is the model's text answer, as a string. With outputFormat: "structured", the model is expected to answer with a tool call, and the result is a dict of { functionName: arguments }, shaped by the function's declared args. The result is typed, with no text to parse. With streamOutput: true, the text and any images the model produces are also streamed straight to the user as part of the agent's output.

Tool calling

promptsystem + history + userLLManswerno tool call · the resulttool callrun the toolyour function or MCPtool resultsRepeats until the LLM answers without a tool call, at most maxToolCallLoops times.A tool error goes back to the LLM with the profile's tool error prompt.
The llm command's tool loop

functions lists the functions of this agent that the model may call. Each needs a description and typed args, because the model sees those. When the model asks for a call, the function runs with the model's arguments, and its return value goes back to the model. The loop repeats until the model answers with text or maxToolCallLoops is reached.

mcp lists tools from MCP servers as server.tool, or server for every tool the server offers. vendorTools passes vendor-defined tools, such as web search, through untouched. The LLM profile caps how many tools one call may carry.

An error inside a tool function is handled by that function's own onError blocks. An error that leaves the function ends the run; it is not given to the model. An MCP tool's error is given to the model, together with the profile's tool error prompt, when the server reports it as a tool error or with a code the MCP profile lists as retryable, and the model can then correct its arguments or give up. See Error handling. An ask inside a tool function pauses the agent as anywhere else, and the agent resumes mid-loop when the user answers.

Example

"functions": {
  "runQuery": {
    "description": "Runs a SQL query against the orders database and returns the rows.",
    "args": {
      "sql": { "type": "str", "description": "A read-only SQL query." }
    },
    "commands": {
      "db": { "profile": "orders", "sql": "{ sql }" },
      "return": "{ result }"
    }
  },
  "main": {
    "commands": {
      "llm": {
        "profile": "gpt5_mini",
        "prompt": "orders",
        "functions": ["runQuery"],
        "streamOutput": true
      }
    }
  }
}

The agent has a prompt named orders, set in the UI. Its system text says You answer questions about orders. The table orders has columns id, status, total and customer_email. Its user text is { sys.query }.

Rules

  • prompt is the literal name of one of the agent's prompts. Validation refuses a name the agent has no prompt for. The prompt's system and user text are evaluated in the function where the command runs, and its history is kept under its name.
  • The prompt's system text must evaluate to text, and its user text to text, a content part or a list of them. Anything else is refused before the model is called; see What the texts may evaluate to.
  • Two llm commands that run at the same time must use different prompts. A tool function cannot use the prompt of the command that called it, and parallel branches need prompts of their own.
  • profile is the literal name of an LLM profile. To choose a profile at run time, branch with if.
  • The token ceiling, retries, headers and any extra request parameters come from the profile. Only timeouts, connection errors and HTTP 429 and 5xx responses are retried, with a short wait that grows on each attempt. A 400, 401 or 404 fails at once. Every attempt that is paid for counts toward the agent's cost limit.
  • The run is stopped once its LLM spend passes the agent's own cost limit; see Runtime limits.
  • end is not allowed inside a tool function. A tool must return to the model.