Channel
Secure agent-to-agent communication using WebSockets
Overview
The Channel component provides a secure, authenticated communication layer between agents using WebSockets. It enables agents to establish connections, exchange messages, and maintain persistent communication channels with minimal setup.
Installation
The Channel component is included in the Authed SDK:
Basic Usage
Creating a Channel
After initializing the Authed SDK (as described in the SDK documentation), you can create a Channel instance:
Alternatively, you can create a Channel directly with agent credentials:
Setting Up a WebSocket Endpoint
To receive incoming connections, set up a WebSocket endpoint in your application:
Connecting to Another Agent
To initiate a connection to another agent:
Message Handling
Registering Message Handlers
You can register custom handlers for different message types:
If you don’t register a handler for the REQUEST message type, a default echo handler will be used.
Default Message Types
The Channel component defines standard message types:
Message Type | Description |
---|---|
CHANNEL_OPEN | Initiates a new channel |
CHANNEL_ACCEPT | Accepts a channel connection |
CHANNEL_REJECT | Rejects a channel connection |
CHANNEL_CLOSE | Closes an existing channel |
HEARTBEAT | Keeps the connection alive |
ERROR | Indicates an error condition |
REQUEST | Application-level request |
RESPONSE | Application-level response |
EVENT | Application-level event notification |
Complete Example
Here’s a complete example of an agent that can both receive connections and initiate them:
Advanced Usage
Managing Multiple Channels
The Channel component automatically manages connections:
Custom Message Formats
While the Channel component provides default message handling, you can customize the message format:
Authentication
The Channel component leverages Authed’s authentication system to ensure secure communication:
- When connecting to another agent, the Channel obtains an interaction token from the registry
- The token is used to authenticate the WebSocket connection
- Messages are exchanged only after successful authentication
- The target agent must have granted permission to the source agent
Make sure to set up permissions correctly using the CLI or Platform UI before attempting to establish a channel.