Skip to content

Commit 3bc6dee

Browse files
committed
Adapt to new breaking changes in AF
1 parent c4bfb30 commit 3bc6dee

File tree

7 files changed

+24
-22
lines changed

7 files changed

+24
-22
lines changed

sample/Server/AgentDiscoveryExtensions.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
using System.Diagnostics.CodeAnalysis;
22
using System.Text.Json.Serialization;
3-
using Microsoft.Agents.AI.Hosting;
3+
using Microsoft.Agents.AI;
44

55
static class AgentDiscoveryExtensions
66
{
77
public static void MapAgentDiscovery(this IEndpointRouteBuilder endpoints, [StringSyntax("Route")] string path)
88
{
99
var routeGroup = endpoints.MapGroup(path);
10-
routeGroup.MapGet("/", async (AgentCatalog catalog, CancellationToken cancellation)
11-
=> Results.Ok(await catalog
12-
.GetAgentsAsync(cancellation)
13-
.Select(agent => new AgentDiscoveryCard(agent.Name!, agent.Description))
14-
.ToArrayAsync()))
10+
routeGroup.MapGet("/", () => Results.Ok(endpoints.ServiceProvider
11+
.GetKeyedServices<AIAgent>(KeyedService.AnyKey)
12+
.Select(agent => new AgentDiscoveryCard(agent.Name!, agent.Description)).ToArray()))
1513
.WithName("GetAgents");
1614
}
1715

sample/Server/ConsoleExtensions.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using Devlooped.Agents.AI;
22
using Devlooped.Extensions.AI;
3-
using Microsoft.Agents.AI.Hosting;
3+
using Microsoft.Agents.AI;
44
using Microsoft.Extensions.AI;
55
using Newtonsoft.Json;
66
using Newtonsoft.Json.Serialization;
@@ -13,7 +13,6 @@ public static class ConsoleExtensions
1313
{
1414
public async ValueTask RenderAgentsAsync(IServiceCollection collection)
1515
{
16-
var catalog = services.GetRequiredService<AgentCatalog>();
1716
var settings = new JsonSerializerSettings
1817
{
1918
NullValueHandling = NullValueHandling.Include,
@@ -38,8 +37,12 @@ public async ValueTask RenderAgentsAsync(IServiceCollection collection)
3837
}
3938

4039
// List configured agents
41-
await foreach (var agent in catalog.GetAgentsAsync())
40+
foreach (var descriptor in collection.AsEnumerable().Where(x => x.ServiceKey != null && x.ServiceType == typeof(AIAgent)))
4241
{
42+
var agent = services.GetKeyedService<AIAgent>(descriptor.ServiceKey);
43+
if (agent is null)
44+
continue;
45+
4346
var metadata = agent.GetService<ConfigurableAIAgentMetadata>();
4447

4548
AnsiConsole.Write(new Panel(new JsonText(JsonConvert.SerializeObject(new { Agent = agent, Metadata = metadata }, settings)))

sample/Server/Program.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
using System.Text;
33
using Devlooped.Extensions.AI;
44
using Microsoft.Agents.AI;
5-
using Microsoft.Agents.AI.Hosting;
6-
using Microsoft.Agents.AI.Hosting.OpenAI;
75
using Microsoft.Extensions.AI;
86
using Spectre.Console;
97

@@ -45,9 +43,8 @@
4543
#endif
4644

4745
// Map each agent's endpoints via response API
48-
var catalog = app.Services.GetRequiredService<AgentCatalog>();
4946
// List configured agents
50-
await foreach (var agent in catalog.GetAgentsAsync())
47+
foreach (var agent in app.Services.GetKeyedServices<AIAgent>(KeyedService.AnyKey))
5148
{
5249
if (agent.Name != null)
5350
app.MapOpenAIResponses(agent.Name);

sample/Server/Server.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
</PropertyGroup>
77

88
<ItemGroup>
9-
<PackageReference Include="Microsoft.Agents.AI.Hosting.OpenAI" Version="42.42.11-pre" />
9+
<PackageReference Include="Microsoft.Agents.AI.Hosting.OpenAI" Version="42.42.12-pre" />
1010
<PackageReference Include="ModelContextProtocol" Version="0.4.0-preview.3" />
1111
<PackageReference Include="Newtonsoft.Json" Version="13.0.4" />
1212
<PackageReference Include="ThisAssembly.Project" Version="2.1.2" PrivateAssets="all" />

src/Agents/Agents.csproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@
2323
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="10.0.0" />
2424
<PackageReference Include="Microsoft.Extensions.Logging" Version="10.0.0" />
2525

26-
<PackageReference Include="Microsoft.Agents.AI" Version="42.42.11-pre" />
27-
<PackageReference Include="Microsoft.Agents.AI.Hosting" Version="42.42.11-pre" />
28-
<PackageReference Include="Microsoft.Agents.AI.AzureAI" Version="42.42.11-pre" />
29-
<PackageReference Include="Microsoft.Agents.AI.OpenAI" Version="42.42.11-pre" />
26+
<PackageReference Include="Microsoft.Agents.AI" Version="42.42.12-pre" />
27+
<PackageReference Include="Microsoft.Agents.AI.Hosting" Version="42.42.12-pre" />
28+
<PackageReference Include="Microsoft.Agents.AI.AzureAI" Version="42.42.12-pre" />
29+
<PackageReference Include="Microsoft.Agents.AI.OpenAI" Version="42.42.12-pre" />
3030
<PackageReference Include="ModelContextProtocol" Version="0.4.0-preview.3" />
3131
<PackageReference Include="PolySharp" Version="1.15.0" PrivateAssets="all" />
3232
<PackageReference Include="YamlDotNet" Version="16.3.0" />

src/Agents/ConfigurableAIAgent.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,11 @@ void OnReload(object? state)
236236

237237
internal class AgentClientOptions : ChatClientAgentOptions
238238
{
239+
public string? Instructions
240+
{
241+
get => ChatOptions?.Instructions;
242+
set => (ChatOptions ??= new()).Instructions = value;
243+
}
239244
public string? Client { get; set; }
240245
public string? Model { get; set; }
241246
public IList<string>? Use { get; set; }

src/Tests/ConfigurableAgentTests.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using Devlooped.Extensions.AI;
2-
using Devlooped.Extensions.AI.Grok;
32
using Microsoft.Agents.AI;
43
using Microsoft.Extensions.AI;
54
using Microsoft.Extensions.Configuration;
@@ -139,7 +138,7 @@ Line 3
139138
- Step 1
140139
- Step 2
141140
- Step 3
142-
""", agent.GetService<ChatClientAgentOptions>()?.Instructions);
141+
""", agent.GetService<ChatClientAgentOptions>()?.ChatOptions?.Instructions);
143142
}
144143

145144
[Fact]
@@ -166,7 +165,7 @@ public void CanReloadConfiguration()
166165
var agent = app.Services.GetRequiredKeyedService<AIAgent>("bot");
167166

168167
Assert.Equal("Helpful chat agent", agent.Description);
169-
Assert.Equal("You are a helpful agent.", agent.GetService<ChatClientAgentOptions>()?.Instructions);
168+
Assert.Equal("You are a helpful agent.", agent.GetService<ChatClientAgentOptions>()?.ChatOptions?.Instructions);
170169
Assert.Equal("openai", agent.GetService<AIAgentMetadata>()?.ProviderName);
171170

172171
// Change the configuration to point to a different client
@@ -179,7 +178,7 @@ public void CanReloadConfiguration()
179178
configuration.Reload();
180179

181180
Assert.Equal("Very helpful chat agent", agent.Description);
182-
Assert.Equal("You are a very helpful chat agent.", agent.GetService<ChatClientAgentOptions>()?.Instructions);
181+
Assert.Equal("You are a very helpful chat agent.", agent.GetService<ChatClientAgentOptions>()?.ChatOptions?.Instructions);
183182
Assert.Equal("xai", agent.GetService<AIAgentMetadata>()?.ProviderName);
184183
}
185184

0 commit comments

Comments
 (0)