pub struct SubagentExecutor { /* private fields */ }Expand description
Subagent executor for managing and executing subagents
§Example
use claude_agent_sdk::subagents::{SubagentExecutor, Subagent, DelegationStrategy};
#[tokio::main]
async fn example() -> Result<(), Box<dyn std::error::Error>> {
let mut executor = SubagentExecutor::new(DelegationStrategy::Auto);
// Register a subagent
let subagent = Subagent {
name: "code-reviewer".to_string(),
description: "Expert code reviewer".to_string(),
instructions: "Review code for bugs and best practices".to_string(),
allowed_tools: vec!["Read".to_string(), "Grep".to_string()],
max_turns: Some(5),
model: Some("claude-sonnet-4".to_string()),
};
executor.register(subagent)?;
// Execute the subagent
let output = executor.execute("code-reviewer", "Review this file").await?;
println!("Output: {:?}", output);
Ok(())
}Implementations§
Source§impl SubagentExecutor
impl SubagentExecutor
Sourcepub fn new(strategy: DelegationStrategy) -> Self
pub fn new(strategy: DelegationStrategy) -> Self
Sourcepub fn register(&mut self, subagent: Subagent) -> Result<(), SubagentError>
pub fn register(&mut self, subagent: Subagent) -> Result<(), SubagentError>
Register a subagent
§Arguments
subagent- The subagent to register
§Errors
Returns an error if a subagent with the same name already exists
§Example
let subagent = Subagent {
name: "my-agent".to_string(),
description: "Description".to_string(),
instructions: "Instructions".to_string(),
allowed_tools: vec![],
max_turns: Some(5),
model: None,
};
executor.register(subagent)?;Sourcepub async fn execute(
&self,
name: &str,
input: &str,
) -> Result<SubagentOutput, SubagentError>
pub async fn execute( &self, name: &str, input: &str, ) -> Result<SubagentOutput, SubagentError>
Sourcepub fn list_subagents(&self) -> Vec<String>
pub fn list_subagents(&self) -> Vec<String>
Sourcepub fn has_subagent(&self, name: &str) -> bool
pub fn has_subagent(&self, name: &str) -> bool
Sourcepub fn strategy(&self) -> &DelegationStrategy
pub fn strategy(&self) -> &DelegationStrategy
Auto Trait Implementations§
impl Freeze for SubagentExecutor
impl RefUnwindSafe for SubagentExecutor
impl Send for SubagentExecutor
impl Sync for SubagentExecutor
impl Unpin for SubagentExecutor
impl UnwindSafe for SubagentExecutor
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