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

HelloAgents App Host with xlang sample #4395

Draft
wants to merge 20 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions dotnet/Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="Aspire.Hosting" Version="9.0.0" />
<PackageVersion Include="Aspire.Hosting.Python" Version="9.0.0" />
<PackageVersion Include="AspNetCore.Authentication.ApiKey" Version="8.0.1" />
<PackageVersion Include="Aspire.Azure.AI.OpenAI" Version="8.0.1-preview.8.24267.1" />
<PackageVersion Include="Aspire.Hosting.AppHost" Version="9.0.0" />
Expand Down
1 change: 1 addition & 0 deletions dotnet/samples/Hello/Hello.AppHost/Hello.AppHost.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<ItemGroup>
<PackageReference Include="Aspire.Hosting.AppHost" />
<PackageReference Include="Aspire.Hosting" />
<PackageReference Include="Aspire.Hosting.Python" />
</ItemGroup>

<ItemGroup>
Expand Down
19 changes: 14 additions & 5 deletions dotnet/samples/Hello/Hello.AppHost/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,24 @@

var builder = DistributedApplication.CreateBuilder(args);
var backend = builder.AddProject<Projects.Backend>("backend").WithExternalHttpEndpoints();
builder.AddProject<Projects.HelloAgent>("client")
var client = builder.AddProject<Projects.HelloAgent>("HelloAgentsDotNET")
.WithReference(backend)
.WithEnvironment("AGENT_HOST", $"{backend.GetEndpoint("https").Property(EndpointProperty.Url)}")
.WithEnvironment("AGENT_HOST", backend.GetEndpoint("https"))
.WithEnvironment("STAY_ALIVE_ON_GOODBYE", "true")
.WaitFor(backend);

#pragma warning disable ASPIREHOSTINGPYTHON001 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.
// xlang is over http for now - in prod use TLS between containers
builder.AddPythonApp("HelloAgentsPython", "../../../../python/packages/autogen-core/samples/xlang/hello_python_agent", "hello_python_agent.py", "../../../../../.venv")
.WithReference(backend)
.WithEnvironment("AGENT_HOST", backend.GetEndpoint("http"))
.WithEnvironment("STAY_ALIVE_ON_GOODBYE", "true")
.WithEnvironment("GRPC_DNS_RESOLVER", "native")
.WithOtlpExporter()
.WaitFor(backend)
.WaitFor(client);
#pragma warning restore ASPIREHOSTINGPYTHON001 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.
using var app = builder.Build();

await app.StartAsync();
var url = backend.GetEndpoint("http").Url;
Console.WriteLine("Backend URL: " + url);

await app.WaitForShutdownAsync();
19 changes: 7 additions & 12 deletions dotnet/samples/Hello/HelloAgent/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,12 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;

// step 1: create in-memory agent runtime

// step 2: register HelloAgent to that agent runtime

// step 3: start the agent runtime

// step 4: send a message to the agent

// step 5: wait for the agent runtime to shutdown
var local = true;
if (Environment.GetEnvironmentVariable("AGENT_HOST") != null) { local = false; }
var app = await AgentsApp.PublishMessageAsync("HelloAgents", new NewMessageReceived
{
Message = "World"
}, local: true);
//var app = await AgentsApp.StartAsync();
}, local: local).ConfigureAwait(false);
await app.WaitForShutdownAsync();

namespace Hello
Expand Down Expand Up @@ -53,7 +45,10 @@ public async Task Handle(ConversationClosed item)
var goodbye = $"********************* {item.UserId} said {item.UserMessage} ************************";
var evt = new Output { Message = goodbye };
await PublishMessageAsync(evt).ConfigureAwait(true);
await PublishMessageAsync(new Shutdown()).ConfigureAwait(false);
if (Environment.GetEnvironmentVariable("STAY_ALIVE_ON_GOODBYE") != "true")
{
await PublishMessageAsync(new Shutdown()).ConfigureAwait(false);
}
}

public async Task Handle(Shutdown item)
Expand Down
8 changes: 8 additions & 0 deletions python/packages/autogen-core/samples/protos/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
"""
The :mod:`autogen_core.worker.protos` module provides Google Protobuf classes for agent-worker communication
"""

import os
import sys

sys.path.insert(0, os.path.abspath(os.path.dirname(__file__)))
50 changes: 50 additions & 0 deletions python/packages/autogen-core/samples/protos/agent_events_pb2.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

197 changes: 197 additions & 0 deletions python/packages/autogen-core/samples/protos/agent_events_pb2.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,197 @@
"""
@generated by mypy-protobuf. Do not edit manually!
isort:skip_file
"""

import builtins
import google.protobuf.descriptor
import google.protobuf.message
import typing

DESCRIPTOR: google.protobuf.descriptor.FileDescriptor

@typing.final
class TextMessage(google.protobuf.message.Message):
DESCRIPTOR: google.protobuf.descriptor.Descriptor

TEXTMESSAGE_FIELD_NUMBER: builtins.int
SOURCE_FIELD_NUMBER: builtins.int
textMessage: builtins.str
source: builtins.str
def __init__(
self,
*,
textMessage: builtins.str = ...,
source: builtins.str = ...,
) -> None: ...
def ClearField(self, field_name: typing.Literal["source", b"source", "textMessage", b"textMessage"]) -> None: ...

global___TextMessage = TextMessage

