arXiv(opens in a new tab)cs.CVAug 2026Cited by 23 papers on PaperVantageClassic Paper

Manuscript Offprint

arXiv:2608.25927

Code World Model: Coding Agent as World Brain

Yiwen Chen, Guosheng Lin, Chi Zhang

Abstract

World models aim to simulate how complex environments evolve under actions and events, yet existing video-based world models primarily learn dynamics from visual observations, which reveal outcomes rather than the underlying knowledge, rules, and mechanisms governing world evolution. This makes it difficult to maintain persistent consequences and support coherent, open-ended evolution. We introduce Code World Model, a framework that separates world evolution from visual realization by combining the reasoning and coding capabilities of language models with the generative priors of video models. A coding agent serves as the world brain, reasoning about events and their consequences and generating executable code to maintain persistent world state and perform rule-consistent evolution. To connect executable state with visual generation, we introduce a proxy representation that encodes frame-wise spatiotemporal constraints and is compiled into a proxy video, which conditions a video model to render high-fidelity visual observations. We further develop data pipelines for constructing aligned proxy–observation pairs from gameplay and real-world videos. After fine-tuning on paired gameplay data, MiniMax-H3 follows proxy-based spatiotemporal specifications from simple interactive worlds built by the coding agent while preserving rich visual details and dynamics. These results demonstrate the potential of combining code for persistent world evolution with video models for flexible visual realization, providing a new path toward open-ended world models.

Figure

Fig. 1. Overview of Code World Model: Left: a coding agent updates state via executable code; Middle: a lightweight compiler renders a coarse proxy video; Right: a video model generates high-fidelity observations from the proxy and text. This figure is AI-generated for illustration purposes.

1. Introduction

A world model aims to represent the state of a world and how that state evolves in response to actions and events [1–3]. Such models are essential for applications that must understand, predict, and act in evolving environments, including autonomous driving, embodied intelligence, and open-ended game worlds [4–6]. A complex interactive world may contain a large number of entities whose attributes, relationships, and behaviors evolve jointly over long time horizons. An action can affect not only the state of its immediate target, but also subsequent events and the future behavior of related entities. For example, in a game setting, actions by players, non-player characters, and environmental events can jointly reshape the world over time. If a player assassinates the ruler of a city, the local order, faction alliances, and the behavior of many non-player characters all change, and the consequences continue to unfold in subsequent interactions. Modeling such evolution requires broad world knowledge, an understanding of complex relationships among entities and events, the ability to infer consequences based on commonsense knowledge and world rules, and continual reasoning, planning, and decision-making. These capabilities are essential for building worlds that evolve coherently beyond predefined trajectories and support open-ended interaction; such worlds, in turn, provide a foundation for game generation and for training and evaluating agents [5, 7–9].

Among existing approaches to interactive world modeling, video world models have emerged as a particularly promising direction because they learn world dynamics directly from visual experience [4–7, 10–14]. Recent systems primarily formulate the task as action- or prompt-conditioned video generation and have achieved substantial progress in visual quality and action controllability [15–31]. Other efforts improve long-horizon temporal consistency and persistent memory [32–44], while streaming and real-time systems support increasingly responsive interaction [45–55]. By learning from large-scale visual data, video models acquire rich priors over environments, agents, motion, and interaction, enabling highly expressive visual synthesis without manually crafting every appearance and motion pattern. Videos also naturally capture how complex worlds evolve over time.

Yet a central obstacle to building such world models is learning the hidden mechanisms that govern world evolution from visual experience alone. Videos record the observable outcomes of world dynamics, whereas the world knowledge, commonsense rules, inter-entity relations, long-horizon plans, and mechanisms of consequence propagation that produce these outcomes are not directly observable. This is particularly evident in gameplay videos: each frame is rendered by executing fixed game code, yet the executable logic that produces each frame is discarded after rendering and can be observed only indirectly through its sparse visual consequences. Moreover, many important state changes occur out of view or extend beyond the temporal context available to the model [34, 38, 39]. Scaling up training data provides more observed outcomes but no direct evidence of the underlying mechanisms: the model must still infer them from their visible effects. Although scaling up video training data can improve these capabilities to some extent, existing video world models have not yet demonstrated the commonsense reasoning, long-horizon planning, and continual prediction of consequences required for open-ended world evolution. Merely generating the next observation is therefore insufficient to sustain a complex interactive world as it continues to evolve.

Building on this motivation, a capable world model should combine two complementary strengths. First, it should continually maintain and operate a complete world, inferring the consequences of events from knowledge and world rules and allowing the resulting changes to persist throughout long-term evolution. Second, it should retain the ability of video models to generate rich visual appearance, motion, and fine-grained dynamics, rendering the evolving world into high-fidelity, open-ended visual observations. Achieving this goal requires several qualitatively different capabilities: broad knowledge and reasoning to decide how events should affect the world; the ability to maintain a persistent world state that records entities, relations, rules, and historical events, so that past changes continue to influence future evolution even when they are not currently visible; and generative visual capabilities that translate the evolved world into final observations. This naturally suggests a functional decomposition: world reasoning and execution determine how the state evolves, while visual generation renders the evolved state into visual observations. Crucially, these two sets of capabilities have already been extensively developed using different data sources, which motivates us to combine the knowledge and reasoning learned from text and code with the visual and motion priors learned from video.

The first strength calls for a component that can understand world knowledge, reason over events, and determine their long-horizon consequences. Language models are natural candidates for governing this evolution [56–70]. Unlike video models, which primarily learn dynamics from visual experience, language models acquire rich world knowledge from large-scale text and code and have demonstrated strong capabilities in understanding abstract concepts, modeling complex relationships, and performing long-horizon reasoning. They can leverage this knowledge to reason, plan, make decisions, and anticipate the potential consequences of events. A complex world, however, also involves a large number of fine-grained and repetitive state changes. Invoking a language model for every low-level interaction is feasible but computationally inefficient; moreover, critical outcomes often need to be rule-consistent and reproducible.

