@aigne/core 1.11.0 → 1.12.0

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.
Files changed (127) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/README.md +11 -10
  3. package/README.zh.md +7 -6
  4. package/lib/cjs/agents/agent.d.ts +20 -20
  5. package/lib/cjs/agents/agent.js +25 -26
  6. package/lib/cjs/agents/ai-agent.d.ts +17 -18
  7. package/lib/cjs/agents/ai-agent.js +6 -6
  8. package/lib/cjs/agents/mcp-agent.d.ts +10 -4
  9. package/lib/cjs/agents/mcp-agent.js +12 -6
  10. package/lib/cjs/agents/memory.d.ts +1 -1
  11. package/lib/cjs/agents/team-agent.d.ts +28 -0
  12. package/lib/cjs/agents/team-agent.js +93 -0
  13. package/lib/cjs/agents/user-agent.d.ts +9 -10
  14. package/lib/cjs/agents/user-agent.js +10 -13
  15. package/lib/{esm/execution-engine/execution-engine.d.ts → cjs/aigne/aigne.d.ts} +9 -12
  16. package/lib/cjs/{execution-engine/execution-engine.js → aigne/aigne.js} +19 -19
  17. package/lib/cjs/{execution-engine → aigne}/context.d.ts +31 -32
  18. package/lib/cjs/{execution-engine → aigne}/context.js +30 -40
  19. package/lib/cjs/aigne/index.d.ts +4 -0
  20. package/lib/cjs/{execution-engine → aigne}/index.js +2 -2
  21. package/lib/cjs/{execution-engine → aigne}/usage.d.ts +1 -1
  22. package/lib/cjs/client/client.d.ts +19 -0
  23. package/lib/cjs/client/client.js +49 -0
  24. package/lib/cjs/index.d.ts +2 -1
  25. package/lib/cjs/index.js +2 -1
  26. package/lib/cjs/loader/agent-yaml.d.ts +3 -3
  27. package/lib/cjs/loader/agent-yaml.js +10 -3
  28. package/lib/cjs/loader/index.d.ts +9 -9
  29. package/lib/cjs/loader/index.js +6 -6
  30. package/lib/cjs/models/chat-model.d.ts +1 -1
  31. package/lib/cjs/models/claude-chat-model.d.ts +3 -3
  32. package/lib/cjs/models/openai-chat-model.d.ts +3 -3
  33. package/lib/cjs/prompt/prompt-builder.d.ts +1 -1
  34. package/lib/cjs/prompt/prompt-builder.js +3 -3
  35. package/lib/cjs/server/error.d.ts +4 -0
  36. package/lib/cjs/server/error.js +11 -0
  37. package/lib/cjs/server/server.d.ts +54 -0
  38. package/lib/cjs/server/server.js +130 -0
  39. package/lib/cjs/utils/event-stream.d.ts +11 -0
  40. package/lib/cjs/utils/event-stream.js +91 -0
  41. package/lib/cjs/utils/mcp-utils.js +4 -1
  42. package/lib/cjs/utils/stream-utils.d.ts +7 -2
  43. package/lib/cjs/utils/stream-utils.js +43 -34
  44. package/lib/cjs/utils/type-utils.d.ts +4 -2
  45. package/lib/cjs/utils/type-utils.js +10 -2
  46. package/lib/dts/agents/agent.d.ts +20 -20
  47. package/lib/dts/agents/ai-agent.d.ts +17 -18
  48. package/lib/dts/agents/mcp-agent.d.ts +10 -4
  49. package/lib/dts/agents/memory.d.ts +1 -1
  50. package/lib/dts/agents/team-agent.d.ts +28 -0
  51. package/lib/dts/agents/user-agent.d.ts +9 -10
  52. package/lib/dts/{execution-engine/execution-engine.d.ts → aigne/aigne.d.ts} +9 -12
  53. package/lib/dts/{execution-engine → aigne}/context.d.ts +31 -32
  54. package/lib/dts/aigne/index.d.ts +4 -0
  55. package/lib/dts/{execution-engine → aigne}/usage.d.ts +1 -1
  56. package/lib/dts/client/client.d.ts +19 -0
  57. package/lib/dts/index.d.ts +2 -1
  58. package/lib/dts/loader/agent-yaml.d.ts +3 -3
  59. package/lib/dts/loader/index.d.ts +9 -9
  60. package/lib/dts/models/chat-model.d.ts +1 -1
  61. package/lib/dts/models/claude-chat-model.d.ts +3 -3
  62. package/lib/dts/models/openai-chat-model.d.ts +3 -3
  63. package/lib/dts/prompt/prompt-builder.d.ts +1 -1
  64. package/lib/dts/server/error.d.ts +4 -0
  65. package/lib/dts/server/server.d.ts +54 -0
  66. package/lib/dts/utils/event-stream.d.ts +11 -0
  67. package/lib/dts/utils/stream-utils.d.ts +7 -2
  68. package/lib/dts/utils/type-utils.d.ts +4 -2
  69. package/lib/esm/agents/agent.d.ts +20 -20
  70. package/lib/esm/agents/agent.js +25 -26
  71. package/lib/esm/agents/ai-agent.d.ts +17 -18
  72. package/lib/esm/agents/ai-agent.js +6 -6
  73. package/lib/esm/agents/mcp-agent.d.ts +10 -4
  74. package/lib/esm/agents/mcp-agent.js +12 -6
  75. package/lib/esm/agents/memory.d.ts +1 -1
  76. package/lib/esm/agents/team-agent.d.ts +28 -0
  77. package/lib/esm/agents/team-agent.js +89 -0
  78. package/lib/esm/agents/user-agent.d.ts +9 -10
  79. package/lib/esm/agents/user-agent.js +11 -14
  80. package/lib/{cjs/execution-engine/execution-engine.d.ts → esm/aigne/aigne.d.ts} +9 -12
  81. package/lib/esm/{execution-engine/execution-engine.js → aigne/aigne.js} +18 -18
  82. package/lib/esm/{execution-engine → aigne}/context.d.ts +31 -32
  83. package/lib/esm/{execution-engine → aigne}/context.js +28 -38
  84. package/lib/esm/aigne/index.d.ts +4 -0
  85. package/lib/esm/aigne/index.js +4 -0
  86. package/lib/esm/{execution-engine → aigne}/usage.d.ts +1 -1
  87. package/lib/esm/client/client.d.ts +19 -0
  88. package/lib/esm/client/client.js +45 -0
  89. package/lib/esm/index.d.ts +2 -1
  90. package/lib/esm/index.js +2 -1
  91. package/lib/esm/loader/agent-yaml.d.ts +3 -3
  92. package/lib/esm/loader/agent-yaml.js +10 -3
  93. package/lib/esm/loader/index.d.ts +9 -9
  94. package/lib/esm/loader/index.js +6 -6
  95. package/lib/esm/models/chat-model.d.ts +1 -1
  96. package/lib/esm/models/claude-chat-model.d.ts +3 -3
  97. package/lib/esm/models/openai-chat-model.d.ts +3 -3
  98. package/lib/esm/prompt/prompt-builder.d.ts +1 -1
  99. package/lib/esm/prompt/prompt-builder.js +3 -3
  100. package/lib/esm/server/error.d.ts +4 -0
  101. package/lib/esm/server/error.js +7 -0
  102. package/lib/esm/server/server.d.ts +54 -0
  103. package/lib/esm/server/server.js +123 -0
  104. package/lib/esm/utils/event-stream.d.ts +11 -0
  105. package/lib/esm/utils/event-stream.js +85 -0
  106. package/lib/esm/utils/mcp-utils.js +4 -1
  107. package/lib/esm/utils/stream-utils.d.ts +7 -2
  108. package/lib/esm/utils/stream-utils.js +42 -33
  109. package/lib/esm/utils/type-utils.d.ts +4 -2
  110. package/lib/esm/utils/type-utils.js +9 -2
  111. package/package.json +13 -4
  112. package/lib/cjs/execution-engine/index.d.ts +0 -4
  113. package/lib/cjs/execution-engine/utils.d.ts +0 -4
  114. package/lib/cjs/execution-engine/utils.js +0 -34
  115. package/lib/dts/execution-engine/index.d.ts +0 -4
  116. package/lib/dts/execution-engine/utils.d.ts +0 -4
  117. package/lib/esm/execution-engine/index.d.ts +0 -4
  118. package/lib/esm/execution-engine/index.js +0 -4
  119. package/lib/esm/execution-engine/utils.d.ts +0 -4
  120. package/lib/esm/execution-engine/utils.js +0 -30
  121. /package/lib/cjs/{execution-engine → aigne}/message-queue.d.ts +0 -0
  122. /package/lib/cjs/{execution-engine → aigne}/message-queue.js +0 -0
  123. /package/lib/cjs/{execution-engine → aigne}/usage.js +0 -0
  124. /package/lib/dts/{execution-engine → aigne}/message-queue.d.ts +0 -0
  125. /package/lib/esm/{execution-engine → aigne}/message-queue.d.ts +0 -0
  126. /package/lib/esm/{execution-engine → aigne}/message-queue.js +0 -0
  127. /package/lib/esm/{execution-engine → aigne}/usage.js +0 -0
