spring-projects / spring-projects/spring-ai
Modify the DefaultToolCallResultConverter.convert method and add filtering code
Open
Nobody has claimed this yet.
status: waiting-for-triage
- Dominant language
- Java
- Stars
- 9.5k
- Forks
- 2.9k
- Avg merge
- 1d 7h
- Merged PRs (30d)
- 6
Description
If the method returns a value of Mono type, the calling effect cannot be achieved.
So the modifications are as follows:
public String convert(@Nullable Object result, @Nullable Type returnType) {
// This is the newly added filtering code used to obtain the real values in Mono
**if (result instanceof Mono<?>) {
result = ((Mono<?>) result).block();
}**
if (returnType == Void.TYPE) {
logger.debug("The tool has no return type. Converting to conventional response.");
return JsonParser.toJson("Done");
} else if (result instanceof RenderedImage) {
ByteArrayOutputStream buf = new ByteArrayOutputStream(4096);
try {
ImageIO.write((RenderedImage)result, "PNG", buf);
} catch (IOException var5) {
return "Failed to convert tool result to a base64 image: " + var5.getMessage();
}
String imgB64 = Base64.getEncoder().encodeToString(buf.toByteArray());
return JsonParser.toJson(Map.of("mimeType", "image/png", "data", imgB64));
} else {
logger.debug("Converting tool result to JSON.");
return JsonParser.toJson(result);
}
}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Locate DefaultToolCallResultConverter.convert and inspect how tool results are converted before the existing void, image, and JSON branches. Verify the Mono result is unwrapped before conversion, then confirm the resulting value follows the existing response behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, spring
- Domain
- ai, backend
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100