Agents

What Is Haystack (LLM Framework)?

An open-source Python framework from deepset for component-based RAG pipelines, multimodal search, and tool-using LLM agents.

What Is Haystack (LLM Framework)?

Haystack is an open-source Python LLM framework from deepset for building component-based RAG pipelines, multimodal search systems, and tool-using agents. It belongs to the agent framework family because it orchestrates retrievers, generators, routers, document stores, tools, and loop-based Agent components across multi-step workflows. In production, it appears as pipeline runs, component spans, tool calls, document-store reads, and agent loop steps; FutureAGI captures those signals with traceAI:haystack for tracing, evaluation, and regression testing.

Why Haystack Matters in Production LLM and Agent Systems

Haystack failures usually start at a component boundary. A retriever returns plausible but irrelevant documents, a router sends a customer query down the wrong branch, or a tool-using Agent loops because its exit condition never fires. The final answer may look fluent while the trace shows context drift, repeated component calls, empty document lists, or a generator that answered from prior conversation state instead of retrieved evidence.

Developers feel this as hard-to-reproduce RAG bugs. SREs see p99 latency grow when a pipeline loop retries validation or when a document store slows one branch. Product teams see answer quality vary by corpus, language, or workflow path. Compliance teams care because Haystack agents can call external tools and APIs; a wrong tool call can move from bad answer to bad action.

The 2026 production shape is often not a single question-answer chain. A Haystack app may index documents, rerank evidence, route by query type, call a web or database tool, stream an answer, and run a self-correction loop. Unlike a simple LangChain prompt wrapper, Haystack pipelines expose typed component connections and loop limits, which helps debugging only if those component names, inputs, outputs, and errors reach your tracing and evaluation system.

How FutureAGI Handles Haystack in traceAI

FutureAGI’s approach is to treat a Haystack run as a graph of decisions, not one opaque LLM call. With traceAI:haystack, a Pipeline or Agent run can be captured as OpenTelemetry spans keyed by component name, status, latency, and parent trace. The useful fields are the ones engineers debug: agent.trajectory.step for loop position, tool.name for external actions, llm.token_count.prompt for context growth, retrieved document IDs, and generator errors when emitted by the integration.

A concrete workflow: a support team builds a Haystack RAG agent with a document retriever, ConditionalRouter, ChatPromptBuilder, OpenAI chat generator, and a billing-status tool wrapped as a Haystack Tool. After a release, refund questions start producing unsupported policy answers. In FutureAGI, the engineer filters traces to the traceAI:haystack surface, compares eval-fail-rate-by-cohort before and after the release, and opens failed runs at the retriever and router spans.

Evaluation then separates the failure. ContextRelevance checks whether retrieved policy chunks match the customer question. Groundedness checks whether the answer stays supported by those chunks. ToolSelectionAccuracy checks whether the Agent chose the billing tool only when the task required account state. TaskCompletion scores the full ticket outcome. If the bad cohort comes from a router branch, the engineer adds a regression eval and blocks deployment on a threshold. If the issue is an unsafe write path, they route that tool through an Agent Command Center pre-guardrail or model fallback before reopening traffic.

How to Measure or Detect It

Measure Haystack reliability at three layers: retrieval quality, agent decisions, and runtime health.

  • ContextRelevance scores whether retrieved Haystack documents answer the user query before the generator sees them.
  • Groundedness scores whether the generated response is supported by the supplied context, not memory or model prior.
  • ToolSelectionAccuracy scores whether a Haystack Agent picked the right tool for the step.
  • Trace fields such as agent.trajectory.step, tool.name, and llm.token_count.prompt expose loops, tool confusion, and prompt growth.
  • Dashboard signals should include eval-fail-rate-by-component, empty-retrieval rate, p99 pipeline latency, token-cost-per-trace, and tool-error rate.
  • User proxies include thumbs-down rate, support escalation rate, refund reopens, and manual review rate by Haystack pipeline version.

Minimal Python:

from fi.evals import ContextRelevance, Groundedness, ToolSelectionAccuracy

context = ContextRelevance().evaluate(query=user_query, contexts=documents)
grounding = Groundedness().evaluate(response=answer, contexts=documents)
tool = ToolSelectionAccuracy().evaluate(trajectory=trace_steps)

print(context.score, grounding.score, tool.score)

Common Haystack Mistakes

The common errors are not about whether Haystack can build the workflow. They are about losing the evidence trail after the workflow becomes multi-step.

  • Tracing only the final generator call. You miss retriever misses, router drift, empty document stores, tool retries, and loop exits.
  • Using broad component names. Names like retriever_1 and generator make eval-fail-rate-by-component hard to act on.
  • Treating RAG and agents as separate stacks. Haystack often combines retrieval, routing, tools, and agent loops in one pipeline.
  • Skipping type and schema checks around tools. A valid tool name can still carry wrong arguments or unsafe side effects.
  • Evaluating only happy-path documents. Add regression cases for stale policies, no-result retrieval, ambiguous queries, and branch-specific failures.

Frequently Asked Questions

What is Haystack?

Haystack is an open-source Python LLM framework from deepset for building component-based RAG pipelines, multimodal search, and tool-using agents.

How is Haystack different from LangChain?

Haystack centers on typed components and directed pipelines for RAG, search, and agents, while LangChain is a broader application framework with many chain and integration abstractions.

How do you measure Haystack reliability?

FutureAGI uses traceAI:haystack traces with agent.trajectory.step, tool.name, and llm.token_count.prompt, then scores runs with ContextRelevance, Groundedness, ToolSelectionAccuracy, and TaskCompletion.