@aigne/core 0.4.204 → 0.4.205-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/lib/cjs/agent.js +60 -0
- package/lib/cjs/definitions/data-type-schema.js +46 -0
- 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 +2 -2
- package/lib/cjs/llm-agent.js +93 -87
- 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/memorable.js +32 -0
- package/lib/cjs/pipeline-agent.js +2 -4
- package/lib/cjs/runnable.js +3 -1
- package/lib/cjs/tsconfig.tsbuildinfo +1 -1
- package/lib/cjs/utils/message-utils.js +72 -0
- package/lib/cjs/utils/nullable.js +2 -0
- package/lib/cjs/utils/ordered-map.js +25 -0
- package/lib/cjs/utils/stream-utils.js +43 -5
- package/lib/cjs/utils/structured-output-schema.js +39 -0
- package/lib/esm/agent.js +53 -0
- package/lib/esm/definitions/data-type-schema.js +43 -0
- 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 +2 -2
- package/lib/esm/llm-agent.js +94 -88
- 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/memorable.js +27 -0
- package/lib/esm/pipeline-agent.js +2 -4
- package/lib/esm/runnable.js +3 -1
- package/lib/esm/tsconfig.tsbuildinfo +1 -1
- package/lib/esm/utils/message-utils.js +64 -0
- package/lib/esm/utils/nullable.js +1 -0
- package/lib/esm/utils/ordered-map.js +25 -0
- package/lib/esm/utils/stream-utils.js +42 -5
- package/lib/esm/utils/structured-output-schema.js +33 -0
- package/lib/types/agent.d.ts +42 -0
- package/lib/types/context.d.ts +5 -1
- package/lib/types/definitions/data-type-schema.d.ts +40 -0
- 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 +2 -2
- package/lib/types/llm-agent.d.ts +74 -19
- 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 +51 -20
- package/lib/types/memorable.d.ts +183 -0
- package/lib/types/pipeline-agent.d.ts +2 -3
- package/lib/types/runnable.d.ts +23 -2
- package/lib/types/tsconfig.tsbuildinfo +1 -1
- package/lib/types/utils/message-utils.d.ts +20 -0
- package/lib/types/utils/nullable.d.ts +7 -0
- package/lib/types/utils/ordered-map.d.ts +6 -0
- package/lib/types/utils/stream-utils.d.ts +12 -1
- package/lib/types/utils/structured-output-schema.d.ts +3 -0
- package/lib/types/utils/union.d.ts +1 -1
- package/package.json +1 -1
|
@@ -1,38 +1,69 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import { Agent, AgentProcessOptions } from './agent';
|
|
2
|
+
import type { Context, ContextState } from './context';
|
|
3
|
+
import { DataTypeSchema, SchemaMapType } from './definitions/data-type-schema';
|
|
4
|
+
import { CreateRunnableMemory } from './definitions/memory';
|
|
5
|
+
import { MemorableSearchOutput, MemoryItemWithScore } from './memorable';
|
|
6
|
+
import { RunnableDefinition, RunnableResponse, RunnableResponseStream } from './runnable';
|
|
7
|
+
export declare class LocalFunctionAgent<I extends {
|
|
8
|
+
[name: string]: any;
|
|
9
|
+
} = {}, O extends {
|
|
10
|
+
[name: string]: any;
|
|
11
|
+
} = {}, Memories extends {
|
|
12
|
+
[name: string]: MemoryItemWithScore[];
|
|
13
|
+
} = {}, State extends ContextState = ContextState> extends Agent<I, O, Memories, State> {
|
|
14
|
+
definition: LocalFunctionAgentDefinition<I, O, Memories, State>;
|
|
7
15
|
static create<I extends {
|
|
8
16
|
[name: string]: DataTypeSchema;
|
|
9
17
|
}, O extends {
|
|
10
18
|
[name: string]: DataTypeSchema;
|
|
11
|
-
},
|
|
12
|
-
|
|
13
|
-
|
|
19
|
+
}, Memories extends {
|
|
20
|
+
[name: string]: CreateRunnableMemory<I>;
|
|
21
|
+
}, State extends ContextState = ContextState>(options: Parameters<typeof createLocalFunctionAgentDefinition<I, O, Memories, State>>[0]): LocalFunctionAgent<SchemaMapType<I>, SchemaMapType<O>, {
|
|
22
|
+
[name in keyof Memories]: MemorableSearchOutput<Memories[name]['memory']>;
|
|
23
|
+
}, State>;
|
|
24
|
+
constructor(definition: LocalFunctionAgentDefinition<I, O, Memories, State>, context?: Context<State>);
|
|
25
|
+
process(input: I, options: AgentProcessOptions<Memories> & {
|
|
14
26
|
stream: true;
|
|
15
27
|
}): Promise<RunnableResponseStream<O>>;
|
|
16
|
-
|
|
28
|
+
process(input: I, options: AgentProcessOptions<Memories> & {
|
|
17
29
|
stream?: false;
|
|
18
30
|
}): Promise<O>;
|
|
19
31
|
}
|
|
20
|
-
export
|
|
32
|
+
export interface CreateLocalFunctionAgentOptions<I extends {
|
|
21
33
|
[name: string]: DataTypeSchema;
|
|
22
34
|
}, O extends {
|
|
23
35
|
[name: string]: DataTypeSchema;
|
|
24
|
-
},
|
|
25
|
-
|
|
36
|
+
}, Memories extends {
|
|
37
|
+
[name: string]: CreateRunnableMemory<I>;
|
|
38
|
+
}, State extends ContextState = ContextState> {
|
|
26
39
|
name?: string;
|
|
27
40
|
inputs: I;
|
|
28
41
|
outputs: O;
|
|
29
|
-
|
|
42
|
+
memories?: Memories;
|
|
43
|
+
function?: LocalFunctionFuncType<SchemaMapType<I>, SchemaMapType<O>, {
|
|
44
|
+
[key in keyof Memories]: MemorableSearchOutput<Memories[key]['memory']>;
|
|
45
|
+
}, State>;
|
|
46
|
+
}
|
|
47
|
+
export declare function createLocalFunctionAgentDefinition<I extends {
|
|
48
|
+
[name: string]: DataTypeSchema;
|
|
49
|
+
}, O extends {
|
|
50
|
+
[name: string]: DataTypeSchema;
|
|
51
|
+
}, Memories extends {
|
|
52
|
+
[name: string]: CreateRunnableMemory<I>;
|
|
53
|
+
}, State extends ContextState = ContextState>(options: CreateLocalFunctionAgentOptions<I, O, Memories, State>): LocalFunctionAgentDefinition<SchemaMapType<I>, SchemaMapType<O>, {
|
|
54
|
+
[key in keyof Memories]: MemorableSearchOutput<Memories[key]['memory']>;
|
|
55
|
+
}, State>;
|
|
56
|
+
export interface LocalFunctionFuncType<I extends {} = {}, O extends {} = {}, Memories extends {
|
|
57
|
+
[name: string]: MemoryItemWithScore[];
|
|
58
|
+
} = {}, State extends ContextState = ContextState> {
|
|
59
|
+
(input: I, options: {
|
|
60
|
+
memories: Memories;
|
|
30
61
|
context: Context<State>;
|
|
31
|
-
})
|
|
32
|
-
}
|
|
33
|
-
export interface LocalFunctionAgentDefinition<I extends {} = {}, O extends {} = {},
|
|
62
|
+
}): Promise<RunnableResponse<O>>;
|
|
63
|
+
}
|
|
64
|
+
export interface LocalFunctionAgentDefinition<I extends {} = {}, O extends {} = {}, Memories extends {
|
|
65
|
+
[name: string]: MemoryItemWithScore[];
|
|
66
|
+
} = {}, State extends ContextState = ContextState> extends RunnableDefinition {
|
|
34
67
|
type: 'local_function_agent';
|
|
35
|
-
function?:
|
|
36
|
-
context: Context<State>;
|
|
37
|
-
}) => Promise<RunnableResponse<O>>;
|
|
68
|
+
function?: LocalFunctionFuncType<I, O, Memories, State>;
|
|
38
69
|
}
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
import { LLMModelInputMessage } from './llm-model';
|
|
2
|
+
import { Runnable } from './runnable';
|
|
3
|
+
export interface MemoryMetadata {
|
|
4
|
+
[key: string]: any;
|
|
5
|
+
}
|
|
6
|
+
export type MemoryActionItem<T> = {
|
|
7
|
+
event: 'add';
|
|
8
|
+
id: string;
|
|
9
|
+
memory: T;
|
|
10
|
+
metadata?: MemoryMetadata;
|
|
11
|
+
} | {
|
|
12
|
+
event: 'update';
|
|
13
|
+
id: string;
|
|
14
|
+
memory: T;
|
|
15
|
+
oldMemory: T;
|
|
16
|
+
metadata?: MemoryMetadata;
|
|
17
|
+
} | {
|
|
18
|
+
event: 'delete';
|
|
19
|
+
id: string;
|
|
20
|
+
memory: T;
|
|
21
|
+
} | {
|
|
22
|
+
event: 'none';
|
|
23
|
+
memory: T;
|
|
24
|
+
};
|
|
25
|
+
export interface MemoryItem<T> {
|
|
26
|
+
id: string;
|
|
27
|
+
userId?: string;
|
|
28
|
+
sessionId?: string;
|
|
29
|
+
createdAt: string;
|
|
30
|
+
updatedAt: string;
|
|
31
|
+
memory: T;
|
|
32
|
+
metadata: MemoryMetadata;
|
|
33
|
+
}
|
|
34
|
+
export interface MemoryItemWithScore<T = any> extends MemoryItem<T> {
|
|
35
|
+
score: number;
|
|
36
|
+
}
|
|
37
|
+
export type MemoryMessage = LLMModelInputMessage;
|
|
38
|
+
export type MemoryActions<T> = {
|
|
39
|
+
action: 'add';
|
|
40
|
+
inputs: {
|
|
41
|
+
messages: MemoryMessage[];
|
|
42
|
+
options?: {
|
|
43
|
+
userId?: string;
|
|
44
|
+
sessionId?: string;
|
|
45
|
+
metadata?: MemoryMetadata;
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
outputs: {
|
|
49
|
+
results: MemoryActionItem<T>[];
|
|
50
|
+
};
|
|
51
|
+
} | {
|
|
52
|
+
action: 'search';
|
|
53
|
+
inputs: {
|
|
54
|
+
query: string;
|
|
55
|
+
options?: {
|
|
56
|
+
k?: number;
|
|
57
|
+
userId?: string;
|
|
58
|
+
sessionId?: string;
|
|
59
|
+
filter?: MemoryMetadata;
|
|
60
|
+
sort?: MemorySortOptions;
|
|
61
|
+
};
|
|
62
|
+
};
|
|
63
|
+
outputs: {
|
|
64
|
+
results: MemoryItemWithScore<T>[];
|
|
65
|
+
};
|
|
66
|
+
} | {
|
|
67
|
+
action: 'filter';
|
|
68
|
+
inputs: {
|
|
69
|
+
options?: {
|
|
70
|
+
k?: number;
|
|
71
|
+
userId?: string;
|
|
72
|
+
sessionId?: string;
|
|
73
|
+
filter?: MemoryMetadata;
|
|
74
|
+
sort?: MemorySortOptions;
|
|
75
|
+
};
|
|
76
|
+
};
|
|
77
|
+
outputs: {
|
|
78
|
+
results: MemoryItem<T>[];
|
|
79
|
+
};
|
|
80
|
+
} | {
|
|
81
|
+
action: 'get';
|
|
82
|
+
inputs: {
|
|
83
|
+
memoryId: string;
|
|
84
|
+
};
|
|
85
|
+
outputs: {
|
|
86
|
+
result: MemoryItem<T> | null;
|
|
87
|
+
};
|
|
88
|
+
} | {
|
|
89
|
+
action: 'create';
|
|
90
|
+
inputs: {
|
|
91
|
+
memory: T;
|
|
92
|
+
options?: {
|
|
93
|
+
userId?: string;
|
|
94
|
+
sessionId?: string;
|
|
95
|
+
metadata?: MemoryMetadata;
|
|
96
|
+
};
|
|
97
|
+
};
|
|
98
|
+
outputs: {
|
|
99
|
+
result: MemoryItem<T>;
|
|
100
|
+
};
|
|
101
|
+
} | {
|
|
102
|
+
action: 'update';
|
|
103
|
+
inputs: {
|
|
104
|
+
memoryId: string;
|
|
105
|
+
memory: T;
|
|
106
|
+
};
|
|
107
|
+
outputs: {
|
|
108
|
+
result: MemoryItem<T> | null;
|
|
109
|
+
};
|
|
110
|
+
} | {
|
|
111
|
+
action: 'delete';
|
|
112
|
+
inputs: {
|
|
113
|
+
filter: string | string[] | Record<string, any>;
|
|
114
|
+
};
|
|
115
|
+
outputs: {};
|
|
116
|
+
} | {
|
|
117
|
+
action: 'reset';
|
|
118
|
+
inputs: {};
|
|
119
|
+
outputs: {};
|
|
120
|
+
};
|
|
121
|
+
export interface SortItem {
|
|
122
|
+
field: string;
|
|
123
|
+
direction: 'asc' | 'desc';
|
|
124
|
+
}
|
|
125
|
+
export type MemorySortOptions = SortItem | SortItem[];
|
|
126
|
+
export declare abstract class Memorable<T, C = undefined> extends Runnable<MemoryActions<T>, MemoryActions<T>['outputs']> {
|
|
127
|
+
constructor();
|
|
128
|
+
abstract runner?: MemoryRunner<T, C>;
|
|
129
|
+
abstract add(messages: Extract<MemoryActions<T>, {
|
|
130
|
+
action: 'add';
|
|
131
|
+
}>['inputs']['messages'], options?: Extract<MemoryActions<T>, {
|
|
132
|
+
action: 'add';
|
|
133
|
+
}>['inputs']['options']): Promise<Extract<MemoryActions<T>, {
|
|
134
|
+
action: 'add';
|
|
135
|
+
}>['outputs']>;
|
|
136
|
+
abstract search(query: Extract<MemoryActions<T>, {
|
|
137
|
+
action: 'search';
|
|
138
|
+
}>['inputs']['query'], options?: Extract<MemoryActions<T>, {
|
|
139
|
+
action: 'search';
|
|
140
|
+
}>['inputs']['options']): Promise<Extract<MemoryActions<T>, {
|
|
141
|
+
action: 'search';
|
|
142
|
+
}>['outputs']>;
|
|
143
|
+
abstract filter(options: Extract<MemoryActions<T>, {
|
|
144
|
+
action: 'filter';
|
|
145
|
+
}>['inputs']['options']): Promise<Extract<MemoryActions<T>, {
|
|
146
|
+
action: 'filter';
|
|
147
|
+
}>['outputs']>;
|
|
148
|
+
abstract get(memoryId: Extract<MemoryActions<T>, {
|
|
149
|
+
action: 'get';
|
|
150
|
+
}>['inputs']['memoryId']): Promise<Extract<MemoryActions<T>, {
|
|
151
|
+
action: 'get';
|
|
152
|
+
}>['outputs']>;
|
|
153
|
+
abstract create(memory: Extract<MemoryActions<T>, {
|
|
154
|
+
action: 'create';
|
|
155
|
+
}>['inputs']['memory'], options?: Extract<MemoryActions<T>, {
|
|
156
|
+
action: 'create';
|
|
157
|
+
}>['inputs']['options']): Promise<Extract<MemoryActions<T>, {
|
|
158
|
+
action: 'create';
|
|
159
|
+
}>['outputs']>;
|
|
160
|
+
abstract update(memoryId: Extract<MemoryActions<T>, {
|
|
161
|
+
action: 'update';
|
|
162
|
+
}>['inputs']['memoryId'], memory: T): Promise<Extract<MemoryActions<T>, {
|
|
163
|
+
action: 'update';
|
|
164
|
+
}>['outputs']>;
|
|
165
|
+
abstract delete(memoryId: Extract<MemoryActions<T>, {
|
|
166
|
+
action: 'delete';
|
|
167
|
+
}>['inputs']['filter']): Promise<Extract<MemoryActions<T>, {
|
|
168
|
+
action: 'delete';
|
|
169
|
+
}>['outputs']>;
|
|
170
|
+
abstract reset(): Promise<void>;
|
|
171
|
+
}
|
|
172
|
+
export interface MemoryRunnerInput<C = undefined> {
|
|
173
|
+
messages: MemoryMessage[];
|
|
174
|
+
userId?: string;
|
|
175
|
+
sessionId?: string;
|
|
176
|
+
metadata?: MemoryMetadata;
|
|
177
|
+
filter?: MemoryMetadata;
|
|
178
|
+
customData: C;
|
|
179
|
+
}
|
|
180
|
+
export declare abstract class MemoryRunner<T, C = undefined> extends Runnable<MemoryRunnerInput<C>, MemoryActionItem<T>[]> {
|
|
181
|
+
constructor(name: string);
|
|
182
|
+
}
|
|
183
|
+
export type MemorableSearchOutput<T extends Memorable<any>> = Awaited<ReturnType<T['search']>>['results'];
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import type { Context } from './context';
|
|
2
|
-
import { DataTypeSchema, SchemaMapType } from './data-type-schema';
|
|
2
|
+
import { DataTypeSchema, SchemaMapType } from './definitions/data-type-schema';
|
|
3
3
|
import { RunOptions, Runnable, RunnableDefinition, RunnableOutput, RunnableResponseStream } from './runnable';
|
|
4
4
|
import { OrderedRecord } from './utils/ordered-map';
|
|
5
5
|
export declare class PipelineAgent<I extends {
|
|
6
6
|
[key: string]: any;
|
|
7
7
|
} = {}, O extends {} = {}> extends Runnable<I, O> {
|
|
8
8
|
definition: PipelineAgentDefinition;
|
|
9
|
-
context?: Context | undefined;
|
|
10
9
|
static create<I extends {
|
|
11
10
|
[name: string]: DataTypeSchema;
|
|
12
11
|
}, O extends {
|
|
@@ -15,7 +14,7 @@ export declare class PipelineAgent<I extends {
|
|
|
15
14
|
fromVariablePropPath?: string[];
|
|
16
15
|
};
|
|
17
16
|
}>(options: Parameters<typeof createPipelineAgentDefinition<I, O>>[0]): PipelineAgent<SchemaMapType<I>, SchemaMapType<O>>;
|
|
18
|
-
constructor(definition: PipelineAgentDefinition, context?: Context
|
|
17
|
+
constructor(definition: PipelineAgentDefinition, context?: Context);
|
|
19
18
|
run(input: I, options: RunOptions & {
|
|
20
19
|
stream: true;
|
|
21
20
|
}): Promise<RunnableResponseStream<O>>;
|
package/lib/types/runnable.d.ts
CHANGED
|
@@ -1,12 +1,19 @@
|
|
|
1
|
+
import { Context, ContextState } from './context';
|
|
1
2
|
import { DataType } from './data-type';
|
|
3
|
+
import { Memorable } from './memorable';
|
|
2
4
|
import { OrderedRecord } from './utils/ordered-map';
|
|
3
5
|
export interface RunOptions {
|
|
4
6
|
stream?: boolean;
|
|
5
7
|
}
|
|
6
8
|
export type RunnableResponse<T> = T | RunnableResponseStream<T>;
|
|
7
|
-
export declare abstract class Runnable<I extends {
|
|
9
|
+
export declare abstract class Runnable<I extends {
|
|
10
|
+
[name: string]: any;
|
|
11
|
+
} = {}, O extends {
|
|
12
|
+
[name: string]: any;
|
|
13
|
+
} = {}, State extends ContextState = ContextState> {
|
|
8
14
|
definition: RunnableDefinition;
|
|
9
|
-
|
|
15
|
+
context?: Context<State> | undefined;
|
|
16
|
+
constructor(definition: RunnableDefinition, context?: Context<State> | undefined);
|
|
10
17
|
get id(): string;
|
|
11
18
|
get name(): string | undefined;
|
|
12
19
|
inputs: {
|
|
@@ -28,9 +35,23 @@ export interface RunnableDefinition {
|
|
|
28
35
|
type: string;
|
|
29
36
|
name?: string;
|
|
30
37
|
description?: string;
|
|
38
|
+
memories?: OrderedRecord<RunnableMemory>;
|
|
31
39
|
inputs: OrderedRecord<RunnableInput>;
|
|
32
40
|
outputs: OrderedRecord<RunnableOutput>;
|
|
33
41
|
}
|
|
42
|
+
export interface RunnableMemory {
|
|
43
|
+
id: string;
|
|
44
|
+
name?: string;
|
|
45
|
+
memory?: Memorable<any>;
|
|
46
|
+
query?: {
|
|
47
|
+
from: 'variable';
|
|
48
|
+
fromVariableId?: string;
|
|
49
|
+
fromVariablePropPath?: string[];
|
|
50
|
+
};
|
|
51
|
+
options?: {
|
|
52
|
+
k?: number;
|
|
53
|
+
};
|
|
54
|
+
}
|
|
34
55
|
export type RunnableInput = DataType;
|
|
35
56
|
export type RunnableOutput = DataType;
|
|
36
57
|
export interface RunnableResponseDelta<T> {
|