use crate::agent::Agent;
use crate::session::Session;
use crate::swarm::SwarmMessage;
use anyhow::Result;
impl Agent {
pub(super) async fn handle_task_execution(
&mut self,
task_id: String,
instruction: String,
) -> Result<SwarmMessage> {
let mut session = Session::new().await?;
Ok(match self.execute(&mut session, &instruction).await {
Ok(response) => SwarmMessage::TaskCompleted {
task_id,
result: response.text,
},
Err(error) => SwarmMessage::TaskFailed {
task_id,
error: error.to_string(),
},
})
}
pub(super) async fn handle_tool_request(
&self,
tool_id: String,
arguments: serde_json::Value,
) -> Result<SwarmMessage> {
let result = self.execute_tool_value(&tool_id, arguments).await;
Ok(SwarmMessage::ToolResponse { tool_id, result })
}
}
pub(super) fn unsupported_message_response() -> SwarmMessage {
SwarmMessage::TaskFailed {
task_id: "unknown".to_string(),
error: "Unsupported message type".to_string(),
}
}