How Dynamic Context Works
Expert Mode Dynamic Context lets you fetch customer data from your external APIs once, before each conversation starts. Instead of relying only on contact records, your agents can access account status, order history, support tickets, and business context from your customer relationship management (CRM) system, databases, and backend systems. You can also use custom API tools to fetch data during conversations.The platform calls the context API once before the conversation begins. The data is available for rendering the greeting and throughout the conversation. It does not refresh during the conversation. The hard request timeout is 30 seconds, but you should design the endpoint to return in under 1 second.
- HTTPS endpoint
- Valid JSON object, or an array of objects that can be merged
- Small response payload with only data needed for the conversation
- Fast response time; aim for under 1 second
- Authentication via Bearer token, Basic auth, custom header, or no auth
How It Works
Request Flow:Inbound calls
direction: "inbound" with caller’s contact_number. Look up customer data in your CRM.Outbound calls
direction: "outbound" with contact_number you’re calling. Fetch campaign context.Web widget
medium: "web" with optional external_id. Identify user in your system via the web widget.Configuration
Navigate to Dynamic Context
- Open your agent in the editor
- Click Call Flow
- In Before Call, open Dynamic Context
Configure Endpoint
This step is usually completed by a technical teammate.Endpoint URL:
https://api.company.com/contextAuthentication: Choose Bearer Token, Basic Auth, Custom Header, or NoneThe request will include: agent_uuid, direction, agent_number, contact_number (and external_id for web widget)Test
Save the Dynamic Context settings, then use Test to verify the saved endpoint and authentication respond correctly.
Request & Response Format
Request Payload (POST Request)
agent_uuid(string, always included) - The UUID of the agent handling the calldirection(string, always included) - “inbound” or “outbound”agent_number(string, optional) - The phone number the agent is usingcontact_number(string, optional) - The customer’s phone numberexternal_id(string/int, optional) - Only for web widget calls, if provided by your integration
X-Agent-UUID,X-Agent-Number,X-Contact-Number,X-Direction,X-Medium(phone/web)X-Room-SID- Unique identifier for this conversation sessionX-External-ID- For web widget calls only
Typical usage: Your endpoint uses
contact_number or external_id to look up the customer in your CRM/database, then returns relevant account data, order history, tickets, etc. The agent_uuid can be used to customize responses per agent if needed.What You Return (JSON Response)
- Valid JSON object, or an array of objects that can be merged
- Keep the response small and focused on fields the agent needs
- Return only necessary fields (keeps response fast)
- Handle missing data gracefully (return
nullor omit fields)
How variables are accessed: All top-level keys in your JSON response become template variables. If you return
{"account": {"tier": "VIP"}}, you access it as {{ account.tier }}, not {{ context.account.tier }}.Using Context Variables
All returned data from your API is available directly as top-level variables in your agent’s greeting and prompt. Accessing fields:Authentication
Bearer Token (Recommended)
Custom Header
Basic Auth
None
No authentication (only for internal/private networks).Example Use Case
Customer Support with Full Context Scenario: Support agent needs complete customer view before conversation starts. Your API returns:Best Practices
Keep responses fast
Keep responses fast
- Target under 1 second response time
- Cache frequently accessed data (5-10 minute TTL)
- Return only fields you’ll use in your prompt
- Use database indexes on lookup fields (contact_number, external_id, or your internal customer IDs)
Handle missing data gracefully
Handle missing data gracefully
- Use
| default("value")filters in your prompt - Return
nullfor missing fields (don’t error) - Test with contacts that have minimal data
Secure sensitive data
Secure sensitive data
- Don’t return SSN, credit cards, passwords
- Use HTTPS only
- Implement authentication (Bearer token recommended)
- Return only necessary fields (e.g., last 4 of account number, not full)
- Log access for audit trails
Test before production
Test before production
- Use Test with real customer data
- Test edge cases (new customer, VIP, suspended account)
- Verify your prompt handles missing fields gracefully
- Pilot with small traffic percentage before full rollout
Troubleshooting
401 Unauthorized
401 Unauthorized
Context variables empty
Context variables empty
- Use Test to verify the endpoint is responding
- Check JSON structure matches what you’re accessing
- Verify Dynamic Context toggle is ON
- Use
| default("fallback")for missing fields
Slow or timeout
Slow or timeout
- Add database indexes
- Implement caching
- Return only necessary fields
- Optimize database queries
- Check network latency to your API
Wrong data returned
Wrong data returned
- Check parameters in Test
- Verify template variables resolve correctly:
{{ account.tier }} - Ensure cache keys include customer identifier
- Test with known customer to confirm data matches
Next Steps
Greeting
Use context variables to personalize your agent’s greeting
Prompt
Use context variables in your prompt with Jinja templating
Template Syntax
Master templating syntax for dynamic prompts
Custom Action
Create tools that use context data during conversations