最新资讯
dev.to 如何在专用 GPU 服务器上用 OpenAI 兼容 API 部署 LLM dev.to 审计 153 份 Claude Code 与 Codex 会话记录:User-Agent 与 URL 中的邮箱泄露 dev.to 你的 Agent Harness 应具备的 17 项能力 dev.to 离线 AI 记忆中 0.8 余弦阈值为何失效 dev.to Kimi K3.1 Pro 开放权重:自托管 2.8T 模型前的开发者清单 dev.to 如何通过工具调用引导模型以提升 Harness 质量 dev.to AI Agent 审计轨迹不等于对话记录 dev.to 精简 MCP server 工具数量:更少工具、更小影响面,双重收益 dev.to 为什么 git checkout 无法撤销 AI 编码 agent 的改动? wechat AI短剧门槛降降降!实测即梦短剧工作室:剧本分镜预演一条龙,伙伴计划长期护航 dev.to 让模型改写文档前,先量化事实保真度 dev.to 回放 153 个 Claude Code 与 Codex 会话,审计 Agent 的生产影响范围
多元动态
登录 注册
智能体 dev.to · @Reid Marlow

编码 Agent 的上下文压缩压错了 prompt 的一侧

原文 我的收藏

文章讨论长上下文编码 Agent 的 token 成本:约 25 轮后 prompt 可达 8 万 token,其中超过 80% 是终端输出、编译警告、grep 结果和目录树等环境观察内容。作者引用北京大学论文《Compress What You See, Not What You Say: Anchored Context Distillation for Latent-Observation Software Engineering Agents》(arXiv:2609.31430),指出把整段 agent transcript 压成 latent 向量会同时压缩环境观察与模型输出两类性质不同的文本,并据此质疑常见的软压缩做法。

AI推荐理由 文章指出编码 Agent 长上下文成本问题:约 25 轮后 prompt 达 8 万 token,其中超八成是终端输出、编译警告、grep 结果和目录树等环境观察内容;并引用北京大学论文《Compress What You See, Not What You Say: Anchored Context Distillation for Latent-Observation Software Engineering Agents》(arXiv:2609.31430,作者 Zhensheng Zou、Guoqing Wang、Dan Hao),讨论对整段 transcript 做 latent 软压缩会同时压缩环境观察与模型输出两类不同文本的问题。具体新信息是区分“所见”与“所说”的压缩思路,对长上下文 Agent 工程有参考价值;但正文片段在关键处截断,未给出论文的完整实验数据与结论,需以原文为准。

72

正文

Most engineering teams working on long-context agents hit the same billing wall around turn twenty. A coding agent runs twenty shell commands, reads twelve files, and runs pytest three times. By turn twenty-five, the prompt is 80,000 tokens long. Over eighty percent of those tokens are terminal dumps, compiler warnings, grep outputs, and directory trees. The default reaction across research and devtools has been to compress the transcript. Teams summarize older turns, drop middle messages, or project prompt tokens into learned latent soft embeddings. A paper from Peking University titled "Compress What You See, Not What You Say: Anchored Context Distillation for Latent-Observation Software Engineering Agents" (arXiv:2609.31430, by Zhensheng Zou, Guoqing Wang, and Dan Hao) puts hard numbers on why soft compression usually ruins coding agents. When you compress an entire agent transcript into latent vectors, you compress two fundamentally different categories of text: what the environment printed, and what the agent decided. The exact-match penalty A software agent does not read historical context the way a human reads an essay. It reads context to copy exact file paths, variable names, line offsets, git commit hashes, and regex patterns. If an agent needs to edit src/core/connection_manager.py at line 412, a compressed semantic summary that says "the user reviewed the connection pooling setup earlier" is useless. The agent needs the exact string src/core/connection_manager.py. If that string gets blurred into soft tokens, the model either invents a nearby path or spends another tool call running find or ls to recover what it already saw. Compressing the agent's own actions creates a second failure mode: behavioral drift. Agents trained with standard instruction tuning rely on the exact surface forms of their tool definitions and scratchpads. Once you feed them soft tokens representing prior thoughts, their syntax degrades. They drop closing brackets, mangle JSON arguments, or repeat earlier failed actions. The split: LOHA and ACD The authors break the problem into two specific techniques: First, a context layout called Latent Observations, Hard Actions (LOHA). Instead of compressing everything, LOHA preserves: Every turn written by the agent in raw text. The system prompt and instructions in raw text. The most recent K tool observations in raw text. Older tool observations compressed into soft latent tokens. The separation addresses the actual workload. The agent retains full, uncorrupted access to its own previous reasoning and tool syntax. It retains byte-exact access to whatever the last few tools just printed. Historical observations (such as a 2,000-line grep run from ten turns ago) remain accessible in latent space so the model knows which files were touched, without occupying thousands of raw token slots. Second, a training objective called Anchored Context Distillation (ACD). Fine-tuning an agent to read soft tokens typically degrades its out-of-distribution performance on standard text. ACD trains the agent on latent-observation histories while simultaneously anchoring its output distributions against the original base model running on plain text. The numbers on SWE-bench Verified The team evaluated the approach on SWE-bench Verified across two open models: Qwen3-4B and SWE-Master-4B-RL. Setting the uncompressed observation window to K=3 produced these results: Context reduction: 43% fewer tokens per call on Qwen3-4B, and 57% fewer on SWE-Master-4B-RL. Task completion: Qwen3-4B resolved 12.1% of issues with LOHA versus 14.5% uncompressed. SWE-Master-4B-RL resolved 21.8% versus 27.5%. Recency scaling: Expanding the exact observation window to K=8 pushed resolve rates back up to 14.4% for Qwen3 and 23.0% for SWE-Master. The critical test comes under memory limits. Under a strict 32K token budget, where a standard uncompressed agent truncates or crashes on long tasks, Qwen3 with K=3 resolved 21.1% on a 199-instance long-horizon subset, compared to only 11.1% for the same adapted agent trying to run on truncated plain text. On concurrent single-GPU serving, the smaller context footprint boosted instance throughput by 1.9x. What to take away for agent harnesses If you are running long-horizon agent workflows on local hardware or self-hosted models, soft context distillation offers a real path to doubling concurrency. But the architectural rule matters more than the specific weights: Never compress the agent's own action history. If your compression scheme touches the model's scratchpad, tool calls, or immediate working memory, you will lose task resolution. Let the environment outputs absorb the lossy compression, and keep the agent's decisions exact.

来源报道 · 1 篇 · 以下链接均前往原始媒体

← 返回精选动态 原文

更多内容