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

ACA-Py中Askar钱包持久化问题:自定义参数被覆盖

解决ACA-Py中Askar钱包持久化参数被覆盖的问题

问题根源

从启动日志可以明确看到:你传入的wallet-name和wallet-key被create_agent_with_args内部的默认逻辑覆盖成了带随机后缀的临时名称(faber_wallet_check30a06fc5),同时缺少Askar持久化必需的存储类型参数,导致钱包仍以内存模式运行。

核心解决方案

要实现Askar钱包持久化,需要同时满足两个条件:

  1. 强制指定Askar的持久化存储类型
  2. 阻止框架自动覆盖自定义的钱包参数

步骤1:添加持久化存储参数

Askar钱包默认使用内存存储,必须显式指定wallet-storage-type为sqlite才能启用持久化。在你的代码中,修改extra参数的构建逻辑,添加存储配置:

# Step 2: Prepare extra args for the agent launcher
extra = {}
if args.wallet_name:
    extra["wallet-name"] = args.wallet_name
if args.wallet_key:
    extra["wallet-key"] = args.wallet_key
if args.seed:
    extra["seed"] = args.seed
if args.wallet_type:
    extra["wallet-type"] = args.wallet_type
# 新增:指定Askar持久化存储类型
extra["wallet-storage-type"] = "sqlite"
# 可选:自定义钱包存储路径(默认是~/.aries_askar/)
# extra["wallet-storage-config"] = '{"path": "/your/custom/wallet/path"}'

步骤2:阻止框架自动覆盖钱包参数

问题出在runners.agent_container中的create_agent_with_args函数,它会自动生成临时钱包名和密钥,覆盖你传入的参数。解决方式有两种:

方式A:修改agent_container.py的自动生成逻辑

找到agent_container.py中自动生成钱包参数的代码段,添加条件判断,仅当用户未指定时才自动生成:

# 原代码(可能存在)
# extra_args["wallet-name"] = f"{ident}{random_suffix}"
# extra_args["wallet-key"] = f"{ident}{random_suffix}"

# 修改后
if not extra_args.get("wallet-name"):
    extra_args["wallet-name"] = f"{ident}{random_suffix}"
if not extra_args.get("wallet-key"):
    extra_args["wallet-key"] = f"{ident}{random_suffix}"

方式B:绕过create_agent_with_args,手动构建启动命令

如果不想修改框架代码,直接手动构建ACA-Py的启动命令,完全控制参数:

# 替换原Step3和Step5的代码
from runners.agent_container import AgentContainer

# 构建完整的ACA-Py启动参数
cmd_args = [
    sys.executable, "-m", "aries_cloudagent", "start",
    "--endpoint", f"http://localhost:{args.port}",
    "--label", "faber_wallet_check",
    "--auto-ping-connection",
    "--auto-respond-messages",
    "--inbound-transport", "http", "0.0.0.0", str(args.port),
    "--outbound-transport", "http",
    "--admin", "0.0.0.0", str(args.port + 1),
    "--admin-insecure-mode",
    "--wallet-type", args.wallet_type,
    "--wallet-name", args.wallet_name,
    "--wallet-key", args.wallet_key,
    "--wallet-storage-type", "sqlite",
    "--seed", args.seed,
    "--preserve-exchange-records",
    "--public-invites",
    "--emit-new-didcomm-prefix",
    # 传入创世交易参数(根据你的框架逻辑获取)
    "--genesis-transactions", *args.genesis_txns
]

# 创建并启动Agent容器
faber_agent = AgentContainer(
    ident="faber_wallet_check",
    cmd=cmd_args,
    start_port=args.port,
    genesis_txns=args.genesis_txns
)
await faber_agent.start()

验证结果

修改后重新执行命令,检查以下两点:

  1. 启动日志中的ACA-Py命令行参数,确认wallet-name、wallet-key、wallet-storage-type为你指定的值
  2. 查看~/.aries_askar/目录,会生成faber_wallet.sqlite文件,说明持久化钱包已创建

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.12 18:44:52