- Add TOOL_CALL_HISTORY constant to store tool call history
- Extend ToolContext with getToolConversationHistory method
- Include tool call history in tool context during function execution
- Add test coverage for tool call history verification
Resolves#1202
Introduces a simplified, type-safe builder pattern for function callbacks to
improve developer experience and code reliability. The new hierarchical API
separates concerns between direct function invocation and method reflection,
while providing better compile-time safety.
This change deprecates the older FunctionCallbackWrapper in favor of a more
intuitive FunctionCallback.Builder that better handles generic types via
ParameterizedTypeReference. It also adds automatic function description
generation as a fallback when none is provided, though explicit descriptions
are still recommended.
The update standardizes function callback handling across all AI model
implementations (OpenAI, Ollama, Minimax, etc.) and improves response
handling with configurable converters.
Core API Enhancements:
- New Builder Interface: Replaced FunctionCallbackWrapper.builder() with
FunctionCallback.builder(), introducing a hierarchical approach that improves
customization and type safety.
- Specialized Builders: Introduced FunctionInvokerBuilder for direct Function/BiFunction
implementations and MethodInvokerBuilder for reflection-based invocations.
- Generic Type Support: Added ParameterizedTypeReference for better handling of generic parameters.
- Unified Method Definition: Merged method() and argumentTypes() into a single method() call
for simplicity and type safety.
- Automatic Descriptions: Implemented auto-generation of function descriptions, with warnings
to encourage explicit descriptions.
- Configurable Response Converters: Enhanced response handling with support for custom
converters, reducing unnecessary JSON conversions.
Architecture Improvements:
- Established common Builder interface for shared properties
- Separated function object handling from constructor
- Added method-specific configuration (name, arg types, target)
- Added JSON schema generation support for ResolvableType
- Moved to standardized schema types across AI providers
- Set OPEN_API_SCHEMA as default for Vertex AI Gemini
Builder Pattern Standardization:
- Standardized builder method ordering across implementations
- Moved function() call after description() for consistency
- Improved function callback configuration with unified patterns
- Enhanced error handling and validation in DefaultFunctionCallbackBuilder
Deprecations:
- FunctionCallbackWrapper.Builder replaced by DefaultFunctionCallbackBuilder
- Removed CustomizedTypeReference in favor of ParameterizedTypeReference
- Deprecated older ChatClient API methods for function handling
Testing & Documentation:
- Updated all AI model implementations (OpenAI, Ollama, Minimax, Moonshot, ZhiPuAI)
- Added comprehensive integration tests for static/instance methods
- Added integration tests for auto-generated descriptions
- Updated documentation to reflect new builder pattern usage
- Added Kotlin extension for inputType() support
Co-authored-by: Sébastien Deleuze <sebastien.deleuze@broadcom.com>
This change enables more flexible integration between Spring AI and LLM function
calling capabilities while maintaining type safety and ease of use.
- Add new MethodFunctionCallback class to support method invocation via reflection
- Supports both static and non-static method calls
- Handles multiple parameter types including primitives, objects, collections
- Supports empty parameters and empty response
- Auto-generates JSON schema from method parameters
- Special handling for ToolContext parameters
- Builder pattern for easy configuration
- Add comprehensive unit tests for MethodFunctionCallback
- Add integration tests for MethodFunctionCallback with both Anthropic and OpenAI clients
- Add jackson-module-jsonSchema dependency
- Modify FunctionCallback to check for empty tool context
Testing coverage includes:
- Static method invocation scenarios
- Non-static method calls with various parameter types
- Void return type methods
- Complex parameter types (enums, records, lists)
- Tool context handling
- Error cases and validation
Add MethodFunctionCallback reference docs
- Disable project-wide Checkstyle checks to unblock development
- Add documentation for enabling Checkstyle locally
- Fix remaining checkstyle violations in current codebase
Fixes#1669
- Update Claude 3.5 Sonnet model version from 20240620 to 20241022 across:
- AnthropicApi model definitions
- Integration tests
- Sample events JSON
- Documentation pages
- Upgrade Ollama container to 0.3.14 in tests
- Add llama3.2:1b model to Ollama tests
- Convert Ollama functionCallTest to parameterized test
Chat model observations support several key-value pairs, coming from the Spring AI abstractions.
Currently, whenever a value is not available (either because not configured by the user or not supported by the model provider), a span/metrics is generated anyway with value none.
That causes several issues, including an unneeded increase in time series, challenges in alerting/monitoring (especially for integer/double attributes that suddenly are populated with a string), and incompliance with the OpenTelemetry Semantic Conventions (according to which, attributes should be excluded altogether if there's no value).
This pull request changes the conventions for chat model observation to exclude the generation of span/metrics attributes for optional values which don't have any value.
Signed-off-by: Thomas Vitale <ThomasVitale@users.noreply.github.com>
This commit adds support for tool context in various chat options classes across
different AI model implementations and enhances function calling capabilities.
The tool context allows passing additional contextual information to function callbacks.
- Add toolContext field to chat options classes
- Update builder classes to support setting toolContext
- Enhance FunctionCallback interface to support context-aware function calls
- Update AbstractFunctionCallback to implement BiFunction instead of Function
- Modify FunctionCallbackWrapper to support both Function and BiFunction and
to use the new SchemaType location
- Add support for BiFunction in TypeResolverHelper
- Update ChatClient interface and DefaultChatClient implementation to support
new function calling methods with Function, BiFunction and FunctionCallback arguments
- Refactor AbstractToolCallSupport to pass tool context to function execution
- Update all affected <Model>ChatOptions with tool context support
- Simplify OpenAiChatClientMultipleFunctionCallsIT test
- Add tests for function calling with tool context
- Add new test cases for function callbacks with context in various integration tests
- Modify existing tests to incorporate new context-aware function calling capabilities
- Add docs in in openai function calling
Resolves#864, #1303, #991
Add support for PortableFunctionCallingOptions across AI models
- Modify FunctionCallingOptions interface to extend ChatOptions for better integration
- Refactor option handling in chat models to accommodate both ChatOptions and FunctionCallingOptions
- Implement handling of FunctionCallingOptions in Anthropic, Azure OpenAI,
MistralAI, Ollama, OpenAI, VertexAI Gemini, and other models
- Update existing function calling tests to use new FunctionCallingOptions.
Resolves#624
- Add handling for cases where ChatCompletion has a stop reason but empty generations.
Creates a Generation with empty content and metadata when this occurs.
- Update AnthropicChatModelObservationIT to expect "end_turn" finish reason.
- Update javadoc.
This commit introduces a new proxyToolCalls option for various chat
models in the Spring AI project. When enabled, it allows the client to
handle function calls externally instead of being processed internally
by Spring AI.
The change affects multiple chat model implementations, including:
AnthropicChatModel
AzureOpenAiChatModel
MiniMaxChatModel
MistralAiChatModel
MoonshotChatModel
OllamaChatModel
OpenAiChatModel
VertexAiGeminiChatModel
ZhiPuAiChatModel
The proxyToolCalls option is added to the respective chat options
classes and integrated into the AbstractToolCallSupport class for
consistent handling across different implementations.
The proxyToolCalls option can be set either programmatically via
the <ModelName>ChatOptions.builder().withProxyToolCalls() method
or the spring.ai.<model-name>.chat.options.proxy-tool-calls
application property.
Documentation for the new option is also updated in the relevant
Antora pages.
Added ITs for proxy tool calls
Remove ChatClientPromptRequestSpec and all ChatClient.prompt() overloads can how take advantage of the full fluent API. Docs updated
Resolves#1367
This change updates the type of portable chat options from Float to
Double. Affected options include:
- frequencyPenalty
- presencePenalty
- temperature
- topP
The motivation for this change is to simplify coding. In Java, Float
values require an "f" suffix (e.g., 0.5f), while Double values don't
need any suffix. This makes Double easier to type and reduces
potential errors from forgetting the "f" suffix.
APIs, tests, and documentation have been updated to reflect this
change.
Fixes gh-712
Signed-off-by: Thomas Vitale <ThomasVitale@users.noreply.github.com>
* Surface more configuration APIs to ChatOptions
* Use abstraction in Observations directly instead of dedicated implementation
* Simplify metadata config in observations for defined models
* Improve merging of runtime and default options in OpenAI
* Fix missing option in Mistral AI
Relates to gh-1148
Signed-off-by: Thomas Vitale <ThomasVitale@users.noreply.github.com>
The autoconfiguration adds the FunctionCallbacks directly to the model's ChatOptions,
which results in the FunctionCallback being included in the request each time it is called.
The modification registers the container's FunctionCallback directly to the model's functionCallbackRegister
using the parent AbstractToolCallSupport constsructor.
Replace the handleFunctionCallbackConfigurations by simplified runtimeFunctionCallbackConfigurations.
Co-authored-by Christian Tzolov <ctzolov@vmware.com>
- factor out the common funciton calling logic form AnthropicChatModel to the AbstractToolCallSupport.
- improve the AbstractToolCallSupport isToolCall to handle OpenAi and Anthropic.
- fix an issue with the function calling streaming aggreagation leading to lost usage statistics.
- small code improvements for OpenAiChatModel.
- introduce copy() method to the ChatOptions.
- make sure that the DefaultChatClientRequestSpec takes a copy of the input chat options to prevent multation.
- add a OpenAiChatClientMultipleFunctionCallsIT to reproduce the problem and verify the solution.
Resolves#1064
* Remove inheritance from HashMap
* No more subclasses per model provider
* Builder class for ChatResponse
* Fix the AbstractResponseMetadata#AI_METADATA_STRING parameter order
* ChatResponseMetadata ignore Null values.
- add new spring-ai-vertex-ai-embedding project.
- add VertexAiTextEmbeddingModel and VertexAiMultimodalEmbeddingMode with related options configuration classes.
- add ITs
- add auto-configuraiton and boot starters.
- register to BOM.
- add documentation.
- add multimodal embedding documentation
- extend the Embedding metdata so that it can keep references to the source document's data, Id, mediatype
Resolves#1013
Related to #1009
- add StreamEven API domain model for reliably parsing stream events.
- add StreamHelper#mergeToolUseEvents to aggregate partial tool use jsons into a list of ContentBlocks.
- add StreamHelper#eventToChatCompletionResponse to convert Flux<StreamEvents> into Flux<ChatCompletionResponse>.
- Rename MediaContent -> ContentBlock, RequestMessage -> AnthropicMessage, ChatCompletion -> ChatCompletionResponse.
- Improve tests and docs.