@agentica/core 0.8.2 → 0.8.3-dev.20250227

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 (53) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +404 -404
  3. package/lib/Agentica.js +1 -4
  4. package/lib/Agentica.js.map +1 -1
  5. package/lib/index.mjs +8 -13
  6. package/lib/index.mjs.map +1 -1
  7. package/lib/internal/AgenticaTokenUsageAggregator.js +7 -9
  8. package/lib/internal/AgenticaTokenUsageAggregator.js.map +1 -1
  9. package/lib/structures/IAgenticaTokenUsage.d.ts +7 -11
  10. package/package.json +1 -1
  11. package/prompts/cancel.md +4 -4
  12. package/prompts/common.md +2 -2
  13. package/prompts/describe.md +6 -6
  14. package/prompts/execute.md +6 -6
  15. package/prompts/initialize.md +2 -2
  16. package/prompts/select.md +6 -6
  17. package/src/Agentica.ts +318 -322
  18. package/src/chatgpt/ChatGptAgent.ts +71 -71
  19. package/src/chatgpt/ChatGptCallFunctionAgent.ts +445 -445
  20. package/src/chatgpt/ChatGptCancelFunctionAgent.ts +283 -283
  21. package/src/chatgpt/ChatGptDescribeFunctionAgent.ts +51 -51
  22. package/src/chatgpt/ChatGptHistoryDecoder.ts +87 -87
  23. package/src/chatgpt/ChatGptInitializeFunctionAgent.ts +88 -88
  24. package/src/chatgpt/ChatGptSelectFunctionAgent.ts +318 -318
  25. package/src/functional/createHttpLlmApplication.ts +63 -63
  26. package/src/index.ts +19 -19
  27. package/src/internal/AgenticaConstant.ts +4 -4
  28. package/src/internal/AgenticaDefaultPrompt.ts +39 -39
  29. package/src/internal/AgenticaOperationComposer.ts +82 -82
  30. package/src/internal/AgenticaPromptFactory.ts +30 -30
  31. package/src/internal/AgenticaPromptTransformer.ts +83 -83
  32. package/src/internal/AgenticaTokenUsageAggregator.ts +115 -123
  33. package/src/internal/MathUtil.ts +3 -3
  34. package/src/internal/Singleton.ts +22 -22
  35. package/src/internal/__map_take.ts +15 -15
  36. package/src/structures/IAgenticaConfig.ts +121 -121
  37. package/src/structures/IAgenticaContext.ts +128 -128
  38. package/src/structures/IAgenticaController.ts +130 -130
  39. package/src/structures/IAgenticaEvent.ts +224 -224
  40. package/src/structures/IAgenticaExecutor.ts +152 -152
  41. package/src/structures/IAgenticaOperation.ts +64 -64
  42. package/src/structures/IAgenticaOperationCollection.ts +50 -50
  43. package/src/structures/IAgenticaOperationSelection.ts +69 -69
  44. package/src/structures/IAgenticaPrompt.ts +173 -173
  45. package/src/structures/IAgenticaProps.ts +64 -64
  46. package/src/structures/IAgenticaProvider.ts +45 -45
  47. package/src/structures/IAgenticaSystemPrompt.ts +122 -122
  48. package/src/structures/IAgenticaTokenUsage.ts +107 -112
  49. package/src/structures/internal/__IChatCancelFunctionsApplication.ts +23 -23
  50. package/src/structures/internal/__IChatFunctionReference.ts +21 -21
  51. package/src/structures/internal/__IChatInitialApplication.ts +15 -15
  52. package/src/structures/internal/__IChatSelectFunctionsApplication.ts +24 -24
  53. package/src/typings/AgenticaSource.ts +6 -6
