@agentica/core 0.9.0 → 0.10.0-dev.20250302

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 (68) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +419 -419
  3. package/lib/Agentica.d.ts +4 -4
  4. package/lib/Agentica.js +7 -7
  5. package/lib/Agentica.js.map +1 -1
  6. package/lib/chatgpt/ChatGptCallFunctionAgent.js +14 -6
  7. package/lib/chatgpt/ChatGptCallFunctionAgent.js.map +1 -1
  8. package/lib/index.d.ts +1 -1
  9. package/lib/index.js +1 -1
  10. package/lib/index.js.map +1 -1
  11. package/lib/index.mjs +10 -5
  12. package/lib/index.mjs.map +1 -1
  13. package/lib/structures/IAgenticaContext.d.ts +1 -1
  14. package/lib/structures/IAgenticaController.d.ts +4 -5
  15. package/lib/structures/IAgenticaEvent.d.ts +3 -3
  16. package/lib/structures/IAgenticaOperation.d.ts +2 -3
  17. package/lib/structures/IAgenticaOperationSelection.d.ts +2 -3
  18. package/lib/structures/IAgenticaPrompt.d.ts +2 -3
  19. package/lib/structures/IAgenticaProps.d.ts +4 -4
  20. package/lib/structures/IAgenticaTokenUsage.d.ts +3 -3
  21. package/lib/structures/{IAgenticaProvider.d.ts → IAgenticaVendor.d.ts} +6 -6
  22. package/lib/structures/{IAgenticaProvider.js → IAgenticaVendor.js} +1 -1
  23. package/lib/structures/IAgenticaVendor.js.map +1 -0
  24. package/package.json +1 -1
  25. package/prompts/cancel.md +4 -4
  26. package/prompts/common.md +2 -2
  27. package/prompts/describe.md +6 -6
  28. package/prompts/execute.md +6 -6
  29. package/prompts/initialize.md +2 -2
  30. package/prompts/select.md +6 -6
  31. package/src/Agentica.ts +323 -323
  32. package/src/chatgpt/ChatGptAgent.ts +75 -75
  33. package/src/chatgpt/ChatGptCallFunctionAgent.ts +464 -448
  34. package/src/chatgpt/ChatGptCancelFunctionAgent.ts +287 -287
  35. package/src/chatgpt/ChatGptDescribeFunctionAgent.ts +52 -52
  36. package/src/chatgpt/ChatGptHistoryDecoder.ts +88 -88
  37. package/src/chatgpt/ChatGptInitializeFunctionAgent.ts +88 -88
  38. package/src/chatgpt/ChatGptSelectFunctionAgent.ts +319 -319
  39. package/src/functional/createHttpLlmApplication.ts +63 -63
  40. package/src/index.ts +19 -19
  41. package/src/internal/AgenticaConstant.ts +4 -4
  42. package/src/internal/AgenticaDefaultPrompt.ts +43 -43
  43. package/src/internal/AgenticaOperationComposer.ts +87 -87
  44. package/src/internal/AgenticaPromptFactory.ts +32 -32
  45. package/src/internal/AgenticaPromptTransformer.ts +86 -86
  46. package/src/internal/AgenticaTokenUsageAggregator.ts +115 -115
  47. package/src/internal/MathUtil.ts +3 -3
  48. package/src/internal/Singleton.ts +22 -22
  49. package/src/internal/__map_take.ts +15 -15
  50. package/src/structures/IAgenticaConfig.ts +123 -123
  51. package/src/structures/IAgenticaContext.ts +129 -129
  52. package/src/structures/IAgenticaController.ts +133 -132
  53. package/src/structures/IAgenticaEvent.ts +229 -229
  54. package/src/structures/IAgenticaExecutor.ts +156 -156
  55. package/src/structures/IAgenticaOperation.ts +63 -64
  56. package/src/structures/IAgenticaOperationCollection.ts +52 -52
  57. package/src/structures/IAgenticaOperationSelection.ts +68 -69
  58. package/src/structures/IAgenticaPrompt.ts +182 -178
  59. package/src/structures/IAgenticaProps.ts +70 -70
  60. package/src/structures/IAgenticaSystemPrompt.ts +124 -124
  61. package/src/structures/IAgenticaTokenUsage.ts +107 -107
  62. package/src/structures/{IAgenticaProvider.ts → IAgenticaVendor.ts} +39 -39
  63. package/src/structures/internal/__IChatCancelFunctionsApplication.ts +23 -23
  64. package/src/structures/internal/__IChatFunctionReference.ts +21 -21
  65. package/src/structures/internal/__IChatInitialApplication.ts +15 -15
  66. package/src/structures/internal/__IChatSelectFunctionsApplication.ts +24 -24
  67. package/src/typings/AgenticaSource.ts +6 -6
  68. package/lib/structures/IAgenticaProvider.js.map +0 -1
