graph TB
subgraph "interaction/ 能力"
A["interaction/ (Service Definition)"]
B["user-approval/ (Provider)"]
C["user-questions/ (Provider)"]
D["commands/ (Consumer)"]
E["ask-user/ (Consumer)"]
end
A --> B
A --> C
D --> A
E --> A
graph TB
subgraph "context/ 能力"
A["context/ (Service Definition)"]
B["agent-instructions/ (Provider)"]
C["time-context/ (Provider)"]
D["references/ (Provider)"]
end
A --> B
A --> C
A --> D
graph TB
subgraph "context/ 能力"
A["context/ (Service Definition)"]
B["agent-instructions/ (Provider)"]
C["time-context/ (Provider)"]
D["references/ (Provider)"]
end
A --> B
A --> C
A --> D
graph TB
subgraph "guard/ 能力"
A["guard/ (Service Definition)"]
B["repeat-call-guard/ (Provider)"]
C["tool-timeout-guard/ (Provider)"]
end
A --> B
A --> C
graph TB
subgraph "guard/ 能力"
A["guard/ (Service Definition)"]
B["repeat-call-guard/ (Provider)"]
C["tool-timeout-guard/ (Provider)"]
end
A --> B
A --> C
8.5.2 Repeat Call Guard
防止 Agent 重复调用相同的工具:
// 来自 packages/guard/repeat-call-guard/src/index.tsclassRepeatCallGuard{private callHistory =newMap<string,number>()/** 检查是否重复调用 */check(toolName:string, params: Record<string,unknown>): GuardResult {const key =this.buildKey(toolName, params)const count =this.callHistory.get(key)??0if(count >=this.maxRepeats){return{
allowed:false,
reason:`Tool "${toolName}" has been called ${count} times with the same parameters`}}this.callHistory.set(key, count +1)return{ allowed:true}}}
8.5.3 Tool Timeout Guard
强制执行工具执行超时:
// 来自 packages/guard/tool-timeout-guard/src/index.tsclassToolTimeoutGuard{/** 包装工具执行,添加超时 */asyncwrapExecution<T>(
toolName:string,execution:()=>Promise<T>,
timeoutMs:number):Promise<T>{returnPromise.race([execution(),newPromise<never>((_, reject)=>{setTimeout(()=>{reject(newError(`Tool "${toolName}" timed out after ${timeoutMs}ms`))}, timeoutMs)})])}}
8.6 Plan 机制
8.6.1 概念
Plan 机制允许 Agent 创建和管理执行计划:
预览
源码
graph TB
subgraph "plan/ 能力"
A["plan/ (Service Definition)"]
B["plan-local/ (Provider)"]
C["tool-plan/ (Consumer)"]
end
A --> B
C --> A
graph TB
subgraph "plan/ 能力"
A["plan/ (Service Definition)"]
B["plan-local/ (Provider)"]
C["tool-plan/ (Consumer)"]
end
A --> B
C --> A
8.6.2 Plan 状态
interfacePlan{/** Plan ID */
id:string/** Plan 标题 */
title:string/** Plan 步骤 */
steps: PlanStep[]/** 当前状态 */
status:'draft'|'active'|'completed'|'failed'/** 创建时间 */
createdAt: Date
/** 更新时间 */
updatedAt: Date
}interfacePlanStep{/** 步骤 ID */
id:string/** 步骤描述 */
description:string/** 步骤状态 */
status:'pending'|'in-progress'|'completed'|'failed'/** 依赖的步骤 */
dependsOn?:string[]}