@agentica/core 0.8.3 → 0.9.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 (91) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +419 -404
  3. package/lib/Agentica.d.ts +10 -9
  4. package/lib/Agentica.js.map +1 -1
  5. package/lib/chatgpt/ChatGptAgent.d.ts +2 -1
  6. package/lib/chatgpt/ChatGptAgent.js.map +1 -1
  7. package/lib/chatgpt/ChatGptCallFunctionAgent.d.ts +2 -1
  8. package/lib/chatgpt/ChatGptCallFunctionAgent.js +3 -1
  9. package/lib/chatgpt/ChatGptCallFunctionAgent.js.map +1 -1
  10. package/lib/chatgpt/ChatGptCancelFunctionAgent.d.ts +3 -2
  11. package/lib/chatgpt/ChatGptCancelFunctionAgent.js +55 -2
  12. package/lib/chatgpt/ChatGptCancelFunctionAgent.js.map +1 -1
  13. package/lib/chatgpt/ChatGptDescribeFunctionAgent.d.ts +2 -1
  14. package/lib/chatgpt/ChatGptDescribeFunctionAgent.js.map +1 -1
  15. package/lib/chatgpt/ChatGptHistoryDecoder.d.ts +2 -1
  16. package/lib/chatgpt/ChatGptHistoryDecoder.js.map +1 -1
  17. package/lib/chatgpt/ChatGptInitializeFunctionAgent.d.ts +2 -1
  18. package/lib/chatgpt/ChatGptInitializeFunctionAgent.js +63 -1
  19. package/lib/chatgpt/ChatGptInitializeFunctionAgent.js.map +1 -1
  20. package/lib/chatgpt/ChatGptSelectFunctionAgent.d.ts +2 -1
  21. package/lib/chatgpt/ChatGptSelectFunctionAgent.js +55 -2
  22. package/lib/chatgpt/ChatGptSelectFunctionAgent.js.map +1 -1
  23. package/lib/functional/createHttpLlmApplication.js +826 -798
  24. package/lib/functional/createHttpLlmApplication.js.map +1 -1
  25. package/lib/index.mjs +987 -804
  26. package/lib/index.mjs.map +1 -1
  27. package/lib/internal/AgenticaDefaultPrompt.d.ts +2 -1
  28. package/lib/internal/AgenticaDefaultPrompt.js.map +1 -1
  29. package/lib/internal/AgenticaOperationComposer.d.ts +5 -4
  30. package/lib/internal/AgenticaOperationComposer.js +1 -1
  31. package/lib/internal/AgenticaOperationComposer.js.map +1 -1
  32. package/lib/internal/AgenticaPromptFactory.d.ts +3 -2
  33. package/lib/internal/AgenticaPromptFactory.js.map +1 -1
  34. package/lib/internal/AgenticaPromptTransformer.d.ts +5 -4
  35. package/lib/internal/AgenticaPromptTransformer.js.map +1 -1
  36. package/lib/structures/IAgenticaConfig.d.ts +4 -3
  37. package/lib/structures/IAgenticaContext.d.ts +7 -6
  38. package/lib/structures/IAgenticaController.d.ts +8 -8
  39. package/lib/structures/IAgenticaEvent.d.ts +19 -18
  40. package/lib/structures/IAgenticaExecutor.d.ts +7 -6
  41. package/lib/structures/IAgenticaOperation.d.ts +4 -4
  42. package/lib/structures/IAgenticaOperationCollection.d.ts +6 -5
  43. package/lib/structures/IAgenticaOperationSelection.d.ts +4 -4
  44. package/lib/structures/IAgenticaPrompt.d.ts +11 -11
  45. package/lib/structures/IAgenticaProps.d.ts +9 -4
  46. package/lib/structures/IAgenticaProvider.d.ts +22 -27
  47. package/lib/structures/IAgenticaSystemPrompt.d.ts +8 -7
  48. package/package.json +6 -9
  49. package/prompts/cancel.md +4 -4
  50. package/prompts/common.md +2 -2
  51. package/prompts/describe.md +6 -6
  52. package/prompts/execute.md +6 -6
  53. package/prompts/initialize.md +2 -2
  54. package/prompts/select.md +6 -6
  55. package/src/Agentica.ts +323 -318
  56. package/src/chatgpt/ChatGptAgent.ts +75 -71
  57. package/src/chatgpt/ChatGptCallFunctionAgent.ts +448 -445
  58. package/src/chatgpt/ChatGptCancelFunctionAgent.ts +287 -283
  59. package/src/chatgpt/ChatGptDescribeFunctionAgent.ts +52 -51
  60. package/src/chatgpt/ChatGptHistoryDecoder.ts +88 -87
  61. package/src/chatgpt/ChatGptInitializeFunctionAgent.ts +88 -88
  62. package/src/chatgpt/ChatGptSelectFunctionAgent.ts +319 -318
  63. package/src/functional/createHttpLlmApplication.ts +63 -63
  64. package/src/index.ts +19 -19
  65. package/src/internal/AgenticaConstant.ts +4 -4
  66. package/src/internal/AgenticaDefaultPrompt.ts +43 -39
  67. package/src/internal/AgenticaOperationComposer.ts +87 -82
  68. package/src/internal/AgenticaPromptFactory.ts +32 -30
  69. package/src/internal/AgenticaPromptTransformer.ts +86 -83
  70. package/src/internal/AgenticaTokenUsageAggregator.ts +115 -115
  71. package/src/internal/MathUtil.ts +3 -3
  72. package/src/internal/Singleton.ts +22 -22
  73. package/src/internal/__map_take.ts +15 -15
  74. package/src/structures/IAgenticaConfig.ts +123 -121
  75. package/src/structures/IAgenticaContext.ts +129 -128
  76. package/src/structures/IAgenticaController.ts +132 -130
  77. package/src/structures/IAgenticaEvent.ts +229 -224
  78. package/src/structures/IAgenticaExecutor.ts +156 -152
  79. package/src/structures/IAgenticaOperation.ts +64 -64
  80. package/src/structures/IAgenticaOperationCollection.ts +52 -50
  81. package/src/structures/IAgenticaOperationSelection.ts +69 -69
  82. package/src/structures/IAgenticaPrompt.ts +178 -173
  83. package/src/structures/IAgenticaProps.ts +70 -64
  84. package/src/structures/IAgenticaProvider.ts +39 -45
  85. package/src/structures/IAgenticaSystemPrompt.ts +124 -122
  86. package/src/structures/IAgenticaTokenUsage.ts +107 -107
  87. package/src/structures/internal/__IChatCancelFunctionsApplication.ts +23 -23
  88. package/src/structures/internal/__IChatFunctionReference.ts +21 -21
  89. package/src/structures/internal/__IChatInitialApplication.ts +15 -15
  90. package/src/structures/internal/__IChatSelectFunctionsApplication.ts +24 -24
  91. package/src/typings/AgenticaSource.ts +6 -6
