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
feat: add Haystack integration documentation and examples (#699)
Dwijf60c31dda953
diff --git a/docs/images/external/haystack/haystack-logo.png b/docs/images/external/haystack/haystack-logo.pngnew file mode 100644index 00000000..7ee951f7Binary files /dev/null and b/docs/images/external/haystack/haystack-logo.png differdiff --git a/docs/mint.json b/docs/mint.jsonindex 7c4aa15f..df1b2474 100644--- a/docs/mint.json+++ b/docs/mint.json@@ -95,6 +95,7 @@"v1/integrations/crewai","v1/integrations/gemini","v1/integrations/groq",+ "v1/integrations/haystack","v1/integrations/langchain","v1/integrations/llama_stack","v1/integrations/litellm",diff --git a/docs/v1/examples/examples.mdx b/docs/v1/examples/examples.mdxindex cc7c9e5b..870e0b79 100644--- a/docs/v1/examples/examples.mdx+++ b/docs/v1/examples/examples.mdx@@ -61,6 +61,10 @@ mode: "wide"Explore Google DeepMind's Gemini with observation via AgentOps</Card>+ <Card title="Haystack" icon={<img src="https://www.github.com/agentops-ai/agentops/blob/main/docs/images/external/haystack/haystack-logo.png?raw=true" alt="Haystack" />} iconType="image" href="/v1/integrations/haystack">+ Monitor your Haystack agents with AgentOps+ </Card>+<Card title="LangChain" icon={<img src="https://www.github.com/agentops-ai/agentops/blob/main/docs/images/external/langchain/langchain-logo.png?raw=true" alt="LangChain" />} iconType="image" href="/v1/examples/langchain">Jupyter Notebook with a sample LangChain integration</Card>diff --git a/docs/v1/integrations/haystack.mdx b/docs/v1/integrations/haystack.mdxnew file mode 100644index 00000000..02c63187--- /dev/null+++ b/docs/v1/integrations/haystack.mdx@@ -0,0 +1,82 @@+---+title: Haystack+description: "Monitor your Haystack agents with AgentOps"+---++import CodeTooltip from '/snippets/add-code-tooltip.mdx'+import EnvTooltip from '/snippets/add-env-tooltip.mdx'++AgentOps makes monitoring your Haystack agents seamless. Haystack, much like AutoGen, is a flexible framework that supports multiple models. For detailed installation instructions and feature overviews, refer to the [Haystack documentation](https://docs.haystack.deepset.ai/docs/installation).++## Integrating AgentOps with Haystack++<Steps>+ <Step title="Install the AgentOps SDK">+ <CodeGroup>+ ```bash pip+ pip install agentops+ ```+ ```bash poetry+ poetry add agentops+ ```+ </CodeGroup>+ </Step>+ <Step title="Install Haystack">+ <Warning>+ We currently only support Haystack 2.x.+ </Warning>+ <CodeGroup>+ ```bash pip+ pip install haystack-ai+ ```+ ```bash poetry+ poetry add haystack-ai+ ```+ </CodeGroup>+ </Step>+ <Step title="Configure your environment">+ <EnvTooltip />+ <CodeGroup>+ ```python .env+ AGENTOPS_API_KEY=<YOUR API KEY>+ ```+ </CodeGroup>+ Read more about environment variables in [Advanced Configuration](/v1/usage/advanced-configuration)+ </Step>+ <Step title="Add 3 lines of code">+ <CodeTooltip/>+ <CodeGroup>+ ```python python+ import agentops+ agentops.init(<INSERT YOUR API KEY HERE>)+ ...+ # End of program (e.g. main.py)+ agentops.end_session("Success") # Success|Fail|Indeterminate+ ```+ </CodeGroup>+ </Step>+ <Step title="Run your agent">+ Execute your script and then visit [app.agentops.ai/drilldown](https://app.agentops.ai/drilldown) to monitor your Haystack agent in action. 🕵️+ <Tip>+ After execution, AgentOps outputs a clickable URL in the console that links directly to your session in the Dashboard.+ </Tip>+ <div/>{/* Intentionally blank div for newline */}+ <Frame type="glass" caption="Clickable link to session">+ <img height="200" src="https://github.com/AgentOps-AI/agentops/blob/main/docs/images/link-to-session.gif?raw=true" />+ </Frame>+ </Step>+</Steps>++## Full Examples++You can refer to the following examples -++- [Philosopher Agent](https://github.com/AgentOps-AI/agentops/blob/main/examples/haystack_examples/haystack_anthropic_example.ipynb)+- [Mathematician Agent](https://github.com/AgentOps-AI/agentops/blob/main/examples/haystack_examples/haystack_openai_example.ipynb)+++<script type="module" src="/scripts/github_stars.js"></script>+<script type="module" src="/scripts/scroll-img-fadein-animation.js"></script>+<script type="module" src="/scripts/button_heartbeat_animation.js"></script>+<script type="css" src="/styles/styles.css"></script>+<script type="module" src="/scripts/adjust_api_dynamically.js"></script>diff --git a/examples/haystack_examples/haystack_anthropic_example.ipynb b/examples/haystack_examples/haystack_anthropic_example.ipynbnew file mode 100644index 00000000..08f39b42--- /dev/null+++ b/examples/haystack_examples/haystack_anthropic_example.ipynb@@ -0,0 +1,131 @@+{+ "cells": [+ {+ "cell_type": "markdown",+ "id": "87626697",+ "metadata": {},+ "source": [+ "First let's install the required packages"+ ]+ },+ {+ "cell_type": "code",+ "execution_count": null,+ "id": "9599cf93",+ "metadata": {},+ "outputs": [],+ "source": [+ "%pip install -U anthropic-haystack\n",+ "%pip install -U agentops\n",+ "%pip install -U python-dotenv"+ ]+ },+ {+ "cell_type": "markdown",+ "id": "intro_anthropic",+ "metadata": {},+ "source": [+ "# Anthropic-Haystack API Example with AgentOps (Philosopher Agent)\n",+ "\n",+ "This notebook demonstrates how to use AgentOps with Haystack's AnthropicGenerator (via the `anthropic-haystack` package) to create a Philosopher Agent. The agent leverages Anthropic's language model to answer philosophical queries with deep insight and thoughtful reasoning."+ ]+ },+ {+ "cell_type": "code",+ "execution_count": null,+ "id": "imports_anthropic",+ "metadata": {},+ "outputs": [],+ "source": [+ "import os\n",+ "from haystack_integrations.components.generators.anthropic import AnthropicGenerator\n",+ "import agentops\n",+ "from dotenv import load_dotenv\n",+ "\n",+ "# Load environment variables from a .env file if available\n",+ "load_dotenv()\n",+ "\n",+ "# Load API keys from environment variables or replace with your keys\n",+ "AGENTOPS_API_KEY = os.getenv(\"AGENTOPS_API_KEY\") or \"your_agentops_api_key\"\n",+ "ANTHROPIC_API_KEY = os.getenv(\"ANTHROPIC_API_KEY\") or \"your_anthropic_api_key\"\n",+ "\n",+ "# Configure your environment for Anthropic API\n",+ "os.environ[\"ANTHROPIC_API_KEY\"] = ANTHROPIC_API_KEY"+ ]+ },+ {+ "cell_type": "code",+ "execution_count": null,+ "id": "init_anthropic",+ "metadata": {},+ "outputs": [],+ "source": [+ "# Initialize AgentOps with the API key\n",+ "agentops.init(\n",+ " api_key=AGENTOPS_API_KEY,\n",+ " default_tags=['haystack', 'llm', 'Anthropic']\n",+ ")\n",+ "\n",+ "# Initialize the Anthropic Generator\n",+ "generator = AnthropicGenerator()\n",+ "\n",+ "# Define a Philosopher Agent that uses the AnthropicGenerator to answer philosophical queries\n",+ "class PhilosopherAgent:\n",+ " def __init__(self, generator):\n",+ " self.generator = generator\n",+ "\n",+ " def answer_question(self, question):\n",+ " prompt = f\"You are a thoughtful philosopher. Answer the following question with deep insight and detailed reasoning: {question}\"\n",+ " return self.generator.run(prompt)\n",+ "\n",+ "# Create an instance of the PhilosopherAgent\n",+ "agent = PhilosopherAgent(generator)"+ ]+ },+ {+ "cell_type": "code",+ "execution_count": null,+ "id": "test_anthropic",+ "metadata": {},+ "outputs": [],+ "source": [+ "# Use the agent to answer a philosophical question\n",+ "response = agent.answer_question(\"What is the meaning of life?\")\n",+ "print(\"Philosopher Agent Response:\")\n",+ "print(response)"+ ]+ },+ {+ "cell_type": "code",+ "execution_count": null,+ "id": "end_anthropic",+ "metadata": {},+ "outputs": [],+ "source": [+ "# End the AgentOps session\n",+ "agentops.end_session(\"Success\")"+ ]+ }+ ],+ "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.11.9"+ }+ },+ "nbformat": 4,+ "nbformat_minor": 5+}diff --git a/examples/haystack_examples/haystack_openai_example.ipynb b/examples/haystack_examples/haystack_openai_example.ipynbnew file mode 100644index 00000000..657f27d2--- /dev/null+++ b/examples/haystack_examples/haystack_openai_example.ipynb@@ -0,0 +1,123 @@+{+ "cells": [+ {+ "cell_type": "markdown",+ "id": "87626697",+ "metadata": {},+ "source": [+ "First let's install the required packages"+ ]+ },+ {+ "cell_type": "code",+ "execution_count": null,+ "id": "9599cf93",+ "metadata": {},+ "outputs": [],+ "source": [+ "%pip install -U haystack-ai\n",+ "%pip install -U agentops\n",+ "%pip install -U python-dotenv"+ ]+ },+ {+ "cell_type": "markdown",+ "id": "intro_openai",+ "metadata": {},+ "source": [+ "# OpenAIGenerator API Example with AgentOps (Mathematician Agent)\n",+ "\n",+ "This notebook demonstrates how to use AgentOps with Haystack's OpenAIGenerator to create a mathematician agent. The agent leverages OpenAI's language models to solve math problems and explain its reasoning step by step."+ ]+ },+ {+ "cell_type": "code",+ "execution_count": null,+ "id": "imports_openai",+ "metadata": {},+ "outputs": [],+ "source": [+ "import os\n",+ "from haystack.components.generators import OpenAIGenerator\n",+ "import agentops\n",+ "from dotenv import load_dotenv\n",+ "\n",+ "# Load environment variables from a .env file if available\n",+ "load_dotenv()\n",+ "\n",+ "# Load API keys from environment variables or replace with your keys\n",+ "AGENTOPS_API_KEY = os.getenv(\"AGENTOPS_API_KEY\") or \"your_agentops_api_key\"\n",+ "OPENAI_API_KEY = os.getenv(\"OPENAI_API_KEY\") or \"your_openai_api_key\"\n",+ "\n",+ "# Configure your environment for OpenAI API\n",+ "os.environ[\"OPENAI_API_KEY\"] = OPENAI_API_KEY"+ ]+ },+ {+ "cell_type": "code",+ "execution_count": null,+ "id": "init_agent",+ "metadata": {},+ "outputs": [],+ "source": [+ "# Initialize AgentOps with the API key\n",+ "agentops.init(\n",+ " api_key=AGENTOPS_API_KEY,\n",+ " default_tags=['haystack', 'llm', 'OpenAI']\n",+ ")\n",+ "\n",+ "# Initialize the OpenAIGenerator\n",+ "client = OpenAIGenerator(model=\"o3-mini\")\n",+ "\n",+ "# Define a Mathematician Agent that uses the OpenAIGenerator to solve math problems\n",+ "class MathematicianAgent:\n",+ " def __init__(self, generator):\n",+ " self.generator = generator\n",+ "\n",+ " def solve_equation(self, equation):\n",+ " prompt = f\"You are a mathematician. Solve the following equation and explain your reasoning step by step: {equation}\"\n",+ " return self.generator.run(prompt)\n",+ "\n",+ "# Create an instance of the MathematicianAgent\n",+ "agent = MathematicianAgent(client)\n",+ "\n",+ "# Use the agent to solve a math problem\n",+ "response = agent.solve_equation(\"2x + 3 = 7\")\n",+ "print(\"Mathematician Agent Response:\")\n",+ "print(response)"+ ]+ },+ {+ "cell_type": "code",+ "execution_count": null,+ "id": "end_openai",+ "metadata": {},+ "outputs": [],+ "source": [+ "# End the AgentOps session\n",+ "agentops.end_session('Success')"+ ]+ }+ ],+ "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.11.9"+ }+ },+ "nbformat": 4,+ "nbformat_minor": 5+}