mirror of
https://github.com/microsoft/autogen.git
synced 2026-04-20 03:02:16 -04:00
rysweet-unsubscribe-and-agent-tests-4744 (#4920)
* add tests for core functionality and client/server * add remove subscription, get subscriptions * fix LOTS of bugs * add grpc tuning * adapt to latest agreed agents_worker proto changes.
This commit is contained in:
@@ -12,6 +12,7 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="../../../src/Microsoft.AutoGen/Core.Grpc/Microsoft.AutoGen.Core.Grpc.csproj" />
|
||||
<ProjectReference Include="..\..\..\src\Microsoft.AutoGen\Agents\Microsoft.AutoGen.Agents.csproj" />
|
||||
<ProjectReference Include="..\..\..\src\Microsoft.AutoGen\Contracts\Microsoft.AutoGen.Contracts.csproj" />
|
||||
<ProjectReference Include="..\..\..\src\Microsoft.AutoGen\Core\Microsoft.AutoGen.Core.csproj" />
|
||||
|
||||
@@ -7,21 +7,21 @@ using Microsoft.AutoGen.Contracts;
|
||||
using Microsoft.AutoGen.Core;
|
||||
|
||||
// send a message to the agent
|
||||
var app = await AgentsApp.PublishMessageAsync("HelloAgents", new NewMessageReceived
|
||||
var local = true;
|
||||
if (Environment.GetEnvironmentVariable("AGENT_HOST") != null) { local = false; }
|
||||
var app = await Microsoft.AutoGen.Core.Grpc.AgentsApp.PublishMessageAsync("HelloAgents", new NewMessageReceived
|
||||
{
|
||||
Message = "World"
|
||||
}, local: false);
|
||||
}, local: local).ConfigureAwait(false);
|
||||
|
||||
await app.WaitForShutdownAsync();
|
||||
|
||||
namespace Hello
|
||||
{
|
||||
[TopicSubscription("agents")]
|
||||
[TopicSubscription("HelloAgents")]
|
||||
public class HelloAgent(
|
||||
IAgentWorker worker,
|
||||
IHostApplicationLifetime hostApplicationLifetime,
|
||||
[FromKeyedServices("EventTypes")] EventTypes typeRegistry) : Agent(
|
||||
worker,
|
||||
[FromKeyedServices("AgentsMetadata")] AgentsMetadata typeRegistry) : Agent(
|
||||
typeRegistry),
|
||||
IHandleConsole,
|
||||
IHandle<NewMessageReceived>,
|
||||
@@ -29,7 +29,7 @@ namespace Hello
|
||||
IHandle<Shutdown>
|
||||
{
|
||||
private AgentState? State { get; set; }
|
||||
public async Task Handle(NewMessageReceived item)
|
||||
public async Task Handle(NewMessageReceived item, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var response = await SayHello(item.Message).ConfigureAwait(false);
|
||||
var evt = new Output
|
||||
@@ -57,7 +57,7 @@ namespace Hello
|
||||
await PublishMessageAsync(new Shutdown { Message = this.AgentId.Key }).ConfigureAwait(false);
|
||||
|
||||
}
|
||||
public async Task Handle(ConversationClosed item)
|
||||
public async Task Handle(ConversationClosed item, CancellationToken cancellationToken = default)
|
||||
{
|
||||
State = await ReadAsync<AgentState>(this.AgentId).ConfigureAwait(false);
|
||||
var state = JsonSerializer.Deserialize<Dictionary<string, string>>(State.TextData) ?? new Dictionary<string, string> { { "data", "No state data found" } };
|
||||
@@ -74,7 +74,7 @@ namespace Hello
|
||||
TextData = JsonSerializer.Serialize(state)
|
||||
}).ConfigureAwait(false);
|
||||
}
|
||||
public async Task Handle(Shutdown item)
|
||||
public async Task Handle(Shutdown item, CancellationToken cancellationToken = default)
|
||||
{
|
||||
string? workflow = null;
|
||||
// make sure the workflow is finished
|
||||
|
||||
@@ -25,10 +25,10 @@ Flow Diagram:
|
||||
```mermaid
|
||||
%%{init: {'theme':'forest'}}%%
|
||||
graph LR;
|
||||
A[Main] --> |"PublishEventAsync(NewMessage('World'))"| B{"Handle(NewMessageReceived item)"}
|
||||
A[Main] --> |"PublishEventAsync(NewMessage('World'))"| B{"Handle(NewMessageReceived item, CancellationToken cancellationToken = default)"}
|
||||
B --> |"PublishEventAsync(Output('***Hello, World***'))"| C[ConsoleAgent]
|
||||
C --> D{"WriteConsole()"}
|
||||
B --> |"PublishEventAsync(ConversationClosed('Goodbye'))"| E{"Handle(ConversationClosed item)"}
|
||||
B --> |"PublishEventAsync(ConversationClosed('Goodbye'))"| E{"Handle(ConversationClosed item, CancellationToken cancellationToken = default)"}
|
||||
B --> |"PublishEventAsync(Output('***Goodbye***'))"| C
|
||||
E --> F{"Shutdown()"}
|
||||
|
||||
@@ -44,14 +44,14 @@ Within that event handler you may optionally *emit* new events, which are then s
|
||||
TopicSubscription("HelloAgents")]
|
||||
public class HelloAgent(
|
||||
iAgentWorker worker,
|
||||
[FromKeyedServices("EventTypes")] EventTypes typeRegistry) : ConsoleAgent(
|
||||
[FromKeyedServices("AgentsMetadata")] AgentsMetadata typeRegistry) : ConsoleAgent(
|
||||
worker,
|
||||
typeRegistry),
|
||||
ISayHello,
|
||||
IHandle<NewMessageReceived>,
|
||||
IHandle<ConversationClosed>
|
||||
{
|
||||
public async Task Handle(NewMessageReceived item)
|
||||
public async Task Handle(NewMessageReceived item, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var response = await SayHello(item.Message).ConfigureAwait(false);
|
||||
var evt = new Output
|
||||
|
||||
Reference in New Issue
Block a user