Skip to content

fix(hooks): apply ModifiedInput from pre-tool hooks to tool call arguments#1950

Merged
dgageot merged 1 commit intodocker:mainfrom
aheritier:feat/rtk-hook-modified-input
Mar 6, 2026
Merged

fix(hooks): apply ModifiedInput from pre-tool hooks to tool call arguments#1950
dgageot merged 1 commit intodocker:mainfrom
aheritier:feat/rtk-hook-modified-input

Conversation

@aheritier
Copy link
Contributor

The pre-tool hook system already supported returning updated_input via
hook_specific_output, and the executor populated Result.ModifiedInput.
However, the runtime never applied it back to toolCall.Function.Arguments
before execution, making input-rewriting hooks (like RTK) ineffective.

Marshal ModifiedInput to JSON and overwrite the tool call arguments
when a pre-tool hook provides modified input.

Assisted-By: cagent

Copilot AI review requested due to automatic review settings March 5, 2026 20:11
@aheritier aheritier requested a review from a team as a code owner March 5, 2026 20:11
…ments

The pre-tool hook system already supported returning updated_input via
hook_specific_output, and the executor populated Result.ModifiedInput.
However, the runtime never applied it back to
toolCall.Function.Arguments before execution, making input-rewriting
hooks (like RTK) ineffective.

Marshal ModifiedInput to JSON and overwrite the tool call arguments
when a pre-tool hook provides modified input.

Assisted-By: cagent
@aheritier aheritier force-pushed the feat/rtk-hook-modified-input branch from 1a1ab28 to cae93d4 Compare March 5, 2026 20:12
@aheritier aheritier changed the title feat(hooks): apply ModifiedInput from pre-tool hooks to tool call arguments fix(hooks): apply ModifiedInput from pre-tool hooks to tool call arguments Mar 5, 2026
@aheritier aheritier marked this pull request as draft March 5, 2026 20:13

This comment was marked as outdated.

@aheritier
Copy link
Contributor Author

I stopped to use RTK but to make it work with cagent I had to apply this patch FYI @dgageot @rumpl

@aheritier
Copy link
Contributor Author

/review

docker-agent[bot]

This comment was marked as outdated.

@aheritier
Copy link
Contributor Author

(not sure if it has some interest)

Copy link

@docker-agent docker-agent bot left a comment

Choose a reason for hiding this comment

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

Review Summary

Assessment: 🟢 APPROVE

This PR correctly implements the missing piece of the pre-tool hook system: applying ModifiedInput back to tool call arguments. The code changes are well-structured and handle edge cases appropriately.

What was reviewed:

  • Error handling for JSON marshaling of modified input
  • Control flow with the refactored default case
  • Integration with existing hook blocking logic

Key observations:

  • The early return when !result.Allowed ensures modified input is only processed for allowed tool calls
  • Failed JSON marshaling logs a warning and proceeds with original input, which is a reasonable fallback strategy
  • The refactoring from case result.SystemMessage != "" to default enables processing both SystemMessage and ModifiedInput together, which is an improvement

No bugs found in the changed code. The implementation looks solid and ready to merge.


Automated review - all hypotheses were verified and dismissed

@aheritier
Copy link
Contributor Author

this one @dgageot was to show to @rumpl what I had to change to use RTK. I am not sure it makes sense to be addressed, and if it is the right fix to do

@docker docker deleted a comment from Copilot AI Mar 6, 2026
@docker docker deleted a comment from Copilot AI Mar 6, 2026
@dgageot dgageot marked this pull request as ready for review March 6, 2026 14:13
@dgageot dgageot merged commit 26f794c into docker:main Mar 6, 2026
8 checks passed
@docker-agent
Copy link

docker-agent bot commented Mar 6, 2026

PR Review Failed — The review agent encountered an error and could not complete the review. View logs.

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.

3 participants