@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.
Files changed (39) hide show
  1. package/lib/cjs/constants.d.ts +1 -1
  2. package/lib/cjs/constants.js +1 -1
  3. package/lib/cjs/definitions/open-api.d.ts +1 -1
  4. package/lib/cjs/function-agent.d.ts +29 -14
  5. package/lib/cjs/function-agent.js +8 -23
  6. package/lib/cjs/index.d.ts +2 -2
  7. package/lib/cjs/index.js +2 -2
  8. package/lib/cjs/runtime.d.ts +2 -2
  9. package/lib/cjs/runtime.js +8 -6
  10. package/lib/cjs/sandbox-function-agent.d.ts +49 -0
  11. package/lib/cjs/{local-function-agent.js → sandbox-function-agent.js} +30 -15
  12. package/lib/cjs/{function-runner.d.ts → sandbox-function-runner.d.ts} +4 -4
  13. package/lib/cjs/{function-runner.js → sandbox-function-runner.js} +6 -6
  14. package/lib/cjs/utils/open-api-parameter.js +1 -1
  15. package/lib/dts/constants.d.ts +1 -1
  16. package/lib/dts/definitions/open-api.d.ts +1 -1
  17. package/lib/dts/function-agent.d.ts +29 -14
  18. package/lib/dts/index.d.ts +2 -2
  19. package/lib/dts/runtime.d.ts +2 -2
  20. package/lib/dts/sandbox-function-agent.d.ts +49 -0
  21. package/lib/dts/{function-runner.d.ts → sandbox-function-runner.d.ts} +4 -4
  22. package/lib/esm/constants.d.ts +1 -1
  23. package/lib/esm/constants.js +1 -1
  24. package/lib/esm/definitions/open-api.d.ts +1 -1
  25. package/lib/esm/function-agent.d.ts +29 -14
  26. package/lib/esm/function-agent.js +9 -23
  27. package/lib/esm/index.d.ts +2 -2
  28. package/lib/esm/index.js +2 -2
  29. package/lib/esm/runtime.d.ts +2 -2
  30. package/lib/esm/runtime.js +8 -6
  31. package/lib/esm/sandbox-function-agent.d.ts +49 -0
  32. package/lib/esm/{local-function-agent.js → sandbox-function-agent.js} +29 -15
  33. package/lib/esm/{function-runner.d.ts → sandbox-function-runner.d.ts} +4 -4
  34. package/lib/esm/{function-runner.js → sandbox-function-runner.js} +4 -4
  35. package/lib/esm/utils/open-api-parameter.js +1 -1
  36. package/package.json +1 -1
  37. package/lib/cjs/local-function-agent.d.ts +0 -64
  38. package/lib/dts/local-function-agent.d.ts +0 -64
  39. package/lib/esm/local-function-agent.d.ts +0 -64
@@ -2,6 +2,6 @@ export declare const TYPES: {
2
2
  context: symbol;
3
3
  definition: symbol;
4
4
  llmModel: symbol;
5
- functionRunner: symbol;
5
+ sandboxFunctionRunner: symbol;
6
6
  };
7
7
  export declare const StreamTextOutputName = "$text";
@@ -5,6 +5,6 @@ exports.TYPES = {
5
5
  context: Symbol.for("AIGNE_CONTEXT"),
6
6
  definition: Symbol.for("AIGNE_DEFINITION"),
7
7
  llmModel: Symbol.for("AIGNE_LLM_MODEL"),
8
- functionRunner: Symbol.for("AIGNE_FUNCTION_RUNNER"),
8
+ sandboxFunctionRunner: Symbol.for("AIGNE_SANDBOX_FUNCTION_RUNNER"),
9
9
  };
10
10
  exports.StreamTextOutputName = "$text";
@@ -11,7 +11,7 @@ export interface BaseAuthConfig {
11
11
  }
12
12
  export interface CustomAuthConfig {
13
13
  type: "custom";
14
- getValue: () => Promise<AuthResult> | AuthResult;
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, context?: Context<State>, runner?: FunctionRunner<I, O, Memories, State> | undefined);
19
- process(input: I, options: AgentProcessOptions<Memories>): Promise<import("./runnable").RunnableResponseStream<O>>;
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
- language?: string;
34
- code: string;
51
+ function?: FunctionFuncType<SchemaMapType<I>, SchemaMapType<O>, {
52
+ [key in keyof Memories]: MemorableSearchOutput<Memories[key]["memory"]>;
53
+ }, State>;
35
54
  }
