fix(agent): handle None content in context compressor (fixes #211)#215
Closed
cutepawss wants to merge 1 commit into
Closed
fix(agent): handle None content in context compressor (fixes #211)#215cutepawss wants to merge 1 commit into
cutepawss wants to merge 1 commit into
Conversation
…arch#211) msg.get('content', '') returns the default '' only when the key is missing. When the key exists with value None (standard OpenAI API behavior for tool-only assistant messages), it returns None. Calling len(None) raises TypeError, crashing context compression. Fix: msg.get('content') or '' handles both missing keys and explicit None values. Applied to both instances in context_compressor.py (lines 90 and 196).
teknium1
added a commit
that referenced
this pull request
Mar 2, 2026
The OpenAI API returns content: null on assistant messages that only
contain tool calls. msg.get('content', '') returns None (not '') when
the key exists with value None, causing TypeError on len() and string
concatenation in _generate_summary and compress.
Fix: msg.get('content') or '' — handles both missing keys and None.
Tests from PR #216 (@Farukest). Fix also in PR #215 (@cutepawss).
Both PRs had stale branches and couldn't be merged directly.
Closes #211
Contributor
|
Thanks for the fix @cutepawss! The code change is correct. Unfortunately, the PR branch is based on an older version of main and includes ~9,000 lines of unrelated deletions across 61 files, so we couldn't merge it directly. We applied the same fix in commit 25c65bc with credit to you. If you'd like to contribute in the future, rebasing onto the latest main before opening a PR will keep things clean. 🙏 |
angelburgosrosado
pushed a commit
to angelburgosrosado/hermes-agent
that referenced
this pull request
Apr 27, 2026
…arch#211) The OpenAI API returns content: null on assistant messages that only contain tool calls. msg.get('content', '') returns None (not '') when the key exists with value None, causing TypeError on len() and string concatenation in _generate_summary and compress. Fix: msg.get('content') or '' — handles both missing keys and None. Tests from PR NousResearch#216 (@Farukest). Fix also in PR NousResearch#215 (@cutepawss). Both PRs had stale branches and couldn't be merged directly. Closes NousResearch#211
olympus-terminal
pushed a commit
to olympus-terminal/hermes-agent
that referenced
this pull request
May 16, 2026
…arch#211) The OpenAI API returns content: null on assistant messages that only contain tool calls. msg.get('content', '') returns None (not '') when the key exists with value None, causing TypeError on len() and string concatenation in _generate_summary and compress. Fix: msg.get('content') or '' — handles both missing keys and None. Tests from PR NousResearch#216 (@Farukest). Fix also in PR NousResearch#215 (@cutepawss). Both PRs had stale branches and couldn't be merged directly. Closes NousResearch#211
Egavasyug
pushed a commit
to Egavasyug/hermes-agent
that referenced
this pull request
Jun 10, 2026
…arch#211) The OpenAI API returns content: null on assistant messages that only contain tool calls. msg.get('content', '') returns None (not '') when the key exists with value None, causing TypeError on len() and string concatenation in _generate_summary and compress. Fix: msg.get('content') or '' — handles both missing keys and None. Tests from PR NousResearch#216 (@Farukest). Fix also in PR NousResearch#215 (@cutepawss). Both PRs had stale branches and couldn't be merged directly. Closes NousResearch#211
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #211
What & Why
_generate_summaryincontext_compressor.pycrashes withTypeErrorwhen any message hascontent: None.Root cause:
msg.get("content", "")returns the default""only when the key is missing. When the key exists with valueNone(standard OpenAI API behavior for tool-only assistant messages), it returnsNone. Callinglen(None)raisesTypeError.This affects any conversation that uses tools and runs long enough to trigger context compression.
Changes
agent/context_compressor.py— two lines:Testing
pytest tests/ -v # 664 passed, 15 failed (all pre-existing, unrelated)Platform Tested