Skip to content
matthewcm.dev

    ↑ ↓ move · ↵ open · tab scopeopen graph →

    Eureka: Automating Reward Design with Coding LLMs

    NVIDIA's Eureka puts an LLM in a loop around reinforcement learning — it reads the environment code, writes reward functions, trains, reflects on the results and rewrites. A blueprint for closed-loop agents.

    Growingtended planted 4 min read
    On this page

    Eureka (Ma et al., NVIDIA, ICLR 2024) answers a question I find more interesting than the robotics it was built for: what happens when an LLM doesn’t just respond to a prompt, but drives a whole closed-loop design process?

    The task is reward design for Reinforcement Learning — notoriously fiddly work that human experts usually do by trial and error. Eureka hands it to an LLM acting as a “reward architect”.

    The loop

    1. Read the environment. The LLM gets the raw source code of the simulation as context, so it understands the task’s mechanics and objectives directly rather than through a description.
    2. Write rewards as code. It generates several candidate reward functions in Python, zero-shot, with no templates.
    3. Train. Each candidate trains a policy in a GPU-parallel physics simulator.
    4. Reflect. Eureka feeds back a reward reflection: statistics on how each component of the reward behaved during training. In effect, a structured critique.
    5. Revise. The LLM keeps the best candidate, works out which terms helped or hurt, and writes improved versions. Repeat for a fixed number of iterations.

    It beat expert human-written rewards on most of the benchmark tasks, including teaching a simulated hand to spin a pen.

    Why code, and why reflection

    • Code is inspectable. The LLM can reason term by term: “the distance penalty dominates; reduce its weight”. A natural-language reward couldn’t be executed or debugged like that.
    • Reflection is the key ingredient. Without feedback, it’s one-shot generation and a guess. With per-component training statistics, it’s guided search — closer to evolution than to autocomplete.
    • There’s a budget. Fixed iterations and samples per round. Explicit stopping criteria are what stop an agentic loop becoming an expensive infinite one.

    The general pattern

    Take the robotics away and Eureka is the shape of most useful agents I’ve seen: propose → execute in a real environment → observe metrics → reflect → revise, with a budget. Coding agents do it with tests (write code, run tests, read failures, fix). It’s the same agent → environment → feedback loop described in What Makes an AI Agent, with a TDD flavour: like a developer who starts writing tests just by reading the source code and the requirements.

    Building a Eureka-style loop yourself

    Re-implementing the loop as a small multi-agent system makes the moving parts explicit. One iteration is generate → evaluate → select → reflect → (optional human input) → exit check → increment.

    AgentJob
    Reward designer (LLM)Generates k reward candidates
    Candidate evaluatorTrains and evaluates a policy per candidate
    SelectorPicks the best candidate
    Reward reflector (LLM)Turns raw training numbers into actionable guidance. It does not write rewards
    Human reflectorAn optional human-in-the-loop pause
    Exit checkerStops early when good enough
    IncrementAdvances the iteration

    Two design choices paid off:

    • Split the config. One config controls how the system runs (iterations, candidates, training steps, seed, environment); a separate task spec controls how performance is judged (episodes, horizon, task metadata).
    • Make failure visible. Write reward functions like validators, prioritising execution reliability over readability. If anything fails, capture it, write an error artefact and still append a leaderboard entry, so failures show up in the results instead of vanishing. Cache expensive evaluations.

    Evaluating it as a system designer

    Reward reflection is the architectural key: try, measure, reflect, edit, so an engineer can debug with evidence. But the greedy loop has risks:

    • Selection pressure overweights noisy early gains. RL training is high-variance (seed luck, PPO variance), so the “best” candidate in round one may just have been lucky.
    • The evaluator quietly becomes the definition of truth. Whatever the training run and metric reward is what the system optimises, which is Goodhart’s Law with a GPU budget. Adding more reflection agents adds exploration, but with the same evaluator they may simply converge early, faster.

    Checks I’d want on any evaluator:

    • Return vs success-rate gap: high return without more task success usually means reward hacking.
    • Episode length distribution and termination reasons.
    • Stability across seeds.
    • Learning-curve shape, not just the final number.

    And test the evaluator itself, the way you’d test a CI suite: inject seeded bugs (mutation testing) and make sure it fails. Same principle as Don’t Read the Code: trust the verification, then verify the verifier.

    In practice

    The part I’ve stolen for my own tooling is reflection as a first-class artefact. When an automated step runs, I want a short structured record of what it tried, what happened and what it would change — not just a pass/fail. It makes the next iteration better, and it makes the loop auditable by a human. That’s as true for a CI pipeline as for an agent.

    • #ai-agents
    • #reinforcement-learning
    • #llm
    • #feedback-loops
    • #papers

    ↪ Links to (4)