You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(agent): record hook-adjusted native tool arguments - #9778
When a before-tool-call hook adjusts a model-supplied argument, native tool history now records the value used for execution or cache lookup. The executor takes this snapshot before the tool runs and pairs it with the matching history entry in serial and parallel batches.
An offline two-kickoff reproduction changes a reservation from 35 to 45 minutes. The tool receives 45 on both revisions. With this change, the returned history and the next kickoff also see 45.
Verification
Regression tests cover sync and async kickoff, serial and parallel tool calls, and post-hook changes.
The native tool hook suite passes all 25 tests. Ruff, formatting, mypy, and the commit message check pass.
The related Windows/Python 3.13 suite reports 85 passes and one existing failure. The POSIX /tmp assertion also fails on the unchanged base in the same environment.
Additional context
Hook-added top-level arguments stay in the tool execution context. Provider-specific raw tool call parts are preserved.
AI-assisted contribution prepared with Codex. Please apply the required llm-generated label if it has not been set. This external contributor account does not have permission to apply upstream labels.
PR summary: This PR makes native tool-call history record the arguments actually used for execution, including values adjusted by before-tool-call hooks, instead of echoing the model's original arguments. It also adds regression tests for sync/async kickoff and serial/parallel tool batches.
Review summary
Reviewed the change in lib/crewai/src/crewai/agents/agent_executor.py that records hook-adjusted native tool arguments into the assistant tool-call history, plus its regression tests. The new history_arguments snapshot only copies values for top-level keys the model itself supplied, is discarded when the tool neither ran nor hit cache, and is written back on the main thread after the batch completes, so it adds no attacker-reachable injection, disclosure, or crash path. Coverage spanned pairing of results with reported tool calls in serial and parallel batches, hook dispatch behaviour, cache keying on the post-hook argument string, and persistence of the mutated message history. No security issues found; two correctness observations (provider-specific raw tool-call parts bypassing the recorded arguments, and the strict result/call pairing) are not reachable by an attacker.
Ruled out (4)
Can hook-injected values under a model-supplied argument name leak into model history and be replayed to the provider? Recording the post-hook value of a model-supplied argument is the change's stated purpose, hook-added top-level keys stay out, and the only leak case is a deployer hook that deliberately commits sensitive data into a model-controlled argument field, exposing no separate victim.
Can the strict zip pairing of execution results with reported tool calls misattribute arguments or crash a run? Every future in the parallel path either writes an ordered result or re-raises, and the sequential loop appends both lists in the same iteration, so the lengths and order always match; a mismatch would in any case be a crash-only reliability issue.
Does recording the post-hook argument string give an attacker a way to poison tool-result caching or bypass usage limits? The cache read/write key and the argument used for repetition and usage checks are computed exactly as before this PR; only a copy of the value written into the stored message changed.
Do hook-adjusted argument values newly reach persisted run transcripts or checkpoints with sensitive data? Only values already present in the model's own tool call are carried forward, and the same post-hook arguments were already exposed to the tool-usage events and failure handlers that included them in the run record.
Review 1 on this PR · 9f78fc3 · requested Nov 25 09:04 UTC when the PR was opened
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
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.
Related issue
Fixes #9775
Summary
When a before-tool-call hook adjusts a model-supplied argument, native tool history now records the value used for execution or cache lookup. The executor takes this snapshot before the tool runs and pairs it with the matching history entry in serial and parallel batches.
An offline two-kickoff reproduction changes a reservation from 35 to 45 minutes. The tool receives 45 on both revisions. With this change, the returned history and the next kickoff also see 45.
Verification
The related Windows/Python 3.13 suite reports 85 passes and one existing failure. The POSIX
/tmpassertion also fails on the unchanged base in the same environment.Additional context
Hook-added top-level arguments stay in the tool execution context. Provider-specific raw tool call parts are preserved.
AI-assisted contribution prepared with Codex. Please apply the required
llm-generatedlabel if it has not been set. This external contributor account does not have permission to apply upstream labels.