Haystack Integration with Future AGI for Pipeline Tracing
Integrate Haystack with Future AGI observability. Set up traceAI-haystack to trace document processing pipelines and LLM calls automatically.
Trace a Haystack pipeline in Future AGI.
1. Installation
Use Python 3.10–3.12. The published traceAI-haystack 0.1.9 package requires haystack-ai>=2.10.0.
pip install 'traceAI-haystack==0.1.9' 'haystack-ai>=2.10.0' trafilatura
2. Set Environment Variables
Set environment variables to authenticate with Future AGI and OpenAI.
import os
os.environ["OPENAI_API_KEY"] = "your-openai-api-key"
os.environ["FI_API_KEY"] = "your-futureagi-api-key"
os.environ["FI_SECRET_KEY"] = "your-futureagi-secret-key"
3. Initialize Trace Provider
Set up the trace provider to create a new project in FutureAGI, establish telemetry data pipelines.
from fi_instrumentation import register
from fi_instrumentation.fi_types import ProjectType
trace_provider = register(
project_type=ProjectType.OBSERVE,
project_name="haystack_project",
)
4. Instrument your Project
Initialize the Haystack instrumentor to enable automatic tracing.
from traceai_haystack import HaystackInstrumentor
HaystackInstrumentor().instrument(tracer_provider=trace_provider)
5. Create Haystack Components
Build and run a pipeline that fetches a page and answers a question about it.
from haystack import Pipeline
from haystack.components.fetchers import LinkContentFetcher
from haystack.components.converters import HTMLToDocument
from haystack.components.builders import ChatPromptBuilder
from haystack.components.generators.chat import OpenAIChatGenerator
from haystack.dataclasses import ChatMessage
fetcher = LinkContentFetcher()
converter = HTMLToDocument()
prompt_template = [
ChatMessage.from_user(
"""
According to the contents of this website:
{% for document in documents %}
{{document.content}}
{% endfor %}
Answer the given question: {{query}}
Answer:
"""
)
]
prompt_builder = ChatPromptBuilder(template=prompt_template)
llm = OpenAIChatGenerator()
pipeline = Pipeline()
pipeline.add_component("fetcher", fetcher)
pipeline.add_component("converter", converter)
pipeline.add_component("prompt", prompt_builder)
pipeline.add_component("llm", llm)
pipeline.connect("fetcher.streams", "converter.sources")
pipeline.connect("converter.documents", "prompt.documents")
pipeline.connect("prompt.prompt", "llm.messages")
result = pipeline.run({"fetcher": {"urls": ["https://haystack.deepset.ai/overview/quick-start"]},
"prompt": {"query": "Which components do I need for a RAG pipeline?"}})
print(result["llm"]["replies"][0].text)
Open the haystack_project project in Future AGI to inspect the pipeline trace.
Questions & Discussion