Skip to content

Fixes: Hermes fallback issue with kimi-for-coding -- anthropic_messages endpoint returning 404 - #33276

Open
buxue2025 wants to merge 1 commit into
NousResearch:mainfrom
buxue2025:kimi-fallback-fix
Open

Fixes: Hermes fallback issue with kimi-for-coding -- anthropic_messages endpoint returning 404#33276
buxue2025 wants to merge 1 commit into
NousResearch:mainfrom
buxue2025:kimi-fallback-fix

Conversation

@buxue2025

Copy link
Copy Markdown

Problem statement:
In Hermes-Agent, when configured primary model fails and Hermes-Agent falls back to secondary, here my configuration is kimi-for-coding, the fallback path uses chat_completions (OpenAI client) against api.kimi.com/coding, which speaks Anthropic Messages → HTTP 404.

Direct provider switches (hermes chat --provider kimi-coding) work correctly because it calls determine_api_mode() / _detect_api_mode_for_url().

Root Cause
Try_activate_fallback() in agent/chat_completion_helpers.py has inline api_mode heuristics that miss api.kimi.com/coding (Anthropic Messages).

Fix
Add a final else branch that calls _detect_api_mode_for_url() as a fallback detector, matching the behavior of explicit model switches.

Verification
- Kimi fallback: api_mode = anthropic_messages ✅
- OpenAI fallback: api_mode = codex_responses ✅
- DeepSeek fallback: api_mode = chat_completions ✅

  • [ x ] 🐛 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)

The inline api_mode heuristics in try_activate_fallback() missed
Kimi's api.kimi.com/coding endpoint, which speaks Anthropic Messages.
When falling back to kimi-coding, the agent used chat_completions
(OpenAI client) against the Anthropic endpoint → HTTP 404.

Direct provider switches already worked because they call
determine_api_mode() / _detect_api_mode_for_url(), which correctly
identifies api.kimi.com/coding as anthropic_messages.

Add a final else-branch that calls _detect_api_mode_for_url() as a
fallback detector, matching the behavior of explicit model switches.

Fixes: fallback to kimi-coding returning 404 after primary model failure
@alt-glitch alt-glitch added type/bug Something isn't working comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint provider/kimi Kimi / Moonshot P3 Low — cosmetic, nice to have labels May 27, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Competes with open #25706 (same kimi fallback api_mode fix). Note: #17107 argues Kimi coding is NOT Anthropic Messages-compatible — needs verification.

@teknium1 teknium1 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for tracing the fallback-specific transport selection path. The bare /coding premise is still present on current main: agent/chat_completion_helpers.py:1461-1497 defaults to chat_completions without a Kimi /coding branch.

Problems

  • The added detector call at agent/chat_completion_helpers.py:1037 imports _detect_api_mode_for_url(), whose current rule at hermes_cli/runtime_provider.py:137-138 classifies every api.kimi.com URL containing /coding as anthropic_messages. The linked #17107 documents that /coding/v1 is OpenAI-compatible, so this would select the wrong transport for that fallback URL.
  • The PR changes only production code and adds no fallback regression coverage. Existing tests/run_agent/test_provider_fallback.py:185-212 covers native Anthropic fallback routing, not the Kimi bare-route versus /coding/v1 distinction.

Suggested changes

  • Narrow and test the Kimi URL rule so bare /coding selects Anthropic Messages while /coding/v1 remains OpenAI-compatible; keep the runtime and fallback paths aligned.
  • Add fallback tests for both endpoint forms.

Automated hermes-sweeper review.

# Kimi's ``api.kimi.com/coding`` (Anthropic Messages) that
# the inline heuristics above miss. See #22548.
from hermes_cli.runtime_provider import _detect_api_mode_for_url
detected = _detect_api_mode_for_url(fb_base_url)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_detect_api_mode_for_url() currently returns anthropic_messages for any api.kimi.com URL containing /coding, including /coding/v1 (hermes_cli/runtime_provider.py:137-138). The linked #17107 identifies /coding/v1 as OpenAI-compatible, so please narrow the shared rule and add bare /coding versus /coding/v1 fallback coverage before using it here.

@teknium1 teknium1 added sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform labels Jul 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint P3 Low — cosmetic, nice to have provider/kimi Kimi / Moonshot sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants