@aigne/core 1.18.4 → 1.18.5
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 +7 -0
- package/lib/cjs/agents/agent.js +5 -0
- package/lib/cjs/aigne/context.d.ts +5 -0
- package/lib/cjs/aigne/context.js +22 -2
- package/lib/cjs/prompt/prompt-builder.d.ts +1 -1
- package/lib/cjs/prompt/prompt-builder.js +2 -2
- package/lib/dts/aigne/context.d.ts +5 -0
- package/lib/dts/prompt/prompt-builder.d.ts +1 -1
- package/lib/esm/agents/agent.js +5 -0
- package/lib/esm/aigne/context.d.ts +5 -0
- package/lib/esm/aigne/context.js +22 -2
- package/lib/esm/prompt/prompt-builder.d.ts +1 -1
- package/lib/esm/prompt/prompt-builder.js +2 -2
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,13 @@
|
|
|
5
5
|
|
|
6
6
|
* add user context support ([#131](https://github.com/AIGNE-io/aigne-framework/issues/131)) ([4dd9d20](https://github.com/AIGNE-io/aigne-framework/commit/4dd9d20953f6ac33933723db56efd9b44bafeb02))
|
|
7
7
|
|
|
8
|
+
## [1.18.5](https://github.com/AIGNE-io/aigne-framework/compare/core-v1.18.4...core-v1.18.5) (2025-06-06)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
* **core:** should pass memories from invocation options to nested agents ([#153](https://github.com/AIGNE-io/aigne-framework/issues/153)) ([57629a5](https://github.com/AIGNE-io/aigne-framework/commit/57629a5da6cf2a295356dfe32ecbb15154e098fe))
|
|
14
|
+
|
|
8
15
|
## [1.18.4](https://github.com/AIGNE-io/aigne-framework/compare/core-v1.18.3...core-v1.18.4) (2025-06-05)
|
|
9
16
|
|
|
10
17
|
|
package/lib/cjs/agents/agent.js
CHANGED
|
@@ -336,6 +336,11 @@ class Agent {
|
|
|
336
336
|
};
|
|
337
337
|
if (options.userContext) {
|
|
338
338
|
Object.assign(opts.context.userContext, options.userContext);
|
|
339
|
+
options.userContext = undefined;
|
|
340
|
+
}
|
|
341
|
+
if (options.memories?.length) {
|
|
342
|
+
opts.context.memories.push(...options.memories);
|
|
343
|
+
options.memories = undefined;
|
|
339
344
|
}
|
|
340
345
|
const message = typeof input === "string" ? (0, prompt_builder_js_1.createMessage)(input) : input;
|
|
341
346
|
logger_js_1.logger.debug("Invoke agent %s started with input: %O", this.name, input);
|
|
@@ -2,6 +2,7 @@ import { Emitter } from "strict-event-emitter";
|
|
|
2
2
|
import { Agent, type AgentInvokeOptions, type AgentProcessAsyncGenerator, type AgentResponse, type AgentResponseStream, type Message } from "../agents/agent.js";
|
|
3
3
|
import type { ChatModel } from "../agents/chat-model.js";
|
|
4
4
|
import { UserAgent } from "../agents/user-agent.js";
|
|
5
|
+
import type { Memory } from "../memory/memory.js";
|
|
5
6
|
import { type OmitPropertiesFromArrayFirstElement } from "../utils/type-utils.js";
|
|
6
7
|
import type { Args, Listener, TypedEventEmitter } from "../utils/typed-event-emtter.js";
|
|
7
8
|
import { type MessagePayload, MessageQueue, type MessageQueueListener, type Unsubscribe } from "./message-queue.js";
|
|
@@ -58,6 +59,7 @@ export interface Context<U extends UserContext = UserContext> extends TypedEvent
|
|
|
58
59
|
limits?: ContextLimits;
|
|
59
60
|
status?: "normal" | "timeout";
|
|
60
61
|
userContext: U;
|
|
62
|
+
memories: Pick<Memory, "content">[];
|
|
61
63
|
/**
|
|
62
64
|
* Create a user agent to consistently invoke an agent
|
|
63
65
|
* @param agent Agent to invoke
|
|
@@ -131,6 +133,8 @@ export declare class AIGNEContext implements Context {
|
|
|
131
133
|
get usage(): ContextUsage;
|
|
132
134
|
get userContext(): Context["userContext"];
|
|
133
135
|
set userContext(userContext: Context["userContext"]);
|
|
136
|
+
get memories(): Context["memories"];
|
|
137
|
+
set memories(memories: Context["memories"]);
|
|
134
138
|
newContext({ reset }?: {
|
|
135
139
|
reset?: boolean;
|
|
136
140
|
}): AIGNEContext;
|
|
@@ -155,6 +159,7 @@ declare class AIGNEContextShared {
|
|
|
155
159
|
get limits(): ContextLimits | undefined;
|
|
156
160
|
usage: ContextUsage;
|
|
157
161
|
userContext: Context["userContext"];
|
|
162
|
+
memories: Context["memories"];
|
|
158
163
|
private abortController;
|
|
159
164
|
private timer?;
|
|
160
165
|
private initTimeout;
|
package/lib/cjs/aigne/context.js
CHANGED
|
@@ -54,6 +54,12 @@ class AIGNEContext {
|
|
|
54
54
|
set userContext(userContext) {
|
|
55
55
|
this.internal.userContext = userContext;
|
|
56
56
|
}
|
|
57
|
+
get memories() {
|
|
58
|
+
return this.internal.memories;
|
|
59
|
+
}
|
|
60
|
+
set memories(memories) {
|
|
61
|
+
this.internal.memories = memories;
|
|
62
|
+
}
|
|
57
63
|
newContext({ reset } = {}) {
|
|
58
64
|
if (reset)
|
|
59
65
|
return new AIGNEContext(this, { userContext: {} });
|
|
@@ -65,8 +71,14 @@ class AIGNEContext {
|
|
|
65
71
|
message,
|
|
66
72
|
options,
|
|
67
73
|
});
|
|
68
|
-
if (options?.userContext)
|
|
74
|
+
if (options?.userContext) {
|
|
69
75
|
Object.assign(this.userContext, options.userContext);
|
|
76
|
+
options.userContext = undefined;
|
|
77
|
+
}
|
|
78
|
+
if (options?.memories?.length) {
|
|
79
|
+
this.memories.push(...options.memories);
|
|
80
|
+
options.memories = undefined;
|
|
81
|
+
}
|
|
70
82
|
if ((0, type_utils_js_1.isNil)(message)) {
|
|
71
83
|
return user_agent_js_1.UserAgent.from({
|
|
72
84
|
context: this,
|
|
@@ -107,8 +119,14 @@ class AIGNEContext {
|
|
|
107
119
|
});
|
|
108
120
|
});
|
|
109
121
|
publish = ((topic, payload, options) => {
|
|
110
|
-
if (options?.userContext)
|
|
122
|
+
if (options?.userContext) {
|
|
111
123
|
Object.assign(this.userContext, options.userContext);
|
|
124
|
+
options.userContext = undefined;
|
|
125
|
+
}
|
|
126
|
+
if (options?.memories?.length) {
|
|
127
|
+
this.memories.push(...options.memories);
|
|
128
|
+
options.memories = undefined;
|
|
129
|
+
}
|
|
112
130
|
return this.internal.messageQueue.publish(topic, {
|
|
113
131
|
...(0, message_queue_js_1.toMessagePayload)(payload),
|
|
114
132
|
context: this,
|
|
@@ -150,6 +168,7 @@ class AIGNEContextShared {
|
|
|
150
168
|
this.parent = parent;
|
|
151
169
|
this.messageQueue = this.parent?.messageQueue ?? new message_queue_js_1.MessageQueue();
|
|
152
170
|
this.userContext = overrides?.userContext ?? {};
|
|
171
|
+
this.memories = overrides?.memories ?? [];
|
|
153
172
|
}
|
|
154
173
|
messageQueue;
|
|
155
174
|
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
|
@@ -165,6 +184,7 @@ class AIGNEContextShared {
|
|
|
165
184
|
}
|
|
166
185
|
usage = (0, usage_js_1.newEmptyContextUsage)();
|
|
167
186
|
userContext;
|
|
187
|
+
memories;
|
|
168
188
|
abortController = new AbortController();
|
|
169
189
|
timer;
|
|
170
190
|
initTimeout() {
|
|
@@ -15,7 +15,7 @@ export declare function getMessage(input: Message): string | undefined;
|
|
|
15
15
|
export interface PromptBuilderOptions {
|
|
16
16
|
instructions?: string | ChatMessagesTemplate;
|
|
17
17
|
}
|
|
18
|
-
export interface PromptBuildOptions extends AgentInvokeOptions {
|
|
18
|
+
export interface PromptBuildOptions extends Pick<AgentInvokeOptions, "context"> {
|
|
19
19
|
agent?: AIAgent;
|
|
20
20
|
input?: Message;
|
|
21
21
|
model?: ChatModel;
|
|
@@ -87,8 +87,8 @@ class PromptBuilder {
|
|
|
87
87
|
if (options.agent) {
|
|
88
88
|
memories.push(...(await options.agent.retrieveMemories({ search: options.input }, options)));
|
|
89
89
|
}
|
|
90
|
-
if (options.memories?.length) {
|
|
91
|
-
memories.push(...options.memories);
|
|
90
|
+
if (options.context.memories?.length) {
|
|
91
|
+
memories.push(...options.context.memories);
|
|
92
92
|
}
|
|
93
93
|
if (memories.length)
|
|
94
94
|
messages.push(...this.convertMemoriesToMessages(memories, options));
|
|
@@ -2,6 +2,7 @@ import { Emitter } from "strict-event-emitter";
|
|
|
2
2
|
import { Agent, type AgentInvokeOptions, type AgentProcessAsyncGenerator, type AgentResponse, type AgentResponseStream, type Message } from "../agents/agent.js";
|
|
3
3
|
import type { ChatModel } from "../agents/chat-model.js";
|
|
4
4
|
import { UserAgent } from "../agents/user-agent.js";
|
|
5
|
+
import type { Memory } from "../memory/memory.js";
|
|
5
6
|
import { type OmitPropertiesFromArrayFirstElement } from "../utils/type-utils.js";
|
|
6
7
|
import type { Args, Listener, TypedEventEmitter } from "../utils/typed-event-emtter.js";
|
|
7
8
|
import { type MessagePayload, MessageQueue, type MessageQueueListener, type Unsubscribe } from "./message-queue.js";
|
|
@@ -58,6 +59,7 @@ export interface Context<U extends UserContext = UserContext> extends TypedEvent
|
|
|
58
59
|
limits?: ContextLimits;
|
|
59
60
|
status?: "normal" | "timeout";
|
|
60
61
|
userContext: U;
|
|
62
|
+
memories: Pick<Memory, "content">[];
|
|
61
63
|
/**
|
|
62
64
|
* Create a user agent to consistently invoke an agent
|
|
63
65
|
* @param agent Agent to invoke
|
|
@@ -131,6 +133,8 @@ export declare class AIGNEContext implements Context {
|
|
|
131
133
|
get usage(): ContextUsage;
|
|
132
134
|
get userContext(): Context["userContext"];
|
|
133
135
|
set userContext(userContext: Context["userContext"]);
|
|
136
|
+
get memories(): Context["memories"];
|
|
137
|
+
set memories(memories: Context["memories"]);
|
|
134
138
|
newContext({ reset }?: {
|
|
135
139
|
reset?: boolean;
|
|
136
140
|
}): AIGNEContext;
|
|
@@ -155,6 +159,7 @@ declare class AIGNEContextShared {
|
|
|
155
159
|
get limits(): ContextLimits | undefined;
|
|
156
160
|
usage: ContextUsage;
|
|
157
161
|
userContext: Context["userContext"];
|
|
162
|
+
memories: Context["memories"];
|
|
158
163
|
private abortController;
|
|
159
164
|
private timer?;
|
|
160
165
|
private initTimeout;
|
|
@@ -15,7 +15,7 @@ export declare function getMessage(input: Message): string | undefined;
|
|
|
15
15
|
export interface PromptBuilderOptions {
|
|
16
16
|
instructions?: string | ChatMessagesTemplate;
|
|
17
17
|
}
|
|
18
|
-
export interface PromptBuildOptions extends AgentInvokeOptions {
|
|
18
|
+
export interface PromptBuildOptions extends Pick<AgentInvokeOptions, "context"> {
|
|
19
19
|
agent?: AIAgent;
|
|
20
20
|
input?: Message;
|
|
21
21
|
model?: ChatModel;
|
package/lib/esm/agents/agent.js
CHANGED
|
@@ -294,6 +294,11 @@ export class Agent {
|
|
|
294
294
|
};
|
|
295
295
|
if (options.userContext) {
|
|
296
296
|
Object.assign(opts.context.userContext, options.userContext);
|
|
297
|
+
options.userContext = undefined;
|
|
298
|
+
}
|
|
299
|
+
if (options.memories?.length) {
|
|
300
|
+
opts.context.memories.push(...options.memories);
|
|
301
|
+
options.memories = undefined;
|
|
297
302
|
}
|
|
298
303
|
const message = typeof input === "string" ? createMessage(input) : input;
|
|
299
304
|
logger.debug("Invoke agent %s started with input: %O", this.name, input);
|
|
@@ -2,6 +2,7 @@ import { Emitter } from "strict-event-emitter";
|
|
|
2
2
|
import { Agent, type AgentInvokeOptions, type AgentProcessAsyncGenerator, type AgentResponse, type AgentResponseStream, type Message } from "../agents/agent.js";
|
|
3
3
|
import type { ChatModel } from "../agents/chat-model.js";
|
|
4
4
|
import { UserAgent } from "../agents/user-agent.js";
|
|
5
|
+
import type { Memory } from "../memory/memory.js";
|
|
5
6
|
import { type OmitPropertiesFromArrayFirstElement } from "../utils/type-utils.js";
|
|
6
7
|
import type { Args, Listener, TypedEventEmitter } from "../utils/typed-event-emtter.js";
|
|
7
8
|
import { type MessagePayload, MessageQueue, type MessageQueueListener, type Unsubscribe } from "./message-queue.js";
|
|
@@ -58,6 +59,7 @@ export interface Context<U extends UserContext = UserContext> extends TypedEvent
|
|
|
58
59
|
limits?: ContextLimits;
|
|
59
60
|
status?: "normal" | "timeout";
|
|
60
61
|
userContext: U;
|
|
62
|
+
memories: Pick<Memory, "content">[];
|
|
61
63
|
/**
|
|
62
64
|
* Create a user agent to consistently invoke an agent
|
|
63
65
|
* @param agent Agent to invoke
|
|
@@ -131,6 +133,8 @@ export declare class AIGNEContext implements Context {
|
|
|
131
133
|
get usage(): ContextUsage;
|
|
132
134
|
get userContext(): Context["userContext"];
|
|
133
135
|
set userContext(userContext: Context["userContext"]);
|
|
136
|
+
get memories(): Context["memories"];
|
|
137
|
+
set memories(memories: Context["memories"]);
|
|
134
138
|
newContext({ reset }?: {
|
|
135
139
|
reset?: boolean;
|
|
136
140
|
}): AIGNEContext;
|
|
@@ -155,6 +159,7 @@ declare class AIGNEContextShared {
|
|
|
155
159
|
get limits(): ContextLimits | undefined;
|
|
156
160
|
usage: ContextUsage;
|
|
157
161
|
userContext: Context["userContext"];
|
|
162
|
+
memories: Context["memories"];
|
|
158
163
|
private abortController;
|
|
159
164
|
private timer?;
|
|
160
165
|
private initTimeout;
|
package/lib/esm/aigne/context.js
CHANGED
|
@@ -48,6 +48,12 @@ export class AIGNEContext {
|
|
|
48
48
|
set userContext(userContext) {
|
|
49
49
|
this.internal.userContext = userContext;
|
|
50
50
|
}
|
|
51
|
+
get memories() {
|
|
52
|
+
return this.internal.memories;
|
|
53
|
+
}
|
|
54
|
+
set memories(memories) {
|
|
55
|
+
this.internal.memories = memories;
|
|
56
|
+
}
|
|
51
57
|
newContext({ reset } = {}) {
|
|
52
58
|
if (reset)
|
|
53
59
|
return new AIGNEContext(this, { userContext: {} });
|
|
@@ -59,8 +65,14 @@ export class AIGNEContext {
|
|
|
59
65
|
message,
|
|
60
66
|
options,
|
|
61
67
|
});
|
|
62
|
-
if (options?.userContext)
|
|
68
|
+
if (options?.userContext) {
|
|
63
69
|
Object.assign(this.userContext, options.userContext);
|
|
70
|
+
options.userContext = undefined;
|
|
71
|
+
}
|
|
72
|
+
if (options?.memories?.length) {
|
|
73
|
+
this.memories.push(...options.memories);
|
|
74
|
+
options.memories = undefined;
|
|
75
|
+
}
|
|
64
76
|
if (isNil(message)) {
|
|
65
77
|
return UserAgent.from({
|
|
66
78
|
context: this,
|
|
@@ -101,8 +113,14 @@ export class AIGNEContext {
|
|
|
101
113
|
});
|
|
102
114
|
});
|
|
103
115
|
publish = ((topic, payload, options) => {
|
|
104
|
-
if (options?.userContext)
|
|
116
|
+
if (options?.userContext) {
|
|
105
117
|
Object.assign(this.userContext, options.userContext);
|
|
118
|
+
options.userContext = undefined;
|
|
119
|
+
}
|
|
120
|
+
if (options?.memories?.length) {
|
|
121
|
+
this.memories.push(...options.memories);
|
|
122
|
+
options.memories = undefined;
|
|
123
|
+
}
|
|
106
124
|
return this.internal.messageQueue.publish(topic, {
|
|
107
125
|
...toMessagePayload(payload),
|
|
108
126
|
context: this,
|
|
@@ -143,6 +161,7 @@ class AIGNEContextShared {
|
|
|
143
161
|
this.parent = parent;
|
|
144
162
|
this.messageQueue = this.parent?.messageQueue ?? new MessageQueue();
|
|
145
163
|
this.userContext = overrides?.userContext ?? {};
|
|
164
|
+
this.memories = overrides?.memories ?? [];
|
|
146
165
|
}
|
|
147
166
|
messageQueue;
|
|
148
167
|
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
|
@@ -158,6 +177,7 @@ class AIGNEContextShared {
|
|
|
158
177
|
}
|
|
159
178
|
usage = newEmptyContextUsage();
|
|
160
179
|
userContext;
|
|
180
|
+
memories;
|
|
161
181
|
abortController = new AbortController();
|
|
162
182
|
timer;
|
|
163
183
|
initTimeout() {
|
|
@@ -15,7 +15,7 @@ export declare function getMessage(input: Message): string | undefined;
|
|
|
15
15
|
export interface PromptBuilderOptions {
|
|
16
16
|
instructions?: string | ChatMessagesTemplate;
|
|
17
17
|
}
|
|
18
|
-
export interface PromptBuildOptions extends AgentInvokeOptions {
|
|
18
|
+
export interface PromptBuildOptions extends Pick<AgentInvokeOptions, "context"> {
|
|
19
19
|
agent?: AIAgent;
|
|
20
20
|
input?: Message;
|
|
21
21
|
model?: ChatModel;
|
|
@@ -82,8 +82,8 @@ export class PromptBuilder {
|
|
|
82
82
|
if (options.agent) {
|
|
83
83
|
memories.push(...(await options.agent.retrieveMemories({ search: options.input }, options)));
|
|
84
84
|
}
|
|
85
|
-
if (options.memories?.length) {
|
|
86
|
-
memories.push(...options.memories);
|
|
85
|
+
if (options.context.memories?.length) {
|
|
86
|
+
memories.push(...options.context.memories);
|
|
87
87
|
}
|
|
88
88
|
if (memories.length)
|
|
89
89
|
messages.push(...this.convertMemoriesToMessages(memories, options));
|