Skip to main content

codetether_agent/agent/swarm/
handler_impl.rs

1//! Swarm message handling for agents.
2//!
3//! This module maps swarm task and tool messages onto the normal agent
4//! execution and tool-dispatch paths.
5//!
6//! # Examples
7//!
8//! ```ignore
9//! let reply = agent.handle(message).await?;
10//! ```
11
12use super::task_execution::unsupported_message_response;
13use crate::agent::Agent;
14use crate::swarm::{Handler, SwarmMessage};
15use anyhow::Result;
16use async_trait::async_trait;
17
18#[async_trait]
19impl Handler<SwarmMessage> for Agent {
20    type Response = SwarmMessage;
21
22    async fn handle(&mut self, message: SwarmMessage) -> Result<Self::Response> {
23        match message {
24            SwarmMessage::ExecuteTask {
25                task_id,
26                instruction,
27            } => self.handle_task_execution(task_id, instruction).await,
28            SwarmMessage::ToolRequest { tool_id, arguments } => {
29                self.handle_tool_request(tool_id, arguments).await
30            }
31            SwarmMessage::Progress { .. }
32            | SwarmMessage::TaskCompleted { .. }
33            | SwarmMessage::TaskFailed { .. }
34            | SwarmMessage::ToolResponse { .. } => Ok(unsupported_message_response()),
35        }
36    }
37}