FSM Group Chat -- User-specified agent transitions
Finite State Machine (FSM) Group Chat allows the user to constrain agent transitions.
TL;DR
Recently, FSM Group Chat is released that allows the user to input a transition graph to constrain agent transitions. This is useful as the number of agents increases because the number of transition pairs (N choose 2 combinations) increases exponentially increasing the risk of sub-optimal transitions, which leads to wastage of tokens and/or poor outcomes.
Possible use-cases for transition graph
- One-pass workflow, i.e., we want each agent to only have one pass at the problem, Agent A -> B -> C.
- Decision tree flow, like a decision tree, we start with a root node (agent), and flow down the decision tree with agents being nodes. For example, if the query is a SQL query, hand over to the SQL agent, else if the query is a RAG query, hand over to the RAG agent.
- Sequential Team Ops. Suppose we have a team of 3 developer agents, each responsible for a different GitHub repo. We also have a team of business analyst that discuss and debate the overall goal of the user. We could have the manager agent of the developer team speak to the manager agent of the business analysis team. That way, the discussions are more focused team-wise, and better outcomes can be expected.
Note that we are not enforcing a directed acyclic graph; the user can specify the graph to be acyclic, but cyclic workflows can also be useful to iteratively work on a problem, and layering additional analysis onto the solution.
Usage Guide
We have added two parameters allowed_or_disallowed_speaker_transitions
and speaker_transitions_type
.
allowed_or_disallowed_speaker_transitions
: is a dictionary with the type expectation of{Agent: [Agent]}
. The key refers to the source agent, while the value(s) in the list refers to the target agent(s). If none, a fully connection graph is assumed.speaker_transitions_type
: is a string with the type expectation of string, and specifically, one of [“allowed”, “disallowed”]. We wanted the user to be able to supply a dictionary of allowed or disallowed transitions to improve the ease of use. In the code base, we would invert the disallowed transition into a allowed transition dictionaryallowed_speaker_transitions_dict
.
Application of the FSM Feature
A quick demonstration of how to initiate a FSM-based GroupChat
in the AutoGen
framework. In this demonstration, if we consider each agent as a state, and each agent speaks according to certain conditions. For example, User always initiates the task first, followed by Planner creating a plan. Then Engineer and Executor work alternately, with Critic intervening when necessary, and after Critic, only Planner should revise additional plans. Each state can only exist at a time, and there are transition conditions between states. Therefore, GroupChat can be well abstracted as a Finite-State Machine (FSM).
Usage
- Pre-requisites
-
Import dependencies
-
Configure LLM parameters
-
Define the task
-
Define agents
- Here, I have configured the
system_messages
as “task” because every agent should know what it needs to do. In this example, each agent has the same task, which is to count in sequence. - The most important point is the
description
parameter, where I have used natural language to describe the transition conditions of the FSM. Because the manager knows which agents are available next based on the constraints of the graph, I describe in thedescription
field of each candidate agent when it can speak, effectively describing the transition conditions in the FSM.
- Here, I have configured the
-
Define the graph
- The graph here and the transition conditions mentioned above together form a complete FSM. Both are essential and cannot be missing.
- You can visualize it as you wish, which is shown as follows
-
Define a
GroupChat
and aGroupChatManager
-
Initiate the chat
-
You may get the following output(I deleted the ignorable warning):
Notebook examples
More examples can be found in the notebook. The notebook includes more examples of possible transition paths such as (1) hub and spoke, (2) sequential team operations, and (3) think aloud and debate. It also uses the function visualize_speaker_transitions_dict
from autogen.graph_utils
to visualize the various graphs.