Spring
Follow
Spring AI 2.1 Message Parts: Reasoning That Survives the Round Trip
Spring AI 2.1 introduces a significant change by replacing its previous message structure with an ordered list of message parts. This new data model is crucial for reasoning models that rely on returning specific blocks of thought and tool calls in their exact order. Previously, Spring AI messages lacked a defined structure for these opaque data types, leading to issues with ordering and loss of information, especially during streaming or when persisting memory.The MessagePart abstraction now serves as a universal way to represent text, reasoning blocks, tool calls, media, and even unknown data structures from various providers. This ensures that the order of content blocks, like reasoning followed by a tool call, is preserved. It also allows for opaque payloads, such as model signatures or encrypted reasoning, to be passed back to the model verbatim without interpretation, facilitating seamless transitions between different AI providers. Any content that Spring AI doesn't explicitly model is captured as an UnknownPart, ensuring it's replayed accurately.This update was essential for supporting OpenAI's newer Responses API, designed for reasoning models. This API returns an array of items like reasoning, function calls, and tool outputs, each with specific requirements for replaying. The MessagePart abstraction allows Spring AI to map these diverse items accurately, preserving their order and details for subsequent requests.The MessagePart system benefits various chat models by enabling them to replay crucial information like signed thinking blocks for Anthropic, thought signatures for Google GenAI, and reasoning content for OpenAI Chat Completions and others. This improves continuity, reduces errors, and maintains the full reasoning quality expected by these models. Session memory is also enhanced, allowing for the persistence of these ordered message parts across conversations. The overall gain is improved accuracy, reliability, and functionality when integrating with advanced AI models that leverage complex reasoning processes.