@@ -1,63 +1,63 @@
1
- import {
2
- HttpLlm,
3
- IHttpLlmApplication,
4
- OpenApi,
5
- OpenApiV3,
6
- OpenApiV3_1,
7
- SwaggerV2,
8
- } from "@samchon/openapi";
9
- import typia, { IValidation } from "typia";
10
-
11
- /**
12
- * Create an HTTP LLM application instance.
13
- *
14
- * Create an {@link IHttpLlmApplication} instance which represents
15
- * the LLM (Large Language Model) function calling application schema
16
- * from the given Swagger/OpenAPI document and the target LLM model.
17
- *
18
- * By the way, even though this `createHttpLlmApplication` function
19
- * supports every version of Swagger/OpenAPI specification, there can
20
- * be a type error in the given document. In that case, the function
21
- * will return {@link IValidation.IFailure} instance with detailed
22
- * type error tracing information.
23
- *
24
- * @param props Properties to create the HTTP LLM application instance
25
- * @returns Validation result of the HTTP LLM application composition
26
- * @author Samchon
27
- */
28
- export const createHttpLlmApplication = (props: {
29
- /**
30
- * Target LLM model.
31
- */
32
- model: "chatgpt";
33
-
34
- /**
35
- * Swagger/OpenAPI document.
36
- */
37
- document:
38
- | SwaggerV2.IDocument
39
- | OpenApiV3.IDocument
40
- | OpenApiV3_1.IDocument
41
- | OpenApi.IDocument;
42
-
43
- /**
44
- * Options for the LLM function calling schema composition.
45
- */
46
- options?: Partial<IHttpLlmApplication.IOptions<"chatgpt">>;
47
- }): IValidation<IHttpLlmApplication<"chatgpt">> => {
48
- const inspect: IValidation<
49
- | SwaggerV2.IDocument
50
- | OpenApiV3.IDocument
51
- | OpenApiV3_1.IDocument
52
- | OpenApi.IDocument
53
- > = typia.validate(props.document);
54
- if (inspect.success === false) return inspect;
55
- return {
56
- success: true,
57
- data: HttpLlm.application({
58
- model: props.model,
59
- document: OpenApi.convert(props.document),
60
- options: props.options,
61
- }),
62
- };
63
- };
1
+ import {
2
+ HttpLlm,
3
+ IHttpLlmApplication,
4
+ OpenApi,
5
+ OpenApiV3,
6
+ OpenApiV3_1,
7
+ SwaggerV2,
8
+ } from "@samchon/openapi";
9
+ import typia, { IValidation } from "typia";
10
+
11
+ /**
12
+ * Create an HTTP LLM application instance.
13
+ *
14
+ * Create an {@link IHttpLlmApplication} instance which represents
15
+ * the LLM (Large Language Model) function calling application schema
16
+ * from the given Swagger/OpenAPI document and the target LLM model.
17
+ *
18
+ * By the way, even though this `createHttpLlmApplication` function
19
+ * supports every version of Swagger/OpenAPI specification, there can
20
+ * be a type error in the given document. In that case, the function
21
+ * will return {@link IValidation.IFailure} instance with detailed
22
+ * type error tracing information.
23
+ *
24
+ * @param props Properties to create the HTTP LLM application instance
25
+ * @returns Validation result of the HTTP LLM application composition
26
+ * @author Samchon
27
+ */
28
+ export const createHttpLlmApplication = (props: {
29
+ /**
30
+ * Target LLM model.
31
+ */
32
+ model: "chatgpt";
33
+
34
+ /**
35
+ * Swagger/OpenAPI document.
36
+ */
37
+ document:
38
+ | SwaggerV2.IDocument
39
+ | OpenApiV3.IDocument
40
+ | OpenApiV3_1.IDocument
41
+ | OpenApi.IDocument;
42
+
43
+ /**
44
+ * Options for the LLM function calling schema composition.
45
+ */
46
+ options?: Partial<IHttpLlmApplication.IOptions<"chatgpt">>;
47
+ }): IValidation<IHttpLlmApplication<"chatgpt">> => {
48
+ const inspect: IValidation<
49
+ | SwaggerV2.IDocument
50
+ | OpenApiV3.IDocument
51
+ | OpenApiV3_1.IDocument
52
+ | OpenApi.IDocument
53
+ > = typia.validate(props.document);
54
+ if (inspect.success === false) return inspect;
55
+ return {
56
+ success: true,
57
+ data: HttpLlm.application({
58
+ model: props.model,
59
+ document: OpenApi.convert(props.document),
60
+ options: props.options,
61
+ }),
62
+ };
63
+ };
package/src/index.ts CHANGED
@@ -1,19 +1,19 @@
1
- // TYPES
2
- export * from "./structures/IAgenticaConfig";
3
- export * from "./structures/IAgenticaContext";
4
- export * from "./structures/IAgenticaController";
5
- export * from "./structures/IAgenticaEvent";
6
- export * from "./structures/IAgenticaExecutor";
7
- export * from "./structures/IAgenticaOperation";
8
- export * from "./structures/IAgenticaOperationCollection";
9
- export * from "./structures/IAgenticaOperationSelection";
10
- export * from "./structures/IAgenticaPrompt";
11
- export * from "./structures/IAgenticaProps";
12
- export * from "./structures/IAgenticaProvider";
13
- export * from "./structures/IAgenticaSystemPrompt";
14
- export * from "./structures/IAgenticaTokenUsage";
15
- export * from "./typings/AgenticaSource";
16
-
17
- // FACADE CLASS
18
- export * from "./functional/createHttpLlmApplication";
19
- export * from "./Agentica";
1
+ // TYPES
2
+ export * from "./structures/IAgenticaConfig";
3
+ export * from "./structures/IAgenticaContext";
4
+ export * from "./structures/IAgenticaController";
5
+ export * from "./structures/IAgenticaEvent";
6
+ export * from "./structures/IAgenticaExecutor";
7
+ export * from "./structures/IAgenticaOperation";
8
+ export * from "./structures/IAgenticaOperationCollection";
9
+ export * from "./structures/IAgenticaOperationSelection";
10
+ export * from "./structures/IAgenticaPrompt";
11
+ export * from "./structures/IAgenticaProps";
12
+ export * from "./structures/IAgenticaVendor";
13
+ export * from "./structures/IAgenticaSystemPrompt";
14
+ export * from "./structures/IAgenticaTokenUsage";
15
+ export * from "./typings/AgenticaSource";
16
+
17
+ // FACADE CLASS
18
+ export * from "./functional/createHttpLlmApplication";
19
+ export * from "./Agentica";
@@ -1,4 +1,4 @@
1
- export namespace AgenticaConstant {
2
- export const RETRY = 3;
3
- export const ELITICISM = true;
4
- }
1
+ export namespace AgenticaConstant {
2
+ export const RETRY = 3;
3
+ export const ELITICISM = true;
4
+ }
@@ -1,43 +1,43 @@
1
- import { ILlmSchema } from "@samchon/openapi";
2
-
3
- import { IAgenticaConfig } from "../structures/IAgenticaConfig";
4
- import { AgenticaSystemPrompt } from "./AgenticaSystemPrompt";
5
- import { Singleton } from "./Singleton";
6
-
7
- export namespace AgenticaDefaultPrompt {
8
- export const write = <Model extends ILlmSchema.Model>(
9
- config?: IAgenticaConfig<Model>,
10
- ): string => {
11
- if (config?.systemPrompt?.common)
12
- return config?.systemPrompt?.common(config);
13
-
14
- const locale: string = config?.locale ?? getLocale.get();
15
- const timezone: string = config?.timezone ?? getTimezone.get();
16
-
17
- return AgenticaSystemPrompt.COMMON.replace("${locale}", locale).replace(
18
- "${timezone}",
19
- timezone,
20
- );
21
- };
22
- }
23
-
24
- const getLocale = new Singleton(() =>
25
- isNode.get()
26
- ? (process.env.LANG?.split(".")[0] ?? "en-US")
27
- : navigator.language,
28
- );
29
-
30
- const getTimezone = new Singleton(
31
- () => Intl.DateTimeFormat().resolvedOptions().timeZone,
32
- );
33
-
34
- const isNode = new Singleton(() => {
35
- const isObject = (obj: any) => typeof obj === "object" && obj !== null;
36
- return (
37
- typeof global === "object" &&
38
- isObject(global) &&
39
- isObject(global.process) &&
40
- isObject(global.process.versions) &&
41
- typeof global.process.versions.node !== "undefined"
42
- );
43
- });
1
+ import { ILlmSchema } from "@samchon/openapi";
2
+
3
+ import { IAgenticaConfig } from "../structures/IAgenticaConfig";
4
+ import { AgenticaSystemPrompt } from "./AgenticaSystemPrompt";
5
+ import { Singleton } from "./Singleton";
6
+
7
+ export namespace AgenticaDefaultPrompt {
8
+ export const write = <Model extends ILlmSchema.Model>(
9
+ config?: IAgenticaConfig<Model>,
10
+ ): string => {
11
+ if (config?.systemPrompt?.common)
12
+ return config?.systemPrompt?.common(config);
13
+
14
+ const locale: string = config?.locale ?? getLocale.get();
15
+ const timezone: string = config?.timezone ?? getTimezone.get();
16
+
17
+ return AgenticaSystemPrompt.COMMON.replace("${locale}", locale).replace(
18
+ "${timezone}",
19
+ timezone,
20
+ );
21
+ };
22
+ }
23
+
24
+ const getLocale = new Singleton(() =>
25
+ isNode.get()
26
+ ? (process.env.LANG?.split(".")[0] ?? "en-US")
27
+ : navigator.language,
28
+ );
29
+
30
+ const getTimezone = new Singleton(
31
+ () => Intl.DateTimeFormat().resolvedOptions().timeZone,
32
+ );
33
+
34
+ const isNode = new Singleton(() => {
35
+ const isObject = (obj: any) => typeof obj === "object" && obj !== null;
36
+ return (
37
+ typeof global === "object" &&
38
+ isObject(global) &&
39
+ isObject(global.process) &&
40
+ isObject(global.process.versions) &&
41
+ typeof global.process.versions.node !== "undefined"
42
+ );
43
+ });
@@ -1,87 +1,87 @@
1
- import { ILlmSchema } from "@samchon/openapi";
2
-
3
- import { IAgenticaConfig } from "../structures/IAgenticaConfig";
4
- import { IAgenticaController } from "../structures/IAgenticaController";
5
- import { IAgenticaOperation } from "../structures/IAgenticaOperation";
6
- import { IAgenticaOperationCollection } from "../structures/IAgenticaOperationCollection";
7
- import { __map_take } from "./__map_take";
8
-
9
- export namespace AgenticaOperationComposer {
10
- export const compose = <Model extends ILlmSchema.Model>(props: {
11
- controllers: IAgenticaController<Model>[];
12
- config?: IAgenticaConfig<Model> | undefined;
13
- }): IAgenticaOperationCollection<Model> => {
14
- const unique: boolean =
15
- props.controllers.length === 1 ||
16
- (() => {
17
- const names: string[] = props.controllers
18
- .map((controller) =>
19
- controller.application.functions.map((func) => func.name),
20
- )
21
- .flat();
22
- return new Set(names).size === names.length;
23
- })();
24
- const naming = (func: string, ci: number) =>
25
- unique ? func : `_${ci}_${func}`;
26
-
27
- const array: IAgenticaOperation<Model>[] = props.controllers
28
- .map((controller, ci) =>
29
- controller.protocol === "http"
30
- ? controller.application.functions.map(
31
- (func) =>
32
- ({
33
- protocol: "http",
34
- controller: controller,
35
- function: func,
36
- name: naming(func.name, ci),
37
- }) satisfies IAgenticaOperation.IHttp<Model>,
38
- )
39
- : controller.application.functions.map(
40
- (func) =>
41
- ({
42
- protocol: "class",
43
- controller,
44
- function: func,
45
- name: naming(func.name, ci),
46
- }) satisfies IAgenticaOperation.IClass<Model>,
47
- ),
48
- )
49
- .flat();
50
- const divided: IAgenticaOperation<Model>[][] | undefined =
51
- !!props.config?.capacity && array.length > props.config.capacity
52
- ? divideOperations({
53
- array,
54
- capacity: props.config.capacity,
55
- })
56
- : undefined;
57
-
58
- const flat: Map<string, IAgenticaOperation<Model>> = new Map();
59
- const group: Map<
60
- string,
61
- Map<string, IAgenticaOperation<Model>>
62
- > = new Map();
63
- for (const item of array) {
64
- flat.set(item.name, item);
65
- __map_take(group, item.controller.name, () => new Map()).set(
66
- item.name,
67
- item,
68
- );
69
- }
70
- return {
71
- array,
72
- divided,
73
- flat,
74
- group,
75
- };
76
- };
77
-
78
- const divideOperations = <Model extends ILlmSchema.Model>(props: {
79
- array: IAgenticaOperation<Model>[];
80
- capacity: number;
81
- }): IAgenticaOperation<Model>[][] => {
82
- const size: number = Math.ceil(props.array.length / props.capacity);
83
- const capacity: number = Math.ceil(props.array.length / size);
84
- const replica: IAgenticaOperation<Model>[] = props.array.slice();
85
- return new Array(size).fill(0).map(() => replica.splice(0, capacity));
86
- };
87
- }
1
+ import { ILlmSchema } from "@samchon/openapi";
2
+
3
+ import { IAgenticaConfig } from "../structures/IAgenticaConfig";
4
+ import { IAgenticaController } from "../structures/IAgenticaController";
5
+ import { IAgenticaOperation } from "../structures/IAgenticaOperation";
6
+ import { IAgenticaOperationCollection } from "../structures/IAgenticaOperationCollection";
7
+ import { __map_take } from "./__map_take";
8
+
9
+ export namespace AgenticaOperationComposer {
10
+ export const compose = <Model extends ILlmSchema.Model>(props: {
11
+ controllers: IAgenticaController<Model>[];
12
+ config?: IAgenticaConfig<Model> | undefined;
13
+ }): IAgenticaOperationCollection<Model> => {
14
+ const unique: boolean =
15
+ props.controllers.length === 1 ||
16
+ (() => {
17
+ const names: string[] = props.controllers
18
+ .map((controller) =>
19
+ controller.application.functions.map((func) => func.name),
20
+ )
21
+ .flat();
22
+ return new Set(names).size === names.length;
23
+ })();
24
+ const naming = (func: string, ci: number) =>
25
+ unique ? func : `_${ci}_${func}`;
26
+
27
+ const array: IAgenticaOperation<Model>[] = props.controllers
28
+ .map((controller, ci) =>
29
+ controller.protocol === "http"
30
+ ? controller.application.functions.map(
31
+ (func) =>
32
+ ({
33
+ protocol: "http",
34
+ controller: controller,
35
+ function: func,
36
+ name: naming(func.name, ci),
37
+ }) satisfies IAgenticaOperation.IHttp<Model>,
38
+ )
39
+ : controller.application.functions.map(
40
+ (func) =>
41
+ ({
42
+ protocol: "class",
43
+ controller,
44
+ function: func,
45
+ name: naming(func.name, ci),
46
+ }) satisfies IAgenticaOperation.IClass<Model>,
47
+ ),
48
+ )
49
+ .flat();
50
+ const divided: IAgenticaOperation<Model>[][] | undefined =
51
+ !!props.config?.capacity && array.length > props.config.capacity
52
+ ? divideOperations({
53
+ array,
54
+ capacity: props.config.capacity,
55
+ })
56
+ : undefined;
57
+
58
+ const flat: Map<string, IAgenticaOperation<Model>> = new Map();
59
+ const group: Map<
60
+ string,
61
+ Map<string, IAgenticaOperation<Model>>
62
+ > = new Map();
63
+ for (const item of array) {
64
+ flat.set(item.name, item);
65
+ __map_take(group, item.controller.name, () => new Map()).set(
66
+ item.name,
67
+ item,
68
+ );
69
+ }
70
+ return {
71
+ array,
72
+ divided,
73
+ flat,
74
+ group,
75
+ };
76
+ };
77
+
78
+ const divideOperations = <Model extends ILlmSchema.Model>(props: {
79
+ array: IAgenticaOperation<Model>[];
80
+ capacity: number;
81
+ }): IAgenticaOperation<Model>[][] => {
82
+ const size: number = Math.ceil(props.array.length / props.capacity);
83
+ const capacity: number = Math.ceil(props.array.length / size);
84
+ const replica: IAgenticaOperation<Model>[] = props.array.slice();
85
+ return new Array(size).fill(0).map(() => replica.splice(0, capacity));
86
+ };
87
+ }
@@ -1,32 +1,32 @@
1
- import { ILlmSchema } from "@samchon/openapi";
2
-
3
- import { IAgenticaOperationSelection } from "../structures/IAgenticaOperationSelection";
4
- import { IAgenticaPrompt } from "../structures/IAgenticaPrompt";
5
-
6
- export namespace AgenticaPromptFactory {
7
- export const execute = <Model extends ILlmSchema.Model>(
8
- props: Omit<IAgenticaPrompt.IExecute<Model>, "toJSON">,
9
- ): IAgenticaPrompt.IExecute<Model> =>
10
- ({
11
- ...props,
12
- toJSON: () =>
13
- ({
14
- ...props,
15
- controller: props.controller.name,
16
- function: props.function.name,
17
- }) as any,
18
- }) as IAgenticaPrompt.IExecute<Model>;
19
-
20
- export const selection = <Model extends ILlmSchema.Model>(
21
- props: Omit<IAgenticaOperationSelection<Model>, "toJSON">,
22
- ): IAgenticaOperationSelection<Model> =>
23
- ({
24
- ...props,
25
- toJSON: () =>
26
- ({
27
- ...props,
28
- controller: props.controller.name,
29
- function: props.function.name,
30
- }) as any,
31
- }) as IAgenticaOperationSelection<Model>;
32
- }
1
+ import { ILlmSchema } from "@samchon/openapi";
2
+
3
+ import { IAgenticaOperationSelection } from "../structures/IAgenticaOperationSelection";
4
+ import { IAgenticaPrompt } from "../structures/IAgenticaPrompt";
5
+
6
+ export namespace AgenticaPromptFactory {
7
+ export const execute = <Model extends ILlmSchema.Model>(
8
+ props: Omit<IAgenticaPrompt.IExecute<Model>, "toJSON">,
9
+ ): IAgenticaPrompt.IExecute<Model> =>
10
+ ({
11
+ ...props,
12
+ toJSON: () =>
13
+ ({
14
+ ...props,
15
+ controller: props.controller.name,
16
+ function: props.function.name,
17
+ }) as any,
18
+ }) as IAgenticaPrompt.IExecute<Model>;
19
+
20
+ export const selection = <Model extends ILlmSchema.Model>(
21
+ props: Omit<IAgenticaOperationSelection<Model>, "toJSON">,
22
+ ): IAgenticaOperationSelection<Model> =>
23
+ ({
24
+ ...props,
25
+ toJSON: () =>
26
+ ({
27
+ ...props,
28
+ controller: props.controller.name,
29
+ function: props.function.name,
30
+ }) as any,
31
+ }) as IAgenticaOperationSelection<Model>;
32
+ }