# CAPO: A Primal-Dual Framework for Constraint-Aware Prompt Optimization

*Victor Ye Dong, Reid Pryzant, Yi Liu, Jian Jiao*

[NeurIPS page](https://neurips.cc/virtual/2026/poster/149769) · [Open on the map](../papers.html#p149769)

Category: [LLM Reasoning, Memory & RAG](../pcat/19.md) › [Test-Time Scaling and Optimization](../pgroup/317.md) · Type: new method · Keywords: constraint-aware prompt optimization, primal-dual framework, LLM agentic prompting, Lagrangian relaxation, system prompt optimization

Areas: [AI Agents](../areas/agents.md) › Agentic Decision Making › Language Model Agents; [RL for LLMs & Agents](../areas/llm-rl.md) › Language Model Agents › Language Model Optimization

## Summary
CAPO is a primal-dual framework that optimizes system prompts under explicit constraints to improve agentic performance and satisfy safety and formatting requirements.

## Explained to a 5-year-old
We want to tell a smart computer how to use tools and stay safe. Writing these instructions by hand is hard and takes a lot of work. We made a new method that automatically improves these instructions while following rules like being short and safe. This helps the computer do tasks better without having to train it a lot. It works for many kinds of tasks, like helping people or acting as an assistant.

## Explained to a 5-year-old, longer
We give a big computer, like a chatbot, a set of instructions called a prompt so it knows what to do. In some situations, we need the computer to use tools, be short, be safe, and follow certain rules. Making these special prompts by hand is difficult because we need to think about many rules at once. The paper introduces a way to automatically improve these prompts while keeping them within the rules. It works like a game where we try to make the prompt better and check that it follows all the limits. The method uses a special math technique that balances two parts: making the prompt good and making sure it obeys the rules. This helps the computer finish tasks more reliably without having to change its internal knowledge. It also works for other kinds of tasks, like answering questions while staying safe and private. The approach can be turned into a simpler version that can be trained once and used many times. This makes it easier for people to use the computer in real life, for example in apps that need to be safe. Overall, it gives a practical tool that saves time and effort for developers. It lets the computer be more helpful while staying within the safety and length limits we set.

## For a technical reader
CAPO is a primal-dual optimization framework that automatically refines LLM system prompts to satisfy explicit constraints such as tool usage, length, safety, and formatting. It formulates prompt optimization as a constrained problem and solves it using Lagrangian relaxation, iteratively adjusting the prompt while penalizing violations. The method has been evaluated on three agentic benchmarks and on assistant-style tasks, consistently reaching feasible operating points and improving performance without extra model training. A key practical contribution is a rewrite policy that can be amortized into a trainable rewriter (DCAPO), allowing the approach to be reused across sessions. This makes it possible for developers to enforce operational requirements on LLM agents using a scalable, post-hoc optimization technique rather than costly fine-tuning.

## Problem
Optimizing system prompts for LLM agents to satisfy multiple operational constraints (tool usage, length, safety, formatting) while maintaining performance is challenging, especially when assembling supervised data is infeasible.

## Method
The approach formulates prompt optimization as a constrained optimization problem and solves it using primal-dual updates with Lagrangian relaxation, iteratively adjusting prompts to meet explicit thresholds while balancing performance. It also introduces a rewrite policy that can be amortized into a trainable rewriter.

## Results
The approach reliably reaches feasible operating points on agentic benchmarks and generalizes to assistant-style tasks, matching performance while improving the constrained trade-off.

## Contributions
A primal-dual framework for constraint-aware prompt optimization that handles explicit thresholds via Lagrangian relaxation, a rewrite policy that can be amortized into a trainable rewriter, and empirical validation on agentic and assistant benchmarks.

## Practical relevance
It provides a scalable, constraint-aware prompt optimization solution that avoids costly post-training and can be applied to various agentic and assistant tasks.

This page was written by language models from the title and abstract of each paper, and the answers were checked by two other models. It can be wrong: check the paper itself. [Suggest a correction](../feedback/?on=p/149769)
