Skip to content

Commit f305766

Browse files
authored
Merge branch 'main' into feat/fallback-invalid-attached-file-with-gemini
2 parents 8c867a3 + 4d5438c commit f305766

11 files changed

Lines changed: 373 additions & 241 deletions

File tree

.github/workflows/isort.yml

Lines changed: 0 additions & 69 deletions
This file was deleted.

.github/workflows/pyink.yml

Lines changed: 0 additions & 69 deletions
This file was deleted.

.pre-commit-config.yaml

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,3 @@
1-
# Copyright 2026 Google LLC
2-
#
3-
# Licensed under the Apache License, Version 2.0 (the "License");
4-
# you may not use this file except in compliance with the License.
5-
# You may obtain a copy of the License at
6-
#
7-
# http://www.apache.org/licenses/LICENSE-2.0
8-
#
9-
# Unless required by applicable law or agreed to in writing, software
10-
# distributed under the License is distributed on an "AS IS" BASIS,
11-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12-
# See the License for the specific language governing permissions and
13-
# limitations under the License.
14-
151
repos:
162
- repo: https://github.com/pre-commit/pre-commit-hooks
173
rev: v4.6.0
@@ -47,5 +33,6 @@ repos:
4733
hooks:
4834
- id: mdformat
4935
files: ^(README\.md|CONTRIBUTING\.md|contributing/.*\.md)$
36+
exclude: (?i)SKILL\.md$
5037
additional_dependencies:
5138
- mdformat-gfm

AGENTS.md

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -255,17 +255,7 @@ the key style points:
255255

256256
### Autoformat (Required Before Committing)
257257

258-
**Always run** before committing code: `bash ./autoformat.sh`
259-
260-
**Manual formatting** (if needed): ```bash
261-
262-
# Format imports
263-
264-
isort src/ tests/ contributing/
265-
266-
# Format code style
267-
268-
pyink --config pyproject.toml src/ tests/ contributing/ ```
258+
**Always run** before committing code: `pre-commit run --all-files`
269259

270260
**Check formatting** without making changes: `bash pyink --check --diff --config
271261
pyproject.toml src/ isort --check src/`
@@ -512,7 +502,9 @@ Quick reference to important project files:
512502
- **Main config:** `pyproject.toml` (uses `flit_core` build backend)
513503
- **Dependencies:** `uv.lock` (managed by `uv`)
514504
- **Linting:** `pylintrc` (Google Python Style Guide)
515-
- **Auto-format:** `autoformat.sh` (runs isort + pyink)
505+
- **Auto-format:** `pre-commit` (runs isort + pyink)
506+
- **Run on all files:** `pre-commit run --all-files`
507+
- **Install as hook:** `pre-commit install`
516508
- **CLI entry point:** `src/google/adk/cli/cli_tools_click.py`
517509
- **Web UI backend:** `src/google/adk/cli/adk_web_server.py`
518510
- **Main exports:** `src/google/adk/__init__.py` (exports Agent, Runner)

CONTRIBUTING.md

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -202,11 +202,18 @@ part before or alongside your code PR.
202202

203203
1. **Auto-format the code:**
204204

205-
**NOTE**: We use `isort` and `pyink` for styles. Use the included
206-
autoformat.sh to auto-format.
205+
We use `pre-commit` to manage code style and formatting (including `isort` and `pyink`).
206+
207+
To run it manually on all files:
208+
209+
```shell
210+
pre-commit run --all-files
211+
```
212+
213+
You can also install it as a git hook to run automatically on every commit:
207214

208215
```shell
209-
./autoformat.sh
216+
pre-commit install
210217
```
211218

212219
1. **Build the wheel file:**

autoformat.sh

Lines changed: 0 additions & 67 deletions
This file was deleted.
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
11
google-adk[a2a]==1.28.1
2-
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
11
google-adk==1.28.1
2-

contributing/samples/skills_agent/skills/weather-skill/SKILL.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1-
______________________________________________________________________
2-
3-
## name: weather-skill description: A skill that provides weather information based on reference data. metadata: adk_additional_tools: - get_wind_speed
1+
---
2+
name: weather-skill
3+
description: A skill that provides weather information based on reference data.
4+
metadata:
5+
adk_additional_tools:
6+
- get_wind_speed
7+
---
48

59
Step 1: Check 'references/weather_info.md' for the current weather.
610
Step 2: If humidity is requested, use run 'scripts/get_humidity.py' with the `location` argument.

src/google/adk/models/gemini_context_cache_manager.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@
3232

3333
logger = logging.getLogger("google_adk." + __name__)
3434

35+
# Gemini API requires a minimum of 4096 tokens for cached content.
36+
_GEMINI_MIN_CACHE_TOKENS = 4096
37+
3538
if TYPE_CHECKING:
3639
from google.genai import Client
3740

@@ -119,6 +122,19 @@ async def handle_context_caching(
119122
)
120123
return cache_metadata
121124

125+
# Cache creation failed (e.g., below Gemini's 4096 token minimum).
126+
# Preserve the original contents_count so the fingerprint stays
127+
# stable for subsequent calls instead of resetting to total.
128+
logger.debug(
129+
"Cache creation failed, preserving prefix fingerprint "
130+
"(contents_count=%d)",
131+
cache_contents_count,
132+
)
133+
return CacheMetadata(
134+
fingerprint=current_fingerprint,
135+
contents_count=cache_contents_count,
136+
)
137+
122138
# Fingerprints don't match - recalculate with total contents
123139
logger.debug(
124140
"Fingerprints don't match, returning fingerprint-only metadata"
@@ -304,6 +320,15 @@ async def _create_new_cache_with_contents(
304320
)
305321
return None
306322

323+
# Check client-side to avoid unnecessary API round-trips.
324+
if llm_request.cacheable_contents_token_count < _GEMINI_MIN_CACHE_TOKENS:
325+
logger.info(
326+
"Request below Gemini minimum cache size (%d < %d tokens)",
327+
llm_request.cacheable_contents_token_count,
328+
_GEMINI_MIN_CACHE_TOKENS,
329+
)
330+
return None
331+
307332
try:
308333
# Create cache using Gemini API directly
309334
return await self._create_gemini_cache(llm_request, cache_contents_count)

0 commit comments

Comments
 (0)