Use Cases
- Use cases
- Notebooks
- All Notebooks
- AutoBuild
- Tools with Dependency Injection
- Chatting with a teachable agent
- Solving Complex Tasks with Nested Chats
- Agent Tracking with AgentOps
- Config loader utility functions
- Websockets: Streaming input and output using websockets
- A Uniform interface to call different LLMs
- RAG OpenAI Assistants in AG2
- From Dad Jokes To Sad Jokes: Function Calling with GPTAssistantAgent
- Agent Chat with custom model loading
- Agentic RAG workflow on tabular data from a PDF file
- Group Chat with Customized Speaker Selection Method
- RealtimeAgent in a Swarm Orchestration using WebRTC
- Auto Generated Agent Chat: Task Solving with Code Generation, Execution, Debugging & Human Feedback
- Web Scraping using Apify Tools
- Swarm Orchestration with AG2
- Currency Calculator: Task Solving with Provided Tools as Functions
- Use LLamaIndexQueryEngine to query Markdown files
- Agent with memory using Mem0
- RealtimeAgent in a Swarm Orchestration
- Solving Complex Tasks with A Sequence of Nested Chats
- Auto Generated Agent Chat: Teaching AI New Skills via Natural Language Interaction
- (Legacy) Implement Swarm-style orchestration with GroupChat
- Use AG2 to Tune ChatGPT
- Perplexity Search Tool
- Perform Research with Multi-Agent Group Chat
- Usage tracking with AG2
- Auto Generated Agent Chat: Collaborative Task Solving with Coding and Planning Agent
- DeepSeek: Adding Browsing Capabilities to AG2
- Chat with OpenAI Assistant using function call in AG2: OSS Insights for Advanced GitHub Data Analysis
- RealtimeAgent with gemini client
- Solving Multiple Tasks in a Sequence of Async Chats
- Group Chat with Tools
- Agent with memory using Mem0
- Adding YouTube Search Capability to AG2
- OpenAI Assistants in AG2
- Demonstrating the `AgentEval` framework using the task of solving math problems as an example
- Adding Browsing Capabilities to AG2
- Group Chat with Retrieval Augmented Generation
- Cross-Framework LLM Tool Integration with AG2
- Auto Generated Agent Chat: GPTAssistant with Code Interpreter
- Auto Generated Agent Chat: Task Solving with Langchain Provided Tools as Functions
- Using Neo4j's graph database with AG2 agents for Question & Answering
- Run a standalone AssistantAgent
- StateFlow: Build Workflows through State-Oriented Actions
- Using RetrieveChat for Retrieve Augmented Code Generation and Question Answering
- ReasoningAgent - Advanced LLM Reasoning with Multiple Search Strategies
- Use AG2 to Tune OpenAI Models
- Generate Dalle Images With Conversable Agents
- DeepResearchAgent
- Enhanced Swarm Orchestration with AG2
- Structured output from json configuration
- Agent Observability with OpenLIT
- Use ChromaDBQueryEngine to query Markdown files
- Auto Generated Agent Chat: Solving Tasks Requiring Web Info
- Task Solving with Code Generation, Execution and Debugging
- Use MongoDBQueryEngine to query Markdown files
- RealtimeAgent with WebRTC connection
- Adding Google Search Capability to AG2
- Solving Multiple Tasks in a Sequence of Chats
- Using RetrieveChat with Qdrant for Retrieve Augmented Code Generation and Question Answering
- Writing a software application using function calls
- Google Drive Tools
- Runtime Logging with AG2
- Load the configuration including the response format
- Using RetrieveChat Powered by MongoDB Atlas for Retrieve Augmented Code Generation and Question Answering
- WebSurferAgent
- Using FalkorGraphRagCapability with agents for GraphRAG Question & Answering
- Auto Generated Agent Chat: Task Solving with Provided Tools as Functions
- Preprocessing Chat History with `TransformMessages`
- CaptainAgent
- FSM - User can input speaker transition constraints
- OptiGuide with Nested Chats in AG2
- Group Chat with Coder and Visualization Critic
- Mitigating Prompt hacking with JSON Mode in Autogen
- Translating Video audio using Whisper and GPT-3.5-turbo
- Auto Generated Agent Chat: Group Chat with GPTAssistantAgent
- Interactive LLM Agent Dealing with Data Stream
- Engaging with Multimodal Models: GPT-4V in AG2
- Using Guidance with AG2
- SQL Agent for Spider text-to-SQL benchmark
- Conversational Chess using non-OpenAI clients
- Group Chat
- Auto Generated Agent Chat: Function Inception
- Making OpenAI Assistants Teachable
- Use AG2 in Databricks with DBRX
- Agent Chat with Async Human Inputs
- Using RetrieveChat Powered by PGVector for Retrieve Augmented Code Generation and Question Answering
- Groupchat with Llamaindex agents
- Discord, Slack, and Telegram messaging tools
- Chat Context Dependency Injection
- Structured output
- Trip planning with a FalkorDB GraphRAG agent using a Swarm
- RealtimeAgent in a Swarm Orchestration
- Small, Local Model (IBM Granite) Multi-Agent RAG
- Assistants with Azure Cognitive Search and Azure Identity
- Supercharging Web Crawling with Crawl4AI
- RealtimeAgent with local websocket connection
- Using a local Telemetry server to monitor a GraphRAG agent
- AgentOptimizer: An Agentic Way to Train Your LLM Agent
- Using RetrieveChat Powered by Couchbase Capella for Retrieve Augmented Code Generation and Question Answering
- Using Neo4j's native GraphRAG SDK with AG2 agents for Question & Answering
- Automatically Build Multi-agent System from Agent Library
- Nested Chats for Tool Use in Conversational Chess
- Task Solving with Provided Tools as Functions (Asynchronous Function Calls)
- SocietyOfMindAgent
- Use AG2 in Microsoft Fabric
- Language Agent Tree Search
- Agent Chat with Multimodal Models: LLaVA
- Agent Chat with Multimodal Models: DALLE and GPT-4V
- Auto Generated Agent Chat: Collaborative Task Solving with Multiple Agents and Human Users
- RealtimeAgent in a Swarm Orchestration
- Cross-Framework LLM Tool for CaptainAgent
- Solving Multiple Tasks in a Sequence of Chats with Different Conversable Agent Pairs
- RAG with DocAgent
- Auto Generated Agent Chat: Using MathChat to Solve Math Problems
- Community Gallery
Group Chat with Tools
Group Chat with Tools
This notebook explains how to set up a group chat where each agent has unique capabilities and is equipped with specialized tools to perform specific tasks.
Installation
pip install -U ag2[openai]
Note: If you have been using
autogen
orpyautogen
, all you need to do is upgrade it using:pip install -U autogen[openai]
or
pip install -U pyautogen[openai]
as
pyautogen
,autogen
, andag2
are aliases for the same PyPI package.
Imports
import random
from autogen import (
ConversableAgent,
GroupChat,
GroupChatManager,
LLMConfig,
UserProxyAgent,
register_function,
)
Agent Configuration
The GroupChat
will contain three agents: - sales_agent
- Responsible
for selling tickets. - cancellation_agent
- Handles ticket
cancellations. - user_proxy
- Acts as an intermediary between the user
and other agents.
llm_config = LLMConfig.from_json(path="OAI_CONFIG_LIST").where(model=["gpt-4o-mini"])
sales_agent = ConversableAgent(
name="SalesAgent",
llm_config=llm_config,
)
cancellation_agent = ConversableAgent(
name="CanelationAgent",
llm_config=llm_config,
)
user_proxy = UserProxyAgent(
name="user_proxy",
human_input_mode="ALWAYS",
)
Tools Registration
In AG2, tool usage follows two steps: - An agent suggests a tool to use (via its LLM). - Another agent executes the tool.
We will define two tools: - buy_airplane_ticket
: Suggested by
sales_agent
and executed by user_proxy
after user verification. -
cancel_airplane_ticket
: Suggested by cancellation_agent
and executed
by user_proxy
after user verification.
def buy_airplane_ticket(from_location: str, to_location: str, date: str) -> str:
ticket_number = random.randint(1000, 9999)
return f"""Your ticket from {from_location} to {to_location} on {date} has been booked.
Your ticket number is {ticket_number}.
Please keep this number for future reference.
"""
register_function(
buy_airplane_ticket,
caller=sales_agent,
executor=user_proxy,
description="Buy an airplane ticket",
)
def cancel_airplane_ticket(ticket_number: str) -> str:
return f"Your ticket with ticket number {ticket_number} has been canceled"
register_function(
cancel_airplane_ticket,
caller=cancellation_agent,
executor=user_proxy,
description="Cancel an airplane ticket",
)
Creating and Initiating the Group Chat
Now, let’s create and start the GroupChat
with the three agents.
groupchat = GroupChat(
agents=[user_proxy, cancellation_agent, sales_agent],
speaker_selection_method="auto",
messages=[],
)
manager = GroupChatManager(
name="group_manager",
groupchat=groupchat,
llm_config=llm_config,
)
user_proxy.initiate_chat(
recipient=manager,
message="I need to buy a plane ticket from New York to Los Angeles on 12th of April 2025",
)