Agentic RL:Harness 也是策略的一部分
传统 RL 常把环境想成一个干净的 API:观测进来,动作出去,奖励回来。真实 coding agent 并不这样运行。它有工具协议、上下文压缩、子 agent、终端、重试和停止规则。对智能体强化学习(agentic RL)而言,这个智能体运行支架(harness)不是可忽略的包装,而是策略实际执行的条件。
1. 为什么把 agent 硬塞进普通 environment API 会丢信息
一个成熟 harness 会定义:系统提示词如何拼接、工具怎么返回、何时压缩上下文、子 agent 怎样并行、文件如何持久化、什么时候终止。把它重写成训练框架内部的 environment,可能改变这些行为,或丢掉 token、log-prob、分支与工具上下文。
这就是 Polar 论文解决的问题:它不是一个新的 PPO / GRPO 公式,也不是 benchmark。它是一个异步 rollout 系统,让原生 harness 把模型请求指向代理网关;网关转发请求并记录模型交互,再从真实执行中重建训练轨迹。
2. Polar 的系统边界
原生 harness
-> 模型 API proxy
-> 推理后端
-> CompletionSession
-> trajectory builder
-> evaluator / reward
-> 独立 trainer
- harness 保持原生。论文支持若干 provider 风格的模型 API,并在代理处捕获 prompt、采样 token、token ID 与 log-prob。
- 轨迹不是一段漂亮文本。对严格前缀延续的对话可以合并;子 agent、并行分支或上下文重写不能假装成一条线性对话,应该保留为独立链。
- 评测器独立。rollout 后,测试、会话完成或其他 evaluator 产生结果级或过程级 reward;trainer 不必拥有 harness。
这四层需要分别记录:运行时隔离、harness 启动配置、模型流量与轨迹重建、验证与奖励。否则出了分数变化,也无法判断是模型、支架、环境还是评分器造成的。
3. 论文提供了什么证据
在论文指定的设置中,作者从同一个 Qwen3.5-4B 起点出发,用标准 GRPO 和 293 个 SWE-Gym 训练任务,在 SWE-Bench Verified 上报告了四种 coding harness 的绝对 pass@1 增益:
| Harness | 论文报告的起点 -> 训练后 | 绝对变化 |
|---|---|---|
| Codex | 3.8% -> 26.4% | +22.6 |
| Claude Code | 29.8% -> 34.6% | +4.8 |
| Qwen Code | 34.6% -> 35.2% | +0.6 |
| Pi | 34.2% -> 40.4% | +6.2 |
作者还报告,在一个轨迹重建消融中,prefix_merging 将 trainer 侧更新条目从 1,185 降到 218,并缩短该设置的 wall-clock 时间。这是关于其系统设计和指定实验设置的证据,不是“所有 harness 都会获得同等收益”的定律。
4. 奖励归因是最危险的地方
长程 agent 的最终 patch 通过了验证器,不代表每次模型调用都同样有功。Polar 论文明确发现,把 session 级 outcome reward 机械地广播给每条 request-level trace 会产生明显的 reward hacking 风险。
因此一个可信的 agentic RL 环境至少应公开:
- reward 是对最终工件、某次提交、某个步骤,还是整段 session 赋值;
- 奖励如何映射到 token 级 loss mask;
- 工具失败、重试、子 agent 分支和上下文压缩是否还留在轨迹中;
- 验证器运行在哪个干净环境,agent 能否污染它;
- 训练、验证和部署使用的 harness 是否版本一致。
5. 和环境文章怎么连起来
环境文章里的 benchmark、harness、sandbox 三层在 agentic RL 中仍然存在,但还需要加一层:轨迹与训练接口。评测系统决定什么算完成;harness 决定策略实际怎样行动;sandbox 决定可见状态和权限;训练接口决定哪些行为被归因、被优化、被复放。
这也解释了为什么“换一个 harness 重新跑同一个模型”不是无关紧要的工程细节。提示词、工具可用性、停止策略、上下文政策和 evaluator 都可能改变 rollout 分布。训练结论需要说明这些条件,而不是把最终分数写成模型脱离环境的固定属性。
6. 给自己的实验清单
- 固定并记录 harness、模型端点、系统提示、工具版本、沙箱镜像和 verifier 哈希。
- 保存可重放的 token 对齐轨迹,而不只保存自然语言 transcript。
- 把训练 reward 与最终独立评测分开,并报告两者的差异。
- 在至少一个没有被选择或调参过的任务分布上评估,避免把 harness 适配写成通用能力。
References
- Xu et al., Polar: Agentic RL on Any Harness at Scale (preprint).
- Polar HTML paper, especially Sections 3 and 4.
- PPO / DPO / GRPO for the objective-level view of LLM RL.
- Agent research environments for task, harness, sandbox, and verifier boundaries.
Agentic RL: The Harness Is Part of the Policy
Conventional RL often imagines a tidy API: observations arrive, actions leave, and rewards return. Real coding agents do not run that way. They have tool protocols, context compression, subagents, terminals, retries, and stopping rules. For agentic RL, this agent harness is not disposable packaging. It is part of the condition under which the policy actually executes.
1. Why Forcing an Agent into an Ordinary Environment API Loses Information
A mature harness defines how system prompts are assembled, how tools return observations, when context is compressed, how subagents run concurrently, how files persist, and when execution stops. Rewriting it as an environment owned by a training framework can alter those behaviors or lose tokens, log-probabilities, branches, and tool context.
This is the problem addressed by Polar. It is neither a new PPO / GRPO objective nor a benchmark. It is an asynchronous rollout system: the native harness points model requests to a gateway, the gateway forwards and records the interactions, and training trajectories are reconstructed from the real execution.
2. Polar’s System Boundary
native harness
-> model API proxy
-> inference backend
-> CompletionSession
-> trajectory builder
-> evaluator / reward
-> independent trainer
- The harness stays native. The paper supports several provider-shaped model APIs and captures prompts, sampled tokens, token IDs, and log-probabilities at the proxy.
- A trajectory is not a pretty transcript. Strict prefix continuations may be merged. Subagents, parallel branches, and context rewrites should remain separate chains rather than be forced into one linear conversation.
- Evaluation stays separate. Tests, session completion, or other evaluators generate outcome or process rewards after rollout; the trainer need not own the harness.
Four layers should be recorded independently: runtime isolation, harness launch configuration, model traffic and trajectory reconstruction, and verification plus reward. Otherwise a score change cannot be attributed to the model, harness, environment, or grader.
3. What the Paper Actually Shows
In the paper’s specified setup, the authors start from the same Qwen3.5-4B base, use standard GRPO and 293 SWE-Gym training tasks, and report the following absolute pass@1 changes on SWE-Bench Verified across four coding harnesses:
| Harness | Reported start -> post-training | Absolute change |
|---|---|---|
| Codex | 3.8% -> 26.4% | +22.6 |
| Claude Code | 29.8% -> 34.6% | +4.8 |
| Qwen Code | 34.6% -> 35.2% | +0.6 |
| Pi | 34.2% -> 40.4% | +6.2 |
The authors also report that prefix_merging reduced trainer-side updates from 1,185 to 218 and shortened wall-clock time in one reconstruction ablation. This is evidence about the paper’s design and stated experimental setting, not a law that every harness will receive equal gains.
4. Reward Attribution Is the Dangerous Part
The final patch of a long-running agent may pass a verifier, but that does not make every model call equally responsible. Polar explicitly finds that mechanically broadcasting a session outcome reward to every request-level trace creates a substantial reward-hacking risk.
A credible agentic RL environment should therefore disclose:
- whether reward is assigned to the final artifact, a submission, a step, or the full session;
- how reward maps onto token-level loss masks;
- whether tool failures, retries, subagent branches, and context compression remain in the trajectory;
- where the verifier runs and whether the agent can contaminate it; and
- whether training, validation, and deployment use the same harness version.
5. How This Connects to Environment Design
The benchmark, harness, and sandbox layers in the environment post still apply to agentic RL. A fourth layer must be added: the trajectory and training interface. Evaluation decides what completion means. The harness determines how the policy acts. The sandbox determines visible state and permissions. The training interface determines which behavior receives credit, optimization, and replay.
That is why rerunning the same model with another harness is not an incidental engineering detail. Prompts, tool availability, stopping policy, context policy, and evaluation can all change the rollout distribution. A training result should name those conditions rather than present a final score as an environment-free model property.
6. A Checklist for Personal Experiments
- Fix and record harness, model endpoint, system prompt, tool versions, sandbox image, and verifier hash.
- Save replayable token-aligned trajectories, not only natural-language transcripts.
- Separate training reward from independent final evaluation and report their gap.
- Evaluate on at least one task distribution that was not selected or tuned against, so harness adaptation is not reported as general ability.
References
- Xu et al., Polar: Agentic RL on Any Harness at Scale (preprint).
- Polar HTML paper, especially Sections 3 and 4.
- PPO / DPO / GRPO for the objective-level view of LLM RL.
- Agent research environments for task, harness, sandbox, and verifier boundaries.