Skip to content

feat(cache): enable Anthropic cache_control for DeepSeek on OpenCode (#24617) - #24639

Open
0xsir0000 wants to merge 1 commit into
NousResearch:mainfrom
0xsir0000:feat/deepseek-cache-control
Open

0xsir0000 wants to merge 1 commit into
NousResearch:mainfrom
0xsir0000:feat/deepseek-cache-control

Conversation

@0xsir0000

Copy link
Copy Markdown
Contributor

Summary

OpenCode Go is a gateway that implements cache_control at its own level, not per model — the same envelope-layout marker injection that makes Qwen on opencode-go pay the cached-read rate also works for DeepSeek models on the same gateway. The model switcher reports \$0.01/M cache read pricing for deepseek-v4-pro on opencode-go, confirming gateway-side cache support. Without markers Hermes serves 0% cache hits and re-bills the full prompt on every turn.

Fix

Extend the alibaba-family branch in _anthropic_prompt_cache_policy (run_agent.py:3570) to accept DeepSeek models alongside Qwen on the four opencode / opencode-zen / opencode-go / alibaba providers. The wire format (OpenAI chat completions) and marker layout (envelope, not native) are identical to the existing Qwen path — this is purely an expansion of the model whitelist.

model_is_qwen = "qwen" in model_lower
model_is_deepseek = "deepseek" in model_lower
provider_is_alibaba_family = provider_lower in {
    "opencode", "opencode-zen", "opencode-go", "alibaba",
}
if provider_is_alibaba_family and (model_is_qwen or model_is_deepseek):
    return True, False

Test plan

  • test_deepseek_on_opencode_go_caches_with_envelope_layout — the reported case (deepseek-v4-pro on opencode-go) returns (True, False).
  • test_deepseek_on_opencode_zen_caches — same marker layout on opencode-zen.
  • test_deepseek_on_openrouter_not_affected — DeepSeek via OpenRouter still falls through to its own caching arrangement (no regression for non-alibaba-family providers).
  • All 39 existing tests in tests/run_agent/test_anthropic_prompt_cache_policy.py still pass.

Risk

Zero. If the gateway doesn't honor cache for a specific DeepSeek model, the markers are silently ignored. Non-DeepSeek/non-Qwen models on opencode-go (GLM, Kimi) keep falling through to (False, False) as before — verified by the existing test_non_qwen_on_opencode_go_does_not_cache and test_kimi_on_opencode_go_does_not_cache.

Fixes #24617

…ousResearch#24617)

OpenCode Go is a gateway that implements `cache_control` at its own
level, not per model. The same envelope-layout marker injection that
makes Qwen on opencode-go pay the cached-read rate also works for
DeepSeek models on the same gateway — the model switcher reports
`$0.01/M cache read` pricing for `deepseek-v4-pro` on opencode-go,
confirming gateway-side cache support. Without markers Hermes serves
0% cache hits and re-bills the full prompt on every turn (~75% cost
overhead on 300K+ token conversations).

Extend the alibaba-family branch in `_anthropic_prompt_cache_policy`
to accept DeepSeek models alongside Qwen on the four
opencode/opencode-zen/opencode-go/alibaba providers. The wire format
(OpenAI chat completions) and marker layout (envelope, not native)
are identical to the existing Qwen path; this is purely an expansion
of the model whitelist.

Tests cover deepseek-v4-pro on opencode-go (the reported case),
deepseek-v3.5 on opencode-zen, and confirm DeepSeek via OpenRouter
still falls through to its own caching arrangement.

Fixes NousResearch#24617
@alt-glitch alt-glitch added type/feature New feature or request P3 Low — cosmetic, nice to have comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint labels May 13, 2026

@teknium1 teknium1 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for isolating the cache-policy gap. Current main still falls through to (False, False) for DeepSeek because agent/agent_runtime_helpers.py:1629-1639 only recognizes Qwen, and agent/conversation_loop.py:889-894 shows that a true policy result is what injects the request cache markers.

Problems

  • The changed predicate at run_agent.py:3582 also enables DeepSeek for direct alibaba. The linked issue supports OpenCode Zen/Go, but current main's Alibaba catalog contains Qwen, Kimi, GLM, and MiniMax entries—not DeepSeek (hermes_cli/models.py:491-502). Keep the direct-Alibaba allowance specific to Qwen unless DeepSeek support there is independently verified.
  • The target function has moved: run_agent.py:1358-1368 now forwards to agent/agent_runtime_helpers.py after c42fa94.

Suggested changes

  • Salvage the policy change into agent/agent_runtime_helpers.py, separating the Qwen four-provider condition from a DeepSeek OpenCode-only condition.
  • Add a negative direct-Alibaba DeepSeek policy test alongside the OpenCode positives.

Automated hermes-sweeper review.

Comment thread run_agent.py
"opencode", "opencode-zen", "opencode-go", "alibaba",
}
if provider_is_alibaba_family and model_is_qwen:
if provider_is_alibaba_family and (model_is_qwen or model_is_deepseek):

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This combines DeepSeek with Qwen across direct alibaba, although the linked report establishes OpenCode Zen/Go only and main's curated Alibaba catalog has no DeepSeek entry (hermes_cli/models.py:491-502). Keep Qwen on all four providers, but scope DeepSeek to the OpenCode provider IDs and add a negative direct-Alibaba test.

@teknium1 teknium1 added sweeper:risk-caching Sweeper risk: may break/degrade prompt caching or cache-key stability (invariant) sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades sweeper:blast-contained Sweeper blast radius: contained — one narrow path / opt-in / few users 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 sweeper:blast-contained Sweeper blast radius: contained — one narrow path / opt-in / few users sweeper:risk-caching Sweeper risk: may break/degrade prompt caching or cache-key stability (invariant) sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades type/feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Prompt caching: add DeepSeek models to cache_control whitelist for OpenCode Go

3 participants