Skip to content

Commit 156ffee

Browse files
committed
Update google_client.py
1 parent 25061f1 commit 156ffee

1 file changed

Lines changed: 24 additions & 3 deletions

File tree

src/llm/google_client.py

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,12 +147,16 @@ async def generate(
147147
args = tc.function.arguments
148148
if isinstance(args, str):
149149
args = json.loads(args) if args else {}
150-
parts.append({
150+
fc_part = {
151151
"function_call": {
152152
"name": tc.function.name,
153153
"args": args
154154
}
155-
})
155+
}
156+
# Include thought_signature if present (required for thinking models)
157+
if hasattr(tc, "thought_signature") and tc.thought_signature:
158+
fc_part["function_call"]["thought_signature"] = tc.thought_signature
159+
parts.append(fc_part)
156160

157161
# Only add if we have parts
158162
if parts:
@@ -253,6 +257,18 @@ async def generate(
253257
import uuid
254258

255259
tool_calls = []
260+
261+
# Build a map of function call names to their thought_signatures from raw parts
262+
# Some models return thought_signature at the Part level, not the FunctionCall level
263+
thought_sig_map = {}
264+
if response.candidates and response.candidates[0].content and response.candidates[0].content.parts:
265+
for part in response.candidates[0].content.parts:
266+
if hasattr(part, "function_call") and part.function_call:
267+
fc_part = part.function_call
268+
sig = getattr(part, "thought_signature", None) or getattr(fc_part, "thought_signature", None)
269+
if sig and hasattr(fc_part, "name"):
270+
thought_sig_map[fc_part.name] = sig
271+
256272
for fc in response.function_calls:
257273
# parsed arguments are usually a dict in google-genai, but main.py expects a JSON string
258274
args_str = json.dumps(fc.args) if fc.args else "{}"
@@ -265,10 +281,15 @@ async def generate(
265281
# Generate unique ID to avoid collisions when same function is called multiple times
266282
call_id = f"call_{fc.name}_{uuid.uuid4().hex[:8]}"
267283

284+
# Capture thought_signature if present (required for thinking models)
285+
# Check both the function call object and our map from raw parts
286+
thought_sig = getattr(fc, "thought_signature", None) or thought_sig_map.get(fc.name)
287+
268288
tool_calls.append(SimpleNamespace(
269289
function=function_obj,
270290
id=call_id,
271-
type="function"
291+
type="function",
292+
thought_signature=thought_sig
272293
))
273294

274295
# Extract usage metadata if available

0 commit comments

Comments
 (0)