Sherry's Blog


  • 首页

  • 关于我

  • 标签

  • 文章列表

Anxiety and Imperfection in the Age of AI

发表于 2026-04-11

About fifteen years ago I opened Coursera for the first time to learn linear algebra. Soon after, I discovered TED and fell into a world of open courses. I first touched Python in 2014 on a very basic tutorial site. With some programming background, the language felt simple—clean abstractions, concise syntax—but feeling something is simple is not the same as using it well.

We now live in the age of AI. A decade ago we learned on the internet, and that learning was often driven by anxiety—mine included. I worry about new knowledge and unfinished deadlines. Even though AI can write code faster than any human, I still miss that earlier era. Back then I sat in classes taught in English I barely understood and still threw myself into algorithms, data structures, games, and websites. Linear algebra and college physics on Coursera thrilled me because the internet changed how I came to know the world. Linear algebra felt “simple yet not simple.” English explanations struck me as pure and precise, focused on meaning; Chinese, in contrast, can be more easily swayed by surrounding context.

The internet rewired how we connect. Once, to find like‑minded people you searched your immediate circle. Over the last fifteen years, information and conversation stretched worldwide. Even from an ordinary school, you could attend extraordinary courses online.

AI has changed something else: it keeps me staring at screens longer and tempts me into “replacement thinking.” That shortcut is often wrong, but it makes laziness easy. And we are still mid‑transition. AI cannot replace human learning. Humans must remain the final check because AI will never be 100% correct. At best, it is an assistant that offers ideas when precision demands are low. We cannot outsource curiosity or judgment.

In an atomized society, AI has also become an emotional listener. Some friends no longer vent to friends when they are down; they talk to AI instead. Offloading negative emotion is hard for people but costs an AI only electricity. In that narrow sense, AI can absorb a bit of society’s stress.

Still, today’s revolutions mostly live at the information layer. Hardware domains—embodied intelligence, autonomous driving—remain constrained by safety and liability. This is where “imperfection” matters. AI often strives for a kind of polished neutrality, but human imperfection is the source of our richness. When I write, I bring bias, feeling, and mood; that color is part of the work. Diversity—biological and intellectual—emerges from tiny deviations. Perhaps we began as paramecia or other marine life. Over millions of years, countless mutations produced the abundance of animals, plants, microbes, even viruses. Creation never aimed at flawless beings; variation is the point.

Because of variation, human emotion is compelling. No one stays rational forever, and our feelings are never singular. As Laozi writes in the Dao De Jing, “Heaven’s way takes from what has excess and replenishes what is lacking.” It reads like mean reversion. Water runs downhill; when land is dry, vapor gathers into clouds and returns as rain. Things swing to extremes, then return. Nature is a song with rises and falls—imperfect cycles that create variety.

“The highest goodness is like water; water benefits all and does not compete,” Laozi also says. Water looks soft yet is resilient. It adapts to any container and, drop by drop, reshapes stone. That blend of softness and strength mirrors the value of imperfection: flexibility hiding power, power containing flexibility. Civilizations follow similar rhythms—peaks, troughs, recoveries. Economies do, too. AI may craft “perfect” sentences, but human diversity is itself beautiful. Tools should serve people; they do not replace us. The steam engine did not end work—it forced us to learn new tools. The AI era is no different.

Even with multimodal systems, AI today mostly processes information and supplies decision references. Five or ten years from now, much may change; even then, embodied systems and full self‑driving will likely be powerful assistants rather than final authorities, because responsibility must land somewhere. Autonomous driving is especially hard; perhaps it works on constrained roads with predictable traffic. I have held a license for thirteen years and still prefer not to drive: too many factors, too much risk. On the other hand, asking a robot to move laundry into a dryer is feasible. Robot vacuums and mop‑washers already automate small chores, but scenarios remain narrow. Once a system touches physical interaction with people, safety dominates. In software—code, text, analysis—AI assists, but people own the decision.

That is why I do not think AI anxiety is necessary. You do not need to chase every release. Live your life and benefit from progress as it matures. AI cannot learn to read or write code for you; those are foundational skills. Technical ability is the base; AI fluency is a multiplier on top. Without fundamentals, AI widens gaps. Used well, it can close them. Calculators did not kill the multiplication table. Fundamentals endure, and human oversight remains essential.

