Guide · RL Environment Design
verl explained: agent loops, tools and rewards for multi-turn RL environments
verl is the RL training library behind a long list of reasoning and agent recipes. It has no environment class: the environment is whatever your agent loop and tools touch. This guide covers where verl draws that line, what its tool lifecycle actually does, and where API-backed environments lose their reset.
Last reviewed against the sources listed at the end of this guide.
At a glance
- What it is
- Volcano Engine Reinforcement Learning for LLMs: an RL training library, the open-source version of the HybridFlow paper
- Made by
- Started by ByteDance's Seed team; maintained by the verl community at
verl-project/verlon GitHub - Environment API
- No
Envclass: anAgentLoopBase.run()per prompt, plus tools built onBaseToolor@function_tool - Rollout engines
- vLLM and SGLang (HF Transformers too); training on FSDP, FSDP2 or Megatron-LM
- Install
- Driven by
uvand the repository'suv.lock; Python 3.10 or newer, CUDA 12.8 or newer - License
- Apache-2.0
What verl is
verl (Volcano Engine Reinforcement Learning for LLMs) describes itself as a flexible, efficient and production-ready RL training library for large language models, and as the open-source version of the HybridFlow paper. ByteDance's Seed team started it; it is now maintained by the verl community under the verl-project organization on GitHub (the older volcengine/verl address redirects there), with documentation at verl.readthedocs.io.
It is a trainer first. PPO, GRPO and the other algorithms it ships run on FSDP, FSDP2 or Megatron-LM for training and on vLLM or SGLang for generating rollouts. Many published agent recipes build on it, including Search-R1, ReTool, RAGEN, verl-agent and verl-tool, which is why people building environments for LLM agents end up reading its code.
Unlike SkyRL, which has SkyRL-Gym, or OpenEnv, which is nothing but an environment contract, verl has no environment class. There is no reset() and no step(). What you write instead is an agent loop, the code that runs one rollout, and the tools that loop calls. Everything this site means by an environment lives inside those two.
The agent loop: one run() per prompt
Multi-turn and agentic rollouts go through the agent loop, which verl's docs mark as ready for use but still alpha, with an API that may change. For each prompt in a batch, an AgentLoopWorker builds a fresh instance of your AgentLoopBase subclass and awaits its run() coroutine. Many of those coroutines run concurrently on each worker, so a tool waiting on a slow call does not leave the GPUs idle.
class AgentLoopBase(ABC):
@abstractmethod
async def run(self, sampling_params: dict[str, Any], **kwargs) -> AgentLoopOutput:
"""Run agent loop to interact with LLM server and environment.
Args:
sampling_params (Dict[str, Any]): LLM sampling params.
**kwargs: dataset fields from `verl.utils.dataset.RLHFDataset`.
"""| Field of AgentLoopOutput | What it holds |
|---|---|
prompt_ids | The prompt's token ids. |
response_ids | Every token after the prompt: what the model generated and what the tools sent back. |
response_mask | 1 for tokens the model generated, 0 for tool responses, so the loss only trains on the model's own tokens. |
reward_score | Optional. Leave it None and verl computes the reward after the loop; set it if your loop already knows the score. |
num_turns | User, assistant and tool turns in the conversation. |
extra_fields | Anything else. The built-in tool loop puts turn_scores and tool_rewards here, and your tools can add their own. |
The loop talks to the model in token ids, not chat messages: it calls generate() with prompt_ids and gets response_ids back. verl's docs explain why. Re-encoding a decoded or tool-parsed message does not always give back the tokens the model produced, and training on the re-encoded version drifts from the policy's distribution. For an environment author that means the observation the agent sees is the token sequence, and whatever your tool returns is tokenized into it.
Each dataset row picks its loop by an agent_name field. single_turn_agent is the default and tool_agent is the built-in multi-turn tool loop. A loop of your own is registered with the @register("name") decorator or listed in the YAML file named by actor_rollout_ref.rollout.agent.agent_loop_config_path. The agentic docs also require data.return_raw_chat=True and actor_rollout_ref.rollout.mode=async.
ToolAgentLoop: how a multi-turn rollout runs
Most environments do not need a custom loop. ToolAgentLoop runs the usual cycle: generate, parse tool calls out of the response with the parser named by multi_turn.format (such as hermes), run the calls, append the results as tool messages, and generate again. It stops when the model answers without calling a tool, when the response reaches the configured length, or when it hits multi_turn.max_assistant_turns or max_user_turns.
max_parallel_callscaps how many tool calls from one turn run; the rest are dropped, not queued.max_tool_response_lengthtruncates long tool output, from the side set bytool_response_truncate_side. Decide how much of an API response the agent reads yourself rather than letting truncation decide.- An unknown tool name, arguments that are not valid JSON, or an exception inside the tool all come back to the model as a
toolmessage with the error text and a reward of0.0. The rollout carries on. - A row can narrow the tool list with
extra_info.tool_selection, which is how one run can give different tasks different action spaces.
BaseTool and what create() and release() really wrap
Tools come in two kinds. A @function_tool is a plain Python function whose schema verl infers from its type hints and docstring; it is stateless by design and gets no lifecycle hooks. A BaseTool subclass, listed in the YAML file named by multi_turn.tool_config_path, has five methods:
| Method | What it does |
|---|---|
create(instance_id, **kwargs) | Makes a tool instance and returns its id and a ToolResponse. |
execute(instance_id, parameters, **kwargs) | Runs the call and returns a ToolResponse, a step reward and a metrics dict. |
calc_reward(instance_id) | Returns a reward computed from the tool's state. |
release(instance_id) | Tears the instance down. |
get_openai_tool_schema() | The schema the model sees, in OpenAI function format. |
Read the lifecycle in the code, not only the docstring. BaseTool's docstring says create makes an instance for a trajectory, and the docs point to it for per-trajectory state. In ToolAgentLoop._call_tool on verl's main branch at the review date above, create() runs before each individual call and release() in a finally right after it. An instance lives for one call, not one episode. State a tool keeps per instance_id is gone by the next turn.
Two more details matter for state. The tool objects are loaded once per worker and shared by every trajectory that worker runs, so anything stored on self is shared across concurrent rollouts. And execute() is passed the rollout's AgentData as agent_data, whose extra_fields the source describes as the place for tool session data. That is the one per-trajectory store the built-in loop gives a tool.
Where the reset happens in verl
Because there is no reset(), the episodic reset contract has to be built from what verl does give you: a fresh agent loop instance per prompt, the dataset row passed to run() as keyword arguments, and per-tool create_kwargs from the row's extra_info.tools_kwargs.
"agent_name": "tool_agent",
"reward_model": {"style": "rule", "ground_truth": solution},
"extra_info": {
"need_tools_kwargs": True,
"tools_kwargs": {
"calc_gsm8k_reward": {
"create_kwargs": {"ground_truth": solution},
},
},
},- Put everything that defines the starting world in the row: a fixture id, a seed, the records the task starts from. Since
create_kwargsreach every call, a tool can find its world from them; setneed_tools_kwargsso verl warns about rows that are missing them. - Key backend state by something that belongs to the rollout, such as
agent_data.request_idor an entry you put inagent_data.extra_fields, never by the tool'sinstance_idand never onself. - If your backend needs a real setup and teardown per episode, write your own agent loop (subclass
ToolAgentLoopto keep its parsing and tokenization) and do both inrun(), around the conversation. That is the only place verl guarantees runs once per rollout. - GRPO samples each prompt several times (
actor_rollout_ref.rollout.n), and those copies run concurrently. Two copies of one task must not write to the same backend state; that is a worker isolation decision verl leaves to you. - Record what you need to reproduce a trajectory in
extra_fields; it travels with the output to the reward function.
Step rewards, the reward function and what the trainer sees
Each execute() returns a step reward, but the built-in loop does not add those up for you. It collects them in tool_rewards inside extra_fields. Unless your loop sets reward_score, the trajectory's reward is whatever the reward function returns, called once on the finished rollout and placed on its last token.
def my_reward_fn(data_source, solution_str, ground_truth, extra_info=None):
return len(solution_str) / 100Point verl at it with reward.custom_reward_function.path and reward.custom_reward_function.name. In the default reward manager on the main branch, extra_info carries the row's own extra_info plus the rollout's extra_fields (so tool_rewards, turn_scores and anything your tools stored) and num_turns. That is the hook for combining step and outcome rewards: sparse vs. dense rewards in agentic API tasks covers which to start with.
solution_str is the decoded response, tool output included. For an API task, score the backend's state after the rollout, which your tools can leave in extra_fields, rather than what the transcript claims happened. Otherwise a backend that accepts a bad write is rewarded for it, which is how reward hacking through fidelity gaps starts.
Wrapping a third-party API as a verl tool environment
Search, code execution and math checking, the tools verl's own examples use, are close to stateless. Most agentic API tasks are not: open a GitHub issue, refund a Stripe charge, post to Slack. Each needs a backend the rollout can own, start from a known state and throw away, and in verl you have to wire that up yourself.
| Backend behind the tools | Fresh per rollout? | What goes wrong |
|---|---|---|
| The live API or a vendor sandbox | No: every rollout on every worker shares one account | Rate limits across a GRPO group, credentials on every worker, rollouts that see each other's writes |
A stateless mock (a @function_tool returning fixtures) | Trivially, because it never changes | Reads ignore writes, so the agent learns the wrong causal model |
| A stateful simulator per rollout | Yes: start it seeded from the row in your loop's run(), stop it when the rollout ends | Only as good as its fidelity to the real API; check how the vendor verifies it |
The third row is the one that fits verl's async loop. Rystic, for example, builds stateful simulators of APIs such as Slack, GitHub and Stripe that run locally or in CI; evaluate an option like that alongside writing your own. Scaffolding a simulated API backend as a Gym environment walks through the shape of that backend, and if a tool call waits on a real network round trip, structuring the training loop clock covers what that does to throughput.
- Subclass
ToolAgentLoop, start a backend seeded from the row before the first turn, and stop it after the last. - Hand the backend's address to your tools through
agent_data.extra_fields, not through state on the tool object. - Have each tool's
execute()act on that backend and return what the agent should read. - Write the backend's final state into
extra_fieldsand score it in your reward function. - Keep live credentials off the workers; a simulator should not need them.
Frequently asked questions
Does verl have a Gym-style environment API?
No. verl has no Env class, reset() or step(). An environment is expressed as an agent loop (AgentLoopBase.run(), one instance per prompt) and the tools it calls. Projects built on verl, such as verl-agent and verl-tool, add their own abstractions on top; check each one's docs for its interface.
Is verl the same thing as volcengine/verl?
Yes. The project moved from volcengine/verl to the verl-project organization on GitHub; the old address redirects. It is still Volcano Engine Reinforcement Learning for LLMs, started by ByteDance's Seed team.
Does a BaseTool instance live for the whole trajectory?
Not in ToolAgentLoop on the main branch at the review date: create() and release() wrap each individual tool call. Keep per-rollout state in agent_data.extra_fields or in a custom agent loop, and check the source of the version you pin.
How do step rewards from tools reach the policy?
Only through your reward function. The built-in tool loop stores each call's reward in tool_rewards, which the default reward manager passes to compute_score inside extra_info. What the function returns is the trajectory's reward, placed on the final token.
Does verl cost anything?
The code is open source under Apache-2.0. Training costs whatever your GPUs cost: check your cloud provider's pricing for the hardware you run it on.
Should I pick verl or SkyRL for an agentic environment?
They put the boundary in different places. SkyRL gives you an environment class with init(), step() and close(); verl gives you an agent loop and tools and leaves the episode lifecycle to you. Either can work against an API backend if the reset is built in; pick on the rest of the stack you need, and check each project's current docs.





