Repository navigation
Conversation
Chat model observations only exposed the names of the tools offered to the model, through spring.ai.model.request.tool.names, so a trace did not show the descriptions and parameter schemas the model received, nor anything about tools that were offered but never invoked. Add a ChatModelToolDefinitionsObservationFilter that records the definitions of the tools in the request as the gen_ai.tool.definitions attribute, a JSON array following the OpenTelemetry tool definitions schema (type, name, description and parameters). A tool whose input schema is not valid JSON is still described, without its parameters. As the definitions can be large, and the OpenTelemetry conventions make the attribute opt-in, the filter is only registered when spring.ai.chat.observations.include-tool-definitions is true. Fixes spring-projects#7260 Signed-off-by: Ajax-1 <85230126+Ajax-1@users.noreply.github.com>
The OpenTelemetry conventions do not recommend populating the optional properties of gen_ai.tool.definitions by default, as they can be large, and let instrumentations provide a way to enable them. Only record the type and name of each tool by default, and add the spring.ai.chat.observations.include-tool-definition-descriptions and spring.ai.chat.observations.include-tool-definition-parameters properties to include the descriptions and parameter schemas. Move the serialization to a ToolDefinitionsSerializer, so that other observations recording the tool definitions can reuse it. See spring-projects#7260 Signed-off-by: Ajax-1 <85230126+Ajax-1@users.noreply.github.com>
Ajax-1
force-pushed
the
feat/tool-definitions-observation-7260
branch
from
November 27, 2026 11:57
db2ab4c to
3637a45
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #7260
Chat model observations only exposed the names of the tools offered to the model (
spring.ai.model.request.tool.names), so a trace did not show the descriptions and parameter schemas the model received, nor anything about tools that were offered but never invoked.Changes
ToolDefinitionsSerializerthat writes tool definitions as a JSON array following the OpenTelemetry tool definitions schema. It is independent of the chat model observation, so it can be reused by other observations that recordgen_ai.tool.definitions.ChatModelToolDefinitionsObservationFilter, following the existingToolCallingContentObservationFilterpattern, which records the request's tool callbacks as thegen_ai.tool.definitionshigh cardinality attribute.REQUEST_TOOL_DEFINITIONSadded toAiObservationAttributesandChatModelObservationDocumentation.HighCardinalityKeyNames.falseby default:
and with both enabled:
A tool whose input schema is not valid JSON is still described, without itsspring.ai.chat.observations.include-tool-definitionsenables the attribute, since the conventions mark it as opt-in.spring.ai.chat.observations.include-tool-definition-descriptionsandspring.ai.chat.observations.include-tool-definition-parametersinclude the descriptions and parameter schemas. The conventions do not recommend populating these optional properties by default, as they can be large, so without them each tool is recorded with itstypeandnameonly:[{"type": "function", "name": "getWeather"}][{"type": "function", "name": "getWeather", "description": "...", "parameters": {"type": "object", ...}}]parameters.Like
spring.ai.model.request.tool.names, it covers the tools passed astoolCallbacksin the request options; provider-native server tools are not included.Scope
#7260 also lists
invoke_agentandfetch_responsespans, where those operations are instrumented. Spring AI does not have them today, so this PR covers the inference (chat {model}) span. Onceinvoke_agentobservations exist (#7343), they can record the attribute with the same serializer.Tests
ToolDefinitionsSerializerTests: types and names only, with descriptions, with parameters, invalid input schema, empty list.ChatModelToolDefinitionsObservationFilterTests: unsupported context, no tools, options without tool calling, default output, full output, idempotency.ChatObservationAutoConfigurationTests: the filter bean by default, enabled and disabled, and the optional properties.