The spectacle of robots and shiny AI apps is understandable, but these are not final forms. Costs stay high in transition, and many products lack optimization and standards. They are interim solutions and will be replaced. Those who build ecosystems early gain an edge. Open and closed approaches will coexist—just as Android and iOS, Linux and Windows have.

Information security is unavoidable. Whatever you choose, you pay to deploy and you carry risk. Today’s AI reads code well enough to surface vulnerabilities quickly—both a capability and a concern.

We are still moving from text‑only toward multimodal systems; that arc may take another two to five years. I cannot predict when things stabilize or how capable future models will be. One point is stable: humans must remain the last mile. Embodied intelligence will likely need years before meaningful deployment. Robots existed decades ago; better algorithms make them feel closer, but the distance to our expectations is still large. These systems assist; they do not replace. AI, autonomy, embodiment—tools for people that can boost productivity and nudge us toward more equity, but not deliver utopia.

Zooming out, no society achieves perfect equality. Welfare without internal competition can dull initiative and weaken resilience to external pressure. The best we can hope for is balance. As long as nations exist, competition exists. If a society chooses high welfare and high taxes, it may reduce internal pressure without reducing external pressure. The result is a familiar tension we must navigate.

Laozi’s “small states with few people” is, in practice, utopian: a small polity struggles before a much larger, unified one. But relentless competition is not an answer either. We negotiate between extremes and look for workable balances. Some places seem to strike a compromise between competition and welfare; others lean heavily one way. Often, it is competition under constraint—not innate advantage—that unlocks potential.

My thoughts jump, but they trace one line: no matter how strong AI becomes, it remains a tool. Human imperfection keeps the world vivid. We need to keep learning—on purpose—to master our tools and to stay responsible for the outcomes.

2026 年 Agent 上下文管理:源码实证与架构建议

发表于 2026-04-05 | 分类于 技术

2026 年 Agent 上下文管理:源码实证与架构建议

  • 结论先行(TL;DR)
    • 把“省 token”当目标会南辕北辙;目标应是“在长任务中少犯错”,token 节省只是副产品。
    • 现成方案最易落地的组合是“语义组装 + 算法压缩”:先用 LCM(lossless-claw)挑对上下文,再用 Headroom 压冗余工具输出。但要把可逆取回(CCR)与结构化任务状态贯穿,否则准确率会掉。
    • OpenClaw 默认 Legacy 引擎确实是“壳”,但内置了一套守护与补救机制;生态里已有 Headroom、context‑mode、LCM 的插件化路径,无需 fork 重写。
    • Hermes 的压缩不是“固定 13.9k + 双调用”,而是一次结构化摘要,预算随上下文规模动态调整。

问题刻画

  • 约束:模型上下文上限;工具输出与检索回流导致会话爆炸;跨会话/跨子任务串联要求“记得住状态而不是记得住过程”。
  • 错位:把“最高压缩比/最少 token”当 KPI 会牺牲可用性(缺关键行、断工具结果配对、遗漏标识符等),更好的目标是“正确率、重试次数、任务完成率、返工率”。

