agent_code_lib/tools/
send_message.rs1use async_trait::async_trait;
7use serde_json::json;
8
9use super::{Tool, ToolContext, ToolResult};
10use crate::error::ToolError;
11
12pub struct SendMessageTool;
13
14#[async_trait]
15impl Tool for SendMessageTool {
16 fn name(&self) -> &'static str {
17 "SendMessage"
18 }
19
20 fn description(&self) -> &'static str {
21 "Send a message to another running agent by ID or name. \
22 Used for inter-agent coordination in multi-agent workflows."
23 }
24
25 fn input_schema(&self) -> serde_json::Value {
26 json!({
27 "type": "object",
28 "required": ["to", "content"],
29 "properties": {
30 "to": {
31 "type": "string",
32 "description": "Target agent ID or name"
33 },
34 "content": {
35 "type": "string",
36 "description": "Message content to send"
37 }
38 }
39 })
40 }
41
42 fn is_read_only(&self) -> bool {
43 false
44 }
45
46 fn is_concurrency_safe(&self) -> bool {
47 true
48 }
49
50 async fn call(
51 &self,
52 input: serde_json::Value,
53 _ctx: &ToolContext,
54 ) -> Result<ToolResult, ToolError> {
55 let to = input
56 .get("to")
57 .and_then(|v| v.as_str())
58 .ok_or_else(|| ToolError::InvalidInput("'to' is required".into()))?;
59
60 let content = input
61 .get("content")
62 .and_then(|v| v.as_str())
63 .ok_or_else(|| ToolError::InvalidInput("'content' is required".into()))?;
64
65 Ok(ToolResult::success(format!(
69 "Message queued for agent '{to}': {content}"
70 )))
71 }
72}