Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

[Bug]: Testing agent fails on numeric array parameters from the LLM (ClassCastException: Double cannot be cast to String)

未关闭 适合新手
#62 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
78/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
android, kotlin
领域
backend

调研方向

从 agent/app/src/main/java/com/example/appfunctions/agent/domain/appfunction/ConvertInputToAppFunctionDataUseCase.kt 开始,尤其关注 setArrayValue 和 setStringList,并将它们的转换与 setParameterValue 中的标量分支进行比较。使用数值 JSON 数组值(如 [0.0, 1.0])复现问题;当来自 LLM 的数组数值项能够转换且不发生 ClassCastException,并到达应用函数时,即表示完成。

由索引模型根据 Issue 内容生成。

描述

Description

When the LLM calls a function whose parameters contain a numeric array (here a DoubleArray inside an @AppFunctionSerializable), the Testing Agent fails before the call reaches the app:

Failed to convert arguments for com.example.app.DesignAppFunctionService#setLayerProperties
java.lang.ClassCastException: java.lang.Double cannot be cast to java.lang.String
Cause

ConvertInputToAppFunctionDataUseCase.setArrayValue assumes every numeric array item is a String:

// agent/app/src/main/java/com/example/appfunctions/agent/domain/appfunction/ConvertInputToAppFunctionDataUseCase.kt
val intArray = values.map { (it as String).toInt() }.toIntArray()          // line 158
val longArray = values.map { (it as String).toLong() }.toLongArray()       // line 162
val doubleArray = values.map { (it as String).toDouble() }.toDoubleArray() // line 170
val floatArray = values.map { (it as String).toFloat() }.toFloatArray()    // line 174

That holds for values typed into the Debug screen, but the Gemini provider passes real JSON numbers. The scalar branches in setParameterValue already accept both (is Number / is String); the array branches don't.

Steps to reproduce
  1. Expose a function taking a serializable with a numeric array, e.g.
    @AppFunctionSerializable(isDescribedByKDoc = true)
    class GradientSpec(val colors: List<String>, val stops: DoubleArray? = null)
    
  2. In Agent Demo, ask for something that makes the model fill the array (e.g. "a gradient from red to gold").
  3. The model sends "stops": [0.0, 1.0] and the conversion throws.
Suggested fix

Accept both forms, as the scalar branches do:

private fun Any.asDouble(): Double = when (this) {
    is Number -> toDouble()
    else -> toString().toDouble()
}
// ...
val doubleArray = values.map { it.asDouble() }.toDoubleArray()

(and the same for Int, Long and Float). setStringList (line 155) also casts with it as String; it.toString() would be safer there.

Environment
  • Testing Agent at a3a2a89 (main, Oct 23, 2026), standard flavor, debug
  • androidx.appfunctions 1.0.0-beta01 (both the agent and the app)
  • Emulator, Android 17 (API 37), model gemini-3.5-flash

Related: #50 (number conversion in cmd app_function, scalar parameters).

主要语言
Kotlin
星标
210
派生
45
平均合并
12 小时 24 分钟
30 天内合并 PR
3

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

android/appfunctions 的其他 Issue

查看 android/appfunctions 的全部 Issue

相似的 Issue

更多 Kotlin Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。