Agent
is one of the most fundamental concepts in AutoGen.Net. In AutoGen.Net, you construct a single agent to process a specific task, and you extend an agent using Middlewares, and you construct a multi-agent workflow using GroupChat.
Note
Every agent in AutoGen.Net implements IAgent, for agent that supports streaming reply, it also implements IStreaming
Create an agent
- Create an Assistant
Agent : Create an assistant agent - Create an Open
AIChat : Create an OpenAI chat agentAgent - Create a Semantic
Kernel : Create a semantic kernel agentAgent - Create a LMStudio
Agent : Connect to LM Studio
Chat with an agent
To chat with an agent, typically you can invoke Generate
Note
AutoGen provides a list of built-in message types like Text
- Send a Text
Message to an agent via GenerateReply :Async
var message = new TextMessage(Role.User, "Hello");
IMessage reply = await agent.GenerateReplyAsync([message]);
- Send a message to an agent via Send
Async :
reply = await agent.SendAsync("Hello");
Streaming chat
If an agent implements IStreaming
- Send a Text
Message to an agent via GenerateStreaming , and print the streaming updates to console:Reply Async
var textMessage = new TextMessage(Role.User, "Hello");
await foreach (var streamingReply in agent.GenerateStreamingReplyAsync([message]))
{
if (streamingReply is TextMessageUpdate update)
{
Console.Write(update.Content);
}
}
Register middleware to an agent
IMiddleware and IStreaming
- Middleware overview: Middleware overview
- Write message to console: Print message middleware
- Convert message type: SemanticKernelChatMessageContentConnector and OpenAIChatRequestMessageConnector
- Create your own middleware: Create your own middleware
Group chat
You can construct a multi-agent workflow using IGroup
For further details, see Group chat overview.