dotnet/website/tutorial/Use-AutoGen.Net-agent-as-model-in-AG-Studio.md
This tutorial shows how to use AutoGen.Net agent as model in AG Studio
dotnet new web
dotnet add package AutoGen
dotnet add package AutoGen.WebAPI
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));
}
}
Run the following command to start web api
dotnet RUN
The web api will listen at `http://localhost:5264/v1/chat/completion
autogenstudio ui
The model name needs to be same with agent name