@aigne/core 1.0.17 → 1.1.0-beta.2
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/agents/agent.d.ts +55 -0
- package/lib/cjs/agents/agent.js +91 -0
- package/lib/cjs/agents/ai-agent.d.ts +20 -0
- package/lib/cjs/agents/ai-agent.js +86 -0
- package/lib/cjs/agents/mcp-agent.d.ts +27 -0
- package/lib/cjs/agents/mcp-agent.js +95 -0
- package/lib/cjs/agents/types.d.ts +9 -0
- package/lib/cjs/agents/types.js +16 -0
- package/lib/cjs/execution-engine/context.d.ts +10 -0
- package/lib/cjs/execution-engine/index.d.ts +45 -0
- package/lib/cjs/execution-engine/index.js +190 -0
- package/lib/cjs/execution-engine/message-queue.d.ts +5 -0
- package/lib/cjs/execution-engine/message-queue.js +9 -0
- package/lib/cjs/index.d.ts +10 -21
- package/lib/cjs/index.js +10 -21
- package/lib/cjs/models/chat-openai.d.ts +14 -0
- package/lib/cjs/{llm-models/openai-llm-model.js → models/chat-openai.js} +62 -27
- package/lib/cjs/models/chat.d.ts +78 -0
- package/lib/cjs/models/chat.js +91 -0
- package/lib/cjs/prompt/prompt-builder.d.ts +34 -0
- package/lib/cjs/prompt/prompt-builder.js +140 -0
- package/lib/cjs/prompt/template.d.ts +70 -0
- package/lib/cjs/prompt/template.js +172 -0
- package/lib/cjs/utils/logger.d.ts +6 -3
- package/lib/cjs/utils/logger.js +9 -14
- package/lib/cjs/utils/type-utils.d.ts +5 -1
- package/lib/cjs/utils/type-utils.js +23 -0
- package/lib/dts/agents/agent.d.ts +55 -0
- package/lib/dts/agents/ai-agent.d.ts +20 -0
- package/lib/dts/agents/mcp-agent.d.ts +27 -0
- package/lib/dts/agents/types.d.ts +9 -0
- package/lib/dts/execution-engine/context.d.ts +10 -0
- package/lib/dts/execution-engine/index.d.ts +45 -0
- package/lib/dts/execution-engine/message-queue.d.ts +5 -0
- package/lib/dts/index.d.ts +10 -21
- package/lib/dts/models/chat-openai.d.ts +14 -0
- package/lib/dts/models/chat.d.ts +78 -0
- package/lib/dts/prompt/prompt-builder.d.ts +34 -0
- package/lib/dts/prompt/template.d.ts +70 -0
- package/lib/dts/utils/logger.d.ts +6 -3
- package/lib/dts/utils/type-utils.d.ts +5 -1
- package/lib/esm/agents/agent.d.ts +55 -0
- package/lib/esm/agents/agent.js +83 -0
- package/lib/esm/agents/ai-agent.d.ts +20 -0
- package/lib/esm/agents/ai-agent.js +82 -0
- package/lib/esm/agents/mcp-agent.d.ts +27 -0
- package/lib/esm/agents/mcp-agent.js +90 -0
- package/lib/esm/agents/types.d.ts +9 -0
- package/lib/esm/agents/types.js +11 -0
- package/lib/esm/execution-engine/context.d.ts +10 -0
- package/lib/esm/execution-engine/index.d.ts +45 -0
- package/lib/esm/execution-engine/index.js +182 -0
- package/lib/esm/execution-engine/message-queue.d.ts +5 -0
- package/lib/esm/execution-engine/message-queue.js +5 -0
- package/lib/esm/index.d.ts +10 -21
- package/lib/esm/index.js +10 -21
- package/lib/esm/models/chat-openai.d.ts +14 -0
- package/lib/esm/{llm-models/openai-llm-model.js → models/chat-openai.js} +59 -24
- package/lib/esm/models/chat.d.ts +78 -0
- package/lib/esm/models/chat.js +87 -0
- package/lib/esm/prompt/prompt-builder.d.ts +34 -0
- package/lib/esm/prompt/prompt-builder.js +131 -0
- package/lib/esm/prompt/template.d.ts +70 -0
- package/lib/esm/prompt/template.js +158 -0
- package/lib/esm/utils/logger.d.ts +6 -3
- package/lib/esm/utils/logger.js +6 -14
- package/lib/esm/utils/type-utils.d.ts +5 -1
- package/lib/esm/utils/type-utils.js +17 -1
- package/package.json +18 -14
- package/lib/cjs/agent.d.ts +0 -96
- package/lib/cjs/agent.js +0 -165
- package/lib/cjs/constants.d.ts +0 -7
- package/lib/cjs/constants.js +0 -10
- package/lib/cjs/context.d.ts +0 -23
- package/lib/cjs/definitions/data-schema.d.ts +0 -61
- package/lib/cjs/definitions/data-schema.js +0 -47
- package/lib/cjs/definitions/data-type.d.ts +0 -32
- package/lib/cjs/definitions/data-type.js +0 -2
- package/lib/cjs/definitions/memory.d.ts +0 -53
- package/lib/cjs/definitions/memory.js +0 -23
- package/lib/cjs/definitions/open-api.d.ts +0 -36
- package/lib/cjs/definitions/open-api.js +0 -2
- package/lib/cjs/definitions/preload.d.ts +0 -43
- package/lib/cjs/definitions/preload.js +0 -34
- package/lib/cjs/function-agent.d.ts +0 -23
- package/lib/cjs/function-agent.js +0 -62
- package/lib/cjs/llm-agent.d.ts +0 -53
- package/lib/cjs/llm-agent.js +0 -140
- package/lib/cjs/llm-decision-agent.d.ts +0 -53
- package/lib/cjs/llm-decision-agent.js +0 -144
- package/lib/cjs/llm-model.d.ts +0 -80
- package/lib/cjs/llm-model.js +0 -27
- package/lib/cjs/llm-models/gemini-llm-model.d.ts +0 -24
- package/lib/cjs/llm-models/gemini-llm-model.js +0 -199
- package/lib/cjs/llm-models/openai-llm-model.d.ts +0 -26
- package/lib/cjs/memorable.d.ts +0 -198
- package/lib/cjs/memorable.js +0 -33
- package/lib/cjs/open-api-agent.d.ts +0 -26
- package/lib/cjs/open-api-agent.js +0 -68
- package/lib/cjs/pipeline-agent.d.ts +0 -56
- package/lib/cjs/pipeline-agent.js +0 -206
- package/lib/cjs/runnable.d.ts +0 -76
- package/lib/cjs/runnable.js +0 -37
- package/lib/cjs/runtime.d.ts +0 -64
- package/lib/cjs/runtime.js +0 -149
- package/lib/cjs/sandbox-function-agent.d.ts +0 -21
- package/lib/cjs/sandbox-function-agent.js +0 -78
- package/lib/cjs/sandbox-function-runner.d.ts +0 -16
- package/lib/cjs/sandbox-function-runner.js +0 -32
- package/lib/cjs/utils/constants.d.ts +0 -1
- package/lib/cjs/utils/constants.js +0 -4
- package/lib/cjs/utils/fetch-open-api.d.ts +0 -2
- package/lib/cjs/utils/fetch-open-api.js +0 -31
- package/lib/cjs/utils/fetch.d.ts +0 -1
- package/lib/cjs/utils/fetch.js +0 -21
- package/lib/cjs/utils/index.d.ts +0 -12
- package/lib/cjs/utils/index.js +0 -28
- package/lib/cjs/utils/is-non-nullable.d.ts +0 -2
- package/lib/cjs/utils/is-non-nullable.js +0 -20
- package/lib/cjs/utils/message-utils.d.ts +0 -20
- package/lib/cjs/utils/message-utils.js +0 -79
- package/lib/cjs/utils/mustache-utils.d.ts +0 -3
- package/lib/cjs/utils/mustache-utils.js +0 -14
- package/lib/cjs/utils/nullable.d.ts +0 -7
- package/lib/cjs/utils/nullable.js +0 -2
- package/lib/cjs/utils/omit.d.ts +0 -1
- package/lib/cjs/utils/omit.js +0 -2
- package/lib/cjs/utils/open-api-parameter.d.ts +0 -7
- package/lib/cjs/utils/open-api-parameter.js +0 -81
- package/lib/cjs/utils/ordered-map.d.ts +0 -37
- package/lib/cjs/utils/ordered-map.js +0 -103
- package/lib/cjs/utils/partial.d.ts +0 -3
- package/lib/cjs/utils/partial.js +0 -2
- package/lib/cjs/utils/runnable-type.d.ts +0 -5
- package/lib/cjs/utils/runnable-type.js +0 -2
- package/lib/cjs/utils/stream-utils.d.ts +0 -20
- package/lib/cjs/utils/stream-utils.js +0 -86
- package/lib/cjs/utils/structured-output-schema.d.ts +0 -3
- package/lib/cjs/utils/structured-output-schema.js +0 -43
- package/lib/cjs/utils/union.d.ts +0 -1
- package/lib/cjs/utils/union.js +0 -2
- package/lib/dts/agent.d.ts +0 -96
- package/lib/dts/constants.d.ts +0 -7
- package/lib/dts/context.d.ts +0 -23
- package/lib/dts/definitions/data-schema.d.ts +0 -61
- package/lib/dts/definitions/data-type.d.ts +0 -32
- package/lib/dts/definitions/memory.d.ts +0 -53
- package/lib/dts/definitions/open-api.d.ts +0 -36
- package/lib/dts/definitions/preload.d.ts +0 -43
- package/lib/dts/function-agent.d.ts +0 -23
- package/lib/dts/llm-agent.d.ts +0 -53
- package/lib/dts/llm-decision-agent.d.ts +0 -53
- package/lib/dts/llm-model.d.ts +0 -80
- package/lib/dts/llm-models/gemini-llm-model.d.ts +0 -24
- package/lib/dts/llm-models/openai-llm-model.d.ts +0 -26
- package/lib/dts/memorable.d.ts +0 -198
- package/lib/dts/open-api-agent.d.ts +0 -26
- package/lib/dts/pipeline-agent.d.ts +0 -56
- package/lib/dts/runnable.d.ts +0 -76
- package/lib/dts/runtime.d.ts +0 -64
- package/lib/dts/sandbox-function-agent.d.ts +0 -21
- package/lib/dts/sandbox-function-runner.d.ts +0 -16
- package/lib/dts/utils/constants.d.ts +0 -1
- package/lib/dts/utils/fetch-open-api.d.ts +0 -2
- package/lib/dts/utils/fetch.d.ts +0 -1
- package/lib/dts/utils/index.d.ts +0 -12
- package/lib/dts/utils/is-non-nullable.d.ts +0 -2
- package/lib/dts/utils/message-utils.d.ts +0 -20
- package/lib/dts/utils/mustache-utils.d.ts +0 -3
- package/lib/dts/utils/nullable.d.ts +0 -7
- package/lib/dts/utils/omit.d.ts +0 -1
- package/lib/dts/utils/open-api-parameter.d.ts +0 -7
- package/lib/dts/utils/ordered-map.d.ts +0 -37
- package/lib/dts/utils/partial.d.ts +0 -3
- package/lib/dts/utils/runnable-type.d.ts +0 -5
- package/lib/dts/utils/stream-utils.d.ts +0 -20
- package/lib/dts/utils/structured-output-schema.d.ts +0 -3
- package/lib/dts/utils/union.d.ts +0 -1
- package/lib/esm/agent.d.ts +0 -96
- package/lib/esm/agent.js +0 -161
- package/lib/esm/constants.d.ts +0 -7
- package/lib/esm/constants.js +0 -7
- package/lib/esm/context.d.ts +0 -23
- package/lib/esm/definitions/data-schema.d.ts +0 -61
- package/lib/esm/definitions/data-schema.js +0 -44
- package/lib/esm/definitions/data-type.d.ts +0 -32
- package/lib/esm/definitions/data-type.js +0 -1
- package/lib/esm/definitions/memory.d.ts +0 -53
- package/lib/esm/definitions/memory.js +0 -20
- package/lib/esm/definitions/open-api.d.ts +0 -36
- package/lib/esm/definitions/open-api.js +0 -1
- package/lib/esm/definitions/preload.d.ts +0 -43
- package/lib/esm/definitions/preload.js +0 -31
- package/lib/esm/function-agent.d.ts +0 -23
- package/lib/esm/function-agent.js +0 -59
- package/lib/esm/llm-agent.d.ts +0 -53
- package/lib/esm/llm-agent.js +0 -137
- package/lib/esm/llm-decision-agent.d.ts +0 -53
- package/lib/esm/llm-decision-agent.js +0 -141
- package/lib/esm/llm-model.d.ts +0 -80
- package/lib/esm/llm-model.js +0 -23
- package/lib/esm/llm-models/gemini-llm-model.d.ts +0 -24
- package/lib/esm/llm-models/gemini-llm-model.js +0 -195
- package/lib/esm/llm-models/openai-llm-model.d.ts +0 -26
- package/lib/esm/memorable.d.ts +0 -198
- package/lib/esm/memorable.js +0 -28
- package/lib/esm/open-api-agent.d.ts +0 -26
- package/lib/esm/open-api-agent.js +0 -65
- package/lib/esm/pipeline-agent.d.ts +0 -56
- package/lib/esm/pipeline-agent.js +0 -203
- package/lib/esm/runnable.d.ts +0 -76
- package/lib/esm/runnable.js +0 -30
- package/lib/esm/runtime.d.ts +0 -64
- package/lib/esm/runtime.js +0 -146
- package/lib/esm/sandbox-function-agent.d.ts +0 -21
- package/lib/esm/sandbox-function-agent.js +0 -74
- package/lib/esm/sandbox-function-runner.d.ts +0 -16
- package/lib/esm/sandbox-function-runner.js +0 -28
- package/lib/esm/utils/constants.d.ts +0 -1
- package/lib/esm/utils/constants.js +0 -1
- package/lib/esm/utils/fetch-open-api.d.ts +0 -2
- package/lib/esm/utils/fetch-open-api.js +0 -28
- package/lib/esm/utils/fetch.d.ts +0 -1
- package/lib/esm/utils/fetch.js +0 -18
- package/lib/esm/utils/index.d.ts +0 -12
- package/lib/esm/utils/index.js +0 -12
- package/lib/esm/utils/is-non-nullable.d.ts +0 -2
- package/lib/esm/utils/is-non-nullable.js +0 -13
- package/lib/esm/utils/message-utils.d.ts +0 -20
- package/lib/esm/utils/message-utils.js +0 -71
- package/lib/esm/utils/mustache-utils.d.ts +0 -3
- package/lib/esm/utils/mustache-utils.js +0 -8
- package/lib/esm/utils/nullable.d.ts +0 -7
- package/lib/esm/utils/nullable.js +0 -1
- package/lib/esm/utils/omit.d.ts +0 -1
- package/lib/esm/utils/omit.js +0 -1
- package/lib/esm/utils/open-api-parameter.d.ts +0 -7
- package/lib/esm/utils/open-api-parameter.js +0 -78
- package/lib/esm/utils/ordered-map.d.ts +0 -37
- package/lib/esm/utils/ordered-map.js +0 -100
- package/lib/esm/utils/partial.d.ts +0 -3
- package/lib/esm/utils/partial.js +0 -1
- package/lib/esm/utils/runnable-type.d.ts +0 -5
- package/lib/esm/utils/runnable-type.js +0 -1
- package/lib/esm/utils/stream-utils.d.ts +0 -20
- package/lib/esm/utils/stream-utils.js +0 -79
- package/lib/esm/utils/structured-output-schema.d.ts +0 -3
- package/lib/esm/utils/structured-output-schema.js +0 -37
- package/lib/esm/utils/union.d.ts +0 -1
- package/lib/esm/utils/union.js +0 -1
- /package/lib/cjs/{context.js → execution-engine/context.js} +0 -0
- /package/lib/esm/{context.js → execution-engine/context.js} +0 -0
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.schemaToDataType = schemaToDataType;
|
|
4
|
-
const nanoid_1 = require("nanoid");
|
|
5
|
-
const ordered_map_1 = require("../utils/ordered-map");
|
|
6
|
-
function schemaToDataType(dataType) {
|
|
7
|
-
return ordered_map_1.OrderedRecord.fromArray(Object.entries(dataType).map(([name, schema]) => {
|
|
8
|
-
const base = {
|
|
9
|
-
...schema,
|
|
10
|
-
id: (0, nanoid_1.nanoid)(),
|
|
11
|
-
name,
|
|
12
|
-
};
|
|
13
|
-
switch (schema.type) {
|
|
14
|
-
case "string":
|
|
15
|
-
return {
|
|
16
|
-
...base,
|
|
17
|
-
type: "string",
|
|
18
|
-
};
|
|
19
|
-
case "number":
|
|
20
|
-
return {
|
|
21
|
-
...base,
|
|
22
|
-
type: "number",
|
|
23
|
-
};
|
|
24
|
-
case "boolean":
|
|
25
|
-
return {
|
|
26
|
-
...base,
|
|
27
|
-
type: "boolean",
|
|
28
|
-
};
|
|
29
|
-
case "object":
|
|
30
|
-
return {
|
|
31
|
-
...base,
|
|
32
|
-
type: "object",
|
|
33
|
-
properties: schema.properties && schemaToDataType(schema.properties),
|
|
34
|
-
};
|
|
35
|
-
case "array":
|
|
36
|
-
return {
|
|
37
|
-
...base,
|
|
38
|
-
type: "array",
|
|
39
|
-
items: schema.items &&
|
|
40
|
-
ordered_map_1.OrderedRecord.find(schemaToDataType({ items: schema.items }), (i) => i.name === "items"),
|
|
41
|
-
};
|
|
42
|
-
default: {
|
|
43
|
-
throw new Error(`Unknown data type: ${schema.type}`);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
}));
|
|
47
|
-
}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import type { OmitPropsFromUnion } from "../utils/omit";
|
|
2
|
-
import type { OrderedRecord } from "../utils/ordered-map";
|
|
3
|
-
export type DataType = DataTypeString | DataTypeNumber | DataTypeBoolean | DataTypeObject | DataTypeArray;
|
|
4
|
-
export interface DataTypeBase {
|
|
5
|
-
id: string;
|
|
6
|
-
name?: string;
|
|
7
|
-
description?: string;
|
|
8
|
-
required?: boolean;
|
|
9
|
-
}
|
|
10
|
-
export interface DataTypeString extends DataTypeBase {
|
|
11
|
-
type: "string";
|
|
12
|
-
defaultValue?: string;
|
|
13
|
-
multiline?: boolean;
|
|
14
|
-
}
|
|
15
|
-
export interface DataTypeNumber extends DataTypeBase {
|
|
16
|
-
type: "number";
|
|
17
|
-
defaultValue?: number;
|
|
18
|
-
}
|
|
19
|
-
export interface DataTypeBoolean extends DataTypeBase {
|
|
20
|
-
type: "boolean";
|
|
21
|
-
defaultValue?: boolean;
|
|
22
|
-
}
|
|
23
|
-
export interface DataTypeObject extends DataTypeBase {
|
|
24
|
-
type: "object";
|
|
25
|
-
defaultValue?: object;
|
|
26
|
-
properties?: OrderedRecord<DataType>;
|
|
27
|
-
}
|
|
28
|
-
export interface DataTypeArray extends DataTypeBase {
|
|
29
|
-
type: "array";
|
|
30
|
-
defaultValue?: object[];
|
|
31
|
-
items?: OmitPropsFromUnion<DataType, "id">;
|
|
32
|
-
}
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import type { Memorable } from "../memorable";
|
|
2
|
-
import type { RunnableInputType } from "../runnable";
|
|
3
|
-
import { OrderedRecord } from "../utils";
|
|
4
|
-
import type { DataSchema } from "./data-schema";
|
|
5
|
-
export interface AgentMemory {
|
|
6
|
-
id: string;
|
|
7
|
-
name?: string;
|
|
8
|
-
memory?: Memorable<unknown>;
|
|
9
|
-
query?: {
|
|
10
|
-
from: "variable";
|
|
11
|
-
fromVariableId?: string;
|
|
12
|
-
fromVariablePropPath?: string[];
|
|
13
|
-
};
|
|
14
|
-
options?: {
|
|
15
|
-
k?: number;
|
|
16
|
-
};
|
|
17
|
-
}
|
|
18
|
-
export interface CreateRunnableMemory<I extends {
|
|
19
|
-
[key: string]: DataSchema;
|
|
20
|
-
} = {}> {
|
|
21
|
-
/**
|
|
22
|
-
* Memory instance to query/store memory.
|
|
23
|
-
*/
|
|
24
|
-
memory: Memorable<any>;
|
|
25
|
-
/**
|
|
26
|
-
* Custom query to retrieve memory, if not provided, all input variables will be used.
|
|
27
|
-
*
|
|
28
|
-
* @example
|
|
29
|
-
* {
|
|
30
|
-
* fromVariable: 'question' // question is a string input variable
|
|
31
|
-
* }
|
|
32
|
-
*/
|
|
33
|
-
query?: {
|
|
34
|
-
/**
|
|
35
|
-
* Variable name from input used to query memory.
|
|
36
|
-
*/
|
|
37
|
-
fromVariable?: keyof {
|
|
38
|
-
[key in keyof I as I[key]["type"] extends "string" ? key : never]: any;
|
|
39
|
-
};
|
|
40
|
-
};
|
|
41
|
-
/**
|
|
42
|
-
* Custom options for memory query.
|
|
43
|
-
*/
|
|
44
|
-
options?: {
|
|
45
|
-
/**
|
|
46
|
-
* Number of memories to retrieve.
|
|
47
|
-
*/
|
|
48
|
-
k?: number;
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
export declare function toRunnableMemories<I extends {}>(agentName: string, inputs: OrderedRecord<RunnableInputType>, memories: {
|
|
52
|
-
[name: string]: CreateRunnableMemory<I>;
|
|
53
|
-
}): OrderedRecord<AgentMemory>;
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.toRunnableMemories = toRunnableMemories;
|
|
4
|
-
const nanoid_1 = require("nanoid");
|
|
5
|
-
const utils_1 = require("../utils");
|
|
6
|
-
function toRunnableMemories(agentName, inputs, memories) {
|
|
7
|
-
return utils_1.OrderedRecord.fromArray(Object.entries(memories).map(([name, { memory, query, options }]) => {
|
|
8
|
-
const queryFromVariable = query?.fromVariable
|
|
9
|
-
? utils_1.OrderedRecord.find(inputs, (j) => j.name === query.fromVariable)
|
|
10
|
-
: null;
|
|
11
|
-
if (query?.fromVariable && !queryFromVariable)
|
|
12
|
-
throw new Error(`LLMAgent ${agentName} -> Memory ${name} -> Query variable ${query.fromVariable.toString()} not found`);
|
|
13
|
-
return {
|
|
14
|
-
id: name || (0, nanoid_1.nanoid)(),
|
|
15
|
-
name,
|
|
16
|
-
memory,
|
|
17
|
-
query: queryFromVariable
|
|
18
|
-
? { from: "variable", fromVariableId: queryFromVariable.id }
|
|
19
|
-
: undefined,
|
|
20
|
-
options,
|
|
21
|
-
};
|
|
22
|
-
}));
|
|
23
|
-
}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import type { DataSchema } from "./data-schema";
|
|
2
|
-
import type { DataType } from "./data-type";
|
|
3
|
-
export interface BaseAuthConfig {
|
|
4
|
-
type: "bearer" | "basic";
|
|
5
|
-
token: string;
|
|
6
|
-
in?: "header" | "query" | "cookie";
|
|
7
|
-
/**
|
|
8
|
-
* The key to use for the token. Default `Authorization` in header and `token` in query and cookie.
|
|
9
|
-
*/
|
|
10
|
-
key?: string;
|
|
11
|
-
}
|
|
12
|
-
export interface CustomAuthConfig {
|
|
13
|
-
type: "custom";
|
|
14
|
-
auth: () => Promise<AuthResult> | AuthResult;
|
|
15
|
-
}
|
|
16
|
-
export type AuthConfig = BaseAuthConfig | CustomAuthConfig;
|
|
17
|
-
export type AuthType = AuthConfig["type"];
|
|
18
|
-
export type AuthResult = Pick<FetchRequest, "headers" | "query" | "cookies">;
|
|
19
|
-
type HTTPMethodLowercase = "get" | "post" | "put" | "delete" | "patch" | "head" | "options";
|
|
20
|
-
export type HTTPMethod = Uppercase<HTTPMethodLowercase> | Lowercase<HTTPMethodLowercase>;
|
|
21
|
-
export type ParameterLocation = "path" | "query" | "body" | "header" | "cookie";
|
|
22
|
-
export type OpenAPIDataType = DataType & {
|
|
23
|
-
in?: ParameterLocation;
|
|
24
|
-
};
|
|
25
|
-
export type OpenAPIDataTypeSchema = DataSchema & {
|
|
26
|
-
in?: ParameterLocation;
|
|
27
|
-
};
|
|
28
|
-
export type FetchRequest = {
|
|
29
|
-
url: string;
|
|
30
|
-
method: HTTPMethod;
|
|
31
|
-
query?: Record<string, string | number | boolean>;
|
|
32
|
-
headers?: Record<string, string>;
|
|
33
|
-
cookies?: Record<string, string>;
|
|
34
|
-
body?: Record<string, unknown>;
|
|
35
|
-
};
|
|
36
|
-
export {};
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import type { CreateAgentInputSchema, CreateAgentPreloadsSchema } from "../agent";
|
|
2
|
-
import type { Runnable, RunnableInputType } from "../runnable";
|
|
3
|
-
import { OrderedRecord } from "../utils/ordered-map";
|
|
4
|
-
import type { ExtractRunnableInputType } from "../utils/runnable-type";
|
|
5
|
-
import type { UnionToIntersection } from "../utils/union";
|
|
6
|
-
import type { SchemaToType } from "./data-schema";
|
|
7
|
-
export declare function preloadCreatorsToPreloads<I extends CreateAgentInputSchema, C extends CreateAgentPreloadsSchema<I>>(inputs: OrderedRecord<RunnableInputType>, creators?: C): OrderedRecord<AgentPreload>;
|
|
8
|
-
export type PreloadCreator<I extends CreateAgentInputSchema> = (preload: <R extends Runnable, Input extends BindAgentInputs<SchemaToType<I>, R>>(runnable: R, input: Input, options?: {
|
|
9
|
-
description?: string;
|
|
10
|
-
}) => Readonly<BoundAgent<I, R, Input>>) => ReturnType<typeof preload>;
|
|
11
|
-
export type BindAgentInputs<Vars extends Record<string, unknown>, R extends Runnable> = {
|
|
12
|
-
[key in keyof ExtractRunnableInputType<R>]: BindAgentInput<Vars, ExtractRunnableInputType<R>[key]>;
|
|
13
|
-
};
|
|
14
|
-
export interface AgentPreload {
|
|
15
|
-
id: string;
|
|
16
|
-
name?: string;
|
|
17
|
-
runnable?: {
|
|
18
|
-
id: string;
|
|
19
|
-
};
|
|
20
|
-
input?: {
|
|
21
|
-
[inputId: string]: BindAgentInput;
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
export type BindAgentInput<Vars extends Record<string, unknown> = Record<string, unknown>, Input = unknown> = {
|
|
25
|
-
from: "ai";
|
|
26
|
-
} | {
|
|
27
|
-
from: "input";
|
|
28
|
-
fromInput: keyof {
|
|
29
|
-
[name in keyof Vars as Vars[name] extends Input ? name : never]: name;
|
|
30
|
-
};
|
|
31
|
-
};
|
|
32
|
-
export interface BoundAgent<Vars extends Record<string, unknown> = Record<string, unknown>, R extends Runnable = Runnable, I extends BindAgentInputs<Vars, R> = BindAgentInputs<Vars, R>> {
|
|
33
|
-
description?: string;
|
|
34
|
-
runnable: R;
|
|
35
|
-
input?: I;
|
|
36
|
-
}
|
|
37
|
-
type PickInputFrom<I, From extends BindAgentInput["from"]> = {
|
|
38
|
-
[key in keyof I as I[key] extends {
|
|
39
|
-
from: From;
|
|
40
|
-
} ? key : never]: I[key];
|
|
41
|
-
};
|
|
42
|
-
export type OmitBoundAgentInput<Case extends BoundAgent, From extends BindAgentInput["from"]> = Omit<UnionToIntersection<ExtractRunnableInputType<Case["runnable"]>, Record<string, never>>, keyof PickInputFrom<Required<UnionToIntersection<NonNullable<Case["input"]>, Record<string, never>>>, From>>;
|
|
43
|
-
export {};
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.preloadCreatorsToPreloads = preloadCreatorsToPreloads;
|
|
4
|
-
const is_non_nullable_1 = require("../utils/is-non-nullable");
|
|
5
|
-
const ordered_map_1 = require("../utils/ordered-map");
|
|
6
|
-
function preloadCreatorsToPreloads(inputs, creators) {
|
|
7
|
-
return ordered_map_1.OrderedRecord.fromArray(Object.entries(creators ?? {}).map(([name, preload]) => {
|
|
8
|
-
const p = preload((runnable, input, options) => ({
|
|
9
|
-
...options,
|
|
10
|
-
runnable,
|
|
11
|
-
input,
|
|
12
|
-
}));
|
|
13
|
-
const input = Object.fromEntries(ordered_map_1.OrderedRecord.map(p.runnable.definition.inputs, (i) => {
|
|
14
|
-
if (!i.name)
|
|
15
|
-
return null;
|
|
16
|
-
const bind = p.input?.[i.name];
|
|
17
|
-
if (!bind)
|
|
18
|
-
return null;
|
|
19
|
-
if (bind.from !== "input")
|
|
20
|
-
throw new Error(`Unsupported bind from ${bind.from} in preloads`);
|
|
21
|
-
const from = ordered_map_1.OrderedRecord.find(inputs, (i) => i.name === bind.fromInput);
|
|
22
|
-
if (!from)
|
|
23
|
-
throw new Error(`Input ${bind.fromInput} not found`);
|
|
24
|
-
return [i.id, { ...bind, fromInput: from.id }];
|
|
25
|
-
}).filter(is_non_nullable_1.isNonNullable));
|
|
26
|
-
return {
|
|
27
|
-
id: name,
|
|
28
|
-
name,
|
|
29
|
-
description: p.description,
|
|
30
|
-
runnable: { id: p.runnable.id },
|
|
31
|
-
input,
|
|
32
|
-
};
|
|
33
|
-
}));
|
|
34
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
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
|
-
import type { Context, ContextState } from "./context";
|
|
3
|
-
import { type SchemaToType } from "./definitions/data-schema";
|
|
4
|
-
import type { RunnableInput, RunnableOutput, RunnableResponse, RunnableResponseChunk } from "./runnable";
|
|
5
|
-
export declare class FunctionAgent<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> {
|
|
6
|
-
definition: FunctionAgentDefinition<I, O, State, Preloads, Memories>;
|
|
7
|
-
static create: typeof create;
|
|
8
|
-
constructor(definition: FunctionAgentDefinition<I, O, State, Preloads, Memories>, context?: Context<State>);
|
|
9
|
-
process(input: AgentProcessInput<I, Preloads, Memories>, options: AgentProcessOptions<Preloads, Memories>): Promise<AsyncGenerator<RunnableResponseChunk<O>, void, any> | RunnableResponse<O>>;
|
|
10
|
-
}
|
|
11
|
-
export interface FunctionAgentDefinition<I extends RunnableInput, O extends RunnableOutput, State extends ContextState, Preloads extends AgentPreloads, Memories extends AgentMemories> extends AgentDefinition {
|
|
12
|
-
type: "function_agent";
|
|
13
|
-
function?: FunctionFuncType<I, O, State, Preloads, Memories>;
|
|
14
|
-
}
|
|
15
|
-
export type FunctionFuncType<I extends RunnableInput, O extends RunnableOutput, State extends ContextState, Preloads extends AgentPreloads, Memories extends AgentMemories> = (input: AgentProcessInput<I, Preloads, Memories>, options: {
|
|
16
|
-
context: Context<State>;
|
|
17
|
-
preloads: Preloads;
|
|
18
|
-
memories: Memories;
|
|
19
|
-
}) => Promise<RunnableResponse<O> | AsyncGenerator<RunnableResponseChunk<O>, void>> | AsyncGenerator<RunnableResponseChunk<O>, void>;
|
|
20
|
-
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> & {
|
|
21
|
-
function?: FunctionFuncType<SchemaToType<I>, SchemaToType<O>, State, CreateAgentPreloadsType<I, Preloads>, CreateAgentMemoriesType<I, Memories>>;
|
|
22
|
-
}): FunctionAgent<SchemaToType<I>, SchemaToType<O>, State, CreateAgentPreloadsType<I, Preloads>, CreateAgentMemoriesType<I, Memories>>;
|
|
23
|
-
export {};
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
-
};
|
|
8
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
-
};
|
|
11
|
-
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
-
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
-
};
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.FunctionAgent = void 0;
|
|
16
|
-
const nanoid_1 = require("nanoid");
|
|
17
|
-
const tsyringe_1 = require("tsyringe");
|
|
18
|
-
const agent_1 = require("./agent");
|
|
19
|
-
const constants_1 = require("./constants");
|
|
20
|
-
const data_schema_1 = require("./definitions/data-schema");
|
|
21
|
-
const memory_1 = require("./definitions/memory");
|
|
22
|
-
const preload_1 = require("./definitions/preload");
|
|
23
|
-
let FunctionAgent = class FunctionAgent extends agent_1.Agent {
|
|
24
|
-
definition;
|
|
25
|
-
static create = create;
|
|
26
|
-
constructor(definition, context) {
|
|
27
|
-
super(definition, context);
|
|
28
|
-
this.definition = definition;
|
|
29
|
-
}
|
|
30
|
-
async process(input, options) {
|
|
31
|
-
const { definition: { function: func }, context, } = this;
|
|
32
|
-
if (!func)
|
|
33
|
-
throw new Error("Function is required");
|
|
34
|
-
if (!context)
|
|
35
|
-
throw new Error("Context is required");
|
|
36
|
-
return await func(input, { ...options, context });
|
|
37
|
-
}
|
|
38
|
-
};
|
|
39
|
-
exports.FunctionAgent = FunctionAgent;
|
|
40
|
-
exports.FunctionAgent = FunctionAgent = __decorate([
|
|
41
|
-
(0, tsyringe_1.injectable)(),
|
|
42
|
-
__param(0, (0, tsyringe_1.inject)(constants_1.TYPES.definition)),
|
|
43
|
-
__param(1, (0, tsyringe_1.inject)(constants_1.TYPES.context)),
|
|
44
|
-
__metadata("design:paramtypes", [Object, Object])
|
|
45
|
-
], FunctionAgent);
|
|
46
|
-
function create(options) {
|
|
47
|
-
const agentId = options.name || (0, nanoid_1.nanoid)();
|
|
48
|
-
const inputs = (0, data_schema_1.schemaToDataType)(options.inputs);
|
|
49
|
-
const outputs = (0, data_schema_1.schemaToDataType)(options.outputs);
|
|
50
|
-
const preloads = (0, preload_1.preloadCreatorsToPreloads)(inputs, options.preloads);
|
|
51
|
-
const memories = (0, memory_1.toRunnableMemories)(agentId, inputs, options.memories || {});
|
|
52
|
-
return new FunctionAgent({
|
|
53
|
-
id: agentId,
|
|
54
|
-
name: options.name,
|
|
55
|
-
type: "function_agent",
|
|
56
|
-
inputs,
|
|
57
|
-
outputs,
|
|
58
|
-
preloads,
|
|
59
|
-
memories,
|
|
60
|
-
function: options.function,
|
|
61
|
-
}, options.context);
|
|
62
|
-
}
|
package/lib/cjs/llm-agent.d.ts
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
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
|
-
import type { Context, ContextState } from "./context";
|
|
3
|
-
import { type SchemaToType } from "./definitions/data-schema";
|
|
4
|
-
import type { LLMModel, LLMModelInputMessage, LLMModelInputs } from "./llm-model";
|
|
5
|
-
import { type RunnableInput, type RunnableOutput } from "./runnable";
|
|
6
|
-
import { OrderedRecord } from "./utils/ordered-map";
|
|
7
|
-
export declare class LLMAgent<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> {
|
|
8
|
-
definition: LLMAgentDefinition;
|
|
9
|
-
model?: LLMModel | undefined;
|
|
10
|
-
static create: typeof create;
|
|
11
|
-
constructor(definition: LLMAgentDefinition, context?: Context<State>, model?: LLMModel | undefined);
|
|
12
|
-
process(input: AgentProcessInput<I, Preloads, Memories>, options: AgentProcessOptions): AsyncGenerator<{
|
|
13
|
-
$text: string | undefined;
|
|
14
|
-
delta?: undefined;
|
|
15
|
-
} | {
|
|
16
|
-
delta: any;
|
|
17
|
-
$text?: undefined;
|
|
18
|
-
}, void, unknown>;
|
|
19
|
-
private runWithStructuredOutput;
|
|
20
|
-
private runWithTextOutput;
|
|
21
|
-
}
|
|
22
|
-
export interface LLMAgentDefinition extends AgentDefinition {
|
|
23
|
-
type: "llm_agent";
|
|
24
|
-
primaryMemoryId?: string;
|
|
25
|
-
messages?: OrderedRecord<LLMModelInputMessage & {
|
|
26
|
-
id: string;
|
|
27
|
-
}>;
|
|
28
|
-
modelOptions?: LLMModelInputs["modelOptions"];
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* Create LLMAgent definition.
|
|
32
|
-
* @param options Options to create LLMAgent.
|
|
33
|
-
* @returns LLMAgent definition.
|
|
34
|
-
*/
|
|
35
|
-
declare function create<I extends CreateAgentInputSchema, O extends CreateAgentOutputSchema, State extends ContextState, Preloads extends CreateAgentPreloadsSchema<I>, Memories extends CreateAgentMemoriesSchema<I, {
|
|
36
|
-
/**
|
|
37
|
-
* Whether this memory is primary? Primary memory will be passed as messages to LLM chat model,
|
|
38
|
-
* otherwise, it will be placed in a system message.
|
|
39
|
-
*
|
|
40
|
-
* Only one primary memory is allowed.
|
|
41
|
-
*/
|
|
42
|
-
primary?: boolean;
|
|
43
|
-
}>>(options: CreateAgentOptions<I, O, State, Preloads, Memories> & {
|
|
44
|
-
/**
|
|
45
|
-
* Options for LLM chat model.
|
|
46
|
-
*/
|
|
47
|
-
modelOptions?: LLMModelInputs["modelOptions"];
|
|
48
|
-
/**
|
|
49
|
-
* Messages to be passed to LLM chat model.
|
|
50
|
-
*/
|
|
51
|
-
messages?: LLMModelInputMessage[];
|
|
52
|
-
}): LLMAgent<SchemaToType<I>, SchemaToType<O>, State, CreateAgentPreloadsType<I, Preloads>, CreateAgentMemoriesType<I, Memories>>;
|
|
53
|
-
export {};
|
package/lib/cjs/llm-agent.js
DELETED
|
@@ -1,140 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
-
};
|
|
8
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
-
};
|
|
11
|
-
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
-
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
-
};
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.LLMAgent = void 0;
|
|
16
|
-
const nanoid_1 = require("nanoid");
|
|
17
|
-
const tsyringe_1 = require("tsyringe");
|
|
18
|
-
const agent_1 = require("./agent");
|
|
19
|
-
const constants_1 = require("./constants");
|
|
20
|
-
const data_schema_1 = require("./definitions/data-schema");
|
|
21
|
-
const memory_1 = require("./definitions/memory");
|
|
22
|
-
const preload_1 = require("./definitions/preload");
|
|
23
|
-
const runnable_1 = require("./runnable");
|
|
24
|
-
const message_utils_1 = require("./utils/message-utils");
|
|
25
|
-
const mustache_utils_1 = require("./utils/mustache-utils");
|
|
26
|
-
const ordered_map_1 = require("./utils/ordered-map");
|
|
27
|
-
const structured_output_schema_1 = require("./utils/structured-output-schema");
|
|
28
|
-
let LLMAgent = class LLMAgent extends agent_1.Agent {
|
|
29
|
-
definition;
|
|
30
|
-
model;
|
|
31
|
-
static create = create;
|
|
32
|
-
constructor(definition, context, model) {
|
|
33
|
-
super(definition, context);
|
|
34
|
-
this.definition = definition;
|
|
35
|
-
this.model = model;
|
|
36
|
-
this.model ??= context?.resolveDependency(constants_1.TYPES.llmModel);
|
|
37
|
-
}
|
|
38
|
-
async *process(input, options) {
|
|
39
|
-
const { definition, model } = this;
|
|
40
|
-
if (!model)
|
|
41
|
-
throw new Error("LLM model is required");
|
|
42
|
-
const { originalMessages, messagesWithMemory } = (0, message_utils_1.prepareMessages)(definition, input, options.memories);
|
|
43
|
-
const llmInputs = {
|
|
44
|
-
messages: messagesWithMemory,
|
|
45
|
-
modelOptions: definition.modelOptions,
|
|
46
|
-
};
|
|
47
|
-
let $text = "";
|
|
48
|
-
const hasTextOutput = ordered_map_1.OrderedRecord.find(definition.outputs, (i) => i.name === constants_1.StreamTextOutputName);
|
|
49
|
-
if (hasTextOutput) {
|
|
50
|
-
for await (const chunk of await this.runWithTextOutput(llmInputs)) {
|
|
51
|
-
if ((0, runnable_1.isRunnableResponseDelta)(chunk)) {
|
|
52
|
-
$text += chunk.$text || "";
|
|
53
|
-
yield { $text: chunk.$text };
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
const json = await this.runWithStructuredOutput(llmInputs);
|
|
58
|
-
if (json)
|
|
59
|
-
yield { delta: json };
|
|
60
|
-
await this.updateMemories([
|
|
61
|
-
...originalMessages,
|
|
62
|
-
{
|
|
63
|
-
role: "assistant",
|
|
64
|
-
content: (0, mustache_utils_1.renderMessage)("{{$text}}\n{{json}}", { $text, json }).trim(),
|
|
65
|
-
},
|
|
66
|
-
]);
|
|
67
|
-
}
|
|
68
|
-
async runWithStructuredOutput(llmInputs) {
|
|
69
|
-
const jsonOutputs = ordered_map_1.OrderedRecord.filter(this.definition.outputs, (i) => i.name !== constants_1.StreamTextOutputName);
|
|
70
|
-
if (!jsonOutputs.length)
|
|
71
|
-
return null;
|
|
72
|
-
const schema = (0, structured_output_schema_1.outputsToJsonSchema)(ordered_map_1.OrderedRecord.fromArray(jsonOutputs));
|
|
73
|
-
const { model } = this;
|
|
74
|
-
if (!model)
|
|
75
|
-
throw new Error("LLM model is required");
|
|
76
|
-
const response = await model.run({
|
|
77
|
-
...llmInputs,
|
|
78
|
-
responseFormat: {
|
|
79
|
-
type: "json_schema",
|
|
80
|
-
jsonSchema: {
|
|
81
|
-
name: "output",
|
|
82
|
-
schema,
|
|
83
|
-
strict: true,
|
|
84
|
-
},
|
|
85
|
-
},
|
|
86
|
-
});
|
|
87
|
-
if (!response.$text)
|
|
88
|
-
throw new Error("No text in JSON mode response");
|
|
89
|
-
return JSON.parse(response.$text);
|
|
90
|
-
}
|
|
91
|
-
async runWithTextOutput(llmInputs) {
|
|
92
|
-
const { model } = this;
|
|
93
|
-
if (!model)
|
|
94
|
-
throw new Error("LLM model is required");
|
|
95
|
-
return model.run(llmInputs, { stream: true });
|
|
96
|
-
}
|
|
97
|
-
};
|
|
98
|
-
exports.LLMAgent = LLMAgent;
|
|
99
|
-
exports.LLMAgent = LLMAgent = __decorate([
|
|
100
|
-
(0, tsyringe_1.injectable)(),
|
|
101
|
-
__param(0, (0, tsyringe_1.inject)(constants_1.TYPES.definition)),
|
|
102
|
-
__param(1, (0, tsyringe_1.inject)(constants_1.TYPES.context)),
|
|
103
|
-
__param(2, (0, tsyringe_1.inject)(constants_1.TYPES.llmModel)),
|
|
104
|
-
__metadata("design:paramtypes", [Object, Object, Function])
|
|
105
|
-
], LLMAgent);
|
|
106
|
-
/**
|
|
107
|
-
* Create LLMAgent definition.
|
|
108
|
-
* @param options Options to create LLMAgent.
|
|
109
|
-
* @returns LLMAgent definition.
|
|
110
|
-
*/
|
|
111
|
-
function create(options) {
|
|
112
|
-
const agentId = options.name || (0, nanoid_1.nanoid)();
|
|
113
|
-
const inputs = (0, data_schema_1.schemaToDataType)(options.inputs);
|
|
114
|
-
const outputs = (0, data_schema_1.schemaToDataType)(options.outputs);
|
|
115
|
-
const preloads = (0, preload_1.preloadCreatorsToPreloads)(inputs, options.preloads);
|
|
116
|
-
const memories = (0, memory_1.toRunnableMemories)(agentId, inputs, options.memories ?? {});
|
|
117
|
-
const primaryMemoryNames = Object.entries(options.memories ?? {})
|
|
118
|
-
.filter(([, i]) => i.primary)
|
|
119
|
-
.map(([name]) => name);
|
|
120
|
-
if (primaryMemoryNames && primaryMemoryNames.length > 1) {
|
|
121
|
-
throw new Error("Only one primary memory is allowed");
|
|
122
|
-
}
|
|
123
|
-
const messages = ordered_map_1.OrderedRecord.fromArray(options.messages?.map((i) => ({
|
|
124
|
-
id: (0, nanoid_1.nanoid)(),
|
|
125
|
-
role: i.role,
|
|
126
|
-
content: i.content,
|
|
127
|
-
})));
|
|
128
|
-
return new LLMAgent({
|
|
129
|
-
id: agentId,
|
|
130
|
-
name: options.name,
|
|
131
|
-
type: "llm_agent",
|
|
132
|
-
inputs,
|
|
133
|
-
outputs,
|
|
134
|
-
preloads,
|
|
135
|
-
primaryMemoryId: primaryMemoryNames?.at(0),
|
|
136
|
-
memories,
|
|
137
|
-
modelOptions: options.modelOptions,
|
|
138
|
-
messages,
|
|
139
|
-
}, options.context);
|
|
140
|
-
}
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import { Agent, type AgentDefinition, type AgentMemories, type AgentPreloads, type AgentProcessInput, type AgentProcessOptions, type CreateAgentMemoriesSchema, type CreateAgentMemoriesType, type CreateAgentOptions, type CreateAgentPreloadsSchema, type CreateAgentPreloadsType } from "./agent";
|
|
2
|
-
import type { Context, ContextState } from "./context";
|
|
3
|
-
import type { TypeToSchema } from "./definitions/data-schema";
|
|
4
|
-
import type { BindAgentInput, BoundAgent, OmitBoundAgentInput } from "./definitions/preload";
|
|
5
|
-
import type { LLMAgentDefinition } from "./llm-agent";
|
|
6
|
-
import type { LLMModel, LLMModelInputMessage, LLMModelInputs } from "./llm-model";
|
|
7
|
-
import type { RunnableInput, RunnableOutput } from "./runnable";
|
|
8
|
-
import { OrderedRecord } from "./utils";
|
|
9
|
-
import type { ExtractRunnableInputTypeIntersection, ExtractRunnableOutputType } from "./utils/runnable-type";
|
|
10
|
-
export declare class LLMDecisionAgent<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> {
|
|
11
|
-
definition: LLMDecisionAgentDefinition;
|
|
12
|
-
model?: LLMModel | undefined;
|
|
13
|
-
static create: typeof create;
|
|
14
|
-
constructor(definition: LLMDecisionAgentDefinition, context?: Context<State>, model?: LLMModel | undefined);
|
|
15
|
-
process(input: AgentProcessInput<I, Preloads, Memories>, options: AgentProcessOptions<Preloads, Memories>): Promise<import("./runnable").RunnableResponse<O>>;
|
|
16
|
-
}
|
|
17
|
-
declare function create<Case extends BoundAgent, InputType extends ExtractRunnableInputTypeIntersection<Case["runnable"]>, OutputType extends ExtractRunnableOutputType<Case["runnable"]>, State extends ContextState, Preloads extends CreateAgentPreloadsSchema<TypeToSchema<InputType>>, Memories extends CreateAgentMemoriesSchema<TypeToSchema<InputType>, {
|
|
18
|
-
/**
|
|
19
|
-
* Whether this memory is primary? Primary memory will be passed as messages to LLM chat model,
|
|
20
|
-
* otherwise, it will be placed in a system message.
|
|
21
|
-
*
|
|
22
|
-
* Only one primary memory is allowed.
|
|
23
|
-
*/
|
|
24
|
-
primary?: boolean;
|
|
25
|
-
}>>(options: Omit<CreateAgentOptions<never, never, State, Preloads, Memories>, "inputs" | "outputs"> & {
|
|
26
|
-
cases: {
|
|
27
|
-
[name: string]: Case;
|
|
28
|
-
};
|
|
29
|
-
/**
|
|
30
|
-
* Options for LLM chat model.
|
|
31
|
-
*/
|
|
32
|
-
modelOptions?: LLMModelInputs["modelOptions"];
|
|
33
|
-
/**
|
|
34
|
-
* Messages to be passed to LLM chat model.
|
|
35
|
-
*/
|
|
36
|
-
messages?: LLMModelInputMessage[];
|
|
37
|
-
}): LLMDecisionAgent<OmitBoundAgentInput<Case, "ai">, OutputType, State, CreateAgentPreloadsType<TypeToSchema<InputType>, Preloads>, CreateAgentMemoriesType<TypeToSchema<InputType>, Memories>>;
|
|
38
|
-
export interface LLMDecisionAgentDefinition extends AgentDefinition, Pick<LLMAgentDefinition, "modelOptions" | "messages" | "primaryMemoryId"> {
|
|
39
|
-
type: "llm_decision_agent";
|
|
40
|
-
cases?: OrderedRecord<LLMDecisionCase>;
|
|
41
|
-
}
|
|
42
|
-
export interface LLMDecisionCase {
|
|
43
|
-
id: string;
|
|
44
|
-
name?: string;
|
|
45
|
-
description?: string;
|
|
46
|
-
runnable?: {
|
|
47
|
-
id?: string;
|
|
48
|
-
};
|
|
49
|
-
input?: {
|
|
50
|
-
[inputId: string]: BindAgentInput;
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
export {};
|