🤖 AI Summary
Spring AI now includes a practical demo for converting tool-call outputs from the default JSON into alternative formats (TOON, YAML, XML, CSV) so developers can experiment with the token-efficiency and parsing trade-offs of each format. The article explains two integration patterns: a per-tool approach using ToolCallResultConverter (the DefaultToolCallResultConverter can be extended—e.g., a ToonToolCallResultConverter that delegates to JSON then runs JToon.encodeJson—and be wired via @Tool(resultConverter=...)), and a global approach that wraps an existing ToolCallbackProvider with a DelegatorToolCallbackProvider. In both flows the tool still executes normally to produce JSON, then a ResponseConverter converts that JSON to the target format before the LLM receives it (execution: Tool → default JSON → format conversion → LLM).
Key technical notes: core interfaces include ToolCallback, ToolCallResultConverter, ToolCallbackProvider and a ResponseConverter with Format enum {TOON, YAML, XML, CSV, JSON}; the demo includes JSON→TOON/YAML/XML/CSV converters (handling arrays-for-XML, dynamic CSV schemas, etc.). Measured token usage in the demo ranks CSV (815 total) and TOON (846) as more token-efficient than JSON (992) and XML (1171), illustrating potential cost/performance benefits but also context sensitivity. The example is a demo (not production-ready), available on GitHub, and can be toggled via mvnw -Dspring.ai.tool.response.format=TOON|CSV|YAML for experimentation.
Loading comments...
login to comment
loading comments...
no comments yet