Repository navigation
Description
Description
Gemini 3 models require a thought_signature to be replayed together with each functionCall part. The Gemini parser in this repo already stores the signature correctly as byte[] in ToolUseBlock metadata (ToolUseBlock.METADATA_THOUGHT_SIGNATURE), and direct in-memory conversion works.
However, when agent state goes through a JSON persistence round-trip (any state store built on JsonUtils / Jackson: save session → load session), typed metadata values do not survive:
byte[]→ Jackson persists it as a Base64String- typed objects such as
OpenAIReasoningDetail→ restored asLinkedHashMap
The message converters only instanceof-check the original types, so the signature is silently dropped. On the next turn the request goes out without the signature and the Gemini API rejects the whole request:
400 INVALID_ARGUMENT
"Function call is missing a thought_signature in functionCall parts.
This is required for tools to work correctly for Gemini 3 models."
This breaks any multi-turn tool-calling loop that persists agent state between turns.
Reproduction
// 1. What the Gemini parser produces after a tool-call turn (works):
byte[] signature = ...; // from the model response
Map<String, Object> metadata = new HashMap<>();
metadata.put(ToolUseBlock.METADATA_THOUGHT_SIGNATURE, signature);
ToolUseBlock toolUse = ToolUseBlock.builder()
.id("call_1").name("search").metadata(metadata).build();
Msg msg = Msg.builder().name("assistant")
.content(List.of(toolUse)).role(MsgRole.ASSISTANT).build();
// 2. What every JSON state store does (save + load):
Msg restored = JsonUtils.getJsonCodec()
.fromJson(JsonUtils.getJsonCodec().toJson(msg), Msg.class);
// metadata value is now a Base64 String, not byte[]
// 3. What the converter does on the next request:
List<Content> contents = new GeminiMessageConverter()
.convertMessages(List.of(restored));
// contents.get(0).parts().get().get(0).thoughtSignature() -> Optional.empty
// signature is gone; the API then returns 400Root cause locations (at 6059782):
GeminiMessageConverter(~L129): onlysignature instanceof byte[]is attached; a Base64Stringis ignored.OpenAIMessageConverter(~L369, ~L396): onlysignature instanceof Stringis accepted (so the in-memorybyte[]cross-provider path is dropped too), and"reasoningDetail"metadata is only accepted as a typedOpenAIReasoningDetail, not as theLinkedHashMapthat comes back from persistence.
Live API verification
Replaying the second turn of a real tool-calling conversation against gemini-3-flash-preview, with the two request payloads identical except for the signature:
- without
thoughtSignature: HTTP400 INVALID_ARGUMENT— "Function call is missing a thought_signature in functionCall parts. This is required for tools to work correctly for Gemini 3 models." - with
thoughtSignature: HTTP200, model answers normally.
Environment
- agentscope-java v2.0.3-SNAPSHOT (6059782)
agentscope-extensions-model-geminiwith google-genai SDK 1.45.0- JDK 21 (Temurin), macOS
- Model:
gemini-3-flash-preview
A fix proposal is ready — decode Base64 strings back to byte[] (and normalize byte[] to Base64 on the OpenAI side) in the converters.
Activity
fix(model): preserve thought signatures across JSON persistence round…