PatchWorld: Gradient-Free Optimization of Executable World Models for Agent Environments

Jiaxin Bai, Yue Guo, Yifei Dong, Jiaxuan Xiong, Tianshi Zheng, Yixia Li, Tianqing Fang, Yufei Li, Yisen Gao, Haoyu Huang, Zhongwei Xie, Hong Ting Tsang, Zihao Wang, Lihui Liu, Jeff Z. Pan, Yangqiu SongarXiv 2026

TL;DR

PatchWorld is a gradient-free framework that automatically synthesizes and refines executable Python programs to serve as world models for text-based AI agents. By using Large Language Models (LLMs) as offline symbolic optimizers in a counterexample-guided repair loop, it creates inspectable, fast-executing models that match or exceed the decision-making performance of traditional LLM lookahead at zero inference token cost.

What Problem Does This Paper Address?

Interactive text agents (like those navigating web interfaces or playing text-based games) operate in black-box, partially observable Markov decision processes (POMDPs). They receive unstructured natural language observations but have no access to the true underlying environment state or transition rules.

To plan ahead, agents need a "world model" to predict how their actions will change the environment. Traditional approaches train massive neural networks to predict the next text token, which is computationally expensive, prone to compounding errors, and completely uninterpretable.

While writing executable code as a world model is an attractive, interpretable alternative, doing so from offline logs is highly underdetermined. As shown in Figure 1, many different programs can perfectly memorize training trajectories (rote learning) without capturing the actual underlying rules needed to generalize to new scenarios.

Figure 1: Text-agent environments are black-box POMDPs: a latent state 𝑠𝑡transitions under action 𝑎𝑡and emits unstructured text observations 𝑜𝑡, but 𝑠𝑡is never exposed (C1-C2). The agent (and any world model) maintains a belief ˆ𝑠𝑡≠𝑠𝑡, updated by predicting through actions and correcting from observations. Offline logs alone are underdetermined (C3): many beliefs can fit the same (𝑜𝑡,𝑎𝑡,𝑜𝑡+1) while differing in transfer, so replay on held-out validation trajectories is needed to probe generalization.

Methods

PatchWorld addresses these challenges by treating world-model induction as a generative optimization problem, executing a Counterexample-Guided Inductive Synthesis (CEGIS) loop:

  1. Core Executable Interface: Every generated world model is structured as a clean Python class that separates state tracking into distinct phases: parsing text into facts, initializing a blank belief, correcting the belief based on new observations, predicting the next belief state given an action, and rendering the predicted observation.
  2. Contrastive Evidence Mining: Instead of overwhelming the LLM with massive training logs, PatchWorld filters trajectories into a compact, balanced set of "contrastive transitions" containing both successful actions and failures. This forces the model to learn conditional rules rather than just memorizing success paths.
  3. Counterexample-Guided Repair: An LLM acts as an offline symbolic optimizer. It generates an initial program, runs it against the training logs, catches execution or prediction failures (counterexamples), and iteratively patches the code.
  4. Validation Gating: Crucially, a candidate patch is only accepted if it improves the replay score on a held-out validation set. This prevents the LLM from creating brittle, overfitted fixes.

The authors evaluate two versions: PatchWorld-Simple (purely symbolic code) and PatchWorld-Residual (which appends a train-only lookup table for recurring exact strings to improve surface-level text matching).

Figure 2: Overall framework of PatchWorld for generative optimization of executable world models and their subsequent repair and evaluation.
Figure 3: Core executable interface implemented by each induced program, separating parsing, belief correction, dy- namics, and readout.

Datasets

The framework was evaluated across seven diverse text-agent environments from the AgentGym benchmark suite:

  • Maze & BabyAI: Grid-world navigation and instruction following.
  • TextCraft: A text-based crafting environment inspired by Minecraft.
  • Wordle: The classic word-guessing game requiring strict constraint solving.
  • WebShop: A complex web-browsing and shopping interface.
  • AlfWorld & SciWorld: Long-horizon household and scientific tasks.

Key Insights and Ideas

  • LLMs as Offline Optimizers, Not Runtime Predictors: Instead of paying the high computational cost of querying an LLM at every single simulation step during agent deployment, PatchWorld uses the LLM once offline to write the simulation code. At runtime, the world model runs as pure, lightning-fast Python code.
  • The Fidelity vs. Utility Frontier: The authors discovered a fascinating trade-off between observation reconstruction fidelity (how closely the predicted text matches the ground truth) and decision-making utility. While adding a residual memory cache (PatchWorld-Residual) boosted text-matching metrics, it actually lowered the agent's decision-making success. This is because exact text matching often prioritizes superficial template details over the core action-discriminative dynamics needed to distinguish good actions from bad ones.
  • Validation Gating is Non-Negotiable: Without the validation-set replay gate, LLM self-repair loops frequently introduce regressions or hallucinate code that satisfies the immediate counterexample but breaks performance on the broader environment.

Key Results

  • Zero-Token Lookahead Success: In live one-step lookahead decision-making, PatchWorld-Simple achieved a macro success rate of 76.4% across all environments. This outperformed other code-induction baselines like PoE-World (69.3%) and WorldCoder (64.4%), and even beat direct LLM lookahead (75.7%)—all while consuming zero lookahead prediction tokens at inference time (saving roughly 64,000 tokens per task).
  • Multi-Step Rollout Stability: In multi-step rollouts up to 5 steps ahead, PatchWorld-Residual maintained the highest token F1 score (0.58). Its explicit belief-correction loop successfully prevented the compounding error cascades that typically plague pure text-generation models.

Limitations and Future Work

  • One-Step Lookahead Isolation: The live decision-making experiments were limited to a lookahead depth of exactly one step. Integrating these executable models with deeper search algorithms like Monte Carlo Tree Search (MCTS) remains an open direction.
  • No Reward Modeling: The induced programs currently predict future observations but do not model environment rewards directly. Consequently, live decision-making still relies on an external LLM selector to rank the utility of the predicted text outcomes.
  • Deterministic Beliefs: PatchWorld assumes deterministic belief updates, which may struggle to capture highly stochastic environments where probabilistic transition models are required.

Summary updated

BibTeX
@misc{bai2026patchworld,
  author = {Jiaxin Bai and Yue Guo and Yifei Dong and Jiaxuan Xiong and Tianshi Zheng and Yixia Li and Tianqing Fang and Yufei Li and Yisen Gao and Haoyu Huang and Zhongwei Xie and Hong Ting Tsang and Zihao Wang and Lihui Liu and Jeff Z. Pan and Yangqiu Song},
  title = {{PatchWorld: Gradient-Free Optimization of Executable World Models for Agent Environments}},
  year = {2026},
  eprint = {2605.30880},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2605.30880},
}
Figure