[KongchangAI]
· 2 min read· 1,356 words

AI-Written Plugin: Porting Token Economizer's Cost-Saving Mechanics to DeepSeek Harness

AI-Written Plugin: Porting Token Economizer's Cost-Saving Mechanics to DeepSeek Harness

AI ports the Token Economizer plugin to DeepSeek Harness, using three mechanisms to save tokens for coding agents.

Token Economizer is an open-source plugin that reduces token waste for coding agents, originally serving tools like Claude Code. A Bilibili creator demonstrated an AI-written version ported to DeepSeek Harness. The port shares design ideas but not code, and is open-sourced under MPL 2.0. Its core mechanisms include: Micro Skills, which turns repeated failures into repository facts injected into sessions via a "three confirmations, two overturns" rule; Loop Guard, which gives tiered hints on looping failures but never forces interruption; and tool trimming, which only records unused tools and offers a suggestion checklist without automatic deletion. Engineering-wise it has zero dependencies, no networking, and zero extra model calls; all nineteen offline self-tests passed, and Loop Guard triggered once in a real scenario. The code is AI-written but reviewable line by line, embodying an "assist without overstepping" design principle. Its effectiveness still needs validation from more users.

How a Plugin That Saves Tokens for Coding Agents Got Ported to DeepSeek Harness by AI

Coding agents have limited context windows, but waste often happens silently. An open-source plugin called Token Economizer attempts to solve this problem at the mechanical level. It originally served Claude Code, Codex, Copilot CLI, and Pi, and a Bilibili creator demonstrated an AI-written port that brings the same cost-saving approach into DeepSeekAd Harness.

This isn't a simple "install"—it's a port. In the video, the creator explicitly states that the two projects share ideas and domain values but not code. This means the original plugin's design logic had to be re-understood and then rebuilt within DeepSeek Harness's plugin system. The entire coding process was done by AI, and every line can be manually reviewed, ultimately open-sourced under the MPL 2.0 license.

The same failure confirmed across three different sessions becomes a repository fact

Three Core Mechanisms: From "Rediscovery" to "Loop Protection"

Token Economizer's design revolves around three specific problems, each corresponding to one mechanism.

Micro Skills: Letting Failures Settle into Repository Facts

One of the most common wastes for coding agents is "rediscovery." In the same repository, the fifth session is still re-figuring out the same things: what the build command is, how to run tests, which environment variables are needed. This information should have been remembered, yet it has to be derived from scratch every time.

Micro Skills handles this with restraint: when the same failure is confirmed across three different sessions, it becomes a repository fact and is injected into context at the start of a session. Conversely, if that fact is overturned twice by new sessions, it is discarded. This "three confirmations, two overturns" rule avoids misjudgment from a single偶然 event while also preventing outdated knowledge from lingering.

What is a "repository fact"

A repository fact refers to verifiable objective information about a code repository, such as build commands, test commands, dependency environment variables, code style conventions, etc. It differs from "model memory": model memory is implicit and generalized across projects, while repository facts are explicit and bound to a specific repository. Token Economizer writes confirmed failure experiences as repository facts and injects them into the context of subsequent sessions, essentially giving the agent a continuously updated "project manual." The benefit is that information is auditable, overturnable, and versionable, avoiding the model having to guess anew in each session.

Loop Guard: Identify Loops, But Never Make Decisions for You

An agent stuck retrying the same error is another major token drain. Loop Guard intervenes in tiers: the same failure appearing three times in the same round triggers a one-time redirect hint; six times, and it only reminds you that you can stop.

You might not have noticed, but it never interrupts the round for you. This design choice involves a clear trade-off—automatic interruption could kill an exploration the agent is in the middle of, while tiered hints return the final decision to the user. According to the creator, this mechanism has triggered once in a real scenario—it's not just theory.

The second mechanism, Loop Guard

Loop Detection and Tiered Intervention

