AS AgentScopeAPI 手册 / API Reference

MemoryBackgroundTasks

public final class MemoryBackgroundTasks
源码Source io/agentscope/harness/agent/memory/MemoryBackgroundTasks.java:33–88

记忆 Background 任务,在多次调用之间保存和恢复会话与记忆数据。位于 io.agentscope.harness.agent.memory 包。核心成员包括 begin、end、awaitQuiescence。

Tracks in-flight fire-and-forget memory background tasks (flush, maintenance) so HarnessAgent.close() can wait for them to quiesce before releasing resources.

The middleware instances that dispatch these tasks are created per agent call, so they cannot be reached from the agent's close() method. Like io.agentscope.harness.agent.memory.session.SessionTree#awaitMirrorQuiescence, the in-flight count is process-wide: close() blocks until every background task started before the call has finished, so async workspace writes do not race with resource cleanup (e.g. temp workspace deletion in tests).

方法摘要Method Summary

方法Method说明Description
public static void begin()
static
执行 `begin` 方法。
Marks the start of a fire-and-forget background task.
public static void end()
static
执行结束相关操作。
Marks the end of a fire-and-forget background task (must pair with `#begin()`).
public static boolean awaitQuiescence(long timeout, TimeUnit unit)
static
执行 `awaitQuiescence` 方法。
Blocks until all background tasks started before this call have finished, or the timeout elapses.

方法详情Method Detail

begin

public static void begin()
static

执行 begin 方法。

Marks the start of a fire-and-forget background task.

源码Source io/agentscope/harness/agent/memory/MemoryBackgroundTasks.java:43–47

end

public static void end()
static

执行结束相关操作。

Marks the end of a fire-and-forget background task (must pair with #begin()).

源码Source io/agentscope/harness/agent/memory/MemoryBackgroundTasks.java:50–59

awaitQuiescence

public static boolean awaitQuiescence(long timeout, TimeUnit unit)
static

执行 awaitQuiescence 方法。

Blocks until all background tasks started before this call have finished, or the timeout elapses.

参数Parameters
名称Name类型Type说明Description
timeoutlong超时时间(类型 `long`)。maximum time to wait
unitTimeUnitunit(类型 `TimeUnit`)。time unit of `timeout`
返回Returns boolean
返回布尔值,表示判断结果。`true` if the tasks quiesced within the timeout
源码Source io/agentscope/harness/agent/memory/MemoryBackgroundTasks.java:69–87
基于官方固定版本源码静态生成Generated from pinned official sources · Python 2.0.11 · Java 2.0.4
签名与文档为静态抽取;如有疑问请以源码为准。Signatures and docs are extracted statically; verify against the source when in doubt.