From 07faebe1a43a0266fea0f40b35659b416f8842da Mon Sep 17 00:00:00 2001 From: TheEterna <125226601+TheEterna@users.noreply.github.com> Date: Tue, 17 Jun 2025 16:23:45 +0800 Subject: [PATCH] fixed #3559 Modify the DefaultToolCallResultConverter.convert method and add the Mono processing code Signed-off-by: TheEterna <125226601+TheEterna@users.noreply.github.com> --- .../ai/tool/execution/DefaultToolCallResultConverter.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/spring-ai-model/src/main/java/org/springframework/ai/tool/execution/DefaultToolCallResultConverter.java b/spring-ai-model/src/main/java/org/springframework/ai/tool/execution/DefaultToolCallResultConverter.java index dcbc5fcab97..13f9f8179c5 100644 --- a/spring-ai-model/src/main/java/org/springframework/ai/tool/execution/DefaultToolCallResultConverter.java +++ b/spring-ai-model/src/main/java/org/springframework/ai/tool/execution/DefaultToolCallResultConverter.java @@ -27,6 +27,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import reactor.core.publisher.Mono; import org.springframework.ai.util.json.JsonParser; import org.springframework.lang.Nullable; @@ -47,6 +48,11 @@ public String convert(@Nullable Object result, @Nullable Type returnType) { logger.debug("The tool has no return type. Converting to conventional response."); return JsonParser.toJson("Done"); } + // handle results of Mono type + if (result instanceof Mono) { + result = ((Mono) result).block(); + } + if (result instanceof RenderedImage) { final var buf = new ByteArrayOutputStream(1024 * 4); try {