Skip to main content

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

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.
Initialize it in init_state:

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.
Setting state.final_result triggers the default FinalResultCriteria stop condition, which is the preferred way to signal a successful completion:

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.

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.
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.
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.
Use the factory methods (Decision.act(), Decision.final(), etc.) rather than constructing Decision directly. They validate required fields and set mode correctly.