Python SDK for AI agent monitoring, LLM cost tracking, benchmarking, and more. Integrates with most LLMs and agent frameworks including CrewAI, Agno, OpenAI Agents SDK, Langchain, Autogen, AG2, and CamelAI
Python agentagentopsagents-sdkaianthropicautogencost-estimationcrewaievalsevaluation-metricsgroqlangchainllmmistralollamaopenaiopenai-agents
{
"cells": [
{
"cell_type": "markdown",
"id": "e78c48e2",
"metadata": {},
"source": [
"\n",
"Collaborative Research Team with Agno\n",
"--------------------------------------\n",
"\n",
"This example demonstrates how to create a sophisticated research team with multiple specialized agents,\n",
"each equipped with different tools and expertise. The team collaborates to research topics from\n",
"multiple perspectives, providing comprehensive insights.\n",
"\n",
"**Overview:**\n",
"\n",
"This example creates a research team consisting of four specialized agents:\n",
"\n",
"1. **Reddit Researcher**\n",
" - Focus: Community discussions and user experiences\n",
" - Tools: Google Search (to find Reddit discussions)\n",
" - Expertise: Analyzing user opinions, practical advice, and real-world experiences\n",
" - Role: Provides insights from community perspectives\n",
"\n",
"2. **HackerNews Researcher**\n",
" - Focus: Technical discussions and industry trends\n",
" - Tools: HackerNews API\n",
" - Expertise: Technical analysis and industry insights\n",
" - Role: Provides technical and startup ecosystem perspectives\n",
"\n",
"3. **Academic Paper Researcher**\n",
" - Focus: Scholarly research and evidence-based findings\n",
" - Tools: Google Search + Arxiv API\n",
" - Expertise: Academic literature and research methodology\n",
" - Role: Provides evidence-based academic insights\n",
"\n",
"4. **Twitter Researcher**\n",
" - Focus: Real-time trends and public sentiment\n",
" - Tools: DuckDuckGo Search\n",
" - Expertise: Current events and public opinion\n",
" - Role: Provides real-time social media insights\n",
"\n",
"**Team Collaboration:**\n",
"\n",
"- Mode: Collaborative discussion\n",
"- Coordination: Team uses GPT-4 for discussion management\n",
"- Process: \n",
" 1. Each agent researches independently using their tools\n",
" 2. Agents share findings and discuss implications\n",
" 3. Team works towards consensus through structured discussion\n",
" 4. Discussion continues until comprehensive understanding is reached\n",
"\n",
"**Features Demonstrated:**\n",
"\n",
"- Creating specialized agents with specific research tools\n",
"- Building collaborative teams that discuss and reach consensus\n",
"- Using various research tools (Google Search, HackerNews, Arxiv, DuckDuckGo)\n",
"- Enabling real-time streaming of agent discussions\n",
"- Tracking agent interactions with AgentOps\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "c9f7fb8d",
"metadata": {},
"outputs": [],
"source": [
"# Install the required dependencies:\n",
"%pip install agentops\n",
"%pip install agno\n",
"%pip install python-dotenv"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "08978603",
"metadata": {},
"outputs": [],
"source": [
"import os\n",
"from textwrap import dedent\n",
"\n",
"import agentops\n",
"from agno.agent import Agent\n",
"from agno.team import Team\n",
"from agno.tools.googlesearch import GoogleSearchTools\n",
"from agno.tools.hackernews import HackerNewsTools\n",
"from agno.tools.arxiv import ArxivTools\n",
"from agno.tools.duckduckgo import DuckDuckGoTools\n",
"from agno.models.openai import OpenAIChat\n",
"from dotenv import load_dotenv"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "143be722",
"metadata": {},
"outputs": [],
"source": [
"# Load environment variables\n",
"load_dotenv()\n",
"os.environ[\"OPENAI_API_KEY\"] = os.getenv(\"OPENAI_API_KEY\", \"your_openai_api_key_here\")\n",
"os.environ[\"AGENTOPS_API_KEY\"] = os.getenv(\"AGENTOPS_API_KEY\", \"your_agentops_api_key_here\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "2e071b24",
"metadata": {},
"outputs": [],
"source": [
"# Initialize AgentOps for monitoring and analytics\n",
"agentops.init(auto_start_session=False, tags=[\"agno-example\", \"research-team\"])"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "8eb6fbe2",
"metadata": {},
"outputs": [],
"source": [
"def demonstrate_research_team():\n",
" \"\"\"\n",
" Demonstrate a collaborative research team with multiple specialized agents.\n",
"\n",
" This function creates a team of researchers, each with:\n",
" - Specific expertise and research focus\n",
" - Specialized tools for their domain\n",
" - Custom instructions for their research approach\n",
"\n",
" The team collaborates to provide comprehensive research insights.\n",
" \"\"\"\n",
" tracer = agentops.start_trace(trace_name=\"Agno Research Team Demonstration\")\n",
"\n",
" try:\n",
" print(\"\\n1. Creating specialized research agents...\")\n",
"\n",
" # Reddit Researcher: Focuses on community discussions and user experiences\n",
" reddit_researcher = Agent(\n",
" name=\"Reddit Researcher\",\n",
" role=\"Research a topic on Reddit\",\n",
" model=OpenAIChat(id=\"gpt-4o\"),\n",
" tools=[GoogleSearchTools()],\n",
" add_name_to_instructions=True,\n",
" instructions=dedent(\n",
" \"\"\"\n",
" You are a Reddit researcher specializing in community insights.\n",
" You will be given a topic to research on Reddit.\n",
" Your tasks:\n",
" - Find the most relevant and popular Reddit posts\n",
" - Identify common opinions and experiences from users\n",
" - Highlight both positive and negative perspectives\n",
" - Focus on practical advice and real-world experiences\n",
" \"\"\"\n",
" ),\n",
" )\n",
"\n",
" # HackerNews Researcher: Focuses on technical discussions and industry trends\n",
" hackernews_researcher = Agent(\n",
" name=\"HackerNews Researcher\",\n",
" model=OpenAIChat(\"gpt-4o\"),\n",
" role=\"Research a topic on HackerNews.\",\n",
" tools=[HackerNewsTools()],\n",
" add_name_to_instructions=True,\n",
" instructions=dedent(\n",
" \"\"\"\n",
" You are a HackerNews researcher specializing in technical insights.\n",
" You will be given a topic to research on HackerNews.\n",
" Your tasks:\n",
" - Find the most relevant technical discussions\n",
" - Identify industry trends and expert opinions\n",
" - Focus on technical depth and innovation\n",
" - Highlight startup and technology perspectives\n",
" \"\"\"\n",
" ),\n",
" )\n",
"\n",
" # Academic Paper Researcher: Focuses on scholarly research and evidence\n",
" academic_paper_researcher = Agent(\n",
" name=\"Academic Paper Researcher\",\n",
" model=OpenAIChat(\"gpt-4o\"),\n",
" role=\"Research academic papers and scholarly content\",\n",
" tools=[GoogleSearchTools(), ArxivTools()],\n",
" add_name_to_instructions=True,\n",
" instructions=dedent(\n",
" \"\"\"\n",
" You are an academic paper researcher specializing in scholarly content.\n",
" You will be given a topic to research in academic literature.\n",
" Your tasks:\n",
" - Find relevant scholarly articles, papers, and academic discussions\n",
" - Focus on peer-reviewed content and citations from reputable sources\n",
" - Provide brief summaries of key findings and methodologies\n",
" - Highlight evidence-based conclusions and research gaps\n",
" \"\"\"\n",
" ),\n",
" )\n",
"\n",
" # Twitter Researcher: Focuses on real-time trends and public sentiment\n",
" twitter_researcher = Agent(\n",
" name=\"Twitter Researcher\",\n",
" model=OpenAIChat(\"gpt-4o\"),\n",
" role=\"Research trending discussions and real-time updates\",\n",
" tools=[DuckDuckGoTools()],\n",
" add_name_to_instructions=True,\n",
" instructions=dedent(\n",
" \"\"\"\n",
" You are a Twitter/X researcher specializing in real-time insights.\n",
" You will be given a topic to research on Twitter/X.\n",
" Your tasks:\n",
" - Find trending discussions and influential voices\n",
" - Track real-time updates and breaking news\n",
" - Focus on verified accounts and credible sources\n",
" - Identify relevant hashtags and ongoing conversations\n",
" - Capture public sentiment and viral content\n",
" \"\"\"\n",
" ),\n",
" )\n",
"\n",
" # Create collaborative team with advanced features\n",
" agent_team = Team(\n",
" name=\"Discussion Team\",\n",
" mode=\"collaborate\",\n",
" model=OpenAIChat(\"gpt-4o\"),\n",
" members=[\n",
" reddit_researcher,\n",
" hackernews_researcher,\n",
" academic_paper_researcher,\n",
" twitter_researcher,\n",
" ],\n",
" instructions=[\n",
" \"You are a discussion master coordinating a research team.\",\n",
" \"Facilitate productive discussion between all researchers.\",\n",
" \"Ensure each researcher contributes their unique perspective.\",\n",
" \"Guide the team towards a comprehensive understanding of the topic.\",\n",
" \"You have to stop the discussion when you think the team has reached a consensus.\",\n",
" ],\n",
" success_criteria=\"The team has reached a consensus with insights from all perspectives.\",\n",
" enable_agentic_context=True,\n",
" add_context=True,\n",
" show_tool_calls=True,\n",
" markdown=True,\n",
" debug_mode=True,\n",
" show_members_responses=True,\n",
" )\n",
"\n",
" # Stream the team discussion in real-time\n",
" agent_team.print_response(\n",
" message=\"Start the discussion on the topic: 'What is the best way to learn to code?'\",\n",
" stream=True,\n",
" stream_intermediate_steps=True,\n",
" )\n",
"\n",
" agentops.end_trace(tracer, end_state=\"Success\")\n",
"\n",
" except Exception:\n",
" agentops.end_trace(tracer, end_state=\"Error\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "754f75be",
"metadata": {},
"outputs": [],
"source": [
"demonstrate_research_team()"
]
}
],
"metadata": {
"jupytext": {
"cell_metadata_filter": "-all",
"main_language": "python",
"notebook_metadata_filter": "-all"
},
"kernelspec": {
"display_name": "venv",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.9"
}
},
"nbformat": 4,
"nbformat_minor": 5
}