Skip to content
gepa-aiPublic

About

No description, website, or topics provided.

Resources

Stars

20 stars

Watchers

0 watching

Forks

Repository files navigation

Terrarium

Common evaluation infrastructure for evolving/auto-research systems. Terrarium provides a standard way to define benchmark tasks and run any evolution system against them with controlled, measured evaluation budgets.

Overview

    ┌──────────┐        ┌────────────────────────────────────────┐
    │  Runner  │───────►│           EvalServer                   │
    └──────────┘        │  (single budget choke point)           │
         │              │                                        │
         │              │  server.evaluate()  ◄── in-process     │
         ▼              │  POST /evaluate     ◄── HTTP (ext.)    │
    ┌──────────┐        │                                        │
    │ Adapter  │───────►│  BudgetTracker ── task.eval_fn         │
    └──────────┘        └────────────────────────────────────────┘

Every adapter — in-process or external — goes through the same EvalServer. The server owns the budget counter and the eval function. Adapters cannot bypass or modify it.

  • In-process adapters (GEPA, custom) call server.evaluate(candidate) directly — no HTTP overhead.
  • External adapters (Claude Code, any subprocess) POST to server.url/evaluate — budget enforced server-side.

Quick Start

0. Setup

gepa is included as a submodule, pinned to the feat/optimize-anything-omni branch, which includes the ClaudeCodeAgentProposer agentic reflection backend used in the agent ablation:

git clone https://github.com/gepa-ai/terrarium.git
cd terrarium
git submodule update --init gepa
pip install -e .

To advance the submodule to the latest feat/optimize-anything-omni branch tip (e.g. to pick up post-submission optimizer features), use git submodule update --init --remote gepa. Note that the branch is under active development, so the tip can change numbers vs. the paper; the paper numbers were produced with cfef49e.

1. Run from the command line

python -m terrarium circle_packing my_adapter.py --max-evals 100

2. From Python

from terrarium import run

result = run("circle_packing", "my_adapter.py", max_evals=100)
print(f"Best score: {result.best_score}")
print(f"Evals used: {result.total_evals}")

3. Pass an adapter object directly

from terrarium import run
from terrarium.adapters.gepa import GEPAAdapter

adapter = GEPAAdapter(reflection_lm="openai/gpt-5")
result = run("circle_packing", adapter, max_evals=150)

Available Tasks

Task Type Candidate Description
circle_packing single-task code Pack 26 circles in a unit square, maximize sum of radii
optuna_blackbox single-task code Evolve code to minimize a blackbox objective function
frontier_cs_algo_<id> single-task program Solve one Frontier-CS algorithmic problem (C++)
cloudcast multi-task code Cross-cloud broadcast routing across 5 region configs
cant_be_late generalization code Spot-instance scheduling under deadlines
aime_math / aime_math_mini generalization prompt AIME math problem solving
arc_agi generalization code ARC-AGI abstract reasoning agent
finer generalization prompt XBRL US-GAAP tag classification (ACE FiNER)
formula generalization prompt Financial-formula numeric QA (ACE Formula)
livebench_math generalization prompt LiveBench math benchmark (stratified by subtask)
needle_in_range single-task code Needle-in-haystack range search
slot_machines single-task code Bandit-style stationary slot-machine search

Reproducing Paper Experiments

The agent-ablation results in our paper are produced by the optimize_anything pipeline (adapter=optimize_anything) wrapping each base optimizer. Each task is run at a matched budget of 4000 metric calls / $400 token cost. The three prompt-optimization tasks use deterministic subsampling for reproducibility:

Paper experiment Task name Split (train / val / test) subsample_seed
FiNER (Fig. agent_vs_gepa) finer 100 / 100 / 150 0
Formula (Fig. agent_vs_gepa) formula 100 / 100 / 150 0
LiveBench-Math (Fig. agent_vs_gepa) livebench_math 100 / 100 / 168 (frozen) n/a
Frontier-CS (Fig. agent_vs_gepa) frontier_cs_algo_<id> for id ∈ {0, 4, 145, 162, 255} per-problem (single-task) n/a

A one-shot reproducer for the prompt-optimization rows lives at scripts/reproduce_paper.sh:

bash scripts/reproduce_paper.sh        # all 3 prompt-opt tasks, GEPA + GEPA-Agent
bash scripts/reproduce_paper.sh finer  # one task

Notes:

  • Both optimizers run under adapter=optimize_anything with engine: gepa inside adapter.configs. The difference is the nested key that selects the reflection proposer: reflection.reflection_lm (LLM reflection) for plain GEPA, claude_code_agent.model (agentic reflection) for GEPA-Agent. See scripts/reproduce_paper.sh for the exact configs payload.
  • The standalone adapter=gepa / adapter=claude_code paths still work but are deprecated (they emit a DeprecationWarning); the paper numbers come from the optimize_anything composition.
  • livebench_math requires the optional dependency group: pip install -e .[livebench_math]. The upstream HF dataset (livebench/math) is downloaded on first use; set HF_HOME if your default cache is read-only.

How to Write an Adapter

An adapter is any class with an evolve(task, server, max_evals) -> Result method. The server is a terrarium EvalServer — use server.evaluate() to score candidates.

Create a Python file that defines create_adapter():

# my_adapter.py
from terrarium.adapter import Result
from terrarium.budget import BudgetExhausted

