Overview
WebSocket connections enable real-time, bidirectional communication with your AI agents. This connection type is ideal for chat-based agents, real-time assistants, or any application that requires persistent, low-latency message exchange. When you connect a WebSocket agent, Coval establishes a secure connection to your endpoint and handles the full conversation flow—sending messages, receiving responses, and evaluating performance.Configuration Requirements
WebSocket Endpoint
- Field:
endpoint - Type: String (required)
- Purpose: The WebSocket URL that Coval connects to for simulations
- Format: Must start with
wss://(secure WebSocket) - Example:
wss://your-api.com/ws/chat
Initialization JSON
- Field:
initialization_json - Type: JSON object (optional)
- Purpose: Initial payload sent to your WebSocket endpoint when the connection is established
- Format: Valid JSON object
- Use Cases: Session initialization, authentication handshakes, context setup
The initialization JSON is sent immediately after the WebSocket connection is established. Use this to configure your agent’s behavior or authenticate the session.
Authorization Header
- Field:
authorization_header - Type: String (optional)
- Purpose: Authentication value sent in the
Authorizationheader during the WebSocket handshake - Format: Standard authorization header value
- Security: Stored encrypted and handled securely
- Bearer token:
Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9... - API key:
X-API-Key your-api-key-here - Basic auth:
Basic base64-encoded-credentials
Custom Headers
- Field:
custom_headers - Type: JSON object (optional)
- Purpose: Additional HTTP headers sent during the WebSocket handshake
- Format: Valid JSON object with string key-value pairs
- Use Cases: Custom authentication, routing headers, client identification
Setup Instructions
-
Prepare your WebSocket endpoint
- Ensure your endpoint accepts secure WebSocket connections (
wss://) - Configure your server to handle the authorization header if authentication is required
- Set up message handling for the conversation flow
- Ensure your endpoint accepts secure WebSocket connections (
-
Create the agent in Coval
- Navigate to app.coval.dev/agents/create
- Select WebSocket as the connection type
- Enter your WebSocket endpoint URL (must start with
wss://) - Add authorization header if your endpoint requires authentication
- Configure initialization JSON if you need to send a setup payload
- Add any custom headers required by your endpoint
-
Test the connection
- Create a simple test set with a few scenarios
- Launch a simulation to verify end-to-end connectivity
- Check that messages are being sent and received correctly
How Simulations Work
When you launch a simulation with a WebSocket agent, Coval:- Establishes the connection — Opens a secure WebSocket connection to your endpoint with the configured headers
- Sends initialization payload — If configured, sends the initialization JSON immediately after connection
- Starts the conversation — Sends the first message based on your test case configuration
- Exchanges messages — Receives agent responses and sends follow-up messages according to the persona behavior
- Records the transcript — Captures the full conversation for evaluation
- Runs metrics — Evaluates the conversation against your configured metrics
- Closes the connection — Cleanly terminates the WebSocket connection
Message Format
Coval sends and expects messages in JSON format with acontent field containing the message text:
Outgoing message (Coval → Your Agent):
Your WebSocket endpoint should respond with JSON messages containing a
content field. Coval extracts this field to build the conversation transcript.Technical Requirements
Endpoint Requirements
| Requirement | Details |
|---|---|
| Protocol | wss:// (TLS-encrypted WebSocket) |
| Accessibility | Must be publicly accessible from Coval servers |
| Response format | JSON with content field |
| Connection timeout | Connections may be held open for the duration of the simulation |
Running Locally
If your WebSocket server is running locally, you’ll need to expose it publicly for Coval to connect. Use a tunneling service like ngrok:Troubleshooting
Connection Failures
“Invalid WebSocket URL” error- Verify your endpoint starts with
wss://(notws://,http://, orhttps://) - Check that the URL is properly formatted with no trailing spaces
- Ensure your WebSocket server is running and accessible
- Check firewall rules allow inbound connections on the WebSocket port
- Verify the endpoint URL is correct
- Confirm your authorization header value is correct
- Check that the header format matches what your server expects
- Verify the API key or token hasn’t expired
Message Handling Issues
“No response received” error- Ensure your agent sends responses in JSON format with a
contentfield - Check that your agent is processing and responding to incoming messages
- Verify there are no errors in your agent’s logs
- Confirm your agent returns valid JSON
- Check for proper encoding of special characters
- Ensure the
contentfield is a string
Timeout Issues
Simulation timeouts- Verify your agent responds within a reasonable time (< 30 seconds per message)
- Check for any blocking operations in your agent’s message handler
- Monitor your agent’s resource usage during simulations
Best Practices
- Use persistent connections — WebSocket agents should maintain the connection throughout the conversation
- Handle reconnection gracefully — If your agent supports it, configure automatic reconnection
- Log initialization payloads — Track the initialization JSON in your server logs for debugging
- Implement health checks — Add a ping/pong mechanism to detect connection issues early
- Secure your endpoint — Always use
wss://and implement proper authentication

