spring-projects / spring-projects/spring-ai
Support empty ToolContext, or null values
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 9.5k
- Forks
- 2.9k
- Avg merge
- 1d 7h
- Merged PRs (30d)
- 6
Description
Current Behavior
As of Spring AI 2.0.0, ToolContext cannot contain null values or be empty.
A null tool context map value fails with an IllegalArgumentException in ChatClientRequestSpec.toolContext.toolContext(...).
Empty tool context fails during tool execution with an IllegalArgumentException in MethodToolCallback.validateToolContextSupport(...).
So when I have to handle optional data (an "orderNumber" in the next example), I have to add some fake data ("bar" under the "foo" key) to prevent an exception :
// Build the context passed to the tools
Map<String, Object> toolContext = new HashMap<>();
if (orderNumber != null) {
toolContext.put("orderNumber", orderNumber);
} else {
toolContext.put("foo", "bar"); // Workaround (tool call will fail if the tool context is empty)
}
// Execute the request
return chatClient.prompt(request).toolContext(toolContext).call().content();
Suggested changes
What are the reasons of these limitations ?
To simplify application code, could you support empty tool context (or else, as a second choice, null values) ?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with ChatClientRequestSpec.toolContext.toolContext(...) and MethodToolCallback.validateToolContextSupport(...), the two validation points identified in the report. Reproduce the null-value and empty-context cases, then inspect related tests before deciding the supported behavior. Done means optional tool context no longer requires fake data and the behavior is covered by tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, spring
- Domain
- api, backend
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 50/100