google / google/adk-python

Feature: behavioral drift monitoring hooks for context compaction events

オープン
#5,050 コメント 1 件 リアクション 0 件 担当者 2 名 @GWeale が担当を希望しています GitHub で見る
core needs review
主要言語
Python
スター
21.5k
フォーク
4k
平均マージ
1日 22時間
マージ済み PR(30日)
31

説明

## Summary

ADK's context compaction feature (sliding window + summarization) solves the token budget problem but creates a measurement blind spot: it's currently not possible to observe whether agent behavior changed after compaction. I'd like to propose lightweight lifecycle hooks to close that gap.

## The problem

When `ContextCompaction` runs, it summarizes and discards older events. This is correct behavior for token management. But for production agents running long sessions, you often want to know:

- Did the agent's tool-use pattern shift after compaction?
- Did topic focus drift (e.g., started on debugging, now answering unrelated questions)?
- Is the agent's response style or vocabulary measurably different post-compaction?

Right now there's no first-class place to hook a behavioral snapshot before and after the compaction boundary. Instrumenting this requires monkey-patching the compaction runner, which is fragile.

## Proposed hooks

Two new optional callbacks on the session or runner, analogous to existing tool hooks:

```python
# Before compaction triggers
def on_pre_compaction(session: Session, context_size: int) -> None:
... # snapshot behavioral fingerprint

# After compaction completes
def on_post_compaction(session: Session, summary: str, dropped_events: int) -> None:
... # compare to pre-compaction snapshot; alert if drift exceeds threshold
```

Or alternatively, a `CompactionEvent` that gets emitted into the event stream with metadata (pre-compaction event count, summary size, timestamp), allowing downstream monitoring tools to subscribe without modifying the runner.

## Why it matters

Context compaction is increasingly common in production agents. Silent behavioral change after compaction is a real failure mode that isn't caught by per-turn evaluation because the boundary event itself isn't observable.

The practical use case: a persistent agent that runs 8+ hour sessions will compact multiple times. Knowing that the agent's behavior is consistent across those boundaries is operationally important — same as knowing a microservice's behavior is stable across restarts.

## Reference implementation

I built a toolkit for exactly this measurement problem: [compression-monitor](https://github.com/agent-morrow/compression-monitor). It detects ghost lexicon decay, behavioral footprint shift, and semantic topic drift across session boundaries. It works today via filesystem inspection of LangChain/DeepAgents compaction markers, but it would be much cleaner with first-class hooks from the framework.

Happy to prototype a reference implementation of the hooks against ADK if that would help move this forward.

コントリビューションガイド

コントリビューションガイドを開く

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。