agentscope-ai / agentscope-ai/agentscope-java
[Bug]: Gemini tool conversion drops function declarations for nullable JSON Schema types
- 主要語言
- Java
- 星號
- 5.6k
- 分支
- 1.3k
- 平均合併
- 4 天 12 小時
- 30 天內合併 PR
- 77
描述
**Describe the bug**
When a Gemini tool parameter uses a nullable JSON Schema such as
`{"type": ["string", "null"]}`, the tool declaration can be dropped during
schema conversion.
If the same tool is forced with `ToolChoice.Specific`, Gemini rejects the
request because the forced tool name is not present in the submitted function
declarations.
**To Reproduce**
1. Define a tool parameter with the following schema:
```json
{
"type": "object",
"properties": {
"value": {
"type": ["string", "null"]
}
}
}
```
2. Use `ToolChoice.Specific("nullable_echo")`.
3. Send the request through `GeminiChatModel`.
4. Observe the Gemini API response.
**Expected behavior**
The nullable parameter should be converted successfully, and the forced tool
should remain present in the Gemini function declarations.
**Error messages**
```text
`allowed_function_names` should be a subset of the provided
`function_declarations` names. Found invalid function names: nullable_echo
```
**Environment**
- AgentScope-Java Version: 2.0.3-SNAPSHOT
- Java Version: 21
- OS: macOS
**Additional context**
The baseline implementation assumed that JSON Schema `type` was always a
string. A nullable schema uses an array, which caused conversion to fail and
the complete function declaration to be skipped.
## Actual reproduction evidence
This was reproduced with the real Gemini API path using
`GeminiNullableToolSchemaE2ETest`.
The test sends a tool named `nullable_echo` with the following parameter
schema:
```json
{
"type": "object",
"properties": {
"value": {
"type": ["string", "null"]
}
}
}
```
The request also uses:
```java
ToolChoice.Specific("nullable_echo")
```
Before the fix, the test produced:
```text
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0
Gemini API call failed: 400
allowed_function_names ... invalid function names: nullable_echo
```
The failure occurs in the following sequence:
1. `GeminiToolsHelper.convertParametersToSchema` assumes that `type` is a
string.
2. The nullable schema provides `type` as a list.
3. The conversion raises a `ClassCastException`.
4. The surrounding tool conversion catches the exception and skips the
complete function declaration.
5. The forced tool configuration still contains `nullable_echo`.
6. Gemini receives a forced tool name without a matching function declaration
and returns HTTP 400.
This is not a mocked or local transport failure. It is a real API validation
error caused by the mismatch between the forced tool configuration and the
submitted function declarations.
The fix is implemented in PR #3051.
貢獻指南
評估
這個 Issue 還沒有評估資料。