Skip to content

Commit c64ad1b

Browse files
committed
- Added support for setting AIContextProviderFactory and ChatMessageStoreFactory on Agents
- Removed obsolete `OpenAIAgentOptionsForChatClientWithoutReasoning`, `OpenAIAgentOptionsForChatClientWithReasoning`, `OpenAIAgentOptionsForResponseApiWithoutReasoning` and `OpenAIAgentOptionsForResponseApiWithReasoning` (Use `AgentOptions` instead) - Added missing Dependency Injection options for EmbeddingFactory in Providers `Mistral` and `OpenRouter` - [BREAKING] Athropic: Renamed 'maxTokenCount' to 'maxOutputTokens' to have consistent naming in the simplified CreateAgent method
1 parent 97ce5a9 commit c64ad1b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+869
-810
lines changed

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* text=auto eol=crlf

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
# Changelog - Agent Framework Toolkit
22

33
## Unreleased
4-
- [BREAKING] Athropic: Renamed 'maxTokenCount' to 'maxOutputTokens' to have consitent naming in the simplified CreateAgent method
4+
- Added support for setting `AIContextProviderFactory` and `ChatMessageStoreFactory` on Agents
5+
- Removed obsolete `OpenAIAgentOptionsForChatClientWithoutReasoning`, `OpenAIAgentOptionsForChatClientWithReasoning`, `OpenAIAgentOptionsForResponseApiWithoutReasoning` and `OpenAIAgentOptionsForResponseApiWithReasoning` (Use `AgentOptions` instead)
6+
- Added missing Dependency Injection options for EmbeddingFactory in Providers `Mistral` and `OpenRouter`
7+
- [BREAKING] Athropic: Renamed 'maxTokenCount' to 'maxOutputTokens' to have consistent naming in the simplified CreateAgent method
58

69
---
710

development/Tests/AIToolsFactoryTests.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using AgentFrameworkToolkit.Tools.ModelContextProtocol;
33
using JetBrains.Annotations;
44
using Microsoft.Extensions.AI;
5+
using Microsoft.Extensions.DependencyInjection;
56

67
namespace AgentFrameworkToolkit.Tests;
78

@@ -64,6 +65,19 @@ public async Task GetLocalMcpToolsAsync()
6465
Assert.Contains("browser_click", clientTools.Tools.Select(x => x.Name));
6566
}
6667

