EventsCompactionConfig required compaction_interval and overlap_size, so a
token-threshold-only compaction config could not be constructed even though the
runtime already tolerates a missing sliding-window trigger. Make both
sliding-window fields Optional and validate them as a both-or-neither pair,
mirroring the token-threshold pair, and require at least one trigger overall.
This also tightens validation with positivity bounds enforced whenever a value
is provided (compaction_interval > 0, overlap_size >= 0). Minor behavior
change: compaction_interval <= 0 and negative overlap_size, previously
accepted, now raise ValidationError.
Close#6398
Co-authored-by: George Weale <gweale@google.com>
PiperOrigin-RevId: 950899288
Move event persistence to the main runner loop, the runtime's
synchronization point: sliding-window compaction now yields its event
instead of appending it, and the runner appends it like any other event.
Co-authored-by: George Weale <gweale@google.com>
PiperOrigin-RevId: 944093841
Merge https://github.com/google/adk-python/pull/6095
## Summary
Removes genuinely unused imports throughout `src/`. No behavior change — a no-brainer cleanup.
Imports that *look* unused but are intentional are **preserved**:
- **Re-export hubs** keep their symbols via the `import X as X` convention (dependency shims, `adk_web_server`, `a2a/executor/utils`, `tools/api_registry`).
- **Optional-dependency availability probes** inside `try/except` and a few defensive imports are kept with `# noqa: F401`.
Also annotates `Context._output_for_ancestors` once before the `if/else` instead of in both branches, fixing a latent mypy `[no-redef]` that surfaces once the file is touched.
## Test plan
- [x] `import google.adk` smoke test passes
- [x] No `__init__.py` public re-exports removed
- [x] Tooling/enforcement (ruff config + pre-commit hook) deliberately kept out — that lands in a follow-up PR
Co-authored-by: Wei Sun (Jack) <weisun@google.com>
COPYBARA_INTEGRATE_REVIEW=https://github.com/google/adk-python/pull/6095 from google:chore/remove-unused-imports e7c24f66ab4ffec1c157dc9870080d0e9193d404
PiperOrigin-RevId: 931258421
The compaction summarizer fed only message text to the LLM, dropping
agent thoughts and tool calls/responses. Ablation found those carry the
analysis and evidence a summary must preserve, so include them, skip a
prior compaction's own thought, and reiterate the user request in the
default prompt to reduce drift.
Change-Id: Ibc09eaa6237c20ede126da263b428dac8ff3e40a
This change introduces logic to identify events containing requests for tool confirmation or auth credentials. The compaction process will now stop before any such "Human-in-the-Loop" (HITL) events, ensuring that the full context of the interaction is preserved and not summarized away. This applies to both sliding window and token threshold compaction strategies.
Co-authored-by: George Weale <gweale@google.com>
PiperOrigin-RevId: 916108771
This change introduces a new helper function `_summarize_events_with_trace` to wrap the event summarization process. This function creates a trace span and records metadata about the compaction trigger, summarizer type, event count, and configuration parameters both before and after the summarization occurs. The existing compaction logic is updated to use this new traced function.
Co-authored-by: George Weale <gweale@google.com>
PiperOrigin-RevId: 905302520
This change modifies the LLM event summarizer to extract the usage_metadata from the LLM's generate content response and include it in the newly created compacted Event
Close#4014
Co-authored-by: George Weale <gweale@google.com>
PiperOrigin-RevId: 905222465
Modified compaction logic to exclude events containing function calls for which no corresponding function response has been recorded in the session. Added helper functions to identify pending function call IDs and check if an event contains such IDs. Applied this exclusion to both sliding window and token threshold-based compaction strategies
Close#4740
Co-authored-by: George Weale <gweale@google.com>
PiperOrigin-RevId: 886268526
Adds optional token_limit and event_retention_size fields to EventsCompactionConfig. When the latest prompt token count meets/exceeds the threshold, ADK compacts older raw events after the invocation and keeps the last N events un-compacted. Updates prompt history building to apply compaction ranges correctly so retained events remain visible.
Close#4146
Co-authored-by: George Weale <gweale@google.com>
PiperOrigin-RevId: 868297968
Merge https://github.com/google/adk-python/pull/4175
### Link to Issue or Description of Change
**1. Link to an existing issue (if applicable):**
N/A: just fixing typos discovered while reading the repo
**2. Or, if no issue exists, describe the change:**
No code change, just typo fixes: see commit diffs for all details
**Problem:**
Trying to improve overall repo quality
**Solution:**
Fixing typos as they get discovered
### Testing Plan
N/A
**Unit Tests:**
N/A
**Manual End-to-End (E2E) Tests:**
N/A
### Checklist
- [X] I have read the [CONTRIBUTING.md](https://github.com/google/adk-python/blob/main/CONTRIBUTING.md) document.
- [X] I have performed a self-review of my own code.
- [ ] I have commented my code, particularly in hard-to-understand areas.
- [ ] I have added tests that prove my fix is effective or that my feature works.
- [X] New and existing unit tests pass locally with my changes.
- [ ] I have manually tested my changes end-to-end.
- [ ] Any dependent changes have been merged and published in downstream modules.
COPYBARA_INTEGRATE_REVIEW=https://github.com/google/adk-python/pull/4175 from didier-durand:fix-typos-c 16e93ed2d9bc153fa0332ab1ae39633fcc5056e9
PiperOrigin-RevId: 858751240
Merge https://github.com/google/adk-python/pull/3538
Main change from:
E(inv=2, role=user), E(inv=2, role=model), E(inv=2, role=user),
To:
E(inv=2, role=user), E(inv=2, role=model)
I think the last E(inv=2, role=user) was wrong. Also reformatted.
Co-authored-by: Hangfei Lin <hangfei@google.com>
COPYBARA_INTEGRATE_REVIEW=https://github.com/google/adk-python/pull/3538 from adrianad:patch-1 627b933bdc3e00e45f704edf95448281e32d127c
PiperOrigin-RevId: 835346467
Creates AdkFolderManager for creating/resetting the .adk layout, helper builders that return SQLite- and filesystembacked services for each agent
Co-authored-by: George Weale <gweale@google.com>
PiperOrigin-RevId: 831206377
Merge https://github.com/google/adk-python/pull/3382
This PR corrects misspellings identified by the [check-spelling action](https://github.com/marketplace/actions/check-spelling)
Note: while I use tooling to identify errors, the tooling doesn't _actually_ provide the corrections, I'm picking them on my own. I'm a human, and I may make mistakes.
### Testing Plan
The misspellings have been reported at https://github.com/jsoref/adk-python/actions/runs/19056081305/attempts/1#summary-54426435973
The action reports that the changes in this PR would make it happy: https://github.com/jsoref/adk-python/actions/runs/19056081446/attempts/1#summary-54426436321
**Unit Tests:**
- [ ] I have added or updated unit tests for my change.
- [ ] All unit tests pass locally.
_Please include a summary of passed `pytest` results._
**Manual End-to-End (E2E) Tests:**
_Please provide instructions on how to manually test your changes, including any
necessary setup or configuration. Please provide logs or screenshots to help
reviewers better understand the fix._
### Checklist
- [x] I have read the [CONTRIBUTING.md](https://github.com/google/adk-python/blob/main/CONTRIBUTING.md) document.
- [x] I have performed a self-review of my own code.
- [ ] I have commented my code, particularly in hard-to-understand areas.
- [ ] I have added tests that prove my fix is effective or that my feature works.
- [ ] New and existing unit tests pass locally with my changes.
- [ ] I have manually tested my changes end-to-end.
- [ ] Any dependent changes have been merged and published in downstream modules.
### Additional context
- follow-up to #2447
Co-authored-by: Hangfei Lin <hangfei@google.com>
COPYBARA_INTEGRATE_REVIEW=https://github.com/google/adk-python/pull/3382 from jsoref:spelling 3df5932e97391c437e1638d7163e5e3d5c52d5c3
PiperOrigin-RevId: 828686941
When there are multiple intervals and compactions, the original implementation only keep the last one. The right implementation is to keep as many compaction events/summary as the requested internals.
PiperOrigin-RevId: 816516662
If `EventsCompactionConfig` is provided without a `compactor`, a `SlidingWindowCompactor` is now automatically instantiated using the `root_agent`'s LLM. This simplifies configuration by providing a sensible default.
PiperOrigin-RevId: 816038579
The class is now named `LlmEventSummarizer` to better reflect that its primary function is to use an LLM to summarize events. The docstring has been updated to clarify that this class is responsible *only* for the LLM-based summarization of a given set of events, while the logic for determining *when* and *which* events form the sliding window is handled by an external component, such as an ADK Runner.
PiperOrigin-RevId: 815976264
1. add a context cache config in app level which will apply to all agents in the app
2. pass on cache config through invocation context to llm_reqeust
3. store cache metadata in llm_response
4. lookup old cache metadata from latest event for reusing old cache
5. create new cache if old cache cannot be reused
PiperOrigin-RevId: 809158578
Provide a more efficient way to compact LLM context for better agentic performance.
* `app`: the top level abstraction for an ADK application. It contains an root agent, and plugins.
* `content_strategy`: the abstraction for selecting the contents for LLM request.
* `compaction_strategy`: the abstraction for compacting the events.
* Added `sequence_id` and `summary_range` in event class.
PiperOrigin-RevId: 808634224
The convention:
- If some fields(like plugin) are defined both at root_agent and app, then a error will be raised.
- app code should be located within agent.py.
- an instance named app should be created
PiperOrigin-RevId: 803155804
The convention:
- If some fields(like plugin) are defined both at root_agent and app, then a error will be raised.
- app code should be located within agent.py.
- an instance named app should be created
PiperOrigin-RevId: 801252329
The convention:
- If some fields(like plugin) are defined both at root_agent and app, then a error will be raised.
- app code should be located within agent.py.
- an instance named app should be created
PiperOrigin-RevId: 801103084
The convention:
- If some fields(like plugin) are defined both at root_agent and app, then a error will be raised.
- app code should be located within agent.py.
- an instance named app should be created
PiperOrigin-RevId: 801084463