Send Message Tool¶
The SendMessageTool facilitates communication between agents in the Bedrock Swarm framework. It provides a standardized way to send and receive messages between agents, with support for different message types and delivery options.
Class Documentation¶
Bases: BaseTool
Tool for sending messages between agents.
| PARAMETER | DESCRIPTION |
|---|---|
valid_recipients
|
Optional list of valid recipient names
TYPE:
|
description
|
Optional tool description
TYPE:
|
agency
|
Optional reference to the agency
TYPE:
|
Source code in src/bedrock_swarm/tools/send_message.py
Attributes¶
name: str
property
¶
Get tool name.
description: str
property
¶
Get tool description.
Functions¶
get_schema() -> Dict[str, Any]
¶
Get JSON schema for the send message tool.
Source code in src/bedrock_swarm/tools/send_message.py
_execute_impl(*, recipient: str, message: str, **kwargs: Any) -> str
¶
Execute the send message tool.
| PARAMETER | DESCRIPTION |
|---|---|
recipient
|
Name of the recipient agent
TYPE:
|
message
|
Message to send
TYPE:
|
**kwargs
|
Additional keyword arguments
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
Response from the recipient agent |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If recipient is not valid |
Source code in src/bedrock_swarm/tools/send_message.py
Features¶
The send message tool supports:
- Message Types:
- Text messages
- Structured data
- Binary content
-
Event notifications
-
Delivery Options:
- Synchronous sending
- Asynchronous delivery
- Broadcast messages
-
Direct messages
-
Message Properties:
- Priority levels
- Delivery status
- Message metadata
- Timestamps
Usage Examples¶
from bedrock_swarm.tools import SendMessageTool
message_tool = SendMessageTool()
# Send a simple message
await message_tool.send(
recipient="agent_id",
content="Hello, how are you?",
priority="normal"
)
# Send structured data
data = {
"type": "task_update",
"status": "completed",
"timestamp": "2024-02-29T15:30:45Z"
}
await message_tool.send(
recipient="agent_id",
content=data,
priority="high"
)
# Broadcast message
await message_tool.broadcast(
content="System maintenance in 5 minutes",
priority="high"
)
Error Handling¶
The send message tool handles:
- Invalid recipients
- Message delivery failures
- Network errors
- Invalid message formats
- Timeout conditions
Implementation Details¶
The tool implementation includes:
- Message queuing system
- Delivery confirmation
- Retry mechanisms
- Priority handling
- Error recovery
Message Format¶
Messages follow this structure: