deepset-ai / deepset-ai/haystack

Feature: behavioral drift monitoring hook at context-engineering boundaries

Open
#10,971 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

P3
Dominant language
Python
Stars
26.6k
Forks
3.2k
Avg merge
1d 3h
Merged PRs (30d)
194

Description

Summary

Haystack positions itself as a framework for "context-engineered" LLM applications. That framing implies control over what enters the context window. But there's currently no way to detect when context engineering fails silently — when truncation, summarization, or window overflow causes an agent to drop a significant topic cluster mid-task without error.

This issue proposes a lightweight hook surface to make context-engineering failures observable.


The problem

When a Haystack pipeline runs a ConversationSummarizer or ContextWindowTruncator, the component produces a shorter output but doesn't signal what was dropped. Downstream components proceed normally. The user never sees that the agent just lost its mental model of, say, a security audit thread it was tracking.

I've been measuring this pattern across several agent frameworks and consistently find 15–40% vocabulary ghost rates at compaction boundaries — terms that were load-bearing in the pre-compaction context simply vanish from post-compaction outputs.


Proposed API surface

A minimal ComponentEvent emitted by context-management components:

@dataclass
class ContextCompactionEvent:
    component_name: str
    pre_message_count: int
    post_message_count: int
    dropped_tokens: int             # approximate
    summary_text: Optional[str]     # if summarization was used
    timestamp: float

And a corresponding pipeline callback:

pipeline.add_event_handler("on_context_compaction", my_handler)

This mirrors the ComponentBase lifecycle pattern already used in Haystack and wouldn't require changes to the pipeline execution model.


Reference implementation

I've been building compression-monitor — a toolkit for measuring behavioral drift at compaction boundaries using ghost lexicon decay, behavioral footprint, and semantic embedding distance.

I just shipped a Haystack adapter: haystack_integration.py

from haystack_integration import install_drift_monitor

monitor = install_drift_monitor(pipeline)

# Before a long agent run:
monitor.snapshot_vocabulary(pre_context)

# After:
report = monitor.report()
# {'status': 'alert', 'avg_ghost_rate': 0.955, 'ghost_terms': ['bcrypt', 'audit', ...]}

Self-test result on a topic-drift scenario: ghost_rate=0.955, severity=alert. The adapter wraps Pipeline.run() without modifying Haystack internals.


Why this matters for Haystack specifically

Haystack's "context-engineered" positioning means users are relying on the framework to make context management deliberate. Observability hooks would let them verify that deliberateness is actually working at runtime — not just at design time.

This is particularly relevant for long-running agents using ChatHistoryConnector + summarization pipelines, where multi-turn topic coherence is implicit and failures are hard to detect.


Happy to prototype a PR for the core callbacks surface if the approach looks reasonable.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

No Haystack repository files are named. Start by reading the ComponentBase lifecycle pattern and the Pipeline.run entry point, then inspect ConversationSummarizer, ContextWindowTruncator, and ChatHistoryConnector. Done means agreeing on a callback/event design that reports context compaction without changing pipeline execution, with behavior validated for the affected components.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
ai, backend-api-design
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.