Commit 6942a69
committed
feat(google-genai): Support thought signatures for Gemini 3 Pro function calling
Add thought signature support required by Gemini 3 Pro when using function
calling with includeThoughts enabled. Thought signatures preserve reasoning
context during the internal tool execution loop.
Changes from original implementation:
- Attach thought signatures to functionCall parts per Google specification
(not to text parts or separate empty parts)
- Clarify in documentation that validation applies only to the current turn's
function calling loop, not to historical conversation messages
- Add integration tests validating function calls with signatures
Key behaviors:
- Signatures are extracted from model responses and stored in message metadata
- During internal tool execution, signatures are correctly attached to
functionCall parts when sending back function responses
- Handles both parallel and sequential function calls correctly:
- Parallel: only first functionCall gets the signature (per API spec)
- Sequential: each step's first functionCall gets its signature
- Previous turn signatures in conversation history are not validated by the API
See: https://ai.google.dev/gemini-api/docs/thought-signatures
Signed-off-by: Dan Dobrin <[email protected]>
Signed-off-by: Mark Pollack <[email protected]>1 parent d4b6cf2 commit 6942a69
File tree
10 files changed
+776
-37
lines changed- auto-configurations/models/spring-ai-autoconfigure-model-google-genai/src/test/java/org/springframework/ai/model/google/genai/autoconfigure/chat
- models/spring-ai-google-genai/src
- main/java/org/springframework/ai/google/genai
- test/java/org/springframework/ai/google/genai
- tool
- spring-ai-docs/src/main/antora/modules/ROOT/pages/api/chat
10 files changed
+776
-37
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
131 | 131 | | |
132 | 132 | | |
133 | 133 | | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
134 | 153 | | |
135 | 154 | | |
136 | 155 | | |
| |||
Lines changed: 66 additions & 13 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
281 | 281 | | |
282 | 282 | | |
283 | 283 | | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
284 | 300 | | |
285 | | - | |
| 301 | + | |
286 | 302 | | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
287 | 307 | | |
288 | | - | |
289 | | - | |
290 | | - | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
291 | 312 | | |
292 | 313 | | |
293 | 314 | | |
294 | | - | |
295 | | - | |
296 | | - | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
297 | 324 | | |
| 325 | + | |
298 | 326 | | |
299 | 327 | | |
300 | 328 | | |
| |||
601 | 629 | | |
602 | 630 | | |
603 | 631 | | |
604 | | - | |
605 | | - | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
606 | 648 | | |
607 | 649 | | |
608 | 650 | | |
| |||
716 | 758 | | |
717 | 759 | | |
718 | 760 | | |
719 | | - | |
720 | | - | |
721 | | - | |
| 761 | + | |
| 762 | + | |
| 763 | + | |
| 764 | + | |
| 765 | + | |
| 766 | + | |
| 767 | + | |
| 768 | + | |
| 769 | + | |
| 770 | + | |
| 771 | + | |
722 | 772 | | |
| 773 | + | |
723 | 774 | | |
724 | 775 | | |
725 | 776 | | |
| |||
1068 | 1119 | | |
1069 | 1120 | | |
1070 | 1121 | | |
1071 | | - | |
| 1122 | + | |
| 1123 | + | |
| 1124 | + | |
1072 | 1125 | | |
1073 | 1126 | | |
1074 | 1127 | | |
| |||
Lines changed: 37 additions & 9 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
119 | 119 | | |
120 | 120 | | |
121 | 121 | | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
122 | 135 | | |
123 | 136 | | |
124 | 137 | | |
| |||
212 | 225 | | |
213 | 226 | | |
214 | 227 | | |
| 228 | + | |
215 | 229 | | |
216 | 230 | | |
217 | 231 | | |
| |||
371 | 385 | | |
372 | 386 | | |
373 | 387 | | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
374 | 396 | | |
375 | 397 | | |
376 | 398 | | |
| |||
474 | 496 | | |
475 | 497 | | |
476 | 498 | | |
| 499 | + | |
477 | 500 | | |
478 | 501 | | |
479 | 502 | | |
| |||
487 | 510 | | |
488 | 511 | | |
489 | 512 | | |
490 | | - | |
491 | | - | |
492 | | - | |
493 | | - | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
494 | 517 | | |
495 | 518 | | |
496 | 519 | | |
497 | 520 | | |
498 | 521 | | |
499 | 522 | | |
500 | 523 | | |
501 | | - | |
502 | | - | |
503 | | - | |
504 | | - | |
505 | | - | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
506 | 529 | | |
507 | 530 | | |
508 | 531 | | |
| |||
640 | 663 | | |
641 | 664 | | |
642 | 665 | | |
| 666 | + | |
| 667 | + | |
| 668 | + | |
| 669 | + | |
| 670 | + | |
643 | 671 | | |
644 | 672 | | |
645 | 673 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
105 | 105 | | |
106 | 106 | | |
107 | 107 | | |
108 | | - | |
| 108 | + | |
109 | 109 | | |
110 | 110 | | |
111 | 111 | | |
| |||
Lines changed: 6 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
64 | 64 | | |
65 | 65 | | |
66 | 66 | | |
67 | | - | |
| 67 | + | |
68 | 68 | | |
69 | 69 | | |
70 | 70 | | |
| |||
86 | 86 | | |
87 | 87 | | |
88 | 88 | | |
89 | | - | |
| 89 | + | |
90 | 90 | | |
91 | 91 | | |
92 | 92 | | |
| |||
126 | 126 | | |
127 | 127 | | |
128 | 128 | | |
129 | | - | |
| 129 | + | |
130 | 130 | | |
131 | 131 | | |
132 | 132 | | |
| |||
174 | 174 | | |
175 | 175 | | |
176 | 176 | | |
177 | | - | |
178 | | - | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
179 | 180 | | |
180 | 181 | | |
181 | 182 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
61 | 61 | | |
62 | 62 | | |
63 | 63 | | |
64 | | - | |
| 64 | + | |
65 | 65 | | |
66 | 66 | | |
67 | 67 | | |
| |||
0 commit comments