agentscope-ai / agentscope-ai/agentscope-java

[Bug]: Gemini tool conversion drops function declarations for nullable JSON Schema types

Đang mở
#3,050 2 bình luận 0 reaction 0 người được giao Xem trên GitHub
area/core/model bug
Ngôn ngữ chính
Java
Star
5.6k
Fork
1.3k
Merge trung bình
4 ngày 12 giờ
Pull request đã merge (30 ngày)
77

Mô tả

**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.

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.