Order of execution

Execution begins in the agent's main function. A function may call other functions with func or parallel, and an LLM may call functions as tools.

Functions and commands

A function runs its commands one after another, in the order they are written. A command completes before the next one starts, with one exception: parallel runs several functions concurrently.

Command fields

A command's fields are evaluated in the order they appear. A field may depend only on variables defined before the command, and on fields written earlier in the same command, through the command. namespace.

Flow control

ifconditiontruefalsethenelsenext commandfor / whileanother iteration?yesbodycontinuebreaknonext commandleavingreturnfunctiona valueendagentsuccessfailagentfailure
Flow control: if, loops, and the commands that leave a loop, a function or the agent
  • break and continue act on the innermost loop and propagate up through if blocks.
  • return leaves the current function, from any depth of loops.
  • end and fail stop the whole agent.
  • An error that no onError block handles, on the command or on the function, propagates to the caller and finally fails the agent.

Pausing on ask

commandsrunaskpauseposition savedwith the conversationUI shows a formuser answers laterthe answers arrive as the next messageaskresumes hereresult = answerskeyed by input namerest of the agentvariables restoredCommands before the pause are not re-executed; a function, loop or LLM tool loop in progress continues where it was.
Pausing on ask and resuming with the answers

When an ask command runs, the agent's complete position is saved with the conversation and the run ends. The position includes the function call chain, the loop iteration and any LLM tool loop in progress. When the user answers, the agent is restored to that position and continues from the ask command, whose result is the user's answers. Commands before the pause are not run again; their variables are restored.

Inside a parallel command, every branch runs until it finishes or pauses. The questions of all the paused branches are sent to the user together. When the answers arrive, each paused branch resumes at its own ask, and the branches that had finished keep their results.

Limits

A run is stopped when it exceeds the agent's maximum run time. An LLM call is refused once the run's spend passes the agent's maximum LLM cost. Long loops yield periodically so that these limits can be enforced while the loop runs.