Using 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.
Full working examples in both Node and Python are available in the Phonic examples repository.
Prerequisites
Before adding tools to your WebSocket conversation, you should have:
- A working WebSocket server that connects to Phonic (see Via WebSockets guide)
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: Create Your Tools
First, create WebSocket tools that your agent can use:
Step 2: Create Your Agent
Add the tools to your agent’s configuration:
Step 3: Handle Tool Calls in Your WebSocket Server
Modify your existing WebSocket message handler to process tool_call messages:
See the complete examples in our examples repository.