@aigne/core 1.0.9 → 1.0.11
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.d.ts +70 -16
- package/lib/cjs/agent.js +68 -16
- package/lib/cjs/context.d.ts +1 -1
- package/lib/cjs/definitions/data-schema.d.ts +61 -0
- package/lib/cjs/definitions/memory.d.ts +18 -5
- package/lib/cjs/definitions/open-api.d.ts +3 -3
- package/lib/cjs/definitions/preload.d.ts +43 -0
- package/lib/cjs/definitions/preload.js +34 -0
- package/lib/cjs/function-agent.d.ts +15 -56
- package/lib/cjs/function-agent.js +9 -6
- package/lib/cjs/index.d.ts +1 -1
- package/lib/cjs/index.js +1 -1
- package/lib/cjs/llm-agent.d.ts +17 -60
- package/lib/cjs/llm-agent.js +8 -5
- package/lib/cjs/llm-decision-agent.d.ts +31 -51
- package/lib/cjs/llm-decision-agent.js +30 -13
- package/lib/cjs/llm-model.d.ts +4 -4
- package/lib/cjs/llm-models/openai-llm-model.d.ts +4 -1
- package/lib/cjs/llm-models/openai-llm-model.js +14 -14
- package/lib/cjs/memorable.d.ts +21 -13
- package/lib/cjs/memorable.js +2 -2
- package/lib/cjs/open-api-agent.d.ts +9 -38
- package/lib/cjs/open-api-agent.js +12 -6
- package/lib/cjs/pipeline-agent.d.ts +14 -37
- package/lib/cjs/pipeline-agent.js +10 -10
- package/lib/cjs/runnable.d.ts +7 -24
- package/lib/cjs/sandbox-function-agent.d.ts +10 -38
- package/lib/cjs/sandbox-function-agent.js +9 -5
- package/lib/cjs/sandbox-function-runner.d.ts +8 -17
- package/lib/cjs/sandbox-function-runner.js +1 -0
- package/lib/cjs/utils/index.d.ts +1 -0
- package/lib/cjs/utils/index.js +1 -0
- package/lib/cjs/utils/logger.d.ts +3 -0
- package/lib/cjs/utils/logger.js +17 -0
- package/lib/cjs/utils/message-utils.d.ts +1 -1
- package/lib/cjs/utils/message-utils.js +1 -4
- package/lib/cjs/utils/open-api-parameter.js +3 -6
- package/lib/cjs/utils/runnable-type.d.ts +5 -3
- package/lib/cjs/utils/structured-output-schema.d.ts +2 -2
- package/lib/cjs/utils/type-utils.d.ts +1 -0
- package/lib/cjs/{logger.js → utils/type-utils.js} +0 -2
- package/lib/dts/agent.d.ts +70 -16
- package/lib/dts/context.d.ts +1 -1
- package/lib/dts/definitions/data-schema.d.ts +61 -0
- package/lib/dts/definitions/memory.d.ts +18 -5
- package/lib/dts/definitions/open-api.d.ts +3 -3
- package/lib/dts/definitions/preload.d.ts +43 -0
- package/lib/dts/function-agent.d.ts +15 -56
- package/lib/dts/index.d.ts +1 -1
- package/lib/dts/llm-agent.d.ts +17 -60
- package/lib/dts/llm-decision-agent.d.ts +31 -51
- package/lib/dts/llm-model.d.ts +4 -4
- package/lib/dts/llm-models/openai-llm-model.d.ts +4 -1
- package/lib/dts/memorable.d.ts +21 -13
- package/lib/dts/open-api-agent.d.ts +9 -38
- package/lib/dts/pipeline-agent.d.ts +14 -37
- package/lib/dts/runnable.d.ts +7 -24
- package/lib/dts/sandbox-function-agent.d.ts +10 -38
- package/lib/dts/sandbox-function-runner.d.ts +8 -17
- package/lib/dts/utils/index.d.ts +1 -0
- package/lib/dts/utils/logger.d.ts +3 -0
- package/lib/dts/utils/message-utils.d.ts +1 -1
- package/lib/dts/utils/runnable-type.d.ts +5 -3
- package/lib/dts/utils/structured-output-schema.d.ts +2 -2
- package/lib/dts/utils/type-utils.d.ts +1 -0
- package/lib/esm/agent.d.ts +70 -16
- package/lib/esm/agent.js +64 -9
- package/lib/esm/context.d.ts +1 -1
- package/lib/esm/definitions/data-schema.d.ts +61 -0
- package/lib/esm/definitions/memory.d.ts +18 -5
- package/lib/esm/definitions/open-api.d.ts +3 -3
- package/lib/esm/definitions/preload.d.ts +43 -0
- package/lib/esm/definitions/preload.js +31 -0
- package/lib/esm/function-agent.d.ts +15 -56
- package/lib/esm/function-agent.js +9 -6
- package/lib/esm/index.d.ts +1 -1
- package/lib/esm/index.js +1 -1
- package/lib/esm/llm-agent.d.ts +17 -60
- package/lib/esm/llm-agent.js +8 -5
- package/lib/esm/llm-decision-agent.d.ts +31 -51
- package/lib/esm/llm-decision-agent.js +32 -15
- package/lib/esm/llm-model.d.ts +4 -4
- package/lib/esm/llm-models/openai-llm-model.d.ts +4 -1
- package/lib/esm/llm-models/openai-llm-model.js +14 -14
- package/lib/esm/memorable.d.ts +21 -13
- package/lib/esm/memorable.js +2 -2
- package/lib/esm/open-api-agent.d.ts +9 -38
- package/lib/esm/open-api-agent.js +11 -5
- package/lib/esm/pipeline-agent.d.ts +14 -37
- package/lib/esm/pipeline-agent.js +9 -6
- package/lib/esm/runnable.d.ts +7 -24
- package/lib/esm/sandbox-function-agent.d.ts +10 -38
- package/lib/esm/sandbox-function-agent.js +9 -5
- package/lib/esm/sandbox-function-runner.d.ts +8 -17
- package/lib/esm/sandbox-function-runner.js +2 -1
- package/lib/esm/utils/index.d.ts +1 -0
- package/lib/esm/utils/index.js +1 -0
- package/lib/esm/utils/logger.d.ts +3 -0
- package/lib/esm/utils/logger.js +14 -0
- package/lib/esm/utils/message-utils.d.ts +1 -1
- package/lib/esm/utils/message-utils.js +1 -4
- package/lib/esm/utils/open-api-parameter.js +1 -1
- package/lib/esm/utils/runnable-type.d.ts +5 -3
- package/lib/esm/utils/structured-output-schema.d.ts +2 -2
- package/lib/esm/utils/type-utils.d.ts +1 -0
- package/lib/esm/utils/type-utils.js +1 -0
- package/package.json +4 -4
- package/lib/cjs/definitions/data-type-schema.d.ts +0 -42
- package/lib/cjs/logger.d.ts +0 -2
- package/lib/dts/definitions/data-type-schema.d.ts +0 -42
- package/lib/dts/logger.d.ts +0 -2
- package/lib/esm/definitions/data-type-schema.d.ts +0 -42
- package/lib/esm/logger.d.ts +0 -2
- package/lib/esm/logger.js +0 -2
- /package/lib/cjs/definitions/{data-type-schema.js → data-schema.js} +0 -0
- /package/lib/esm/definitions/{data-type-schema.js → data-schema.js} +0 -0
|
@@ -1,63 +1,40 @@
|
|
|
1
|
-
import { Agent, type AgentProcessOptions } from "./agent";
|
|
1
|
+
import { Agent, type AgentDefinition, type AgentMemories, type AgentPreloads, type AgentProcessInput, type AgentProcessOptions, type CreateAgentInputSchema, type CreateAgentMemoriesSchema, type CreateAgentMemoriesType, type CreateAgentOptions, type CreateAgentOutputSchema, type CreateAgentPreloadsSchema, type CreateAgentPreloadsType } from "./agent";
|
|
2
2
|
import type { Context, ContextState } from "./context";
|
|
3
|
-
import { type
|
|
4
|
-
import {
|
|
5
|
-
import type { MemorableSearchOutput, MemoryItemWithScore } from "./memorable";
|
|
6
|
-
import type { Runnable, RunnableDefinition, RunnableOutput, RunnableResponseDelta } from "./runnable";
|
|
3
|
+
import { type SchemaToType } from "./definitions/data-schema";
|
|
4
|
+
import type { Runnable, RunnableInput, RunnableOutput, RunnableOutputType, RunnableResponseDelta } from "./runnable";
|
|
7
5
|
import type { MakeNullablePropertyOptional } from "./utils/nullable";
|
|
8
6
|
import { OrderedRecord } from "./utils/ordered-map";
|
|
9
7
|
import type { ExtractRunnableInputType } from "./utils/runnable-type";
|
|
10
|
-
export declare class PipelineAgent<I extends {
|
|
11
|
-
[key: string]: any;
|
|
12
|
-
} = {}, O extends {
|
|
13
|
-
[name: string]: any;
|
|
14
|
-
} = {}, Memories extends {
|
|
15
|
-
[name: string]: MemoryItemWithScore[];
|
|
16
|
-
} = {}, State extends ContextState = ContextState> extends Agent<I, O, Memories, State> {
|
|
8
|
+
export declare class PipelineAgent<I extends RunnableInput = RunnableInput, O extends RunnableOutput = RunnableOutput, State extends ContextState = ContextState, Preloads extends AgentPreloads = AgentPreloads, Memories extends AgentMemories = AgentMemories> extends Agent<I, O, State, AgentPreloads, Memories> {
|
|
17
9
|
definition: PipelineAgentDefinition;
|
|
18
10
|
static create: typeof create;
|
|
19
11
|
constructor(definition: PipelineAgentDefinition, context?: Context<State>);
|
|
20
|
-
process(input: I, options: AgentProcessOptions<Memories>): Promise<import("stream/web").ReadableStream<RunnableResponseDelta<O>>>;
|
|
12
|
+
process(input: AgentProcessInput<I, Preloads, Memories>, options: AgentProcessOptions<Preloads, Memories>): Promise<import("stream/web").ReadableStream<RunnableResponseDelta<O>>>;
|
|
21
13
|
}
|
|
22
14
|
type VariableWithPropPath = {
|
|
23
15
|
fromVariable: string;
|
|
24
16
|
fromVariablePropPath?: (string | number)[];
|
|
25
17
|
};
|
|
26
|
-
export type PipelineAgentProcessParameter<R extends Runnable =
|
|
27
|
-
[name: string]: DataTypeSchema;
|
|
28
|
-
} = ExtractRunnableInputType<R>> = {
|
|
18
|
+
export type PipelineAgentProcessParameter<R extends Runnable = Runnable, RI extends RunnableInput = ExtractRunnableInputType<R>> = {
|
|
29
19
|
runnable: R;
|
|
30
20
|
input: MakeNullablePropertyOptional<{
|
|
31
21
|
[key in keyof RI]: VariableWithPropPath;
|
|
32
22
|
}>;
|
|
33
23
|
};
|
|
34
|
-
declare function create<I extends {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
fromVariable: string;
|
|
39
|
-
fromVariablePropPath?: string[];
|
|
40
|
-
};
|
|
41
|
-
}, Memories extends {
|
|
42
|
-
[name: string]: CreateRunnableMemory<I>;
|
|
43
|
-
}, State extends ContextState, Processes extends {
|
|
24
|
+
declare function create<I extends CreateAgentInputSchema, O extends CreateAgentOutputSchema<{
|
|
25
|
+
fromVariable: string;
|
|
26
|
+
fromVariablePropPath?: string[];
|
|
27
|
+
}>, State extends ContextState, Preloads extends CreateAgentPreloadsSchema<I>, Memories extends CreateAgentMemoriesSchema<I>, Processes extends {
|
|
44
28
|
[name: string]: PipelineAgentProcessParameter;
|
|
45
|
-
}>(
|
|
46
|
-
context: Context<State>;
|
|
47
|
-
name?: string;
|
|
48
|
-
inputs: I;
|
|
49
|
-
outputs: O;
|
|
50
|
-
memories?: Memories;
|
|
29
|
+
}>(options: CreateAgentOptions<I, O, State, Preloads, Memories> & {
|
|
51
30
|
processes: Processes;
|
|
52
|
-
}): PipelineAgent<
|
|
53
|
-
|
|
54
|
-
}, State>;
|
|
55
|
-
export interface PipelineAgentDefinition extends RunnableDefinition {
|
|
31
|
+
}): PipelineAgent<SchemaToType<I>, SchemaToType<O>, State, CreateAgentPreloadsType<I, Preloads>, CreateAgentMemoriesType<I, Memories>>;
|
|
32
|
+
export interface PipelineAgentDefinition extends AgentDefinition {
|
|
56
33
|
type: "pipeline_agent";
|
|
57
34
|
processes?: OrderedRecord<PipelineAgentProcess>;
|
|
58
35
|
outputs: OrderedRecord<PipelineAgentOutput>;
|
|
59
36
|
}
|
|
60
|
-
export type PipelineAgentOutput =
|
|
37
|
+
export type PipelineAgentOutput = RunnableOutputType & {
|
|
61
38
|
from: "variable";
|
|
62
39
|
fromVariableId?: string;
|
|
63
40
|
fromVariablePropPath?: (string | number)[];
|
|
@@ -11,9 +11,6 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
11
11
|
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
12
|
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
13
|
};
|
|
14
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
15
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
16
|
-
};
|
|
17
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
15
|
exports.PipelineAgent = void 0;
|
|
19
16
|
const lodash_1 = require("lodash");
|
|
@@ -21,10 +18,11 @@ const nanoid_1 = require("nanoid");
|
|
|
21
18
|
const tsyringe_1 = require("tsyringe");
|
|
22
19
|
const agent_1 = require("./agent");
|
|
23
20
|
const constants_1 = require("./constants");
|
|
24
|
-
const
|
|
21
|
+
const data_schema_1 = require("./definitions/data-schema");
|
|
25
22
|
const memory_1 = require("./definitions/memory");
|
|
26
|
-
const
|
|
23
|
+
const preload_1 = require("./definitions/preload");
|
|
27
24
|
const is_non_nullable_1 = require("./utils/is-non-nullable");
|
|
25
|
+
const logger_1 = require("./utils/logger");
|
|
28
26
|
const ordered_map_1 = require("./utils/ordered-map");
|
|
29
27
|
let PipelineAgent = class PipelineAgent extends agent_1.Agent {
|
|
30
28
|
definition;
|
|
@@ -59,7 +57,7 @@ let PipelineAgent = class PipelineAgent extends agent_1.Agent {
|
|
|
59
57
|
let result = {};
|
|
60
58
|
for (const process of ordered_map_1.OrderedRecord.iterator(processes)) {
|
|
61
59
|
if (!process.runnable?.id) {
|
|
62
|
-
logger_1.
|
|
60
|
+
logger_1.logger.warn("Runnable id is required for process", process);
|
|
63
61
|
continue;
|
|
64
62
|
}
|
|
65
63
|
const runnable = await context.resolve(process.runnable.id);
|
|
@@ -144,9 +142,10 @@ exports.PipelineAgent = PipelineAgent = __decorate([
|
|
|
144
142
|
__param(1, (0, tsyringe_1.inject)(constants_1.TYPES.context)),
|
|
145
143
|
__metadata("design:paramtypes", [Object, Object])
|
|
146
144
|
], PipelineAgent);
|
|
147
|
-
function create(
|
|
145
|
+
function create(options) {
|
|
148
146
|
const agentId = options.name || (0, nanoid_1.nanoid)();
|
|
149
|
-
const inputs = (0,
|
|
147
|
+
const inputs = (0, data_schema_1.schemaToDataType)(options.inputs);
|
|
148
|
+
const preloads = (0, preload_1.preloadCreatorsToPreloads)(inputs, options.preloads);
|
|
150
149
|
const memories = (0, memory_1.toRunnableMemories)(agentId, inputs, options.memories || {});
|
|
151
150
|
const processes = ordered_map_1.OrderedRecord.fromArray([]);
|
|
152
151
|
for (const [name, p] of Object.entries(options.processes)) {
|
|
@@ -178,7 +177,7 @@ function create({ context, ...options }) {
|
|
|
178
177
|
}).filter(is_non_nullable_1.isNonNullable)),
|
|
179
178
|
});
|
|
180
179
|
}
|
|
181
|
-
const outputs = ordered_map_1.OrderedRecord.fromArray(ordered_map_1.OrderedRecord.map((0,
|
|
180
|
+
const outputs = ordered_map_1.OrderedRecord.fromArray(ordered_map_1.OrderedRecord.map((0, data_schema_1.schemaToDataType)(options.outputs), (output) => {
|
|
182
181
|
const { fromVariable, fromVariablePropPath } = options.outputs[output.name];
|
|
183
182
|
const from = ordered_map_1.OrderedRecord.find(inputs, (i) => i.name === fromVariable) ||
|
|
184
183
|
ordered_map_1.OrderedRecord.find(processes, (p) => p.name === fromVariable);
|
|
@@ -196,8 +195,9 @@ function create({ context, ...options }) {
|
|
|
196
195
|
name: options.name,
|
|
197
196
|
type: "pipeline_agent",
|
|
198
197
|
inputs,
|
|
198
|
+
preloads,
|
|
199
199
|
memories,
|
|
200
200
|
outputs,
|
|
201
201
|
processes,
|
|
202
|
-
}, context);
|
|
202
|
+
}, options.context);
|
|
203
203
|
}
|
package/lib/cjs/runnable.d.ts
CHANGED
|
@@ -1,16 +1,13 @@
|
|
|
1
1
|
import type { Context, ContextState } from "./context";
|
|
2
2
|
import type { DataType } from "./definitions/data-type";
|
|
3
|
-
import type { Memorable } from "./memorable";
|
|
4
3
|
import { OrderedRecord } from "./utils/ordered-map";
|
|
5
4
|
export interface RunOptions {
|
|
6
5
|
stream?: boolean;
|
|
7
6
|
}
|
|
8
7
|
export type RunnableResponse<T> = T | RunnableResponseStream<T>;
|
|
9
|
-
export
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
[name: string]: any;
|
|
13
|
-
} = {}, State extends ContextState = ContextState> {
|
|
8
|
+
export type RunnableInput = Record<string, any>;
|
|
9
|
+
export type RunnableOutput = Record<string, any>;
|
|
10
|
+
export declare abstract class Runnable<I extends RunnableInput = RunnableInput, O extends RunnableOutput = RunnableOutput, State extends ContextState = ContextState> {
|
|
14
11
|
definition: RunnableDefinition;
|
|
15
12
|
context?: Context<State> | undefined;
|
|
16
13
|
constructor(definition: RunnableDefinition, context?: Context<State> | undefined);
|
|
@@ -35,25 +32,11 @@ export interface RunnableDefinition {
|
|
|
35
32
|
type: string;
|
|
36
33
|
name?: string;
|
|
37
34
|
description?: string;
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
outputs: OrderedRecord<RunnableOutput>;
|
|
35
|
+
inputs: OrderedRecord<RunnableInputType>;
|
|
36
|
+
outputs: OrderedRecord<RunnableOutputType>;
|
|
41
37
|
}
|
|
42
|
-
export
|
|
43
|
-
|
|
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
|
-
}
|
|
55
|
-
export type RunnableInput = DataType;
|
|
56
|
-
export type RunnableOutput = DataType;
|
|
38
|
+
export type RunnableInputType = DataType;
|
|
39
|
+
export type RunnableOutputType = DataType;
|
|
57
40
|
export interface RunnableResponseDelta<T> {
|
|
58
41
|
$text?: string;
|
|
59
42
|
delta?: Partial<T>;
|
|
@@ -1,48 +1,20 @@
|
|
|
1
|
-
import { Agent, type AgentProcessOptions } from "./agent";
|
|
1
|
+
import { Agent, type AgentDefinition, type AgentMemories, type AgentPreloads, type AgentProcessInput, type AgentProcessOptions, type CreateAgentInputSchema, type CreateAgentMemoriesSchema, type CreateAgentMemoriesType, type CreateAgentOptions, type CreateAgentOutputSchema, type CreateAgentPreloadsSchema, type CreateAgentPreloadsType } from "./agent";
|
|
2
2
|
import type { Context, ContextState } from "./context";
|
|
3
|
-
import { type
|
|
4
|
-
import {
|
|
5
|
-
import type { MemorableSearchOutput, MemoryItemWithScore } from "./memorable";
|
|
6
|
-
import type { RunnableDefinition } from "./runnable";
|
|
3
|
+
import { type SchemaToType } from "./definitions/data-schema";
|
|
4
|
+
import type { RunnableInput, RunnableOutput } from "./runnable";
|
|
7
5
|
import type { SandboxFunctionRunner } from "./sandbox-function-runner";
|
|
8
|
-
export declare class SandboxFunctionAgent<I extends {
|
|
9
|
-
[name: string]: any;
|
|
10
|
-
} = {}, O extends {
|
|
11
|
-
[name: string]: any;
|
|
12
|
-
} = {}, Memories extends {
|
|
13
|
-
[name: string]: MemoryItemWithScore[];
|
|
14
|
-
} = {}, State extends ContextState = ContextState> extends Agent<I, O, Memories, State> {
|
|
6
|
+
export declare class SandboxFunctionAgent<I extends RunnableInput = RunnableInput, O extends RunnableOutput = RunnableOutput, State extends ContextState = ContextState, Preloads extends AgentPreloads = AgentPreloads, Memories extends AgentMemories = AgentMemories> extends Agent<I, O, State, Preloads, Memories> {
|
|
15
7
|
definition: SandboxFunctionAgentDefinition;
|
|
16
|
-
runner?: SandboxFunctionRunner<I, O,
|
|
8
|
+
runner?: SandboxFunctionRunner<I, O, State, Preloads, Memories> | undefined;
|
|
17
9
|
static create: typeof create;
|
|
18
|
-
constructor(definition: SandboxFunctionAgentDefinition, context?: Context<State>, runner?: SandboxFunctionRunner<I, O,
|
|
19
|
-
process(input: I, options: AgentProcessOptions<Memories>): Promise<import("./runnable").RunnableResponseStream<O>>;
|
|
10
|
+
constructor(definition: SandboxFunctionAgentDefinition, context?: Context<State>, runner?: SandboxFunctionRunner<I, O, State, Preloads, Memories> | undefined);
|
|
11
|
+
process(input: AgentProcessInput<I, Preloads, Memories>, options: AgentProcessOptions<Preloads, Memories>): Promise<import("./runnable").RunnableResponseStream<O>>;
|
|
20
12
|
}
|
|
21
|
-
export
|
|
22
|
-
[name: string]: DataTypeSchema;
|
|
23
|
-
}, O extends {
|
|
24
|
-
[name: string]: DataTypeSchema;
|
|
25
|
-
}, Memories extends {
|
|
26
|
-
[name: string]: CreateRunnableMemory<I>;
|
|
27
|
-
}, State extends ContextState> {
|
|
28
|
-
context?: Context<State>;
|
|
29
|
-
name?: string;
|
|
30
|
-
inputs: I;
|
|
31
|
-
outputs: O;
|
|
32
|
-
memories?: Memories;
|
|
13
|
+
export declare function create<I extends CreateAgentInputSchema, O extends CreateAgentOutputSchema, State extends ContextState, Preloads extends CreateAgentPreloadsSchema<I>, Memories extends CreateAgentMemoriesSchema<I>>(options: CreateAgentOptions<I, O, State, Preloads, Memories> & {
|
|
33
14
|
language?: string;
|
|
34
15
|
code: string;
|
|
35
|
-
}
|
|
36
|
-
export
|
|
37
|
-
[name: string]: DataTypeSchema;
|
|
38
|
-
}, O extends {
|
|
39
|
-
[name: string]: DataTypeSchema;
|
|
40
|
-
}, Memories extends {
|
|
41
|
-
[name: string]: CreateRunnableMemory<I>;
|
|
42
|
-
}, State extends ContextState>({ context, ...options }: CreateSandboxFunctionAgentOptions<I, O, Memories, State>): SandboxFunctionAgent<SchemaMapType<I>, SchemaMapType<O>, {
|
|
43
|
-
[name in keyof Memories]: MemorableSearchOutput<Memories[name]["memory"]>;
|
|
44
|
-
}, State>;
|
|
45
|
-
export interface SandboxFunctionAgentDefinition extends RunnableDefinition {
|
|
16
|
+
}): SandboxFunctionAgent<SchemaToType<I>, SchemaToType<O>, State, CreateAgentPreloadsType<I, Preloads>, CreateAgentMemoriesType<I, Memories>>;
|
|
17
|
+
export interface SandboxFunctionAgentDefinition extends AgentDefinition {
|
|
46
18
|
type: "sandbox_function_agent";
|
|
47
19
|
language?: string;
|
|
48
20
|
code?: string;
|
|
@@ -18,8 +18,9 @@ const nanoid_1 = require("nanoid");
|
|
|
18
18
|
const tsyringe_1 = require("tsyringe");
|
|
19
19
|
const agent_1 = require("./agent");
|
|
20
20
|
const constants_1 = require("./constants");
|
|
21
|
-
const
|
|
21
|
+
const data_schema_1 = require("./definitions/data-schema");
|
|
22
22
|
const memory_1 = require("./definitions/memory");
|
|
23
|
+
const preload_1 = require("./definitions/preload");
|
|
23
24
|
let SandboxFunctionAgent = class SandboxFunctionAgent extends agent_1.Agent {
|
|
24
25
|
definition;
|
|
25
26
|
runner;
|
|
@@ -43,6 +44,7 @@ let SandboxFunctionAgent = class SandboxFunctionAgent extends agent_1.Agent {
|
|
|
43
44
|
language,
|
|
44
45
|
code,
|
|
45
46
|
input,
|
|
47
|
+
preloads: options.preloads,
|
|
46
48
|
memories: options.memories,
|
|
47
49
|
context: { state: context.state },
|
|
48
50
|
}, { stream: true });
|
|
@@ -56,10 +58,11 @@ exports.SandboxFunctionAgent = SandboxFunctionAgent = __decorate([
|
|
|
56
58
|
__param(2, (0, tsyringe_1.inject)(constants_1.TYPES.sandboxFunctionRunner)),
|
|
57
59
|
__metadata("design:paramtypes", [Object, Object, Function])
|
|
58
60
|
], SandboxFunctionAgent);
|
|
59
|
-
function create(
|
|
61
|
+
function create(options) {
|
|
60
62
|
const agentId = options.name || (0, nanoid_1.nanoid)();
|
|
61
|
-
const inputs = (0,
|
|
62
|
-
const outputs = (0,
|
|
63
|
+
const inputs = (0, data_schema_1.schemaToDataType)(options.inputs);
|
|
64
|
+
const outputs = (0, data_schema_1.schemaToDataType)(options.outputs);
|
|
65
|
+
const preloads = (0, preload_1.preloadCreatorsToPreloads)(inputs, options.preloads);
|
|
63
66
|
const memories = (0, memory_1.toRunnableMemories)(agentId, inputs, options.memories ?? {});
|
|
64
67
|
return new SandboxFunctionAgent({
|
|
65
68
|
id: agentId,
|
|
@@ -67,8 +70,9 @@ function create({ context, ...options }) {
|
|
|
67
70
|
type: "sandbox_function_agent",
|
|
68
71
|
inputs,
|
|
69
72
|
outputs,
|
|
73
|
+
preloads,
|
|
70
74
|
memories,
|
|
71
75
|
language: options.language,
|
|
72
76
|
code: options.code,
|
|
73
|
-
}, context);
|
|
77
|
+
}, options.context);
|
|
74
78
|
}
|
|
@@ -1,25 +1,16 @@
|
|
|
1
|
-
import { Agent } from "./agent";
|
|
1
|
+
import { Agent, type AgentMemories, type AgentPreloads } from "./agent";
|
|
2
2
|
import type { Context, ContextState } from "./context";
|
|
3
|
-
import type {
|
|
4
|
-
export
|
|
5
|
-
[name: string]: any;
|
|
6
|
-
} = {}, Memories extends {
|
|
7
|
-
[name: string]: MemoryItemWithScore[];
|
|
8
|
-
} = {}, State extends ContextState = ContextState> {
|
|
3
|
+
import type { RunnableInput, RunnableOutput } from "./runnable";
|
|
4
|
+
export type SandboxFunctionRunnerInput<Input extends RunnableInput = RunnableInput, State extends ContextState = ContextState, Preloads extends AgentPreloads = AgentPreloads, Memories extends AgentMemories = AgentMemories> = {
|
|
9
5
|
name: string;
|
|
10
6
|
language?: string;
|
|
11
7
|
code: string;
|
|
12
|
-
input:
|
|
8
|
+
input: Input;
|
|
9
|
+
preloads: Preloads;
|
|
13
10
|
memories: Memories;
|
|
14
11
|
context: Pick<Context<State>, "state">;
|
|
15
|
-
}
|
|
16
|
-
export type SandboxFunctionRunnerOutput<
|
|
17
|
-
export declare abstract class SandboxFunctionRunner<I extends {
|
|
18
|
-
[name: string]: any;
|
|
19
|
-
} = {}, O extends {
|
|
20
|
-
[name: string]: any;
|
|
21
|
-
} = {}, Memories extends {
|
|
22
|
-
[name: string]: MemoryItemWithScore[];
|
|
23
|
-
} = {}, State extends ContextState = ContextState> extends Agent<SandboxFunctionRunnerInput<I, Memories, State>, SandboxFunctionRunnerOutput<O>> {
|
|
12
|
+
};
|
|
13
|
+
export type SandboxFunctionRunnerOutput<Output extends RunnableOutput> = Output;
|
|
14
|
+
export declare abstract class SandboxFunctionRunner<I extends RunnableInput = RunnableInput, O extends RunnableOutput = RunnableOutput, State extends ContextState = ContextState, Preloads extends AgentPreloads = AgentPreloads, Memories extends AgentMemories = AgentMemories> extends Agent<SandboxFunctionRunnerInput<I, State, Preloads, Memories>, SandboxFunctionRunnerOutput<O>> {
|
|
24
15
|
constructor(context?: Context);
|
|
25
16
|
}
|
|
@@ -15,6 +15,7 @@ class SandboxFunctionRunner extends agent_1.Agent {
|
|
|
15
15
|
{ id: "language", name: "language", type: "string" },
|
|
16
16
|
{ id: "code", name: "code", type: "string", required: true },
|
|
17
17
|
{ id: "input", name: "input", type: "object", required: true },
|
|
18
|
+
{ id: "preloads", name: "preloads", type: "object", required: true },
|
|
18
19
|
{ id: "memories", name: "memories", type: "object", required: true },
|
|
19
20
|
{ id: "context", name: "context", type: "object", required: true },
|
|
20
21
|
]),
|
package/lib/cjs/utils/index.d.ts
CHANGED
package/lib/cjs/utils/index.js
CHANGED
|
@@ -17,6 +17,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
17
17
|
__exportStar(require("./fetch"), exports);
|
|
18
18
|
__exportStar(require("./fetch-open-api"), exports);
|
|
19
19
|
__exportStar(require("./is-non-nullable"), exports);
|
|
20
|
+
__exportStar(require("./logger"), exports);
|
|
20
21
|
__exportStar(require("./mustache-utils"), exports);
|
|
21
22
|
__exportStar(require("./nullable"), exports);
|
|
22
23
|
__exportStar(require("./omit"), exports);
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.logger = void 0;
|
|
4
|
+
function logLevel() {
|
|
5
|
+
return process.env.LOG_LEVEL || "info";
|
|
6
|
+
}
|
|
7
|
+
function createLogger(logger, level = logLevel()) {
|
|
8
|
+
return {
|
|
9
|
+
debug: level === "debug" ? logger.debug : () => { },
|
|
10
|
+
info: level === "debug" || level === "info" ? logger.info : () => { },
|
|
11
|
+
warn: level === "debug" || level === "info" || level === "warn"
|
|
12
|
+
? logger.warn
|
|
13
|
+
: () => { },
|
|
14
|
+
error: logger.error,
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
exports.logger = createLogger(console);
|
|
@@ -11,7 +11,7 @@ export declare function memoriesToMessages(memories: {
|
|
|
11
11
|
memory: string;
|
|
12
12
|
};
|
|
13
13
|
export declare function prepareMessages(definition: Pick<LLMAgentDefinition, "messages" | "memories" | "primaryMemoryId">, input: {
|
|
14
|
-
[name: string]:
|
|
14
|
+
[name: string]: unknown;
|
|
15
15
|
}, memories: {
|
|
16
16
|
[name: string]: MemoryItemWithScore[];
|
|
17
17
|
}): {
|
|
@@ -49,12 +49,9 @@ function memoriesToMessages(memories, { primaryMemoryName } = {}) {
|
|
|
49
49
|
};
|
|
50
50
|
}
|
|
51
51
|
function prepareMessages(definition, input, memories) {
|
|
52
|
-
const variables = { ...input, ...memories };
|
|
53
52
|
const originalMessages = ordered_map_1.OrderedRecord.toArray(definition.messages).map(({ role, content }) => ({
|
|
54
53
|
role,
|
|
55
|
-
content: typeof content === "string"
|
|
56
|
-
? (0, mustache_utils_1.renderMessage)(content, variables)
|
|
57
|
-
: content,
|
|
54
|
+
content: typeof content === "string" ? (0, mustache_utils_1.renderMessage)(content, input) : content,
|
|
58
55
|
}));
|
|
59
56
|
if (!originalMessages.length)
|
|
60
57
|
throw new Error("Messages are required");
|
|
@@ -1,17 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.formatOpenAPIRequest = formatOpenAPIRequest;
|
|
7
4
|
const lodash_1 = require("lodash");
|
|
8
|
-
const logger_1 =
|
|
5
|
+
const logger_1 = require("./logger");
|
|
9
6
|
const ordered_map_1 = require("./ordered-map");
|
|
10
7
|
async function formatOpenAPIRequest(api, inputs, input) {
|
|
11
8
|
const { url, method, ...inputParams } = processParameters(api, inputs, input);
|
|
12
|
-
logger_1.
|
|
9
|
+
logger_1.logger.debug("inputParams", inputParams);
|
|
13
10
|
const authParams = await getAuthParams(api.auth);
|
|
14
|
-
logger_1.
|
|
11
|
+
logger_1.logger.debug("authParams", authParams);
|
|
15
12
|
return {
|
|
16
13
|
url,
|
|
17
14
|
method,
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
-
import type { Runnable, RunnableResponseStream } from "../runnable";
|
|
2
|
-
|
|
3
|
-
export type
|
|
1
|
+
import type { Runnable, RunnableInput, RunnableOutput, RunnableResponseStream } from "../runnable";
|
|
2
|
+
import type { UnionToIntersection } from "./union";
|
|
3
|
+
export type ExtractRunnableInputType<T> = T extends Runnable<infer I, RunnableOutput> ? I : never;
|
|
4
|
+
export type ExtractRunnableOutputType<T> = T extends Runnable<RunnableInput, infer O> ? Exclude<O, RunnableResponseStream<unknown>> : never;
|
|
5
|
+
export type ExtractRunnableInputTypeIntersection<T> = UnionToIntersection<ExtractRunnableInputType<T>, Record<string, unknown>>;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { RunnableOutputType } from "../runnable";
|
|
2
2
|
import { OrderedRecord } from "./ordered-map";
|
|
3
|
-
export declare function outputsToJsonSchema(outputs: OrderedRecord<
|
|
3
|
+
export declare function outputsToJsonSchema(outputs: OrderedRecord<RunnableOutputType>): object;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type ArrayElement<T> = T extends (infer U)[] ? U : never;
|
package/lib/dts/agent.d.ts
CHANGED
|
@@ -1,18 +1,17 @@
|
|
|
1
1
|
import type { Context, ContextState } from "./context";
|
|
2
|
-
import type {
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
}
|
|
9
|
-
export
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
} = {}, State extends ContextState = ContextState> extends Runnable<I, O, State> {
|
|
2
|
+
import type { DataSchema } from "./definitions/data-schema";
|
|
3
|
+
import type { AgentMemory, CreateRunnableMemory } from "./definitions/memory";
|
|
4
|
+
import type { AgentPreload, BindAgentInputs, BoundAgent, PreloadCreator } from "./definitions/preload";
|
|
5
|
+
import type { MemorableSearchOutput, MemoryItemWithScore, MemoryMessage } from "./memorable";
|
|
6
|
+
import { type RunOptions, Runnable, type RunnableDefinition, type RunnableInput, type RunnableOutput, type RunnableResponse, type RunnableResponseChunk, type RunnableResponseStream } from "./runnable";
|
|
7
|
+
import { OrderedRecord } from "./utils";
|
|
8
|
+
import type { ExtractRunnableOutputType } from "./utils/runnable-type";
|
|
9
|
+
export type AgentPreloads = Record<string, unknown>;
|
|
10
|
+
export type AgentMemories = Record<string, MemoryItemWithScore[]>;
|
|
11
|
+
export declare abstract class Agent<I extends RunnableInput = RunnableInput, O extends RunnableOutput = RunnableOutput, State extends ContextState = ContextState, Preloads extends AgentPreloads = AgentPreloads, Memories extends AgentMemories = AgentMemories> extends Runnable<I, O, State> {
|
|
12
|
+
definition: AgentDefinition;
|
|
13
|
+
context?: Context<State> | undefined;
|
|
14
|
+
constructor(definition: AgentDefinition, context?: Context<State> | undefined);
|
|
16
15
|
private getMemoryQuery;
|
|
17
16
|
/**
|
|
18
17
|
* Load memories that are defined in the agent definition.
|
|
@@ -20,12 +19,13 @@ export declare abstract class Agent<I extends {
|
|
|
20
19
|
* @param context The AIGNE context.
|
|
21
20
|
* @returns A dictionary of memories, where the key is the memory id or name and the value is an array of memory items.
|
|
22
21
|
*/
|
|
23
|
-
protected loadMemories(input: I
|
|
22
|
+
protected loadMemories(input: I): Promise<Memories>;
|
|
24
23
|
/**
|
|
25
24
|
* Update memories by user messages and assistant responses.
|
|
26
25
|
* @param messages Messages to be added to memories.
|
|
27
26
|
*/
|
|
28
27
|
protected updateMemories(messages: MemoryMessage[]): Promise<void>;
|
|
28
|
+
protected loadPreloads(input: I): Promise<Preloads>;
|
|
29
29
|
run(input: I, options: RunOptions & {
|
|
30
30
|
stream: true;
|
|
31
31
|
}): Promise<RunnableResponseStream<O>>;
|
|
@@ -37,5 +37,59 @@ export declare abstract class Agent<I extends {
|
|
|
37
37
|
* @param _result The agent result.
|
|
38
38
|
*/
|
|
39
39
|
protected onResult(_result: O): Promise<void>;
|
|
40
|
-
abstract process(input: I, options: AgentProcessOptions
|
|
40
|
+
abstract process(input: AgentProcessInput<I, Preloads, Memories>, options: AgentProcessOptions): Promise<RunnableResponse<O> | AsyncGenerator<RunnableResponseChunk<O>, void>> | AsyncGenerator<RunnableResponseChunk<O>, void>;
|
|
41
|
+
/**
|
|
42
|
+
* Bind some inputs to the agent, used for process of `PipelineAgent` or case of `LLMDecisionAgent`.
|
|
43
|
+
* @param options The bind options.
|
|
44
|
+
* @returns The bound agent.
|
|
45
|
+
*/
|
|
46
|
+
bind<Input extends BindAgentInputs<Record<string, never>, typeof this>>(options: {
|
|
47
|
+
description?: string;
|
|
48
|
+
input?: Input;
|
|
49
|
+
}): BoundAgent<Record<string, never>, typeof this, Readonly<Input>>;
|
|
50
|
+
}
|
|
51
|
+
export type AgentProcessOptions<Preloads extends AgentPreloads = AgentPreloads, Memories extends AgentMemories = AgentMemories> = {
|
|
52
|
+
preloads: Preloads;
|
|
53
|
+
memories: Memories;
|
|
54
|
+
};
|
|
55
|
+
export type AgentProcessInput<I extends RunnableInput, Preloads extends AgentPreloads, Memories extends AgentMemories> = I & Preloads & Memories;
|
|
56
|
+
export interface AgentDefinition extends RunnableDefinition {
|
|
57
|
+
preloads?: OrderedRecord<AgentPreload>;
|
|
58
|
+
memories?: OrderedRecord<AgentMemory>;
|
|
59
|
+
}
|
|
60
|
+
export type CreateAgentInputSchema = Record<string, DataSchema>;
|
|
61
|
+
export type CreateAgentOutputSchema<Extra extends Record<string, unknown> = Record<string, unknown>> = Record<string, DataSchema & Extra>;
|
|
62
|
+
export type CreateAgentPreloadsSchema<I extends CreateAgentInputSchema> = Record<string, PreloadCreator<I>>;
|
|
63
|
+
export type CreateAgentPreloadsType<I extends CreateAgentInputSchema, Preloads extends CreateAgentPreloadsSchema<I>> = {
|
|
64
|
+
[name in keyof Preloads]: ExtractRunnableOutputType<ReturnType<Preloads[name]>["runnable"]>;
|
|
65
|
+
};
|
|
66
|
+
export type CreateAgentMemoriesSchema<I extends CreateAgentInputSchema, Extras extends Record<string, unknown> = Record<string, unknown>> = Record<string, CreateRunnableMemory<I> & Extras>;
|
|
67
|
+
export type CreateAgentMemoriesType<I extends CreateAgentInputSchema, Memories extends CreateAgentMemoriesSchema<I, Record<string, unknown>>> = {
|
|
68
|
+
[key in keyof Memories]: MemorableSearchOutput<Memories[key]["memory"]>;
|
|
69
|
+
};
|
|
70
|
+
/**
|
|
71
|
+
* Common options to create Agent.
|
|
72
|
+
*/
|
|
73
|
+
export interface CreateAgentOptions<I extends CreateAgentInputSchema, O extends CreateAgentOutputSchema, State extends ContextState, Preloads extends CreateAgentPreloadsSchema<I>, Memories extends CreateAgentMemoriesSchema<I, Record<string, unknown>>> {
|
|
74
|
+
context?: Context<State>;
|
|
75
|
+
/**
|
|
76
|
+
* Agent name, used to identify the agent.
|
|
77
|
+
*/
|
|
78
|
+
name?: string;
|
|
79
|
+
/**
|
|
80
|
+
* Input variables for this agent.
|
|
81
|
+
*/
|
|
82
|
+
inputs: I;
|
|
83
|
+
/**
|
|
84
|
+
* Output variables for this agent.
|
|
85
|
+
*/
|
|
86
|
+
outputs: O;
|
|
87
|
+
/**
|
|
88
|
+
* Preload runnables before running this agent. the preloaded data are available in the agent as input variables.
|
|
89
|
+
*/
|
|
90
|
+
preloads?: Preloads;
|
|
91
|
+
/**
|
|
92
|
+
* Memories to be used in this agent.
|
|
93
|
+
*/
|
|
94
|
+
memories?: Memories;
|
|
41
95
|
}
|
package/lib/dts/context.d.ts
CHANGED