Hugging Face

Training Agents 4: From reward functions to environments.

Published 2026-09-11 · Duration 1:13:40

Summary

This session details the evolution of agent training from simple functional reward signals to complex, stateful environments. The core concept is the `reset()/step()` contract, which allows agents to interact with a simulated world (the environment) over a sequence of actions. The discussion covers the OpenM framework, which standardizes environment definition, and its integration with TRL (Transformer Reinforcement Learning) using isolated compute environments like Hugging Face sandboxes. This enables training sophisticated agents, such as coding agents (OpenCode), on complex, multi-step tasks while maintaining reproducibility and isolation.

Download summary

Key takeaways

  1. The Shift to Stateful Environments 1:42

    For agents performing sequences of actions (e.g., tool calls, file edits), the reward signal must come from the environment's state after an action, rather than being a simple Python function evaluated once. This requires adopting the standard `reset()/step()` contract, moving from sparse signals to continuous interaction loops.

  2. The OpenM Ecosystem 5:30

    OpenM provides a standardized, containerized way to define any task as an environment. It packages the task, the runtime (compute backend), and the grading components (verifiers, rewards) into a single, shareable unit that can be deployed on various platforms (e.g., Hugging Face Spaces, Kubernetes).

  3. Advanced Agentic Training Loops 9:10

    Training can be managed by two models: the 'White Box' (where the training framework owns the loop) and the 'Black Box' (where the agent/harness owns the loop). The latter requires a 'capture proxy' to intercept agent calls and send the resulting rollout graph back to the trainer for policy updates.

  4. Reproducibility and Isolation 7:30

    Environments are designed to be self-contained applications, often deployed in isolated compute environments (like HF sandboxes). This ensures that training runs are reproducible and prevents the agent from accessing or manipulating the verifiers or task description to 'hack' the reward signal.

Technical details

  • RL Environment Contract 150s

    The fundamental contract is `reset()` (to define a new world state) and `step()` (to move through the world based on an action). The observation returned must include both the environment state and the reward signal for the training framework (TRL) to use.

  • OpenM Workflow 370s

    OpenM environments can be managed via a CLI with commands: `init` (to create boilerplate), `push` (to publish to the Hub), `pull` (to retrieve), and `fork` (to create variations). This allows for structured environment development and sharing.

  • Training Integration 400s

    The training process uses TRL (Transformer Reinforcement Learning) and integrates with OpenM via an `environment_factory`. This allows the trainer to instantiate and manage multiple, complex environments (e.g., OpenCode) in parallel using isolated compute resources like HF sandboxes.

  • OpenCode Demo 520s

    A practical example demonstrated training a small model (3B parameters) on OpenCode problems using a set of test cases. The reward signal is the fraction of hidden test cases passed, showing a rapid increase from 0 to 1 over 10 steps.

Mentioned resources

  • OpenM (Framework)
  • Hugging Face Hub (Platform)
  • TRL (Transformer Reinforcement Learning) (Library)
  • OpenCode (Environment/Harness)

Channel & topics

Watch on YouTube · Back to latest

This independent, AI-assisted summary is provided for commentary and informational purposes. It may contain errors or omit important context. Please watch the original video for the creator's complete presentation. Video, thumbnail, and related copyrights belong to their respective owners.