DA

deepset-ai/hayhooks

Developer toolsOfficial
157 stars 46 forks Quality 74 Trend 20Apache-2.0

REST APIs, OpenAI-compatible chat, MCP tools, and A2A agents, with durable execution and built-in tracing.

Overview

REST APIs, OpenAI-compatible chat, MCP tools, and A2A agents, with durable execution and built-in tracing.

README

Serve your pipelines and agents

Write a Python wrapper around your pipeline or agent. Choose the interfaces and runtime features you need:

  • REST APIs. Deploy Python wrappers or YAML pipelines as typed, validated endpoints with OpenAPI docs, file uploads, and custom routes.
  • OpenAI-compatible APIs. Serve streaming Chat Completions and Responses endpoints. Connect Open WebUI or use the embedded Chainlit UI.
  • MCP support. Run an MCP server that exposes pipelines and agents as tools for Cursor, Claude Desktop, and other Model Context Protocol clients.
  • A2A support. Expose chat-capable pipelines and agents through the Agent2Agent protocol, with generated agent cards for discovery and task delegation.
  • Durable execution. Checkpoint long-running work in Redis, wait for human approval, retry failures, and recover after restarts.
  • Tracing and observability. Inspect executions and component traces in the terminal dashboard, or export spans to an OpenTelemetry backend with hayhooks[tracing].

Terminal dashboard

Inspect deployments, follow executions, and find slow components in your terminal.

Actual terminal UI with demo data. Explore the dashboard.

Quick start

Serve a Haystack agent through a typed HTTP endpoint. You need Python 3.10 through 3.14 and an OpenAI API key.

Install and start

In your Python environment, install Hayhooks and set the API key before starting the server:

pip install hayhooks
export OPENAI_API_KEY="your-api-key"
hayhooks run

Leave the server running. Use a second terminal for the following commands.

Create an agent

Create a directory named my_agent_dir and save this as my_agent_dir/pipeline_wrapper.py:

from haystack.components.agents import Agent
from haystack.components.generators.chat import OpenAIResponsesChatGenerator
from haystack.dataclasses import ChatMessage
from haystack.tools import tool

from hayhooks import BasePipelineWrapper

@tool
def search(query: str) -> str:
    """Search the knowledge base."""
    return f"This is a demo tool."

class PipelineWrapper(BasePipelineWrapper):
    def setup(self) -> None:
        self.pipeline = Agent(
            chat_generator=OpenAIResponsesChatGenerator(model="gpt-4o-mini"),
            tools=[search],
        )

    async def run_api_async(self, question: str) -> str:
        result = await self.pipeline.run_async(messages=[ChatMessage.from_user(question)])
        return result["last_message"].text

Hayhooks uses the method’s type hints to validate requests and generate the API schema.

Deploy and run

hayhooks pipeline deploy-files -n my_agent ./my_agent_dir
curl http://localhost:1416/my_agent/run \
  -H 'Content-Type: application/json' \
  -d '{"question": "What can you do?"}'

The response contains the agent’s answer. Open the API docs to inspect and try the endpoint.

Durable execution

Run work beyond the lifetime of a request. Hayhooks checkpoints pipelines and agents in Redis so another worker can resume after a restart.

Suspend a run for human approval, retry failures, or reconnect to its output stream from any replica.

stateDiagram-v2
    direction LR
    [*] --> queued: submit (202)
    queued --> running: worker claims
    running --> waiting: suspend for a human
    waiting --> queued: resume
    running --> queued: retry or crash recovery
    running --> completed
    running --> failed
    running --> canceled

Read the durable execution guide for checkpoint behavior and the operations guide for deployment and recovery. The same engine also embeds in any FastAPI app.

Next steps

Community & Support

Hayhooks is actively maintained by the deepset team.

View the full README on GitHub

Install

docker run -d -p 6379:6379 redis
New to MCP? Start with the mcpskill.org guide →