@@ -1,224 +1,229 @@
1
- import OpenAI from "openai";
2
-
3
- import { AgenticaSource } from "../typings/AgenticaSource";
4
- import { IAgenticaOperation } from "./IAgenticaOperation";
5
- import { IAgenticaPrompt } from "./IAgenticaPrompt";
6
-
7
- /**
8
- * Nestia A.I. chatbot event.
9
- *
10
- * `IAgenticaEvent` is an union type of all possible events that can
11
- * be emitted by the A.I. chatbot of the {@link Agentica} class. You
12
- * can discriminate the subtype by checking the {@link type} property.
13
- *
14
- * @author Samchon
15
- */
16
- export type IAgenticaEvent =
17
- | IAgenticaEvent.IInitialize
18
- | IAgenticaEvent.ISelect
19
- | IAgenticaEvent.ICancel
20
- | IAgenticaEvent.ICall
21
- | IAgenticaEvent.IExecute
22
- | IAgenticaEvent.IDescribe
23
- | IAgenticaEvent.IText
24
- | IAgenticaEvent.IRequest
25
- | IAgenticaEvent.IResponse;
26
- export namespace IAgenticaEvent {
27
- export type Type = IAgenticaEvent["type"];
28
- export type Mapper = {
29
- initialize: IInitialize;
30
- select: ISelect;
31
- cancel: ICancel;
32
- call: ICall;
33
- execute: IExecute;
34
- describe: IDescribe;
35
- text: IText;
36
- request: IRequest;
37
- response: IResponse;
38
- };
39
-
40
- /**
41
- * Event of initializing the chatbot.
42
- */
43
- export interface IInitialize extends IBase<"initialize"> {}
44
-
45
- /**
46
- * Event of selecting a function to call.
47
- */
48
- export interface ISelect extends IBase<"select"> {
49
- /**
50
- * Selected operation.
51
- *
52
- * Operation that has been selected to prepare LLM function calling.
53
- */
54
- operation: IAgenticaOperation;
55
-
56
- /**
57
- * Reason of selecting the function.
58
- *
59
- * The A.I. chatbot will fill this property describing why the function
60
- * has been selected.
61
- */
62
- reason: string;
63
- }
64
-
65
- /**
66
- * Event of canceling a function calling.
67
- */
68
- export interface ICancel extends IBase<"cancel"> {
69
- /**
70
- * Selected operation to cancel.
71
- *
72
- * Operation that has been selected to prepare LLM function calling,
73
- * but canceled due to no more required.
74
- */
75
- operation: IAgenticaOperation;
76
-
77
- /**
78
- * Reason of selecting the function.
79
- *
80
- * The A.I. chatbot will fill this property describing why the function
81
- * has been cancelled.
82
- *
83
- * For reference, if the A.I. chatbot successfully completes the LLM
84
- * function calling, the reason of the function cancellation will be
85
- * "complete".
86
- */
87
- reason: string;
88
- }
89
-
90
- /**
91
- * Event of calling a function.
92
- */
93
- export interface ICall extends IBase<"call"> {
94
- /**
95
- * ID of the tool calling.
96
- */
97
- id: string;
98
-
99
- /**
100
- * Target operation to call.
101
- */
102
- operation: IAgenticaOperation;
103
-
104
- /**
105
- * Arguments of the function calling.
106
- *
107
- * If you modify this {@link arguments} property, it actually modifies
108
- * the backend server's request. Therefore, be careful when you're
109
- * trying to modify this property.
110
- */
111
- arguments: object;
112
- }
113
-
114
- /**
115
- * Event of function calling execution.
116
- */
117
- export interface IExecute extends IBase<"execute"> {
118
- /**
119
- * ID of the tool calling.
120
- */
121
- id: string;
122
-
123
- /**
124
- * Target operation had called.
125
- */
126
- operation: IAgenticaOperation;
127
-
128
- /**
129
- * Arguments of the function calling.
130
- */
131
- arguments: object;
132
-
133
- /**
134
- * Return value.
135
- */
136
- value: any;
137
- }
138
-
139
- /**
140
- * Event of description.
141
- *
142
- * Event describing return values of LLM function callings.
143
- */
144
- export interface IDescribe extends IBase<"describe"> {
145
- /**
146
- * Executions of the LLM function calling.
147
- *
148
- * This prompt describes the return value of them.
149
- */
150
- executions: IAgenticaPrompt.IExecute[];
151
-
152
- /**
153
- * Description text.
154
- */
155
- text: string;
156
- }
157
-
158
- /**
159
- * Event of text message.
160
- */
161
- export interface IText extends IBase<"text"> {
162
- /**
163
- * Role of the orator.
164
- */
165
- role: "assistant" | "user";
166
-
167
- /**
168
- * The text content.
169
- */
170
- text: string;
171
- }
172
-
173
- /**
174
- * Request event of LLM provider API.
175
- */
176
- export interface IRequest extends IBase<"request"> {
177
- /**
178
- * The source agent of the request.
179
- */
180
- source: AgenticaSource;
181
-
182
- /**
183
- * Request body.
184
- */
185
- body: OpenAI.ChatCompletionCreateParamsNonStreaming;
186
-
187
- /**
188
- * Options for the request.
189
- */
190
- options?: OpenAI.RequestOptions | undefined;
191
- }
192
-
193
- /**
194
- * Response event of LLM provider API.
195
- */
196
- export interface IResponse extends IBase<"response"> {
197
- /**
198
- * The source agent of the response.
199
- */
200
- source: AgenticaSource;
201
-
202
- /**
203
- * Request body.
204
- */
205
- body: OpenAI.ChatCompletionCreateParamsNonStreaming;
206
-
207
- /**
208
- * Options for the request.
209
- */
210
- options?: OpenAI.RequestOptions | undefined;
211
-
212
- /**
213
- * Return value from the LLM provider API.
214
- */
215
- value: OpenAI.ChatCompletion;
216
- }
217
-
218
- interface IBase<Type extends string> {
219
- /**
220
- * Discriminator type.
221
- */
222
- type: Type;
223
- }
224
- }
1
+ import { ILlmSchema } from "@samchon/openapi";
2
+ import OpenAI from "openai";
3
+
4
+ import { AgenticaSource } from "../typings/AgenticaSource";
5
+ import { IAgenticaOperation } from "./IAgenticaOperation";
6
+ import { IAgenticaPrompt } from "./IAgenticaPrompt";
7
+
8
+ /**
9
+ * Nestia A.I. chatbot event.
10
+ *
11
+ * `IAgenticaEvent` is an union type of all possible events that can
12
+ * be emitted by the A.I. chatbot of the {@link Agentica} class. You
13
+ * can discriminate the subtype by checking the {@link type} property.
14
+ *
15
+ * @author Samchon
16
+ */
17
+ export type IAgenticaEvent<Model extends ILlmSchema.Model> =
18
+ | IAgenticaEvent.IInitialize
19
+ | IAgenticaEvent.ISelect<Model>
20
+ | IAgenticaEvent.ICancel<Model>
21
+ | IAgenticaEvent.ICall<Model>
22
+ | IAgenticaEvent.IExecute<Model>
23
+ | IAgenticaEvent.IDescribe<Model>
24
+ | IAgenticaEvent.IText
25
+ | IAgenticaEvent.IRequest
26
+ | IAgenticaEvent.IResponse;
27
+ export namespace IAgenticaEvent {
28
+ export type Type = IAgenticaEvent<any>["type"];
29
+ export type Mapper<Model extends ILlmSchema.Model> = {
30
+ initialize: IInitialize;
31
+ select: ISelect<Model>;
32
+ cancel: ICancel<Model>;
33
+ call: ICall<Model>;
34
+ execute: IExecute<Model>;
35
+ describe: IDescribe<Model>;
36
+ text: IText;
37
+ request: IRequest;
38
+ response: IResponse;
39
+ };
40
+
41
+ /**
42
+ * Event of initializing the chatbot.
43
+ */
44
+ export interface IInitialize extends IBase<"initialize"> {}
45
+
46
+ /**
47
+ * Event of selecting a function to call.
48
+ */
49
+ export interface ISelect<Model extends ILlmSchema.Model>
50
+ extends IBase<"select"> {
51
+ /**
52
+ * Selected operation.
53
+ *
54
+ * Operation that has been selected to prepare LLM function calling.
55
+ */
56
+ operation: IAgenticaOperation<Model>;
57
+
58
+ /**
59
+ * Reason of selecting the function.
60
+ *
61
+ * The A.I. chatbot will fill this property describing why the function
62
+ * has been selected.
63
+ */
64
+ reason: string;
65
+ }
66
+
67
+ /**
68
+ * Event of canceling a function calling.
69
+ */
70
+ export interface ICancel<Model extends ILlmSchema.Model>
71
+ extends IBase<"cancel"> {
72
+ /**
73
+ * Selected operation to cancel.
74
+ *
75
+ * Operation that has been selected to prepare LLM function calling,
76
+ * but canceled due to no more required.
77
+ */
78
+ operation: IAgenticaOperation<Model>;
79
+
80
+ /**
81
+ * Reason of selecting the function.
82
+ *
83
+ * The A.I. chatbot will fill this property describing why the function
84
+ * has been cancelled.
85
+ *
86
+ * For reference, if the A.I. chatbot successfully completes the LLM
87
+ * function calling, the reason of the function cancellation will be
88
+ * "complete".
89
+ */
90
+ reason: string;
91
+ }
92
+
93
+ /**
94
+ * Event of calling a function.
95
+ */
96
+ export interface ICall<Model extends ILlmSchema.Model> extends IBase<"call"> {
97
+ /**
98
+ * ID of the tool calling.
99
+ */
100
+ id: string;
101
+
102
+ /**
103
+ * Target operation to call.
104
+ */
105
+ operation: IAgenticaOperation<Model>;
106
+
107
+ /**
108
+ * Arguments of the function calling.
109
+ *
110
+ * If you modify this {@link arguments} property, it actually modifies
111
+ * the backend server's request. Therefore, be careful when you're
112
+ * trying to modify this property.
113
+ */
114
+ arguments: object;
115
+ }
116
+
117
+ /**
118
+ * Event of function calling execution.
119
+ */
120
+ export interface IExecute<Model extends ILlmSchema.Model>
121
+ extends IBase<"execute"> {
122
+ /**
123
+ * ID of the tool calling.
124
+ */
125
+ id: string;
126
+
127
+ /**
128
+ * Target operation had called.
129
+ */
130
+ operation: IAgenticaOperation<Model>;
131
+
132
+ /**
133
+ * Arguments of the function calling.
134
+ */
135
+ arguments: object;
136
+
137
+ /**
138
+ * Return value.
139
+ */
140
+ value: any;
141
+ }
142
+
143
+ /**
144
+ * Event of description.
145
+ *
146
+ * Event describing return values of LLM function callings.
147
+ */
148
+ export interface IDescribe<Model extends ILlmSchema.Model>
149
+ extends IBase<"describe"> {
150
+ /**
151
+ * Executions of the LLM function calling.
152
+ *
153
+ * This prompt describes the return value of them.
154
+ */
155
+ executions: IAgenticaPrompt.IExecute<Model>[];
156
+
157
+ /**
158
+ * Description text.
159
+ */
160
+ text: string;
161
+ }
162
+
163
+ /**
164
+ * Event of text message.
165
+ */
166
+ export interface IText extends IBase<"text"> {
167
+ /**
168
+ * Role of the orator.
169
+ */
170
+ role: "assistant" | "user";
171
+
172
+ /**
173
+ * The text content.
174
+ */
175
+ text: string;
176
+ }
177
+
178
+ /**
179
+ * Request event of LLM provider API.
180
+ */
181
+ export interface IRequest extends IBase<"request"> {
182
+ /**
183
+ * The source agent of the request.
184
+ */
185
+ source: AgenticaSource;
186
+
187
+ /**
188
+ * Request body.
189
+ */
190
+ body: OpenAI.ChatCompletionCreateParamsNonStreaming;
191
+
192
+ /**
193
+ * Options for the request.
194
+ */
195
+ options?: OpenAI.RequestOptions | undefined;
196
+ }
197
+
198
+ /**
199
+ * Response event of LLM provider API.
200
+ */
201
+ export interface IResponse extends IBase<"response"> {
202
+ /**
203
+ * The source agent of the response.
204
+ */
205
+ source: AgenticaSource;
206
+
207
+ /**
208
+ * Request body.
209
+ */
210
+ body: OpenAI.ChatCompletionCreateParamsNonStreaming;
211
+
212
+ /**
213
+ * Options for the request.
214
+ */
215
+ options?: OpenAI.RequestOptions | undefined;
216
+
217
+ /**
218
+ * Return value from the LLM provider API.
219
+ */
220
+ value: OpenAI.ChatCompletion;
221
+ }
222
+
223
+ interface IBase<Type extends string> {
224
+ /**
225
+ * Discriminator type.
226
+ */
227
+ type: Type;
228
+ }
229
+ }