dsh-agent-frugality
Agent 与会话 活跃维护

dsh-agent-frugality

gongyijie85/dsh-agent-frugality

提供面向DeepSeek Harness多智能体场景的节俭防御能力,支持读账本去重、抗压缩规则、完成门控、低成本审查通道四项核心特性,可有效降低多智能体协作的冗余调用成本,避免无效资源消耗,提升整体运行效率。

0
Stars 标星
0
Forks 分支
0
Watchers 关注
0
Open Issues
JavaScript
主要语言
MIT
开源协议
76 KB
仓库大小
3 个月前
最后推送
一键安装扩展 / 插件指令
dsh plugin --profile web add github:gongyijie85/dsh-agent-frugality
git clone https://github.com/gongyijie85/dsh-agent-frugality.git
git clone git@github.com:gongyijie85/dsh-agent-frugality.git
README.md main

dsh-agent-frugality

English | 中文

npm version
GitHub
License: MIT
Tests
Zero deps

A DeepSeek Harness defense plugin against three mechanism-level failure modes of multi-agent systems:
read-ledger dedup · compaction-immune rules · mechanical completion gate · cheap-review lane.
Zero external dependencies — inject and go.

📐 Spec: docs/SPEC.md · 📋 Tickets: TICKETS.md · 📝 Changelog: CHANGELOG.md

Why

Three failure modes are real and independently evidenced:

Failure Evidence This plugin's defense
Subagent duplicate reads (no shared memory → token waste) Claude Code #46968, #45660; Jack Maguire: subagents account for most token cost in long runs, 70–90% recoverable read-ledger content-hash ledger + "already read" sheet injection
Prompt decay (soft rules fade, compaction erases them) Anthropic Building effective agents: cost tradeoffs come from architecture, not wording immutable-core rules in a compaction-immune prompt section + completion-gate mechanical gate
Expensive-model fallacy (costly models are worse reviewers) Anthropic multi-agent research system: gains come from token budget; RouteLLM/FrugalGPT consensus review-lane cheap-model independent review

This plugin does not forbid multi-agents — it makes the waste visible and the behavior mechanically bounded; measure first, intervene second (DEDUP off by default).

⚠️ Research-integrity note: this plugin does not endorse the headline numbers of the "$85K multi-agent experiment" (54.7% duplicate reads / 243→311 commits / Opus 23.9% — verified to have no primary source; they are a generated-summary hallucination; verification report: research/01-primary-source.md). It targets the mechanism problems themselves, which do have independent evidence.

Install

Published (v0.1.0):

# GitHub channel (primary; marketplace ingestion is topic-driven)
dsh plugin add github:gongyijie85/dsh-agent-frugality

# npm channel
npm install dsh-agent-frugality

# Local dev (runtime injection, no restart)
dev_inject_plugin D:\plugins\dsh-agent-frugality
# Uninstall
dev_uninject_plugin dsh-agent-frugality

How it works

tool calls ──→ tools/result ──→ [read-ledger] SHA-1 ledger → JSONL persistence
                      │                │
                      └─ 2nd+ same content ──→ [dedup-replace] summary swap (DEDUP=1)
system-prompt/assemble ──→ [immutable-core] frugality-rules (compaction-immune) + frugality-read-cache
agent/turn-stopping ──→ completion claim without gate proof ──→ steer back (≤2)
frugality_gate / frugality_review / frugality_ledger ──→ three tools

Tools

Tool Purpose
frugality_ledger Read ledger (per-agent reads/dups/bytes, dup rate, gate & review counters; JSONL-restored) — baseline first, then decide on intervention
frugality_gate Completion gate: claim required; verify command must exit 0 (host-configured only)
frugality_review Cheap-review lane: independent review on a CHEAP-class model (quick/deep), verdict + findings

Configuration (env vars — full table in docs/SPEC.md §6)

Variable Default Meaning
DSH_FRUGALITY_DEDUP 0 1 = replace 2nd+ identical read with a summary
DSH_FRUGALITY_GATE 1 0 = disable completion gate
DSH_FRUGALITY_GATE_MAX 2 max gate objections (anti-loop)
DSH_FRUGALITY_VERIFY empty default verify command (npm test; exit 0 = pass)
DSH_FRUGALITY_ALLOW_ARG_VERIFY 0 1 = accept tool-arg verify (default ignored — anti-RCE, SPEC §7.1)
DSH_FRUGALITY_REVIEW_MODEL auto review model id; auto = CHEAP family
DSH_FRUGALITY_RULES builtin rules file (≤8KB)
DSH_FRUGALITY_LEDGER_CAP 30 read-cache sheet max entries
DSH_FRUGALITY_WORKDIR cwd gate verify command cwd
DSH_FRUGALITY_READ_PATTERNS builtin extra read-tool substrings (comma-separated)

Layout

lib/index.js       host assembly (hooks / tool registration / config / persistence)
lib/core.js        pure functions & constants (18 unit tests green)
test/core.test.mjs node:test, zero-dependency
docs/SPEC.md       spec (FR / NFR / security model §7 / API contract §8 / acceptance §9)
docs/MARKETPLACE.md marketplace ingestion kit
TICKETS.md         productization checklist (phase 1-5)
CHANGELOG.md       release notes
LICENSE            MIT

Test & verify

node --test test/core.test.mjs   # 18/18
node --check lib/index.js && node --check lib/core.js

Design principles

  1. Measure first, intervene second — ledger on, DEDUP off until your baseline shows net gain.
  2. Mechanical bounds > prompts — rules land in tool-result errors / turn-stopping objections; prompts only echo (the rules section itself is compaction-immune).
  3. Only fill real gaps — shared memory via dsh-memory-vault, routing via dsh-model-router, task gates via dsh-agent-teams; this plugin adds read-ledger, host completion gate, cheap-review lane.
  4. Zero deps — node built-ins + lib/core.js; JS-direct like dsh-mode-boost.

Logs

$DSH_HOME/agent-frugality.log (JSONL events) and $DSH_HOME/agent-frugality-ledger.jsonl (ledger persistence).

Experiment data (daily-use-as-experiment)

The plugin is instrumented by design: every real session feeds the ledger, and periodic snapshots are published to the repo as evidence.

node scripts/experiment-report.mjs   # -> docs/experiments/YYYY-MM-DD-snapshot.{json,md}
  • First snapshot (2026-08-29): 34 reads, 5.9% duplicate rate, 93KB, gate 3 pass / 3 objections, review lane 1×9 findings, 0 plugin errors
  • Exp-3 done (2026-08-29): cheap lane (flash) 81.8% recall @ $0.033 with 1.65× per-dollar hits vs strong; strong (v4) 100%/0 FPs @ $0.067 → dual-lane policy validated (results)
  • Thresholds & ops loop: docs/EXPERIMENT.md ("运营模式" section)

Release & ingestion status (v0.1.0, 2026-08-29)

  • [x] GitHub: github.com/gongyijie85/dsh-agent-frugality (main + tag v0.1.0, topics: dsh-plugin deepseek-harness multi-agent)
  • [x] npm: dsh-agent-frugality@0.1.0
  • [x] Topics set (dsh-plugin → auto-synced by AwesomeHou marketplace and dsh-market)
  • [ ] awesome-dsh-plugin curated registry submission (kit in docs/MARKETPLACE.md) — required for one-click install inside dsh-market
  • [ ] GitHub Release @ v0.1.0 (notes: CHANGELOG 0.1.0 section)

Contributing

See CONTRIBUTING.md. Security review: SPEC §7 model (verify command is host-config only; review file whitelist; no content in logs).

License

MIT