生态速写(源代码为证)

  • OpenClaw(默认)
    • Legacy 引擎是“兼容壳”:
      • openclaw/src/context-engine/legacy.ts:28 ingest() 返回 { ingested: false }
      • openclaw/src/context-engine/legacy.ts:38 assemble() 原样透传、estimatedTokens: 0
      • openclaw/src/context-engine/legacy.ts:79 compact() 委托给运行时 delegateCompactionToRuntime
    • 压缩“固定比例 + 护栏”并存:
      • openclaw/src/agents/compaction.ts:16 BASE_CHUNK_RATIO=0.4
      • openclaw/src/agents/compaction.ts:17 MIN_CHUNK_RATIO=0.15
      • openclaw/src/agents/compaction.ts:18 SAFETY_MARGIN=1.2
      • 同文件包含“按 token 份额切块、成对保留 tool 调用/结果、摘要开销预算”等逻辑与重试补救
    • 插件“排他 slot”:
      • openclaw/src/plugins/slots.ts:12 kind→slot 映射(memory / context-engine)
      • openclaw/src/plugins/slots.ts:76 applyExclusiveSlotSelection(…) 切换 slot 并禁用同类插件
    • 任务状态不是“纯内存”:
      • 运行时 Map:openclaw/src/tasks/task-registry.ts:50
      • 可插拔持久化(默认 SQLite):openclaw/src/tasks/task-registry.store.ts:31
  • lossless‑claw(LCM)
    • 架构解耦(SQLite/FTS5 存储 + 语义组装 + 可扩展摘要),通过插件契约接入 OpenClaw:
      • lossless-claw/src/engine.ts:1199 LcmContextEngine implements ContextEngine
      • 依赖的是 openclaw/plugin-sdk 契约而非零依赖:lossless-claw/src/engine.ts:19
      • 会话存储:lossless-claw/src/store/conversation-store.ts:263
      • 语义检索:lossless-claw/src/retrieval.ts:124
  • Headroom
    • JSON 工具输出智能压缩(SmartCrusher)、文本压缩(Kompress,可选 ML)、可逆取回(CCR):
      • 非 JSON 直通(不压):headroom/tests/test_text_compressors.py:289
      • CCR 工具名:headroom/headroom/ccr/mcp_server.py:64
    • 已有 OpenClaw 引擎插件(零 LLM、调用 compress()):
      • headroom/plugins/openclaw/src/engine.ts:1
  • Hermes Agent
    • 压缩预算动态,不是“固定 13.9k + 双调用”:
      • 下限/比例/上限:hermes-agent/agent/context_compressor.py:39, :41, :43
      • 预算计算与上限约束:hermes-agent/agent/context_compressor.py:220–:225
      • 唯一 LLM 调用(结构化摘要,支持迭代更新):hermes-agent/agent/context_compressor.py:404, :287
      • 低成本预处理(裁剪旧工具输出):hermes-agent/agent/context_compressor.py:155
    • 记忆 provider 可插拔,但“是否调用 LLM”取决于 provider 实现:
      • hermes-agent/agent/memory_provider.py:164
  • context‑mode
    • 以“会话简历”跨压缩注入、计数与可观测:
      • 计数:context-mode/src/session/db.ts:84, :194
      • before/after_compaction 钩子 + resume 注入:context-mode/src/pi-extension.ts:297, :307, :265

发现与补正

  • “OpenClaw 等于‘塞满再摘要’”并不全面
    • 确有固定比例与 Legacy 默认,但生产路径包含分块、工具配对修复、摘要质量守卫、标识符保护、重试/超时治理与“预压缩记忆冲洗”等演进;判词宜改为“默认策略偏朴素,但配备成体系护栏,可通过插件替换/接管”。
  • “任务状态在内存 Map,测试强耦合”偏颇
    • TaskRegistry 提供持久化与 Observer 注入点,可替换为轻量 store,隔离测试(见上)。
  • “Headroom 压不动自然语言摘要”要加限定
    • SmartCrusher 针对 JSON,文本默认直通;但 Kompress 可对文本压缩(需 [ml] 额外依赖)。并且 CCR 让“可逆检索”成为安全阀。
  • “LCM 零 OpenClaw 依赖”应更严谨
    • 是“契约依赖、实现解耦”,能在 OpenClaw 外独立复用,但仍以 plugin-sdk 类型做编译时契约绑定。

