WorldCoder, a Model-Based LLM Agent: Building World Models by Writing Code and Interacting with the Environment
Hao Tang, Darren Key, Kevin Ellis
TL;DR
WorldCoder proposes a novel framework for model-based RL where a world model is a Python program synthesized by an LLM from environment interactions. The agent uses an optimism-under-uncertainty objective to drive exploration, enabling sample-efficient learning and transfer across environments by editing code. It demonstrates strong performance on grid-worlds and AlfWorld with reduced computational costs compared to deep RL baselines and ReAct-style agents. The work highlights the benefits of explicit, auditable, and transferable world models, and discusses limitations such as assuming deterministic dynamics and symbolized states.
Abstract
We give a model-based agent that builds a Python program representing its knowledge of the world based on its interactions with the environment. The world model tries to explain its interactions, while also being optimistic about what reward it can achieve. We define this optimism as a logical constraint between a program and a planner. We study our agent on gridworlds, and on task planning, finding our approach is more sample-efficient compared to deep RL, more compute-efficient compared to ReAct-style agents, and that it can transfer its knowledge across environments by editing its code.
