@aigne/core 1.22.0 → 1.23.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 +33 -87
- package/lib/cjs/agents/agent.d.ts +15 -10
- package/lib/cjs/agents/agent.js +6 -10
- package/lib/cjs/agents/ai-agent.d.ts +1 -1
- package/lib/cjs/agents/mcp-agent.d.ts +1 -1
- package/lib/cjs/aigne/aigne.d.ts +4 -4
- package/lib/cjs/aigne/aigne.js +2 -0
- package/lib/cjs/aigne/context.d.ts +2 -2
- package/lib/cjs/loader/index.d.ts +2 -2
- package/lib/cjs/memory/memory.d.ts +5 -3
- package/lib/cjs/memory/memory.js +17 -3
- package/lib/cjs/memory/recorder.d.ts +14 -8
- package/lib/cjs/memory/recorder.js +13 -1
- package/lib/cjs/memory/retriever.d.ts +13 -7
- package/lib/cjs/memory/retriever.js +9 -1
- package/lib/cjs/utils/type-utils.d.ts +1 -0
- package/lib/cjs/utils/type-utils.js +5 -0
- package/lib/dts/agents/agent.d.ts +15 -10
- package/lib/dts/agents/ai-agent.d.ts +1 -1
- package/lib/dts/agents/mcp-agent.d.ts +1 -1
- package/lib/dts/aigne/aigne.d.ts +4 -4
- package/lib/dts/aigne/context.d.ts +2 -2
- package/lib/dts/loader/index.d.ts +2 -2
- package/lib/dts/memory/memory.d.ts +5 -3
- package/lib/dts/memory/recorder.d.ts +14 -8
- package/lib/dts/memory/retriever.d.ts +13 -7
- package/lib/dts/utils/type-utils.d.ts +1 -0
- package/lib/esm/agents/agent.d.ts +15 -10
- package/lib/esm/agents/agent.js +6 -10
- package/lib/esm/agents/ai-agent.d.ts +1 -1
- package/lib/esm/agents/mcp-agent.d.ts +1 -1
- package/lib/esm/aigne/aigne.d.ts +4 -4
- package/lib/esm/aigne/aigne.js +2 -0
- package/lib/esm/aigne/context.d.ts +2 -2
- package/lib/esm/loader/index.d.ts +2 -2
- package/lib/esm/memory/memory.d.ts +5 -3
- package/lib/esm/memory/memory.js +17 -3
- package/lib/esm/memory/recorder.d.ts +14 -8
- package/lib/esm/memory/recorder.js +14 -2
- package/lib/esm/memory/retriever.d.ts +13 -7
- package/lib/esm/memory/retriever.js +10 -2
- package/lib/esm/utils/type-utils.d.ts +1 -0
- package/lib/esm/utils/type-utils.js +4 -0
- package/package.json +2 -2
|
@@ -37,7 +37,7 @@ export type PublishTopic<O extends Message> = string | string[] | ((output: O) =
|
|
|
37
37
|
* @template I The agent input message type
|
|
38
38
|
* @template O The agent output message type
|
|
39
39
|
*/
|
|
40
|
-
export interface AgentOptions<I extends Message = Message, O extends Message = Message> extends Partial<Pick<Agent, "guideRails"
|
|
40
|
+
export interface AgentOptions<I extends Message = Message, O extends Message = Message> extends Partial<Pick<Agent, "guideRails">> {
|
|
41
41
|
/**
|
|
42
42
|
* Topics the agent should subscribe to
|
|
43
43
|
*
|
|
@@ -106,6 +106,7 @@ export interface AgentOptions<I extends Message = Message, O extends Message = M
|
|
|
106
106
|
* Maximum number of memory items to retrieve
|
|
107
107
|
*/
|
|
108
108
|
maxRetrieveMemoryCount?: number;
|
|
109
|
+
hooks?: AgentHooks<I, O>;
|
|
109
110
|
}
|
|
110
111
|
export declare const agentOptionsSchema: ZodObject<{
|
|
111
112
|
[key in keyof AgentOptions]: ZodType<AgentOptions[key]>;
|
|
@@ -161,7 +162,7 @@ export interface AgentInvokeOptions<U extends UserContext = UserContext> {
|
|
|
161
162
|
* Here's an example of how to create a custom agent:
|
|
162
163
|
* {@includeCode ../../test/agents/agent.test.ts#example-custom-agent}
|
|
163
164
|
*/
|
|
164
|
-
export declare abstract class Agent<I extends Message =
|
|
165
|
+
export declare abstract class Agent<I extends Message = any, O extends Message = any> {
|
|
165
166
|
/**
|
|
166
167
|
* Custom object inspection behavior
|
|
167
168
|
*
|
|
@@ -191,7 +192,7 @@ export declare abstract class Agent<I extends Message = Message, O extends Messa
|
|
|
191
192
|
* Here's an example of using hooks:
|
|
192
193
|
* {@includeCode ../../test/agents/agent.test.ts#example-agent-hooks}
|
|
193
194
|
*/
|
|
194
|
-
readonly hooks: AgentHooks
|
|
195
|
+
readonly hooks: AgentHooks<I, O>;
|
|
195
196
|
/**
|
|
196
197
|
* List of GuideRail agents applied to this agent
|
|
197
198
|
*
|
|
@@ -277,8 +278,8 @@ export declare abstract class Agent<I extends Message = Message, O extends Messa
|
|
|
277
278
|
* Skills can be accessed by name or by array index, allowing
|
|
278
279
|
* the agent to delegate tasks to specialized sub-agents
|
|
279
280
|
*/
|
|
280
|
-
readonly skills: Agent<
|
|
281
|
-
[key: string]: Agent<
|
|
281
|
+
readonly skills: Agent<any, any>[] & {
|
|
282
|
+
[key: string]: Agent<any, any>;
|
|
282
283
|
};
|
|
283
284
|
/**
|
|
284
285
|
* Whether to disable emitting events for agent actions
|
|
@@ -519,7 +520,9 @@ export interface AgentHooks<I extends Message = Message, O extends Message = Mes
|
|
|
519
520
|
onStart?: (event: {
|
|
520
521
|
context: Context;
|
|
521
522
|
input: I;
|
|
522
|
-
}) => PromiseOrValue<void
|
|
523
|
+
}) => PromiseOrValue<void | {
|
|
524
|
+
input?: I;
|
|
525
|
+
}>;
|
|
523
526
|
/**
|
|
524
527
|
* Called when agent processing completes or fails
|
|
525
528
|
*
|
|
@@ -534,7 +537,9 @@ export interface AgentHooks<I extends Message = Message, O extends Message = Mes
|
|
|
534
537
|
input: I;
|
|
535
538
|
output: O;
|
|
536
539
|
error: Error;
|
|
537
|
-
}, "output", "error">) => PromiseOrValue<void
|
|
540
|
+
}, "output", "error">) => PromiseOrValue<void | {
|
|
541
|
+
output?: O;
|
|
542
|
+
}>;
|
|
538
543
|
/**
|
|
539
544
|
* Called before a skill (sub-agent) is invoked
|
|
540
545
|
*
|
|
@@ -546,7 +551,7 @@ export interface AgentHooks<I extends Message = Message, O extends Message = Mes
|
|
|
546
551
|
onSkillStart?: (event: {
|
|
547
552
|
context: Context;
|
|
548
553
|
skill: Agent;
|
|
549
|
-
input:
|
|
554
|
+
input: Message;
|
|
550
555
|
}) => PromiseOrValue<void>;
|
|
551
556
|
/**
|
|
552
557
|
* Called after a skill (sub-agent) completes or fails
|
|
@@ -560,8 +565,8 @@ export interface AgentHooks<I extends Message = Message, O extends Message = Mes
|
|
|
560
565
|
onSkillEnd?: (event: XOr<{
|
|
561
566
|
context: Context;
|
|
562
567
|
skill: Agent;
|
|
563
|
-
input:
|
|
564
|
-
output:
|
|
568
|
+
input: Message;
|
|
569
|
+
output: Message;
|
|
565
570
|
error: Error;
|
|
566
571
|
}, "output", "error">) => PromiseOrValue<void>;
|
|
567
572
|
/**
|
|
@@ -131,7 +131,7 @@ export declare const aiAgentOptionsSchema: ZodObject<{
|
|
|
131
131
|
* Basic AIAgent creation:
|
|
132
132
|
* {@includeCode ../../test/agents/ai-agent.test.ts#example-ai-agent-basic}
|
|
133
133
|
*/
|
|
134
|
-
export declare class AIAgent<I extends Message =
|
|
134
|
+
export declare class AIAgent<I extends Message = any, O extends Message = any> extends Agent<I, O> {
|
|
135
135
|
tag: string;
|
|
136
136
|
/**
|
|
137
137
|
* Create an AIAgent with the specified options
|
|
@@ -183,7 +183,7 @@ declare class ClientWithReconnect extends Client {
|
|
|
183
183
|
private reconnect;
|
|
184
184
|
request<T extends ZodType<object>>(request: Request, resultSchema: T, options?: RequestOptions): Promise<z.infer<T>>;
|
|
185
185
|
}
|
|
186
|
-
export interface MCPBaseOptions<I extends Message =
|
|
186
|
+
export interface MCPBaseOptions<I extends Message = any, O extends Message = any> extends AgentOptions<I, O> {
|
|
187
187
|
client: ClientWithReconnect;
|
|
188
188
|
}
|
|
189
189
|
export declare abstract class MCPBase<I extends Message, O extends Message> extends Agent<I, O> {
|
package/lib/dts/aigne/aigne.d.ts
CHANGED
|
@@ -93,15 +93,15 @@ export declare class AIGNE<U extends UserContext = UserContext> {
|
|
|
93
93
|
* Collection of skill agents available to this AIGNE instance.
|
|
94
94
|
* Provides indexed access by skill name.
|
|
95
95
|
*/
|
|
96
|
-
readonly skills: Agent<
|
|
97
|
-
[key: string]: Agent<
|
|
96
|
+
readonly skills: Agent<any, any>[] & {
|
|
97
|
+
[key: string]: Agent<any, any>;
|
|
98
98
|
};
|
|
99
99
|
/**
|
|
100
100
|
* Collection of primary agents managed by this AIGNE instance.
|
|
101
101
|
* Provides indexed access by agent name.
|
|
102
102
|
*/
|
|
103
|
-
readonly agents: Agent<
|
|
104
|
-
[key: string]: Agent<
|
|
103
|
+
readonly agents: Agent<any, any>[] & {
|
|
104
|
+
[key: string]: Agent<any, any>;
|
|
105
105
|
};
|
|
106
106
|
/**
|
|
107
107
|
* Observer for the AIGNE instance.
|
|
@@ -148,7 +148,7 @@ export declare class AIGNEContext implements Context {
|
|
|
148
148
|
readonly internal: AIGNEContextShared;
|
|
149
149
|
get messageQueue(): MessageQueue;
|
|
150
150
|
get model(): ChatModel | undefined;
|
|
151
|
-
get skills(): Agent<
|
|
151
|
+
get skills(): Agent<any, any>[] | undefined;
|
|
152
152
|
get observer(): AIGNEObserver | undefined;
|
|
153
153
|
get limits(): ContextLimits | undefined;
|
|
154
154
|
get status(): "normal" | "timeout";
|
|
@@ -180,7 +180,7 @@ declare class AIGNEContextShared {
|
|
|
180
180
|
readonly messageQueue: MessageQueue;
|
|
181
181
|
readonly events: Emitter<any>;
|
|
182
182
|
get model(): ChatModel | undefined;
|
|
183
|
-
get skills(): Agent<
|
|
183
|
+
get skills(): Agent<any, any>[] | undefined;
|
|
184
184
|
get observer(): AIGNEObserver | undefined;
|
|
185
185
|
get limits(): ContextLimits | undefined;
|
|
186
186
|
usage: ContextUsage;
|
|
@@ -17,8 +17,8 @@ export interface LoadOptions {
|
|
|
17
17
|
}
|
|
18
18
|
export declare function load(options: LoadOptions): Promise<{
|
|
19
19
|
model: ChatModel | undefined;
|
|
20
|
-
agents: Agent<
|
|
21
|
-
skills: Agent<
|
|
20
|
+
agents: Agent<any, any>[];
|
|
21
|
+
skills: Agent<any, any>[];
|
|
22
22
|
name?: string | null | undefined;
|
|
23
23
|
description?: string | null | undefined;
|
|
24
24
|
chat_model?: {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Agent, type AgentInvokeOptions, type AgentOptions, type Message } from "../agents/agent.js";
|
|
2
2
|
import type { Context } from "../aigne/context.js";
|
|
3
3
|
import type { MessagePayload } from "../aigne/message-queue.js";
|
|
4
|
-
import
|
|
5
|
-
import
|
|
4
|
+
import { MemoryRecorder, type MemoryRecorderInput, type MemoryRecorderOptions, type MemoryRecorderOutput } from "./recorder.js";
|
|
5
|
+
import { MemoryRetriever, type MemoryRetrieverInput, type MemoryRetrieverOptions, type MemoryRetrieverOutput } from "./retriever.js";
|
|
6
6
|
export interface Memory {
|
|
7
7
|
id: string;
|
|
8
8
|
sessionId?: string | null;
|
|
@@ -10,7 +10,9 @@ export interface Memory {
|
|
|
10
10
|
createdAt: string;
|
|
11
11
|
}
|
|
12
12
|
export declare const newMemoryId: () => string;
|
|
13
|
-
export interface MemoryAgentOptions extends Partial<Pick<MemoryAgent, "
|
|
13
|
+
export interface MemoryAgentOptions extends Partial<Pick<MemoryAgent, "autoUpdate">>, Pick<AgentOptions, "subscribeTopic" | "skills"> {
|
|
14
|
+
recorder?: MemoryRecorder | MemoryRecorderOptions["process"] | MemoryRecorderOptions;
|
|
15
|
+
retriever?: MemoryRetriever | MemoryRetrieverOptions["process"] | MemoryRetrieverOptions;
|
|
14
16
|
}
|
|
15
17
|
/**
|
|
16
18
|
* A specialized agent responsible for managing, storing, and retrieving memories within the agent system.
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type ZodType, z } from "zod";
|
|
2
|
-
import { Agent, type AgentOptions, type Message } from "../agents/agent.js";
|
|
2
|
+
import { Agent, type AgentInvokeOptions, type AgentOptions, type AgentProcessResult, type FunctionAgentFn, type Message } from "../agents/agent.js";
|
|
3
|
+
import type { PromiseOrValue } from "../utils/type-utils.js";
|
|
3
4
|
import type { Memory } from "./memory.js";
|
|
4
5
|
/**
|
|
5
6
|
* Input for memory recording operations.
|
|
@@ -9,11 +10,11 @@ import type { Memory } from "./memory.js";
|
|
|
9
10
|
* should be stored as memories.
|
|
10
11
|
*/
|
|
11
12
|
export interface MemoryRecorderInput extends Message {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
content: {
|
|
14
|
+
input?: Message;
|
|
15
|
+
output?: Message;
|
|
16
|
+
source?: string;
|
|
17
|
+
}[];
|
|
17
18
|
}
|
|
18
19
|
/**
|
|
19
20
|
* @hidden
|
|
@@ -62,6 +63,9 @@ export declare const memoryRecorderOutputSchema: z.ZodObject<{
|
|
|
62
63
|
createdAt: string;
|
|
63
64
|
}[];
|
|
64
65
|
}>;
|
|
66
|
+
export interface MemoryRecorderOptions extends Omit<AgentOptions<MemoryRecorderInput, MemoryRecorderOutput>, "inputSchema" | "outputSchema"> {
|
|
67
|
+
process?: FunctionAgentFn<MemoryRecorderInput, MemoryRecorderOutput>;
|
|
68
|
+
}
|
|
65
69
|
/**
|
|
66
70
|
* Abstract base class for agents that record and store memories.
|
|
67
71
|
*
|
|
@@ -76,12 +80,14 @@ export declare const memoryRecorderOutputSchema: z.ZodObject<{
|
|
|
76
80
|
* Custom implementations should extend this class and provide concrete
|
|
77
81
|
* implementations of the process method to handle the actual storage logic.
|
|
78
82
|
*/
|
|
79
|
-
export declare
|
|
83
|
+
export declare class MemoryRecorder extends Agent<MemoryRecorderInput, MemoryRecorderOutput> {
|
|
80
84
|
tag: string;
|
|
81
85
|
/**
|
|
82
86
|
* Creates a new MemoryRecorder instance with predefined input and output schemas.
|
|
83
87
|
*
|
|
84
88
|
* @param options - Configuration options for the memory recorder agent
|
|
85
89
|
*/
|
|
86
|
-
constructor(options:
|
|
90
|
+
constructor(options: MemoryRecorderOptions);
|
|
91
|
+
private _process?;
|
|
92
|
+
process(input: MemoryRecorderInput, options: AgentInvokeOptions): PromiseOrValue<AgentProcessResult<MemoryRecorderOutput>>;
|
|
87
93
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
-
import { Agent, type AgentOptions, type Message } from "../agents/agent.js";
|
|
2
|
+
import { Agent, type AgentInvokeOptions, type AgentOptions, type AgentProcessResult, type FunctionAgentFn, type Message } from "../agents/agent.js";
|
|
3
|
+
import type { PromiseOrValue } from "../utils/type-utils.js";
|
|
3
4
|
import type { Memory } from "./memory.js";
|
|
4
5
|
/**
|
|
5
6
|
* Input for memory retrieval operations.
|
|
@@ -17,7 +18,7 @@ export interface MemoryRetrieverInput extends Message {
|
|
|
17
18
|
* Search term to filter memories by.
|
|
18
19
|
* How the search is implemented depends on the specific retriever implementation.
|
|
19
20
|
*/
|
|
20
|
-
search?: string;
|
|
21
|
+
search?: string | Message;
|
|
21
22
|
}
|
|
22
23
|
/**
|
|
23
24
|
* Output from memory retrieval operations.
|
|
@@ -37,13 +38,13 @@ export interface MemoryRetrieverOutput extends Message {
|
|
|
37
38
|
*/
|
|
38
39
|
export declare const memoryRetrieverInputSchema: z.ZodObject<{
|
|
39
40
|
limit: z.ZodOptional<z.ZodNumber>;
|
|
40
|
-
search: z.ZodOptional<z.ZodString
|
|
41
|
+
search: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodRecord<z.ZodString, z.ZodUnknown>]>>;
|
|
41
42
|
}, "strip", z.ZodTypeAny, {
|
|
43
|
+
search?: string | Record<string, unknown> | undefined;
|
|
42
44
|
limit?: number | undefined;
|
|
43
|
-
search?: string | undefined;
|
|
44
45
|
}, {
|
|
46
|
+
search?: string | Record<string, unknown> | undefined;
|
|
45
47
|
limit?: number | undefined;
|
|
46
|
-
search?: string | undefined;
|
|
47
48
|
}>;
|
|
48
49
|
/**
|
|
49
50
|
* @hidden
|
|
@@ -75,6 +76,9 @@ export declare const memoryRetrieverOutputSchema: z.ZodObject<{
|
|
|
75
76
|
createdAt: string;
|
|
76
77
|
}[];
|
|
77
78
|
}>;
|
|
79
|
+
export interface MemoryRetrieverOptions extends Omit<AgentOptions<MemoryRetrieverInput, MemoryRetrieverOutput>, "inputSchema" | "outputSchema"> {
|
|
80
|
+
process?: FunctionAgentFn<MemoryRetrieverInput, MemoryRetrieverOutput>;
|
|
81
|
+
}
|
|
78
82
|
/**
|
|
79
83
|
* Abstract base class for agents that retrieve memories from storage.
|
|
80
84
|
*
|
|
@@ -89,12 +93,14 @@ export declare const memoryRetrieverOutputSchema: z.ZodObject<{
|
|
|
89
93
|
* Custom implementations should extend this class and provide concrete
|
|
90
94
|
* implementations of the process method to handle the actual retrieval logic.
|
|
91
95
|
*/
|
|
92
|
-
export declare
|
|
96
|
+
export declare class MemoryRetriever extends Agent<MemoryRetrieverInput, MemoryRetrieverOutput> {
|
|
93
97
|
tag: string;
|
|
94
98
|
/**
|
|
95
99
|
* Creates a new MemoryRetriever instance with predefined input and output schemas.
|
|
96
100
|
*
|
|
97
101
|
* @param options - Configuration options for the memory retriever agent
|
|
98
102
|
*/
|
|
99
|
-
constructor(options:
|
|
103
|
+
constructor(options: MemoryRetrieverOptions);
|
|
104
|
+
private _process?;
|
|
105
|
+
process(input: MemoryRetrieverInput, options: AgentInvokeOptions): PromiseOrValue<AgentProcessResult<MemoryRetrieverOutput>>;
|
|
100
106
|
}
|
|
@@ -15,6 +15,7 @@ export declare function isNotEmpty<T>(arr: T[]): arr is [T, ...T[]];
|
|
|
15
15
|
export declare function duplicates<T>(arr: T[], key?: (item: T) => unknown): T[];
|
|
16
16
|
export declare function remove<T>(arr: T[], remove: T[] | ((item: T) => boolean)): T[];
|
|
17
17
|
export declare function unique<T>(arr: T[], key?: (item: T) => unknown): T[];
|
|
18
|
+
export declare function pick<T extends Record<string, unknown>, K extends keyof T | string>(obj: T, ...keys: (K | K[])[]): Pick<T, Extract<K, keyof T>> & Partial<Record<Exclude<K, keyof T>, unknown>>;
|
|
18
19
|
export declare function omit<T extends Record<string, unknown>, K extends keyof T>(obj: T, ...keys: (K | K[])[]): Omit<T, K>;
|
|
19
20
|
export declare function omitDeep<T, K>(obj: T, ...keys: (K | K[])[]): unknown;
|
|
20
21
|
export declare function omitBy<T extends Record<string, unknown>, K extends keyof T>(obj: T, predicate: (value: T[K], key: K) => boolean): Partial<T>;
|
|
@@ -37,7 +37,7 @@ export type PublishTopic<O extends Message> = string | string[] | ((output: O) =
|
|
|
37
37
|
* @template I The agent input message type
|
|
38
38
|
* @template O The agent output message type
|
|
39
39
|
*/
|
|
40
|
-
export interface AgentOptions<I extends Message = Message, O extends Message = Message> extends Partial<Pick<Agent, "guideRails"
|
|
40
|
+
export interface AgentOptions<I extends Message = Message, O extends Message = Message> extends Partial<Pick<Agent, "guideRails">> {
|
|
41
41
|
/**
|
|
42
42
|
* Topics the agent should subscribe to
|
|
43
43
|
*
|
|
@@ -106,6 +106,7 @@ export interface AgentOptions<I extends Message = Message, O extends Message = M
|
|
|
106
106
|
* Maximum number of memory items to retrieve
|
|
107
107
|
*/
|
|
108
108
|
maxRetrieveMemoryCount?: number;
|
|
109
|
+
hooks?: AgentHooks<I, O>;
|
|
109
110
|
}
|
|
110
111
|
export declare const agentOptionsSchema: ZodObject<{
|
|
111
112
|
[key in keyof AgentOptions]: ZodType<AgentOptions[key]>;
|
|
@@ -161,7 +162,7 @@ export interface AgentInvokeOptions<U extends UserContext = UserContext> {
|
|
|
161
162
|
* Here's an example of how to create a custom agent:
|
|
162
163
|
* {@includeCode ../../test/agents/agent.test.ts#example-custom-agent}
|
|
163
164
|
*/
|
|
164
|
-
export declare abstract class Agent<I extends Message =
|
|
165
|
+
export declare abstract class Agent<I extends Message = any, O extends Message = any> {
|
|
165
166
|
/**
|
|
166
167
|
* Custom object inspection behavior
|
|
167
168
|
*
|
|
@@ -191,7 +192,7 @@ export declare abstract class Agent<I extends Message = Message, O extends Messa
|
|
|
191
192
|
* Here's an example of using hooks:
|
|
192
193
|
* {@includeCode ../../test/agents/agent.test.ts#example-agent-hooks}
|
|
193
194
|
*/
|
|
194
|
-
readonly hooks: AgentHooks
|
|
195
|
+
readonly hooks: AgentHooks<I, O>;
|
|
195
196
|
/**
|
|
196
197
|
* List of GuideRail agents applied to this agent
|
|
197
198
|
*
|
|
@@ -277,8 +278,8 @@ export declare abstract class Agent<I extends Message = Message, O extends Messa
|
|
|
277
278
|
* Skills can be accessed by name or by array index, allowing
|
|
278
279
|
* the agent to delegate tasks to specialized sub-agents
|
|
279
280
|
*/
|
|
280
|
-
readonly skills: Agent<
|
|
281
|
-
[key: string]: Agent<
|
|
281
|
+
readonly skills: Agent<any, any>[] & {
|
|
282
|
+
[key: string]: Agent<any, any>;
|
|
282
283
|
};
|
|
283
284
|
/**
|
|
284
285
|
* Whether to disable emitting events for agent actions
|
|
@@ -519,7 +520,9 @@ export interface AgentHooks<I extends Message = Message, O extends Message = Mes
|
|
|
519
520
|
onStart?: (event: {
|
|
520
521
|
context: Context;
|
|
521
522
|
input: I;
|
|
522
|
-
}) => PromiseOrValue<void
|
|
523
|
+
}) => PromiseOrValue<void | {
|
|
524
|
+
input?: I;
|
|
525
|
+
}>;
|
|
523
526
|
/**
|
|
524
527
|
* Called when agent processing completes or fails
|
|
525
528
|
*
|
|
@@ -534,7 +537,9 @@ export interface AgentHooks<I extends Message = Message, O extends Message = Mes
|
|
|
534
537
|
input: I;
|
|
535
538
|
output: O;
|
|
536
539
|
error: Error;
|
|
537
|
-
}, "output", "error">) => PromiseOrValue<void
|
|
540
|
+
}, "output", "error">) => PromiseOrValue<void | {
|
|
541
|
+
output?: O;
|
|
542
|
+
}>;
|
|
538
543
|
/**
|
|
539
544
|
* Called before a skill (sub-agent) is invoked
|
|
540
545
|
*
|
|
@@ -546,7 +551,7 @@ export interface AgentHooks<I extends Message = Message, O extends Message = Mes
|
|
|
546
551
|
onSkillStart?: (event: {
|
|
547
552
|
context: Context;
|
|
548
553
|
skill: Agent;
|
|
549
|
-
input:
|
|
554
|
+
input: Message;
|
|
550
555
|
}) => PromiseOrValue<void>;
|
|
551
556
|
/**
|
|
552
557
|
* Called after a skill (sub-agent) completes or fails
|
|
@@ -560,8 +565,8 @@ export interface AgentHooks<I extends Message = Message, O extends Message = Mes
|
|
|
560
565
|
onSkillEnd?: (event: XOr<{
|
|
561
566
|
context: Context;
|
|
562
567
|
skill: Agent;
|
|
563
|
-
input:
|
|
564
|
-
output:
|
|
568
|
+
input: Message;
|
|
569
|
+
output: Message;
|
|
565
570
|
error: Error;
|
|
566
571
|
}, "output", "error">) => PromiseOrValue<void>;
|
|
567
572
|
/**
|
package/lib/esm/agents/agent.js
CHANGED
|
@@ -273,7 +273,6 @@ export class Agent {
|
|
|
273
273
|
for (const memory of this.memories) {
|
|
274
274
|
const ms = (await memory.retrieve({
|
|
275
275
|
...input,
|
|
276
|
-
search: typeof input.search === "string" ? input.search : JSON.stringify(input.search),
|
|
277
276
|
limit: input.limit ?? this.maxRetrieveMemoryCount,
|
|
278
277
|
}, options.context)).memories;
|
|
279
278
|
memories.push(...ms);
|
|
@@ -304,8 +303,8 @@ export class Agent {
|
|
|
304
303
|
if (!this.disableEvents)
|
|
305
304
|
opts.context.emit("agentStarted", { agent: this, input });
|
|
306
305
|
try {
|
|
307
|
-
await this.hooks.onStart?.({ context: opts.context, input });
|
|
308
|
-
|
|
306
|
+
let parsedInput = (await this.hooks.onStart?.({ context: opts.context, input }))?.input ?? input;
|
|
307
|
+
parsedInput = checkArguments(`Agent ${this.name} input`, this.inputSchema, input);
|
|
309
308
|
await this.preprocess(parsedInput, opts);
|
|
310
309
|
this.checkContextStatus(opts);
|
|
311
310
|
let response = await this.process(parsedInput, opts);
|
|
@@ -368,7 +367,9 @@ export class Agent {
|
|
|
368
367
|
logger.debug("Invoke agent %s succeed with output: %O", this.name, finalOutput);
|
|
369
368
|
if (!this.disableEvents)
|
|
370
369
|
context.emit("agentSucceed", { agent: this, output: finalOutput });
|
|
371
|
-
await this.hooks.onEnd?.({ context, input, output: finalOutput });
|
|
370
|
+
const o = (await this.hooks.onEnd?.({ context, input, output: finalOutput }))?.output;
|
|
371
|
+
if (o)
|
|
372
|
+
return o;
|
|
372
373
|
return finalOutput;
|
|
373
374
|
}
|
|
374
375
|
/**
|
|
@@ -475,12 +476,7 @@ export class Agent {
|
|
|
475
476
|
async postprocess(input, output, options) {
|
|
476
477
|
this.checkContextStatus(options);
|
|
477
478
|
this.publishToTopics(output, options);
|
|
478
|
-
await this.recordMemories({
|
|
479
|
-
content: [
|
|
480
|
-
{ role: "user", content: input },
|
|
481
|
-
{ role: "agent", content: replaceTransferAgentToName(output), source: this.name },
|
|
482
|
-
],
|
|
483
|
-
}, options);
|
|
479
|
+
await this.recordMemories({ content: [{ input, output: replaceTransferAgentToName(output), source: this.name }] }, options);
|
|
484
480
|
}
|
|
485
481
|
async publishToTopics(output, options) {
|
|
486
482
|
const publishTopics = typeof this.publishTopic === "function" ? await this.publishTopic(output) : this.publishTopic;
|
|
@@ -131,7 +131,7 @@ export declare const aiAgentOptionsSchema: ZodObject<{
|
|
|
131
131
|
* Basic AIAgent creation:
|
|
132
132
|
* {@includeCode ../../test/agents/ai-agent.test.ts#example-ai-agent-basic}
|
|
133
133
|
*/
|
|
134
|
-
export declare class AIAgent<I extends Message =
|
|
134
|
+
export declare class AIAgent<I extends Message = any, O extends Message = any> extends Agent<I, O> {
|
|
135
135
|
tag: string;
|
|
136
136
|
/**
|
|
137
137
|
* Create an AIAgent with the specified options
|
|
@@ -183,7 +183,7 @@ declare class ClientWithReconnect extends Client {
|
|
|
183
183
|
private reconnect;
|
|
184
184
|
request<T extends ZodType<object>>(request: Request, resultSchema: T, options?: RequestOptions): Promise<z.infer<T>>;
|
|
185
185
|
}
|
|
186
|
-
export interface MCPBaseOptions<I extends Message =
|
|
186
|
+
export interface MCPBaseOptions<I extends Message = any, O extends Message = any> extends AgentOptions<I, O> {
|
|
187
187
|
client: ClientWithReconnect;
|
|
188
188
|
}
|
|
189
189
|
export declare abstract class MCPBase<I extends Message, O extends Message> extends Agent<I, O> {
|
package/lib/esm/aigne/aigne.d.ts
CHANGED
|
@@ -93,15 +93,15 @@ export declare class AIGNE<U extends UserContext = UserContext> {
|
|
|
93
93
|
* Collection of skill agents available to this AIGNE instance.
|
|
94
94
|
* Provides indexed access by skill name.
|
|
95
95
|
*/
|
|
96
|
-
readonly skills: Agent<
|
|
97
|
-
[key: string]: Agent<
|
|
96
|
+
readonly skills: Agent<any, any>[] & {
|
|
97
|
+
[key: string]: Agent<any, any>;
|
|
98
98
|
};
|
|
99
99
|
/**
|
|
100
100
|
* Collection of primary agents managed by this AIGNE instance.
|
|
101
101
|
* Provides indexed access by agent name.
|
|
102
102
|
*/
|
|
103
|
-
readonly agents: Agent<
|
|
104
|
-
[key: string]: Agent<
|
|
103
|
+
readonly agents: Agent<any, any>[] & {
|
|
104
|
+
[key: string]: Agent<any, any>;
|
|
105
105
|
};
|
|
106
106
|
/**
|
|
107
107
|
* Observer for the AIGNE instance.
|
package/lib/esm/aigne/aigne.js
CHANGED
|
@@ -125,6 +125,7 @@ export class AIGNE {
|
|
|
125
125
|
return context;
|
|
126
126
|
}
|
|
127
127
|
invoke(agent, message, options) {
|
|
128
|
+
this.observer?.serve();
|
|
128
129
|
const context = new AIGNEContext(this);
|
|
129
130
|
return context.invoke(agent, message, { ...options, newContext: false });
|
|
130
131
|
}
|
|
@@ -142,6 +143,7 @@ export class AIGNE {
|
|
|
142
143
|
* {@includeCode ../../test/aigne/aigne.test.ts#example-publish-message}
|
|
143
144
|
*/
|
|
144
145
|
publish(topic, payload, options) {
|
|
146
|
+
this.observer?.serve();
|
|
145
147
|
return new AIGNEContext(this).publish(topic, payload, options);
|
|
146
148
|
}
|
|
147
149
|
subscribe(topic, listener) {
|
|
@@ -148,7 +148,7 @@ export declare class AIGNEContext implements Context {
|
|
|
148
148
|
readonly internal: AIGNEContextShared;
|
|
149
149
|
get messageQueue(): MessageQueue;
|
|
150
150
|
get model(): ChatModel | undefined;
|
|
151
|
-
get skills(): Agent<
|
|
151
|
+
get skills(): Agent<any, any>[] | undefined;
|
|
152
152
|
get observer(): AIGNEObserver | undefined;
|
|
153
153
|
get limits(): ContextLimits | undefined;
|
|
154
154
|
get status(): "normal" | "timeout";
|
|
@@ -180,7 +180,7 @@ declare class AIGNEContextShared {
|
|
|
180
180
|
readonly messageQueue: MessageQueue;
|
|
181
181
|
readonly events: Emitter<any>;
|
|
182
182
|
get model(): ChatModel | undefined;
|
|
183
|
-
get skills(): Agent<
|
|
183
|
+
get skills(): Agent<any, any>[] | undefined;
|
|
184
184
|
get observer(): AIGNEObserver | undefined;
|
|
185
185
|
get limits(): ContextLimits | undefined;
|
|
186
186
|
usage: ContextUsage;
|
|
@@ -17,8 +17,8 @@ export interface LoadOptions {
|
|
|
17
17
|
}
|
|
18
18
|
export declare function load(options: LoadOptions): Promise<{
|
|
19
19
|
model: ChatModel | undefined;
|
|
20
|
-
agents: Agent<
|
|
21
|
-
skills: Agent<
|
|
20
|
+
agents: Agent<any, any>[];
|
|
21
|
+
skills: Agent<any, any>[];
|
|
22
22
|
name?: string | null | undefined;
|
|
23
23
|
description?: string | null | undefined;
|
|
24
24
|
chat_model?: {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Agent, type AgentInvokeOptions, type AgentOptions, type Message } from "../agents/agent.js";
|
|
2
2
|
import type { Context } from "../aigne/context.js";
|
|
3
3
|
import type { MessagePayload } from "../aigne/message-queue.js";
|
|
4
|
-
import
|
|
5
|
-
import
|
|
4
|
+
import { MemoryRecorder, type MemoryRecorderInput, type MemoryRecorderOptions, type MemoryRecorderOutput } from "./recorder.js";
|
|
5
|
+
import { MemoryRetriever, type MemoryRetrieverInput, type MemoryRetrieverOptions, type MemoryRetrieverOutput } from "./retriever.js";
|
|
6
6
|
export interface Memory {
|
|
7
7
|
id: string;
|
|
8
8
|
sessionId?: string | null;
|
|
@@ -10,7 +10,9 @@ export interface Memory {
|
|
|
10
10
|
createdAt: string;
|
|
11
11
|
}
|
|
12
12
|
export declare const newMemoryId: () => string;
|
|
13
|
-
export interface MemoryAgentOptions extends Partial<Pick<MemoryAgent, "
|
|
13
|
+
export interface MemoryAgentOptions extends Partial<Pick<MemoryAgent, "autoUpdate">>, Pick<AgentOptions, "subscribeTopic" | "skills"> {
|
|
14
|
+
recorder?: MemoryRecorder | MemoryRecorderOptions["process"] | MemoryRecorderOptions;
|
|
15
|
+
retriever?: MemoryRetriever | MemoryRetrieverOptions["process"] | MemoryRetrieverOptions;
|
|
14
16
|
}
|
|
15
17
|
/**
|
|
16
18
|
* A specialized agent responsible for managing, storing, and retrieving memories within the agent system.
|
package/lib/esm/memory/memory.js
CHANGED
|
@@ -2,6 +2,8 @@ import { v7 } from "uuid";
|
|
|
2
2
|
import { z } from "zod";
|
|
3
3
|
import { Agent, } from "../agents/agent.js";
|
|
4
4
|
import { checkArguments, remove } from "../utils/type-utils.js";
|
|
5
|
+
import { MemoryRecorder, } from "./recorder.js";
|
|
6
|
+
import { MemoryRetriever, } from "./retriever.js";
|
|
5
7
|
export const newMemoryId = () => v7();
|
|
6
8
|
/**
|
|
7
9
|
* A specialized agent responsible for managing, storing, and retrieving memories within the agent system.
|
|
@@ -22,8 +24,20 @@ export class MemoryAgent extends Agent {
|
|
|
22
24
|
subscribeTopic: options.subscribeTopic,
|
|
23
25
|
skills: options.skills,
|
|
24
26
|
});
|
|
25
|
-
this.recorder =
|
|
26
|
-
|
|
27
|
+
this.recorder =
|
|
28
|
+
options.recorder instanceof MemoryRecorder
|
|
29
|
+
? options.recorder
|
|
30
|
+
: options.recorder &&
|
|
31
|
+
new MemoryRecorder(typeof options.recorder === "function"
|
|
32
|
+
? { process: options.recorder }
|
|
33
|
+
: options.recorder);
|
|
34
|
+
this.retriever =
|
|
35
|
+
options.retriever instanceof MemoryRetriever
|
|
36
|
+
? options.retriever
|
|
37
|
+
: options.retriever &&
|
|
38
|
+
new MemoryRetriever(typeof options.retriever === "function"
|
|
39
|
+
? { process: options.retriever }
|
|
40
|
+
: options.retriever);
|
|
27
41
|
this.autoUpdate = options.autoUpdate;
|
|
28
42
|
}
|
|
29
43
|
_retriever;
|
|
@@ -116,7 +130,7 @@ export class MemoryAgent extends Agent {
|
|
|
116
130
|
return context.invoke(this.recorder, input);
|
|
117
131
|
}
|
|
118
132
|
async onMessage({ role, source, message, context }) {
|
|
119
|
-
this.record({ content: [{
|
|
133
|
+
this.record({ content: [role === "user" ? { input: message } : { output: message, source }] }, context);
|
|
120
134
|
}
|
|
121
135
|
}
|
|
122
136
|
const memoryAgentOptionsSchema = z.object({
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type ZodType, z } from "zod";
|
|
2
|
-
import { Agent, type AgentOptions, type Message } from "../agents/agent.js";
|
|
2
|
+
import { Agent, type AgentInvokeOptions, type AgentOptions, type AgentProcessResult, type FunctionAgentFn, type Message } from "../agents/agent.js";
|
|
3
|
+
import type { PromiseOrValue } from "../utils/type-utils.js";
|
|
3
4
|
import type { Memory } from "./memory.js";
|
|
4
5
|
/**
|
|
5
6
|
* Input for memory recording operations.
|
|
@@ -9,11 +10,11 @@ import type { Memory } from "./memory.js";
|
|
|
9
10
|
* should be stored as memories.
|
|
10
11
|
*/
|
|
11
12
|
export interface MemoryRecorderInput extends Message {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
content: {
|
|
14
|
+
input?: Message;
|
|
15
|
+
output?: Message;
|
|
16
|
+
source?: string;
|
|
17
|
+
}[];
|
|
17
18
|
}
|
|
18
19
|
/**
|
|
19
20
|
* @hidden
|
|
@@ -62,6 +63,9 @@ export declare const memoryRecorderOutputSchema: z.ZodObject<{
|
|
|
62
63
|
createdAt: string;
|
|
63
64
|
}[];
|
|
64
65
|
}>;
|
|
66
|
+
export interface MemoryRecorderOptions extends Omit<AgentOptions<MemoryRecorderInput, MemoryRecorderOutput>, "inputSchema" | "outputSchema"> {
|
|
67
|
+
process?: FunctionAgentFn<MemoryRecorderInput, MemoryRecorderOutput>;
|
|
68
|
+
}
|
|
65
69
|
/**
|
|
66
70
|
* Abstract base class for agents that record and store memories.
|
|
67
71
|
*
|
|
@@ -76,12 +80,14 @@ export declare const memoryRecorderOutputSchema: z.ZodObject<{
|
|
|
76
80
|
* Custom implementations should extend this class and provide concrete
|
|
77
81
|
* implementations of the process method to handle the actual storage logic.
|
|
78
82
|
*/
|
|
79
|
-
export declare
|
|
83
|
+
export declare class MemoryRecorder extends Agent<MemoryRecorderInput, MemoryRecorderOutput> {
|
|
80
84
|
tag: string;
|
|
81
85
|
/**
|
|
82
86
|
* Creates a new MemoryRecorder instance with predefined input and output schemas.
|
|
83
87
|
*
|
|
84
88
|
* @param options - Configuration options for the memory recorder agent
|
|
85
89
|
*/
|
|
86
|
-
constructor(options:
|
|
90
|
+
constructor(options: MemoryRecorderOptions);
|
|
91
|
+
private _process?;
|
|
92
|
+
process(input: MemoryRecorderInput, options: AgentInvokeOptions): PromiseOrValue<AgentProcessResult<MemoryRecorderOutput>>;
|
|
87
93
|
}
|