组合方案:Meta‑Engine 编排(LCM → Headroom)

  • 目标:既保留语义相关性(由 LCM 负责),又显著压掉冗长工具输出等结构化内容(由 Headroom 负责);对纯对话场景自动旁路,避免过度压缩。
  • 编排要点
    • 接口所有权:实现一个 ContextEngine,占住 context-engine slot。
    • 生命周期
      • assemble():先调用 LCM assemble(),对输出消息做“工具输出占比估算”;若工具占比>阈值(如 ≥50%),调用 Headroom compress();否则直通 LCM 输出。
      • compact():传入 token 预算给 Headroom(RollingWindow + CCR),并透传/保留 LCM 的摘要(避免对摘要再压缩)。
    • 格式桥接
      • LCM/Headroom 使用的消息格式(Agent/OpenAI)互转:参考 headroom/plugins/openclaw/src/engine.ts:11 转换器思路。
      • 对“工具结果成对”保持:遵循 OpenClaw 分块配对逻辑避免“孤儿调用/结果”(见 openclaw/src/agents/compaction.ts:117)。
    • 可逆性/取回
      • 同步注入 CCR 工具使用说明,或在 system prompt 添加“若需要更多细节,调用 headroom_retrieve”提示,见 headroom/headroom/ccr/mcp_server.py:64。
    • 旁路策略
      • 统计最近 N 条消息文本 token 比例、工具输出 token 比例与 JSON 可压缩度评分(可用样本规则先行),不满足门槛直接返回 LCM 结果。
  • 风险与对策
    • “摘要+压缩”双重丢失风险:禁止对摘要文本做 lossy 压缩;CCR 仅覆盖被压缩的原文,不覆盖摘要。
    • 桥接一致性:保持 tool_call_id/tool_result 成对与顺序稳定,避免模型拒绝或工具注入失配。
    • 观测:记录 tokens_before/after/saved、错配修复次数、CCR 取回次数等,作为回归指标。

评价指标(建议用例)

  • 基础:token 节省(prompt_tokens)、压缩前后 API 错误率、继续对话“重复工作”比率。
  • 任务正确性代理:修 bug 类用例中“首次定位关键错误行”的命中率;代码生成用例中的“路径/标识符保真率”。
  • 稳定性:工具调用-结果配对完整率,CCR 取回命中率与延迟。

我会怎么实现(最小工作量)

  • 新建一个 context-engine 插件(占 slot)
    • 复用 lossless-claw 作为子引擎生产 assemble 结果
    • 条件触发 headroom compress()(沿用 headroom/plugins/openclaw/src/engine.ts:1 里的 compress() 调用方式)
    • 旁路或失败一律回退到 LCM 输出;compact() 仅分发预算与记录观测
  • 工期估计:~300–500 行 TypeScript(含桥接与指标),不改三方仓库

证据清单(可点开核查)

  • OpenClaw
    • openclaw/src/context-engine/legacy.ts:28, openclaw/src/context-engine/legacy.ts:38, openclaw/src/context-engine/legacy.ts:79
    • openclaw/src/agents/compaction.ts:16, openclaw/src/agents/compaction.ts:17, openclaw/src/agents/compaction.ts:18, openclaw/src/agents/compaction.ts:117, openclaw/src/agents/compaction.ts:211
    • openclaw/src/plugins/slots.ts:12, openclaw/src/plugins/slots.ts:76
    • openclaw/src/tasks/task-registry.ts:50, openclaw/src/tasks/task-registry.store.ts:31
  • lossless‑claw
    • lossless-claw/src/engine.ts:1199, lossless-claw/src/engine.ts:19
    • lossless-claw/src/store/conversation-store.ts:263, lossless-claw/src/retrieval.ts:124
  • Headroom
    • headroom/tests/test_text_compressors.py:289
    • headroom/headroom/ccr/mcp_server.py:64
    • headroom/plugins/openclaw/src/engine.ts:1
  • Hermes Agent
    • hermes-agent/agent/context_compressor.py:39, hermes-agent/agent/context_compressor.py:41, hermes-agent/agent/context_compressor.py:43
    • hermes-agent/agent/context_compressor.py:220, hermes-agent/agent/context_compressor.py:225
    • hermes-agent/agent/context_compressor.py:404, hermes-agent/agent/context_compressor.py:287, hermes-agent/agent/context_compressor.py:155
    • hermes-agent/agent/memory_provider.py:164
  • context‑mode
    • context-mode/src/session/db.ts:84, context-mode/src/session/db.ts:194
    • context-mode/src/pi-extension.ts:297, context-mode/src/pi-extension.ts:307, context-mode/src/pi-extension.ts:265
1234…22

50 日志
2 分类
31 标签
© 2026 Sherry
由 Hexo 强力驱动
|
主题 — NexT.Muse v5.1.4