# AgentGarten: Code Worlds for Evolving Agents

AgentGarten renders code-defined simulator worlds with a shared neural renderer

Jiawei Chi, Shangchen Miao, Zhiyuan Shi, Kailu Wu, Hanyang Wang, Weiliang Chen and 9 more · arXiv · 2026-10-8

- **Problem** Game engines keep state and rules controllable, but varied visuals need costly 3D assets. Each new environment is expensive to build, even when its rules are simple.
- **Method** AgentGarten keeps world state in an engine program, and a shared neural renderer draws only what the camera sees from exported conditions.
- **Results** Agents learn from just 4 rounds, compared with millions of episodes for a conventional reinforcement learning counterpart.

## Why building varied environments is costly

Agents learn from trajectories of actions and observations, so their practice environments must keep the effects of past actions over long interactions. Simulators and game engines provide explicit state and programmable interaction rules, which keeps their dynamics controllable and inspectable. Yet making their visuals varied requires substantial 3D asset creation and complex rendering pipelines.

Each new environment therefore becomes costly to build and customize, even when its rules are simple to write.

Video world models take the opposite route and synthesize rich, interactive visual observations directly from data. In these models, task-relevant state and physical transition rules stay implicit within generated histories and learned representations. Because the state is implicit, the environment can't be directly inspected, edited, or tested for its behavior.

The authors frame this as a fundamental trade-off: controllable dynamics on one side, diverse visuals on the other.

AgentGarten is introduced to combine both sides, with each scene program running in a simulator or game engine that keeps persistent state. A shared neural renderer then synthesizes visual observations from structured conditions that the engine exports through a unified interface. This separation keeps control over state and rules while letting compatible engines share one renderer.

## Keeping state in code and appearance in the renderer

The key idea is to keep the world's state in an executable program, so the renderer only has to draw what the camera sees. The engine exports structured conditions through one unified interface, and the shared renderer turns them into observations. This separation keeps control over state and rules, while compatible engines can share a single renderer.

Formally, the engine updates the state and the camera pose from the agent's actions, then captures a structured condition from the camera. The neural renderer then produces each observation from earlier observations, the conditions up to that step, the appearance reference, and the text. The transition never reads a rendered frame, so rendering errors can't feed back into the state.

The renderer sees the state only through the conditions, so attributes such as color and material come from the reference image and the text. The conditions are colorized depth or surface normals, stored as three-channel maps. Because the three-channel representation matches RGB, the pretrained video encoder and Transformer can be reused.

Coding agents build a scene from one image or a text description, and the scene needs only coarse geometry, since appearance is left to the renderer.

## Adapting a video model to geometry and short blocks

The authors start from the Cosmos 3-Nano backbone and split its understanding and generation towers. A frozen Wan video autoencoder maps RGB and geometry videos to latents, so the appearance reference x0 is kept as a clean frame that never gets denoised. Training then runs in three stages: geometry conditioning, teacher-forcing adaptation, and Adversarial Forcing.

Geometry enters as condition tokens, built by spatially pooling each condition frame, encoding it, and grouping latent patches. The pretrained RGB input projection is reused, and a zero-initialized modality embedding is added, so the geometry tokens start with no effect. Geometry and RGB tokens share one sequence and the same Transformer layers, because the authors avoid channel concatenation and control branches to skip a pixel-aligned inductive bias.

Condition tokens get no diffusion timestep, and only noisy RGB tokens produce velocity predictions. Since estimated geometry differs from rendered geometry, the authors randomly keep depth or normals, occasionally drop both, and perturb the maps with a smooth warp and added noise.

The noisy copy never sees its own clean target, so all target blocks train in parallel with independently sampled flow times. The teacher-forcing loss averages the squared error of the velocity prediction over the M target blocks, conditioned on earlier clean latents and the reference, text, and conditions.

## Exact replay for history gradients

In standard Self Forcing, finished blocks go into a detached KV cache, so losses can't reach the computation that wrote those keys and values. Keeping that computation differentiable in one serial rollout would retain cache-formation graphs across blocks, at a substantial memory cost. The authors follow Self Gradient Forcing (SGF) and split the work into two passes.

A no-gradient rollout records each block's input U and its clean output Z at the final denoising time t\*. Both the DMD loss and the generator adversarial loss use this replayed prediction.

SGF runs its second pass as one full-sequence FlexAttention call. In finite precision, that difference can make the replay diverge from the sampled trajectory. Projections and feed-forward layers keep the same block grouping.

