mirror of
https://github.com/microsoft/agent-framework.git
synced 2026-06-16 21:04:09 +08:00
.NET: [BREAKING] Renamed CreateAIAgent/GetAIAgent to AsAIAgent (#3222)
* Renamed chat client extension method * Additional renaming * Updated documentation * Fixed tests * Small fix * Small fix
This commit is contained in:
+2
-2
@@ -34,7 +34,7 @@ public sealed class A2AAgentCardExtensionsTests
|
||||
public void GetAIAgent_ReturnsAIAgent()
|
||||
{
|
||||
// Act
|
||||
var agent = this._agentCard.GetAIAgent();
|
||||
var agent = this._agentCard.AsAIAgent();
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(agent);
|
||||
@@ -56,7 +56,7 @@ public sealed class A2AAgentCardExtensionsTests
|
||||
Parts = [new TextPart { Text = "Response" }],
|
||||
});
|
||||
|
||||
var agent = this._agentCard.GetAIAgent(httpClient);
|
||||
var agent = this._agentCard.AsAIAgent(httpClient);
|
||||
|
||||
// Act
|
||||
await agent.RunAsync("Test input");
|
||||
|
||||
+1
-1
@@ -21,7 +21,7 @@ public sealed class A2AClientExtensionsTests
|
||||
const string TestDescription = "This is a test agent description";
|
||||
|
||||
// Act
|
||||
var agent = a2aClient.GetAIAgent(TestId, TestName, TestDescription);
|
||||
var agent = a2aClient.AsAIAgent(TestId, TestName, TestDescription);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(agent);
|
||||
|
||||
@@ -30,7 +30,7 @@ public sealed class AGUIAgentTests
|
||||
]);
|
||||
|
||||
var chatClient = new AGUIChatClient(httpClient, "http://localhost/agent", null, AGUIJsonSerializerContext.Default.Options);
|
||||
AIAgent agent = chatClient.CreateAIAgent(instructions: null, name: "agent1", description: "Test agent", tools: []);
|
||||
AIAgent agent = chatClient.AsAIAgent(instructions: null, name: "agent1", description: "Test agent", tools: []);
|
||||
List<ChatMessage> messages = [new ChatMessage(ChatRole.User, "Test")];
|
||||
|
||||
// Act
|
||||
@@ -55,7 +55,7 @@ public sealed class AGUIAgentTests
|
||||
]);
|
||||
|
||||
var chatClient = new AGUIChatClient(httpClient, "http://localhost/agent", null, AGUIJsonSerializerContext.Default.Options);
|
||||
AIAgent agent = chatClient.CreateAIAgent(instructions: null, name: "agent1", description: "Test agent", tools: []);
|
||||
AIAgent agent = chatClient.AsAIAgent(instructions: null, name: "agent1", description: "Test agent", tools: []);
|
||||
List<ChatMessage> messages = [new ChatMessage(ChatRole.User, "Test")];
|
||||
|
||||
// Act
|
||||
@@ -74,7 +74,7 @@ public sealed class AGUIAgentTests
|
||||
// Arrange
|
||||
using HttpClient httpClient = new();
|
||||
var chatClient = new AGUIChatClient(httpClient, "http://localhost/agent", null, AGUIJsonSerializerContext.Default.Options);
|
||||
AIAgent agent = chatClient.CreateAIAgent(instructions: "Test agent", name: "agent1");
|
||||
AIAgent agent = chatClient.AsAIAgent(instructions: "Test agent", name: "agent1");
|
||||
|
||||
// Act & Assert
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => agent.RunAsync(messages: null!));
|
||||
@@ -91,7 +91,7 @@ public sealed class AGUIAgentTests
|
||||
]);
|
||||
|
||||
var chatClient = new AGUIChatClient(httpClient, "http://localhost/agent", null, AGUIJsonSerializerContext.Default.Options);
|
||||
AIAgent agent = chatClient.CreateAIAgent(instructions: "Test agent", name: "agent1");
|
||||
AIAgent agent = chatClient.AsAIAgent(instructions: "Test agent", name: "agent1");
|
||||
List<ChatMessage> messages = [new ChatMessage(ChatRole.User, "Test")];
|
||||
|
||||
// Act
|
||||
@@ -115,7 +115,7 @@ public sealed class AGUIAgentTests
|
||||
]);
|
||||
|
||||
var chatClient = new AGUIChatClient(httpClient, "http://localhost/agent", null, AGUIJsonSerializerContext.Default.Options);
|
||||
AIAgent agent = chatClient.CreateAIAgent(instructions: "Test agent", name: "agent1");
|
||||
AIAgent agent = chatClient.AsAIAgent(instructions: "Test agent", name: "agent1");
|
||||
List<ChatMessage> messages = [new ChatMessage(ChatRole.User, "Test")];
|
||||
|
||||
// Act
|
||||
@@ -139,7 +139,7 @@ public sealed class AGUIAgentTests
|
||||
// Arrange
|
||||
using HttpClient httpClient = new();
|
||||
var chatClient = new AGUIChatClient(httpClient, "http://localhost/agent", null, AGUIJsonSerializerContext.Default.Options);
|
||||
AIAgent agent = chatClient.CreateAIAgent(instructions: "Test agent", name: "agent1");
|
||||
AIAgent agent = chatClient.AsAIAgent(instructions: "Test agent", name: "agent1");
|
||||
|
||||
// Act & Assert
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(async () =>
|
||||
@@ -162,7 +162,7 @@ public sealed class AGUIAgentTests
|
||||
]);
|
||||
|
||||
var chatClient = new AGUIChatClient(httpClient, "http://localhost/agent", null, AGUIJsonSerializerContext.Default.Options);
|
||||
AIAgent agent = chatClient.CreateAIAgent(instructions: "Test agent", name: "agent1");
|
||||
AIAgent agent = chatClient.AsAIAgent(instructions: "Test agent", name: "agent1");
|
||||
List<ChatMessage> messages = [new ChatMessage(ChatRole.User, "Test")];
|
||||
|
||||
// Act
|
||||
@@ -195,7 +195,7 @@ public sealed class AGUIAgentTests
|
||||
using HttpClient httpClient = new(handler);
|
||||
|
||||
var chatClient = new AGUIChatClient(httpClient, "http://localhost/agent", null, AGUIJsonSerializerContext.Default.Options);
|
||||
AIAgent agent = chatClient.CreateAIAgent(instructions: null, name: "agent1", description: "Test agent", tools: []);
|
||||
AIAgent agent = chatClient.AsAIAgent(instructions: null, name: "agent1", description: "Test agent", tools: []);
|
||||
List<ChatMessage> messages = [new ChatMessage(ChatRole.User, "Test")];
|
||||
|
||||
// Act
|
||||
@@ -227,7 +227,7 @@ public sealed class AGUIAgentTests
|
||||
]);
|
||||
|
||||
var chatClient = new AGUIChatClient(httpClient, "http://localhost/agent", null, AGUIJsonSerializerContext.Default.Options);
|
||||
AIAgent agent = chatClient.CreateAIAgent(instructions: null, name: "agent1", description: "Test agent", tools: []);
|
||||
AIAgent agent = chatClient.AsAIAgent(instructions: null, name: "agent1", description: "Test agent", tools: []);
|
||||
AgentThread thread = await agent.GetNewThreadAsync();
|
||||
List<ChatMessage> messages = [new ChatMessage(ChatRole.User, "Hello")];
|
||||
|
||||
@@ -249,7 +249,7 @@ public sealed class AGUIAgentTests
|
||||
// Arrange
|
||||
using var httpClient = new HttpClient();
|
||||
var chatClient = new AGUIChatClient(httpClient, "http://localhost/agent", null, AGUIJsonSerializerContext.Default.Options);
|
||||
AIAgent agent = chatClient.CreateAIAgent(instructions: null, name: "agent1", description: "Test agent", tools: []);
|
||||
AIAgent agent = chatClient.AsAIAgent(instructions: null, name: "agent1", description: "Test agent", tools: []);
|
||||
AgentThread originalThread = await agent.GetNewThreadAsync();
|
||||
JsonElement serialized = originalThread.Serialize();
|
||||
|
||||
@@ -301,7 +301,7 @@ public sealed class AGUIAgentTests
|
||||
]);
|
||||
|
||||
var chatClient = new AGUIChatClient(httpClient, "http://localhost/agent", null, AGUIJsonSerializerContext.Default.Options);
|
||||
AIAgent agent = chatClient.CreateAIAgent(instructions: null, name: "agent1", description: "Test agent", tools: [testTool]);
|
||||
AIAgent agent = chatClient.AsAIAgent(instructions: null, name: "agent1", description: "Test agent", tools: [testTool]);
|
||||
List<ChatMessage> messages = [new ChatMessage(ChatRole.User, "What's the weather?")];
|
||||
|
||||
// Act
|
||||
@@ -353,7 +353,7 @@ public sealed class AGUIAgentTests
|
||||
using HttpClient httpClient = new(handler);
|
||||
|
||||
var chatClient = new AGUIChatClient(httpClient, "http://localhost/agent", null, AGUIJsonSerializerContext.Default.Options);
|
||||
AIAgent agent = chatClient.CreateAIAgent(instructions: null, name: "agent1", description: "Test agent", tools: [tool1]); // Only tool1, not tool2
|
||||
AIAgent agent = chatClient.AsAIAgent(instructions: null, name: "agent1", description: "Test agent", tools: [tool1]); // Only tool1, not tool2
|
||||
List<ChatMessage> messages = [new ChatMessage(ChatRole.User, "Test")];
|
||||
|
||||
// Act
|
||||
@@ -403,7 +403,7 @@ public sealed class AGUIAgentTests
|
||||
]);
|
||||
|
||||
var chatClient = new AGUIChatClient(httpClient, "http://localhost/agent", null, AGUIJsonSerializerContext.Default.Options);
|
||||
AIAgent agent = chatClient.CreateAIAgent(instructions: null, name: "agent1", description: "Test agent", tools: [faultyTool]);
|
||||
AIAgent agent = chatClient.AsAIAgent(instructions: null, name: "agent1", description: "Test agent", tools: [faultyTool]);
|
||||
List<ChatMessage> messages = [new ChatMessage(ChatRole.User, "Test")];
|
||||
|
||||
// Act
|
||||
@@ -448,7 +448,7 @@ public sealed class AGUIAgentTests
|
||||
]);
|
||||
|
||||
var chatClient = new AGUIChatClient(httpClient, "http://localhost/agent", null, AGUIJsonSerializerContext.Default.Options);
|
||||
AIAgent agent = chatClient.CreateAIAgent(instructions: null, name: "agent1", description: "Test agent", tools: [tool1, tool2]);
|
||||
AIAgent agent = chatClient.AsAIAgent(instructions: null, name: "agent1", description: "Test agent", tools: [tool1, tool2]);
|
||||
List<ChatMessage> messages = [new ChatMessage(ChatRole.User, "Test")];
|
||||
|
||||
// Act
|
||||
@@ -486,7 +486,7 @@ public sealed class AGUIAgentTests
|
||||
]);
|
||||
|
||||
var chatClient = new AGUIChatClient(httpClient, "http://localhost/agent", null, AGUIJsonSerializerContext.Default.Options);
|
||||
AIAgent agent = chatClient.CreateAIAgent(instructions: null, name: "agent1", description: "Test agent", tools: [testTool]);
|
||||
AIAgent agent = chatClient.AsAIAgent(instructions: null, name: "agent1", description: "Test agent", tools: [testTool]);
|
||||
AgentThread thread = await agent.GetNewThreadAsync();
|
||||
List<ChatMessage> messages = [new ChatMessage(ChatRole.User, "Test")];
|
||||
|
||||
|
||||
+7
-7
@@ -34,7 +34,7 @@ public sealed class AnthropicBetaServiceExtensionsTests
|
||||
var testChatClient = new TestChatClient(chatClient.Beta.AsIChatClient());
|
||||
|
||||
// Act
|
||||
var agent = chatClient.Beta.CreateAIAgent(
|
||||
var agent = chatClient.Beta.AsAIAgent(
|
||||
model: "test-model",
|
||||
instructions: "Test instructions",
|
||||
name: "Test Agent",
|
||||
@@ -63,7 +63,7 @@ public sealed class AnthropicBetaServiceExtensionsTests
|
||||
TestChatClient? testChatClient = null;
|
||||
|
||||
// Act
|
||||
var agent = chatClient.Beta.CreateAIAgent(
|
||||
var agent = chatClient.Beta.AsAIAgent(
|
||||
model: "test-model",
|
||||
instructions: "Test instructions",
|
||||
clientFactory: (innerClient) =>
|
||||
@@ -95,7 +95,7 @@ public sealed class AnthropicBetaServiceExtensionsTests
|
||||
};
|
||||
|
||||
// Act
|
||||
var agent = chatClient.Beta.CreateAIAgent(
|
||||
var agent = chatClient.Beta.AsAIAgent(
|
||||
options,
|
||||
clientFactory: (innerClient) => testChatClient);
|
||||
|
||||
@@ -120,7 +120,7 @@ public sealed class AnthropicBetaServiceExtensionsTests
|
||||
var chatClient = new TestAnthropicChatClient();
|
||||
|
||||
// Act
|
||||
var agent = chatClient.Beta.CreateAIAgent(
|
||||
var agent = chatClient.Beta.AsAIAgent(
|
||||
model: "test-model",
|
||||
instructions: "Test instructions",
|
||||
name: "Test Agent");
|
||||
@@ -144,7 +144,7 @@ public sealed class AnthropicBetaServiceExtensionsTests
|
||||
var chatClient = new TestAnthropicChatClient();
|
||||
|
||||
// Act
|
||||
var agent = chatClient.Beta.CreateAIAgent(
|
||||
var agent = chatClient.Beta.AsAIAgent(
|
||||
model: "test-model",
|
||||
instructions: "Test instructions",
|
||||
name: "Test Agent",
|
||||
@@ -167,7 +167,7 @@ public sealed class AnthropicBetaServiceExtensionsTests
|
||||
{
|
||||
// Act & Assert
|
||||
var exception = Assert.Throws<ArgumentNullException>(() =>
|
||||
((IBetaService)null!).CreateAIAgent("test-model"));
|
||||
((IBetaService)null!).AsAIAgent("test-model"));
|
||||
|
||||
Assert.Equal("betaService", exception.ParamName);
|
||||
}
|
||||
@@ -183,7 +183,7 @@ public sealed class AnthropicBetaServiceExtensionsTests
|
||||
|
||||
// Act & Assert
|
||||
var exception = Assert.Throws<ArgumentNullException>(() =>
|
||||
chatClient.Beta.CreateAIAgent((ChatClientAgentOptions)null!));
|
||||
chatClient.Beta.AsAIAgent((ChatClientAgentOptions)null!));
|
||||
|
||||
Assert.Equal("options", exception.ParamName);
|
||||
}
|
||||
|
||||
+7
-7
@@ -101,7 +101,7 @@ public sealed class AnthropicClientExtensionsTests
|
||||
var testChatClient = new TestChatClient(chatClient.AsIChatClient());
|
||||
|
||||
// Act
|
||||
var agent = chatClient.CreateAIAgent(
|
||||
var agent = chatClient.AsAIAgent(
|
||||
model: "test-model",
|
||||
instructions: "Test instructions",
|
||||
name: "Test Agent",
|
||||
@@ -130,7 +130,7 @@ public sealed class AnthropicClientExtensionsTests
|
||||
TestChatClient? testChatClient = null;
|
||||
|
||||
// Act
|
||||
var agent = chatClient.CreateAIAgent(
|
||||
var agent = chatClient.AsAIAgent(
|
||||
model: "test-model",
|
||||
instructions: "Test instructions",
|
||||
clientFactory: (innerClient) =>
|
||||
@@ -162,7 +162,7 @@ public sealed class AnthropicClientExtensionsTests
|
||||
};
|
||||
|
||||
// Act
|
||||
var agent = chatClient.CreateAIAgent(
|
||||
var agent = chatClient.AsAIAgent(
|
||||
options,
|
||||
clientFactory: (innerClient) => testChatClient);
|
||||
|
||||
@@ -187,7 +187,7 @@ public sealed class AnthropicClientExtensionsTests
|
||||
var chatClient = new TestAnthropicChatClient();
|
||||
|
||||
// Act
|
||||
var agent = chatClient.CreateAIAgent(
|
||||
var agent = chatClient.AsAIAgent(
|
||||
model: "test-model",
|
||||
instructions: "Test instructions",
|
||||
name: "Test Agent");
|
||||
@@ -211,7 +211,7 @@ public sealed class AnthropicClientExtensionsTests
|
||||
var chatClient = new TestAnthropicChatClient();
|
||||
|
||||
// Act
|
||||
var agent = chatClient.CreateAIAgent(
|
||||
var agent = chatClient.AsAIAgent(
|
||||
model: "test-model",
|
||||
instructions: "Test instructions",
|
||||
name: "Test Agent",
|
||||
@@ -234,7 +234,7 @@ public sealed class AnthropicClientExtensionsTests
|
||||
{
|
||||
// Act & Assert
|
||||
var exception = Assert.Throws<ArgumentNullException>(() =>
|
||||
((TestAnthropicChatClient)null!).CreateAIAgent("test-model"));
|
||||
((TestAnthropicChatClient)null!).AsAIAgent("test-model"));
|
||||
|
||||
Assert.Equal("client", exception.ParamName);
|
||||
}
|
||||
@@ -250,7 +250,7 @@ public sealed class AnthropicClientExtensionsTests
|
||||
|
||||
// Act & Assert
|
||||
var exception = Assert.Throws<ArgumentNullException>(() =>
|
||||
chatClient.CreateAIAgent((ChatClientAgentOptions)null!));
|
||||
chatClient.AsAIAgent((ChatClientAgentOptions)null!));
|
||||
|
||||
Assert.Equal("options", exception.ParamName);
|
||||
}
|
||||
|
||||
+8
-8
@@ -42,7 +42,7 @@ public sealed class PersistentAgentsClientExtensionsTests
|
||||
|
||||
// Act & Assert - null agentId
|
||||
var exception1 = Assert.Throws<ArgumentException>(() =>
|
||||
mockClient.Object.GetAIAgent((string)null!));
|
||||
mockClient.Object.GetAIAgent(null!));
|
||||
Assert.Equal("agentId", exception1.ParamName);
|
||||
|
||||
// Act & Assert - empty agentId
|
||||
@@ -314,7 +314,7 @@ public sealed class PersistentAgentsClientExtensionsTests
|
||||
};
|
||||
|
||||
// Act
|
||||
var agent = client.GetAIAgent(response, options);
|
||||
var agent = client.AsAIAgent(response, options);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(agent);
|
||||
@@ -341,7 +341,7 @@ public sealed class PersistentAgentsClientExtensionsTests
|
||||
};
|
||||
|
||||
// Act
|
||||
var agent = client.GetAIAgent(persistentAgent, options);
|
||||
var agent = client.AsAIAgent(persistentAgent, options);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(agent);
|
||||
@@ -363,7 +363,7 @@ public sealed class PersistentAgentsClientExtensionsTests
|
||||
var options = new ChatClientAgentOptions(); // Empty options
|
||||
|
||||
// Act
|
||||
var agent = client.GetAIAgent(persistentAgent, options);
|
||||
var agent = client.AsAIAgent(persistentAgent, options);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(agent);
|
||||
@@ -443,7 +443,7 @@ public sealed class PersistentAgentsClientExtensionsTests
|
||||
};
|
||||
|
||||
// Act
|
||||
var agent = client.GetAIAgent(
|
||||
var agent = client.AsAIAgent(
|
||||
persistentAgent,
|
||||
options,
|
||||
clientFactory: (innerClient) => testChatClient);
|
||||
@@ -470,7 +470,7 @@ public sealed class PersistentAgentsClientExtensionsTests
|
||||
|
||||
// Act & Assert
|
||||
var exception = Assert.Throws<ArgumentNullException>(() =>
|
||||
client.GetAIAgent((Response<PersistentAgent>)null!, options));
|
||||
client.AsAIAgent(null!, options));
|
||||
|
||||
Assert.Equal("persistentAgentResponse", exception.ParamName);
|
||||
}
|
||||
@@ -487,7 +487,7 @@ public sealed class PersistentAgentsClientExtensionsTests
|
||||
|
||||
// Act & Assert
|
||||
var exception = Assert.Throws<ArgumentNullException>(() =>
|
||||
client.GetAIAgent((PersistentAgent)null!, options));
|
||||
client.AsAIAgent((PersistentAgent)null!, options));
|
||||
|
||||
Assert.Equal("persistentAgentMetadata", exception.ParamName);
|
||||
}
|
||||
@@ -504,7 +504,7 @@ public sealed class PersistentAgentsClientExtensionsTests
|
||||
|
||||
// Act & Assert
|
||||
var exception = Assert.Throws<ArgumentNullException>(() =>
|
||||
client.GetAIAgent(persistentAgent, (ChatClientAgentOptions)null!));
|
||||
client.AsAIAgent(persistentAgent, (ChatClientAgentOptions)null!));
|
||||
|
||||
Assert.Equal("options", exception.ParamName);
|
||||
}
|
||||
|
||||
+58
-58
@@ -25,13 +25,13 @@ namespace Microsoft.Agents.AI.AzureAI.UnitTests;
|
||||
/// </summary>
|
||||
public sealed class AzureAIProjectChatClientExtensionsTests
|
||||
{
|
||||
#region GetAIAgent(AIProjectClient, AgentRecord) Tests
|
||||
#region AsAIAgent(AIProjectClient, AgentRecord) Tests
|
||||
|
||||
/// <summary>
|
||||
/// Verify that GetAIAgent throws ArgumentNullException when AIProjectClient is null.
|
||||
/// Verify that AsAIAgent throws ArgumentNullException when AIProjectClient is null.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void GetAIAgent_WithAgentRecord_WithNullClient_ThrowsArgumentNullException()
|
||||
public void AsAIAgent_WithAgentRecord_WithNullClient_ThrowsArgumentNullException()
|
||||
{
|
||||
// Arrange
|
||||
AIProjectClient? client = null;
|
||||
@@ -39,39 +39,39 @@ public sealed class AzureAIProjectChatClientExtensionsTests
|
||||
|
||||
// Act & Assert
|
||||
var exception = Assert.Throws<ArgumentNullException>(() =>
|
||||
client!.GetAIAgent(agentRecord));
|
||||
client!.AsAIAgent(agentRecord));
|
||||
|
||||
Assert.Equal("aiProjectClient", exception.ParamName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verify that GetAIAgent throws ArgumentNullException when agentRecord is null.
|
||||
/// Verify that AsAIAgent throws ArgumentNullException when agentRecord is null.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void GetAIAgent_WithAgentRecord_WithNullAgentRecord_ThrowsArgumentNullException()
|
||||
public void AsAIAgent_WithAgentRecord_WithNullAgentRecord_ThrowsArgumentNullException()
|
||||
{
|
||||
// Arrange
|
||||
var mockClient = new Mock<AIProjectClient>();
|
||||
|
||||
// Act & Assert
|
||||
var exception = Assert.Throws<ArgumentNullException>(() =>
|
||||
mockClient.Object.GetAIAgent((AgentRecord)null!));
|
||||
mockClient.Object.AsAIAgent((AgentRecord)null!));
|
||||
|
||||
Assert.Equal("agentRecord", exception.ParamName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verify that GetAIAgent with AgentRecord creates a valid agent.
|
||||
/// Verify that AsAIAgent with AgentRecord creates a valid agent.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void GetAIAgent_WithAgentRecord_CreatesValidAgent()
|
||||
public void AsAIAgent_WithAgentRecord_CreatesValidAgent()
|
||||
{
|
||||
// Arrange
|
||||
AIProjectClient client = this.CreateTestAgentClient();
|
||||
AgentRecord agentRecord = this.CreateTestAgentRecord();
|
||||
|
||||
// Act
|
||||
var agent = client.GetAIAgent(agentRecord);
|
||||
var agent = client.AsAIAgent(agentRecord);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(agent);
|
||||
@@ -79,10 +79,10 @@ public sealed class AzureAIProjectChatClientExtensionsTests
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verify that GetAIAgent with AgentRecord and clientFactory applies the factory.
|
||||
/// Verify that AsAIAgent with AgentRecord and clientFactory applies the factory.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void GetAIAgent_WithAgentRecord_WithClientFactory_AppliesFactoryCorrectly()
|
||||
public void AsAIAgent_WithAgentRecord_WithClientFactory_AppliesFactoryCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
AIProjectClient client = this.CreateTestAgentClient();
|
||||
@@ -90,7 +90,7 @@ public sealed class AzureAIProjectChatClientExtensionsTests
|
||||
TestChatClient? testChatClient = null;
|
||||
|
||||
// Act
|
||||
var agent = client.GetAIAgent(
|
||||
var agent = client.AsAIAgent(
|
||||
agentRecord,
|
||||
clientFactory: (innerClient) => testChatClient = new TestChatClient(innerClient));
|
||||
|
||||
@@ -103,13 +103,13 @@ public sealed class AzureAIProjectChatClientExtensionsTests
|
||||
|
||||
#endregion
|
||||
|
||||
#region GetAIAgent(AIProjectClient, AgentVersion) Tests
|
||||
#region AsAIAgent(AIProjectClient, AgentVersion) Tests
|
||||
|
||||
/// <summary>
|
||||
/// Verify that GetAIAgent throws ArgumentNullException when AIProjectClient is null.
|
||||
/// Verify that AsAIAgent throws ArgumentNullException when AIProjectClient is null.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void GetAIAgent_WithAgentVersion_WithNullClient_ThrowsArgumentNullException()
|
||||
public void AsAIAgent_WithAgentVersion_WithNullClient_ThrowsArgumentNullException()
|
||||
{
|
||||
// Arrange
|
||||
AIProjectClient? client = null;
|
||||
@@ -117,39 +117,39 @@ public sealed class AzureAIProjectChatClientExtensionsTests
|
||||
|
||||
// Act & Assert
|
||||
var exception = Assert.Throws<ArgumentNullException>(() =>
|
||||
client!.GetAIAgent(agentVersion));
|
||||
client!.AsAIAgent(agentVersion));
|
||||
|
||||
Assert.Equal("aiProjectClient", exception.ParamName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verify that GetAIAgent throws ArgumentNullException when agentVersion is null.
|
||||
/// Verify that AsAIAgent throws ArgumentNullException when agentVersion is null.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void GetAIAgent_WithAgentVersion_WithNullAgentVersion_ThrowsArgumentNullException()
|
||||
public void AsAIAgent_WithAgentVersion_WithNullAgentVersion_ThrowsArgumentNullException()
|
||||
{
|
||||
// Arrange
|
||||
var mockClient = new Mock<AIProjectClient>();
|
||||
|
||||
// Act & Assert
|
||||
var exception = Assert.Throws<ArgumentNullException>(() =>
|
||||
mockClient.Object.GetAIAgent((AgentVersion)null!));
|
||||
mockClient.Object.AsAIAgent((AgentVersion)null!));
|
||||
|
||||
Assert.Equal("agentVersion", exception.ParamName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verify that GetAIAgent with AgentVersion creates a valid agent.
|
||||
/// Verify that AsAIAgent with AgentVersion creates a valid agent.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void GetAIAgent_WithAgentVersion_CreatesValidAgent()
|
||||
public void AsAIAgent_WithAgentVersion_CreatesValidAgent()
|
||||
{
|
||||
// Arrange
|
||||
AIProjectClient client = this.CreateTestAgentClient();
|
||||
AgentVersion agentVersion = this.CreateTestAgentVersion();
|
||||
|
||||
// Act
|
||||
var agent = client.GetAIAgent(agentVersion);
|
||||
var agent = client.AsAIAgent(agentVersion);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(agent);
|
||||
@@ -157,10 +157,10 @@ public sealed class AzureAIProjectChatClientExtensionsTests
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verify that GetAIAgent with AgentVersion and clientFactory applies the factory.
|
||||
/// Verify that AsAIAgent with AgentVersion and clientFactory applies the factory.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void GetAIAgent_WithAgentVersion_WithClientFactory_AppliesFactoryCorrectly()
|
||||
public void AsAIAgent_WithAgentVersion_WithClientFactory_AppliesFactoryCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
AIProjectClient client = this.CreateTestAgentClient();
|
||||
@@ -168,7 +168,7 @@ public sealed class AzureAIProjectChatClientExtensionsTests
|
||||
TestChatClient? testChatClient = null;
|
||||
|
||||
// Act
|
||||
var agent = client.GetAIAgent(
|
||||
var agent = client.AsAIAgent(
|
||||
agentVersion,
|
||||
clientFactory: (innerClient) => testChatClient = new TestChatClient(innerClient));
|
||||
|
||||
@@ -183,7 +183,7 @@ public sealed class AzureAIProjectChatClientExtensionsTests
|
||||
/// Verify that GetAIAgent with requireInvocableTools=true enforces invocable tools.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void GetAIAgent_WithAgentVersion_WithRequireInvocableToolsTrue_EnforcesInvocableTools()
|
||||
public void AsAIAgent_WithAgentVersion_WithRequireInvocableToolsTrue_EnforcesInvocableTools()
|
||||
{
|
||||
// Arrange
|
||||
AIProjectClient client = this.CreateTestAgentClient();
|
||||
@@ -194,7 +194,7 @@ public sealed class AzureAIProjectChatClientExtensionsTests
|
||||
};
|
||||
|
||||
// Act
|
||||
var agent = client.GetAIAgent(agentVersion, tools: tools);
|
||||
var agent = client.AsAIAgent(agentVersion, tools: tools);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(agent);
|
||||
@@ -205,14 +205,14 @@ public sealed class AzureAIProjectChatClientExtensionsTests
|
||||
/// Verify that GetAIAgent with requireInvocableTools=false allows declarative functions.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void GetAIAgent_WithAgentVersion_WithRequireInvocableToolsFalse_AllowsDeclarativeFunctions()
|
||||
public void AsAIAgent_WithAgentVersion_WithRequireInvocableToolsFalse_AllowsDeclarativeFunctions()
|
||||
{
|
||||
// Arrange
|
||||
AIProjectClient client = this.CreateTestAgentClient();
|
||||
AgentVersion agentVersion = this.CreateTestAgentVersion();
|
||||
|
||||
// Act - should not throw even without tools when requireInvocableTools is false
|
||||
var agent = client.GetAIAgent(agentVersion);
|
||||
var agent = client.AsAIAgent(agentVersion);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(agent);
|
||||
@@ -374,7 +374,7 @@ public sealed class AzureAIProjectChatClientExtensionsTests
|
||||
#region GetAIAgent(AIProjectClient, string) Tests
|
||||
|
||||
/// <summary>
|
||||
/// Verify that GetAIAgent throws ArgumentNullException when AIProjectClient is null.
|
||||
/// Verify that AsAIAgent throws ArgumentNullException when AIProjectClient is null.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void GetAIAgent_ByName_WithNullClient_ThrowsArgumentNullException()
|
||||
@@ -390,7 +390,7 @@ public sealed class AzureAIProjectChatClientExtensionsTests
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verify that GetAIAgent throws ArgumentNullException when name is null.
|
||||
/// Verify that AsAIAgent throws ArgumentNullException when name is null.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void GetAIAgent_ByName_WithNullName_ThrowsArgumentNullException()
|
||||
@@ -406,7 +406,7 @@ public sealed class AzureAIProjectChatClientExtensionsTests
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verify that GetAIAgent throws ArgumentException when name is empty.
|
||||
/// Verify that AsAIAgent throws ArgumentException when name is empty.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void GetAIAgent_ByName_WithEmptyName_ThrowsArgumentException()
|
||||
@@ -422,7 +422,7 @@ public sealed class AzureAIProjectChatClientExtensionsTests
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verify that GetAIAgent throws InvalidOperationException when agent is not found.
|
||||
/// Verify that AsAIAgent throws InvalidOperationException when agent is not found.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void GetAIAgent_ByName_WithNonExistentAgent_ThrowsInvalidOperationException()
|
||||
@@ -505,13 +505,13 @@ public sealed class AzureAIProjectChatClientExtensionsTests
|
||||
|
||||
#endregion
|
||||
|
||||
#region GetAIAgent(AIProjectClient, AgentRecord) with tools Tests
|
||||
#region AsAIAgent(AIProjectClient, AgentRecord) with tools Tests
|
||||
|
||||
/// <summary>
|
||||
/// Verify that GetAIAgent with additional tools when the definition has no tools does not throw and results in an agent with no tools.
|
||||
/// Verify that AsAIAgent with additional tools when the definition has no tools does not throw and results in an agent with no tools.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void GetAIAgent_WithAgentRecordAndAdditionalTools_WhenDefinitionHasNoTools_ShouldNotThrow()
|
||||
public void AsAIAgent_WithAgentRecordAndAdditionalTools_WhenDefinitionHasNoTools_ShouldNotThrow()
|
||||
{
|
||||
// Arrange
|
||||
AIProjectClient client = this.CreateTestAgentClient();
|
||||
@@ -522,7 +522,7 @@ public sealed class AzureAIProjectChatClientExtensionsTests
|
||||
};
|
||||
|
||||
// Act
|
||||
var agent = client.GetAIAgent(agentRecord, tools: tools);
|
||||
var agent = client.AsAIAgent(agentRecord, tools: tools);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(agent);
|
||||
@@ -536,17 +536,17 @@ public sealed class AzureAIProjectChatClientExtensionsTests
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verify that GetAIAgent with null tools works correctly.
|
||||
/// Verify that AsAIAgent with null tools works correctly.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void GetAIAgent_WithAgentRecordAndNullTools_WorksCorrectly()
|
||||
public void AsAIAgent_WithAgentRecordAndNullTools_WorksCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
AIProjectClient client = this.CreateTestAgentClient();
|
||||
AgentRecord agentRecord = this.CreateTestAgentRecord();
|
||||
|
||||
// Act
|
||||
var agent = client.GetAIAgent(agentRecord, tools: null);
|
||||
var agent = client.AsAIAgent(agentRecord, tools: null);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(agent);
|
||||
@@ -1104,7 +1104,7 @@ public sealed class AzureAIProjectChatClientExtensionsTests
|
||||
var shouldBeIgnoredTool = AIFunctionFactory.Create(() => "test", "additional_tool", "An additional test function that should be ignored");
|
||||
|
||||
// Act & Assert
|
||||
var agent = client.GetAIAgent(agentVersion, tools: [invocableInlineAITool, shouldBeIgnoredTool]);
|
||||
var agent = client.AsAIAgent(agentVersion, tools: [invocableInlineAITool, shouldBeIgnoredTool]);
|
||||
Assert.NotNull(agent);
|
||||
var version = agent.GetService<AgentVersion>();
|
||||
Assert.NotNull(version);
|
||||
@@ -1136,7 +1136,7 @@ public sealed class AzureAIProjectChatClientExtensionsTests
|
||||
};
|
||||
|
||||
// Act
|
||||
var agent = client.GetAIAgent(agentRecord, tools: tools);
|
||||
var agent = client.AsAIAgent(agentRecord, tools: tools);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(agent);
|
||||
@@ -1632,7 +1632,7 @@ public sealed class AzureAIProjectChatClientExtensionsTests
|
||||
#region AgentName Validation Tests
|
||||
|
||||
/// <summary>
|
||||
/// Verify that GetAIAgent throws ArgumentException when agent name is invalid.
|
||||
/// Verify that AsAIAgent throws ArgumentException when agent name is invalid.
|
||||
/// </summary>
|
||||
[Theory]
|
||||
[MemberData(nameof(InvalidAgentNameTestData.GetInvalidAgentNames), MemberType = typeof(InvalidAgentNameTestData))]
|
||||
@@ -1846,7 +1846,7 @@ public sealed class AzureAIProjectChatClientExtensionsTests
|
||||
/// Verify that the underlying chat client created by extension methods can be wrapped with clientFactory.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void GetAIAgent_WithClientFactory_WrapsUnderlyingChatClient()
|
||||
public void AsAIAgent_WithClientFactory_WrapsUnderlyingChatClient()
|
||||
{
|
||||
// Arrange
|
||||
AIProjectClient client = this.CreateTestAgentClient();
|
||||
@@ -1854,7 +1854,7 @@ public sealed class AzureAIProjectChatClientExtensionsTests
|
||||
int factoryCallCount = 0;
|
||||
|
||||
// Act
|
||||
var agent = client.GetAIAgent(
|
||||
var agent = client.AsAIAgent(
|
||||
agentRecord,
|
||||
clientFactory: (innerClient) =>
|
||||
{
|
||||
@@ -1903,18 +1903,18 @@ public sealed class AzureAIProjectChatClientExtensionsTests
|
||||
/// Verify that multiple clientFactory calls create independent wrapped clients.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void GetAIAgent_MultipleCallsWithClientFactory_CreatesIndependentClients()
|
||||
public void AsAIAgent_MultipleCallsWithClientFactory_CreatesIndependentClients()
|
||||
{
|
||||
// Arrange
|
||||
AIProjectClient client = this.CreateTestAgentClient();
|
||||
AgentRecord agentRecord = this.CreateTestAgentRecord();
|
||||
|
||||
// Act
|
||||
var agent1 = client.GetAIAgent(
|
||||
var agent1 = client.AsAIAgent(
|
||||
agentRecord,
|
||||
clientFactory: (innerClient) => new TestChatClient(innerClient));
|
||||
|
||||
var agent2 = client.GetAIAgent(
|
||||
var agent2 = client.AsAIAgent(
|
||||
agentRecord,
|
||||
clientFactory: (innerClient) => new TestChatClient(innerClient));
|
||||
|
||||
@@ -2165,7 +2165,7 @@ public sealed class AzureAIProjectChatClientExtensionsTests
|
||||
#region GetAIAgent(AIProjectClient, AgentReference) Tests
|
||||
|
||||
/// <summary>
|
||||
/// Verify that GetAIAgent throws ArgumentNullException when AIProjectClient is null.
|
||||
/// Verify that AsAIAgent throws ArgumentNullException when AIProjectClient is null.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void GetAIAgent_WithAgentReference_WithNullClient_ThrowsArgumentNullException()
|
||||
@@ -2182,7 +2182,7 @@ public sealed class AzureAIProjectChatClientExtensionsTests
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verify that GetAIAgent throws ArgumentNullException when agentReference is null.
|
||||
/// Verify that AsAIAgent throws ArgumentNullException when agentReference is null.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void GetAIAgent_WithAgentReference_WithNullAgentReference_ThrowsArgumentNullException()
|
||||
@@ -2297,7 +2297,7 @@ public sealed class AzureAIProjectChatClientExtensionsTests
|
||||
AgentRecord agentRecord = this.CreateTestAgentRecord();
|
||||
|
||||
// Act
|
||||
var agent = client.GetAIAgent(agentRecord);
|
||||
var agent = client.AsAIAgent(agentRecord);
|
||||
var retrievedRecord = agent.GetService<AgentRecord>();
|
||||
|
||||
// Assert
|
||||
@@ -2338,7 +2338,7 @@ public sealed class AzureAIProjectChatClientExtensionsTests
|
||||
AgentVersion agentVersion = this.CreateTestAgentVersion();
|
||||
|
||||
// Act
|
||||
var agent = client.GetAIAgent(agentVersion);
|
||||
var agent = client.AsAIAgent(agentVersion);
|
||||
var retrievedVersion = agent.GetService<AgentVersion>();
|
||||
|
||||
// Assert
|
||||
@@ -2379,7 +2379,7 @@ public sealed class AzureAIProjectChatClientExtensionsTests
|
||||
AgentRecord agentRecord = this.CreateTestAgentRecord();
|
||||
|
||||
// Act
|
||||
var agent = client.GetAIAgent(agentRecord);
|
||||
var agent = client.AsAIAgent(agentRecord);
|
||||
var metadata = agent.GetService<ChatClientMetadata>();
|
||||
|
||||
// Assert
|
||||
@@ -2402,7 +2402,7 @@ public sealed class AzureAIProjectChatClientExtensionsTests
|
||||
AgentRecord agentRecord = this.CreateTestAgentRecord(definition);
|
||||
|
||||
// Act
|
||||
var agent = client.GetAIAgent(agentRecord);
|
||||
var agent = client.AsAIAgent(agentRecord);
|
||||
var metadata = agent.GetService<ChatClientMetadata>();
|
||||
|
||||
// Assert
|
||||
@@ -2423,7 +2423,7 @@ public sealed class AzureAIProjectChatClientExtensionsTests
|
||||
AgentVersion agentVersion = this.CreateTestAgentVersion();
|
||||
|
||||
// Act
|
||||
var agent = client.GetAIAgent(agentVersion);
|
||||
var agent = client.AsAIAgent(agentVersion);
|
||||
var metadata = agent.GetService<ChatClientMetadata>();
|
||||
|
||||
// Assert
|
||||
@@ -2467,7 +2467,7 @@ public sealed class AzureAIProjectChatClientExtensionsTests
|
||||
AgentRecord agentRecord = this.CreateTestAgentRecord();
|
||||
|
||||
// Act
|
||||
var agent = client.GetAIAgent(agentRecord);
|
||||
var agent = client.AsAIAgent(agentRecord);
|
||||
var retrievedReference = agent.GetService<AgentReference>();
|
||||
|
||||
// Assert
|
||||
@@ -2486,7 +2486,7 @@ public sealed class AzureAIProjectChatClientExtensionsTests
|
||||
AgentVersion agentVersion = this.CreateTestAgentVersion();
|
||||
|
||||
// Act
|
||||
var agent = client.GetAIAgent(agentVersion);
|
||||
var agent = client.AsAIAgent(agentVersion);
|
||||
var retrievedReference = agent.GetService<AgentReference>();
|
||||
|
||||
// Assert
|
||||
|
||||
@@ -41,7 +41,7 @@ public sealed class AgentEntityTests(ITestOutputHelper outputHelper) : IDisposab
|
||||
public async Task EntityNamePrefixAsync()
|
||||
{
|
||||
// Setup
|
||||
AIAgent simpleAgent = TestHelper.GetAzureOpenAIChatClient(s_configuration).CreateAIAgent(
|
||||
AIAgent simpleAgent = TestHelper.GetAzureOpenAIChatClient(s_configuration).AsAIAgent(
|
||||
name: "TestAgent",
|
||||
instructions: "You are a helpful assistant that always responds with a friendly greeting."
|
||||
);
|
||||
@@ -88,7 +88,7 @@ public sealed class AgentEntityTests(ITestOutputHelper outputHelper) : IDisposab
|
||||
public async Task RunAgentMethodNamesAllWorkAsync(string runAgentMethodName)
|
||||
{
|
||||
// Setup
|
||||
AIAgent simpleAgent = TestHelper.GetAzureOpenAIChatClient(s_configuration).CreateAIAgent(
|
||||
AIAgent simpleAgent = TestHelper.GetAzureOpenAIChatClient(s_configuration).AsAIAgent(
|
||||
name: "TestAgent",
|
||||
instructions: "You are a helpful assistant that always responds with a friendly greeting."
|
||||
);
|
||||
@@ -143,7 +143,7 @@ public sealed class AgentEntityTests(ITestOutputHelper outputHelper) : IDisposab
|
||||
public async Task OrchestrationIdSetDuringOrchestrationAsync()
|
||||
{
|
||||
// Arrange
|
||||
AIAgent simpleAgent = TestHelper.GetAzureOpenAIChatClient(s_configuration).CreateAIAgent(
|
||||
AIAgent simpleAgent = TestHelper.GetAzureOpenAIChatClient(s_configuration).AsAIAgent(
|
||||
name: "TestAgent",
|
||||
instructions: "You are a helpful assistant that always responds with a friendly greeting."
|
||||
);
|
||||
|
||||
+6
-6
@@ -41,7 +41,7 @@ public sealed class ExternalClientTests(ITestOutputHelper outputHelper) : IDispo
|
||||
public async Task SimplePromptAsync()
|
||||
{
|
||||
// Setup
|
||||
AIAgent simpleAgent = TestHelper.GetAzureOpenAIChatClient(s_configuration).CreateAIAgent(
|
||||
AIAgent simpleAgent = TestHelper.GetAzureOpenAIChatClient(s_configuration).AsAIAgent(
|
||||
instructions: "You are a helpful assistant that always responds with a friendly greeting.",
|
||||
name: "TestAgent");
|
||||
|
||||
@@ -94,7 +94,7 @@ public sealed class ExternalClientTests(ITestOutputHelper outputHelper) : IDispo
|
||||
return isSunny ? "Pack sunglasses and sunscreen." : "Pack a raincoat and umbrella.";
|
||||
}
|
||||
|
||||
AIAgent tripPlanningAgent = TestHelper.GetAzureOpenAIChatClient(s_configuration).CreateAIAgent(
|
||||
AIAgent tripPlanningAgent = TestHelper.GetAzureOpenAIChatClient(s_configuration).AsAIAgent(
|
||||
instructions: "You are a trip planning assistant. Use the weather tool and packing list tool as needed.",
|
||||
name: "TripPlanningAgent",
|
||||
description: "An agent to help plan your day trips",
|
||||
@@ -174,7 +174,7 @@ public sealed class ExternalClientTests(ITestOutputHelper outputHelper) : IDispo
|
||||
// This is the agent that will be used to start the workflow
|
||||
agents.AddAIAgentFactory(
|
||||
"WorkflowAgent",
|
||||
sp => TestHelper.GetAzureOpenAIChatClient(s_configuration).CreateAIAgent(
|
||||
sp => TestHelper.GetAzureOpenAIChatClient(s_configuration).AsAIAgent(
|
||||
name: "WorkflowAgent",
|
||||
instructions: "You can start greeting workflows and check their status.",
|
||||
services: sp,
|
||||
@@ -184,7 +184,7 @@ public sealed class ExternalClientTests(ITestOutputHelper outputHelper) : IDispo
|
||||
]));
|
||||
|
||||
// This is the agent that will be called by the workflow
|
||||
agents.AddAIAgent(TestHelper.GetAzureOpenAIChatClient(s_configuration).CreateAIAgent(
|
||||
agents.AddAIAgent(TestHelper.GetAzureOpenAIChatClient(s_configuration).AsAIAgent(
|
||||
name: "SimpleAgent",
|
||||
instructions: "You are a simple assistant."
|
||||
));
|
||||
@@ -217,14 +217,14 @@ public sealed class ExternalClientTests(ITestOutputHelper outputHelper) : IDispo
|
||||
public void AsDurableAgentProxy_ThrowsWhenAgentNotRegistered()
|
||||
{
|
||||
// Setup: Register one agent but try to use a different one
|
||||
AIAgent registeredAgent = TestHelper.GetAzureOpenAIChatClient(s_configuration).CreateAIAgent(
|
||||
AIAgent registeredAgent = TestHelper.GetAzureOpenAIChatClient(s_configuration).AsAIAgent(
|
||||
instructions: "You are a helpful assistant.",
|
||||
name: "RegisteredAgent");
|
||||
|
||||
using TestHelper testHelper = TestHelper.Start([registeredAgent], this._outputHelper);
|
||||
|
||||
// Create an agent with a different name that isn't registered
|
||||
AIAgent unregisteredAgent = TestHelper.GetAzureOpenAIChatClient(s_configuration).CreateAIAgent(
|
||||
AIAgent unregisteredAgent = TestHelper.GetAzureOpenAIChatClient(s_configuration).AsAIAgent(
|
||||
instructions: "You are a helpful assistant.",
|
||||
name: "UnregisteredAgent");
|
||||
|
||||
|
||||
@@ -57,7 +57,7 @@ public sealed class OrchestrationTests(ITestOutputHelper outputHelper) : IDispos
|
||||
// Register a different agent, but not "NonExistentAgent"
|
||||
agents.AddAIAgentFactory(
|
||||
"OtherAgent",
|
||||
sp => TestHelper.GetAzureOpenAIChatClient(s_configuration).CreateAIAgent(
|
||||
sp => TestHelper.GetAzureOpenAIChatClient(s_configuration).AsAIAgent(
|
||||
name: "OtherAgent",
|
||||
instructions: "You are a test agent."));
|
||||
},
|
||||
|
||||
@@ -40,7 +40,7 @@ public sealed class TimeToLiveTests(ITestOutputHelper outputHelper) : IDisposabl
|
||||
{
|
||||
// Arrange: Create agent with short TTL (10 seconds)
|
||||
TimeSpan ttl = TimeSpan.FromSeconds(10);
|
||||
AIAgent simpleAgent = TestHelper.GetAzureOpenAIChatClient(s_configuration).CreateAIAgent(
|
||||
AIAgent simpleAgent = TestHelper.GetAzureOpenAIChatClient(s_configuration).AsAIAgent(
|
||||
name: "TTLTestAgent",
|
||||
instructions: "You are a helpful assistant."
|
||||
);
|
||||
@@ -105,7 +105,7 @@ public sealed class TimeToLiveTests(ITestOutputHelper outputHelper) : IDisposabl
|
||||
{
|
||||
// Arrange: Create agent with short TTL
|
||||
TimeSpan ttl = TimeSpan.FromSeconds(6);
|
||||
AIAgent simpleAgent = TestHelper.GetAzureOpenAIChatClient(s_configuration).CreateAIAgent(
|
||||
AIAgent simpleAgent = TestHelper.GetAzureOpenAIChatClient(s_configuration).AsAIAgent(
|
||||
name: "TTLResetTestAgent",
|
||||
instructions: "You are a helpful assistant."
|
||||
);
|
||||
|
||||
+6
-6
@@ -30,7 +30,7 @@ public sealed class BasicStreamingTests : IAsyncDisposable
|
||||
// Arrange
|
||||
await this.SetupTestServerAsync();
|
||||
var chatClient = new AGUIChatClient(this._client!, "", null);
|
||||
AIAgent agent = chatClient.CreateAIAgent(instructions: null, name: "assistant", description: "Sample assistant", tools: []);
|
||||
AIAgent agent = chatClient.AsAIAgent(instructions: null, name: "assistant", description: "Sample assistant", tools: []);
|
||||
ChatClientAgentThread thread = (ChatClientAgentThread)await agent.GetNewThreadAsync();
|
||||
ChatMessage userMessage = new(ChatRole.User, "hello");
|
||||
|
||||
@@ -61,7 +61,7 @@ public sealed class BasicStreamingTests : IAsyncDisposable
|
||||
// Arrange
|
||||
await this.SetupTestServerAsync();
|
||||
var chatClient = new AGUIChatClient(this._client!, "", null);
|
||||
AIAgent agent = chatClient.CreateAIAgent(instructions: null, name: "assistant", description: "Sample assistant", tools: []);
|
||||
AIAgent agent = chatClient.AsAIAgent(instructions: null, name: "assistant", description: "Sample assistant", tools: []);
|
||||
ChatClientAgentThread thread = (ChatClientAgentThread)await agent.GetNewThreadAsync();
|
||||
ChatMessage userMessage = new(ChatRole.User, "test");
|
||||
|
||||
@@ -105,7 +105,7 @@ public sealed class BasicStreamingTests : IAsyncDisposable
|
||||
// Arrange
|
||||
await this.SetupTestServerAsync();
|
||||
var chatClient = new AGUIChatClient(this._client!, "", null);
|
||||
AIAgent agent = chatClient.CreateAIAgent(instructions: null, name: "assistant", description: "Sample assistant", tools: []);
|
||||
AIAgent agent = chatClient.AsAIAgent(instructions: null, name: "assistant", description: "Sample assistant", tools: []);
|
||||
ChatClientAgentThread thread = (ChatClientAgentThread)await agent.GetNewThreadAsync();
|
||||
ChatMessage userMessage = new(ChatRole.User, "hello");
|
||||
|
||||
@@ -124,7 +124,7 @@ public sealed class BasicStreamingTests : IAsyncDisposable
|
||||
// Arrange
|
||||
await this.SetupTestServerAsync();
|
||||
var chatClient = new AGUIChatClient(this._client!, "", null);
|
||||
AIAgent agent = chatClient.CreateAIAgent(instructions: null, name: "assistant", description: "Sample assistant", tools: []);
|
||||
AIAgent agent = chatClient.AsAIAgent(instructions: null, name: "assistant", description: "Sample assistant", tools: []);
|
||||
ChatClientAgentThread chatClientThread = (ChatClientAgentThread)await agent.GetNewThreadAsync();
|
||||
ChatMessage firstUserMessage = new(ChatRole.User, "First question");
|
||||
|
||||
@@ -168,7 +168,7 @@ public sealed class BasicStreamingTests : IAsyncDisposable
|
||||
// Arrange
|
||||
await this.SetupTestServerAsync(useMultiMessageAgent: true);
|
||||
var chatClient = new AGUIChatClient(this._client!, "", null);
|
||||
AIAgent agent = chatClient.CreateAIAgent(instructions: null, name: "assistant", description: "Sample assistant", tools: []);
|
||||
AIAgent agent = chatClient.AsAIAgent(instructions: null, name: "assistant", description: "Sample assistant", tools: []);
|
||||
ChatClientAgentThread chatClientThread = (ChatClientAgentThread)await agent.GetNewThreadAsync();
|
||||
ChatMessage userMessage = new(ChatRole.User, "Tell me a story");
|
||||
|
||||
@@ -200,7 +200,7 @@ public sealed class BasicStreamingTests : IAsyncDisposable
|
||||
// Arrange
|
||||
await this.SetupTestServerAsync();
|
||||
var chatClient = new AGUIChatClient(this._client!, "", null);
|
||||
AIAgent agent = chatClient.CreateAIAgent(instructions: null, name: "assistant", description: "Sample assistant", tools: []);
|
||||
AIAgent agent = chatClient.AsAIAgent(instructions: null, name: "assistant", description: "Sample assistant", tools: []);
|
||||
ChatClientAgentThread chatClientThread = (ChatClientAgentThread)await agent.GetNewThreadAsync();
|
||||
|
||||
// Multiple user messages sent in one turn
|
||||
|
||||
+7
-7
@@ -33,7 +33,7 @@ public sealed class SharedStateTests : IAsyncDisposable
|
||||
|
||||
await this.SetupTestServerAsync(fakeAgent);
|
||||
var chatClient = new AGUIChatClient(this._client!, "", null);
|
||||
AIAgent agent = chatClient.CreateAIAgent(instructions: null, name: "assistant", description: "Sample assistant", tools: []);
|
||||
AIAgent agent = chatClient.AsAIAgent(instructions: null, name: "assistant", description: "Sample assistant", tools: []);
|
||||
ChatClientAgentThread thread = (ChatClientAgentThread)await agent.GetNewThreadAsync();
|
||||
|
||||
string stateJson = JsonSerializer.Serialize(initialState);
|
||||
@@ -76,7 +76,7 @@ public sealed class SharedStateTests : IAsyncDisposable
|
||||
|
||||
await this.SetupTestServerAsync(fakeAgent);
|
||||
var chatClient = new AGUIChatClient(this._client!, "", null);
|
||||
AIAgent agent = chatClient.CreateAIAgent(instructions: null, name: "assistant", description: "Sample assistant", tools: []);
|
||||
AIAgent agent = chatClient.AsAIAgent(instructions: null, name: "assistant", description: "Sample assistant", tools: []);
|
||||
ChatClientAgentThread thread = (ChatClientAgentThread)await agent.GetNewThreadAsync();
|
||||
|
||||
string stateJson = JsonSerializer.Serialize(initialState);
|
||||
@@ -118,7 +118,7 @@ public sealed class SharedStateTests : IAsyncDisposable
|
||||
|
||||
await this.SetupTestServerAsync(fakeAgent);
|
||||
var chatClient = new AGUIChatClient(this._client!, "", null);
|
||||
AIAgent agent = chatClient.CreateAIAgent(instructions: null, name: "assistant", description: "Sample assistant", tools: []);
|
||||
AIAgent agent = chatClient.AsAIAgent(instructions: null, name: "assistant", description: "Sample assistant", tools: []);
|
||||
ChatClientAgentThread thread = (ChatClientAgentThread)await agent.GetNewThreadAsync();
|
||||
|
||||
string stateJson = JsonSerializer.Serialize(complexState);
|
||||
@@ -158,7 +158,7 @@ public sealed class SharedStateTests : IAsyncDisposable
|
||||
|
||||
await this.SetupTestServerAsync(fakeAgent);
|
||||
var chatClient = new AGUIChatClient(this._client!, "", null);
|
||||
AIAgent agent = chatClient.CreateAIAgent(instructions: null, name: "assistant", description: "Sample assistant", tools: []);
|
||||
AIAgent agent = chatClient.AsAIAgent(instructions: null, name: "assistant", description: "Sample assistant", tools: []);
|
||||
ChatClientAgentThread thread = (ChatClientAgentThread)await agent.GetNewThreadAsync();
|
||||
|
||||
string stateJson = JsonSerializer.Serialize(initialState);
|
||||
@@ -209,7 +209,7 @@ public sealed class SharedStateTests : IAsyncDisposable
|
||||
|
||||
await this.SetupTestServerAsync(fakeAgent);
|
||||
var chatClient = new AGUIChatClient(this._client!, "", null);
|
||||
AIAgent agent = chatClient.CreateAIAgent(instructions: null, name: "assistant", description: "Sample assistant", tools: []);
|
||||
AIAgent agent = chatClient.AsAIAgent(instructions: null, name: "assistant", description: "Sample assistant", tools: []);
|
||||
ChatClientAgentThread thread = (ChatClientAgentThread)await agent.GetNewThreadAsync();
|
||||
|
||||
ChatMessage userMessage = new(ChatRole.User, "hello");
|
||||
@@ -242,7 +242,7 @@ public sealed class SharedStateTests : IAsyncDisposable
|
||||
|
||||
await this.SetupTestServerAsync(fakeAgent);
|
||||
var chatClient = new AGUIChatClient(this._client!, "", null);
|
||||
AIAgent agent = chatClient.CreateAIAgent(instructions: null, name: "assistant", description: "Sample assistant", tools: []);
|
||||
AIAgent agent = chatClient.AsAIAgent(instructions: null, name: "assistant", description: "Sample assistant", tools: []);
|
||||
ChatClientAgentThread thread = (ChatClientAgentThread)await agent.GetNewThreadAsync();
|
||||
|
||||
string stateJson = JsonSerializer.Serialize(emptyState);
|
||||
@@ -279,7 +279,7 @@ public sealed class SharedStateTests : IAsyncDisposable
|
||||
|
||||
await this.SetupTestServerAsync(fakeAgent);
|
||||
var chatClient = new AGUIChatClient(this._client!, "", null);
|
||||
AIAgent agent = chatClient.CreateAIAgent(instructions: null, name: "assistant", description: "Sample assistant", tools: []);
|
||||
AIAgent agent = chatClient.AsAIAgent(instructions: null, name: "assistant", description: "Sample assistant", tools: []);
|
||||
ChatClientAgentThread thread = (ChatClientAgentThread)await agent.GetNewThreadAsync();
|
||||
|
||||
string stateJson = JsonSerializer.Serialize(initialState);
|
||||
|
||||
+10
-10
@@ -44,7 +44,7 @@ public sealed class ToolCallingTests : IAsyncDisposable
|
||||
|
||||
await this.SetupTestServerAsync(serverTools: [serverTool]);
|
||||
var chatClient = new AGUIChatClient(this._client!, "", null);
|
||||
AIAgent agent = chatClient.CreateAIAgent(instructions: null, name: "assistant", description: "Test assistant", tools: []);
|
||||
AIAgent agent = chatClient.AsAIAgent(instructions: null, name: "assistant", description: "Test assistant", tools: []);
|
||||
AgentThread thread = await agent.GetNewThreadAsync();
|
||||
ChatMessage userMessage = new(ChatRole.User, "Call the server function");
|
||||
|
||||
@@ -92,7 +92,7 @@ public sealed class ToolCallingTests : IAsyncDisposable
|
||||
|
||||
await this.SetupTestServerAsync(serverTools: [getWeatherTool, getTimeTool]);
|
||||
var chatClient = new AGUIChatClient(this._client!, "", null);
|
||||
AIAgent agent = chatClient.CreateAIAgent(instructions: null, name: "assistant", description: "Test assistant", tools: []);
|
||||
AIAgent agent = chatClient.AsAIAgent(instructions: null, name: "assistant", description: "Test assistant", tools: []);
|
||||
AgentThread thread = await agent.GetNewThreadAsync();
|
||||
ChatMessage userMessage = new(ChatRole.User, "What's the weather and time?");
|
||||
|
||||
@@ -133,7 +133,7 @@ public sealed class ToolCallingTests : IAsyncDisposable
|
||||
|
||||
await this.SetupTestServerAsync();
|
||||
var chatClient = new AGUIChatClient(this._client!, "", null);
|
||||
AIAgent agent = chatClient.CreateAIAgent(instructions: null, name: "assistant", description: "Test assistant", tools: [clientTool]);
|
||||
AIAgent agent = chatClient.AsAIAgent(instructions: null, name: "assistant", description: "Test assistant", tools: [clientTool]);
|
||||
AgentThread thread = await agent.GetNewThreadAsync();
|
||||
ChatMessage userMessage = new(ChatRole.User, "Call the client function");
|
||||
|
||||
@@ -181,7 +181,7 @@ public sealed class ToolCallingTests : IAsyncDisposable
|
||||
|
||||
await this.SetupTestServerAsync();
|
||||
var chatClient = new AGUIChatClient(this._client!, "", null);
|
||||
AIAgent agent = chatClient.CreateAIAgent(instructions: null, name: "assistant", description: "Test assistant", tools: [calculateTool, formatTool]);
|
||||
AIAgent agent = chatClient.AsAIAgent(instructions: null, name: "assistant", description: "Test assistant", tools: [calculateTool, formatTool]);
|
||||
AgentThread thread = await agent.GetNewThreadAsync();
|
||||
ChatMessage userMessage = new(ChatRole.User, "Calculate 5 + 3 and format 'hello'");
|
||||
|
||||
@@ -232,7 +232,7 @@ public sealed class ToolCallingTests : IAsyncDisposable
|
||||
|
||||
await this.SetupTestServerAsync(serverTools: [serverTool]);
|
||||
var chatClient = new AGUIChatClient(this._client!, "", null);
|
||||
AIAgent agent = chatClient.CreateAIAgent(instructions: null, name: "assistant", description: "Test assistant", tools: [clientTool]);
|
||||
AIAgent agent = chatClient.AsAIAgent(instructions: null, name: "assistant", description: "Test assistant", tools: [clientTool]);
|
||||
AgentThread thread = await agent.GetNewThreadAsync();
|
||||
ChatMessage userMessage = new(ChatRole.User, "Get both server and client data");
|
||||
|
||||
@@ -297,7 +297,7 @@ public sealed class ToolCallingTests : IAsyncDisposable
|
||||
|
||||
await this.SetupTestServerAsync(serverTools: [testTool]);
|
||||
var chatClient = new AGUIChatClient(this._client!, "", null);
|
||||
AIAgent agent = chatClient.CreateAIAgent(instructions: null, name: "assistant", description: "Test assistant", tools: []);
|
||||
AIAgent agent = chatClient.AsAIAgent(instructions: null, name: "assistant", description: "Test assistant", tools: []);
|
||||
AgentThread thread = await agent.GetNewThreadAsync();
|
||||
ChatMessage userMessage = new(ChatRole.User, "Call the test function");
|
||||
|
||||
@@ -341,7 +341,7 @@ public sealed class ToolCallingTests : IAsyncDisposable
|
||||
|
||||
await this.SetupTestServerAsync(serverTools: [func1, func2], triggerParallelCalls: true);
|
||||
var chatClient = new AGUIChatClient(this._client!, "", null);
|
||||
AIAgent agent = chatClient.CreateAIAgent(instructions: null, name: "assistant", description: "Test assistant", tools: []);
|
||||
AIAgent agent = chatClient.AsAIAgent(instructions: null, name: "assistant", description: "Test assistant", tools: []);
|
||||
AgentThread thread = await agent.GetNewThreadAsync();
|
||||
ChatMessage userMessage = new(ChatRole.User, "Call both functions in parallel");
|
||||
|
||||
@@ -427,7 +427,7 @@ public sealed class ToolCallingTests : IAsyncDisposable
|
||||
|
||||
await this.SetupTestServerAsync(serverTools: [serverTool], jsonSerializerOptions: ServerJsonContext.Default.Options);
|
||||
var chatClient = new AGUIChatClient(this._client!, "", null, ServerJsonContext.Default.Options);
|
||||
AIAgent agent = chatClient.CreateAIAgent(instructions: null, name: "assistant", description: "Test assistant", tools: []);
|
||||
AIAgent agent = chatClient.AsAIAgent(instructions: null, name: "assistant", description: "Test assistant", tools: []);
|
||||
AgentThread thread = await agent.GetNewThreadAsync();
|
||||
ChatMessage userMessage = new(ChatRole.User, "Get server forecast for Seattle for 5 days");
|
||||
|
||||
@@ -473,7 +473,7 @@ public sealed class ToolCallingTests : IAsyncDisposable
|
||||
|
||||
await this.SetupTestServerAsync();
|
||||
var chatClient = new AGUIChatClient(this._client!, "", null, ClientJsonContext.Default.Options);
|
||||
AIAgent agent = chatClient.CreateAIAgent(instructions: null, name: "assistant", description: "Test assistant", tools: [clientTool]);
|
||||
AIAgent agent = chatClient.AsAIAgent(instructions: null, name: "assistant", description: "Test assistant", tools: [clientTool]);
|
||||
AgentThread thread = await agent.GetNewThreadAsync();
|
||||
ChatMessage userMessage = new(ChatRole.User, "Get client forecast for Portland with hourly data");
|
||||
|
||||
@@ -518,7 +518,7 @@ public sealed class ToolCallingTests : IAsyncDisposable
|
||||
this._app = builder.Build();
|
||||
// FakeChatClient will receive options.Tools containing both server and client tools (merged by framework)
|
||||
var fakeChatClient = new FakeToolCallingChatClient(triggerParallelCalls, this._output, jsonSerializerOptions: jsonSerializerOptions);
|
||||
AIAgent baseAgent = fakeChatClient.CreateAIAgent(instructions: null, name: "base-agent", description: "A base agent for tool testing", tools: serverTools ?? []);
|
||||
AIAgent baseAgent = fakeChatClient.AsAIAgent(instructions: null, name: "base-agent", description: "A base agent for tool testing", tools: serverTools ?? []);
|
||||
this._app.MapAGUI("/agent", baseAgent);
|
||||
|
||||
await this._app.StartAsync();
|
||||
|
||||
+24
-24
@@ -210,10 +210,10 @@ public sealed class OpenAIAssistantClientExtensionsTests
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verify that GetAIAgent with ClientResult and options works correctly.
|
||||
/// Verify that AsAIAgent with ClientResult and options works correctly.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void GetAIAgent_WithClientResultAndOptions_WorksCorrectly()
|
||||
public void AsAIAgent_WithClientResultAndOptions_WorksCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
var assistantClient = new TestAssistantClient();
|
||||
@@ -228,7 +228,7 @@ public sealed class OpenAIAssistantClientExtensionsTests
|
||||
};
|
||||
|
||||
// Act
|
||||
var agent = assistantClient.GetAIAgent(clientResult, options);
|
||||
var agent = assistantClient.AsAIAgent(clientResult, options);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(agent);
|
||||
@@ -238,10 +238,10 @@ public sealed class OpenAIAssistantClientExtensionsTests
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verify that GetAIAgent with Assistant and options works correctly.
|
||||
/// Verify that AsAIAgent with Assistant and options works correctly.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void GetAIAgent_WithAssistantAndOptions_WorksCorrectly()
|
||||
public void AsAIAgent_WithAssistantAndOptions_WorksCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
var assistantClient = new TestAssistantClient();
|
||||
@@ -255,7 +255,7 @@ public sealed class OpenAIAssistantClientExtensionsTests
|
||||
};
|
||||
|
||||
// Act
|
||||
var agent = assistantClient.GetAIAgent(assistant, options);
|
||||
var agent = assistantClient.AsAIAgent(assistant, options);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(agent);
|
||||
@@ -265,10 +265,10 @@ public sealed class OpenAIAssistantClientExtensionsTests
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verify that GetAIAgent with Assistant and options falls back to assistant metadata when options are null.
|
||||
/// Verify that AsAIAgent with Assistant and options falls back to assistant metadata when options are null.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void GetAIAgent_WithAssistantAndOptionsWithNullFields_FallsBackToAssistantMetadata()
|
||||
public void AsAIAgent_WithAssistantAndOptionsWithNullFields_FallsBackToAssistantMetadata()
|
||||
{
|
||||
// Arrange
|
||||
var assistantClient = new TestAssistantClient();
|
||||
@@ -277,7 +277,7 @@ public sealed class OpenAIAssistantClientExtensionsTests
|
||||
var options = new ChatClientAgentOptions(); // Empty options
|
||||
|
||||
// Act
|
||||
var agent = assistantClient.GetAIAgent(assistant, options);
|
||||
var agent = assistantClient.AsAIAgent(assistant, options);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(agent);
|
||||
@@ -341,10 +341,10 @@ public sealed class OpenAIAssistantClientExtensionsTests
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verify that GetAIAgent with clientFactory parameter correctly applies the factory.
|
||||
/// Verify that AsAIAgent with clientFactory parameter correctly applies the factory.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void GetAIAgent_WithClientFactory_AppliesFactoryCorrectly()
|
||||
public void AsAIAgent_WithClientFactory_AppliesFactoryCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
var assistantClient = new TestAssistantClient();
|
||||
@@ -357,7 +357,7 @@ public sealed class OpenAIAssistantClientExtensionsTests
|
||||
};
|
||||
|
||||
// Act
|
||||
var agent = assistantClient.GetAIAgent(
|
||||
var agent = assistantClient.AsAIAgent(
|
||||
assistant,
|
||||
options,
|
||||
clientFactory: (innerClient) => testChatClient);
|
||||
@@ -373,10 +373,10 @@ public sealed class OpenAIAssistantClientExtensionsTests
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verify that GetAIAgent throws ArgumentNullException when assistantClientResult is null.
|
||||
/// Verify that AsAIAgent throws ArgumentNullException when assistantClientResult is null.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void GetAIAgent_WithNullClientResult_ThrowsArgumentNullException()
|
||||
public void AsAIAgent_WithNullClientResult_ThrowsArgumentNullException()
|
||||
{
|
||||
// Arrange
|
||||
var assistantClient = new TestAssistantClient();
|
||||
@@ -384,16 +384,16 @@ public sealed class OpenAIAssistantClientExtensionsTests
|
||||
|
||||
// Act & Assert
|
||||
var exception = Assert.Throws<ArgumentNullException>(() =>
|
||||
assistantClient.GetAIAgent((ClientResult<Assistant>)null!, options));
|
||||
assistantClient.AsAIAgent(null!, options));
|
||||
|
||||
Assert.Equal("assistantClientResult", exception.ParamName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verify that GetAIAgent throws ArgumentNullException when assistant is null.
|
||||
/// Verify that AsAIAgent throws ArgumentNullException when assistant is null.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void GetAIAgent_WithNullAssistant_ThrowsArgumentNullException()
|
||||
public void AsAIAgent_WithNullAssistant_ThrowsArgumentNullException()
|
||||
{
|
||||
// Arrange
|
||||
var assistantClient = new TestAssistantClient();
|
||||
@@ -401,16 +401,16 @@ public sealed class OpenAIAssistantClientExtensionsTests
|
||||
|
||||
// Act & Assert
|
||||
var exception = Assert.Throws<ArgumentNullException>(() =>
|
||||
assistantClient.GetAIAgent((Assistant)null!, options));
|
||||
assistantClient.AsAIAgent((Assistant)null!, options));
|
||||
|
||||
Assert.Equal("assistantMetadata", exception.ParamName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verify that GetAIAgent throws ArgumentNullException when options is null.
|
||||
/// Verify that AsAIAgent throws ArgumentNullException when options is null.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void GetAIAgent_WithNullOptions_ThrowsArgumentNullException()
|
||||
public void AsAIAgent_WithNullOptions_ThrowsArgumentNullException()
|
||||
{
|
||||
// Arrange
|
||||
var assistantClient = new TestAssistantClient();
|
||||
@@ -418,7 +418,7 @@ public sealed class OpenAIAssistantClientExtensionsTests
|
||||
|
||||
// Act & Assert
|
||||
var exception = Assert.Throws<ArgumentNullException>(() =>
|
||||
assistantClient.GetAIAgent(assistant, (ChatClientAgentOptions)null!));
|
||||
assistantClient.AsAIAgent(assistant, (ChatClientAgentOptions)null!));
|
||||
|
||||
Assert.Equal("options", exception.ParamName);
|
||||
}
|
||||
@@ -518,10 +518,10 @@ public sealed class OpenAIAssistantClientExtensionsTests
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verify that GetAIAgent with services parameter correctly passes it through to the ChatClientAgent.
|
||||
/// Verify that AsAIAgent with services parameter correctly passes it through to the ChatClientAgent.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void GetAIAgent_WithServices_PassesServicesToAgent()
|
||||
public void AsAIAgent_WithServices_PassesServicesToAgent()
|
||||
{
|
||||
// Arrange
|
||||
var assistantClient = new TestAssistantClient();
|
||||
@@ -529,7 +529,7 @@ public sealed class OpenAIAssistantClientExtensionsTests
|
||||
var assistant = ModelReaderWriter.Read<Assistant>(BinaryData.FromString("""{"id": "asst_abc123", "name": "Test Agent"}"""))!;
|
||||
|
||||
// Act
|
||||
var agent = assistantClient.GetAIAgent(assistant, services: serviceProvider);
|
||||
var agent = assistantClient.AsAIAgent(assistant, services: serviceProvider);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(agent);
|
||||
|
||||
+7
-7
@@ -76,7 +76,7 @@ public sealed class OpenAIChatClientExtensionsTests
|
||||
var testChatClient = new TestChatClient(chatClient.AsIChatClient());
|
||||
|
||||
// Act
|
||||
var agent = chatClient.CreateAIAgent(
|
||||
var agent = chatClient.AsAIAgent(
|
||||
instructions: "Test instructions",
|
||||
name: "Test Agent",
|
||||
description: "Test description",
|
||||
@@ -104,7 +104,7 @@ public sealed class OpenAIChatClientExtensionsTests
|
||||
TestChatClient? testChatClient = null;
|
||||
|
||||
// Act
|
||||
var agent = chatClient.CreateAIAgent(
|
||||
var agent = chatClient.AsAIAgent(
|
||||
instructions: "Test instructions",
|
||||
clientFactory: (innerClient) =>
|
||||
innerClient.AsBuilder().Use((innerClient) => testChatClient = new TestChatClient(innerClient)).Build());
|
||||
@@ -135,7 +135,7 @@ public sealed class OpenAIChatClientExtensionsTests
|
||||
};
|
||||
|
||||
// Act
|
||||
var agent = chatClient.CreateAIAgent(
|
||||
var agent = chatClient.AsAIAgent(
|
||||
options,
|
||||
clientFactory: (innerClient) => testChatClient);
|
||||
|
||||
@@ -160,7 +160,7 @@ public sealed class OpenAIChatClientExtensionsTests
|
||||
var chatClient = new TestOpenAIChatClient();
|
||||
|
||||
// Act
|
||||
var agent = chatClient.CreateAIAgent(
|
||||
var agent = chatClient.AsAIAgent(
|
||||
instructions: "Test instructions",
|
||||
name: "Test Agent");
|
||||
|
||||
@@ -183,7 +183,7 @@ public sealed class OpenAIChatClientExtensionsTests
|
||||
var chatClient = new TestOpenAIChatClient();
|
||||
|
||||
// Act
|
||||
var agent = chatClient.CreateAIAgent(
|
||||
var agent = chatClient.AsAIAgent(
|
||||
instructions: "Test instructions",
|
||||
name: "Test Agent",
|
||||
clientFactory: null);
|
||||
@@ -205,7 +205,7 @@ public sealed class OpenAIChatClientExtensionsTests
|
||||
{
|
||||
// Act & Assert
|
||||
var exception = Assert.Throws<ArgumentNullException>(() =>
|
||||
((OpenAIChatClient)null!).CreateAIAgent());
|
||||
((OpenAIChatClient)null!).AsAIAgent());
|
||||
|
||||
Assert.Equal("client", exception.ParamName);
|
||||
}
|
||||
@@ -221,7 +221,7 @@ public sealed class OpenAIChatClientExtensionsTests
|
||||
|
||||
// Act & Assert
|
||||
var exception = Assert.Throws<ArgumentNullException>(() =>
|
||||
chatClient.CreateAIAgent((ChatClientAgentOptions)null!));
|
||||
chatClient.AsAIAgent((ChatClientAgentOptions)null!));
|
||||
|
||||
Assert.Equal("options", exception.ParamName);
|
||||
}
|
||||
|
||||
+8
-8
@@ -75,7 +75,7 @@ public sealed class OpenAIResponseClientExtensionsTests
|
||||
var testChatClient = new TestChatClient(responseClient.AsIChatClient());
|
||||
|
||||
// Act
|
||||
var agent = responseClient.CreateAIAgent(
|
||||
var agent = responseClient.AsAIAgent(
|
||||
instructions: "Test instructions",
|
||||
name: "Test Agent",
|
||||
description: "Test description",
|
||||
@@ -102,7 +102,7 @@ public sealed class OpenAIResponseClientExtensionsTests
|
||||
var responseClient = new TestOpenAIResponseClient();
|
||||
|
||||
// Act
|
||||
var agent = responseClient.CreateAIAgent(
|
||||
var agent = responseClient.AsAIAgent(
|
||||
instructions: "Test instructions",
|
||||
name: "Test Agent");
|
||||
|
||||
@@ -125,7 +125,7 @@ public sealed class OpenAIResponseClientExtensionsTests
|
||||
var responseClient = new TestOpenAIResponseClient();
|
||||
|
||||
// Act
|
||||
var agent = responseClient.CreateAIAgent(
|
||||
var agent = responseClient.AsAIAgent(
|
||||
instructions: "Test instructions",
|
||||
name: "Test Agent",
|
||||
clientFactory: null);
|
||||
@@ -147,7 +147,7 @@ public sealed class OpenAIResponseClientExtensionsTests
|
||||
{
|
||||
// Act & Assert
|
||||
var exception = Assert.Throws<ArgumentNullException>(() =>
|
||||
((ResponsesClient)null!).CreateAIAgent());
|
||||
((ResponsesClient)null!).AsAIAgent());
|
||||
|
||||
Assert.Equal("client", exception.ParamName);
|
||||
}
|
||||
@@ -163,7 +163,7 @@ public sealed class OpenAIResponseClientExtensionsTests
|
||||
|
||||
// Act & Assert
|
||||
var exception = Assert.Throws<ArgumentNullException>(() =>
|
||||
responseClient.CreateAIAgent((ChatClientAgentOptions)null!));
|
||||
responseClient.AsAIAgent((ChatClientAgentOptions)null!));
|
||||
|
||||
Assert.Equal("options", exception.ParamName);
|
||||
}
|
||||
@@ -179,7 +179,7 @@ public sealed class OpenAIResponseClientExtensionsTests
|
||||
var serviceProvider = new TestServiceProvider();
|
||||
|
||||
// Act
|
||||
var agent = responseClient.CreateAIAgent(
|
||||
var agent = responseClient.AsAIAgent(
|
||||
instructions: "Test instructions",
|
||||
name: "Test Agent",
|
||||
services: serviceProvider);
|
||||
@@ -211,7 +211,7 @@ public sealed class OpenAIResponseClientExtensionsTests
|
||||
};
|
||||
|
||||
// Act
|
||||
var agent = responseClient.CreateAIAgent(options, services: serviceProvider);
|
||||
var agent = responseClient.AsAIAgent(options, services: serviceProvider);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(agent);
|
||||
@@ -237,7 +237,7 @@ public sealed class OpenAIResponseClientExtensionsTests
|
||||
var testChatClient = new TestChatClient(responseClient.AsIChatClient());
|
||||
|
||||
// Act
|
||||
var agent = responseClient.CreateAIAgent(
|
||||
var agent = responseClient.AsAIAgent(
|
||||
instructions: "Test instructions",
|
||||
name: "Test Agent",
|
||||
clientFactory: (innerClient) => testChatClient,
|
||||
|
||||
@@ -19,7 +19,7 @@ public sealed class ChatClientExtensionsTests
|
||||
var chatClientMock = new Mock<IChatClient>();
|
||||
|
||||
// Act
|
||||
var agent = chatClientMock.Object.CreateAIAgent(
|
||||
var agent = chatClientMock.Object.AsAIAgent(
|
||||
instructions: "Test instructions",
|
||||
name: "TestAgent",
|
||||
description: "Test description"
|
||||
@@ -40,7 +40,7 @@ public sealed class ChatClientExtensionsTests
|
||||
var tools = new List<AITool> { new Mock<AITool>().Object };
|
||||
|
||||
// Act
|
||||
var agent = chatClientMock.Object.CreateAIAgent(tools: tools);
|
||||
var agent = chatClientMock.Object.AsAIAgent(tools: tools);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(agent);
|
||||
@@ -62,7 +62,7 @@ public sealed class ChatClientExtensionsTests
|
||||
};
|
||||
|
||||
// Act
|
||||
var agent = chatClientMock.Object.CreateAIAgent(options);
|
||||
var agent = chatClientMock.Object.AsAIAgent(options);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(agent);
|
||||
@@ -79,7 +79,7 @@ public sealed class ChatClientExtensionsTests
|
||||
IChatClient chatClient = null!;
|
||||
|
||||
// Act & Assert
|
||||
Assert.Throws<ArgumentNullException>(() => chatClient.CreateAIAgent(instructions: "instructions"));
|
||||
Assert.Throws<ArgumentNullException>(() => chatClient.AsAIAgent(instructions: "instructions"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -89,6 +89,6 @@ public sealed class ChatClientExtensionsTests
|
||||
IChatClient chatClient = null!;
|
||||
|
||||
// Act & Assert
|
||||
Assert.Throws<ArgumentNullException>(() => chatClient.CreateAIAgent(options: new() { ChatOptions = new() { Instructions = "instructions" } }));
|
||||
Assert.Throws<ArgumentNullException>(() => chatClient.AsAIAgent(options: new() { ChatOptions = new() { Instructions = "instructions" } }));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user