fix(agent): run response hooks before yielding llm_result in skills_like fallback (#9788) - #9835
Open
aniruddhaadak80 wants to merge 1 commit into
Open
Conversation
…ike fallback (AstrBotDevs#9788) In the skills_like tool requery fallback path, the runner yielded llm_result (sending the response to the user) before calling _complete_with_assistant_response, which triggers on_agent_done hooks. Plugins doing content safety review, sanitization, or rewriting could not affect text already sent. Moved the completion call before the yields.
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.
What Problem This Solves
In the
skills_liketool requery fallback path, the runner yieldsllm_result(sending the response to the user) before calling_complete_with_assistant_response, which triggerson_agent_donehooks. Plugins doing content safety review, sanitization, or rewriting cannot affect text that has already been sent.Why This Change Was Made
When
tool_schema_mode=skills_likeand the model initially selects a tool but the schema requery returns a plain assistant response (no tool calls), the fallback branch attool_loop_agent_runner.py:934yields the response to the user before the response hooks run. The normal no-tool path already has the correct order (complete first, then yield); this fallback branch was missed.User Impact
Response hooks (content safety, sanitization, rewriting, audit) now run before the response reaches the user in the
skills_likefallback path, matching the behavior of the normal no-tool path.Evidence
tool_loop_agent_runner.py:934-962— yields before_complete_with_assistant_response_complete_with_assistant_responsecallson_agent_donehook at line 201await self._complete_with_assistant_response(llm_resp)before the yield statementsSummary by Sourcery
Bug Fixes:
skills_likefallback path, allowing safety, sanitization, rewriting, and audit hooks to affect user-visible content.