mirror of
https://github.com/microsoft/autogen.git
synced 2025-07-15 21:11:05 +00:00
85 lines
2.5 KiB
Markdown
85 lines
2.5 KiB
Markdown
![]() |
This tutorial shows how to use AutoGen.Net agent as model in AG Studio
|
||
|
|
||
|
## Step 1. Create Dotnet empty web app and install AutoGen and AutoGen.WebAPI package
|
||
|
|
||
|
```bash
|
||
|
dotnet new web
|
||
|
dotnet add package AutoGen
|
||
|
dotnet add package AutoGen.WebAPI
|
||
|
```
|
||
|
|
||
|
## Step 2. Replace the Program.cs with following code
|
||
|
|
||
|
```bash
|
||
|
using AutoGen.Core;
|
||
|
using AutoGen.Service;
|
||
|
|
||
|
var builder = WebApplication.CreateBuilder(args);
|
||
|
var app = builder.Build();
|
||
|
|
||
|
var helloWorldAgent = new HelloWorldAgent();
|
||
|
app.UseAgentAsOpenAIChatCompletionEndpoint(helloWorldAgent);
|
||
|
|
||
|
app.Run();
|
||
|
|
||
|
class HelloWorldAgent : IAgent
|
||
|
{
|
||
|
public string Name => "HelloWorld";
|
||
|
|
||
|
public Task<IMessage> GenerateReplyAsync(IEnumerable<IMessage> messages, GenerateReplyOptions? options = null, CancellationToken cancellationToken = default)
|
||
|
{
|
||
|
return Task.FromResult<IMessage>(new TextMessage(Role.Assistant, "Hello World!", from: this.Name));
|
||
|
}
|
||
|
}
|
||
|
```
|
||
|
|
||
|
## Step 3: Start the web app
|
||
|
|
||
|
Run the following command to start web api
|
||
|
|
||
|
```bash
|
||
|
dotnet RUN
|
||
|
```
|
||
|
|
||
|
The web api will listen at `http://localhost:5264/v1/chat/completion
|
||
|
|
||
|

|
||
|
|
||
|
## Step 4: In another terminal, start autogen-studio
|
||
|
|
||
|
```bash
|
||
|
autogenstudio ui
|
||
|
```
|
||
|
|
||
|
## Step 5: Navigate to AutoGen Studio UI and add hello world agent as openai Model
|
||
|
|
||
|
### Step 5.1: Go to model tab
|
||
|
|
||
|

|
||
|
|
||
|
### Step 5.2: Select "OpenAI model" card
|
||
|
|
||
|

|
||
|
|
||
|
### Step 5.3: Fill the model name and url
|
||
|
|
||
|
The model name needs to be same with agent name
|
||
|
|
||
|

|
||
|
|
||
|
## Step 6: Create a hello world agent that uses the hello world model
|
||
|
|
||
|

|
||
|
|
||
|

|
||
|
|
||
|
## Final Step: Use the hello world agent in workflow
|
||
|
|
||
|

|
||
|
|
||
|

|
||
|
|
||
|

|
||
|
|
||
|

|