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 IStreamingAgent.
Create an agent
- Create an AssistantAgent: Create an assistant agent
- Create an OpenAIChatAgent: Create an OpenAI chat agent
- Create a SemanticKernelAgent: Create a semantic kernel agent
- Create a LMStudioAgent: Connect to LM Studio
Chat with an agent
To chat with an agent, typically you can invoke GenerateReplyAsync. On top of that, you can also use one of the extension methods like SendAsync as shortcuts.
Note
AutoGen provides a list of built-in message types like TextMessage, ImageMessage, MultiModalMessage, ToolCallMessage, ToolCallResultMessage, etc. You can use these message types to chat with an agent. For further details, see built-in messages.
- Send a TextMessage to an agent via GenerateReplyAsync:
var message = new TextMessage(Role.User, "Hello");
IMessage reply = await agent.GenerateReplyAsync([message]);
- Send a message to an agent via SendAsync:
reply = await agent.SendAsync("Hello");
Streaming chat
If an agent implements IStreamingAgent, you can use GenerateStreamingReplyAsync to chat with the agent in a streaming way. You would need to process the streaming updates on your side though.
- Send a TextMessage to an agent via GenerateStreamingReplyAsync, and print the streaming updates to console:
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 IStreamingMiddleware are used to extend the behavior of GenerateReplyAsync and GenerateStreamingReplyAsync. You can register middleware to an agent to customize the behavior of the agent on things like function call support, converting message of different types, print message, gather user input, etc.
- 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 IGroupChat. In AutoGen.Net, there are two type of group chat: SequentialGroupChat: Orchestrates the agents in the group chat in a fix, sequential order. GroupChat: Provide more dynamic yet controllable way to orchestrate the agents in the group chat.
For further details, see Group chat overview.