Commit 1bf4617
Preserve Gemini thought_signature across OpenAI-compatible tool-call round trips (#1631)
## Summary
This fixes a loss of Gemini thinking-model state in the
OpenAI-compatible adapter.
When kagent is configured to use Gemini through an OpenAI-compatible
endpoint, the adapter was flattening tool calls and tool results into
standard OpenAI chat messages without preserving Gemini-specific
`extra_content.google.thought_signature`. That caused thinking-capable
Gemini models to fail on the post-tool turn, even though the tool call
itself succeeded.
This change preserves the thought signature in both directions:
- OpenAI-compatible response -> ADK Part
- ADK Content -> OpenAI-compatible follow-up tool/result messages
It also applies the same preservation in the streaming tool-call
accumulation path.
## Why
We traced a production stream where:
1. The first model turn succeeded,
2. The model issued a tool call,
3. The tool executed successfully,
4. The follow-up request failed because the original function call’s
`thought_signature` was no longer present.
The lossy step was in kagent’s Python OpenAI-compatible adapter.
The adapter was reconstructing only standard OpenAI fields like text,
tool calls, and tool results. Gemini thinking models require the opaque
thought signature to survive the round-trip, so dropping it breaks the
second turn.
## What Changed
- Added logic to extract extra_content.google.thought_signature from
OpenAI-compatible tool calls.
- Mapped that value onto ADK Part.thought_signature.
- Preserved Part.thought_signature when converting function-call parts
back into OpenAI-compatible tool_calls.
- Preserved the same signature on the paired tool-result message sent
after tool execution.
- Applied the same preservation in the streaming tool-call aggregation
path.
- Added regression tests for:
- response conversion preserving thought signatures,
- outbound message conversion preserving thought signatures,
- full round-trip preservation across tool call + tool result.
## Scope
This PR does not change public config or CRD APIs. It only fixes
internal adapter behavior for OpenAI-compatible model flows.
## Validation
Ran:
`uv run pytest
python/packages/kagent-adk/tests/unittests/models/test_openai.py`
Result:
`26 passed`
---------
Signed-off-by: adminturneddevops <mlevan1992@gmail.com>
Co-authored-by: Eitan Yarmush <eitan.yarmush@solo.io>1 parent 85e038c commit 1bf4617
File tree
4 files changed
+527
-23
lines changed- go/adk/pkg/models
- python/packages/kagent-adk
- src/kagent/adk/models
- tests/unittests/models
4 files changed
+527
-23
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| 17 | + | |
17 | 18 | | |
18 | 19 | | |
19 | 20 | | |
| |||
28 | 29 | | |
29 | 30 | | |
30 | 31 | | |
| 32 | + | |
31 | 33 | | |
32 | 34 | | |
33 | 35 | | |
| |||
42 | 44 | | |
43 | 45 | | |
44 | 46 | | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
45 | 123 | | |
46 | 124 | | |
47 | 125 | | |
| |||
126 | 204 | | |
127 | 205 | | |
128 | 206 | | |
| 207 | + | |
129 | 208 | | |
130 | 209 | | |
131 | 210 | | |
| |||
167 | 246 | | |
168 | 247 | | |
169 | 248 | | |
170 | | - | |
171 | | - | |
172 | | - | |
173 | | - | |
174 | | - | |
175 | | - | |
176 | | - | |
177 | | - | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
178 | 255 | | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
179 | 262 | | |
180 | 263 | | |
181 | 264 | | |
182 | 265 | | |
183 | 266 | | |
184 | | - | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
185 | 278 | | |
186 | 279 | | |
187 | 280 | | |
| |||
357 | 450 | | |
358 | 451 | | |
359 | 452 | | |
360 | | - | |
| 453 | + | |
361 | 454 | | |
362 | 455 | | |
363 | 456 | | |
| |||
369 | 462 | | |
370 | 463 | | |
371 | 464 | | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
372 | 468 | | |
373 | 469 | | |
374 | 470 | | |
| |||
404 | 500 | | |
405 | 501 | | |
406 | 502 | | |
407 | | - | |
408 | | - | |
| 503 | + | |
| 504 | + | |
409 | 505 | | |
410 | 506 | | |
411 | 507 | | |
| |||
438 | 534 | | |
439 | 535 | | |
440 | 536 | | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
441 | 543 | | |
442 | 544 | | |
443 | 545 | | |
| |||
455 | 557 | | |
456 | 558 | | |
457 | 559 | | |
458 | | - | |
459 | | - | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
460 | 567 | | |
461 | 568 | | |
462 | 569 | | |
| |||
467 | 574 | | |
468 | 575 | | |
469 | 576 | | |
470 | | - | |
| 577 | + | |
471 | 578 | | |
472 | 579 | | |
473 | 580 | | |
474 | 581 | | |
475 | 582 | | |
476 | 583 | | |
477 | | - | |
478 | | - | |
479 | 584 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
| 4 | + | |
| 5 | + | |
4 | 6 | | |
5 | 7 | | |
6 | 8 | | |
| |||
246 | 248 | | |
247 | 249 | | |
248 | 250 | | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
0 commit comments