agentscope-ai / agentscope-ai/agentscope-java

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

Ouverte
#3,050 2 commentaires 0 réactions 0 personnes assignées Voir sur GitHub
area/core/model bug
Langage dominant
Java
Étoiles
5.6k
Forks
1.3k
Merge moyen
4 j 12 h
PR mergées (30 j)
77

Description

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

Guide de contribution

Ouvrir le guide de contribution

Évaluation

Cette issue n'a pas encore été évaluée.

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.