Cisco Foundation AI released a system that does something most prompt engineering tools still don't: it optimizes entire pipelines, not just individual prompts. FAPO (Fully Automated Prompt Optimization), presented in arXiv paper 2606.19605, uses Claude Code as an autonomous optimizer that iterates through eval-driven loops—editing prompts first, then escalating to chain parameters and structural changes only when the evidence demands it. The results are substantial: across six benchmarks and three task models, FAPO beats the baseline GEPA in 15 of 18 comparisons, with a mean gain of +14.1 percentage points. When it escalates to structural changes, the gains jump to +33.8 pp.

The code is on GitHub at cisco-foundation-ai/fully-automated-prompt-optimization. It's open source, MIT-licensed, and ready to use.

The Problem FAPO Solves

Multi-step LLM pipelines are everywhere now. A typical pipeline might retrieve documents, reason over them, then format an answer. Each step is an LLM call, and each step can fail in different ways. The retrieval step might pull irrelevant documents. The reasoning step might hallucinate. The formatting step might produce malformed output.

The standard approach to improving these pipelines is prompt optimization—tweaking the instruction text at each step until performance improves. Tools like DSPy and GEPA do this. They treat the prompt as the only variable and search over instruction strings while keeping the pipeline structure fixed.

This works, up to a point. But it misses something fundamental: when a pipeline fails, the root cause often isn't the prompt. It's the pipeline structure itself. A retrieval step that consistently pulls bad evidence can't be fixed by better prompting downstream. The answer is to add a re-ranking step, or to change how retrieval works. Prompt-only optimization can't see this, because it doesn't inspect what happens inside the pipeline.

FAPO's core insight is that you need step-level attribution to know what to change. You need to look at intermediate outputs, classify failures by which step caused them, and then decide whether a prompt edit can fix the problem or whether you need to restructure the pipeline.

How FAPO Works

FAPO is built around a six-stage optimization loop that runs inside Claude Code:

  1. Evaluate. Run the current pipeline variant on the training dataset. Record the final output and every intermediate step output.
  2. Attribute. Classify each failure by pipeline step and fix type. Was the retrieval step pulling bad evidence? Did the reasoning step hallucinate? Did the formatting step produce invalid JSON?
  3. Propose. Generate one scoped variant targeting the dominant failure cluster. This might be a prompt edit, a parameter change, or a structural change to the chain.
  4. Review. An independent variant reviewer checks the proposal for scope compliance, placeholder integrity, data leakage, and scorer compatibility.
  5. Compare. Re-run the variant and compare it against the previous best on aggregate validation scores.
  6. Iterate or escalate. Keep improved variants. If prompt-level changes plateau, escalate to chain parameters or chain structure—but only if the attribution report identifies a structural bottleneck and the tenant's scope contract allows it.

This loop runs repeatedly until the pipeline reaches the target score or the optimizer exhausts its allowed changes.

The Prompt-First Escalation Model

FAPO's escalation strategy is one of its most important design decisions. It always starts with prompt edits. Only when prompt optimization plateaus—and the attribution report shows that the remaining failures are structural—does it escalate to chain-level changes.

This is deliberate. Prompt edits are cheap, safe, and easy to review. Structural changes are expensive, risk introducing new failures, and need more careful validation. FAPO treats structural changes as a last resort, not a first option.

The paper shows this clearly: in the six HoVer and IFBench comparisons where FAPO escalated to structural changes, it won all six with a mean gain of +33.8 pp. These are tasks where the pipeline structure was genuinely the bottleneck—retrieval was insufficient or constraint enforcement was missing. In the other comparisons, prompt edits were enough, and FAPO still outperformed GEPA.

Step Attribution

Step attribution is what makes FAPO different from every other prompt optimizer. Each node in a FAPO pipeline writes its output to a named field in the shared chain state. The optimizer can then inspect every intermediate result—what the retrieval node returned, what the reasoning node produced, what the formatting node output.

