deepset-ai / deepset-ai/haystack
Feature: behavioral drift monitoring hook at context-engineering boundaries
Nobody has claimed this yet.
- 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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