Skip to main content

Crate rig_multiagent

Crate rig_multiagent 

Source
Expand description

Multi-agent patterns for Rig.

  • A Swarm is a team of agents that pass the work to each other: each agent gets a handoff_to_agent tool, and the first agent that answers without handing off gives the swarm’s answer.
  • A Graph runs 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.
GraphBuilder
Builds a Graph.
GraphError
A graph run in which something failed, with what the rest produced.
GraphRun
A graph run, whole or (in a GraphError) partial.
GraphState
A run so far, as edge conditions see it.
Handoff
One agent passing the work to another.
HumanNode
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).
NodeOutput
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_if conditions and node_fn_with_state functions read them through GraphState::run_state or NodeIo::run_state.
StateFnNode
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.
SwarmBuilder
Builds a Swarm.
SwarmError
A swarm run that ended without an answer, with what happened before.
SwarmRun
A swarm run that ended with an answer.

Enums§

BuildError
Why a Swarm or Graph could not be built.
CheckpointError
Why a run’s checkpoint could not be read or written.
GraphEvent
What a streamed graph run reports, as it happens.
GraphFailure
Something that went wrong in a graph run.
SwarmEvent
What a streamed swarm run reports, as it happens.
SwarmFailure
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 f with the request-scoped state of its run: as node_fn, and f also gets the RunState the graph was started with.

Type Aliases§

NodeError
Why a node failed: a boxed error, Send + Sync except on wasm.