@aigne/core 1.72.0-beta.7 → 1.72.0-beta.9

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 (67) hide show
  1. package/CHANGELOG.md +27 -0
  2. package/lib/cjs/agents/agent.d.ts +2 -21
  3. package/lib/cjs/agents/agent.js +10 -15
  4. package/lib/cjs/agents/ai-agent.d.ts +20 -4
  5. package/lib/cjs/agents/ai-agent.js +37 -35
  6. package/lib/cjs/agents/image-model.d.ts +4 -4
  7. package/lib/cjs/agents/mcp-agent.d.ts +2 -2
  8. package/lib/cjs/agents/video-model.d.ts +4 -4
  9. package/lib/cjs/index.d.ts +1 -0
  10. package/lib/cjs/index.js +1 -0
  11. package/lib/cjs/loader/agent-yaml.d.ts +1 -2
  12. package/lib/cjs/loader/agent-yaml.js +0 -8
  13. package/lib/cjs/loader/index.d.ts +2 -2
  14. package/lib/cjs/memory/recorder.d.ts +4 -4
  15. package/lib/cjs/memory/retriever.d.ts +4 -4
  16. package/lib/cjs/prompt/agent-session.d.ts +53 -0
  17. package/lib/cjs/prompt/agent-session.js +345 -0
  18. package/lib/cjs/prompt/compact/compactor.d.ts +7 -0
  19. package/lib/cjs/prompt/compact/compactor.js +48 -0
  20. package/lib/cjs/prompt/compact/types.d.ts +79 -0
  21. package/lib/cjs/prompt/compact/types.js +19 -0
  22. package/lib/cjs/prompt/context/afs/history.js +1 -1
  23. package/lib/cjs/prompt/prompt-builder.d.ts +6 -8
  24. package/lib/cjs/prompt/prompt-builder.js +67 -123
  25. package/lib/cjs/prompt/skills/afs/agent-skill/skill-loader.js +1 -0
  26. package/lib/cjs/prompt/template.d.ts +16 -16
  27. package/lib/dts/agents/agent.d.ts +2 -21
  28. package/lib/dts/agents/ai-agent.d.ts +20 -4
  29. package/lib/dts/agents/image-model.d.ts +4 -4
  30. package/lib/dts/agents/mcp-agent.d.ts +2 -2
  31. package/lib/dts/agents/video-model.d.ts +4 -4
  32. package/lib/dts/index.d.ts +1 -0
  33. package/lib/dts/loader/agent-yaml.d.ts +1 -2
  34. package/lib/dts/loader/index.d.ts +2 -2
  35. package/lib/dts/memory/recorder.d.ts +4 -4
  36. package/lib/dts/memory/retriever.d.ts +4 -4
  37. package/lib/dts/prompt/agent-session.d.ts +53 -0
  38. package/lib/dts/prompt/compact/compactor.d.ts +7 -0
  39. package/lib/dts/prompt/compact/types.d.ts +79 -0
  40. package/lib/dts/prompt/prompt-builder.d.ts +6 -8
  41. package/lib/dts/prompt/template.d.ts +16 -16
  42. package/lib/esm/agents/agent.d.ts +2 -21
  43. package/lib/esm/agents/agent.js +10 -15
  44. package/lib/esm/agents/ai-agent.d.ts +20 -4
  45. package/lib/esm/agents/ai-agent.js +37 -35
  46. package/lib/esm/agents/image-model.d.ts +4 -4
  47. package/lib/esm/agents/mcp-agent.d.ts +2 -2
  48. package/lib/esm/agents/video-model.d.ts +4 -4
  49. package/lib/esm/index.d.ts +1 -0
  50. package/lib/esm/index.js +1 -0
  51. package/lib/esm/loader/agent-yaml.d.ts +1 -2
  52. package/lib/esm/loader/agent-yaml.js +0 -8
  53. package/lib/esm/loader/index.d.ts +2 -2
  54. package/lib/esm/memory/recorder.d.ts +4 -4
  55. package/lib/esm/memory/retriever.d.ts +4 -4
  56. package/lib/esm/prompt/agent-session.d.ts +53 -0
  57. package/lib/esm/prompt/agent-session.js +308 -0
  58. package/lib/esm/prompt/compact/compactor.d.ts +7 -0
  59. package/lib/esm/prompt/compact/compactor.js +44 -0
  60. package/lib/esm/prompt/compact/types.d.ts +79 -0
  61. package/lib/esm/prompt/compact/types.js +16 -0
  62. package/lib/esm/prompt/context/afs/history.js +1 -1
  63. package/lib/esm/prompt/prompt-builder.d.ts +6 -8
  64. package/lib/esm/prompt/prompt-builder.js +68 -124
  65. package/lib/esm/prompt/skills/afs/agent-skill/skill-loader.js +1 -0
  66. package/lib/esm/prompt/template.d.ts +16 -16
  67. package/package.json +4 -4
