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

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 (65) hide show
  1. package/CHANGELOG.md +20 -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 +341 -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/template.d.ts +16 -16
  26. package/lib/dts/agents/agent.d.ts +2 -21
  27. package/lib/dts/agents/ai-agent.d.ts +20 -4
  28. package/lib/dts/agents/image-model.d.ts +4 -4
  29. package/lib/dts/agents/mcp-agent.d.ts +2 -2
  30. package/lib/dts/agents/video-model.d.ts +4 -4
  31. package/lib/dts/index.d.ts +1 -0
  32. package/lib/dts/loader/agent-yaml.d.ts +1 -2
  33. package/lib/dts/loader/index.d.ts +2 -2
  34. package/lib/dts/memory/recorder.d.ts +4 -4
  35. package/lib/dts/memory/retriever.d.ts +4 -4
  36. package/lib/dts/prompt/agent-session.d.ts +53 -0
  37. package/lib/dts/prompt/compact/compactor.d.ts +7 -0
  38. package/lib/dts/prompt/compact/types.d.ts +79 -0
  39. package/lib/dts/prompt/prompt-builder.d.ts +6 -8
  40. package/lib/dts/prompt/template.d.ts +16 -16
  41. package/lib/esm/agents/agent.d.ts +2 -21
  42. package/lib/esm/agents/agent.js +10 -15
  43. package/lib/esm/agents/ai-agent.d.ts +20 -4
  44. package/lib/esm/agents/ai-agent.js +37 -35
  45. package/lib/esm/agents/image-model.d.ts +4 -4
  46. package/lib/esm/agents/mcp-agent.d.ts +2 -2
  47. package/lib/esm/agents/video-model.d.ts +4 -4
  48. package/lib/esm/index.d.ts +1 -0
  49. package/lib/esm/index.js +1 -0
  50. package/lib/esm/loader/agent-yaml.d.ts +1 -2
  51. package/lib/esm/loader/agent-yaml.js +0 -8
  52. package/lib/esm/loader/index.d.ts +2 -2
  53. package/lib/esm/memory/recorder.d.ts +4 -4
  54. package/lib/esm/memory/retriever.d.ts +4 -4
  55. package/lib/esm/prompt/agent-session.d.ts +53 -0
  56. package/lib/esm/prompt/agent-session.js +304 -0
  57. package/lib/esm/prompt/compact/compactor.d.ts +7 -0
  58. package/lib/esm/prompt/compact/compactor.js +44 -0
  59. package/lib/esm/prompt/compact/types.d.ts +79 -0
  60. package/lib/esm/prompt/compact/types.js +16 -0
  61. package/lib/esm/prompt/context/afs/history.js +1 -1
  62. package/lib/esm/prompt/prompt-builder.d.ts +6 -8
  63. package/lib/esm/prompt/prompt-builder.js +68 -124
  64. package/lib/esm/prompt/template.d.ts +16 -16
  65. package/package.json +4 -4
@@ -137,7 +137,6 @@ declare const aigneFileSchema: z.ZodObject<{
137
137
  chat?: string | undefined;
138
138
  } | undefined>;
