你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn

代理计算器(预览版)

Important

本文中标记了“(预览版)”的项目目前为公共预览版。 此预览版未提供服务级别协议,不建议将其用于生产工作负载。 某些功能可能不受支持或者受限。 有关详细信息,请参阅 Microsoft Azure 预览版补充使用条款

代理是强大的生产力助手。 他们可以计划、做出决策和执行作。 代理通常 通过对话中的用户意向进行第一个原因, 选择正确的工具来 调用和满足用户请求,并根据他们的说明 完成各种任务 。 Azure AI Foundry 目前为代理工作流支持这些特定于代理的计算器:

评估 Azure AI 代理

代理发出消息。 提供输入通常需要分析消息并提取相关信息。 如果要使用 Azure AI 代理服务生成代理,该服务会提供本机集成,用于直接获取代理消息的评估。 有关示例,请参阅 评估 AI 代理

IntentResolution此外,ToolCallAccuracyTaskAdherence特定于代理工作流,还可以使用一套全面的内置评估程序来评估代理工作流的其他质量和安全方面。 Azure AI Foundry 支持转换器提供的 Azure AI 代理消息评估程序列表:

  • 质量IntentResolution、、ToolCallAccuracyTaskAdherenceRelevanceCoherenceFluency
  • 安全性CodeVulnerabilities、、ViolenceSexualSelf-harmHateUnfairnessIndirectAttackProtectedMaterials

本文演示IntentResolution示例和 ToolCallAccuracyTaskAdherence。 有关将其他评估程序用于 Azure AI 代理消息的示例,请参阅 评估 Azure AI 代理

AI 辅助评估器的模型配置

为了参考以下代码片段,AI 辅助评估程序对大型语言模型判断(LLM-judge)使用模型配置:

import os
from azure.ai.evaluation import AzureOpenAIModelConfiguration
from dotenv import load_dotenv
load_dotenv()

model_config = AzureOpenAIModelConfiguration(
    azure_endpoint=os.environ["AZURE_ENDPOINT"],
    api_key=os.environ.get("AZURE_API_KEY"),
    azure_deployment=os.environ.get("AZURE_DEPLOYMENT_NAME"),
    api_version=os.environ.get("AZURE_API_VERSION"),
)

计算器模型支持

Azure AI 代理服务支持 LLM 判断的 AzureOpenAI 或 OpenAI 推理模型 和非推理模型,具体取决于评估者:

Evaluators 推理模型作为法官 (示例:Azure OpenAI /OpenAI 中的 o 系列模型) 非推理模型作为法官 (例如: gpt-4.1 或 gpt-4o) 若要为
Intent ResolutionTask AdherenceTool Call AccuracyResponse Completeness Supported Supported 在初始化计算器时设置其他参数is_reasoning_model=True
其他质量评估程序 不支持 Supported --

对于需要优化推理的复杂评估,我们建议使用具有推理性能和成本效益的平衡的强推理模型,例如 o3-mini 之后发布的 o 系列微型模型。

意向解析

IntentResolutionEvaluator 测量系统识别和理解用户请求的方式。 此理解包括它如何限定用户的意图范围、提出问题以澄清和提醒最终用户其功能范围。 更高的分数意味着更好地识别用户意向。

意向解析示例

from azure.ai.evaluation import IntentResolutionEvaluator

intent_resolution = IntentResolutionEvaluator(model_config=model_config, threshold=3)
intent_resolution(
    query="What are the opening hours of the Eiffel Tower?",
    response="Opening hours of the Eiffel Tower are 9:00 AM to 11:00 PM."
)

意向解析输出

数值分数以 Likert 刻度(整数 1 到 5)表示。 分数越高越好。 给定数值阈值(默认值为 3),如果评分 >= 阈值或失败,计算器也会输出传递。 使用原因和其他字段可帮助你了解分数高或低的原因。

{
    "intent_resolution": 5.0,
    "intent_resolution_result": "pass",
    "intent_resolution_threshold": 3,
    "intent_resolution_reason": "The response provides the opening hours of the Eiffel Tower clearly and accurately, directly addressing the user's query. It includes specific times, which fully resolves the user's request for information about the opening hours.",
    "additional_details": {
        "conversation_has_intent": True,
        "agent_perceived_intent": "inquire about opening hours",
        "actual_user_intent": "find out the opening hours of the Eiffel Tower",
        "correct_intent_detected": True,
        "intent_resolved": True
    }
}

如果要在 Azure AI Foundry 代理服务外部生成代理,此评估程序接受代理消息的典型架构。 有关示例笔记本,请参阅 意向解析

工具调用准确性

ToolCallAccuracyEvaluator 度量运行中代理发出的工具调用的准确性和效率。 它提供基于 1-5 的分数:

  • 调用的工具的相关性和帮助性
  • 工具调用中使用的参数的正确性
  • 缺失或过多调用的计数

工具调用评估支持

ToolCallAccuracyEvaluator 支持在 Azure AI Foundry 代理服务中评估以下工具:

  • 文件搜索
  • Azure AI 搜索
  • 必应地面
  • 必应自定义搜索
  • SharePoint 地面
  • 代码解释器
  • Fabric 数据代理
  • OpenAPI
  • 函数工具(用户定义的工具)

如果在代理运行中使用了不支持的工具,则计算器会输出 一个传递 ,并且不支持评估调用的工具的原因。 此方法可以轻松筛选掉这些情况。 建议将不支持的工具包装为用户定义的工具以启用评估。

