fix(chat): propagate toolApprovalLevel through agentic auto-sends#2464
Open
fix(chat): propagate toolApprovalLevel through agentic auto-sends#2464
Conversation
Store toolApprovalLevel in user-message metadata so it is available via messages.at(-1)?.metadata on every subsequent auto-send (where requestMetadata is empty). Echo the value back from the server in the assistant-message metadata so the fallback chain is complete for multi-turn agentic flows. Without this fix, GATEWAY_SEARCH_TOOLS and GATEWAY_DESCRIBE_TOOLS always asked for approval on auto-sends even when the user had set approval to "yolo", because the server defaulted toolApprovalLevel to "none" when the field was absent from the request. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Contributor
🧪 BenchmarkShould we run the Virtual MCP strategy benchmark for this PR? React with 👍 to run the benchmark.
Benchmark will run on the next push after you react. |
Contributor
Release OptionsShould a new version be published when this PR is merged? React with an emoji to vote on the release type:
Current version: Deployment
|
Both fields had server-side defaults (0.5 and DEFAULT_WINDOW_SIZE=50) and were absent from the message-metadata fallback chain, meaning every AI SDK auto-send (tool result → next step) silently reset them to their defaults rather than preserving the values from the originating request. Apply the same three-step pattern used for toolApprovalLevel: 1. Add temperature and windowSize to the Metadata interface so they can be carried in message metadata. 2. Echo both values from the server in the assistant-message metadata (part.type === "start") so they survive the round-trip. 3. Read them from lastMsgMeta in prepareSendMessagesRequest so every auto-send inherits the last-known values. windowSize is reconstructed into the memory object (which also requires thread_id) to satisfy the MemoryConfigSchema on the server. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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 is this contribution about?
When a user sets tool approval to "yolo" (disabled) in settings,
GATEWAY_SEARCH_TOOLSandGATEWAY_DESCRIBE_TOOLSstill prompted for approval on subsequent agentic steps.Root cause:
toolApprovalLevelwas only sent in the initialrequestMetadata, which is populated on user-initiated sends. The AI SDK'ssendAutomaticallyWhenauto-sends fire with emptyrequestMetadata, so the field was absent from the request. The server then defaulted it to"none", causingtoolNeedsApproval("none", true)to returntrueeven for read-only gateway tools.Fix — follow the existing
agent/models/thread_idfallback pattern:toolApprovalLevelin the user-message metadata (messageMetadata) so it rides along inmessages.at(-1)?.metadatafor all subsequent auto-sends.toolApprovalLevelfrom the server in the assistant-message metadata (messageMetadatacallback onpart.type === "start"), completing the fallback chain for multi-turn flows.prepareSendMessagesRequest, readtoolApprovalLevelfromlastMsgMeta(last message metadata) instead ofrequestMetadata, and remove the now-unnecessary intersection type cast.Screenshots/Demonstration
N/A — no UI changes.
How to Test
smart_tool_selectionorcode_executionmode.GATEWAY_SEARCH_TOOLSorGATEWAY_DESCRIBE_TOOLS.Migration Notes
No database migrations or configuration changes required.
Review Checklist
Summary by cubic
Ensure agent auto-sends inherit toolApprovalLevel, temperature, and windowSize from the last message metadata, preventing unwanted approval prompts and resets to server defaults.
Written for commit c748693. Summary will update on new commits.