Agent Optimizer is currently in preview. This preview is provided without a service-level agreement, and we don’t recommend it for production workloads. Certain features might not be supported or might have constrained capabilities. For more information, see Supplemental Terms of Use for Microsoft Azure Previews.
Prerequisites
- A Foundry project with a deployed hosted agent
- The
azure.ai.agentsCLI extension installed (see Quickstart: Optimize a hosted agent)
Generate a dataset and evaluators (recommended)
The fastest way to create evaluation assets is withazd ai agent eval generate. The command auto-detects your agent and generates everything the optimizer needs:
- A seed dataset of tasks tuned to your agent’s domain.
- Evaluators that score responses - a built-in evaluator (such as
builtin.task_adherence) plus a custom rubric evaluator tailored to your agent. - A runnable
eval.yamlthat wires them together.
azd ai agent optimize auto-detects eval.yaml:
eval.yaml; see Configure the optimization run.
Customize evaluators (advanced)
Evaluators score each agent response. The optimizer supports two kinds:- Built-in evaluators, such as
builtin.task_adherence, which scores each task-level criterion as pass or fail. - Custom rubric evaluators, which score responses across several quality dimensions tuned to your agent.
azd ai agent eval generatecreates one automatically as an editablerubric_dimensions.jsonfile.
rubric_dimensions.json to refine dimensions, then run azd ai agent eval update to register the changes as a new version. For details on generating, editing, and versioning evaluators, see Initialize evaluation assets.
To wire evaluators into your run configuration, see Configure the optimization run.
Create a custom dataset (advanced)
Create a custom dataset when you need precise control over test scenarios or have production data to use directly. The recommended approach is to iterate on top of the seed dataset thatazd ai agent eval generate produces—refine it into a local dataset, or point to another dataset already registered in your Foundry project.
Choose a dataset source
A dataset can come from either of two sources:- Foundry dataset — a dataset already registered in your Foundry project. Reference it in
eval.yamlbynameandversion. - Local dataset — a JSONL file you author and keep in your project. Reference it in
eval.yamlbylocal_uri.
eval.yaml wiring, see Configure the optimization run.
Dataset schema
A dataset uses JSONL (JSON Lines) format. Each line is one JSON object that represents a single evaluation task—an individual scenario. A task has a prompt (query) and, optionally, task-level criteria.
When you use a local dataset, validate the JSONL syntax before you run optimization:
Add task-level criteria
Criteria are optional. The evaluators you configure ineval.yaml apply to every task in the dataset. Add per-task criteria only when a specific task needs checks beyond those shared evaluators. When present, a task’s criteria are scored and aggregated together with the shared evaluators to produce the task’s overall score.
The following customer-support dataset shows tasks with task-level criteria:
Tips for writing good datasets
Include edge cases
Test beyond the happy path. Include:- Out-of-scope requests — Inputs your agent should decline or redirect
- Ambiguous queries — Tasks where the agent should ask for clarification
- Adversarial inputs — Attempts to trick the agent into bad behavior
- Multi-step tasks — Complex requests that require structured reasoning
Size guidelines
Larger datasets give broader coverage but take longer to evaluate.
Provide ground truth when useful
Theground_truth field gives evaluators a reference answer to compare against. It’s not required - evaluators can also judge responses from their instructions and any task-level criteria alone.