工具调用准确性示例

from azure.ai.evaluation import ToolCallAccuracyEvaluator

tool_call_accuracy = ToolCallAccuracyEvaluator(model_config=model_config, threshold=3)

# provide the agent response with tool calls 
tool_call_accuracy(
    query="What timezone corresponds to 41.8781,-87.6298?",
    response=[
    {
        "createdAt": "2025-04-25T23:55:52Z",
        "run_id": "run_DmnhUGqYd1vCBolcjjODVitB",
        "role": "assistant",
        "content": [
            {
                "type": "tool_call",
                "tool_call_id": "call_qi2ug31JqzDuLy7zF5uiMbGU",
                "name": "azure_maps_timezone",
                "arguments": {
                    "lat": 41.878100000000003,
                    "lon": -87.629800000000003
                }
            }
        ]
    },    
    {
        "createdAt": "2025-04-25T23:55:54Z",
        "run_id": "run_DmnhUGqYd1vCBolcjjODVitB",
        "tool_call_id": "call_qi2ug31JqzDuLy7zF5uiMbGU",
        "role": "tool",
        "content": [
            {
                "type": "tool_result",
                "tool_result": {
                    "ianaId": "America/Chicago",
                    "utcOffset": None,
                    "abbreviation": None,
                    "isDaylightSavingTime": None
                }
            }
        ]
    },
    {
        "createdAt": "2025-04-25T23:55:55Z",
        "run_id": "run_DmnhUGqYd1vCBolcjjODVitB",
        "role": "assistant",
        "content": [
            {
                "type": "text",
                "text": "The timezone for the coordinates 41.8781, -87.6298 is America/Chicago."
            }
        ]
    }
    ],   
    tool_definitions=[
                {
                    "name": "azure_maps_timezone",
                    "description": "local time zone information for a given latitude and longitude.",
                    "parameters": {
                        "type": "object",
                        "properties": {
                            "lat": {
                                "type": "float",
                                "description": "The latitude of the location."
                            },
                            "lon": {
                                "type": "float",
                                "description": "The longitude of the location."
                            }
                        }
                    }
                }
    ]
)

# alternatively, provide the tool calls directly without the full agent response
tool_call_accuracy(
    query="How is the weather in Seattle?",
    tool_calls=[{
                    "type": "tool_call",
                    "tool_call_id": "call_CUdbkBfvVBla2YP3p24uhElJ",
                    "name": "fetch_weather",
                    "arguments": {
                        "location": "Seattle"
                    }
                }],
    tool_definitions=[{
                    "id": "fetch_weather",
                    "name": "fetch_weather",
                    "description": "Fetches the weather information for the specified location.",
                    "parameters": {
                        "type": "object",
                        "properties": {
                            "location": {
                                "type": "string",
                                "description": "The location to fetch weather for."
                            }
                        }
                    }
                }
    ]
)

工具调用准确性输出

数值分数以 Likert 刻度(整数 1 到 5)表示。 分数越高越好。 给定数值阈值(默认值为 3),如果评分 >= 阈值或失败,计算器也会输出传递。 使用原因和工具调用详细信息字段来了解分数高或低的原因。

{
    "tool_call_accuracy": 5,
    "tool_call_accuracy_result": "pass",
    "tool_call_accuracy_threshold": 3,
    "details": {
        "tool_calls_made_by_agent": 1,
        "correct_tool_calls_made_by_agent": 1,
        "per_tool_call_details": [
            {
                "tool_name": "fetch_weather",
                "total_calls_required": 1,
                "correct_calls_made_by_agent": 1,
                "correct_tool_percentage": 1.0,
                "tool_call_errors": 0,
                "tool_success_result": "pass"
            }
        ],
        "excess_tool_calls": {
            "total": 0,
            "details": []
        },
        "missing_tool_calls": {
            "total": 0,
            "details": []
        }
    }
}

如果要在 Azure AI 代理服务外部生成代理,此评估程序接受代理消息的典型架构。 有关示例笔记本,请参阅 工具调用准确性

任务符合性

在各种面向任务的 AI 系统(如代理系统)中,请务必评估代理是否能够继续完成任务,而不是执行效率低下或范围外的步骤。 TaskAdherenceEvaluator 根据代理的任务说明和可用工具衡量代理响应遵守其分配的任务的方式。 任务指令是从系统消息和用户查询中提取的。 更高的分数意味着更好地遵守系统指令来解决任务。

任务符合性示例

from azure.ai.evaluation import TaskAdherenceEvaluator

task_adherence = TaskAdherenceEvaluator(model_config=model_config, threshold=3)
task_adherence(
        query="What are the best practices for maintaining a healthy rose garden during the summer?",
        response="Make sure to water your roses regularly and trim them occasionally."                         
)

任务符合性输出

数值分数以 Likert 刻度(整数 1 到 5)表示。 分数越高越好。 给定数值阈值(默认值为 3),如果评分 >= 阈值或失败,计算器也会输出传递。 使用原因字段了解分数高或低的原因。

{
   "task_adherence": 2.0,
    "task_adherence_result": "fail",
    "task_adherence_threshold": 3,
    "task_adherence_reason": "The response partially addresses the query by mentioning relevant practices but lacks critical details and depth, making it insufficient for a comprehensive understanding of maintaining a rose garden in summer."
}

如果要在 Azure AI 代理服务外部生成代理,此评估程序接受代理消息的典型架构。 有关示例笔记本,请参阅 任务遵循