RFC 006: Agentic RL through Harness Interception — token-faithful traces for TRL - #941
RFC 006: Agentic RL through Harness Interception — token-faithful traces for TRL#941rycerzes wants to merge 6 commits into
Conversation
sergiopaniego
left a comment
There was a problem hiding this comment.
linking huggingface/trl#6420 for considering it as it's directly related with this one.
|
@rycerzes solid RFC. One alignment point on the TRL seam: the harness-training path is being implemented in TRL as |
There was a problem hiding this comment.
Pull request overview
Adds a new design RFC describing an “installed-agent” RL training path for black-box CLI harnesses by intercepting OpenAI-compatible LLM traffic and emitting token-faithful traces consumable by TRL.
Changes:
- Introduces RFC 006 describing an interception server + trace recorder architecture for token-level rollouts.
- Defines the proposed trace contract
(prompt_ids, response_ids, loss_mask, response_logprobs, reward)and key design decisions (TITO, prefix-break forking, session-as-API-key, etc.). - Documents intended integration points with existing OpenEnv harness seams (
CLIHarnessAdapter.run_white_box,build_harness_rollout_func) and TRL’srollout_func.
Alignment Review Notes (per skill)
- Automated Checks
- Lint: Not run (no facility to execute
.claude/hooks/lint.shin this review environment) - Debug code: Not run (no facility to execute
.claude/hooks/check-debug.shin this review environment)
- Lint: Not run (no facility to execute
- Open RFCs context (relevant)
- RFC 005: In Review (
rfcs/005-agentic-harnesses.md) — this RFC explicitly extends it. - Other RFCs in Draft/In Review exist but no direct conflict identified from this doc-only change.
- RFC 005: In Review (
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Following up on my earlier note about the TRL seam. Now that huggingface/trl#6420 is merged, the installed-agent path in TRL is concretely 1. Remote / managed-sandbox interception topology. The architecture assumes the harness can reach the trainer-side interception server. For agents in remote, network-isolated sandboxes (HF Sandbox, E2B) that needs spelling out: the sandbox can egress HTTPS but has no easy inbound. The shape we validated keeps the server trainer-side/colocated and exposes it to the sandbox through an egress tunnel. The harness only gets 2. Where the TITO buffer should live. For context on the status quo: in the merged worker path, We have validated real OpenCode/Pi harnesses that could plug into the interception server, happy to help wire them up when it exists. For reference, the in-sandbox vs trainer-side placement in a remote-sandbox run: |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.
Comments suppressed due to low confidence (2)
rfcs/006-agentic-rl-harness-interception.md:7
- RFC numbering: RFC 010 explicitly states that numbers 006–009 are reserved for the self-improving-gym RFC family (rfcs/010-echo-env-token-world-model.md:8-11). Using RFC ID: 006 here (and the filename/README index) creates an in-repo inconsistency. Consider renumbering this RFC (and renaming the file + README entry), or updating RFC 010’s reservation note if that plan has changed.
**Created**: 2026-07-11
**Authors**: @rycerzes, @sergiopaniego
**RFC ID**: 006
rfcs/README.md:96
- This RFC index entry uses
006-..., but RFC 010 notes that IDs 006–009 are reserved (rfcs/010-echo-env-token-world-model.md:8-11). If that reservation still stands, this entry (and the RFC filename/header) should be renumbered to an unreserved ID to avoid conflicting documentation.
- [005-agentic-harnesses.md](./005-agentic-harnesses.md) - Agentic Harness Integration (OpenClaw, Claude Code, etc.)
- [006-agentic-rl-harness-interception.md](./006-agentic-rl-harness-interception.md) - Agentic RL through Harness Interception: token-faithful traces for TRL
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.
Comments suppressed due to low confidence (1)
rfcs/006-agentic-rl-harness-interception.md:6
- RFC ID 006 is currently also used by open PRs #624 and #794 (both add different
rfcs/006-*.mdfiles). Keeping this as 006 will force a renumber + file rename + README index update during merge conflict resolution; it’s safer to pick an unused RFC ID now (or mark the ID as TBD) to avoid collisions and broken cross-references.
**Created**: 2026-07-11
**Authors**: @rycerzes, @sergiopaniego
**RFC ID**: 006
rycerzes
left a comment
There was a problem hiding this comment.
@sergiopaniego Pushed a revision covering all three points.
- Seam — now
AsyncGRPOTrainer+HarnessRolloutWorker;run_white_boxis the secondary mode,rollout_funca sync bridge. - Buffer — your call. My "verifiers and Polar assemble at the interception point" claim was wrong: Polar merges post-hoc in
prefix_merging.py, verifiers ingraph.py, TRL in_chain_to_sequences. None buffers in the proxy. OpenEnv is a recorder only. - D3 adds one thing: inject
return_token_idsand record the engine's canonicalprompt_token_ids. Interstitials then come from slicing the next call's prompt after the EOT token (as Polar does) — nothing re-rendered, no tokenizer in core. - That implies one TRL change:
_turns_from_tracereadingentry["prompt_token_ids"]instead of re-rendering, with a fallback. It currently passes neitherchat_templatenorchat_template_kwargswhere_sample_turnpasses both, so the training-template substitution is skipped and ourenable_thinking=Falseinjection is invisible. Divergent prompts make_chain_to_sequencesFORKevery turn and pairinput_idswith logprobs from a different rendering. - Topology — D18 + a section from your description, now grounded in
huggingface_hub.Sandbox.proxy_url_for. Since that port proxy carrieswss://and streamed responses, the trainer can dial in to a thin in-sandbox relay rather than needing a publicly reachable address, so I wrote that up as the preferred transport with an outbound tunnel as the alternative — which of the two did you actually use? Also kept the in-sandbox proxy as a supported mode rather than legacy; it's the simpler deployment and both modes can share the recorder andTraceEntry. - D12 fixed — the fence is TRL's
WeightTransferClient.pause()/.resume()on aVLLM_SERVER_DEV_MODE=1server, nottrl vllm-serve(no pause endpoint there).
One question: D16 puts TraceEntry + the loop-owning session protocol in openenv.core.harness. Does that match your "contract stays HarnessTrace"? I made TraceEntry what OpenEnv emits and HarnessTrace the consumer-built target, since a framework-side buffer means we can't be emitting a loss_mask.
Yes please on wiring up the OpenCode/Pi harnesses once the server exists.
Summary
Adds an RFC for training the policy driving a black-box agent harness (Pi, OpenCode, Claude Code, …) inside OpenEnv by intercepting its LLM calls at an OpenAI-compatible boundary and recording a token-faithful trace —
(prompt_ids, response_ids, loss_mask, response_logprobs, reward)— that TRL consumes viarollout_func.This turns RFC 005's
CLIHarnessAdapter.run_white_boxstub (currentlyNotImplementedError) into a real seam. It is the installed-agent training path — the counterpart to the external-agent pattern TRL's Harbor integration already covers.Design-only RFC PR — no runtime behavior changes.
What's in it
chat_template_utils, prefix-break forking, session-ID-as-API-key auth, synthetic SSE replay, weight-sync fencing, proxy-enforced budgets.Relationship to other work
rfcs/005-agentic-harnesses.md) — reconciles with it, does not parallel it.Note on numbering
Filed as
006, but006is also used by open PRs #794 and #624 — happy to renumber to whatever's free at merge time.cc @burtenshaw @adithya-s-k @sergiopaniego
Note
Low Risk
Documentation-only PR; no production code, dependencies, or behavior changes.
Overview
Adds RFC 006 (draft) and links it from
rfcs/README.mdunder Agentic Harnesses. No runtime or API changes in this PR—design and roadmap only.The RFC specifies how to train policies for black-box CLI harnesses (Pi, OpenCode, Claude Code, etc.) by hosting a trainer-colocated OpenAI-compatible interception server that forwards to TRL-controlled vLLM, injects
return_token_ids, and records per-callTraceEntrytraces (canonicalprompt_token_ids, completion ids, rollout logprobs, provenance, budgets). OpenEnv stays a recorder without tokenizers or assembly; TRLHarnessRolloutWorker/_chain_to_sequencesbuilds training rows forAsyncGRPOTrainer.It extends RFC 005 (fills
CLIHarnessAdapter.run_white_box, loop-owningwait_for_completion/fetch_proxy_trace), supersedes the message-level #864 direction, and documents 18 decisions (ownership vs TRL, trainer-side vs in-sandbox topology, session-as-API-key, prefix-based chain forking, weight-sync alignment, HF Sandboxproxy_url_forconnectivity). Includes a “What OpenEnv must land” checklist and example wiring.Reviewed by Cursor Bugbot for commit 0975c2d. Bugbot is set up for automated code reviews on this repo. Configure here.