Skip to main content

Subagent

Struct Subagent 

Source
pub struct Subagent<M>
where M: Runnable<Vec<Message>, Message> + 'static,
{ /* private fields */ }
Expand description

A bounded brain↔hand pairing.

The agent loop uses model as the brain, dispatching tools through tool_registry — a narrowed view of the parent registry that inherits the parent’s layer stack at zero copy cost (see module docs for the managed-agent rationale).

The constructor mandates an explicit filter (or whitelist). This is the F7 mitigation: there is no Default, no with_all_tools shortcut. Callers must say which tools and which skills they trust the sub-agent with.

Implementations§

Source§

impl<M> Subagent<M>
where M: Runnable<Vec<Message>, Message> + 'static,

Source

pub fn builder( model: M, parent_registry: &ToolRegistry, name: impl Into<String>, description: impl Into<String>, ) -> SubagentBuilder<'_, M>

Open a SubagentBuilder anchored at parent_registry. The builder is the sole construction surface — operators set the LLM-facing identity (name, description), choose the tool selection (restrict_to / filter), and attach optional sink / approver / skills before calling SubagentBuilder::build.

name and description flow through into_tool to populate SubagentTool’s metadata; declaring them at the builder surface (not at into_tool) makes the sub-agent’s identity inspectable via Subagent::name / Subagent::description before the conversion-to-tool boundary, which matters for operators that list sub-agent metadata in a parent agent’s system prompt.

Source

pub fn name(&self) -> &str

LLM-facing name surfaced to the parent’s tool dispatch. Equal to the SubagentTool’s metadata name after Self::into_tool.

Source

pub fn description(&self) -> &str

One-line description surfaced to the parent’s tool listing.

Source

pub fn metadata(&self) -> SubagentMetadata

Compact metadata snapshot for parent-side inspection. Convenient when the parent’s system prompt enumerates available sub-agents and their tool surfaces without consuming the Subagent (which into_tool does).

Source

pub fn tool_count(&self) -> usize

Number of tools the sub-agent can dispatch.

Source

pub fn tool_names(&self) -> Vec<&str>

Names of the tools the sub-agent can dispatch — useful for audit log entries. Order is unspecified.

Source

pub const fn tool_registry(&self) -> &ToolRegistry

Borrow the narrowed tool registry the sub-agent dispatches through. The view inherits the parent’s layer stack — PolicyLayer, OtelLayer, retry middleware all apply.

Source

pub const fn skills(&self) -> &SkillRegistry

Borrow the filtered skill registry the sub-agent inherited. Empty when SubagentBuilder::with_skills was never called.

Source

pub fn into_react_agent(self) -> Result<Agent<ReActState>>

Build a ReAct loop bound to this sub-agent’s narrowed tool registry (which inherits the parent’s layer stack), model, and — when SubagentBuilder::with_skills was called — the three LLM-facing skill tools (list_skills, activate_skill, read_skill_resource) backed by the inherited skill registry. See and §“Sub-agent layer-stack inheritance”. Sub-agents with no with_skills call build the registry without skill tools, matching their declared authority.

Source

pub fn into_tool(self) -> Result<SubagentTool>

Wrap this sub-agent as a Tool callable from the parent’s LLM. The resulting SubagentTool reports a metadata block keyed by name / description and accepts a single task: string input which is rendered as the first user message of the sub-agent’s ReAct loop.

§Effect classification

Sub-agents may dispatch arbitrary tools — without inspecting every transitive tool, a conservative ToolEffect::Mutating is reported. Operators that know the sub-agent is read-only override via SubagentTool::with_effect.

Trait Implementations§

Source§

impl<M> Debug for Subagent<M>
where M: Runnable<Vec<Message>, Message> + 'static,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<M> Freeze for Subagent<M>

§

impl<M> !RefUnwindSafe for Subagent<M>

§

impl<M> Send for Subagent<M>

§

impl<M> Sync for Subagent<M>

§

impl<M> Unpin for Subagent<M>

§

impl<M> UnsafeUnpin for Subagent<M>

§

impl<M> !UnwindSafe for Subagent<M>

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
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 = Infallible

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