Herring
03/11/2025, 2:14 AMVapi Support Bot
03/11/2025, 2:16 AMjavascript
vapi.on('message', (message) => {
// Check if this is a tool call message
if (message.type === 'conversation-update' && message.role === 'tools_calls') {
// Extract the arguments from the function
const toolCall = message.content;
const argumentsStr = toolCall.function.arguments;
try {
// Parse the arguments
const parsedArgs = JSON.parse(argumentsStr);
// Now you have the arguments as provided to the tool call
console.log('Tool call arguments:', parsedArgs);
} catch (err) {
console.error("Failed to parse arguments:", err);
}
}
});
Note that there's a [known discrepancy in message types](https://discord.com/channels/1211482211119796234/1211483291191083018/1328825176783065128) - you might receive conversation-update
messages with roles tools_calls
and tool_call_result
instead of the expected tool-calls
and tool-call-result
.
### Best Practices for Maintaining Argument Integrity
1. **Break Down Complex Workflows**: Segment complex automations into smaller, focused workflows for better integrity and easier debugging.
2. **Use Clear Naming Conventions**: This helps with traceability and understanding of workflows.
3. **Proper Error Handling**: Always include robust error handling when parsing arguments:
javascript
let parsedArgs = {};
try {
parsedArgs = JSON.parse(argumentsStr);
} catch (err) {
console.error("Failed to parse arguments:", err);
}
Vapi Support Bot
03/11/2025, 2:16 AMKyle Brunker
03/12/2025, 6:56 PM