fix(agent): strip finish_reason and internal fields before API calls#250
Closed
Bartok9 wants to merge 1 commit into
Closed
fix(agent): strip finish_reason and internal fields before API calls#250Bartok9 wants to merge 1 commit into
Bartok9 wants to merge 1 commit into
Conversation
Fixes NousResearch#134 Mistral API (and potentially others) returns 422 error when extra fields like finish_reason are sent in the request. The error message is: 'Extra inputs are not permitted', 'loc': ['body', 'messages', 2, 'assistant', 'finish_reason'] This fix ensures internal-only fields (finish_reason, reasoning) are stripped from all message copies before sending to the API: - flush_memories API call - summary generation API call - main conversation API call The fields are preserved in the local messages array for trajectory storage and debugging, but excluded from API requests.
48e46b6 to
3eb2937
Compare
Contributor
|
Thanks for the report, @Bartok9! This issue was already largely fixed by PR #253 (commit 7a0b377 by @Sertug17), which stripped Your PR did catch one remaining gap though — Closing this since the fix is now fully covered, but appreciate you spotting the missing code path! |
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
Fixes #134
Mistral API returns 422 error on the second message because internal fields like
finish_reasonare being sent in the request.Error
Root Cause
finish_reasonis response metadata from the API, not a valid request field. The code was storing it in messages for trajectory/debugging purposes, but then copying those messages (including the field) when making subsequent API calls.Fix
Strip internal-only fields (
finish_reason,reasoning) from message copies before sending to the API. Applied to all three places where API messages are constructed:flush_memories()API callFields Affected
finish_reason- Now stripped (caused the Mistral 422)reasoning- Was already being stripped (for different reasons)Testing