Expand description
Multi-agent patterns for Rig.
- A
Swarmis a team of agents that pass the work to each other: each agent gets ahandoff_to_agenttool, and the first agent that answers without handing off gives the swarm’s answer. - A
Graphruns nodes (agents, swarms, graphs or plain async functions) along edges, some of them conditional. Nodes that become ready together run in parallel, and each node gets the outputs of the nodes that led to it.
use rig_multiagent::{Graph, Swarm};
// The researcher starts and hands off to the coder when it is done.
let swarm = Swarm::builder().agent(researcher).agent(coder).build()?;
let run = swarm.run("Add a retry to the HTTP client").await?;
println!("{} answered: {}", run.agent, run.answer);
// The same team as one step of a graph, followed by a review.
let graph = Graph::builder()
.node("build", swarm)
.node("review", reviewer)
.edge("build", "review")
.build()?;
let run = graph.run("Add a retry to the HTTP client").await?;
println!("{}", run.answer());Re-exports§
pub use rig_memory;
Structs§
- FnNode
- A node made of an async function; see
node_fn. - Graph
- Nodes (agents, swarms, graphs, functions) connected by edges.
- Graph
Builder - Builds a
Graph. - Graph
Error - A graph run in which something failed, with what the rest produced.
- Graph
Run - A graph run, whole or (in a
GraphError) partial. - Graph
State - A run so far, as edge conditions see it.
- Handoff
- One agent passing the work to another.
- Human
Node - A graph node that asks a person; see
human. - NodeIo
- What a node can do while it runs: report text and ask a person (in a streamed run), and keep its progress (in a checkpointed one).
- Node
Output - What a node produced.
- Question
- A question for a person, reported by a streamed run. The part of the run that asked waits until it is answered; time spent waiting does not count against the run’s timeouts. Dropping it unanswered tells the asker that nobody answered.
- RunState
- Request-scoped values a run is given when it starts: a user id, a tenant,
a database handle. Nodes,
edge_ifconditions andnode_fn_with_statefunctions read them throughGraphState::run_stateorNodeIo::run_state. - State
FnNode - A node made of an async function that reads the run’s state; see
node_fn_with_state. - Swarm
- A team of agents that pass the work to each other.
- Swarm
Builder - Builds a
Swarm. - Swarm
Error - A swarm run that ended without an answer, with what happened before.
- Swarm
Run - A swarm run that ended with an answer.
Enums§
- Build
Error - Why a
SwarmorGraphcould not be built. - Checkpoint
Error - Why a run’s checkpoint could not be read or written.
- Graph
Event - What a streamed graph run reports, as it happens.
- Graph
Failure - Something that went wrong in a graph run.
- Swarm
Event - What a streamed swarm run reports, as it happens.
- Swarm
Failure - Why a swarm run stopped without an answer.
Constants§
- ASK_
TOOL - The name of the tool a swarm that allows questions gives its agents.
- HANDOFF_
TOOL - The name of the tool a swarm gives each of its agents.
Traits§
- Node
- One step of a
Graph: takes the text built from the task and the outputs before it, and produces text.
Functions§
- human
- A graph node that asks a person
question, with its input as the question’s context, and outputs their answer. - node_fn
- A node that runs
f: deterministic steps between agents (parsing, validation, a lookup, a tool) without a model call. - node_
fn_ with_ state - A node that runs
fwith the request-scoped state of its run: asnode_fn, andfalso gets theRunStatethe graph was started with.
Type Aliases§
- Node
Error - Why a node failed: a boxed error,
Send + Syncexcept on wasm.