Skip to content

Commit 6aad10d

Browse files
GWealecopybara-github
authored andcommitted
feat: expose SKIP_THOUGHT_SIGNATURE_VALIDATOR constant
Gemini thinking models require a thought_signature on generated parts, and the backend rejects replayed parts that lack one. Callers who synthesize conversation history must set b'skip_thought_signature_validator' on the fabricated part to bypass validation, and several ADK consumers hardcode that byte-string independently. Expose it once so they can depend on a single constant. Co-authored-by: George Weale <gweale@google.com> PiperOrigin-RevId: 941277709
1 parent 4d88a52 commit 6aad10d

2 files changed

Lines changed: 40 additions & 0 deletions

File tree

src/google/adk/utils/content_utils.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@
1616

1717
from google.genai import types
1818

19+
SKIP_THOUGHT_SIGNATURE_VALIDATOR: bytes = b'skip_thought_signature_validator'
20+
"""Placeholder ``Part.thought_signature`` that bypasses backend validation.
21+
22+
Set it on a part you synthesize yourself (a model turn or tool call/response
23+
the model never produced) so the Gemini backend accepts the fabricated part
24+
instead of rejecting it for a missing signature.
25+
"""
26+
1927

2028
def is_audio_part(part: types.Part) -> bool:
2129
return (
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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+
15+
from __future__ import annotations
16+
17+
from google.adk.utils.content_utils import SKIP_THOUGHT_SIGNATURE_VALIDATOR
18+
from google.genai import types
19+
20+
21+
def test_skip_thought_signature_validator_wire_value():
22+
# The backend recognizes this exact byte string to bypass validation;
23+
# changing it would break every replayed synthetic part.
24+
assert SKIP_THOUGHT_SIGNATURE_VALIDATOR == b'skip_thought_signature_validator'
25+
26+
27+
def test_skip_thought_signature_validator_assignable_to_part():
28+
part = types.Part(
29+
text='injected',
30+
thought_signature=SKIP_THOUGHT_SIGNATURE_VALIDATOR,
31+
)
32+
assert part.thought_signature == SKIP_THOUGHT_SIGNATURE_VALIDATOR

0 commit comments

Comments
 (0)