Agent P2P Module — Client Developer Documentation
Introduction
The Agent P2P Module enables decentralized, real-time communication between AI agents using WebSocket and HTTP. It supports direct messaging, API calls, file transfer, and remote task execution, making it ideal for distributed multi-agent coordination.
Registering P2P System in Subject Specification
{
"sub_system_id": "p2p-system-01",
"sub_system_type": "p2p-system",
"sub_system_config": {
"api_port": 6666,
"ws_host": "0.0.0.0",
"ws_port": 8766
}
}
Import and Setup
from agent_sdk.p2p import *
Usage Guide
Start P2P Servers
start_p2p_servers(
api_port=6666,
ws_host="0.0.0.0",
ws_port=8766,
max_threads=4,
handler_function=my_task_handler
)
Send & Receive Messages
p2p = P2PManager()
resp = p2p.send_recv("agent_123", {"type": "ping"})
print(resp)
Send API Request
data = {"task": "classify", "payload": {...}}
resp = p2p.send_api("agent_123", data)
Send File
file = P2PFile("image.jpg", open("image.jpg", "rb").read())
p2p.send_api("agent_123", {"meta": "image"}, files={"file": file.file})
Estimation API
estimator = AgentEstimator(base_url="http://agent_123.local:6666")
result = estimator.estimate(query={"task": "search", "keywords": ["AI"]})
Agent Chat Server — Client Developer Documentation
Introduction
The Agent Chat Server is a WebSocket-based real-time chat service for multi-user, session-specific communication. It supports message persistence via an optional cache backend and can broadcast messages to all connected clients in a session.
Registering Chat System in Subject Specification
{
"sub_system_id": "chat-server-01",
"sub_system_type": "chat-server",
"sub_system_config": {
"websocket_url": "ws://chat-server.default.svc.cluster.local:8765"
}
}
Import and Setup
from agents_sdk.chat import start_chat_server
from agents_sdk.chat.utils.chat import ChatManager
chat_manager = ChatManager()
start_chat_server(chat_manager, host="0.0.0.0", port=8765)
Usage Guide
Client Message Format
{
"session_id": "abc123",
"role": "user",
"content": "Hello!"
}
Broadcast from Server
chat_manager.send_message("abc123", "System broadcast message.")
Full Example
chat_manager = ChatManager()
start_chat_server(chat_manager)
chat_manager.send_message("abc123", "Welcome to the session!")