fix(agent): run post_llm_call hook before session persistence#14913
Open
aniruddhaadak80 wants to merge 4 commits into
Open
fix(agent): run post_llm_call hook before session persistence#14913aniruddhaadak80 wants to merge 4 commits into
aniruddhaadak80 wants to merge 4 commits into
Conversation
The post_llm_call plugin hook was invoked AFTER _persist_session(), so any response overrides applied by plugins were never captured in the persisted session history. This caused a mismatch between the final_response returned to the caller and the history stored in SQLite/JSON logs. Move _persist_session() to fire after the hook block and add support for plugins to return override_response dicts that update both the final_response and the last assistant message before persistence. Closes NousResearch#14894
…ersist-order # Conflicts: # agent/conversation_loop.py
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
Fixes #14894
The
post_llm_callplugin hook was invoked after_persist_session(), so any response overrides applied by plugins were never captured in the persisted session history. This caused a mismatch between thefinal_responsereturned to the caller and the history stored in SQLite/JSON logs.Root Cause
In
run_conversation():_persist_session(messages, conversation_history)writes to DBpost_llm_callhook fires — plugin can modifyfinal_responseThe hook result was never re-persisted.
Changes
run_agent.py —
run_conversation():_persist_session()to fire after thepost_llm_callhook block{"override_response": "..."}dictsfinal_responseand the last assistant message are updated before persistenceTesting
try/except— plugin failures cannot break persistence_persist_session()still runs unconditionally after the hooktest_plugins.pytests remain compatible (invoke_hookreturn value was previously ignored)Checklist