Skip to content

python-v0.6.0

Choose a tag to compare

@ekzhu ekzhu released this 05 Jun 00:37
· 128 commits to main since this release
16e1943

What's New

Change to BaseGroupChatManager.select_speaker and support for concurrent agents in GraphFlow

We made a type hint change to the select_speaker method of BaseGroupChatManager to allow for a list of agent names as a return value. This makes it possible to support concurrent agents in GraphFlow, such as in a fan-out-fan-in pattern.
 

# Original signature:
async def select_speaker(self, thread: Sequence[BaseAgentEvent | BaseChatMessage]) -> str:
  ...

# New signature:
async def select_speaker(self, thread: Sequence[BaseAgentEvent | BaseChatMessage]) -> List[str] | str:
  ...

Now you can run GraphFlow with concurrent agents as follows:

import asyncio

from autogen_agentchat.agents import AssistantAgent
from autogen_agentchat.conditions import MaxMessageTermination
from autogen_agentchat.teams import DiGraphBuilder, GraphFlow
from autogen_ext.models.openai import OpenAIChatCompletionClient


async def main():
    # Initialize agents with OpenAI model clients.
    model_client = OpenAIChatCompletionClient(model="gpt-4.1-nano")
    agent_a = AssistantAgent("A", model_client=model_client, system_message="You are a helpful assistant.")
    agent_b = AssistantAgent("B", model_client=model_client, system_message="Translate input to Chinese.")
    agent_c = AssistantAgent("C", model_client=model_client, system_message="Translate input to Japanese.")

    # Create a directed graph with fan-out flow A -> (B, C).
    builder = DiGraphBuilder()
    builder.add_node(agent_a).add_node(agent_b).add_node(agent_c)
    builder.add_edge(agent_a, agent_b).add_edge(agent_a, agent_c)
    graph = builder.build()

    # Create a GraphFlow team with the directed graph.
    team = GraphFlow(
        participants=[agent_a, agent_b, agent_c],
        graph=graph,
        termination_condition=MaxMessageTermination(5),
    )

    # Run the team and print the events.
    async for event in team.run_stream(task="Write a short story about a cat."):
        print(event)


asyncio.run(main())

Agent B and C will run concurrently in separate coroutines.

Callable conditions for GraphFlow edges

Now you can use lambda functions or other callables to specify edge conditions in GraphFlow. This addresses the issue of the keyword substring-based conditions cannot cover all possibilities and leading to "cannot find next agent" bug.

NOTE: callable conditions are currently experimental, and it cannot be serialized with the graph.

New Agent: OpenAIAgent

MCP Improvement

AssistantAgent Improvement

Code Executors Improvement

OpenAIChatCompletionClient Improvement

OllamaChatCompletionClient Improvement

AnthropicBedrockChatCompletionClient Improvement

MagenticOneGroupChat Improvement

Other Changes

New Contributors

Full Changelog: python-v0.5.7...python-v0.6.0