SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2605.30880 · 2026

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

Zihao Wang, Yangqiu Song, Tianqing Fang, Yisen Gao, Yixia Li, Yifei Dong, Jeff Pan, Haoyu Huang, Tianshi Zheng, Hong Tsang, Jiaxin Bai, Yue Guo, and 4 more

arXiv · PDF · Open in the Atlas

Code that ran

6 of 11 samples (functions and classes) lifted from this paper's linked repositories executed on a synthesized input in Syntology's jail (0 of them constructed an object rather than computing a result; 0 honoured the contract we drafted, 0 violated it and 0 have no contract verdict; 6 failures of our instrument; 5 no recorded run), measured 2026-11-23; bodies inline only under a permissive licence as GitHub detects it. Not a reproduction of the paper's results.

"Ran" means the function executed on a synthesized input and returned a value. It is not a reproduction of the paper's results. This record, dated, as JSON: /api/ran/2605.30880.json · badge: /api/ran/2605.30880.svg

Each repository's role is a label: a classifier's output recorded on the link, or, where no role is recorded, what the Papers with Code archive marked. The line under it names its basis. Neither says who wrote the code.

RepositoryRoleRan
HKBU-KnowComp/PatchWorld canonical (classifier label)
classifier basis: census
6 ran · 5 no recorded run
FunctionStatusWhere it lives
belief_snapshot Ran
ran; our contract draft was wrong, not the code
HKBU-KnowComp/PatchWorld/patchworld/worldmodel_signals.py
code served (permissive licence) · get_code("b2adc0ff6d0a9044")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned dict. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch
import numpy as np
from typing import Any, Dict, List

torch.manual_seed(0)

# Test case 1: dict belief
dict_belief = {
    'state': 'active',
    'confidence': 0.95,
    'data': [1, 2, 3]
}

# Test case 2: custom belief object with metadata, nodes, and edges
class BeliefObject:
    def __init__(self):
        self.metadata = {
            'source': 'sensor',
            'timestamp': 1234567890,
            'version': 1
        }
        self.nodes = {
            'node_1': {'value': 0.5},
            'node_2': {'value': 0.7},
            'node_3': {'value': 0.3}
        }
        self.edges = [
            ('node_1', 'node_2'),
            ('node_2', 'node_3'),
            ('node_1', 'node_3')
        ]

belief_obj = BeliefObject()

# Test case 3: minimal belief object (only belief_type)
class MinimalBelief:
    pass

minimal_belief = MinimalBelief()

# Test case 4: belief with nodes but no edges
class BeliefWithNodes:
    def __init__(self):
        self.metadata = {'id': 'test'}
        self.nodes = {'a': 1, 'b': 2}

belief_with_nodes = BeliefWithNodes()

# Use the dict_belief as the primary test argument
ARGS = {
    'belief': dict_belief
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
numpy, torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type dict — a dict output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a dict output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
group_by_problem Ran
ran; our contract draft was wrong, not the code
HKBU-KnowComp/PatchWorld/patchworld/worldmodel_data.py
code served (permissive licence) · get_code("5a91f0e529cfd644")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned dict. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

from dataclasses import dataclass
from collections import defaultdict
from typing import Dict, List

@dataclass
class Transition:
    observation: str
    action: str
    next_observation: str
    reward: float
    done: bool

@dataclass
class Trajectory:
    transitions: List[Transition]
    env: str
    item_id: str
    task_idx: int
    rollout_index: int
    split: str
    success: bool
    total_reward: float

    @property
    def task_description(self) -> str:
        return self.transitions[0].observation if self.transitions else ''

    @property
    def num_steps(self) -> int:
        return len(self.transitions)

# Create sample transitions
transition1 = Transition(
    observation="initial state 1",
    action="action_a",
    next_observation="next state 1",
    reward=1.0,
    done=False
)

transition2 = Transition(
    observation="state 2",
    action="action_b",
    next_observation="final state 2",
    reward=2.0,
    done=True
)

transition3 = Transition(
    observation="initial state 3",
    action="action_c",
    next_observation="next state 3",
    reward=0.5,
    done=False
)

# Create sample trajectories with distinct item_ids and rollout_indices
trajectory1 = Trajectory(
    transitions=[transition1, transition2],
    env="env_1",
    item_id="item_001",
    task_idx=0,
    rollout_index=2,
    split="train",
    success=True,
    total_reward=3.0
)

trajectory2 = Trajectory(
    transitions=[transition3],
    env="env_1",
    item_id="item_001",
    task_idx=0,
    rollout_index=1,
    split="train",
    success=False,
    total_reward=0.5
)

trajectory3 = Trajectory(
    transitions=[transition1],
    env="env_2",
    item_id="item_002",
    task_idx=1,
    rollout_index=0,
    split="test",
    success=True,
    total_reward=1.0
)

trajectory4 = Trajectory(
    transitions=[transition2, transition3],
    env="env_3",
    item_id="",
    task_idx=2,
    rollout_index=0,
    split="val",
    success=False,
    total_reward=2.5
)

trajectories = [trajectory1, trajectory2, trajectory3, trajectory4]

ARGS = {
    "trajectories": trajectories
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
none outside the standard library — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type dict — a dict output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a dict output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
group_by_task_type Ran
ran; our contract draft was wrong, not the code
HKBU-KnowComp/PatchWorld/patchworld/worldmodel_data.py
code served (permissive licence) · get_code("ae92ed406adb1edf")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned dict. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch
import numpy as np
from dataclasses import dataclass
from collections import defaultdict
from typing import Dict, List

@dataclass
class Transition:
    observation: str
    action: str
    next_observation: str
    reward: float
    done: bool

@dataclass
class Trajectory:
    transitions: List[Transition]
    env: str
    item_id: str
    task_idx: int
    rollout_index: int
    split: str
    success: bool
    total_reward: float

    @property
    def task_description(self) -> str:
        return self.transitions[0].observation if self.transitions else ''

    @property
    def num_steps(self) -> int:
        return len(self.transitions)

# Create sample transitions
transition1 = Transition(
    observation="Pick up the red block. This is a test task.",
    action="move_right",
    next_observation="Block moved.",
    reward=1.0,
    done=False
)

transition2 = Transition(
    observation="Next step",
    action="grasp",
    next_observation="Block grasped.",
    reward=0.5,
    done=True
)

transition3 = Transition(
    observation="Stack the blue cube. Another task here.",
    action="move_up",
    next_observation="Cube positioned.",
    reward=2.0,
    done=False
)

transition4 = Transition(
    observation="Pick up the red block. Same as first.",
    action="move_left",
    next_observation="Block moved left.",
    reward=1.0,
    done=True
)

# Create sample trajectories
traj1 = Trajectory(
    transitions=[transition1, transition2],
    env="simulation",
    item_id="item_1",
    task_idx=0,
    rollout_index=0,
    split="train",
    success=True,
    total_reward=1.5
)

traj2 = Trajectory(
    transitions=[transition3],
    env="simulation",
    item_id="item_2",
    task_idx=1,
    rollout_index=0,
    split="train",
    success=False,
    total_reward=2.0
)

traj3 = Trajectory(
    transitions=[transition4],
    env="simulation",
    item_id="item_3",
    task_idx=0,
    rollout_index=1,
    split="test",
    success=True,
    total_reward=1.0
)

trajectories = [traj1, traj2, traj3]

ARGS = {
    "trajectories": trajectories
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
numpy, torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type dict — a dict output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a dict output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
load_trajectories Ran
ran; our contract draft was wrong, not the code
HKBU-KnowComp/PatchWorld/patchworld/worldmodel_data.py
code served (permissive licence) · get_code("df272630397f75fe")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned list, ndim 1, dtype family float; no output shape is stated. The image it ran in was not recorded. If your copy returns the same type and ndim on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import json
import tempfile
from pathlib import Path
from typing import Iterable, List

# Create temporary JSONL files with valid trajectory data
temp_dir = tempfile.TemporaryDirectory()
temp_path = Path(temp_dir.name)

# Create first JSONL file
jsonl_file_1 = temp_path / "trajectories_1.jsonl"
with jsonl_file_1.open('w', encoding='utf-8') as f:
    # Write first trajectory
    traj_1 = {
        "metadata": {
            "env": "CartPole-v1",
            "item_id": "item_001",
            "task_idx": 0,
            "rollout_index": 0,
            "split": "train",
            "success": True,
            "total_reward": 195.5
        },
        "transitions": [
            {
                "observation": "Move the cart left",
                "action": "LEFT",
                "next_observation": "Cart moved",
                "reward": 1.0,
                "done": False
            },
            {
                "observation": "Cart moved",
                "action": "RIGHT",
                "next_observation": "Cart centered",
                "reward": 0.5,
                "done": False
            },
            {
                "observation": "Cart centered",
                "action": "LEFT",
                "next_observation": "Task complete",
                "reward": 194.0,
                "done": True
            }
        ]
    }
    f.write(json.dumps(traj_1) + '\n')
    
    # Write second trajectory
    traj_2 = {
        "metadata": {
            "env": "CartPole-v1",
            "item_id": "item_002",
            "task_idx": 1,
            "rollout_index": 1,
            "split": "train",
            "success": False,
            "total_reward": 42.0
        },
        "transitions": [
            {
                "observation": "Start task",
                "action": "MOVE",
                "next_observation": "In progress",
                "reward": 42.0,
                "done": True
            }
        ]
    }
    f.write(json.dumps(traj_2) + '\n')

# Create second JSONL file
jsonl_file_2 = temp_path / "trajectories_2.jsonl"
with jsonl_file_2.open('w', encoding='utf-8') as f:
    traj_3 = {
        "metadata": {
            "env": "MuJoCo",
            "item_id": "item_003",
            "task_idx": 0,
            "rollout_index": 0,
            "split": "test",
            "success": True,
            "total_reward": 150.0
        },
        "transitions": [
            {
                "observation": "Initial state",
                "action": "WALK",
                "next_observation": "Walking",
                "reward": 75.0,
                "done": False
            },
            {
                "observation": "Walking",
                "action": "RUN",
                "next_observation": "Running",
                "reward": 75.0,
                "done": True
            }
        ]
    }
    f.write(json.dumps(traj_3) + '\n')

# Define the arguments for load_trajectories
ARGS = {
    "paths": [jsonl_file_1, jsonl_file_2]
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
none outside the standard library — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type list, ndim 1, dtype family float — a list output has no array shape of its own; none is stated
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
normalize_parsed_observation Ran
ran; our contract draft was wrong, not the code
HKBU-KnowComp/PatchWorld/patchworld/worldmodel_evaluator.py
code served (permissive licence) · get_code("a5b2c75cb8f46df5")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned dict. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch
import numpy as np
from typing import Any, Dict

torch.manual_seed(0)

# Construct a test parsed observation dictionary
# The function processes dicts with various value types
parsed_observation = {
    "string_key": "  Hello WORLD  ",
    "numeric_key": 42,
    "float_key": 3.14,
    "bool_key": True,
    "none_key": None,
    "list_key": [3, 1, 2, "apple"],
    "tuple_key": (5, 4, 3),
    "set_key": {1, 2, 3},
    "nested_dict": {
        "inner_string": "  test  ",
        "inner_number": 100,
        "  MixedCase  ": "  VALUE  "
    },
    "  MIXED_CASE_KEY  ": "some value",
    "empty_list": [],
    "empty_dict": {},
}

ARGS = {
    "parsed": parsed_observation
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
numpy, torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type dict — a dict output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a dict output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
render_maze_observation Ran
ran; our contract draft was wrong, not the code
HKBU-KnowComp/PatchWorld/patchworld/worldmodel_base.py
code served (permissive licence) · get_code("768f4ef0ae8134ce")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned str. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

from dataclasses import dataclass
from typing import Any, Dict, Iterable, List, Optional, Set, Tuple

@dataclass(frozen=True)
class MazeState:
    """Canonical explicit state for maze-style navigation tasks."""
    agent_x: Optional[int] = None
    agent_y: Optional[int] = None
    goal_x: Optional[int] = None
    goal_y: Optional[int] = None
    local_walls: Tuple[str, ...] = ()
    status: str = ''
    obs_text: str = ''

    def to_dict(self) -> Dict[str, Any]:
        data: Dict[str, Any] = {'agent_x': self.agent_x, 'agent_y': self.agent_y, 'goal_x': self.goal_x, 'goal_y': self.goal_y, 'local_walls': self.local_walls}
        if self.status:
            data['status'] = self.status
        if self.obs_text:
            data['obs_text'] = self.obs_text
        return data


# Test case 1: Success state
state_success = MazeState(
    agent_x=5,
    agent_y=5,
    goal_x=10,
    goal_y=10,
    local_walls=(),
    status='success',
    obs_text=''
)

# Test case 2: Normal state with walls
state_with_walls = MazeState(
    agent_x=3,
    agent_y=4,
    goal_x=8,
    goal_y=9,
    local_walls=('up', 'left'),
    status='',
    obs_text=''
)

# Test case 3: State with all walls
state_all_walls = MazeState(
    agent_x=1,
    agent_y=2,
    goal_x=5,
    goal_y=6,
    local_walls=('up', 'down', 'left', 'right'),
    status='',
    obs_text=''
)

# Test case 4: State with only obs_text (None values)
state_text_only = MazeState(
    agent_x=None,
    agent_y=None,
    goal_x=None,
    goal_y=None,
    local_walls=(),
    status='',
    obs_text='You are in a maze'
)

# Test case 5: Minimal state with single wall
state_single_wall = MazeState(
    agent_x=2,
    agent_y=3,
    goal_x=7,
    goal_y=8,
    local_walls=('right',),
    status='',
    obs_text=''
)

ARGS = {
    'state': state_with_walls
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
none outside the standard library — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type str — a str output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a str output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
action_actually_failed Not yet run
unverified (harvested, no recorded run)
HKBU-KnowComp/PatchWorld/patchworld/worldmodel_signals.py
code served (permissive licence) · get_code("8a70fa041911372d")
How it ran

no invocation recorded.

canonicalize_maze_walls Not yet run
unverified (harvested, no recorded run)
HKBU-KnowComp/PatchWorld/patchworld/worldmodel_base.py
code served (permissive licence) · get_code("bae399b849dec121")
How it ran

no invocation recorded.

coerce_maze_state Not yet run
unverified (harvested, no recorded run)
HKBU-KnowComp/PatchWorld/patchworld/worldmodel_base.py
code served (permissive licence) · get_code("d75958a67fea5b7e")
How it ran

no invocation recorded.

extract_observation_state_fields Not yet run
unverified (harvested, no recorded run)
HKBU-KnowComp/PatchWorld/patchworld/worldmodel_evaluator.py
code served (permissive licence) · get_code("8f9a483585663e09")
How it ran

no invocation recorded.

load_model_from_code Not yet run
unverified (harvested, no recorded run)
HKBU-KnowComp/PatchWorld/patchworld/worldmodel_validator.py
code served (permissive licence) · get_code("e7a2a4869c012316")
How it ran

no invocation recorded.

Also present in other papers' code

Of 11 samples lifted from this paper's linked repositories, 11 carry a function identity and 0 do not. Of the 11 distinct functions with an identity, 0 are also present in other papers whose code we hold (0 with at least one paper dated earlier, 0 the same month, 0 later) and 11 are only here among the 52,977 papers whose code Syntology holds (as of 2026-09-26).

Only here means: among the 52,977 papers whose code Syntology holds (51,887 with lifted samples, 1,090 through their assemblies only), as of 2026-09-26, no other paper's lifted samples or current assembly bricks contain an identical function body after normalisation.

Presence, not direction: an identical function body in two papers' repositories does not say who wrote it, which came from which, or that either paper's method rests on it. Matching is exact after normalisation, so a renamed or edited function is not matched. Dates are when papers appeared, not when code was written. Only .py files the harvester lifted are covered; notebooks are not read. A new-style arXiv id YYMM.NNNN dates a paper to the month 20YY-MM; otherwise Paper.year dates it to the year; otherwise it is undated. Dates are when the paper appeared, not when the code was written. Read 2026-11-23.

Repositories linked to this paper

Some links come from the archived Papers with Code dataset (CC BY-SA 4.0): attribution and licence.

Abstract

World models for interactive text agents must typically be learned from observation-action trajectories alone. Specifically, the environment returns text observations after each action, but does not expose a ground-truth latent state nor an inspectable transition model. A research gap remains in how to induce executable code as a world model in this black-box setting for prediction and agent decision making. We introduce PatchWorld, a gradient-free framework that turns offline trajectories into executable Python world models through counterexample-guided code repair. Instead of predicting the next observation with a black-box model, Patch-World induces symbolic belief-state programs whose action updates can be inspected, replayed, and locally patched. Across seven AgentGym environments, PatchWorld-Simple achieves the highest code-based decision-making score among evaluated methods (76.4% macro success in live one-step lookahead), matching or exceeding LLM-based lookahead while invoking no LLM calls inside the world-model prediction module itself. We further find that a human-specified residual-memory bias improves surface observation fidelity but weakens agent decision-making utility. This reveals a tradeoff in executable world models, since improving observation fidelity can come at the expense of action-discriminative dynamics, and vice versa. Code is available at https://github.com/HKBU-KnowComp/PatchWorld.

For agents

The same record, over MCP at https://syntology.ai/mcp:

get_harvested_code_for_paper("2605.30880")
get_code_for_paper("2605.30880")
have("2605.30880")

The run record, dated, one paper per request, free:

curl https://syntology.ai/api/ran/2605.30880.json

A badge for a README (the split and the date, never a ratio):

[![Syntology run record](https://syntology.ai/api/ran/2605.30880.svg)](https://syntology.ai/paper/2605.30880)

Connect an agent — have() is free.