@aigne/core 1.0.4 → 1.0.6
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/constants.d.ts +1 -1
- package/lib/cjs/constants.js +1 -1
- package/lib/cjs/definitions/open-api.d.ts +1 -1
- package/lib/cjs/function-agent.d.ts +29 -14
- package/lib/cjs/function-agent.js +8 -23
- package/lib/cjs/index.d.ts +2 -2
- package/lib/cjs/index.js +2 -2
- package/lib/cjs/runtime.d.ts +2 -2
- package/lib/cjs/runtime.js +8 -6
- package/lib/cjs/sandbox-function-agent.d.ts +49 -0
- package/lib/cjs/{local-function-agent.js → sandbox-function-agent.js} +30 -15
- package/lib/cjs/{function-runner.d.ts → sandbox-function-runner.d.ts} +4 -4
- package/lib/cjs/{function-runner.js → sandbox-function-runner.js} +6 -6
- package/lib/cjs/utils/open-api-parameter.js +1 -1
- package/lib/dts/constants.d.ts +1 -1
- package/lib/dts/definitions/open-api.d.ts +1 -1
- package/lib/dts/function-agent.d.ts +29 -14
- package/lib/dts/index.d.ts +2 -2
- package/lib/dts/runtime.d.ts +2 -2
- package/lib/dts/sandbox-function-agent.d.ts +49 -0
- package/lib/dts/{function-runner.d.ts → sandbox-function-runner.d.ts} +4 -4
- package/lib/esm/constants.d.ts +1 -1
- package/lib/esm/constants.js +1 -1
- package/lib/esm/definitions/open-api.d.ts +1 -1
- package/lib/esm/function-agent.d.ts +29 -14
- package/lib/esm/function-agent.js +9 -23
- package/lib/esm/index.d.ts +2 -2
- package/lib/esm/index.js +2 -2
- package/lib/esm/runtime.d.ts +2 -2
- package/lib/esm/runtime.js +8 -6
- package/lib/esm/sandbox-function-agent.d.ts +49 -0
- package/lib/esm/{local-function-agent.js → sandbox-function-agent.js} +29 -15
- package/lib/esm/{function-runner.d.ts → sandbox-function-runner.d.ts} +4 -4
- package/lib/esm/{function-runner.js → sandbox-function-runner.js} +4 -4
- package/lib/esm/utils/open-api-parameter.js +1 -1
- package/package.json +1 -1
- package/lib/cjs/local-function-agent.d.ts +0 -64
- package/lib/dts/local-function-agent.d.ts +0 -64
- package/lib/esm/local-function-agent.d.ts +0 -64
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Agent } from "./agent";
|
|
2
2
|
import type { Context, ContextState } from "./context";
|
|
3
3
|
import type { MemoryItemWithScore } from "./memorable";
|
|
4
|
-
export interface
|
|
4
|
+
export interface SandboxFunctionRunnerInput<I extends {
|
|
5
5
|
[name: string]: any;
|
|
6
6
|
} = {}, Memories extends {
|
|
7
7
|
[name: string]: MemoryItemWithScore[];
|
|
@@ -13,13 +13,13 @@ export interface FunctionRunnerInput<I extends {
|
|
|
13
13
|
memories: Memories;
|
|
14
14
|
context: Pick<Context<State>, "state">;
|
|
15
15
|
}
|
|
16
|
-
export type
|
|
17
|
-
export declare abstract class
|
|
16
|
+
export type SandboxFunctionRunnerOutput<O> = O;
|
|
17
|
+
export declare abstract class SandboxFunctionRunner<I extends {
|
|
18
18
|
[name: string]: any;
|
|
19
19
|
} = {}, O extends {
|
|
20
20
|
[name: string]: any;
|
|
21
21
|
} = {}, Memories extends {
|
|
22
22
|
[name: string]: MemoryItemWithScore[];
|
|
23
|
-
} = {}, State extends ContextState = ContextState> extends Agent<
|
|
23
|
+
} = {}, State extends ContextState = ContextState> extends Agent<SandboxFunctionRunnerInput<I, Memories, State>, SandboxFunctionRunnerOutput<O>> {
|
|
24
24
|
constructor(context?: Context);
|
|
25
25
|
}
|
package/lib/esm/constants.d.ts
CHANGED
package/lib/esm/constants.js
CHANGED
|
@@ -2,6 +2,6 @@ export const TYPES = {
|
|
|
2
2
|
context: Symbol.for("AIGNE_CONTEXT"),
|
|
3
3
|
definition: Symbol.for("AIGNE_DEFINITION"),
|
|
4
4
|
llmModel: Symbol.for("AIGNE_LLM_MODEL"),
|
|
5
|
-
|
|
5
|
+
sandboxFunctionRunner: Symbol.for("AIGNE_SANDBOX_FUNCTION_RUNNER"),
|
|
6
6
|
};
|
|
7
7
|
export const StreamTextOutputName = "$text";
|
|
@@ -11,7 +11,7 @@ export interface BaseAuthConfig {
|
|
|
11
11
|
}
|
|
12
12
|
export interface CustomAuthConfig {
|
|
13
13
|
type: "custom";
|
|
14
|
-
|
|
14
|
+
auth: () => Promise<AuthResult> | AuthResult;
|
|
15
15
|
}
|
|
16
16
|
export type AuthConfig = BaseAuthConfig | CustomAuthConfig;
|
|
17
17
|
export type AuthType = AuthConfig["type"];
|
|
@@ -2,9 +2,8 @@ import { Agent, type AgentProcessOptions } from "./agent";
|
|
|
2
2
|
import type { Context, ContextState } from "./context";
|
|
3
3
|
import { type DataTypeSchema, type SchemaMapType } from "./definitions/data-type-schema";
|
|
4
4
|
import { type CreateRunnableMemory } from "./definitions/memory";
|
|
5
|
-
import type { FunctionRunner } from "./function-runner";
|
|
6
5
|
import type { MemorableSearchOutput, MemoryItemWithScore } from "./memorable";
|
|
7
|
-
import type { RunnableDefinition } from "./runnable";
|
|
6
|
+
import type { RunnableDefinition, RunnableResponse, RunnableResponseChunk } from "./runnable";
|
|
8
7
|
export declare class FunctionAgent<I extends {
|
|
9
8
|
[name: string]: any;
|
|
10
9
|
} = {}, O extends {
|
|
@@ -12,12 +11,31 @@ export declare class FunctionAgent<I extends {
|
|
|
12
11
|
} = {}, Memories extends {
|
|
13
12
|
[name: string]: MemoryItemWithScore[];
|
|
14
13
|
} = {}, State extends ContextState = ContextState> extends Agent<I, O, Memories, State> {
|
|
15
|
-
definition: FunctionAgentDefinition
|
|
16
|
-
runner?: FunctionRunner<I, O, Memories, State> | undefined;
|
|
14
|
+
definition: FunctionAgentDefinition<I, O, Memories, State>;
|
|
17
15
|
static create: typeof create;
|
|
18
|
-
constructor(definition: FunctionAgentDefinition
|
|
19
|
-
process(input: I, options: AgentProcessOptions<Memories>): Promise<
|
|
16
|
+
constructor(definition: FunctionAgentDefinition<I, O, Memories, State>, context?: Context<State>);
|
|
17
|
+
process(input: I, options: AgentProcessOptions<Memories>): Promise<AsyncGenerator<RunnableResponseChunk<O>, void, any> | RunnableResponse<O>>;
|
|
20
18
|
}
|
|
19
|
+
export interface FunctionAgentDefinition<I extends {
|
|
20
|
+
[name: string]: any;
|
|
21
|
+
}, O extends {
|
|
22
|
+
[name: string]: any;
|
|
23
|
+
}, Memories extends {
|
|
24
|
+
[name: string]: MemoryItemWithScore[];
|
|
25
|
+
}, State extends ContextState> extends RunnableDefinition {
|
|
26
|
+
type: "function_agent";
|
|
27
|
+
function?: FunctionFuncType<I, O, Memories, State>;
|
|
28
|
+
}
|
|
29
|
+
export type FunctionFuncType<I extends {
|
|
30
|
+
[name: string]: any;
|
|
31
|
+
}, O extends {
|
|
32
|
+
[name: string]: any;
|
|
33
|
+
}, Memories extends {
|
|
34
|
+
[name: string]: MemoryItemWithScore[];
|
|
35
|
+
}, State extends ContextState> = (input: I, options: {
|
|
36
|
+
memories: Memories;
|
|
37
|
+
context: Context<State>;
|
|
38
|
+
}) => Promise<RunnableResponse<O> | AsyncGenerator<RunnableResponseChunk<O>, void>> | AsyncGenerator<RunnableResponseChunk<O>, void>;
|
|
21
39
|
export interface CreateFunctionAgentOptions<I extends {
|
|
22
40
|
[name: string]: DataTypeSchema;
|
|
23
41
|
}, O extends {
|
|
@@ -30,10 +48,11 @@ export interface CreateFunctionAgentOptions<I extends {
|
|
|
30
48
|
inputs: I;
|
|
31
49
|
outputs: O;
|
|
32
50
|
memories?: Memories;
|
|
33
|
-
|
|
34
|
-
|
|
51
|
+
function?: FunctionFuncType<SchemaMapType<I>, SchemaMapType<O>, {
|
|
52
|
+
[key in keyof Memories]: MemorableSearchOutput<Memories[key]["memory"]>;
|
|
53
|
+
}, State>;
|
|
35
54
|
}
|
|
36
|
-
|
|
55
|
+
declare function create<I extends {
|
|
37
56
|
[name: string]: DataTypeSchema;
|
|
38
57
|
}, O extends {
|
|
39
58
|
[name: string]: DataTypeSchema;
|
|
@@ -42,8 +61,4 @@ export declare function create<I extends {
|
|
|
42
61
|
}, State extends ContextState>({ context, ...options }: CreateFunctionAgentOptions<I, O, Memories, State>): FunctionAgent<SchemaMapType<I>, SchemaMapType<O>, {
|
|
43
62
|
[name in keyof Memories]: MemorableSearchOutput<Memories[name]["memory"]>;
|
|
44
63
|
}, State>;
|
|
45
|
-
export
|
|
46
|
-
type: "function_agent";
|
|
47
|
-
language?: string;
|
|
48
|
-
code?: string;
|
|
49
|
-
}
|
|
64
|
+
export {};
|
|
@@ -18,45 +18,32 @@ import { schemaToDataType, } from "./definitions/data-type-schema";
|
|
|
18
18
|
import { toRunnableMemories, } from "./definitions/memory";
|
|
19
19
|
let FunctionAgent = class FunctionAgent extends Agent {
|
|
20
20
|
definition;
|
|
21
|
-
runner;
|
|
22
21
|
static create = create;
|
|
23
|
-
constructor(definition, context
|
|
22
|
+
constructor(definition, context) {
|
|
24
23
|
super(definition, context);
|
|
25
24
|
this.definition = definition;
|
|
26
|
-
this.runner = runner;
|
|
27
|
-
this.runner ??= context?.resolveDependency(TYPES.functionRunner);
|
|
28
25
|
}
|
|
29
26
|
async process(input, options) {
|
|
30
|
-
const { definition: {
|
|
31
|
-
if (!
|
|
32
|
-
throw new Error("Function
|
|
33
|
-
if (!code)
|
|
34
|
-
throw new Error("Code is required");
|
|
27
|
+
const { definition: { function: func }, context, } = this;
|
|
28
|
+
if (!func)
|
|
29
|
+
throw new Error("Function is required");
|
|
35
30
|
if (!context)
|
|
36
31
|
throw new Error("Context is required");
|
|
37
|
-
return await
|
|
38
|
-
name: definition.name || definition.id,
|
|
39
|
-
language,
|
|
40
|
-
code,
|
|
41
|
-
input,
|
|
42
|
-
memories: options.memories,
|
|
43
|
-
context: { state: context.state },
|
|
44
|
-
}, { stream: true });
|
|
32
|
+
return await func(input, { context, memories: options.memories });
|
|
45
33
|
}
|
|
46
34
|
};
|
|
47
35
|
FunctionAgent = __decorate([
|
|
48
36
|
injectable(),
|
|
49
37
|
__param(0, inject(TYPES.definition)),
|
|
50
38
|
__param(1, inject(TYPES.context)),
|
|
51
|
-
|
|
52
|
-
__metadata("design:paramtypes", [Object, Object, Function])
|
|
39
|
+
__metadata("design:paramtypes", [Object, Object])
|
|
53
40
|
], FunctionAgent);
|
|
54
41
|
export { FunctionAgent };
|
|
55
|
-
|
|
42
|
+
function create({ context, ...options }) {
|
|
56
43
|
const agentId = options.name || nanoid();
|
|
57
44
|
const inputs = schemaToDataType(options.inputs);
|
|
58
45
|
const outputs = schemaToDataType(options.outputs);
|
|
59
|
-
const memories = toRunnableMemories(agentId, inputs, options.memories
|
|
46
|
+
const memories = toRunnableMemories(agentId, inputs, options.memories || {});
|
|
60
47
|
return new FunctionAgent({
|
|
61
48
|
id: agentId,
|
|
62
49
|
name: options.name,
|
|
@@ -64,7 +51,6 @@ export function create({ context, ...options }) {
|
|
|
64
51
|
inputs,
|
|
65
52
|
outputs,
|
|
66
53
|
memories,
|
|
67
|
-
|
|
68
|
-
code: options.code,
|
|
54
|
+
function: options.function,
|
|
69
55
|
}, context);
|
|
70
56
|
}
|
package/lib/esm/index.d.ts
CHANGED
|
@@ -6,16 +6,16 @@ export * from "./definitions/data-type-schema";
|
|
|
6
6
|
export * from "./definitions/memory";
|
|
7
7
|
export * from "./definitions/open-api";
|
|
8
8
|
export * from "./function-agent";
|
|
9
|
-
export * from "./function-runner";
|
|
10
9
|
export * from "./llm-agent";
|
|
11
10
|
export * from "./llm-decision-agent";
|
|
12
11
|
export * from "./llm-model";
|
|
13
12
|
export * from "./llm-models/gemini-llm-model";
|
|
14
13
|
export * from "./llm-models/openai-llm-model";
|
|
15
|
-
export * from "./local-function-agent";
|
|
16
14
|
export * from "./memorable";
|
|
17
15
|
export * from "./open-api-agent";
|
|
18
16
|
export * from "./pipeline-agent";
|
|
19
17
|
export * from "./runnable";
|
|
20
18
|
export * from "./runtime";
|
|
19
|
+
export * from "./sandbox-function-agent";
|
|
20
|
+
export * from "./sandbox-function-runner";
|
|
21
21
|
export * from "./utils";
|
package/lib/esm/index.js
CHANGED
|
@@ -6,16 +6,16 @@ export * from "./definitions/data-type-schema";
|
|
|
6
6
|
export * from "./definitions/memory";
|
|
7
7
|
export * from "./definitions/open-api";
|
|
8
8
|
export * from "./function-agent";
|
|
9
|
-
export * from "./function-runner";
|
|
10
9
|
export * from "./llm-agent";
|
|
11
10
|
export * from "./llm-decision-agent";
|
|
12
11
|
export * from "./llm-model";
|
|
13
12
|
export * from "./llm-models/gemini-llm-model";
|
|
14
13
|
export * from "./llm-models/openai-llm-model";
|
|
15
|
-
export * from "./local-function-agent";
|
|
16
14
|
export * from "./memorable";
|
|
17
15
|
export * from "./open-api-agent";
|
|
18
16
|
export * from "./pipeline-agent";
|
|
19
17
|
export * from "./runnable";
|
|
20
18
|
export * from "./runtime";
|
|
19
|
+
export * from "./sandbox-function-agent";
|
|
20
|
+
export * from "./sandbox-function-runner";
|
|
21
21
|
export * from "./utils";
|
package/lib/esm/runtime.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { type DependencyContainer } from "tsyringe";
|
|
2
2
|
import type { constructor as Constructor } from "tsyringe/dist/typings/types";
|
|
3
3
|
import type { Context, ContextState } from "./context";
|
|
4
|
-
import type { FunctionRunner } from "./function-runner";
|
|
5
4
|
import type { LLMModel, LLMModelConfiguration } from "./llm-model";
|
|
6
5
|
import { Runnable, type RunnableDefinition } from "./runnable";
|
|
6
|
+
import type { SandboxFunctionRunner } from "./sandbox-function-runner";
|
|
7
7
|
import { OrderedRecord } from "./utils/ordered-map";
|
|
8
8
|
import type { DeepPartial } from "./utils/partial";
|
|
9
9
|
export interface RuntimeConfiguration {
|
|
@@ -18,7 +18,7 @@ export interface RuntimeOptions<Agents extends {
|
|
|
18
18
|
state?: State;
|
|
19
19
|
agents?: Agents;
|
|
20
20
|
llmModel?: LLMModel | Constructor<LLMModel>;
|
|
21
|
-
|
|
21
|
+
sandboxFunctionRunner?: SandboxFunctionRunner | Constructor<SandboxFunctionRunner>;
|
|
22
22
|
}
|
|
23
23
|
export declare class Runtime<Agents extends {
|
|
24
24
|
[name: string]: Runnable;
|
package/lib/esm/runtime.js
CHANGED
|
@@ -16,10 +16,10 @@ import { TYPES } from "./constants";
|
|
|
16
16
|
import { FunctionAgent } from "./function-agent";
|
|
17
17
|
import { LLMAgent } from "./llm-agent";
|
|
18
18
|
import { LLMDecisionAgent } from "./llm-decision-agent";
|
|
19
|
-
import { LocalFunctionAgent } from "./local-function-agent";
|
|
20
19
|
import { OpenAPIAgent } from "./open-api-agent";
|
|
21
20
|
import { PipelineAgent } from "./pipeline-agent";
|
|
22
21
|
import { Runnable } from "./runnable";
|
|
22
|
+
import { SandboxFunctionAgent } from "./sandbox-function-agent";
|
|
23
23
|
import { OrderedRecord } from "./utils/ordered-map";
|
|
24
24
|
let Runtime = Runtime_1 = class Runtime {
|
|
25
25
|
constructor(options = {}) {
|
|
@@ -111,16 +111,18 @@ class RuntimeInner {
|
|
|
111
111
|
this.state = options.state || {};
|
|
112
112
|
this.container.register("pipeline_agent", { useClass: PipelineAgent });
|
|
113
113
|
this.container.register("llm_agent", { useClass: LLMAgent });
|
|
114
|
-
this.container.register("
|
|
114
|
+
this.container.register("sandbox_function_agent", {
|
|
115
|
+
useClass: SandboxFunctionAgent,
|
|
116
|
+
});
|
|
115
117
|
this.container.register("llm_decision_agent", {
|
|
116
118
|
useClass: LLMDecisionAgent,
|
|
117
119
|
});
|
|
118
|
-
this.container.register("
|
|
119
|
-
useClass:
|
|
120
|
+
this.container.register("function_agent", {
|
|
121
|
+
useClass: FunctionAgent,
|
|
120
122
|
});
|
|
121
123
|
this.container.register("open_api_agent", { useClass: OpenAPIAgent });
|
|
122
|
-
if (options.
|
|
123
|
-
this.registerDependency(TYPES.
|
|
124
|
+
if (options.sandboxFunctionRunner)
|
|
125
|
+
this.registerDependency(TYPES.sandboxFunctionRunner, options.sandboxFunctionRunner);
|
|
124
126
|
if (options.llmModel)
|
|
125
127
|
this.registerDependency(TYPES.llmModel, options.llmModel);
|
|
126
128
|
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { Agent, type AgentProcessOptions } from "./agent";
|
|
2
|
+
import type { Context, ContextState } from "./context";
|
|
3
|
+
import { type DataTypeSchema, type SchemaMapType } from "./definitions/data-type-schema";
|
|
4
|
+
import { type CreateRunnableMemory } from "./definitions/memory";
|
|
5
|
+
import type { MemorableSearchOutput, MemoryItemWithScore } from "./memorable";
|
|
6
|
+
import type { RunnableDefinition } from "./runnable";
|
|
7
|
+
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> {
|
|
15
|
+
definition: SandboxFunctionAgentDefinition;
|
|
16
|
+
runner?: SandboxFunctionRunner<I, O, Memories, State> | undefined;
|
|
17
|
+
static create: typeof create;
|
|
18
|
+
constructor(definition: SandboxFunctionAgentDefinition, context?: Context<State>, runner?: SandboxFunctionRunner<I, O, Memories, State> | undefined);
|
|
19
|
+
process(input: I, options: AgentProcessOptions<Memories>): Promise<import("./runnable").RunnableResponseStream<O>>;
|
|
20
|
+
}
|
|
21
|
+
export interface CreateSandboxFunctionAgentOptions<I extends {
|
|
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;
|
|
33
|
+
language?: string;
|
|
34
|
+
code: string;
|
|
35
|
+
}
|
|
36
|
+
export declare function create<I extends {
|
|
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 {
|
|
46
|
+
type: "sandbox_function_agent";
|
|
47
|
+
language?: string;
|
|
48
|
+
code?: string;
|
|
49
|
+
}
|
|
@@ -16,41 +16,55 @@ import { Agent } from "./agent";
|
|
|
16
16
|
import { TYPES } from "./constants";
|
|
17
17
|
import { schemaToDataType, } from "./definitions/data-type-schema";
|
|
18
18
|
import { toRunnableMemories, } from "./definitions/memory";
|
|
19
|
-
let
|
|
19
|
+
let SandboxFunctionAgent = class SandboxFunctionAgent extends Agent {
|
|
20
20
|
definition;
|
|
21
|
+
runner;
|
|
21
22
|
static create = create;
|
|
22
|
-
constructor(definition, context) {
|
|
23
|
+
constructor(definition, context, runner) {
|
|
23
24
|
super(definition, context);
|
|
24
25
|
this.definition = definition;
|
|
26
|
+
this.runner = runner;
|
|
27
|
+
this.runner ??= context?.resolveDependency(TYPES.sandboxFunctionRunner);
|
|
25
28
|
}
|
|
26
29
|
async process(input, options) {
|
|
27
|
-
const { definition: {
|
|
28
|
-
if (!
|
|
29
|
-
throw new Error("
|
|
30
|
+
const { definition: { language, code, ...definition }, runner, context, } = this;
|
|
31
|
+
if (!runner)
|
|
32
|
+
throw new Error("Sandbox function runner is required");
|
|
33
|
+
if (!code)
|
|
34
|
+
throw new Error("Code is required");
|
|
30
35
|
if (!context)
|
|
31
36
|
throw new Error("Context is required");
|
|
32
|
-
return await
|
|
37
|
+
return await runner.run({
|
|
38
|
+
name: definition.name || definition.id,
|
|
39
|
+
language,
|
|
40
|
+
code,
|
|
41
|
+
input,
|
|
42
|
+
memories: options.memories,
|
|
43
|
+
context: { state: context.state },
|
|
44
|
+
}, { stream: true });
|
|
33
45
|
}
|
|
34
46
|
};
|
|
35
|
-
|
|
47
|
+
SandboxFunctionAgent = __decorate([
|
|
36
48
|
injectable(),
|
|
37
49
|
__param(0, inject(TYPES.definition)),
|
|
38
50
|
__param(1, inject(TYPES.context)),
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
51
|
+
__param(2, inject(TYPES.sandboxFunctionRunner)),
|
|
52
|
+
__metadata("design:paramtypes", [Object, Object, Function])
|
|
53
|
+
], SandboxFunctionAgent);
|
|
54
|
+
export { SandboxFunctionAgent };
|
|
55
|
+
export function create({ context, ...options }) {
|
|
43
56
|
const agentId = options.name || nanoid();
|
|
44
57
|
const inputs = schemaToDataType(options.inputs);
|
|
45
58
|
const outputs = schemaToDataType(options.outputs);
|
|
46
|
-
const memories = toRunnableMemories(agentId, inputs, options.memories
|
|
47
|
-
return new
|
|
59
|
+
const memories = toRunnableMemories(agentId, inputs, options.memories ?? {});
|
|
60
|
+
return new SandboxFunctionAgent({
|
|
48
61
|
id: agentId,
|
|
49
62
|
name: options.name,
|
|
50
|
-
type: "
|
|
63
|
+
type: "sandbox_function_agent",
|
|
51
64
|
inputs,
|
|
52
65
|
outputs,
|
|
53
66
|
memories,
|
|
54
|
-
|
|
67
|
+
language: options.language,
|
|
68
|
+
code: options.code,
|
|
55
69
|
}, context);
|
|
56
70
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Agent } from "./agent";
|
|
2
2
|
import type { Context, ContextState } from "./context";
|
|
3
3
|
import type { MemoryItemWithScore } from "./memorable";
|
|
4
|
-
export interface
|
|
4
|
+
export interface SandboxFunctionRunnerInput<I extends {
|
|
5
5
|
[name: string]: any;
|
|
6
6
|
} = {}, Memories extends {
|
|
7
7
|
[name: string]: MemoryItemWithScore[];
|
|
@@ -13,13 +13,13 @@ export interface FunctionRunnerInput<I extends {
|
|
|
13
13
|
memories: Memories;
|
|
14
14
|
context: Pick<Context<State>, "state">;
|
|
15
15
|
}
|
|
16
|
-
export type
|
|
17
|
-
export declare abstract class
|
|
16
|
+
export type SandboxFunctionRunnerOutput<O> = O;
|
|
17
|
+
export declare abstract class SandboxFunctionRunner<I extends {
|
|
18
18
|
[name: string]: any;
|
|
19
19
|
} = {}, O extends {
|
|
20
20
|
[name: string]: any;
|
|
21
21
|
} = {}, Memories extends {
|
|
22
22
|
[name: string]: MemoryItemWithScore[];
|
|
23
|
-
} = {}, State extends ContextState = ContextState> extends Agent<
|
|
23
|
+
} = {}, State extends ContextState = ContextState> extends Agent<SandboxFunctionRunnerInput<I, Memories, State>, SandboxFunctionRunnerOutput<O>> {
|
|
24
24
|
constructor(context?: Context);
|
|
25
25
|
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { Agent } from "./agent";
|
|
2
2
|
import { OrderedRecord } from "./utils";
|
|
3
|
-
export class
|
|
3
|
+
export class SandboxFunctionRunner extends Agent {
|
|
4
4
|
constructor(context) {
|
|
5
5
|
super({
|
|
6
|
-
id: "
|
|
7
|
-
type: "
|
|
8
|
-
name: "Function Runner",
|
|
6
|
+
id: "sandbox_function_runner",
|
|
7
|
+
type: "sandbox_function_runner",
|
|
8
|
+
name: "Sandbox Function Runner",
|
|
9
9
|
description: "Run a function",
|
|
10
10
|
inputs: OrderedRecord.fromArray([
|
|
11
11
|
{ id: "name", name: "name", type: "string", required: true },
|
package/package.json
CHANGED
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import { Agent, type AgentProcessOptions } from "./agent";
|
|
2
|
-
import type { Context, ContextState } from "./context";
|
|
3
|
-
import { type DataTypeSchema, type SchemaMapType } from "./definitions/data-type-schema";
|
|
4
|
-
import { type CreateRunnableMemory } from "./definitions/memory";
|
|
5
|
-
import type { MemorableSearchOutput, MemoryItemWithScore } from "./memorable";
|
|
6
|
-
import type { RunnableDefinition, RunnableResponse, RunnableResponseChunk } from "./runnable";
|
|
7
|
-
export declare class LocalFunctionAgent<I extends {
|
|
8
|
-
[name: string]: any;
|
|
9
|
-
} = {}, O extends {
|
|
10
|
-
[name: string]: any;
|
|
11
|
-
} = {}, Memories extends {
|
|
12
|
-
[name: string]: MemoryItemWithScore[];
|
|
13
|
-
} = {}, State extends ContextState = ContextState> extends Agent<I, O, Memories, State> {
|
|
14
|
-
definition: LocalFunctionAgentDefinition<I, O, Memories, State>;
|
|
15
|
-
static create: typeof create;
|
|
16
|
-
constructor(definition: LocalFunctionAgentDefinition<I, O, Memories, State>, context?: Context<State>);
|
|
17
|
-
process(input: I, options: AgentProcessOptions<Memories>): Promise<AsyncGenerator<RunnableResponseChunk<O>, void, any> | RunnableResponse<O>>;
|
|
18
|
-
}
|
|
19
|
-
export interface LocalFunctionAgentDefinition<I extends {
|
|
20
|
-
[name: string]: any;
|
|
21
|
-
}, O extends {
|
|
22
|
-
[name: string]: any;
|
|
23
|
-
}, Memories extends {
|
|
24
|
-
[name: string]: MemoryItemWithScore[];
|
|
25
|
-
}, State extends ContextState> extends RunnableDefinition {
|
|
26
|
-
type: "local_function_agent";
|
|
27
|
-
function?: LocalFunctionFuncType<I, O, Memories, State>;
|
|
28
|
-
}
|
|
29
|
-
export type LocalFunctionFuncType<I extends {
|
|
30
|
-
[name: string]: any;
|
|
31
|
-
}, O extends {
|
|
32
|
-
[name: string]: any;
|
|
33
|
-
}, Memories extends {
|
|
34
|
-
[name: string]: MemoryItemWithScore[];
|
|
35
|
-
}, State extends ContextState> = (input: I, options: {
|
|
36
|
-
memories: Memories;
|
|
37
|
-
context: Context<State>;
|
|
38
|
-
}) => Promise<RunnableResponse<O> | AsyncGenerator<RunnableResponseChunk<O>, void>> | AsyncGenerator<RunnableResponseChunk<O>, void>;
|
|
39
|
-
export interface CreateLocalFunctionAgentOptions<I extends {
|
|
40
|
-
[name: string]: DataTypeSchema;
|
|
41
|
-
}, O extends {
|
|
42
|
-
[name: string]: DataTypeSchema;
|
|
43
|
-
}, Memories extends {
|
|
44
|
-
[name: string]: CreateRunnableMemory<I>;
|
|
45
|
-
}, State extends ContextState> {
|
|
46
|
-
context?: Context<State>;
|
|
47
|
-
name?: string;
|
|
48
|
-
inputs: I;
|
|
49
|
-
outputs: O;
|
|
50
|
-
memories?: Memories;
|
|
51
|
-
function?: LocalFunctionFuncType<SchemaMapType<I>, SchemaMapType<O>, {
|
|
52
|
-
[key in keyof Memories]: MemorableSearchOutput<Memories[key]["memory"]>;
|
|
53
|
-
}, State>;
|
|
54
|
-
}
|
|
55
|
-
declare function create<I extends {
|
|
56
|
-
[name: string]: DataTypeSchema;
|
|
57
|
-
}, O extends {
|
|
58
|
-
[name: string]: DataTypeSchema;
|
|
59
|
-
}, Memories extends {
|
|
60
|
-
[name: string]: CreateRunnableMemory<I>;
|
|
61
|
-
}, State extends ContextState>({ context, ...options }: CreateLocalFunctionAgentOptions<I, O, Memories, State>): LocalFunctionAgent<SchemaMapType<I>, SchemaMapType<O>, {
|
|
62
|
-
[name in keyof Memories]: MemorableSearchOutput<Memories[name]["memory"]>;
|
|
63
|
-
}, State>;
|
|
64
|
-
export {};
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import { Agent, type AgentProcessOptions } from "./agent";
|
|
2
|
-
import type { Context, ContextState } from "./context";
|
|
3
|
-
import { type DataTypeSchema, type SchemaMapType } from "./definitions/data-type-schema";
|
|
4
|
-
import { type CreateRunnableMemory } from "./definitions/memory";
|
|
5
|
-
import type { MemorableSearchOutput, MemoryItemWithScore } from "./memorable";
|
|
6
|
-
import type { RunnableDefinition, RunnableResponse, RunnableResponseChunk } from "./runnable";
|
|
7
|
-
export declare class LocalFunctionAgent<I extends {
|
|
8
|
-
[name: string]: any;
|
|
9
|
-
} = {}, O extends {
|
|
10
|
-
[name: string]: any;
|
|
11
|
-
} = {}, Memories extends {
|
|
12
|
-
[name: string]: MemoryItemWithScore[];
|
|
13
|
-
} = {}, State extends ContextState = ContextState> extends Agent<I, O, Memories, State> {
|
|
14
|
-
definition: LocalFunctionAgentDefinition<I, O, Memories, State>;
|
|
15
|
-
static create: typeof create;
|
|
16
|
-
constructor(definition: LocalFunctionAgentDefinition<I, O, Memories, State>, context?: Context<State>);
|
|
17
|
-
process(input: I, options: AgentProcessOptions<Memories>): Promise<AsyncGenerator<RunnableResponseChunk<O>, void, any> | RunnableResponse<O>>;
|
|
18
|
-
}
|
|
19
|
-
export interface LocalFunctionAgentDefinition<I extends {
|
|
20
|
-
[name: string]: any;
|
|
21
|
-
}, O extends {
|
|
22
|
-
[name: string]: any;
|
|
23
|
-
}, Memories extends {
|
|
24
|
-
[name: string]: MemoryItemWithScore[];
|
|
25
|
-
}, State extends ContextState> extends RunnableDefinition {
|
|
26
|
-
type: "local_function_agent";
|
|
27
|
-
function?: LocalFunctionFuncType<I, O, Memories, State>;
|
|
28
|
-
}
|
|
29
|
-
export type LocalFunctionFuncType<I extends {
|
|
30
|
-
[name: string]: any;
|
|
31
|
-
}, O extends {
|
|
32
|
-
[name: string]: any;
|
|
33
|
-
}, Memories extends {
|
|
34
|
-
[name: string]: MemoryItemWithScore[];
|
|
35
|
-
}, State extends ContextState> = (input: I, options: {
|
|
36
|
-
memories: Memories;
|
|
37
|
-
context: Context<State>;
|
|
38
|
-
}) => Promise<RunnableResponse<O> | AsyncGenerator<RunnableResponseChunk<O>, void>> | AsyncGenerator<RunnableResponseChunk<O>, void>;
|
|
39
|
-
export interface CreateLocalFunctionAgentOptions<I extends {
|
|
40
|
-
[name: string]: DataTypeSchema;
|
|
41
|
-
}, O extends {
|
|
42
|
-
[name: string]: DataTypeSchema;
|
|
43
|
-
}, Memories extends {
|
|
44
|
-
[name: string]: CreateRunnableMemory<I>;
|
|
45
|
-
}, State extends ContextState> {
|
|
46
|
-
context?: Context<State>;
|
|
47
|
-
name?: string;
|
|
48
|
-
inputs: I;
|
|
49
|
-
outputs: O;
|
|
50
|
-
memories?: Memories;
|
|
51
|
-
function?: LocalFunctionFuncType<SchemaMapType<I>, SchemaMapType<O>, {
|
|
52
|
-
[key in keyof Memories]: MemorableSearchOutput<Memories[key]["memory"]>;
|
|
53
|
-
}, State>;
|
|
54
|
-
}
|
|
55
|
-
declare function create<I extends {
|
|
56
|
-
[name: string]: DataTypeSchema;
|
|
57
|
-
}, O extends {
|
|
58
|
-
[name: string]: DataTypeSchema;
|
|
59
|
-
}, Memories extends {
|
|
60
|
-
[name: string]: CreateRunnableMemory<I>;
|
|
61
|
-
}, State extends ContextState>({ context, ...options }: CreateLocalFunctionAgentOptions<I, O, Memories, State>): LocalFunctionAgent<SchemaMapType<I>, SchemaMapType<O>, {
|
|
62
|
-
[name in keyof Memories]: MemorableSearchOutput<Memories[name]["memory"]>;
|
|
63
|
-
}, State>;
|
|
64
|
-
export {};
|