@aigne/core 1.10.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 (142) hide show
  1. package/CHANGELOG.md +28 -0
  2. package/LICENSE +93 -0
  3. package/README.md +90 -0
  4. package/README.zh.md +90 -0
  5. package/lib/cjs/agents/agent.d.ts +21 -20
  6. package/lib/cjs/agents/agent.js +29 -26
  7. package/lib/cjs/agents/ai-agent.d.ts +9 -8
  8. package/lib/cjs/agents/ai-agent.js +20 -14
  9. package/lib/cjs/agents/mcp-agent.d.ts +10 -4
  10. package/lib/cjs/agents/mcp-agent.js +12 -6
  11. package/lib/cjs/agents/memory.d.ts +1 -1
  12. package/lib/cjs/agents/team-agent.d.ts +28 -0
  13. package/lib/cjs/agents/team-agent.js +93 -0
  14. package/lib/cjs/agents/user-agent.d.ts +9 -10
  15. package/lib/cjs/agents/user-agent.js +10 -13
  16. package/lib/{esm/execution-engine/execution-engine.d.ts → cjs/aigne/aigne.d.ts} +9 -12
  17. package/lib/cjs/{execution-engine/execution-engine.js → aigne/aigne.js} +19 -19
  18. package/lib/cjs/{execution-engine → aigne}/context.d.ts +31 -32
  19. package/lib/cjs/{execution-engine → aigne}/context.js +30 -40
  20. package/lib/cjs/aigne/index.d.ts +4 -0
  21. package/lib/cjs/{execution-engine → aigne}/index.js +2 -2
  22. package/lib/cjs/{execution-engine → aigne}/usage.d.ts +1 -1
  23. package/lib/cjs/client/client.d.ts +19 -0
  24. package/lib/cjs/client/client.js +49 -0
  25. package/lib/cjs/index.d.ts +2 -1
  26. package/lib/cjs/index.js +2 -1
  27. package/lib/cjs/loader/agent-js.d.ts +2 -2
  28. package/lib/cjs/loader/agent-js.js +4 -5
  29. package/lib/cjs/loader/agent-yaml.d.ts +8 -5
  30. package/lib/cjs/loader/agent-yaml.js +21 -2
  31. package/lib/cjs/loader/index.d.ts +5 -5
  32. package/lib/cjs/loader/index.js +8 -19
  33. package/lib/cjs/models/chat-model.d.ts +1 -1
  34. package/lib/cjs/models/claude-chat-model.d.ts +3 -1
  35. package/lib/cjs/models/claude-chat-model.js +75 -60
  36. package/lib/cjs/models/openai-chat-model.d.ts +3 -3
  37. package/lib/cjs/models/openai-chat-model.js +1 -3
  38. package/lib/cjs/prompt/prompt-builder.d.ts +1 -1
  39. package/lib/cjs/prompt/prompt-builder.js +3 -3
  40. package/lib/cjs/server/error.d.ts +4 -0
  41. package/lib/cjs/server/error.js +11 -0
  42. package/lib/cjs/server/server.d.ts +54 -0
  43. package/lib/cjs/server/server.js +130 -0
  44. package/lib/cjs/utils/camelize.d.ts +13 -0
  45. package/lib/cjs/utils/camelize.js +16 -0
  46. package/lib/cjs/utils/event-stream.d.ts +11 -0
  47. package/lib/cjs/utils/event-stream.js +91 -0
  48. package/lib/cjs/utils/mcp-utils.js +4 -1
  49. package/lib/cjs/utils/stream-utils.d.ts +10 -3
  50. package/lib/cjs/utils/stream-utils.js +51 -36
  51. package/lib/cjs/utils/type-utils.d.ts +4 -2
  52. package/lib/cjs/utils/type-utils.js +10 -2
  53. package/lib/dts/agents/agent.d.ts +21 -20
  54. package/lib/dts/agents/ai-agent.d.ts +9 -8
  55. package/lib/dts/agents/mcp-agent.d.ts +10 -4
  56. package/lib/dts/agents/memory.d.ts +1 -1
  57. package/lib/dts/agents/team-agent.d.ts +28 -0
  58. package/lib/dts/agents/user-agent.d.ts +9 -10
  59. package/lib/dts/{execution-engine/execution-engine.d.ts → aigne/aigne.d.ts} +9 -12
  60. package/lib/dts/{execution-engine → aigne}/context.d.ts +31 -32
  61. package/lib/dts/aigne/index.d.ts +4 -0
  62. package/lib/dts/{execution-engine → aigne}/usage.d.ts +1 -1
  63. package/lib/dts/client/client.d.ts +19 -0
  64. package/lib/dts/index.d.ts +2 -1
  65. package/lib/dts/loader/agent-js.d.ts +2 -2
  66. package/lib/dts/loader/agent-yaml.d.ts +8 -5
  67. package/lib/dts/loader/index.d.ts +5 -5
  68. package/lib/dts/models/chat-model.d.ts +1 -1
  69. package/lib/dts/models/claude-chat-model.d.ts +3 -1
  70. package/lib/dts/models/openai-chat-model.d.ts +3 -3
  71. package/lib/dts/prompt/prompt-builder.d.ts +1 -1
  72. package/lib/dts/server/error.d.ts +4 -0
  73. package/lib/dts/server/server.d.ts +54 -0
  74. package/lib/dts/utils/camelize.d.ts +13 -0
  75. package/lib/dts/utils/event-stream.d.ts +11 -0
  76. package/lib/dts/utils/stream-utils.d.ts +10 -3
  77. package/lib/dts/utils/type-utils.d.ts +4 -2
  78. package/lib/esm/agents/agent.d.ts +21 -20
  79. package/lib/esm/agents/agent.js +29 -27
  80. package/lib/esm/agents/ai-agent.d.ts +9 -8
  81. package/lib/esm/agents/ai-agent.js +20 -14
  82. package/lib/esm/agents/mcp-agent.d.ts +10 -4
  83. package/lib/esm/agents/mcp-agent.js +12 -6
  84. package/lib/esm/agents/memory.d.ts +1 -1
  85. package/lib/esm/agents/team-agent.d.ts +28 -0
  86. package/lib/esm/agents/team-agent.js +89 -0
  87. package/lib/esm/agents/user-agent.d.ts +9 -10
  88. package/lib/esm/agents/user-agent.js +11 -14
  89. package/lib/{cjs/execution-engine/execution-engine.d.ts → esm/aigne/aigne.d.ts} +9 -12
  90. package/lib/esm/{execution-engine/execution-engine.js → aigne/aigne.js} +18 -18
  91. package/lib/esm/{execution-engine → aigne}/context.d.ts +31 -32
  92. package/lib/esm/{execution-engine → aigne}/context.js +28 -38
  93. package/lib/esm/aigne/index.d.ts +4 -0
  94. package/lib/esm/aigne/index.js +4 -0
  95. package/lib/esm/{execution-engine → aigne}/usage.d.ts +1 -1
  96. package/lib/esm/client/client.d.ts +19 -0
  97. package/lib/esm/client/client.js +45 -0
  98. package/lib/esm/index.d.ts +2 -1
  99. package/lib/esm/index.js +2 -1
  100. package/lib/esm/loader/agent-js.d.ts +2 -2
  101. package/lib/esm/loader/agent-js.js +4 -5
  102. package/lib/esm/loader/agent-yaml.d.ts +8 -5
  103. package/lib/esm/loader/agent-yaml.js +21 -2
  104. package/lib/esm/loader/index.d.ts +5 -5
  105. package/lib/esm/loader/index.js +8 -19
  106. package/lib/esm/models/chat-model.d.ts +1 -1
  107. package/lib/esm/models/claude-chat-model.d.ts +3 -1
  108. package/lib/esm/models/claude-chat-model.js +75 -60
  109. package/lib/esm/models/openai-chat-model.d.ts +3 -3
  110. package/lib/esm/models/openai-chat-model.js +1 -3
  111. package/lib/esm/prompt/prompt-builder.d.ts +1 -1
  112. package/lib/esm/prompt/prompt-builder.js +3 -3
  113. package/lib/esm/server/error.d.ts +4 -0
  114. package/lib/esm/server/error.js +7 -0
  115. package/lib/esm/server/server.d.ts +54 -0
  116. package/lib/esm/server/server.js +123 -0
  117. package/lib/esm/utils/camelize.d.ts +13 -0
  118. package/lib/esm/utils/camelize.js +10 -0
  119. package/lib/esm/utils/event-stream.d.ts +11 -0
  120. package/lib/esm/utils/event-stream.js +85 -0
  121. package/lib/esm/utils/mcp-utils.js +4 -1
  122. package/lib/esm/utils/stream-utils.d.ts +10 -3
  123. package/lib/esm/utils/stream-utils.js +49 -35
  124. package/lib/esm/utils/type-utils.d.ts +4 -2
  125. package/lib/esm/utils/type-utils.js +9 -2
  126. package/package.json +15 -5
  127. package/lib/cjs/execution-engine/index.d.ts +0 -4
  128. package/lib/cjs/execution-engine/utils.d.ts +0 -4
  129. package/lib/cjs/execution-engine/utils.js +0 -34
  130. package/lib/dts/execution-engine/index.d.ts +0 -4
  131. package/lib/dts/execution-engine/utils.d.ts +0 -4
  132. package/lib/esm/execution-engine/index.d.ts +0 -4
  133. package/lib/esm/execution-engine/index.js +0 -4
  134. package/lib/esm/execution-engine/utils.d.ts +0 -4
  135. package/lib/esm/execution-engine/utils.js +0 -30
  136. /package/lib/cjs/{execution-engine → aigne}/message-queue.d.ts +0 -0
  137. /package/lib/cjs/{execution-engine → aigne}/message-queue.js +0 -0
  138. /package/lib/cjs/{execution-engine → aigne}/usage.js +0 -0
  139. /package/lib/dts/{execution-engine → aigne}/message-queue.d.ts +0 -0
  140. /package/lib/esm/{execution-engine → aigne}/message-queue.d.ts +0 -0
  141. /package/lib/esm/{execution-engine → aigne}/message-queue.js +0 -0
  142. /package/lib/esm/{execution-engine → aigne}/usage.js +0 -0
