pub struct MultiAgentRuntime { /* private fields */ }Expand description
Coordinates sub-agent lifecycle, event bridging, and cancellation.
Created once during builder setup and shared via Arc to all 6 multi-agent
tools. Each tool calls methods on the runtime to spawn, communicate with, or
close sub-agents.
Implementations§
Source§impl MultiAgentRuntime
impl MultiAgentRuntime
Sourcepub fn new(
config: MultiAgentConfig,
client: Arc<dyn LlmClient>,
business_tools: Vec<Arc<dyn Tool>>,
root_cancel: CancellationToken,
error_recovery: Option<Arc<dyn ToolErrorRecovery>>,
language: Language,
) -> Self
pub fn new( config: MultiAgentConfig, client: Arc<dyn LlmClient>, business_tools: Vec<Arc<dyn Tool>>, root_cancel: CancellationToken, error_recovery: Option<Arc<dyn ToolErrorRecovery>>, language: Language, ) -> Self
Create a new multi-agent runtime.
This is called internally by the builder. Tools receive an Arc<Self>.
Sourcepub fn set_event_sender(&self, tx: UnboundedSender<RuntimeEvent>)
pub fn set_event_sender(&self, tx: UnboundedSender<RuntimeEvent>)
Set the event sender for bridging child events to parent.
Called by the builder after creating the bridge channel.
Sourcepub async fn spawn_child(
&self,
name: &str,
system_prompt: String,
depth: i32,
tool_count: usize,
) -> Result<String, String>
pub async fn spawn_child( &self, name: &str, system_prompt: String, depth: i32, tool_count: usize, ) -> Result<String, String>
Spawn a child agent at the given path with a specific system prompt.
This is called by the spawn_agent tool. It:
- Checks spawn limits
- Registers the agent in the registry
- Creates a mailbox
- Builds a child AgentRuntime
- Spawns a tokio task for the child’s event loop
- Returns the AgentPath
§Errors
Returns a string error message if spawning fails (limits exceeded, etc.).
Sourcepub fn send_message(
&self,
agent_path: &str,
message: String,
) -> Result<bool, String>
pub fn send_message( &self, agent_path: &str, message: String, ) -> Result<bool, String>
Send a message to a child agent (no execution trigger).
Called by send_message tool.
Sourcepub fn send_task(
&self,
agent_path: &str,
task: String,
interrupt: bool,
) -> Result<bool, String>
pub fn send_task( &self, agent_path: &str, task: String, interrupt: bool, ) -> Result<bool, String>
Send a task to a child agent (triggers execution).
Called by followup_task tool. Updates status to Running.
Sourcepub async fn wait_for_result(
&self,
agent_path: Option<&str>,
timeout_ms: u64,
) -> WaitResult
pub async fn wait_for_result( &self, agent_path: Option<&str>, timeout_ms: u64, ) -> WaitResult
Wait for a result from any or a specific child agent.
Called by wait_agent tool. Blocks until a result arrives or timeout.
Sourcepub fn close_agent(&self, agent_path: &str) -> Result<CloseResult, String>
pub fn close_agent(&self, agent_path: &str) -> Result<CloseResult, String>
Close a child agent.
Called by close_agent tool. Cancels the child’s task, removes from
registry, and posts a Closed result.
Sourcepub fn list_agents(&self) -> Vec<AgentInfo>
pub fn list_agents(&self) -> Vec<AgentInfo>
List all active sub-agents.
Called by list_agents tool.
Sourcepub fn mailbox(&self) -> &Arc<MailboxHub> ⓘ
pub fn mailbox(&self) -> &Arc<MailboxHub> ⓘ
Get the mailbox hub (for tools that need it directly).
Sourcepub fn registry(&self) -> &Mutex<AgentRegistry>
pub fn registry(&self) -> &Mutex<AgentRegistry>
Get reference to the registry.
Sourcepub fn cancel_all(&self)
pub fn cancel_all(&self)
Cancel all child agents.