RFC: Generic AgentFn — Schema-Driven Input Specialization #327
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
背景
当前
AgentFn的签名是:这假设了所有 agent 的工作输入都是
string(prompt),但现实中不同 agent 有结构化输入需求:{ cwd, mode, model }string(prompt){ endpoint, payload }从类型论看,函数参数的泛化是函数类型的特化(逆变)。
AgentFn强制I = string丢失了表达力。现在adapter-cursor里_ctx被直接忽略、cwd硬编码process.cwd(),就是这个 mismatch 的直接症状。核心设计
1. AgentFn 泛型化
ctx保留:thread history、abort signal 等运行时上下文,所有 agent 都需要input泛型化:每个 agent 声明自己需要的结构化输入2. Schema 驱动的 Adapt 层
Adapter 不需要泛型 — 给定 schema,extract 逻辑是通用的:
3. 具体 Agent 只声明 schema
Phase 拆分
Phase 1: 类型层改造
AgentFn<I>泛型化adaptAgent函数 +extractFromContext通用实现AgentFn消费者迁移为AgentFn<string>(向后兼容默认值)Phase 2: Adapter 迁移
adapter-cursor用 schema 重写,去掉_ctxhackadapter-hermes迁移createRole(workflow-utils) 适配新签名Phase 3: 端到端验证
完成标准