@@ -1,20 +1,19 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.PromptBuilder = void 0;
4
- const afs_history_1 = require("@aigne/afs-history");
5
4
  const index_js_1 = require("@aigne/platform-helpers/nodejs/index.js");
5
+ const uuid_1 = require("@aigne/uuid");
6
6
  const yaml_1 = require("yaml");
7
7
  const zod_1 = require("zod");
8
8
  const zod_to_json_schema_1 = require("zod-to-json-schema");
9
9
  const agent_js_1 = require("../agents/agent.js");
10
10
  const ai_agent_js_1 = require("../agents/ai-agent.js");
11
- const chat_model_js_1 = require("../agents/chat-model.js");
12
11
  const model_js_1 = require("../agents/model.js");
13
12
  const schema_js_1 = require("../loader/schema.js");
14
13
  const json_schema_js_1 = require("../utils/json-schema.js");
15
14
  const type_utils_js_1 = require("../utils/type-utils.js");
15
+ const agent_session_js_1 = require("./agent-session.js");
16
16
  const index_js_2 = require("./context/index.js");
17
- const afs_builtin_prompt_js_1 = require("./prompts/afs-builtin-prompt.js");
18
17
  const memory_message_template_js_1 = require("./prompts/memory-message-template.js");
19
18
  const structured_stream_instructions_js_1 = require("./prompts/structured-stream-instructions.js");
20
19
  const index_js_3 = require("./skills/afs/index.js");
@@ -74,13 +73,28 @@ class PromptBuilder {
74
73
  });
75
74
  }
76
75
  async build(options) {
76
+ let { userId, sessionId } = options.context?.userContext || {};
77
+ const agentId = options.agent?.name;
78
+ const afs = options.agent?.afs;
79
+ sessionId ||= (0, uuid_1.v7)();
80
+ const session = new agent_session_js_1.AgentSession({
81
+ agentId,
82
+ userId,
83
+ sessionId,
84
+ afs,
85
+ compact: options.agent?.compact,
86
+ });
87
+ const { systemMessage, userMessage } = await this.buildMessages(options);
88
+ if (systemMessage)
89
+ await session.setSystemMessages(systemMessage);
77
90
  return {
78
- messages: await this.buildMessages(options),
91
+ userMessage,
79
92
  responseFormat: options.agent?.structuredStreamMode
80
93
  ? undefined
81
94
  : this.buildResponseFormat(options),
82
95
  outputFileType: options.agent?.outputFileType,
83
96
  ...(await this.buildTools(options)),
97
+ session,
84
98
  };
85
99
  }
