Skip to main content
Advanced/compatible programmatic examples. Fragments illustrate mechanisms; HostEnv or workspace does not provide isolation. New projects start with Quickstart, Session and explicit resource configuration.

StateSchema

StateSchema is the base class for your agent’s typed state. It acts as the single source of truth during a run — every hook in your AgentModule reads from and writes to it.

Built-in fields

Illustrative fragment (not a standalone program; use the complete example linked on this page).

Subclassing StateSchema

Add your own fields by subclassing StateSchema. The Engine serializes state diffs into each step record using state.to_dict(), so all fields are captured in the trace automatically. Illustrative fragment (not a standalone program; use the complete example linked on this page).
Initialize it in init_state: Illustrative fragment (not a standalone program; use the complete example linked on this page).

Stopping the run

Call state.set_stop() from within reduce (the hook that folds the step’s observation and decision back into state) to halt the run on the next stop check. It accepts a StopReason enum value or its string equivalent. Illustrative fragment (not a standalone program; use the complete example linked on this page).
Setting state.final_result triggers the default FinalResultCriteria stop condition, which is the preferred way to signal a successful completion: Illustrative fragment (not a standalone program; use the complete example linked on this page).

Task

Task is a structured package that describes what the agent should do, what resources it needs, and what constraints apply. You can pass a Task anywhere agent.run() or Engine.run() accepts a task argument. Illustrative fragment (not a standalone program; use the complete example linked on this page).

Task fields

TaskBudget

TaskBudget sets per-task limits on steps, wall-clock time, and tokens. When a Task is passed to Engine.run(), its budget takes precedence over the Engine’s default RuntimeBudget. Illustrative fragment (not a standalone program; use the complete example linked on this page).
Any field left as None inherits the Engine’s default.

TaskResource

TaskResource declares a file, directory, URL, or artifact that the task depends on. The Engine validates required resources before the loop starts. Illustrative fragment (not a standalone program; use the complete example linked on this page).
Valid kind values: "file", "dir", "url", "artifact".

Decision

Decision represents the output of a single decide step — the structured choice the agent makes about what to do next, whether that is calling tools, returning a final answer, waiting, or branching. It has four modes, each with a factory method.
Execute one or more tool actions.Illustrative fragment (not a standalone program; use the complete example linked on this page).
Use the factory methods (Decision.act(), Decision.final(), etc.) rather than constructing Decision directly. They validate required fields and set mode correctly.