|
22 | 22 | import com.google.adk.models.LlmResponse; |
23 | 23 | import com.google.genai.types.Content; |
24 | 24 | import com.google.genai.types.FunctionCall; |
| 25 | +import com.google.genai.types.FunctionResponse; |
25 | 26 | import com.google.genai.types.GenerateContentResponseUsageMetadata; |
26 | 27 | import com.google.genai.types.Part; |
27 | 28 | import java.net.URI; |
@@ -261,10 +262,15 @@ private List<Message> handleUserContent(Content content) { |
261 | 262 | if (part.text().isPresent()) { |
262 | 263 | textBuilder.append(part.text().get()); |
263 | 264 | } else if (part.functionResponse().isPresent()) { |
264 | | - // TODO: Spring AI 1.1.0 ToolResponseMessage constructors are protected |
265 | | - // For now, we skip tool responses in user messages |
266 | | - // This will need to be addressed in a future update when Spring AI provides |
267 | | - // a public API for creating ToolResponseMessage |
| 265 | + FunctionResponse functionResponse = part.functionResponse().get(); |
| 266 | + String id = functionResponse.id().orElse(""); |
| 267 | + String name = functionResponse.name().orElse(""); |
| 268 | + String responseData = toJson(functionResponse.response().orElse(Map.of())); |
| 269 | + |
| 270 | + ToolResponseMessage.ToolResponse toolResponse = |
| 271 | + new ToolResponseMessage.ToolResponse(id, name, responseData); |
| 272 | + toolResponseMessages.add( |
| 273 | + ToolResponseMessage.builder().responses(List.of(toolResponse)).build()); |
268 | 274 | } else if (part.inlineData().isPresent()) { |
269 | 275 | // Handle inline media data (images, audio, video, etc.) |
270 | 276 | com.google.genai.types.Blob blob = part.inlineData().get(); |
@@ -298,7 +304,9 @@ private List<Message> handleUserContent(Content content) { |
298 | 304 | } |
299 | 305 |
|
300 | 306 | List<Message> messages = new ArrayList<>(); |
301 | | - messages.add(UserMessage.builder().text(textBuilder.toString()).media(mediaList).build()); |
| 307 | + if (textBuilder.length() > 0 || !mediaList.isEmpty() || toolResponseMessages.isEmpty()) { |
| 308 | + messages.add(UserMessage.builder().text(textBuilder.toString()).media(mediaList).build()); |
| 309 | + } |
302 | 310 | messages.addAll(toolResponseMessages); |
303 | 311 |
|
304 | 312 | return messages; |
|
0 commit comments