The config of event compaction for an application.
| 48 | |
| 49 | @experimental |
| 50 | class EventsCompactionConfig(BaseModel): |
| 51 | """The config of event compaction for an application.""" |
| 52 | |
| 53 | model_config = ConfigDict( |
| 54 | arbitrary_types_allowed=True, |
| 55 | extra="forbid", |
| 56 | ) |
| 57 | |
| 58 | summarizer: Optional[BaseEventsSummarizer] = None |
| 59 | """The event summarizer to use for compaction.""" |
| 60 | |
| 61 | compaction_interval: int |
| 62 | """The number of *new* user-initiated invocations that, once |
| 63 | fully represented in the session's events, will trigger a compaction.""" |
| 64 | |
| 65 | overlap_size: int |
| 66 | """The number of preceding invocations to include from the |
| 67 | end of the last compacted range. This creates an overlap between consecutive |
| 68 | compacted summaries, maintaining context.""" |
| 69 | |
| 70 | token_threshold: Optional[int] = Field( |
| 71 | default=None, |
| 72 | gt=0, |
| 73 | ) |
| 74 | """Post-invocation token threshold trigger. |
| 75 | |
| 76 | If set, ADK will attempt a post-invocation compaction when the most recently |
| 77 | observed prompt token count meets or exceeds this threshold. |
| 78 | """ |
| 79 | |
| 80 | event_retention_size: Optional[int] = Field(default=None, ge=0) |
| 81 | """Post-invocation raw event retention size. |
| 82 | |
| 83 | If token-based post-invocation compaction is triggered, this keeps the last N |
| 84 | raw events un-compacted. |
| 85 | """ |
| 86 | |
| 87 | @model_validator(mode="after") |
| 88 | def _validate_token_params(self) -> EventsCompactionConfig: |
| 89 | token_threshold_set = self.token_threshold is not None |
| 90 | retention_size_set = self.event_retention_size is not None |
| 91 | if token_threshold_set != retention_size_set: |
| 92 | raise ValueError( |
| 93 | "token_threshold and event_retention_size must be set together." |
| 94 | ) |
| 95 | return self |
no outgoing calls