Skip to content

examples/prompt: GEPA as a Daft pipeline#42

Open
everettVT wants to merge 1 commit into
mainfrom
everettVT/gepa-daft-example
Open

examples/prompt: GEPA as a Daft pipeline#42
everettVT wants to merge 1 commit into
mainfrom
everettVT/gepa-daft-example

Conversation

@everettVT

Copy link
Copy Markdown
Contributor

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:

  • eval — classify a batch of examples with the candidate instruction, score vs gold labels
  • reflect — rewrite the instruction from the minibatch failures

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

  • Deps = daft[openai] only. Self-contained single file.
  • Live via OpenRouter (OPENROUTER_API_KEY); one-line Anthropic swap is noted inline. use_chat_completions=True, matching the other prompt_* examples.
  • Offline fallback: with no key it runs a deterministic mock so the loop (and the Pareto accept/reject trace) is visible without spend — keeps it runnable in CI.

Run

export OPENROUTER_API_KEY=sk-or-...
uv run examples/prompt/prompt_gepa.py

🤖 Generated with Claude Code

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>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment on lines +225 to +226
live = bool(os.environ.get("OPENROUTER_API_KEY"))
eval_fn, reflect_fn = daft_effects() if live else mock_effects()

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@claude can you tackle this and commit to this PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant