Use the original request model for tool-loop follow-up requests#723
Open
sulimanbenhalim wants to merge 1 commit into
Open
Use the original request model for tool-loop follow-up requests#723sulimanbenhalim wants to merge 1 commit into
sulimanbenhalim wants to merge 1 commit into
Conversation
…-loop follow-up requests
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.
Fixes #680
When
generateTextruns a multi-step tool loop, six gateways build the follow-up request after tool results using the model from the API response ($data['model']) instead of the original model the caller requested. When a provider resolves the requested alias to a different id in its response, the next tool-call request goes out with that resolved id and fails withmodel_not_found.The original model is dropped at the parse boundary:
generateTextbuilds the first request with the caller's$modelbut never passes it intoparseTextResponse, so the parser falls back to$data['model']and reuses it for the follow-up request body.Affected: Xai, Mistral, DeepSeek, Groq, Ollama, OpenRouter. OpenAI and Anthropic already carry the original request body through the loop, and Gemini already threads the original model, so they are not affected. The streaming path was already correct everywhere (it threads the original model from
streamText).The fix
Thread the caller's model through as an optional
$requestModelfromgenerateText→parseTextResponse→processResponse→continueWithToolResults, and use it for the follow-up request body ($requestModel ?? $model).Meta/Stepreporting is intentionally left on the response model, so$response->meta->modelstill reflects the model the provider actually used. The parameter is optional and falls back to the response model, so nothing else changes.Tests
The reporter wasn't able to share a repro, so the added tests are the repro. Each affected gateway's
ToolCallLoopTestgets a regression test that fakes a tool-call response whosemodeldiffers from the requested alias, then asserts the follow-up request uses the original alias (and thatmeta->modelstill reports the response model). Every one of them fails on0.xtoday and passes with this change. Full suite, Pint, and PHPStan all pass.