Feature #896: Support custom-type tool parameter #941
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Context
Langchain4j currently only supports Java built-in types as tool parameters.
While it's advisable to maintain a flat and simple tool interface,
there are situations where using custom-type tool parameters is preferred.
Change
This PR delegates the generation of
ToolSpecification
and the deserialization ofToolExecutionRequest
's arguments toToolJsonSchemas
usingJsonSchemaService
.JsonSchemaService
is a separate pluggable dependency via SPI. This PR created two implementations forJsonSchemaService
:DefaultJsonSchemaService
(in modulelangchain4j-core
) is consistent with the old behavior of Langchain4j. It supports only Java Built-in types as tool parameters, and sanitizes the tool execution arguments before deserializationVictoolsJsonSchemaService
(in a separated modellangchain4j-jsonschema-service-victools
) adopts victools/jsonschema-generator for JSON Schema generation and arguments deserialization.Besides SPI, the user can override the default by customizing an implementation of
JsonSchemaService
viaAiServices#jsonSchemaService
The original
ToolSpecification
is kept for now to stay compatible with the current codebase. It might be replaced byToolJsonSchema
in the future if needed.Checklist
Before submitting this PR, please check the following points: