RunState#

class scikitplot.agent.RunState(run_id, goal, status=RunStatus.RUNNING, stop_reason=None, steps=<factory>, spent=<factory>, answer=None, pending=None, in_flight=None, error=None, audit_head=None)[source]#

The whole of one run, saved after every step.

Parameters:
run_idstr

64 hexadecimal digits.

goalstr

What the run is for, as given to Agent.run.

statusRunStatus, default=”running”
stop_reasonStopReason or None, default=None

Set whenever status is not running.

stepslist of Step
spentSpent
answerobject, default=None

The accepted answer, for a completed run.

pendingApprovalRequest or None, default=None

The action waiting for approval, for a paused run.

in_flightdict or None, default=None

{"step", "key", "idempotent", "attempt", "decision", "gates"} while a tool call runs; a state saved with it set is a run that stopped during the call.

errorAgentError or None, default=None

Why the run failed or stopped.

audit_headdict or None, default=None

{"seq", "digest"} of the run’s last audit record, so a resumed run continues the same hash chain.

Parameters:

Notes

User. A planner receives a copy of the state rebuilt from its JSON form, so it reads exactly what was saved and cannot change the run.

answer: Any = None#
audit_head: dict[str, Any] | None = None#
check()[source]#

Check that the state is one a run can be in.

Raises:
StateError

If the status and the stop reason disagree; the steps are not numbered 0, 1, …; a pending request or an in-flight call is not for the next step of this run; a completed run does not end with its accepted answer; or spent.steps is not the number of decisions the steps account for.

Return type:

None

copy()[source]#

Return an independent copy, rebuilt from to_dict.

Return type:

RunState

property done: bool#

Whether the run has ended (completed, stopped or failed).

error: AgentError | None = None#
classmethod from_dict(data)[source]#

Rebuild a state written by to_dict.

Raises:
StateError

If a key is missing or unknown, the schema version is not SCHEMA_VERSION, or a field is malformed.

Parameters:

data (Mapping[str, Any])

Return type:

RunState

goal: str[source]#
in_flight: dict[str, Any] | None = None#
observations()[source]#

Return each step as a planner reads it, in order.

Returns:
list of dict

{"index", "kind", "tool", "arguments", "outcome", "result", "error"} per step; error is {"code", "message"} or None.

Return type:

list[dict[str, Any]]

pending: ApprovalRequest | None = None#
run_id: str[source]#
spent: Spent[source]#
status: RunStatus = 'running'[source]#
steps: list[Step][source]#
stop_reason: StopReason | None = None#
to_dict()[source]#

Return a JSON-compatible mapping (schema version SCHEMA_VERSION).

Return type:

dict[str, Any]