47 model prices
  1. Home
  2. Releases
  3. Haystack
  4. 3.1.0

Haystack 3.1.0 release notes

Haystack 3.1.0 was released on August 24, 2026. The latest version is 3.5.0.

v3.1.0 · · 84 listed changes

Release notes

⭐️ Highlights

🪝CompactionHook and Built-in Compactors for Context Length Management

Experimental context compaction for Agent. Runs before LLM calls and shortens the conversation once it crosses a configured fraction of the context window. The built-in SlidingWindowCompactor first removes entire historical turns, then, if needed, individual steps of the current task, replacing what it removes with a short omission note. A second experimental compaction strategy, ToolResultPruningCompactor, instead of dropping whole turns, replaces older/large tool results with placeholders while keeping the most recent tool-calling steps (and their parallel results) intact.

from haystack.hooks.compaction import CompactionHook, SlidingWindowCompactor, ToolResultPruningCompactor
from haystack.components.generators.chat import OpenAIResponsesChatGenerator

hook = CompactionHook(
    compactor=SlidingWindowCompactor(), # or ToolResultPruningCompactor(min_keep_steps=2, min_tokens=200),
    context_window=400_000,
    compact_at=0.7,
    compact_to=0.4,
)
agent = Agent(
    chat_generator=OpenAIResponsesChatGenerator(model="gpt-5.4-nano"),
    tools=[web_search],
    hooks={"before_llm": [hook]},
)
🪙 New Token Counters for Estimating Token Usage

New haystack.token_counters module for estimating message/tool-schema size before sending a request (e.g. to decide when to compact). ApproximateTokenCounter needs no dependencies; TiktokenCounter is a local counter, closer estimates for OpenAI models; OpenAITokenCounter calls OpenAI's counting API for exact, model-specific counts.

from haystack.token_counters import OpenAITokenCounter, ApproximateTokenCounter, TiktokenCounter
from haystack.dataclasses import ChatMessage

counter = OpenAITokenCounter("gpt-5-mini")
# No dependencies: estimates from text length.
counter_app = ApproximateTokenCounter(chars_per_token=4.0).count(messages)
# Closer for OpenAI models; needs: pip install tiktoken
counter_tiktoken = TiktokenCounter(encoding="o200k_base").count(messages)

count = counter.count([ChatMessage.from_user("Hello!")])
🛠️ AgentTool for Multi-Agent Systems

AgentTool wraps a Haystack Agent as a Tool so another Agent can delegate to it. Only the wrapped Agent's final reply is visible to the caller; its intermediate steps remain outside the main agent's context.

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

researcher = Agent(
    chat_generator=OpenAIResponsesChatGenerator(model="gpt-5.4-mini"),
    system_prompt="You are a research specialist. Investigate the task and report your findings.",
    tools=[web_search],
  )

research_specialist = AgentTool(
    agent=researcher,
    name="research",
    description="Research a question on the web and report the findings",
)

coordinator = Agent(
    chat_generator=OpenAIResponsesChatGenerator(model="gpt-5.4"),
    tools=[research_specialist],
    system_prompt="You coordinate specialists. Delegate research questions, then answer the user.",
)

result = coordinator.run([ChatMessage.from_user("What are the latest developments in the Haystack framework?")])
print(result["last_message"].text)

See the multi-agent systems tutorial for a full walkthrough.

🚀 New Features

⬆️ Upgrade Notes

🐛 Bug Fixes

🔒 Security Notes

Enhancement Notes

Deprecation Notes

💙 Big thank you to everyone who contributed to this release!

@Aarkin7, @anakin87, @anxkhn, @aquib8112, @Aryan-Pardeshi, @atikulmunna, @bharadwaj-pendyala, @bilgeyucel, @bogdankostic, @camgrimsec, @chuenchen309, @davidpavlovschi, @davidsbatista, @DhanushPillay, @DivyaNarahari97, @erikos, @GovindhKishore, @hxaxd, @immuhammadfurqan, @iridescentWen, @jaideeppyne, @julian-risch, @kacperlukawski, @KXHXK, @LHMQ878, @LK-maker-007, @lntutor, @manjunathbhaskar, @mittalpk, @MVS-source, @onatozmenn, @otiscuilei, @pcbeingused333, @rautaditya2606, @sjrl, @sohumt123, @Solaris-star, @TimurRakhmatullin86, @vidigoat, @vinkiYu, @winklemad, @yaodong-shen

Source: GitHub release v3.1.0

Newer: 3.1.1Older: 3.0.0Haystack