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
impl Graph
Sourcepub async fn run(&self, task: impl Into<String>) -> Result<GraphRun, GraphError>
pub async fn run(&self, task: impl Into<String>) -> Result<GraphRun, GraphError>
Run the graph on task.
Sourcepub async fn run_as(
&self,
run_id: &str,
task: impl Into<String>,
) -> Result<GraphRun, GraphError>
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_-].
Sourcepub fn stream_as<'a>(
&'a self,
run_id: &'a str,
task: impl Into<String>,
) -> WasmBoxedStream<'a, GraphEvent>
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.
Sourcepub fn stream(&self, task: impl Into<String>) -> WasmBoxedStream<'_, GraphEvent>
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.
Trait Implementations§
Source§impl Node for Graph
impl Node for Graph
Source§fn run<'a>(
&'a self,
input: String,
io: &'a NodeIo<'a>,
) -> WasmBoxedFuture<'a, Result<NodeOutput, NodeError>>
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.