Skip to content

fix(agent): handle None content in context compressor (fixes #211)#215

Closed
cutepawss wants to merge 1 commit into
NousResearch:mainfrom
cutepawss:fix/compressor-none-content
Closed

fix(agent): handle None content in context compressor (fixes #211)#215
cutepawss wants to merge 1 commit into
NousResearch:mainfrom
cutepawss:fix/compressor-none-content

Conversation

@cutepawss

Copy link
Copy Markdown
Contributor

Fixes #211

What & Why

_generate_summary in context_compressor.py crashes with TypeError when any message has content: None.

Root cause: 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.

This affects any conversation that uses tools and runs long enough to trigger context compression.

Changes

agent/context_compressor.py — two lines:

- content = msg.get("content", "")
+ content = msg.get("content") or ""
- msg["content"] = msg.get("content", "") + "\n\n[Note: ...]"
+ msg["content"] = (msg.get("content") or "") + "\n\n[Note: ...]"

Testing

pytest tests/ -v
# 664 passed, 15 failed (all pre-existing, unrelated)

Platform Tested

  • macOS (Python 3.14)

…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
@teknium1

teknium1 commented Mar 2, 2026

Copy link
Copy Markdown
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. 🙏

@teknium1 teknium1 closed this Mar 2, 2026
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Context compressor crashes with TypeError when message content is None

2 participants