Skip to main content

SwarmBuilder

Struct SwarmBuilder 

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

Builds a Swarm.

Implementations§

Source§

impl SwarmBuilder

Source

pub fn agent(self, agent: Agent) -> Self

Add an agent. It needs a name, which the others hand off to; its description tells them what it is for.

The swarm adds the handoff_to_agent tool to the agent’s tool set, which clones of the agent share.

Each run of the agent gets max_turns_per_agent model calls, or the agent’s own default_max_turns if that is higher. Rig’s own default of one turn is never used here, so a refused handoff, or a tool whose result the agent must read, gets its follow-up answer.

Source

pub fn entry(self, name: impl Into<String>) -> Self

The agent the run starts with. Defaults to the first one added.

Source

pub fn max_handoffs(self, max_handoffs: usize) -> Self

How many handoffs a run may make before it fails. Defaults to 20.

Source

pub fn max_turns_per_agent(self, max_turns: usize) -> Self

How many model calls one agent’s run may make, counting the first call and every follow-up after a tool call. Applies to each agent run; an agent whose own default_max_turns is higher keeps its own. Defaults to 8; zero fails the build with BuildError::ZeroTurns. A handoff ends the run at once, so the budget only has to cover the tool calls an agent makes before it answers or hands off.

Source

pub fn execution_timeout(self, timeout: Duration) -> Self

How long a whole run may take. Defaults to 15 minutes.

Source

pub fn agent_timeout(self, timeout: Duration) -> Self

How long one agent’s turn may take. Defaults to 5 minutes.

Source

pub fn detect_repetition(self, window: usize, min_unique: usize) -> Self

Fail a run whose last window turns went to fewer than min_unique distinct agents: two agents passing the work back and forth. Off by default.

Source

pub fn allow_questions(self) -> Self

Give the agents an ask_human tool, to ask the person behind a streamed run for a decision or a fact. The agent waits for the answer within its turn, and the run’s timeouts stop meanwhile. In a plain run nobody can answer, and the tool says so to the agent.

Source

pub fn checkpoints( self, store: impl AsyncStore + WasmCompatSend + WasmCompatSync + 'static, ) -> Self

Keep the progress of runs started with run_as or stream_as in store (any rig-memory store: a DirStore, a database), so a run that stopped resumes where it was.

Source

pub fn build(self) -> Result<Swarm, BuildError>

Check the agents and give each one the handoff tool.

Auto Trait Implementations§

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