use super::tools::{CommsToolState, PeersTool, SendTool};
use meerkat_comms::{Router, TrustedPeersView};
use std::sync::Arc;
pub struct CommsToolSet {
pub send: SendTool,
pub peers: PeersTool,
}
impl CommsToolSet {
pub fn new(router: Arc<Router>, trusted_peers: TrustedPeersView) -> Self {
let state = CommsToolState::new(router, trusted_peers);
Self {
send: SendTool::new(state.clone()),
peers: PeersTool::new(state),
}
}
pub fn tool_names(&self) -> Vec<&str> {
vec!["send", "peers"]
}
pub fn usage_instructions() -> &'static str {
r"## Inter-Agent Communication Tools
You have access to comms tools for communicating with other agents:
- `send`: Send a message, request, or response to a peer. Use `kind` to select the type.
- `peers`: List all visible peers.
When communicating with other agents, identify them by their peer name (not pubkey)."
}
}
#[cfg(test)]
#[allow(clippy::unwrap_used, clippy::expect_used)]
mod tests {
use super::*;
use meerkat_comms::{CommsConfig, Keypair};
#[test]
fn test_comms_tool_set_creation() {
let keypair = Keypair::generate();
let (_, inbox_sender) = meerkat_comms::Inbox::new();
let router = Arc::new(Router::new(
keypair,
CommsConfig::default(),
inbox_sender,
true,
));
let trusted_peers = router.trusted_peers_view();
let tool_set = CommsToolSet::new(router, trusted_peers);
assert_eq!(tool_set.tool_names().len(), 2);
}
}