@aigne/core 1.0.17 → 1.1.0-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (252) hide show
  1. package/lib/cjs/agents/agent.d.ts +55 -0
  2. package/lib/cjs/agents/agent.js +91 -0
  3. package/lib/cjs/agents/ai-agent.d.ts +20 -0
  4. package/lib/cjs/agents/ai-agent.js +86 -0
  5. package/lib/cjs/agents/mcp-agent.d.ts +27 -0
  6. package/lib/cjs/agents/mcp-agent.js +95 -0
  7. package/lib/cjs/agents/types.d.ts +9 -0
  8. package/lib/cjs/agents/types.js +16 -0
  9. package/lib/cjs/execution-engine/context.d.ts +10 -0
  10. package/lib/cjs/execution-engine/index.d.ts +45 -0
  11. package/lib/cjs/execution-engine/index.js +190 -0
  12. package/lib/cjs/execution-engine/message-queue.d.ts +5 -0
  13. package/lib/cjs/execution-engine/message-queue.js +9 -0
  14. package/lib/cjs/index.d.ts +10 -21
  15. package/lib/cjs/index.js +10 -21
  16. package/lib/cjs/models/chat-openai.d.ts +14 -0
  17. package/lib/cjs/{llm-models/openai-llm-model.js → models/chat-openai.js} +62 -27
  18. package/lib/cjs/models/chat.d.ts +78 -0
  19. package/lib/cjs/models/chat.js +91 -0
  20. package/lib/cjs/prompt/prompt-builder.d.ts +34 -0
  21. package/lib/cjs/prompt/prompt-builder.js +140 -0
  22. package/lib/cjs/prompt/template.d.ts +70 -0
  23. package/lib/cjs/prompt/template.js +172 -0
  24. package/lib/cjs/utils/logger.d.ts +6 -3
  25. package/lib/cjs/utils/logger.js +9 -14
  26. package/lib/cjs/utils/type-utils.d.ts +5 -1
  27. package/lib/cjs/utils/type-utils.js +23 -0
  28. package/lib/dts/agents/agent.d.ts +55 -0
  29. package/lib/dts/agents/ai-agent.d.ts +20 -0
  30. package/lib/dts/agents/mcp-agent.d.ts +27 -0
  31. package/lib/dts/agents/types.d.ts +9 -0
  32. package/lib/dts/execution-engine/context.d.ts +10 -0
  33. package/lib/dts/execution-engine/index.d.ts +45 -0
  34. package/lib/dts/execution-engine/message-queue.d.ts +5 -0
  35. package/lib/dts/index.d.ts +10 -21
  36. package/lib/dts/models/chat-openai.d.ts +14 -0
  37. package/lib/dts/models/chat.d.ts +78 -0
  38. package/lib/dts/prompt/prompt-builder.d.ts +34 -0
  39. package/lib/dts/prompt/template.d.ts +70 -0
  40. package/lib/dts/utils/logger.d.ts +6 -3
  41. package/lib/dts/utils/type-utils.d.ts +5 -1
  42. package/lib/esm/agents/agent.d.ts +55 -0
  43. package/lib/esm/agents/agent.js +83 -0
  44. package/lib/esm/agents/ai-agent.d.ts +20 -0
  45. package/lib/esm/agents/ai-agent.js +82 -0
  46. package/lib/esm/agents/mcp-agent.d.ts +27 -0
  47. package/lib/esm/agents/mcp-agent.js +90 -0
  48. package/lib/esm/agents/types.d.ts +9 -0
  49. package/lib/esm/agents/types.js +11 -0
  50. package/lib/esm/execution-engine/context.d.ts +10 -0
  51. package/lib/esm/execution-engine/index.d.ts +45 -0
  52. package/lib/esm/execution-engine/index.js +182 -0
  53. package/lib/esm/execution-engine/message-queue.d.ts +5 -0
  54. package/lib/esm/execution-engine/message-queue.js +5 -0
  55. package/lib/esm/index.d.ts +10 -21
  56. package/lib/esm/index.js +10 -21
  57. package/lib/esm/models/chat-openai.d.ts +14 -0
  58. package/lib/esm/{llm-models/openai-llm-model.js → models/chat-openai.js} +59 -24
  59. package/lib/esm/models/chat.d.ts +78 -0
  60. package/lib/esm/models/chat.js +87 -0
  61. package/lib/esm/prompt/prompt-builder.d.ts +34 -0
  62. package/lib/esm/prompt/prompt-builder.js +131 -0
  63. package/lib/esm/prompt/template.d.ts +70 -0
  64. package/lib/esm/prompt/template.js +158 -0
  65. package/lib/esm/utils/logger.d.ts +6 -3
  66. package/lib/esm/utils/logger.js +6 -14
  67. package/lib/esm/utils/type-utils.d.ts +5 -1
  68. package/lib/esm/utils/type-utils.js +17 -1
  69. package/package.json +18 -14
  70. package/lib/cjs/agent.d.ts +0 -96
  71. package/lib/cjs/agent.js +0 -165
  72. package/lib/cjs/constants.d.ts +0 -7
  73. package/lib/cjs/constants.js +0 -10
  74. package/lib/cjs/context.d.ts +0 -23
  75. package/lib/cjs/definitions/data-schema.d.ts +0 -61
  76. package/lib/cjs/definitions/data-schema.js +0 -47
  77. package/lib/cjs/definitions/data-type.d.ts +0 -32
  78. package/lib/cjs/definitions/data-type.js +0 -2
  79. package/lib/cjs/definitions/memory.d.ts +0 -53
  80. package/lib/cjs/definitions/memory.js +0 -23
  81. package/lib/cjs/definitions/open-api.d.ts +0 -36
  82. package/lib/cjs/definitions/open-api.js +0 -2
  83. package/lib/cjs/definitions/preload.d.ts +0 -43
  84. package/lib/cjs/definitions/preload.js +0 -34
  85. package/lib/cjs/function-agent.d.ts +0 -23
  86. package/lib/cjs/function-agent.js +0 -62
  87. package/lib/cjs/llm-agent.d.ts +0 -53
  88. package/lib/cjs/llm-agent.js +0 -140
  89. package/lib/cjs/llm-decision-agent.d.ts +0 -53
  90. package/lib/cjs/llm-decision-agent.js +0 -144
  91. package/lib/cjs/llm-model.d.ts +0 -80
  92. package/lib/cjs/llm-model.js +0 -27
  93. package/lib/cjs/llm-models/gemini-llm-model.d.ts +0 -24
  94. package/lib/cjs/llm-models/gemini-llm-model.js +0 -199
  95. package/lib/cjs/llm-models/openai-llm-model.d.ts +0 -26
  96. package/lib/cjs/memorable.d.ts +0 -198
  97. package/lib/cjs/memorable.js +0 -33
  98. package/lib/cjs/open-api-agent.d.ts +0 -26
  99. package/lib/cjs/open-api-agent.js +0 -68
  100. package/lib/cjs/pipeline-agent.d.ts +0 -56
  101. package/lib/cjs/pipeline-agent.js +0 -206
  102. package/lib/cjs/runnable.d.ts +0 -76
  103. package/lib/cjs/runnable.js +0 -37
  104. package/lib/cjs/runtime.d.ts +0 -64
  105. package/lib/cjs/runtime.js +0 -149
  106. package/lib/cjs/sandbox-function-agent.d.ts +0 -21
  107. package/lib/cjs/sandbox-function-agent.js +0 -78
  108. package/lib/cjs/sandbox-function-runner.d.ts +0 -16
  109. package/lib/cjs/sandbox-function-runner.js +0 -32
  110. package/lib/cjs/utils/constants.d.ts +0 -1
  111. package/lib/cjs/utils/constants.js +0 -4
  112. package/lib/cjs/utils/fetch-open-api.d.ts +0 -2
  113. package/lib/cjs/utils/fetch-open-api.js +0 -31
  114. package/lib/cjs/utils/fetch.d.ts +0 -1
  115. package/lib/cjs/utils/fetch.js +0 -21
  116. package/lib/cjs/utils/index.d.ts +0 -12
  117. package/lib/cjs/utils/index.js +0 -28
  118. package/lib/cjs/utils/is-non-nullable.d.ts +0 -2
  119. package/lib/cjs/utils/is-non-nullable.js +0 -20
  120. package/lib/cjs/utils/message-utils.d.ts +0 -20
  121. package/lib/cjs/utils/message-utils.js +0 -79
  122. package/lib/cjs/utils/mustache-utils.d.ts +0 -3
  123. package/lib/cjs/utils/mustache-utils.js +0 -14
  124. package/lib/cjs/utils/nullable.d.ts +0 -7
  125. package/lib/cjs/utils/nullable.js +0 -2
  126. package/lib/cjs/utils/omit.d.ts +0 -1
  127. package/lib/cjs/utils/omit.js +0 -2
  128. package/lib/cjs/utils/open-api-parameter.d.ts +0 -7
  129. package/lib/cjs/utils/open-api-parameter.js +0 -81
  130. package/lib/cjs/utils/ordered-map.d.ts +0 -37
  131. package/lib/cjs/utils/ordered-map.js +0 -103
  132. package/lib/cjs/utils/partial.d.ts +0 -3
  133. package/lib/cjs/utils/partial.js +0 -2
  134. package/lib/cjs/utils/runnable-type.d.ts +0 -5
  135. package/lib/cjs/utils/runnable-type.js +0 -2
  136. package/lib/cjs/utils/stream-utils.d.ts +0 -20
  137. package/lib/cjs/utils/stream-utils.js +0 -86
  138. package/lib/cjs/utils/structured-output-schema.d.ts +0 -3
  139. package/lib/cjs/utils/structured-output-schema.js +0 -43
  140. package/lib/cjs/utils/union.d.ts +0 -1
  141. package/lib/cjs/utils/union.js +0 -2
  142. package/lib/dts/agent.d.ts +0 -96
  143. package/lib/dts/constants.d.ts +0 -7
  144. package/lib/dts/context.d.ts +0 -23
  145. package/lib/dts/definitions/data-schema.d.ts +0 -61
  146. package/lib/dts/definitions/data-type.d.ts +0 -32
  147. package/lib/dts/definitions/memory.d.ts +0 -53
  148. package/lib/dts/definitions/open-api.d.ts +0 -36
  149. package/lib/dts/definitions/preload.d.ts +0 -43
  150. package/lib/dts/function-agent.d.ts +0 -23
  151. package/lib/dts/llm-agent.d.ts +0 -53
  152. package/lib/dts/llm-decision-agent.d.ts +0 -53
  153. package/lib/dts/llm-model.d.ts +0 -80
  154. package/lib/dts/llm-models/gemini-llm-model.d.ts +0 -24
  155. package/lib/dts/llm-models/openai-llm-model.d.ts +0 -26
  156. package/lib/dts/memorable.d.ts +0 -198
  157. package/lib/dts/open-api-agent.d.ts +0 -26
  158. package/lib/dts/pipeline-agent.d.ts +0 -56
  159. package/lib/dts/runnable.d.ts +0 -76
  160. package/lib/dts/runtime.d.ts +0 -64
  161. package/lib/dts/sandbox-function-agent.d.ts +0 -21
  162. package/lib/dts/sandbox-function-runner.d.ts +0 -16
  163. package/lib/dts/utils/constants.d.ts +0 -1
  164. package/lib/dts/utils/fetch-open-api.d.ts +0 -2
  165. package/lib/dts/utils/fetch.d.ts +0 -1
  166. package/lib/dts/utils/index.d.ts +0 -12
  167. package/lib/dts/utils/is-non-nullable.d.ts +0 -2
  168. package/lib/dts/utils/message-utils.d.ts +0 -20
  169. package/lib/dts/utils/mustache-utils.d.ts +0 -3
  170. package/lib/dts/utils/nullable.d.ts +0 -7
  171. package/lib/dts/utils/omit.d.ts +0 -1
  172. package/lib/dts/utils/open-api-parameter.d.ts +0 -7
  173. package/lib/dts/utils/ordered-map.d.ts +0 -37
  174. package/lib/dts/utils/partial.d.ts +0 -3
  175. package/lib/dts/utils/runnable-type.d.ts +0 -5
  176. package/lib/dts/utils/stream-utils.d.ts +0 -20
  177. package/lib/dts/utils/structured-output-schema.d.ts +0 -3
  178. package/lib/dts/utils/union.d.ts +0 -1
  179. package/lib/esm/agent.d.ts +0 -96
  180. package/lib/esm/agent.js +0 -161
  181. package/lib/esm/constants.d.ts +0 -7
  182. package/lib/esm/constants.js +0 -7
  183. package/lib/esm/context.d.ts +0 -23
  184. package/lib/esm/definitions/data-schema.d.ts +0 -61
  185. package/lib/esm/definitions/data-schema.js +0 -44
  186. package/lib/esm/definitions/data-type.d.ts +0 -32
  187. package/lib/esm/definitions/data-type.js +0 -1
  188. package/lib/esm/definitions/memory.d.ts +0 -53
  189. package/lib/esm/definitions/memory.js +0 -20
  190. package/lib/esm/definitions/open-api.d.ts +0 -36
  191. package/lib/esm/definitions/open-api.js +0 -1
  192. package/lib/esm/definitions/preload.d.ts +0 -43
  193. package/lib/esm/definitions/preload.js +0 -31
  194. package/lib/esm/function-agent.d.ts +0 -23
  195. package/lib/esm/function-agent.js +0 -59
  196. package/lib/esm/llm-agent.d.ts +0 -53
  197. package/lib/esm/llm-agent.js +0 -137
  198. package/lib/esm/llm-decision-agent.d.ts +0 -53
  199. package/lib/esm/llm-decision-agent.js +0 -141
  200. package/lib/esm/llm-model.d.ts +0 -80
  201. package/lib/esm/llm-model.js +0 -23
  202. package/lib/esm/llm-models/gemini-llm-model.d.ts +0 -24
  203. package/lib/esm/llm-models/gemini-llm-model.js +0 -195
  204. package/lib/esm/llm-models/openai-llm-model.d.ts +0 -26
  205. package/lib/esm/memorable.d.ts +0 -198
  206. package/lib/esm/memorable.js +0 -28
  207. package/lib/esm/open-api-agent.d.ts +0 -26
  208. package/lib/esm/open-api-agent.js +0 -65
  209. package/lib/esm/pipeline-agent.d.ts +0 -56
  210. package/lib/esm/pipeline-agent.js +0 -203
  211. package/lib/esm/runnable.d.ts +0 -76
  212. package/lib/esm/runnable.js +0 -30
  213. package/lib/esm/runtime.d.ts +0 -64
  214. package/lib/esm/runtime.js +0 -146
  215. package/lib/esm/sandbox-function-agent.d.ts +0 -21
  216. package/lib/esm/sandbox-function-agent.js +0 -74
  217. package/lib/esm/sandbox-function-runner.d.ts +0 -16
  218. package/lib/esm/sandbox-function-runner.js +0 -28
  219. package/lib/esm/utils/constants.d.ts +0 -1
  220. package/lib/esm/utils/constants.js +0 -1
  221. package/lib/esm/utils/fetch-open-api.d.ts +0 -2
  222. package/lib/esm/utils/fetch-open-api.js +0 -28
  223. package/lib/esm/utils/fetch.d.ts +0 -1
  224. package/lib/esm/utils/fetch.js +0 -18
  225. package/lib/esm/utils/index.d.ts +0 -12
  226. package/lib/esm/utils/index.js +0 -12
  227. package/lib/esm/utils/is-non-nullable.d.ts +0 -2
  228. package/lib/esm/utils/is-non-nullable.js +0 -13
  229. package/lib/esm/utils/message-utils.d.ts +0 -20
  230. package/lib/esm/utils/message-utils.js +0 -71
  231. package/lib/esm/utils/mustache-utils.d.ts +0 -3
  232. package/lib/esm/utils/mustache-utils.js +0 -8
  233. package/lib/esm/utils/nullable.d.ts +0 -7
  234. package/lib/esm/utils/nullable.js +0 -1
  235. package/lib/esm/utils/omit.d.ts +0 -1
  236. package/lib/esm/utils/omit.js +0 -1
  237. package/lib/esm/utils/open-api-parameter.d.ts +0 -7
  238. package/lib/esm/utils/open-api-parameter.js +0 -78
  239. package/lib/esm/utils/ordered-map.d.ts +0 -37
  240. package/lib/esm/utils/ordered-map.js +0 -100
  241. package/lib/esm/utils/partial.d.ts +0 -3
  242. package/lib/esm/utils/partial.js +0 -1
  243. package/lib/esm/utils/runnable-type.d.ts +0 -5
  244. package/lib/esm/utils/runnable-type.js +0 -1
  245. package/lib/esm/utils/stream-utils.d.ts +0 -20
  246. package/lib/esm/utils/stream-utils.js +0 -79
  247. package/lib/esm/utils/structured-output-schema.d.ts +0 -3
  248. package/lib/esm/utils/structured-output-schema.js +0 -37
  249. package/lib/esm/utils/union.d.ts +0 -1
  250. package/lib/esm/utils/union.js +0 -1
  251. /package/lib/cjs/{context.js → execution-engine/context.js} +0 -0
  252. /package/lib/esm/{context.js → execution-engine/context.js} +0 -0