class MyEvolver:
    def evolve(self, task, server, max_evals):
        """
        Args:
            task: Task definition — use task.objective, task.background,
                  task.initial_candidate, task.train_set, task.test_set as needed.
            server: EvalServer — the single eval + budget choke point.
                - server.evaluate(candidate) -> (score, info)
                - server.evaluate(candidate, example) -> (score, info)
                - Raises BudgetExhausted when budget runs out.
            max_evals: Total eval budget (informational; enforced by server).
        """
        candidate = task.initial_candidate
        best_candidate = candidate
        best_score = float("-inf")

        for i in range(max_evals):
            try:
                score, info = server.evaluate(candidate)
            except BudgetExhausted:
                break

            if score > best_score:
                best_score = score
                best_candidate = candidate

            # Your mutation/evolution logic here
            candidate = self.improve(candidate, score, info)

        return Result(best_candidate=best_candidate, best_score=best_score)

    def improve(self, candidate, score, info):
        # ... your evolution logic ...
        return candidate

def create_adapter():
    return MyEvolver()

Then run:

python -m terrarium circle_packing my_adapter.py --max-evals 100

For dataset tasks

Dataset tasks have examples in task.train_set. Pass them to server.evaluate():

class DatasetEvolver:
    def evolve(self, task, server, max_evals):
        candidate = task.initial_candidate
        best_candidate, best_score = candidate, float("-inf")

        for i in range(max_evals // len(task.train_set)):
            scores = []
            for example in task.train_set:
                score, info = server.evaluate(candidate, example)
                scores.append(score)

            avg = sum(scores) / len(scores)
            if avg > best_score:
                best_score = avg
                best_candidate = candidate

            candidate = self.improve(candidate, scores)

        return Result(best_candidate=best_candidate, best_score=best_score)

Built-in adapters

  • terrarium/adapters/gepa.py — Uses GEPA's optimize_anything. Calls server.evaluate() (in-process, no HTTP).
  • terrarium/adapters/claude_code.py — Launches Claude Code as a subprocess. Gives it a shell script that POSTs to server.url (HTTP, budget enforced server-side).
  • terrarium/adapters/meta_harness.py — Meta-Harness loop (arXiv:2603.28052): repeatedly spawns a Claude proposer that writes candidate files, then benchmarks each through server.evaluate(). Budget counter (max_evals, max_token_cost) shared with every other adapter; per-iteration proposer spend capped via claude --max-budget-usd.

Black-box / external system adapters

For systems that run as external processes, use the HTTP endpoint. The runner already starts the server — your adapter just needs to tell the subprocess where to POST:

class ExternalSystemAdapter:
    def evolve(self, task, server, max_evals):
        # The server is already running (started by the runner).
        # Tell your external system to POST to it:
        #
        #   POST http://localhost:{port}/evaluate
        #   Body: {"candidate": "...", "example_id": "..."}
        #   Response: {"score": 1.23, "info": {...}, "budget": {...}}
        #   HTTP 429 when budget exhausted

        run_my_system(eval_url=server.url, task_desc=task.background)

        return Result(
            best_candidate=server.best_candidate,
            best_score=server.best_score,
            total_evals=server.budget.used,
        )

How to Add a Benchmark Task

Create a new file in terrarium/tasks/ and register it:

# terrarium/tasks/my_task.py
from terrarium.registry import register_task
from terrarium.task import Example, Task

DESCRIPTION = "What this task optimizes and how it's scored."

INITIAL_CANDIDATE = "The starting text (code, prompt, etc.) to evolve from."

def evaluate(candidate: str) -> tuple[float, dict]:
    """Score a candidate. Return (score, info_dict).

    For dataset tasks, the signature is:
        def evaluate(candidate: str, example: Example) -> tuple[float, dict]
    """
    score = run_my_eval(candidate)
    return score, {"score": score}

# For dataset tasks, also define train/test sets:
# train_set = [Example(id="1", inputs={"problem": "..."}, expected="answer"), ...]
# test_set = [...]

TASK = register_task(Task(
    name="my_task",
    objective="One-line objective for the evolution system.",
    background=DESCRIPTION,
    initial_candidate=INITIAL_CANDIDATE,
    eval_fn=evaluate,
    # train_set=train_set,   # for dataset tasks
    # test_set=test_set,     # for dataset tasks
    metadata={
        "type": "single_task",  # or "generalization"
        "candidate_type": "code",  # or "prompt"
    },
))

Then add the import to terrarium/tasks/__init__.py:

from terrarium.tasks import my_task  # registers on import

Task types

  • Single-task (train_set=None): One hard problem. evaluate(candidate) takes no example. E.g., circle packing, blackbox optimization.
  • Dataset / generalization (train_set=[...]): Many related problems. evaluate(candidate, example) is called per-example. E.g., AIME math, ARC-AGI.

Eval function guidelines

  • Return (score: float, info: dict). Higher score = better.
  • The info dict should include diagnostic feedback that helps the evolution system improve (error messages, partial results, execution traces).
  • Keep eval functions deterministic when possible.
  • Import heavy dependencies inside the function body to keep task registration fast.

Architecture

Unified eval path

In-process adapter (GEPA)          External adapter (Claude Code)
        │                                     │
        │ server.evaluate(candidate)          │ POST /evaluate {"candidate": "..."}
        │                                     │
        └──────────────┬──────────────────────┘
                       ▼
              ┌─────────────────┐
              │   EvalServer    │   ◄── single choke point
              │                 │
              │  budget.check() │   ◄── pre-check
              │  task.eval_fn() │   ◄── actual eval
              │  budget.record()│   ◄── count it
              │  track best     │   ◄── update leaderboard
              └─────────────────┘

The BudgetTracker and EvalServer live in the terrarium process. The evolution system — whether it's a Python library running in-process or a subprocess communicating over HTTP — can only evaluate through this server. It cannot read, write, or reset the budget counter.

HTTP endpoints

POST /evaluate  — submit a candidate, get score (HTTP 429 when budget exhausted)
GET  /status    — check budget and best score
GET  /task      — get task description and initial candidate

About

No description, website, or topics provided.

Resources

Stars

20 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages