@agentica/core 0.12.0 → 0.12.2-dev.20250314

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 (83) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +461 -461
  3. package/lib/Agentica.js +3 -1
  4. package/lib/Agentica.js.map +1 -1
  5. package/lib/context/internal/AgenticaTokenUsageAggregator.js +1 -1
  6. package/lib/context/internal/AgenticaTokenUsageAggregator.js.map +1 -1
  7. package/lib/index.mjs +5 -2
  8. package/lib/index.mjs.map +1 -1
  9. package/package.json +1 -1
  10. package/prompts/cancel.md +4 -4
  11. package/prompts/common.md +2 -2
  12. package/prompts/describe.md +6 -6
  13. package/prompts/execute.md +6 -6
  14. package/prompts/initialize.md +2 -2
  15. package/prompts/select.md +6 -6
  16. package/src/Agentica.ts +359 -356
  17. package/src/chatgpt/ChatGptAgent.ts +76 -76
  18. package/src/chatgpt/ChatGptCallFunctionAgent.ts +466 -466
  19. package/src/chatgpt/ChatGptCancelFunctionAgent.ts +280 -280
  20. package/src/chatgpt/ChatGptCompletionMessageUtil.ts +166 -166
  21. package/src/chatgpt/ChatGptDescribeFunctionAgent.ts +122 -122
  22. package/src/chatgpt/ChatGptHistoryDecoder.ts +88 -88
  23. package/src/chatgpt/ChatGptInitializeFunctionAgent.ts +96 -96
  24. package/src/chatgpt/ChatGptSelectFunctionAgent.ts +311 -311
  25. package/src/chatgpt/ChatGptUsageAggregator.ts +62 -62
  26. package/src/context/AgenticaCancelPrompt.ts +32 -32
  27. package/src/context/AgenticaClassOperation.ts +23 -23
  28. package/src/context/AgenticaContext.ts +130 -130
  29. package/src/context/AgenticaHttpOperation.ts +27 -27
  30. package/src/context/AgenticaOperation.ts +66 -66
  31. package/src/context/AgenticaOperationBase.ts +57 -57
  32. package/src/context/AgenticaOperationCollection.ts +52 -52
  33. package/src/context/AgenticaOperationSelection.ts +27 -27
  34. package/src/context/AgenticaTokenUsage.ts +170 -170
  35. package/src/context/internal/AgenticaTokenUsageAggregator.ts +66 -66
  36. package/src/context/internal/__IChatCancelFunctionsApplication.ts +23 -23
  37. package/src/context/internal/__IChatFunctionReference.ts +21 -21
  38. package/src/context/internal/__IChatInitialApplication.ts +15 -15
  39. package/src/context/internal/__IChatSelectFunctionsApplication.ts +24 -24
  40. package/src/events/AgenticaCallEvent.ts +36 -36
  41. package/src/events/AgenticaCancelEvent.ts +28 -28
  42. package/src/events/AgenticaDescribeEvent.ts +66 -66
  43. package/src/events/AgenticaEvent.ts +36 -36
  44. package/src/events/AgenticaEventBase.ts +7 -7
  45. package/src/events/AgenticaEventSource.ts +6 -6
  46. package/src/events/AgenticaExecuteEvent.ts +50 -50
  47. package/src/events/AgenticaInitializeEvent.ts +14 -14
  48. package/src/events/AgenticaRequestEvent.ts +45 -45
  49. package/src/events/AgenticaResponseEvent.ts +48 -48
  50. package/src/events/AgenticaSelectEvent.ts +37 -37
  51. package/src/events/AgenticaTextEvent.ts +62 -62
  52. package/src/functional/assertHttpLlmApplication.ts +55 -55
  53. package/src/functional/validateHttpLlmApplication.ts +66 -66
  54. package/src/index.ts +44 -44
  55. package/src/internal/AgenticaConstant.ts +4 -4
  56. package/src/internal/AgenticaDefaultPrompt.ts +43 -43
  57. package/src/internal/AgenticaOperationComposer.ts +96 -96
  58. package/src/internal/ByteArrayUtil.ts +5 -5
  59. package/src/internal/MPSCUtil.ts +111 -111
  60. package/src/internal/MathUtil.ts +3 -3
  61. package/src/internal/Singleton.ts +22 -22
  62. package/src/internal/StreamUtil.ts +64 -64
  63. package/src/internal/__map_take.ts +15 -15
  64. package/src/json/IAgenticaEventJson.ts +178 -178
  65. package/src/json/IAgenticaOperationJson.ts +36 -36
  66. package/src/json/IAgenticaOperationSelectionJson.ts +19 -19
  67. package/src/json/IAgenticaPromptJson.ts +130 -130
  68. package/src/json/IAgenticaTokenUsageJson.ts +107 -107
  69. package/src/prompts/AgenticaCancelPrompt.ts +32 -32
  70. package/src/prompts/AgenticaDescribePrompt.ts +41 -41
  71. package/src/prompts/AgenticaExecutePrompt.ts +52 -52
  72. package/src/prompts/AgenticaPrompt.ts +14 -14
  73. package/src/prompts/AgenticaPromptBase.ts +27 -27
  74. package/src/prompts/AgenticaSelectPrompt.ts +32 -32
  75. package/src/prompts/AgenticaTextPrompt.ts +31 -31
  76. package/src/structures/IAgenticaConfig.ts +123 -123
  77. package/src/structures/IAgenticaController.ts +133 -133
  78. package/src/structures/IAgenticaExecutor.ts +157 -157
  79. package/src/structures/IAgenticaProps.ts +69 -69
  80. package/src/structures/IAgenticaSystemPrompt.ts +125 -125
  81. package/src/structures/IAgenticaVendor.ts +39 -39
  82. package/src/transformers/AgenticaEventTransformer.ts +165 -165
  83. package/src/transformers/AgenticaPromptTransformer.ts +134 -134
@@ -1,66 +1,66 @@
1
- import { IHttpLlmFunction, ILlmFunction, ILlmSchema } from "@samchon/openapi";
2
-
3
- import { IAgenticaOperationJson } from "../json/IAgenticaOperationJson";
4
- import { IAgenticaController } from "../structures/IAgenticaController";
5
-
6
- /**
7
- * Operation information in the Agentica Agent.
8
- *
9
- * `AgenticaOperation` is a type represents an operation that would
10
- * be selected by the A.I. chatbot of {@link Agentica} class to
11
- * perform the LLM (Large Language Model) function calling.
12
- *
13
- * Also, it is an union type that is discriminated by the {@link protocol}
14
- * property. If the protocol value is `http`, it means that the HTTP API
15
- * operation would be called by the A.I. chatbot. Otherwise, if the protocol
16
- * value is `class`, it means that the operation has come from a
17
- * TypeScript class.
18
- *
19
- * @author Samchon
20
- */
21
- export type AgenticaOperation<Model extends ILlmSchema.Model> =
22
- | AgenticaOperation.Class<Model>
23
- | AgenticaOperation.Http<Model>;
24
- export namespace AgenticaOperation {
25
- export type Class<Model extends ILlmSchema.Model> = Base<
26
- "class",
27
- IAgenticaController.IClass<Model>,
28
- ILlmFunction<Model>
29
- >;
30
- export type Http<Model extends ILlmSchema.Model> = Base<
31
- "http",
32
- IAgenticaController.IHttp<Model>,
33
- IHttpLlmFunction<Model>
34
- >;
35
-
36
- interface Base<
37
- Protocol extends "http" | "class",
38
- Controller extends object,
39
- Function extends object,
40
- > {
41
- /**
42
- * Protocol discriminator.
43
- */
44
- protocol: Protocol;
45
-
46
- /**
47
- * Belonged controller of the target function.
48
- */
49
- controller: Controller;
50
-
51
- /**
52
- * Target function to call.
53
- */
54
- function: Function;
55
-
56
- /**
57
- * Identifier name.
58
- */
59
- name: string;
60
-
61
- /**
62
- * Convert to primitive JSON object.
63
- */
64
- toJSON(): IAgenticaOperationJson;
65
- }
66
- }
1
+ import { IHttpLlmFunction, ILlmFunction, ILlmSchema } from "@samchon/openapi";
2
+
3
+ import { IAgenticaOperationJson } from "../json/IAgenticaOperationJson";
4
+ import { IAgenticaController } from "../structures/IAgenticaController";
5
+
6
+ /**
7
+ * Operation information in the Agentica Agent.
8
+ *
9
+ * `AgenticaOperation` is a type represents an operation that would
10
+ * be selected by the A.I. chatbot of {@link Agentica} class to
11
+ * perform the LLM (Large Language Model) function calling.
12
+ *
13
+ * Also, it is an union type that is discriminated by the {@link protocol}
14
+ * property. If the protocol value is `http`, it means that the HTTP API
15
+ * operation would be called by the A.I. chatbot. Otherwise, if the protocol
16
+ * value is `class`, it means that the operation has come from a
17
+ * TypeScript class.
18
+ *
19
+ * @author Samchon
20
+ */
21
+ export type AgenticaOperation<Model extends ILlmSchema.Model> =
22
+ | AgenticaOperation.Class<Model>
23
+ | AgenticaOperation.Http<Model>;
24
+ export namespace AgenticaOperation {
25
+ export type Class<Model extends ILlmSchema.Model> = Base<
26
+ "class",
27
+ IAgenticaController.IClass<Model>,
28
+ ILlmFunction<Model>
29
+ >;
30
+ export type Http<Model extends ILlmSchema.Model> = Base<
31
+ "http",
32
+ IAgenticaController.IHttp<Model>,
33
+ IHttpLlmFunction<Model>
34
+ >;
35
+
36
+ interface Base<
37
+ Protocol extends "http" | "class",
38
+ Controller extends object,
39
+ Function extends object,
40
+ > {
41
+ /**
42
+ * Protocol discriminator.
43
+ */
44
+ protocol: Protocol;
45
+
46
+ /**
47
+ * Belonged controller of the target function.
48
+ */
49
+ controller: Controller;
50
+
51
+ /**
52
+ * Target function to call.
53
+ */
54
+ function: Function;
55
+
56
+ /**
57
+ * Identifier name.
58
+ */
59
+ name: string;
60
+
61
+ /**
62
+ * Convert to primitive JSON object.
63
+ */
64
+ toJSON(): IAgenticaOperationJson;
65
+ }
66
+ }
@@ -1,57 +1,57 @@
1
- import { IAgenticaOperationJson } from "../json/IAgenticaOperationJson";
2
-
3
- export abstract class AgenticaOperationBase<
4
- Protocol extends "http" | "class",
5
- Controller extends object,
6
- Function extends object,
7
- > {
8
- /**
9
- * Protocol discriminator.
10
- */
11
- public readonly protocol: Protocol;
12
-
13
- /**
14
- * Belonged controller of the target function.
15
- */
16
- public readonly controller: Controller;
17
-
18
- /**
19
- * Target function to call.
20
- */
21
- public readonly function: Function;
22
-
23
- /**
24
- * Identifier name.
25
- */
26
- public readonly name: string;
27
-
28
- protected constructor(
29
- props: AgenticaOperationBase.IProps<Protocol, Controller, Function>,
30
- ) {
31
- this.protocol = props.protocol;
32
- this.controller = props.controller;
33
- this.function = props.function;
34
- this.name = props.name;
35
- }
36
-
37
- public toJSON(): IAgenticaOperationJson {
38
- return {
39
- protocol: this.protocol,
40
- controller: this.controller.constructor.name,
41
- function: this.function.constructor.name,
42
- name: this.name,
43
- };
44
- }
45
- }
46
- export namespace AgenticaOperationBase {
47
- export interface IProps<
48
- Protocol extends "http" | "class",
49
- Controller extends object,
50
- Function extends object,
51
- > {
52
- protocol: Protocol;
53
- controller: Controller;
54
- function: Function;
55
- name: string;
56
- }
57
- }
1
+ import { IAgenticaOperationJson } from "../json/IAgenticaOperationJson";
2
+
3
+ export abstract class AgenticaOperationBase<
4
+ Protocol extends "http" | "class",
5
+ Controller extends object,
6
+ Function extends object,
7
+ > {
8
+ /**
9
+ * Protocol discriminator.
10
+ */
11
+ public readonly protocol: Protocol;
12
+
13
+ /**
14
+ * Belonged controller of the target function.
15
+ */
16
+ public readonly controller: Controller;
17
+
18
+ /**
19
+ * Target function to call.
20
+ */
21
+ public readonly function: Function;
22
+
23
+ /**
24
+ * Identifier name.
25
+ */
26
+ public readonly name: string;
27
+
28
+ protected constructor(
29
+ props: AgenticaOperationBase.IProps<Protocol, Controller, Function>,
30
+ ) {
31
+ this.protocol = props.protocol;
32
+ this.controller = props.controller;
33
+ this.function = props.function;
34
+ this.name = props.name;
35
+ }
36
+
37
+ public toJSON(): IAgenticaOperationJson {
38
+ return {
39
+ protocol: this.protocol,
40
+ controller: this.controller.constructor.name,
41
+ function: this.function.constructor.name,
42
+ name: this.name,
43
+ };
44
+ }
45
+ }
46
+ export namespace AgenticaOperationBase {
47
+ export interface IProps<
48
+ Protocol extends "http" | "class",
49
+ Controller extends object,
50
+ Function extends object,
51
+ > {
52
+ protocol: Protocol;
53
+ controller: Controller;
54
+ function: Function;
55
+ name: string;
56
+ }
57
+ }
@@ -1,52 +1,52 @@
1
- import { ILlmSchema } from "@samchon/openapi";
2
-
3
- import { AgenticaOperation } from "./AgenticaOperation";
4
-
5
- /**
6
- * Collection of operations used in the Nestia Agent.
7
- *
8
- * `IAgenticaOperationCollection` is an interface type representing
9
- * a collection of operations for several purposes used in the
10
- * {@link Agentica} internally.
11
- *
12
- * @author Samchon
13
- */
14
- export interface AgenticaOperationCollection<Model extends ILlmSchema.Model> {
15
- /**
16
- * List of every operations.
17
- */
18
- array: AgenticaOperation<Model>[];
19
-
20
- /**
21
- * Divided operations.
22
- *
23
- * If you've configured the {@link IAgenticaConfig.capacity} property,
24
- * the A.I. chatbot ({@link Agentica}) will separate the operations
25
- * into the several groups to divide and conquer and LLM function selecting
26
- * for accuracy.
27
- *
28
- * In that case, this property `divided`'s length would be dtermined by
29
- * dividing the number of operations ({@link array}'s length) by the
30
- * {@link IAgenticaConfig.capacity}.
31
- *
32
- * Otherwise, if the {@link IAgenticaConfig.capacity} has not been
33
- * configured, this `divided` property would be the `undefined` value.
34
- */
35
- divided?: AgenticaOperation<Model>[][] | undefined;
36
-
37
- /**
38
- * Flat dictionary of operations.
39
- *
40
- * Dictionary of operations with their {@link IAgenticaOperation.name}.
41
- */
42
- flat: Map<string, AgenticaOperation<Model>>;
43
-
44
- /**
45
- * Group dictionary of operations.
46
- *
47
- * Dictionary of operations with their
48
- * {@link IAgenticaOperation.controller.name} and
49
- * {@link IAgenticaOperation.function.name}.
50
- */
51
- group: Map<string, Map<string, AgenticaOperation<Model>>>;
52
- }
1
+ import { ILlmSchema } from "@samchon/openapi";
2
+
3
+ import { AgenticaOperation } from "./AgenticaOperation";
4
+
5
+ /**
6
+ * Collection of operations used in the Nestia Agent.
7
+ *
8
+ * `IAgenticaOperationCollection` is an interface type representing
9
+ * a collection of operations for several purposes used in the
10
+ * {@link Agentica} internally.
11
+ *
12
+ * @author Samchon
13
+ */
14
+ export interface AgenticaOperationCollection<Model extends ILlmSchema.Model> {
15
+ /**
16
+ * List of every operations.
17
+ */
18
+ array: AgenticaOperation<Model>[];
19
+
20
+ /**
21
+ * Divided operations.
22
+ *
23
+ * If you've configured the {@link IAgenticaConfig.capacity} property,
24
+ * the A.I. chatbot ({@link Agentica}) will separate the operations
25
+ * into the several groups to divide and conquer and LLM function selecting
26
+ * for accuracy.
27
+ *
28
+ * In that case, this property `divided`'s length would be dtermined by
29
+ * dividing the number of operations ({@link array}'s length) by the
30
+ * {@link IAgenticaConfig.capacity}.
31
+ *
32
+ * Otherwise, if the {@link IAgenticaConfig.capacity} has not been
33
+ * configured, this `divided` property would be the `undefined` value.
34
+ */
35
+ divided?: AgenticaOperation<Model>[][] | undefined;
36
+
37
+ /**
38
+ * Flat dictionary of operations.
39
+ *
40
+ * Dictionary of operations with their {@link IAgenticaOperation.name}.
41
+ */
42
+ flat: Map<string, AgenticaOperation<Model>>;
43
+
44
+ /**
45
+ * Group dictionary of operations.
46
+ *
47
+ * Dictionary of operations with their
48
+ * {@link IAgenticaOperation.controller.name} and
49
+ * {@link IAgenticaOperation.function.name}.
50
+ */
51
+ group: Map<string, Map<string, AgenticaOperation<Model>>>;
52
+ }
@@ -1,27 +1,27 @@
1
- import { ILlmSchema } from "@samchon/openapi";
2
-
3
- import { IAgenticaOperationSelectionJson } from "../json/IAgenticaOperationSelectionJson";
4
- import { AgenticaOperation } from "./AgenticaOperation";
5
-
6
- export class AgenticaOperationSelection<Model extends ILlmSchema.Model> {
7
- public readonly operation: AgenticaOperation<Model>;
8
- public readonly reason: string;
9
-
10
- public constructor(props: AgenticaOperationSelection.IProps<Model>) {
11
- this.operation = props.operation;
12
- this.reason = props.reason;
13
- }
14
-
15
- public toJSON(): IAgenticaOperationSelectionJson {
16
- return {
17
- operation: this.operation.toJSON(),
18
- reason: this.reason,
19
- };
20
- }
21
- }
22
- export namespace AgenticaOperationSelection {
23
- export interface IProps<Model extends ILlmSchema.Model> {
24
- operation: AgenticaOperation<Model>;
25
- reason: string;
26
- }
27
- }
1
+ import { ILlmSchema } from "@samchon/openapi";
2
+
3
+ import { IAgenticaOperationSelectionJson } from "../json/IAgenticaOperationSelectionJson";
4
+ import { AgenticaOperation } from "./AgenticaOperation";
5
+
6
+ export class AgenticaOperationSelection<Model extends ILlmSchema.Model> {
7
+ public readonly operation: AgenticaOperation<Model>;
8
+ public readonly reason: string;
9
+
10
+ public constructor(props: AgenticaOperationSelection.IProps<Model>) {
11
+ this.operation = props.operation;
12
+ this.reason = props.reason;
13
+ }
14
+
15
+ public toJSON(): IAgenticaOperationSelectionJson {
16
+ return {
17
+ operation: this.operation.toJSON(),
18
+ reason: this.reason,
19
+ };
20
+ }
21
+ }
22
+ export namespace AgenticaOperationSelection {
23
+ export interface IProps<Model extends ILlmSchema.Model> {
24
+ operation: AgenticaOperation<Model>;
25
+ reason: string;
26
+ }
27
+ }