代理计算器(预览版)

重要

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

代理是强大的生产力助手。 他们可以计划、做出决策和执行作。 代理通常 通过对话中的用户意向进行第一个原因, 选择正确的工具来 调用和满足用户请求,并根据他们的说明 完成各种任务

评估 Azure AI 代理

代理发出消息,并提供上述输入通常需要分析消息并提取相关信息。 如果要使用 Azure AI 代理服务生成代理,我们将提供本机集成,用于直接获取代理消息的评估。 若要了解详细信息,请参阅 Azure AI 代理服务中评估代理的端到端示例

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

  • 质量IntentResolution、、ToolCallAccuracyTaskAdherenceRelevanceCoherenceFluency
  • 安全CodeVulnerabilities、、ViolenceSelf-harmSexualHateUnfairnessIndirectAttack、。 ProtectedMaterials

我们将在此处演示示例IntentResolutionToolCallAccuracyTaskAdherence。 请参阅更多示例,了解如何使用 Azure AI 代理 消息支持为其他评估程序评估 Azure AI 代理。

AI 辅助评估器的模型配置

为了参考以下代码片段,AI 辅助计算器使用 LLM 法官的模型配置:

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"),
)

小窍门

我们建议使用 o3-mini 推理功能和成本效益的平衡。

意向解析

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."
)

意向解析输出

类似比例的数字分数(整数 1 到 5)和更高的分数更好。 给定数值阈值(默认值为 3),如果分数 <= 阈值,则我们还输出“pass”,否则将输出“fail”。 使用原因和其他字段可帮助你了解分数高或低的原因。

{
    "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 代理 Serice 外部生成代理,此评估程序接受代理消息的典型架构。 若要了解详细信息,请参阅我们的 意向解析示例笔记本。

工具调用准确性

ToolCallAccuracyEvaluator 度量代理从代理工作流的前面步骤中选择适当的工具、提取和处理正确参数的能力。 它会检测每个工具调用是否准确(以二进制方式),并报告平均得分,这可以解释为工具调用的通过率。

注释

ToolCallAccuracyEvaluator 仅支持 Azure AI 代理的函数工具评估,但不支持内置工具评估。 代理消息必须至少调用一个函数工具才能进行评估。

工具调用准确性示例

from azure.ai.evaluation import ToolCallAccuracyEvaluator

tool_call_accuracy = ToolCallAccuracyEvaluator(model_config=model_config, threshold=3)
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."
                            }
                        }
                    }
                }
    ]
)

工具调用准确性输出

数值分数(正确工具调用的传递速率)为 0-1,分数越高越好。 给定数值阈值(默认值为 3),如果分数 <= 阈值,则我们还输出“pass”,否则将输出“fail”。 使用原因和工具调用详细信息字段可帮助你了解分数高或低的原因。

{
    "tool_call_accuracy": 1.0,
    "tool_call_accuracy_result": "pass",
    "tool_call_accuracy_threshold": 0.8,
    "per_tool_call_details": [
        {
            "tool_call_accurate": True,
            "tool_call_accurate_reason": "The input Data should get a Score of 1 because the TOOL CALL is directly relevant to the user's question about the weather in Seattle, includes appropriate parameters that match the TOOL DEFINITION, and the parameter values are correct and relevant to the user's query.",
            "tool_call_id": "call_CUdbkBfvVBla2YP3p24uhElJ"
        }
    ]
}

如果要在 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."                         
)

任务符合性输出

类似比例的数字分数(整数 1 到 5)和更高的分数更好。 给定数值阈值(默认值为 3),如果分数 <= 阈值,则我们还输出“pass”,否则将输出“fail”。 使用原因字段可帮助你了解分数高或低的原因。

{
   "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 代理服务外部生成代理,此评估程序接受代理消息的典型架构。 若要了解详细信息,请参阅我们的 任务遵循示例笔记本。