onSummary

View as MarkdownOpen in Claude

Lifecycle hook invoked when a post-prompt summary is received after a conversation ends. Override this method in a subclass to process summaries — for example, saving them to a CRM, triggering follow-up workflows, or logging call outcomes.

A post-prompt must be configured via setPostPrompt() for summaries to be generated.

The default implementation does nothing. You must override it in a subclass or set a setPostPromptUrl() to receive summaries at an external endpoint.

Parameters

summary
Record<string, unknown> | nullRequired

The summary object generated by the AI based on your post-prompt instructions. null if no summary could be extracted from the response.

rawData
Record<string, unknown>Required

The complete raw POST data from the post-prompt request, including metadata like call_id and the full AI response.

Returns

void | Promise<void>

Example

1import { AgentBase } from '@signalwire/sdk';
2
3class SupportAgent extends AgentBase {
4 constructor() {
5 super({ name: 'support', route: '/support' });
6 this.setPromptText('You are a helpful customer support agent.');
7 this.setPostPrompt(`
8 Summarize this call as JSON:
9 - intent: caller's primary intent
10 - resolved: yes/no/partial
11 - sentiment: positive/neutral/negative
12 `);
13 }
14
15 override async onSummary(
16 summary: Record<string, unknown> | null,
17 rawData: Record<string, unknown>,
18 ): Promise<void> {
19 if (summary) {
20 const callId = (rawData.call_id as string) ?? 'unknown';
21 console.log(`Call ${callId} summary:`, summary);
22 // await saveToDatabase(callId, summary);
23 }
24 }
25}
26
27const agent = new SupportAgent();
28await agent.serve();