@agentica/core 0.8.3-dev.20250227 → 0.8.3

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 (46) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +404 -404
  3. package/package.json +1 -1
  4. package/prompts/cancel.md +4 -4
  5. package/prompts/common.md +2 -2
  6. package/prompts/describe.md +6 -6
  7. package/prompts/execute.md +6 -6
  8. package/prompts/initialize.md +2 -2
  9. package/prompts/select.md +6 -6
  10. package/src/Agentica.ts +318 -318
  11. package/src/chatgpt/ChatGptAgent.ts +71 -71
  12. package/src/chatgpt/ChatGptCallFunctionAgent.ts +445 -445
  13. package/src/chatgpt/ChatGptCancelFunctionAgent.ts +283 -283
  14. package/src/chatgpt/ChatGptDescribeFunctionAgent.ts +51 -51
  15. package/src/chatgpt/ChatGptHistoryDecoder.ts +87 -87
  16. package/src/chatgpt/ChatGptInitializeFunctionAgent.ts +88 -88
  17. package/src/chatgpt/ChatGptSelectFunctionAgent.ts +318 -318
  18. package/src/functional/createHttpLlmApplication.ts +63 -63
  19. package/src/index.ts +19 -19
  20. package/src/internal/AgenticaConstant.ts +4 -4
  21. package/src/internal/AgenticaDefaultPrompt.ts +39 -39
  22. package/src/internal/AgenticaOperationComposer.ts +82 -82
  23. package/src/internal/AgenticaPromptFactory.ts +30 -30
  24. package/src/internal/AgenticaPromptTransformer.ts +83 -83
  25. package/src/internal/AgenticaTokenUsageAggregator.ts +115 -115
  26. package/src/internal/MathUtil.ts +3 -3
  27. package/src/internal/Singleton.ts +22 -22
  28. package/src/internal/__map_take.ts +15 -15
  29. package/src/structures/IAgenticaConfig.ts +121 -121
  30. package/src/structures/IAgenticaContext.ts +128 -128
  31. package/src/structures/IAgenticaController.ts +130 -130
  32. package/src/structures/IAgenticaEvent.ts +224 -224
  33. package/src/structures/IAgenticaExecutor.ts +152 -152
  34. package/src/structures/IAgenticaOperation.ts +64 -64
  35. package/src/structures/IAgenticaOperationCollection.ts +50 -50
  36. package/src/structures/IAgenticaOperationSelection.ts +69 -69
  37. package/src/structures/IAgenticaPrompt.ts +173 -173
  38. package/src/structures/IAgenticaProps.ts +64 -64
  39. package/src/structures/IAgenticaProvider.ts +45 -45
  40. package/src/structures/IAgenticaSystemPrompt.ts +122 -122
  41. package/src/structures/IAgenticaTokenUsage.ts +107 -107
  42. package/src/structures/internal/__IChatCancelFunctionsApplication.ts +23 -23
  43. package/src/structures/internal/__IChatFunctionReference.ts +21 -21
  44. package/src/structures/internal/__IChatInitialApplication.ts +15 -15
  45. package/src/structures/internal/__IChatSelectFunctionsApplication.ts +24 -24
  46. package/src/typings/AgenticaSource.ts +6 -6
@@ -1,224 +1,224 @@
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 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
+ }