-
Notifications
You must be signed in to change notification settings - Fork 249
fix(ollama): handle no-parameter tool calls with empty arguments #572
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
254c374
c15b356
a54ed1b
e08ab15
acf7d42
8f978bc
e8d9ea2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -24,6 +24,7 @@ | |||||||||
| import io.agentscope.core.message.ToolUseBlock; | ||||||||||
| import io.agentscope.core.model.ChatResponse; | ||||||||||
| import io.agentscope.core.model.ChatUsage; | ||||||||||
| import io.agentscope.core.util.JsonUtils; | ||||||||||
| import java.util.ArrayList; | ||||||||||
| import java.util.HashMap; | ||||||||||
| import java.util.List; | ||||||||||
|
|
@@ -66,9 +67,16 @@ public ChatResponse parseResponse(OllamaResponse response) { | |||||||||
| // AgentScope requirement. | ||||||||||
| String callId = UUID.randomUUID().toString(); | ||||||||||
|
|
||||||||||
| // Convert input to JSON string for validation in ToolExecutor | ||||||||||
| // For tools with no parameters, input will be an empty map {} | ||||||||||
| String argumentsJson = "{}"; | ||||||||||
| if (input != null && !input.isEmpty()) { | ||||||||||
| argumentsJson = JsonUtils.getJsonCodec().toJson(input); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| contentBlocks.add( | ||||||||||
| new ToolUseBlock( | ||||||||||
| callId, fn.getName(), input, null // raw content | ||||||||||
| callId, fn.getName(), input, argumentsJson, null // metadata | ||||||||||
| )); | ||||||||||
|
||||||||||
| callId, fn.getName(), input, argumentsJson, null // metadata | |
| )); | |
| callId, fn.getName(), input, argumentsJson, // raw content | |
| null)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The fix correctly addresses the issue, but there's an inconsistency with how other formatters handle this case. OpenAI's approach (line 222-234 in OpenAIResponseParser) handles null arguments by setting them to empty string "", then parsing to create an empty map. Anthropic (line 72-75 in AnthropicResponseParser) uses an empty string "" when _input is null. For consistency across formatters and to handle potential null inputs more robustly, consider adding a null check:
if (input == null || input.isEmpty()) { argumentsJson = "{}"; }instead of relying on the assumption that input is never null.