Michael Isaac built the module during an internship at Compound AI (cmpnd). He is a doctoral candidate at Carnegie Mellon, where his field is the engineering of software itself. It changes what an optimizer is allowed to touch. Instead of tuning only a program’s prompt, Flex exposes the program’s source code to the optimizer, so a model can rewrite the logic that decides when to call another model at all. That is a meaningfully larger surface than prompt tuning has ever offered.
DSPy’s optimizers have expanded their reach in stages. BootstrapFewShot, released in 2022, automated the selection of few-shot examples. MIPROv2 and GEPA later rewrote instruction text once models became competent prompt authors. Flex is the next stage: it treats the code around the model call, not just the words fed into it, as something an optimizer can restructure.
Compound AI tested Flex on a location-matching task: given two business listings, decide whether they describe one physical place or two. The team trained on 1,029 labeled location pairs, then measured accuracy against a held-out set of 240 records. A plain dspy.Predict baseline, calling a model on every record, hit 90.4 percent accuracy at $0.98 per thousand records. Running GEPA to optimize only the prompt raised accuracy to 92.5 percent but nearly tripled the cost, because the only lever available was a longer instruction that every inference call had to pay for.
Handing GEPA the code produced a different trade. With no penalty on model calls, Flex plus GEPA reached 95.0 percent accuracy while cutting cost by roughly 28 percent and latency by about 40 percent against the original baseline. The rewritten program routed three-quarters of records through ordinary Python comparisons on names, addresses, and distance, calling a model only for pairs its own rules could not resolve. Adding a cost penalty to the scoring function pushed the routing further: at the highest penalty Compound AI tested, the program called a model once across all 240 records and still matched baseline accuracy, at close to a hundredth of the price.
That result reframes what prompt-optimization frameworks like DSPy’s own MIPROv2 have been doing. Those tools search a fixed architecture, one model call per record, for the best wording. Flex expands the search to the architecture itself: whether to call a model, how often, and what code runs before and after. Compound AI also reports a smaller pilot on the SWE-bench Pro coding benchmark, where Claude Haiku 4.5 alone resolved zero of twelve sampled issues but a Flex-optimized harness resolved four, after assembling its own multi-step research-and-repair workflow. The company frames that result as preliminary, not a benchmark claim to generalize from.
The harder question is what happens once optimizers routinely write and rewrite the code running in production, not just the prompts. Compound AI’s answer to execution risk is to run model-written code inside an isolated interpreter rather than the host process, with a call cap limiting how often it can reach back out. That does not resolve the audit problem: a saved Flex program is inspectable text, but a team now has to review model-authored branching logic, thresholds, and routing rules the way it would review a contractor’s pull request, on every optimization run rather than once at launch.
Teams already running DSPy pipelines in production should treat a Flex program’s generated diff as a mandatory code review step before it touches live traffic, not an optional one, and should keep a prompt-only fallback on hand for cases where an auditor cannot sign off on rewritten logic in time.
Published by Compound AI on August 5, 2026.