@@ -223,6 +223,46 @@ void testToLlmResponseFromChatResponseWithToolCalls() {
223223 Part functionCallPart = content .parts ().get ().get (1 );
224224 assertThat (functionCallPart .functionCall ()).isPresent ();
225225 assertThat (functionCallPart .functionCall ().get ().name ()).contains ("get_weather" );
226+ // Verify ID is preserved
227+ assertThat (functionCallPart .functionCall ().get ().id ()).contains ("call_123" );
228+ }
229+
230+ @ Test
231+ void testToolCallIdPreservedInConversion () {
232+ // Create AssistantMessage with tool call including ID
233+ AssistantMessage .ToolCall toolCall =
234+ new AssistantMessage .ToolCall (
235+ "call_abc123" , // ID must be preserved
236+ "function" ,
237+ "get_weather" ,
238+ "{\" location\" :\" San Francisco\" }" );
239+
240+ AssistantMessage assistantMessage =
241+ new AssistantMessage ("Let me check the weather." , Map .of (), List .of (toolCall ));
242+
243+ Generation generation = new Generation (assistantMessage );
244+ ChatResponse chatResponse = new ChatResponse (List .of (generation ));
245+
246+ // Convert to LlmResponse
247+ LlmResponse llmResponse = messageConverter .toLlmResponse (chatResponse );
248+
249+ // Verify the converted content preserves the tool call ID
250+ assertThat (llmResponse .content ()).isPresent ();
251+ Content content = llmResponse .content ().get ();
252+ assertThat (content .parts ()).isPresent ();
253+
254+ List <Part > parts = content .parts ().get ();
255+ Part functionCallPart =
256+ parts .stream ()
257+ .filter (p -> p .functionCall ().isPresent ())
258+ .findFirst ()
259+ .orElseThrow (() -> new AssertionError ("Expected function call part" ));
260+
261+ FunctionCall convertedCall = functionCallPart .functionCall ().get ();
262+ assertThat (convertedCall .id ()).contains ("call_abc123" ); // ✅ ID MUST BE PRESERVED
263+ assertThat (convertedCall .name ()).contains ("get_weather" );
264+ assertThat (convertedCall .args ()).isPresent ();
265+ assertThat (convertedCall .args ().get ()).containsEntry ("location" , "San Francisco" );
226266 }
227267
228268 @ Test
0 commit comments