@aigne/core 1.61.1-beta → 1.62.0-beta.1

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/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # Changelog
2
2
 
3
+ ## [1.62.0-beta.1](https://github.com/AIGNE-io/aigne-framework/compare/core-v1.62.0-beta...core-v1.62.0-beta.1) (2025-10-01)
4
+
5
+
6
+ ### Bug Fixes
7
+
8
+ * prevent template rendering for agent and tool messages ([#572](https://github.com/AIGNE-io/aigne-framework/issues/572)) ([859687e](https://github.com/AIGNE-io/aigne-framework/commit/859687e499b07ffebced8b2cd89d4af676f6a462))
9
+
10
+ ## [1.62.0-beta](https://github.com/AIGNE-io/aigne-framework/compare/core-v1.61.1-beta...core-v1.62.0-beta) (2025-09-30)
11
+
12
+
13
+ ### Features
14
+
15
+ * **cli:** support define nested commands for sub apps ([#568](https://github.com/AIGNE-io/aigne-framework/issues/568)) ([0693b80](https://github.com/AIGNE-io/aigne-framework/commit/0693b807e0f8d335010e6ad00763b07cf095e65b))
16
+
3
17
  ## [1.61.1-beta](https://github.com/AIGNE-io/aigne-framework/compare/core-v1.61.0...core-v1.61.1-beta) (2025-09-29)
4
18
 
5
19
 
@@ -6,6 +6,7 @@ import type { UserAgent } from "../agents/user-agent.js";
6
6
  import { type LoadOptions } from "../loader/index.js";
7
7
  import { AIGNEContext, type Context, type InvokeOptions, type UserContext } from "./context.js";
8
8
  import { type MessagePayload, MessageQueue, type MessageQueueListener, type Unsubscribe } from "./message-queue.js";
9
+ import type { AIGNECLIAgents } from "./type.js";
9
10
  import type { ContextLimits } from "./usage.js";
10
11
  /**
11
12
  * Options for the AIGNE class.
@@ -43,10 +44,7 @@ export interface AIGNEOptions {
43
44
  mcpServer?: {
44
45
  agents?: Agent[];
45
46
  };
46
- cli?: {
47
- chat?: Agent;
48
- agents?: Agent[];
49
- };
47
+ cli?: AIGNECLIAgents;
50
48
  /**
51
49
  * Limits for the AIGNE instance, such as timeout, max tokens, max invocations, etc.
52
50
  */
@@ -133,12 +131,7 @@ export declare class AIGNE<U extends UserContext = UserContext> {
133
131
  [key: string]: Agent<any, any>;
134
132
  };
135
133
  };
136
- readonly cli: {
137
- chat: Agent | undefined;
138
- agents: Agent<any, any>[] & {
139
- [key: string]: Agent<any, any>;
140
- };
141
- };
134
+ readonly cli: AIGNECLIAgents;
142
135
  /**
143
136
  * Observer for the AIGNE instance.
144
137
  */
@@ -63,10 +63,7 @@ class AIGNE {
63
63
  this.addAgent(...options.agents);
64
64
  if (options?.mcpServer?.agents?.length)
65
65
  this.mcpServer.agents.push(...options.mcpServer.agents);
66
- if (options?.cli?.agents?.length)
67
- this.cli.agents.push(...options.cli.agents);
68
- if (options?.cli?.chat)
69
- this.cli.chat = options.cli.chat;
66
+ this.cli = options?.cli ?? {};
70
67
  this.observer?.serve();
71
68
  this.initProcessExitHandler();
72
69
  }
@@ -113,10 +110,7 @@ class AIGNE {
113
110
  mcpServer = {
114
111
  agents: (0, type_utils_js_1.createAccessorArray)([], (arr, name) => arr.find((i) => i.name === name)),
115
112
  };
116
- cli = {
117
- chat: undefined,
118
- agents: (0, type_utils_js_1.createAccessorArray)([], (arr, name) => arr.find((i) => i.name === name)),
119
- };
113
+ cli = {};
120
114
  /**
121
115
  * Observer for the AIGNE instance.
122
116
  */
@@ -0,0 +1,12 @@
1
+ import type { Agent } from "../agents/agent.ts";
2
+ export interface AIGNECLIAgents {
3
+ chat?: Agent;
4
+ agents?: AIGNECLIAgent[];
5
+ }
6
+ export interface AIGNECLIAgent {
7
+ agent?: Agent;
8
+ name?: string;
9
+ alias?: string[];
10
+ description?: string;
11
+ agents?: AIGNECLIAgent[];
12
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,4 +1,4 @@
1
- import { z } from "zod";
1
+ import { type ZodType, z } from "zod";
2
2
  import { Agent, type AgentOptions } from "../agents/agent.js";
3
3
  import type { ChatModel } from "../agents/chat-model.js";
4
4
  import type { ImageModel } from "../agents/image-model.js";
@@ -14,10 +14,17 @@ export interface LoadOptions {
14
14
  }
15
15
  export declare function load(path: string, options?: LoadOptions): Promise<AIGNEOptions>;
16
16
  export declare function loadAgent(path: string, options?: LoadOptions, agentOptions?: AgentOptions): Promise<Agent>;
17
+ type CliAgent = string | {
18
+ url?: string;
19
+ name?: string;
20
+ alias?: string[];
21
+ description?: string;
22
+ agents?: CliAgent[];
23
+ };
17
24
  declare const aigneFileSchema: z.ZodObject<{
18
- name: z.ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
19
- description: z.ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
20
- model: z.ZodType<{
25
+ name: ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
26
+ description: ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
27
+ model: ZodType<{
21
28
  model?: string | undefined;
22
29
  temperature?: number | undefined;
23
30
  topP?: number | undefined;
@@ -30,23 +37,23 @@ declare const aigneFileSchema: z.ZodObject<{
30
37
  frequencyPenalty?: number | undefined;
31
38
  presencePenalty?: number | undefined;
32
39
  } | undefined>;
33
- imageModel: z.ZodType<{
40
+ imageModel: ZodType<{
34
41
  model?: string | undefined;
35
42
  } | undefined, z.ZodTypeDef, {
36
43
  model?: string | undefined;
37
44
  } | undefined>;
38
- agents: z.ZodType<string[] | undefined, z.ZodTypeDef, string[] | undefined>;
39
- skills: z.ZodType<string[] | undefined, z.ZodTypeDef, string[] | undefined>;
40
- mcpServer: z.ZodType<{
45
+ agents: ZodType<string[] | undefined, z.ZodTypeDef, string[] | undefined>;
46
+ skills: ZodType<string[] | undefined, z.ZodTypeDef, string[] | undefined>;
47
+ mcpServer: ZodType<{
41
48
  agents?: string[] | undefined;
42
49
  } | undefined, z.ZodTypeDef, {
43
50
  agents?: string[] | undefined;
44
51
  } | undefined>;
45
- cli: z.ZodType<{
46
- agents?: string[] | undefined;
52
+ cli: ZodType<{
53
+ agents?: CliAgent[] | undefined;
47
54
  chat?: string | undefined;
48
55
  } | undefined, z.ZodTypeDef, {
49
- agents?: string[] | undefined;
56
+ agents?: CliAgent[] | undefined;
50
57
  chat?: string | undefined;
51
58
  } | undefined>;
52
59
  }, "strip", z.ZodTypeAny, {
@@ -68,7 +75,7 @@ declare const aigneFileSchema: z.ZodObject<{
68
75
  agents?: string[] | undefined;
69
76
  } | undefined;
70
77
  cli?: {
71
- agents?: string[] | undefined;
78
+ agents?: CliAgent[] | undefined;
72
79
  chat?: string | undefined;
73
80
  } | undefined;
74
81
  }, {
@@ -90,7 +97,7 @@ declare const aigneFileSchema: z.ZodObject<{
90
97
  agents?: string[] | undefined;
91
98
  } | undefined;
92
99
  cli?: {
93
- agents?: string[] | undefined;
100
+ agents?: CliAgent[] | undefined;
94
101
  chat?: string | undefined;
95
102
  } | undefined;
96
103
  }>;
@@ -21,12 +21,27 @@ const schema_js_1 = require("./schema.js");
21
21
  const AIGNE_FILE_NAME = ["aigne.yaml", "aigne.yml"];
22
22
  async function load(path, options = {}) {
23
23
  const { aigne, rootDir } = await loadAIGNEFile(path);
24
- const allAgentPaths = new Set((0, type_utils_js_1.flat)(aigne.agents, aigne.skills, aigne.mcpServer?.agents, aigne.cli?.agents, aigne.cli?.chat).map((i) => index_js_1.nodejs.path.join(rootDir, i)));
24
+ const flatCliAgents = (cliAgent) => {
25
+ if (typeof cliAgent === "string")
26
+ return [cliAgent];
27
+ return (0, type_utils_js_1.flat)(cliAgent.url, cliAgent.agents?.flatMap(flatCliAgents));
28
+ };
29
+ const allAgentPaths = new Set((0, type_utils_js_1.flat)(aigne.agents, aigne.skills, aigne.mcpServer?.agents, aigne.cli?.chat, aigne.cli?.agents?.flatMap((i) => (typeof i === "string" ? i : flatCliAgents(i)))).map((i) => index_js_1.nodejs.path.join(rootDir, i)));
25
30
  const allAgents = {};
26
31
  for (const path of allAgentPaths) {
27
32
  allAgents[path] = await loadAgent(path, options);
28
33
  }
29
- const pickAgents = (paths) => paths.map((filename) => allAgents[index_js_1.nodejs.path.join(rootDir, filename)]).filter(type_utils_js_1.isNonNullable);
34
+ const pickAgent = (path) => allAgents[index_js_1.nodejs.path.join(rootDir, path)];
35
+ const pickAgents = (paths) => paths.map((filename) => pickAgent(filename)).filter(type_utils_js_1.isNonNullable);
36
+ const mapCliAgents = (cliAgent) => {
37
+ if (typeof cliAgent === "string")
38
+ return { agent: pickAgent(cliAgent) };
39
+ return {
40
+ ...cliAgent,
41
+ agent: cliAgent.url ? pickAgent(cliAgent.url) : undefined,
42
+ agents: cliAgent.agents?.map(mapCliAgents),
43
+ };
44
+ };
30
45
  return {
31
46
  ...aigne,
32
47
  rootDir,
@@ -41,7 +56,7 @@ async function load(path, options = {}) {
41
56
  },
42
57
  cli: {
43
58
  chat: aigne.cli?.chat ? pickAgents([aigne.cli.chat])[0] : undefined,
44
- agents: pickAgents(aigne.cli?.agents ?? []),
59
+ agents: aigne.cli?.agents?.map(mapCliAgents),
45
60
  },
46
61
  };
47
62
  }
@@ -186,6 +201,16 @@ async function loadMemory(memories, provider, options) {
186
201
  throw new Error(`Unsupported memory: ${provider}`);
187
202
  return new M(options);
188
203
  }
204
+ const cliAgentSchema = zod_1.z.union([
205
+ zod_1.z.string(),
206
+ zod_1.z.object({
207
+ url: (0, schema_js_1.optionalize)(zod_1.z.string()),
208
+ name: (0, schema_js_1.optionalize)(zod_1.z.string()),
209
+ alias: (0, schema_js_1.optionalize)(zod_1.z.array(zod_1.z.string())),
210
+ description: (0, schema_js_1.optionalize)(zod_1.z.string()),
211
+ agents: (0, schema_js_1.optionalize)(zod_1.z.array(zod_1.z.lazy(() => cliAgentSchema))),
212
+ }),
213
+ ]);
189
214
  const aigneFileSchema = (0, schema_js_1.camelizeSchema)(zod_1.z.object({
190
215
  name: (0, schema_js_1.optionalize)(zod_1.z.string()),
191
216
  description: (0, schema_js_1.optionalize)(zod_1.z.string()),
@@ -198,7 +223,7 @@ const aigneFileSchema = (0, schema_js_1.camelizeSchema)(zod_1.z.object({
198
223
  })),
199
224
  cli: (0, schema_js_1.optionalize)(zod_1.z.object({
200
225
  chat: (0, schema_js_1.optionalize)(zod_1.z.string()),
201
- agents: (0, schema_js_1.optionalize)(zod_1.z.array(zod_1.z.string())),
226
+ agents: (0, schema_js_1.optionalize)(zod_1.z.array(cliAgentSchema)),
202
227
  })),
203
228
  }));
204
229
  async function loadAIGNEFile(path) {
@@ -40,31 +40,22 @@ export declare class AgentMessageTemplate extends ChatMessageTemplate {
40
40
  toolCalls?: ChatModelOutputToolCall[] | undefined;
41
41
  static from(template?: ChatModelInputMessage["content"], toolCalls?: ChatModelOutputToolCall[], name?: string, options?: FormatOptions): AgentMessageTemplate;
42
42
  constructor(content?: ChatModelInputMessage["content"], toolCalls?: ChatModelOutputToolCall[] | undefined, name?: string, options?: FormatOptions);
43
- format(variables?: Record<string, unknown>, options?: FormatOptions): Promise<{
43
+ format(_variables?: Record<string, unknown>, _options?: FormatOptions): Promise<{
44
+ role: "agent" | "system" | "user" | "tool";
45
+ name: string | undefined;
46
+ content: ChatModelInputMessageContent | undefined;
44
47
  toolCalls: ChatModelOutputToolCall[] | undefined;
45
- role: import("../agents/chat-model.js").Role;
46
- content?: ChatModelInputMessageContent;
47
- toolCallId?: string;
48
- name?: string;
49
48
  }>;
50
49
  }
51
50
  export declare class ToolMessageTemplate extends ChatMessageTemplate {
52
51
  toolCallId: string;
53
52
  static from(content: object | string, toolCallId: string, name?: string, options?: FormatOptions): ToolMessageTemplate;
54
53
  constructor(content: object | string, toolCallId: string, name?: string, options?: FormatOptions);
55
- format(variables?: Record<string, unknown>, options?: FormatOptions): Promise<{
54
+ format(_variables?: Record<string, unknown>, _options?: FormatOptions): Promise<{
55
+ role: "agent" | "system" | "user" | "tool";
56
+ name: string | undefined;
57
+ content: ChatModelInputMessageContent | undefined;
56
58
  toolCallId: string;
57
- role: import("../agents/chat-model.js").Role;
58
- content?: ChatModelInputMessageContent;
59
- toolCalls?: {
60
- id: string;
61
- type: "function";
62
- function: {
63
- name: string;
64
- arguments: import("../index.js").Message;
65
- };
66
- }[];
67
- name?: string;
68
59
  }>;
69
60
  }
70
61
  export declare class ChatMessagesTemplate {
@@ -125,9 +125,12 @@ class AgentMessageTemplate extends ChatMessageTemplate {
125
125
  super("agent", content, name, options);
126
126
  this.toolCalls = toolCalls;
127
127
  }
128
- async format(variables, options) {
128
+ async format(_variables, _options) {
129
129
  return {
130
- ...(await super.format(variables, options)),
130
+ role: this.role,
131
+ name: this.name,
132
+ // NOTE: agent message should not rendered by template
133
+ content: this.content,
131
134
  toolCalls: this.toolCalls,
132
135
  };
133
136
  }
@@ -144,9 +147,12 @@ class ToolMessageTemplate extends ChatMessageTemplate {
144
147
  : JSON.stringify(content, (_, value) => typeof value === "bigint" ? value.toString() : value), name, options);
145
148
  this.toolCallId = toolCallId;
146
149
  }
147
- async format(variables, options) {
150
+ async format(_variables, _options) {
148
151
  return {
149
- ...(await super.format(variables, options)),
152
+ role: this.role,
153
+ name: this.name,
154
+ // NOTE: tool result should not rendered by template
155
+ content: this.content,
150
156
  toolCallId: this.toolCallId,
151
157
  };
152
158
  }
@@ -1,2 +1,12 @@
1
1
  import type { AgentHooks } from "../agents/agent.ts";
2
+ import type { AIGNECLIAgents } from "../aigne/type.js";
2
3
  export declare function sortHooks(hooks: AgentHooks[]): AgentHooks[];
4
+ export interface CLIAgent<T> {
5
+ agent?: T;
6
+ name?: string;
7
+ alias?: string[];
8
+ description?: string;
9
+ agents?: CLIAgent<T>[];
10
+ }
11
+ export declare function mapCliAgent<A, O>({ agent, agents, ...input }: CLIAgent<A>, transform: (input: A) => O): CLIAgent<O>;
12
+ export declare function findCliAgent(cli: AIGNECLIAgents, parent: string[] | "*", name: string): import("../agents/agent.ts").Agent<any, any> | undefined;
@@ -1,9 +1,53 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.sortHooks = sortHooks;
4
+ exports.mapCliAgent = mapCliAgent;
5
+ exports.findCliAgent = findCliAgent;
4
6
  const priorities = ["high", "medium", "low"];
5
7
  function sortHooks(hooks) {
6
8
  return hooks
7
9
  .slice(0)
8
10
  .sort(({ priority: a = "low" }, { priority: b = "low" }) => a === b ? 0 : priorities.indexOf(a) - priorities.indexOf(b));
9
11
  }
12
+ function mapCliAgent({ agent, agents, ...input }, transform) {
13
+ return {
14
+ ...input,
15
+ agent: agent ? transform(agent) : undefined,
16
+ agents: agents?.map((item) => mapCliAgent(item, transform)),
17
+ };
18
+ }
19
+ function findCliAgent(cli, parent, name) {
20
+ if (parent === "*")
21
+ return findCliAgentRecursive(cli, name);
22
+ let currentAgents = cli.agents ?? [];
23
+ for (const name of parent) {
24
+ const found = currentAgents.find((i) => (i.name || i.agent?.name) === name);
25
+ if (!found)
26
+ throw new Error(`Agent ${name} not found in parent path ${parent.join(" -> ")}`);
27
+ if (found.agents)
28
+ currentAgents = found.agents;
29
+ else
30
+ currentAgents = [];
31
+ }
32
+ return currentAgents.find((i) => (i.name || i.agent?.name) === name)?.agent;
33
+ }
34
+ function findCliAgentRecursive(agents, name) {
35
+ if (agents.chat?.name === name) {
36
+ return agents.chat;
37
+ }
38
+ if (agents.agents) {
39
+ const queue = [...agents.agents];
40
+ while (queue.length > 0) {
41
+ const c = queue.shift();
42
+ if (!c)
43
+ break;
44
+ if ((c.name || c.agent?.name) === name) {
45
+ return c.agent;
46
+ }
47
+ if (c.agents) {
48
+ queue.push(...c.agents);
49
+ }
50
+ }
51
+ }
52
+ return undefined;
53
+ }
@@ -6,6 +6,7 @@ import type { UserAgent } from "../agents/user-agent.js";
6
6
  import { type LoadOptions } from "../loader/index.js";
7
7
  import { AIGNEContext, type Context, type InvokeOptions, type UserContext } from "./context.js";
8
8
  import { type MessagePayload, MessageQueue, type MessageQueueListener, type Unsubscribe } from "./message-queue.js";
9
+ import type { AIGNECLIAgents } from "./type.js";
9
10
  import type { ContextLimits } from "./usage.js";
10
11
  /**
11
12
  * Options for the AIGNE class.
@@ -43,10 +44,7 @@ export interface AIGNEOptions {
43
44
  mcpServer?: {
44
45
  agents?: Agent[];
45
46
  };
46
- cli?: {
47
- chat?: Agent;
48
- agents?: Agent[];
49
- };
47
+ cli?: AIGNECLIAgents;
50
48
  /**
51
49
  * Limits for the AIGNE instance, such as timeout, max tokens, max invocations, etc.
52
50
  */
@@ -133,12 +131,7 @@ export declare class AIGNE<U extends UserContext = UserContext> {
133
131
  [key: string]: Agent<any, any>;
134
132
  };
135
133
  };
136
- readonly cli: {
137
- chat: Agent | undefined;
138
- agents: Agent<any, any>[] & {
139
- [key: string]: Agent<any, any>;
140
- };
141
- };
134
+ readonly cli: AIGNECLIAgents;
142
135
  /**
143
136
  * Observer for the AIGNE instance.
144
137
  */
@@ -0,0 +1,12 @@
1
+ import type { Agent } from "../agents/agent.ts";
2
+ export interface AIGNECLIAgents {
3
+ chat?: Agent;
4
+ agents?: AIGNECLIAgent[];
5
+ }
6
+ export interface AIGNECLIAgent {
7
+ agent?: Agent;
8
+ name?: string;
9
+ alias?: string[];
10
+ description?: string;
11
+ agents?: AIGNECLIAgent[];
12
+ }
@@ -1,4 +1,4 @@
1
- import { z } from "zod";
1
+ import { type ZodType, z } from "zod";
2
2
  import { Agent, type AgentOptions } from "../agents/agent.js";
3
3
  import type { ChatModel } from "../agents/chat-model.js";
4
4
  import type { ImageModel } from "../agents/image-model.js";
@@ -14,10 +14,17 @@ export interface LoadOptions {
14
14
  }
15
15
  export declare function load(path: string, options?: LoadOptions): Promise<AIGNEOptions>;
16
16
  export declare function loadAgent(path: string, options?: LoadOptions, agentOptions?: AgentOptions): Promise<Agent>;
17
+ type CliAgent = string | {
18
+ url?: string;
19
+ name?: string;
20
+ alias?: string[];
21
+ description?: string;
22
+ agents?: CliAgent[];
23
+ };
17
24
  declare const aigneFileSchema: z.ZodObject<{
18
- name: z.ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
19
- description: z.ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
20
- model: z.ZodType<{
25
+ name: ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
26
+ description: ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
27
+ model: ZodType<{
21
28
  model?: string | undefined;
22
29
  temperature?: number | undefined;
23
30
  topP?: number | undefined;
@@ -30,23 +37,23 @@ declare const aigneFileSchema: z.ZodObject<{
30
37
  frequencyPenalty?: number | undefined;
31
38
  presencePenalty?: number | undefined;
32
39
  } | undefined>;
33
- imageModel: z.ZodType<{
40
+ imageModel: ZodType<{
34
41
  model?: string | undefined;
35
42
  } | undefined, z.ZodTypeDef, {
36
43
  model?: string | undefined;
37
44
  } | undefined>;
38
- agents: z.ZodType<string[] | undefined, z.ZodTypeDef, string[] | undefined>;
39
- skills: z.ZodType<string[] | undefined, z.ZodTypeDef, string[] | undefined>;
40
- mcpServer: z.ZodType<{
45
+ agents: ZodType<string[] | undefined, z.ZodTypeDef, string[] | undefined>;
46
+ skills: ZodType<string[] | undefined, z.ZodTypeDef, string[] | undefined>;
47
+ mcpServer: ZodType<{
41
48
  agents?: string[] | undefined;
42
49
  } | undefined, z.ZodTypeDef, {
43
50
  agents?: string[] | undefined;
44
51
  } | undefined>;
45
- cli: z.ZodType<{
46
- agents?: string[] | undefined;
52
+ cli: ZodType<{
53
+ agents?: CliAgent[] | undefined;
47
54
  chat?: string | undefined;
48
55
  } | undefined, z.ZodTypeDef, {
49
- agents?: string[] | undefined;
56
+ agents?: CliAgent[] | undefined;
50
57
  chat?: string | undefined;
51
58
  } | undefined>;
52
59
  }, "strip", z.ZodTypeAny, {
@@ -68,7 +75,7 @@ declare const aigneFileSchema: z.ZodObject<{
68
75
  agents?: string[] | undefined;
69
76
  } | undefined;
70
77
  cli?: {
71
- agents?: string[] | undefined;
78
+ agents?: CliAgent[] | undefined;
72
79
  chat?: string | undefined;
73
80
  } | undefined;
74
81
  }, {
@@ -90,7 +97,7 @@ declare const aigneFileSchema: z.ZodObject<{
90
97
  agents?: string[] | undefined;
91
98
  } | undefined;
92
99
  cli?: {
93
- agents?: string[] | undefined;
100
+ agents?: CliAgent[] | undefined;
94
101
  chat?: string | undefined;
95
102
  } | undefined;
96
103
  }>;
@@ -40,31 +40,22 @@ export declare class AgentMessageTemplate extends ChatMessageTemplate {
40
40
  toolCalls?: ChatModelOutputToolCall[] | undefined;
41
41
  static from(template?: ChatModelInputMessage["content"], toolCalls?: ChatModelOutputToolCall[], name?: string, options?: FormatOptions): AgentMessageTemplate;
42
42
  constructor(content?: ChatModelInputMessage["content"], toolCalls?: ChatModelOutputToolCall[] | undefined, name?: string, options?: FormatOptions);
43
- format(variables?: Record<string, unknown>, options?: FormatOptions): Promise<{
43
+ format(_variables?: Record<string, unknown>, _options?: FormatOptions): Promise<{
44
+ role: "agent" | "system" | "user" | "tool";
45
+ name: string | undefined;
46
+ content: ChatModelInputMessageContent | undefined;
44
47
  toolCalls: ChatModelOutputToolCall[] | undefined;
45
- role: import("../agents/chat-model.js").Role;
46
- content?: ChatModelInputMessageContent;
47
- toolCallId?: string;
48
- name?: string;
49
48
  }>;
50
49
  }
51
50
  export declare class ToolMessageTemplate extends ChatMessageTemplate {
52
51
  toolCallId: string;
53
52
  static from(content: object | string, toolCallId: string, name?: string, options?: FormatOptions): ToolMessageTemplate;
54
53
  constructor(content: object | string, toolCallId: string, name?: string, options?: FormatOptions);
55
- format(variables?: Record<string, unknown>, options?: FormatOptions): Promise<{
54
+ format(_variables?: Record<string, unknown>, _options?: FormatOptions): Promise<{
55
+ role: "agent" | "system" | "user" | "tool";
56
+ name: string | undefined;
57
+ content: ChatModelInputMessageContent | undefined;
56
58
  toolCallId: string;
57
- role: import("../agents/chat-model.js").Role;
58
- content?: ChatModelInputMessageContent;
59
- toolCalls?: {
60
- id: string;
61
- type: "function";
62
- function: {
63
- name: string;
64
- arguments: import("../index.js").Message;
65
- };
66
- }[];
67
- name?: string;
68
59
  }>;
69
60
  }
70
61
  export declare class ChatMessagesTemplate {
@@ -1,2 +1,12 @@
1
1
  import type { AgentHooks } from "../agents/agent.ts";
2
+ import type { AIGNECLIAgents } from "../aigne/type.js";
2
3
  export declare function sortHooks(hooks: AgentHooks[]): AgentHooks[];
4
+ export interface CLIAgent<T> {
5
+ agent?: T;
6
+ name?: string;
7
+ alias?: string[];
8
+ description?: string;
9
+ agents?: CLIAgent<T>[];
10
+ }
11
+ export declare function mapCliAgent<A, O>({ agent, agents, ...input }: CLIAgent<A>, transform: (input: A) => O): CLIAgent<O>;
12
+ export declare function findCliAgent(cli: AIGNECLIAgents, parent: string[] | "*", name: string): import("../agents/agent.ts").Agent<any, any> | undefined;
@@ -6,6 +6,7 @@ import type { UserAgent } from "../agents/user-agent.js";
6
6
  import { type LoadOptions } from "../loader/index.js";
7
7
  import { AIGNEContext, type Context, type InvokeOptions, type UserContext } from "./context.js";
8
8
  import { type MessagePayload, MessageQueue, type MessageQueueListener, type Unsubscribe } from "./message-queue.js";
9
+ import type { AIGNECLIAgents } from "./type.js";
9
10
  import type { ContextLimits } from "./usage.js";
10
11
  /**
11
12
  * Options for the AIGNE class.
@@ -43,10 +44,7 @@ export interface AIGNEOptions {
43
44
  mcpServer?: {
44
45
  agents?: Agent[];
45
46
  };
46
- cli?: {
47
- chat?: Agent;
48
- agents?: Agent[];
49
- };
47
+ cli?: AIGNECLIAgents;
50
48
  /**
51
49
  * Limits for the AIGNE instance, such as timeout, max tokens, max invocations, etc.
52
50
  */
@@ -133,12 +131,7 @@ export declare class AIGNE<U extends UserContext = UserContext> {
133
131
  [key: string]: Agent<any, any>;
134
132
  };
135
133
  };
136
- readonly cli: {
137
- chat: Agent | undefined;
138
- agents: Agent<any, any>[] & {
139
- [key: string]: Agent<any, any>;
140
- };
141
- };
134
+ readonly cli: AIGNECLIAgents;
142
135
  /**
143
136
  * Observer for the AIGNE instance.
144
137
  */
@@ -60,10 +60,7 @@ export class AIGNE {
60
60
  this.addAgent(...options.agents);
61
61
  if (options?.mcpServer?.agents?.length)
62
62
  this.mcpServer.agents.push(...options.mcpServer.agents);
63
- if (options?.cli?.agents?.length)
64
- this.cli.agents.push(...options.cli.agents);
65
- if (options?.cli?.chat)
66
- this.cli.chat = options.cli.chat;
63
+ this.cli = options?.cli ?? {};
67
64
  this.observer?.serve();
68
65
  this.initProcessExitHandler();
69
66
  }
@@ -110,10 +107,7 @@ export class AIGNE {
110
107
  mcpServer = {
111
108
  agents: createAccessorArray([], (arr, name) => arr.find((i) => i.name === name)),
112
109
  };
113
- cli = {
114
- chat: undefined,
115
- agents: createAccessorArray([], (arr, name) => arr.find((i) => i.name === name)),
116
- };
110
+ cli = {};
117
111
  /**
118
112
  * Observer for the AIGNE instance.
119
113
  */
@@ -0,0 +1,12 @@
1
+ import type { Agent } from "../agents/agent.ts";
2
+ export interface AIGNECLIAgents {
3
+ chat?: Agent;
4
+ agents?: AIGNECLIAgent[];
5
+ }
6
+ export interface AIGNECLIAgent {
7
+ agent?: Agent;
8
+ name?: string;
9
+ alias?: string[];
10
+ description?: string;
11
+ agents?: AIGNECLIAgent[];
12
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -1,4 +1,4 @@
1
- import { z } from "zod";
1
+ import { type ZodType, z } from "zod";
2
2
  import { Agent, type AgentOptions } from "../agents/agent.js";
3
3
  import type { ChatModel } from "../agents/chat-model.js";
4
4
  import type { ImageModel } from "../agents/image-model.js";
@@ -14,10 +14,17 @@ export interface LoadOptions {
14
14
  }
15
15
  export declare function load(path: string, options?: LoadOptions): Promise<AIGNEOptions>;
16
16
  export declare function loadAgent(path: string, options?: LoadOptions, agentOptions?: AgentOptions): Promise<Agent>;
17
+ type CliAgent = string | {
18
+ url?: string;
19
+ name?: string;
20
+ alias?: string[];
21
+ description?: string;
22
+ agents?: CliAgent[];
23
+ };
17
24
  declare const aigneFileSchema: z.ZodObject<{
18
- name: z.ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
19
- description: z.ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
20
- model: z.ZodType<{
25
+ name: ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
26
+ description: ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
27
+ model: ZodType<{
21
28
  model?: string | undefined;
22
29
  temperature?: number | undefined;
23
30
  topP?: number | undefined;
@@ -30,23 +37,23 @@ declare const aigneFileSchema: z.ZodObject<{
30
37
  frequencyPenalty?: number | undefined;
31
38
  presencePenalty?: number | undefined;
32
39
  } | undefined>;
33
- imageModel: z.ZodType<{
40
+ imageModel: ZodType<{
34
41
  model?: string | undefined;
35
42
  } | undefined, z.ZodTypeDef, {
36
43
  model?: string | undefined;
37
44
  } | undefined>;
38
- agents: z.ZodType<string[] | undefined, z.ZodTypeDef, string[] | undefined>;
39
- skills: z.ZodType<string[] | undefined, z.ZodTypeDef, string[] | undefined>;
40
- mcpServer: z.ZodType<{
45
+ agents: ZodType<string[] | undefined, z.ZodTypeDef, string[] | undefined>;
46
+ skills: ZodType<string[] | undefined, z.ZodTypeDef, string[] | undefined>;
47
+ mcpServer: ZodType<{
41
48
  agents?: string[] | undefined;
42
49
  } | undefined, z.ZodTypeDef, {
43
50
  agents?: string[] | undefined;
44
51
  } | undefined>;
45
- cli: z.ZodType<{
46
- agents?: string[] | undefined;
52
+ cli: ZodType<{
53
+ agents?: CliAgent[] | undefined;
47
54
  chat?: string | undefined;
48
55
  } | undefined, z.ZodTypeDef, {
49
- agents?: string[] | undefined;
56
+ agents?: CliAgent[] | undefined;
50
57
  chat?: string | undefined;
51
58
  } | undefined>;
52
59
  }, "strip", z.ZodTypeAny, {
@@ -68,7 +75,7 @@ declare const aigneFileSchema: z.ZodObject<{
68
75
  agents?: string[] | undefined;
69
76
  } | undefined;
70
77
  cli?: {
71
- agents?: string[] | undefined;
78
+ agents?: CliAgent[] | undefined;
72
79
  chat?: string | undefined;
73
80
  } | undefined;
74
81
  }, {
@@ -90,7 +97,7 @@ declare const aigneFileSchema: z.ZodObject<{
90
97
  agents?: string[] | undefined;
91
98
  } | undefined;
92
99
  cli?: {
93
- agents?: string[] | undefined;
100
+ agents?: CliAgent[] | undefined;
94
101
  chat?: string | undefined;
95
102
  } | undefined;
96
103
  }>;
@@ -16,12 +16,27 @@ import { camelizeSchema, chatModelSchema, imageModelSchema, optionalize } from "
16
16
  const AIGNE_FILE_NAME = ["aigne.yaml", "aigne.yml"];
17
17
  export async function load(path, options = {}) {
18
18
  const { aigne, rootDir } = await loadAIGNEFile(path);
19
- const allAgentPaths = new Set(flat(aigne.agents, aigne.skills, aigne.mcpServer?.agents, aigne.cli?.agents, aigne.cli?.chat).map((i) => nodejs.path.join(rootDir, i)));
19
+ const flatCliAgents = (cliAgent) => {
20
+ if (typeof cliAgent === "string")
21
+ return [cliAgent];
22
+ return flat(cliAgent.url, cliAgent.agents?.flatMap(flatCliAgents));
23
+ };
24
+ const allAgentPaths = new Set(flat(aigne.agents, aigne.skills, aigne.mcpServer?.agents, aigne.cli?.chat, aigne.cli?.agents?.flatMap((i) => (typeof i === "string" ? i : flatCliAgents(i)))).map((i) => nodejs.path.join(rootDir, i)));
20
25
  const allAgents = {};
21
26
  for (const path of allAgentPaths) {
22
27
  allAgents[path] = await loadAgent(path, options);
23
28
  }
24
- const pickAgents = (paths) => paths.map((filename) => allAgents[nodejs.path.join(rootDir, filename)]).filter(isNonNullable);
29
+ const pickAgent = (path) => allAgents[nodejs.path.join(rootDir, path)];
30
+ const pickAgents = (paths) => paths.map((filename) => pickAgent(filename)).filter(isNonNullable);
31
+ const mapCliAgents = (cliAgent) => {
32
+ if (typeof cliAgent === "string")
33
+ return { agent: pickAgent(cliAgent) };
34
+ return {
35
+ ...cliAgent,
36
+ agent: cliAgent.url ? pickAgent(cliAgent.url) : undefined,
37
+ agents: cliAgent.agents?.map(mapCliAgents),
38
+ };
39
+ };
25
40
  return {
26
41
  ...aigne,
27
42
  rootDir,
@@ -36,7 +51,7 @@ export async function load(path, options = {}) {
36
51
  },
37
52
  cli: {
38
53
  chat: aigne.cli?.chat ? pickAgents([aigne.cli.chat])[0] : undefined,
39
- agents: pickAgents(aigne.cli?.agents ?? []),
54
+ agents: aigne.cli?.agents?.map(mapCliAgents),
40
55
  },
41
56
  };
42
57
  }
@@ -181,6 +196,16 @@ async function loadMemory(memories, provider, options) {
181
196
  throw new Error(`Unsupported memory: ${provider}`);
182
197
  return new M(options);
183
198
  }
199
+ const cliAgentSchema = z.union([
200
+ z.string(),
201
+ z.object({
202
+ url: optionalize(z.string()),
203
+ name: optionalize(z.string()),
204
+ alias: optionalize(z.array(z.string())),
205
+ description: optionalize(z.string()),
206
+ agents: optionalize(z.array(z.lazy(() => cliAgentSchema))),
207
+ }),
208
+ ]);
184
209
  const aigneFileSchema = camelizeSchema(z.object({
185
210
  name: optionalize(z.string()),
186
211
  description: optionalize(z.string()),
@@ -193,7 +218,7 @@ const aigneFileSchema = camelizeSchema(z.object({
193
218
  })),
194
219
  cli: optionalize(z.object({
195
220
  chat: optionalize(z.string()),
196
- agents: optionalize(z.array(z.string())),
221
+ agents: optionalize(z.array(cliAgentSchema)),
197
222
  })),
198
223
  }));
199
224
  export async function loadAIGNEFile(path) {
@@ -40,31 +40,22 @@ export declare class AgentMessageTemplate extends ChatMessageTemplate {
40
40
  toolCalls?: ChatModelOutputToolCall[] | undefined;
41
41
  static from(template?: ChatModelInputMessage["content"], toolCalls?: ChatModelOutputToolCall[], name?: string, options?: FormatOptions): AgentMessageTemplate;
42
42
  constructor(content?: ChatModelInputMessage["content"], toolCalls?: ChatModelOutputToolCall[] | undefined, name?: string, options?: FormatOptions);
43
- format(variables?: Record<string, unknown>, options?: FormatOptions): Promise<{
43
+ format(_variables?: Record<string, unknown>, _options?: FormatOptions): Promise<{
44
+ role: "agent" | "system" | "user" | "tool";
45
+ name: string | undefined;
46
+ content: ChatModelInputMessageContent | undefined;
44
47
  toolCalls: ChatModelOutputToolCall[] | undefined;
45
- role: import("../agents/chat-model.js").Role;
46
- content?: ChatModelInputMessageContent;
47
- toolCallId?: string;
48
- name?: string;
49
48
  }>;
50
49
  }
51
50
  export declare class ToolMessageTemplate extends ChatMessageTemplate {
52
51
  toolCallId: string;
53
52
  static from(content: object | string, toolCallId: string, name?: string, options?: FormatOptions): ToolMessageTemplate;
54
53
  constructor(content: object | string, toolCallId: string, name?: string, options?: FormatOptions);
55
- format(variables?: Record<string, unknown>, options?: FormatOptions): Promise<{
54
+ format(_variables?: Record<string, unknown>, _options?: FormatOptions): Promise<{
55
+ role: "agent" | "system" | "user" | "tool";
56
+ name: string | undefined;
57
+ content: ChatModelInputMessageContent | undefined;
56
58
  toolCallId: string;
57
- role: import("../agents/chat-model.js").Role;
58
- content?: ChatModelInputMessageContent;
59
- toolCalls?: {
60
- id: string;
61
- type: "function";
62
- function: {
63
- name: string;
64
- arguments: import("../index.js").Message;
65
- };
66
- }[];
67
- name?: string;
68
59
  }>;
69
60
  }
70
61
  export declare class ChatMessagesTemplate {
@@ -112,9 +112,12 @@ export class AgentMessageTemplate extends ChatMessageTemplate {
112
112
  super("agent", content, name, options);
113
113
  this.toolCalls = toolCalls;
114
114
  }
115
- async format(variables, options) {
115
+ async format(_variables, _options) {
116
116
  return {
117
- ...(await super.format(variables, options)),
117
+ role: this.role,
118
+ name: this.name,
119
+ // NOTE: agent message should not rendered by template
120
+ content: this.content,
118
121
  toolCalls: this.toolCalls,
119
122
  };
120
123
  }
@@ -130,9 +133,12 @@ export class ToolMessageTemplate extends ChatMessageTemplate {
130
133
  : JSON.stringify(content, (_, value) => typeof value === "bigint" ? value.toString() : value), name, options);
131
134
  this.toolCallId = toolCallId;
132
135
  }
133
- async format(variables, options) {
136
+ async format(_variables, _options) {
134
137
  return {
135
- ...(await super.format(variables, options)),
138
+ role: this.role,
139
+ name: this.name,
140
+ // NOTE: tool result should not rendered by template
141
+ content: this.content,
136
142
  toolCallId: this.toolCallId,
137
143
  };
138
144
  }
@@ -1,2 +1,12 @@
1
1
  import type { AgentHooks } from "../agents/agent.ts";
2
+ import type { AIGNECLIAgents } from "../aigne/type.js";
2
3
  export declare function sortHooks(hooks: AgentHooks[]): AgentHooks[];
4
+ export interface CLIAgent<T> {
5
+ agent?: T;
6
+ name?: string;
7
+ alias?: string[];
8
+ description?: string;
9
+ agents?: CLIAgent<T>[];
10
+ }
11
+ export declare function mapCliAgent<A, O>({ agent, agents, ...input }: CLIAgent<A>, transform: (input: A) => O): CLIAgent<O>;
12
+ export declare function findCliAgent(cli: AIGNECLIAgents, parent: string[] | "*", name: string): import("../agents/agent.ts").Agent<any, any> | undefined;
@@ -4,3 +4,45 @@ export function sortHooks(hooks) {
4
4
  .slice(0)
5
5
  .sort(({ priority: a = "low" }, { priority: b = "low" }) => a === b ? 0 : priorities.indexOf(a) - priorities.indexOf(b));
6
6
  }
7
+ export function mapCliAgent({ agent, agents, ...input }, transform) {
8
+ return {
9
+ ...input,
10
+ agent: agent ? transform(agent) : undefined,
11
+ agents: agents?.map((item) => mapCliAgent(item, transform)),
12
+ };
13
+ }
14
+ export function findCliAgent(cli, parent, name) {
15
+ if (parent === "*")
16
+ return findCliAgentRecursive(cli, name);
17
+ let currentAgents = cli.agents ?? [];
18
+ for (const name of parent) {
19
+ const found = currentAgents.find((i) => (i.name || i.agent?.name) === name);
20
+ if (!found)
21
+ throw new Error(`Agent ${name} not found in parent path ${parent.join(" -> ")}`);
22
+ if (found.agents)
23
+ currentAgents = found.agents;
24
+ else
25
+ currentAgents = [];
26
+ }
27
+ return currentAgents.find((i) => (i.name || i.agent?.name) === name)?.agent;
28
+ }
29
+ function findCliAgentRecursive(agents, name) {
30
+ if (agents.chat?.name === name) {
31
+ return agents.chat;
32
+ }
33
+ if (agents.agents) {
34
+ const queue = [...agents.agents];
35
+ while (queue.length > 0) {
36
+ const c = queue.shift();
37
+ if (!c)
38
+ break;
39
+ if ((c.name || c.agent?.name) === name) {
40
+ return c.agent;
41
+ }
42
+ if (c.agents) {
43
+ queue.push(...c.agents);
44
+ }
45
+ }
46
+ }
47
+ return undefined;
48
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aigne/core",
3
- "version": "1.61.1-beta",
3
+ "version": "1.62.0-beta.1",
4
4
  "description": "The functional core of agentic AI",
5
5
  "publishConfig": {
6
6
  "access": "public"