Sends a message to a specific agent.
Target agent identifier
Message to send (without routing fields)
Delivery status
await bus.sendToAgent('researcher-gmi', {
type: 'question',
content: 'What did you find about topic X?',
priority: 'normal',
});
Sends a message to an agent by role. If multiple agents have the role, uses load balancing.
Agency context
Target role identifier
Message to send
Delivery status
Broadcasts a message to all agents in an agency.
Target agency
Message to broadcast
Array of delivery statuses
await bus.broadcast('agency-123', {
type: 'broadcast',
content: 'Meeting in 5 minutes',
priority: 'high',
});
Broadcasts to specific roles within an agency.
Target agency
Target roles
Message to broadcast
Array of delivery statuses
Sends a request and waits for a response. Implements request-response pattern over async messaging.
Target agent
Request message
Response from target agent
const response = await bus.requestResponse('expert-gmi', {
type: 'question',
content: 'What is the optimal approach?',
fromAgentId: 'coordinator-gmi',
timeoutMs: 30000,
});
if (response.status === 'success') {
console.log('Answer:', response.content);
}
Initiates a structured handoff between agents. Used for transferring task ownership with full context.
Current owner
New owner
Handoff context
Handoff result
const result = await bus.handoff('analyst-gmi', 'reviewer-gmi', {
taskId: 'analysis-task-1',
taskDescription: 'Data analysis for Q4 report',
progress: 0.8,
completedWork: ['Data collection', 'Initial analysis'],
remainingWork: ['Final review', 'Report generation'],
context: { findings: [...] },
reason: 'completion',
});
Subscribes an agent to receive messages.
Agent to subscribe
Message handler function
Optional options: SubscriptionOptionsSubscription filter options
Unsubscribe function
const unsub = bus.subscribe('worker-gmi', async (msg) => {
console.log('Received:', msg.type, msg.content);
}, {
messageTypes: ['task_delegation', 'question'],
minPriority: 'normal',
});
// Later: unsub();
Publishes a message to a topic.
Topic identifier
Message to publish
Delivery statuses for all subscribers
Retries delivery of a failed message.
Each call counts one retry, which the returned status carries in
retryCount. Once RoutingConfig.maxRetries retries have been made, the
call throws without sending.
Message to retry
New delivery status
Gets message history for an agent.
Agent identifier
Optional options: { Query options
Optional limit?: numberOptional since?: DateOptional types?: AgentMessageType[]Optional direction?: "sent" | "received" | "both"Message history
Interface for the AgentOS Agent Communication Bus.
The Communication Bus enables structured messaging between agents within an agency, supporting various communication patterns:
Example