@@ -1,69 +1,69 @@
1
- import { IHttpLlmFunction } from "@samchon/openapi";
2
- import { ILlmFunctionOfValidate } from "typia";
3
-
4
- import { IAgenticaController } from "./IAgenticaController";
5
-
6
- /**
7
- * Nestia agent operation selection.
8
- *
9
- * `IAgenticaOperationSelection` is a type represents an operation
10
- * which has been selected by the A.I. chatbot of {@link Agentica}
11
- * class for the LLM (Large Language Model) function calling with
12
- * detailed {@link reason} of the selection (or cancellation).
13
- *
14
- * Also, `IAgenticaOperationSelection` is an union type that can
15
- * specify a subtype by checking the {@link protocol} property.
16
- *
17
- * @author Samchon
18
- */
19
- export type IAgenticaOperationSelection =
20
- | IAgenticaOperationSelection.IHttp
21
- | IAgenticaOperationSelection.IClass;
22
- export namespace IAgenticaOperationSelection {
23
- export type IHttp = IBase<
24
- "http",
25
- IAgenticaController.IHttp,
26
- IHttpLlmFunction<"chatgpt">
27
- >;
28
-
29
- export type IClass = IBase<
30
- "class",
31
- IAgenticaController.IClass,
32
- ILlmFunctionOfValidate<"chatgpt">
33
- >;
34
-
35
- interface IBase<Protocol, Controller, Function> {
36
- /**
37
- * Discriminator protocol.
38
- */
39
- protocol: Protocol;
40
-
41
- /**
42
- * Belonged controller of the target function.
43
- */
44
- controller: Controller;
45
-
46
- /**
47
- * Target function.
48
- *
49
- * Function that has been selected to prepare LLM function calling,
50
- * or canceled due to no more required.
51
- */
52
- function: Function;
53
-
54
- /**
55
- * Identifier name of the target function.
56
- *
57
- * If {@link Agentica} has multiple {@link IAgenticaController}s,
58
- * the `name` can be different from target function's name.
59
- */
60
- name: string;
61
-
62
- /**
63
- * The reason of the function selection or cancellation.
64
- */
65
- reason: string;
66
-
67
- toJSON(): Omit<IBase<Protocol, string, string>, "toJSON">;
68
- }
69
- }
1
+ import { IHttpLlmFunction } from "@samchon/openapi";
2
+ import { ILlmFunctionOfValidate } from "typia";
3
+
4
+ import { IAgenticaController } from "./IAgenticaController";
5
+
6
+ /**
7
+ * Nestia agent operation selection.
8
+ *
9
+ * `IAgenticaOperationSelection` is a type represents an operation
10
+ * which has been selected by the A.I. chatbot of {@link Agentica}
11
+ * class for the LLM (Large Language Model) function calling with
12
+ * detailed {@link reason} of the selection (or cancellation).
13
+ *
14
+ * Also, `IAgenticaOperationSelection` is an union type that can
15
+ * specify a subtype by checking the {@link protocol} property.
16
+ *
17
+ * @author Samchon
18
+ */
19
+ export type IAgenticaOperationSelection =
20
+ | IAgenticaOperationSelection.IHttp
21
+ | IAgenticaOperationSelection.IClass;
22
+ export namespace IAgenticaOperationSelection {
23
+ export type IHttp = IBase<
24
+ "http",
25
+ IAgenticaController.IHttp,
26
+ IHttpLlmFunction<"chatgpt">
27
+ >;
28
+
29
+ export type IClass = IBase<
30
+ "class",
31
+ IAgenticaController.IClass,
32
+ ILlmFunctionOfValidate<"chatgpt">
33
+ >;
34
+
35
+ interface IBase<Protocol, Controller, Function> {
36
+ /**
37
+ * Discriminator protocol.
38
+ */
39
+ protocol: Protocol;
40
+
41
+ /**
42
+ * Belonged controller of the target function.
43
+ */
44
+ controller: Controller;
45
+
46
+ /**
47
+ * Target function.
48
+ *
49
+ * Function that has been selected to prepare LLM function calling,
50
+ * or canceled due to no more required.
51
+ */
52
+ function: Function;
53
+
54
+ /**
55
+ * Identifier name of the target function.
56
+ *
57
+ * If {@link Agentica} has multiple {@link IAgenticaController}s,
58
+ * the `name` can be different from target function's name.
59
+ */
60
+ name: string;
61
+
62
+ /**
63
+ * The reason of the function selection or cancellation.
64
+ */
65
+ reason: string;
66
+
67
+ toJSON(): Omit<IBase<Protocol, string, string>, "toJSON">;
68
+ }
69
+ }
@@ -1,173 +1,173 @@
1
- import { IHttpLlmFunction, IHttpResponse } from "@samchon/openapi";
2
- import { ILlmFunctionOfValidate } from "typia";
3
-
4
- import { IAgenticaController } from "./IAgenticaController";
5
- import { IAgenticaOperationSelection } from "./IAgenticaOperationSelection";
6
-
7
- /**
8
- * Nestia A.I. chatbot prompt.
9
- *
10
- * `IWrtnChatPrompt` is an union type of all possible prompts that can
11
- * be generated by the A.I. chatbot of the {@link Agentica} class.
12
- *
13
- * In other words, `IWrtnChatPrompt` is a type of chat history that
14
- * is occurred during the conversation between the user and the A.I. chatbot
15
- * in the {@link Agentica} class.
16
- *
17
- * If you want to continue the previous A.I. chatbot session, you can
18
- * accomplish it by assigning the {@link IAgenticaProps.histories}
19
- * property when creating a new {@link Agentica} instance.
20
- *
21
- * @author Samchon
22
- */
23
- export type IAgenticaPrompt =
24
- | IAgenticaPrompt.IText
25
- | IAgenticaPrompt.ISelect
26
- | IAgenticaPrompt.ICancel
27
- | IAgenticaPrompt.IExecute
28
- | IAgenticaPrompt.IDescribe;
29
- export namespace IAgenticaPrompt {
30
- /**
31
- * Select prompt.
32
- *
33
- * Selection prompt about candidate functions to call.
34
- */
35
- export interface ISelect extends IBase<"select"> {
36
- /**
37
- * ID of the LLM tool call result.
38
- */
39
- id: string;
40
-
41
- /**
42
- * Operations that have been selected.
43
- */
44
- operations: IAgenticaOperationSelection[];
45
- }
46
-
47
- /**
48
- * Cancel prompt.
49
- *
50
- * Cancellation prompt about the candidate functions to be discarded.
51
- */
52
- export interface ICancel extends IBase<"cancel"> {
53
- /**
54
- * ID of the LLM tool call result.
55
- */
56
- id: string;
57
-
58
- /**
59
- * Operations that have been cancelled.
60
- */
61
- operations: IAgenticaOperationSelection[];
62
- }
63
-
64
- /**
65
- * Execute prompt.
66
- *
67
- * Execution prompt about the LLM function calling.
68
- */
69
- export type IExecute = IExecute.IHttp | IExecute.IClass;
70
- export namespace IExecute {
71
- export type IHttp = IBase<
72
- "http",
73
- IAgenticaController.IHttp,
74
- IHttpLlmFunction<"chatgpt">,
75
- IHttpResponse
76
- >;
77
- export type IClass = IBase<
78
- "class",
79
- IAgenticaController.IClass,
80
- ILlmFunctionOfValidate<"chatgpt">,
81
- any
82
- >;
83
- interface IBase<Protocol, Controller, Function, Value> {
84
- /**
85
- * Discriminator type.
86
- */
87
- type: "execute";
88
-
89
- /**
90
- * Protocol discriminator.
91
- */
92
- protocol: Protocol;
93
-
94
- /**
95
- * Belonged controller of the target function.
96
- */
97
- controller: Controller;
98
-
99
- /**
100
- * Target function to call.
101
- */
102
- function: Function;
103
-
104
- /**
105
- * ID of the LLM tool call result.
106
- */
107
- id: string;
108
-
109
- /**
110
- * Identifier name of the function.
111
- *
112
- * If {@link Agentica} has multiple {@link IAgenticaController}s,
113
- * the `name` can be different from target function's name.
114
- */
115
- name: string;
116
-
117
- /**
118
- * Arguments of the LLM function calling.
119
- */
120
- arguments: object;
121
-
122
- /**
123
- * Return value.
124
- */
125
- value: Value;
126
-
127
- toJSON(): Omit<IBase<Protocol, string, string, Value>, "toJSON">;
128
- }
129
- }
130
-
131
- /**
132
- * Description prompt.
133
- *
134
- * Description prompt about the return value of the LLM function calling.
135
- */
136
- export interface IDescribe extends IBase<"describe"> {
137
- /**
138
- * Executions of the LLM function calling.
139
- *
140
- * This prompt describes the return value of them.
141
- */
142
- executions: IExecute[];
143
-
144
- /**
145
- * Description text.
146
- */
147
- text: string;
148
- }
149
-
150
- /**
151
- * Text prompt.
152
- */
153
- export interface IText<
154
- Role extends "assistant" | "user" = "assistant" | "user",
155
- > extends IBase<"text"> {
156
- /**
157
- * Role of the orator.
158
- */
159
- role: Role;
160
-
161
- /**
162
- * The text content.
163
- */
164
- text: string;
165
- }
166
-
167
- interface IBase<Type extends string> {
168
- /**
169
- * Discriminator type.
170
- */
171
- type: Type;
172
- }
173
- }
1
+ import { IHttpLlmFunction, IHttpResponse } from "@samchon/openapi";
2
+ import { ILlmFunctionOfValidate } from "typia";
3
+
4
+ import { IAgenticaController } from "./IAgenticaController";
5
+ import { IAgenticaOperationSelection } from "./IAgenticaOperationSelection";
6
+
7
+ /**
8
+ * Nestia A.I. chatbot prompt.
9
+ *
10
+ * `IWrtnChatPrompt` is an union type of all possible prompts that can
11
+ * be generated by the A.I. chatbot of the {@link Agentica} class.
12
+ *
13
+ * In other words, `IWrtnChatPrompt` is a type of chat history that
14
+ * is occurred during the conversation between the user and the A.I. chatbot
15
+ * in the {@link Agentica} class.
16
+ *
17
+ * If you want to continue the previous A.I. chatbot session, you can
18
+ * accomplish it by assigning the {@link IAgenticaProps.histories}
19
+ * property when creating a new {@link Agentica} instance.
20
+ *
21
+ * @author Samchon
22
+ */
23
+ export type IAgenticaPrompt =
24
+ | IAgenticaPrompt.IText
25
+ | IAgenticaPrompt.ISelect
26
+ | IAgenticaPrompt.ICancel
27
+ | IAgenticaPrompt.IExecute
28
+ | IAgenticaPrompt.IDescribe;
29
+ export namespace IAgenticaPrompt {
30
+ /**
31
+ * Select prompt.
32
+ *
33
+ * Selection prompt about candidate functions to call.
34
+ */
35
+ export interface ISelect extends IBase<"select"> {
36
+ /**
37
+ * ID of the LLM tool call result.
38
+ */
39
+ id: string;
40
+
41
+ /**
42
+ * Operations that have been selected.
43
+ */
44
+ operations: IAgenticaOperationSelection[];
45
+ }
46
+
47
+ /**
48
+ * Cancel prompt.
49
+ *
50
+ * Cancellation prompt about the candidate functions to be discarded.
51
+ */
52
+ export interface ICancel extends IBase<"cancel"> {
53
+ /**
54
+ * ID of the LLM tool call result.
55
+ */
56
+ id: string;
57
+
58
+ /**
59
+ * Operations that have been cancelled.
60
+ */
61
+ operations: IAgenticaOperationSelection[];
62
+ }
63
+
64
+ /**
65
+ * Execute prompt.
66
+ *
67
+ * Execution prompt about the LLM function calling.
68
+ */
69
+ export type IExecute = IExecute.IHttp | IExecute.IClass;
70
+ export namespace IExecute {
71
+ export type IHttp = IBase<
72
+ "http",
73
+ IAgenticaController.IHttp,
74
+ IHttpLlmFunction<"chatgpt">,
75
+ IHttpResponse
76
+ >;
77
+ export type IClass = IBase<
78
+ "class",
79
+ IAgenticaController.IClass,
80
+ ILlmFunctionOfValidate<"chatgpt">,
81
+ any
82
+ >;
83
+ interface IBase<Protocol, Controller, Function, Value> {
84
+ /**
85
+ * Discriminator type.
86
+ */
87
+ type: "execute";
88
+
89
+ /**
90
+ * Protocol discriminator.
91
+ */
92
+ protocol: Protocol;
93
+
94
+ /**
95
+ * Belonged controller of the target function.
96
+ */
97
+ controller: Controller;
98
+
99
+ /**
100
+ * Target function to call.
101
+ */
102
+ function: Function;
103
+
104
+ /**
105
+ * ID of the LLM tool call result.
106
+ */
107
+ id: string;
108
+
109
+ /**
110
+ * Identifier name of the function.
111
+ *
112
+ * If {@link Agentica} has multiple {@link IAgenticaController}s,
113
+ * the `name` can be different from target function's name.
114
+ */
115
+ name: string;
116
+
117
+ /**
118
+ * Arguments of the LLM function calling.
119
+ */
120
+ arguments: object;
121
+
122
+ /**
123
+ * Return value.
124
+ */
125
+ value: Value;
126
+
127
+ toJSON(): Omit<IBase<Protocol, string, string, Value>, "toJSON">;
128
+ }
129
+ }
130
+
131
+ /**
132
+ * Description prompt.
133
+ *
134
+ * Description prompt about the return value of the LLM function calling.
135
+ */
136
+ export interface IDescribe extends IBase<"describe"> {
137
+ /**
138
+ * Executions of the LLM function calling.
139
+ *
140
+ * This prompt describes the return value of them.
141
+ */
142
+ executions: IExecute[];
143
+
144
+ /**
145
+ * Description text.
146
+ */
147
+ text: string;
148
+ }
149
+
150
+ /**
151
+ * Text prompt.
152
+ */
153
+ export interface IText<
154
+ Role extends "assistant" | "user" = "assistant" | "user",
155
+ > extends IBase<"text"> {
156
+ /**
157
+ * Role of the orator.
158
+ */
159
+ role: Role;
160
+
161
+ /**
162
+ * The text content.
163
+ */
164
+ text: string;
165
+ }
166
+
167
+ interface IBase<Type extends string> {
168
+ /**
169
+ * Discriminator type.
170
+ */
171
+ type: Type;
172
+ }
173
+ }
@@ -1,64 +1,64 @@
1
- import { Primitive } from "typia";
2
-
3
- import { IAgenticaConfig } from "./IAgenticaConfig";
4
- import { IAgenticaController } from "./IAgenticaController";
5
- import { IAgenticaPrompt } from "./IAgenticaPrompt";
6
- import { IAgenticaProvider } from "./IAgenticaProvider";
7
-
8
- /**
9
- * Properties of the Nestia Agent.
10
- *
11
- * `IAgenticaProps` is an interface that defines the properties
12
- * of the {@link Agentica.constructor}. In the `IAgenticaProps`,
13
- * there're everything to prepare to create a Super A.I. chatbot
14
- * performing the LLM (Large Language Model) function calling.
15
- *
16
- * At first, you have to specify the LLM service {@link provider} like
17
- * OpenAI with its API key and client API. And then, you have to define
18
- * the {@link controllers} serving the functions to call. The controllers
19
- * are separated by two protocols; HTTP API and TypeScript class. At last,
20
- * you can {@link config configure} the agent by setting the locale, timezone,
21
- * and some of system prompts.
22
- *
23
- * Additionally, if you want to start from the previous A.I. chatbot
24
- * session, you can accomplish it by assigning the previous prompt
25
- * histories to the {@link histories} property.
26
- *
27
- * @author Samchon
28
- */
29
- export interface IAgenticaProps {
30
- /**
31
- * LLM service provider.
32
- */
33
- provider: IAgenticaProvider;
34
-
35
- /**
36
- * Controllers serving functions to call.
37
- */
38
- controllers: IAgenticaController[];
39
-
40
- /**
41
- * Configuration of agent.
42
- *
43
- * Configuration of A.I. chatbot agent including the user's locale,
44
- * timezone, and some of system prompts. Also, you can affect to the
45
- * LLM function selecting/calling logic by configuring additional
46
- * properties.
47
- *
48
- * If you don't configure this property, these values would be default.
49
- *
50
- * - `locale`: your system's locale and timezone
51
- * - `timezone`: your system's timezone
52
- * - `systemPrompt`: default prompts written in markdown
53
- * - https://github.com/samchon/nestia/tree/master/packages/agent/prompts
54
- */
55
- config?: IAgenticaConfig;
56
-
57
- /**
58
- * Prompt histories.
59
- *
60
- * If you're starting the conversation from an existing session,
61
- * assign the previouis prompt histories to this property.
62
- */
63
- histories?: Primitive<IAgenticaPrompt>[];
64
- }
1
+ import { Primitive } from "typia";
2
+
3
+ import { IAgenticaConfig } from "./IAgenticaConfig";
4
+ import { IAgenticaController } from "./IAgenticaController";
5
+ import { IAgenticaPrompt } from "./IAgenticaPrompt";
6
+ import { IAgenticaProvider } from "./IAgenticaProvider";
7
+
8
+ /**
9
+ * Properties of the Nestia Agent.
10
+ *
11
+ * `IAgenticaProps` is an interface that defines the properties
12
+ * of the {@link Agentica.constructor}. In the `IAgenticaProps`,
13
+ * there're everything to prepare to create a Super A.I. chatbot
14
+ * performing the LLM (Large Language Model) function calling.
15
+ *
16
+ * At first, you have to specify the LLM service {@link provider} like
17
+ * OpenAI with its API key and client API. And then, you have to define
18
+ * the {@link controllers} serving the functions to call. The controllers
19
+ * are separated by two protocols; HTTP API and TypeScript class. At last,
20
+ * you can {@link config configure} the agent by setting the locale, timezone,
21
+ * and some of system prompts.
22
+ *
23
+ * Additionally, if you want to start from the previous A.I. chatbot
24
+ * session, you can accomplish it by assigning the previous prompt
25
+ * histories to the {@link histories} property.
26
+ *
27
+ * @author Samchon
28
+ */
29
+ export interface IAgenticaProps {
30
+ /**
31
+ * LLM service provider.
32
+ */
33
+ provider: IAgenticaProvider;
34
+
35
+ /**
36
+ * Controllers serving functions to call.
37
+ */
38
+ controllers: IAgenticaController[];
39
+
40
+ /**
41
+ * Configuration of agent.
42
+ *
43
+ * Configuration of A.I. chatbot agent including the user's locale,
44
+ * timezone, and some of system prompts. Also, you can affect to the
45
+ * LLM function selecting/calling logic by configuring additional
46
+ * properties.
47
+ *
48
+ * If you don't configure this property, these values would be default.
49
+ *
50
+ * - `locale`: your system's locale and timezone
51
+ * - `timezone`: your system's timezone
52
+ * - `systemPrompt`: default prompts written in markdown
53
+ * - https://github.com/samchon/nestia/tree/master/packages/agent/prompts
54
+ */
55
+ config?: IAgenticaConfig;
56
+
57
+ /**
58
+ * Prompt histories.
59
+ *
60
+ * If you're starting the conversation from an existing session,
61
+ * assign the previouis prompt histories to this property.
62
+ */
63
+ histories?: Primitive<IAgenticaPrompt>[];
64
+ }