@typing.final
class Input(google.protobuf.message.Message):
DESCRIPTOR: google.protobuf.descriptor.Descriptor

MESSAGE_FIELD_NUMBER: builtins.int
message: builtins.str
def __init__(
self,
*,
message: builtins.str = ...,
) -> None: ...
def ClearField(self, field_name: typing.Literal["message", b"message"]) -> None: ...

global___Input = Input

@typing.final
class InputProcessed(google.protobuf.message.Message):
DESCRIPTOR: google.protobuf.descriptor.Descriptor

ROUTE_FIELD_NUMBER: builtins.int
route: builtins.str
def __init__(
self,
*,
route: builtins.str = ...,
) -> None: ...
def ClearField(self, field_name: typing.Literal["route", b"route"]) -> None: ...

global___InputProcessed = InputProcessed

@typing.final
class Output(google.protobuf.message.Message):
DESCRIPTOR: google.protobuf.descriptor.Descriptor

MESSAGE_FIELD_NUMBER: builtins.int
message: builtins.str
def __init__(
self,
*,
message: builtins.str = ...,
) -> None: ...
def ClearField(self, field_name: typing.Literal["message", b"message"]) -> None: ...

global___Output = Output

@typing.final
class OutputWritten(google.protobuf.message.Message):
DESCRIPTOR: google.protobuf.descriptor.Descriptor

ROUTE_FIELD_NUMBER: builtins.int
route: builtins.str
def __init__(
self,
*,
route: builtins.str = ...,
) -> None: ...
def ClearField(self, field_name: typing.Literal["route", b"route"]) -> None: ...

global___OutputWritten = OutputWritten

@typing.final
class IOError(google.protobuf.message.Message):
DESCRIPTOR: google.protobuf.descriptor.Descriptor

MESSAGE_FIELD_NUMBER: builtins.int
message: builtins.str
def __init__(
self,
*,
message: builtins.str = ...,
) -> None: ...
def ClearField(self, field_name: typing.Literal["message", b"message"]) -> None: ...

global___IOError = IOError

@typing.final
class NewMessageReceived(google.protobuf.message.Message):
DESCRIPTOR: google.protobuf.descriptor.Descriptor

MESSAGE_FIELD_NUMBER: builtins.int
message: builtins.str
def __init__(
self,
*,
message: builtins.str = ...,
) -> None: ...
def ClearField(self, field_name: typing.Literal["message", b"message"]) -> None: ...

global___NewMessageReceived = NewMessageReceived

@typing.final
class ResponseGenerated(google.protobuf.message.Message):
DESCRIPTOR: google.protobuf.descriptor.Descriptor

RESPONSE_FIELD_NUMBER: builtins.int
response: builtins.str
def __init__(
self,
*,
response: builtins.str = ...,
) -> None: ...
def ClearField(self, field_name: typing.Literal["response", b"response"]) -> None: ...

global___ResponseGenerated = ResponseGenerated

@typing.final
class GoodBye(google.protobuf.message.Message):
DESCRIPTOR: google.protobuf.descriptor.Descriptor

MESSAGE_FIELD_NUMBER: builtins.int
message: builtins.str
def __init__(
self,
*,
message: builtins.str = ...,
) -> None: ...
def ClearField(self, field_name: typing.Literal["message", b"message"]) -> None: ...

global___GoodBye = GoodBye

@typing.final
class MessageStored(google.protobuf.message.Message):
DESCRIPTOR: google.protobuf.descriptor.Descriptor

MESSAGE_FIELD_NUMBER: builtins.int
message: builtins.str
def __init__(
self,
*,
message: builtins.str = ...,
) -> None: ...
def ClearField(self, field_name: typing.Literal["message", b"message"]) -> None: ...

global___MessageStored = MessageStored

@typing.final
class ConversationClosed(google.protobuf.message.Message):
DESCRIPTOR: google.protobuf.descriptor.Descriptor

USER_ID_FIELD_NUMBER: builtins.int
USER_MESSAGE_FIELD_NUMBER: builtins.int
user_id: builtins.str
user_message: builtins.str
def __init__(
self,
*,
user_id: builtins.str = ...,
user_message: builtins.str = ...,
) -> None: ...
def ClearField(self, field_name: typing.Literal["user_id", b"user_id", "user_message", b"user_message"]) -> None: ...

global___ConversationClosed = ConversationClosed

@typing.final
class Shutdown(google.protobuf.message.Message):
DESCRIPTOR: google.protobuf.descriptor.Descriptor

MESSAGE_FIELD_NUMBER: builtins.int
message: builtins.str
def __init__(
self,
*,
message: builtins.str = ...,
) -> None: ...
def ClearField(self, field_name: typing.Literal["message", b"message"]) -> None: ...

global___Shutdown = Shutdown
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT!
"""Client and server classes corresponding to protobuf-defined services."""

import grpc
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
"""
@generated by mypy-protobuf. Do not edit manually!
isort:skip_file
"""

import abc
import collections.abc
import grpc
import grpc.aio
import typing

_T = typing.TypeVar("_T")

class _MaybeAsyncIterator(collections.abc.AsyncIterator[_T], collections.abc.Iterator[_T], metaclass=abc.ABCMeta): ...

class _ServicerContext(grpc.ServicerContext, grpc.aio.ServicerContext): # type: ignore[misc, type-arg]
...
Loading
Loading