37 Commits

Author SHA1 Message Date
Google Team Member 66908e4c61 fix: count tool call and response chars in compaction
PiperOrigin-RevId: 967437247
2026-08-19 15:20:52 -07:00
George Weale ec42cfa237 feat: make EventsCompactionConfig sliding-window fields optional
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
2026-07-20 09:56:27 -07:00
Wiktoria Walczak 0d4d3783f7 fix: exclude rewound invocations from event compaction
Co-authored-by: Wiktoria Walczak <wwalczak@google.com>
PiperOrigin-RevId: 946902983
2026-07-13 02:37:53 -07:00
Kazi Eajaj Hossain b44d2c9d6c fix: explicitly preserve language and tools during event compaction
Merge https://github.com/google/adk-python/pull/6329

Fixes #6273

PiperOrigin-RevId: 944746917
2026-07-08 15:54:10 -07:00
George Weale 49c0a36538 refactor: yield the sliding-window compaction event to the runner
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
2026-07-07 14:26:48 -07:00
Wiktoria Walczak 71b936bf48 fix: prevent compaction from orphaning function responses
Co-authored-by: Wiktoria Walczak <wwalczak@google.com>
PiperOrigin-RevId: 932325806
2026-06-15 02:26:49 -07:00
Wei (Jack) Sun b79096ac86 refactor: Remove unused imports across src
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
2026-06-12 11:51:29 -07:00
George Weale bdb5582624 feat: include thoughts and tool calls in compaction summaries
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
2026-06-02 15:39:09 -07:00
Sasha Sobran 162279358c chore: switch main to v2.0.0 GA (transition to v2)
Co-authored-by: Bo Yang <ybo@google.com>
Co-authored-by: Wei Sun (Jack) <weisun@google.com>
Co-authored-by: George Weale <gweale@google.com>
Co-authored-by: Swapnil Agarwal <swapnilag@google.com>
Co-authored-by: Xuan Yang <xygoogle@google.com>
Co-authored-by: Shangjie Chen <deanchen@google.com>
Co-authored-by: Yifan Wang <wanyif@google.com>
Co-authored-by: Kathy Wu <wukathy@google.com>
2026-05-19 02:01:33 +00:00
Google Team Member bd062ec9eb perf: lazy-load service registries and split apps.app to cut cold start ~8%
PiperOrigin-RevId: 916278514
2026-05-15 18:35:23 -07:00
Google Team Member 6e6621c768 perf: lazy-load service registries and split apps.app to cut cold start ~8%
PiperOrigin-RevId: 916265957
2026-05-15 17:50:01 -07:00
George Weale 6ca6a14187 perf: lazy-load service registries and split apps.app to cut cold start ~8%
Co-authored-by: George Weale <gweale@google.com>
PiperOrigin-RevId: 916195791
2026-05-15 14:54:10 -07:00
George Weale bb2efb6bd2 fix: Prevent compaction of events involved in Human-in-the-Loop interactions
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
2026-05-15 11:43:53 -07:00
George Weale c65dd5580f feat: Add OpenTelemetry tracing for event compaction
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
2026-04-24 17:51:31 -07:00
George Weale 5ce33b9c1e fix: Capture and include LLM usage metadata in summarized events
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
2026-04-24 14:30:02 -07:00
George Weale 991c4111e3 fix: Prevent compaction of events with pending function calls
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
2026-03-19 11:01:53 -07:00
George Weale 485fcb84e3 feat: Add intra-invocation compaction and token compaction pre-request
Compact session events before LLM calls when token threshold is exceeded

Co-authored-by: George Weale <gweale@google.com>
PiperOrigin-RevId: 873095899
2026-02-20 15:19:45 -08:00
George Weale a88e864755 fix: Add post-invocation token-threshold compaction with event retention
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
2026-02-10 13:38:28 -08:00
George Weale 2367901ec5 chore: Upgrade to headers to 2026
Co-authored-by: George Weale <gweale@google.com>
PiperOrigin-RevId: 858763407
2026-01-20 14:50:09 -08:00
Didier Durand a8f2ddd943 chore: fixing various typos
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
2026-01-20 14:21:01 -08:00
Adrian Altermatt 609c6172d9 docs: too many E(inv=2, role=user) plus reformatting
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
2025-11-21 13:49:01 -08:00
George Weale 99fc17b336 feat: add adk folder manager and per agent local storage helpers
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
2025-11-11 21:38:51 -08:00
Josh Soref 1d80d32efc chore: Fix spelling in src
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
2025-11-05 16:59:10 -08:00
Hangfei Lin b23eed6a85 feat: Remove @experimental from App class
This change marks the `App` class as no longer experimental.

Co-authored-by: Hangfei Lin <hangfei@google.com>
PiperOrigin-RevId: 825739749
2025-10-29 15:45:56 -07:00
Hangfei Lin 3f2b457efd fix: fix compaction logic
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
2025-10-07 21:16:07 -07:00
Hangfei Lin 3f4bd67b49 fix: Make compactor optional in EventsCompactionConfig and add a default
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
2025-10-06 22:20:49 -07:00
Hangfei Lin f1abdb1938 fix: Rename SlidingWindowCompactor to LlmEventSummarizer and refine its docstring
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
2025-10-06 18:54:20 -07:00
Hangfei Lin e0dd06ff04 feat: implementation of LLM context compaction
Provide a more efficient way to compact LLM context for better agentic performance.

PiperOrigin-RevId: 815785898
2025-10-06 10:28:46 -07:00
Xinran (Sherry) Tang b5a65fb4f4 chore: Remove the too-detailed edge case descriptions for resumability
PiperOrigin-RevId: 811432962
2025-09-25 11:32:38 -07:00
Xinran (Sherry) Tang cbb6e4945a feat: Add a app level config for resumable applications
PiperOrigin-RevId: 811272046
2025-09-25 03:14:34 -07:00
Xiang (Sean) Zhou c66245a3b8 feat: support context caching
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
2025-09-19 13:17:02 -07:00
Hangfei Lin c37bd2742c feat: Introduce LLM context compaction interface
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
2025-09-18 10:14:12 -07:00
Hangfei Lin 4df79dd5c9 feat: Upgrade ADK stack to use App instead in addition to root_agent
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
2025-09-04 13:38:00 -07:00
Google Team Member 831e2e6d4d ADK changes
PiperOrigin-RevId: 801284664
2025-08-30 11:08:43 -07:00
Hangfei Lin dff733c6fc feat: Upgrade ADK stack to use App instead in addition to root_agent
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
2025-08-30 08:01:53 -07:00
Google Team Member 214f2884f5 feat: Upgrade ADK stack to use App instead in addition to root_agent
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
2025-08-29 18:49:04 -07:00
Hangfei Lin a2e89a22a5 feat: Upgrade ADK stack to use App instead in addition to root_agent
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
2025-08-29 17:33:38 -07:00