Skip to content

docs(tutorials): add black-box coding agent training tutorial (OpenCode + AsyncGRPO) - #1028

Open
sergiopaniego wants to merge 2 commits into
mainfrom
feature/docs-opencode-harness-recipe
Open

docs(tutorials): add black-box coding agent training tutorial (OpenCode + AsyncGRPO)#1028
sergiopaniego wants to merge 2 commits into
mainfrom
feature/docs-opencode-harness-recipe

Conversation

@sergiopaniego

@sergiopaniego sergiopaniego commented Jul 31, 2026

Copy link
Copy Markdown
Member

Summary

Adds a tutorial page for the black-box (loop-owning) training path: training the real OpenCode agent with TRL's experimental AsyncGRPOTrainer and the opencode_env transparent interception proxy. The recipe itself lives in TRL (docs section plus examples/scripts/openenv/opencode.py), so this page explains when to use the pattern, how the pieces fit, and links out. It also adds the row to the tutorials index and the toctree entry.

Until now this recipe was not discoverable from OpenEnv docs at all: the BrowserGym harness tutorial covers the white-box pattern where the trainer keeps sampling, and nothing pointed at the black-box path.

This is the index/discoverability piece discussed in RFC #924 (GRPO harness training recipes): recipes live in each framework's repo, OpenEnv curates the index.

Type of Change

  • Documentation

Alignment Checklist

  • I have read .claude/docs/PRINCIPLES.md and this PR aligns with our principles
  • I have checked .claude/docs/INVARIANTS.md and no invariants are violated
  • I have run /pre-submit-pr (or bash .claude/hooks/lint.sh and tests) and addressed all issues

RFC Status

Test Plan

  • _toctree.yml parses (yaml.safe_load) and the new entry mirrors the existing tutorial entries.
  • Docs-only change, no code paths touched.
  • Links point at TRL main (docs/trl/openenv harness section, examples/scripts/openenv/opencode.py) and envs/opencode_env, all verified to exist.

Claude Code Review

N/A (docs-only)


Note

Low Risk
Documentation-only changes with no runtime or API impact.

Overview
Adds discoverability for training the real OpenCode agent with TRL’s experimental AsyncGRPOTrainer—the black-box path where the agent owns its loop and OpenEnv records token ids/logprobs via a transparent proxy.

New page opencode-agent-grpo.md explains when to use this pattern vs Wordle (TRL-driven reset/step) and BrowserGym (white-box harness), walks through session factory → trace → HarnessRolloutWorker → GRPO, and links to TRL’s harness docs, opencode.py script, and opencode_env. The tutorials index table and _toctree.yml get a matching entry (“Coding Agent Training with TRL”).

Reviewed by Cursor Bugbot for commit 5702e24. Bugbot is set up for automated code reviews on this repo. Configure here.

Copilot AI review requested due to automatic review settings July 31, 2026 10:17

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@burtenshaw burtenshaw added documentation Improvements or additions to documentation size: small Small pull request labels Jul 31, 2026 — with Cursor
@bot-ci-comment

Copy link
Copy Markdown

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alignment Review Report

Scope: Docs-only PR — 3 files, +65 lines (docs/source/_toctree.yml, docs/source/tutorials/index.md, new docs/source/tutorials/opencode-agent-grpo.md). No Python/source changes.

Automated Checks

  • Lint: N/A for this PR (no .py files changed). For reference I ran .claude/hooks/lint.sh after installing uv; it fails only on pre-existing ruff format drift in ~20 envs/* Python files (e.g. envs/opencode_env/*.py) that this PR does not touch — consistent with the baseline drift noted in AGENTS.md. (Side note, unrelated to this PR: the hook also reformats python code blocks inside envs/**/README.md but only reverts .py, so it leaves .md files dirty.)
  • Debug code: CLEAN for this PR. .claude/hooks/check-debug.sh lists many print()s and 3 TODOs, but all are pre-existing in src/; none are in the changed docs files.

