feat: activate plugin lifecycle hooks (pre/post_llm_call, session start/end)#3542
Merged
feat: activate plugin lifecycle hooks (pre/post_llm_call, session start/end)#3542
Conversation
…rt/end)
The plugin system defined six lifecycle hooks but only pre_tool_call and
post_tool_call were invoked. This activates the remaining four so that
external plugins (e.g. memory systems) can hook into the conversation
loop without touching core code.
Hook semantics:
- on_session_start: fires once when a new session is created
- pre_llm_call: fires once per turn before the tool-calling loop;
plugins can return {"context": "..."} to inject into the ephemeral
system prompt (not cached, not persisted)
- post_llm_call: fires once per turn after the loop completes, with
user_message and assistant_response for sync/storage
- on_session_end: fires at the end of every run_conversation call
invoke_hook() now returns a list of non-None callback return values,
enabling pre_llm_call context injection while remaining backward
compatible (existing hooks that return None are unaffected).
Salvaged from PR #2823.
3 tasks
teknium1
added a commit
that referenced
this pull request
Mar 28, 2026
… pages Fixes found by auditing docs against recent PRs/commits: Critical (misleading): - hooks.md: Remove stale 'planned — not yet wired' markers for 4 hooks that are now active (#3542). Add correct callback signatures. - security.md: Update tirith verdict behavior — block verdicts now go through approval flow instead of hard-blocking (#3428). Add pkill/killall self-termination guard and gateway-run backgrounding patterns (#3593). New feature docs: - configuration.md: Add tool_use_enforcement section with value table (auto/true/false/list) from #3551/#3528. - configuration.md: Expand auxiliary config with per-task timeouts (compression 120s, web_extract 30s, approval 30s) from #3597. - api-server.md: Add /v1/health alias, Security Headers section, CORS details (Max-Age, SSE headers, Idempotency-Key) from #3572/#3573/#3576/#3580/#3530. Stale/incomplete: - configuration.md: Fix Alibaba model name qwen-plus -> qwen3.5-plus (#3484). - environment-variables.md: Specify actual DashScope default URL. - cli-commands.md: Add alibaba to --provider list. - fallback-providers.md: Add Alibaba/DashScope to provider table. - email.md: Document noreply/automated sender filtering (#3606). - toolsets-reference.md: Add 4 missing platform toolsets — matrix, mattermost, dingtalk, api-server (#3583). - skills.md: List default GitHub taps including garrytan/gstack (#3605).
teknium1
added a commit
that referenced
this pull request
Mar 28, 2026
… pages (#3618) Fixes found by auditing docs against recent PRs/commits: Critical (misleading): - hooks.md: Remove stale 'planned — not yet wired' markers for 4 hooks that are now active (#3542). Add correct callback signatures. - security.md: Update tirith verdict behavior — block verdicts now go through approval flow instead of hard-blocking (#3428). Add pkill/killall self-termination guard and gateway-run backgrounding patterns (#3593). New feature docs: - configuration.md: Add tool_use_enforcement section with value table (auto/true/false/list) from #3551/#3528. - configuration.md: Expand auxiliary config with per-task timeouts (compression 120s, web_extract 30s, approval 30s) from #3597. - api-server.md: Add /v1/health alias, Security Headers section, CORS details (Max-Age, SSE headers, Idempotency-Key) from #3572/#3573/#3576/#3580/#3530. Stale/incomplete: - configuration.md: Fix Alibaba model name qwen-plus -> qwen3.5-plus (#3484). - environment-variables.md: Specify actual DashScope default URL. - cli-commands.md: Add alibaba to --provider list. - fallback-providers.md: Add Alibaba/DashScope to provider table. - email.md: Document noreply/automated sender filtering (#3606). - toolsets-reference.md: Add 4 missing platform toolsets — matrix, mattermost, dingtalk, api-server (#3583). - skills.md: List default GitHub taps including garrytan/gstack (#3605).
crxssrazr93
added a commit
to crxssrazr93/hermes-agent
that referenced
this pull request
Mar 29, 2026
Example plugin demonstrating the lifecycle hooks activated in NousResearch#3542. Auto-manages a local llama-server (or any OpenAI-compatible server) when the active model matches a locally configured model name. Features: - pre_llm_call hook: auto-starts the correct server on first message when hermes is configured with a local model name - on_session_end hook: kills the server on exit - switch_local_llm tool: mid-session model switching — the agent swaps the server when asked ("switch to the code model") - Declarative YAML config for model definitions (GGUF paths, context sizes, KV cache quantization, sampling params) replacing shell scripts The plugin is self-contained in docs/llm-switch-plugin-example/ with a README, example config, and full implementation. Users copy it to ~/.hermes/plugins/llm-switch/ to install. Complements NousResearch#3360 and NousResearch#3548 which restore /model as a slash command — once merged, /model custom:write would trigger the pre_llm_call hook to auto-start the right server seamlessly. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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.
Summary
Salvaged from PR #2823 by @nicoloboschi.
Activates the four lifecycle hooks that were defined in the plugin system but never invoked:
on_session_start,pre_llm_call,post_llm_call,on_session_end.This enables external plugins (e.g. memory systems like Hindsight) to integrate as pip-installable plugins that hook every conversation turn, without requiring core changes.
Hook semantics
on_session_startpre_llm_call{"context": "..."}injected into ephemeral system promptpost_llm_callon_session_endrun_conversation()callChanges from original PR
conversation_historypassed as a shallow copy (list(messages)) to prevent plugins from mutating the live conversationmodelandplatformkwargs toon_session_endfor consistency with all other hooksfeatures/plugins.mdto remove *(planned)* markers now that all hooks are active--authorFiles changed
hermes_cli/plugins.py—invoke_hook()now returnsList[Any]of non-None resultsrun_agent.py— invoke all four hooks at appropriate lifecycle pointstests/test_plugins.py— added tests for return value collectionwebsite/docs/guides/build-a-hermes-plugin.md— updated hook reference tablewebsite/docs/user-guide/features/plugins.md— removed (planned) markersTest plan