@aigne/core 0.4.205 → 0.4.206-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/lib/cjs/agent.js +27 -1
- package/lib/cjs/data-type-schema.js +46 -0
- package/lib/cjs/definitions/data-type-schema.js +2 -2
- package/lib/cjs/definitions/data-type.js +2 -0
- package/lib/cjs/function-agent.js +34 -29
- package/lib/cjs/function-runner.js +6 -4
- package/lib/cjs/index.js +1 -1
- package/lib/cjs/llm-agent.js +22 -54
- package/lib/cjs/llm-decision-agent.js +8 -12
- package/lib/cjs/llm-model.js +2 -2
- package/lib/cjs/local-function-agent.js +7 -21
- package/lib/cjs/memory.js +32 -0
- package/lib/cjs/pipeline-agent.js +9 -19
- package/lib/cjs/runnable.js +1 -0
- package/lib/cjs/tsconfig.tsbuildinfo +1 -1
- package/lib/cjs/utils/index.js +5 -2
- package/lib/cjs/utils/stream-utils.js +35 -13
- package/lib/esm/agent.js +29 -3
- package/lib/esm/data-type-schema.js +43 -0
- package/lib/esm/definitions/data-type-schema.js +2 -2
- package/lib/esm/definitions/data-type.js +1 -0
- package/lib/esm/function-agent.js +33 -28
- package/lib/esm/function-runner.js +6 -4
- package/lib/esm/index.js +1 -1
- package/lib/esm/llm-agent.js +22 -53
- package/lib/esm/llm-decision-agent.js +8 -11
- package/lib/esm/llm-model.js +2 -2
- package/lib/esm/local-function-agent.js +7 -20
- package/lib/esm/memory.js +27 -0
- package/lib/esm/pipeline-agent.js +9 -18
- package/lib/esm/runnable.js +1 -0
- package/lib/esm/tsconfig.tsbuildinfo +1 -1
- package/lib/esm/utils/index.js +5 -2
- package/lib/esm/utils/stream-utils.js +33 -13
- package/lib/types/agent.d.ts +8 -9
- package/lib/types/context.d.ts +2 -0
- package/lib/types/data-type-schema.d.ts +46 -0
- package/lib/types/definitions/data-type-schema.d.ts +7 -5
- package/lib/types/definitions/data-type.d.ts +32 -0
- package/lib/types/function-agent.d.ts +33 -20
- package/lib/types/function-runner.d.ts +20 -7
- package/lib/types/index.d.ts +1 -1
- package/lib/types/llm-agent.d.ts +27 -30
- package/lib/types/llm-decision-agent.d.ts +15 -22
- package/lib/types/llm-model.d.ts +2 -2
- package/lib/types/local-function-agent.d.ts +31 -34
- package/lib/types/memory.d.ts +184 -0
- package/lib/types/pipeline-agent.d.ts +21 -55
- package/lib/types/runnable.d.ts +1 -1
- package/lib/types/tsconfig.tsbuildinfo +1 -1
- package/lib/types/utils/index.d.ts +5 -2
- package/lib/types/utils/stream-utils.d.ts +5 -3
- package/lib/types/utils/union.d.ts +1 -2
- package/package.json +3 -2
|
@@ -0,0 +1,184 @@
|
|
|
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
|
+
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { Agent, AgentProcessOptions } from './agent';
|
|
2
|
-
import type { Context } from './context';
|
|
3
|
-
import { DataTypeSchema,
|
|
2
|
+
import type { Context, ContextState } from './context';
|
|
3
|
+
import { DataTypeSchema, SchemaMapType } from './definitions/data-type-schema';
|
|
4
4
|
import { CreateRunnableMemory } from './definitions/memory';
|
|
5
5
|
import { MemorableSearchOutput, MemoryItemWithScore } from './memorable';
|
|
6
|
-
import { Runnable, RunnableDefinition, RunnableOutput,
|
|
6
|
+
import { Runnable, RunnableDefinition, RunnableOutput, RunnableResponseDelta } from './runnable';
|
|
7
7
|
import { MakeNullablePropertyOptional } from './utils/nullable';
|
|
8
8
|
import { OrderedRecord } from './utils/ordered-map';
|
|
9
9
|
import { ExtractRunnableInputType } from './utils/runnable-type';
|
|
@@ -13,50 +13,25 @@ export declare class PipelineAgent<I extends {
|
|
|
13
13
|
[name: string]: any;
|
|
14
14
|
} = {}, Memories extends {
|
|
15
15
|
[name: string]: MemoryItemWithScore[];
|
|
16
|
-
} = {}> extends Agent<I, O, Memories> {
|
|
16
|
+
} = {}, State extends ContextState = ContextState> extends Agent<I, O, Memories, State> {
|
|
17
17
|
definition: PipelineAgentDefinition;
|
|
18
|
-
static create
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
[name: string]: DataTypeSchema & {
|
|
22
|
-
fromVariable: string;
|
|
23
|
-
fromVariablePropPath?: string[];
|
|
24
|
-
};
|
|
25
|
-
}, Memories extends {
|
|
26
|
-
[name: string]: CreateRunnableMemory<I>;
|
|
27
|
-
}, Processes extends {
|
|
28
|
-
[name: string]: PipelineAgentProcessParameter<I>;
|
|
29
|
-
}>(options: Parameters<typeof createPipelineAgentDefinition<I, O, Memories, Processes>>[0]): PipelineAgent<SchemaMapType<I>, SchemaMapType<O>, {
|
|
30
|
-
[name in keyof Memories]: MemorableSearchOutput<Memories[name]['memory']>;
|
|
31
|
-
}>;
|
|
32
|
-
constructor(definition: PipelineAgentDefinition, context?: Context);
|
|
33
|
-
process(input: I, options: AgentProcessOptions<Memories> & {
|
|
34
|
-
stream: true;
|
|
35
|
-
}): Promise<RunnableResponseStream<O>>;
|
|
36
|
-
process(input: I, options: AgentProcessOptions<Memories> & {
|
|
37
|
-
stream?: false;
|
|
38
|
-
}): Promise<O>;
|
|
18
|
+
static create: typeof create;
|
|
19
|
+
constructor(definition: PipelineAgentDefinition, context?: Context<State>);
|
|
20
|
+
process(input: I, options: AgentProcessOptions<Memories>): Promise<ReadableStream<RunnableResponseDelta<O>>>;
|
|
39
21
|
}
|
|
40
|
-
type VariableWithPropPath
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
fromVariable: Var;
|
|
44
|
-
fromVariablePropPath?: VariablePaths<Vars, Var>;
|
|
22
|
+
type VariableWithPropPath = {
|
|
23
|
+
fromVariable: string;
|
|
24
|
+
fromVariablePropPath?: (string | number)[];
|
|
45
25
|
};
|
|
46
|
-
type
|
|
47
|
-
[name: string]: DataTypeSchema;
|
|
48
|
-
}, Var extends keyof Vars = keyof Vars> = Vars[Var] extends DataTypeSchemaObject ? Array<keyof Vars[Var]['properties']> : never;
|
|
49
|
-
export type PipelineAgentProcessParameter<I extends {
|
|
50
|
-
[name: string]: DataTypeSchema;
|
|
51
|
-
}, R extends Runnable = any, RI extends {
|
|
26
|
+
export type PipelineAgentProcessParameter<R extends Runnable = any, RI extends {
|
|
52
27
|
[name: string]: DataTypeSchema;
|
|
53
28
|
} = ExtractRunnableInputType<R>> = {
|
|
54
29
|
runnable: R;
|
|
55
30
|
input: MakeNullablePropertyOptional<{
|
|
56
|
-
[key in keyof RI]: VariableWithPropPath
|
|
31
|
+
[key in keyof RI]: VariableWithPropPath;
|
|
57
32
|
}>;
|
|
58
33
|
};
|
|
59
|
-
|
|
34
|
+
declare function create<I extends {
|
|
60
35
|
[name: string]: DataTypeSchema;
|
|
61
36
|
}, O extends {
|
|
62
37
|
[name: string]: DataTypeSchema & {
|
|
@@ -65,27 +40,18 @@ export interface CreatePipelineAgentOptions<I extends {
|
|
|
65
40
|
};
|
|
66
41
|
}, Memories extends {
|
|
67
42
|
[name: string]: CreateRunnableMemory<I>;
|
|
68
|
-
}, Processes extends {
|
|
69
|
-
[name: string]: PipelineAgentProcessParameter
|
|
70
|
-
}> {
|
|
43
|
+
}, State extends ContextState, Processes extends {
|
|
44
|
+
[name: string]: PipelineAgentProcessParameter;
|
|
45
|
+
}>({ context, ...options }: {
|
|
46
|
+
context: Context<State>;
|
|
71
47
|
name?: string;
|
|
72
48
|
inputs: I;
|
|
73
49
|
outputs: O;
|
|
74
|
-
memories
|
|
50
|
+
memories?: Memories;
|
|
75
51
|
processes: Processes;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
}, O extends {
|
|
80
|
-
[name: string]: DataTypeSchema & {
|
|
81
|
-
fromVariable: string;
|
|
82
|
-
fromVariablePropPath?: string[];
|
|
83
|
-
};
|
|
84
|
-
}, Memories extends {
|
|
85
|
-
[name: string]: CreateRunnableMemory<I>;
|
|
86
|
-
}, Processes extends {
|
|
87
|
-
[name: string]: PipelineAgentProcessParameter<I>;
|
|
88
|
-
}>(options: CreatePipelineAgentOptions<I, O, Memories, Processes>): PipelineAgentDefinition;
|
|
52
|
+
}): PipelineAgent<SchemaMapType<I>, SchemaMapType<O>, {
|
|
53
|
+
[name in keyof Memories]: MemorableSearchOutput<Memories[name]['memory']>;
|
|
54
|
+
}, State>;
|
|
89
55
|
export interface PipelineAgentDefinition extends RunnableDefinition {
|
|
90
56
|
type: 'pipeline_agent';
|
|
91
57
|
processes?: OrderedRecord<PipelineAgentProcess>;
|
package/lib/types/runnable.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Context, ContextState } from './context';
|
|
2
|
-
import type { DataType } from './data-type';
|
|
2
|
+
import type { DataType } from './definitions/data-type';
|
|
3
3
|
import type { Memorable } from './memorable';
|
|
4
4
|
import { OrderedRecord } from './utils/ordered-map';
|
|
5
5
|
export interface RunOptions {
|