Skip to main content
Update function code, debug errors, rotate credentials, and optimize performance.

Quick reference

I need to…Action
Update function codeEdit in Function Editor → Save → Test in Agent Chat
Debug a function errorAnalytics > Conversations → Diagnosis → check logs
Update API credentialsWorkspace homepage > Secrets tab → Edit → Save
Add loggingUse conv.log.info() in code
Fix function not triggeringReview KB action or rules → clarify description
Update API integrationConfigure > APIs → edit endpoint

Updating function code

  1. Go to Build > Tools and select the function
  2. Edit the Python code in the Function Editor
  3. Save, then test in Agent Chat
  4. Review logs in Conversation Review → Diagnosis
  5. 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

  1. Review Diagnosis logs for the failing function
  2. Reproduce the issue in Agent Chat
  3. Check function inputs — are parameters being passed correctly?
  4. Validate external APIs directly (Postman, curl)
  5. Review the function description — is it clear when the function should trigger?

Common errors

ErrorLikely causeFix
Function not triggeringUnclear description or KB actionSimplify description; clarify when to call it
Wrong parametersLLM misunderstandingImprove parameter names and descriptions
TimeoutSlow API or complex logicAdd delay controls; optimize code
Auth failuresExpired credentialsUpdate secrets
Import errorsMissing libraryCheck available libraries

Managing secrets

When API keys or credentials change:
  1. Go to the Secrets tab on the workspace homepage
  2. Find and edit the secret
  3. 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.

Optimizing performance

If functions are slow:
  1. Add delay controls with filler phrases (“Let me check that for you.”)
  2. Cache frequently-accessed data
  3. Reduce unnecessary API calls
  4. 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:
  1. Simplify the description — make it clear when to call the function
  2. Update KB actions — ensure topics reference the function correctly
  3. 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.”
Last modified on March 28, 2026