@aigne/core 1.0.1 → 1.0.2-beta.1

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 (107) hide show
  1. package/lib/dts/agent.d.ts +41 -0
  2. package/lib/dts/constants.d.ts +7 -0
  3. package/lib/dts/context.d.ts +17 -0
  4. package/lib/dts/definitions/data-type-schema.d.ts +42 -0
  5. package/lib/dts/definitions/data-type.d.ts +32 -0
  6. package/lib/dts/definitions/memory.d.ts +40 -0
  7. package/lib/dts/definitions/open-api.d.ts +36 -0
  8. package/lib/dts/function-agent.d.ts +49 -0
  9. package/lib/dts/function-runner.d.ts +25 -0
  10. package/lib/dts/index.d.ts +18 -0
  11. package/lib/dts/llm-agent.d.ts +96 -0
  12. package/lib/dts/llm-decision-agent.d.ts +73 -0
  13. package/lib/dts/llm-model.d.ts +80 -0
  14. package/lib/dts/local-function-agent.d.ts +64 -0
  15. package/lib/dts/logger.d.ts +2 -0
  16. package/lib/dts/memorable.d.ts +183 -0
  17. package/lib/dts/open-api-agent.d.ts +55 -0
  18. package/lib/dts/pipeline-agent.d.ts +79 -0
  19. package/lib/dts/runnable.d.ts +70 -0
  20. package/lib/dts/utils/constants.d.ts +1 -0
  21. package/lib/dts/utils/fetch-open-api.d.ts +2 -0
  22. package/lib/dts/utils/fetch.d.ts +1 -0
  23. package/lib/dts/utils/index.d.ts +10 -0
  24. package/lib/dts/utils/is-non-nullable.d.ts +2 -0
  25. package/lib/dts/utils/message-utils.d.ts +20 -0
  26. package/lib/dts/utils/mustache-utils.d.ts +3 -0
  27. package/lib/dts/utils/nullable.d.ts +7 -0
  28. package/lib/dts/utils/omit.d.ts +1 -0
  29. package/lib/dts/utils/open-api-parameter.d.ts +7 -0
  30. package/lib/dts/utils/ordered-map.d.ts +37 -0
  31. package/lib/dts/utils/runnable-type.d.ts +3 -0
  32. package/lib/dts/utils/stream-utils.d.ts +20 -0
  33. package/lib/dts/utils/structured-output-schema.d.ts +3 -0
  34. package/lib/dts/utils/union.d.ts +1 -0
  35. package/lib/esm/agent.d.ts +41 -0
  36. package/lib/esm/constants.d.ts +7 -0
  37. package/lib/esm/context.d.ts +17 -0
  38. package/lib/esm/definitions/data-type-schema.d.ts +42 -0
  39. package/lib/esm/definitions/data-type.d.ts +32 -0
  40. package/lib/esm/definitions/memory.d.ts +40 -0
  41. package/lib/esm/definitions/open-api.d.ts +36 -0
  42. package/lib/esm/function-agent.d.ts +49 -0
  43. package/lib/esm/function-runner.d.ts +25 -0
  44. package/lib/esm/index.d.ts +18 -0
  45. package/lib/esm/llm-agent.d.ts +96 -0
  46. package/lib/esm/llm-decision-agent.d.ts +73 -0
  47. package/lib/esm/llm-model.d.ts +80 -0
  48. package/lib/esm/local-function-agent.d.ts +64 -0
  49. package/lib/esm/logger.d.ts +2 -0
  50. package/lib/esm/memorable.d.ts +183 -0
  51. package/lib/esm/open-api-agent.d.ts +55 -0
  52. package/lib/esm/pipeline-agent.d.ts +79 -0
  53. package/lib/esm/runnable.d.ts +70 -0
  54. package/lib/esm/utils/constants.d.ts +1 -0
  55. package/lib/esm/utils/fetch-open-api.d.ts +2 -0
  56. package/lib/esm/utils/fetch.d.ts +1 -0
  57. package/lib/esm/utils/index.d.ts +10 -0
  58. package/lib/esm/utils/is-non-nullable.d.ts +2 -0
  59. package/lib/esm/utils/message-utils.d.ts +20 -0
  60. package/lib/esm/utils/mustache-utils.d.ts +3 -0
  61. package/lib/esm/utils/nullable.d.ts +7 -0
  62. package/lib/esm/utils/omit.d.ts +1 -0
  63. package/lib/esm/utils/open-api-parameter.d.ts +7 -0
  64. package/lib/esm/utils/ordered-map.d.ts +37 -0
  65. package/lib/esm/utils/runnable-type.d.ts +3 -0
  66. package/lib/esm/utils/stream-utils.d.ts +20 -0
  67. package/lib/esm/utils/structured-output-schema.d.ts +3 -0
  68. package/lib/esm/utils/union.d.ts +1 -0
  69. package/lib/tsconfig.build.cjs.tsbuildinfo +1 -0
  70. package/lib/tsconfig.build.dts.tsbuildinfo +1 -0
  71. package/lib/tsconfig.build.esm.tsbuildinfo +1 -0
  72. package/package.json +3 -6
  73. package/tsconfig.json +1 -7
  74. /package/lib/{types → cjs}/agent.d.ts +0 -0
  75. /package/lib/{types → cjs}/constants.d.ts +0 -0
  76. /package/lib/{types → cjs}/context.d.ts +0 -0
  77. /package/lib/{types → cjs}/definitions/data-type-schema.d.ts +0 -0
  78. /package/lib/{types → cjs}/definitions/data-type.d.ts +0 -0
  79. /package/lib/{types → cjs}/definitions/memory.d.ts +0 -0
  80. /package/lib/{types → cjs}/definitions/open-api.d.ts +0 -0
  81. /package/lib/{types → cjs}/function-agent.d.ts +0 -0
  82. /package/lib/{types → cjs}/function-runner.d.ts +0 -0
  83. /package/lib/{types → cjs}/index.d.ts +0 -0
  84. /package/lib/{types → cjs}/llm-agent.d.ts +0 -0
  85. /package/lib/{types → cjs}/llm-decision-agent.d.ts +0 -0
  86. /package/lib/{types → cjs}/llm-model.d.ts +0 -0
  87. /package/lib/{types → cjs}/local-function-agent.d.ts +0 -0
  88. /package/lib/{types → cjs}/logger.d.ts +0 -0
  89. /package/lib/{types → cjs}/memorable.d.ts +0 -0
  90. /package/lib/{types → cjs}/open-api-agent.d.ts +0 -0
  91. /package/lib/{types → cjs}/pipeline-agent.d.ts +0 -0
  92. /package/lib/{types → cjs}/runnable.d.ts +0 -0
  93. /package/lib/{types → cjs}/utils/constants.d.ts +0 -0
  94. /package/lib/{types → cjs}/utils/fetch-open-api.d.ts +0 -0
  95. /package/lib/{types → cjs}/utils/fetch.d.ts +0 -0
  96. /package/lib/{types → cjs}/utils/index.d.ts +0 -0
  97. /package/lib/{types → cjs}/utils/is-non-nullable.d.ts +0 -0
  98. /package/lib/{types → cjs}/utils/message-utils.d.ts +0 -0
  99. /package/lib/{types → cjs}/utils/mustache-utils.d.ts +0 -0
  100. /package/lib/{types → cjs}/utils/nullable.d.ts +0 -0
  101. /package/lib/{types → cjs}/utils/omit.d.ts +0 -0
  102. /package/lib/{types → cjs}/utils/open-api-parameter.d.ts +0 -0
  103. /package/lib/{types → cjs}/utils/ordered-map.d.ts +0 -0
  104. /package/lib/{types → cjs}/utils/runnable-type.d.ts +0 -0
  105. /package/lib/{types → cjs}/utils/stream-utils.d.ts +0 -0
  106. /package/lib/{types → cjs}/utils/structured-output-schema.d.ts +0 -0
  107. /package/lib/{types → cjs}/utils/union.d.ts +0 -0