Loop detection is typically implemented by comparing the similarity of consecutive actions or tool-call sequences. Loop Guard uses a rule based on failure counts: the same failure appearing three or six times in the same round triggers different levels of hints. This tiered intervention design draws on the concept of "progressive reminders" in human-computer interaction—lower-level hints only offer redirect suggestions, while higher-level hints explicitly recommend stopping. The key is that it does not automatically interrupt, because automatic interruption could break legitimate exploration the agent is conducting (e.g., temporary failures during multi-step debugging). Leaving the final decision to the user preserves automation efficiency while avoiding over-intervention.

Tool Trimming: Only Give Suggestions, Don't Act

Every tool's definition is sent along with the request, even if the project has never used that tool. Tokens are wasted for nothing.

Tool trimming's approach is: only record tools that were "loaded but not used," list them as a suggestion checklist, but do not automatically delete them. This restraint is also intentional—automatically removing tools could leave the agent lacking necessary capabilities in subsequent tasks, whereas a suggestion checklist lets humans decide which tools are truly redundant for this repository.

The third mechanism, tool trimming

Tool Definitions and Context Consumption

In LLM-based agent systems, every available tool requires its name, description, and parameter schema to be included in the request, and this content consumes context window tokens. Even if a tool is never called, its definition is still sent, causing waste. The tool trimming mechanism records "loaded but unused" tools to generate a redundant tool list. It does not automatically delete tools because changes to the toolset could affect the agent's subsequent capabilities—for example, a tool not useful for the current task may be essential for the next. The suggestion checklist lets humans judge which tools are truly redundant for the repository, balancing token savings and capability preservation.

Engineering Implementation: Zero Dependencies, Zero Networking, Zero Extra Model Calls

From an engineering perspective, this port has several noteworthy characteristics.

The installation process is lightweight: clone the repository, add the directory in the plugin panel. Zero dependencies means no additional package management; no networking means all logic runs locally and state is written only locally. For teams concerned about data privacy or running in restricted environments, these constraints lower the adoption barrier.

More critically, there are zero extra model calls. A token-saving plugin that itself needs to call a model to make decisions would be self-contradictory. Token Economizer's three mechanisms are all based on rules and counting, introducing no extra inference overhead.

On validation, the creator mentions that all nineteen offline self-tests passed, and Loop Guard triggered once in real use. These numbers are small in scale, but at least show the mechanisms are not spinning idle.

All nineteen offline self-tests passed; Loop Guard triggered once in real use

MPL 2.0 License and Open-Source Review

MPL 2.0 (Mozilla Public License 2.0) is a weak copyleft license that requires modifications to source code files covered by the license to be made public under the same license, but allows combination with other code (including proprietary code) into larger works. For this plugin, choosing MPL 2.0 means any derivative work based on its code must make the modified portions public, which encourages community review and contribution while allowing the project to be integrated into broader toolchains without forcing the entire toolchain to open-source. Combined with the practice of "code written by AI but reviewable line by line," MPL 2.0 provides a legal basis for manual review and subsequent improvements.

What It Means for Code to Be AI-Written Yet Reviewable Line by Line

One special aspect of this project is that the code is AI-written. In today's discourse, "AI-written code" often carries an implication of questionable quality. But the creator emphasizes that "every line can be reviewed"—this actually shifts the question from "who wrote it" to "whether it is reviewable."

For a plugin with uncomplicated logic, zero dependencies, and no networking, line-by-line review is feasible. This also offers a reference model for similar small tool development: AI handles coding, humans handle review and gatekeeping, and the result is released under an open-source license so more people can participate in validation.

A note: current information about this port mainly comes from a single-source video introduction. Its actual performance across different repositories and workflows still needs more user feedback for cross-validation.

Who Should Pay Attention to This Plugin

If you frequently use DeepSeek Harness for coding tasks and notice the agent repeatedly fumbling with build commands, going in circles on the same error, or loading a large number of unused tools, this plugin's three mechanisms directly address these pain points.

Its restrained design is also worth learning from: Micro Skills' confirmation and overturn rules, Loop Guard's tiered hints rather than forced interruption, tool trimming's suggestions rather than automatic deletion—these trade-offs reflect a shared principle: assist without overstepping. For developers designing their own agent toolchains, this design thinking itself may be more valuable than the plugin code.

#Token Economizer#DeepSeek Harness#coding agent#token saving#AI-written code#open-source plugin#MPL 2.0
Share:

Related articles