算法艺术创作
algorithmic-art
通过代码和可调参数创作生成艺术与交互式视觉效果。
manage-token-budget【设计与创意】Monitor, cap, and recover from context accumulation in agentic systems. Covers per-cycle cost tracking, context window auditing, budget caps with enforcement policies, emergency pruning when approaching limits, and progressive disclosure integration to minimize token spend on routing. Use when running long-lived agent loops (heartbeats, polling, auto…
独立 GitHub 快照 · 自动分类 · 以原作者文档为准
控代理系之費與脈絡跡:每周追用、審何占脈絡、執預限、限近時剪低值、入元前繞註經。要旨:脈絡之諸 token 必有其位。助決者留;占位無影者剪。
證:37 時自運費 $13.74,緣半時心跳+繁系令+脈絡無檢之積。修:心跳改 4 時,僅通知,去訂閱瀏覽。此技載防範之模。
於代理環各執界,記 token 用。
各周(心跳、輪、任務行)獲:
存於結構化記(JSON 行、CSV、庫)——非脈絡內:
{"cycle": 47, "ts": "2026-03-12T14:30:00Z", "trigger": "heartbeat",
"input_tokens": 18420, "output_tokens": 2105, "cost_usd": 0.0891,
"cumulative_cost_usd": 3.42}
無器→由 API 賬估:
得:每周 token 與費記,足細以辨何周貴何故。記居脈絡外。
敗:精數無(某 API 不返用元)→用賬板取均。粗追(日費/日周)亦顯勢。全無追→赴二,由脈絡審估費。
量脈絡之占用,按大排各占。
分脈絡為部,各量:
成脈絡預表:
Context Budget Audit:
+------------------------+--------+------+-----------------------------------+
| Component | Tokens | % | Notes |
+------------------------+--------+------+-----------------------------------+
| System prompt | 4,200 | 21% | Includes CLAUDE.md chain |
| Memory (auto-loaded) | 3,800 | 19% | MEMORY.md + 4 topic files |
| Tool schemas | 2,600 | 13% | 3 MCP servers, 47 tools |
| Active skill procedure | 1,900 | 9% | Full SKILL.md loaded |
| Conversation history | 5,100 | 25% | 12 prior turns |
| Current cycle content | 2,400 | 12% | Tool outputs from this cycle |
+------------------------+--------+------+-----------------------------------+
| TOTAL | 20,000 | 100% | Model limit: 200,000 |
| Remaining headroom |180,000 | | |
+------------------------+--------+------+-----------------------------------+
標決值不稱之大者。4000-token 記檔本任不引者乃純荷。
得:排序表顯各占、其大、其窗百。至少一部宜減——常為對話史或繁工具出。
敗:精數難得→以字符數/4 估英文。結構數據(JSON、YAML)用/3。意在相對排序,非精測。
定硬軟限,明各觸時何為。
軟限(警閾):常硬限六七五成。觸:
硬限(停閾):絕極費或脈絡。觸:
每周限:單周最多。防一周失控耗全預:
於流配記限:
token_budget:
soft_limit_usd: 5.00 # warn and begin pruning
hard_limit_usd: 10.00 # halt and alert
per_cycle_cap_usd: 0.50 # max per individual cycle
soft_limit_pct: 70 # % of context window triggering pruning
hard_limit_pct: 90 # % of context window triggering halt
enforcement: strict # strict = halt on hard limit; advisory = log only
alert_channel: notification # how to notify the operator
得:三層限(軟、硬、每周)皆記含執行。策答「觸限則何」於觸前。
敗:精金限早(新流費未明)→先用百分限(軟 70%、硬 90%),24-48 時追費後加金限。校期間諮模可。
近限時系剪低值容於預內。
剪先(最低先棄):
各剪存一行碑:
[PRUNED: 2,400 tokens of npm audit output from cycle 12 — 3 vulnerabilities found, all patched]
碑費約 20 token 而存決相關之結。
得:剪後脈絡用降至軟限下。各剪有碑存其結。決關信息不失——僅去已成決之證。
敗:剪至四級仍超軟限→流本就周頻過重。報人:「剪後脈絡 N%。選:(a) 增周距、(b) 減每周範、(c) 拆子流、(d) 受高費」。
入元前繞註——費於繞而非讀。
模:
_registry.yml——約 3-5 行 50 token同模施於他大脈絡載:
Without progressive disclosure:
Load 5 candidate skills → 5 × 1,500 tokens = 7,500 tokens → use 1 skill
With progressive disclosure:
Route through 5 registry entries → 5 × 50 tokens = 250 tokens
Load 1 matched skill → 1 × 1,500 tokens = 1,500 tokens
Total: 1,750 tokens (77% reduction)
得:技載循二段:輕經元繞、驗合方全載。同模施於記、工具註、檔容。
敗:註元繞不足(述泛、標缺)→改註而非棄漸顯。修為更善之元,非更多脈絡載。
依費數設執距,非任意排。
算今周距之時費:
cost_per_hour = avg_cost_per_cycle × cycles_per_hour對預:
hours_until_hard_limit = (hard_limit - cumulative_cost) / cost_per_hour定最小有效距:
施距:
Before: 30-minute heartbeat, verbose processing
→ 48 cycles/day × $0.09/cycle = $4.32/day
After: 4-hour heartbeat, notification-only
→ 6 cycles/day × $0.04/cycle = $0.24/day
→ 94% cost reduction
得:周距由費數證,匹監系更率。距費衡權記,後調有基。
敗:系需低延不容長距→改減每周費(系令小、工具註少、史摘)。預等有二桿:頻與每周費。
確諸控行且系於預內運。
Budget Validation Report:
+-----------------------+----------+--------+
| Check | Expected | Actual |
+-----------------------+----------+--------+
| Per-cycle logging | Present | |
| Soft limit warning | Fires | |
| Hard limit halt | Halts | |
| Per-cycle cap | Truncates| |
| Progressive disclosure| Routes | |
| Daily cost projection | < $X.XX | |
+-----------------------+----------+--------+
得:五控(追、軟、硬、每周、漸顯)皆驗行。費投於預內。
敗:控不鳴→察執機已連入實環,非僅記。配無執乃謀,非控。費投超預→返步六調周距或每周費。
assess-contextmetalchrysopoeiamanage-memory