68+
[Fact]
69+
public void InjectAIToolFactoryFactoryTest()
70+
{
71+
ServiceCollection services = new();
72+
services.AddAIToolFactory();
73+
74+
ServiceProvider provider = services.BuildServiceProvider();
75+
76+
AIToolsFactory aiToolsFactory = provider.GetRequiredService<AIToolsFactory>();
77+
IList<AITool> tools = aiToolsFactory.GetTools(typeof(DiTools));
78+
Assert.Single(tools);
79+
}
80+
6781
[PublicAPI]
6882
private class TestToolsWithAttributes
6983
{
@@ -96,4 +110,13 @@ private string NotATool(string input1)
96110
return input1;
97111
}
98112
}
113+
114+
private class DiTools
115+
{
116+
[AITool]
117+
public static string GetWeather(string city)
118+
{
119+
return "{ \"condition\": \"sunny\", \"degrees\":19 }";
120+
}
121+
}
99122
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
using AgentFrameworkToolkit.Anthropic;
2+
using Microsoft.Extensions.DependencyInjection;
3+
using Secrets;
4+
5+
namespace AgentFrameworkToolkit.Tests;
6+
7+
[Collection("AgentFactoryTests")]
8+
public sealed class AnthropicAgentFactoryTests : TestsBase
9+
{
10+
[Fact]
11+
public Task AgentFactory_Simple() => SimpleAgentTestsAsync(AgentProvider.Anthropic);
12+
13+
[Fact]
14+
public Task AgentFactory_Normal() => NormalAgentTestsAsync(AgentProvider.Anthropic);
15+
16+
[Fact]
17+
public Task AgentFactory_OpenTelemetryAndLoggingMiddleware() => OpenTelemetryAndLoggingMiddlewareTestsAsync(AgentProvider.Anthropic);
18+
19+
[Fact]
20+
public Task AgentFactory_ToolCall() => ToolCallAgentTestsAsync(AgentProvider.Anthropic);
21+
22+
[Fact]
23+
public Task AgentFactory_McpToolCall() => McpToolCallAgentTestsAsync(AgentProvider.Anthropic);
24+
25+
[Fact]
26+
public async Task AgentFactory_DependencyInjection()
27+
{
28+
var secrets = SecretsManager.GetSecrets();
29+
ServiceCollection services = new();
30+
services.AddAnthropicAgentFactory(secrets.AnthropicApiKey);
31+
32+
ServiceProvider provider = services.BuildServiceProvider();
33+
34+
var cancellationToken = TestContext.Current.CancellationToken;
35+
string text = (await provider.GetRequiredService<AnthropicAgentFactory>()
36+
.CreateAgent(AnthropicChatModels.ClaudeHaiku45, 2000)
37+
.RunAsync("Hello", cancellationToken: cancellationToken)).Text;
38+
Assert.NotEmpty(text);
39+
}
40+
41+
[Fact]
42+
public async Task AgentFactory_DependencyInjection_Connection()
43+
{
44+
var secrets = SecretsManager.GetSecrets();
45+
ServiceCollection services = new();
46+
services.AddAnthropicAgentFactory(new AnthropicConnection
47+
{
48+
ApiKey = secrets.AnthropicApiKey,
49+
NetworkTimeout = TimeSpan.FromSeconds(10)
50+
});
51+
52+
ServiceProvider provider = services.BuildServiceProvider();
53+
54+
var cancellationToken = TestContext.Current.CancellationToken;
55+
string text = (await provider.GetRequiredService<AnthropicAgentFactory>()
56+
.CreateAgent(AnthropicChatModels.ClaudeHaiku45, 2000)
57+
.RunAsync("Hello", cancellationToken: cancellationToken)).Text;
58+
Assert.NotEmpty(text);
59+
}
60+
}
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
using AgentFrameworkToolkit.AzureOpenAI;
2+
using AgentFrameworkToolkit.OpenAI;
3+
using Microsoft.Extensions.AI;
4+
using Microsoft.Extensions.DependencyInjection;
5+
using Secrets;
6+
7+
namespace AgentFrameworkToolkit.Tests;
8+
9+
[Collection("AgentFactoryTests")]
10+
public sealed class AzureOpenAIChatClientAgentFactoryTests : TestsBase
11+
{
12+
[Fact]
13+
public Task AgentFactory_Simple_ChatClient() => SimpleAgentTestsAsync(AgentProvider.AzureOpenAIChatClient);
14+
15+
[Fact]
16+
public Task AgentFactory_Normal_ChatClient() => NormalAgentTestsAsync(AgentProvider.AzureOpenAIChatClient);
17+
18+
[Fact]
19+
public Task AgentFactory_OpenTelemetryAndLoggingMiddleware_ChatClient() => OpenTelemetryAndLoggingMiddlewareTestsAsync(AgentProvider.AzureOpenAIChatClient);
20+
21+
[Fact]
22+
public Task AgentFactory_ToolCall_ChatClient() => ToolCallAgentTestsAsync(AgentProvider.AzureOpenAIChatClient);
23+
24+
[Fact]
25+
public Task AgentFactory_McpToolCall_ChatClient() => McpToolCallAgentTestsAsync(AgentProvider.AzureOpenAIChatClient);
26+
27+
[Fact]
28+
public Task AgentFactory_StructuredOutput_ChatClient() => StructuredOutputAgentTestsAsync(AgentProvider.AzureOpenAIChatClient);
29+
30+
[Fact]
31+
public Task AgentFactory_Simple_ResponsesApi() => SimpleAgentTestsAsync(AgentProvider.AzureOpenAIResponsesApi);
32+
33+
[Fact]
34+
public Task AgentFactory_Normal_ResponsesApi() => NormalAgentTestsAsync(AgentProvider.AzureOpenAIResponsesApi);
35+
36+
[Fact]
37+
public Task AgentFactory_OpenTelemetryAndLoggingMiddleware_ResponsesApi() => OpenTelemetryAndLoggingMiddlewareTestsAsync(AgentProvider.AzureOpenAIResponsesApi);
38+
39+
[Fact]
40+
public Task AgentFactory_ToolCall_ResponsesApi() => ToolCallAgentTestsAsync(AgentProvider.AzureOpenAIResponsesApi);
41+
42+
[Fact]
43+
public Task AgentFactory_McpToolCall_ResponsesApi() => McpToolCallAgentTestsAsync(AgentProvider.AzureOpenAIResponsesApi);
44+
45+
[Fact]
46+
public Task AgentFactory_StructuredOutput_ResponsesApi() => StructuredOutputAgentTestsAsync(AgentProvider.AzureOpenAIResponsesApi);
47+
48+
[Fact]
49+
public async Task AgentFactory_DependencyInjection()
50+
{
51+
var secrets = SecretsManager.GetSecrets();
52+
ServiceCollection services = new();
53+
services.AddAzureOpenAIAgentFactory(secrets.AzureOpenAiEndpoint, secrets.AzureOpenAiKey);
54+
55+
ServiceProvider provider = services.BuildServiceProvider();
56+
57+
var cancellationToken = TestContext.Current.CancellationToken;
58+
string text = (await provider.GetRequiredService<AzureOpenAIAgentFactory>()
59+
.CreateAgent(OpenAIChatModels.Gpt5Nano)
60+
.RunAsync("Hello", cancellationToken: cancellationToken)).Text;
61+
Assert.NotEmpty(text);
62+
}
63+
64+
[Fact]
65+
public async Task AgentFactory_DependencyInjection_Connection()
66+
{
67+
var secrets = SecretsManager.GetSecrets();
68+
ServiceCollection services = new();
69+
services.AddAzureOpenAIAgentFactory(new AzureOpenAIConnection
70+
{
71+
Endpoint = secrets.AzureOpenAiEndpoint,
72+
ApiKey = secrets.AzureOpenAiKey,
73+
NetworkTimeout = TimeSpan.FromSeconds(10)
74+
});
75+
76+
ServiceProvider provider = services.BuildServiceProvider();
77+
78+
var cancellationToken = TestContext.Current.CancellationToken;
79+
string text = (await provider.GetRequiredService<AzureOpenAIAgentFactory>()
80+
.CreateAgent(OpenAIChatModels.Gpt5Nano)
81+
.RunAsync("Hello", cancellationToken: cancellationToken)).Text;
82+
Assert.NotEmpty(text);
83+
}
84+
85+
[Fact]
86+
public async Task EmbeddingFactory()
87+
{
88+
Secrets.Secrets secrets = SecretsManager.GetSecrets();
89+
AzureOpenAIEmbeddingFactory factory = new(secrets.AzureOpenAiEndpoint, secrets.AzureOpenAiKey);
90+
IEmbeddingGenerator<string, Embedding<float>> generator = factory.GetEmbeddingGenerator("text-embedding-3-small");
91+
Embedding<float> embedding = await generator.GenerateAsync("Hello", cancellationToken: TestContext.Current.CancellationToken);
92+
Assert.Equal(1536, embedding.Dimensions);
93+
}
94+
95+
[Fact]
96+
public async Task EmbeddingFactory_DependencyInjection()
97+
{
98+
var secrets = SecretsManager.GetSecrets();
99+
ServiceCollection services = new();
100+
services.AddAzureOpenAIEmbeddingFactory(secrets.AzureOpenAiEndpoint, secrets.AzureOpenAiKey);
101+
102+
ServiceProvider provider = services.BuildServiceProvider();
103+
104+
AzureOpenAIEmbeddingFactory embeddingFactory = provider.GetRequiredService<AzureOpenAIEmbeddingFactory>();
105+
var cancellationToken = TestContext.Current.CancellationToken;
106+
Embedding<float> embedding = await embeddingFactory.GetEmbeddingGenerator("text-embedding-3-small")
107+
.GenerateAsync("Hello", cancellationToken: cancellationToken);
108+
Assert.Equal(1536, embedding.Dimensions);
109+
}
110+
}

development/Tests/DependencyInjectionTests.cs

Lines changed: 0 additions & 148 deletions
This file was deleted.

0 commit comments

Comments
 (0)