@aipack-ai/multi-agent 1.1.5 → 1.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +87 -5
- package/dist/index.js +828 -356
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -59,6 +59,22 @@ interface AgentNode {
|
|
|
59
59
|
inputMapping?: (ctx: SharedContext) => string | Request;
|
|
60
60
|
/** 输出转换:将Agent结果写入SharedContext */
|
|
61
61
|
outputMapping?: (result: Result, ctx: SharedContext) => void;
|
|
62
|
+
/** 节点级重试配置(失败/超时自动重试,默认不重试) */
|
|
63
|
+
retry?: NodeRetryOpts;
|
|
64
|
+
/** 节点级超时(ms):单次执行超过该时长抛出超时错误(可与 retry 配合重试) */
|
|
65
|
+
timeoutMs?: number;
|
|
66
|
+
/**
|
|
67
|
+
* 依赖的其他节点 ID(仅 Supervisor auto 调度使用):
|
|
68
|
+
* 声明后该 Worker 在所依赖的 Worker 全部完成后再执行。
|
|
69
|
+
*/
|
|
70
|
+
dependsOn?: string[];
|
|
71
|
+
}
|
|
72
|
+
/** 节点级重试配置 */
|
|
73
|
+
interface NodeRetryOpts {
|
|
74
|
+
/** 最大尝试次数(含首次执行,默认 1 即不重试) */
|
|
75
|
+
maxAttempts?: number;
|
|
76
|
+
/** 重试间隔(ms,默认 0 立即重试) */
|
|
77
|
+
backoffMs?: number;
|
|
62
78
|
}
|
|
63
79
|
/** Agent间流转边 */
|
|
64
80
|
interface AgentEdge {
|
|
@@ -110,12 +126,15 @@ interface MultiAgentResult {
|
|
|
110
126
|
success: boolean;
|
|
111
127
|
/** 错误信息 */
|
|
112
128
|
error?: string;
|
|
129
|
+
/** 失败的 Agent ID 列表(onWorkerError/onMapperError='skip' 容忍失败时暴露) */
|
|
130
|
+
failedAgents?: string[];
|
|
113
131
|
}
|
|
114
132
|
/** 多Agent流式事件类型 */
|
|
115
133
|
type MultiAgentEvent = {
|
|
116
134
|
type: 'agent_start';
|
|
117
135
|
agentId: string;
|
|
118
|
-
agentName: string;
|
|
136
|
+
agentName: string; /** 该节点的输入摘要(文本) */
|
|
137
|
+
input?: string;
|
|
119
138
|
} | {
|
|
120
139
|
type: 'agent_result';
|
|
121
140
|
agentId: string;
|
|
@@ -150,6 +169,18 @@ type MultiAgentEvent = {
|
|
|
150
169
|
type: 'graph_error';
|
|
151
170
|
error: string;
|
|
152
171
|
};
|
|
172
|
+
/** 图执行配置选项(createAgentGraph 参数) */
|
|
173
|
+
interface GraphExecutionOpts {
|
|
174
|
+
/**
|
|
175
|
+
* 并行分支(多条出边同时匹配)执行时的最大并发数(默认 Infinity,不限制)
|
|
176
|
+
*/
|
|
177
|
+
concurrency?: number;
|
|
178
|
+
/**
|
|
179
|
+
* 单个节点的最大访问次数(环图防死循环安全阀,默认 10)。
|
|
180
|
+
* 超限时图以 stopReason='max_visits_exceeded' 安全截断
|
|
181
|
+
*/
|
|
182
|
+
maxVisitsPerNode?: number;
|
|
183
|
+
}
|
|
153
184
|
/** AgentGraph: 编排核心 */
|
|
154
185
|
interface AgentGraph {
|
|
155
186
|
/** 添加Agent节点 */
|
|
@@ -168,7 +199,10 @@ interface AgentGraph {
|
|
|
168
199
|
getState(): GraphExecutionState;
|
|
169
200
|
/** 中止执行 */
|
|
170
201
|
abort(): void;
|
|
171
|
-
/**
|
|
202
|
+
/**
|
|
203
|
+
* 事件监听:事件名对应 MultiAgentEvent 的 type 字段
|
|
204
|
+
* (如 'agent_start' / 'agent_result' / 'graph_done'),run 与 stream 均会触发
|
|
205
|
+
*/
|
|
172
206
|
on(event: string, listener: EventListener): this;
|
|
173
207
|
}
|
|
174
208
|
/** Pipeline 配置选项 */
|
|
@@ -182,7 +216,10 @@ interface PipelineOpts {
|
|
|
182
216
|
interface RouterOpts {
|
|
183
217
|
/** 从路由Agent输出中解析目标Agent ID */
|
|
184
218
|
resolve: (routerResult: Result) => string;
|
|
185
|
-
/**
|
|
219
|
+
/**
|
|
220
|
+
* 未匹配到目标时的默认路由Agent ID。
|
|
221
|
+
* resolve 返回的 ID 不在目标列表中时,自动回退路由到该 Agent
|
|
222
|
+
*/
|
|
186
223
|
defaultTarget?: string;
|
|
187
224
|
/** 是否将原始输入传递给目标Agent(默认true),否则传递路由Agent的输出 */
|
|
188
225
|
passOriginalInput?: boolean;
|
|
@@ -209,6 +246,12 @@ interface SupervisorOpts {
|
|
|
209
246
|
* 默认 true
|
|
210
247
|
*/
|
|
211
248
|
passOriginalInput?: boolean;
|
|
249
|
+
/**
|
|
250
|
+
* Worker 失败策略:
|
|
251
|
+
* - 'fail-fast': 任一 Worker 失败立即中止(默认,与 sequential 模式语义一致)
|
|
252
|
+
* - 'skip': 容忍失败,跳过失败的 Worker 继续,失败的 Worker ID 暴露在 result.failedAgents
|
|
253
|
+
*/
|
|
254
|
+
onWorkerError?: 'fail-fast' | 'skip';
|
|
212
255
|
}
|
|
213
256
|
/** Debate 配置选项 */
|
|
214
257
|
interface DebateOpts {
|
|
@@ -227,6 +270,12 @@ interface MapReduceOpts {
|
|
|
227
270
|
concurrency?: number;
|
|
228
271
|
/** Reducer 的输入格式化(默认将所有 mapper 结果用分隔符连接) */
|
|
229
272
|
reduceInputFormat?: (mapperResults: Map<number, Result>) => string;
|
|
273
|
+
/**
|
|
274
|
+
* Mapper 失败策略:
|
|
275
|
+
* - 'fail-fast': 任一子任务失败立即中止(默认)
|
|
276
|
+
* - 'skip': 容忍失败,仅汇总成功的子任务,失败的虚拟 Agent ID 暴露在 result.failedAgents
|
|
277
|
+
*/
|
|
278
|
+
onMapperError?: 'fail-fast' | 'skip';
|
|
230
279
|
}
|
|
231
280
|
/** MCPBridge 配置选项 */
|
|
232
281
|
interface MCPBridgeOpts {
|
|
@@ -302,6 +351,22 @@ declare class SimpleToolRegistry implements ToolRegistry {
|
|
|
302
351
|
/** 创建默认 SharedContext */
|
|
303
352
|
declare function createSharedContext(init?: Partial<SharedContext>): SharedContext;
|
|
304
353
|
|
|
354
|
+
/**
|
|
355
|
+
* core/executor.ts - 图执行引擎
|
|
356
|
+
*
|
|
357
|
+
* 负责 AgentGraph 的执行逻辑:从入口节点出发,
|
|
358
|
+
* 根据边条件遍历图,依次执行各节点的 Runtime。
|
|
359
|
+
*/
|
|
360
|
+
|
|
361
|
+
/** abort() 触发的中止错误,run() 会将其转换为 stopReason='aborted' 的结果 */
|
|
362
|
+
declare class GraphAbortedError extends Error {
|
|
363
|
+
constructor();
|
|
364
|
+
}
|
|
365
|
+
/** 节点执行超时错误(timeoutMs 触发,可配合 retry 重试) */
|
|
366
|
+
declare class NodeTimeoutError extends Error {
|
|
367
|
+
constructor(nodeId: string, timeoutMs: number);
|
|
368
|
+
}
|
|
369
|
+
|
|
305
370
|
/**
|
|
306
371
|
* core/graph.ts - AgentGraph 实现
|
|
307
372
|
*
|
|
@@ -310,7 +375,24 @@ declare function createSharedContext(init?: Partial<SharedContext>): SharedConte
|
|
|
310
375
|
*/
|
|
311
376
|
|
|
312
377
|
/** 创建空的 AgentGraph,通过链式调用定义图结构 */
|
|
313
|
-
declare function createAgentGraph(): AgentGraph;
|
|
378
|
+
declare function createAgentGraph(opts?: GraphExecutionOpts): AgentGraph;
|
|
379
|
+
|
|
380
|
+
/**
|
|
381
|
+
* core/event-stream.ts - 流式事件队列工具
|
|
382
|
+
*
|
|
383
|
+
* 统一各执行器 stream() 的 push-pull 事件队列实现:
|
|
384
|
+
* 后台执行图逻辑,事件按发生顺序产出给消费者,
|
|
385
|
+
* 同时同步分发到外部事件监听(on() API 的 eventSink)。
|
|
386
|
+
*/
|
|
387
|
+
|
|
388
|
+
/**
|
|
389
|
+
* 创建流式事件生成器。
|
|
390
|
+
*
|
|
391
|
+
* @param execute - 后台执行函数,通过 emit 发出事件;
|
|
392
|
+
* 返回的 Promise 决不 reject(错误应转换为 graph_error 事件后 resolve)
|
|
393
|
+
* @param sink - 外部事件监听(可选),异常会被吞掉以防中断事件传播
|
|
394
|
+
*/
|
|
395
|
+
declare function createEventStream(execute: (emit: (event: MultiAgentEvent) => void) => Promise<void>, sink?: (event: MultiAgentEvent) => void): AsyncGenerator<MultiAgentEvent>;
|
|
314
396
|
|
|
315
397
|
/**
|
|
316
398
|
* patterns/pipeline.ts - Pipeline 顺序链模式
|
|
@@ -561,4 +643,4 @@ declare class GraphDebugger {
|
|
|
561
643
|
/** 创建 GraphDebugger */
|
|
562
644
|
declare function createDebugger(graph: AgentGraph): GraphDebugger;
|
|
563
645
|
|
|
564
|
-
export { type AgentEdge, type AgentGraph, type AgentNode, type DebateOpts, type EventBus, type EventListener, GraphDebugger, type GraphExecutionState, type GraphTrace, MCPBridge, type MCPBridgeOpts, type MCPToolCallRequest, type MCPToolCallResult, type MCPToolDefinition, type MCPToolParameter, type MapReduceOpts, type MultiAgentEvent, type MultiAgentResult, type NodeExecutionState, type PipelineOpts, type RouterOpts, type ScheduleMode, type SharedContext, SimpleEventBus, SimpleToolRegistry, type SupervisorOpts, type ToolRegistry, type TraceStep, createAgentGraph, createDebate, createDebugger, createMCPBridge, createMapReduce, createMultiAgentMcpServerHost, createPipeline, createRouter, createSharedContext, createSupervisor };
|
|
646
|
+
export { type AgentEdge, type AgentGraph, type AgentNode, type DebateOpts, type EventBus, type EventListener, GraphAbortedError, GraphDebugger, type GraphExecutionOpts, type GraphExecutionState, type GraphTrace, MCPBridge, type MCPBridgeOpts, type MCPToolCallRequest, type MCPToolCallResult, type MCPToolDefinition, type MCPToolParameter, type MapReduceOpts, type MultiAgentEvent, type MultiAgentResult, type NodeExecutionState, type NodeRetryOpts, NodeTimeoutError, type PipelineOpts, type RouterOpts, type ScheduleMode, type SharedContext, SimpleEventBus, SimpleToolRegistry, type SupervisorOpts, type ToolRegistry, type TraceStep, createAgentGraph, createDebate, createDebugger, createEventStream, createMCPBridge, createMapReduce, createMultiAgentMcpServerHost, createPipeline, createRouter, createSharedContext, createSupervisor };
|