Haystack is a flexible framework for building production-ready AI agents. AgentOps makes monitoring your Haystack agents seamless.

Installation

pip install agentops haystack-ai python-dotenv
We currently only support Haystack 2.x.

Setting Up API Keys

You’ll need API keys for AgentOps and whatever model provider you use with Haystack (e.g. OpenAI): Set these as environment variables or in a .env file.
export AGENTOPS_API_KEY="your_agentops_api_key_here"
export OPENAI_API_KEY="your_openai_api_key_here"
Then load them in your Python code:
from dotenv import load_dotenv
import os

load_dotenv()
AGENTOPS_API_KEY = os.getenv("AGENTOPS_API_KEY")
OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")

Usage

Integrating AgentOps with Haystack only takes a few lines:
import agentops
from haystack.components.generators.openai import OpenAIGenerator

agentops.init(AGENTOPS_API_KEY)

generator = OpenAIGenerator(model="gpt-4o-mini", api_key=OPENAI_API_KEY)
result = generator.run(prompt="In one sentence, what is AgentOps?")
print(result["replies"][0])
Run your script and visit the AgentOps Dashboard to monitor the trace.

Examples