Repository navigation
feat(training): train with TRL on a bundle served as an OpenEnv env - #363
Open
earakely-scale wants to merge 2 commits into
Open
earakely-scale wants to merge 2 commits into
earakely-scale wants to merge 2 commits into
Conversation
agent_env.training.trl, behind a new `trl` extra (openenv and datasets): AgentEnv(url) reads a build_app server's tasks into a dataset, one row per task, and builds TRL's environment_factory. Each environment holds one session on the server and plays one episode at a time over OpenEnv's WebSocket. The turn's tools become typed, documented methods, reset runs in the background, end_turn hands over the next prompt, and get_reward owns the reward, None when the episode ended in an error. GRPOTrainer and AsyncGRPO take both unchanged. AgentEnv.local(bundle) serves the bundle in the training process. The Task API now names each task's toolset (the played agent's envs, role, and whether it gets bash). Tasks with different toolsets take TRL's multi-environment mode. The dependency tests now allow an extra that includes another, as trl includes openenv. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
… and tool access joins the toolset - end_turn takes the reset deadline, not a tool's. The server answers it once the next turn opens or the verifiers have scored the episode. - factory lists each toolset's tools in turn, so a server that allows one session still sets up. - A task's toolset now includes its modify_env_tool_access changes for the played agent's role. Tasks that hide different tools from the same role get classes of their own. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
TRL's
GRPOTrainerand AsyncGRPO can now train on a bundle served byagent_env.openenv.build_app, through TRL's ownenvironment_factory, with no changes to TRL.agent_env/training/trl.py, behind a newtrlextra (agentenv-framework[openenv]anddatasets). TRL itself stays the trainer's to pin.agent_env/training/is where later trainers' modules go, each behind its own extra.env.datasethas one row per task of the split, read from the server's Task API: the prompt as chat messages, plussplitandindex.env.dataset_for(split)reads any other split.env.factoryis a generated class. Its methods are the turn's tools, typed and documented from their JSON Schema (ported from the privateagentenv-trl'sAgentEnvSpec), plusend_turn.GenericEnvClient).resetreturns at once, sinceGRPOTrainerresets one rollout at a time. The first tool call orget_rewardwaits for the deploy.end_turnanswers with the next turn's prompt, so multi-turn tasks work as they are.end_turnwaits up to the reset deadline rather than a tool's, since the last one runs the task's verifiers.get_reward, which both trainers read, so noreward_funcsare needed. It returnsNonewhen the episode ended in an error, didn't match its row, or a tool missed its deadline. TRL turnsNoneinto NaN. Instances are reused across rollouts, as TRL's pool reuses them.reset, and the error namesMAX_CONCURRENT_ENVS/max_concurrent_envs=.toolset: the played agent's envs, its role, the task'smodify_env_tool_accesschanges for that role, and whether its turns offerbash. Buildingfactoryplays one task per toolset, one at a time, to list its tools. Tasks with different toolsets get one class each (factoryis then a dict), and every row carries TRL'senvironmentcolumn.AgentEnv.local(bundle, ...)servesbuild_appin process on a loopback port. A trainer that exits or crashes ends the episodes it left running and stops that server, using the same exit hook asagentenv-trl.build_app's app construction is split into_app(served, ...), so the unit tests serve hand-built tasks through the same server.trlincludesopenenv). A new check confirms that importingagent_env.training.trlwithout the extra names[trl].THIRD_PARTY_NOTICES.mdadds the five runtime packages the extra brings: datasets, dill, multiprocess, pyarrow and xxhash. Every license link resolves.OpenEnv 0.10 requires
fastmcp<4and so mcp 1. A trainer with OpenEnv installed therefore runs vLLM 0.29 or older, which TRL 1.16 allows. The README says so. Once OpenEnv releases FastMCP 4 and agent-env supports mcp 2, the helper runs on vLLM 0.30+ unchanged.Tests
tst/unit/training/trl_test.py: 18 tests against the real OpenEnv server over the Episode API's fake steps, driven the way TRL drives it:end_turnthat waits past it for a slow verifier;local()with teardown atcloseand at exit;tst/integration/training/trl_test.pyon local Docker, 2 tests, 46 s:+bashtoolset of its own, plays throughbash, and scores 1.0. Nothing is left running.get_json_schema, the function TRL uses to show tools to the model, renders PortSim's real tools through these methods exactly as it did foragentenv-trl.tst/integration/openenv: 6 of 7 pass locally. The other fails building the echo test agent'slinux/amd64image on a Mac without buildx. That happens after its OpenEnv checks pass, and it's unrelated to this change.🤖 Generated with Claude Code


Confidence Score: 5/5
The PR appears safe to merge; all three previous findings are addressed.Summary
Adds TRL training on bundles served through OpenEnv, with task datasets, generated tool classes, owned rewards, and an optional local server.
Diagram
sequenceDiagram participant Trainer as TRL trainer participant Env as Generated environment participant Server as OpenEnv server participant Episode as Task episode Trainer->>Env: reset(dataset row) Env->>Server: Start task Server->>Episode: Deploy and open turn Trainer->>Env: Call tools / end_turn Env->>Server: WebSocket requests Server->>Episode: Run tools and finish turns Episode-->>Env: Final reward Trainer->>Env: get_reward() Env-->>Trainer: RewardReviews (2) · Last reviewed commit: "fix(training): end_turn waits for the sc..." · Reviewed by Greptile