AI

A Comprehensive Coding Guide to Crafting Advanced Round-Robin Multi-Agent Workflows with Microsoft AutoGen

In this tutorial, we have shown how the Microsoft Autogen framework enables developers to regulate the complex multi -agent workflow with minimal code. By taking advantage of Autogen’s Roundrobingroupchat and Teamtool Abstruptions, you can assemble smoothly specialized assistants, such as researchers, fact monitors, critics, editors, and editors, to a coherent “deep” tool. Autogen deals with the complexities of the transitional conditions, termination, and broadcasting of the broadcast, allowing you to focus on determining the experience of each agent and demands of the system instead of reconnecting together or handicraft chains. Whether it is to conduct in -depth research, verify facts, prose refining, or integrate the third butcher tools, Autogen provides a unified applications programming interface that holds from simple pipelines from two as to cooperation with the cooperation of five agents.

!pip install -q autogen-agentchat[gemini] autogen-ext[openai] nest_asyncio

We install the Autogen Agentchat package with Gemini’s support, the Openai supplement for API compatibility, and the Nest_asyncio library to correct the episode of the notebook event event, making sure that you have all the ingredients needed to operate a multi -kwak simultaneous workflow in colum.

import os, nest_asyncio
from getpass import getpass


nest_asyncio.apply()
os.environ["GEMINI_API_KEY"] = getpass("Enter your Gemini API key: ")

We import and apply Nest_asyncio to enable interrelated events in notebooks, then safely demand the API Gemini key using GetPass and store it in OS.NVIRON to reach the customer of the approved form.

from autogen_ext.models.openai import OpenAIChatCompletionClient


model_client = OpenAIChatCompletionClient(
    model="gemini-1.5-flash-8b",    
    api_key=os.environ["GEMINI_API_KEY"],
    api_type="google",
)

We configure the Openai-Compaatib chat that was directed to the GEMINI from Google by selecting the Gemini-1.5-Flash-8B model, which leads to the stored API GEINI key injection, and the API_type preparation, which gives you a ready-to-use model for automatic spontaneous workers.

from autogen_agentchat.agents import AssistantAgent


researcher   = AssistantAgent(name="Researcher", system_message="Gather and summarize factual info.", model_client=model_client)
factchecker  = AssistantAgent(name="FactChecker", system_message="Verify facts and cite sources.",       model_client=model_client)
critic       = AssistantAgent(name="Critic",    system_message="Critique clarity and logic.",         model_client=model_client)
summarizer   = AssistantAgent(name="Summarizer",system_message="Condense into a brief executive summary.", model_client=model_client)
editor       = AssistantAgent(name="Editor",    system_message="Polish language and signal APPROVED when done.", model_client=model_client)

We define five specialized assistant agents, researchers, facts reformer, critic, summary, and editor, each of which is to create a message of a system for the role and the customer of the joint model that works in Jimini, and enables them to collect information, respectively, verify accuracy, criticism content, condensed summaries, and the Polish language in the field of automatic work.

from autogen_agentchat.teams import RoundRobinGroupChat
from autogen_agentchat.conditions import MaxMessageTermination, TextMentionTermination


max_msgs = MaxMessageTermination(max_messages=20)
text_term = TextMentionTermination(text="APPROVED", sources=["Editor"])
termination = max_msgs | text_term                                    
team = RoundRobinGroupChat(
    participants=[researcher, factchecker, critic, summarizer, editor],
    termination_condition=termination
)

We import the Roundrobingroupchat category along with two terminal stipulations, then put the stop base that shoots after 20 total letters or when the “approved” editor is mentioned. Finally, it installs a round Robin team of the five specialized agents with the logic of joint termination, and enables them to rotate through research, examining facts, criticism, summary, and editing until one of the conditions for stopping is fulfilled.

from autogen_agentchat.tools import TeamTool


deepdive_tool = TeamTool(team=team, name="DeepDive", description="Collaborative multi-agent deep dive")

We wrap our Roundrobingroupchat team in the Teamtool team called “Deepdive” with a readable description, and fill out the entirely multi -agent workflow to one communication tool that other agents can call smoothly.

host = AssistantAgent(
    name="Host",
    model_client=model_client,
    tools=[deepdive_tool],
    system_message="You have access to a DeepDive tool for in-depth research."
)

We create a “host” assistant agent formed using Model_client, which works in the joint gymnastics, and gives him the tool of the deep team to organize in -depth research, and tells it with a system of a system that teaches it by its ability to summon the work of multiple agents.

import asyncio


async def run_deepdive(topic: str):
    result = await host.run(task=f"Deep dive on: {topic}")
    print("🔍 DeepDive result:\n", result)
    await model_client.close()


topic = "Impacts of Model Context Protocl on Agentic AI"
loop = asyncio.get_event_loop()
loop.run_until_complete(run_deepdive(topic))

Finally, we define the invalid run_deepdive function that tells the host agent to implement the deep team tool in a specific topic, print the comprehensive result, then closes the form of the form; Then he holds the current ASYNCIO episode of Colab and runs Coroutine to complete the synchronous smooth implementation.

In conclusion, the merging of Google Gemini through Openai’s Openai’s Openai and our multi -factor team as a communication team that gives us a strong template to build a very reusable unit traffic flow. Autogen Abstracts Away Event Loop Management (with Nest_asyncio), flowing responses, and the logic of termination, allowing us to repeat quickly on the roles of the agent and comprehensive coordination. This advanced style simplifies the development of cooperative artificial intelligence systems and sets the basis for extension in retrieval pipelines, dynamic determinants, or police implementation strategies.


Check the notebook here. All the credit for this research goes to researchers in this project. Also, do not hesitate to follow us twitter And do not forget to join 95K+ ML Subreddit And subscribe to Our newsletter.


Asif Razzaq is the CEO of Marktechpost Media Inc .. As a pioneer and vision engineer, ASIF is committed to harnessing the potential of artificial intelligence for social goodness. His last endeavor is to launch the artificial intelligence platform, Marktechpost, which highlights its in -depth coverage of machine learning and deep learning news, which is technically sound and can be easily understood by a wide audience. The platform is proud of more than 2 million monthly views, which shows its popularity among the masses.

Don’t miss more hot News like this! Click here to discover the latest in AI news!

2025-05-24 03:55:00

Related Articles

Back to top button