[Bug]: Testing agent fails on numeric array parameters from the LLM (ClassCastException: Double cannot be cast to String)
还没有人认领这个 Issue。
评估
调研方向
从 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
- 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) - In Agent Demo, ask for something that makes the model fill the array (e.g. "a gradient from red to gold").
- 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),
standardflavor, 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
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
android/appfunctions 的其他 Issue
-
documentation
难度 1/5 1 小时以内 新手友好度 90/100
android/appfunctions#66 ·
-
难度 4/5 1-2 天 新手友好度 55/100
android/appfunctions#64 ·
-
[FR]: Testing agent should handle AppFunctionUriGrant results and pass returned images to the model未关闭
难度 4/5 3-5 天 新手友好度 45/100
android/appfunctions#63 ·
-
Clarify production invocation, Android Auto support, and Android 16 fallback in AppFunctions docs未关闭
难度 4/5 3-5 天 新手友好度 52/100
android/appfunctions#51 ·
-
难度 4/5 3-5 天 新手友好度 48/100
android/appfunctions#50 · 1 条评论 ·
查看 android/appfunctions 的全部 Issue
相似的 Issue
-
OkHttp versions 5.4.0+ no longer include baseline-prof.txt可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭bug
难度 1/5 1 小时以内 新手友好度 83/100
lysine-dev/okhttp#9828 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 77/100
ReadYouApp/ReadYou#1347 ·
-
难度 2/5 1-3 小时 新手友好度 62/100
yschimke/compose-preview-contracts#210 ·
维护者通常 1 天内回复
-
📦 expo-device Android contributor: external needs review sdk-58 severity: low
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复
-
afk-ok area:data-quality importer size:S
难度 2/5 1-3 小时 新手友好度 76/100
enorm-labs/event-junkie#4221 ·
维护者通常 1 天内回复