hermes - 💡(How to fix) Fix Gateway mode doesn't invoke pre_llm_call / post_llm_call hooks — LCM and other context plugins fail silently in platform sessions [1 comments, 2 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#23140Fetched 2026-05-11 03:30:49
View on GitHub
Comments
1
Participants
2
Timeline
6
Reactions
0
Timeline (top)
labeled ×4commented ×1cross-referenced ×1

Root Cause

In run_agent.py, the LLM call lifecycle is:

pre_llm_call hook → [LLM call + tool loop] → post_llm_call hook

Both hooks receive conversation_history=list(messages) and in LCM's case, post_llm_call triggers the ingest into lcm.db.

In gateway/run.py, the message handling path does NOT invoke these hooks. It only calls:

  • on_session_finalize
  • on_session_reset

Fix Action

Workaround

Manual /compress command works because it explicitly calls compress(), but this must be done manually per session and doesn't auto-trigger.


This issue affects all plugin authors building context/memory systems that rely on these hooks.

Code Example

pre_llm_call hook → [LLM call + tool loop] → post_llm_call hook
RAW_BUFFERClick to expand / collapse

Problem

The pre_llm_call and post_llm_call plugin hooks are invoked in CLI mode (run_agent.py) but not in Gateway mode (gateway/run.py). This causes context management plugins like Hermes-LCM to silently fail for all platform sessions (Feishu, Telegram, Discord, etc.).

Root Cause

In run_agent.py, the LLM call lifecycle is:

pre_llm_call hook → [LLM call + tool loop] → post_llm_call hook

Both hooks receive conversation_history=list(messages) and in LCM's case, post_llm_call triggers the ingest into lcm.db.

In gateway/run.py, the message handling path does NOT invoke these hooks. It only calls:

  • on_session_finalize
  • on_session_reset

Impact

  • LCM threshold_tokens stays at 0 in Gateway mode (set only via update_from_response() in CLI loop)
  • should_compress_preflight() with its ingest logic is never called
  • All platform sessions (Feishu, Telegram, WhatsApp, etc.) bypass LCM entirely
  • Only CLI sessions work correctly with LCM

Expected Fix

In gateway/run.py, add pre_llm_call / post_llm_call invocations in the message processing path, matching what run_agent.py does. Specifically around where the agent is called to produce a response.

Alternatively, add a new hook like on_message_processed that fires after each message exchange with the full conversation_history.

Evidence

hook 调用分布:

  • CLI mode (run_agent.py:8962): ✅ pre_llm_call with conversation_history
  • CLI mode (run_agent.py:11868): ✅ post_llm_call with conversation_history
  • Gateway mode (gateway/run.py): ❌ neither hook is called

Workaround

Manual /compress command works because it explicitly calls compress(), but this must be done manually per session and doesn't auto-trigger.


This issue affects all plugin authors building context/memory systems that rely on these hooks.

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 - 💡(How to fix) Fix Gateway mode doesn't invoke pre_llm_call / post_llm_call hooks — LCM and other context plugins fail silently in platform sessions [1 comments, 2 participants]