36
- export declare function create<I extends {
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 interface FunctionAgentDefinition extends RunnableDefinition {
46
- type: "function_agent";
47
- language?: string;
48
- code?: string;
49
- }
64
+ export {};
@@ -13,7 +13,6 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.FunctionAgent = void 0;
16
- exports.create = create;
17
16
  const nanoid_1 = require("nanoid");
18
17
  const tsyringe_1 = require("tsyringe");
19
18
  const agent_1 = require("./agent");
@@ -22,30 +21,18 @@ const data_type_schema_1 = require("./definitions/data-type-schema");
22
21
  const memory_1 = require("./definitions/memory");
23
22
  let FunctionAgent = class FunctionAgent extends agent_1.Agent {
24
23
  definition;
25
- runner;
26
24
  static create = create;
27
- constructor(definition, context, runner) {
25
+ constructor(definition, context) {
28
26
  super(definition, context);
29
27
  this.definition = definition;
30
- this.runner = runner;
31
- this.runner ??= context?.resolveDependency(constants_1.TYPES.functionRunner);
32
28
  }
33
29
  async process(input, options) {
34
- const { definition: { language, code, ...definition }, runner, context, } = this;
35
- if (!runner)
36
- throw new Error("Function runner is required");
37
- if (!code)
38
- throw new Error("Code is required");
30
+ const { definition: { function: func }, context, } = this;
31
+ if (!func)
32
+ throw new Error("Function is required");
39
33
  if (!context)
40
34
  throw new Error("Context is required");
41
- return await runner.run({
42
- name: definition.name || definition.id,
43
- language,
44
- code,
45
- input,
46
- memories: options.memories,
47
- context: { state: context.state },
48
- }, { stream: true });
35
+ return await func(input, { context, memories: options.memories });
49
36
  }
50
37
  };
51
38
  exports.FunctionAgent = FunctionAgent;
@@ -53,14 +40,13 @@ exports.FunctionAgent = FunctionAgent = __decorate([
53
40
  (0, tsyringe_1.injectable)(),
54
41
  __param(0, (0, tsyringe_1.inject)(constants_1.TYPES.definition)),
55
42
  __param(1, (0, tsyringe_1.inject)(constants_1.TYPES.context)),
56
- __param(2, (0, tsyringe_1.inject)(constants_1.TYPES.functionRunner)),
57
- __metadata("design:paramtypes", [Object, Object, Function])
43
+ __metadata("design:paramtypes", [Object, Object])
58
44
  ], FunctionAgent);
59
45
  function create({ context, ...options }) {
60
46
  const agentId = options.name || (0, nanoid_1.nanoid)();
61
47
  const inputs = (0, data_type_schema_1.schemaToDataType)(options.inputs);
62
48
  const outputs = (0, data_type_schema_1.schemaToDataType)(options.outputs);
63
- const memories = (0, memory_1.toRunnableMemories)(agentId, inputs, options.memories ?? {});
49
+ const memories = (0, memory_1.toRunnableMemories)(agentId, inputs, options.memories || {});
64
50
  return new FunctionAgent({
65
51
  id: agentId,
66
52
  name: options.name,
@@ -68,7 +54,6 @@ function create({ context, ...options }) {
68
54
  inputs,
69
55
  outputs,
70
56
  memories,
71
- language: options.language,
72
- code: options.code,
57
+ function: options.function,
73
58
  }, context);
74
59
  }
@@ -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/cjs/index.js CHANGED
@@ -22,16 +22,16 @@ __exportStar(require("./definitions/data-type-schema"), exports);
22
22
  __exportStar(require("./definitions/memory"), exports);
23
23
  __exportStar(require("./definitions/open-api"), exports);
24
24
  __exportStar(require("./function-agent"), exports);
25
- __exportStar(require("./function-runner"), exports);
26
25
  __exportStar(require("./llm-agent"), exports);
27
26
  __exportStar(require("./llm-decision-agent"), exports);
28
27
  __exportStar(require("./llm-model"), exports);
29
28
  __exportStar(require("./llm-models/gemini-llm-model"), exports);
30
29
  __exportStar(require("./llm-models/openai-llm-model"), exports);
31
- __exportStar(require("./local-function-agent"), exports);
32
30
  __exportStar(require("./memorable"), exports);
33
31
  __exportStar(require("./open-api-agent"), exports);
34
32
  __exportStar(require("./pipeline-agent"), exports);
35
33
  __exportStar(require("./runnable"), exports);
36
34
  __exportStar(require("./runtime"), exports);
35
+ __exportStar(require("./sandbox-function-agent"), exports);
36
+ __exportStar(require("./sandbox-function-runner"), exports);
37
37
  __exportStar(require("./utils"), exports);
@@ -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
- functionRunner?: FunctionRunner | Constructor<FunctionRunner>;
21
+ sandboxFunctionRunner?: SandboxFunctionRunner | Constructor<SandboxFunctionRunner>;
22
22
  }
23
23
  export declare class Runtime<Agents extends {
24
24
  [name: string]: Runnable;
@@ -19,10 +19,10 @@ const constants_1 = require("./constants");
19
19
  const function_agent_1 = require("./function-agent");
20
20
  const llm_agent_1 = require("./llm-agent");
21
21
  const llm_decision_agent_1 = require("./llm-decision-agent");
22
- const local_function_agent_1 = require("./local-function-agent");
23
22
  const open_api_agent_1 = require("./open-api-agent");
24
23
  const pipeline_agent_1 = require("./pipeline-agent");
25
24
  const runnable_1 = require("./runnable");
25
+ const sandbox_function_agent_1 = require("./sandbox-function-agent");
26
26
  const ordered_map_1 = require("./utils/ordered-map");
27
27
  let Runtime = Runtime_1 = class Runtime {
28
28
  constructor(options = {}) {
@@ -114,16 +114,18 @@ class RuntimeInner {
114
114
  this.state = options.state || {};
115
115
  this.container.register("pipeline_agent", { useClass: pipeline_agent_1.PipelineAgent });
116
116
  this.container.register("llm_agent", { useClass: llm_agent_1.LLMAgent });
117
- this.container.register("function_agent", { useClass: function_agent_1.FunctionAgent });
117
+ this.container.register("sandbox_function_agent", {
118
+ useClass: sandbox_function_agent_1.SandboxFunctionAgent,
119
+ });
118
120
  this.container.register("llm_decision_agent", {
119
121
  useClass: llm_decision_agent_1.LLMDecisionAgent,
120
122
  });
121
- this.container.register("local_function_agent", {
122
- useClass: local_function_agent_1.LocalFunctionAgent,
123
+ this.container.register("function_agent", {
124
+ useClass: function_agent_1.FunctionAgent,
123
125
  });
124
126
  this.container.register("open_api_agent", { useClass: open_api_agent_1.OpenAPIAgent });
125
- if (options.functionRunner)
126
- this.registerDependency(constants_1.TYPES.functionRunner, options.functionRunner);
127
+ if (options.sandboxFunctionRunner)
128
+ this.registerDependency(constants_1.TYPES.sandboxFunctionRunner, options.sandboxFunctionRunner);
127
129
  if (options.llmModel)
128
130
  this.registerDependency(constants_1.TYPES.llmModel, options.llmModel);
129
131
  }
@@ -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
+ }
@@ -12,48 +12,63 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
12
12
  return function (target, key) { decorator(target, key, paramIndex); }
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.LocalFunctionAgent = void 0;
15
+ exports.SandboxFunctionAgent = void 0;
16
+ exports.create = create;
16
17
  const nanoid_1 = require("nanoid");
17
18
  const tsyringe_1 = require("tsyringe");
18
19
  const agent_1 = require("./agent");
19
20
  const constants_1 = require("./constants");
20
21
  const data_type_schema_1 = require("./definitions/data-type-schema");
21
22
  const memory_1 = require("./definitions/memory");
22
- let LocalFunctionAgent = class LocalFunctionAgent extends agent_1.Agent {
23
+ let SandboxFunctionAgent = class SandboxFunctionAgent extends agent_1.Agent {
23
24
  definition;
25
+ runner;
24
26
  static create = create;
25
- constructor(definition, context) {
27
+ constructor(definition, context, runner) {
26
28
  super(definition, context);
27
29
  this.definition = definition;
30
+ this.runner = runner;
31
+ this.runner ??= context?.resolveDependency(constants_1.TYPES.sandboxFunctionRunner);
28
32
  }
29
33
  async process(input, options) {
30
- const { definition: { function: func }, context, } = this;
31
- if (!func)
32
- throw new Error("Function is required");
34
+ const { definition: { language, code, ...definition }, runner, context, } = this;
35
+ if (!runner)
36
+ throw new Error("Sandbox function runner is required");
37
+ if (!code)
38
+ throw new Error("Code is required");
33
39
  if (!context)
34
40
  throw new Error("Context is required");
35
- return await func(input, { context, memories: options.memories });
41
+ return await runner.run({
42
+ name: definition.name || definition.id,
43
+ language,
44
+ code,
45
+ input,
46
+ memories: options.memories,
47
+ context: { state: context.state },
48
+ }, { stream: true });
36
49
  }
37
50
  };
38
- exports.LocalFunctionAgent = LocalFunctionAgent;
39
- exports.LocalFunctionAgent = LocalFunctionAgent = __decorate([
51
+ exports.SandboxFunctionAgent = SandboxFunctionAgent;
52
+ exports.SandboxFunctionAgent = SandboxFunctionAgent = __decorate([
40
53
  (0, tsyringe_1.injectable)(),
41
54
  __param(0, (0, tsyringe_1.inject)(constants_1.TYPES.definition)),
42
55
  __param(1, (0, tsyringe_1.inject)(constants_1.TYPES.context)),
43
- __metadata("design:paramtypes", [Object, Object])
44
- ], LocalFunctionAgent);
56
+ __param(2, (0, tsyringe_1.inject)(constants_1.TYPES.sandboxFunctionRunner)),
57
+ __metadata("design:paramtypes", [Object, Object, Function])
58
+ ], SandboxFunctionAgent);
45
59
  function create({ context, ...options }) {
46
60
  const agentId = options.name || (0, nanoid_1.nanoid)();
47
61
  const inputs = (0, data_type_schema_1.schemaToDataType)(options.inputs);
48
62
  const outputs = (0, data_type_schema_1.schemaToDataType)(options.outputs);
49
- const memories = (0, memory_1.toRunnableMemories)(agentId, inputs, options.memories || {});
50
- return new LocalFunctionAgent({
63
+ const memories = (0, memory_1.toRunnableMemories)(agentId, inputs, options.memories ?? {});
64
+ return new SandboxFunctionAgent({
51
65
  id: agentId,
52
66
  name: options.name,
53
- type: "local_function_agent",
67
+ type: "sandbox_function_agent",
54
68
  inputs,
55
69
  outputs,
56
70
  memories,
57
- function: options.function,
71
+ language: options.language,
72
+ code: options.code,
58
73
  }, context);
59
74
  }
@@ -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 FunctionRunnerInput<I extends {
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 FunctionRunnerOutput<O> = O;
17
- export declare abstract class FunctionRunner<I extends {
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<FunctionRunnerInput<I, Memories, State>, FunctionRunnerOutput<O>> {
23
+ } = {}, State extends ContextState = ContextState> extends Agent<SandboxFunctionRunnerInput<I, Memories, State>, SandboxFunctionRunnerOutput<O>> {
24
24
  constructor(context?: Context);
25
25
  }
@@ -1,14 +1,14 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.FunctionRunner = void 0;
3
+ exports.SandboxFunctionRunner = void 0;
4
4
  const agent_1 = require("./agent");
5
5
  const utils_1 = require("./utils");
6
- class FunctionRunner extends agent_1.Agent {
6
+ class SandboxFunctionRunner extends agent_1.Agent {
7
7
  constructor(context) {
8
8
  super({
9
- id: "function_runner",
10
- type: "function_runner",
11
- name: "Function Runner",
9
+ id: "sandbox_function_runner",
10
+ type: "sandbox_function_runner",
11
+ name: "Sandbox Function Runner",
12
12
  description: "Run a function",
13
13
  inputs: utils_1.OrderedRecord.fromArray([
14
14
  { id: "name", name: "name", type: "string", required: true },
@@ -28,4 +28,4 @@ class FunctionRunner extends agent_1.Agent {
28
28
  }, context);
29
29
  }
30
30
  }
31
- exports.FunctionRunner = FunctionRunner;
31
+ exports.SandboxFunctionRunner = SandboxFunctionRunner;
@@ -27,7 +27,7 @@ async function getAuthParams(auth) {
27
27
  if (!auth)
28
28
  return {};
29
29
  if (auth.type === "custom") {
30
- return await auth.getValue();
30
+ return await auth.auth();
31
31
  }
32
32
  const { type, key, token } = auth;
33
33
  switch (auth.in) {
@@ -2,6 +2,6 @@ export declare const TYPES: {
2
2
  context: symbol;
3
3
  definition: symbol;
4
4
  llmModel: symbol;
5
- functionRunner: symbol;
5
+ sandboxFunctionRunner: symbol;
6
6
  };
7
7
  export declare const StreamTextOutputName = "$text";
@@ -11,7 +11,7 @@ export interface BaseAuthConfig {
11
11
  }
12
12
  export interface CustomAuthConfig {
13
13
  type: "custom";
14
- getValue: () => Promise<AuthResult> | AuthResult;
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, context?: Context<State>, runner?: FunctionRunner<I, O, Memories, State> | undefined);
19
- process(input: I, options: AgentProcessOptions<Memories>): Promise<import("./runnable").RunnableResponseStream<O>>;
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
- language?: string;
34
- code: string;
51
+ function?: FunctionFuncType<SchemaMapType<I>, SchemaMapType<O>, {
52
+ [key in keyof Memories]: MemorableSearchOutput<Memories[key]["memory"]>;
53
+ }, State>;
35
54
  }
36
- export declare function create<I extends {
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 interface FunctionAgentDefinition extends RunnableDefinition {
46
- type: "function_agent";
47
- language?: string;
48
- code?: string;
49
- }
64
+ export {};
@@ -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";
@@ -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
- functionRunner?: FunctionRunner | Constructor<FunctionRunner>;
21
+ sandboxFunctionRunner?: SandboxFunctionRunner | Constructor<SandboxFunctionRunner>;
22
22
  }
23
23
  export declare class Runtime<Agents extends {
24
24
  [name: string]: Runnable;
@@ -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
+ }