@agentica/core 0.10.0-dev.20250302 → 0.10.0

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 +419 -419
  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 +323 -323
  11. package/src/chatgpt/ChatGptAgent.ts +75 -75
  12. package/src/chatgpt/ChatGptCallFunctionAgent.ts +464 -464
  13. package/src/chatgpt/ChatGptCancelFunctionAgent.ts +287 -287
  14. package/src/chatgpt/ChatGptDescribeFunctionAgent.ts +52 -52
  15. package/src/chatgpt/ChatGptHistoryDecoder.ts +88 -88
  16. package/src/chatgpt/ChatGptInitializeFunctionAgent.ts +88 -88
  17. package/src/chatgpt/ChatGptSelectFunctionAgent.ts +319 -319
  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 +43 -43
  22. package/src/internal/AgenticaOperationComposer.ts +87 -87
  23. package/src/internal/AgenticaPromptFactory.ts +32 -32
  24. package/src/internal/AgenticaPromptTransformer.ts +86 -86
  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 +123 -123
  30. package/src/structures/IAgenticaContext.ts +129 -129
  31. package/src/structures/IAgenticaController.ts +133 -133
  32. package/src/structures/IAgenticaEvent.ts +229 -229
  33. package/src/structures/IAgenticaExecutor.ts +156 -156
  34. package/src/structures/IAgenticaOperation.ts +63 -63
  35. package/src/structures/IAgenticaOperationCollection.ts +52 -52
  36. package/src/structures/IAgenticaOperationSelection.ts +68 -68
  37. package/src/structures/IAgenticaPrompt.ts +182 -182
  38. package/src/structures/IAgenticaProps.ts +70 -70
  39. package/src/structures/IAgenticaSystemPrompt.ts +124 -124
  40. package/src/structures/IAgenticaTokenUsage.ts +107 -107
  41. package/src/structures/IAgenticaVendor.ts +39 -39
  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,229 +1,229 @@
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 vendor 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 vendor 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 vendor API.
219
- */
220
- value: OpenAI.ChatCompletion;
221
- }
222
-
223
- interface IBase<Type extends string> {
224
- /**
225
- * Discriminator type.
226
- */
227
- type: Type;
228
- }
229
- }
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 vendor 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 vendor 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 vendor API.
219
+ */
220
+ value: OpenAI.ChatCompletion;
221
+ }
222
+
223
+ interface IBase<Type extends string> {
224
+ /**
225
+ * Discriminator type.
226
+ */
227
+ type: Type;
228
+ }
229
+ }