hermes - ✅(Solved) Fix Bug: ContextEngine ABC compress() missing focus_topic parameter causes TypeError [3 pull requests, 1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
NousResearch/hermes-agent#11586Fetched 2026-04-18 06:00:10
View on GitHub
Comments
0
Participants
1
Timeline
5
Reactions
0
Participants
Timeline (top)
cross-referenced ×3referenced ×2

Error Message

  • Error only manifests at runtime when compression is triggered, not at import time

Root Cause

The ABC signature in agent/context_engine.py:

def compress(
    self,
    messages: List[Dict[str, Any]],
    current_tokens: int = None,
) -> List[Dict[str, Any]]:

Missing: focus_topic: str = None

Fix Action

Fix

Add focus_topic: str = None to the ABC signature:

def compress(
    self,
    messages: List[Dict[str, Any]],
    current_tokens: int = None,
    focus_topic: str = None,
) -> List[Dict[str, Any]]:

PR fix notes

PR #11650: fix(context): accept focus_topic in ContextEngine ABC

Description (problem / solution / changelog)

Summary

  • add focus_topic to the ContextEngine.compress() abstract signature so plugin engines match the arguments AIAgent already passes during manual or guided compression
  • update the plugin and ABC test stubs to implement the new parameter
  • add a regression test that verifies a concrete context engine accepts focus_topic

Closes #11586

Testing

  • source venv/bin/activate && python -m pytest tests/agent/test_context_engine.py -q
  • source venv/bin/activate && python -m pytest tests/run_agent/test_plugin_context_engine_init.py -q
  • source venv/bin/activate && python -m pytest tests/agent/test_compress_focus.py -q
  • source venv/bin/activate && python -m pytest tests/ -q

Full suite note

The full suite still fails in this environment on existing unrelated issues and missing optional deps (acp, fastapi), plus current gateway/web/discord/transcription failures. The context-engine-specific coverage above passed locally.

Changed files

  • agent/context_engine.py (modified, +4/-1)
  • scripts/release.py (modified, +1/-0)
  • tests/agent/test_context_engine.py (modified, +13/-1)
  • tests/run_agent/test_plugin_context_engine_init.py (modified, +1/-1)

PR #11660: fix(agent): add focus_topic to ContextEngine.compress() ABC

Description (problem / solution / changelog)

Summary

  • Add missing focus_topic: Optional[str] = None parameter to ContextEngine.compress() ABC signature
  • AIAgent._compress_context() in run_agent.py passes focus_topic=... to all engines, but the ABC didn't declare it — plugin engines strictly following the ABC signature get TypeError
  • Update documentation example and test stubs to match the new signature

Changes

  • agent/context_engine.py: Add focus_topic: Optional[str] = None to the abstract compress() method, add Optional import
  • website/docs/developer-guide/context-engine-plugin.md: Update code example to include focus_topic parameter
  • tests/agent/test_context_engine.py: Update StubEngine.compress() signature, add tests for focus_topic acceptance and default
  • tests/run_agent/test_plugin_context_engine_init.py: Update _StubEngine.compress() signature

Test plan

  • Existing tests in tests/agent/test_context_engine.py pass
  • Existing tests in tests/agent/test_compress_focus.py pass
  • New test_compress_accepts_focus_topic and test_compress_focus_topic_defaults_to_none tests pass
  • Plugin engines implementing compress(self, messages, current_tokens=None, focus_topic=None) no longer get TypeError

Closes #11586

🤖 Generated with Claude Code

Changed files

  • agent/context_engine.py (modified, +9/-1)
  • tests/agent/test_context_engine.py (modified, +15/-1)
  • tests/run_agent/test_plugin_context_engine_init.py (modified, +1/-1)
  • website/docs/developer-guide/context-engine-plugin.md (modified, +2/-1)

PR #11828: fix(context): add focus_topic parameter to ContextEngine.compress ABC

Description (problem / solution / changelog)

Summary

AIAgent._compress_context() in run_agent.py calls engine.compress(..., focus_topic=focus_topic) on all context engines. However, the ContextEngine abstract base class did not declare focus_topic in its compress() signature.

Any third-party ContextEngine subclass that didn't mirror the internal implementation would raise TypeError: compress() got an unexpected keyword argument 'focus_topic'.

Changes

  • agent/context_engine.py: add focus_topic: Optional[str] = None to the ContextEngine.compress abstract method signature

Testing

Existing context engine implementations continue to work. Third-party implementations no longer get TypeError.

Closes #11586

Changed files

  • agent/context_engine.py (modified, +8/-1)
  • scripts/release.py (modified, +1/-0)

Code Example

# run_agent.py
compressed = await context_engine.compress(
    messages,
    current_tokens=current_tokens,
    focus_topic=focus_topic,  # <— passed to ALL engines
)

---

def compress(
    self,
    messages: List[Dict[str, Any]],
    current_tokens: int = None,
) -> List[Dict[str, Any]]:

---

def compress(
    self,
    messages: List[Dict[str, Any]],
    current_tokens: int = None,
    focus_topic: str = None,
) -> List[Dict[str, Any]]:
RAW_BUFFERClick to expand / collapse

Bug Description

ContextEngine.compress() is an abstract base class (ABC) in agent/context_engine.py. Its signature does not include focus_topic: str = None, but AIAgent._compress_context() in run_agent.py passes focus_topic to all engines:

# run_agent.py
compressed = await context_engine.compress(
    messages,
    current_tokens=current_tokens,
    focus_topic=focus_topic,  # <— passed to ALL engines
)

When the built-in ContextCompressor engine is used, it works fine because it accepts **kwargs. But when a plugin engine (e.g. UnifiedContextEngine) is registered that uses the ABC signature without focus_topic, it causes a TypeError: compress() got an unexpected keyword argument focus_topic at runtime.

Root Cause

The ABC signature in agent/context_engine.py:

def compress(
    self,
    messages: List[Dict[str, Any]],
    current_tokens: int = None,
) -> List[Dict[str, Any]]:

Missing: focus_topic: str = None

Fix

Add focus_topic: str = None to the ABC signature:

def compress(
    self,
    messages: List[Dict[str, Any]],
    current_tokens: int = None,
    focus_topic: str = None,
) -> List[Dict[str, Any]]:

Impact

  • Plugin context engines that follow the ABC signature strictly cannot be used
  • Error only manifests at runtime when compression is triggered, not at import time
  • Silent failure mode: if someone catches the TypeError, compression silently fails and the full message list is returned unchanged (which is actually safe but confusing)

Suggested Labels

bug, context-engine, plugin-system

extent analysis

TL;DR

Update the ContextEngine.compress() abstract base class (ABC) signature to include focus_topic: str = None to prevent TypeError when using plugin engines.

Guidance

  • Verify that all plugin engines using the ContextEngine ABC are updated to accept the new focus_topic parameter, even if they don't use it.
  • Review the AIAgent._compress_context() method to ensure it handles cases where focus_topic is not provided.
  • Consider adding a check in the ContextEngine ABC to raise a more informative error if an engine does not accept the focus_topic parameter.
  • Test the updated ContextEngine ABC with various plugin engines to ensure compatibility.

Example

# Updated ContextEngine ABC signature
def compress(
    self,
    messages: List[Dict[str, Any]],
    current_tokens: int = None,
    focus_topic: str = None,
) -> List[Dict[str, Any]]:
    # Engine implementation
    pass

Notes

This fix assumes that all plugin engines will be updated to accept the new focus_topic parameter. If some engines cannot be updated, a backwards compatibility solution may be needed.

Recommendation

Apply workaround: Update the ContextEngine ABC signature to include focus_topic: str = None, as this will prevent the TypeError and ensure compatibility with plugin engines.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

hermes - ✅(Solved) Fix Bug: ContextEngine ABC compress() missing focus_topic parameter causes TypeError [3 pull requests, 1 participants]