A prompt change can fix the response that prompted it and still make the agent less reliable somewhere else. Testing both versions against the same inputs and criteria gives you a way to see what actually changed.
Agent Optimizer in Microsoft Foundry helps find changes worth testing. It evaluates a baseline, proposes alternative configurations, and compares the results. This article explains how the optimizer works, walks through a prompt-agent run in the Foundry portal, and shows how to run the same workflow for a hosted agent with the Azure Developer CLI.
What Agent Optimizer can change
Agent Optimizer changes agent configuration, not model weights. What it can change depends on the agent type and which parts of its configuration are available to the optimization job.
| Agent type | What can be optimized | How to start |
|---|---|---|
| Prompt agent | Instructions, function-calling tool descriptions, and model selection | Use the Optimize tab in the Foundry portal. This workflow supports prompt agents without the Microsoft Copilot harness. |
| Hosted agent | Instructions, existing skills, function-calling tool descriptions, and model selection |
Make the agent optimizer-ready, then run it with azd. The Foundry Toolkit for VS Code can scaffold the integration. |
Tool-description optimization changes what the model knows about a function and its parameters. It doesn’t rewrite the function. For prompt agents, the optimizer doesn’t execute client-side functions during tool-description optimization, so their actual behavior still needs an end-to-end test.
For hosted agents, refining an existing skill is different from learning a reusable skill from recorded conversations, which is a separate preview workflow.
How an optimization run works
A run starts with a baseline to compare against, a dataset to exercise the agent, and evaluators that define what good behavior looks like. Include cases that cover the behavior you want to improve and cases that cover behavior you don’t want to break.
The optimizer runs the baseline, scores its responses, generates alternative configurations, and evaluates those candidates. Foundry ranks the results using a composite score on a 0–1 scale. That score helps you decide which candidate to inspect first; it isn’t the percentage of cases that passed.
There are three model roles. The agent model produces responses, the evaluation model judges them when model-based scoring is used, and the optimization model proposes changes. For a first run, keep the agent model fixed. If the result changes, it’s easier to tell whether the revised instructions helped.
Choose criteria that help diagnose failures
A convincing answer doesn’t tell you whether the agent used the right tool, supplied the right arguments, or handled a failed lookup correctly. Score those steps separately when they matter. Use deterministic checks for things that can be verified exactly, such as required fields or tool arguments. Use a model-based evaluator when the criterion requires judgment, such as whether an answer distinguishes confirmed facts from speculation.
Foundry’s built-in agent evaluators cover behaviors such as tool selection and input accuracy. A custom quality rubric lets you define criteria specific to the agent. If a score is surprising, read the evaluator’s explanation alongside the response or trace. An ambiguous instruction, a bad tool call, and a backend error need different fixes.
Optimization jobs can invoke tools even though they run outside live traffic. If those tools can modify data, use read-only permissions or isolated test systems.
Prompt agent: run it in the Foundry portal
The demo agent turns short synthetic notes into a brief with three headings: Facts, Unknowns, and Next check. The baseline specified the format but didn’t say what to do when the notes contradicted each other or didn’t support a conclusion.
The run used 12 cases for tuning and held back six for a separate evaluation. A single quality rubric scored fidelity to the notes, handling of uncertainty, the usefulness of the next check, and clarity.
In the Foundry portal, open Build → Agents, select the agent, and go to Optimize → Create optimization run.
- Target: Select the baseline version, evaluation model, optimization model, and candidate count. The demo used v2 as the baseline, gpt-5-mini as both agent and judge, and gpt-5.4 to generate two candidates. The agent had no tools, and cross-model comparison was off.
- Dataset: Upload or select the tuning dataset. The wizard doesn’t map columns, so check that the dataset has the inputs the evaluator expects.
- Criteria: Select the quality rubric.
- Review: Confirm the settings and submit the run.
Read the results and inspect the prompt
Candidate 1 scored 0.859 on the tuning run. The baseline scored 0.757, and Candidate 2 scored 0.820. That made Candidate 1 the first one to inspect.
The prompt diff shows what the score alone can’t. Candidate 1 instructed the agent to preserve conflicting evidence, say when the notes didn’t establish a cause, and suggest one specific verification step rather than a list of possible follow-ups. The original prompt had left those decisions to the model. The model itself stayed the same.
Test the candidate on cases the optimizer didn’t see
Baseline v2 was evaluated on the six holdout cases in a regular Foundry agent evaluation. Candidate 1 was then promoted to v3 of the test agent and evaluated on the same six cases with the same rubric. Neither holdout run was part of the optimization job.
The revised agent passed three more cases in this demo. Six cases aren’t enough to establish production performance, but the comparison shows that the improvement wasn’t limited to the tuning set. One case still failed. Its response and the evaluator’s explanation are the best place to start before changing the instructions again.
Hosted agent: optimize with the Azure Developer CLI
Hosted agents use the same optimization loop, but the application code loads the configuration. An optimizer-ready hosted agent can load its baseline configuration normally and use a candidate configuration during an optimization run. That lets the optimizer test changes without rewriting the application.
The Microsoft Learn hosted-agent quickstart covers the setup: deploy an optimizer-ready agent, register the dataset and evaluators, and create a turn-level agent evaluation named optimize-check. The commands below use that setup. The measured results earlier in this article are from the prompt-agent walkthrough.
First, measure the deployed baseline:
azd ai eval run start --eval optimize-check --name baseline --wait
Then run the optimizer using the same evaluation definition. Replace the placeholders with the model deployment names from your Foundry project.
azd ai agent optimize \
--eval optimize-check \
--max-candidates 2 \
--eval-model <eval-deployment> \
--optimize-model <optimization-deployment>
The results show how each candidate scored and which parts of the configuration changed. Apply the selected candidate locally, review the diff, and deploy it to the test environment. Then rerun optimize-check:
azd ai agent optimize apply --candidate <candidate-id>
azd deploy
azd ai eval run start --eval optimize-check --name optimized --wait
The last command measures the deployed candidate. Because it reuses the evaluation that supplied the tuning data, it doesn’t test unseen inputs. To check whether the improvement carries over, compare the baseline and candidate on a separate holdout dataset, as in the prompt-agent walkthrough.
Where Foundry Insights fits
At Microsoft Ignite 2026, Foundry Insights and multi-turn evaluation reached general availability. Agent Optimizer was already generally available.
In the portal demo, the tuning run identified which prompt to inspect. The diff showed what changed, and the holdout showed where the change helped: the revised agent passed five of six cases, compared with two for the baseline. One case still failed. That response and the evaluator’s explanation give the next round of work a concrete starting point.
Published Dec 01, 2026
Version 1.0SriAishwaryaMasina
Microsoft
Joined November 16, 2026
Microsoft Foundry Blog
Follow this blog board to get notified when there's new activity