On one H100 with 36 layers, 480 × 832 resolution, and 61 latent frames, the FlexAttention replay differed from the cached rollout by 3.99% in relative L2 error. Block-by-block SDPA replay matched the rollout bitwise, with a replay error of 0. Forward time dropped from 2.95 s to 2.79 s, a change of −5.4%. Peak allocated memory rose from 50.83 GiB to 50.92 GiB, an increase of 0.2%.

So exactness came at almost no memory cost in this configuration, which is the only one the table measures.

## Exact R1/R2 penalty without double backward

Score distillation alone degrades visually over long rollouts, so the authors add a real-data adversarial objective. They follow DMD2 and use the relativistic pairing of R3GAN, where real-clip logits and student logits enter softplus terms. The student minimizes the DMD loss plus a weighted generator term, with the generator-side gradient injected through a linear surrogate.

R1 and R2 penalize the squared input-gradient norms of the discriminator on real and generated samples. Their parameter gradients would normally need a backward pass through a backward pass. The fused attention kernels in the backbone, such as FlashAttention, don't support this double backward. They can do this because the backbone is frozen, so only the head's parameter gradient needs exact treatment.

One vector-Jacobian product gives the gradient g, which backpropagates through the head and then the backbone. From g, the penalty is R equal to g transposed times g. One Jacobian-vector product carries g forward through the frozen backbone to give v, and neither step materializes the full Jacobian A. The authors' Figure 6 shows this as three steps: input gradient, feature JVP, and head update.

The head forward runs on the detached features z and directions v, which produces the relativistic logits and the directional terms. The paper gives no separate ablation of this penalty; the evidence for the adversarial branch comes from the renderer comparison in Section 4.1.

## Long-rollout visual quality against Self Forcing

The authors compare 30-second rollouts from a Self Forcing renderer and an Adversarial Forcing renderer on the same condition trajectories. Adversarial Forcing keeps natural textures and fine detail across the whole clip.

Both renderers receive the same condition trajectory, so the difference comes from the training objective rather than the inputs. The figure shows four moments of each 30-second trajectory, at 1 s, 10 s, 20 s and 30 s. The comparison is visual, so the evidence for the adversarial term rests on inspection of the figure rather than on a metric.

The adversarial branch sits on top of distribution matching, and the authors add it because score distillation alone degrades over long rollouts. Those settings match the throughput measurements reported later in the section.

## Serving speed of one block

The renderer has to keep pace with an agent, so the authors cut launch overhead and decoding time at serving. They wrote custom Triton kernels to fuse elementwise operations around attention, instead of relying on torch.compile. Torch.compile incurs minutes-long cold-start compilation delays, which the custom kernels avoid. A distilled tiny decoder replaces the standard VAE decoder, and it reconstructs pixel frames in under 10 ms.

At steady state, one served block of 16 frames took 438.8 ms in total on one H100 in BF16. That total gives a throughput of 36.5 frames per second. The Transformer dominates the time, at 414.4 ms for four denoising steps and cache publication. Condition encoding took 10.6 ms, and the tiny decoder with host transfer took 8.8 ms.

The measurement used a cache with five sink and 44 recent latent frames, plus four current latent frames per block. The authors averaged blocks 17 to 48 of a 48-block, 769-frame rollout over two rollouts, with the cache full. Attention is dense in this measurement, and the tiny decoder runs in FP16. So the 35-plus frames per second figure describes this serving setup, not the training setup used for the replay test.

## Hide-and-seek with agents that see only rendered frames

The authors revisit OpenAI's hide-and-seek setting, but this time the agents perceive only frames produced by the neural renderer. The agents never receive object coordinates, hidden world state, or the opponent's private observations, so their feedback comes only from pixels. Each role keeps its own playbook, a library of short Markdown skill files with one lesson per file, which may contain code.

Both successful and unsuccessful attempts feed into later revisions of the playbooks.

Three characteristic behaviours emerged during play, and Figure 10 shows them. A hider moved a barrier panel to block an entrance and build cover. A seeker carried a ramp to an inner wall and climbed over it. After an initial leap fell short, the same seeker moved the ramp closer to the wall and tried again. These maneuvers show that the agents learned multi-step physical tool-use strategies from neural-rendered first-person observations alone.

Those two milestones correspond to roughly 25 million and 100 million training episodes, as the authors summarize them. The authors stress that these numbers reflect two different learning paradigms, not a direct sample-efficiency ratio. The 2019 agents learned from random weights and operated directly on ground-truth coordinate state. For these agents the main challenge is grounding that knowledge in closed-loop sensorimotor action, not discovering concepts from nothing.

The authors argue that this pairing of a neural renderer with reflective playbooks lets agents skip tabula rasa exploration.

## The same loop in four more worlds

The authors ran the same practice procedure in four more worlds, changing only the world and its task file. In herding, two dogs see only from their own eye height and guide four sheep into a pen, holding them there for five seconds.

Each of the four worlds ran for four rounds. Figure 12 shows representative frames from round 1 and round 4 of each run.

The companion-dog engagement score rose from 13 in round 1 to 19 in round 4. The bridge time fell from 71 seconds in round 1 to 41 seconds in round 4, and both cars arrived in every round. The herding pair penned three of four sheep in round 1 and all four in every later round. The quarry loader cleared the rocks in round 1 and scored nothing in round 2.

Its score went 30, 0, 30, and 90.9 across the four rounds, so the loop didn't improve steadily there.

Table 4 lists the outcome of every round, using each world's own terminal measure. Each row reports one episode per round, so the table gives single values rather than averages. For the bridge, lower is better. Hide-and-seek in the same renderer gives a reference point, with shelters and ramp use in Table 3.

## Limits of the renderer and the evidence

Geometry conditions alone leave part of the world's state unspecified, so the renderer can't recover everything the code world holds. Material, color, and object identity aren't determined by geometry, so they must come from the reference and the visual history. The authors suggest structured text describing object attributes as one way to carry such state, for example the spin of a bullet about its long axis.

The Self Forcing comparison in Figure 8 is a set of frames with no metric attached. Adversarial Forcing keeps natural textures and fine detail in those 30-second rollouts, while Self Forcing shows repetitive surface patterns.

The replay and throughput numbers each come from one H100 setup, with 36 layers and 480 × 832 resolution. Table 1 reports a replay error of 3.99% for the SGF-style replay, while block-by-block SDPA replay is bitwise identical. Table 2 reports 438.8 ms total wall time per block and 36.5 frames/s throughput. The hide-and-seek comparison with the 2019 study crosses learning paradigms, so its episode and round counts aren't a direct efficiency ratio.

The four extra worlds ran four rounds with one episode each, so their results in Table 4 are single runs. The quarry loader's score went from 30 to 0 and back to 30 before reaching 90.9, which one episode per round can't separate from noise. The paper doesn't report variance across seeds for these worlds.

## Paper info

