Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
fix(call): better ai summary (#2973)
Will Hutchinson148a1d09d26f
diff --git a/rust/cloud-storage/call/src/domain/ports.rs b/rust/cloud-storage/call/src/domain/ports.rsindex 3fed141a02..f4a24a3fa6 100644--- a/rust/cloud-storage/call/src/domain/ports.rs+++ b/rust/cloud-storage/call/src/domain/ports.rs@@ -321,11 +321,17 @@ pub trait CallSummarizer: Send + Sync + 'static {/// supplied finalized `transcript` segments. The segments are expected/// to be ordered by `sequence_num` ascending (matching what is stored/// in a [`CallRecord`]).+ ///+ /// Returns `Ok(None)` when the transcript has no substantive content to+ /// summarize (empty, silence, fragmented/incoherent speech). Callers+ /// must treat `None` as "do not persist a summary" — writing a+ /// placeholder "transcript is uninformative" line is exactly the+ /// behavior this is meant to avoid.fn summarize_call(&self,call_id: &Uuid,transcript: Vec<CallRecordTranscriptSegment>,- ) -> impl Future<Output = Result<String, Self::Err>> + Send;+ ) -> impl Future<Output = Result<Option<String>, Self::Err>> + Send;/// Produce a short display name for the call from its already-generated/// summary. Used by the auto-name flow only when the call has nodiff --git a/rust/cloud-storage/call/src/domain/service.rs b/rust/cloud-storage/call/src/domain/service.rsindex ca49d22084..6c3cf35acf 100644--- a/rust/cloud-storage/call/src/domain/service.rs+++ b/rust/cloud-storage/call/src/domain/service.rs@@ -1030,11 +1030,18 @@ impl<return Ok(());}- let summary = summarizer+ let Some(summary) = summarizer.summarize_call(call_id, record.transcript).await.inspect_err(|e| tracing::error!(error=?e, %call_id, "call summarizer failed"))- .map_err(|e| CallError::Internal(e.into()))?;+ .map_err(|e| CallError::Internal(e.into()))?+ else {+ tracing::info!(+ %call_id,+ "summarizer returned no summary (uninformative transcript); skipping persistence"+ );+ return Ok(());+ };self.repo.insert_call_summary(call_id, &summary)@@ -1116,7 +1123,14 @@ impl<}let summary = match summarizer.summarize_call(&call_id, record.transcript).await {- Ok(summary) => summary,+ Ok(Some(summary)) => summary,+ Ok(None) => {+ tracing::info!(+ %call_id,+ "summarizer returned no summary (uninformative transcript); skipping persistence"+ );+ return;+ }Err(e) => {tracing::error!(error=?e, %call_id, "failed to summarize call on completion");return;@@ -1186,7 +1200,7 @@ impl CallSummarizer for NoopCallSummarizer {&self,_call_id: &Uuid,_transcript: Vec<CallRecordTranscriptSegment>,- ) -> Result<String, Self::Err> {+ ) -> Result<Option<String>, Self::Err> {// Type-placeholder only — [`CallServiceImpl`] must never invoke this// when `summarizer` is `None`, and [`NoopCallSummarizer`] is never a// `Some(_)` value in practice.diff --git a/rust/cloud-storage/call/src/outbound/ai_call_summarizer.rs b/rust/cloud-storage/call/src/outbound/ai_call_summarizer.rsindex dadbcdbca3..880678c499 100644--- a/rust/cloud-storage/call/src/outbound/ai_call_summarizer.rs+++ b/rust/cloud-storage/call/src/outbound/ai_call_summarizer.rs@@ -31,10 +31,23 @@ Rules:- Write in plain prose, using short paragraphs or bullet points where \appropriate. No markdown headings.- Do not speculate or invent content that is not in the transcript.-- If the transcript is empty or uninformative, say so briefly rather than \- fabricating content.+- Write directly about what was discussed in the call. Do NOT begin with a \+ meta-reference to the transcript or recording itself such as `This \+ transcript...`, `The transcript...`, `The call...`, `In this call...`, \+ `The recording...`, or similar — start with the actual content (a topic, \+ a decision, a participant).+- If the transcript is empty, contains only fragmented or incoherent speech, \+ or otherwise has no useful information to summarize, respond with exactly \+ the single token `NULL` and nothing else. Do not produce a summary that \+ merely states the transcript is uninformative — return `NULL` instead.- Respond with only the summary text — no preamble, no sign-off.";+/// Sentinel the model is asked to emit when the transcript has no useful+/// content to summarize. Mapped to `None` so the caller skips persisting a+/// summary at all (rather than writing a placeholder \"transcript is+/// uninformative\" line).+const NULL_SUMMARY_SENTINEL: &str = "NULL";+/// System prompt for naming a call from its summary. Kept tight so the model/// returns a bare title instead of a sentence.const CALL_NAME_SYSTEM_PROMPT: &str = "\@@ -102,7 +115,7 @@ impl CallSummarizer for AiCallSummarizer {&self,call_id: &Uuid,transcript: Vec<CallRecordTranscriptSegment>,- ) -> Result<String, Self::Err> {+ ) -> Result<Option<String>, Self::Err> {let user_message = format_transcript_prompt(call_id, &transcript);let request = RequestBuilder::new()@@ -111,12 +124,14 @@ impl CallSummarizer for AiCallSummarizer {.user_message(user_message).build();- get_chat_completion(request)+ let raw = get_chat_completion(request).await.map_err(|e| anyhow::anyhow!(e)).inspect_err(|e| {tracing::error!(error = ?e, %call_id, "ai call summarization failed");- })+ })?;++ Ok(parse_summary(&raw))}#[tracing::instrument(skip(self, summary), fields(summary_len = summary.len()), err)]@@ -162,6 +177,25 @@ impl CallSummarizer for AiCallSummarizer {#[cfg(test)]mod test;+/// Map a raw summary completion to `Some(text)` or `None`.+///+/// Trims whitespace and surrounding quotes/backticks. Returns `None` when+/// the model emitted [`NULL_SUMMARY_SENTINEL`] (case-insensitive, with or+/// without surrounding quotes/whitespace) or when sanitization left+/// nothing usable. The caller treats `None` as "do not persist a summary".+fn parse_summary(raw: &str) -> Option<String> {+ let trimmed = raw+ .trim()+ .trim_matches(|c: char| c == '"' || c == '\'' || c == '`')+ .trim();++ if trimmed.is_empty() || trimmed.eq_ignore_ascii_case(NULL_SUMMARY_SENTINEL) {+ return None;+ }++ Some(trimmed.to_string())+}+/// Trim quotes/whitespace, normalize internal whitespace, and clamp to/// [`CALL_NAME_MAX_CHARS`] at a word boundary. Returns `None` when the model/// emitted [`UNTITLED_CALL_SENTINEL`] or sanitization left nothing usable, so@@ -199,8 +233,8 @@ fn sanitize_call_name(raw: &str) -> Option<String> {fn format_transcript_prompt(call_id: &Uuid, transcript: &[CallRecordTranscriptSegment]) -> String {if transcript.is_empty() {return format!(- "Call {call_id} has no transcript segments. Produce a one-line \- summary noting that the call has no transcribed content."+ "Call {call_id} has no transcript segments. Per the system prompt, \+ respond with exactly the single token NULL.");}diff --git a/rust/cloud-storage/call/src/outbound/ai_call_summarizer/test.rs b/rust/cloud-storage/call/src/outbound/ai_call_summarizer/test.rsindex 05cdaccb4b..7169fe62f3 100644--- a/rust/cloud-storage/call/src/outbound/ai_call_summarizer/test.rs+++ b/rust/cloud-storage/call/src/outbound/ai_call_summarizer/test.rs@@ -1,4 +1,46 @@-use super::{CALL_NAME_MAX_CHARS, UNTITLED_CALL_SENTINEL, sanitize_call_name};+use super::{+ CALL_NAME_MAX_CHARS, NULL_SUMMARY_SENTINEL, UNTITLED_CALL_SENTINEL, parse_summary,+ sanitize_call_name,+};++#[test]+fn parse_summary_returns_none_for_null_sentinel() {+ assert_eq!(parse_summary(NULL_SUMMARY_SENTINEL), None);+ assert_eq!(parse_summary("null"), None);+ assert_eq!(parse_summary(" NULL "), None);+ assert_eq!(parse_summary("\"NULL\""), None);+ assert_eq!(parse_summary("`null`"), None);+}++#[test]+fn parse_summary_returns_none_for_empty_input() {+ assert_eq!(parse_summary(""), None);+ assert_eq!(parse_summary(" \n\t"), None);+ assert_eq!(parse_summary("\"\""), None);+}++#[test]+fn parse_summary_strips_surrounding_quotes_and_whitespace() {+ assert_eq!(+ parse_summary(" \"Alex and Priya reviewed Q3 spend.\" ").as_deref(),+ Some("Alex and Priya reviewed Q3 spend.")+ );+}++#[test]+fn parse_summary_preserves_real_summary_text() {+ let input = "Alex and Priya reviewed Q3 marketing spend and agreed to cut paid \+ search by 20% next quarter.";+ assert_eq!(parse_summary(input).as_deref(), Some(input));+}++#[test]+fn parse_summary_does_not_mistake_substring_for_sentinel() {+ // Real summary that happens to contain the word "null" — must not be+ // suppressed.+ let input = "Discussed handling of null fields in the API response.";+ assert_eq!(parse_summary(input).as_deref(), Some(input));+}#[test]fn sanitize_strips_quotes_and_whitespace() {