139
139
  }, "strip", z.ZodTypeAny, {
140
- name?: string | undefined;
141
140
  model?: z.objectInputType<{
142
141
  model: ZodType<string | {
143
142
  $get: string;
@@ -170,6 +169,7 @@ declare const aigneFileSchema: z.ZodObject<{
170
169
  $get: string;
171
170
  } | undefined>;
172
171
  }, z.ZodTypeAny, "passthrough"> | undefined;
172
+ name?: string | undefined;
173
173
  description?: string | undefined;
174
174
  imageModel?: z.objectInputType<{
175
175
  model: ZodType<string | {
@@ -188,7 +188,6 @@ declare const aigneFileSchema: z.ZodObject<{
188
188
  chat?: string | undefined;
189
189
  } | undefined;
190
190
  }, {
191
- name?: string | undefined;
192
191
  model?: z.objectInputType<{
193
192
  model: ZodType<string | {
194
193
  $get: string;
@@ -221,6 +220,7 @@ declare const aigneFileSchema: z.ZodObject<{
221
220
  $get: string;
222
221
  } | undefined>;
223
222
  }, z.ZodTypeAny, "passthrough"> | undefined;
223
+ name?: string | undefined;
224
224
  description?: string | undefined;
225
225
  imageModel?: z.objectInputType<{
226
226
  model: ZodType<string | {
@@ -42,24 +42,24 @@ export declare const memoryRecorderOutputSchema: z.ZodObject<{
42
42
  content: ZodType<{}, z.ZodTypeDef, {}>;
43
43
  createdAt: z.ZodString;
44
44
  }, "strip", z.ZodTypeAny, {
45
- content: {};
46
45
  id: string;
46
+ content: {};
47
47
  createdAt: string;
48
48
  }, {
49
- content: {};
50
49
  id: string;
50
+ content: {};
51
51
  createdAt: string;
52
52
  }>, "many">;
53
53
  }, "strip", z.ZodTypeAny, {
54
54
  memories: {
55
- content: {};
56
55
  id: string;
56
+ content: {};
57
57
  createdAt: string;
58
58
  }[];
59
59
  }, {
60
60
  memories: {
61
- content: {};
62
61
  id: string;
62
+ content: {};
63
63
  createdAt: string;
64
64
  }[];
65
65
  }>;
@@ -55,24 +55,24 @@ export declare const memoryRetrieverOutputSchema: z.ZodObject<{
55
55
  content: z.ZodType<{}, z.ZodTypeDef, {}>;
56
56
  createdAt: z.ZodString;
57
57
  }, "strip", z.ZodTypeAny, {
58
- content: {};
59
58
  id: string;
59
+ content: {};
60
60
  createdAt: string;
61
61
  }, {
62
- content: {};
63
62
  id: string;
63
+ content: {};
64
64
  createdAt: string;
65
65
  }>, "many">;
66
66
  }, "strip", z.ZodTypeAny, {
67
67
  memories: {
68
- content: {};
69
68
  id: string;
69
+ content: {};
70
70
  createdAt: string;
71
71
  }[];
72
72
  }, {
73
73
  memories: {
74
- content: {};
75
74
  id: string;
75
+ content: {};
76
76
  createdAt: string;
77
77
  }[];
78
78
  }>;
@@ -0,0 +1,53 @@
1
+ import type { AFS } from "@aigne/afs";
2
+ import type { AgentInvokeOptions } from "../agents/agent.js";
3
+ import type { ChatModelInputMessage } from "../agents/chat-model.js";
4
+ import { type CompactConfig, type CompactContent, type EntryContent } from "./compact/types.js";
5
+ export type { CompactConfig, CompactContent, EntryContent };
6
+ export interface AgentSessionOptions {
7
+ sessionId: string;
8
+ userId?: string;
9
+ agentId?: string;
10
+ afs?: AFS;
11
+ /**
12
+ * Compaction configuration
13
+ */
14
+ compact?: CompactConfig;
15
+ }
16
+ export declare class AgentSession {
17
+ readonly sessionId: string;
18
+ readonly userId?: string;
19
+ readonly agentId?: string;
20
+ private afs?;
21
+ private historyModulePath?;
22
+ private compactConfig;
23
+ private runtimeState;
24
+ private initialized?;
25
+ private compactionPromise?;
26
+ constructor(options: AgentSessionOptions);
27
+ setSystemMessages(...messages: ChatModelInputMessage[]): Promise<void>;
28
+ getMessages(): Promise<ChatModelInputMessage[]>;
29
+ startMessage(input: unknown, message: ChatModelInputMessage, options: AgentInvokeOptions): Promise<void>;
30
+ endMessage(output: unknown, options: AgentInvokeOptions): Promise<void>;
31
+ /**
32
+ * Manually trigger compaction
33
+ */
34
+ compact(options: AgentInvokeOptions): Promise<void>;
35
+ /**
36
+ * Internal method that performs the actual compaction
37
+ */
38
+ private doCompact;
39
+ private maybeAutoCompact;
40
+ /**
41
+ * Estimate token count for an array of messages
42
+ */
43
+ private estimateMessagesTokens;
44
+ /**
45
+ * Split entries into batches based on token limit
46
+ * Each batch will not exceed the specified maxTokens
47
+ */
48
+ private splitIntoBatches;
49
+ appendCurrentMessages(...messages: ChatModelInputMessage[]): Promise<void>;
50
+ private ensureInitialized;
51
+ private initialize;
52
+ private initializeDefaultCompactor;
53
+ }
@@ -0,0 +1,7 @@
1
+ import { AIAgent, type AIAgentOptions } from "../../agents/ai-agent.js";
2
+ import type { CompactContent, CompactorInput } from "./types.js";
3
+ export interface CreateCompactorOptions extends AIAgentOptions<CompactorInput, CompactContent> {
4
+ }
5
+ export declare class AISessionCompactor extends AIAgent<CompactorInput, CompactContent> {
6
+ constructor(options?: CreateCompactorOptions);
7
+ }
@@ -0,0 +1,79 @@
1
+ import type { Agent, Message } from "../../agents/agent.js";
2
+ import type { ChatModelInputMessage } from "../../agents/chat-model.js";
3
+ /**
4
+ * Default compaction mode
5
+ */
6
+ export declare const DEFAULT_COMPACT_MODE: "auto";
7
+ /**
8
+ * Default maximum tokens before triggering compaction
9
+ */
10
+ export declare const DEFAULT_MAX_TOKENS = 80000;
11
+ /**
12
+ * Default ratio of maxTokens to reserve for keeping recent messages
13
+ */
14
+ export declare const DEFAULT_KEEP_RECENT_RATIO = 0.5;
15
+ /**
16
+ * Default async mode for compaction
17
+ */
18
+ export declare const DEFAULT_COMPACT_ASYNC = true;
19
+ /**
20
+ * Content structure for history entries
21
+ */
22
+ export interface EntryContent {
23
+ input?: unknown;
24
+ output?: unknown;
25
+ messages?: ChatModelInputMessage[];
26
+ }
27
+ /**
28
+ * Output structure from the compactor agent
29
+ */
30
+ export interface CompactContent extends Message {
31
+ summary: string;
32
+ }
33
+ /**
34
+ * Input structure for the compactor agent
35
+ */
36
+ export interface CompactorInput extends Message {
37
+ previousSummary?: string[];
38
+ messages: ChatModelInputMessage[];
39
+ }
40
+ /**
41
+ * Type alias for a compactor agent
42
+ */
43
+ export type Compactor = Agent<CompactorInput, CompactContent>;
44
+ /**
45
+ * Configuration for session compaction
46
+ */
47
+ export interface CompactConfig {
48
+ /**
49
+ * Compaction mode
50
+ * @default DEFAULT_COMPACT_MODE ("auto")
51
+ */
52
+ mode?: "auto" | "disabled";
53
+ /**
54
+ * Maximum tokens before triggering compaction
55
+ * @default DEFAULT_MAX_TOKENS (80000)
56
+ */
57
+ maxTokens?: number;
58
+ /**
59
+ * Ratio of maxTokens to reserve for keeping recent messages (0-1)
60
+ *
61
+ * Defines what portion of maxTokens budget should be allocated for
62
+ * preserving recent conversation history without compaction.
63
+ *
64
+ * @default 0.5 (50% of maxTokens)
65
+ * @example 0.5 means if maxTokens=80000, keep up to 40000 tokens of recent messages
66
+ */
67
+ keepRecentRatio?: number;
68
+ /**
69
+ * Whether to perform compaction asynchronously
70
+ * @default DEFAULT_COMPACT_ASYNC (true)
71
+ */
72
+ async?: boolean;
73
+ /**
74
+ * Agent that generates summaries from conversation entries
75
+ * Input: { entries: EntryContent[] }
76
+ * Output: { summary: string }
77
+ */
78
+ compactor?: Compactor;
79
+ }
@@ -1,9 +1,10 @@
1
1
  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
- import { type ChatModel, type ChatModelInput, type ChatModelInputMessage } from "../agents/chat-model.js";
4
+ import type { ChatModel, ChatModelInput, ChatModelInputMessage } from "../agents/chat-model.js";
5
5
  import { type FileUnionContent } from "../agents/model.js";
6
6
  import type { Context } from "../aigne/context.js";
7
+ import { AgentSession } from "./agent-session.js";
7
8
  import { ChatMessagesTemplate } from "./template.js";
8
9
  export interface PromptBuilderOptions {
9
10
  instructions?: string | ChatMessagesTemplate;
@@ -28,7 +29,9 @@ export declare class PromptBuilder {
28
29
  instructions?: string | ChatMessagesTemplate;
29
30
  workingDir?: string;
30
31
  copy(): PromptBuilder;
31
- build(options: PromptBuildOptions): Promise<ChatModelInput & {
32
+ build(options: PromptBuildOptions): Promise<Omit<ChatModelInput, "messages"> & {
33
+ session: AgentSession;
34
+ userMessage: ChatModelInputMessage;
32
35
  toolAgents?: Agent[];
33
36
  }>;
34
37
  buildPrompt(options: Pick<PromptBuildOptions, "input" | "context"> & {
@@ -39,13 +42,8 @@ export declare class PromptBuilder {
39
42
  }>;
40
43
  private getTemplateVariables;
41
44
  private buildMessages;
45
+ private mergeMessages;
42
46
  protected deprecatedMemories(message: string | undefined, options: PromptBuildOptions): Promise<ChatModelInputMessage[]>;
43
- getHistories({ agentId, userId, sessionId, ...options }: PromptBuildOptions & {
44
- agentId?: string;
45
- userId?: string;
46
- sessionId?: string;
47
- }): Promise<ChatModelInputMessage[]>;
48
- private refineMessages;
49
47
  private convertMemoriesToMessages;
50
48
  private buildResponseFormat;
51
49
  private buildTools;
@@ -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:
@@ -104,7 +104,6 @@ export class Agent {
104
104
  if (options.skills?.length)
105
105
  this.skills.push(...options.skills.map(functionToAgent));
106
106
  this.disableEvents = options.disableEvents;
107
- this.historyConfig = options.historyConfig;
108
107
  if (Array.isArray(options.memory)) {
109
108
  this.memories.push(...options.memory);
110
109
  }
@@ -131,15 +130,15 @@ export class Agent {
131
130
  : options.retryOnError;
132
131
  this.guideRails = options.guideRails;
133
132
  }
133
+ afs;
134
+ tag;
134
135
  /**
135
136
  * List of memories this agent can use
136
137
  *
137
138
  * @deprecated use afs instead
138
139
  */
139
140
  memories = [];
140
- afs;
141
141
  asyncMemoryRecord;
142
- tag;
143
142
  /**
144
143
  * Maximum number of memory items to retrieve
145
144
  */
@@ -284,7 +283,6 @@ export class Agent {
284
283
  * agentSucceed, or agentFailed
285
284
  */
286
285
  disableEvents;
287
- historyConfig;
288
286
  subscriptions = [];
289
287
  /**
290
288
  * Attach agent to context:
@@ -532,17 +530,14 @@ export class Agent {
532
530
  const o = await this.callHooks(["onSuccess", "onEnd"], { input, output: finalOutput }, options);
533
531
  if (o?.output)
534
532
  finalOutput = o.output;
535
- if (this.historyConfig?.record === true ||
536
- (this.historyConfig?.record !== false && this.historyConfig?.enabled)) {
537
- this.afs?.emit("agentSucceed", {
538
- agentId: this.name,
539
- userId: context.userContext.userId,
540
- sessionId: context.userContext.sessionId,
541
- input,
542
- output: finalOutput,
543
- messages,
544
- });
545
- }
533
+ this.afs?.emit("agentSucceed", {
534
+ agentId: this.name,
535
+ userId: context.userContext.userId,
536
+ sessionId: context.userContext.sessionId,
537
+ input,
538
+ output: finalOutput,
539
+ messages,
540
+ });
546
541
  if (!this.disableEvents)
547
542
  context.emit("agentSucceed", { agent: this, output: finalOutput });
548
543
  return finalOutput;
@@ -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