Conversation
🦋 Changeset detectedLatest commit: 908aab7 The changes in this PR will be included in the next version bump. Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
| const promptCtx = new ChatContext(); | ||
| promptCtx.addMessage({ | ||
| role: 'system', | ||
| content: | ||
| 'Compress older chat history into a short, faithful summary.\n' + | ||
| 'Focus on user goals, constraints, decisions, key facts/preferences/entities, and pending tasks.\n' + | ||
| 'Exclude chit-chat and greetings. Be concise.', | ||
| }); | ||
| promptCtx.addMessage({ | ||
| role: 'user', | ||
| content: `Conversation to summarize:\n\n${sourceText}`, | ||
| }); | ||
|
|
||
| const chunks: string[] = []; | ||
| for await (const chunk of llm.chat({ chatCtx: promptCtx })) { | ||
| if (chunk.delta?.content) { | ||
| chunks.push(chunk.delta.content); | ||
| } | ||
| } |
There was a problem hiding this comment.
We don't need it for now, but I also added a better way to call LLMs on Python
livekit/agents#4680
| } | ||
|
|
||
| if (it.type === 'message' && (it.role === 'user' || it.role === 'assistant')) { | ||
| continue; | ||
| } |
There was a problem hiding this comment.
🟡 _summarize unconditionally drops existing summary messages and non-text user/assistant messages
The filtering loop at lines 862-864 removes ALL ChatMessage items with role user or assistant, regardless of whether they were part of the summarized head or preserved tail. Only tail messages are re-inserted at line 881. This silently drops:
Detailed explanation of lost messages
-
Existing summary messages (
extra.is_summary === true): These are excluded fromtoSummarizeat line 789, so they're NOT inheadortail. But they ARE assistant messages, so they're removed at line 862 and never re-inserted. Their content is also NOT included insourceTextfor the new summary. -
User/assistant messages with only non-text content (e.g., images):
textContentreturnsundefinedfor these, so(item.textContent ?? '').trim()is empty, excluding them fromtoSummarize(line 792). They're removed at line 862 but never re-inserted.
Calling _summarize twice on the same context causes the first summary to be silently lost without its content being incorporated into the second summary. The fix should either preserve items with extra?.is_summary === true in the preserved array, or include them in the summarization input.
Impact: If _summarize is ever called more than once on the same ChatContext (e.g., incremental summarization), previously summarized information is permanently lost.
| } | |
| if (it.type === 'message' && (it.role === 'user' || it.role === 'assistant')) { | |
| continue; | |
| } | |
| if (it.type === 'message' && (it.role === 'user' || it.role === 'assistant') && it.extra?.is_summary !== true) { | |
| continue; | |
| } |
Was this helpful? React with 👍 or 👎 to provide feedback.
Add TaskGroup as well as it's dependent features:
ChatContext._summarizeagent.updateToolsToolFlags