Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rysweet 4676 remove iagentruntime - collapse into iagentworker #4740

Merged
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,9 @@ await app.WaitForShutdownAsync();

[TopicSubscription("agents")]
public class HelloAgent(
IAgentContext context,
IAgentContext worker,
[FromKeyedServices("EventTypes")] EventTypes typeRegistry) : ConsoleAgent(
context,
worker,
typeRegistry),
ISayHello,
IHandle<NewMessageReceived>,
Expand Down
4 changes: 2 additions & 2 deletions dotnet/samples/Hello/HelloAIAgents/HelloAIAgent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
namespace Hello;
[TopicSubscription("agents")]
public class HelloAIAgent(
IAgentRuntime context,
IAgentWorker worker,
[FromKeyedServices("EventTypes")] EventTypes typeRegistry,
IHostApplicationLifetime hostApplicationLifetime,
IChatClient client) : HelloAgent(
context,
worker,
typeRegistry,
hostApplicationLifetime),
IHandle<NewMessageReceived>
Expand Down
4 changes: 2 additions & 2 deletions dotnet/samples/Hello/HelloAIAgents/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ namespace Hello
{
[TopicSubscription("agents")]
public class HelloAgent(
IAgentRuntime context,
IAgentWorker worker,
[FromKeyedServices("EventTypes")] EventTypes typeRegistry,
IHostApplicationLifetime hostApplicationLifetime) : ConsoleAgent(
context,
worker,
typeRegistry),
ISayHello,
IHandle<NewMessageReceived>,
Expand Down
6 changes: 3 additions & 3 deletions dotnet/samples/Hello/HelloAgent/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ namespace Hello
{
[TopicSubscription("agents")]
public class HelloAgent(
IAgentRuntime context, IHostApplicationLifetime hostApplicationLifetime,
IAgentWorker worker, IHostApplicationLifetime hostApplicationLifetime,
[FromKeyedServices("EventTypes")] EventTypes typeRegistry) : Agent(
context,
worker,
typeRegistry),
ISayHello,
IHandleConsole,
Expand All @@ -35,7 +35,7 @@ public async Task Handle(NewMessageReceived item)
await PublishMessageAsync(evt).ConfigureAwait(false);
var goodbye = new ConversationClosed
{
UserId = this.AgentId.Key,
UserId = this.AgentId.Type,
UserMessage = "Goodbye"
};
await PublishMessageAsync(goodbye).ConfigureAwait(false);
Expand Down
4 changes: 2 additions & 2 deletions dotnet/samples/Hello/HelloAgent/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ Within that event handler you may optionally *emit* new events, which are then s
```csharp
TopicSubscription("HelloAgents")]
public class HelloAgent(
IAgentContext context,
iAgentWorker worker,
[FromKeyedServices("EventTypes")] EventTypes typeRegistry) : ConsoleAgent(
context,
worker,
typeRegistry),
ISayHello,
IHandle<NewMessageReceived>,
Expand Down
4 changes: 2 additions & 2 deletions dotnet/samples/Hello/HelloAgentState/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ namespace Hello
{
[TopicSubscription("agents")]
public class HelloAgent(
IAgentRuntime context,
IAgentWorker worker,
IHostApplicationLifetime hostApplicationLifetime,
[FromKeyedServices("EventTypes")] EventTypes typeRegistry) : Agent(
context,
worker,
typeRegistry),
IHandleConsole,
IHandle<NewMessageReceived>,
Expand Down
4 changes: 2 additions & 2 deletions dotnet/samples/Hello/HelloAgentState/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ Within that event handler you may optionally *emit* new events, which are then s
```csharp
TopicSubscription("HelloAgents")]
public class HelloAgent(
IAgentContext context,
iAgentWorker worker,
[FromKeyedServices("EventTypes")] EventTypes typeRegistry) : ConsoleAgent(
context,
worker,
typeRegistry),
ISayHello,
IHandle<NewMessageReceived>,
Expand Down
4 changes: 2 additions & 2 deletions dotnet/samples/dev-team/DevTeam.Agents/Developer/Developer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
namespace DevTeam.Agents;

[TopicSubscription("devteam")]
public class Dev(IAgentRuntime context, Kernel kernel, ISemanticTextMemory memory, [FromKeyedServices("EventTypes")] EventTypes typeRegistry, ILogger<Dev> logger)
: SKAiAgent<DeveloperState>(context, memory, kernel, typeRegistry), IDevelopApps,
public class Dev(IAgentWorker worker, Kernel kernel, ISemanticTextMemory memory, [FromKeyedServices("EventTypes")] EventTypes typeRegistry, ILogger<Dev> logger)
: SKAiAgent<DeveloperState>(worker, memory, kernel, typeRegistry), IDevelopApps,
IHandle<CodeGenerationRequested>,
IHandle<CodeChainClosed>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
namespace DevTeam.Agents;

[TopicSubscription("devteam")]
public class DeveloperLead(IAgentRuntime context, Kernel kernel, ISemanticTextMemory memory, [FromKeyedServices("EventTypes")] EventTypes typeRegistry, ILogger<DeveloperLead> logger)
: SKAiAgent<DeveloperLeadState>(context, memory, kernel, typeRegistry), ILeadDevelopers,
public class DeveloperLead(IAgentWorker worker, Kernel kernel, ISemanticTextMemory memory, [FromKeyedServices("EventTypes")] EventTypes typeRegistry, ILogger<DeveloperLead> logger)
: SKAiAgent<DeveloperLeadState>(worker, memory, kernel, typeRegistry), ILeadDevelopers,
IHandle<DevPlanRequested>,
IHandle<DevPlanChainClosed>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
namespace DevTeam.Agents;

[TopicSubscription("devteam")]
public class ProductManager(IAgentRuntime context, Kernel kernel, ISemanticTextMemory memory, [FromKeyedServices("EventTypes")] EventTypes typeRegistry, ILogger<ProductManager> logger)
: SKAiAgent<ProductManagerState>(context, memory, kernel, typeRegistry), IManageProducts,
public class ProductManager(IAgentWorker worker, Kernel kernel, ISemanticTextMemory memory, [FromKeyedServices("EventTypes")] EventTypes typeRegistry, ILogger<ProductManager> logger)
: SKAiAgent<ProductManagerState>(worker, memory, kernel, typeRegistry), IManageProducts,
IHandle<ReadmeChainClosed>,
IHandle<ReadmeRequested>
{
Expand Down
4 changes: 2 additions & 2 deletions dotnet/samples/dev-team/DevTeam.Backend/Agents/AzureGenie.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
using Microsoft.SemanticKernel.Memory;
namespace Microsoft.AI.DevTeam;

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

Expand Down
4 changes: 2 additions & 2 deletions dotnet/samples/dev-team/DevTeam.Backend/Agents/Hubber.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@

namespace Microsoft.AI.DevTeam;

public class Hubber(IAgentRuntime context, Kernel kernel, ISemanticTextMemory memory, [FromKeyedServices("EventTypes")] EventTypes typeRegistry, IManageGithub ghService)
: SKAiAgent<object>(context, memory, kernel, typeRegistry),
public class Hubber(IAgentWorker worker, Kernel kernel, ISemanticTextMemory memory, [FromKeyedServices("EventTypes")] EventTypes typeRegistry, IManageGithub ghService)
: SKAiAgent<object>(worker, memory, kernel, typeRegistry),
IHandle<NewAsk>,
IHandle<ReadmeGenerated>,
IHandle<DevPlanGenerated>,
Expand Down
4 changes: 2 additions & 2 deletions dotnet/src/Microsoft.AutoGen/Agents/AIAgent/InferenceAgent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
using Microsoft.Extensions.AI;
namespace Microsoft.AutoGen.Agents;
public abstract class InferenceAgent<T>(
IAgentRuntime context,
IAgentWorker worker,
EventTypes typeRegistry,
IChatClient client)
: Agent(context, typeRegistry)
: Agent(worker, typeRegistry)
where T : IMessage, new()
{
protected IChatClient ChatClient { get; } = client;
Expand Down
21 changes: 10 additions & 11 deletions dotnet/src/Microsoft.AutoGen/Agents/AIAgent/SKAiAgent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,17 @@
using Microsoft.SemanticKernel.Memory;

namespace Microsoft.AutoGen.Agents;
public abstract class SKAiAgent<T> : Agent where T : class, new()
public abstract class SKAiAgent<T>(
IAgentWorker worker,
ISemanticTextMemory memory,
Kernel kernel,
EventTypes typeRegistry) : Agent(
worker,
typeRegistry) where T : class, new()
{
protected AgentState<T> _state;
protected Kernel _kernel;
private readonly ISemanticTextMemory _memory;

public SKAiAgent(IAgentRuntime context, ISemanticTextMemory memory, Kernel kernel, EventTypes typeRegistry) : base(context, typeRegistry)
{
_state = new();
_memory = memory;
_kernel = kernel;
}
protected AgentState<T> _state = new();
protected Kernel _kernel = kernel;
private readonly ISemanticTextMemory _memory = memory;

public void AddToHistory(string message, ChatUserType userType) => _state.History.Add(new ChatHistoryItem
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public abstract class ConsoleAgent : IOAgent,
{

// instead of the primary constructor above, make a constructr here that still calls the base constructor
public ConsoleAgent(IAgentRuntime context, [FromKeyedServices("EventTypes")] EventTypes typeRegistry) : base(context, typeRegistry)
public ConsoleAgent(IAgentWorker worker, [FromKeyedServices("EventTypes")] EventTypes typeRegistry) : base(worker, typeRegistry)
{
_route = "console";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ namespace Microsoft.AutoGen.Agents;

[TopicSubscription("FileIO")]
public abstract class FileAgent(
IAgentRuntime context,
IAgentWorker worker,
[FromKeyedServices("EventTypes")] EventTypes typeRegistry,
string inputPath = "input.txt",
string outputPath = "output.txt"
) : IOAgent(context, typeRegistry),
) : IOAgent(worker, typeRegistry),
IUseFiles,
IHandle<Input>,
IHandle<Output>
Expand Down
6 changes: 2 additions & 4 deletions dotnet/src/Microsoft.AutoGen/Agents/IOAgent/IOAgent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@
using Microsoft.AutoGen.Core;
namespace Microsoft.AutoGen.Agents;

public abstract class IOAgent : Agent
public abstract class IOAgent(IAgentWorker worker, EventTypes eventTypes) : Agent(worker, eventTypes)
{
public string _route = "base";
protected IOAgent(IAgentRuntime context, EventTypes eventTypes) : base(context, eventTypes)
{
}

public virtual async Task Handle(Input item)
{

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ public abstract class WebAPIAgent : IOAgent,
private readonly string _url = "/agents/webio";

public WebAPIAgent(
IAgentRuntime context,
IAgentWorker worker,
[FromKeyedServices("EventTypes")] EventTypes typeRegistry,
ILogger<WebAPIAgent> logger,
string url = "/agents/webio") : base(
context,
worker,
typeRegistry)
{
_url = url;
Expand Down
8 changes: 2 additions & 6 deletions dotnet/src/Microsoft.AutoGen/Core.Grpc/GrpcAgentWorker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// GrpcAgentWorker.cs

using System.Collections.Concurrent;
using System.Diagnostics;
using System.Reflection;
using System.Threading.Channels;
using Grpc.Core;
Expand All @@ -18,8 +17,7 @@ public sealed class GrpcAgentWorker(
IHostApplicationLifetime hostApplicationLifetime,
IServiceProvider serviceProvider,
[FromKeyedServices("AgentTypes")] IEnumerable<Tuple<string, Type>> configuredAgentTypes,
ILogger<GrpcAgentWorker> logger,
DistributedContextPropagator distributedContextPropagator) :
ILogger<GrpcAgentWorker> logger) :
IHostedService, IDisposable, IAgentWorker
{
private readonly object _channelLock = new();
Expand All @@ -37,7 +35,6 @@ public sealed class GrpcAgentWorker(
private readonly IServiceProvider _serviceProvider = serviceProvider;
private readonly IEnumerable<Tuple<string, Type>> _configuredAgentTypes = configuredAgentTypes;
private readonly ILogger<GrpcAgentWorker> _logger = logger;
private readonly DistributedContextPropagator _distributedContextPropagator = distributedContextPropagator;
private readonly CancellationTokenSource _shutdownCts = CancellationTokenSource.CreateLinkedTokenSource(hostApplicationLifetime.ApplicationStopping);
private AsyncDuplexStreamingCall<Message, Message>? _channel;
private Task? _readTask;
Expand Down Expand Up @@ -178,8 +175,7 @@ private Agent GetOrActivateAgent(AgentId agentId)
{
if (_agentTypes.TryGetValue(agentId.Type, out var agentType))
{
var context = new AgentRuntime(agentId, this, _serviceProvider.GetRequiredService<ILogger<Agent>>(), _distributedContextPropagator);
agent = (Agent)ActivatorUtilities.CreateInstance(_serviceProvider, agentType, context);
agent = (Agent)ActivatorUtilities.CreateInstance(_serviceProvider, agentType, this);
_agents.TryAdd((agentId.Type, agentId.Key), agent);
}
else
Expand Down
Loading
Loading