@@ -11,7 +11,12 @@ export declare function onAgentResponseStreamEnd<T extends Message>(stream: Agen
11
11
  }): ReadableStream<any>;
12
12
  export declare function isAsyncGenerator<T extends AsyncGenerator>(value: AsyncGenerator | unknown): value is T;
13
13
  export declare function arrayToAgentProcessAsyncGenerator<T extends Message>(chunks: (AgentResponseChunk<T> | Error)[], result?: Partial<T>): AgentProcessAsyncGenerator<T>;
14
- export declare function arrayToAgentResponseStream<T>(chunks: (AgentResponseChunk<T> | Error)[]): AgentResponseStream<T>;
15
- export declare function readableStreamToArray<T>(stream: ReadableStream<T>): Promise<T[]>;
14
+ export declare function arrayToReadableStream<T>(chunks: (T | Error)[]): ReadableStream<T>;
15
+ export declare function readableStreamToArray<T>(stream: ReadableStream<T>, options: {
16
+ catchError: true;
17
+ }): Promise<(T | Error)[]>;
18
+ export declare function readableStreamToArray<T>(stream: ReadableStream<T>, options?: {
19
+ catchError?: false;
20
+ }): Promise<T[]>;
16
21
  export declare function readableStreamToAsyncIterator<T>(stream: ReadableStream<T>): AsyncIterable<T>;
