fix(agent): route Anthropic fast mode via extra_body - #8013
Closed
marcelruhf wants to merge 1 commit into
Closed
Conversation
Contributor
|
Thanks for the careful analysis and the SDK-boundary regression test, @marcelruhf! This fix was independently implemented on This is an automated hermes-sweeper review.
The |
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 does this PR do?
Fixes the native Anthropic fast-mode request shape introduced in #7037.
/fast faststores{"speed": "fast"}inrequest_overrides, and the Anthropic adapter was forwarding that as a top-levelspeed=kwarg. On the stable Anthropic Python SDK,client.messages.create()andclient.messages.stream()do not accept top-levelspeed; both surfaces accept undocumented body params throughextra_body. The old shape fails locally withTypeErrorbefore a request is sent.This PR keeps the fix at the adapter boundary:
extra_body["speed"] = "fast"extra_bodyis the right fix becausebuild_anthropic_kwargs()already owns Anthropic-specific request shaping, and the SDK exposesextra_bodyon both the current release (0.93.0) and the repo's minimum supported floor (0.39.0).Related Issue
Regression from #7037.
Type of Change
Changes Made
agent/anthropic_adapter.py: move fast-modespeedfrom a top-level kwarg toextra_body, with SDK-compatibility notes in the docstring/commentstests/agent/test_anthropic_adapter.py: add a real SDK-boundary regression test usinganthropic+httpx.MockTransportto verify"speed": "fast"is serialized into the JSON bodytests/cli/test_fast_command.py: update fast-mode assertions to expectextra_body, and keep the third-party endpoint exclusion coverageHow to Test
source /home/mruhf/.hermes/hermes-agent/venv/bin/activatepython -m pytest tests/cli/test_fast_command.py -qpython -m pytest tests/agent/test_anthropic_adapter.py -qpython -m pytest tests/cli/test_fast_command.py tests/agent/test_anthropic_adapter.py -qpython -m pytest tests/agent/test_minimax_provider.py -qpython -m pytest tests/gateway/test_fast_command.py -qclient.messages.create(..., speed="fast")andclient.messages.stream(..., speed="fast")raiseTypeErrorbuild_anthropic_kwargs(..., fast_mode=True)succeeds and sends"speed": "fast"in the JSON bodyAdditional note:
python -m pytest tests/ -qcurrently fails on this worktree with unrelated pre-existing failures outside this PR's scope; the focused suites above are green.Checklist
Code
fix(scope):,feat(scope):, etc.)pytest tests/ -qand all tests passDocumentation & Housekeeping
docs/, docstrings) — or N/Acli-config.yaml.exampleif I added/changed config keys — or N/ACONTRIBUTING.mdorAGENTS.mdif I changed architecture or workflows — or N/AScreenshots / Logs
Manual SDK verification on
anthropic==0.93.0:Patched adapter verification: