Predictive Code Worlds: Write the World First, Then Predict It, for Robot Code Agents
Authors: Ge Wang, Zhixin Mai, Zheng Sun, Mingkai Jia, Ziyue Zhu, Zhen Li
Organizations: The Chinese University of Hong Kong, Shenzhen · The Chinese University of Hong Kong · The Hong Kong University of Science and Technology · Nankai University
Code-as-policy agents write robot programs on top of perception and motion APIs, and how well they do depends heavily on the language model behind them. Masks, depth and bounding boxes are not a model of the task's world, so the model has to work that world out by itself. We present Predictive Code World (PCW), in which the agent writes the world down before the policy and then makes that world predictive. The agent first writes a code world, an executable model of its task that keeps measured facts, predicts what each action should change and judges progress toward the goal, and writes its skill on it. Once the skill works, the code world also predicts the observable outcome of each subgoal. These world predictions come from the same agent as the skill they check and are not trusted by default: faults injected during development label their verdicts, and only predictions certified on these labels may roll the program back. With a small open-weight model, Qwen3.8-Flash, and self-improvement, PCW reaches 89.4% success on 80 LIBERO-Pro tasks, surpassing ASPIRE with the same model, a larger open-weight model, and even the closed-source Claude Opus 4.6; its gains carry over to Robosuite and BEHAVIOR-1K. Under disturbances, world predictions catch failures that would otherwise go unnoticed and recover from them.
Figures & tables
Figure 2: Overview of PCW. (a) The agent first writes a code world W=(σ,f,g) : a state map that turns an observation into named facts, an effect model that predicts what a motion call should change, and a goal map. The skill π reads its facts and is rehearsed on it. (b) A world prediction measures one quantity for a subgoal and names the range expected after success and the range expected after the most likely failure ( Eq. 1 ); here a threshold t separates them. (c) Faults injected during development label its verdicts, and each of its two verdicts, pass and fail , is certified only if it is precise enough on these labels ( Eq. 2 ); a verdict that is not certified sends the agent back to revise. (d) At run time only certified verdicts act: when a re-check of the completed subgoals finds a certified fail , the program rolls back to the earliest subgoal that no longer holds; otherwise, and with world predictions off, it stays on its default path. The example is the bowl-into-drawer program, simplified; the figure is schematic and shows no logged values.
Figure 3: A certified world prediction at run time (put the bowl into the drawer). (a) One held-out episode with world predictions on, and its loop as logged below the frames (squares are verdicts). After opening, drawer_open measures 0.159 m. The drawer is then silently pushed back while the bowl is held; the re-check before placing measures 0.055 m, a certified fail , and the program rolls back: it re-opens the drawer in two tries (the first measures 0.007 m), grasps the bowl again and places it. (b) The world prediction: it passes above 0.10 m, and both of its verdicts are certified, fail on injected push-backs. (c) The same seed with world predictions off: the same 0.055 m is unknown , the program stays on its default path, and the bowl ends up on the closed drawer.
System
Model
Self-improving
Success (%)
ASPIRE
Qwen3.8-Flash
✗
49.4 †
ASPIRE
Qwen3.8-Flash
✓
63.8 †
ASPIRE
Qwen3.8-Max
✗
58.3 †
ASPIRE
Claude Opus 4.6
✓
65.7
ASPIRE
Claude Opus 5
✓
94.5
ASPIRE
Claude Opus 5.5
✓
98.8
Table 1: Success on 80 LIBERO-Pro tasks (held-out seeds, without our disturbances; same tasks for all rows). ASPIRE [ 34 ] rows are ordered by model strength; PCW uses the weakest of these models. Self-improving: see Sec. 4.1 . Our rows use 50 held-out seeds per task. ASPIRE’s Opus rows are from [ 34 ] and average its eight suites (Opus 4.6: the two Long suites without evolutionary search). Bold: ours. † Run with ASPIRE’s released code.
Code world
World predictions
Success (%)
✗
✗
49.4
✓
✗
78.2
✓
✓
83.4
Table 2: Ablation of the two parts on the 80 tasks of Tab. 1 , with Qwen3.8-Flash and without self-improvement (50 held-out seeds per task). The last row is the full PCW; without a code world, the skill is written directly on the perception and motion APIs.
Model
Self-improving
Robosuite
BEHAVIOR-1K
ASPIRE
Claude Opus 4.6
✓
81.0
88.0
Claude Opus 5
✓
98.9
96.0
Claude Opus 5.5
✓
100.0
100.0
PCW (ours)
Qwen3.8-Flash
✗
88.3
90.0
Table 3: Success (%) on Robosuite and BEHAVIOR-1K (held-out seeds; the tasks and seeds of ASPIRE [ 34 ] ): seven Robosuite tasks with 100 seeds each and two BEHAVIOR-1K tasks with 25 seeds each. ASPIRE numbers are from [ 34 ] . Bold: ours.
Figure 4: Robustness under disturbances on held-out seeds (six tasks, the same disturbance on the same seed for both variants). Bars show success rate, and brackets the gain of PCW in percentage points.
Figure 5: A second certified world prediction at run time (put the milk in the basket). (a) The milk is moved before the grasp and the gripper closes on air. lifted measures the carton at 0.065 m with an empty hand, a certified fail ; the program checks its earlier subgoals again, grasps the carton where it now is, and places it. (b) The world prediction. (c) Same seed, world predictions off: the same 0.065 m is unknown , the carton is never lifted, and an empty hand goes to the basket.
Appendix figures & tables9 assets
Supplementary material from the paper’s appendix.
Appendix
Benchmark
Development
Held-out
LIBERO-Pro
51–65 (15)
1–50 (50)
Robosuite
101–125 (25)
1–100 (100)
BEHAVIOR-1K
26–35 (10)
1–25 (25)
Appendix
Table S1: Seeds per task, as in ASPIRE [ 34 ] : seed ids, with their number in parentheses.
Part
Function
Role
σ
observe , update
write perception results as facts, with frame, unit and evidence
f
predict
what the next observation should show after a motion call
g
done , progress
whether the goal holds, and how far the state is from it
rehearsal
simulate
a return value for every API call from the effect model, without the simulator
Appendix
Table S2: The parts of a code world.
Threshold
pass
fail
0.05 m
13/20, not certified
–
0.10 m
38/41, certified
11/11, certified
Appendix
Table S3: Correct labels over all labels for the two verdicts of drawer_open , before and after the agent revised its threshold.
Suite
Instruction
goal_swap
Open the top layer of the drawer and put the bowl inside
goal_task
Open the top layer of the drawer and put the cream cheese inside
10_swap
put the black bowl in the bottom drawer of the cabinet and close it
10_swap
turn on the stove and put the moka pot on it
object_task
Pick the milk and place it in the basket
spatial_task
Pick the akita black bowl next to the cookie box and place it on the plate
Appendix
Table S4: The six LIBERO-Pro tasks of the disturbance study, from five suites.
Kind
Interface
As in ASPIRE
Observation
RGB, depth, camera parameters, arm state
Perception
SAM 3 segmentation from a text or point prompt; mask or pixel to world points; oriented box of a point cloud
Grasping
grasp candidates; choice of a top-down grasp
Motion
inverse kinematics; move to a pose or to joint values; open and close the gripper; go home
Added by PCW
Appendix
Table S5: Interfaces a program may call on LIBERO-Pro: the perception and motion APIs of ASPIRE [ 34 ] , unchanged, and the run-time support of the code world that PCW adds. None reads the simulator’s state.
Kind
Trigger
Effect
During an operation
Drop
the grasped object is first lifted by 3 cm
the gripper is forced open and the object falls back
Displace
the fingers first come within 6 cm of an object not yet grasped
the object moves 3–5 cm in a random horizontal direction
Push-back
an articulated part first passes 60% of its range and the gripper is 5 cm away
the part is pushed back to 40%
After confirmation
Undo
a subgoal has held for 25 steps, the program works on the next one, and the gripper is 10 cm away
a placed object is moved out of its goal region, or an articulated part is pushed back to 40%
Appendix
Table S6: Disturbances on held-out episodes.
ASPIRE
Ours
Model
Qwen3.8-Flash †
Opus 4.6
Qwen3.8-Flash
Code world
only
PCW
PCW
Self-improving
✗
✓
✓
✗
✗
✓
object_swap
88.0
96.4
98.0
89.4
97.8
99.2
object_task
83.2
91.2
95.0
96.8
97.0
97.0
Appendix
Table S7: Success (%) per LIBERO-Pro suite (ASPIRE’s tasks and held-out seeds; ten tasks per suite, 50 seeds per task). The Opus 4.6 numbers are from [ 34 ] ; swap is its position perturbation and task its task perturbation. Bold: best in each row. † Run with ASPIRE’s released code. ‡ Without evolutionary search: ASPIRE reports Opus 4.6 on the two Long suites only without it ( [ 34 ] , Fig. 9 and Tab. 24).
Ours, Qwen3.8-Flash
ASPIRE
Code world
only
PCW
PCW
Opus 4.6
Self-improving
✗
✗
✓
✓
cube_lift
94
100
100
97
cube_stack
99
100
100
99
cube_restack
100
100
100
100
Appendix
Table S8: Success (%) per Robosuite task (ASPIRE’s tasks and held-out seeds; 100 seeds per task). ASPIRE numbers are from [ 34 ] . Bold: best in each row.
Ours, Qwen3.8-Flash
ASPIRE
Code world
only
PCW
PCW
Opus 4.6
Self-improving
✗
✗
✓
✓
Soda can
88
92
96
88
Radio
84
88
96
88
Mean
86.0
90.0
96.0
88.0
Appendix
Table S9: Success (%) per BEHAVIOR-1K task (ASPIRE’s tasks and held-out seeds; 25 seeds per task). ASPIRE numbers are from [ 34 ] . Bold: best in each row.