TL;DR
How do you teach an AI agent to master complex worlds without writing custom APIs, recording years of human gameplay, or hand-designing reward functions? CODE-SHARP uses Foundation Models to read an environment’s source code directly and autonomously write a growing dependency tree of Python reward programs. By dynamically routing a reinforcement learning agent through these hierarchical skills at runtime, the agent learns complex, multi-step behaviors—like mining diamonds or cooking a meal—entirely from scratch.
What Problem Does This Paper Address?
A hallmark of general intelligence is open-endedness: stepping into a brand-new environment, figuring out what is interesting to do, and learning increasingly complex skills without a human holding your hand.
Recently, Foundation Model (FM) agents like Voyager in Minecraft have shown impressive skill discovery. However, there is a catch: massive human engineering under the hood. Voyager relies on the Mineflayer API (13,000 lines of hand-written JavaScript) to translate high-level plans into low-level actions, while other agents rely on pre-training over decades of annotated human gameplay. Alternatives that train agents from scratch (like ELLM and OMNI) avoid massive datasets, but still require researchers to hand-engineer state captioners and translation functions for every new environment. Moving an agent to a new domain means rebuilding that scaffolding all over again. CODE-SHARP asks: can an agent discover and master long-horizon skills directly from the environment's raw code, with zero pre-defined tasks or human demonstrations?
Methods
Instead of putting a slow, expensive FM directly inside the agent's action loop, CODE-SHARP uses the FM as an offline architect that builds a curriculum of Skills as Hierarchical Reward Programs (SHARPs)—executable Python programs arranged in a directed acyclic graph. Meanwhile, a standard reinforcement learning policy (trained via PPO) learns to execute those skills from scratch.
Each SHARP encodes two things: a binary success condition (e.g., has_stone_pickaxe) and an ordered list of environment conditions mapped to prerequisite SHARPs already in the archive (e.g., if stone < 1 -> invoke MineStone).
The novel magic happens at runtime via a recursive transition operator. At every single environment step, if the agent is tasked with crafting a stone pickaxe, the SHARP checks its prerequisites. Missing stone? Control routes to MineStone. Missing a wooden pickaxe to mine that stone? MineStone routes control down to CraftWoodPickaxe. The RL policy is conditioned only on the immediately actionable skill at the bottom of that chain. Once the agent masters prerequisites, learning a new, complex skill only requires learning the marginal final step.
The archive grows and self-corrects through two FM-driven loops:
- Discovery (Propose–Implement–Judge): Given the environment source code and current archive, FMs propose new skill pseudo-code, translate it to Python, and filter candidates for correctness, feasibility, and novelty. Candidates enter the archive only if the RL agent shows measurable learning progress on them.
- Archive Evolution (Mutation): FMs sample low-performing SHARPs and mutate them—reordering conditions or swapping prerequisites. Because the RL policy only ever sees the active leaf skill, mutations just change how the graph is traversed and can be evaluated immediately in parallel without retraining the agent's neural network.
Datasets
Because this is an embodied RL paper, evaluation happens across interactive simulators rather than static datasets:
- Craftax-Classic: A 2D procedural survival grid-world (based on Crafter) with 22 native achievements up to mining diamonds.
- XLand-MiniGrid: A procedural 2D grid-world featuring stochastic object-interaction rules that randomize every episode. The authors introduce 20 new evaluation targets (picking up crafted objects and unlocking doors).
- AI2-THOR: A photorealistic 3D household simulator. Because the full engine source code exceeds FM context limits, the system is given only the initial environment state. The authors introduce 98 hand-authored kitchen achievements (up to 6 sub-tasks deep, like frying sliced potatoes).
- Craftax-Extended: A massive scale-up adding 8 NetHack-style dungeon levels, evaluated on four challenging long-horizon benchmark tasks (up to 11 sub-tasks each).
Key Insights and Ideas
- Step-level dynamic routing beats flat checklists: In stochastic worlds like XLand-MiniGrid, crafting rules change every episode. Fixed sequences of sub-goals (used by prior work and tested via a "Flat Reward Program" ablation) break down immediately. Re-evaluating the prerequisite tree at every step lets the agent adapt on the fly and relieves the FM from having to specify massive, error-prone chains from scratch.
- Emergent exploitation of game physics: In the pitch-black Mines of Craftax-Extended, CODE-SHARP invented a skill to walk to the edge of a lit area, and built another skill on top of it to place a torch there. Using this as a prerequisite implicitly induced systematic exploration—the agent continuously pushed back the darkness boundary step by step.
- Zero-gradient curriculum debugging: Decoupling the high-level dependency graph from the low-level goal-conditioned policy means structural bugs (like telling an agent to enter a dungeon before crafting a sword) can be patched by mutating Python code and testing rollouts instantly, yielding a 68.8% relative jump in mutated skill success rates in long runs.
Key Results
Performance comparison across Craftax-Classic and XLand-MiniGrid
- Craftax-Classic: CODE-SHARP hits a 94.8% median success rate across all 22 achievements, beating OMNI (15.8%) by 6x and ELLM (8.1%) by over 11x. It is the only method to craft iron tools (>94% success) and mine diamonds (16% average, up to 39%).
- XLand-MiniGrid: Achieves 79.2% median success, a 2.7x improvement over ELLM (29.7%) and far ahead of OMNI (2.2%).
- AI2-THOR: Without full source code, CODE-SHARP reaches 66.7% median success versus 0.0% for both ELLM and OMNI, and is the only method to solve the 6-step
CookSlicedPotatotask (16.7%). - Craftax-Extended (2 billion steps): Discovers ~90 skills and achieves an overall zero-shot benchmark score of 50.5, matching an oracle baseline pre-trained and fine-tuned directly on ground-truth rewards (47.9), while crushing standalone ReAct LLM agents (6.7).
Limitations and Future Work
CODE-SHARP reduces human engineering, but doesn't eliminate the need for structured environment access—it still requires either readable environment source code or a structured representation of the initial state. Furthermore, the authors note through ablations that when environment source information is restricted, the system's success leans heavily on world priors baked into the Foundation Model during pre-training (meaning a truly alien physics engine with hidden code would still pose a major hurdle). Future work is not explicitly discussed in the main text beyond positioning CODE-SHARP as a stepping stone toward fully autonomous generalist agents.
Summary updated