Hacktoberfest 2026:維護者為十月標記出來的 issue,仍然開放、適合新手。 瀏覽 Hacktoberfest issue

[spring-ai] ToolConverter silently drops enum and items from tool parameter schemas

已關閉 適合新手
#1,609 2 則留言 0 個 reaction 已指派 1 人 在 GitHub 檢視

維護者通常 1 天內回覆

@hirematha 已經在處理了。

開始於 2026年10月5日。

  • #1617 來自 @caps-xia —— 未關閉

評估

難度
2/5
預估耗時
1-3 小時
新手友好度
76/100
Issue 類型
缺陷
描述清晰度
描述清楚
活躍度
活躍
技術堆疊
java, spring
領域
ai

研究方向

丟棄發生在 ToolConverter#convertSchemaToSpringAi 中,當每個 ToolDefinition input schema 被建構時,從 convertToSpringAiTools 到達;首先閱讀該方法以及它在其間映射的 genai Schema 和 Spring AI schema 類型。用 issue 的最小範例(一個 enum 字串屬性加上一個帶 items 的陣列屬性)重現,然後按屬性映射 enum_ 和 items,遞迴進入巢狀屬性。完成意味著發出的 inputSchema JSON 包含這些參數的 enum 和 items,同時現有的 ToolConverter 測試仍然通過。

由索引模型根據 Issue 內容生成。

描述

needs review
Describe the Bug

ToolConverter#convertSchemaToSpringAi (used by convertToSpringAiTools) maps only
type, properties, description and required when converting a genai Schema
to a Spring AI ToolDefinition input schema. enum and items are silently
dropped.

Impact: any ADK tool whose parameters use enum-constrained strings or typed arrays —
including the mainstream path of annotated FunctionTool methods (enum Java fields,
List<String> parameters) — ends up with a degraded schema sent to the model:
enum parameters become free-form strings (models then send invalid values), and array
parameters lose their element type.

Steps to Reproduce
  1. Define a BaseTool whose declaration() returns a FunctionDeclaration with
    parameters containing an enum property and an array-with-items property.
  2. Convert it via new ToolConverter().convertToSpringAiTools(...).
  3. Inspect getToolDefinition().inputSchema() — no enum, no items.
Expected Behavior

enum, items (and ideally format, nullable, minItems/maxItems) survive the
conversion, so the model receives the same parameter constraints the ADK tool declared.

Observed Behavior

Identical output on 1.9.0 and 1.11.0 (latest):

declared: color = string + enum ["red","green"],  tags = array of string (items)
converted inputSchema:
{"description":"参数","type":"object","properties":{"color":{"description":"颜色","type":"string"},"tags":{"description":"标签","type":"array"}},"required":["color"]}
                                   ^ no "enum"                      ^ no "items"
Environment Details
  • ADK Library Version: verified on 1.9.0 and 1.11.0 with identical output;
    on current main, convertSchemaToSpringAi still only emits type/properties
  • OS: macOS (logic bug, OS-independent)
  • TS Version: N/A (Java)
Model Information

Model-independent — the loss happens in tool-definition conversion before any model
call. Observed with GLM via an OpenAI-compatible gateway.

Regression

N/A.

Additional Context

We maintain a patched bridge for this reason (among others): we bypass the wrapped
conversion and restore the original callbacks per tool name so the raw schema reaches
the model. A minimal fix is to map enum_ and items in convertSchemaToSpringAi;
serializing the genai Schema to JSON directly would also work and would future-proof
against further field drift.

Minimal Reproduction Code
Schema color = Schema.builder().type("string")
        .description("颜色").enum_(List.of("red", "green")).build();
Schema tags = Schema.builder().type("array")
        .description("标签").items(Schema.builder().type("string").build()).build();
Schema params = Schema.builder().type("object")
        .properties(Map.of("color", color, "tags", tags))
        .required(List.of("color"))
        .build();

BaseTool tool = new BaseTool("probeTool", "probe") {
    @Override public Optional<FunctionDeclaration> declaration() {
        return Optional.of(FunctionDeclaration.builder()
                .name("probeTool").description("probe").parameters(params).build());
    }
    @Override public Single<Map<String, Object>> runAsync(Map<String, Object> args, ToolContext ctx) {
        return Single.just(Map.of());
    }
};

String schema = new ToolConverter()
        .convertToSpringAiTools(Map.of("probeTool", tool))
        .get(0).getToolDefinition().inputSchema();
// schema contains no "enum" and no "items"
How often has this issue occurred?

Always (100%) — every enum/array tool parameter.

主要語言
Java
星號
1.8k
分支
440
平均合併
4 天 17 小時
30 天內合併 PR
87

環境準備

在 Codespaces 中開啟

在瀏覽器裡用你自己的 GitHub 帳號啟動這個專案的開發容器。

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

google/adk-java 的其他 Issue

查看 google/adk-java 的全部 Issue

相似的 Issue

更多 Java Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。