17
22
  export declare function stringToAgentResponseStream(str: string, key?: "text" | typeof MESSAGE_KEY | string): AgentResponseStream<Message>;
@@ -10,7 +10,7 @@ exports.asyncGeneratorToReadableStream = asyncGeneratorToReadableStream;
10
10
  exports.onAgentResponseStreamEnd = onAgentResponseStreamEnd;
11
11
  exports.isAsyncGenerator = isAsyncGenerator;
12
12
  exports.arrayToAgentProcessAsyncGenerator = arrayToAgentProcessAsyncGenerator;
13
- exports.arrayToAgentResponseStream = arrayToAgentResponseStream;
13
+ exports.arrayToReadableStream = arrayToReadableStream;
14
14
  exports.readableStreamToArray = readableStreamToArray;
15
15
  exports.readableStreamToAsyncIterator = readableStreamToAsyncIterator;
16
16
  exports.stringToAgentResponseStream = stringToAgentResponseStream;
@@ -19,7 +19,7 @@ const agent_js_1 = require("../agents/agent.js");
19
19
  const type_utils_js_1 = require("./type-utils.js");
20
20
  function objectToAgentResponseStream(json) {
21
21
  return new ReadableStream({
22
- start(controller) {
22
+ pull(controller) {
23
23
  controller.enqueue({ delta: { json } });
24
24
  controller.close();
25
25
  },
@@ -65,22 +65,20 @@ async function agentResponseStreamToObject(stream) {
65
65
  }
66
66
  function asyncGeneratorToReadableStream(generator) {
67
67
  return new ReadableStream({
68
- async start(controller) {
68
+ async pull(controller) {
69
69
  try {
70
- for (;;) {
71
- const chunk = await generator.next();
72
- if (chunk.value) {
73
- if (chunk.done) {
74
- controller.enqueue({ delta: { json: chunk.value } });
75
- }
76
- else {
77
- controller.enqueue(chunk.value);
78
- }
70
+ const chunk = await generator.next();
71
+ if (chunk.value) {
72
+ if (chunk.done) {
73
+ controller.enqueue({ delta: { json: chunk.value } });
74
+ }
75
+ else {
76
+ controller.enqueue(chunk.value);
79
77
  }
80
- if (chunk.done)
81
- break;
82
78
  }
83
- controller.close();
79
+ if (chunk.done) {
80
+ controller.close();
81
+ }
84
82
  }
85
83
  catch (error) {
86
84
  controller.error(error);
@@ -89,15 +87,18 @@ function asyncGeneratorToReadableStream(generator) {
89
87
  });
90
88
  }
91
89
  function onAgentResponseStreamEnd(stream, callback, options) {
90
+ const json = {};
91
+ const reader = stream.getReader();
92
92
  return new ReadableStream({
93
- async start(controller) {
93
+ async pull(controller) {
94
94
  try {
95
- const json = {};
96
- for await (const value of readableStreamToAsyncIterator(stream)) {
95
+ const { value, done } = await reader.read();
96
+ if (!done) {
97
97
  const chunk = options?.processChunk ? options.processChunk(value) : value;
98
98
  if (!(0, agent_js_1.isEmptyChunk)(chunk))
99
99
  controller.enqueue(chunk);
100
100
  mergeAgentResponseChunk(json, value);
101
+ return;
101
102
  }
102
103
  const result = await callback(json);
103
104
  if (result && !(0, fast_deep_equal_1.default)(result, json)) {
@@ -106,13 +107,11 @@ function onAgentResponseStreamEnd(stream, callback, options) {
106
107
  chunk = options.processChunk(chunk);
107
108
  controller.enqueue(chunk);
108
109
  }
110
+ controller.close();
109
111
  }
110
112
  catch (error) {
111
113
  controller.error(options?.errorCallback?.(error) ?? error);
112
114
  }
113
- finally {
114
- controller.close();
115
- }
116
115
  },
117
116
  });
118
117
  }
@@ -128,24 +127,34 @@ async function* arrayToAgentProcessAsyncGenerator(chunks, result) {
128
127
  if (result !== undefined)
129
128
  return result;
130
129
  }
131
- function arrayToAgentResponseStream(chunks) {
130
+ function arrayToReadableStream(chunks) {
131
+ const list = [...chunks];
132
132
  return new ReadableStream({
133
- start(controller) {
134
- for (const chunk of chunks) {
135
- if (chunk instanceof Error) {
136
- controller.error(chunk);
137
- return;
138
- }
139
- controller.enqueue(chunk);
133
+ pull(controller) {
134
+ const item = list.shift();
135
+ if (!item) {
136
+ controller.close();
137
+ return;
140
138
  }
141
- controller.close();
139
+ if (item instanceof Error) {
140
+ controller.error(item);
141
+ return;
142
+ }
143
+ controller.enqueue(item);
142
144
  },
143
145
  });
144
146
  }
145
- async function readableStreamToArray(stream) {
147
+ async function readableStreamToArray(stream, options) {
146
148
  const result = [];
147
- for await (const value of readableStreamToAsyncIterator(stream)) {
148
- result.push(value);
149
+ try {
150
+ for await (const value of readableStreamToAsyncIterator(stream)) {
151
+ result.push(value);
152
+ }
153
+ }
154
+ catch (error) {
155
+ if (!options?.catchError)
156
+ throw error;
157
+ result.push(error);
149
158
  }
150
159
  return result;
151
160
  }
@@ -161,5 +170,5 @@ async function* readableStreamToAsyncIterator(stream) {
161
170
  function stringToAgentResponseStream(str, key = "text") {
162
171
  const segmenter = new Intl.Segmenter(undefined, { granularity: "word" });
163
172
  const segments = segmenter.segment(str);
164
- return arrayToAgentResponseStream(Array.from(segments).map((segment) => ({ delta: { text: { [key]: segment.segment } } })));
173
+ return arrayToReadableStream(Array.from(segments).map((segment) => ({ delta: { text: { [key]: segment.segment } } })));
165
174
  }
@@ -1,8 +1,9 @@
1
1
  import { type ZodType } from "zod";
2
2
  export type PromiseOrValue<T> = T | Promise<T>;
3
- export type Nullish<T> = T | null | undefined;
3
+ export type Nullish<T> = T | null | undefined | void;
4
4
  export type OmitPropertiesFromArrayFirstElement<T extends unknown[], K extends string | number | symbol> = T extends [infer U, ...infer Rest] ? [Omit<U, K>, ...Rest] : never;
5
5
  export declare function isNil(value: unknown): value is null | undefined;
6
+ export declare function isRecord<T>(value: unknown): value is Record<string, T>;
6
7
  export declare function isEmpty(obj: unknown): boolean;
7
8
  export declare function isNonNullable<T>(value: T): value is NonNullable<T>;
8
9
  export declare function isNotEmpty<T>(arr: T[]): arr is [T, ...T[]];
@@ -12,5 +13,6 @@ export declare function orArrayToArray<T>(value?: T | T[]): T[];
12
13
  export declare function createAccessorArray<T>(array: T[], accessor: (array: T[], name: string) => T | undefined): T[] & {
13
14
  [key: string]: T;
14
15
  };
15
- export declare function checkArguments<T>(prefix: string, schema: ZodType<T>, args: T): T;
16
+ export declare function checkArguments<T>(prefix: string, schema: ZodType<T>, args: T | unknown): T;
16
17
  export declare function tryOrThrow<P extends PromiseOrValue<unknown>>(fn: () => P, error: string | Error | ((error: Error) => Error)): P;
18
+ export declare function tryOrThrow<P extends PromiseOrValue<unknown>>(fn: () => P, error?: Nullish<string | Error | ((error: Error) => Nullish<Error>)>): P | undefined;
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.isNil = isNil;
4
+ exports.isRecord = isRecord;
4
5
  exports.isEmpty = isEmpty;
5
6
  exports.isNonNullable = isNonNullable;
6
7
  exports.isNotEmpty = isNotEmpty;
@@ -14,6 +15,9 @@ const zod_1 = require("zod");
14
15
  function isNil(value) {
15
16
  return value === null || value === undefined;
16
17
  }
18
+ function isRecord(value) {
19
+ return !!value && typeof value === "object" && !Array.isArray(value);
20
+ }
17
21
  function isEmpty(obj) {
18
22
  if (isNil(obj))
19
23
  return true;
@@ -113,12 +117,16 @@ function tryOrThrow(fn, error) {
113
117
  const result = fn();
114
118
  if (result instanceof Promise) {
115
119
  return result.catch((e) => {
116
- throw createError(e);
120
+ const error = createError(e);
121
+ if (error)
122
+ throw error;
117
123
  });
118
124
  }
119
125
  return result;
120
126
  }
121
127
  catch (e) {
122
- throw createError(e);
128
+ const error = createError(e);
129
+ if (error)
130
+ throw error;
123
131
  }
124
132
  }
@@ -1,6 +1,6 @@
1
1
  import { inspect } from "node:util";
2
2
  import { type ZodType } from "zod";
3
- import type { Context } from "../execution-engine/context.js";
3
+ import type { Context } from "../aigne/context.js";
4
4
  import { type Nullish, type PromiseOrValue } from "../utils/type-utils.js";
5
5
  import { AgentMemory, type AgentMemoryOptions } from "./memory.js";
6
6
  import { type TransferAgentOutput } from "./types.js";
@@ -15,11 +15,11 @@ export interface AgentOptions<I extends Message = Message, O extends Message = M
15
15
  inputSchema?: AgentInputOutputSchema<I>;
16
16
  outputSchema?: AgentInputOutputSchema<O>;
17
17
  includeInputInOutput?: boolean;
18
- tools?: (Agent | FunctionAgentFn)[];
18
+ skills?: (Agent | FunctionAgentFn)[];
19
19
  disableEvents?: boolean;
20
20
  memory?: AgentMemory | AgentMemoryOptions | true;
21
21
  }
22
- export interface AgentCallOptions {
22
+ export interface AgentInvokeOptions {
23
23
  streaming?: boolean;
24
24
  }
25
25
  export declare abstract class Agent<I extends Message = Message, O extends Message = Message> {
@@ -38,38 +38,38 @@ export declare abstract class Agent<I extends Message = Message, O extends Messa
38
38
  readonly includeInputInOutput?: boolean;
39
39
  readonly subscribeTopic?: SubscribeTopic;
40
40
  readonly publishTopic?: PublishTopic<Message>;
41
- readonly tools: Agent<Message, Message>[] & {
41
+ readonly skills: Agent<Message, Message>[] & {
42
42
  [key: string]: Agent<Message, Message>;
43
43
  };
44
44
  private disableEvents?;
45
45
  /**
46
46
  * Attach agent to context:
47
- * - subscribe to topic and call process method when message received
47
+ * - subscribe to topic and invoke process method when message received
48
48
  * - subscribe to memory topic if memory is enabled
49
49
  * @param context Context to attach
50
50
  */
51
51
  attach(context: Pick<Context, "subscribe">): void;
52
- addTool<I extends Message, O extends Message>(tool: Agent<I, O> | FunctionAgentFn<I, O>): void;
53
- get isCallable(): boolean;
52
+ addSkill(...skills: (Agent | FunctionAgentFn)[]): void;
53
+ get isInvokable(): boolean;
54
54
  private checkContextStatus;
55
55
  private newDefaultContext;
56
- call(input: I | string, context: Context | undefined, options: AgentCallOptions & {
56
+ invoke(input: I | string, context: Context | undefined, options: AgentInvokeOptions & {
57
57
  streaming: true;
58
58
  }): Promise<AgentResponseStream<O>>;
59
- call(input: I | string, context?: Context, options?: AgentCallOptions & {
59
+ invoke(input: I | string, context?: Context, options?: AgentInvokeOptions & {
60
60
  streaming?: false;
61
61
  }): Promise<O>;
62
- call(input: I | string, context?: Context, options?: AgentCallOptions): Promise<AgentResponse<O>>;
62
+ invoke(input: I | string, context?: Context, options?: AgentInvokeOptions): Promise<AgentResponse<O>>;
63
63
  private processAgentOutput;
64
64
  private processAgentError;
65
- protected checkUsageAgentCalls(context: Context): void;
65
+ protected checkAgentInvokesUsage(context: Context): void;
66
66
  protected preprocess(_: I, context: Context): void;
67
67
  protected postprocess(input: I, output: O, context: Context): void;
68
- abstract process(input: I, context: Context, options?: AgentCallOptions): AgentProcessResult<O | TransferAgentOutput>;
68
+ abstract process(input: I, context: Context, options?: AgentInvokeOptions): PromiseOrValue<AgentProcessResult<O>>;
69
69
  shutdown(): Promise<void>;
70
70
  [inspect.custom](): string;
71
71
  }
72
- export type AgentResponse<T> = T | AgentResponseStream<T>;
72
+ export type AgentResponse<T> = T | TransferAgentOutput | AgentResponseStream<T>;
73
73
  export type AgentResponseStream<T> = ReadableStream<AgentResponseChunk<T>>;
74
74
  export type AgentResponseChunk<T> = AgentResponseDelta<T>;
75
75
  export declare function isEmptyChunk<T>(chunk: AgentResponseChunk<T>): boolean;
@@ -77,14 +77,14 @@ export interface AgentResponseDelta<T> {
77
77
  delta: {
78
78
  text?: Partial<{
79
79
  [key in keyof T as Extract<T[key], string> extends string ? key : never]: string;
80
- }> | {
80
+ }> | Partial<{
81
81
  [key: string]: string;
82
- };
83
- json?: Partial<T>;
82
+ }>;
83
+ json?: Partial<T | TransferAgentOutput>;
84
84
  };
85
85
  }
86
- export type AgentProcessAsyncGenerator<O extends Message> = AsyncGenerator<AgentResponseChunk<O>, Partial<O> | undefined | void>;
87
- export type AgentProcessResult<O extends Message> = Promise<AgentResponse<O>> | AgentProcessAsyncGenerator<O>;
86
+ export type AgentProcessAsyncGenerator<O extends Message> = AsyncGenerator<AgentResponseChunk<O>, Partial<O | TransferAgentOutput> | undefined | void>;
87
+ export type AgentProcessResult<O extends Message> = AgentResponse<O> | AgentProcessAsyncGenerator<O> | Agent;
88
88
  export type AgentInputOutputSchema<I extends Message = Message> = ZodType<I> | ((agent: Agent) => ZodType<I>);
89
89
  export interface FunctionAgentOptions<I extends Message = Message, O extends Message = Message> extends AgentOptions<I, O> {
90
90
  fn?: FunctionAgentFn<I, O>;
@@ -93,6 +93,6 @@ export declare class FunctionAgent<I extends Message = Message, O extends Messag
93
93
  static from<I extends Message, O extends Message>(options: FunctionAgentOptions<I, O> | FunctionAgentFn<I, O>): FunctionAgent<I, O>;
94
94
  constructor(options: FunctionAgentOptions<I, O>);
95
95
  fn: FunctionAgentFn<I, O>;
96
- process(input: I, context: Context, options?: AgentCallOptions): Promise<AgentResponse<O | TransferAgentOutput>>;
96
+ process(input: I, context: Context): PromiseOrValue<AgentProcessResult<O>>;
97
97
  }
98
- export type FunctionAgentFn<I extends Message = Message, O extends Message = Message> = (input: I, context: Context) => O | Promise<O> | Agent | Promise<Agent>;
98
+ export type FunctionAgentFn<I extends Message = any, O extends Message = any> = (input: I, context: Context) => PromiseOrValue<AgentProcessResult<O>>;
@@ -1,10 +1,9 @@
1
1
  import { z } from "zod";
2
- import type { Context } from "../execution-engine/context.js";
2
+ import type { Context } from "../aigne/context.js";
3
3
  import { ChatModel } from "../models/chat-model.js";
4
4
  import type { ChatModelInput } from "../models/chat-model.js";
5
5
  import { PromptBuilder } from "../prompt/prompt-builder.js";
6
6
  import { Agent, type AgentOptions, type AgentProcessAsyncGenerator, type Message } from "./agent.js";
7
- import { type TransferAgentOutput } from "./types.js";
8
7
  export interface AIAgentOptions<I extends Message = Message, O extends Message = Message> extends AgentOptions<I, O> {
9
8
  model?: ChatModel;
10
9
  instructions?: string | PromptBuilder;
@@ -25,39 +24,39 @@ export declare const aiAgentOptionsSchema: z.ZodObject<{
25
24
  publishTopic: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">, z.ZodFunction<z.ZodTuple<[], z.ZodUnknown>, z.ZodUnknown>]>>;
26
25
  name: z.ZodOptional<z.ZodString>;
27
26
  description: z.ZodOptional<z.ZodString>;
28
- tools: z.ZodOptional<z.ZodArray<z.ZodUnion<[z.ZodType<Agent<Message, Message>, z.ZodTypeDef, Agent<Message, Message>>, z.ZodFunction<z.ZodTuple<[], z.ZodUnknown>, z.ZodUnknown>]>, "many">>;
27
+ skills: z.ZodOptional<z.ZodArray<z.ZodUnion<[z.ZodType<Agent<Message, Message>, z.ZodTypeDef, Agent<Message, Message>>, z.ZodFunction<z.ZodTuple<[], z.ZodUnknown>, z.ZodUnknown>]>, "many">>;
29
28
  disableLogging: z.ZodOptional<z.ZodBoolean>;
30
29
  memory: z.ZodOptional<z.ZodUnion<[z.ZodBoolean, z.ZodAny, z.ZodAny]>>;
31
30
  }, "strip", z.ZodTypeAny, {
32
- tools?: (Agent<Message, Message> | ((...args: unknown[]) => unknown))[] | undefined;
33
- toolChoice?: Agent<Message, Message> | "auto" | "none" | "required" | "router" | undefined;
34
- name?: string | undefined;
35
31
  description?: string | undefined;
32
+ memory?: any;
33
+ name?: string | undefined;
34
+ includeInputInOutput?: boolean | undefined;
35
+ subscribeTopic?: string | string[] | undefined;
36
+ publishTopic?: string | string[] | ((...args: unknown[]) => unknown) | undefined;
37
+ skills?: (Agent<Message, Message> | ((...args: unknown[]) => unknown))[] | undefined;
38
+ toolChoice?: Agent<Message, Message> | "auto" | "none" | "required" | "router" | undefined;
36
39
  model?: ChatModel | undefined;
37
40
  instructions?: string | PromptBuilder | undefined;
38
41
  outputKey?: string | undefined;
39
42
  enableHistory?: boolean | undefined;
40
43
  maxHistoryMessages?: number | undefined;
44
+ disableLogging?: boolean | undefined;
45
+ }, {
46
+ description?: string | undefined;
47
+ memory?: any;
48
+ name?: string | undefined;
41
49
  includeInputInOutput?: boolean | undefined;
42
50
  subscribeTopic?: string | string[] | undefined;
43
51
  publishTopic?: string | string[] | ((...args: unknown[]) => unknown) | undefined;
44
- disableLogging?: boolean | undefined;
45
- memory?: any;
46
- }, {
47
- tools?: (Agent<Message, Message> | ((...args: unknown[]) => unknown))[] | undefined;
52
+ skills?: (Agent<Message, Message> | ((...args: unknown[]) => unknown))[] | undefined;
48
53
  toolChoice?: Agent<Message, Message> | "auto" | "none" | "required" | "router" | undefined;
49
- name?: string | undefined;
50
- description?: string | undefined;
51
54
  model?: ChatModel | undefined;
52
55
  instructions?: string | PromptBuilder | undefined;
53
56
  outputKey?: string | undefined;
54
57
  enableHistory?: boolean | undefined;
55
58
  maxHistoryMessages?: number | undefined;
56
- includeInputInOutput?: boolean | undefined;
57
- subscribeTopic?: string | string[] | undefined;
58
- publishTopic?: string | string[] | ((...args: unknown[]) => unknown) | undefined;
59
59
  disableLogging?: boolean | undefined;
60
- memory?: any;
61
60
  }>;
62
61
  export declare class AIAgent<I extends Message = Message, O extends Message = Message> extends Agent<I, O> {
63
62
  static from<I extends Message, O extends Message>(options: AIAgentOptions<I, O>): AIAgent<I, O>;
@@ -66,6 +65,6 @@ export declare class AIAgent<I extends Message = Message, O extends Message = Me
66
65
  instructions: PromptBuilder;
67
66
  outputKey?: string;
68
67
  toolChoice?: AIAgentToolChoice;
69
- process(input: I, context: Context): AgentProcessAsyncGenerator<O | TransferAgentOutput>;
70
- processRouter(input: I, model: ChatModel, modelInput: ChatModelInput, context: Context, toolsMap: Map<string, Agent>): AgentProcessAsyncGenerator<O | TransferAgentOutput>;
68
+ process(input: I, context: Context): AgentProcessAsyncGenerator<O>;
69
+ processRouter(input: I, model: ChatModel, modelInput: ChatModelInput, context: Context, toolsMap: Map<string, Agent>): AgentProcessAsyncGenerator<O>;
71
70
  }
@@ -1,11 +1,12 @@
1
1
  import { Client, type ClientOptions } from "@modelcontextprotocol/sdk/client/index.js";
2
2
  import { type SSEClientTransportOptions } from "@modelcontextprotocol/sdk/client/sse.js";
3
3
  import { type StdioServerParameters } from "@modelcontextprotocol/sdk/client/stdio.js";
4
+ import { type StreamableHTTPClientTransportOptions } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
4
5
  import type { RequestOptions } from "@modelcontextprotocol/sdk/shared/protocol.js";
5
6
  import type { Transport } from "@modelcontextprotocol/sdk/shared/transport.js";
6
7
  import type { CallToolResult, GetPromptResult, Implementation, ReadResourceResult, Request } from "@modelcontextprotocol/sdk/types.js";
7
8
  import { type ZodType, z } from "zod";
8
- import type { Context } from "../execution-engine/context.js";
9
+ import type { Context } from "../aigne/context.js";
9
10
  import { type PromiseOrValue } from "../utils/type-utils.js";
10
11
  import { Agent, type AgentOptions, type Message } from "./agent.js";
11
12
  export interface MCPAgentOptions extends AgentOptions {
@@ -17,9 +18,14 @@ export type MCPServerOptions = SSEServerParameters | StdioServerParameters;
17
18
  export type SSEServerParameters = {
18
19
  url: string;
19
20
  /**
20
- * Additional options to pass to the SSEClientTransport.
21
+ * Whether to use the StreamableHTTPClientTransport instead of the SSEClientTransport.
22
+ * @default "sse"
21
23
  */
22
- opts?: SSEClientTransportOptions;
24
+ transport?: "sse" | "streamableHttp";
25
+ /**
26
+ * Additional options to pass to the SSEClientTransport or StreamableHTTPClientTransport.
27
+ */
28
+ opts?: SSEClientTransportOptions | StreamableHTTPClientTransportOptions;
23
29
  /**
24
30
  * The timeout for requests to the server, in milliseconds.
25
31
  * @default 60000
@@ -48,7 +54,7 @@ export declare class MCPAgent extends Agent {
48
54
  readonly resources: MCPResource[] & {
49
55
  [key: string]: MCPResource;
50
56
  };
51
- get isCallable(): boolean;
57
+ get isInvokable(): boolean;
52
58
  process(_input: Message, _context?: Context): Promise<Message>;
53
59
  shutdown(): Promise<void>;
54
60
  }
@@ -1,4 +1,4 @@
1
- import type { Context } from "../execution-engine/context.js";
1
+ import type { Context } from "../aigne/context.js";
2
2
  import type { Message } from "./agent.js";
3
3
  export interface AgentMemoryOptions {
4
4
  /**
@@ -0,0 +1,28 @@
1
+ import type { Context } from "../aigne/context.js";
2
+ import { type PromiseOrValue } from "../utils/type-utils.js";
3
+ import { Agent, type AgentOptions, type AgentProcessResult, type Message } from "./agent.js";
4
+ export declare enum ProcessMode {
5
+ /**
6
+ * Process the agents one by one, passing the output of each agent to the next.
7
+ */
8
+ sequential = "sequential",
9
+ /**
10
+ * Process all agents in parallel, merging the output of all agents.
11
+ */
12
+ parallel = "parallel"
13
+ }
14
+ export interface TeamAgentOptions<I extends Message, O extends Message> extends AgentOptions<I, O> {
15
+ /**
16
+ * The method to process the agents in the team.
17
+ * @default {ProcessMode.sequential}
18
+ */
19
+ mode?: ProcessMode;
20
+ }
21
+ export declare class TeamAgent<I extends Message, O extends Message> extends Agent<I, O> {
22
+ static from<I extends Message, O extends Message>(options: TeamAgentOptions<I, O>): TeamAgent<I, O>;
23
+ constructor(options: TeamAgentOptions<I, O>);
24
+ mode: ProcessMode;
25
+ process(input: I, context: Context): PromiseOrValue<AgentProcessResult<O>>;
26
+ _processSequential(input: I, context: Context): PromiseOrValue<AgentProcessResult<O>>;
27
+ _processParallel(input: I, context: Context): PromiseOrValue<AgentProcessResult<O>>;
28
+ }
@@ -1,26 +1,25 @@
1
1
  import { ReadableStream } from "node:stream/web";
2
- import { type Context, type Runnable } from "../execution-engine/context.js";
3
- import type { MessagePayload } from "../execution-engine/message-queue.js";
4
- import { type PromiseOrValue } from "../utils/type-utils.js";
5
- import { Agent, type AgentOptions, type AgentProcessAsyncGenerator, type Message } from "./agent.js";
2
+ import { type Context } from "../aigne/context.js";
3
+ import type { MessagePayload } from "../aigne/message-queue.js";
4
+ import { type Agent, type AgentOptions, type AgentProcessResult, FunctionAgent, type FunctionAgentFn, type Message } from "./agent.js";
6
5
  export interface UserAgentOptions<I extends Message = Message, O extends Message = Message> extends AgentOptions<I, O> {
7
6
  context: Context;
8
- process?: (input: I, context: Context) => PromiseOrValue<O>;
9
- activeAgent?: Runnable;
7
+ process?: FunctionAgentFn<I, O>;
8
+ activeAgent?: Agent;
10
9
  }
11
- export declare class UserAgent<I extends Message = Message, O extends Message = Message> extends Agent<I, O> {
10
+ export declare class UserAgent<I extends Message = Message, O extends Message = Message> extends FunctionAgent<I, O> {
12
11
  static from<I extends Message, O extends Message>(options: UserAgentOptions<I, O>): UserAgent<I, O>;
13
12
  constructor(options: UserAgentOptions<I, O>);
14
13
  context: Context;
15
14
  private _process?;
16
15
  private activeAgent?;
17
- call: Agent<I, O>["call"];
18
- process(input: I, context: Context): AgentProcessAsyncGenerator<O>;
16
+ invoke: Agent<I, O>["invoke"];
17
+ process(input: I, context: Context): Promise<AgentProcessResult<O>>;
19
18
  publish: Context["publish"];
20
19
  subscribe: Context["subscribe"];
21
20
  unsubscribe: Context["unsubscribe"];
22
21
  get stream(): ReadableStream<MessagePayload & {
23
22
  topic: string;
24
23
  }>;
25
- protected checkUsageAgentCalls(_context: Context): void;
24
+ protected checkAgentInvokesUsage(_context: Context): void;
26
25
  }
@@ -1,29 +1,26 @@
1
1
  import { Agent } from "../agents/agent.js";
2
2
  import { ChatModel } from "../models/chat-model.js";
3
- import { type Context, ExecutionContext } from "./context.js";
3
+ import { AIGNEContext, type Context } from "./context.js";
4
4
  import { MessageQueue } from "./message-queue.js";
5
5
  import type { ContextLimits } from "./usage.js";
6
- export interface ExecutionEngineOptions {
6
+ export interface AIGNEOptions {
7
7
  name?: string;
8
8
  description?: string;
9
9
  model?: ChatModel;
10
- tools?: Agent[];
10
+ skills?: Agent[];
11
11
  agents?: Agent[];
12
12
  limits?: ContextLimits;
13
13
  }
14
- export interface ExecutionEngineRunOptions {
15
- returnActiveAgent?: boolean;
16
- }
17
- export declare class ExecutionEngine {
14
+ export declare class AIGNE {
18
15
  static load({ path, ...options }: {
19
16
  path: string;
20
- } & ExecutionEngineOptions): Promise<ExecutionEngine>;
21
- constructor(options?: ExecutionEngineOptions);
17
+ } & AIGNEOptions): Promise<AIGNE>;
18
+ constructor(options?: AIGNEOptions);
22
19
  name?: string;
23
20
  description?: string;
24
21
  readonly messageQueue: MessageQueue;
25
22
  model?: ChatModel;
26
- readonly tools: Agent<import("../agents/agent.js").Message, import("../agents/agent.js").Message>[] & {
23
+ readonly skills: Agent<import("../agents/agent.js").Message, import("../agents/agent.js").Message>[] & {
27
24
  [key: string]: Agent<import("../agents/agent.js").Message, import("../agents/agent.js").Message>;
28
25
  };
29
26
  readonly agents: Agent<import("../agents/agent.js").Message, import("../agents/agent.js").Message>[] & {
@@ -31,9 +28,9 @@ export declare class ExecutionEngine {
31
28
  };
32
29
  limits?: ContextLimits;
33
30
  addAgent(...agents: Agent[]): void;
34
- newContext(): ExecutionContext;
31
+ newContext(): AIGNEContext;
35
32
  publish: Context["publish"];
36
- call: Context["call"];
33
+ invoke: Context["invoke"];
37
34
  subscribe: Context["subscribe"];
38
35
  unsubscribe: Context["unsubscribe"];
39
36
  shutdown(): Promise<void>;