You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

InMemoryRunner类的run()方法实际参数是什么?调用传参报错

问题分析与解决方案

错误原因

报错TypeError: Runner.run() takes 1 positional argument, but 2 were given说明InMemoryRunner.run()方法仅接受self这1个隐式位置参数,你传入的message作为第二个位置参数不符合方法定义要求,而run_debug()的参数结构刚好匹配,所以能正常运行。

解决方法

1. 确认run()方法的正确参数签名

查看google.adk.runners.InMemoryRunner.run()的源码或内部文档,确认它接收的参数名称(比如可能是input、request等关键字参数)。

2. 调整调用方式(示例)

如果run()要求通过关键字参数传入消息,修改调用代码:

async def run_agent(message: str):
    # 替换input为实际要求的参数名
    response = await runner.run(input=message)
    return response

如果run()需要接收结构化的请求对象,可包装消息后传递:

async def run_agent(message: str):
    response = await runner.run(request={"content": message})
    return response

3. 参考run_debug()的调用逻辑

对比run_debug()的参数传递方式(比如你调用run_debug(message)能成功,说明它支持位置参数),照此调整run()的参数传递,确保参数名或结构匹配方法定义。

内容的提问来源于stack exchange,提问作者Devanand J

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.11 14:02:36