Doc-specific checks (all pass)

  • _toctree.yml entry tutorials/opencode-agent-grpo resolves to the new file. ✓
  • Internal links wordle-grpo.md and browsergym-harness.md exist. ✓
  • API references are accurate: OpenCodeSessionFactory, transparent_proxy mode, and session verify() all exist in envs/opencode_env/harness.py, and the proxy description (/v1/chat/completions interception, per-turn ids + logprobs) matches envs/opencode_env/README.md. ✓
  • > [!NOTE] alert syntax matches the established convention across the other tutorials. ✓

Open RFCs Context

All RFCs are In Review except RFC 010 (Draft). The directly relevant one is RFC 005 — Agentic Harness Integration (In Review, @Darktex), which is exactly the area this tutorial documents (training a real coding-agent harness).

Tier 1: Fixes Required

None. No mechanical, lint, debug, or broken-reference issues in the changed files.

Tier 2: Alignment Discussion

Principle Conflicts

None identified. Notably the described reward path aligns with rewards inside environment (PRINCIPLES.md / RFC 004): the domain scoring lives in the session's held-out verify() inside the env, which "the agent never sees" — consistent with the reward-boundary and agents cannot reset invariants. Training the production agent as-is also supports minimize lifecycle deltas and minimize human-agent divergence.

RFC Conflicts

ALIGNMENT FLAG: Tutorial canonizes a harness-training design that diverges from the abstraction proposed in RFC 005 (In Review)

  • Principle/RFC at stake: RFC 005 — Agentic Harness Integration (Status: In Review)
  • The concern: RFC 005 proposes harness training via a HarnessEnvironment (extends MCPEnvironment) where each step() is one conversational turn the orchestrator drives, plus a HarnessAdapter, HarnessEvent/HarnessResponse trajectory, and a Rubric computing reward after each turn. This tutorial instead documents the shipped opencode_env + TRL path: the agent owns its entire loop, a transparent_proxy intercepts LLM calls to capture token ids/logprobs, TRL's HarnessRolloutWorker rebuilds training rows from the trace, scoring uses the session's verify(), and adaptation happens via rollout_reward_fn / train_turn_fn / agent_turn_fn. RFC 005 explicitly rejected the "each step() is the entire episode" model that this black-box path effectively uses. The divergence is not introduced by this PR (it already exists in opencode_env + TRL) — the PR just makes it canonical in user-facing docs. Per the two-tier model, flagging so the team can reconcile: most likely by updating RFC 005 to reflect the shipped Session / proxy / HarnessRolloutWorker design (or documenting both paths side by side). Non-blocking.
  • Suggested reviewer: @Darktex (RFC 005 author; also authored the reward-boundary lines in PRINCIPLES.md/INVARIANTS.md). cc @burtenshaw (tutorials/docs).

Summary

  • 0 mechanical issues to fix (Tier 1)
  • 0 principle conflicts
  • 1 RFC conflict to discuss (RFC 005 divergence — non-blocking; docs describe shipped reality, RFC likely needs updating)

Overall a clear, well-structured tutorial that accurately reflects the opencode_env implementation and is nicely positioned against the other two GRPO tutorials. The only item for humans is the RFC 005 reconciliation above.

Open in Web View Automation 

Sent by Cursor Automation: Pre-review

This tutorial covers the black-box training path: training the actual
[`opencode`](https://opencode.ai) coding agent, with its own planner, tools,
context management, and stop condition, using TRL's experimental
`AsyncGRPOTrainer`. The agent owns its loop, and OpenEnv captures what it did.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ALIGNMENT FLAG (Tier 2, non-blocking) — RFC 005: Agentic Harness Integration (In Review)

This "agent owns its loop" black-box model diverges from RFC 005's proposed abstraction, where harness training goes through a HarnessEnvironment with per-turn step() + HarnessAdapter + Rubric. RFC 005 explicitly rejected the "one step() = whole episode" model that this path effectively uses.

The divergence already exists in the shipped opencode_env + TRL code — this tutorial just makes it canonical in the docs. Worth reconciling: probably update RFC 005 to reflect the shipped transparent_proxy / HarnessRolloutWorker / session-verify() design (or document both paths). cc @Darktex (RFC 005 author).

Copilot AI review requested due to automatic review settings July 31, 2026 10:26

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@sergiopaniego sergiopaniego mentioned this pull request Jul 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation size: small Small pull request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants