You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/ai-foundry/how-to/develop/agent-evaluate-sdk.md
+47-25Lines changed: 47 additions & 25 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -24,7 +24,10 @@ AI Agents are powerful productivity assistants to create workflows for business
24
24

25
25
26
26
27
-
Triggered by a user query about “weather tomorrow”, the agentic workflow may include multiple steps, such as reasoning through user intents, tool calling, and utilizing retrieval-augmented generation to produce a final response. In this process, assessing the quality and safety of each step — along with the final output of an agentic workflow — is crucial.
27
+
Triggered by a user query about “weather tomorrow”, the agentic workflow may include multiple steps, such as reasoning through user intents, tool calling, and utilizing retrieval-augmented generation to produce a final response. In this process, evaluating each steps of the workflow — along with the quality and safety of the final output — is crucial. Specifically, we formulate these steps into the following evaluators for agents:
28
+
-[Intent resolution](https://aka.ms/intentresolution-sample): Measures how well the agent identifies the user’s request, including how well it scopes the user’s intent, asks clarifying questions, and reminds end users of its scope of capabilities.
29
+
-[Tool call accuracy](https://aka.ms/toolcallaccuracy-sample): Evaluates the agent’s ability to select the appropriate tools, and process correct parameters from previous steps.
30
+
-[Task adherence](https://aka.ms/taskadherence-sample): Measures how well the agent’s response adheres to its assigned tasks, according to its system message and prior steps.
28
31
29
32
In this article, you learn how to run built-in evaluators locally on simple agent data as well as agent messages with built-in evaluators to thoroughly assess the performance of your AI agents.
Our built-in evaluators can accept simple data types such as strings in `query`, `response`, `ground_truth`as with the [single-turn data input requirements](./evaluate-sdk.md#data-requirements-for-built-in-evaluators). However, to extract simple data from agent messages can be a formidable challenge, due to its complex interaction patterns. For example, as mentioned, a single user query can trigger a long list of agent messages, typically with tool calls invoked.
46
+
Agents typically emit messages to interact with a user or other agents. Our built-in evaluators can accept simple data types such as strings in `query`, `response`, `ground_truth`according to the [single-turn data input requirements](./evaluate-sdk.md#data-requirements-for-built-in-evaluators). However, to extract simple data from agent messages can be a challenge, due to its complex interaction patterns. For example, as mentioned, a single user query can trigger a long list of agent messages, typically with multiple tool calls invoked.
44
47
45
-
Therefore, we have specifically enabled agent message suport for these built-in evaluators:
48
+
As illustrated in the example, we have enabled agent message suport specifically for these built-in evaluators to evaluate these aspects of agentic workflow. These evaluators take `tool_calls` or `tool_definitions` as parameters as they are unique to agents.
-`Messages`: `dict` of openai-style messages describing agent interactions with a user
54
-
-`ToolCall`: `dict` specifying tool calls invoked during agent interactions with a user
55
-
-`ToolDefinition`: `dict` describing the tools available to an agent
56
+
-`Message`: `dict` openai-style message describing agent interactions with a user, where `query` must include a system message as the first message.
57
+
-`ToolCall`: `dict` specifying tool calls invoked during agent interactions with a user.
58
+
-`ToolDefinition`: `dict` describing the tools available to an agent.
59
+
60
+
For `ToolCallAccuracyEvaluator`, either `response` or `tool_calls` must be provided. See examples below to showcase the two data formats: simple agent data, and agent messages. However, due to the unique requirements of these evaluators, we recommend referring to the [sample notebooks](#sample-notebooks) which illustrate the possible input paths for each one.
61
+
62
+
As with other [built-in AI-assisted quality evaluators](#performance-and-quality-evaluators), `IntentResolutionEvaluator` and `TaskAdherenceEvaluator` output a likert score (integer 1-5) where the higher score is better the result. `ToolCallAccuracyEvaluator` output the passing rate of all tool calls made (a float between 0-1) based on user query. To further improve intelligibility, all evaluators accept a binary threshold and output two new keys. For the binarization threshold, a default is set and user can override it. The two new keys are:
63
+
64
+
-`{metric_name}_result` a "pass" or "fail" string based on a binarization threshold.
65
+
-`{metric_name}_threshold` a numerical binarization threshold set by default or by the user
56
66
57
-
For `ToolCallAccuracyEvaluator`, either `response` or `tool_calls` must be provided. See examples below to showcase the two data formats: simple agent data, and agent messages.
58
-
59
67
60
68
61
69
#### Simple agent data
@@ -66,7 +74,7 @@ In simple agent data format, `query` and `response` are simple python strings. F
66
74
import os
67
75
from azure.ai.evaluation import AzureOpenAIModelConfiguration
68
76
from azure.identity import DefaultAzureCredential
69
-
from azure.ai.evaluation import IntentResolutionEvaluator
77
+
from azure.ai.evaluation import IntentResolutionEvaluator, ResponseCompletenessEvaluator
# A successful example. Intent is identified and understood and the response correctly resolves user intent
91
+
# A positive example. Intent is identified and understood and the response correctly resolves user intent
83
92
result = intent_resolution_evaluator(
84
93
query="What are the opening hours of the Eiffel Tower?",
85
94
response="Opening hours of the Eiffel Tower are 9:00 AM to 11:00 PM.",
86
95
)
87
96
print(result)
97
+
98
+
# A negative example. Only half of the statements in the response were complete according to the ground truth
99
+
result = completeness_evaluator(
100
+
response="Itinery: Day 1 take a train to visit Disneyland outside of the city; Day 2 rests in hotel.",
101
+
ground_truth="Itinery: Day 1 take a train to visit the downtown area for city sightseeing; Day 2 rests in hotel."
102
+
)
103
+
print(result)
104
+
88
105
```
89
106
90
-
Tool calls are typically made within the agent response messages, you can also extract them in this format:
107
+
Examples of `tool_calls` and `tool_definitions` for `ToolCallAccuracyEvaluator`:
91
108
92
109
```python
93
-
query ="How is the weather in Seattle?"
110
+
query ="How is the weather in Seattle?"
94
111
tool_calls = [{
95
112
"type": "tool_call",
96
113
"tool_call_id": "call_CUdbkBfvVBla2YP3p24uhElJ",
@@ -127,14 +144,17 @@ print(response)
127
144
128
145
#### Agent messages
129
146
130
-
In agent message format, `query` and `response` are list of openai-style messages. Specifically, `query` requires the system message (of the agent) on top of the list:
147
+
In agent message format, `query` and `response` are list of openai-style messages. Specifically, `query` carry the past agent-user interactions leading up to the last user query and requires the system message (of the agent) on top of the list; and `response` will carry the last message of the agent in response to the last user query. Example:
148
+
131
149
```python
132
150
# user asked a question
133
151
query = [
134
152
{
135
153
"role": "system",
136
154
"content": "You are a friendly and helpful customer service agent."
137
155
},
156
+
# past interactions omitted
157
+
# ...
138
158
{
139
159
"createdAt": "2025-03-14T06:14:20Z",
140
160
"role": "user",
@@ -174,7 +194,8 @@ response = [
174
194
}
175
195
]
176
196
},
177
-
...
197
+
# many more messages omitted
198
+
# ...
178
199
# here is the agent's final response
179
200
{
180
201
"createdAt": "2025-03-14T06:15:05Z",
@@ -204,7 +225,8 @@ tool_definitions = [
204
225
}
205
226
}
206
227
},
207
-
...
228
+
# other tool definitions omitted
229
+
# ...
208
230
]
209
231
210
232
result = intent_resolution_evaluator(
@@ -215,14 +237,12 @@ result = intent_resolution_evaluator(
215
237
)
216
238
print(result)
217
239
218
-
219
240
```
220
241
221
242
222
243
#### Converter support
223
244
224
-
225
-
If you use [Azure AI Agent Service](https://learn.microsoft.com/azure/ai-services/agents/overview), you can seamlessly evaluate your agents via our converter support for Azure AI agent threads and runs. To create an Azure AI agent and some data, you need:
245
+
Transforming agent messages into the right evaluation data to use our evaluators can be a non-trivial task. If you use [Azure AI Agent Service](https://learn.microsoft.com/azure/ai-services/agents/overview), however, you can seamlessly evaluate your agents via our converter support for Azure AI agent threads and runs. Here is an example to create an Azure AI agent and some data for evaluation:
226
246
227
247
```bash
228
248
pip install azure-ai-projects azure-identity
@@ -238,7 +258,6 @@ from azure.ai.projects.models import FunctionTool, ToolSet
238
258
239
259
from dotenv import load_dotenv
240
260
241
-
242
261
load_dotenv()
243
262
244
263
# Define some custom python function
@@ -316,7 +335,7 @@ for message in project_client.agents.list_messages(thread.id, order="asc").data:
316
335
317
336
##### Convert agent runs (single-run)
318
337
319
-
Now you use our converter to transform the agent thread or run data, into required evaluation data that the evaluators can understand.
338
+
Now you use our converter to transform the Azure AI agent thread or run data into required evaluation data that the evaluators can understand.
320
339
```python
321
340
import json
322
341
from azure.ai.evaluation import AIAgentConverter
@@ -350,12 +369,15 @@ print(f"Evaluation data saved to {filename}")
350
369
351
370
#### Batch evaluation on agent thread data
352
371
353
-
Select the evaluators to assess the agent quality (for example, intent resolution, tool call accuracy, and task adherence), and submit a batch
372
+
With the evaluation data prepared in one line of code, you can simply select the evaluators to assess the agent quality (for example, intent resolution, tool call accuracy, and task adherence), and submit a batch evaluation run:
354
373
```python
355
374
from azure.ai.evaluation import IntentResolutionEvaluator, TaskAdherenceEvaluator, ToolCallAccuracyEvaluator
356
375
from azure.ai.projects.models import ConnectionType
Copy file name to clipboardExpand all lines: articles/ai-foundry/how-to/develop/evaluate-sdk.md
+9-2Lines changed: 9 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -292,10 +292,17 @@ For
292
292
293
293
The result of the AI-assisted quality evaluators for a query and response pair is a dictionary containing:
294
294
295
-
-`{metric_name}` provides a numerical score.
296
-
-`{metric_name}_label` provides a binary label.
295
+
-`{metric_name}` provides a numerical score, on a likert scale (integer 1 to 5) or a float between 0-1.
296
+
-`{metric_name}_label` provides a binary label (if the metric outputs a binary score naturally).
297
297
-`{metric_name}_reason` explains why a certain score or label was given for each data point.
298
298
299
+
To further improve intelligibility, all evaluators accept a binary threshold and output two new keys. For the binarization threshold, a default is set and user can override it. The two new keys are:
300
+
301
+
-`{metric_name}_result` a "pass" or "fail" string based on a binarization threshold.
302
+
-`{metric_name}_threshold` a numerical binarization threshold set by default or by the user
303
+
304
+
305
+
299
306
#### Comparing quality and custom evaluators
300
307
301
308
For NLP evaluators, only a score is given in the `{metric_name}` key.
0 commit comments