examples/prompt: GEPA as a Daft pipeline#42
Conversation
Reflective prompt optimization (Agrawal et al. 2025, arXiv:2507.19457) where the two effects are daft.functions.prompt expressions: eval classifies a batch and scores vs gold; reflect rewrites the instruction from the failures. The optimizer itself — Pareto candidate selection + reflect/mutate + minibatch accept gate — is ~70 lines of plain Python. No agent framework, no orchestration glue. Self-contained, deps = daft[openai] only. Live via OpenRouter (OPENROUTER_API_KEY; one-line Anthropic swap noted inline); falls back to a deterministic offline mock when no key is set so the loop is visible without spend. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 2b4a382c1b
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| live = bool(os.environ.get("OPENROUTER_API_KEY")) | ||
| eval_fn, reflect_fn = daft_effects() if live else mock_effects() |
There was a problem hiding this comment.
Load .env before selecting the live path
When users follow the repo setup and put OPENROUTER_API_KEY in .env (as the other prompt examples do via load_dotenv()), this check never sees it during a direct uv run examples/prompt/prompt_gepa.py, so the script silently runs the offline mock instead of the Daft/OpenRouter pipeline. That makes the new example appear to work while not exercising the live prompt path for the standard local setup.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
@claude can you tackle this and commit to this PR?
What
A new self-contained example: GEPA (reflective prompt optimization, Agrawal et al. 2025, arXiv:2507.19457) implemented as a Daft pipeline.
The two effects GEPA needs are just
daft.functions.prompt(...)expressions:The optimizer itself (instance-wise Pareto candidate selection + reflect/mutate + minibatch accept gate, metric-call budget) is ~70 lines of plain Python. No agent framework, no orchestration glue — the optimizer is a loop, the LLM is a column, Daft runs the batch.
Notes
daft[openai]only. Self-contained single file.OPENROUTER_API_KEY); one-line Anthropic swap is noted inline.use_chat_completions=True, matching the otherprompt_*examples.Run
export OPENROUTER_API_KEY=sk-or-... uv run examples/prompt/prompt_gepa.py🤖 Generated with Claude Code