Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

LittleLittleCloud/AgentChat

Repository files navigation

This repo is archived

Please use the official AutoGen.Net

An unofficial implementation of AutoGen for dotnet

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.

CI nightly-build

Usage

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.

TwoAgent 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.

Group 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 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.

Function call

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.

Notebook Examples

You can find notebook examples from here.

More Examples

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.

Group chat

check out our AutoGen library for more information over group chat.

How to configure environment for GPT access

In order to run examples under this repo, you need to provide the following environment variables:

OpenAI

  • OPENAI_API_KEY - your OpenAI API key

Azure OpenAI

  • AZURE_OPENAI_ENDPOINT - your Azure OpenAI endpoint
  • AZURE_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)

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published