There seems to be some models not handling correctly the non-nullability of toolCallArguments when defining a tool call. For example, the Ollama implementation is always null-safe (if no tool argument, then '{}' is used). Other implementations might produce a null value.
This PR relaxes the toolCallArguments validation to support null toolCallArguments within ToolCallingObservationContext.
Fixes gh-3234
Signed-off-by: Thomas Vitale <ThomasVitale@users.noreply.github.com>
The features are disabled by default and users need to explicitly
enable them. Probably it makes more sense to log on INFO level so that
users don't need to change the log level if they use the default
behavior of Spring Boot.
See gh-3003
See gh-3127
Improve separation of concerns by keeping model-related functionality in the model module
while maintaining client-specific functionality in the client module.
- Move MessageAggregator class from spring-ai-client-chat to spring-ai-model module
- Create new ChatClientMessageAggregator in spring-ai-client-chat module to handle client-specific aggregation
- Extract client-specific aggregation logic from MessageAggregator to ChatClientMessageAggregator
- Update references in advisor classes to use the new ChatClientMessageAggregator
Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
- Remove deprecated ChatMemory.get(String conversationId, int lastN) method
- Replace AbstractChatMemoryAdvisor with BaseChatMemoryAdvisor interface in api package
- Make constructors private in all memory advisor implementations to enforce builder usage
- Rename CHAT_MEMORY_CONVERSATION_ID_KEY to CONVERSATION_ID and move to ChatMemory interface
- In VectorStoreChatMemoryAdvisor:
- Rename DEFAULT_CHAT_MEMORY_RESPONSE_SIZE (100) to DEFAULT_TOP_K (20)
- Rename builder method chatMemoryRetrieveSize() to topK()
- Remove systemTextAdvise() builder method
- In PromptChatMemoryAdvisor:
- Remove systemTextAdvise() builder method
- Fix bug where only the last user message was stored from prompts with multiple messages
- Enhance logging in memory advisors to aid in debugging
- Add comprehensive tests for all advisor implementations:
- Unit tests for builder behavior
- Integration tests for the various chat memory advisors
Signed-off-by: Mark Pollack <mark.pollack@broadcom.com>
Introduce instrumentation for tool calling using the Micrometer Observation API.
By default, metadata about tool calling are exported as metrics and traces.
Optionally, the actual tool call input and result can be exported as well by enabling the dedicated feature flag.
Signed-off-by: Thomas Vitale <ThomasVitale@users.noreply.github.com>
This removes the possible large amount of data that was attached
to spans and it logs the data out. This change also removes the direct
dependency on the OTel SDK. approach for content in Spring AI.
Refactors the observability approach for content in Spring AI:
- Replace content observation filters with logging handlers
- Rename configuration properties to better reflect their purpose:
- `include-prompt` → `log-prompt`
- `include-completion` → `log-completion`
- `include-query-response` → `log-query-response`
- Add TracingAwareLoggingObservationHandler for trace-aware logging
- Replace micrometer-tracing-bridge-otel with micrometer-tracing
- Remove event-based tracing in favor of direct logging
- Update documentation to reflect these changes (add breaking-changes section)
- Rename includePrompt to logPrompt in observation properties. Updated in ChatClientBuilderProperties, ChatObservationProperties, and ImageObservationProperties.
Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
- Enhance MethodToolCallback to properly handle generic types by using parameterized types
- Add unit tests for generic type handling (List, Map<String,Integer>, nested generics)
- Add integration tests for both Anthropic and OpenAI clients to verify tool calls with generic argument types
Resolves#2462
Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
- Update the builder to initialize the default chatmemory respository if it isn't set by the builder method
Signed-off-by: Ilayaperumal Gopinathan <ilayaperumal.gopinathan@broadcom.com>
Fixes: #2995
Replaces direct parseInt/parseLong with BigDecimal-based parsing to handle
scientific notation safely and accurately.
Signed-off-by: BeomSeogKim <kbs4520@daum.net>
Remove circular dependencies:
Move utility classes from various packages to dedicated support packages:
- Move ToolCallbacks from ai.tool to ai.support
- Move UsageUtils to UsageCalculator in ai.support
- Move tool.util to tool.support
- Create new ToolDefinitions utility class
Support packages for the classes in question is more idomatic in spring than util packages.
Signed-off-by: Mark Pollack <mark.pollack@broadcom.com>
- Add error handling to SpringBeanToolCallbackResolver to return null
instead of throwing exceptions when resolving non-existing tools.
This make is consitent with other tool resolver implementations
and centralize the error handling in the tool calling manager.
- Add test to verify that the ToolCallbackResolver correctly
returns null for non-existing tools.
Related to #2667
Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
- Add remaining deepseek modules
- Fix build order to put autoconfig modules after model modules to fix javadoc build
Signed-off-by: GR <gr@fastball.dev>
- Configure OBJECT_MAPPER to accept empty strings as null objects during deserialization.
- Add overloaded jsonToMap(String, ObjectMapper) for custom ObjectMapper usage.
- Add and update tests to verify correct handling of empty strings for both Map and POJO deserialization, including custom ObjectMapper scenarios.
- Clarify documentation and ensure extensibility without global side effects.
Fixes#2222
Signed-off-by: Mark Pollack <mark.pollack@broadcom.com>
* Update remaining Advisors and related classes to use the new APIs.
* In AbstractChatMemoryAdvisor, the “doNextWithProtectFromBlockingBefore()” protected method has been changed from accepting AdvisedRequest to ChatClientRequest. It’s a breaking change since the alternative was not part of M8.
* MessageAggregator has a new method to aggregate messages from ChatClientRequest. The previous method aggregating messages from AdvisedRequest has been removed. Warning since it wasn’t marked as deprecated in M8.
* In SimpleLoggerAdvisor, the “requestToString” input argument needs to be updated to use ChatClientRequest. It’s a breaking change since the alternative was not part of M8. Same thing about the constructor.
* The “getTemplateRenderer” method has been removed from BaseAdvisorChain. Each Advisor is encouraged to accept a PromptTemplate to achieve self-contained prompt augmentation operations.
* Remove deprecations in ChatClient and Advisors, and update tests accordingly.
* When building a Prompt from the ChatClient input, the SystemMessage passed via systemText() is placed first in the message list. Before, it was put last, resulting in errors with several model providers.
Relates to gh-2655
Signed-off-by: Thomas Vitale <ThomasVitale@users.noreply.github.com>
* Remove deprecated APIs for JdbcChatMemory.
* Improve documentation about chat memory vs. chat history.
* Fix mismatch between docs vs code for max messages in MessageWindowChatMemory.
Signed-off-by: Thomas Vitale <ThomasVitale@users.noreply.github.com>
- Remove deprecated constructor method Media(MimeType mimeType, URL url) from Media
- Remove deprecated builder method data(URL url) from Media builder
- Update references to use the builder and the data(URI) methods
Signed-off-by: Ilayaperumal Gopinathan <ilayaperumal.gopinathan@broadcom.com>
- Remove the deprecated constructors from PromptTemplate and replace the references using the builder methods
Signed-off-by: Ilayaperumal Gopinathan <ilayaperumal.gopinathan@broadcom.com>
Remove deprecated DocumentCompressor/Ranker/Selector
- These are replaced by the org.springframework.ai.rag.postretrieval.document.DocumentPostProcessor
Remove deprecated Chatclient/DefaultChatClient methods
In ChatClient:
- Remove defaultTools and tools as these are replaced by defaultToolCallbacks and defaultToolNames respectively.
In DefaultChatClient:
- Remove tools method implementation
- Remove unused DefaultCallPromptResponseSpec and DefaultStreamPromptResponseSpec
Remove deprecated addMessage from Prompt
Remove deprecated isInternalToolExecutionEnabled() from ToolCallingChatOptions
- This is replaced by getInternalToolExecutionEnabled()
Signed-off-by: Ilayaperumal Gopinathan <ilayaperumal.gopinathan@broadcom.com>
- Improve the jsonToStruct method in VertexAiGeminiChatModel to handle JSON arrays
in addition to JSON objects. When a JSON array is detected, it's now properly
converted to a Protobuf Struct with an items field containing the array elements.
- Added test
Resolves#2647 , #2849
Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
This ensures that validation errors are caught early during object construction
rather than later when methods are called, providing better error feedback.
- Add validation for tool-annotated methods during construction
- Validate duplicate tool names in constructor instead of only at getToolCallbacks() time
- Add comprehensive test suite for MethodToolCallbackProvider
Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
- Move evaluation core classes (Request, Response, Evaluator) to spring-ai-commons.
- Move chat-specific evaluators (FactChecking, Relevancy) to spring-ai-client-chat#evaluation package.
- Move OutputConverter implementations and related classes to spring-ai-model#converter package.
- Move MetadataEnricher transformer classes to spring-ai-model#transformer package.
- Move PromptAssert utility to spring-ai-rag#util package.
- Update relevant pom.xml files and adjust imports in affected classes.
- Document class movements in upgrade-notes.adoc for M8 release.
This refactoring improves module organization and separation of concerns.
Signed-off-by: Mark Pollack <mark.pollack@broadcom.com>
This reverts commit 4eeeb83d3f.
Revert "Make ImageOptions non-null when constructing ImagePrompt"
This reverts commit 0c0787b849.
Need to review more the impact of making these options not null.
Signed-off-by: Ilayaperumal Gopinathan <ilayaperumal.gopinathan@broadcom.com>
- Extend the ChatClient with a new templateRenderer() method to pass a custom TemplateRenderer object used to render user and system templates.
- Evolve the QuestionAnswerAdvisor to accept a PromptTemplate for customising the RAG prompt and templating logic while maintaining backward compatibility.
- Introduce integration tests for the QuestionAnswerAdvisor.
- Document the TemplateRenderer API and how to use it to build PromptTemplate with custom templating logic.
- Document how to customise the templating logic used internally by the ChatClient via the TemplateRendererAPI.
Add validation tests and improve PromptTemplate resource handling
Enhance robustness and reliability of the PromptTemplate class with better
resource handling and comprehensive input validation:
- Add dedicated validation tests for builder methods with null/invalid inputs
- Improve renderResource method to gracefully handle edge cases:
- Null resources return empty string
- ByteArrayResource handling with proper charset (UTF-8)
- Empty resources check with proper existence test
- Better error handling with logging instead of exception propagation
- Add input validation assertions to all Builder methods
- Fix typo in deprecated annotation comment ("fahvor" → "favor")
Update documentation to clarify template rendering in different contexts:
- Add clear notes about TemplateRenderer usage in ChatClient vs Advisors
- Document how advisor template customization differs from ChatClient template rendering
- Add comprehensive API upgrade notes for template-related deprecations
- Include detailed migration examples for PromptTemplate and QuestionAnswerAdvisor
Fixes gh-355, gh-1687, gh-2448, gh-1849, gh-1428
Signed-off-by: Thomas Vitale <ThomasVitale@users.noreply.github.com>
fix: correct name typo from 'AsynClients' to 'AsyncClients'
fix: correct name typo from 'Autoconfiguration' to 'AutoConfiguration', 'optoins' to 'options'
fix: correct name typo from 'Differnt' to 'Different'
fix: correct name typo from 'Compatability' to 'Compatibility'
fix: correct name typo from 'Evalutaor' to 'Evaluator'
fix: correct name typo from 'Empyt' to 'Empty'
fix: correct name typo from 'Chroma Vecor Store' to 'Chroma Vector Store'
fix: correct name typo from 'Specificaiton' to 'Specification'
fix: correct name typo from 'applicaiton' to 'application'
fix: correct name typo from 'apropriate' to 'appropriate'
fix: correct name typo from 'asigned' to 'assigned'
fix: correct name typo from 'capabilitity' to 'capability'
fix: correct name typo from 'configuraiton' to 'configuration'
fix: correct name typo from 'conntection' to 'connection'
fix: correct name typo from 'curent' to 'current'
fix: correct name typo from 'customised' to 'customized'
Signed-off-by: Changho Kim <dukso4885@gmail.com>
Introduce defining Media objects from a URI, deprecating the previous URL support.
Fixes gh-1147
Signed-off-by: Thomas Vitale <ThomasVitale@users.noreply.github.com>
* ChatClient observations now include the full prompt content instead of just the userText and systemText. Furthermore, they include consistent telemetry for the tools passed via the ChatClient and a first-class conversation ID when using memory advisors. Incomplete or unsafe attributes have been deprecated.
* Adopted the new robust Advisor APIs for BaseAdvisor and RetrievalAugmentationAdvisor.
* Improved the prompt augmentation facilities in ChatClientRequest and Prompt for performance and immutability.
* Fixed integration test racing condition.
* Updated the documentation for ChatClient and Observability accordingly.
* Documented changes in upgrade notes.
* Introduced `prompt.augmentUserMessage(String text)` to directly replace the user message content.
* Added `prompt.augmentUserMessage(Function<UserMessage, UserMessage> augmenter)` for more granular updates using the `userMessage.mutate()` pattern, allowing modification of text, media, and metadata.
Relates to gh-2655
Signed-off-by: Thomas Vitale <ThomasVitale@users.noreply.github.com>
- The commit removes deprecated methods and parameters, including
- requestOptions in image observation context and proxyToolCalls in Vertex AI
- Gemini options. Updates code to use ImagePrompt.getOptions() instead of
- the separate parameter for more consistent API design.
- Remove the deprecated FunctionCallback related classes, references
- Replace them with the corresponding ToolCallback usage
Signed-off-by: Ilayaperumal Gopinathan <ilayaperumal.gopinathan@broadcom.com>
Fixes: #2518
Issue: https://github.com/spring-projects/spring-ai/issues/2518
This commit removes the deprecated requestOptions field from ChatModelObservationContext
and EmbeddingModelObservationContext classes. Instead of passing options separately,
the code now retrieves them directly from the request objects (prompt.getOptions() or
embeddingRequest.getOptions()).
Key changes:
- Removed requestOptions parameter from observation context builders
- Updated all model implementations to stop passing options separately
- Fixed EmbeddingRequest handling in several model implementations
- Added buildEmbeddingRequest method in models to properly merge options
This change simplifies the API and removes duplication, as options are already
available in the request objects themselves.
Signed-off-by: Soby Chacko <soby.chacko@broadcom.com>
- Remove @Nullable on ChatOptions
- By default, pass the default ChatOptions from the DefaultChatOptionsBuilder
Signed-off-by: Ilayaperumal Gopinathan <ilayaperumal.gopinathan@broadcom.com>
* ChatMemory will become a generic interface to implement different memory management strategies. It’s been moved from the “”spring-ai-client-chat” package to “spring-ai-model” package while retaining the same package, so it’s transparent to users.
* A MessageWindowChatMemory has been introduced to provide support for a chat memory that keeps at most N messages in the memory.
* A ChatMemoryRepository interface has been introduced to support different storage strategies for the chat memory. It’s meant to be used as part of a ChatMemory implementation. This is different than before, where the storage-specific implementation was directly tied to the ChatMemory. This design is familiar to Spring users since it’s used already in the ecosystem. The goal was to use a programming model similar to Spring Session and Spring Data.
* The JdbcChatMemory has been supersed by JdbcChatMemoryRepository.
* A ChatMemory bean is auto-configured for you whenever using one of the Spring AI Model starters. By default, it uses the MessageWindowChatMemory implementation and stores the conversation history in memory. If a different repository is already configured (e.g., Cassandra, JDBC, or Neo4j), Spring AI will use that instead.
* First-class documentation has been introduced to describe the ChatMemory API and related features.
* All the changes introduced in this PR are backward-compatible.
Signed-off-by: Thomas Vitale <ThomasVitale@users.noreply.github.com>