Skip to content

Commit 3e396e7

Browse files
authored
Merge branch 'main' into feature/azure-ai-inference-client
2 parents f441aa5 + c74c2d6 commit 3e396e7

File tree

128 files changed

+6795
-5132
lines changed

Some content is hidden

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

128 files changed

+6795
-5132
lines changed

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ Currently, there are three main APIs your application can target:
5656

5757
- [Core](https://microsoft.github.io/autogen/dev/user-guide/core-user-guide/index.html)
5858
- [AgentChat](https://microsoft.github.io/autogen/dev/user-guide/agentchat-user-guide/index.html)
59-
- [Extensions](https://microsoft.github.io/autogen/dev/reference/python/autogen_ext/autogen_ext.html)
59+
- [Extensions](https://microsoft.github.io/autogen/dev/user-guide/extensions-user-guide/index.html)
6060

6161
## Core
6262

@@ -186,9 +186,9 @@ await app.WaitForShutdownAsync();
186186

187187
[TopicSubscription("agents")]
188188
public class HelloAgent(
189-
IAgentContext context,
189+
IAgentContext worker,
190190
[FromKeyedServices("EventTypes")] EventTypes typeRegistry) : ConsoleAgent(
191-
context,
191+
worker,
192192
typeRegistry),
193193
ISayHello,
194194
IHandle<NewMessageReceived>,

dotnet/samples/Hello/HelloAIAgents/HelloAIAgent.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
namespace Hello;
99
[TopicSubscription("agents")]
1010
public class HelloAIAgent(
11-
IAgentRuntime context,
11+
IAgentWorker worker,
1212
[FromKeyedServices("EventTypes")] EventTypes typeRegistry,
1313
IHostApplicationLifetime hostApplicationLifetime,
1414
IChatClient client) : HelloAgent(
15-
context,
15+
worker,
1616
typeRegistry,
1717
hostApplicationLifetime),
1818
IHandle<NewMessageReceived>

dotnet/samples/Hello/HelloAIAgents/Program.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ namespace Hello
3333
{
3434
[TopicSubscription("agents")]
3535
public class HelloAgent(
36-
IAgentRuntime context,
36+
IAgentWorker worker,
3737
[FromKeyedServices("EventTypes")] EventTypes typeRegistry,
3838
IHostApplicationLifetime hostApplicationLifetime) : ConsoleAgent(
39-
context,
39+
worker,
4040
typeRegistry),
4141
ISayHello,
4242
IHandle<NewMessageReceived>,

dotnet/samples/Hello/HelloAgent/Program.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ namespace Hello
1818
{
1919
[TopicSubscription("agents")]
2020
public class HelloAgent(
21-
IAgentRuntime context, IHostApplicationLifetime hostApplicationLifetime,
21+
IAgentWorker worker, IHostApplicationLifetime hostApplicationLifetime,
2222
[FromKeyedServices("EventTypes")] EventTypes typeRegistry) : Agent(
23-
context,
23+
worker,
2424
typeRegistry),
2525
ISayHello,
2626
IHandleConsole,
@@ -35,7 +35,7 @@ public async Task Handle(NewMessageReceived item)
3535
await PublishMessageAsync(evt).ConfigureAwait(false);
3636
var goodbye = new ConversationClosed
3737
{
38-
UserId = this.AgentId.Key,
38+
UserId = this.AgentId.Type,
3939
UserMessage = "Goodbye"
4040
};
4141
await PublishMessageAsync(goodbye).ConfigureAwait(false);

dotnet/samples/Hello/HelloAgent/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ Within that event handler you may optionally *emit* new events, which are then s
4343
```csharp
4444
TopicSubscription("HelloAgents")]
4545
public class HelloAgent(
46-
IAgentContext context,
46+
iAgentWorker worker,
4747
[FromKeyedServices("EventTypes")] EventTypes typeRegistry) : ConsoleAgent(
48-
context,
48+
worker,
4949
typeRegistry),
5050
ISayHello,
5151
IHandle<NewMessageReceived>,

dotnet/samples/Hello/HelloAgentState/Program.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ namespace Hello
1818
{
1919
[TopicSubscription("agents")]
2020
public class HelloAgent(
21-
IAgentRuntime context,
21+
IAgentWorker worker,
2222
IHostApplicationLifetime hostApplicationLifetime,
2323
[FromKeyedServices("EventTypes")] EventTypes typeRegistry) : Agent(
24-
context,
24+
worker,
2525
typeRegistry),
2626
IHandleConsole,
2727
IHandle<NewMessageReceived>,

dotnet/samples/Hello/HelloAgentState/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ Within that event handler you may optionally *emit* new events, which are then s
4343
```csharp
4444
TopicSubscription("HelloAgents")]
4545
public class HelloAgent(
46-
IAgentContext context,
46+
iAgentWorker worker,
4747
[FromKeyedServices("EventTypes")] EventTypes typeRegistry) : ConsoleAgent(
48-
context,
48+
worker,
4949
typeRegistry),
5050
ISayHello,
5151
IHandle<NewMessageReceived>,

dotnet/samples/dev-team/DevTeam.Agents/Developer/Developer.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
namespace DevTeam.Agents;
1212

1313
[TopicSubscription("devteam")]
14-
public class Dev(IAgentRuntime context, Kernel kernel, ISemanticTextMemory memory, [FromKeyedServices("EventTypes")] EventTypes typeRegistry, ILogger<Dev> logger)
15-
: SKAiAgent<DeveloperState>(context, memory, kernel, typeRegistry), IDevelopApps,
14+
public class Dev(IAgentWorker worker, Kernel kernel, ISemanticTextMemory memory, [FromKeyedServices("EventTypes")] EventTypes typeRegistry, ILogger<Dev> logger)
15+
: SKAiAgent<DeveloperState>(worker, memory, kernel, typeRegistry), IDevelopApps,
1616
IHandle<CodeGenerationRequested>,
1717
IHandle<CodeChainClosed>
1818
{

dotnet/samples/dev-team/DevTeam.Agents/DeveloperLead/DeveloperLead.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
namespace DevTeam.Agents;
1313

1414
[TopicSubscription("devteam")]
15-
public class DeveloperLead(IAgentRuntime context, Kernel kernel, ISemanticTextMemory memory, [FromKeyedServices("EventTypes")] EventTypes typeRegistry, ILogger<DeveloperLead> logger)
16-
: SKAiAgent<DeveloperLeadState>(context, memory, kernel, typeRegistry), ILeadDevelopers,
15+
public class DeveloperLead(IAgentWorker worker, Kernel kernel, ISemanticTextMemory memory, [FromKeyedServices("EventTypes")] EventTypes typeRegistry, ILogger<DeveloperLead> logger)
16+
: SKAiAgent<DeveloperLeadState>(worker, memory, kernel, typeRegistry), ILeadDevelopers,
1717
IHandle<DevPlanRequested>,
1818
IHandle<DevPlanChainClosed>
1919
{

dotnet/samples/dev-team/DevTeam.Agents/ProductManager/ProductManager.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
namespace DevTeam.Agents;
1212

1313
[TopicSubscription("devteam")]
14-
public class ProductManager(IAgentRuntime context, Kernel kernel, ISemanticTextMemory memory, [FromKeyedServices("EventTypes")] EventTypes typeRegistry, ILogger<ProductManager> logger)
15-
: SKAiAgent<ProductManagerState>(context, memory, kernel, typeRegistry), IManageProducts,
14+
public class ProductManager(IAgentWorker worker, Kernel kernel, ISemanticTextMemory memory, [FromKeyedServices("EventTypes")] EventTypes typeRegistry, ILogger<ProductManager> logger)
15+
: SKAiAgent<ProductManagerState>(worker, memory, kernel, typeRegistry), IManageProducts,
1616
IHandle<ReadmeChainClosed>,
1717
IHandle<ReadmeRequested>
1818
{

dotnet/samples/dev-team/DevTeam.Backend/Agents/AzureGenie.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
using Microsoft.SemanticKernel.Memory;
1010
namespace Microsoft.AI.DevTeam;
1111

12-
public class AzureGenie(IAgentRuntime context, Kernel kernel, ISemanticTextMemory memory, [FromKeyedServices("EventTypes")] EventTypes typeRegistry, IManageAzure azureService)
13-
: SKAiAgent<object>(context, memory, kernel, typeRegistry),
12+
public class AzureGenie(IAgentWorker worker, Kernel kernel, ISemanticTextMemory memory, [FromKeyedServices("EventTypes")] EventTypes typeRegistry, IManageAzure azureService)
13+
: SKAiAgent<object>(worker, memory, kernel, typeRegistry),
1414
IHandle<ReadmeCreated>,
1515
IHandle<CodeCreated>
1616

dotnet/samples/dev-team/DevTeam.Backend/Agents/Hubber.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212

1313
namespace Microsoft.AI.DevTeam;
1414

15-
public class Hubber(IAgentRuntime context, Kernel kernel, ISemanticTextMemory memory, [FromKeyedServices("EventTypes")] EventTypes typeRegistry, IManageGithub ghService)
16-
: SKAiAgent<object>(context, memory, kernel, typeRegistry),
15+
public class Hubber(IAgentWorker worker, Kernel kernel, ISemanticTextMemory memory, [FromKeyedServices("EventTypes")] EventTypes typeRegistry, IManageGithub ghService)
16+
: SKAiAgent<object>(worker, memory, kernel, typeRegistry),
1717
IHandle<NewAsk>,
1818
IHandle<ReadmeGenerated>,
1919
IHandle<DevPlanGenerated>,

dotnet/src/Microsoft.AutoGen/Agents/AIAgent/InferenceAgent.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
using Microsoft.Extensions.AI;
66
namespace Microsoft.AutoGen.Agents;
77
public abstract class InferenceAgent<T>(
8-
IAgentRuntime context,
8+
IAgentWorker worker,
99
EventTypes typeRegistry,
1010
IChatClient client)
11-
: Agent(context, typeRegistry)
11+
: Agent(worker, typeRegistry)
1212
where T : IMessage, new()
1313
{
1414
protected IChatClient ChatClient { get; } = client;

dotnet/src/Microsoft.AutoGen/Agents/AIAgent/SKAiAgent.cs

+10-11
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,17 @@
88
using Microsoft.SemanticKernel.Memory;
99

1010
namespace Microsoft.AutoGen.Agents;
11-
public abstract class SKAiAgent<T> : Agent where T : class, new()
11+
public abstract class SKAiAgent<T>(
12+
IAgentWorker worker,
13+
ISemanticTextMemory memory,
14+
Kernel kernel,
15+
EventTypes typeRegistry) : Agent(
16+
worker,
17+
typeRegistry) where T : class, new()
1218
{
13-
protected AgentState<T> _state;
14-
protected Kernel _kernel;
15-
private readonly ISemanticTextMemory _memory;
16-
17-
public SKAiAgent(IAgentRuntime context, ISemanticTextMemory memory, Kernel kernel, EventTypes typeRegistry) : base(context, typeRegistry)
18-
{
19-
_state = new();
20-
_memory = memory;
21-
_kernel = kernel;
22-
}
19+
protected AgentState<T> _state = new();
20+
protected Kernel _kernel = kernel;
21+
private readonly ISemanticTextMemory _memory = memory;
2322

2423
public void AddToHistory(string message, ChatUserType userType) => _state.History.Add(new ChatHistoryItem
2524
{

dotnet/src/Microsoft.AutoGen/Agents/IOAgent/ConsoleAgent/ConsoleAgent.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public abstract class ConsoleAgent : IOAgent,
1313
{
1414

1515
// instead of the primary constructor above, make a constructr here that still calls the base constructor
16-
public ConsoleAgent(IAgentRuntime context, [FromKeyedServices("EventTypes")] EventTypes typeRegistry) : base(context, typeRegistry)
16+
public ConsoleAgent(IAgentWorker worker, [FromKeyedServices("EventTypes")] EventTypes typeRegistry) : base(worker, typeRegistry)
1717
{
1818
_route = "console";
1919
}

dotnet/src/Microsoft.AutoGen/Agents/IOAgent/FileAgent/FileAgent.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ namespace Microsoft.AutoGen.Agents;
99

1010
[TopicSubscription("FileIO")]
1111
public abstract class FileAgent(
12-
IAgentRuntime context,
12+
IAgentWorker worker,
1313
[FromKeyedServices("EventTypes")] EventTypes typeRegistry,
1414
string inputPath = "input.txt",
1515
string outputPath = "output.txt"
16-
) : IOAgent(context, typeRegistry),
16+
) : IOAgent(worker, typeRegistry),
1717
IUseFiles,
1818
IHandle<Input>,
1919
IHandle<Output>

dotnet/src/Microsoft.AutoGen/Agents/IOAgent/IOAgent.cs

+2-4
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,10 @@
55
using Microsoft.AutoGen.Core;
66
namespace Microsoft.AutoGen.Agents;
77

8-
public abstract class IOAgent : Agent
8+
public abstract class IOAgent(IAgentWorker worker, EventTypes eventTypes) : Agent(worker, eventTypes)
99
{
1010
public string _route = "base";
11-
protected IOAgent(IAgentRuntime context, EventTypes eventTypes) : base(context, eventTypes)
12-
{
13-
}
11+
1412
public virtual async Task Handle(Input item)
1513
{
1614

dotnet/src/Microsoft.AutoGen/Agents/IOAgent/WebAPIAgent/WebAPIAgent.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ public abstract class WebAPIAgent : IOAgent,
1717
private readonly string _url = "/agents/webio";
1818

1919
public WebAPIAgent(
20-
IAgentRuntime context,
20+
IAgentWorker worker,
2121
[FromKeyedServices("EventTypes")] EventTypes typeRegistry,
2222
ILogger<WebAPIAgent> logger,
2323
string url = "/agents/webio") : base(
24-
context,
24+
worker,
2525
typeRegistry)
2626
{
2727
_url = url;

dotnet/src/Microsoft.AutoGen/Core.Grpc/GrpcAgentWorker.cs

+2-6
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// GrpcAgentWorker.cs
33

44
using System.Collections.Concurrent;
5-
using System.Diagnostics;
65
using System.Reflection;
76
using System.Threading.Channels;
87
using Grpc.Core;
@@ -18,8 +17,7 @@ public sealed class GrpcAgentWorker(
1817
IHostApplicationLifetime hostApplicationLifetime,
1918
IServiceProvider serviceProvider,
2019
[FromKeyedServices("AgentTypes")] IEnumerable<Tuple<string, Type>> configuredAgentTypes,
21-
ILogger<GrpcAgentWorker> logger,
22-
DistributedContextPropagator distributedContextPropagator) :
20+
ILogger<GrpcAgentWorker> logger) :
2321
IHostedService, IDisposable, IAgentWorker
2422
{
2523
private readonly object _channelLock = new();
@@ -37,7 +35,6 @@ public sealed class GrpcAgentWorker(
3735
private readonly IServiceProvider _serviceProvider = serviceProvider;
3836
private readonly IEnumerable<Tuple<string, Type>> _configuredAgentTypes = configuredAgentTypes;
3937
private readonly ILogger<GrpcAgentWorker> _logger = logger;
40-
private readonly DistributedContextPropagator _distributedContextPropagator = distributedContextPropagator;
4138
private readonly CancellationTokenSource _shutdownCts = CancellationTokenSource.CreateLinkedTokenSource(hostApplicationLifetime.ApplicationStopping);
4239
private AsyncDuplexStreamingCall<Message, Message>? _channel;
4340
private Task? _readTask;
@@ -178,8 +175,7 @@ private Agent GetOrActivateAgent(AgentId agentId)
178175
{
179176
if (_agentTypes.TryGetValue(agentId.Type, out var agentType))
180177
{
181-
var context = new AgentRuntime(agentId, this, _serviceProvider.GetRequiredService<ILogger<Agent>>(), _distributedContextPropagator);
182-
agent = (Agent)ActivatorUtilities.CreateInstance(_serviceProvider, agentType, context);
178+
agent = (Agent)ActivatorUtilities.CreateInstance(_serviceProvider, agentType, this);
183179
_agents.TryAdd((agentId.Type, agentId.Key), agent);
184180
}
185181
else

0 commit comments

Comments
 (0)