-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Summary input limit can produce a content-free compaction #6470
Copy link
Copy link
Open
Labels
org:internalIssue or pull request created by a member of the `langchain-ai` GitHub organization.Issue or pull request created by a member of the `langchain-ai` GitHub organization.package:deepagentsChanges related to the `deepagents` SDK and agent harness.Changes related to the `deepagents` SDK and agent harness.priority:backlogNot currently planned/prioritized work, often affecting a limited feature or set of users.Not currently planned/prioritized work, often affecting a limited feature or set of users.topic:backendsFilesystem and storage backends for Deep Agents.Filesystem and storage backends for Deep Agents.topic:middlewareMiddleware behavior and composition.Middleware behavior and composition.type:bugAn unexpected problem or incorrect behavior.An unexpected problem or incorrect behavior.
Description
Activity
Metadata
Metadata
Assignees
Labels
org:internalIssue or pull request created by a member of the `langchain-ai` GitHub organization.Issue or pull request created by a member of the `langchain-ai` GitHub organization.package:deepagentsChanges related to the `deepagents` SDK and agent harness.Changes related to the `deepagents` SDK and agent harness.priority:backlogNot currently planned/prioritized work, often affecting a limited feature or set of users.Not currently planned/prioritized work, often affecting a limited feature or set of users.topic:backendsFilesystem and storage backends for Deep Agents.Filesystem and storage backends for Deep Agents.topic:middlewareMiddleware behavior and composition.Middleware behavior and composition.type:bugAn unexpected problem or incorrect behavior.An unexpected problem or incorrect behavior.
Submission checklist
Area (Required)
Related Issues / PRs
Reproduction Steps / Example Code (Python)
trim_tokens_to_summarizeis a safety limit for the internal summarization request. It does not control when conversation compaction starts or how long the final summary may be. After Deep Agents chooses old messages to compact, this option limits how many tokens from those messages are sent to the summarization model, preventing that internal request from exceeding the model's context window.The bug occurs when the limit is smaller than an individual message. LangChain may be unable to retain even a partial valid message, so non-empty history becomes an empty summarization input:
The model API is not called. The same branch is used by
_acreate_summaryduring normal async agent execution.This also reproduces with
trim_tokens_to_summarize=4000andmessages = [HumanMessage(content="important context " * 2000)]. The default partial-message splitter splits on newlines, so an oversized single-line message cannot be shortened to fit even withallow_partial=True. A large single-line tool result or application payload can therefore leave no valid messages for the summarizer. This is pre-summary trimming exhaustion, not a context-window error returned by the summarization model.Error Message and Stack Trace (if applicable)
No exception is raised. Compaction is recorded as successful with the fallback "Previous conversation was too long to summarize."Description
During automatic compaction, Deep Agents:
/conversation_history/<session>.md;_summarization_event.When
trim_tokens_to_summarizereduces non-empty history to zero messages, step 3 returns a generic fallback instead of a summary. Deep Agents still completes step 4, replacing the evicted task context with:The event looks successful but preserves no task state or decisions. The agent may then follow the archive pointer and read back the history it just compacted, adding latency and token usage.
Expected behavior: if bounded trimming cannot retain content from non-empty history, Deep Agents should not commit a successful compaction with the generic fallback. It should retain a safe bounded portion, skip the compaction event, or fail explicitly.
The factory deliberately leaves
trim_tokens_to_summarizeunset by default, so its default configuration does not take this branch. The bug affects users who opt into this public safety limit and subclasses that inherit the middleware class's bounded default.Environment / System Info