Skip to content

Commit

Permalink
Add tutorial for adding autogen agent to chatroom (#130)
Browse files Browse the repository at this point in the history
* add tutorial

* add autogen_net example
  • Loading branch information
LittleLittleCloud authored Jul 13, 2024
1 parent 428aba4 commit 9e54e37
Show file tree
Hide file tree
Showing 16 changed files with 206 additions and 30 deletions.
19 changes: 17 additions & 2 deletions ChatRoom.sln
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ChatRoom.WebSearch", "ChatR
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ChatRoom.WebSearch.Tests", "test\ChatRoom.BingSearch.Tests\ChatRoom.WebSearch.Tests.csproj", "{3521DC79-706D-4B21-81BC-2D6C793FE17F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ChatRoom.Planner", "ChatRoom\ChatRoom.Planner\ChatRoom.Planner.csproj", "{0B450A6C-5EF2-409D-8079-B61D235E1FB7}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ChatRoom.Planner", "ChatRoom\ChatRoom.Planner\ChatRoom.Planner.csproj", "{0B450A6C-5EF2-409D-8079-B61D235E1FB7}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ChatRoom.Planner.Tests", "test\ChatRoom.Planner.Tests\ChatRoom.Planner.Tests.csproj", "{8669DBAE-75B0-4347-9648-1B8C6E389035}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ChatRoom.Planner.Tests", "test\ChatRoom.Planner.Tests\ChatRoom.Planner.Tests.csproj", "{8669DBAE-75B0-4347-9648-1B8C6E389035}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "hello-world", "example\dotnet\hello-world\hello-world.csproj", "{F8A1FDE5-930E-48D0-A26C-00620701CB78}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -262,6 +264,18 @@ Global
{8669DBAE-75B0-4347-9648-1B8C6E389035}.Release|x64.Build.0 = Release|Any CPU
{8669DBAE-75B0-4347-9648-1B8C6E389035}.Release|x86.ActiveCfg = Release|Any CPU
{8669DBAE-75B0-4347-9648-1B8C6E389035}.Release|x86.Build.0 = Release|Any CPU
{F8A1FDE5-930E-48D0-A26C-00620701CB78}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F8A1FDE5-930E-48D0-A26C-00620701CB78}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F8A1FDE5-930E-48D0-A26C-00620701CB78}.Debug|x64.ActiveCfg = Debug|Any CPU
{F8A1FDE5-930E-48D0-A26C-00620701CB78}.Debug|x64.Build.0 = Debug|Any CPU
{F8A1FDE5-930E-48D0-A26C-00620701CB78}.Debug|x86.ActiveCfg = Debug|Any CPU
{F8A1FDE5-930E-48D0-A26C-00620701CB78}.Debug|x86.Build.0 = Debug|Any CPU
{F8A1FDE5-930E-48D0-A26C-00620701CB78}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F8A1FDE5-930E-48D0-A26C-00620701CB78}.Release|Any CPU.Build.0 = Release|Any CPU
{F8A1FDE5-930E-48D0-A26C-00620701CB78}.Release|x64.ActiveCfg = Release|Any CPU
{F8A1FDE5-930E-48D0-A26C-00620701CB78}.Release|x64.Build.0 = Release|Any CPU
{F8A1FDE5-930E-48D0-A26C-00620701CB78}.Release|x86.ActiveCfg = Release|Any CPU
{F8A1FDE5-930E-48D0-A26C-00620701CB78}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -284,6 +298,7 @@ Global
{3521DC79-706D-4B21-81BC-2D6C793FE17F} = {4503B3D3-D2C7-4FE8-A450-5A051089635C}
{0B450A6C-5EF2-409D-8079-B61D235E1FB7} = {C0FE0076-894A-4462-8B31-3099EDBCE0A7}
{8669DBAE-75B0-4347-9648-1B8C6E389035} = {4503B3D3-D2C7-4FE8-A450-5A051089635C}
{F8A1FDE5-930E-48D0-A26C-00620701CB78} = {24BF590F-A466-4AB2-B750-A14C4CA2EFF2}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {E2F0A4B1-A064-41DD-B0C3-A4FF892EF46A}
Expand Down
7 changes: 0 additions & 7 deletions ChatRoom/ChatRoom.StaticWebUI/Class1.cs

This file was deleted.

1 change: 1 addition & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<ImplicitUsings>enable</ImplicitUsings>
<IsTestProject>false</IsTestProject>
<IsPackable>false</IsPackable>
<LangVersion>preview</LangVersion>
</PropertyGroup>

