Use this file to discover all available pages before exploring further.
This example demonstrates how to build a complete research assistant application that can browse the web, analyze information, and generate comprehensive reports.
import asynciofrom typing import Listfrom autogen_agentchat.agents import AssistantAgentfrom autogen_agentchat.teams import RoundRobinGroupChatfrom autogen_agentchat.ui import Consolefrom autogen_ext.models.openai import OpenAIChatCompletionClientfrom autogen_ext.tools.mcp import McpWorkbench, StdioServerParamsclass ResearchAssistant: """Multi-agent research assistant.""" def __init__(self, model_client: OpenAIChatCompletionClient): self.model_client = model_client self.planner = None self.researcher = None self.analyzer = None self.writer = None async def setup_agents(self, mcp_workbench): """Initialize all research agents.""" # Planner: Creates research strategy self.planner = AssistantAgent( "research_planner", model_client=self.model_client, system_message="""You are a research planner. Break down research questions into specific, actionable subtasks. Identify key information needed and potential sources. Create a clear research strategy.""", model_client_stream=True, ) # Researcher: Gathers information self.researcher = AssistantAgent( "web_researcher", model_client=self.model_client, workbench=mcp_workbench, system_message="""You are a web researcher. Use web browsing tools to gather accurate, relevant information. Cite your sources and verify information from multiple sources. Focus on credible, authoritative sources.""", model_client_stream=True, max_tool_iterations=15, ) # Analyzer: Validates and analyzes information self.analyzer = AssistantAgent( "information_analyst", model_client=self.model_client, system_message="""You are an information analyst. Analyze gathered information for: - Accuracy and credibility - Relevance to the research question - Gaps or contradictions - Key insights and patterns Provide critical analysis, not just summary.""", model_client_stream=True, ) # Writer: Synthesizes findings self.writer = AssistantAgent( "report_writer", model_client=self.model_client, system_message="""You are a research report writer. Synthesize findings into a clear, comprehensive report. Structure: Executive Summary, Findings, Analysis, Conclusions. Use clear headings, bullet points, and cite sources. Write professionally and objectively.""", model_client_stream=True, ) async def research(self, question: str) -> str: """Conduct research on a question.""" team = RoundRobinGroupChat( participants=[ self.planner, self.researcher, self.analyzer, self.writer, ], max_turns=20, ) result = await Console( team.run_stream(task=f"Research question: {question}") ) return result.messages[-1].contentasync def main() -> None: model_client = OpenAIChatCompletionClient(model="gpt-4o") # Setup MCP server for web browsing server_params = StdioServerParams( command="npx", args=["@playwright/mcp@latest", "--headless"], ) async with McpWorkbench(server_params) as mcp: # Create research assistant assistant = ResearchAssistant(model_client) await assistant.setup_agents(mcp) # Conduct research question = """What are the latest developments in quantum computing and their potential impact on cryptography?""" print(f"Researching: {question}\n") report = await assistant.research(question) print("\n" + "="*80) print("FINAL REPORT") print("="*80) print(report) await model_client.close()if __name__ == "__main__": asyncio.run(main())
---------- research_planner ----------Research Strategy:1. Define current state of quantum computing2. Identify recent breakthroughs (2023-2024)3. Understand quantum threat to cryptography4. Research post-quantum cryptography solutions5. Analyze timeline and implications---------- web_researcher ----------[Browsing quantum computing sources...]Key findings:- IBM's 433-qubit Osprey processor (2023)- Google's quantum error correction breakthrough- NIST post-quantum cryptography standards- Timeline: 10-15 years to cryptographically relevant quantum computersSources:- nature.com/articles/quantum-computing-2024- nist.gov/post-quantum-cryptography- ibm.com/quantum-computing---------- information_analyst ----------Analysis:- Quantum computing advancing rapidly but still early stage- Real threat to current RSA/ECC cryptography within 10-15 years- Post-quantum algorithms being standardized now- Organizations should begin transition planning- Some areas of uncertainty remain on timeline---------- report_writer ----------EXECUTIVE SUMMARYQuantum computing poses a significant long-term threat to current cryptographic systems. While cryptographically relevant quantum computers are estimated to be 10-15 years away, organizations should begin transitioning to post-quantum cryptography now...[Full detailed report follows]
For document-based research, integrate with GraphRAG:
from autogen_agentchat.agents import AssistantAgentfrom autogen_ext.tools.graphrag import GlobalSearchTool, LocalSearchTool# Setup GraphRAG (assuming you've indexed documents)global_search = GlobalSearchTool(config_path="./graphrag_config")local_search = LocalSearchTool(config_path="./graphrag_config")# Add to researcher agentresearcher = AssistantAgent( "document_researcher", model_client=model_client, tools=[global_search, local_search], system_message="""You are a document researcher. Use GraphRAG tools to search indexed documents. - Use global search for broad questions - Use local search for specific entity information """,)