凡自治之物 · LGD 治理学 · 创造术家族 | 评测协议:skill-quality-gate(外部公开评测门禁文档)
English
When to use
- The model starts giving off-topic answers or forgetting earlier settings ("context pollution / decay").
- Designing / optimizing an agent's prompt, memory, RAG retrieval or tool orchestration.
- Token burn is high; the context window is too long; memory orchestration needs refinement.
- Trigger words: "context engineering", "long-context optimization", "RAG recall".
Usage
- Run
context_budget.py --calculateto estimate current token budget and remaining window. - Set
--budget_limit(int) and--model_namefor model-specific advice. context_budget.py --auditproduces a relevance/redundancy checklist.- For doc-style tasks, read the in-file function library for memory-decay and retrieval-recall helpers.
Flow
- Context audit: scan interaction history; flag low-relevance, stale or duplicate info.
- Budget accounting: compute current token share and remaining-window risk.
- Trimming: apply the four-dimension standard (relevance / redundancy / budget / decay); compress memory.
- Retrieval tuning: adjust RAG recall params and tool order so key data loads first.
- Gate check: gate new incoming info so new tokens don't overwrite old key settings.
- Closed loop: re-inject the optimized context into the model; log adjustments.
Evidence & safety
- Evidence: TBD. Version: 1.0.1. Security: no independent scan (TBD).
中文
何时用
- 当用户反馈模型"答非所问"、"遗忘设定"或遭遇"上下文污染"、"上下文衰减"等质量问题时。
- 在进行 Agent 设计、优化提示词(Prompt)、记忆管理或 RAG 检索策略的技术调试与评估场景。
- 监控对话成本,涉及"token 预算烧太快"、"上下文窗口过长"或需要精细化"记忆编排"时的决策节点。
- 触发关键词包含"context engineering"、"长上下文优化"、"RAG 召回"及具体指标时自动介入。
用法
- 执行核心计算脚本
context_budget.py,启用--calculate模式以输出当前对话的 Token 预算与剩余窗口估算。 - 配置
--budget_limit参数(整数)以设定最大可接受上下文长度,配合--model_name指定目标模型优化建议。 - 调用
context_budget.py --audit生成包含相关性、冗余度评分的详细清单,用于审查历史会话质量。 - 对于文档型任务,可通过读取
context_budget.py文件内的函数库获取预定义的"内存衰减"与"检索召回"算法接口。
流程
- 上下文审计:扫描当前交互历史,识别低相关性、过期或重复信息(使用审计清单生成器)。
- 预算核算:调用
context_budget.py计算当前输入占用的 Token 比例及剩余窗口风险。 - 信息裁剪:依据四维度标准(相关性·冗余·预算·衰减)删除不必要节点,实施记忆压缩。
- 检索优化:调整 RAG 召回参数与工具编排顺序,确保关键数据被优先加载。
- 门禁校验:对新进入的信息进行"上下文门控"检查,防止新 Token 覆盖旧的关键设定。
- 闭环反馈:将优化后的上下文结构重新注入模型,并记录本次调整日志用于下一轮参考。
证据与安全声明
- 证据:TBD(暂无评测/徽章链接;产生后在此更新实际链接)
- 版本:1.0.1
- 安全:未做独立安全扫描(TBD),结论待补;补全前不作推荐背书。
