- Real-time metrics are written during the call from your flow functions using
conv.write_metric. - Post-call AI extraction runs after the call ends. The full transcript is sent to an LLM via
conv.utils.prompt_llmso you can pull out fields that can only be determined by reviewing the whole conversation.
Layer 1: Real-time metrics
Inside your flow functions, write metrics at key moments using a single line of code:| Metric | When it fires |
|---|---|
APPOINTMENT_BOOKED | Caller confirms an appointment |
PAYMENT_PROCESSED | Payment completes on the call |
HANDOFF_BILLING | Caller is transferred to your billing team |
SMS_SENT | An SMS confirmation is sent during the call |
INSURANCE_VERIFIED | Insurance is confirmed on the call |
conv.write_metric() calls anywhere in your flow functions. See Metrics for naming conventions and how metric definitions affect Smart Analyst.
Layer 2: Post-call AI extraction
After the call ends, the platform can run the full transcript through an LLM to extract structured data that depends on the whole conversation – call reasons, sentiment, summaries, follow-up flags, and so on. You configure this in your End tool (end_function.py).
The pattern has three pieces: a dictionary of extraction queries, a helper function that builds the prompt and calls the LLM, and a call from end_function itself.
Define what you want to extract
Define each field as a key with a plain-English instruction. The key becomes the metric name; the value tells the LLM what to look for.
Build the prompt and call the LLM
Format the transcript from
conv.history, embed the queries, and call conv.utils.prompt_llm with return_json=True so the response is parsed into a dict.prompt_llm requires activation on your account. If you receive a NotImplementedError, contact your PolyAI representative to enable it.Call it from end_function
Run the extraction from Writing each extracted field back with
end_function, alongside any real-time metrics that depend on final call state.conv.write_metric is what makes the extracted values available in dashboards, Smart Analyst, and API exports alongside your real-time metrics.Example queries
| Query | What it extracts |
|---|---|
CALL_SUMMARY | One-line summary, e.g. “Patient called to reschedule a cleaning, booked for June 18th” |
CALL_REASON | Categorized reason for the call |
RESOLUTION | yes / no / partial |
SENTIMENT | positive / neutral / frustrated |
FOLLOW_UP_NEEDED | Free-text note, e.g. “Patient asked about a referral to an oral surgeon – needs callback” |
NO_SHOW_RISK | Free-text note, e.g. “Patient mentioned they might not make it depending on work schedule” |
ESCALATION_COUNT | Number of times the caller asked for a human |
When to use each layer
Use real-time metrics when the outcome is known at a specific point in the call – a function succeeded, a booking was confirmed, a handoff happened. Use post-call extraction when the answer depends on the full transcript – sentiment, summaries, categorized reasons, or counts that span the whole conversation. For each extraction query you plan to expose in dashboards, register a matching metric and write the result back withconv.write_metric. This keeps real-time and post-call data in a single, queryable column per conversation.
Where the data goes
Both real-time metrics and post-call extractions land in the same surfaces:| Surface | What it does |
|---|---|
| Dashboards | Visual analytics in Agent Studio – call volumes, outcomes, trends |
| Smart Analyst | Built-in AI analyst. Ask “What are the top reasons callers request a human this week?” and get answers linked to actual conversations |
| Conversations API | Programmatic export of transcripts and structured data to your BI tools, data warehouse, or CRM |
- “How many callers mentioned insurance concerns this month?”
- “What percentage of calls resulted in a booked appointment?”
- “Show me all calls where follow-up was flagged.”
End-to-end flow
Your agent handles a call → real-time metrics fire during the call → the call ends → post-call extraction runs automatically → all data lands in dashboards, Smart Analyst, and the Conversations API.Related pages
Metrics
Define the custom metrics that hold your reporting data.
End tool
Run post-call processing asynchronously after every conversation.
prompt_llm
Standalone LLM call used by the extraction pattern.
Smart Analyst
Natural-language queries over your metrics and transcripts.
Conversations API
Export metrics and transcripts to external systems.
Dashboards
Visualize metric trends and outcomes.

