Reject invalid tool calls in agent loops#27
Open
gold-silver-copper wants to merge 14 commits into
Open
Conversation
Owner
Author
|
Pushed follow-up fix commit This addresses the remaining review items:
Validation passed locally:
|
Owner
Author
|
Pushed Changes:
Validation run locally:
|
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.
Summary
Adds a generic agent-loop validation boundary for model-emitted tool calls before they can be dispatched or exposed to streaming callers, and aligns validation with the effective provider tool contract where Rig can infer or construct that contract.
Changes include:
CompletionError::InvalidToolCall.ToolCallContract/ToolCallNameValidatorfor request-declared tools, provider-native function declarations, hosted provider tools, and tool-choice allowlists.UnknownToolCallErrorfor model-requested tools that are not registered with the prompt.ToolNotFoundErrorinto successful tool results.additional_params.toolsfor OpenAI/Gemini-style shapes and Anthropic-style{ name, input_schema }function tools.input_schemasupport for OpenAI Responses, Gemini REST, Gemini Interactions, and xAI.code_executionuntilexecutableCode/codeExecutionResultresponse parts are preserved instead of accepting partial request-only support.Intentionally out of scope for this PR:
default_apiprovider canaries.Validation
Passed locally:
cargo fmtgit diff --checkcargo test -p rig-core tool_call_contract --libcargo test -p rig-core provider_function_tool_normalizes_input_schema --libcargo test -p rig-core raw_additional_params_tools --libcargo test -p rig-core gemini_contract_uses_raw --libcargo test -p rig-core code_execution --libcargo test -p rig-core provider_native_function_names_filter_duplicate_local_declarations --libcargo test -p rig-core --lib(706 passed, 8 ignored)cargo check --all-featurescargo clippy --all-targets --all-features