When a case fails, the attribution agent classifies the failure by step and type:

  • Missing evidence: The retrieval step didn't find relevant information.
  • Unsupported abstention: The model refused to answer despite having sufficient evidence.
  • Verbose answers: The model produced unnecessarily long outputs that lose the answer in noise.
  • Malformed output: The model produced invalid format (bad JSON, wrong structure).
  • Weak instruction: The prompt itself wasn't specific enough to guide the model.

This classification drives the next iteration. If most failures are "missing evidence," the optimizer knows to look at the retrieval step—not to keep tweaking the reasoning prompt.

The Architecture

FAPO has three main components:

Hephaestus (the evaluation engine). Located in src/hephaestus/, this is the shared runtime that loads datasets, renders prompts, calls LLM providers, runs LangGraph chains, validates scorer outputs, and writes run artifacts. It's task-agnostic. Any tenant can use it.

Tenant workspaces. Each optimization project gets its own isolated workspace under tenants/<id>/. This contains the chain code, prompt variants, dataset, scorer, eval configs, and optimization history. Tenants are isolated from each other, so assumptions and invariants from one project don't leak into another.

The Claude Code optimizer. This is the orchestration layer. It reads the tenant playbook, writes a scope contract, and drives the optimization loop. It dispatches subagents for step attribution and variant review. It runs evaluations, compares results, and decides when to escalate.

The separation between the optimizer and the task model is important. The optimizer is always Claude Code. The task model—the model being optimized—can be anything: GPT-4o, GPT-5, Gemma 3-12B, Foundation-Sec-8B, or any model accessible through the supported providers (OpenAI, Baseten, SageMaker). The optimizer never becomes the task model.

The Tenant Playbook and Scope Contracts

Each tenant has a playbook that defines what the optimizer is allowed to change. This is the governance layer. The playbook specifies:

  • Which files can be modified (via glob patterns)
  • Which optimization levels are allowed (prompt text, chain parameters, chain structure)
  • What the success criteria are (e.g., composite_score >= 90)
  • Any domain-specific constraints

The optimizer reads the playbook at the start of each cycle and checks every proposed change against it. The variant reviewer independently verifies scope compliance. This double-checking ensures the optimizer doesn't violate the tenant's rules.

Chain Representation with LangGraph

FAPO represents each pipeline as a LangGraph state graph. Each node in the graph is a processing step—either an LLM call or a custom function. Edges define the flow between steps. The shared state has four fields:

  • context: Input from the dataset case
  • output_text: The final output, read by the scorer
  • step_outputs: Intermediate outputs, keyed by node name
  • diagnostics: Debug traces and warnings

The step_outputs field is what makes attribution possible. Because every node writes a named output, the pipeline is inspectable as a sequence of intermediate artifacts rather than a single opaque final string.

Results

The paper evaluates FAPO against GEPA across six benchmarks:

  • HotpotQA (multi-hop question answering)
  • HoVer (fact verification with multi-hop reasoning)
  • IFBench (instruction following)
  • GSM8K (math reasoning)
  • CTIBench-RCM (CVE-to-CWE security classification)

Three task models: GPT-4.1-mini, GPT-5.4-mini, and Gemma 3-12B.

The headline numbers:

  • FAPO beats GEPA in 15 of 18 model-benchmark comparisons.
  • In 11 comparisons, FAPO wins with non-overlapping confidence intervals (mean ± trial standard deviation).
  • The mean FAPO-GEPA gain is +14.1 pp.
  • When FAPO escalates to structural changes (6 comparisons on HoVer and IFBench), it wins all 6 with a mean gain of +33.8 pp.
  • On prompt-only comparisons, FAPO wins 9 of 12.

On the security task (CTIBench-RCM), where only prompt edits were allowed per the Foundation-Sec evaluation protocol, FAPO improved accuracy by +4.0 pp on GPT-5, +7.1 pp on Foundation-Sec-8B-Instruct, and +2.0 pp on Foundation-Sec-8B-Reasoning.

