google / google/adk-python

Feature: behavioral drift monitoring hooks for context compaction events

Aperta
#5,050 1 commento 0 reazioni 2 assegnatari Rivendicata da @GWeale Vedi su GitHub
core needs review
Lingua principale
Python
Stelle
21.5k
Fork
4k
Merge medio
1g 14h
PR unite (30g)
37

Descrizione

## 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.

Guida per i contributori

Apri la guida per i contributori

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.