-
Notifications
You must be signed in to change notification settings - Fork 834
Introduce evaluators for agentic workflows #6514
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
shyamnamboodiripad
merged 15 commits into
dotnet:main
from
shyamnamboodiripad:agentevals
Jun 13, 2025
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
01bbf46
Fix a regex bug
shyamnamboodiripad 6eade5b
Update some diagnostic messages
shyamnamboodiripad b051881
Report a diagnostic if no context chunks are supplied when invoking R…
shyamnamboodiripad cd0a2fd
Introduce ToolCallAccuracyEvaluator
shyamnamboodiripad f554de0
Add support for displaying tool calls and other json based content in…
shyamnamboodiripad 043df3e
Add tests
shyamnamboodiripad 82dd782
Remove SemanticKernel tests
shyamnamboodiripad 1c4f5c8
Introduce TaskAdherenceEvaluator
shyamnamboodiripad 3f37c9e
Update tests
shyamnamboodiripad 0d832ff
Make tool definitions more complete
shyamnamboodiripad 093d2e1
Simplify serialization to JsonNode
shyamnamboodiripad eb33b31
Introduce IntentResolutionEvaluator
shyamnamboodiripad fd908ed
Add more tests
shyamnamboodiripad ac33a87
Improve validation for inputs
shyamnamboodiripad cf1717f
Add missing context
shyamnamboodiripad File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
src/Libraries/Microsoft.Extensions.AI.Evaluation.Quality/AIToolExtensions.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text.Json; | ||
using System.Text.Json.Nodes; | ||
using Microsoft.Shared.Diagnostics; | ||
|
||
namespace Microsoft.Extensions.AI.Evaluation.Quality; | ||
|
||
internal static class AIToolExtensions | ||
{ | ||
internal static string RenderAsJson( | ||
this IEnumerable<AITool> toolDefinitions, | ||
JsonSerializerOptions? options = null) | ||
{ | ||
_ = Throw.IfNull(toolDefinitions); | ||
|
||
var toolDefinitionsJsonArray = new JsonArray(); | ||
|
||
foreach (AIFunction function in toolDefinitions.OfType<AIFunction>()) | ||
{ | ||
JsonNode functionJsonNode = | ||
new JsonObject | ||
{ | ||
["name"] = function.Name, | ||
["description"] = function.Description, | ||
["functionSchema"] = JsonNode.Parse(function.JsonSchema.GetRawText()), | ||
}; | ||
|
||
if (function.ReturnJsonSchema is not null) | ||
{ | ||
functionJsonNode["functionReturnValueSchema"] = | ||
JsonNode.Parse(function.ReturnJsonSchema.Value.GetRawText()); | ||
} | ||
|
||
toolDefinitionsJsonArray.Add(functionJsonNode); | ||
} | ||
|
||
string renderedToolDefinitions = toolDefinitionsJsonArray.ToJsonString(options); | ||
return renderedToolDefinitions; | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
src/Libraries/Microsoft.Extensions.AI.Evaluation.Quality/ChatMessageExtensions.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System.Collections.Generic; | ||
using System.Text.Json; | ||
using System.Text.Json.Nodes; | ||
using Microsoft.Shared.Diagnostics; | ||
|
||
namespace Microsoft.Extensions.AI.Evaluation.Quality; | ||
|
||
internal static class ChatMessageExtensions | ||
{ | ||
internal static string RenderAsJson(this IEnumerable<ChatMessage> messages, JsonSerializerOptions? options = null) | ||
{ | ||
_ = Throw.IfNull(messages); | ||
|
||
var messagesJsonArray = new JsonArray(); | ||
|
||
foreach (ChatMessage message in messages) | ||
{ | ||
JsonNode? messageJsonNode = | ||
JsonSerializer.SerializeToNode( | ||
message, | ||
AIJsonUtilities.DefaultOptions.GetTypeInfo(typeof(ChatMessage))); | ||
|
||
if (messageJsonNode is not null) | ||
{ | ||
messagesJsonArray.Add(messageJsonNode); | ||
} | ||
} | ||
|
||
string renderedMessages = messagesJsonArray.ToJsonString(options); | ||
return renderedMessages; | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
src/Libraries/Microsoft.Extensions.AI.Evaluation.Quality/ChatResponseExtensions.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System; | ||
using System.Linq; | ||
using System.Text.Json; | ||
using System.Text.Json.Nodes; | ||
using Microsoft.Shared.Diagnostics; | ||
|
||
namespace Microsoft.Extensions.AI.Evaluation.Quality; | ||
|
||
internal static class ChatResponseExtensions | ||
{ | ||
internal static string RenderAsJson(this ChatResponse modelResponse, JsonSerializerOptions? options = null) | ||
{ | ||
_ = Throw.IfNull(modelResponse); | ||
|
||
return modelResponse.Messages.RenderAsJson(options); | ||
} | ||
|
||
internal static string RenderToolCallsAndResultsAsJson( | ||
this ChatResponse modelResponse, | ||
JsonSerializerOptions? options = null) | ||
{ | ||
_ = Throw.IfNull(modelResponse); | ||
|
||
var toolCallsAndResultsJsonArray = new JsonArray(); | ||
|
||
foreach (AIContent content in modelResponse.Messages.SelectMany(m => m.Contents)) | ||
{ | ||
if (content is FunctionCallContent or FunctionResultContent) | ||
{ | ||
Type contentType = | ||
content is FunctionCallContent ? typeof(FunctionCallContent) : typeof(FunctionResultContent); | ||
|
||
JsonNode? toolCallOrResultJsonNode = | ||
JsonSerializer.SerializeToNode( | ||
content, | ||
AIJsonUtilities.DefaultOptions.GetTypeInfo(contentType)); | ||
|
||
if (toolCallOrResultJsonNode is not null) | ||
{ | ||
toolCallsAndResultsJsonArray.Add(toolCallOrResultJsonNode); | ||
} | ||
} | ||
} | ||
|
||
string renderedToolCallsAndResults = toolCallsAndResultsJsonArray.ToJsonString(options); | ||
return renderedToolCallsAndResults; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.