These are not marginal improvements. The +33.8 pp gain on structural-change tasks shows that pipeline structure matters enormously, and that prompt-only optimization leaves significant performance on the table.

Using FAPO

Getting started with FAPO is straightforward. You need four things: a dataset, a chain, a scorer, and a config file.

The dataset is a JSONL file where each line is a test case with a unique ID, task type, context, expected output, and metadata.

The chain is a LangGraph pipeline with a build_chain function that takes a provider and config, then returns a compiled graph.

The scorer is a Python class that implements validatecase and scorecase, returning a composite score between 0 and 100 plus a breakdown of individual metrics.

The config ties everything together—specifying the provider, model, dataset path, chain path, scorer path, and output directory.

Once you have these, run the evaluation with:

python -m hephaestus.cli eval --config eval.json

Then start the optimization loop with Claude Code:

/optimization
→ Tenant: my_project
→ Config: eval.json
→ Success criteria: composite_score >= 90

Claude Code takes over from there. It analyzes failures, creates improved prompt variants, evaluates them, compares scores, and iterates. If you've allowed structural changes in your playbook, it will escalate when attribution shows that prompts alone can't fix the problem.

Why This Matters

FAPO represents a shift in how we think about LLM pipeline optimization. The current dominant approach—prompt engineering as a manual, one-step-at-a-time activity—doesn't scale. As pipelines get more complex, manual tuning becomes intractable. You can't manually inspect intermediate outputs for hundreds of test cases, classify failures by step, and then decide whether to edit a prompt or restructure the chain. That's exactly the kind of work that should be automated.

FAPO also makes a design argument: optimization should be grounded in evidence, not intuition. The step-level attribution means every change is tied to a specific, observed failure pattern. You're not guessing that the retrieval step is weak—you have the intermediate outputs that prove it. And you're not making structural changes on a hunch—you're escalating because the attribution report shows that prompt edits can't fix the dominant failure mode.

The security results are particularly interesting. CTIBench-RCM is a real-world task—mapping CVEs to CWEs—and FAPO produced meaningful improvements across three different models. This suggests the approach transfers beyond academic benchmarks to operationally relevant security work.

Limitations and Open Questions

FAPO relies on Claude Code as the optimizer. This means you need access to Claude Code, and the quality of optimization depends on Claude's ability to analyze failures and propose effective changes. The paper doesn't explore how sensitive results are to the choice of optimizer model.

The prompt-first escalation strategy is conservative by design. In some cases, a structural change early might produce faster convergence. FAPO's current approach trades speed for safety—structural changes are riskier, so it waits until evidence supports them.

The evaluation is limited to GEPA as the baseline. Comparisons against other optimization approaches (DSPy's MIPRO, text-grad-based methods) would strengthen the case. The paper focuses on GEPA because it's the most directly comparable prior work—it optimizes prompts within the same pipeline structure—but the landscape of optimization methods is broader.

Finally, FAPO's tenant model is well-suited for the corporate environments where Cisco operates, but it adds complexity. For simple single-step prompts, the full tenant workspace might be overkill. The system is designed for multi-step pipelines where attribution matters; for single-step tasks, lighter-weight tools might be more appropriate.

Bottom Line

FAPO is the most complete prompt optimization system I've seen. It addresses the real problem—pipelines fail at specific steps, and you need to know which steps before you can fix them—with a principled attribution-driven approach. The prompt-first escalation strategy is sensible. The results are strong, especially when structural changes are involved. And the open-source release means you can start using it today.

If you're building multi-step LLM pipelines and still optimizing prompts by hand, FAPO is worth a serious look. The step attribution alone—being able to see exactly where your pipeline fails—is valuable even if you never use the automated optimization loop. And if you do use the loop, the +14.1 pp average improvement over GEPA speaks for itself.

Links: