This page requires Python familiarity. The end function is written in Python and runs after every call.
conv.state during the call is fully available in the end function. This is the core mechanism that makes it useful: any data your functions collected or computed mid-call can be read, transformed, and sent to external systems after the conversation is over.
Key features and functionality
- Asynchronous execution: Runs after the conversation ends, so it does not delay the call.
- Post-conversation data handling: Captures and processes important details from the conversation for reporting, logging, or integration.
- External integrations: Call APIs, create tickets, or trigger follow-up workflows from the end function.
Use cases
The End function:1. Generates a structured call summary
The most common end function pattern is generating a structured summary fromconv.state at the end of the conversation. This is especially valuable for voice agents where human agents need a written record of what was discussed.
- Example use case: Compile caller intent, topics discussed, and resolution status into a summary and push it to your CRM or ticketing system.
2. Logs conversation metadata
- Save key conversation details, such as duration, topic, or sentiment analysis, to a database or CRM.
- Example use case: Track customer service interactions for reporting and performance analysis.
3. Triggers workflows
- Start processes like creating support tickets, sending confirmation emails, or updating account records.
- Example use case: Automatically notify the sales team about potential leads from the conversation.
4. Schedules follow-ups
- Prepare reminders, SMS notifications, or callbacks for unresolved queries.
- Example use case: Send a confirmation SMS after booking an appointment or a callback request.
5. Logs outbound call dispositions
The end function is not limited to inbound voice. Outbound agents use it to log call dispositions, update lead records, and trigger follow-up sequences after each call.- Example use case: After an outbound sales call, update the lead status in your CRM and queue a follow-up email if the prospect requested more information.
Implementation example
Below is a Python implementation of the End function:The end function’s return value is not used by the runtime. You do not need to return anything.
Best practices for end function design
-
Efficient execution:
- Design the function to complete quickly. Parallelize independent API calls where possible, avoid unnecessary data fetching, and keep heavy computation outside the critical path.
-
Error handling:
- Wrap your end function body in a
try/exceptblock and log errors to an external monitoring service. Without this, failures are completely invisible.
- Wrap your end function body in a
-
Data consistency:
- Validate and sanitize data collected during the conversation before processing or logging it.
-
Relevance:
- Include only necessary post-conversation tasks to maintain efficiency and focus.
Examples: Enhancing post-conversation workflows
Data logging for analytics
Capture details like customer sentiment, topics discussed, and the resolution status for reporting and analytics. Example:- “Logged: Customer expressed interest in our premium plan and showed positive sentiment.”
Automatic follow-ups
Send reminders, confirmation messages, or escalation notices to keep the customer informed. Example:- “An email has been sent confirming your booking for January 10th.”
Task automation
Streamline processes by triggering external workflows or integrations. Example:- “Support ticket created: Issue with account login noted during the conversation.”

