Add provider-agnostic toolChoice option and ToolChoice validator - #25
Merged
Conversation
Introduce the ToolChoice value object that validates and normalises the
toolChoice chat option ("auto", "none", "required", or ["name" => "<tool>"]),
throwing before any HTTP call on an unknown value or an unenforceable choice
(no tools declared, or a name not among the declared tools).
Define the chat options bag once as a reusable @psalm-type ChatOptions on
ProviderInterface so providers import it with @psalm-import-type instead of
repeating the shape across per-provider docblocks.
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.
First step of v0.13 (forced tool choice). Core-only; providers follow once this is released.
What
PapiAI\Core\ToolChoice: validates and normalises thetoolChoicechat option ("auto","none","required", or["name" => "<tool>"]) against the declared tools, throwingInvalidArgumentExceptionbefore any HTTP call on an unknown value, onnone/required/specific with no tools declared, or a name not among the declared tools. It never silently drops an unenforceable choice.@psalm-type ChatOptionsonProviderInterface; providers import it with@psalm-import-type ChatOptions from ProviderInterface, so adding an option no longer drifts across per-provider docblocks.toolChoiceon the contract.Design note
This is the deliberate option-bag design (the option flows through verbatim; each provider maps and validates it). The ISP-clean alternative (a segregated
ToolCallingProviderInterface, asupportsToolChoice()capability query, and first-classChatOptions/ToolChoicevalue objects) is parked as #24 for the v1.0 interface audit.Tests
217 passed (10 new ToolChoice tests), lint and Psalm (level 4) clean.