[PR #228] [CLOSED] fix(summarization): prevent context overflow and orphaned tool messages #225

Closed
opened 2026-02-16 06:17:29 -05:00 by yindo · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/langchain-ai/deepagentsjs/pull/228
Author: @christian-bromann
Created: 2/12/2026
Status: Closed

Base: mainHead: cb/summarization-improvements


📝 Commits (4)

📊 Changes

5 files changed (+857 additions, -506 deletions)

View changed files

📝 examples/sandbox/vfs-sandbox.ts (+1 -0)
📝 libs/deepagents/src/agent.ts (+11 -9)
📝 libs/deepagents/src/middleware/fs.ts (+29 -4)
📝 libs/deepagents/src/middleware/summarization.ts (+292 -22)
📝 pnpm-lock.yaml (+524 -471)

📄 Description

Three issues with the summarization middleware caused agent crashes:

  1. No post-summarization safety check: after cutting messages, a single oversized tool result (e.g. a 668K-char glob) in the preserved window could still exceed the model limit. Added emergency truncation both when summarization is not triggered and after summarization completes.

  2. Orphaned ToolMessages: determineCutoffIndex could split an AIMessage from its ToolMessages, leaving tool_result blocks without a preceding tool_use. Added adjustCutoffForToolMessages to advance the cutoff past any leading ToolMessages, applied at summarization time and defensively in getEffectiveMessages for backward compatibility.

  3. Token estimation included system message and tool schema overhead in the count (matching Python's approach), and the trigger was lowered from 170K to 130K after removing the arbitrary 1.25x safety factor from the proactive trigger path. The safety factor is now only used for hard-limit checks (emergency truncation).


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/langchain-ai/deepagentsjs/pull/228 **Author:** [@christian-bromann](https://github.com/christian-bromann) **Created:** 2/12/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `cb/summarization-improvements` --- ### 📝 Commits (4) - [`232bc4a`](https://github.com/langchain-ai/deepagentsjs/commit/232bc4a87a644c8831ff621c9dd42cedbff4d7e9) fix(summarization): prevent context overflow and orphaned tool messages - [`258d6a3`](https://github.com/langchain-ai/deepagentsjs/commit/258d6a3b37416f80b7050811d51ad8b5282c47ce) cr - [`d1247c2`](https://github.com/langchain-ai/deepagentsjs/commit/d1247c24141d321b0171799302dae77df81f02cf) format - [`6f4b2c1`](https://github.com/langchain-ai/deepagentsjs/commit/6f4b2c1f2d1c38c1b550cd128ceb3849559d779a) remove logging ### 📊 Changes **5 files changed** (+857 additions, -506 deletions) <details> <summary>View changed files</summary> 📝 `examples/sandbox/vfs-sandbox.ts` (+1 -0) 📝 `libs/deepagents/src/agent.ts` (+11 -9) 📝 `libs/deepagents/src/middleware/fs.ts` (+29 -4) 📝 `libs/deepagents/src/middleware/summarization.ts` (+292 -22) 📝 `pnpm-lock.yaml` (+524 -471) </details> ### 📄 Description Three issues with the summarization middleware caused agent crashes: 1. No post-summarization safety check: after cutting messages, a single oversized tool result (e.g. a 668K-char glob) in the preserved window could still exceed the model limit. Added emergency truncation both when summarization is not triggered and after summarization completes. 2. Orphaned ToolMessages: determineCutoffIndex could split an AIMessage from its ToolMessages, leaving tool_result blocks without a preceding tool_use. Added adjustCutoffForToolMessages to advance the cutoff past any leading ToolMessages, applied at summarization time and defensively in getEffectiveMessages for backward compatibility. 3. Token estimation included system message and tool schema overhead in the count (matching Python's approach), and the trigger was lowered from 170K to 130K after removing the arbitrary 1.25x safety factor from the proactive trigger path. The safety factor is now only used for hard-limit checks (emergency truncation). --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
yindo added the pull-request label 2026-02-16 06:17:29 -05:00
yindo changed title from [PR #228] fix(summarization): prevent context overflow and orphaned tool messages to [PR #228] [CLOSED] fix(summarization): prevent context overflow and orphaned tool messages 2026-06-05 17:22:29 -04:00
yindo closed this issue 2026-06-05 17:22:29 -04:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langchain-ai/deepagentsjs#225