Update function code, debug errors, rotate credentials, and optimize performance.
Quick reference
| I need to… | Action |
|---|
| Update function code | Edit in Function Editor → Save → Test in Agent Chat |
| Debug a function error | Analytics > Conversations → Diagnosis → check logs |
| Update API credentials | Workspace homepage > Secrets tab → Edit → Save |
| Add logging | Use conv.log.info() in code |
| Fix function not triggering | Review KB action or rules → clarify description |
| Update API integration | Configure > APIs → edit endpoint |
Updating function code
- Go to Build > Tools and select the function
- Edit the Python code in the Function Editor
- Save, then test in Agent Chat
- Review logs in Conversation Review → Diagnosis
- Publish when satisfied
Always test function changes in Sandbox before promoting to Live.
Example: updating an API endpoint
def book_reservation(date, time, party_size, special_requests=None):
conv.log.info(f"Booking for {party_size} guests on {date} at {time}")
response = requests.post(
"https://api.example.com/v2/bookings",
json={"date": date, "time": time, "guests": party_size,
"special_requests": special_requests or ""},
headers={"Authorization": f"Bearer {conv.utils.get_secret('booking_api_key')}"}
)
if response.status_code == 200:
conv.log.info("Booking successful")
return {"utterance": "Your reservation is confirmed."}
else:
conv.log.error(f"Booking failed: {response.text}")
return {"utterance": "I'm having trouble completing your reservation. Let me transfer you to someone who can help."}
Debugging
Using conv.log
conv.log.info("Starting payment processing") # general flow
conv.log.warning("Customer account has low balance") # potential issues
conv.log.error(f"Payment API returned: {error}") # failures
conv.log.info("Processing order", pii=True) # sensitive data
Logs appear in Conversation Review → Diagnosis, Agent Chat (during testing), and the Conversations API.
Common debugging steps
- Review Diagnosis logs for the failing function
- Reproduce the issue in Agent Chat
- Check function inputs — are parameters being passed correctly?
- Validate external APIs directly (Postman, curl)
- Review the function description — is it clear when the function should trigger?
Common errors
| Error | Likely cause | Fix |
|---|
| Function not triggering | Unclear description or KB action | Simplify description; clarify when to call it |
| Wrong parameters | LLM misunderstanding | Improve parameter names and descriptions |
| Timeout | Slow API or complex logic | Add delay controls; optimize code |
| Auth failures | Expired credentials | Update secrets |
| Import errors | Missing library | Check available libraries |
Managing secrets
When API keys or credentials change:
- Go to the Secrets tab on the workspace homepage
- Find and edit the secret
- Save, then test all functions using it
api_key = conv.utils.get_secret("my_api_key")
headers = {"Authorization": f"Bearer {api_key}"}
- Rotate credentials every 90 days
- Use descriptive names (
stripe_live_api_key, not key1)
- Test all dependent functions after rotation
Managing API integrations
Configure per-environment endpoints in Configure > APIs:
- Sandbox — test/staging endpoints
- Pre-release — UAT endpoints
- Live — production endpoints
This ensures you don’t call production APIs during testing.
If functions are slow:
- Add delay controls with filler phrases (“Let me check that for you.”)
- Cache frequently-accessed data
- Reduce unnecessary API calls
- Simplify logic and remove unnecessary processing
You can reference state variables in delay responses using $. For example: Still checking availability at $branch_name...
Improving function triggering
If the agent isn’t calling your function when expected:
- Simplify the description — make it clear when to call the function
- Update KB actions — ensure topics reference the function correctly
- Check for conflicts — ensure other functions aren’t being called instead
Bad description: “Handles reservations”
Good description: “Call this function when the user wants to book a table. Required: date, time, party_size. Only call after confirming all three with the user.”
Related pages