Skip to content

[.Net] Support graph group chat by adding workflow and transition.#1761

Merged
LittleLittleCloud merged 5 commits into
dotnetfrom
u/xiaoyun/dotnet-workflow
Feb 23, 2024
Merged

[.Net] Support graph group chat by adding workflow and transition.#1761
LittleLittleCloud merged 5 commits into
dotnetfrom
u/xiaoyun/dotnet-workflow

Conversation

@LittleLittleCloud

@LittleLittleCloud LittleLittleCloud commented Feb 22, 2024

Copy link
Copy Markdown
Collaborator

Why are these changes needed?

This PR enables graph group chat in AutoGen.Net by adding a Workflow and Transition class.

Transition

Transition represents a transit step from one agent to another. To create a Transition, using Transition.Create

Transition also conditionally accepts a lambda function which determines if it's enable or not. This allows workflow to be dynamically adjusted based on conversation. (Inspired by the Workflow in PROSE.Conversations)

var alice = new EchoAgent("alice");
var bob = new EchoAgent("bob");

// create a transition that is enabled in all situation.
var aliceToBob = Transition.Create(alice, bob);

// create a transition that is enabled only when conversation satisfy a certain condition
var aliceToBobWhenMessageIsHello = Transition.Create(alice, bob, async (from, to, messages) =>
{
    if (messages.Any(m => m is { Content: "Hello" }))
    {
        return true;
    }

    return false;
});

Workflow

Workflow is essentially a list of Transition. The next transabled candidates from one agent can be retrieved by TransitToNextAvailableAgentsAsync API

To create a workflow

var alice = new EchoAgent("alice");
var bob = new EchoAgent("bob");
var charlie = new EchoAgent("charlie");

// alice can speak to bob
// bob can speak to charlie
// charlie can speak to alice
var aliceToBob = Transition.Create(alice, bob);
var bobToCharlie = Transition.Create(bob, charlie);
var charlieToAlice = Transition.Create(charlie, alice);
var workflow = new Workflow([aliceToBob, bobToCharlie, charlieToAlice]);

var nextAgents = await workflow.TransitToNextAvailableAgentsAsync(alice , []); // nextAgents will be [bob]

Consume workflow in group chat

The group chat now supports workflow. In SelectNextSpeaker function, the group chat will first retrieve the available candidates based on current agent and work flow, then use admin to intelligently decide the next speaker.
To consume a workflow in group chat, simply pass it when creating the group

var groupChat = new GroupChat(
   workflow: workflow,
   ...);

Example

checkout Example04_Dynamic_GroupChat_Coding_Task which is accommodated to groupchat with workflow

Related issue number

Resolve #1648

Checks

@LittleLittleCloud LittleLittleCloud added the dotnet issues related to AutoGen.Net label Feb 22, 2024
@LittleLittleCloud LittleLittleCloud changed the base branch from main to dotnet February 22, 2024 08:25
@codecov-commenter

codecov-commenter commented Feb 22, 2024

Copy link
Copy Markdown

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (1e07f47) 39.35% compared to head (f3570cf) 39.12%.

Additional details and impacted files
@@            Coverage Diff             @@
##           dotnet    #1761      +/-   ##
==========================================
- Coverage   39.35%   39.12%   -0.24%     
==========================================
  Files          57       57              
  Lines        6093     6173      +80     
  Branches     1362     1383      +21     
==========================================
+ Hits         2398     2415      +17     
- Misses       3499     3564      +65     
+ Partials      196      194       -2     
Flag Coverage Δ
unittests 39.12% <ø> (-0.24%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@joshkyh joshkyh left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the invite to review. I don't code in .net so I might be wrong here, I think the current functionalities only support the provision of Allowed Transitions. I'm not sure if you meant to fully translate the Python functionalities which could be missing here in .net.

  1. Support the input of Disallowed Transitions.
  2. Transitions validations and raising warnings where appropriate?

@LittleLittleCloud

Copy link
Copy Markdown
Collaborator Author

@joshkyh

Overall, it's not the goal of this PR to fully transfer what python autogen graph chat has to dotnet one. And there'll be a little difference in api design and implementation because of difference in ecosystem and language syntax.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dotnet issues related to AutoGen.Net

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature Request]: [.Net] bring Graph-based group chat to AutoGen.Net

4 participants