The second strength calls for an execution substrate that can realize these decisions through frequent, rule-consistent updates. Code provides a natural execution substrate for such updates. In a game, for example, a video model can render the visual appearance of an attack, but whether it hits should be determined by the current world state, including the distance to the target and the attack range. Without stable rules, players cannot form reliable expectations about how their actions affect the world. Meanwhile, recent agentic language models and coding agents have become increasingly capable of autonomously generating, modifying, and maintaining complex codebases [71–74]. Code therefore need not be limited to static scripts predefined by developers: a coding agent can invoke, compose, and revise executable mechanisms as the world state, goals, and interactions change.

Figure

feedback

Fig. 2. Pipeline of the proposed Code World Model. The coding agent serves as the brain of the world model, translating interaction intent into code that updates the world state. The updated world state is compiled into a proxy and paired with a text prompt to condition the video model, which generates the corresponding visual observations. Generated observations and state feedback then support subsequent interaction and world evolution.

Motivated by these observations, we propose Code World Model (Fig. 1), a world-modeling framework that comprises an executable world-evolution mechanism driven by a coding agent, a programmable interface between world state and visual generation, and a video model that produces the final visual observations. At its core, the coding agent serves as the world brain: it governs world state and its evolution through code, while the video model renders the evolved world into visual observations. Knowledge and rules thus drive changes in world state, while the world's visual realization draws on learned priors, allowing an interactive world to evolve continually and coherently beyond predefined trajectories. Fig. 2 summarizes how the coding agent updates world state through code and how the resulting proxy and prompt condition the video model to generate visual observations.

The coding agent and code operate in two distinct computational regimes. The coding agent handles infrequent but complex decisions, such as interpreting new events, reasoning about long-term consequences, selecting mechanisms, and revising how the world operates; it translates these decisions into executable, reusable, and modifiable code. Code then performs high-frequency, repetitive, and deterministic operations—updating positions and numerical attributes, resolving collisions, and executing rules—without invoking the coding agent at every step. This agent–code organization decouples the frequency of high-level reasoning from that of low-level state updates, allowing world state to evolve continuously while its operating mechanisms remain modifiable.

With this executable world state in place, a central technical challenge is to translate it into a conditioning representation that a video model can reliably interpret. One straightforward solution is to express the state as structured text; however, current video models cannot yet reliably translate dense, constantly changing textual specifications into observations with precise frame-wise positions, spatial relations, and camera trajectories. An alternative is for the coding agent to construct a complete, explicit 3D world and condition the video model on its renderings [75, 76]. Although this provides stronger spatial control, constructing production-quality geometry, assets, animation, materials, and rendering systems is costly and prematurely constrains the final visual realization. To retain the flexibility of text-based specifications while recovering the spatial control of explicit 3D representations, we introduce proxy, a coarse representation of world state that encodes entity positions, poses, trajectories, spatial relations, and camera motion. A lightweight deterministic compiler renders it into a proxy video, which provides the video model with direct spatiotemporal constraints while leaving appearance and fine-grained dynamics unspecified. The proxy need only specify coarse spatial relations and overall trajectories, while the video model synthesizes local motion and physical interactions from its learned priors. Conditioned jointly on the proxy video and structured text, the video model generates the final observation using its learned priors over appearance, motion, and interaction. In this way, code determines what happens in the world and which consequences persist, while the video model determines how these outcomes are visually realized. Proxy therefore extends the coding agent's control from language into visual space, allowing it to express evolving world state as adjustable frame-wise constraints for the video model.

To instantiate and evaluate the interface from executable world state to visual observations, we develop a data-construction scheme for both gameplay and real-world videos. Our current prototype first adapts a pretrained video model using gameplay data. During gameplay, the target video and the camera, entity, and scene states required to construct the proxy are recorded synchronously from the same execution, yielding spatiotemporally aligned proxy-observation pairs. Real-world videos can likewise be paired with aligned proxies constructed from 3D reconstructions and object annotations, without requiring action labels and thereby substantially lowering the annotation burden. Fine-tuned on our paired gameplay data, MiniMax-H3 [77] qualitatively adheres to the proxy specifications for character locations, action trajectories, scene layouts, and camera motion when conditioned on proxies recorded from simple interactive worlds built by the coding agent, while preserving high-fidelity appearance and fine-grained dynamics. Compared with control interfaces that express only coarse intent through text or low-dimensional signals for action and camera control [31, 34, 37], our interface directly specifies frame-wise entity motion and viewpoint changes, enabling finer-grained and more direct spatiotemporal control.

Overall, Code World Model unifies knowledge-driven, rule-consistent world evolution with the visual, motion, and interaction priors learned by video models. Our current prototype provides preliminary evidence for the viability of the framework’s two key components: the coding agent can modify the state and operating mechanisms of a world by writing and revising code, and the fine-tuned video model can render the world state expressed by the proxy into corresponding visual observations.

Our contributions are summarized as follows:

• We introduce Code World Model, a framework in which a coding agent governs long-horizon world evolution through executable code, while a video model renders the evolving world state into high-fidelity visual observations.

• We design a proxy-based interface that translates executable world state into a proxy video, providing direct frame-wise spatiotemporal constraints without requiring a complete high-quality 3D asset and rendering pipeline.

• We construct a spatiotemporally aligned gameplay data pipeline and demonstrate geometry-assisted offline proxy construction on real-world recordings, providing preliminary evidence that proxy can serve as a learnable interface to world state.

References (92)

Cited by (23)