@aigne/core 0.4.205-0 → 0.4.205
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/lib/cjs/agent.js +65 -0
- package/lib/cjs/{data-type-schema.js → definitions/data-type-schema.js} +1 -1
- package/lib/cjs/definitions/memory.js +21 -0
- package/lib/cjs/function-agent.js +1 -1
- package/lib/cjs/function-runner.js +2 -2
- package/lib/cjs/index.js +1 -1
- package/lib/cjs/llm-agent.js +20 -127
- package/lib/cjs/llm-decision-agent.js +40 -33
- package/lib/cjs/llm-model.js +2 -2
- package/lib/cjs/local-function-agent.js +11 -9
- package/lib/cjs/pipeline-agent.js +23 -18
- package/lib/cjs/runnable.js +3 -1
- package/lib/cjs/tsconfig.tsbuildinfo +1 -1
- package/lib/cjs/utils/message-utils.js +62 -0
- package/lib/cjs/utils/nullable.js +2 -0
- package/lib/cjs/utils/ordered-map.js +12 -0
- package/lib/cjs/utils/stream-utils.js +43 -5
- package/lib/esm/agent.js +58 -0
- package/lib/esm/{data-type-schema.js → definitions/data-type-schema.js} +1 -1
- package/lib/esm/definitions/memory.js +18 -0
- package/lib/esm/function-agent.js +1 -1
- package/lib/esm/function-runner.js +2 -2
- package/lib/esm/index.js +1 -1
- package/lib/esm/llm-agent.js +22 -126
- package/lib/esm/llm-decision-agent.js +41 -34
- package/lib/esm/llm-model.js +2 -2
- package/lib/esm/local-function-agent.js +11 -9
- package/lib/esm/pipeline-agent.js +23 -18
- package/lib/esm/runnable.js +3 -1
- package/lib/esm/tsconfig.tsbuildinfo +1 -1
- package/lib/esm/utils/message-utils.js +57 -0
- package/lib/esm/utils/nullable.js +1 -0
- package/lib/esm/utils/ordered-map.js +12 -0
- package/lib/esm/utils/stream-utils.js +42 -5
- package/lib/types/agent.d.ts +42 -0
- package/lib/types/{data-type-schema.d.ts → definitions/data-type-schema.d.ts} +3 -9
- package/lib/types/definitions/memory.d.ts +40 -0
- package/lib/types/function-agent.d.ts +1 -1
- package/lib/types/function-runner.d.ts +2 -1
- package/lib/types/index.d.ts +1 -1
- package/lib/types/llm-agent.d.ts +34 -63
- package/lib/types/llm-decision-agent.d.ts +54 -30
- package/lib/types/llm-model.d.ts +2 -1
- package/lib/types/local-function-agent.d.ts +50 -19
- package/lib/types/memorable.d.ts +3 -2
- package/lib/types/pipeline-agent.d.ts +63 -23
- package/lib/types/runnable.d.ts +10 -4
- package/lib/types/tsconfig.tsbuildinfo +1 -1
- package/lib/types/utils/message-utils.d.ts +19 -1
- package/lib/types/utils/nullable.d.ts +7 -0
- package/lib/types/utils/ordered-map.d.ts +3 -0
- package/lib/types/utils/stream-utils.d.ts +12 -1
- package/lib/types/utils/union.d.ts +1 -1
- package/package.json +1 -1
- package/lib/cjs/memory.js +0 -32
- package/lib/esm/memory.js +0 -27
- package/lib/types/memory.d.ts +0 -184
|
@@ -1,2 +1,20 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { LLMAgentDefinition } from '../llm-agent';
|
|
2
|
+
import type { LLMModelInputMessage } from '../llm-model';
|
|
3
|
+
import type { MemoryItemWithScore } from '../memorable';
|
|
2
4
|
export declare function mergeHistoryMessages(messages: LLMModelInputMessage[], history: LLMModelInputMessage[]): LLMModelInputMessage[];
|
|
5
|
+
export declare function memoriesToMessages(memories: {
|
|
6
|
+
[name: string]: MemoryItemWithScore[];
|
|
7
|
+
}, { primaryMemoryName }?: {
|
|
8
|
+
primaryMemoryName?: string;
|
|
9
|
+
}): {
|
|
10
|
+
primaryMemory: LLMModelInputMessage[];
|
|
11
|
+
memory: string;
|
|
12
|
+
};
|
|
13
|
+
export declare function prepareMessages(definition: Pick<LLMAgentDefinition, 'messages' | 'memories' | 'primaryMemoryId'>, input: {
|
|
14
|
+
[name: string]: any;
|
|
15
|
+
}, memories: {
|
|
16
|
+
[name: string]: MemoryItemWithScore[];
|
|
17
|
+
}): {
|
|
18
|
+
originalMessages: LLMModelInputMessage[];
|
|
19
|
+
messagesWithMemory: LLMModelInputMessage[];
|
|
20
|
+
};
|
|
@@ -28,6 +28,9 @@ export declare namespace OrderedRecord {
|
|
|
28
28
|
function push<T extends {
|
|
29
29
|
id: string;
|
|
30
30
|
}>(record: OrderedRecord<T>, ...items: T[]): OrderedRecord<T>;
|
|
31
|
+
function merge<T extends {
|
|
32
|
+
id: string;
|
|
33
|
+
}>(...records: OrderedRecord<T>[]): OrderedRecord<T>;
|
|
31
34
|
function pushOrUpdate<T extends {
|
|
32
35
|
id: string;
|
|
33
36
|
}>(record: OrderedRecord<T>, ...items: T[]): OrderedRecord<T>;
|
|
@@ -1,7 +1,18 @@
|
|
|
1
|
-
import { RunnableResponseStream } from '../runnable';
|
|
1
|
+
import { RunnableResponse, RunnableResponseStream } from '../runnable';
|
|
2
2
|
export declare function objectToRunnableResponseStream<T extends {
|
|
3
3
|
[key: string]: any;
|
|
4
4
|
}>(obj: T): RunnableResponseStream<T>;
|
|
5
5
|
export declare function runnableResponseStreamToObject<T extends {
|
|
6
6
|
[key: string]: any;
|
|
7
7
|
}>(stream: RunnableResponseStream<T>): Promise<T>;
|
|
8
|
+
/**
|
|
9
|
+
* Extracts the outputs from a runnable output stream and run the
|
|
10
|
+
* resolve function on the result before the stream closes. It can be
|
|
11
|
+
* used to update the memories of an agent.
|
|
12
|
+
* @param output The runnable output stream or object
|
|
13
|
+
* @param resolve The function to run on the result
|
|
14
|
+
* @returns The runnable output stream or object
|
|
15
|
+
*/
|
|
16
|
+
export declare function extractOutputsFromRunnableOutput<T extends {
|
|
17
|
+
[key: string]: any;
|
|
18
|
+
}>(output: RunnableResponse<T>, resolve: (result: T) => Promise<void> | void): Promise<typeof output>;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export type UnionToIntersection<U> = (U extends any ? (arg: U) => void : never) extends (arg: infer I) => void ? I : never;
|
|
2
|
-
export type ObjectUnionToIntersection<T> = UnionToIntersection<T> extends
|
|
2
|
+
export type ObjectUnionToIntersection<T, O = object> = UnionToIntersection<T> extends O ? UnionToIntersection<T> : never;
|
package/package.json
CHANGED
package/lib/cjs/memory.js
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MemoryRunner = exports.Memory = void 0;
|
|
4
|
-
const lodash_1 = require("lodash");
|
|
5
|
-
const runnable_1 = require("./runnable");
|
|
6
|
-
const utils_1 = require("./utils");
|
|
7
|
-
class Memory extends runnable_1.Runnable {
|
|
8
|
-
constructor() {
|
|
9
|
-
super({
|
|
10
|
-
id: 'memory',
|
|
11
|
-
type: 'memory',
|
|
12
|
-
name: 'Memory',
|
|
13
|
-
inputs: utils_1.OrderedRecord.fromArray([]),
|
|
14
|
-
outputs: utils_1.OrderedRecord.fromArray([]),
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
exports.Memory = Memory;
|
|
19
|
-
class MemoryRunner extends runnable_1.Runnable {
|
|
20
|
-
constructor(name) {
|
|
21
|
-
const id = `${(0, lodash_1.camelCase)(name)}_runner`;
|
|
22
|
-
super({
|
|
23
|
-
id,
|
|
24
|
-
type: id,
|
|
25
|
-
name: `${(0, lodash_1.startCase)(name)} Runner`,
|
|
26
|
-
description: `${(0, lodash_1.startCase)(name)} Runner`,
|
|
27
|
-
inputs: utils_1.OrderedRecord.fromArray([]),
|
|
28
|
-
outputs: utils_1.OrderedRecord.fromArray([]),
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
exports.MemoryRunner = MemoryRunner;
|
package/lib/esm/memory.js
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { camelCase, startCase } from 'lodash';
|
|
2
|
-
import { Runnable } from './runnable';
|
|
3
|
-
import { OrderedRecord } from './utils';
|
|
4
|
-
export class Memory extends Runnable {
|
|
5
|
-
constructor() {
|
|
6
|
-
super({
|
|
7
|
-
id: 'memory',
|
|
8
|
-
type: 'memory',
|
|
9
|
-
name: 'Memory',
|
|
10
|
-
inputs: OrderedRecord.fromArray([]),
|
|
11
|
-
outputs: OrderedRecord.fromArray([]),
|
|
12
|
-
});
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
export class MemoryRunner extends Runnable {
|
|
16
|
-
constructor(name) {
|
|
17
|
-
const id = `${camelCase(name)}_runner`;
|
|
18
|
-
super({
|
|
19
|
-
id,
|
|
20
|
-
type: id,
|
|
21
|
-
name: `${startCase(name)} Runner`,
|
|
22
|
-
description: `${startCase(name)} Runner`,
|
|
23
|
-
inputs: OrderedRecord.fromArray([]),
|
|
24
|
-
outputs: OrderedRecord.fromArray([]),
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
}
|
package/lib/types/memory.d.ts
DELETED
|
@@ -1,184 +0,0 @@
|
|
|
1
|
-
import { Runnable } from './runnable';
|
|
2
|
-
export interface MemoryMetadata {
|
|
3
|
-
[key: string]: any;
|
|
4
|
-
}
|
|
5
|
-
export type MemoryActionItem<T> = {
|
|
6
|
-
event: 'add';
|
|
7
|
-
id: string;
|
|
8
|
-
memory: T;
|
|
9
|
-
metadata?: MemoryMetadata;
|
|
10
|
-
} | {
|
|
11
|
-
event: 'update';
|
|
12
|
-
id: string;
|
|
13
|
-
memory: T;
|
|
14
|
-
oldMemory: T;
|
|
15
|
-
metadata?: MemoryMetadata;
|
|
16
|
-
} | {
|
|
17
|
-
event: 'delete';
|
|
18
|
-
id: string;
|
|
19
|
-
memory: T;
|
|
20
|
-
} | {
|
|
21
|
-
event: 'none';
|
|
22
|
-
memory: T;
|
|
23
|
-
};
|
|
24
|
-
export interface MemoryItem<T> {
|
|
25
|
-
id: string;
|
|
26
|
-
userId?: string;
|
|
27
|
-
sessionId?: string;
|
|
28
|
-
createdAt: string;
|
|
29
|
-
updatedAt: string;
|
|
30
|
-
memory: T;
|
|
31
|
-
metadata: MemoryMetadata;
|
|
32
|
-
}
|
|
33
|
-
export interface MemoryItemWithScore<T> extends MemoryItem<T> {
|
|
34
|
-
score: number;
|
|
35
|
-
}
|
|
36
|
-
export interface MemoryMessage {
|
|
37
|
-
role: string;
|
|
38
|
-
content: string;
|
|
39
|
-
}
|
|
40
|
-
export type MemoryActions<T> = {
|
|
41
|
-
action: 'add';
|
|
42
|
-
inputs: {
|
|
43
|
-
messages: MemoryMessage[];
|
|
44
|
-
options?: {
|
|
45
|
-
userId?: string;
|
|
46
|
-
sessionId?: string;
|
|
47
|
-
metadata?: MemoryMetadata;
|
|
48
|
-
};
|
|
49
|
-
};
|
|
50
|
-
outputs: {
|
|
51
|
-
results: MemoryActionItem<T>[];
|
|
52
|
-
};
|
|
53
|
-
} | {
|
|
54
|
-
action: 'search';
|
|
55
|
-
inputs: {
|
|
56
|
-
query: string;
|
|
57
|
-
options?: {
|
|
58
|
-
k?: number;
|
|
59
|
-
userId?: string;
|
|
60
|
-
sessionId?: string;
|
|
61
|
-
filter?: MemoryMetadata;
|
|
62
|
-
sort?: MemorySortOptions;
|
|
63
|
-
};
|
|
64
|
-
};
|
|
65
|
-
outputs: {
|
|
66
|
-
results: MemoryItemWithScore<T>[];
|
|
67
|
-
};
|
|
68
|
-
} | {
|
|
69
|
-
action: 'filter';
|
|
70
|
-
inputs: {
|
|
71
|
-
options?: {
|
|
72
|
-
k?: number;
|
|
73
|
-
userId?: string;
|
|
74
|
-
sessionId?: string;
|
|
75
|
-
filter?: MemoryMetadata;
|
|
76
|
-
sort?: MemorySortOptions;
|
|
77
|
-
};
|
|
78
|
-
};
|
|
79
|
-
outputs: {
|
|
80
|
-
results: MemoryItem<T>[];
|
|
81
|
-
};
|
|
82
|
-
} | {
|
|
83
|
-
action: 'get';
|
|
84
|
-
inputs: {
|
|
85
|
-
memoryId: string;
|
|
86
|
-
};
|
|
87
|
-
outputs: {
|
|
88
|
-
result: MemoryItem<T> | null;
|
|
89
|
-
};
|
|
90
|
-
} | {
|
|
91
|
-
action: 'create';
|
|
92
|
-
inputs: {
|
|
93
|
-
memory: T;
|
|
94
|
-
options?: {
|
|
95
|
-
userId?: string;
|
|
96
|
-
sessionId?: string;
|
|
97
|
-
metadata?: MemoryMetadata;
|
|
98
|
-
};
|
|
99
|
-
};
|
|
100
|
-
outputs: {
|
|
101
|
-
result: MemoryItem<T>;
|
|
102
|
-
};
|
|
103
|
-
} | {
|
|
104
|
-
action: 'update';
|
|
105
|
-
inputs: {
|
|
106
|
-
memoryId: string;
|
|
107
|
-
memory: T;
|
|
108
|
-
};
|
|
109
|
-
outputs: {
|
|
110
|
-
result: MemoryItem<T> | null;
|
|
111
|
-
};
|
|
112
|
-
} | {
|
|
113
|
-
action: 'delete';
|
|
114
|
-
inputs: {
|
|
115
|
-
filter: string | string[] | Record<string, any>;
|
|
116
|
-
};
|
|
117
|
-
outputs: {};
|
|
118
|
-
} | {
|
|
119
|
-
action: 'reset';
|
|
120
|
-
inputs: {};
|
|
121
|
-
outputs: {};
|
|
122
|
-
};
|
|
123
|
-
export interface SortItem {
|
|
124
|
-
field: string;
|
|
125
|
-
direction: 'asc' | 'desc';
|
|
126
|
-
}
|
|
127
|
-
export type MemorySortOptions = SortItem | SortItem[];
|
|
128
|
-
export declare abstract class Memory<T, C = undefined> extends Runnable<MemoryActions<T>, MemoryActions<T>['outputs']> {
|
|
129
|
-
constructor();
|
|
130
|
-
abstract runner?: MemoryRunner<T, C>;
|
|
131
|
-
abstract add(messages: Extract<MemoryActions<T>, {
|
|
132
|
-
action: 'add';
|
|
133
|
-
}>['inputs']['messages'], options?: Extract<MemoryActions<T>, {
|
|
134
|
-
action: 'add';
|
|
135
|
-
}>['inputs']['options']): Promise<Extract<MemoryActions<T>, {
|
|
136
|
-
action: 'add';
|
|
137
|
-
}>['outputs']>;
|
|
138
|
-
abstract search(query: Extract<MemoryActions<T>, {
|
|
139
|
-
action: 'search';
|
|
140
|
-
}>['inputs']['query'], options?: Extract<MemoryActions<T>, {
|
|
141
|
-
action: 'search';
|
|
142
|
-
}>['inputs']['options']): Promise<Extract<MemoryActions<T>, {
|
|
143
|
-
action: 'search';
|
|
144
|
-
}>['outputs']>;
|
|
145
|
-
abstract filter(options: Extract<MemoryActions<T>, {
|
|
146
|
-
action: 'filter';
|
|
147
|
-
}>['inputs']['options']): Promise<Extract<MemoryActions<T>, {
|
|
148
|
-
action: 'filter';
|
|
149
|
-
}>['outputs']>;
|
|
150
|
-
abstract get(memoryId: Extract<MemoryActions<T>, {
|
|
151
|
-
action: 'get';
|
|
152
|
-
}>['inputs']['memoryId']): Promise<Extract<MemoryActions<T>, {
|
|
153
|
-
action: 'get';
|
|
154
|
-
}>['outputs']>;
|
|
155
|
-
abstract create(memory: Extract<MemoryActions<T>, {
|
|
156
|
-
action: 'create';
|
|
157
|
-
}>['inputs']['memory'], options?: Extract<MemoryActions<T>, {
|
|
158
|
-
action: 'create';
|
|
159
|
-
}>['inputs']['options']): Promise<Extract<MemoryActions<T>, {
|
|
160
|
-
action: 'create';
|
|
161
|
-
}>['outputs']>;
|
|
162
|
-
abstract update(memoryId: Extract<MemoryActions<T>, {
|
|
163
|
-
action: 'update';
|
|
164
|
-
}>['inputs']['memoryId'], memory: T): Promise<Extract<MemoryActions<T>, {
|
|
165
|
-
action: 'update';
|
|
166
|
-
}>['outputs']>;
|
|
167
|
-
abstract delete(memoryId: Extract<MemoryActions<T>, {
|
|
168
|
-
action: 'delete';
|
|
169
|
-
}>['inputs']['filter']): Promise<Extract<MemoryActions<T>, {
|
|
170
|
-
action: 'delete';
|
|
171
|
-
}>['outputs']>;
|
|
172
|
-
abstract reset(): Promise<void>;
|
|
173
|
-
}
|
|
174
|
-
export interface MemoryRunnerInput<C = undefined> {
|
|
175
|
-
messages: MemoryMessage[];
|
|
176
|
-
userId?: string;
|
|
177
|
-
sessionId?: string;
|
|
178
|
-
metadata?: MemoryMetadata;
|
|
179
|
-
filter?: MemoryMetadata;
|
|
180
|
-
customData: C;
|
|
181
|
-
}
|
|
182
|
-
export declare abstract class MemoryRunner<T, C = undefined> extends Runnable<MemoryRunnerInput<C>, MemoryActionItem<T>[]> {
|
|
183
|
-
constructor(name: string);
|
|
184
|
-
}
|