feat: extend AgentOptions with fork / cleanup (Phase 2a) #145

Closed
opened 2026-06-07 04:57:26 +00:00 by xiaoju · 0 comments
Owner

动机

step ask 做基础设施:agent 需要支持 session fork(复制 session 到新的独立副本)。

#142 拆出

这是 #142 Phase 2 的基础设施部分。依赖 Phase 1 (#142-P1) 先完成。

接口扩展

// util-agent/src/types.ts
type AgentForkFn = (sessionId: string, store: AgentContext["store"]) => Promise<string>;
type AgentCleanupFn = () => Promise<void>;

type AgentOptions = {
  name: string;
  run: AgentRunFn;
  continue: AgentContinueFn;
  fork: AgentForkFn | null;      // 新增
  cleanup: AgentCleanupFn | null; // 新增
};

Session cache 扩展

支持 stepHash:ask 格式的 cache key(与现有 threadId:role 共存)。

Adapter 实现

每个 adapter 补 fork: null, cleanup: null(占位,后续按需实现):

  • agent-hermes
  • agent-claude-code
  • agent-builtin
  • agent-mock

测试要点

  1. AgentOptions 类型兼容(有/无 fork 都能编译)
  2. Session cache stepHash:ask key 读写
  3. exec cache 和 ask cache 互不干扰
  4. 各 adapter fork: null 不影响现有功能

小橘 🍊(NEKO Team)

## 动机 为 `step ask` 做基础设施:agent 需要支持 session fork(复制 session 到新的独立副本)。 ## 从 #142 拆出 这是 #142 Phase 2 的基础设施部分。依赖 Phase 1 (#142-P1) 先完成。 ## 接口扩展 ```typescript // util-agent/src/types.ts type AgentForkFn = (sessionId: string, store: AgentContext["store"]) => Promise<string>; type AgentCleanupFn = () => Promise<void>; type AgentOptions = { name: string; run: AgentRunFn; continue: AgentContinueFn; fork: AgentForkFn | null; // 新增 cleanup: AgentCleanupFn | null; // 新增 }; ``` ## Session cache 扩展 支持 `stepHash:ask` 格式的 cache key(与现有 `threadId:role` 共存)。 ## Adapter 实现 每个 adapter 补 `fork: null, cleanup: null`(占位,后续按需实现): - `agent-hermes` - `agent-claude-code` - `agent-builtin` - `agent-mock` ## 测试要点 1. `AgentOptions` 类型兼容(有/无 fork 都能编译) 2. Session cache `stepHash:ask` key 读写 3. exec cache 和 ask cache 互不干扰 4. 各 adapter `fork: null` 不影响现有功能 小橘 🍊(NEKO Team)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: shazhou/united-workforce#145