Skip to main content

MagenticBuilder

Struct MagenticBuilder 

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

Builder for a Magentic workflow. Rust analogue of MagenticBuilder.

let manager = StandardMagenticManager::new(manager_agent);
let workflow = MagenticBuilder::new()
    .participant("coder", coder)
    .participant("researcher", researcher)
    .standard_manager(manager)
    .max_round_count(10)
    .build()?;

Implementations§

Source§

impl MagenticBuilder

Source

pub fn new() -> Self

Create an empty builder.

Source

pub fn participant( self, name: impl Into<String>, agent: Arc<dyn SupportsAgentRun>, ) -> Self

Register a participant (its description defaults to its name).

Source

pub fn participant_described( self, name: impl Into<String>, description: impl Into<String>, agent: Arc<dyn SupportsAgentRun>, ) -> Self

Register a participant with an explicit description (shown to the manager).

Source

pub fn participants( self, participants: impl IntoIterator<Item = (String, Arc<dyn SupportsAgentRun>)>, ) -> Self

Register several participants as (name, agent) pairs.

Source

pub fn manager(self, manager: Arc<dyn MagenticManager>) -> Self

Use a custom MagenticManager.

Source

pub fn standard_manager(self, manager: StandardMagenticManager) -> Self

Use a StandardMagenticManager (convenience wrapper around MagenticBuilder::manager).

Source

pub fn max_round_count(self, n: usize) -> Self

Override the maximum number of rounds.

Source

pub fn max_stall_count(self, n: usize) -> Self

Override the stall threshold.

Source

pub fn max_reset_count(self, n: usize) -> Self

Override the maximum number of replans.

Source

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

Set the workflow name.

Source

pub fn with_plan_review(self) -> Self

Require a human to review and approve (or send back for revision) the initial plan before the coordination round loop starts. See the module-level docs for the full request/response loop semantics. Rust analogue of Python’s MagenticBuilder.with_plan_review(enable=True).

Source

pub fn max_plan_review_rounds(self, n: u32) -> Self

Override the maximum number of plan-review revise rounds before the orchestrator force-proceeds with whatever plan is current (default 10, matching Python). Only meaningful with Self::with_plan_review.

Source

pub fn with_stall_intervention(self) -> Self

Pause for a human decision when the round loop detects a stall, instead of silently auto-replanning. When stall_count exceeds max_stall_count the orchestrator emits a MagenticStallInterventionRequest via WorkflowContext::request_info and suspends until a MagenticStallInterventionDecision is supplied. See the module-level docs for the full loop semantics. Rust analogue of Python’s MagenticBuilder.with_human_input_on_stall(enable=True).

Source

pub fn output_from( self, names: impl IntoIterator<Item = impl Into<String>>, ) -> Self

Designate participants (by the name passed to Self::participant/Self::participant_described) as a workflow output source, forwarded to WorkflowBuilder::output_from.

Divergence from Sequential/Concurrent: like GroupChatBuilder, Magentic compiles to a single orchestrator Executor that drives the whole plan/round loop internally (see the module-level design note) rather than one executor per participant, so there is no per-participant executor id to route to individually. Naming any participant here keeps the orchestrator’s single final yield — the synthesized final answer — as the terminal WorkflowEvent::Output (already the default). Call Self::intermediate_output_from instead to demote it to a non-terminal WorkflowEvent::Intermediate event when composing Magentic into a larger workflow.

Rejected at build() if a name does not match any registered participant, or if this and Self::intermediate_output_from are both non-empty (both resolve to the same underlying executor id).

Source

pub fn intermediate_output_from( self, names: impl IntoIterator<Item = impl Into<String>>, ) -> Self

Designate participants (by name) as an intermediate-output source, demoting the orchestrator’s single final yield to a non-terminal WorkflowEvent::Intermediate event instead of the workflow’s terminal output. See Self::output_from for the single-executor caveat.

Source

pub fn build(self) -> Result<Workflow>

Validate and build the Magentic workflow.

Trait Implementations§

Source§

impl Default for MagenticBuilder

Source§

fn default() -> MagenticBuilder

Returns the “default value” for a type. Read more

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, 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, 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, <T as TryFrom<U>>::Error>

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