pub struct GraphRun { /* private fields */ }Expand description
One graph run as plain serializable data: the workflow snapshot, the
limits, the typed state, the active branches, status, usage, retry
count, event seq and step number. The host calls step and saves
checkpoint() after every step whose number moved.
Implementations§
Source§impl GraphRun
impl GraphRun
Sourcepub async fn new(
workflow: Workflow,
input: Map<String, Value>,
limits: Limits,
io: &dyn GraphIo,
) -> Result<GraphRun, GraphError>
pub async fn new( workflow: Workflow, input: Map<String, Value>, limits: Limits, io: &dyn GraphIo, ) -> Result<GraphRun, GraphError>
Starts a run of workflow on input under limits. Checks before
any step that every persona loads and can run, every tool and
condition is registered and every input key is declared and typed.
Sourcepub fn set_trace(&mut self, spec: TraceSpec)
pub fn set_trace(&mut self, spec: TraceSpec)
Traces this run with spec from its next step on; the spec is kept
in the checkpoint, so a resumed run keeps it. Input: the spec.
Output: none.
Sourcepub fn trace(&self) -> Option<TraceSpec>
pub fn trace(&self) -> Option<TraceSpec>
Returns the trace spec set with set_trace, if any.
Input: none. Output: the spec.
Sourcepub fn with_time_limit(self, limit_ms: u64) -> GraphRun
pub fn with_time_limit(self, limit_ms: u64) -> GraphRun
Sets the active-work time limit: the run stops once its steps have
taken limit_ms in total; time spent waiting never counts.
Returns the run. Call it before the first step.
Sourcepub fn add_active_ms(&mut self, ms: u64)
pub fn add_active_ms(&mut self, ms: u64)
Adds ms of active work, as the host measured one step.
The host saves it with that step’s checkpoint.
Saturates instead of overflowing.
Sourcepub fn active_ms(&self) -> u64
pub fn active_ms(&self) -> u64
Returns the active work so far, in milliseconds. Only time spent inside steps counts. Zero for runs saved before time was tracked.
Sourcepub fn time_limit_ms(&self) -> Option<u64>
pub fn time_limit_ms(&self) -> Option<u64>
Returns the active-work time limit, if the run has one. Set at start or on retry. None means no limit.
Sourcepub fn over_time(&self) -> bool
pub fn over_time(&self) -> bool
Whether the run has used up its active-work time limit. Always false without a limit. The host checks it before every step.
Sourcepub fn stopped(&self) -> Option<&Stop>
pub fn stopped(&self) -> Option<&Stop>
Returns why the run was stopped, while it is stopped.
None for runs that run, wait, finished or failed on their own.
Cleared by retry.
Sourcepub fn stop(&mut self, why: Stop) -> Result<(), GraphError>
pub fn stop(&mut self, why: Stop) -> Result<(), GraphError>
Stops the run for why: it becomes failed and takes no step until
retry, so it calls no model. A durable change for the next save.
Returns Resume when the run is already finished.
Sourcepub fn retryable(&self) -> bool
pub fn retryable(&self) -> bool
Whether retry would continue the run: it was stopped, or it failed
on a tool’s store or network error or ran out of transient retries.
False for runs that run, wait, finished, or failed for good.
Sourcepub fn retry(&mut self, time_limit_ms: Option<u64>) -> Result<(), GraphError>
pub fn retry(&mut self, time_limit_ms: Option<u64>) -> Result<(), GraphError>
Continues a stopped or retryably failed run where it stopped, with
active time back at zero and time_limit_ms as its new limit, and
queues it. A failed tool call re-runs with its first idempotency key.
Returns Resume when the run is not retryable.
Sourcepub fn from_checkpoint(cp: &Checkpoint) -> Result<GraphRun, GraphError>
pub fn from_checkpoint(cp: &Checkpoint) -> Result<GraphRun, GraphError>
Restores a run from cp. Returns Checkpoint when the state does
not parse, has another GRAPH_FORMAT, holds an agent run of another
format, is running, or does not match the checkpoint header.
Sourcepub fn checkpoint(&self) -> Checkpoint
pub fn checkpoint(&self) -> Checkpoint
Snapshots the run for a CheckpointStore: step 0 before the first
step, then one more after every durable change.
Returns the checkpoint.
Sourcepub fn host_failed(&self) -> bool
pub fn host_failed(&self) -> bool
Whether the run failed because an agent node’s host model failed in its own callback. Taken from the node’s typed failure, never from the error text, and saved in every checkpoint.
Sourcepub fn run_id(&self) -> RunId
pub fn run_id(&self) -> RunId
Returns the run’s id. Every event and checkpoint of the run carries it. It never changes.
Sourcepub fn status(&self) -> &GraphStatus
pub fn status(&self) -> &GraphStatus
Returns the current status.
It changes only in step, resume and raise_budget.
It is never running outside step.
Sourcepub fn state(&self) -> &Map<String, Value>
pub fn state(&self) -> &Map<String, Value>
Returns the shared state: input, agent outputs, tool outputs and human answers by key. Every value matches its key’s declared type.
Sourcepub fn usage(&self) -> Usage
pub fn usage(&self) -> Usage
Returns tokens and cost of every agent model call so far, in finished and in-flight nodes. This is the spend the graph run budget caps.
Sourcepub fn steps(&self) -> u64
pub fn steps(&self) -> u64
Returns the step number: how many durable changes the run has had. It is the step of the next checkpoint. Starts at 0.
Sourcepub fn workflow(&self) -> &Workflow
pub fn workflow(&self) -> &Workflow
Returns the workflow snapshot the run started with. Edits to the workflow file never reach a running run. It never changes.
Sourcepub fn pending_human(&self) -> Vec<HumanAsk>
pub fn pending_human(&self) -> Vec<HumanAsk>
Lists every human node waiting for an answer, first branch first, with its ask, prompt and the state keys it reads. Empty when no branch waits for a human.
Sourcepub fn resume(&mut self, node: &str, answer: Value) -> Result<(), GraphError>
pub fn resume(&mut self, node: &str, answer: Value) -> Result<(), GraphError>
Answers human node node with answer, checked against the node’s
writes type, and queues the run; the branch moves on at the next
step. Returns Resume when no branch waits there or it does not fit.
Sourcepub fn tighten(&mut self, limits: &Limits)
pub fn tighten(&mut self, limits: &Limits)
Tightens the graph limits with limits, each layer the stricter of
the two (Limits::stricter), and every agent branch’s limits with
its share of them, so a host that lowered limits binds older runs.
Input: the limits. Output: none.
Sourcepub fn raise_budget(&mut self, limits: Limits) -> Result<(), GraphError>
pub fn raise_budget(&mut self, limits: Limits) -> Result<(), GraphError>
Replaces the graph limits with limits and resumes every branch
paused on its budget with the new remaining run budget, then queues
the run. Returns Resume when the run is finished.
Sourcepub async fn step(&mut self, io: &dyn GraphIo) -> GraphOutcome
pub async fn step(&mut self, io: &dyn GraphIo) -> GraphOutcome
Runs one step: one unit of work (one agent step or one tool call) for every branch that can work, concurrently, with control nodes resolved before and after. Waiting and final runs change nothing. With a trace spec the step nests in the active scope, keeping content only when both the scope and the spec keep it, or writes its file.