Skip to content

fix(agent): run response hooks before yielding llm_result in skills_like fallback (#9788) - #9835

Open
aniruddhaadak80 wants to merge 1 commit into
AstrBotDevs:masterfrom
aniruddhaadak80:fix/skills-like-hook-order
Open

fix(agent): run response hooks before yielding llm_result in skills_like fallback (#9788)#9835
aniruddhaadak80 wants to merge 1 commit into
AstrBotDevs:masterfrom
aniruddhaadak80:fix/skills-like-hook-order

Conversation

@aniruddhaadak80

@aniruddhaadak80 aniruddhaadak80 commented Aug 26, 2026

Copy link
Copy Markdown

What Problem This Solves

In the skills_like tool requery fallback path, the runner yields 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 cannot affect text that has already been sent.

Why This Change Was Made

When tool_schema_mode=skills_like and the model initially selects a tool but the schema requery returns a plain assistant response (no tool calls), the fallback branch at tool_loop_agent_runner.py:934 yields 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_like fallback path, matching the behavior of the normal no-tool path.

Evidence

Summary by Sourcery

Bug Fixes:

  • Run response-completion hooks before yielding assistant responses in the skills_like fallback path, allowing safety, sanitization, rewriting, and audit hooks to affect user-visible content.

…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.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've reviewed your changes and they look great!

Sourcery assessment

Approved.


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant