dsh-bailian-gold: DSH Agent Preset for Prefix Caching Optimization on Alibaba Cloud Bailian

Preface

When connecting Alibaba Cloud Model Studio (Bailian) in DeepSeek Harness (DSH), the common practice is to reuse the standard preset designed for the official DeepSeek API. That route benefits from the systemPromptUpdate: in-history fallback on official endpoints: when the system prompt changes, it is appended to the history rather than rewriting the beginning of the conversation. However, for the OpenAI-compatible shell and Anthropic endpoints on Bailian, the middle layer (pi-ai) does not expose equivalent capabilities for custom routes. Consequently, the standard preset tends to allow system prompt rewriting, causing the implicit prefix cache to fail entirely. In long conversations, input tokens are repeatedly billed at full price, whereas Bailian offers significant discounts for cache hits (approximately 20% for implicit, 10% for explicit), resulting in a cost gap of several multiples.

Below is an introduction to the community plugin Bailian Gold Mode (dsh-bailian-gold), maintained by SZYTree0312. It is an agent preset attached to DSH, not a standalone runtime or a fork. Its goal is to guarantee prefix stability on the harness side, treating prefix cache hit rate as a first-class metric rather than simply minimizing token count.

What is this

In short: It is a DSH agent preset optimized for prefix caching specifically for the Alibaba Cloud Bailian route. Models such as Qwen, DeepSeek, Kimi, GLM, and MiniMax share the same preset; model differences are handled via the models and modelPolicies of the Host-level route.

The name is a play on the idiom “Bailian chenggang” (refining a hundred times to make steel): “Bailian” refers to the platform, and “Cheng Jin” (making gold) refers to the result—repeatedly refining the conversation prefix to save on input costs billed at the hit rate. The upstream harness baseline needs to be pinned to 0.2.0-rc.2 (upstream explicitly states there will be breaking changes).

Plugin directory page: dsh-bailian-gold. Source code and documentation: GitHub — SZYTree0312/dsh-bailian-gold. Categorized under model inference; License MIT (see repository package.json).

Core Principles and Strategies

Bailian bills cache-hit inputs at a discount: approximately 20% for implicit hits and 10% for explicit hits of the input unit price. Therefore, the preset’s design is contrary to common practices in other harnesses, summarized in three points:

  1. The tool catalog remains fixed throughout, without trimming or extension by phase (consistent with the upstream plan-mode principle that “the tool catalog remains unchanged across modes to benefit the request-cache,” generalized to the entire session).
  2. History is append-only; compression only performs targeted range replacement, and system prompts never enter the compression zone.
  3. Dynamic state is always pushed to the tail, never injected at the beginning of the system prompt.

The README records tests from 2026-09-30: sending a prefix of approximately 10391 tokens three consecutive times on the same instance resulted in cached 10240 starting from the second request for the OpenAI shell (implicit cache), and read 10377 starting from the second request for the Anthropic endpoint (explicit cache); both caching mechanisms worked. Full data is available in the repository at docs/verify-prefix-cache.md.

This has the same form as Liang Shen Mode (both are installed via @deepseek-ai/dsh-agent-preset using bundle patches into the profile), but the mechanisms are opposite: Liang Shen Mode anchors the first turn by switching the tool catalog, which breaks the prefix multiple times during long Bailian sessions; this preset achieves a similar goal using “resident tool catalog + first-turn output budget bootstrapMaxTokens + tail-anchored instructions” without sacrificing cache.

Preset Contents and Route Highlights

After installing the plugin, the preset comes with two parts. Generally, there is no need to manually layer the routes from examples/ on top (unless you modify the profile yourself):

Segment Layer Function
insert · preset-bailian-gold Agent (preset) Tool surface, prompts, compression strategy
override · llm-pi-ai Host (profile patch) Model routing: Fixed to Anthropic endpoint

The second segment overrides the llm-pi-ai in the base by ID, changing it to api: anthropic-messages, path /apps/anthropic, and writing contextWindow: 991808.

Route names must align: The provider identifier takes the route name of llm-pi-ai in the profile. The documentation example uses aliyun (not dashscope). Writing it incorrectly will not cause an error, but modelPolicies will silently fail. The modelPolicies.provider and summarizationProvider within the preset must be consistent with this.

contextWindow is a critical number. If not filled, it falls back to defaultContextWindow 262144, with a compression trigger point of approximately 163840. Normal coding sessions may trigger compaction, causing the prefix cache to fail entirely due to replace. When opened to the maximum input of the official standard mode for Qwen3.8-Flash, 991808, the trigger point is approximately 893504, making it unlikely for regular sessions to trigger compression. The README explicitly states: Not filling contextWindow is equivalent to abandoning the main benefits of this preset. At the same time, do not set maxTokens for the model, otherwise it will lower messageBudget and trigger compression earlier.

Regarding protocol, this preset only uses the Anthropic endpoint (/apps/anthropic), supporting both implicit caching and cache_control explicit breakpoints. The OpenAI-compatible shell only supports implicit caching and is available as an alternative in examples/aliyun-route.patch.yml. For long conversations (approx. N ≥ 4 rounds repeating the same stable prefix), explicit caching is more economical than implicit; the accompanying example is examples/aliyun-anthropic-route.patch.yml. The validity period of explicit cache is fixed at 5 minutes (reset upon hit).

Version Compatibility

The dividing line is dsh 0.1.7-rc.1:

dsh Version Mechanism Usage Path
0.1.7-rc.1 and later (including 0.2.0-rc.x) @deepseek-ai/dsh-agent-preset plugin lines presets/bailian-gold.patch.yml
0.1.5-rc.1 ~ rc.3 @deepseek-ai/dsh-agent-presets scanning ~/.dsh/.agent-presets/ compat/0.1.5/ (see compat/README.md)

Installation and Activation

Prerequisites: The profile already has the aliyun route for llm-pi-ai, and it is recommended to use the configuration for the Anthropic endpoint (consistent with the preset’s built-in override; public endpoints suffice, no dedicated instance needed).

  1. Install the plugin (command from the repository README):
dsh plugin --profile web add github:SZYTree0312/dsh-bailian-gold
  1. Select Bailian Gold Mode in the DSH session preset selector.

  2. If you need to switch back to the OpenAI shell, change the instance domain, or add/remove models, you can override it again in your profile’s cordis.patch.yml or a --patch overlay (this layer applies after the preset).

Uninstallation:

dsh plugin --profile web remove dsh-bailian-gold

Typical Usage and Cost Levers

First-class metric: Observe the prefix cache hit rate, rather than just looking at total tokens.

Three cost levers (README sorts by impact):

  1. Switch from Implicit to Explicit: The more rounds the stable prefix repeats, the more cost-effective explicit caching becomes (break-even point is approx. N ≥ 4); asymptotically, it can save about 50% of input-side cache-related fees.
  2. Do not trigger compression: Rely on the correct contextWindow and compression strategy to avoid actively interrupting the prefix.
  3. Thinking output: Some Bailian models have thinking enabled by default, where the chain of thought counts as output tokens; output prices are much higher than cache-hit input prices. See Section 4 of docs/verify-prefix-cache.md for control methods (some configuration syntax is noted as unverified in the README).

If you maintain your own profile, you can merge the route snippet from examples/aliyun-anthropic-route.patch.yml into cordis.patch.yml and verify the aliyun route name and contextWindow: 991808.

Use Cases and Notes

Suitable for: Developers who connect to Bailian via DSH for long-term use, have many conversation turns, and wish to utilize prefix cache discounts; the same preset can cover multi-vendor models on Bailian, requiring only adjustments to models and modelPolicies at the Host layer.

Not suitable for or things to know:

  • Scenarios that rely on the standard behavior of the official DeepSeek API and do not run on Bailian do not need to switch to this preset.
  • The README notes: Partial live validation—prefix hits have been tested and passed with real requests; the preset author states they have not yet run a complete real conversation, so whether the tool catalog remains unchanged throughout and the actual hit rate are pending real-world testing.
  • DSH plugins run with the permissions of the current dsh process; before installation, please read the repository source code and MIT license yourself to ensure the patch content matches your local profile routing and key configurations.
  • The community directory SkillHub is an independent site and has no official affiliation with DeepSeek or Hialogy; the DSH ecosystem philosophy is “everything is a plugin.” This preset is a community contribution, not an official built-in item in the app store.

Conclusion

Bailian Gold Mode aligns harness strategies with Bailian’s billing structure: fixed tool surface, append-only history, delaying compression as much as possible, and defaulting to the Anthropic endpoint to accommodate explicit caching. If you are already using Bailian for model inference on DSH, you can install it using the command above and switch to Bailian Gold Mode in the presets, while verifying the aliyun route and contextWindow.

  • Directory page: https://www.skillhub.cn/plugins/SZYTree0312/dsh-bailian-gold
  • GitHub: https://github.com/SZYTree0312/dsh-bailian-gold
羽毛球分组比赛记分
小程序二维码

欢迎使用《羽毛球分组比赛记分》微信小程序

Xiaoye