JetbrainsNikita KhramovTutorial
Prompts That Can Write Themselves: A Kotlin Experiment
Summary
JetBrains Research developed the Koog Agents Optimization Library for optimizing prompts of Koog agents without requiring agent rewrites. Developers mark steps as optimizable using optimizableSubgraphWithTask, lifting instructions into a parameter that an optimizer can replace. The GEPA optimizer runs the agent over a training set, scores outputs with a user-provided function, and iteratively improves instructions using a reflection model, outputting optimized instructions as a separate JSON file. In the PUPA privacy benchmark, GEPA improved the agent’s score from 81.19 to 94.22, and the optimized instruction grew from two vague lines to a 4,456-character detailed instruction. The library also includes BootstrapFewShot, MIPROv2, and ACE optimizers behind the same interface, and all are available in the open-source repository.
Context
JetBrains Research developed the Koog Agents Optimization Library to automate prompt optimization for Koog agents. The post demonstrates how to mark agent steps as optimizable, run the GEPA optimizer, and shows results on the PUPA privacy benchmark.
Approach / What changed
Mark agent steps as optimizable using optimizableSubgraphWithTask, provide a scoring function that returns a score and summary, then run the GEPA optimizer via train() and loadOptimizedAgent() to produce improved instructions as a JSON file.
Takeaways
The library allows marking specific steps in a Koog agent graph as optimizable without changing the agent’s control flow.
GEPA iteratively improves instructions by running the agent over a training set, scoring outputs, and using a reflection model to generate better instructions.
On the PUPA benchmark, GEPA improved the agent’s score from 81.19 to 94.22, and the optimized instruction grew from two vague lines to a 4,456-character detailed instruction.
FAQ
How do I mark a step as optimizable?
Replace subgraphWithTask with optimizableSubgraphWithTask and pass the instruction as the optimizableInstruction parameter. The instruction is lifted out of the string and into its own parameter, where an optimizer can find and replace it.
What does GEPA need from the agent author?
The optimizer needs a function that returns a score and a short summary of how the run went. The score decides which candidate instructions survive, and the text is what the reflection model reads to generate improvements.
Can I switch between different optimizers?
Yes, all optimizers implement the same interface with train and loadOptimizedAgent methods. Switching between GEPA, BootstrapFewShot, MIPROv2, or ACE requires only a constructor change; the surrounding code remains unchanged.
Source and freshness
- Source
- blog.jetbrains.com
- Published
- Added to Yomu
Summaries are generated from the original by a language model. Check the original before relying on it.
Keep reading
Related reading
The Good Stuff
Paid picks we use ourselves. Links carry a referral code — a subscription through one earns us a commission at no extra cost to you.
The best engineering reads, once a week
One useful email. Unsubscribe anytime.