Please use the official AutoGen.Net
This repo contains an unofficial implementation of AutoGen for dotnet. It is a library that allows you to build a group chat bot that can help you to resolve tasks by writing and running code.
First add the following package reference to your project file:
<ItemGroup>
<PackageReference Include="AgentChat.Core" />
<!-- Add AgentChat.OpenAI to connect to OpenAI chat models -->
<PackageReference Include="AgentChat.OpenAI" />
</ItemGroup>
Nightly Build Feed: https://www.myget.org/F/agentchat/api/v3/index.json
Then you can using the following code to create an agent chat.
using AgentChat;
var gpt35 = GPT.CreateFromOpenAI(OPENAI_API_KEY, GPT_35_MODEL_ID);
var alice = gpt35.CreateAgent(
name: "Alice",
roleInformation: "You are a helpful AI assistant.");
var bob = gpt35.CreateAgent(
name: "Bob",
roleInformation: "You are a helpful AI assistant.");
var chatHistory = await alice.SendMessageToAgentAsync(
bob,
"Hi, I am Alice.",
maxRound: 1);
// chatHistory
// From Alice: Hi, I am Alice.
// From Bob: Hi, I am Bob.
using AgentChat;
var gpt35 = GPT.CreateFromOpenAI(OPENAI_API_KEY, GPT_35_MODEL_ID);
var alice = gpt35.CreateAgent(
name: "Alice",
roleInformation: "You are a helpful AI assistant.");
var bob = gpt35.CreateAgent(
name: "Bob",
roleInformation: "You are a helpful AI assistant.");
var carol = gpt35.CreateAgent(
name: "Carol",
roleInformation: "You are a helpful AI assistant.");
var group = new GroupChat(
chatLLM: gpt35,
admin: alice,
agents: new[] { bob, carol });
var chatHistory = await alice.SendMessageToGroupAsync(
group,
"Hi, I am Alice.",
maxRound: 3);
// chatHistory
// From Alice: Hi, I am Alice.
// From Bob: Hi, I am Bob.
// From Carol: Hi, I am Carol.
You can augment agent chat with function call.
// file: SayNameFunction.cs
using AgentChat;
/// <summary>
/// Say name.
/// </summary>
/// <param name="name">name.</param>
[FunctionAttribution]
public async Task<string> SayName(string name)
{
return $"Your name is {name}.";
}
// file: Program.cs
using AgentChat;
var sayNameFunction = new SayNameFunction();
var gpt35 = GPT.CreateFromOpenAI(OPENAI_API_KEY, GPT_35_MODEL_ID);
var heisenberg = gpt35.CreateAgent(
name: "Heisenberg",
roleInformation: "You are Heisenberg.");
var bob = gpt35.CreateAgent(
name: "Bob",
roleInformation: "You call SayName function.",
functionMap: new Dictionary<FunctionDefinition, Func<string, Task<string>>>{
{ sayNameFunction.SayNameFunction, sayNameFunction.SayNameWrapper }
});
var chatHistory = await heisenberg.SendMessageToAgentAsync(
bob,
"Say, My, Name.",
maxRound: 1);
// chatHistory
// From Heisenberg: Say, My, Name.
// From Bob: Your name is Heisenberg.
AgentChat.OpenAI
provides a source generator that generates FunctionDefition
and wrapper caller according to the signature of a function. For more information, please check Facilitate Chat FunctionCall for GPT-series model.
You can find notebook examples from here.
You can find more examples from below table.
Name | Description |
---|---|
dotnet interpreter | Using LLM to resolve task by writing and running csharp code. |
coder runner | Group chat using coder-runner pattern. This example shows how to use a coder agent and a runner agent to find the most recent PR from ML.Net using github api and save it under pr.txt. |
coder runner examplar | Group chat using coder-runner-examplar pattern. This example shows how to use a mlnet examplar agent, a coder agent and a runner agent to train a lightgbm binary classifier on a dummy dataset and save the model as lgbm.mlnet. |
To run the examples, you first need to configure the environment variables. See How to configure environment for GPT access for more information.
check out our AutoGen library for more information over group chat.
In order to run examples under this repo, you need to provide the following environment variables:
OPENAI_API_KEY
- your OpenAI API key
AZURE_OPENAI_ENDPOINT
- your Azure OpenAI endpointAZURE_OPENAI_API_KEY
- your Azure OpenAI key- (Optional)
AZURE_GPT_35_MODEL_ID
- GPT-3.5 model name (default:gpt-35-turbo
) - (Optional)
AZURE_GPT_4_MODEL_ID
- GPT-4 model name (default:gpt-4.0
)