Skip to main content

GraphRun

Struct GraphRun 

Source
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

Source

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.

Source

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.

Source

pub fn trace(&self) -> Option<TraceSpec>

Returns the trace spec set with set_trace, if any. Input: none. Output: the spec.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn run_id(&self) -> RunId

Returns the run’s id. Every event and checkpoint of the run carries it. It never changes.

Source

pub fn status(&self) -> &GraphStatus

Returns the current status. It changes only in step, resume and raise_budget. It is never running outside step.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Trait Implementations§

Source§

impl Clone for GraphRun

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for GraphRun

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for GraphRun

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for GraphRun

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Serialize for GraphRun

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for GraphRun

Auto Trait Implementations§

§

impl Forget for GraphRun

§

impl Freeze for GraphRun

§

impl Move for GraphRun

§

impl RefUnwindSafe for GraphRun

§

impl Send for GraphRun
where RawVecInner: Send, NodeRef<Owned, String, Value, LeafOrInternal>: Send, BoxRaw<(String, Value)>: Send, BoxRaw<AgentRun>: Send,

§

impl Sync for GraphRun
where RawVecInner: Sync, NodeRef<Owned, String, Value, LeafOrInternal>: Sync, BoxRaw<(String, Value)>: Sync, BoxRaw<AgentRun>: Sync,

§

impl Unpin for GraphRun
where *const u8 is !null: Unpin, *const LeafNode<String, Value> is !null: Unpin, Box<(String, Value)>: Unpin, Box<AgentRun>: Unpin,

§

impl UnsafeUnpin for GraphRun

§

impl UnwindSafe for GraphRun
where RawVecInner: UnwindSafe, BTreeMap<String, Value>: UnwindSafe, BoxRaw<AgentRun>: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more