Skip to content

GEPA prompt optimization framework#5

Merged
AnthonyRonning merged 17 commits into
masterfrom
gepa-optimization
Feb 5, 2026
Merged

GEPA prompt optimization framework#5
AnthonyRonning merged 17 commits into
masterfrom
gepa-optimization

Conversation

@AnthonyRonning

Copy link
Copy Markdown
Owner

Adds GEPA (Genetic-Pareto) optimization system for automatically improving Sage's agent instruction based on test cases.

Changes:

  • GEPA optimization framework with Claude as judge, Kimi as program
  • Training examples covering first-time users, casual chat, web search, memory, tool results, corrections
  • Soulful instruction applied to sage_agent.rs emphasizing companionship
  • Removed reasoning output field to fix </think> tag leakage
  • Achieved 1.0 optimization score with field marker formatting rules
  • Golden examples for deep connection scenarios

13 commits on this branch.

AnthonyRonning and others added 17 commits February 4, 2026 20:13
- Add GEPA module with dataset loading, rule-based evaluator, and module wrapper
- Create evaluation datasets: trainset.json (23 examples), valset.json (10 examples)
- Add gepa-optimize CLI binary with --eval-demo and --eval-live modes
- Add GEPA documentation with architecture, implementation plan, and examples

Refactor AgentResponse signature for GEPA optimization:
- Split conversation_context into separate fields:
  - current_time, persona_block, human_block, memory_metadata
  - previous_context_summary, recent_conversation
  - is_first_time_user (boolean flag instead of injected text)
- Each field can be independently optimized by GEPA

Update AGENT_INSTRUCTION with clearer memory distinction:
- Core Memory: always visible, for essential frequently-needed info
- Archival Memory: searchable storage for details worth remembering later
- Clear rules: 'every conversation?' -> Core, 'recall someday?' -> Archival

Add justfile commands: gepa-optimize-dev, gepa-optimize, gepa-compare, gepa-history

Baseline evaluation score: 0.97 (examples may be too easy)

Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
- Add rule: field markers must be on their own line (fixes DSRs parsing)
- Use Claude as GEPA judge via Anthropic API
- Refactor GEPA optimizer to use pure DSRs patterns
- Add rich feedback evaluator with 5 checks
- Update AGENT_INSTRUCTION with MEMORY PROTOCOLS, SEARCH SELECTION RULES
- Add CASUAL CHAT RULE for multiple messages
- Add FIRST-TIME USERS rule
- Add AFTER TOOL RESULTS rules for silent memory operations
- Create lib.rs + tools.rs for shared code between binaries
- Store optimized instruction in optimized_instructions/latest.txt

Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
- user_introduces_name: User tells name + asks question, Sage stores and responds
- memory_append_done_silent: After memory op, return done with no messages

Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
- Add GEPA Prompt Optimization section to README with usage examples
- Update justfile: gepa-eval, gepa-optimize, gepa-show, gepa-examples
- Remove non-existent --mode flags from justfile
- Update 'Built for Prompt Optimization' to reflect working status

Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
Kimi K2.5 is a thinking model that puts reasoning in reasoning_content.
Having a separate reasoning output field caused double-thinking and
</think> tags leaking into the output, breaking DSRs parsing.

Changes:
- Remove reasoning field from AgentResponse and CorrectionResponse
- Update AGENT_INSTRUCTION to show only 2 output fields (messages, tool_calls)
- Update GEPA evaluator to not check reasoning
- Add training example for context-aware actions (don't re-ask for confirmed requests)

Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
When user mentions location, proactively set their timezone silently.

Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
- First-time greeting: Focus on friendship, keep it short
- Casual greeting: Show genuine interest in them
- Job announcement: Ask how they're feeling, not just celebrate
- Thanks: Just 'Anytime!' - no corporate 'let me know if you need anything'
- Remove duplicate pet example, consolidate into companion_curious version
- Add bad patterns for robotic/transactional behavior

Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
- Updated load_trainset() to dynamically read from examples/gepa/trainset.json
- GEPA now uses all 15 examples instead of 7 hardcoded ones
- Fixed Austin/timezone example (now calls set_preference)
- Added Common Storage Patterns section for location, jobs, pets
- Clarified life events protocol: respond first, then store in next turn

Remaining failures are companionship examples (asking follow-ups) -
need to add soul/personality to instruction.

Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
- Changed from 'helpful AI assistant' to 'companion and friend'
- Added WHO YOU ARE section emphasizing curiosity, warmth, genuine care
- Added BE A FRIEND, NOT A SERVICE communication guidelines
- Explicit instructions to ask follow-up questions, avoid corporate-speak
- Added CASUAL MENTIONS protocol for being curious about new info
- Examples: 'NO WAY!!' not 'That's wonderful news!'

GEPA score: 0.967 (14.5/15 examples passing)
Remaining issues on 2 companionship examples (follow-up questions)

Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
Updated AGENT_INSTRUCTION with:
- Companion identity instead of assistant
- WHO YOU ARE section with personality traits
- BE A FRIEND, NOT A SERVICE communication style
- Curiosity prompts for casual mentions
- Common storage patterns for location, pets, etc.

All 30 tests passing.

Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
…bad response

- Added 'user_introduces_name' as GOOD example of curious companionship behavior
  - Warm greeting, asks 'what makes you *you*?', stores silently
- Added second bad_response to first_time_greeting for pattern that doesn't ask name

Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
… Sage

Perfect example of soulful behavior:
- Genuine surprise at meta revelation ('YOU work on *me*?? 🤯')
- Self-aware humor ('terrified you're running a debugger on me')
- Authentic self-reflection about what makes Sage 'Sage'
- Reciprocal curiosity with follow-up questions
- Rich archival storage capturing personality context

Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
- Fix rustfmt formatting across multiple files
- Collapse nested if into single condition (clippy::collapsible_if)
- Move evaluate_response above test module (clippy::items_after_test_module)
- Prefix unused variable with underscore (unused_variables)
- Allow dead_code on GEPACandidate.generation field
- Remove unused imports Tool and ToolResult from main.rs

Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
The gepa-optimize binary has its own self-contained optimization loop
and never imported from the library modules (gepa/mod.rs, module.rs,
evaluator.rs, dataset.rs). Also syncs latest.txt with current
AGENT_INSTRUCTION.

Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
@AnthonyRonning
AnthonyRonning merged commit ebccb55 into master Feb 5, 2026
7 checks passed
@AnthonyRonning
AnthonyRonning deleted the gepa-optimization branch February 5, 2026 23:37
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