Haystack Agents
What it is
Haystack is an open-source Python framework from deepset for building LLM applications, especially retrieval-augmented generation (RAG) systems. Its Agent component adds reasoning and external tools to a pipeline: an agent can understand different inputs, decide when to take action, and use tools and memory to complete tasks. The docs describe the Agent as a coordinator for a pipeline that manages the flow of a conversation and determines which tools to use and when.
Haystack is built around pipelines: graphs of components such as retrievers, generators, and document stores. An agent fits into that model as a component that runs the tool-calling loop for you, so you can combine it with retrieval, ranking, and other pipeline steps.
Who made it
Haystack is made by deepset, a company based in Berlin, Germany. The documentation is at docs.haystack.deepset.ai, and the source is on GitHub under the deepset-ai organisation.
- Official docs: https://docs.haystack.deepset.ai/docs/agents
- GitHub: https://github.com/deepset-ai/haystack
What it does
Haystack agents can search the web, retrieve from a document store, calculate, call APIs, and use tools built from Python functions, from other Haystack components, from whole pipelines, or from MCP servers. The docs list several ways to make a tool: the Tool class or @tool decorator for a function, ComponentTool to wrap any Haystack component, PipelineTool to wrap a full pipeline, AgentTool to wrap another agent, and MCPTool or MCPToolset to load tools from a Model Context Protocol server.
The Agent supports state management, so tools can share typed data and accumulate results; streaming, so you can show tokens as they arrive; human-in-the-loop, so you can intercept a tool call for review before it runs; and multi-agent systems, where one agent delegates to another through an AgentTool. Haystack also ships ready-made agents in its Agent Pack, including a deep research agent that researches the web and produces a cited Markdown report, and an advanced RAG agent that inspects document metadata before retrieving. Those packs are marked experimental in the docs.
How it works
You create an Agent with a chat generator, such as an OpenAI chat generator, a system prompt, and a list of tools. When you run it with a list of ChatMessage objects, the agent sends the message to the model with the list of available tools. The model decides whether to respond directly or call a tool. If it calls a tool, the agent runs it, adds the result to the history, and calls the model again. The loop continues until a stop condition is met, such as a final answer or a maximum number of iterations.
Hooks let you influence the loop at specific points, for example before or after a tool call. State is defined with a state_schema, and any keys you declare there are returned with the messages and the last message in the result. The agent can also be exposed as an MCP server with Hayhooks, so any MCP-compatible client can call it.
How to start
- Install Haystack with
pip install haystack-ai— check the official docs for the current package name and command. - Set your model API key as an environment variable, for example
OPENAI_API_KEY, and any search API key your tools need, such as a SerperDev key for web search. - Follow the Agents page in the docs, which builds a tool-calling agent that searches for tipping customs and calculates a tip. It uses
Agentfromhaystack.components.agents, a chat generator, and a@toolfunction. - Run the example, read the tool calls, and check the final answer against the search results.
- Add a document store and a retriever when the agent needs your own documents, and add a human-in-the-loop hook before any tool that changes data.
- When you need a ready-made pattern, read the Agent Pack docs for the deep research or advanced RAG agent, and note that they are experimental.
Check the official docs for current install and import names, because Haystack’s package and component names have changed between major versions.
Who it is for
Haystack Agents are for Python developers who want RAG and agents in the same framework, especially teams building search, document Q&A, and research tools. It suits developers who like pipelines as a way to compose components, and teams that need state, streaming, and human-in-the-loop built in. It is a code framework, not a no-code builder, although deepset also offers a visual Haystack Platform for building pipelines on a canvas.
Watch out for
Haystack is a large framework with many integrations, so check the docs for the version you installed before copying an example — import paths and package names have changed. The Agent Pack agents are experimental, and the docs warn their APIs and architectures can change in any release without following the usual deprecation policy. If you use the agent without tools, the docs recommend using the plain LLM component instead. As with any agent, set iteration limits, test with read-only tools first, and add human approval for actions that change data. Retrieval quality depends on your documents and your retriever, so test the retrieval step on its own before you blame the agent.
Source
- Official docs: https://docs.haystack.deepset.ai/docs/agents
- GitHub: https://github.com/deepset-ai/haystack