- **Authors**: Jiawei Chi, Shangchen Miao, Zhiyuan Shi, Kailu Wu, Hanyang Wang, Weiliang Chen, Qiyu Dai, Chengyang Li, Jinshan Ren, Jun Gao, Mingsheng Long, Yueqi Duan, Jiangran Lyu, Jialong Wu, Fangfu Liu
- **Venue**: arXiv · Preprint
- **First published**: 2026-10-8
- **Added**: 2026-10-20
- **Updated**: 2026-10-10
- **Version**: v2
- **arXiv**: 2610.12374
- **Category**: cs.CV
- **Original paper terms**: [arXiv non-exclusive 1.0](https://arxiv.org/licenses/nonexclusive-distrib/1.0/)
- **What we show**: Paper info and commentary

[Original paper ↗](https://arxiv.org/abs/2610.12374v2) · [PDF ↗](https://arxiv.org/pdf/2610.12374v2)

AI commentary is a separate explanation from the original paper and may contain errors. The original paper and figures follow each source's terms of use and any rights noted separately.

## Quote from the paper

Jiawei Chi, Shangchen Miao, Zhiyuan Shi, Kailu Wu, Hanyang Wang, Weiliang Chen, Qiyu Dai, Chengyang Li, Jinshan Ren, Jun Gao, Mingsheng Long, Yueqi Duan, Jiangran Lyu, Jialong Wu, Fangfu Liu (2026). AgentGarten: Code Worlds for Evolving Agents. arXiv:2610.12374v2. https://arxiv.org/abs/2610.12374v2

**BibTeX**

```
@misc{chi2026agentgarten,
  title = {{AgentGarten: Code Worlds for Evolving Agents}},
  author = {Jiawei Chi and Shangchen Miao and Zhiyuan Shi and Kailu Wu and Hanyang Wang and Weiliang Chen and Qiyu Dai and Chengyang Li and Jinshan Ren and Jun Gao and Mingsheng Long and Yueqi Duan and Jiangran Lyu and Jialong Wu and Fangfu Liu},
  year = {2026},
  eprint = {2610.12374},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2610.12374v2}
}
```

## Related papers

- [ChatGLM: A Family of Large Language Models from GLM-130B to GLM-4 All Tools](https://refivu.com/en/papers/9637d904-3e6d-4047-bd71-6ae5b68f90d8-chatglm-a-family-of-large-language-models-from.md)
- [FlashAttention-2: Faster Attention with Better Parallelism and Work Partitioning](https://refivu.com/en/papers/177a3817-56f7-448e-964a-a2e688dc7c81-flashattention-2-faster-attention-with-better-parallelism.md)
- [FlashAttention: Fast and Memory-Efficient Exact Attention with IO-Awareness](https://refivu.com/en/papers/cc000b48-2d42-4287-aae7-f3583a852720-flashattention-fast-and-memory-efficient-exact-attention.md)
- [SpargeAttention: Accurate and Training-free Sparse Attention Accelerating Any Model Inference](https://refivu.com/en/papers/6a719301-c428-424d-9dc3-3159ff623aea-spargeattention-accurate-and-training-free-sparse-attention.md)
- [Spatial-Spectral Coupling as Attention: Scaling Shape Correspondence to High-Resolution Surfaces](https://refivu.com/en/papers/ec4cab4c-a79c-4fcf-9756-a37f9deb749b-spatial-spectral-coupling-as-attention-scaling-shape.md)
- [YOLOv12: Attention-Centric Real-Time Object Detectors](https://refivu.com/en/papers/1b328616-dcc0-4c66-b27e-453b2482a00d-yolov12-attention-centric-real-time-object-detectors.md)

## Other paper commentary

- [Agent-Reflex: Teaching Language Agents to Act Reflectively](https://refivu.com/en/papers/7eb7b09e-c398-4382-9fbd-fe06f80512f9-agent-reflex-teaching-language-agents-to-act-reflectively.md)
- [AgentSWE: Can Coding Agents Build the Agent You Actually Want?](https://refivu.com/en/papers/0edc53d4-a7db-411e-a9bd-bcb685052116-agentswe-can-coding-agents-build-the-agent-you.md)
- [Reflexion: Language Agents with Verbal Reinforcement Learning](https://refivu.com/en/papers/a572f458-b121-4d38-bfc9-7a77309a3aba-reflexion-language-agents-with-verbal-reinforcement-learning.md)
- [A Generalist Agent](https://refivu.com/en/papers/890475cb-e797-43df-8de3-0d0eb9ed882e-a-generalist-agent.md)
- [Toward Agentic Robotics: A Large-Scale Study of Harness Design for Robot-Use Agents](https://refivu.com/en/papers/14d1c215-9799-4493-b5f1-c86c787dcba4-toward-agentic-robotics-a-large-scale-study-of.md)
- [VeriLadder: A Multi-Agent Specification Refinement System for Tool-Verified Verilog Datasets](https://refivu.com/en/papers/f3a3ce4f-fd41-462e-8bb7-f3e5263ba827-veriladder-a-multi-agent-specification-refinement-system-for.md)
- [Player-1: Learning to Play from Synthetic Experience](https://refivu.com/en/papers/956db0bc-965d-49f9-830e-3f50b69835ff-player-1-learning-to-play-from-synthetic-experience.md)
- [Rethinking Latent Visual Reasoning: Grounding Latent Reasoning in Visual Evidence](https://refivu.com/en/papers/cf1b0b5e-f469-4d64-9cf8-0a5efb7be754-rethinking-latent-visual-reasoning-grounding-latent.md)
- [In-Context Learning for Robots: Methods and Applications](https://refivu.com/en/papers/1959d5d6-622e-402b-9b12-43fc55497afc-in-context-learning-for-robots-methods-and-applications.md)
- [Prefix-Tuning: Optimizing Continuous Prompts for Generation](https://refivu.com/en/papers/01cf041e-b71c-444b-8b44-e94ac976a9db-prefix-tuning-optimizing-continuous-prompts-for-generation.md)
- [WebGPT: Browser-assisted question-answering with human feedback](https://refivu.com/en/papers/b41258c0-ce1e-478c-ad2b-6bccd936ae34-webgpt-browser-assisted-question-answering-with-human.md)

## Terms in this paper

- [throughput](https://refivu.com/en/terms/f064ae564aec-throughput)
- [agents](https://refivu.com/en/terms/58a2f064fc9d-agents)
- [distribution matching distillation](https://refivu.com/en/terms/2985d6d603f1-distribution-matching-distillation)
- [video world models](https://refivu.com/en/terms/0f332dca48f9-video-world-models)

---

AI-written text can contain mistakes. [Refivu](https://refivu.com/en/papers/01ba62df-ac45-4380-9eaa-9088dfb2b6ff-agentgarten-code-worlds-for-evolving-agents)
