Skip to content

fix(agent): route Anthropic fast mode via extra_body - #8013

Closed
marcelruhf wants to merge 1 commit into
NousResearch:mainfrom
marcelruhf:fix/anthropic-fast-mode-pr
Closed

fix(agent): route Anthropic fast mode via extra_body#8013
marcelruhf wants to merge 1 commit into
NousResearch:mainfrom
marcelruhf:fix/anthropic-fast-mode-pr

Conversation

@marcelruhf

@marcelruhf marcelruhf commented Apr 12, 2026

Copy link
Copy Markdown

What does this PR do?

Fixes the native Anthropic fast-mode request shape introduced in #7037.

/fast fast stores {"speed": "fast"} in request_overrides, and the Anthropic adapter was forwarding that as a top-level speed= kwarg. On the stable Anthropic Python SDK, client.messages.create() and client.messages.stream() do not accept top-level speed; both surfaces accept undocumented body params through extra_body. The old shape fails locally with TypeError before a request is sent.

This PR keeps the fix at the adapter boundary:

  • route fast mode as extra_body["speed"] = "fast"
  • preserve the fast-mode beta header
  • keep third-party Anthropic-compatible endpoints excluded from fast mode

extra_body is the right fix because build_anthropic_kwargs() already owns Anthropic-specific request shaping, and the SDK exposes extra_body on 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

  • 🐛 Bug fix (non-breaking change that fixes an issue)
  • ✨ New feature (non-breaking change that adds functionality)
  • 🔒 Security fix
  • 📝 Documentation update
  • ✅ Tests (adding or improving test coverage)
  • ♻️ Refactor (no behavior change)
  • 🎯 New skill (bundled or hub)

Changes Made

  • agent/anthropic_adapter.py: move fast-mode speed from a top-level kwarg to extra_body, with SDK-compatibility notes in the docstring/comments
  • tests/agent/test_anthropic_adapter.py: add a real SDK-boundary regression test using anthropic + httpx.MockTransport to verify "speed": "fast" is serialized into the JSON body
  • tests/cli/test_fast_command.py: update fast-mode assertions to expect extra_body, and keep the third-party endpoint exclusion coverage

How to Test

  1. Activate the project environment:
    source /home/mruhf/.hermes/hermes-agent/venv/bin/activate
  2. Run the focused regression suites:
    python -m pytest tests/cli/test_fast_command.py -q
    python -m pytest tests/agent/test_anthropic_adapter.py -q
    python -m pytest tests/cli/test_fast_command.py tests/agent/test_anthropic_adapter.py -q
    python -m pytest tests/agent/test_minimax_provider.py -q
    python -m pytest tests/gateway/test_fast_command.py -q
  3. Verify the old and new request shapes against the current Anthropic SDK:
    • old shape: client.messages.create(..., speed="fast") and client.messages.stream(..., speed="fast") raise TypeError
    • patched shape: build_anthropic_kwargs(..., fast_mode=True) succeeds and sends "speed": "fast" in the JSON body

Additional note:

  • python -m pytest tests/ -q currently fails on this worktree with unrelated pre-existing failures outside this PR's scope; the focused suites above are green.

Checklist

Code

  • I've read the Contributing Guide
  • My commit messages follow Conventional Commits (fix(scope):, feat(scope):, etc.)
  • I searched for existing PRs to make sure this isn't a duplicate
  • My PR contains only changes related to this fix/feature (no unrelated commits)
  • I've run pytest tests/ -q and all tests pass
  • I've added tests for my changes (required for bug fixes, strongly encouraged for features)
  • I've tested on my platform: Linux 6.8.0-106-generic

Documentation & Housekeeping

  • I've updated relevant documentation (README, docs/, docstrings) — or N/A
  • I've updated cli-config.yaml.example if I added/changed config keys — or N/A
  • I've updated CONTRIBUTING.md or AGENTS.md if I changed architecture or workflows — or N/A
  • I've considered cross-platform impact (Windows, macOS) per the compatibility guide — or N/A
  • I've updated tool descriptions/schemas if I changed tool behavior — or N/A

Screenshots / Logs

Manual SDK verification on anthropic==0.93.0:

Messages.create() got an unexpected keyword argument 'speed'
Messages.stream() got an unexpected keyword argument 'speed'

Patched adapter verification:

response_text ok
body_speed fast
header_has_fast_beta True
top_level_speed_in_kwargs False

@teknium1

Copy link
Copy Markdown
Contributor

Thanks for the careful analysis and the SDK-boundary regression test, @marcelruhf! This fix was independently implemented on main before your PR could be reviewed.

This is an automated hermes-sweeper review.

  • The identical fix (kwargs.setdefault("extra_body", {})["speed"] = "fast") landed in commit cdd44817f on Apr 13 2026 — one day after this PR was opened.
  • It shipped in release v2026.4.16.
  • The fix lives at agent/anthropic_adapter.py line 1704, exactly as proposed here.
  • tests/cli/test_fast_command.py was also updated in that commit with extra_body assertions covering the same regression.

The tests/agent/test_anthropic_adapter.py SDK-boundary test using httpx.MockTransport is the one novel addition here that didn't make it to main — if you'd like to contribute that test in isolation it would still be welcome as a follow-up.

@teknium1 teknium1 closed this Apr 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants