- Trace2Env is a training-free framework for agentic world modeling, designed for faithful, stateful, and long-horizon simulation of textual environments.
- Environments built with Trace2Env can be used to train agents without the real system, test agents in safe and reproducible sandboxes, build stateful mocks for tools and APIs, or reconstruct unavailable, private, or legacy environments.
- Trace2Env does not recover the original executable system. Instead, it automatically reconstructs a model of the environment dynamics from observed action–observation trajectories.
- Trace2Env is not tied to a particular environment domain. The paper evaluates it on terminals, software repositories, Android and web apps, enterprise services, and text games. The same framework can be applied to other text-interactive systems, including internal enterprise tools, ticketing workflows, cloud and DevOps consoles, API and MCP backends, and other textual worlds.
Specifically, Trace2Env works in two phases:
-
Offline reconstruction. Past trajectories are processed and organized into a worldbook containing environment schemas, transition rules, constraints, invariants, observation contracts, grounded evidence, and demonstrations. Check out what a worldbook looks like here.
-
Agentic simulation. A world model agent actively calls tools to inspect the worldbook, together with the maintained episode state and episodic memory, and infers the next observation together with the state changes that should persist. A shared runtime harness verifies the proposal against the schemas, rules, and invariants and commits the accepted changes, so the consequences of a task agent's action carry into later turns.
-
Build from tens of traces. Worldbook construction needs only recorded interactions, not access to the original executable environment, its source code, dependencies, or infrastructure.
-
Agentic world modeling. The world model agent actively consults the knowledge needed for each action instead of relying on a single flattened environment prompt.
-
Stateful, long-horizon simulation. Verified state changes persist across turns, allowing the simulated environment to preserve the consequences of earlier actions throughout an interaction.
-
Evaluated as a world model. Trace2Env supports both next-observation prediction (Qwen-AgentWorld) and successive interaction with the world model to evaluate its long-horizon consistency.
- 🚀 [2026-10] Trace2Env is released. The paper, From Traces to Agentic Worlds: Agentic Language World Models for Interactive Environment Simulation, is on arXiv and Hugging Face Papers; the project page summarizes the method and results, and the live demo lets you play against a reconstructed terminal.
Python 3.11 or newer. The demo below needs no model and no API key.
git clone --recurse-submodules https://github.com/ruyue0001/trace2env.git
cd trace2env
python -m pip install -e '.[dev]'
python -m pytest # 285 tests, no network
python -m trace2env init-demo --output .trace2env/demo-authored
python -m trace2env inspect .trace2env/demo-authored --action withdraw
python -m trace2env replay .trace2env/demo-authored \
--cases examples/replay/ledger_cases.jsonl --output work/demo-replay.json \
--promote-to .trace2env/demo-validated
python -m trace2env simulate .trace2env/demo-validated --session .trace2env/demo-session \
--action '{"type":"withdraw","arguments":{"amount":25}}' # -> "Withdrew 25. Balance: 75.0"The demo worldbook is hand-authored to show the machinery: replay validation against reference cases, promotion to a
validated package, and a persistent session. In the code, a worldbook is called a package and one episode's state and
audit a session. docs/WALKTHROUGH.md follows it file by file.
Package destinations (--output, --promote-to) must not already exist.
python -m trace2env ingest TRACES --output work/parsed # deterministic parse and segmentation, no model
export OPENAI_API_KEY=... # or --base-url URL --api-key-env VAR for any OpenAI-compatible server
python -m trace2env reconstruct TRACES --environment-id my.env --name "My environment" \
--description @description.md --domain terminal \
--work-dir work/build --cache-dir work/cache --output work/my-env-candidate-v1
python -m trace2env inspect work/my-env-candidate-v1 --action some_action
python -m trace2env simulate work/my-env-candidate-v1 --session work/session-1 --allow-unvalidated \
--initial-state @initial_state.json --agent --action '{"type":"some_action","arguments":{...}}'docs/TRACE_COLLECTION.md covers the trace formats and the converters for Terminal-Bench,
WebArena, AgentWorldBench, EnvScaler, ALFWorld and SciWorld traces; docs/OFFLINE_VALIDATION.md
how to replay, promote and repair a worldbook; docs/ARCHITECTURE.md what each generated file is
and who consumes it. For research runs, scripts/pilot_stages.py runs the reconstruction stage by stage and keeps an
inspectable version of every stage (inputs, every model call, outputs).
docs/RUNTIME_HARNESS.md explains how one action is simulated: rule selection, the agent's brief and tools, verification, trust policy, rendering, commit. Two evaluation protocols are built in:
- Single-turn next-state prediction on AgentWorldBench:
awb-runpredicts held-out turns with the harness or with the official prompting layout and its augmented variants,awb-judgeandawb-scoreport the official judge and aggregation (docs/AGENTWORLDBENCH.md). - Multi-turn interaction, where a task agent acts inside the simulated environment and its action sequence is
replayed in the real one:
envscaler-long-horizonfor EnvScaler environments (docs/LONG_HORIZON.md), and the ALFWorld and SciWorld scripts (docs/ALFWORLD_TRACE2ENV.md).
REPRODUCING.md maps every experiment of the paper to its data, scripts and flags. The scripts of each
environment are under experiments/. The frozen Terminal worldbook is published with the
live demo; the other frozen worldbooks and the collected traces are available on request.
| Path | Contents |
|---|---|
src/trace2env/ |
Library and CLI: trace adapters, reconstruction, compiler, runtime harness, world model agent, state tracking, benchmark adapters, long-horizon runner |
tests/ |
285 tests with scripted models; no network |
scripts/ |
Stage-by-stage reconstruction driver, trace collection (Terminal-Bench 2.0 with Harbor, WebArena through Playwright MCP), ALFWorld and SciWorld runs, worldbook ablation |
experiments/ |
Launchers, cross-fit tooling, audits and report scripts of the paper's experiments, per environment |
docs/ |
Architecture, runtime harness, offline validation, prompt contracts, trace collection, benchmark protocol, long-horizon evaluation |
examples/ |
The authored ledger demo and a synthetic benchmark file for smoke tests |
baseline/Word2World |
Submodule used by the ALFWorld and SciWorld scripts (task lists, grammar, simulator adapters) |
DEVELOPMENT.md has the commands, the code map and the design constraints to preserve.
If you find Trace2Env useful in your research, please consider citing our paper:
@article{long2026agenticworlds,
title={From Traces to Agentic Worlds: Agentic Language World Models for Interactive Environment Simulation},
author={Long, Quanyu and Chen, Xiao and Chen, Jianda and Zhang, Haozhen and Hu, Qisheng and Bao, Jianzhu and Wang, Wenya},
journal={arXiv preprint arXiv:2610.06100},
year={2026}
}