<ItemGroup Condition="'$(IsTestProject)' == 'true'">
Expand Down
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
## 🌟 Highlights
- **Multi-Agent WebUI**: Chat with multiple agents simultaneously in a web browser.
- **Server mode**: You can run `ChatRoom.Client` as a restful server. For more information, see [Server mode](#-server-mode).
- **Extensible**: Create your own agents and integrate them into the chatroom.
- **API driven**: Use the `ChatRoom.SDK` to interact with the chatroom server programmatically.
- **Extensible**: Use code-first approach to add your own agents to the chatroom.

## Install from NuGet
`Agent Chatroom` is published as a dotnet tool on nuget.org. You can install the latest `Agent Chatroom` client from nuget.org by running the following command, this will install the `ChatRoom.Client` globally:
Expand Down Expand Up @@ -64,9 +65,6 @@ We provide the following configuration to help you get started quickly. More con
## 🌐 Server mode
To start a restful backend from `ChatRoom.Client`, add a `server_config` section to the client configuration file.

> [!Note]
> You can find the complete configuration sample in [chatroom-client-server.json](configuration/chatroom-client-server.json)
```json
// file: chatroom-client-server.json
"server_config": {
Expand Down
57 changes: 57 additions & 0 deletions example/dotnet/hello-world/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@


using AutoGen.Core;
using ChatRoom.SDK;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;

#region start_chatroom_server
// program.cs
var serverConfig = new ChatRoomServerConfiguration
{
RoomConfig = new RoomConfiguration
{
Room = "room",
Port = 30000,
},
YourName = "User",
// provide the server configuration for in-proc chatroom server
ServerConfig = new ServerConfiguration
{
Urls = "http://localhost:50001",
},
};

using var host = Host.CreateDefaultBuilder()
.UseChatRoomServer(serverConfig)
.Build();

await host.StartAsync();
#endregion

#region get_chatroom_client
// program.cs
var client = host.Services.GetRequiredService<ChatPlatformClient>();
var agent = new HelloWorldAgent("hello_world");

await client.RegisterAutoGenAgentAsync(agent, "A hello world agent.");
await host.WaitForShutdownAsync();
#endregion

#region hello_world_agent
// program.cs
public class HelloWorldAgent : IAgent
{
public HelloWorldAgent(string name)
{
Name = name;
}

public string Name { get; }

public async Task<IMessage> GenerateReplyAsync(IEnumerable<IMessage> messages, GenerateReplyOptions? options = null, CancellationToken cancellationToken = default)
{
return new TextMessage(Role.Assistant, "Hello, World!", from: this.Name);
}
}
#endregion
16 changes: 16 additions & 0 deletions example/dotnet/hello-world/hello-world.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<RootNamespace>hello_world</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\ChatRoom\ChatRoom.Common\ChatRoom.SDK.csproj" />
<ProjectReference Include="..\..\..\ChatRoom\ChatRoom.StaticWebUI\ChatRoom.StaticWebUI.csproj" />
</ItemGroup>

</Project>
1 change: 0 additions & 1 deletion example/dotnet/weather-agent/weather-agent.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="AutoGen.OpenAI" />
<PackageReference Include="AutoGen.SourceGenerator" />
</ItemGroup>

Expand Down
12 changes: 12 additions & 0 deletions website/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
###############
# folder #
###############
/**/DROP/
/**/TEMP/
/**/packages/
/**/bin/
/**/obj/

# build artifacts for web
_site/
api/
30 changes: 30 additions & 0 deletions website/docfx.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,36 @@
{
"metadata": [
{
"src": [
{
"files": ["ChatRoom/**/*.csproj"],
"src": "../",
"exclude": [
"**/bin/**",
"**/obj/**",
"**/ChatRoom.StaticWebUI/**"
]
}
],
"dest": "api",
"includePrivateMembers": false,
"disableGitFeatures": false,
"disableDefaultFilter": false,
"noRestore": false,
"namespaceLayout": "flattened",
"memberLayout": "samePage",
"allowCompilationErrors": false,
"filter": "filterConfig.yml"
}
],
"build": {
"content": [
{
"files": [
"api/**.yml",
"api/index.md"
]
},
{
"files": [
"articles/**.md",
Expand Down
3 changes: 3 additions & 0 deletions website/filterConfig.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
apiRules:
- include:
uidRegex: ^ChatRoom.SDK
9 changes: 0 additions & 9 deletions website/get_start/configure_client.md

This file was deleted.

9 changes: 2 additions & 7 deletions website/get_start/toc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,6 @@
href: chat_with_powershell_helpers.md
- name: Write release notes with Github agents
href: write_release_notes.md

- name: Guide
items:
- name: Develop an agent
href: coming_soon.md
- name: Develop an orchestrator
href: coming_soon.md
- name: Add AutoGen.Net agent to chatroom
href: use_autogen_net_agent.md

59 changes: 59 additions & 0 deletions website/get_start/use_autogen_net_agent.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
You can add AutoGen agent from your project to **Agent ChatRoom** using a code-first approach. First, you need to configure the chatroom services to either start a in-proc server or connect to an out-proc one. Then you create a @ChatRoom.SDK.ChatPlatformClient from configured services and use it to interact with the chatroom server. Finally, you can add an AutoGen agent to the chatroom by calling the @ChatRoom.SDK.ChatPlatformClient.RegisterAutoGenAgentAsync method on the `ChatPlatformClient` object.

> [!Note]
> `AutoGen.Net` is the .NET implementation of the AutoGen framework. It provides first-class support for connecting to various LLM platforms, tool-call usage, group chat and more. You can find more information and tutorial about `AutoGen.Net` [here](https://microsoft.github.io/autogen-for-net/index.html)
In the rest of tutorial, we will show you how to add an AutoGen agent to the chatroom using the code-first approach step by step.

## Step 1: Create an empty console project and install the ChatRoom SDK and AutoGen.Net

To create a new console project, open a terminal and run the following command:

```bash
dotnet new console -n hello-world
cd hello-world
```

Next, install the following NuGet packages:

```bash
dotnet add package ChatRoom.SDK
dotnet add package ChatRoom.StaticWebUI # the artifacts for web-based chatroom UI
```

## Step 2: Create an in-proc chatroom server and connect to it

>[!TIP]
> ### in-proc VS out-proc
> - In-proc: The chatroom server runs in the same process as the client project. Client will configure and start the server.
> - Out-proc: The chatroom server runs in a separate process. Client will connect to the server using room name and port number.
In this step, we will create an in-proc chatroom server and start it. Note that we are using the in-proc mode, we also need to provide a `ServerConfig` object to chatroom server configuration.

[!code-csharp[program](../../example/dotnet/hello-world/Program.cs?name=start_chatroom_server)]

## Step 3: Create a dummy AutoGen agent that always returns `Hello, World!`

In this step, we will create a dummy AutoGen agent that always returns `Hello, World!`. First, create a new class named `HelloWorldAgent` in the project, and implement the `IAgent` interface:

[!code-csharp[hello_world_agent](../../example/dotnet/hello-world/Program.cs?name=hello_world_agent)]

## Step 4: Get `ChatPlatformClient` from service collections and register the hello-world agent

The @ChatRoom.SDK.ChatPlatformClient is the entry point to interact with chatroom server. You can use it to programmatically interact with the chatroom server.

In this step, we will get the `ChatPlatformClient` instance from service collections and register the `hello-wrold` agent to the chatroom server. Once the agent is registered, you can use the chatroom UI to interact with the agent.

[!code-csharp[register_agent](../../example/dotnet/hello-world/Program.cs?name=get_chatroom_client)]

## Final Step: Run the chatroom server
Now all the code is ready. You can run the chatroom server by running the console project. After the server is started, you can open a web browser and navigate to `http://localhost:50001` to use the web-based chatroom UI.

```bash
dotnet run
```

![Hello, World!](../images/use_autogen_net_agent/hello-world.png)

## Conclusion
In this tutorial, we have shown you how to add an AutoGen agent to the chatroom using the code-first approach. You can use the same approach to add other AutoGen agents to the chatroom. If you have any questions or feedback, please feel free to contact us.
4 changes: 4 additions & 0 deletions website/get_start/write_release_notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,8 @@ The `issue-helper` agent will respond with the list of completed issues in the m
The `gpt4o` agent will respond with the release notes generated based on the completed issues in the milestone. After the release note are generated, you can ask `gpt4o` to improve the release note (if needed) or save the release note for further use.

## Conclusion
<<<<<<< HEAD
This tutorial introduced how the release notes of `Agent-Chatroom` is written using `Agent-Chatroom` and github agents. The release notes are generated based on the completed issue in the milestone of the project. The release notes are written in markdown format and are displayed on the [release notes](../release_notes/) page.
=======
This tutorial introduced how the release notes of `Agent-Chatroom` is written using `Agent-Chatroom` and github agents. The release notes are generated based on the completed issue in the milestone of the project. The release notes are written in markdown format and are displayed on the [release notes](../release_notes/) page.
>>>>>>> main
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions website/toc.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
- name: Documentation
href: get_start/

- name: API Reference
href: api/

- name: Release Notes
href: release_notes/

0 comments on commit 9e54e37

Please sign in to comment.