86
100
  async buildPrompt(options) {
@@ -101,47 +115,43 @@ class PromptBuilder {
101
115
  }
102
116
  async buildMessages(options) {
103
117
  const { input } = options;
104
- const agentId = options.agent?.name;
105
- const userId = options.context?.userContext.userId;
106
- const sessionId = options.context?.userContext.sessionId;
107
118
  const inputKey = options.agent?.inputKey;
108
119
  const message = inputKey && typeof input?.[inputKey] === "string" ? input[inputKey] : undefined;
109
- const [messages, otherCustomMessages] = (0, type_utils_js_1.partition)((await (typeof this.instructions === "string"
120
+ const template = typeof this.instructions === "string"
110
121
  ? template_js_1.ChatMessagesTemplate.from([template_js_1.SystemMessageTemplate.from(this.instructions)])
111
- : this.instructions)?.format(this.getTemplateVariables(options), { workingDir: this.workingDir })) ?? [], (i) => i.role === "system");
122
+ : this.instructions;
123
+ const [systemMessages, userMessages] = (0, type_utils_js_1.partition)((await template?.format(this.getTemplateVariables(options), {
124
+ workingDir: this.workingDir,
125
+ })) ?? [], (i) => i.role === "system");
112
126
  const inputFileKey = options.agent?.inputFileKey;
113
127
  const files = (0, type_utils_js_1.flat)(inputFileKey
114
128
  ? (0, type_utils_js_1.checkArguments)("Check input files", (0, schema_js_1.optionalize)(model_js_1.fileUnionContentsSchema), input?.[inputFileKey])
115
129
  : null);
116
- const historyConfig = options.agent?.historyConfig;
117
- const injectHistory = historyConfig?.inject === true || (historyConfig?.inject !== false && historyConfig?.enabled);
118
- if (injectHistory) {
119
- if (historyConfig.useOldMemory) {
120
- messages.push(...(await this.deprecatedMemories(message, options)));
121
- }
122
- else {
123
- const history = await this.getHistories({ ...options, agentId, userId, sessionId });
124
- messages.push(...history);
125
- }
130
+ if (options.agent?.memories.length || options.context?.memories.length) {
131
+ const deprecatedMemories = await this.deprecatedMemories(message, options);
132
+ if (deprecatedMemories.length)
133
+ systemMessages.push(...deprecatedMemories);
126
134
  }
127
135
  // if the agent is using structured stream mode, add the instructions
128
136
  const { structuredStreamMode, outputSchema } = options.agent || {};
129
137
  if (structuredStreamMode && outputSchema) {
130
138
  const instructions = options.agent?.customStructuredStreamInstructions?.instructions ||
131
139
  PromptBuilder.from(structured_stream_instructions_js_1.STRUCTURED_STREAM_INSTRUCTIONS.instructions);
132
- messages.push(...(await instructions.buildMessages({
133
- input: {
134
- ...input,
135
- outputJsonSchema: (0, zod_to_json_schema_1.zodToJsonSchema)(outputSchema),
136
- },
137
- })));
140
+ systemMessages.push({
141
+ role: "system",
142
+ content: (await instructions.buildPrompt({
143
+ input: {
144
+ ...input,
145
+ outputJsonSchema: (0, zod_to_json_schema_1.zodToJsonSchema)(outputSchema),
146
+ },
147
+ })).prompt,
148
+ });
138
149
  }
139
- messages.push(...otherCustomMessages);
140
150
  if (message || files.length) {
141
151
  const content = [];
142
152
  if (message &&
143
153
  // avoid duplicate user messages: developer may have already included the message in the messages
144
- !otherCustomMessages.some((i) => i.role === "user" &&
154
+ !userMessages.some((i) => i.role === "user" &&
145
155
  (typeof i.content === "string"
146
156
  ? i.content.includes(message)
147
157
  : i.content?.some((c) => c.type === "text" && c.text.includes(message))))) {
@@ -150,10 +160,38 @@ class PromptBuilder {
150
160
  if (files.length)
151
161
  content.push(...files);
152
162
  if (content.length) {
153
- messages.push({ role: "user", content });
163
+ userMessages.push({ role: "user", content });
154
164
  }
155
165
  }
156
- return this.refineMessages(options, messages);
166
+ let systemMessage = this.mergeMessages(systemMessages, "system");
167
+ if (!systemMessage.content?.length)
168
+ systemMessage = undefined;
169
+ let userMessage = this.mergeMessages(userMessages, "user");
170
+ if (!userMessage.content?.length) {
171
+ userMessage = { role: "user", content: systemMessage?.content };
172
+ systemMessage = undefined;
173
+ }
174
+ if (!userMessage.content?.length)
175
+ throw new Error("User message cannot be empty.");
176
+ return {
177
+ systemMessage,
178
+ userMessage,
179
+ };
180
+ }
181
+ mergeMessages(messages, role) {
182
+ const content = [];
183
+ for (const message of messages) {
184
+ if (typeof message.content === "string") {
185
+ content.push({ type: "text", text: message.content });
186
+ }
187
+ else if (Array.isArray(message.content)) {
188
+ content.push(...message.content);
189
+ }
190
+ else if (message.content) {
191
+ throw new Error(`Unsupported message content type: ${typeof message.content}`);
192
+ }
193
+ }
194
+ return { role, content };
157
195
  }
158
196
  async deprecatedMemories(message, options) {
159
197
  const messages = [];
@@ -164,104 +202,10 @@ class PromptBuilder {
164
202
  if (options.agent?.useMemoriesFromContext && options.context?.memories?.length) {
165
203
  memories.push(...options.context.memories);
166
204
  }
167
- const afs = options.agent?.afs;
168
- if (afs && options.agent?.historyConfig?.enabled) {
169
- const historyModule = (await afs.listModules()).find((m) => m.module instanceof afs_history_1.AFSHistory);
170
- if (historyModule) {
171
- const history = await afs.list(historyModule.path, {
172
- limit: options.agent?.maxRetrieveMemoryCount || 10,
173
- orderBy: [["createdAt", "desc"]],
174
- });
175
- memories.push(...history.data
176
- .reverse()
177
- .filter((i) => (0, type_utils_js_1.isNonNullable)(i.content)));
178
- if (message) {
179
- const result = (await afs.search("/", message)).data;
180
- const ms = result
181
- .map((entry) => {
182
- if (entry.metadata?.execute)
183
- return null;
184
- const content = entry.content || entry.summary;
185
- if (!content)
186
- return null;
187
- return {
188
- content,
189
- description: entry.description,
190
- };
191
- })
192
- .filter(type_utils_js_1.isNonNullable);
193
- memories.push(...ms);
194
- const executable = result.filter((i) => !!i.metadata?.execute);
195
- if (executable.length) {
196
- messages.push({
197
- role: "system",
198
- content: await template_js_1.PromptTemplate.from(afs_builtin_prompt_js_1.AFS_EXECUTABLE_TOOLS_PROMPT_TEMPLATE).format({
199
- tools: executable.map((entry) => ({
200
- path: entry.path,
201
- name: entry.metadata.execute.name,
202
- description: entry.metadata.execute.description,
203
- inputSchema: entry.metadata.execute.inputSchema,
204
- outputSchema: entry.metadata.execute.outputSchema,
205
- })),
206
- }),
207
- });
208
- }
209
- }
210
- }
211
- }
212
205
  if (memories.length)
213
206
  messages.push(...(await this.convertMemoriesToMessages(memories, options)));
214
207
  return messages;
215
208
  }
216
- async getHistories({ agentId, userId, sessionId, ...options }) {
217
- const { agent } = options;
218
- const afs = agent?.afs;
219
- if (!afs)
220
- return [];
221
- const historyModule = (await afs.listModules()).find((m) => m.module instanceof afs_history_1.AFSHistory);
222
- if (!historyModule)
223
- return [];
224
- const history = (await afs.list(historyModule.path, {
225
- filter: { agentId, userId, sessionId },
226
- limit: agent.historyConfig?.maxItems || 10,
227
- orderBy: [["createdAt", "desc"]],
228
- })).data.reverse();
229
- return (await Promise.all(history.map(async (i) => {
230
- if (Array.isArray(i.content?.messages) &&
231
- i.content.messages.every((m) => chat_model_js_1.roleSchema.parse(m?.role))) {
232
- return i.content.messages;
233
- }
234
- const { input, output } = i.content || {};
235
- if (input && output) {
236
- return await this.convertMemoriesToMessages([{ content: { input, output } }], options);
237
- }
238
- return [];
239
- }))).flat();
240
- }
241
- refineMessages(options, messages) {
242
- const { autoReorderSystemMessages, autoMergeSystemMessages } = options.agent ?? {};
243
- if (!autoReorderSystemMessages && !autoMergeSystemMessages)
244
- return messages;
245
- const [systemMessages, otherMessages] = (0, type_utils_js_1.partition)(messages, (m) => m.role === "system");
246
- if (!autoMergeSystemMessages) {
247
- return systemMessages.concat(otherMessages);
248
- }
249
- const result = [];
250
- if (systemMessages.length) {
251
- result.push({
252
- role: "system",
253
- content: systemMessages
254
- .map((i) => typeof i.content === "string"
255
- ? i.content
256
- : i.content
257
- ?.map((c) => (c.type === "text" ? c.text : null))
258
- .filter(type_utils_js_1.isNonNullable)
259
- .join("\n"))
260
- .join("\n"),
261
- });
262
- }
263
- return result.concat(otherMessages);
264
- }
265
209
  async convertMemoriesToMessages(memories, options) {
266
210
  const messages = [];
267
211
  const other = [];
@@ -44,6 +44,7 @@ async function loadAgentSkillFromAFS({ afs, }) {
44
44
  for (const module of filtered) {
45
45
  const data = (await afs.list(module.path, {
46
46
  pattern: "**/SKILL.md",
47
+ maxDepth: 10,
47
48
  })).data;
48
49
  for (const entry of data) {
49
50
  const { data: file } = await afs.read(entry.path);
@@ -42,7 +42,7 @@ export declare class AgentMessageTemplate extends ChatMessageTemplate {
42
42
  static from(template?: ChatModelInputMessage["content"], toolCalls?: ChatModelOutputToolCall[], name?: string, options?: FormatOptions, cacheControl?: ChatModelInputMessage["cacheControl"]): AgentMessageTemplate;
43
43
  constructor(content?: ChatModelInputMessage["content"], toolCalls?: ChatModelOutputToolCall[] | undefined, name?: string, options?: FormatOptions, cacheControl?: ChatModelInputMessage["cacheControl"]);
44
44
  format(_variables?: Record<string, unknown>, _options?: FormatOptions): Promise<{
45
- role: "system" | "user" | "agent" | "tool";
45
+ role: "agent" | "user" | "system" | "tool";
46
46
  name: string | undefined;
47
47
  content: ChatModelInputMessageContent | undefined;
48
48
  toolCalls: ChatModelOutputToolCall[] | undefined;
@@ -54,7 +54,7 @@ export declare class ToolMessageTemplate extends ChatMessageTemplate {
54
54
  static from(content: object | string, toolCallId: string, name?: string, options?: FormatOptions, cacheControl?: ChatModelInputMessage["cacheControl"]): ToolMessageTemplate;
55
55
  constructor(content: object | string, toolCallId: string, name?: string, options?: FormatOptions, cacheControl?: ChatModelInputMessage["cacheControl"]);
56
56
  format(_variables?: Record<string, unknown>, _options?: FormatOptions): Promise<{
57
- role: "system" | "user" | "agent" | "tool";
57
+ role: "agent" | "user" | "system" | "tool";
58
58
  name: string | undefined;
59
59
  content: ChatModelInputMessageContent | undefined;
60
60
  toolCallId: string;
@@ -83,21 +83,21 @@ declare const chatMessageSchema: z.ZodUnion<[z.ZodObject<{
83
83
  ttl?: "5m" | "1h" | undefined;
84
84
  }>>;
85
85
  }, "strip", z.ZodTypeAny, {
86
- content: string;
87
86
  role: "system";
87
+ content: string;
88
+ name?: string | undefined;
88
89
  cacheControl?: {
89
90
  type: "ephemeral";
90
91
  ttl?: "5m" | "1h" | undefined;
91
92
  } | undefined;
92
- name?: string | undefined;
93
93
  }, {
94
- content: string;
95
94
  role: "system";
95
+ content: string;
96
+ name?: string | undefined;
96
97
  cacheControl?: {
97
98
  type: "ephemeral";
98
99
  ttl?: "5m" | "1h" | undefined;
99
100
  } | undefined;
100
- name?: string | undefined;
101
101
  }>, z.ZodObject<{
102
102
  role: z.ZodLiteral<"user">;
103
103
  content: z.ZodString;
@@ -113,21 +113,21 @@ declare const chatMessageSchema: z.ZodUnion<[z.ZodObject<{
113
113
  ttl?: "5m" | "1h" | undefined;
114
114
  }>>;
115
115
  }, "strip", z.ZodTypeAny, {
116
- content: string;
117
116
  role: "user";
117
+ content: string;
118
+ name?: string | undefined;
118
119
  cacheControl?: {
119
120
  type: "ephemeral";
120
121
  ttl?: "5m" | "1h" | undefined;
121
122
  } | undefined;
122
- name?: string | undefined;
123
123
  }, {
124
- content: string;
125
124
  role: "user";
125
+ content: string;
126
+ name?: string | undefined;
126
127
  cacheControl?: {
127
128
  type: "ephemeral";
128
129
  ttl?: "5m" | "1h" | undefined;
129
130
  } | undefined;
130
- name?: string | undefined;
131
131
  }>, z.ZodObject<{
132
132
  role: z.ZodLiteral<"agent">;
133
133
  content: z.ZodOptional<z.ZodString>;
@@ -172,6 +172,7 @@ declare const chatMessageSchema: z.ZodUnion<[z.ZodObject<{
172
172
  }>>;
173
173
  }, "strip", z.ZodTypeAny, {
174
174
  role: "agent";
175
+ name?: string | undefined;
175
176
  content?: string | undefined;
176
177
  cacheControl?: {
177
178
  type: "ephemeral";
@@ -185,9 +186,9 @@ declare const chatMessageSchema: z.ZodUnion<[z.ZodObject<{
185
186
  type: "function";
186
187
  id: string;
187
188
  }[] | undefined;
188
- name?: string | undefined;
189
189
  }, {
190
190
  role: "agent";
191
+ name?: string | undefined;
191
192
  content?: string | undefined;
192
193
  cacheControl?: {
193
194
  type: "ephemeral";
@@ -201,7 +202,6 @@ declare const chatMessageSchema: z.ZodUnion<[z.ZodObject<{
201
202
  type: "function";
202
203
  id: string;
203
204
  }[] | undefined;
204
- name?: string | undefined;
205
205
  }>, z.ZodObject<{
206
206
  role: z.ZodLiteral<"tool">;
207
207
  content: z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodRecord<z.ZodString, z.ZodUnknown>]>, string, string | Record<string, unknown>>;
@@ -218,23 +218,23 @@ declare const chatMessageSchema: z.ZodUnion<[z.ZodObject<{
218
218
  ttl?: "5m" | "1h" | undefined;
219
219
  }>>;
220
220
  }, "strip", z.ZodTypeAny, {
221
- content: string;
222
221
  role: "tool";
222
+ content: string;
223
223
  toolCallId: string;
224
+ name?: string | undefined;
224
225
  cacheControl?: {
225
226
  type: "ephemeral";
226
227
  ttl?: "5m" | "1h" | undefined;
227
228
  } | undefined;
228
- name?: string | undefined;
229
229
  }, {
230
- content: string | Record<string, unknown>;
231
230
  role: "tool";
231
+ content: string | Record<string, unknown>;
232
232
  toolCallId: string;
233
+ name?: string | undefined;
233
234
  cacheControl?: {
234
235
  type: "ephemeral";
235
236
  ttl?: "5m" | "1h" | undefined;
236
237
  } | undefined;
237
- name?: string | undefined;
238
238
  }>]>;
239
239
  export declare function safeParseChatMessages(messages: unknown): ChatMessageTemplate[] | undefined;
240
240
  export declare function parseChatMessages(messages: (z.infer<typeof chatMessageSchema> & {
@@ -118,7 +118,6 @@ export interface AgentOptions<I extends Message = Message, O extends Message = M
118
118
  * agentSucceed, or agentFailed
119
119
  */
120
120
  disableEvents?: boolean;
121
- historyConfig?: Agent["historyConfig"];
122
121
  /**
123
122
  * One or more memory agents this agent can use
124
123
  */
@@ -211,15 +210,15 @@ export declare abstract class Agent<I extends Message = any, O extends Message =
211
210
  parsed: object;
212
211
  }): Promise<Agent<I, O>>;
213
212
  constructor(options?: AgentOptions<I, O>);
213
+ afs?: AFS;
214
+ tag?: string;
214
215
  /**
215
216
  * List of memories this agent can use
216
217
  *
217
218
  * @deprecated use afs instead
218
219
  */
219
220
  readonly memories: MemoryAgent[];
220
- afs?: AFS;
221
221
  asyncMemoryRecord?: boolean;
222
- tag?: string;
223
222
  /**
224
223
  * Maximum number of memory items to retrieve
225
224
  */
@@ -349,24 +348,6 @@ export declare abstract class Agent<I extends Message = any, O extends Message =
349
348
  * agentSucceed, or agentFailed
350
349
  */
351
350
  private disableEvents?;
352
- historyConfig?: {
353
- /**
354
- * Whether to enable history recording and injection
355
- * @default false
356
- */
357
- enabled?: boolean;
358
- /**
359
- * Whether to record history entries, default to enabled when history is enabled
360
- */
361
- record?: boolean;
362
- /**
363
- * Whether to inject history entries into the context, default to enabled when history is enabled
364
- */
365
- inject?: boolean;
366
- useOldMemory?: boolean;
367
- maxTokens?: number;
368
- maxItems?: number;
369
- };
370
351
  private subscriptions;
371
352
  /**
372
353
  * Attach agent to context:
@@ -1,4 +1,8 @@
1
1
  import { type ZodObject, type ZodType, z } from "zod";
2
+ import { type NestAgentSchema } from "../loader/agent-yaml.js";
3
+ import type { AgentLoadOptions } from "../loader/index.js";
4
+ import { type Instructions } from "../loader/schema.js";
5
+ import type { CompactConfig } from "../prompt/agent-session.js";
2
6
  import { PromptBuilder } from "../prompt/prompt-builder.js";
3
7
  import { Agent, type AgentInvokeOptions, type AgentOptions, type AgentProcessAsyncGenerator, type AgentProcessResult, type Message } from "./agent.js";
4
8
  import type { ChatModel, ChatModelInput } from "./chat-model.js";
@@ -23,8 +27,6 @@ export interface AIAgentOptions<I extends Message = Message, O extends Message =
23
27
  * more complex prompt templates
24
28
  */
25
29
  instructions?: string | PromptBuilder;
26
- autoReorderSystemMessages?: boolean;
27
- autoMergeSystemMessages?: boolean;
28
30
  /**
29
31
  * Pick a message from input to use as the user's message
30
32
  */
@@ -124,6 +126,20 @@ export interface AIAgentOptions<I extends Message = Message, O extends Message =
124
126
  */
125
127
  memoryPromptTemplate?: string;
126
128
  useMemoriesFromContext?: boolean;
129
+ compact?: CompactConfig;
130
+ }
131
+ export interface AIAgentLoadSchema {
132
+ instructions?: Instructions;
133
+ inputKey?: string;
134
+ inputFileKey?: string;
135
+ outputKey?: string;
136
+ outputFileKey?: string;
137
+ toolChoice?: AIAgentToolChoice;
138
+ toolCallsConcurrency?: number;
139
+ keepTextInToolUses?: boolean;
140
+ compact?: Omit<CompactConfig, "compactor"> & {
141
+ compactor?: NestAgentSchema;
142
+ };
127
143
  }
128
144
  /**
129
145
  * Tool choice options for AI agents
@@ -194,6 +210,7 @@ export declare class AIAgent<I extends Message = any, O extends Message = any> e
194
210
  static load<I extends Message = any, O extends Message = any>(options: {
195
211
  filepath: string;
196
212
  parsed: object;
213
+ options?: AgentLoadOptions;
197
214
  }): Promise<Agent<I, O>>;
198
215
  /**
199
216
  * Create an AIAgent with the specified options
@@ -225,8 +242,6 @@ export declare class AIAgent<I extends Message = any, O extends Message = any> e
225
242
  * {@includeCode ../../test/agents/ai-agent.test.ts#example-ai-agent-prompt-builder}
226
243
  */
227
244
  instructions: PromptBuilder;
228
- autoReorderSystemMessages?: boolean;
229
- autoMergeSystemMessages?: boolean;
230
245
  /**
231
246
  * Pick a message from input to use as the user's message
232
247
  */
@@ -322,6 +337,7 @@ export declare class AIAgent<I extends Message = any, O extends Message = any> e
322
337
  metadataEnd: string;
323
338
  parse: (raw: string) => object;
324
339
  };
340
+ compact?: CompactConfig;
325
341
  get inputSchema(): ZodType<I>;
326
342
  /**
327
343
  * Process an input message and generate a response
@@ -91,7 +91,6 @@ export declare const imageModelInputSchema: z.ZodObject<{
91
91
  }, "strip", z.ZodTypeAny, {
92
92
  prompt: string;
93
93
  modelOptions?: Record<string, unknown> | undefined;
94
- outputFileType?: "local" | "url" | "file" | undefined;
95
94
  image?: ({
96
95
  type: "url";
97
96
  url: string;
@@ -109,10 +108,10 @@ export declare const imageModelInputSchema: z.ZodObject<{
109
108
  mimeType?: string | undefined;
110
109
  })[] | undefined;
111
110
  n?: number | undefined;
111
+ outputFileType?: "local" | "file" | "url" | undefined;
112
112
  }, {
113
113
  prompt: string;
114
114
  modelOptions?: Record<string, unknown> | undefined;
115
- outputFileType?: "local" | "url" | "file" | undefined;
116
115
  image?: ({
117
116
  type: "url";
118
117
  url: string;
@@ -130,6 +129,7 @@ export declare const imageModelInputSchema: z.ZodObject<{
130
129
  mimeType?: string | undefined;
131
130
  })[] | undefined;
132
131
  n?: number | undefined;
132
+ outputFileType?: "local" | "file" | "url" | undefined;
133
133
  }>;
134
134
  export interface ImageModelOutput extends Message {
135
135
  images: FileUnionContent[];
@@ -232,6 +232,7 @@ export declare const imageModelOutputSchema: z.ZodObject<{
232
232
  filename?: string | undefined;
233
233
  mimeType?: string | undefined;
234
234
  })[];
235
+ model?: string | undefined;
235
236
  usage?: {
236
237
  inputTokens: number;
237
238
  outputTokens: number;
@@ -240,7 +241,6 @@ export declare const imageModelOutputSchema: z.ZodObject<{
240
241
  cacheReadInputTokens?: number | undefined;
241
242
  creditPrefix?: "$" | "€" | "¥" | undefined;
242
243
  } | undefined;
243
- model?: string | undefined;
244
244
  }, {
245
245
  images: ({
246
246
  type: "url";
@@ -258,6 +258,7 @@ export declare const imageModelOutputSchema: z.ZodObject<{
258
258
  filename?: string | undefined;
259
259
  mimeType?: string | undefined;
260
260
  })[];
261
+ model?: string | undefined;
261
262
  usage?: {
262
263
  inputTokens: number;
263
264
  outputTokens: number;
@@ -266,5 +267,4 @@ export declare const imageModelOutputSchema: z.ZodObject<{
266
267
  cacheReadInputTokens?: number | undefined;
267
268
  creditPrefix?: "$" | "€" | "¥" | undefined;
268
269
  } | undefined;
269
- model?: string | undefined;
270
270
  }>;
@@ -64,12 +64,12 @@ export declare class MCPAgent extends Agent {
64
64
  args: ZodType<string[] | undefined, z.ZodTypeDef, string[] | undefined>;
65
65
  }, "strip", z.ZodTypeAny, {
66
66
  url?: string | undefined;
67
- args?: string[] | undefined;
68
67
  command?: string | undefined;
68
+ args?: string[] | undefined;
69
69
  }, {
70
70
  url?: string | undefined;
71
- args?: string[] | undefined;
72
71
  command?: string | undefined;
72
+ args?: string[] | undefined;
73
73
  }>;
74
74
  static load<I extends Message = any, O extends Message = any>(options: {
75
75
  filepath: string;
@@ -94,7 +94,6 @@ export declare const videoModelInputSchema: z.ZodObject<{
94
94
  prompt: string;
95
95
  model?: string | undefined;
96
96
  modelOptions?: Record<string, unknown> | undefined;
97
- outputFileType?: "local" | "url" | "file" | undefined;
98
97
  image?: {
99
98
  type: "url";
100
99
  url: string;
@@ -111,13 +110,13 @@ export declare const videoModelInputSchema: z.ZodObject<{
111
110
  filename?: string | undefined;
112
111
  mimeType?: string | undefined;
113
112
  } | undefined;
113
+ outputFileType?: "local" | "file" | "url" | undefined;
114
114
  size?: string | undefined;
115
115
  seconds?: string | undefined;
116
116
  }, {
117
117
  prompt: string;
118
118
  model?: string | undefined;
119
119
  modelOptions?: Record<string, unknown> | undefined;
120
- outputFileType?: "local" | "url" | "file" | undefined;
121
120
  image?: {
122
121
  type: "url";
123
122
  url: string;
@@ -134,6 +133,7 @@ export declare const videoModelInputSchema: z.ZodObject<{
134
133
  filename?: string | undefined;
135
134
  mimeType?: string | undefined;
136
135
  } | undefined;
136
+ outputFileType?: "local" | "file" | "url" | undefined;
137
137
  size?: string | undefined;
138
138
  seconds?: string | undefined;
139
139
  }>;
@@ -240,6 +240,7 @@ export declare const videoModelOutputSchema: z.ZodObject<{
240
240
  filename?: string | undefined;
241
241
  mimeType?: string | undefined;
242
242
  })[];
243
+ model?: string | undefined;
243
244
  usage?: {
244
245
  inputTokens: number;
245
246
  outputTokens: number;
@@ -248,7 +249,6 @@ export declare const videoModelOutputSchema: z.ZodObject<{
248
249
  cacheReadInputTokens?: number | undefined;
249
250
  creditPrefix?: "$" | "€" | "¥" | undefined;
250
251
  } | undefined;
251
- model?: string | undefined;
252
252
  seconds?: number | undefined;
253
253
  }, {
254
254
  videos: ({
@@ -267,6 +267,7 @@ export declare const videoModelOutputSchema: z.ZodObject<{
267
267
  filename?: string | undefined;
268
268
  mimeType?: string | undefined;
269
269
  })[];
270
+ model?: string | undefined;
270
271
  usage?: {
271
272
  inputTokens: number;
272
273
  outputTokens: number;
@@ -275,6 +276,5 @@ export declare const videoModelOutputSchema: z.ZodObject<{
275
276
  cacheReadInputTokens?: number | undefined;
276
277
  creditPrefix?: "$" | "€" | "¥" | undefined;
277
278
  } | undefined;
278
- model?: string | undefined;
279
279
  seconds?: number | undefined;
280
280
  }>;
@@ -13,6 +13,7 @@ export * from "./agents/user-agent.js";
13
13
  export * from "./agents/video-model.js";
14
14
  export * from "./aigne/index.js";
15
15
  export * from "./memory/index.js";
16
+ export * from "./prompt/agent-session.js";
16
17
  export * from "./prompt/prompt-builder.js";
17
18
  export * from "./prompt/template.js";
18
19
  export * from "./utils/json-utils.js";
@@ -1,6 +1,6 @@
1
1
  import type { AFSOptions } from "@aigne/afs";
2
2
  import { type ZodType, z } from "zod";
3
- import type { Agent, AgentHooks, TaskRenderMode } from "../agents/agent.js";
3
+ import type { AgentHooks, TaskRenderMode } from "../agents/agent.js";
4
4
  import type { LoadOptions } from "./index.js";
5
5
  import { chatModelSchema, imageModelSchema } from "./schema.js";
6
6
  export interface HooksSchema {
@@ -65,7 +65,6 @@ export interface AgentSchema {
65
65
  context?: AFSContextSchema;
66
66
  });
67
67
  shareAFS?: boolean;
68
- historyConfig?: Agent["historyConfig"];
69
68
  [key: string]: unknown;
70
69
  }
71
70
  export declare function parseAgentFile(path: string, data: any, options: LoadOptions): Promise<AgentSchema>;