<RETURN_TO_BASE

Harnessing Microsoft AutoGen and Gemini API for a Multi-Agent AI Framework

Learn how to build a multi-agent conversational AI framework by integrating Microsoft AutoGen with the free Gemini API. This tutorial covers creating specialized AI agent teams to autonomously manage research, business analysis, and software development projects.

Integrating Microsoft AutoGen with Gemini API

This tutorial demonstrates how to combine Microsoft AutoGen with Google's free Gemini API using LiteLLM to build a robust multi-agent conversational AI framework. The framework runs seamlessly on Google Colab, enabling the creation of specialized agent teams for diverse tasks such as research, business analysis, and software development.

Setting Up the Environment

To get started, install the required libraries: AutoGen, LiteLLM, and Google Generative AI. These tools facilitate multi-agent orchestration with Gemini models. Essential modules are imported, and logging is configured to monitor the framework's execution.

!pip install AutoGen
!pip install pyautogen google-generativeai litellm
 
import os
import json
import asyncio
from typing import Dict, List, Any, Optional, Callable
from datetime import datetime
import logging
 
import autogen
from autogen import AssistantAgent, UserProxyAgent, GroupChat, GroupChatManager
from autogen.agentchat.contrib.retrieve_assistant_agent import RetrieveAssistantAgent
from autogen.agentchat.contrib.retrieve_user_proxy_agent import RetrieveUserProxyAgent
 
import google.generativeai as genai
import litellm
 
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)

The GeminiAutoGenFramework Class

The core of this system is the GeminiAutoGenFramework class, which manages multi-agent conversations by integrating the Gemini API. It configures Gemini for AutoGen compatibility, creates specialized agents, and facilitates group chats among agents.

Agent Teams

  • Research Team: Includes a Researcher, Data Analyst, Writer, and Code Executor to perform thorough research projects with structured reports.
  • Business Team: Comprises a Business Strategist, Financial Analyst, Market Researcher, and a Business Executor to handle business analysis and strategy.
  • Development Team: Consists of a Senior Developer, DevOps Engineer, QA Engineer, and Dev Executor to develop, deploy, and test software projects.

Group Chat and Project Execution

The framework supports creating group chats with selected agents and running projects such as research, business analysis, and software development. Each project follows a defined workflow with clear roles assigned to each agent.

Example Usage

def demo_autogen_framework():
   print(" Microsoft AutoGen + Gemini Framework Demo")
   print("=" * 60)
 
   GEMINI_API_KEY = "your-gemini-api-key-here"
 
   framework = GeminiAutoGenFramework(GEMINI_API_KEY)
 
   print(" Framework initialized successfully!")
   print(f" Stats: {json.dumps(framework.get_framework_stats(), indent=2)}")
 
   return framework
 
async def run_demo_projects(framework):
   print("\n Running Research Project...")
   research_result = framework.run_research_project(
       "Impact of Generative AI on Software Development in 2025"
   )
   print("Research Result (excerpt):")
   print(research_result[:500] + "..." if len(research_result) > 500 else research_result)
 
   print("\n Running Business Analysis...")
   business_result = framework.run_business_analysis(
       "A mid-sized company wants to implement AI-powered customer service. "
       "They currently have 50 support staff and handle 1000 tickets daily. "
       "Budget is $500K annually."
   )
   print("Business Analysis Result (excerpt):")
   print(business_result[:500] + "..." if len(business_result) > 500 else business_result)
 
   print("\n Running Development Project...")
   dev_result = framework.run_development_project(
       "Build a Python web scraper that extracts product information from e-commerce sites, "
       "stores data in a database, and provides a REST API for data access."
   )
   print("Development Result (excerpt):")
   print(dev_result[:500] + "..." if len(dev_result) > 500 else dev_result)
 
if __name__ == "__main__":
   print("Microsoft AutoGen + Gemini Framework Ready! ")
   print("\n For Google Colab, run:")
   print("!pip install pyautogen google-generativeai litellm")
   print("\n Get your free Gemini API key:")
   print("https://makersuite.google.com/app/apikey")
   print("\n Quick start:")
   print("""
# Initialize framework
# framework = GeminiAutoGenFramework("your-gemini-api-key")
 
# Run research project 
result = framework.run_research_project("AI Trends 2025")
print(result)
 
# Run business analysis
result = framework.run_business_analysis("Market entry strategy for AI startup")
print(result)
 
# Run development project
result = framework.run_development_project("Build a REST API for user management")
print(result)
   """)

This framework offers a versatile and modular approach to orchestrating specialized AI agents in conversational settings, enabling autonomous execution of complex workflows with minimal human input.

🇷🇺

Сменить язык

Читать эту статью на русском

Переключить на Русский