@@ -1,12 +1,11 @@
1
1
  import EventEmitter from "node:events";
2
- import { Agent, type AgentCallOptions, type AgentProcessAsyncGenerator, type AgentResponse, type AgentResponseStream, type FunctionAgentFn, type Message } from "../agents/agent.js";
2
+ import { Agent, type AgentInvokeOptions, type AgentProcessAsyncGenerator, type AgentResponse, type AgentResponseStream, type Message } from "../agents/agent.js";
3
3
  import { UserAgent } from "../agents/user-agent.js";
4
4
  import type { ChatModel } from "../models/chat-model.js";
5
5
  import { type OmitPropertiesFromArrayFirstElement } from "../utils/type-utils.js";
6
6
  import type { Args, Listener, TypedEventEmitter } from "../utils/typed-event-emtter.js";
7
7
  import { type MessagePayload, MessageQueue, type MessageQueueListener, type Unsubscribe } from "./message-queue.js";
8
8
  import { type ContextLimits, type ContextUsage } from "./usage.js";
9
- export type Runnable<I extends Message = Message, O extends Message = Message> = Agent<I, O> | FunctionAgentFn;
10
9
  export interface AgentEvent {
11
10
  parentContextId?: string;
12
11
  contextId: string;
@@ -27,53 +26,53 @@ export interface ContextEventMap {
27
26
  export type ContextEmitEventMap = {
28
27
  [K in keyof ContextEventMap]: OmitPropertiesFromArrayFirstElement<ContextEventMap[K], "contextId" | "parentContextId" | "timestamp">;
29
28
  };
30
- export interface CallOptions extends AgentCallOptions {
29
+ export interface InvokeOptions extends AgentInvokeOptions {
31
30
  returnActiveAgent?: boolean;
32
31
  disableTransfer?: boolean;
33
32
  }
34
33
  export interface Context extends TypedEventEmitter<ContextEventMap, ContextEmitEventMap> {
35
34
  model?: ChatModel;
36
- tools?: Agent[];
35
+ skills?: Agent[];
37
36
  usage: ContextUsage;
38
37
  limits?: ContextLimits;
39
38
  status?: "normal" | "timeout";
40
39
  /**
41
- * Create a user agent to consistently call an agent
42
- * @param agent Agent to call
40
+ * Create a user agent to consistently invoke an agent
41
+ * @param agent Agent to invoke
43
42
  * @returns User agent
44
43
  */
45
- call<I extends Message, O extends Message>(agent: Runnable<I, O>): UserAgent<I, O>;
44
+ invoke<I extends Message, O extends Message>(agent: Agent<I, O>): UserAgent<I, O>;
46
45
  /**
47
- * Call an agent with a message and return the output and the active agent
48
- * @param agent Agent to call
46
+ * Invoke an agent with a message and return the output and the active agent
47
+ * @param agent Agent to invoke
49
48
  * @param message Message to pass to the agent
50
49
  * @param options.returnActiveAgent return the active agent
51
50
  * @param options.streaming return a stream of the output
52
51
  * @returns the output of the agent and the final active agent
53
52
  */
54
- call<I extends Message, O extends Message>(agent: Runnable<I, O>, message: I | string, options: CallOptions & {
53
+ invoke<I extends Message, O extends Message>(agent: Agent<I, O>, message: I | string, options: InvokeOptions & {
55
54
  returnActiveAgent: true;
56
55
  streaming?: false;
57
- }): Promise<[O, Runnable]>;
58
- call<I extends Message, O extends Message>(agent: Runnable<I, O>, message: I | string, options: CallOptions & {
56
+ }): Promise<[O, Agent]>;
57
+ invoke<I extends Message, O extends Message>(agent: Agent<I, O>, message: I | string, options: InvokeOptions & {
59
58
  returnActiveAgent: true;
60
59
  streaming: true;
61
- }): Promise<[AgentResponseStream<O>, Promise<Runnable>]>;
60
+ }): Promise<[AgentResponseStream<O>, Promise<Agent>]>;
62
61
  /**
63
- * Call an agent with a message
64
- * @param agent Agent to call
62
+ * Invoke an agent with a message
63
+ * @param agent Agent to invoke
65
64
  * @param message Message to pass to the agent
66
65
  * @returns the output of the agent
67
66
  */
68
- call<I extends Message, O extends Message>(agent: Runnable<I, O>, message: I | string, options?: CallOptions & {
67
+ invoke<I extends Message, O extends Message>(agent: Agent<I, O>, message: I | string, options?: InvokeOptions & {
69
68
  streaming?: false;
70
69
  }): Promise<O>;
71
- call<I extends Message, O extends Message>(agent: Runnable<I, O>, message: I | string, options: CallOptions & {
70
+ invoke<I extends Message, O extends Message>(agent: Agent<I, O>, message: I | string, options: InvokeOptions & {
72
71
  streaming: true;
73
72
  }): Promise<AgentResponseStream<O>>;
74
- call<I extends Message, O extends Message>(agent: Runnable<I, O>, message?: I | string, options?: CallOptions): UserAgent<I, O> | Promise<AgentResponse<O> | [AgentResponse<O>, Runnable]>;
73
+ invoke<I extends Message, O extends Message>(agent: Agent<I, O>, message?: I | string, options?: InvokeOptions): UserAgent<I, O> | Promise<AgentResponse<O> | [AgentResponse<O>, Agent]>;
75
74
  /**
76
- * Publish a message to a topic, the engine will call the listeners of the topic
75
+ * Publish a message to a topic, the aigne will invoke the listeners of the topic
77
76
  * @param topic topic name, or an array of topic names
78
77
  * @param payload message to publish
79
78
  */
@@ -96,21 +95,21 @@ export interface Context extends TypedEventEmitter<ContextEventMap, ContextEmitE
96
95
  }): Context;
97
96
  }
98
97
  export declare function createPublishMessage(message: string | Message, from?: Agent): Omit<MessagePayload, "context">;
99
- export declare class ExecutionContext implements Context {
100
- constructor(parent?: ConstructorParameters<typeof ExecutionContextInternal>[0]);
98
+ export declare class AIGNEContext implements Context {
99
+ constructor(parent?: ConstructorParameters<typeof AIGNEContextInternal>[0]);
101
100
  parentId?: string;
102
101
  id: string;
103
- readonly internal: ExecutionContextInternal;
102
+ readonly internal: AIGNEContextInternal;
104
103
  get model(): ChatModel | undefined;
105
- get tools(): Agent<Message, Message>[] | undefined;
104
+ get skills(): Agent<Message, Message>[] | undefined;
106
105
  get limits(): ContextLimits | undefined;
107
106
  get status(): "normal" | "timeout";
108
107
  get usage(): ContextUsage;
109
108
  newContext({ reset }?: {
110
109
  reset?: boolean;
111
- }): ExecutionContext;
112
- call: Context["call"];
113
- private onCallSuccess;
110
+ }): AIGNEContext;
111
+ invoke: Context["invoke"];
112
+ private onInvokeSuccess;
114
113
  publish: Context["publish"];
115
114
  subscribe: Context["subscribe"];
116
115
  unsubscribe: Context["unsubscribe"];
@@ -119,24 +118,24 @@ export declare class ExecutionContext implements Context {
119
118
  once<K extends keyof ContextEventMap>(eventName: K, listener: Listener<K, ContextEventMap>): this;
120
119
  off<K extends keyof ContextEventMap>(eventName: K, listener: Listener<K, ContextEventMap>): this;
121
120
  }
122
- declare class ExecutionContextInternal {
121
+ declare class AIGNEContextInternal {
123
122
  private readonly parent?;
124
- constructor(parent?: (Pick<Context, "model" | "tools" | "limits"> & {
123
+ constructor(parent?: (Pick<Context, "model" | "skills" | "limits"> & {
125
124
  messageQueue?: MessageQueue;
126
125
  }) | undefined);
127
126
  readonly messageQueue: MessageQueue;
128
127
  readonly events: EventEmitter<ContextEventMap>;
129
128
  get model(): ChatModel | undefined;
130
- get tools(): Agent<Message, Message>[] | undefined;
129
+ get skills(): Agent<Message, Message>[] | undefined;
131
130
  get limits(): ContextLimits | undefined;
132
131
  usage: ContextUsage;
133
132
  private abortController;
134
133
  private timer?;
135
134
  private initTimeout;
136
135
  get status(): "normal" | "timeout";
137
- call<I extends Message, O extends Message>(agent: Runnable<I, O>, input: I, context: Context, options?: CallOptions): AgentProcessAsyncGenerator<O & {
138
- __activeAgent__: Runnable;
136
+ invoke<I extends Message, O extends Message>(agent: Agent<I, O>, input: I, context: Context, options?: InvokeOptions): AgentProcessAsyncGenerator<O & {
137
+ __activeAgent__: Agent;
139
138
  }>;
140
- private callAgent;
139
+ private invokeAgent;
141
140
  }
142
141
  export {};
@@ -0,0 +1,4 @@
1
+ export * from "./context.js";
2
+ export * from "./aigne.js";
3
+ export * from "./message-queue.js";
4
+ export * from "./usage.js";
@@ -6,6 +6,6 @@ export interface ContextUsage {
6
6
  export declare function newEmptyContextUsage(): ContextUsage;
7
7
  export interface ContextLimits {
8
8
  maxTokens?: number;
9
- maxAgentCalls?: number;
9
+ maxAgentInvokes?: number;
10
10
  timeout?: number;
11
11
  }
@@ -0,0 +1,19 @@
1
+ import type { AgentInvokeOptions, AgentResponse, AgentResponseStream, Message } from "../agents/agent.js";
2
+ export interface AIGNEClientOptions {
3
+ url: string;
4
+ }
5
+ export interface AIGNEClientInvokeOptions extends AgentInvokeOptions {
6
+ fetchOptions?: Partial<RequestInit>;
7
+ }
8
+ export declare class AIGNEClient {
9
+ options: AIGNEClientOptions;
10
+ constructor(options: AIGNEClientOptions);
11
+ invoke<I extends Message, O extends Message>(agent: string, input: I, options: AIGNEClientInvokeOptions & {
12
+ streaming: true;
13
+ }): Promise<AgentResponseStream<O>>;
14
+ invoke<I extends Message, O extends Message>(agent: string, input: I, options?: AIGNEClientInvokeOptions & {
15
+ streaming?: false;
16
+ }): Promise<O>;
17
+ invoke<I extends Message, O extends Message>(agent: string, input: I, options?: AIGNEClientInvokeOptions): Promise<AgentResponse<O>>;
18
+ fetch(...args: Parameters<typeof globalThis.fetch>): Promise<Response>;
19
+ }
@@ -2,9 +2,10 @@ export * from "./agents/agent.js";
2
2
  export * from "./agents/ai-agent.js";
3
3
  export * from "./agents/mcp-agent.js";
4
4
  export * from "./agents/memory.js";
5
+ export * from "./agents/team-agent.js";
5
6
  export * from "./agents/types.js";
6
7
  export * from "./agents/user-agent.js";
7
- export * from "./execution-engine/index.js";
8
+ export * from "./aigne/index.js";
8
9
  export * from "./models/chat-model.js";
9
10
  export * from "./prompt/prompt-builder.js";
10
11
  export * from "./prompt/template.js";
@@ -4,12 +4,12 @@ export declare function loadAgentFromJsFile(path: string): Promise<{
4
4
  name: string;
5
5
  fn: (args_0: Message) => Message;
6
6
  description?: string | undefined;
7
- input_schema?: ZodObject<Record<string, ZodType<any, z.ZodTypeDef, any>>, z.UnknownKeysParam, z.ZodTypeAny, {
7
+ inputSchema?: ZodObject<Record<string, ZodType<any, z.ZodTypeDef, any>>, z.UnknownKeysParam, z.ZodTypeAny, {
8
8
  [x: string]: any;
9
9
  }, {
10
10
  [x: string]: any;
11
11
  }> | undefined;
12
- output_schema?: ZodObject<Record<string, ZodType<any, z.ZodTypeDef, any>>, z.UnknownKeysParam, z.ZodTypeAny, {
12
+ outputSchema?: ZodObject<Record<string, ZodType<any, z.ZodTypeDef, any>>, z.UnknownKeysParam, z.ZodTypeAny, {
13
13
  [x: string]: any;
14
14
  }, {
15
15
  [x: string]: any;
@@ -3,20 +3,23 @@ export declare function loadAgentFromYamlFile(path: string): Promise<{
3
3
  type: "ai";
4
4
  name: string;
5
5
  description?: string | undefined;
6
- tools?: string[] | undefined;
6
+ memory?: true | {
7
+ subscribeTopic?: string[] | undefined;
8
+ } | undefined;
9
+ skills?: string[] | undefined;
7
10
  instructions?: string | undefined;
8
- input_schema?: ZodObject<Record<string, ZodType<any, z.ZodTypeDef, any>>, z.UnknownKeysParam, z.ZodTypeAny, {
11
+ inputSchema?: ZodObject<Record<string, ZodType<any, z.ZodTypeDef, any>>, z.UnknownKeysParam, z.ZodTypeAny, {
9
12
  [x: string]: any;
10
13
  }, {
11
14
  [x: string]: any;
12
15
  }> | undefined;
13
- tool_choice?: "auto" | "none" | "required" | "router" | undefined;
14
- output_schema?: ZodObject<Record<string, ZodType<any, z.ZodTypeDef, any>>, z.UnknownKeysParam, z.ZodTypeAny, {
16
+ toolChoice?: "auto" | "none" | "required" | "router" | undefined;
17
+ outputSchema?: ZodObject<Record<string, ZodType<any, z.ZodTypeDef, any>>, z.UnknownKeysParam, z.ZodTypeAny, {
15
18
  [x: string]: any;
16
19
  }, {
17
20
  [x: string]: any;
18
21
  }> | undefined;
19
- output_key?: string | undefined;
22
+ outputKey?: string | undefined;
20
23
  } | {
21
24
  type: "mcp";
22
25
  url?: string | undefined;
@@ -7,7 +7,7 @@ export interface LoadOptions {
7
7
  export declare function load(options: LoadOptions): Promise<{
8
8
  model: ChatModel | undefined;
9
9
  agents: Agent<import("../agents/agent.js").Message, import("../agents/agent.js").Message>[];
10
- tools: Agent<import("../agents/agent.js").Message, import("../agents/agent.js").Message>[];
10
+ skills: Agent<import("../agents/agent.js").Message, import("../agents/agent.js").Message>[];
11
11
  description?: string | null | undefined;
12
12
  name?: string | null | undefined;
13
13
  chat_model?: {
@@ -61,11 +61,11 @@ declare const aigneFileSchema: z.ZodObject<{
61
61
  presence_penalty?: number | null | undefined;
62
62
  } | null | undefined>;
63
63
  agents: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodString, "many">>>;
64
- tools: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodString, "many">>>;
64
+ skills: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodString, "many">>>;
65
65
  }, "strip", z.ZodTypeAny, {
66
66
  description?: string | null | undefined;
67
- tools?: string[] | null | undefined;
68
67
  name?: string | null | undefined;
68
+ skills?: string[] | null | undefined;
69
69
  chat_model?: {
70
70
  name?: string | null | undefined;
71
71
  temperature?: number | null | undefined;
@@ -77,8 +77,8 @@ declare const aigneFileSchema: z.ZodObject<{
77
77
  agents?: string[] | null | undefined;
78
78
  }, {
79
79
  description?: string | null | undefined;
80
- tools?: string[] | null | undefined;
81
80
  name?: string | null | undefined;
81
+ skills?: string[] | null | undefined;
82
82
  chat_model?: string | {
83
83
  name?: string | null | undefined;
84
84
  temperature?: number | null | undefined;
@@ -91,8 +91,8 @@ declare const aigneFileSchema: z.ZodObject<{
91
91
  }>;
92
92
  export declare function loadAIGNEFile(path: string): Promise<{
93
93
  description?: string | null | undefined;
94
- tools?: string[] | null | undefined;
95
94
  name?: string | null | undefined;
95
+ skills?: string[] | null | undefined;
96
96
  chat_model?: {
97
97
  name?: string | null | undefined;
98
98
  temperature?: number | null | undefined;
@@ -1,5 +1,5 @@
1
1
  import { Agent, type Message } from "../agents/agent.js";
2
- import type { Context } from "../execution-engine/context.js";
2
+ import type { Context } from "../aigne/context.js";
3
3
  export declare abstract class ChatModel extends Agent<ChatModelInput, ChatModelOutput> {
4
4
  constructor();
5
5
  protected supportsParallelToolCalls: boolean;
@@ -1,5 +1,7 @@
1
1
  import Anthropic from "@anthropic-ai/sdk";
2
2
  import { z } from "zod";
3
+ import type { AgentInvokeOptions, AgentResponse } from "../agents/agent.js";
4
+ import type { Context } from "../aigne/context.js";
3
5
  import { ChatModel, type ChatModelInput, type ChatModelOptions, type ChatModelOutput } from "./chat-model.js";
4
6
  export interface ClaudeChatModelOptions {
5
7
  apiKey?: string;
@@ -60,7 +62,7 @@ export declare class ClaudeChatModel extends ChatModel {
60
62
  protected _client?: Anthropic;
61
63
  get client(): Anthropic;
62
64
  get modelOptions(): ChatModelOptions | undefined;
63
- process(input: ChatModelInput): Promise<ChatModelOutput>;
65
+ process(input: ChatModelInput, _context: Context, options?: AgentInvokeOptions): Promise<AgentResponse<ChatModelOutput>>;
64
66
  private extractResultFromClaudeStream;
65
67
  private requestStructuredOutput;
66
68
  }
@@ -1,8 +1,8 @@
1
1
  import OpenAI from "openai";
2
2
  import type { ChatCompletionMessageParam, ChatCompletionTool } from "openai/resources";
3
3
  import { z } from "zod";
4
- import type { AgentCallOptions, AgentResponse } from "../agents/agent.js";
5
- import type { Context } from "../execution-engine/context.js";
4
+ import type { AgentInvokeOptions, AgentResponse } from "../agents/agent.js";
5
+ import type { Context } from "../aigne/context.js";
6
6
  import { ChatModel, type ChatModelInput, type ChatModelInputMessage, type ChatModelInputTool, type ChatModelOptions, type ChatModelOutput, type Role } from "./chat-model.js";
7
7
  export interface OpenAIChatModelCapabilities {
8
8
  supportsNativeStructuredOutputs: boolean;
@@ -83,7 +83,7 @@ export declare class OpenAIChatModel extends ChatModel {
83
83
  protected supportsTemperature: boolean;
84
84
  get client(): OpenAI;
85
85
  get modelOptions(): ChatModelOptions | undefined;
86
- process(input: ChatModelInput, _context: Context, options?: AgentCallOptions): Promise<AgentResponse<ChatModelOutput>>;
86
+ process(input: ChatModelInput, _context: Context, options?: AgentInvokeOptions): Promise<AgentResponse<ChatModelOutput>>;
87
87
  private getParallelToolCalls;
88
88
  private getRunMessages;
89
89
  private getRunResponseFormat;
@@ -2,7 +2,7 @@ import type { GetPromptResult } from "@modelcontextprotocol/sdk/types.js";
2
2
  import { Agent, type Message } from "../agents/agent.js";
3
3
  import type { AIAgent } from "../agents/ai-agent.js";
4
4
  import type { AgentMemory } from "../agents/memory.js";
5
- import type { Context } from "../execution-engine/context.js";
5
+ import type { Context } from "../aigne/context.js";
6
6
  import type { ChatModel, ChatModelInput } from "../models/chat-model.js";
7
7
  import { ChatMessagesTemplate } from "./template.js";
8
8
  export declare const MESSAGE_KEY = "$message";
@@ -0,0 +1,4 @@
1
+ export declare class ServerError extends Error {
2
+ status: number;
3
+ constructor(status: number, message: string);
4
+ }
@@ -0,0 +1,54 @@
1
+ import { IncomingMessage, ServerResponse } from "node:http";
2
+ import { z } from "zod";
3
+ import type { AIGNE } from "../aigne/aigne.js";
4
+ export declare const invokePayloadSchema: z.ZodObject<{
5
+ agent: z.ZodString;
6
+ input: z.ZodRecord<z.ZodString, z.ZodUnknown>;
7
+ options: z.ZodOptional<z.ZodNullable<z.ZodObject<{
8
+ streaming: z.ZodOptional<z.ZodNullable<z.ZodBoolean>>;
9
+ }, "strip", z.ZodTypeAny, {
10
+ streaming?: boolean | null | undefined;
11
+ }, {
12
+ streaming?: boolean | null | undefined;
13
+ }>>>;
14
+ }, "strip", z.ZodTypeAny, {
15
+ agent: string;
16
+ input: Record<string, unknown>;
17
+ options?: {
18
+ streaming?: boolean | null | undefined;
19
+ } | null | undefined;
20
+ }, {
21
+ agent: string;
22
+ input: Record<string, unknown>;
23
+ options?: {
24
+ streaming?: boolean | null | undefined;
25
+ } | null | undefined;
26
+ }>;
27
+ export interface AIGNEServerOptions {
28
+ /**
29
+ * Maximum body size for the request.
30
+ * Only used when the request is a Node.js IncomingMessage and no `body` property is present.
31
+ * @default "4mb"
32
+ */
33
+ maximumBodySize?: string;
34
+ }
35
+ export declare class AIGNEServer {
36
+ engine: AIGNE;
37
+ options?: AIGNEServerOptions | undefined;
38
+ constructor(engine: AIGNE, options?: AIGNEServerOptions | undefined);
39
+ /**
40
+ * Invoke the agent with the given input.
41
+ * @param request - The request object, which can be a parsed JSON object, a Fetch API Request object, or a Node.js IncomingMessage object.
42
+ * @returns The web standard response, you can return it directly in supported frameworks like hono.
43
+ */
44
+ invoke(request: Record<string, unknown> | Request | IncomingMessage): Promise<Response>;
45
+ /**
46
+ * Invoke the agent with the given input, and write the SSE response to the Node.js ServerResponse.
47
+ * @param request - The request object, which can be a parsed JSON object, a Fetch API Request object, or a Node.js IncomingMessage object.
48
+ * @param response - The Node.js ServerResponse object to write the SSE response to.
49
+ */
50
+ invoke(request: Record<string, unknown> | Request | IncomingMessage, response: ServerResponse): Promise<void>;
51
+ _invoke(request: Record<string, unknown> | Request | IncomingMessage): Promise<Response>;
52
+ _prepareInput(request: Record<string, unknown> | Request | IncomingMessage): Promise<Record<string, unknown>>;
53
+ _writeResponse(response: Response, res: ServerResponse): Promise<void>;
54
+ }
@@ -0,0 +1,13 @@
1
+ export declare function customCamelize<T extends Record<string, unknown>, K extends KeyofUnion<T> = never>(obj: T, { shallowKeys }?: {
2
+ shallowKeys?: K[];
3
+ }): CustomCamelize<T, K>;
4
+ type KeyofUnion<U> = U extends Record<string, unknown> ? keyof U : never;
5
+ type CamelCase<S extends string> = S extends `${infer P1}_${infer P2}${infer P3}` ? `${P1}${Uppercase<P2>}${CamelCase<P3>}` : S;
6
+ declare const _unique: unique symbol;
7
+ type _never = typeof _unique;
8
+ type ExtractTypeFromUnion<T, U> = Extract<T, U> extends never ? _never : Extract<T, U> extends Array<infer E> ? Array<E> : U;
9
+ type ExtractTypeWithConstFromUnion<T, U> = Exclude<T, Exclude<T, U>>;
10
+ export type CustomCamelize<T, ShallowKeys extends KeyofUnion<T> | undefined = undefined> = ExtractTypeFromUnion<T, never> extends never ? never : ExtractTypeFromUnion<T, Date> extends Date ? ExtractTypeWithConstFromUnion<T, Date> | CustomCamelize<Exclude<T, Date>> : ExtractTypeFromUnion<T, RegExp> extends RegExp ? ExtractTypeWithConstFromUnion<T, RegExp> | CustomCamelize<Exclude<T, RegExp>> : ExtractTypeFromUnion<T, Array<unknown>> extends Array<infer U> ? Array<CustomCamelize<U>> | CustomCamelize<Exclude<T, Array<U>>> : ExtractTypeFromUnion<T, Function> extends Function ? ExtractTypeWithConstFromUnion<T, Function> | CustomCamelize<Exclude<T, Function>> : ExtractTypeFromUnion<T, object> extends object ? {
11
+ [K in keyof T as Uncapitalize<CamelCase<string & K>>]: K extends Exclude<ShallowKeys, undefined> ? T[K] : CustomCamelize<T[K]>;
12
+ } : T;
13
+ export {};
@@ -0,0 +1,11 @@
1
+ import type { AgentResponseChunk, AgentResponseStream, Message } from "../agents/agent.js";
2
+ export declare class EventStreamParser<T> extends TransformStream<string, T | Error> {
3
+ constructor();
4
+ }
5
+ export declare class AgentResponseStreamParser<O extends Message> extends TransformStream<AgentResponseChunk<O> | Error, AgentResponseChunk<O>> {
6
+ private json;
7
+ constructor();
8
+ }
9
+ export declare class AgentResponseStreamSSE<O extends Message> extends ReadableStream<string> {
10
+ constructor(stream: AgentResponseStream<O>);
11
+ }
@@ -1,4 +1,5 @@
1
- import type { AgentProcessAsyncGenerator, AgentResponseChunk, AgentResponseStream, Message } from "../agents/agent.js";
1
+ import { type AgentProcessAsyncGenerator, type AgentResponseChunk, type AgentResponseStream, type Message } from "../agents/agent.js";
2
+ import type { MESSAGE_KEY } from "../prompt/prompt-builder.js";
2
3
  import { type PromiseOrValue } from "./type-utils.js";
3
4
  export declare function objectToAgentResponseStream<T extends Message>(json: T): AgentResponseStream<T>;
4
5
  export declare function mergeAgentResponseChunk<T extends Message>(output: T, chunk: AgentResponseChunk<T>): T;
@@ -10,6 +11,12 @@ export declare function onAgentResponseStreamEnd<T extends Message>(stream: Agen
10
11
  }): ReadableStream<any>;
11
12
  export declare function isAsyncGenerator<T extends AsyncGenerator>(value: AsyncGenerator | unknown): value is T;
12
13
  export declare function arrayToAgentProcessAsyncGenerator<T extends Message>(chunks: (AgentResponseChunk<T> | Error)[], result?: Partial<T>): AgentProcessAsyncGenerator<T>;
13
- export declare function arrayToAgentResponseStream<T>(chunks: (AgentResponseChunk<T> | Error)[]): AgentResponseStream<T>;
14
- 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[]>;
15
21
  export declare function readableStreamToAsyncIterator<T>(stream: ReadableStream<T>): AsyncIterable<T>;
22
+ export declare function stringToAgentResponseStream(str: string, key?: "text" | typeof MESSAGE_KEY | string): AgentResponseStream<Message>;
@@ -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,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,52 +38,53 @@ 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
+ export declare function isEmptyChunk<T>(chunk: AgentResponseChunk<T>): boolean;
75
76
  export interface AgentResponseDelta<T> {
76
77
  delta: {
77
78
  text?: Partial<{
78
79
  [key in keyof T as Extract<T[key], string> extends string ? key : never]: string;
79
- }> | {
80
+ }> | Partial<{
80
81
  [key: string]: string;
81
- };
82
- json?: Partial<T>;
82
+ }>;
83
+ json?: Partial<T | TransferAgentOutput>;
83
84
  };
84
85
  }
85
- export type AgentProcessAsyncGenerator<O extends Message> = AsyncGenerator<AgentResponseChunk<O>, Partial<O> | undefined | void>;
86
- 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;
87
88
  export type AgentInputOutputSchema<I extends Message = Message> = ZodType<I> | ((agent: Agent) => ZodType<I>);
88
89
  export interface FunctionAgentOptions<I extends Message = Message, O extends Message = Message> extends AgentOptions<I, O> {
89
90
  fn?: FunctionAgentFn<I, O>;
@@ -92,6 +93,6 @@ export declare class FunctionAgent<I extends Message = Message, O extends Messag
92
93
  static from<I extends Message, O extends Message>(options: FunctionAgentOptions<I, O> | FunctionAgentFn<I, O>): FunctionAgent<I, O>;
93
94
  constructor(options: FunctionAgentOptions<I, O>);
94
95
  fn: FunctionAgentFn<I, O>;
95
- process(input: I, context: Context, options?: AgentCallOptions): Promise<AgentResponse<O | TransferAgentOutput>>;
96
+ process(input: I, context: Context): PromiseOrValue<AgentProcessResult<O>>;
96
97
  }
97
- 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>>;