📡 fix: Stream Compaction Summaries as They Are Written (#18174)

* 🧽 fix: Replace an Abandoned Summary Attempt's Text When Its Retry Streams

Summary deltas append to the in-flight summary part. Once the agents SDK
streams them while the provider is still responding, an attempt that is
then abandoned (a retry, a fallback provider) has already put text in the
part, and the next attempt's deltas would follow it until the completion
event replaced the lot.

A delta may now carry `reset`: the part's content is replaced instead of
extended, and a reset with no content empties it. The part keeps its slot
and stays in flight. Deltas without the field behave as before, so this
is inert until the SDK sends it.

* 🦿 chore: Bump Agents SDK to 4.2.3

4.2.3 dispatches each summary delta while the provider is still responding
and marks the first delta after an abandoned attempt `reset`, which the
chat reducer now honors. It also stops sending reasoning as summary text,
which is where the `incoming.content is not iterable` handler errors
during compaction came from.

The release changed only the SDK's own dev dependencies and overrides, so
the lockfile moves the package's version, URL and integrity and nothing
else.
This commit is contained in:
Danny Avila 2026-11-15 08:53:22 -05:00 • committed by GitHub
parent 08f9d7f7e0
commit c83336c7bf
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 60 additions and 11 deletions

View file

@ -40,7 +40,7 @@
"@azure/storage-blob": "^12.30.0",
"@google/genai": "^2.8.0",
"@keyv/redis": "5.1.6",
"@librechat/agents": "^4.2.2",
"@librechat/agents": "^4.2.3",
"@librechat/api": "*",
"@librechat/data-schemas": "*",
"@microsoft/microsoft-graph-client": "^3.0.7",

10
package-lock.json generated
View file

@ -70,7 +70,7 @@
"@azure/storage-blob": "^12.30.0",
"@google/genai": "^2.8.0",
"@keyv/redis": "5.1.6",
"@librechat/agents": "^4.2.2",
"@librechat/agents": "^4.2.3",
"@librechat/api": "*",
"@librechat/data-schemas": "*",
"@microsoft/microsoft-graph-client": "^3.0.7",
@ -9479,9 +9479,9 @@
}
},
"node_modules/@librechat/agents": {
"version": "4.2.2",
"resolved": "https://registry.npmjs.org/@librechat/agents/-/agents-4.2.2.tgz",
"integrity": "sha512-Yx248RpKQo0UAGNpPny5Y5anmYVXTbg5UhGJXeeYdxX7wKn+cBvM691jCWPTBWgps5D0Q4p5gj0T4Y2kyUTksw==",
"version": "4.2.3",
"resolved": "https://registry.npmjs.org/@librechat/agents/-/agents-4.2.3.tgz",
"integrity": "sha512-nLZlff0YAXi26a1P9V5ydSEEjKsyMZi0WtEW2fo0xBipDvK9n5uvFExU9WK5z6YinLzJD6MY7gcpl2wQYh69Uw==",
"license": "MIT",
"dependencies": {
"@anthropic-ai/sdk": "^0.115.0",
@ -42444,7 +42444,7 @@
"@azure/identity": "^4.14.0",
"@azure/storage-blob": "^12.30.0",
"@keyv/redis": "5.1.6",
"@librechat/agents": "^4.2.2",
"@librechat/agents": "^4.2.3",
"@librechat/data-schemas": "*",
"@modelcontextprotocol/sdk": "^1.32.1",
"@opentelemetry/api": "^1.9.0",

View file

@ -120,7 +120,7 @@
"@azure/identity": "^4.14.0",
"@azure/storage-blob": "^12.30.0",
"@keyv/redis": "5.1.6",
"@librechat/agents": "^4.2.2",
"@librechat/agents": "^4.2.3",
"@librechat/data-schemas": "*",
"@modelcontextprotocol/sdk": "^1.32.1",
"@opentelemetry/api": "^1.9.0",

View file

@ -906,6 +906,42 @@ describe('steps', () => {
).toBeUndefined();
});
it('replaces what an abandoned attempt streamed when a delta is marked reset', () => {
const text = (message: TMessage) =>
((message.content?.[1] as SummaryContentPart).content ?? [])
.map((block) => ('text' in block ? block.text : ''))
.join('');
const abandoned = streamSummary();
expect(text(abandoned)).toBe('Earlier, we talked.');
let retried = applySummarizeDelta(
abandoned,
summarize,
{ ...summaryDelta('Second '), reset: true },
0,
);
retried = applySummarizeDelta(retried, summarize, summaryDelta('attempt.'), 0);
expect(text(retried)).toBe('Second attempt.');
expect(retried.content?.[1]).toMatchObject({ summarizing: true });
expectStepPositions(retried, [[summarize, ContentTypes.SUMMARY]]);
const withdrawn = applySummarizeDelta(
retried,
summarize,
{
id: summarize.id,
reset: true,
delta: { summary: { type: ContentTypes.SUMMARY, content: [] } as SummaryContentPart },
},
0,
);
expect(text(withdrawn)).toBe('');
expect(withdrawn.content?.[1]).toMatchObject({
type: ContentTypes.SUMMARY,
summarizing: true,
});
});
it('carries agent and group metadata onto the finalized summary', () => {
const parallel = messageStep('step-summary-p', 1, {
agentId: 'agent-b',

View file

@ -236,7 +236,8 @@ export function updateContent(
/**
* Writes one incoming part into `message.content[index]` and returns the next message. Text and
* reasoning append, tool calls merge (args concatenate until they arrive as an object), summaries
* concatenate their content, and a part of a different type never overwrites an occupied slot.
* concatenate their content (or replace it on a final update), and a part of a different type
* never overwrites an occupied slot.
* Returns the input message unchanged when the part is rejected.
*/
function writeContent(
@ -354,9 +355,11 @@ function writeContent(
} else if (contentType === ContentTypes.SUMMARY) {
const currentSummary = updatedContent[index] as SummaryContentPart | undefined;
const incoming = contentPart as SummaryContentPart;
/** A final update carries the whole content: the summary so far is replaced, not extended. */
const streamed = finalUpdate ? [] : (currentSummary?.content ?? []);
updatedContent[index] = {
...incoming,
content: [...(currentSummary?.content ?? []), ...(incoming.content ?? [])],
content: [...streamed, ...(incoming.content ?? [])],
};
} else if (contentType === ContentTypes.TOOL_CALL && 'tool_call' in contentPart) {
const existingContent = updatedContent[index] as Agents.ToolCallContent | undefined;

View file

@ -151,7 +151,10 @@ export function applySummaryStep(
);
}
/** Appends a summary delta to its step's in-flight summary part. */
/**
* Appends a summary delta to its step's in-flight summary part. A delta marked `reset` replaces
* what the part held: the attempt that streamed it was abandoned.
*/
export function applySummarizeDelta(
message: TMessage,
runStep: Agents.RunStep,
@ -163,7 +166,7 @@ export function applySummarizeDelta(
message,
runStep.index + editPrefixOffset,
contentPart,
false,
delta.reset === true,
getStepMetadata(runStep),
);
}

View file

@ -773,6 +773,13 @@ export namespace Agents {
export interface SummarizeDeltaEvent {
id: string;
/**
* Discard what the step has streamed so far, then apply `delta`. Deltas arrive while the
* provider is still responding, so an attempt that is then abandoned (a retry, a fallback
* provider) has already shown text; the next attempt's first delta carries this, or a delta
* with no content when no attempt follows.
*/
reset?: boolean;
delta: {
summary: SummaryContentPart;
};