@@ -0,0 +1,41 @@
1
+ import type { Context, ContextState } from "./context";
2
+ import type { MemoryItemWithScore, MemoryMessage } from "./memorable";
3
+ import { type RunOptions, Runnable, type RunnableResponse, type RunnableResponseChunk, type RunnableResponseStream } from "./runnable";
4
+ export interface AgentProcessOptions<Memories extends {
5
+ [name: string]: MemoryItemWithScore[];
6
+ }> {
7
+ memories: Memories;
8
+ }
9
+ export declare abstract class Agent<I extends {
10
+ [key: string]: any;
11
+ } = {}, O extends {
12
+ [key: string]: any;
13
+ } = {}, Memories extends {
14
+ [name: string]: MemoryItemWithScore[];
15
+ } = {}, State extends ContextState = ContextState> extends Runnable<I, O, State> {
16
+ private getMemoryQuery;
17
+ /**
18
+ * Load memories that are defined in the agent definition.
19
+ * @param input The agent input.
20
+ * @param context The AIGNE context.
21
+ * @returns A dictionary of memories, where the key is the memory id or name and the value is an array of memory items.
22
+ */
23
+ protected loadMemories(input: I, context?: Context): Promise<Memories>;
24
+ /**
25
+ * Update memories by user messages and assistant responses.
26
+ * @param messages Messages to be added to memories.
27
+ */
28
+ protected updateMemories(messages: MemoryMessage[]): Promise<void>;
29
+ run(input: I, options: RunOptions & {
30
+ stream: true;
31
+ }): Promise<RunnableResponseStream<O>>;
32
+ run(input: I, options?: RunOptions & {
33
+ stream?: false;
34
+ }): Promise<O>;
35
+ /**
36
+ * Hook that is called before the agent result is returned.
37
+ * @param _result The agent result.
38
+ */
39
+ protected onResult(_result: O): Promise<void>;
40
+ abstract process(input: I, options: AgentProcessOptions<Memories>): Promise<RunnableResponse<O> | AsyncGenerator<RunnableResponseChunk<O>, void>> | AsyncGenerator<RunnableResponseChunk<O>, void>;
41
+ }
@@ -0,0 +1,7 @@
1
+ export declare const TYPES: {
2
+ context: symbol;
3
+ definition: symbol;
4
+ llmModel: symbol;
5
+ functionRunner: symbol;
6
+ };
7
+ export declare const StreamTextOutputName = "$text";
@@ -0,0 +1,17 @@
1
+ import type { LLMModelConfiguration } from "./llm-model";
2
+ import type { Runnable, RunnableDefinition } from "./runnable";
3
+ export interface ContextState {
4
+ userId?: string;
5
+ sessionId?: string;
6
+ [key: string]: any;
7
+ }
8
+ export interface ContextConfig {
9
+ llmModel?: LLMModelConfiguration;
10
+ }
11
+ export interface Context<State extends ContextState = ContextState, Config extends ContextConfig = ContextConfig> {
12
+ state: State;
13
+ config: Config;
14
+ resolve<T extends Runnable>(id: string | RunnableDefinition | T): Promise<T>;
15
+ register<R extends Array<RunnableDefinition | Runnable> = []>(...definition: R): void;
16
+ resolveDependency<T>(token: string | symbol): T;
17
+ }
@@ -0,0 +1,42 @@
1
+ import type { MakeNullablePropertyOptional } from "../utils/nullable";
2
+ import { OrderedRecord } from "../utils/ordered-map";
3
+ import type { DataType } from "./data-type";
4
+ export declare function schemaToDataType(dataType: {
5
+ [name: string]: DataTypeSchema;
6
+ }): OrderedRecord<DataType>;
7
+ export type DataTypeSchema = DataTypeSchemaString | DataTypeSchemaNumber | DataTypeSchemaBoolean | DataTypeSchemaObject | DataTypeSchemaArray;
8
+ export interface DataTypeSchemaBase {
9
+ description?: string;
10
+ required?: boolean;
11
+ }
12
+ export interface DataTypeSchemaString extends DataTypeSchemaBase {
13
+ type: "string";
14
+ }
15
+ export interface DataTypeSchemaNumber extends DataTypeSchemaBase {
16
+ type: "number";
17
+ }
18
+ export interface DataTypeSchemaBoolean extends DataTypeSchemaBase {
19
+ type: "boolean";
20
+ }
21
+ export interface DataTypeSchemaObject extends DataTypeSchemaBase {
22
+ type: "object";
23
+ properties?: {
24
+ [key: string]: DataTypeSchema;
25
+ };
26
+ }
27
+ export interface DataTypeSchemaArray extends DataTypeSchemaBase {
28
+ type: "array";
29
+ items?: DataTypeSchema;
30
+ }
31
+ type SchemaTypeInner<T extends DataTypeSchema> = T extends DataTypeSchemaString ? string : T extends DataTypeSchemaNumber ? number : T extends DataTypeSchemaBoolean ? boolean : T extends DataTypeSchemaObject ? MakeNullablePropertyOptional<{
32
+ [K in keyof T["properties"]]: SchemaType<NonNullable<T["properties"]>[K]>;
33
+ }> : T extends DataTypeSchemaArray ? T["items"] extends null | undefined ? SchemaType<{
34
+ type: "object";
35
+ }>[] : SchemaType<NonNullable<T["items"]>>[] : never;
36
+ export type SchemaType<T extends DataTypeSchema> = T["required"] extends true ? SchemaTypeInner<T> : SchemaTypeInner<T> | undefined | null;
37
+ export type SchemaMapType<T extends Record<string, DataTypeSchema>> = SchemaType<{
38
+ type: "object";
39
+ required: true;
40
+ properties: T;
41
+ }>;
42
+ export {};
@@ -0,0 +1,32 @@
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
+ }
@@ -0,0 +1,40 @@
1
+ import type { Memorable } from "../memorable";
2
+ import type { RunnableInput, RunnableMemory } from "../runnable";
3
+ import { OrderedRecord } from "../utils";
4
+ import type { DataTypeSchema } from "./data-type-schema";
5
+ export interface CreateRunnableMemory<I extends {
6
+ [key: string]: DataTypeSchema;
7
+ } = {}> {
8
+ /**
9
+ * Memory instance to query/store memory.
10
+ */
11
+ memory: Memorable<any>;
12
+ /**
13
+ * Custom query to retrieve memory, if not provided, all input variables will be used.
14
+ *
15
+ * @example
16
+ * {
17
+ * fromVariable: 'question' // question is a string input variable
18
+ * }
19
+ */
20
+ query?: {
21
+ /**
22
+ * Variable name from input used to query memory.
23
+ */
24
+ fromVariable?: keyof {
25
+ [key in keyof I as I[key]["type"] extends "string" ? key : never]: any;
26
+ };
27
+ };
28
+ /**
29
+ * Custom options for memory query.
30
+ */
31
+ options?: {
32
+ /**
33
+ * Number of memories to retrieve.
34
+ */
35
+ k?: number;
36
+ };
37
+ }
38
+ export declare function toRunnableMemories<I extends {}>(agentName: string, inputs: OrderedRecord<RunnableInput>, memories: {
39
+ [name: string]: CreateRunnableMemory<I>;
40
+ }): OrderedRecord<RunnableMemory>;
@@ -0,0 +1,36 @@
1
+ import type { DataType } from "./data-type";
2
+ import type { DataTypeSchema } from "./data-type-schema";
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
+ getValue: () => 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 = DataTypeSchema & {
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, any>;
35
+ };
36
+ export {};
@@ -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 { FunctionRunner } from "./function-runner";
6
+ import type { MemorableSearchOutput, MemoryItemWithScore } from "./memorable";
7
+ import type { RunnableDefinition } from "./runnable";
8
+ export declare class FunctionAgent<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: FunctionAgentDefinition;
16
+ runner?: FunctionRunner<I, O, Memories, State> | undefined;
17
+ 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>>;
20
+ }
21
+ export interface CreateFunctionAgentOptions<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 }: CreateFunctionAgentOptions<I, O, Memories, State>): FunctionAgent<SchemaMapType<I>, SchemaMapType<O>, {
43
+ [name in keyof Memories]: MemorableSearchOutput<Memories[name]["memory"]>;
44
+ }, State>;
45
+ export interface FunctionAgentDefinition extends RunnableDefinition {
46
+ type: "function_agent";
47
+ language?: string;
48
+ code?: string;
49
+ }
@@ -0,0 +1,25 @@
1
+ import { Agent } from "./agent";
2
+ import type { Context, ContextState } from "./context";
3
+ import type { MemoryItemWithScore } from "./memorable";
4
+ export interface FunctionRunnerInput<I extends {
5
+ [name: string]: any;
6
+ } = {}, Memories extends {
7
+ [name: string]: MemoryItemWithScore[];
8
+ } = {}, State extends ContextState = ContextState> {
9
+ name: string;
10
+ language?: string;
11
+ code: string;
12
+ input: I;
13
+ memories: Memories;
14
+ context: Pick<Context<State>, "state">;
15
+ }
16
+ export type FunctionRunnerOutput<O> = O;
17
+ export declare abstract class FunctionRunner<I extends {
18
+ [name: string]: any;
19
+ } = {}, O extends {
20
+ [name: string]: any;
21
+ } = {}, Memories extends {
22
+ [name: string]: MemoryItemWithScore[];
23
+ } = {}, State extends ContextState = ContextState> extends Agent<FunctionRunnerInput<I, Memories, State>, FunctionRunnerOutput<O>> {
24
+ constructor(context?: Context);
25
+ }
@@ -0,0 +1,18 @@
1
+ export * from "./utils";
2
+ export * from "./constants";
3
+ export * from "./definitions/data-type";
4
+ export * from "./definitions/data-type-schema";
5
+ export * from "./definitions/open-api";
6
+ export * from "./definitions/memory";
7
+ export * from "./context";
8
+ export * from "./runnable";
9
+ export * from "./agent";
10
+ export * from "./pipeline-agent";
11
+ export * from "./llm-agent";
12
+ export * from "./llm-model";
13
+ export * from "./function-agent";
14
+ export * from "./function-runner";
15
+ export * from "./llm-decision-agent";
16
+ export * from "./local-function-agent";
17
+ export * from "./open-api-agent";
18
+ export * from "./memorable";
@@ -0,0 +1,96 @@
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 { LLMModel, LLMModelInputMessage, LLMModelInputs } from "./llm-model";
6
+ import type { MemorableSearchOutput, MemoryItemWithScore } from "./memorable";
7
+ import type { RunnableDefinition } from "./runnable";
8
+ import { OrderedRecord } from "./utils/ordered-map";
9
+ export declare class LLMAgent<I extends {
10
+ [name: string]: any;
11
+ } = {}, O extends {
12
+ [name: string]: any;
13
+ } = {}, Memories extends {
14
+ [name: string]: MemoryItemWithScore[];
15
+ } = {}, State extends ContextState = ContextState> extends Agent<I, O, Memories, State> {
16
+ definition: LLMAgentDefinition;
17
+ model?: LLMModel | undefined;
18
+ static create: typeof create;
19
+ constructor(definition: LLMAgentDefinition, context?: Context<State>, model?: LLMModel | undefined);
20
+ process(input: I, options: AgentProcessOptions<Memories>): AsyncGenerator<{
21
+ $text: string | undefined;
22
+ delta?: undefined;
23
+ } | {
24
+ delta: any;
25
+ $text?: undefined;
26
+ }, void, unknown>;
27
+ private runWithStructuredOutput;
28
+ private runWithTextOutput;
29
+ }
30
+ export interface LLMAgentDefinition extends RunnableDefinition {
31
+ type: "llm_agent";
32
+ primaryMemoryId?: string;
33
+ messages?: OrderedRecord<LLMModelInputMessage & {
34
+ id: string;
35
+ }>;
36
+ modelOptions?: LLMModelInputs["modelOptions"];
37
+ }
38
+ /**
39
+ * Options to create LLMAgent.
40
+ */
41
+ export interface CreateLLMAgentOptions<I extends {
42
+ [name: string]: DataTypeSchema;
43
+ }, O extends {
44
+ [name: string]: DataTypeSchema;
45
+ }, Memories extends {
46
+ [name: string]: CreateRunnableMemory<I>;
47
+ }, State extends ContextState> {
48
+ context?: Context<State>;
49
+ /**
50
+ * Agent name, used to identify the agent.
51
+ */
52
+ name?: string;
53
+ /**
54
+ * Input variables for this agent.
55
+ */
56
+ inputs: I;
57
+ /**
58
+ * Output variables for this agent.
59
+ */
60
+ outputs: O;
61
+ /**
62
+ * Memories to be used in this agent.
63
+ */
64
+ memories?: Memories;
65
+ /**
66
+ * Options for LLM chat model.
67
+ */
68
+ modelOptions?: LLMModelInputs["modelOptions"];
69
+ /**
70
+ * Messages to be passed to LLM chat model.
71
+ */
72
+ messages?: LLMModelInputMessage[];
73
+ }
74
+ /**
75
+ * Create LLMAgent definition.
76
+ * @param options Options to create LLMAgent.
77
+ * @returns LLMAgent definition.
78
+ */
79
+ declare function create<I extends {
80
+ [name: string]: DataTypeSchema;
81
+ }, O extends {
82
+ [name: string]: DataTypeSchema;
83
+ }, Memories extends {
84
+ [name: string]: CreateRunnableMemory<I> & {
85
+ /**
86
+ * Whether this memory is primary? Primary memory will be passed as messages to LLM chat model,
87
+ * otherwise, it will be placed in a system message.
88
+ *
89
+ * Only one primary memory is allowed.
90
+ */
91
+ primary?: boolean;
92
+ };
93
+ }, State extends ContextState>({ context, ...options }: CreateLLMAgentOptions<I, O, Memories, State>): LLMAgent<SchemaMapType<I>, SchemaMapType<O>, {
94
+ [name in keyof Memories]: MemorableSearchOutput<Memories[name]["memory"]>;
95
+ }, State>;
96
+ export {};
@@ -0,0 +1,73 @@
1
+ import { Agent, type AgentProcessOptions } from "./agent";
2
+ import type { Context, ContextState } from "./context";
3
+ import type { DataTypeSchema } from "./definitions/data-type-schema";
4
+ import { type CreateRunnableMemory } from "./definitions/memory";
5
+ import type { CreateLLMAgentOptions, LLMAgentDefinition } from "./llm-agent";
6
+ import type { LLMModel } from "./llm-model";
7
+ import type { MemorableSearchOutput, MemoryItemWithScore } from "./memorable";
8
+ import type { Runnable, RunnableDefinition } from "./runnable";
9
+ import { OrderedRecord } from "./utils";
10
+ import type { ExtractRunnableInputType, ExtractRunnableOutputType } from "./utils/runnable-type";
11
+ import type { UnionToIntersection } from "./utils/union";
12
+ export declare class LLMDecisionAgent<I extends {
13
+ [name: string]: any;
14
+ } = {}, O extends {
15
+ [name: string]: any;
16
+ } = {}, Memories extends {
17
+ [name: string]: MemoryItemWithScore[];
18
+ } = {}, State extends ContextState = ContextState> extends Agent<I, O, Memories, State> {
19
+ definition: LLMDecisionAgentDefinition;
20
+ model?: LLMModel | undefined;
21
+ static create: typeof create;
22
+ constructor(definition: LLMDecisionAgentDefinition, context?: Context<State>, model?: LLMModel | undefined);
23
+ process(input: I, options: AgentProcessOptions<Memories>): Promise<import("./runnable").RunnableResponse<O>>;
24
+ }
25
+ export interface DecisionAgentCaseParameter<R extends Runnable = Runnable> {
26
+ description?: string;
27
+ runnable: R;
28
+ }
29
+ /**
30
+ * Options to create LLMDecisionAgent.
31
+ */
32
+ export interface CreateLLMDecisionAgentOptions<Case extends DecisionAgentCaseParameter, I extends UnionToIntersection<ExtractRunnableInputType<Case["runnable"]>, {
33
+ [name: string]: DataTypeSchema;
34
+ }>, O extends UnionToIntersection<ExtractRunnableOutputType<Case["runnable"]>, {
35
+ [name: string]: DataTypeSchema;
36
+ }>, Memories extends {
37
+ [name: string]: CreateRunnableMemory<I>;
38
+ }, State extends ContextState> extends Pick<CreateLLMAgentOptions<I, O, Memories, State>, "name" | "memories" | "messages" | "modelOptions"> {
39
+ context: Context<State>;
40
+ cases: {
41
+ [name: string]: Case;
42
+ };
43
+ }
44
+ declare function create<Case extends DecisionAgentCaseParameter, I extends UnionToIntersection<ExtractRunnableInputType<Case["runnable"]>, {
45
+ [name: string]: DataTypeSchema;
46
+ }>, O extends UnionToIntersection<ExtractRunnableOutputType<Case["runnable"]>, {
47
+ [name: string]: DataTypeSchema;
48
+ }>, Memories extends {
49
+ [name: string]: CreateRunnableMemory<I> & {
50
+ /**
51
+ * Whether this memory is primary? Primary memory will be passed as messages to LLM chat model,
52
+ * otherwise, it will be placed in a system message.
53
+ *
54
+ * Only one primary memory is allowed.
55
+ */
56
+ primary?: boolean;
57
+ };
58
+ }, State extends ContextState>({ context, ...options }: CreateLLMDecisionAgentOptions<Case, I, O, Memories, State>): LLMDecisionAgent<UnionToIntersection<ExtractRunnableInputType<Case["runnable"]>, {}>, ExtractRunnableOutputType<Case["runnable"]>, {
59
+ [name in keyof Memories]: MemorableSearchOutput<Memories[name]["memory"]>;
60
+ }, State>;
61
+ export interface LLMDecisionAgentDefinition extends RunnableDefinition, Pick<LLMAgentDefinition, "modelOptions" | "messages" | "primaryMemoryId"> {
62
+ type: "llm_decision_agent";
63
+ cases?: OrderedRecord<LLMDecisionCase>;
64
+ }
65
+ export interface LLMDecisionCase {
66
+ id: string;
67
+ name?: string;
68
+ description?: string;
69
+ runnable?: {
70
+ id?: string;
71
+ };
72
+ }
73
+ export {};
@@ -0,0 +1,80 @@
1
+ import { Agent } from "./agent";
2
+ import type { Context } from "./context";
3
+ export type Role = "system" | "user" | "assistant" | "tool";
4
+ export interface LLMModelInputs {
5
+ messages: LLMModelInputMessage[];
6
+ responseFormat?: {
7
+ type: "text";
8
+ } | {
9
+ type: "json_schema";
10
+ jsonSchema: {
11
+ name: string;
12
+ description?: string;
13
+ schema: object;
14
+ strict?: boolean;
15
+ };
16
+ };
17
+ tools?: LLMModelInputTool[];
18
+ toolChoice?: "auto" | "none" | "required" | {
19
+ type: "function";
20
+ function: {
21
+ name: string;
22
+ description?: string;
23
+ };
24
+ };
25
+ modelOptions?: LLMModelOptions;
26
+ }
27
+ export interface LLMModelInputMessage {
28
+ role: Role;
29
+ content: string | ({
30
+ type: "text";
31
+ text: string;
32
+ } | {
33
+ type: "image_url";
34
+ imageUrl: {
35
+ url: string;
36
+ };
37
+ })[];
38
+ toolCalls?: {
39
+ id: string;
40
+ type: "function";
41
+ function: {
42
+ name: string;
43
+ arguments: string;
44
+ };
45
+ }[];
46
+ toolCallId?: string;
47
+ }
48
+ export interface LLMModelInputTool {
49
+ type: "function";
50
+ function: {
51
+ name: string;
52
+ description?: string;
53
+ parameters: object;
54
+ };
55
+ }
56
+ export interface LLMModelOptions {
57
+ model?: string;
58
+ temperature?: number;
59
+ topP?: number;
60
+ frequencyPenalty?: number;
61
+ presencePenalty?: number;
62
+ }
63
+ export interface LLMModelOutputs {
64
+ $text?: string | null;
65
+ toolCalls?: {
66
+ id?: string;
67
+ type?: "function";
68
+ function?: {
69
+ name?: string;
70
+ arguments?: string;
71
+ };
72
+ }[];
73
+ }
74
+ export declare abstract class LLMModel extends Agent<LLMModelInputs, LLMModelOutputs> {
75
+ constructor(context?: Context);
76
+ }
77
+ export interface LLMModelConfiguration {
78
+ default?: Partial<LLMModelOptions>;
79
+ override?: Partial<LLMModelOptions>;
80
+ }
@@ -0,0 +1,64 @@
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 {};
@@ -0,0 +1,2 @@
1
+ declare const logger: Console;
2
+ export default logger;