Tool Execution
BlackBox agents can call tools/functions during conversations to interact with external systems, query databases, perform actions, and retrieve real-time information. This guide covers handling tool execution requests via WebSocket.Overview
Tools enable agents to:- Query external APIs and databases
- Perform actions (create records, send emails, etc.)
- Retrieve real-time information
- Integrate with your business systems
- Webhook Tools: Agent calls webhook endpoint (traditional method)
- WebSocket Tools: Agent sends tool request via WebSocket (real-time)
When to Use WebSocket Tools: WebSocket tool execution should only be used when the tool needs to interact directly with the user or user’s application in the browser. Examples include:
- UI Interactions: Switching browser tabs, scrolling pages, clicking buttons
- Form Manipulation: Writing text in input fields, selecting dropdown options, checking checkboxes
- Browser Actions: Opening new windows, navigating to URLs, manipulating DOM elements
- Client-Side State: Accessing localStorage, sessionStorage, or browser APIs
Tool Execution Flow
Step 1: Configure Tools for WebSocket
Tools must be configured to use WebSocket execution:Via Web Integration Settings
In your web integration configuration, select tools that should use WebSocket:- Navigate to agent → Web Integrations
- Select your integration
- Go to Features tab
- Select tools from the dropdown Allowed Tools
- Selected tools will be called via WebSocket
Via API
When creating/updating web integration, specify tools intoolsViaWebsocket:
Step 2: Handle Tool Requests
HandlewebsocketToolRequest messages via WebSocket:
Manual WebSocket Implementation
HandlewebsocketToolRequest messages directly:
Step 3: Implement Tool Functions
Example: Customer Info Tool
Example: Support Ticket Tool
Example: Inventory Check Tool
Step 4: Complete Example
Here’s a complete React component handling tool execution:- React
- Node.js
Step 5: Error Handling
Handle tool execution errors gracefully:Step 6: Tool Result Format
Tool results should follow a consistent format:Success Response
Error Response
Example Responses
Best Practices
1. Validate Arguments
Always validate tool arguments before execution:2. Handle Timeouts
Set reasonable timeouts for tool execution:3. Log Tool Execution
Log tool calls for debugging and monitoring:4. Cache Results
Cache frequently accessed data:Troubleshooting
Tool Not Called
Symptoms: Agent doesn’t call expected tool Solutions:- Verify tool is configured in agent settings
- Check tool is selected in web integration
- Ensure tool name matches exactly
- Verify tool description helps agent understand when to use it
Tool Execution Fails
Symptoms: Tool called but returns error Solutions:- Check argument validation
- Verify API endpoints are accessible
- Check authentication/authorization
- Review error logs for details
- Test tool function independently
Slow Tool Execution
Symptoms: Long delays before agent responds Solutions:- Optimize tool implementation
- Add caching for frequent queries
- Set appropriate timeouts
- Consider async processing for long operations
- Use webhooks for slow tools instead
Next Steps
- Message Reference - Complete message documentation
- Error Handling - Robust error patterns
- Best Practices - Production patterns