Overview
Pre-call functions execute before your AI agent starts a call. They allow you to customize the system prompt and update call metadata based on external data. Common Use Cases:- Fetch user preferences from database
- Customize greeting based on language
- Load context from CRM
- Set dynamic variables in system prompt
Execution Timing
Basic Mode
Configure API integrations without writing code.
Configuration Fields
| Field | Required | Description |
|---|---|---|
| Name | Yes | Function name (no spaces) |
| API URL | Yes | Endpoint to call |
| Method | Yes | GET, POST, PUT, or DELETE |
| Headers | No | Authentication and custom headers |
| Parameters | No | Query or body parameters |
Example: Fetch User Language
API URL:https://api.example.com/users/{user_id}/preferences
Method: GET
Headers:
Advanced Mode (Python)
Write custom Python code for complex logic.
Function Signature
- Must be
async def - Takes exactly 2 parameters:
metadataandsystem_prompt - Must return the updated
system_promptstring - Can modify existing metadata keys only (cannot add new keys)
Metadata Rules
Allowed:System Prompt Updates
Replace placeholders in the system prompt with actual values:Example: Load Language Preferences
AI Generation
Click “Generate with AI” to create functions using natural language. Example Prompt:Allowed Operations
- Allowed ✅
- Forbidden ❌
- HTTP calls with
httpx.AsyncClient - JSON parsing
- String manipulation
- Environment variables
- Logging
Best Practices
- Timeout API calls - Always set timeouts (5-10 seconds)
- Handle errors gracefully - Don’t break the call if API fails
- Use existing keys - Only modify metadata keys that already exist
- Keep it fast - Pre-call functions delay call start
- Log important events - Use logger for debugging