@@ -1,32 +0,0 @@
1
- import type { OmitPropsFromUnion } from "../utils/omit";
2
- import type { OrderedRecord } from "../utils/ordered-map";
3
- export type DataType = DataTypeString | DataTypeNumber | DataTypeBoolean | DataTypeObject | DataTypeArray;
4
- export interface DataTypeBase {
5
- id: string;
6
- name?: string;
7
- description?: string;
8
- required?: boolean;
9
- }
10
- export interface DataTypeString extends DataTypeBase {
11
- type: "string";
12
- defaultValue?: string;
13
- multiline?: boolean;
14
- }
15
- export interface DataTypeNumber extends DataTypeBase {
16
- type: "number";
17
- defaultValue?: number;
18
- }
19
- export interface DataTypeBoolean extends DataTypeBase {
20
- type: "boolean";
21
- defaultValue?: boolean;
22
- }
23
- export interface DataTypeObject extends DataTypeBase {
24
- type: "object";
25
- defaultValue?: object;
26
- properties?: OrderedRecord<DataType>;
27
- }
28
- export interface DataTypeArray extends DataTypeBase {
29
- type: "array";
30
- defaultValue?: object[];
31
- items?: OmitPropsFromUnion<DataType, "id">;
32
- }
@@ -1,53 +0,0 @@
1
- import type { Memorable } from "../memorable";
2
- import type { RunnableInputType } from "../runnable";
3
- import { OrderedRecord } from "../utils";
4
- import type { DataSchema } from "./data-schema";
5
- export interface AgentMemory {
6
- id: string;
7
- name?: string;
8
- memory?: Memorable<unknown>;
9
- query?: {
10
- from: "variable";
11
- fromVariableId?: string;
12
- fromVariablePropPath?: string[];
13
- };
14
- options?: {
15
- k?: number;
16
- };
17
- }
18
- export interface CreateRunnableMemory<I extends {
19
- [key: string]: DataSchema;
20
- } = {}> {
21
- /**
22
- * Memory instance to query/store memory.
23
- */
24
- memory: Memorable<any>;
25
- /**
26
- * Custom query to retrieve memory, if not provided, all input variables will be used.
27
- *
28
- * @example
29
- * {
30
- * fromVariable: 'question' // question is a string input variable
31
- * }
32
- */
33
- query?: {
34
- /**
35
- * Variable name from input used to query memory.
36
- */
37
- fromVariable?: keyof {
38
- [key in keyof I as I[key]["type"] extends "string" ? key : never]: any;
39
- };
40
- };
41
- /**
42
- * Custom options for memory query.
43
- */
44
- options?: {
45
- /**
46
- * Number of memories to retrieve.
47
- */
48
- k?: number;
49
- };
50
- }
51
- export declare function toRunnableMemories<I extends {}>(agentName: string, inputs: OrderedRecord<RunnableInputType>, memories: {
52
- [name: string]: CreateRunnableMemory<I>;
53
- }): OrderedRecord<AgentMemory>;
@@ -1,36 +0,0 @@
1
- import type { DataSchema } from "./data-schema";
2
- import type { DataType } from "./data-type";
3
- export interface BaseAuthConfig {
4
- type: "bearer" | "basic";
5
- token: string;
6
- in?: "header" | "query" | "cookie";
7
- /**
8
- * The key to use for the token. Default `Authorization` in header and `token` in query and cookie.
9
- */
10
- key?: string;
11
- }
12
- export interface CustomAuthConfig {
13
- type: "custom";
14
- auth: () => Promise<AuthResult> | AuthResult;
15
- }
16
- export type AuthConfig = BaseAuthConfig | CustomAuthConfig;
17
- export type AuthType = AuthConfig["type"];
18
- export type AuthResult = Pick<FetchRequest, "headers" | "query" | "cookies">;
19
- type HTTPMethodLowercase = "get" | "post" | "put" | "delete" | "patch" | "head" | "options";
20
- export type HTTPMethod = Uppercase<HTTPMethodLowercase> | Lowercase<HTTPMethodLowercase>;
21
- export type ParameterLocation = "path" | "query" | "body" | "header" | "cookie";
22
- export type OpenAPIDataType = DataType & {
23
- in?: ParameterLocation;
24
- };
25
- export type OpenAPIDataTypeSchema = DataSchema & {
26
- in?: ParameterLocation;
27
- };
28
- export type FetchRequest = {
29
- url: string;
30
- method: HTTPMethod;
31
- query?: Record<string, string | number | boolean>;
32
- headers?: Record<string, string>;
33
- cookies?: Record<string, string>;
34
- body?: Record<string, unknown>;
35
- };
36
- export {};
@@ -1,43 +0,0 @@
1
- import type { CreateAgentInputSchema, CreateAgentPreloadsSchema } from "../agent";
2
- import type { Runnable, RunnableInputType } from "../runnable";
3
- import { OrderedRecord } from "../utils/ordered-map";
4
- import type { ExtractRunnableInputType } from "../utils/runnable-type";
5
- import type { UnionToIntersection } from "../utils/union";
6
- import type { SchemaToType } from "./data-schema";
7
- export declare function preloadCreatorsToPreloads<I extends CreateAgentInputSchema, C extends CreateAgentPreloadsSchema<I>>(inputs: OrderedRecord<RunnableInputType>, creators?: C): OrderedRecord<AgentPreload>;
8
- export type PreloadCreator<I extends CreateAgentInputSchema> = (preload: <R extends Runnable, Input extends BindAgentInputs<SchemaToType<I>, R>>(runnable: R, input: Input, options?: {
9
- description?: string;
10
- }) => Readonly<BoundAgent<I, R, Input>>) => ReturnType<typeof preload>;
11
- export type BindAgentInputs<Vars extends Record<string, unknown>, R extends Runnable> = {
12
- [key in keyof ExtractRunnableInputType<R>]: BindAgentInput<Vars, ExtractRunnableInputType<R>[key]>;
13
- };
14
- export interface AgentPreload {
15
- id: string;
16
- name?: string;
17
- runnable?: {
18
- id: string;
19
- };
20
- input?: {
21
- [inputId: string]: BindAgentInput;
22
- };
23
- }
24
- export type BindAgentInput<Vars extends Record<string, unknown> = Record<string, unknown>, Input = unknown> = {
25
- from: "ai";
26
- } | {
27
- from: "input";
28
- fromInput: keyof {
29
- [name in keyof Vars as Vars[name] extends Input ? name : never]: name;
30
- };
31
- };
32
- export interface BoundAgent<Vars extends Record<string, unknown> = Record<string, unknown>, R extends Runnable = Runnable, I extends BindAgentInputs<Vars, R> = BindAgentInputs<Vars, R>> {
33
- description?: string;
34
- runnable: R;
35
- input?: I;
36
- }
37
- type PickInputFrom<I, From extends BindAgentInput["from"]> = {
38
- [key in keyof I as I[key] extends {
39
- from: From;
40
- } ? key : never]: I[key];
41
- };
42
- export type OmitBoundAgentInput<Case extends BoundAgent, From extends BindAgentInput["from"]> = Omit<UnionToIntersection<ExtractRunnableInputType<Case["runnable"]>, Record<string, never>>, keyof PickInputFrom<Required<UnionToIntersection<NonNullable<Case["input"]>, Record<string, never>>>, From>>;
43
- export {};
@@ -1,23 +0,0 @@
1
- import { Agent, type AgentDefinition, type AgentMemories, type AgentPreloads, type AgentProcessInput, type AgentProcessOptions, type CreateAgentInputSchema, type CreateAgentMemoriesSchema, type CreateAgentMemoriesType, type CreateAgentOptions, type CreateAgentOutputSchema, type CreateAgentPreloadsSchema, type CreateAgentPreloadsType } from "./agent";
2
- import type { Context, ContextState } from "./context";
3
- import { type SchemaToType } from "./definitions/data-schema";
4
- import type { RunnableInput, RunnableOutput, RunnableResponse, RunnableResponseChunk } from "./runnable";
5
- export declare class FunctionAgent<I extends RunnableInput = RunnableInput, O extends RunnableOutput = RunnableOutput, State extends ContextState = ContextState, Preloads extends AgentPreloads = AgentPreloads, Memories extends AgentMemories = AgentMemories> extends Agent<I, O, State, Preloads, Memories> {
6
- definition: FunctionAgentDefinition<I, O, State, Preloads, Memories>;
7
- static create: typeof create;
8
- constructor(definition: FunctionAgentDefinition<I, O, State, Preloads, Memories>, context?: Context<State>);
9
- process(input: AgentProcessInput<I, Preloads, Memories>, options: AgentProcessOptions<Preloads, Memories>): Promise<AsyncGenerator<RunnableResponseChunk<O>, void, any> | RunnableResponse<O>>;
10
- }
11
- export interface FunctionAgentDefinition<I extends RunnableInput, O extends RunnableOutput, State extends ContextState, Preloads extends AgentPreloads, Memories extends AgentMemories> extends AgentDefinition {
12
- type: "function_agent";
13
- function?: FunctionFuncType<I, O, State, Preloads, Memories>;
14
- }
15
- export type FunctionFuncType<I extends RunnableInput, O extends RunnableOutput, State extends ContextState, Preloads extends AgentPreloads, Memories extends AgentMemories> = (input: AgentProcessInput<I, Preloads, Memories>, options: {
16
- context: Context<State>;
17
- preloads: Preloads;
18
- memories: Memories;
19
- }) => Promise<RunnableResponse<O> | AsyncGenerator<RunnableResponseChunk<O>, void>> | AsyncGenerator<RunnableResponseChunk<O>, void>;
20
- declare function create<I extends CreateAgentInputSchema, O extends CreateAgentOutputSchema, State extends ContextState, Preloads extends CreateAgentPreloadsSchema<I>, Memories extends CreateAgentMemoriesSchema<I>>(options: CreateAgentOptions<I, O, State, Preloads, Memories> & {
21
- function?: FunctionFuncType<SchemaToType<I>, SchemaToType<O>, State, CreateAgentPreloadsType<I, Preloads>, CreateAgentMemoriesType<I, Memories>>;
22
- }): FunctionAgent<SchemaToType<I>, SchemaToType<O>, State, CreateAgentPreloadsType<I, Preloads>, CreateAgentMemoriesType<I, Memories>>;
23
- export {};
@@ -1,53 +0,0 @@
1
- import { Agent, type AgentDefinition, type AgentMemories, type AgentPreloads, type AgentProcessInput, type AgentProcessOptions, type CreateAgentInputSchema, type CreateAgentMemoriesSchema, type CreateAgentMemoriesType, type CreateAgentOptions, type CreateAgentOutputSchema, type CreateAgentPreloadsSchema, type CreateAgentPreloadsType } from "./agent";
2
- import type { Context, ContextState } from "./context";
3
- import { type SchemaToType } from "./definitions/data-schema";
4
- import type { LLMModel, LLMModelInputMessage, LLMModelInputs } from "./llm-model";
5
- import { type RunnableInput, type RunnableOutput } from "./runnable";
6
- import { OrderedRecord } from "./utils/ordered-map";
7
- export declare class LLMAgent<I extends RunnableInput = RunnableInput, O extends RunnableOutput = RunnableOutput, State extends ContextState = ContextState, Preloads extends AgentPreloads = AgentPreloads, Memories extends AgentMemories = AgentMemories> extends Agent<I, O, State, Preloads, Memories> {
8
- definition: LLMAgentDefinition;
9
- model?: LLMModel | undefined;
10
- static create: typeof create;
11
- constructor(definition: LLMAgentDefinition, context?: Context<State>, model?: LLMModel | undefined);
12
- process(input: AgentProcessInput<I, Preloads, Memories>, options: AgentProcessOptions): AsyncGenerator<{
13
- $text: string | undefined;
14
- delta?: undefined;
15
- } | {
16
- delta: any;
17
- $text?: undefined;
18
- }, void, unknown>;
19
- private runWithStructuredOutput;
20
- private runWithTextOutput;
21
- }
22
- export interface LLMAgentDefinition extends AgentDefinition {
23
- type: "llm_agent";
24
- primaryMemoryId?: string;
25
- messages?: OrderedRecord<LLMModelInputMessage & {
26
- id: string;
27
- }>;
28
- modelOptions?: LLMModelInputs["modelOptions"];
29
- }
30
- /**
31
- * Create LLMAgent definition.
32
- * @param options Options to create LLMAgent.
33
- * @returns LLMAgent definition.
34
- */
35
- declare function create<I extends CreateAgentInputSchema, O extends CreateAgentOutputSchema, State extends ContextState, Preloads extends CreateAgentPreloadsSchema<I>, Memories extends CreateAgentMemoriesSchema<I, {
36
- /**
37
- * Whether this memory is primary? Primary memory will be passed as messages to LLM chat model,
38
- * otherwise, it will be placed in a system message.
39
- *
40
- * Only one primary memory is allowed.
41
- */
42
- primary?: boolean;
43
- }>>(options: CreateAgentOptions<I, O, State, Preloads, Memories> & {
44
- /**
45
- * Options for LLM chat model.
46
- */
47
- modelOptions?: LLMModelInputs["modelOptions"];
48
- /**
49
- * Messages to be passed to LLM chat model.
50
- */
51
- messages?: LLMModelInputMessage[];
52
- }): LLMAgent<SchemaToType<I>, SchemaToType<O>, State, CreateAgentPreloadsType<I, Preloads>, CreateAgentMemoriesType<I, Memories>>;
53
- export {};
@@ -1,53 +0,0 @@
1
- import { Agent, type AgentDefinition, type AgentMemories, type AgentPreloads, type AgentProcessInput, type AgentProcessOptions, type CreateAgentMemoriesSchema, type CreateAgentMemoriesType, type CreateAgentOptions, type CreateAgentPreloadsSchema, type CreateAgentPreloadsType } from "./agent";
2
- import type { Context, ContextState } from "./context";
3
- import type { TypeToSchema } from "./definitions/data-schema";
4
- import type { BindAgentInput, BoundAgent, OmitBoundAgentInput } from "./definitions/preload";
5
- import type { LLMAgentDefinition } from "./llm-agent";
6
- import type { LLMModel, LLMModelInputMessage, LLMModelInputs } from "./llm-model";
7
- import type { RunnableInput, RunnableOutput } from "./runnable";
8
- import { OrderedRecord } from "./utils";
9
- import type { ExtractRunnableInputTypeIntersection, ExtractRunnableOutputType } from "./utils/runnable-type";
10
- export declare class LLMDecisionAgent<I extends RunnableInput = RunnableInput, O extends RunnableOutput = RunnableOutput, State extends ContextState = ContextState, Preloads extends AgentPreloads = AgentPreloads, Memories extends AgentMemories = AgentMemories> extends Agent<I, O, State, Preloads, Memories> {
11
- definition: LLMDecisionAgentDefinition;
12
- model?: LLMModel | undefined;
13
- static create: typeof create;
14
- constructor(definition: LLMDecisionAgentDefinition, context?: Context<State>, model?: LLMModel | undefined);
15
- process(input: AgentProcessInput<I, Preloads, Memories>, options: AgentProcessOptions<Preloads, Memories>): Promise<import("./runnable").RunnableResponse<O>>;
16
- }
17
- declare function create<Case extends BoundAgent, InputType extends ExtractRunnableInputTypeIntersection<Case["runnable"]>, OutputType extends ExtractRunnableOutputType<Case["runnable"]>, State extends ContextState, Preloads extends CreateAgentPreloadsSchema<TypeToSchema<InputType>>, Memories extends CreateAgentMemoriesSchema<TypeToSchema<InputType>, {
18
- /**
19
- * Whether this memory is primary? Primary memory will be passed as messages to LLM chat model,
20
- * otherwise, it will be placed in a system message.
21
- *
22
- * Only one primary memory is allowed.
23
- */
24
- primary?: boolean;
25
- }>>(options: Omit<CreateAgentOptions<never, never, State, Preloads, Memories>, "inputs" | "outputs"> & {
26
- cases: {
27
- [name: string]: Case;
28
- };
29
- /**
30
- * Options for LLM chat model.
31
- */
32
- modelOptions?: LLMModelInputs["modelOptions"];
33
- /**
34
- * Messages to be passed to LLM chat model.
35
- */
36
- messages?: LLMModelInputMessage[];
37
- }): LLMDecisionAgent<OmitBoundAgentInput<Case, "ai">, OutputType, State, CreateAgentPreloadsType<TypeToSchema<InputType>, Preloads>, CreateAgentMemoriesType<TypeToSchema<InputType>, Memories>>;
38
- export interface LLMDecisionAgentDefinition extends AgentDefinition, Pick<LLMAgentDefinition, "modelOptions" | "messages" | "primaryMemoryId"> {
39
- type: "llm_decision_agent";
40
- cases?: OrderedRecord<LLMDecisionCase>;
41
- }
42
- export interface LLMDecisionCase {
43
- id: string;
44
- name?: string;
45
- description?: string;
46
- runnable?: {
47
- id?: string;
48
- };
49
- input?: {
50
- [inputId: string]: BindAgentInput;
51
- };
52
- }
53
- export {};
@@ -1,80 +0,0 @@
1
- import { Agent } from "./agent";
2
- import type { Context } from "./context";
3
- export type Role = "system" | "user" | "assistant" | "tool";
4
- export type 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 type 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
- }
@@ -1,24 +0,0 @@
1
- import { LLMModel, type LLMModelInputs } from "../llm-model";
2
- export declare class GeminiLLMModel extends LLMModel {
3
- private config;
4
- constructor(config: {
5
- apiKey: string;
6
- model: string;
7
- });
8
- private client;
9
- private model;
10
- setApiKey(apiKey: string): void;
11
- process(input: LLMModelInputs): AsyncGenerator<{
12
- $text: string;
13
- delta: {
14
- toolCalls: {
15
- id?: string;
16
- type?: "function";
17
- function?: {
18
- name?: string;
19
- arguments?: string;
20
- };
21
- }[];
22
- };
23
- }, void, unknown>;
24
- }
@@ -1,26 +0,0 @@
1
- import { LLMModel, type LLMModelInputs } from "../llm-model";
2
- export declare class OpenaiLLMModel extends LLMModel {
3
- private config;
4
- constructor(config: {
5
- apiKey: string;
6
- model: string;
7
- });
8
- private client;
9
- setApiKey(apiKey: string): void;
10
- process(input: LLMModelInputs): AsyncGenerator<{
11
- $text: string;
12
- delta?: undefined;
13
- } | {
14
- delta: {
15
- toolCalls: {
16
- id?: string;
17
- type?: "function";
18
- function?: {
19
- name?: string;
20
- arguments?: string;
21
- };
22
- }[];
23
- };
24
- $text?: undefined;
25
- }, void, unknown>;
26
- }
@@ -1,198 +0,0 @@
1
- import { Agent } from "./agent";
2
- import type { Context } from "./context";
3
- import type { LLMModelInputMessage } from "./llm-model";
4
- import { Runnable } from "./runnable";
5
- export type MemoryMetadata = Record<string, unknown>;
6
- export type MemoryActionItem<T> = {
7
- event: "add";
8
- id: string;
9
- memory: T;
10
- metadata?: MemoryMetadata;
11
- } | {
12
- event: "update";
13
- id: string;
14
- memory: T;
15
- oldMemory: T;
16
- metadata?: MemoryMetadata;
17
- } | {
18
- event: "delete";
19
- id: string;
20
- memory: T;
21
- } | {
22
- event: "none";
23
- memory: T;
24
- };
25
- export interface MemoryItem<T> {
26
- id: string;
27
- userId?: string;
28
- sessionId?: string;
29
- agentId?: string;
30
- createdAt: string;
31
- updatedAt: string;
32
- memory: T;
33
- metadata: MemoryMetadata;
34
- }
35
- export interface MemoryItemWithScore<T = unknown> extends MemoryItem<T> {
36
- score: number;
37
- }
38
- export type MemoryMessage = LLMModelInputMessage;
39
- export type MemoryActions<T> = {
40
- action: "add";
41
- inputs: {
42
- messages: MemoryMessage[];
43
- options?: {
44
- userId?: string;
45
- sessionId?: string;
46
- agentId?: string;
47
- metadata?: MemoryMetadata;
48
- };
49
- };
50
- outputs: {
51
- results: MemoryActionItem<T>[];
52
- };
53
- } | {
54
- action: "search";
55
- inputs: {
56
- query: string;
57
- options?: {
58
- k?: number;
59
- userId?: string;
60
- sessionId?: string;
61
- agentId?: string;
62
- filter?: MemoryMetadata;
63
- sort?: MemorySortOptions;
64
- };
65
- };
66
- outputs: {
67
- results: MemoryItemWithScore<T>[];
68
- };
69
- } | {
70
- action: "filter";
71
- inputs: {
72
- options?: {
73
- k?: number;
74
- userId?: string;
75
- sessionId?: string;
76
- agentId?: string;
77
- filter?: MemoryMetadata;
78
- sort?: MemorySortOptions;
79
- };
80
- };
81
- outputs: {
82
- results: MemoryItem<T>[];
83
- };
84
- } | {
85
- action: "get";
86
- inputs: {
87
- memoryId: string;
88
- };
89
- outputs: {
90
- result: MemoryItem<T> | null;
91
- };
92
- } | {
93
- action: "create";
94
- inputs: {
95
- memory: T;
96
- options?: {
97
- userId?: string;
98
- sessionId?: string;
99
- agentId?: string;
100
- metadata?: MemoryMetadata;
101
- };
102
- };
103
- outputs: {
104
- result: MemoryItem<T>;
105
- };
106
- } | {
107
- action: "update";
108
- inputs: {
109
- memoryId: string;
110
- memory: T;
111
- };
112
- outputs: {
113
- result: MemoryItem<T> | null;
114
- };
115
- } | {
116
- action: "delete";
117
- inputs: {
118
- filter: string | string[] | Record<string, unknown>;
119
- };
120
- outputs: {
121
- [name: string]: never;
122
- };
123
- } | {
124
- action: "reset";
125
- inputs: {
126
- [name: string]: never;
127
- };
128
- outputs: {
129
- [name: string]: never;
130
- };
131
- };
132
- export interface SortItem {
133
- field: string;
134
- direction: "asc" | "desc";
135
- }
136
- export type MemorySortOptions = SortItem | SortItem[];
137
- export declare abstract class Memorable<T, C extends Record<string, any> = Record<string, any>> extends Runnable<MemoryActions<T>, MemoryActions<T>["outputs"]> {
138
- constructor(context?: Context);
139
- abstract runner?: MemoryRunner<T, C>;
140
- abstract add(messages: Extract<MemoryActions<T>, {
141
- action: "add";
142
- }>["inputs"]["messages"], options?: Extract<MemoryActions<T>, {
143
- action: "add";
144
- }>["inputs"]["options"]): Promise<Extract<MemoryActions<T>, {
145
- action: "add";
146
- }>["outputs"]>;
147
- abstract search(query: Extract<MemoryActions<T>, {
148
- action: "search";
149
- }>["inputs"]["query"], options?: Extract<MemoryActions<T>, {
150
- action: "search";
151
- }>["inputs"]["options"]): Promise<Extract<MemoryActions<T>, {
152
- action: "search";
153
- }>["outputs"]>;
154
- abstract filter(options: Extract<MemoryActions<T>, {
155
- action: "filter";
156
- }>["inputs"]["options"]): Promise<Extract<MemoryActions<T>, {
157
- action: "filter";
158
- }>["outputs"]>;
159
- abstract get(memoryId: Extract<MemoryActions<T>, {
160
- action: "get";
161
- }>["inputs"]["memoryId"]): Promise<Extract<MemoryActions<T>, {
162
- action: "get";
163
- }>["outputs"]>;
164
- abstract create(memory: Extract<MemoryActions<T>, {
165
- action: "create";
166
- }>["inputs"]["memory"], options?: Extract<MemoryActions<T>, {
167
- action: "create";
168
- }>["inputs"]["options"]): Promise<Extract<MemoryActions<T>, {
169
- action: "create";
170
- }>["outputs"]>;
171
- abstract update(memoryId: Extract<MemoryActions<T>, {
172
- action: "update";
173
- }>["inputs"]["memoryId"], memory: T): Promise<Extract<MemoryActions<T>, {
174
- action: "update";
175
- }>["outputs"]>;
176
- abstract delete(memoryId: Extract<MemoryActions<T>, {
177
- action: "delete";
178
- }>["inputs"]["filter"]): Promise<Extract<MemoryActions<T>, {
179
- action: "delete";
180
- }>["outputs"]>;
181
- abstract reset(): Promise<void>;
182
- }
183
- export type MemoryRunnerInput<C extends Record<string, any> = Record<string, any>> = {
184
- messages: MemoryMessage[];
185
- userId?: string;
186
- sessionId?: string;
187
- agentId?: string;
188
- metadata?: MemoryMetadata;
189
- filter?: MemoryMetadata;
190
- customData: C;
191
- };
192
- export type MemoryRunnerOutput<T> = {
193
- actions: MemoryActionItem<T>[];
194
- };
195
- export declare abstract class MemoryRunner<T, C extends Record<string, any> = Record<string, any>> extends Agent<MemoryRunnerInput<C>, MemoryRunnerOutput<T>> {
196
- constructor(name: string);
197
- }
198
- export type MemorableSearchOutput<T extends Memorable<unknown>> = Awaited<ReturnType<T["search"]>>["results"];
@@ -1,26 +0,0 @@
1
- import { Agent, type AgentDefinition, type AgentMemories, type AgentPreloads, type AgentProcessInput, type CreateAgentInputSchema, type CreateAgentMemoriesSchema, type CreateAgentMemoriesType, type CreateAgentOptions, type CreateAgentOutputSchema, type CreateAgentPreloadsSchema, type CreateAgentPreloadsType } from "./agent";
2
- import type { Context, ContextState } from "./context";
3
- import { type SchemaToType } from "./definitions/data-schema";
4
- import type { AuthConfig, FetchRequest, HTTPMethod, OpenAPIDataType } from "./definitions/open-api";
5
- import type { RunnableInput, RunnableOutput } from "./runnable";
6
- import type { OrderedRecord } from "./utils";
7
- export declare class OpenAPIAgent<I extends RunnableInput = RunnableInput, O extends RunnableOutput = RunnableOutput, State extends ContextState = ContextState, Preloads extends AgentPreloads = AgentPreloads, Memories extends AgentMemories = AgentMemories> extends Agent<I, O, State, Preloads, Memories> {
8
- definition: OpenAPIAgentDefinition;
9
- static create: typeof create;
10
- constructor(definition: OpenAPIAgentDefinition, context?: Context<State>);
11
- process(input: AgentProcessInput<I, Preloads, Memories>): Promise<O>;
12
- fetch<T>(request: FetchRequest): Promise<T>;
13
- }
14
- export interface OpenAPIAgentDefinition extends AgentDefinition {
15
- type: "open_api_agent";
16
- inputs: OrderedRecord<OpenAPIDataType>;
17
- url: string;
18
- method?: HTTPMethod;
19
- auth?: AuthConfig;
20
- }
21
- declare function create<I extends CreateAgentInputSchema, O extends CreateAgentOutputSchema, State extends ContextState, Preloads extends CreateAgentPreloadsSchema<I>, Memories extends CreateAgentMemoriesSchema<I>>(options: CreateAgentOptions<I, O, State, Preloads, Memories> & {
22
- url: string;
23
- method?: HTTPMethod;
24
- auth?: AuthConfig;
25
- }): OpenAPIAgent<SchemaToType<I>, SchemaToType<O>, State, CreateAgentPreloadsType<I, Preloads>, CreateAgentMemoriesType<I, Memories>>;
26
- export {};