SocietyOfMindAgent
Explore the demonstration of the SocietyOfMindAgent in the AG2 library, which runs a group chat as an internal monologue, but appears to the external world as a single agent, offering a structured way to manage complex interactions among multiple agents and handle issues such as extracting responses from complex dialogues and dealing with context window constraints.
TODO: reimplement the society of mind agent using register_nested_chat
and move to the core library.
This notebook demonstrates the SocietyOfMindAgent, which runs a group chat as an internal monologue, but appears to the external world as a single agent. This confers three distinct advantages:
- It provides a clean way of producing a hierarchy of agents, hiding complexity as inner monologues.
- It provides a consistent way of extracting an answer from a lengthy group chat (normally, it is not clear which message is the final response, and the response itself may not always be formatted in a way that makes sense when extracted as a standalone message).
- It provides a way of recovering when agents exceed their context window constraints (the inner monologue is protected by try-catch blocks)
Learn more about configuring LLMs for agents here.
Example Group Chat with Two Agents
In this example, we will use an AssistantAgent and a UserProxy agent (configured for code execution) to work together to solve a problem. Executing code requires at least two conversation turns (one to write the code, and one to execute the code). If the code fails, or needs further refinement, then additional turns may also be needed. We will then wrap these agents in a SocietyOfMindAgent, hiding the internal discussion from other agents (though will still appear in the console), and ensuring that the response is suitable as a standalone message.
Construct the Inner-Monologue Agents
We begin by constructing the inner-monologue agents. These are the agents that do that real work.
Construct and Run the SocietyOfMind Agent
We now wrap the inner group-chat with the SocietyOfMind Agent, and create a UserProxy to talk to it.
Remarks
There are a few things to notice about this output: - First, the user_proxy sent only one message to the society_of_mind agent, and received only one message in response. As far as it is concerned, the society_of_mind agent is the only agent in the chat. - Second, the final response is formatted in a way that is standalone. Unlike the prior response, it makes no reference of a previous script or execution, and it lacks the TERMINATE keyword that ended the inner monologue.