Skip to main content

Graph

Struct Graph 

Source
pub struct Graph { /* private fields */ }
Expand description

Nodes (agents, swarms, graphs, functions) connected by edges.

A run starts with the entry nodes, by default the ones without incoming edges, on the task. Then, batch by batch: the nodes of a batch run in parallel; a node that finished follows each of its outgoing edges whose condition holds, and the nodes those edges reach make the next batch. A node reached from several nodes of a batch runs once. A node gets the task when nothing led to it, and otherwise the task with the outputs of every finished node with an edge to it that holds.

A node that fails does not follow its edges, so its branch stops; the other branches carry on, and the run then fails with what it got.

With cycles, a node can run again (a reviewer sending work back to a writer, say), seeing the newest outputs before it; such a graph needs max_node_executions.

Cloning is cheap; clones share the nodes.

Implementations§

Source§

impl Graph

Source

pub fn builder() -> GraphBuilder

Start building a graph.

Source§

impl Graph

Source

pub async fn run(&self, task: impl Into<String>) -> Result<GraphRun, GraphError>

Run the graph on task.

Source

pub async fn run_with_state( &self, task: impl Into<String>, state: RunState, ) -> Result<GraphRun, GraphError>

run with the request-scoped state every node, edge condition and node_fn_with_state function of the run can read. See RunState.

Source

pub async fn run_as( &self, run_id: &str, task: impl Into<String>, ) -> Result<GraphRun, GraphError>

Run the graph as run run_id: resume it from its last checkpoint if it has one and did not finish, or else start it on task. Progress is saved as each node finishes and at the end, so a run that stopped runs only the nodes that had not finished, and a run that ended with failed nodes runs those nodes again.

Agent nodes keep a journal of their tool results, which a node run again replays rather than executing the tools twice; swarm and graph nodes keep their own progress and resume inside too.

Needs checkpoints; without them it is run. A run_id is 1-128 of [A-Za-z0-9_-].

Source

pub async fn run_as_with_state( &self, run_id: &str, task: impl Into<String>, state: RunState, ) -> Result<GraphRun, GraphError>

run_as with the request-scoped state of the run. A resumed run needs the state passed again: it is not in the checkpoint. See RunState.

Source

pub fn stream_as<'a>( &'a self, run_id: &'a str, task: impl Into<String>, ) -> WasmBoxedStream<'a, GraphEvent>

stream as run run_id, resuming it as run_as does. A resumed run starts with GraphEvent::Resumed.

Source

pub fn stream_as_with_state<'a>( &'a self, run_id: &'a str, task: impl Into<String>, state: RunState, ) -> WasmBoxedStream<'a, GraphEvent>

stream_as with the request-scoped state of the run; a resumed run needs it passed again. See RunState.

Source

pub fn stream(&self, task: impl Into<String>) -> WasmBoxedStream<'_, GraphEvent>

Run the graph on task, reporting each node as it starts, writes and finishes, and the outcome last.

The run makes progress only while the stream is polled, and stops when the stream is dropped.

Source

pub fn stream_with_state( &self, task: impl Into<String>, state: RunState, ) -> WasmBoxedStream<'_, GraphEvent>

stream with the request-scoped state of the run. See RunState.

Trait Implementations§

Source§

impl Clone for Graph

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 Node for Graph

Source§

fn run<'a>( &'a self, input: String, io: &'a NodeIo<'a>, ) -> WasmBoxedFuture<'a, Result<NodeOutput, NodeError>>

Streams the text of its nodes and passes on their questions. In a checkpointed graph run, the inner graph keeps its own progress (in its store, or else the outer graph’s), so it resumes inside too.

Auto Trait Implementations§

§

impl !RefUnwindSafe for Graph

§

impl !UnwindSafe for Graph

§

impl Forget for Graph

§

impl Freeze for Graph
where *const ArcInner<Inner> is !null: Freeze, PhantomData<ArcInner<Inner>>: Freeze,

§

impl Move for Graph

§

impl Send for Graph
where Arc<Inner>: Send,

§

impl Sync for Graph
where Arc<Inner>: Sync,

§

impl Unpin for Graph
where Arc<Inner>: Unpin,

§

impl UnsafeUnpin for Graph
where *const ArcInner<Inner> is !null: UnsafeUnpin, PhantomData<ArcInner<Inner>>: UnsafeUnpin,

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<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> 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> 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> Same for T

Source§

type Output = T

Should always be Self
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> WasmCompatSend for T
where T: Send,

Source§

impl<T> WasmCompatSync for T
where T: Sync,

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
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