Skip to content

开启长期记忆后,每次对话完成,会同步卡在那里等待,能不能做成异步的 #2821

Open

Description

@luoshu-open

AgentScope-Java is an open-source project. To involve a broader community, we recommend asking your questions in English.

Describe the bug
开启长期记忆后,每次对话完成,会同步卡在那里等待,能不能做成异步的。
对话完成后,有的时候要等两三分钟

版本号:2.0.0 和 最尊重的2.0.1都有。


这个问题是当成正常的功能不修改,还是定义成BUG后面会改呀。

Activity

  1. added
    bug
    on Aug 24, 2026
  2. guslegend0510 commented on Aug 24, 2026

    @guslegend0510
    Contributor

    感谢反馈。

    目前 STATIC_CONTROL 和 BOTH 模式已经支持异步写入长期记忆,可以通过以下配置开启:

    ReActAgent agent = ReActAgent.builder()
        .name("Assistant")
        .model(model)
        .longTermMemory(longTermMemory)
        .longTermMemoryMode(LongTermMemoryMode.BOTH)
        .longTermMemoryAsyncRecord(true)
        .build();

    longTermMemoryAsyncRecord 当前默认值为 false。如果没有显式开启,框架会等待长期记忆的 record() 操作完成后再结束本次调用。当记忆服务或其使用的模型响应较慢时,就可能出现等待两三分钟的情况。
    开启异步写入后,回复流程不会再等待长期记忆保存完成。不过需要注意:该模式属于后台异步写入,如果应用立即退出,尚未完成的记忆写入可能无法保存。

    在这个PR中已经修复了 #1177 @luoshu-open

  3. luoshu-open commented on Aug 24, 2026

    @luoshu-open
    Author

    @guslegend0510 可是我在最新的2.0.1版本,没有看到这个方法

  4. guslegend0510 commented on Aug 24, 2026

    @guslegend0510
    Contributor

    对应源码位置:
    https://github.com/agentscope-ai/agentscope-java/blob/v2.0.1/agentscope-core/src/main/java/io/agentscope/core/ReActAgent.java#L4602-L4605
    麻烦检查一下项目实际解析到的 agentscope-core 版本,可能存在依赖版本冲突。

    同时确认导入的是:
    import io.agentscope.core.ReActAgent;

    正常情况下可以这样配置:
    ReActAgent agent = ReActAgent.builder()
    .name("Assistant")
    .model(model)
    .longTermMemory(longTermMemory)
    .longTermMemoryMode(LongTermMemoryMode.BOTH)
    .longTermMemoryAsyncRecord(true)
    .build();

  5. luoshu-open commented on Aug 25, 2026

    @luoshu-open
    Author

    @guslegend0510

    @deprecated(forRemoval = true, since = "2.0.0")
    public Builder longTermMemoryAsyncRecord(boolean asyncRecord) {
    this.longTermMemoryAsyncRecord = asyncRecord;
    return this;
    }

    为什么这个功能上线就要被移除呀?有Deprecated注解。


    另外我使用的是 HarnessAgent ,这个类是没有的

  6. guslegend0510 commented on Aug 25, 2026

    @guslegend0510
    Contributor

    @luoshu-open 你说得对,抱歉,我之前是按照 ReActAgent 的长期记忆兼容链路排查的,没有注意到你使用的是 HarnessAgent。

    longTermMemoryAsyncRecord(...) 上的 @Deprecated 并不是单独废弃异步功能,而是因为 2.0 将原来的 LongTermMemory + ReActAgent 整套旧接口标记为了待移除,并改用 Harness 的记忆管线。

    我重新检查了 HarnessAgent 在 2.0.1 中的实现,目前确实没有对应的异步配置。

  7. luoshu-open commented on Aug 25, 2026

    @luoshu-open
    Author

    @guslegend0510 后续版本有计划添加 HarnessAgent 的异步配置吗?

  8. guslegend0510 commented on Aug 25, 2026

    @guslegend0510
    Contributor

    @guslegend0510后续版本有计划添加 HarnessAgent 的异步配置吗?

    会的

  9. luoshu-open commented on Aug 25, 2026

    @luoshu-open
    Author

    谢谢,期待新版本

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions