Table of Contents

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

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.

var message = new TextMessage(Role.User, "Hello");
IMessage reply = await agent.GenerateReplyAsync([message]);
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.

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.

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.