跳到主内容
@wquguru
精选88Microsoft Foundry 博客(RSS)技巧与观点

微软Foundry Agent Optimizer实操:从评估到优化

Agent Optimizer in Microsoft Foundry: From Evaluation to a Better Agent

原文
发到 X
推荐理由

Agent 调优是落地痛点,这篇提供了从 Portal 到 CLI 的完整可复用工作流和参数细节,做 Agent 的同学可以直接照着压测自己的链路。

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.

Microsoft Foundry 中的 Agent Optimizer(代理优化器)有助于发现值得测试的更改。它评估基线、提出替代配置并比较结果。本文解释了优化器的工作原理,逐步演示了在 Foundry 门户中运行代理的过程,并展示了如何使用 Azure Developer CLI 为托管代理运行相同的工作流。

What Agent Optimizer can change

Agent Optimizer 可以更改的内容

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 Optimizer 更改的是代理配置,而非模型权重。它可以更改的内容取决于代理类型以及优化作业可用的配置部分。

Agent typeWhat can be optimizedHow to start
Prompt agentInstructions, function-calling tool descriptions, and model selectionUse the Optimize tab in the Foundry portal. This workflow supports prompt agents without the Microsoft Copilot harness.
Hosted agentInstructions, existing skills, function-calling tool descriptions, and model selectionMake the agent optimizer-ready, then run it with azd. The Foundry Toolkit for VS Code can scaffold the integration.
代理类型可优化的内容启动方式
提示词代理指令、函数调用工具描述和模型选择在 Foundry 门户中使用“Optimize”选项卡。此工作流支持不带 Microsoft Copilot harness 的提示词代理。
托管代理指令、现有技能、函数调用工具描述和模型选择使代理准备好接受优化器处理,然后使用 azd 运行它。Foundry Toolkit for VS Code 可以生成集成脚手架。

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.

优化器运行基线、对其响应进行评分、生成替代配置,并评估这些候选方案。Foundry 使用 0–1 尺度上的综合得分对结果进行排名。该得分有助于决定首先检查哪个候选方案;它并不代表通过用例的百分比。

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.

Foundry 内置的代理评估器涵盖工具选择和输入准确性等行为。自定义质量评分表允许你定义针对特定代理的标准。如果得分出乎意料,请结合回复或追踪记录阅读评估器的解释。模糊的指令、错误的工具调用和后端错误需要不同的修复方案。

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

提示代理:在 Foundry 门户中运行

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.

演示代理将简短的合成笔记转换为包含三个标题的简报:Facts(事实)、Unknowns(未知)和 Next check(下一步检查)。基线指定了格式,但未说明当笔记相互矛盾或不支持结论时应如何处理。

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.

该运行使用 12 个案例进行调优,并保留另外六个案例用于独立评估。单一的质量评分表对以下方面进行评分:对笔记的忠实度、对不确定性的处理、下一步检查的有用性以及清晰度。

In the Foundry portal, open Build → Agents, select the agent, and go to Optimize → Create optimization run.

在 Foundry 门户中,打开 Build → Agents(构建 → 代理),选择代理,然后进入 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.
  • 目标:选择基线版本、评估模型、优化模型和候选数量。演示中使用了 v2 作为基线,gpt-5-mini 同时作为代理和裁判,并使用 gpt-5.4 生成两个候选项。代理未配置任何工具,且关闭了跨模型比较功能。
  • 数据集:上传或选择调优数据集。向导不会自动映射列,因此请确保数据集包含评估器所期望的输入内容。
  • 标准:选择质量评分表。
  • 审查:确认设置并提交运行。

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.

候选 1 在调优运行中得分为 0.859。基线得分为 0.757,候选 2 得分为 0.820。因此,候选 1 成为第一个需要检查的对象。

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.

提示词差异(prompt diff)展示了仅凭分数无法体现的内容。候选 1 指示代理保留相互矛盾的证据(例如当笔记未能确立因果关系时),并建议一个具体的验证步骤,而不是一系列可能的后续操作。原始提示词将这些决策留给了模型。模型本身保持不变。

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.

基线 v2 在常规 Foundry 代理评估中对六个保留案例进行了评估。随后,候选 1 被提升为测试代理的 v3 版本,并使用相同的评分标准对相同的六个案例进行评估。这两次保留案例的运行均不属于优化作业的一部分。

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

托管代理:使用 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.

Microsoft Learn 托管代理快速入门涵盖了设置步骤:部署一个准备好优化的代理、注册数据集和评估器,并创建一个名为 optimize-check 的逐轮代理评估。以下命令使用该设置。本文前面部分测量的结果来自 prompt-agent 演练。

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.

然后使用相同的评估定义运行优化器。将占位符替换为你 Foundry 项目中的模型部署名称。

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:

结果显示了每个候选方案的得分以及配置中发生更改的部分。在本地应用所选候选方案,审查差异(diff),并将其部署到测试环境。然后重新运行 optimize-check:

azd ai agent optimize apply --candidate <candidate-id> azd deploy azd ai eval run start --eval optimize-check --name optimized --wait

azd ai agent optimize apply --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

Foundry Insights 的应用场景

At Microsoft Ignite 2026, Foundry Insights and multi-turn evaluation reached general availability. Agent Optimizer was already generally available.

在 Microsoft Ignite 2026 大会上,Foundry Insights 和多轮评估功能正式进入通用可用阶段(GA)。Agent Optimizer 此前已处于通用可用状态。

更进一步:量化金融体系

看懂新闻只是起点——沿量化金融路径,把它变成能交付的工程能力

进入量化体系 →

相似阅读

关联信息,但可能不是同一事件