Repository navigation
Commit d1d9dc2
committed
fix: round-trip thinking blocks in the Claude model
Claude.anthropicContentBlockToPart converted only text and tool_use
blocks and threw UnsupportedOperationException("Not supported yet.")
for any other block. The Claude 5 models use adaptive thinking when the
request has no thinking field, which ADK Java never sets, so their
responses can contain thinking blocks without being asked, and each
such response ended the agent run.
Convert the blocks the same way as ADK Python:
- thinking -> Part(text, thought=true, thoughtSignature=signature)
- redacted_thinking -> Part(thought=true, thoughtSignature=data)
partToAnthropicMessageBlock sends them back unchanged, which Anthropic
requires within a tool-use turn: a thought with a signature becomes a
thinking block when it has text and a redacted_thinking block when it
has none. Only signatures stored this way, as UTF-8 text, are sent
back. A binary signature that another model such as Gemini left on a
thought is not Claude's, and Anthropic rejects signatures it cannot
decode.
It also ports google/adk-python@a5d6238cb. A non-thought part that
carries only a thought signature, which Gemini leaves in the history,
is dropped with a warning instead of throwing or going out as an empty
text block, and a message whose parts were all dropped is left out,
since Anthropic rejects empty messages. The part stays in the session,
so without this every later turn failed the same way.
Three deliberate differences from ADK Python:
- A thought with empty text (display "omitted", the Claude 5 default)
goes back as the thinking block it came from. ADK Python treats the
empty text as absent and sends a redacted_thinking block whose data
is the signature.
- Any other thought is never sent as a thinking block. It is still
sent as text, as before, or dropped if it has no text, since there
is nothing to send back and Anthropic rejects empty text blocks.
ADK Python sends an unsigned thought with text as a thinking block
with an empty signature.
- A part with a function call or response is always sent as tool_use
or tool_result, even if it is a thought or also has text, so that
the call and its tool_result stay paired. ADK Python checks
non-empty text and a thought's signature before the call, so the
call is lost in those cases.1 parent c239870 commit d1d9dc2
2 files changed
Lines changed: 492 additions & 4 deletions
File tree
- core/src
- main/java/com/google/adk/models
- test/java/com/google/adk/models
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| 19 | + | |
| 20 | + | |
19 | 21 | | |
20 | 22 | | |
21 | 23 | | |
22 | 24 | | |
23 | 25 | | |
24 | 26 | | |
25 | 27 | | |
| 28 | + | |
26 | 29 | | |
| 30 | + | |
27 | 31 | | |
28 | 32 | | |
29 | 33 | | |
| |||
32 | 36 | | |
33 | 37 | | |
34 | 38 | | |
| 39 | + | |
35 | 40 | | |
36 | 41 | | |
37 | 42 | | |
| |||
44 | 49 | | |
45 | 50 | | |
46 | 51 | | |
| 52 | + | |
47 | 53 | | |
48 | 54 | | |
49 | 55 | | |
| |||
104 | 110 | | |
105 | 111 | | |
106 | 112 | | |
| 113 | + | |
| 114 | + | |
107 | 115 | | |
108 | 116 | | |
109 | 117 | | |
| |||
173 | 181 | | |
174 | 182 | | |
175 | 183 | | |
176 | | - | |
177 | | - | |
178 | | - | |
179 | | - | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
180 | 231 | | |
181 | 232 | | |
182 | 233 | | |
| |||
205 | 256 | | |
206 | 257 | | |
207 | 258 | | |
| 259 | + | |
| 260 | + | |
208 | 261 | | |
209 | 262 | | |
210 | 263 | | |
| |||
387 | 440 | | |
388 | 441 | | |
389 | 442 | | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
390 | 455 | | |
391 | 456 | | |
392 | 457 | | |
| |||
0 commit comments