Skip to content

Agent

An autonomous loop: input -> tool calls -> final answer.

The provider never sees tool-use APIs. The protocol renders tool instructions into the system prompt and parses tool calls out of the model's plain-text responses; results are fed back as observations until the model emits a final_answer envelope.

from_state(state, provider, tools=(), **kwargs) classmethod

Build an agent that continues the conversation stored in state.

Provider, tools and hooks are code — pass them here, not in the state. The next run() appends its input to the loaded conversation.

run(input, *, max_iterations=25, on_max=OnMax.RAISE, control=None, output_model=None) async

Run the loop until final_answer, max_iterations or a hook stops it.

If this agent was built with from_state (or has run before), the new input continues the existing conversation instead of starting one.

to_state()

Snapshot the current session (conversation + audit history).

RunResult

Final outcome of Agent.run with a full audit trail.

OnMax

Bases: StrEnum

What to do when max_iterations is exhausted.

Exceptions

Bases: ToolloopError

Invalid control-mode configuration (e.g. APPROVE without an approver).

Bases: ToolloopError

run() exhausted max_iterations with OnMax.RAISE.

Bases: ToolloopError

Too many consecutive unparseable responses: auto-repair gave up.