mirror of
https://github.com/microsoft/agent-framework.git
synced 2026-06-16 21:04:09 +08:00
7a8b456294
* WIP * Wip * Updated ADR * Updated ADR * Update files * Address copilot comments * Update filters from Task<T> to Task only * Project endpoint * Add agent ctor filter * Other Agent Framework investigation * Remove SK Java, no support * Update LlamaIndex info * Removing unrelated files * Implementation with specialization * Remove the specialization option as extra unecessary complexity * Move middleware responsibility to a decorator * Update readme * Function invocation wip * Add Agent Builder * Adding comparison samples * Reorganize Samples and Processor vs Decorator * Remove merge files * Address formating warnigs * Update ADR * Step13 README's update * Address PR feedback * Address PR feedback * Remove configure await from ADR samples * Update variables * Address feedback * Address Agent level tool invocation with Options.ToolsTransformer strategy * Removing the Processor approach * Proposal design for Middleware in CreateAIAgent extensions * Examples clean up and consolitation * Update middlewares to work with ApprovalREquiredFunction * Clean-up sample * Update override function call sample * Drop configuration from the extensions, looks overkill * Builder interface .. * Revert IAIBuilder interface approach * Cleanup sample * Adding unit tests * Fix UT * Cleanup sample * Remove unneeded dependency * Address PR comment + Readme Samples * Add missing comments for Program.cs Middleware * Address mor PR comments + add client factory for OpenAI extensions * Add OpenAI UnitTests for extensions * Add AzureAI PersistentChatClient UT * Addess feedback * Add function invoking UT * Add builder extension UT * Address feedback + Rearange abstractions + UT fixes * Drop context based middleware for full decorating impl * Update unit tests * Update UT coverage * Removing Middelware namespace * Add missing UT * Remove internal ToolTransformation Property * Adjust xmldoc * Remove transient file * Address merge conflict * Add xmldoc remark for clarity * Address comment * Address feedback * Update UT --------- Co-authored-by: Chris <66376200+crickman@users.noreply.github.com>
147 lines
4.3 KiB
C#
147 lines
4.3 KiB
C#
// Copyright (c) Microsoft. All rights reserved.
|
|
|
|
using System;
|
|
using Microsoft.Extensions.Logging;
|
|
using Moq;
|
|
|
|
namespace Microsoft.Agents.AI.UnitTests;
|
|
|
|
/// <summary>
|
|
/// Unit tests for the <see cref="OpenTelemetryAIAgentBuilderExtensions"/> class.
|
|
/// </summary>
|
|
public class OpenTelemetryAIAgentBuilderExtensionsTests
|
|
{
|
|
/// <summary>
|
|
/// Verify that UseOpenTelemetry throws ArgumentNullException when builder is null.
|
|
/// </summary>
|
|
[Fact]
|
|
public void UseOpenTelemetry_WithNullBuilder_ThrowsArgumentNullException()
|
|
{
|
|
// Act & Assert
|
|
Assert.Throws<ArgumentNullException>("builder", () =>
|
|
OpenTelemetryAIAgentBuilderExtensions.UseOpenTelemetry(null!));
|
|
}
|
|
|
|
/// <summary>
|
|
/// Verify that UseOpenTelemetry returns an OpenTelemetryAgent.
|
|
/// </summary>
|
|
[Fact]
|
|
public void UseOpenTelemetry_WithValidBuilder_ReturnsOpenTelemetryAgent()
|
|
{
|
|
// Arrange
|
|
var mockAgent = new Mock<AIAgent>();
|
|
var builder = new AIAgentBuilder(mockAgent.Object);
|
|
|
|
// Act
|
|
var result = builder.UseOpenTelemetry().Build();
|
|
|
|
// Assert
|
|
Assert.IsType<OpenTelemetryAgent>(result);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Verify that UseOpenTelemetry with logger factory works correctly.
|
|
/// </summary>
|
|
[Fact]
|
|
public void UseOpenTelemetry_WithLoggerFactory_UsesProvidedLoggerFactory()
|
|
{
|
|
// Arrange
|
|
var mockAgent = new Mock<AIAgent>();
|
|
using var loggerFactory = LoggerFactory.Create(builder => { });
|
|
var builder = new AIAgentBuilder(mockAgent.Object);
|
|
|
|
// Act
|
|
var result = builder.UseOpenTelemetry(loggerFactory).Build();
|
|
|
|
// Assert
|
|
Assert.IsType<OpenTelemetryAgent>(result);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Verify that UseOpenTelemetry with source name works correctly.
|
|
/// </summary>
|
|
[Fact]
|
|
public void UseOpenTelemetry_WithSourceName_WorksCorrectly()
|
|
{
|
|
// Arrange
|
|
var mockAgent = new Mock<AIAgent>();
|
|
var builder = new AIAgentBuilder(mockAgent.Object);
|
|
const string SourceName = "TestSource";
|
|
|
|
// Act
|
|
var result = builder.UseOpenTelemetry(sourceName: SourceName).Build();
|
|
|
|
// Assert
|
|
Assert.IsType<OpenTelemetryAgent>(result);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Verify that UseOpenTelemetry with configure action works correctly.
|
|
/// </summary>
|
|
[Fact]
|
|
public void UseOpenTelemetry_WithConfigureAction_CallsConfigureAction()
|
|
{
|
|
// Arrange
|
|
var mockAgent = new Mock<AIAgent>();
|
|
var builder = new AIAgentBuilder(mockAgent.Object);
|
|
var configureWasCalled = false;
|
|
|
|
// Act
|
|
var result = builder.UseOpenTelemetry(configure: agent =>
|
|
{
|
|
configureWasCalled = true;
|
|
Assert.NotNull(agent);
|
|
Assert.IsType<OpenTelemetryAgent>(agent);
|
|
}).Build();
|
|
|
|
// Assert
|
|
Assert.True(configureWasCalled);
|
|
Assert.IsType<OpenTelemetryAgent>(result);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Verify that UseOpenTelemetry returns the same builder instance for chaining.
|
|
/// </summary>
|
|
[Fact]
|
|
public void UseOpenTelemetry_ReturnsBuilderForChaining()
|
|
{
|
|
// Arrange
|
|
var mockAgent = new Mock<AIAgent>();
|
|
var builder = new AIAgentBuilder(mockAgent.Object);
|
|
|
|
// Act
|
|
var result = builder.UseOpenTelemetry();
|
|
|
|
// Assert
|
|
Assert.Same(builder, result);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Verify that UseOpenTelemetry with all parameters works correctly.
|
|
/// </summary>
|
|
[Fact]
|
|
public void UseOpenTelemetry_WithAllParameters_WorksCorrectly()
|
|
{
|
|
// Arrange
|
|
var mockAgent = new Mock<AIAgent>();
|
|
using var loggerFactory = LoggerFactory.Create(builder => { });
|
|
var builder = new AIAgentBuilder(mockAgent.Object);
|
|
const string SourceName = "TestSource";
|
|
var configureWasCalled = false;
|
|
|
|
// Act
|
|
var result = builder.UseOpenTelemetry(
|
|
loggerFactory: loggerFactory,
|
|
sourceName: SourceName,
|
|
configure: agent =>
|
|
{
|
|
configureWasCalled = true;
|
|
Assert.NotNull(agent);
|
|
}).Build();
|
|
|
|
// Assert
|
|
Assert.True(configureWasCalled);
|
|
Assert.IsType<OpenTelemetryAgent>(result);
|
|
}
|
|
}
|