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
Cursor/improve agno tool integrations py output d88d (#1134)
Alex Reibmanfceaab9a47aa
diff --git a/examples/agno/agno_tool_integrations.ipynb b/examples/agno/agno_tool_integrations.ipynbindex a5d6458d..a3f66e4e 100644--- a/examples/agno/agno_tool_integrations.ipynb+++ b/examples/agno/agno_tool_integrations.ipynb@@ -1,28 +1,342 @@{- "cells": [- {- "cell_type": "markdown",- "id": "813b80b7",- "metadata": {},- "source": [- "\n",- "# Tool Integration with RAG (Retrieval-Augmented Generation) in Agno\n",- "\n",- "This example demonstrates how to enhance Agno agents with RAG capabilities, allowing them to access and reason over external knowledge bases for more accurate and source-backed responses.\n",- "\n",- "**Overview**\n",- "\n",- "This example shows how to integrate RAG with Agno agents where we:\n",- "\n",- "1. **Set up a knowledge base** with documents, URLs, and other external sources\n",- "2. **Configure vector databases** (like Pinecone, Weaviate, or ChromaDB) for efficient semantic search\n",- "3. **Implement retrieval** using embeddings and reranking for accurate information access\n",- "4. **Create RAG-enabled agents** that can search, retrieve, and reason over the knowledge base\n",- "\n",- "By using RAG, agents can provide responses backed by external sources rather than relying solely on their training data, significantly improving accuracy and verifiability of their outputs.\n",- "\n",- "RAG enables agents to access and reason over large knowledge bases,\n"- ]+ "cells": [+ {+ "cell_type": "markdown",+ "metadata": {},+ "source": [+ "# Tool Integration Example with Agno\n",+ "\n",+ "This example demonstrates how to integrate and use various tools with Agno agents, showing how AgentOps automatically tracks tool usage and agent interactions.\n",+ "\n",+ "## Overview\n",+ "\n",+ "This example demonstrates:\n",+ "\n",+ "1. **Using built-in Agno tools** like GoogleSearch, DuckDuckGo, and Arxiv\n",+ "2. **Creating agents with tools** and seeing how they use them\n",+ "3. **Tool execution tracking** with AgentOps\n",+ "4. **Combining multiple tools** for comprehensive research\n",+ "\n",+ "## Key Concepts\n",+ "\n",+ "### Tool Integration\n",+ "Agno provides various built-in tools that agents can use to access external information and services. These tools are automatically invoked by agents based on the task at hand.\n",+ "\n",+ "### Available Tools\n",+ "- **GoogleSearchTools**: Search the web using Google\n",+ "- **DuckDuckGoTools**: Alternative web search engine\n",+ "- **ArxivTools**: Search academic papers on arXiv\n",+ "- **HackerNewsTools**: Access HackerNews content\n",+ "- And many more...\n",+ "\n",+ "### Automatic Tool Selection\n",+ "Agents intelligently select which tools to use based on their instructions and the user's query. They can also combine multiple tools to provide comprehensive responses."+ ]+ },+ {+ "cell_type": "code",+ "execution_count": null,+ "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,+ "metadata": {},+ "outputs": [],+ "source": [+ "import os\n",+ "from dotenv import load_dotenv\n",+ "\n",+ "import agentops\n",+ "from agno.agent import Agent\n",+ "from agno.models.openai import OpenAIChat\n",+ "from agno.tools.googlesearch import GoogleSearchTools\n",+ "from agno.tools.duckduckgo import DuckDuckGoTools\n",+ "from agno.tools.arxiv import ArxivTools"+ ]+ },+ {+ "cell_type": "code",+ "execution_count": null,+ "metadata": {},+ "outputs": [],+ "source": [+ "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,+ "metadata": {},+ "outputs": [],+ "source": [+ "agentops.init(auto_start_session=False, tags=[\"agno-tools\", \"tool-integration\", \"demo\"])"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {},+ "source": [+ "## Example 1: Agent with Single Tool\n",+ "\n",+ "Let's start with a simple example where we create an agent that uses Google Search to find information. This demonstrates:\n",+ "- How to create an agent with a specific tool\n",+ "- How the agent automatically uses the tool when needed\n",+ "- How AgentOps tracks the tool execution"+ ]+ },+ {+ "cell_type": "code",+ "execution_count": null,+ "metadata": {},+ "outputs": [],+ "source": [+ "# Start an AgentOps trace for tracking\n",+ "tracer = agentops.start_trace(trace_name=\"Example 1: Single Tool Agent\")\n",+ "\n",+ "try:\n",+ " # Create an agent with Google Search tool\n",+ " search_agent = Agent(\n",+ " name=\"Search Agent\",\n",+ " role=\"Research information using Google Search\",\n",+ " model=OpenAIChat(id=\"gpt-4o-mini\"),\n",+ " tools=[GoogleSearchTools()],\n",+ " instructions=\"You are a research assistant. Use Google Search to find accurate, up-to-date information.\"\n",+ " )\n",+ " \n",+ " # Run the agent with a query\n",+ " response = search_agent.run(\"What are the latest developments in AI agents?\")\n",+ " \n",+ " print(\"Search Agent Response:\")\n",+ " print(\"-\" * 60)\n",+ " print(response.content)\n",+ " print(\"-\" * 60)\n",+ " \n",+ " agentops.end_trace(tracer, end_state=\"Success\")\n",+ " \n",+ "except Exception as e:\n",+ " print(f\"An error occurred: {e}\")\n",+ " agentops.end_trace(tracer, end_state=\"Error\")"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {},+ "source": [+ "## Example 2: Agent with Multiple Tools\n",+ "\n",+ "Now let's create an agent that has access to multiple tools. The agent will intelligently decide which tool(s) to use based on the query. This demonstrates:\n",+ "- How to provide multiple tools to an agent\n",+ "- How agents select appropriate tools\n",+ "- How to combine information from different sources"+ ]+ },+ {+ "cell_type": "code",+ "execution_count": null,+ "metadata": {},+ "outputs": [],+ "source": [+ "# Start a new trace for Example 2\n",+ "tracer = agentops.start_trace(trace_name=\"Example 2: Multi-Tool Agent\")\n",+ "\n",+ "try:\n",+ " # Create an agent with multiple research tools\n",+ " research_agent = Agent(\n",+ " name=\"Research Agent\",\n",+ " role=\"Comprehensive research using multiple tools\",\n",+ " model=OpenAIChat(id=\"gpt-4o-mini\"),\n",+ " tools=[\n",+ " GoogleSearchTools(),\n",+ " ArxivTools(),\n",+ " DuckDuckGoTools()\n",+ " ],\n",+ " instructions=\"\"\"You are a comprehensive research assistant. \n",+ " Use Google Search for general information, Arxiv for academic papers, \n",+ " and DuckDuckGo as an alternative search engine. \n",+ " Provide well-researched, balanced information from multiple sources.\"\"\"\n",+ " )\n",+ " \n",+ " # Run the agent with a complex query\n",+ " response = research_agent.run(\n",+ " \"Find information about recent advances in tool-use for AI agents. \"\n",+ " \"Include both academic research and practical implementations.\"\n",+ " )\n",+ " \n",+ " print(\"Research Agent Response:\")\n",+ " print(\"-\" * 60)\n",+ " print(response.content)\n",+ " print(\"-\" * 60)\n",+ " \n",+ " agentops.end_trace(tracer, end_state=\"Success\")\n",+ " \n",+ "except Exception as e:\n",+ " print(f\"An error occurred: {e}\")\n",+ " agentops.end_trace(tracer, end_state=\"Error\")"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {},+ "source": [+ "## Example 3: Specialized Tool Usage\n",+ "\n",+ "Let's create an agent specialized in academic research using the Arxiv tool. This demonstrates:\n",+ "- How to create domain-specific agents\n",+ "- How specialized tools provide focused results\n",+ "- The value of tool specialization for specific tasks"+ ]+ },+ {+ "cell_type": "code",+ "execution_count": null,+ "metadata": {},+ "outputs": [],+ "source": [+ "# Start a new trace for Example 3\n",+ "tracer = agentops.start_trace(trace_name=\"Example 3: Academic Research Agent\")\n",+ "\n",+ "try:\n",+ " # Create an agent specialized in academic research\n",+ " academic_agent = Agent(\n",+ " name=\"Academic Agent\",\n",+ " role=\"Find and summarize academic papers\",\n",+ " model=OpenAIChat(id=\"gpt-4o-mini\"),\n",+ " tools=[ArxivTools()],\n",+ " instructions=\"You are an academic research assistant. Use Arxiv to find relevant papers and provide concise summaries.\"\n",+ " )\n",+ " \n",+ " # Run the agent with an academic query\n",+ " response = academic_agent.run(\n",+ " \"Find recent papers about tool augmented language models\"\n",+ " )\n",+ " \n",+ " print(\"Academic Agent Response:\")\n",+ " print(\"-\" * 60)\n",+ " print(response.content)\n",+ " print(\"-\" * 60)\n",+ " \n",+ " agentops.end_trace(tracer, end_state=\"Success\")\n",+ " \n",+ "except Exception as e:\n",+ " print(f\"An error occurred: {e}\")\n",+ " agentops.end_trace(tracer, end_state=\"Error\")"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {},+ "source": [+ "## Example 4: Comparing Different Search Tools\n",+ "\n",+ "Finally, let's create an agent that can compare results from different search engines. This demonstrates:\n",+ "- How agents can use multiple tools strategically\n",+ "- How to compare and synthesize information from different sources\n",+ "- The benefits of having alternative data sources"+ ]+ },+ {+ "cell_type": "code",+ "execution_count": null,+ "metadata": {},+ "outputs": [],+ "source": [+ "# Start a new trace for Example 4\n",+ "tracer = agentops.start_trace(trace_name=\"Example 4: Tool Comparison Agent\")\n",+ "\n",+ "try:\n",+ " # Create an agent that compares different search tools\n",+ " comparison_agent = Agent(\n",+ " name=\"Comparison Agent\",\n",+ " role=\"Compare results from different search engines\",\n",+ " model=OpenAIChat(id=\"gpt-4o-mini\"),\n",+ " tools=[\n",+ " GoogleSearchTools(),\n",+ " DuckDuckGoTools()\n",+ " ],\n",+ " instructions=\"\"\"Compare search results from Google and DuckDuckGo. \n",+ " Note any differences in results, ranking, or information quality.\n",+ " Be objective in your comparison.\"\"\"\n",+ " )\n",+ " \n",+ " # Run the agent with a comparison task\n",+ " response = comparison_agent.run(\n",+ " \"Search for 'AgentOps observability platform' on both search engines and compare the results\"\n",+ " )\n",+ " \n",+ " print(\"Comparison Agent Response:\")\n",+ " print(\"-\" * 60)\n",+ " print(response.content)\n",+ " print(\"-\" * 60)\n",+ " \n",+ " agentops.end_trace(tracer, end_state=\"Success\")\n",+ " \n",+ "except Exception as e:\n",+ " print(f\"An error occurred: {e}\")\n",+ " agentops.end_trace(tracer, end_state=\"Error\")"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {},+ "source": [+ "## Key Takeaways\n",+ "\n",+ "This notebook demonstrated several important concepts about tool integration in Agno:\n",+ "\n",+ "1. **Automatic Tool Usage**: Agents automatically determine when and how to use their available tools based on the query.\n",+ "\n",+ "2. **Tool Selection**: When given multiple tools, agents intelligently select the most appropriate ones for the task.\n",+ "\n",+ "3. **Information Synthesis**: Agents can combine information from multiple tools to provide comprehensive responses.\n",+ "\n",+ "4. **AgentOps Tracking**: All tool executions are automatically tracked by AgentOps, providing observability into:\n",+ " - Which tools were used\n",+ " - What parameters were passed\n",+ " - Tool execution times\n",+ " - Success/failure rates\n",+ "\n",+ "5. **Specialized vs. General Agents**: You can create both specialized agents (with specific tools) and general-purpose agents (with multiple tools).\n",+ "\n",+ "## Viewing Results in AgentOps\n",+ "\n",+ "After running these examples, you can visit [AgentOps Dashboard](https://app.agentops.ai/) to see:\n",+ "- Detailed traces of each agent execution\n",+ "- Tool usage patterns\n",+ "- Performance metrics\n",+ "- Error tracking and debugging information\n",+ "\n",+ "Each trace URL printed during execution provides direct access to that specific session's details."+ ]+ }+ ],+ "metadata": {+ "kernelspec": {+ "display_name": "Python 3",+ "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.9.0"+ }},{"cell_type": "code",diff --git a/examples/agno/agno_tool_integrations.py b/examples/agno/agno_tool_integrations.pyindex 6cc0d0b4..3a28f0e9 100644--- a/examples/agno/agno_tool_integrations.py+++ b/examples/agno/agno_tool_integrations.py@@ -1,96 +1,149 @@"""-# Tool Integration with RAG (Retrieval-Augmented Generation) in Agno+# Tool Integration Example with Agno-This example demonstrates how to enhance Agno agents with RAG capabilities, allowing them to access and reason over external knowledge bases for more accurate and source-backed responses.+This example demonstrates how to integrate and use various tools with Agno agents,+showing how AgentOps automatically tracks tool usage and agent interactions.## Overview-This example shows how to integrate RAG with Agno agents where we:+This example demonstrates:-1. **Set up a knowledge base** with documents, URLs, and other external sources-2. **Configure vector databases** (like Pinecone, Weaviate, or ChromaDB) for efficient semantic search-3. **Implement retrieval** using embeddings and reranking for accurate information access-4. **Create RAG-enabled agents** that can search, retrieve, and reason over the knowledge base+1. **Using built-in Agno tools** like GoogleSearch, DuckDuckGo, and Arxiv+2. **Creating agents with tools** and seeing how they use them+3. **Tool execution tracking** with AgentOps+4. **Combining multiple tools** for comprehensive research-By using RAG, agents can provide responses backed by external sources rather than relying solely on their training data, significantly improving accuracy and verifiability of their outputs.--RAG enables agents to access and reason over large knowledge bases,-providing accurate, source-backed responses instead of relying solely on training data.+This example uses actual Agno components to show real tool integration patterns."""import os+from dotenv import load_dotenv+import agentopsfrom agno.agent import Agentfrom agno.models.openai import OpenAIChat-import agentops-from dotenv import load_dotenv--# Knowledge and RAG components-from agno.knowledge.url import UrlKnowledge-from agno.vectordb.lancedb import LanceDb-from agno.vectordb.search import SearchType-from agno.embedder.cohere import CohereEmbedder-from agno.reranker.cohere import CohereReranker-from agno.tools.reasoning import ReasoningTools+from agno.tools.googlesearch import GoogleSearchTools+from agno.tools.duckduckgo import DuckDuckGoTools+from agno.tools.arxiv import ArxivTools# Load environment variablesload_dotenv()-# Initialize AgentOps for monitoring-agentops.init(auto_start_session=False, tags=["agno-example", "tool-integrations"])+# Set environment variables if not already set+os.environ["OPENAI_API_KEY"] = os.getenv("OPENAI_API_KEY", "your_openai_api_key_here")+os.environ["AGENTOPS_API_KEY"] = os.getenv("AGENTOPS_API_KEY", "your_agentops_api_key_here")-# API keys and configuration-os.environ["COHERE_API_KEY"] = os.getenv("COHERE_API_KEY")+# Initialize AgentOps+agentops.init(+ auto_start_session=False,+ tags=["agno-tools", "tool-integration", "demo"]+)def demonstrate_tool_integration():- """- Demonstrate advanced tool integration with RAG and knowledge bases.-- This function shows how to:- 1. Create a knowledge base from external sources- 2. Set up a vector database with embeddings- 3. Configure an agent with RAG capabilities- 4. Enable reasoning tools for complex problem-solving- """- tracer = agentops.start_trace(trace_name="Agno Tool Integration Demonstration")+ """Demonstrate tool integration with Agno agents."""+ print("🚀 Agno Tool Integration Demonstration")+ print("=" * 60)++ # Start AgentOps trace+ tracer = agentops.start_trace(trace_name="Agno Tool Integration Demo")+try:- # Create knowledge base from documentation URLs- # This loads content from the specified URLs and prepares it for RAG- knowledge_base = UrlKnowledge(- urls=["https://docs.agno.com/introduction/agents.md"],- vector_db=LanceDb(- uri="tmp/lancedb",- table_name="agno_docs",- search_type=SearchType.hybrid,- embedder=CohereEmbedder(- id="embed-v4.0",- ),- reranker=CohereReranker(- model="rerank-v3.5",- ),- ),+ # Example 1: Single Tool Agent+ print("\n📌 Example 1: Agent with Google Search Tool")+ print("-" * 40)++ search_agent = Agent(+ name="Search Agent",+ role="Research information using Google Search",+ model=OpenAIChat(id="gpt-4o-mini"),+ tools=[GoogleSearchTools()],+ instructions="You are a research assistant. Use Google Search to find accurate, up-to-date information."+ )++ response = search_agent.run("What are the latest developments in AI agents?")+ print(f"Search Agent Response:\n{response.content}")++ # Example 2: Multi-Tool Agent+ print("\n\n📌 Example 2: Agent with Multiple Tools")+ print("-" * 40)++ research_agent = Agent(+ name="Research Agent",+ role="Comprehensive research using multiple tools",+ model=OpenAIChat(id="gpt-4o-mini"),+ tools=[+ GoogleSearchTools(),+ ArxivTools(),+ DuckDuckGoTools()+ ],+ instructions="""You are a comprehensive research assistant.+ Use Google Search for general information, Arxiv for academic papers,+ and DuckDuckGo as an alternative search engine.+ Provide well-researched, balanced information from multiple sources.""")- # Create an intelligent agent with RAG capabilities- agent = Agent(+ response = research_agent.run(+ "Find information about recent advances in tool-use for AI agents. "+ "Include both academic research and practical implementations."+ )+ print(f"Research Agent Response:\n{response.content}")++ # Example 3: Specialized Tool Usage+ print("\n\n📌 Example 3: Academic Research with Arxiv")+ print("-" * 40)++ academic_agent = Agent(+ name="Academic Agent",+ role="Find and summarize academic papers",model=OpenAIChat(id="gpt-4o-mini"),- knowledge=knowledge_base,- search_knowledge=True,- tools=[ReasoningTools(add_instructions=True)],- instructions=[- "Include sources in your response.",- "Always search your knowledge before answering the question.",- "Only include the output in your response. No other text.",+ tools=[ArxivTools()],+ instructions="You are an academic research assistant. Use Arxiv to find relevant papers and provide concise summaries."+ )++ response = academic_agent.run(+ "Find recent papers about tool augmented language models"+ )+ print(f"Academic Agent Response:\n{response.content}")++ # Example 4: Comparing Search Tools+ print("\n\n📌 Example 4: Comparing Different Search Tools")+ print("-" * 40)++ comparison_agent = Agent(+ name="Comparison Agent",+ role="Compare results from different search engines",+ model=OpenAIChat(id="gpt-4o-mini"),+ tools=[+ GoogleSearchTools(),+ DuckDuckGoTools()],+ instructions="""Compare search results from Google and DuckDuckGo.+ Note any differences in results, ranking, or information quality.+ Be objective in your comparison.""")- # Print response with full reasoning process visible- agent.print_response(- "What are Agents?",- show_full_reasoning=True,+ response = comparison_agent.run(+ "Search for 'AgentOps observability platform' on both search engines and compare the results")+ print(f"Comparison Agent Response:\n{response.content}")++ print("\n\n✨ Demonstration Complete!")+ print("\nKey Takeaways:")+ print("- Agno agents can use multiple tools seamlessly")+ print("- Tools are automatically invoked based on the agent's task")+ print("- AgentOps tracks all tool executions automatically")+ print("- Different tools serve different purposes (web search, academic search, etc.)")+ print("- Agents can compare and synthesize information from multiple tools")++ # End the AgentOps trace successfully+ print("\n📊 View your tool execution traces in AgentOps:")+ print(" Visit https://app.agentops.ai/ to see detailed analytics")agentops.end_trace(tracer, end_state="Success")- except Exception:++ except Exception as e:+ print(f"\n❌ An error occurred: {e}")agentops.end_trace(tracer, end_state="Error")+ raise-demonstrate_tool_integration()+if __name__ == "__main__":+ demonstrate_tool_integration()