@aigne/core 1.13.0 → 1.14.0
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 +15 -0
- package/README.md +13 -26
- package/README.zh.md +24 -37
- package/lib/cjs/agents/agent.d.ts +522 -15
- package/lib/cjs/agents/agent.js +357 -36
- package/lib/cjs/agents/ai-agent.d.ts +210 -52
- package/lib/cjs/agents/ai-agent.js +182 -24
- package/lib/cjs/agents/mcp-agent.d.ts +112 -0
- package/lib/cjs/agents/mcp-agent.js +79 -1
- package/lib/cjs/agents/team-agent.d.ts +99 -0
- package/lib/cjs/agents/team-agent.js +94 -0
- package/lib/cjs/agents/user-agent.d.ts +6 -4
- package/lib/cjs/agents/user-agent.js +16 -5
- package/lib/cjs/aigne/aigne.d.ts +263 -16
- package/lib/cjs/aigne/aigne.js +130 -20
- package/lib/cjs/aigne/context.d.ts +24 -8
- package/lib/cjs/aigne/context.js +8 -22
- package/lib/cjs/aigne/message-queue.d.ts +26 -4
- package/lib/cjs/aigne/message-queue.js +42 -7
- package/lib/cjs/aigne/usage.d.ts +9 -0
- package/lib/cjs/aigne/usage.js +3 -0
- package/lib/cjs/client/client.d.ts +81 -3
- package/lib/cjs/client/client.js +38 -0
- package/lib/cjs/client/index.d.ts +1 -0
- package/lib/cjs/client/index.js +17 -0
- package/lib/cjs/index.d.ts +0 -1
- package/lib/cjs/index.js +0 -1
- package/lib/cjs/loader/agent-js.d.ts +1 -1
- package/lib/cjs/loader/agent-js.js +2 -2
- package/lib/cjs/loader/agent-yaml.d.ts +3 -2
- package/lib/cjs/loader/agent-yaml.js +2 -1
- package/lib/cjs/loader/index.d.ts +4 -4
- package/lib/cjs/memory/default-memory.d.ts +16 -0
- package/lib/cjs/memory/default-memory.js +70 -0
- package/lib/cjs/memory/index.d.ts +3 -0
- package/lib/cjs/memory/index.js +19 -0
- package/lib/cjs/memory/memory.d.ts +89 -0
- package/lib/cjs/memory/memory.js +132 -0
- package/lib/cjs/memory/recorder.d.ts +86 -0
- package/lib/cjs/memory/recorder.js +50 -0
- package/lib/cjs/memory/retriever.d.ts +99 -0
- package/lib/cjs/memory/retriever.js +51 -0
- package/lib/cjs/models/bedrock-chat-model.d.ts +12 -3
- package/lib/cjs/models/bedrock-chat-model.js +54 -24
- package/lib/cjs/models/chat-model.d.ts +278 -1
- package/lib/cjs/models/chat-model.js +54 -0
- package/lib/cjs/models/claude-chat-model.d.ts +49 -3
- package/lib/cjs/models/claude-chat-model.js +34 -2
- package/lib/cjs/models/deepseek-chat-model.d.ts +16 -0
- package/lib/cjs/models/deepseek-chat-model.js +16 -0
- package/lib/cjs/models/gemini-chat-model.d.ts +14 -0
- package/lib/cjs/models/gemini-chat-model.js +14 -0
- package/lib/cjs/models/ollama-chat-model.d.ts +16 -0
- package/lib/cjs/models/ollama-chat-model.js +16 -0
- package/lib/cjs/models/open-router-chat-model.d.ts +16 -0
- package/lib/cjs/models/open-router-chat-model.js +16 -0
- package/lib/cjs/models/openai-chat-model.d.ts +67 -3
- package/lib/cjs/models/openai-chat-model.js +47 -2
- package/lib/cjs/models/xai-chat-model.d.ts +16 -0
- package/lib/cjs/models/xai-chat-model.js +16 -0
- package/lib/cjs/prompt/prompt-builder.d.ts +4 -4
- package/lib/cjs/prompt/prompt-builder.js +19 -18
- package/lib/cjs/prompt/prompts/memory-message-template.d.ts +1 -0
- package/lib/cjs/prompt/prompts/memory-message-template.js +10 -0
- package/lib/cjs/prompt/template.js +5 -1
- package/lib/cjs/server/error.d.ts +11 -0
- package/lib/cjs/server/error.js +11 -0
- package/lib/cjs/server/index.d.ts +2 -0
- package/lib/cjs/server/index.js +18 -0
- package/lib/cjs/server/server.d.ts +89 -8
- package/lib/cjs/server/server.js +58 -0
- package/lib/cjs/utils/fs.d.ts +2 -0
- package/lib/cjs/utils/fs.js +25 -0
- package/lib/cjs/utils/prompts.d.ts +1 -0
- package/lib/cjs/utils/prompts.js +11 -2
- package/lib/cjs/utils/type-utils.d.ts +1 -0
- package/lib/cjs/utils/type-utils.js +14 -0
- package/lib/dts/agents/agent.d.ts +522 -15
- package/lib/dts/agents/ai-agent.d.ts +210 -52
- package/lib/dts/agents/mcp-agent.d.ts +112 -0
- package/lib/dts/agents/team-agent.d.ts +99 -0
- package/lib/dts/agents/user-agent.d.ts +6 -4
- package/lib/dts/aigne/aigne.d.ts +263 -16
- package/lib/dts/aigne/context.d.ts +24 -8
- package/lib/dts/aigne/message-queue.d.ts +26 -4
- package/lib/dts/aigne/usage.d.ts +9 -0
- package/lib/dts/client/client.d.ts +81 -3
- package/lib/dts/client/index.d.ts +1 -0
- package/lib/dts/index.d.ts +0 -1
- package/lib/dts/loader/agent-js.d.ts +1 -1
- package/lib/dts/loader/agent-yaml.d.ts +3 -2
- package/lib/dts/loader/index.d.ts +4 -4
- package/lib/dts/memory/default-memory.d.ts +16 -0
- package/lib/dts/memory/index.d.ts +3 -0
- package/lib/dts/memory/memory.d.ts +89 -0
- package/lib/dts/memory/recorder.d.ts +86 -0
- package/lib/dts/memory/retriever.d.ts +99 -0
- package/lib/dts/models/bedrock-chat-model.d.ts +12 -3
- package/lib/dts/models/chat-model.d.ts +278 -1
- package/lib/dts/models/claude-chat-model.d.ts +49 -3
- package/lib/dts/models/deepseek-chat-model.d.ts +16 -0
- package/lib/dts/models/gemini-chat-model.d.ts +14 -0
- package/lib/dts/models/ollama-chat-model.d.ts +16 -0
- package/lib/dts/models/open-router-chat-model.d.ts +16 -0
- package/lib/dts/models/openai-chat-model.d.ts +67 -3
- package/lib/dts/models/xai-chat-model.d.ts +16 -0
- package/lib/dts/prompt/prompt-builder.d.ts +4 -4
- package/lib/dts/prompt/prompts/memory-message-template.d.ts +1 -0
- package/lib/dts/server/error.d.ts +11 -0
- package/lib/dts/server/index.d.ts +2 -0
- package/lib/dts/server/server.d.ts +89 -8
- package/lib/dts/utils/fs.d.ts +2 -0
- package/lib/dts/utils/prompts.d.ts +1 -0
- package/lib/dts/utils/type-utils.d.ts +1 -0
- package/lib/esm/agents/agent.d.ts +522 -15
- package/lib/esm/agents/agent.js +351 -35
- package/lib/esm/agents/ai-agent.d.ts +210 -52
- package/lib/esm/agents/ai-agent.js +183 -25
- package/lib/esm/agents/mcp-agent.d.ts +112 -0
- package/lib/esm/agents/mcp-agent.js +79 -1
- package/lib/esm/agents/team-agent.d.ts +99 -0
- package/lib/esm/agents/team-agent.js +94 -0
- package/lib/esm/agents/user-agent.d.ts +6 -4
- package/lib/esm/agents/user-agent.js +17 -6
- package/lib/esm/aigne/aigne.d.ts +263 -16
- package/lib/esm/aigne/aigne.js +132 -22
- package/lib/esm/aigne/context.d.ts +24 -8
- package/lib/esm/aigne/context.js +9 -22
- package/lib/esm/aigne/message-queue.d.ts +26 -4
- package/lib/esm/aigne/message-queue.js +42 -8
- package/lib/esm/aigne/usage.d.ts +9 -0
- package/lib/esm/aigne/usage.js +3 -0
- package/lib/esm/client/client.d.ts +81 -3
- package/lib/esm/client/client.js +38 -0
- package/lib/esm/client/index.d.ts +1 -0
- package/lib/esm/client/index.js +1 -0
- package/lib/esm/index.d.ts +0 -1
- package/lib/esm/index.js +0 -1
- package/lib/esm/loader/agent-js.d.ts +1 -1
- package/lib/esm/loader/agent-js.js +2 -2
- package/lib/esm/loader/agent-yaml.d.ts +3 -2
- package/lib/esm/loader/agent-yaml.js +2 -1
- package/lib/esm/loader/index.d.ts +4 -4
- package/lib/esm/memory/default-memory.d.ts +16 -0
- package/lib/esm/memory/default-memory.js +63 -0
- package/lib/esm/memory/index.d.ts +3 -0
- package/lib/esm/memory/index.js +3 -0
- package/lib/esm/memory/memory.d.ts +89 -0
- package/lib/esm/memory/memory.js +127 -0
- package/lib/esm/memory/recorder.d.ts +86 -0
- package/lib/esm/memory/recorder.js +46 -0
- package/lib/esm/memory/retriever.d.ts +99 -0
- package/lib/esm/memory/retriever.js +47 -0
- package/lib/esm/models/bedrock-chat-model.d.ts +12 -3
- package/lib/esm/models/bedrock-chat-model.js +56 -26
- package/lib/esm/models/chat-model.d.ts +278 -1
- package/lib/esm/models/chat-model.js +54 -0
- package/lib/esm/models/claude-chat-model.d.ts +49 -3
- package/lib/esm/models/claude-chat-model.js +35 -3
- package/lib/esm/models/deepseek-chat-model.d.ts +16 -0
- package/lib/esm/models/deepseek-chat-model.js +16 -0
- package/lib/esm/models/gemini-chat-model.d.ts +14 -0
- package/lib/esm/models/gemini-chat-model.js +14 -0
- package/lib/esm/models/ollama-chat-model.d.ts +16 -0
- package/lib/esm/models/ollama-chat-model.js +16 -0
- package/lib/esm/models/open-router-chat-model.d.ts +16 -0
- package/lib/esm/models/open-router-chat-model.js +16 -0
- package/lib/esm/models/openai-chat-model.d.ts +67 -3
- package/lib/esm/models/openai-chat-model.js +47 -2
- package/lib/esm/models/xai-chat-model.d.ts +16 -0
- package/lib/esm/models/xai-chat-model.js +16 -0
- package/lib/esm/prompt/prompt-builder.d.ts +4 -4
- package/lib/esm/prompt/prompt-builder.js +20 -19
- package/lib/esm/prompt/prompts/memory-message-template.d.ts +1 -0
- package/lib/esm/prompt/prompts/memory-message-template.js +7 -0
- package/lib/esm/prompt/template.js +5 -1
- package/lib/esm/server/error.d.ts +11 -0
- package/lib/esm/server/error.js +11 -0
- package/lib/esm/server/index.d.ts +2 -0
- package/lib/esm/server/index.js +2 -0
- package/lib/esm/server/server.d.ts +89 -8
- package/lib/esm/server/server.js +58 -0
- package/lib/esm/utils/fs.d.ts +2 -0
- package/lib/esm/utils/fs.js +21 -0
- package/lib/esm/utils/prompts.d.ts +1 -0
- package/lib/esm/utils/prompts.js +10 -2
- package/lib/esm/utils/type-utils.d.ts +1 -0
- package/lib/esm/utils/type-utils.js +13 -0
- package/package.json +14 -11
- package/lib/cjs/agents/memory.d.ts +0 -26
- package/lib/cjs/agents/memory.js +0 -45
- package/lib/dts/agents/memory.d.ts +0 -26
- package/lib/esm/agents/memory.d.ts +0 -26
- package/lib/esm/agents/memory.js +0 -41
- /package/{LICENSE → LICENSE.md} +0 -0
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { Agent, type AgentOptions, type Message } from "../agents/agent.js";
|
|
2
|
+
import type { Context } from "../aigne/context.js";
|
|
3
|
+
import type { MessagePayload } from "../aigne/message-queue.js";
|
|
4
|
+
import type { MemoryRecorder, MemoryRecorderInput, MemoryRecorderOutput } from "./recorder.js";
|
|
5
|
+
import type { MemoryRetriever, MemoryRetrieverInput, MemoryRetrieverOutput } from "./retriever.js";
|
|
6
|
+
export interface Memory {
|
|
7
|
+
id: string;
|
|
8
|
+
content: unknown;
|
|
9
|
+
createdAt: string;
|
|
10
|
+
}
|
|
11
|
+
export declare const newMemoryId: () => string;
|
|
12
|
+
export interface MemoryAgentOptions extends Partial<Pick<MemoryAgent, "recorder" | "retriever" | "autoUpdate">>, Pick<AgentOptions, "subscribeTopic" | "skills"> {
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* A specialized agent responsible for managing, storing, and retrieving memories within the agent system.
|
|
16
|
+
*
|
|
17
|
+
* MemoryAgent serves as a bridge between application logic and memory storage/retrieval mechanisms.
|
|
18
|
+
* It delegates the actual memory operations to specialized recorder and retriever agents that
|
|
19
|
+
* are attached as skills. This agent doesn't directly process messages like other agents but
|
|
20
|
+
* instead provides memory management capabilities to the system.
|
|
21
|
+
*/
|
|
22
|
+
export declare class MemoryAgent extends Agent {
|
|
23
|
+
/**
|
|
24
|
+
* Creates a new MemoryAgent instance.
|
|
25
|
+
*/
|
|
26
|
+
constructor(options: MemoryAgentOptions);
|
|
27
|
+
private _retriever?;
|
|
28
|
+
/**
|
|
29
|
+
* Agent used for retrieving memories from storage.
|
|
30
|
+
*
|
|
31
|
+
* This retriever is automatically added to the agent's skills when set.
|
|
32
|
+
* Setting a new retriever will remove any previously set retriever from skills.
|
|
33
|
+
*/
|
|
34
|
+
get retriever(): MemoryRetriever | undefined;
|
|
35
|
+
set retriever(value: MemoryRetriever | undefined);
|
|
36
|
+
private _recorder?;
|
|
37
|
+
/**
|
|
38
|
+
* Agent used for recording and storing new memories.
|
|
39
|
+
*
|
|
40
|
+
* This recorder is automatically added to the agent's skills when set.
|
|
41
|
+
* Setting a new recorder will remove any previously set recorder from skills.
|
|
42
|
+
*/
|
|
43
|
+
get recorder(): MemoryRecorder | undefined;
|
|
44
|
+
set recorder(value: MemoryRecorder | undefined);
|
|
45
|
+
/**
|
|
46
|
+
* Controls whether to automatically update the memory when agent call completes.
|
|
47
|
+
*
|
|
48
|
+
* When true, the agent will automatically record any relevant information
|
|
49
|
+
* after completing operations, creating a history of interactions.
|
|
50
|
+
*/
|
|
51
|
+
autoUpdate?: boolean;
|
|
52
|
+
/**
|
|
53
|
+
* Indicates whether this agent can be directly called.
|
|
54
|
+
*
|
|
55
|
+
* MemoryAgent is designed to be used as a supporting component rather than
|
|
56
|
+
* being directly invoked for processing, so this returns false.
|
|
57
|
+
*/
|
|
58
|
+
get isCallable(): boolean;
|
|
59
|
+
/**
|
|
60
|
+
* The standard message processing method required by the Agent interface.
|
|
61
|
+
*
|
|
62
|
+
* MemoryAgent doesn't directly process messages like other agents, so this method
|
|
63
|
+
* throws an error when called. Use the specialized retrieve() and record() methods instead.
|
|
64
|
+
*/
|
|
65
|
+
process(_input: Message, _context: Context): Promise<Message>;
|
|
66
|
+
/**
|
|
67
|
+
* Retrieves memories based on the provided input criteria.
|
|
68
|
+
*
|
|
69
|
+
* Delegates the actual retrieval operation to the configured retriever agent.
|
|
70
|
+
*
|
|
71
|
+
* @param input - The retrieval parameters (can include search terms, limits, etc.)
|
|
72
|
+
* @param context - The execution context
|
|
73
|
+
* @returns A promise resolving to the retrieved memories
|
|
74
|
+
* @throws Error - If no retriever has been initialized
|
|
75
|
+
*/
|
|
76
|
+
retrieve(input: MemoryRetrieverInput, context: Context): Promise<MemoryRetrieverOutput>;
|
|
77
|
+
/**
|
|
78
|
+
* Records new memories based on the provided input content.
|
|
79
|
+
*
|
|
80
|
+
* Delegates the actual recording operation to the configured recorder agent.
|
|
81
|
+
*
|
|
82
|
+
* @param input - The content to be recorded as memories
|
|
83
|
+
* @param context - The execution context
|
|
84
|
+
* @returns A promise resolving to the recorded memories
|
|
85
|
+
* @throws Error - If no recorder has been initialized
|
|
86
|
+
*/
|
|
87
|
+
record(input: MemoryRecorderInput, context: Context): Promise<MemoryRecorderOutput>;
|
|
88
|
+
onMessage({ role, source, message, context }: MessagePayload): Promise<void>;
|
|
89
|
+
}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MemoryAgent = exports.newMemoryId = void 0;
|
|
4
|
+
const uuid_1 = require("uuid");
|
|
5
|
+
const zod_1 = require("zod");
|
|
6
|
+
const agent_js_1 = require("../agents/agent.js");
|
|
7
|
+
const type_utils_js_1 = require("../utils/type-utils.js");
|
|
8
|
+
const newMemoryId = () => (0, uuid_1.v7)();
|
|
9
|
+
exports.newMemoryId = newMemoryId;
|
|
10
|
+
/**
|
|
11
|
+
* A specialized agent responsible for managing, storing, and retrieving memories within the agent system.
|
|
12
|
+
*
|
|
13
|
+
* MemoryAgent serves as a bridge between application logic and memory storage/retrieval mechanisms.
|
|
14
|
+
* It delegates the actual memory operations to specialized recorder and retriever agents that
|
|
15
|
+
* are attached as skills. This agent doesn't directly process messages like other agents but
|
|
16
|
+
* instead provides memory management capabilities to the system.
|
|
17
|
+
*/
|
|
18
|
+
class MemoryAgent extends agent_js_1.Agent {
|
|
19
|
+
/**
|
|
20
|
+
* Creates a new MemoryAgent instance.
|
|
21
|
+
*/
|
|
22
|
+
constructor(options) {
|
|
23
|
+
(0, type_utils_js_1.checkArguments)("MemoryAgent", memoryAgentOptionsSchema, options);
|
|
24
|
+
super({
|
|
25
|
+
subscribeTopic: options.subscribeTopic,
|
|
26
|
+
skills: options.skills,
|
|
27
|
+
});
|
|
28
|
+
this.recorder = options.recorder;
|
|
29
|
+
this.retriever = options.retriever;
|
|
30
|
+
this.autoUpdate = options.autoUpdate;
|
|
31
|
+
}
|
|
32
|
+
_retriever;
|
|
33
|
+
/**
|
|
34
|
+
* Agent used for retrieving memories from storage.
|
|
35
|
+
*
|
|
36
|
+
* This retriever is automatically added to the agent's skills when set.
|
|
37
|
+
* Setting a new retriever will remove any previously set retriever from skills.
|
|
38
|
+
*/
|
|
39
|
+
get retriever() {
|
|
40
|
+
return this._retriever;
|
|
41
|
+
}
|
|
42
|
+
set retriever(value) {
|
|
43
|
+
if (this._retriever)
|
|
44
|
+
(0, type_utils_js_1.remove)(this.skills, [this._retriever]);
|
|
45
|
+
this._retriever = value;
|
|
46
|
+
if (value)
|
|
47
|
+
this.skills.push(value);
|
|
48
|
+
}
|
|
49
|
+
_recorder;
|
|
50
|
+
/**
|
|
51
|
+
* Agent used for recording and storing new memories.
|
|
52
|
+
*
|
|
53
|
+
* This recorder is automatically added to the agent's skills when set.
|
|
54
|
+
* Setting a new recorder will remove any previously set recorder from skills.
|
|
55
|
+
*/
|
|
56
|
+
get recorder() {
|
|
57
|
+
return this._recorder;
|
|
58
|
+
}
|
|
59
|
+
set recorder(value) {
|
|
60
|
+
if (this._recorder)
|
|
61
|
+
(0, type_utils_js_1.remove)(this.skills, [this._recorder]);
|
|
62
|
+
this._recorder = value;
|
|
63
|
+
if (value)
|
|
64
|
+
this.skills.push(value);
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Controls whether to automatically update the memory when agent call completes.
|
|
68
|
+
*
|
|
69
|
+
* When true, the agent will automatically record any relevant information
|
|
70
|
+
* after completing operations, creating a history of interactions.
|
|
71
|
+
*/
|
|
72
|
+
autoUpdate;
|
|
73
|
+
/**
|
|
74
|
+
* Indicates whether this agent can be directly called.
|
|
75
|
+
*
|
|
76
|
+
* MemoryAgent is designed to be used as a supporting component rather than
|
|
77
|
+
* being directly invoked for processing, so this returns false.
|
|
78
|
+
*/
|
|
79
|
+
get isCallable() {
|
|
80
|
+
return false;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* The standard message processing method required by the Agent interface.
|
|
84
|
+
*
|
|
85
|
+
* MemoryAgent doesn't directly process messages like other agents, so this method
|
|
86
|
+
* throws an error when called. Use the specialized retrieve() and record() methods instead.
|
|
87
|
+
*/
|
|
88
|
+
async process(_input, _context) {
|
|
89
|
+
throw new Error("Method not implemented.");
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Retrieves memories based on the provided input criteria.
|
|
93
|
+
*
|
|
94
|
+
* Delegates the actual retrieval operation to the configured retriever agent.
|
|
95
|
+
*
|
|
96
|
+
* @param input - The retrieval parameters (can include search terms, limits, etc.)
|
|
97
|
+
* @param context - The execution context
|
|
98
|
+
* @returns A promise resolving to the retrieved memories
|
|
99
|
+
* @throws Error - If no retriever has been initialized
|
|
100
|
+
*/
|
|
101
|
+
async retrieve(input, context) {
|
|
102
|
+
if (!this.retriever)
|
|
103
|
+
throw new Error("MemoryAgent retriever not initialized");
|
|
104
|
+
return context.invoke(this.retriever, input);
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Records new memories based on the provided input content.
|
|
108
|
+
*
|
|
109
|
+
* Delegates the actual recording operation to the configured recorder agent.
|
|
110
|
+
*
|
|
111
|
+
* @param input - The content to be recorded as memories
|
|
112
|
+
* @param context - The execution context
|
|
113
|
+
* @returns A promise resolving to the recorded memories
|
|
114
|
+
* @throws Error - If no recorder has been initialized
|
|
115
|
+
*/
|
|
116
|
+
async record(input, context) {
|
|
117
|
+
if (!this.recorder)
|
|
118
|
+
throw new Error("MemoryAgent recorder not initialized");
|
|
119
|
+
return context.invoke(this.recorder, input);
|
|
120
|
+
}
|
|
121
|
+
async onMessage({ role, source, message, context }) {
|
|
122
|
+
this.record({ content: [{ role, source, content: message }] }, context);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
exports.MemoryAgent = MemoryAgent;
|
|
126
|
+
const memoryAgentOptionsSchema = zod_1.z.object({
|
|
127
|
+
retriever: zod_1.z.custom().optional(),
|
|
128
|
+
recorder: zod_1.z.custom().optional(),
|
|
129
|
+
autoUpdate: zod_1.z.boolean().optional(),
|
|
130
|
+
subscribeTopic: zod_1.z.union([zod_1.z.string(), zod_1.z.array(zod_1.z.string())]).optional(),
|
|
131
|
+
skills: zod_1.z.array(zod_1.z.custom()).optional(),
|
|
132
|
+
});
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { type ZodType, z } from "zod";
|
|
2
|
+
import { Agent, type AgentOptions, type Message } from "../agents/agent.js";
|
|
3
|
+
import type { Memory } from "./memory.js";
|
|
4
|
+
/**
|
|
5
|
+
* Input for memory recording operations.
|
|
6
|
+
*
|
|
7
|
+
* This interface represents the data needed to record new memories
|
|
8
|
+
* in the system. The content array can contain any type of data that
|
|
9
|
+
* should be stored as memories.
|
|
10
|
+
*/
|
|
11
|
+
export interface MemoryRecorderInput extends Message {
|
|
12
|
+
/**
|
|
13
|
+
* Array of content items to record as memories.
|
|
14
|
+
* Each item in this array will typically be converted into a separate memory entry.
|
|
15
|
+
*/
|
|
16
|
+
content: unknown[];
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* @hidden
|
|
20
|
+
*/
|
|
21
|
+
export declare const memoryRecorderInputSchema: ZodType<MemoryRecorderInput>;
|
|
22
|
+
/**
|
|
23
|
+
* Output from memory recording operations.
|
|
24
|
+
*
|
|
25
|
+
* This interface represents the result of recording new memories,
|
|
26
|
+
* including the newly created memory objects with their IDs and timestamps.
|
|
27
|
+
*/
|
|
28
|
+
export interface MemoryRecorderOutput extends Message {
|
|
29
|
+
/**
|
|
30
|
+
* Array of newly created memory objects.
|
|
31
|
+
* Each memory includes a unique ID, the stored content, and a creation timestamp.
|
|
32
|
+
*/
|
|
33
|
+
memories: Memory[];
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* @hidden
|
|
37
|
+
*/
|
|
38
|
+
export declare const memoryRecorderOutputSchema: z.ZodObject<{
|
|
39
|
+
memories: z.ZodArray<z.ZodObject<{
|
|
40
|
+
id: z.ZodString;
|
|
41
|
+
content: ZodType<{}, z.ZodTypeDef, {}>;
|
|
42
|
+
createdAt: z.ZodString;
|
|
43
|
+
}, "strip", z.ZodTypeAny, {
|
|
44
|
+
content: {};
|
|
45
|
+
id: string;
|
|
46
|
+
createdAt: string;
|
|
47
|
+
}, {
|
|
48
|
+
content: {};
|
|
49
|
+
id: string;
|
|
50
|
+
createdAt: string;
|
|
51
|
+
}>, "many">;
|
|
52
|
+
}, "strip", z.ZodTypeAny, {
|
|
53
|
+
memories: {
|
|
54
|
+
content: {};
|
|
55
|
+
id: string;
|
|
56
|
+
createdAt: string;
|
|
57
|
+
}[];
|
|
58
|
+
}, {
|
|
59
|
+
memories: {
|
|
60
|
+
content: {};
|
|
61
|
+
id: string;
|
|
62
|
+
createdAt: string;
|
|
63
|
+
}[];
|
|
64
|
+
}>;
|
|
65
|
+
/**
|
|
66
|
+
* Abstract base class for agents that record and store memories.
|
|
67
|
+
*
|
|
68
|
+
* The MemoryRecorder serves as a foundation for implementing specific memory storage
|
|
69
|
+
* mechanisms. Implementations of this class are responsible for:
|
|
70
|
+
*
|
|
71
|
+
* 1. Converting input content into standardized memory objects
|
|
72
|
+
* 2. Assigning unique IDs to new memories
|
|
73
|
+
* 3. Storing memories in an appropriate backend (database, file system, etc.)
|
|
74
|
+
* 4. Ensuring proper timestamping of memories
|
|
75
|
+
*
|
|
76
|
+
* Custom implementations should extend this class and provide concrete
|
|
77
|
+
* implementations of the process method to handle the actual storage logic.
|
|
78
|
+
*/
|
|
79
|
+
export declare abstract class MemoryRecorder extends Agent<MemoryRecorderInput, MemoryRecorderOutput> {
|
|
80
|
+
/**
|
|
81
|
+
* Creates a new MemoryRecorder instance with predefined input and output schemas.
|
|
82
|
+
*
|
|
83
|
+
* @param options - Configuration options for the memory recorder agent
|
|
84
|
+
*/
|
|
85
|
+
constructor(options: Omit<AgentOptions<MemoryRecorderInput, MemoryRecorderOutput>, "inputSchema" | "outputSchema">);
|
|
86
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MemoryRecorder = exports.memoryRecorderOutputSchema = exports.memoryRecorderInputSchema = void 0;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
const agent_js_1 = require("../agents/agent.js");
|
|
6
|
+
/**
|
|
7
|
+
* @hidden
|
|
8
|
+
*/
|
|
9
|
+
exports.memoryRecorderInputSchema = zod_1.z.object({
|
|
10
|
+
content: zod_1.z.array(zod_1.z.unknown()),
|
|
11
|
+
});
|
|
12
|
+
/**
|
|
13
|
+
* @hidden
|
|
14
|
+
*/
|
|
15
|
+
exports.memoryRecorderOutputSchema = zod_1.z.object({
|
|
16
|
+
memories: zod_1.z.array(zod_1.z.object({
|
|
17
|
+
id: zod_1.z.string(),
|
|
18
|
+
content: zod_1.z.custom(),
|
|
19
|
+
createdAt: zod_1.z.string().datetime(),
|
|
20
|
+
})),
|
|
21
|
+
});
|
|
22
|
+
/**
|
|
23
|
+
* Abstract base class for agents that record and store memories.
|
|
24
|
+
*
|
|
25
|
+
* The MemoryRecorder serves as a foundation for implementing specific memory storage
|
|
26
|
+
* mechanisms. Implementations of this class are responsible for:
|
|
27
|
+
*
|
|
28
|
+
* 1. Converting input content into standardized memory objects
|
|
29
|
+
* 2. Assigning unique IDs to new memories
|
|
30
|
+
* 3. Storing memories in an appropriate backend (database, file system, etc.)
|
|
31
|
+
* 4. Ensuring proper timestamping of memories
|
|
32
|
+
*
|
|
33
|
+
* Custom implementations should extend this class and provide concrete
|
|
34
|
+
* implementations of the process method to handle the actual storage logic.
|
|
35
|
+
*/
|
|
36
|
+
class MemoryRecorder extends agent_js_1.Agent {
|
|
37
|
+
/**
|
|
38
|
+
* Creates a new MemoryRecorder instance with predefined input and output schemas.
|
|
39
|
+
*
|
|
40
|
+
* @param options - Configuration options for the memory recorder agent
|
|
41
|
+
*/
|
|
42
|
+
constructor(options) {
|
|
43
|
+
super({
|
|
44
|
+
...options,
|
|
45
|
+
inputSchema: exports.memoryRecorderInputSchema,
|
|
46
|
+
outputSchema: exports.memoryRecorderOutputSchema,
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
exports.MemoryRecorder = MemoryRecorder;
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { Agent, type AgentOptions, type Message } from "../agents/agent.js";
|
|
3
|
+
import type { Memory } from "./memory.js";
|
|
4
|
+
/**
|
|
5
|
+
* Input for memory retrieval operations.
|
|
6
|
+
*
|
|
7
|
+
* This interface defines the parameters that can be used to query and filter
|
|
8
|
+
* memories when retrieving them from storage.
|
|
9
|
+
*/
|
|
10
|
+
export interface MemoryRetrieverInput extends Message {
|
|
11
|
+
/**
|
|
12
|
+
* Maximum number of memories to retrieve.
|
|
13
|
+
* Used for pagination or limiting result set size.
|
|
14
|
+
*/
|
|
15
|
+
limit?: number;
|
|
16
|
+
/**
|
|
17
|
+
* Search term to filter memories by.
|
|
18
|
+
* How the search is implemented depends on the specific retriever implementation.
|
|
19
|
+
*/
|
|
20
|
+
search?: string;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Output from memory retrieval operations.
|
|
24
|
+
*
|
|
25
|
+
* This interface represents the result of retrieving memories from storage,
|
|
26
|
+
* containing an array of memory objects that match the query criteria.
|
|
27
|
+
*/
|
|
28
|
+
export interface MemoryRetrieverOutput extends Message {
|
|
29
|
+
/**
|
|
30
|
+
* Array of retrieved memory objects.
|
|
31
|
+
* Each memory includes its ID, content, and creation timestamp.
|
|
32
|
+
*/
|
|
33
|
+
memories: Memory[];
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* @hidden
|
|
37
|
+
*/
|
|
38
|
+
export declare const memoryRetrieverInputSchema: z.ZodObject<{
|
|
39
|
+
limit: z.ZodOptional<z.ZodNumber>;
|
|
40
|
+
search: z.ZodOptional<z.ZodString>;
|
|
41
|
+
}, "strip", z.ZodTypeAny, {
|
|
42
|
+
limit?: number | undefined;
|
|
43
|
+
search?: string | undefined;
|
|
44
|
+
}, {
|
|
45
|
+
limit?: number | undefined;
|
|
46
|
+
search?: string | undefined;
|
|
47
|
+
}>;
|
|
48
|
+
/**
|
|
49
|
+
* @hidden
|
|
50
|
+
*/
|
|
51
|
+
export declare const memoryRetrieverOutputSchema: z.ZodObject<{
|
|
52
|
+
memories: z.ZodArray<z.ZodObject<{
|
|
53
|
+
id: z.ZodString;
|
|
54
|
+
content: z.ZodType<{}, z.ZodTypeDef, {}>;
|
|
55
|
+
createdAt: z.ZodString;
|
|
56
|
+
}, "strip", z.ZodTypeAny, {
|
|
57
|
+
content: {};
|
|
58
|
+
id: string;
|
|
59
|
+
createdAt: string;
|
|
60
|
+
}, {
|
|
61
|
+
content: {};
|
|
62
|
+
id: string;
|
|
63
|
+
createdAt: string;
|
|
64
|
+
}>, "many">;
|
|
65
|
+
}, "strip", z.ZodTypeAny, {
|
|
66
|
+
memories: {
|
|
67
|
+
content: {};
|
|
68
|
+
id: string;
|
|
69
|
+
createdAt: string;
|
|
70
|
+
}[];
|
|
71
|
+
}, {
|
|
72
|
+
memories: {
|
|
73
|
+
content: {};
|
|
74
|
+
id: string;
|
|
75
|
+
createdAt: string;
|
|
76
|
+
}[];
|
|
77
|
+
}>;
|
|
78
|
+
/**
|
|
79
|
+
* Abstract base class for agents that retrieve memories from storage.
|
|
80
|
+
*
|
|
81
|
+
* The MemoryRetriever serves as a foundation for implementing specific memory
|
|
82
|
+
* retrieval mechanisms. Implementations of this class are responsible for:
|
|
83
|
+
*
|
|
84
|
+
* 1. Querying a memory storage backend to find relevant memories
|
|
85
|
+
* 2. Filtering memories based on search criteria
|
|
86
|
+
* 3. Limiting the number of results returned
|
|
87
|
+
* 4. Potentially implementing sorting, ranking, or relevance-based retrieval
|
|
88
|
+
*
|
|
89
|
+
* Custom implementations should extend this class and provide concrete
|
|
90
|
+
* implementations of the process method to handle the actual retrieval logic.
|
|
91
|
+
*/
|
|
92
|
+
export declare abstract class MemoryRetriever extends Agent<MemoryRetrieverInput, MemoryRetrieverOutput> {
|
|
93
|
+
/**
|
|
94
|
+
* Creates a new MemoryRetriever instance with predefined input and output schemas.
|
|
95
|
+
*
|
|
96
|
+
* @param options - Configuration options for the memory retriever agent
|
|
97
|
+
*/
|
|
98
|
+
constructor(options: Omit<AgentOptions<MemoryRetrieverInput, MemoryRetrieverOutput>, "inputSchema" | "outputSchema">);
|
|
99
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MemoryRetriever = exports.memoryRetrieverOutputSchema = exports.memoryRetrieverInputSchema = void 0;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
const agent_js_1 = require("../agents/agent.js");
|
|
6
|
+
/**
|
|
7
|
+
* @hidden
|
|
8
|
+
*/
|
|
9
|
+
exports.memoryRetrieverInputSchema = zod_1.z.object({
|
|
10
|
+
limit: zod_1.z.number().optional(),
|
|
11
|
+
search: zod_1.z.string().optional(),
|
|
12
|
+
});
|
|
13
|
+
/**
|
|
14
|
+
* @hidden
|
|
15
|
+
*/
|
|
16
|
+
exports.memoryRetrieverOutputSchema = zod_1.z.object({
|
|
17
|
+
memories: zod_1.z.array(zod_1.z.object({
|
|
18
|
+
id: zod_1.z.string(),
|
|
19
|
+
content: zod_1.z.custom(),
|
|
20
|
+
createdAt: zod_1.z.string().datetime(),
|
|
21
|
+
})),
|
|
22
|
+
});
|
|
23
|
+
/**
|
|
24
|
+
* Abstract base class for agents that retrieve memories from storage.
|
|
25
|
+
*
|
|
26
|
+
* The MemoryRetriever serves as a foundation for implementing specific memory
|
|
27
|
+
* retrieval mechanisms. Implementations of this class are responsible for:
|
|
28
|
+
*
|
|
29
|
+
* 1. Querying a memory storage backend to find relevant memories
|
|
30
|
+
* 2. Filtering memories based on search criteria
|
|
31
|
+
* 3. Limiting the number of results returned
|
|
32
|
+
* 4. Potentially implementing sorting, ranking, or relevance-based retrieval
|
|
33
|
+
*
|
|
34
|
+
* Custom implementations should extend this class and provide concrete
|
|
35
|
+
* implementations of the process method to handle the actual retrieval logic.
|
|
36
|
+
*/
|
|
37
|
+
class MemoryRetriever extends agent_js_1.Agent {
|
|
38
|
+
/**
|
|
39
|
+
* Creates a new MemoryRetriever instance with predefined input and output schemas.
|
|
40
|
+
*
|
|
41
|
+
* @param options - Configuration options for the memory retriever agent
|
|
42
|
+
*/
|
|
43
|
+
constructor(options) {
|
|
44
|
+
super({
|
|
45
|
+
...options,
|
|
46
|
+
inputSchema: exports.memoryRetrieverInputSchema,
|
|
47
|
+
outputSchema: exports.memoryRetrieverOutputSchema,
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
exports.MemoryRetriever = MemoryRetriever;
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { BedrockRuntimeClient } from "@aws-sdk/client-bedrock-runtime";
|
|
2
2
|
import { z } from "zod";
|
|
3
|
-
import type {
|
|
4
|
-
import type { Context } from "../aigne/context.js";
|
|
3
|
+
import type { AgentResponse } from "../agents/agent.js";
|
|
5
4
|
import { ChatModel, type ChatModelInput, type ChatModelOptions, type ChatModelOutput } from "./chat-model.js";
|
|
5
|
+
/**
|
|
6
|
+
* @hidden
|
|
7
|
+
*/
|
|
6
8
|
export declare function extractLastJsonObject(text: string): string | null;
|
|
7
9
|
export interface BedrockChatModelOptions {
|
|
8
10
|
accessKeyId?: string;
|
|
@@ -11,6 +13,9 @@ export interface BedrockChatModelOptions {
|
|
|
11
13
|
model?: string;
|
|
12
14
|
modelOptions?: ChatModelOptions;
|
|
13
15
|
}
|
|
16
|
+
/**
|
|
17
|
+
* @hidden
|
|
18
|
+
*/
|
|
14
19
|
export declare const bedrockChatModelOptionsSchema: z.ZodObject<{
|
|
15
20
|
region: z.ZodOptional<z.ZodString>;
|
|
16
21
|
model: z.ZodOptional<z.ZodString>;
|
|
@@ -62,9 +67,13 @@ export declare const bedrockChatModelOptionsSchema: z.ZodObject<{
|
|
|
62
67
|
export declare class BedrockChatModel extends ChatModel {
|
|
63
68
|
options?: BedrockChatModelOptions | undefined;
|
|
64
69
|
constructor(options?: BedrockChatModelOptions | undefined);
|
|
70
|
+
/**
|
|
71
|
+
* @hidden
|
|
72
|
+
*/
|
|
65
73
|
protected _client?: BedrockRuntimeClient;
|
|
66
74
|
get client(): BedrockRuntimeClient;
|
|
67
75
|
get modelOptions(): ChatModelOptions | undefined;
|
|
68
|
-
process(input: ChatModelInput
|
|
76
|
+
process(input: ChatModelInput): Promise<AgentResponse<ChatModelOutput>>;
|
|
69
77
|
private extractResultFromStream;
|
|
78
|
+
private requestStructuredOutput;
|
|
70
79
|
}
|