WebSocket Tools
This guide shows how to extend a basic WebSocket conversation to work with WebSocket tools.
While this guide runs through creating and using a sync WebSocket tool, the core workflow remains the same with async WebSocket tools.
Prerequisites
Before adding tools to your WebSocket conversation, you should have:
- A working WebSocket server that connects to Phonic (see Via WebSockets guide)
Tool Call Messages
When the agent makes a tool call, Phonic sends this message over the WebSocket:
Respond with a tool_call_output message:
WebSocket tools expose an Output timeout (tool_call_output_timeout_ms) — the maximum time to wait for the tool_call_output message. Default 5000 ms, between 1000 and 180000 ms.
Adding Tool Support
To handle tool calls in your existing WebSocket server, you need to:
- Listen for
tool_callmessages from Phonic - Process the tool call with your business logic
- Send back a
tool_call_outputmessage with the result
Step 1: Choose How to Provide Tools
You can provide WebSocket tools in two ways:
- Pre-defined WebSocket tools: create the tool once with the Tools API or Phonic UI, then reference it by name from an agent or conversation config. Use pre-defined WebSocket tools to avoid having to define the same tool across agents or conversations.
- Inline WebSocket tools: define the tool inline in the WebSocket
configmessage. Inline WebSocket tools are not persisted to your workspace. Use inline WebSocket tools when the parameters for the tool may change between conversations.
Inline tools are defined when you make the tool available (see Step 2). For a pre-defined tool, create it first with the Tools API or in the dashboard:
Step 2: Make the Tool Available
Pre-defined Tools
Add pre-defined tools to your agent’s configuration by name:
Inline WebSocket Tools
For inline WebSocket tools, pass the tool definition inline when you start the WebSocket conversation. The tool_schema follows OpenAI’s function tool shape.
Inline tools currently support type: "custom_websocket" only.
Step 3: Handle Tool Calls in Your WebSocket Server
Modify your existing WebSocket message handler to process tool_call messages: