pub struct Subagent<M>{ /* 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>
impl<M> Subagent<M>
Sourcepub fn builder(
model: M,
parent_registry: &ToolRegistry,
name: impl Into<String>,
description: impl Into<String>,
) -> SubagentBuilder<'_, M>
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.
Sourcepub fn name(&self) -> &str
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.
Sourcepub fn description(&self) -> &str
pub fn description(&self) -> &str
One-line description surfaced to the parent’s tool listing.
Sourcepub fn metadata(&self) -> SubagentMetadata
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).
Sourcepub fn tool_count(&self) -> usize
pub fn tool_count(&self) -> usize
Number of tools the sub-agent can dispatch.
Sourcepub fn tool_names(&self) -> Vec<&str>
pub fn tool_names(&self) -> Vec<&str>
Names of the tools the sub-agent can dispatch — useful for audit log entries. Order is unspecified.
Sourcepub const fn tool_registry(&self) -> &ToolRegistry
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.
Sourcepub const fn skills(&self) -> &SkillRegistry
pub const fn skills(&self) -> &SkillRegistry
Borrow the filtered skill registry the sub-agent inherited.
Empty when SubagentBuilder::with_skills was never called.
Sourcepub fn into_react_agent(self) -> Result<Agent<ReActState>>
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.
Sourcepub fn into_tool(self) -> Result<SubagentTool>
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§
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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