pub struct SubAgentMiddleware {
pub max_iterations: u32,
/* private fields */
}Expand description
Middleware that allows the main agent to delegate tasks to isolated sub-agents.
Provides a SubAgentTool that the main agent can invoke with a task description.
The tool spins up a lightweight sub-agent (a single model call), runs it to
completion, and returns the sub-agent’s output.
Fields§
§max_iterations: u32Maximum number of iterations a sub-agent may run.
Implementations§
Source§impl SubAgentMiddleware
impl SubAgentMiddleware
Sourcepub fn new(model: Arc<dyn BaseChatModel>, max_iterations: u32) -> Self
pub fn new(model: Arc<dyn BaseChatModel>, max_iterations: u32) -> Self
Create a new SubAgentMiddleware with the given model and iteration limit.
Sourcepub fn tools(&self) -> Vec<Arc<dyn BaseTool>>
pub fn tools(&self) -> Vec<Arc<dyn BaseTool>>
Return the set of tools this middleware provides.
Sourcepub async fn subagents(&self) -> HashMap<String, SubAgentHandle>
pub async fn subagents(&self) -> HashMap<String, SubAgentHandle>
Get a snapshot of all sub-agent handles.
Trait Implementations§
Source§impl Middleware for SubAgentMiddleware
impl Middleware for SubAgentMiddleware
Source§fn before_model<'life0, 'life1, 'async_trait>(
&'life0 self,
_state: &'life1 mut AgentState,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn before_model<'life0, 'life1, 'async_trait>(
&'life0 self,
_state: &'life1 mut AgentState,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Called before the model is invoked. Can mutate the state (e.g. inject context).
Source§fn after_model<'life0, 'life1, 'async_trait>(
&'life0 self,
_state: &'life1 mut AgentState,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn after_model<'life0, 'life1, 'async_trait>(
&'life0 self,
_state: &'life1 mut AgentState,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Called after the model responds. Can inspect or mutate the state.
Source§fn before_tool<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
_state: &'life1 mut AgentState,
_tool_name: &'life2 str,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn before_tool<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
_state: &'life1 mut AgentState,
_tool_name: &'life2 str,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Called before a tool is executed.
Source§fn gate_tool<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
_state: &'life1 mut AgentState,
_tool_name: &'life2 str,
_tool_input: &'life3 Value,
) -> Pin<Box<dyn Future<Output = Result<ToolGateDecision>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
fn gate_tool<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
_state: &'life1 mut AgentState,
_tool_name: &'life2 str,
_tool_input: &'life3 Value,
) -> Pin<Box<dyn Future<Output = Result<ToolGateDecision>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
Called before a tool is executed, with an opportunity to short-circuit. Read more
Source§fn after_tool<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
_state: &'life1 mut AgentState,
_tool_name: &'life2 str,
_result: &'life3 str,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
fn after_tool<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
_state: &'life1 mut AgentState,
_tool_name: &'life2 str,
_result: &'life3 str,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
Called after a tool execution completes.
Auto Trait Implementations§
impl Freeze for SubAgentMiddleware
impl !RefUnwindSafe for SubAgentMiddleware
impl Send for SubAgentMiddleware
impl Sync for SubAgentMiddleware
impl Unpin for SubAgentMiddleware
impl UnsafeUnpin for SubAgentMiddleware
impl !UnwindSafe for SubAgentMiddleware
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
Mutably borrows from an owned value. Read more