What is an agentic RL environment? State, actions, observations and reward
At a glance
An agentic RL environment is a program an AI agent acts in over many turns. It holds hidden state, accepts actions such as tool calls, returns observations such as text or screenshots, and pays a reward when it checks the outcome. Gymnasium's reset and step are the usual way to write one.
- Compiled by
- AgenticRLEnvironments editors
- First recorded
- Last revised
- Reading time
- 5 min
An agentic RL environment is the world an AI agent acts in during training or evaluation: a program with its own state, a set of actions the agent may take, what the agent gets to see after each action, and a rule that scores the result. "Agentic" means the agent takes many steps, usually by calling tools, running commands or using an application, before anything is scored.
What are the parts of an agent environment?
An agent environment has five parts: state, actions, observations, reward and an end condition.
Table: The parts of an agent environment, with examples from published environments
| Part | What it is | Example |
|---|---|---|
| State | Everything the environment knows, most of which the agent does not observe | The orders, users and products in a shop's database |
| Action | What the agent may do in one step | A tool call, a shell command, a click, a search query |
| Observation | What the agent sees after an action | A tool's text output, a web page, test results, a screenshot |
| Reward | A number that says how well the agent did | 1 if the right order was cancelled and nothing else changed, else 0 |
| End condition | When the episode stops | The agent says it is done, or a step limit is reached |
Published environments fill these slots in different ways. WebShop, a simulated shopping site, gives two kinds of action: a search with a text query and a click on a text button, and it computes a reward between 0 and 1 by matching the bought product's attributes, options and price against the instruction (WebShop paper, arXiv 2207.01206, read 2026-11-26). AppWorld, a world of nine apps operated through 457 APIs, lets the agent write code against those APIs and scores the result with state-based unit tests that also look for collateral damage (AppWorld, arXiv 2407.18901, read 2026-11-26).
How does Gymnasium define an environment?
Gymnasium defines an environment as a class with two main methods, reset and step, and two declared spaces, action_space and observation_space.
reset(seed=None, options=None)starts an episode and returns the first observation and an info dictionary. Passing an integer seed re-initialises the environment's random number generator, so the same seed gives the same start.step(action)applies one action and returns five values:observation, reward, terminated, truncated, info.action_spaceandobservation_spacedescribe which actions and observations are valid.close()releases resources; the documentation names "database or HTTP connections" among them.
The Gymnasium API reference describes terminated as "Whether the agent reaches the terminal state (as defined under the MDP of the task)" and truncated as "Whether the truncation condition outside the scope of the MDP is satisfied", typically a time limit (Gymnasium Env API, read 2026-11-26). Gymnasium replaced the older single done flag with these two in version 0.26 (same page). The current release on PyPI is gymnasium 1.4.0, published 5 October 2026, for Python 3.10 or later (gymnasium on PyPI, read 2026-11-26).
The library's introduction calls the cycle of observe, act and receive a new state and reward the "agent-environment loop", repeated until the episode ends (Gymnasium basic usage, read 2026-11-26).
Why does the terminated and truncated split matter for agents?
The split matters because a learning algorithm must treat "the task ended" and "we ran out of steps" differently. When an episode is truncated, the agent might still have succeeded with more steps, so the value of the last state is not zero. When it is terminated, the outcome is final.
For language agents this shows up as two common rules:
- Terminate when the agent calls a
finishorsubmittool, or does something the task defines as fatal, such as deleting the record it was meant to fix. - Truncate at a step limit or a wall-clock limit. Gymnasium's
registertakesmax_episode_steps, "The maximum number of episodes steps before truncation" (Gymnasium registry API, read 2026-11-26).
Never record a truncated episode as a failure of the task in training data without saying so. It mixes "wrong answer" with "too slow".
Why are agent environments partially observable?
Agent environments are partially observable because the agent sees only what its tools and screens show, not the state behind them. A shop's database, a repository's full history or a server's logs exist whether or not the agent looks.
The ScienceWorld paper notes that most approaches to interactive text environments "frame reasoning as a partially-observable Markov decision process (POMDP)" (ScienceWorld paper, arXiv 2203.07540, read 2026-11-26). In practice this means:
- The observation is a view, not the state. Design it on purpose: what a real user of the app would see.
- The agent has to take actions that only gather information, such as reading a file or listing orders.
- The reward should be computed from the hidden state, not from what the agent says it did.
What makes an environment "agentic" rather than single-turn?
An environment is agentic when the agent must take several actions, each depending on what the previous ones returned, before the outcome is known. A single-turn task, such as answering one math question, has one action and one reward.
Table: Single-turn tasks and agentic environments compared
| Single-turn task | Agentic environment | |
|---|---|---|
| Actions per episode | One answer | Many tool calls, commands or clicks |
| State | None, or the prompt only | A database, file system, app or simulated world |
| Reward from | Comparing the answer with a reference | Checking the final state, running tests, or both |
| What can go wrong outside the agent | Little | Services time out, state leaks between episodes, tools change |
| Cost of one episode | One model call | Many model calls plus the environment's compute |
SWE-Gym is an example of the agentic kind: each of its 2,438 Python task instances comes with "a codebase with an executable runtime environment, unit tests, and a task specified in natural language" (SWE-Gym, arXiv 2412.21139, read 2026-11-26).
What should I decide before building one?
Decide five things before writing code:
- The action interface. Tool calls as JSON, shell commands, code, or screen actions. Fewer, clearer actions make credit assignment easier.
- The observation. What a capable person doing the job would see, trimmed to fit the model's context.
- The reward. Which final state counts as success, and how a program checks it.
- The limits. Maximum steps, maximum time, and which actions end the episode at once.
- The seed. Which parts of a task are random, and how one integer reproduces them.
The rest of this site covers each step: wrapping a task in the Gymnasium API, cloning a web app, generating tasks, writing graders and designing rewards.
What we read for this article
- Gymnasium Env API, read 2026-11-26
- Gymnasium basic usage, read 2026-11-26
- Gymnasium registry API, read 2026-11-26
- gymnasium on PyPI, read 2026-11-26
- WebShop (arXiv 2207.01206), read 2026-11-26
- AppWorld (arXiv 2407.18901), read 2026-11-26
- ScienceWorld (arXiv 2203.07540), read 2026-11-26
- SWE-Gym (arXiv 2412.21139), read 2026-11-26
Field questions
What is the difference between an environment and a benchmark?
An environment is the world the agent acts in, plus its reward. A benchmark is a fixed set of tasks in one or more environments, with a scoring rule and a published leaderboard. The same environment can serve training, where tasks are generated freely, and evaluation, where a frozen task set is used.
What is the difference between terminated and truncated in Gymnasium?
Terminated means the episode reached an end defined by the task, such as success or an unrecoverable failure. Truncated means it was cut off for a reason outside the task, usually a step or time limit. Gymnasium returns both flags from step, and you reset the environment when either is true.
Why is an agent environment partially observable?
Because the agent only sees what its tools return or what is on screen, never the full database, file system or server state behind them. Text environments are often framed as partially observable Markov decision processes for this reason.
Does an LLM agent environment need a numeric reward?
For reinforcement learning, yes. For evaluation, a pass or fail is enough, and it is the same check. Many agent environments give a reward only at the end, from a program that inspects the final state.