@agentica/core 0.7.0-dev.20250224

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 (163) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +464 -0
  3. package/lib/Agentica.d.ts +124 -0
  4. package/lib/Agentica.js +271 -0
  5. package/lib/Agentica.js.map +1 -0
  6. package/lib/chatgpt/ChatGptAgent.d.ts +6 -0
  7. package/lib/chatgpt/ChatGptAgent.js +59 -0
  8. package/lib/chatgpt/ChatGptAgent.js.map +1 -0
  9. package/lib/chatgpt/ChatGptCallFunctionAgent.d.ts +5 -0
  10. package/lib/chatgpt/ChatGptCallFunctionAgent.js +362 -0
  11. package/lib/chatgpt/ChatGptCallFunctionAgent.js.map +1 -0
  12. package/lib/chatgpt/ChatGptCancelFunctionAgent.d.ts +8 -0
  13. package/lib/chatgpt/ChatGptCancelFunctionAgent.js +359 -0
  14. package/lib/chatgpt/ChatGptCancelFunctionAgent.js.map +1 -0
  15. package/lib/chatgpt/ChatGptDescribeFunctionAgent.d.ts +5 -0
  16. package/lib/chatgpt/ChatGptDescribeFunctionAgent.js +56 -0
  17. package/lib/chatgpt/ChatGptDescribeFunctionAgent.js.map +1 -0
  18. package/lib/chatgpt/ChatGptHistoryDecoder.d.ts +5 -0
  19. package/lib/chatgpt/ChatGptHistoryDecoder.js +77 -0
  20. package/lib/chatgpt/ChatGptHistoryDecoder.js.map +1 -0
  21. package/lib/chatgpt/ChatGptInitializeFunctionAgent.d.ts +5 -0
  22. package/lib/chatgpt/ChatGptInitializeFunctionAgent.js +1883 -0
  23. package/lib/chatgpt/ChatGptInitializeFunctionAgent.js.map +1 -0
  24. package/lib/chatgpt/ChatGptSelectFunctionAgent.d.ts +5 -0
  25. package/lib/chatgpt/ChatGptSelectFunctionAgent.js +381 -0
  26. package/lib/chatgpt/ChatGptSelectFunctionAgent.js.map +1 -0
  27. package/lib/functional/createHttpLlmApplication.d.ts +33 -0
  28. package/lib/functional/createHttpLlmApplication.js +7766 -0
  29. package/lib/functional/createHttpLlmApplication.js.map +1 -0
  30. package/lib/index.d.ts +16 -0
  31. package/lib/index.js +35 -0
  32. package/lib/index.js.map +1 -0
  33. package/lib/index.mjs +10366 -0
  34. package/lib/index.mjs.map +1 -0
  35. package/lib/internal/AgenticaConstant.d.ts +4 -0
  36. package/lib/internal/AgenticaConstant.js +9 -0
  37. package/lib/internal/AgenticaConstant.js.map +1 -0
  38. package/lib/internal/AgenticaCostAggregator.d.ts +5 -0
  39. package/lib/internal/AgenticaCostAggregator.js +30 -0
  40. package/lib/internal/AgenticaCostAggregator.js.map +1 -0
  41. package/lib/internal/AgenticaDefaultPrompt.d.ts +4 -0
  42. package/lib/internal/AgenticaDefaultPrompt.js +32 -0
  43. package/lib/internal/AgenticaDefaultPrompt.js.map +1 -0
  44. package/lib/internal/AgenticaOperationComposer.d.ts +9 -0
  45. package/lib/internal/AgenticaOperationComposer.js +58 -0
  46. package/lib/internal/AgenticaOperationComposer.js.map +1 -0
  47. package/lib/internal/AgenticaPromptFactory.d.ts +6 -0
  48. package/lib/internal/AgenticaPromptFactory.js +9 -0
  49. package/lib/internal/AgenticaPromptFactory.js.map +1 -0
  50. package/lib/internal/AgenticaPromptTransformer.d.ts +9 -0
  51. package/lib/internal/AgenticaPromptTransformer.js +58 -0
  52. package/lib/internal/AgenticaPromptTransformer.js.map +1 -0
  53. package/lib/internal/AgenticaSystemPrompt.d.ts +8 -0
  54. package/lib/internal/AgenticaSystemPrompt.js +13 -0
  55. package/lib/internal/AgenticaSystemPrompt.js.map +1 -0
  56. package/lib/internal/MathUtil.d.ts +3 -0
  57. package/lib/internal/MathUtil.js +8 -0
  58. package/lib/internal/MathUtil.js.map +1 -0
  59. package/lib/internal/Singleton.d.ts +1 -0
  60. package/lib/internal/Singleton.js +23 -0
  61. package/lib/internal/Singleton.js.map +1 -0
  62. package/lib/internal/__map_take.d.ts +1 -0
  63. package/lib/internal/__map_take.js +16 -0
  64. package/lib/internal/__map_take.js.map +1 -0
  65. package/lib/structures/IAgenticaConfig.d.ts +112 -0
  66. package/lib/structures/IAgenticaConfig.js +3 -0
  67. package/lib/structures/IAgenticaConfig.js.map +1 -0
  68. package/lib/structures/IAgenticaContext.d.ts +106 -0
  69. package/lib/structures/IAgenticaContext.js +3 -0
  70. package/lib/structures/IAgenticaContext.js.map +1 -0
  71. package/lib/structures/IAgenticaController.d.ts +110 -0
  72. package/lib/structures/IAgenticaController.js +3 -0
  73. package/lib/structures/IAgenticaController.js.map +1 -0
  74. package/lib/structures/IAgenticaEvent.d.ts +191 -0
  75. package/lib/structures/IAgenticaEvent.js +3 -0
  76. package/lib/structures/IAgenticaEvent.js.map +1 -0
  77. package/lib/structures/IAgenticaExecutor.d.ts +144 -0
  78. package/lib/structures/IAgenticaExecutor.js +3 -0
  79. package/lib/structures/IAgenticaExecutor.js.map +1 -0
  80. package/lib/structures/IAgenticaOperation.d.ts +48 -0
  81. package/lib/structures/IAgenticaOperation.js +3 -0
  82. package/lib/structures/IAgenticaOperation.js.map +1 -0
  83. package/lib/structures/IAgenticaOperationCollection.d.ts +46 -0
  84. package/lib/structures/IAgenticaOperationCollection.js +3 -0
  85. package/lib/structures/IAgenticaOperationCollection.js.map +1 -0
  86. package/lib/structures/IAgenticaOperationSelection.d.ts +51 -0
  87. package/lib/structures/IAgenticaOperationSelection.js +3 -0
  88. package/lib/structures/IAgenticaOperationSelection.js.map +1 -0
  89. package/lib/structures/IAgenticaPrompt.d.ts +139 -0
  90. package/lib/structures/IAgenticaPrompt.js +3 -0
  91. package/lib/structures/IAgenticaPrompt.js.map +1 -0
  92. package/lib/structures/IAgenticaProps.d.ts +59 -0
  93. package/lib/structures/IAgenticaProps.js +3 -0
  94. package/lib/structures/IAgenticaProps.js.map +1 -0
  95. package/lib/structures/IAgenticaProvider.d.ts +41 -0
  96. package/lib/structures/IAgenticaProvider.js +3 -0
  97. package/lib/structures/IAgenticaProvider.js.map +1 -0
  98. package/lib/structures/IAgenticaSystemPrompt.d.ts +116 -0
  99. package/lib/structures/IAgenticaSystemPrompt.js +3 -0
  100. package/lib/structures/IAgenticaSystemPrompt.js.map +1 -0
  101. package/lib/structures/IAgenticaTokenUsage.d.ts +50 -0
  102. package/lib/structures/IAgenticaTokenUsage.js +3 -0
  103. package/lib/structures/IAgenticaTokenUsage.js.map +1 -0
  104. package/lib/structures/internal/__IChatCancelFunctionsApplication.d.ts +22 -0
  105. package/lib/structures/internal/__IChatCancelFunctionsApplication.js +3 -0
  106. package/lib/structures/internal/__IChatCancelFunctionsApplication.js.map +1 -0
  107. package/lib/structures/internal/__IChatFunctionReference.d.ts +20 -0
  108. package/lib/structures/internal/__IChatFunctionReference.js +3 -0
  109. package/lib/structures/internal/__IChatFunctionReference.js.map +1 -0
  110. package/lib/structures/internal/__IChatInitialApplication.d.ts +14 -0
  111. package/lib/structures/internal/__IChatInitialApplication.js +3 -0
  112. package/lib/structures/internal/__IChatInitialApplication.js.map +1 -0
  113. package/lib/structures/internal/__IChatSelectFunctionsApplication.d.ts +23 -0
  114. package/lib/structures/internal/__IChatSelectFunctionsApplication.js +3 -0
  115. package/lib/structures/internal/__IChatSelectFunctionsApplication.js.map +1 -0
  116. package/lib/typings/AgenticaSource.d.ts +1 -0
  117. package/lib/typings/AgenticaSource.js +3 -0
  118. package/lib/typings/AgenticaSource.js.map +1 -0
  119. package/package.json +74 -0
  120. package/prompts/cancel.md +5 -0
  121. package/prompts/common.md +3 -0
  122. package/prompts/describe.md +7 -0
  123. package/prompts/execute.md +7 -0
  124. package/prompts/initialize.md +3 -0
  125. package/prompts/select.md +7 -0
  126. package/src/Agentica.ts +322 -0
  127. package/src/chatgpt/ChatGptAgent.ts +71 -0
  128. package/src/chatgpt/ChatGptCallFunctionAgent.ts +445 -0
  129. package/src/chatgpt/ChatGptCancelFunctionAgent.ts +283 -0
  130. package/src/chatgpt/ChatGptDescribeFunctionAgent.ts +51 -0
  131. package/src/chatgpt/ChatGptHistoryDecoder.ts +86 -0
  132. package/src/chatgpt/ChatGptInitializeFunctionAgent.ts +88 -0
  133. package/src/chatgpt/ChatGptSelectFunctionAgent.ts +316 -0
  134. package/src/functional/createHttpLlmApplication.ts +63 -0
  135. package/src/index.ts +19 -0
  136. package/src/internal/AgenticaConstant.ts +4 -0
  137. package/src/internal/AgenticaCostAggregator.ts +35 -0
  138. package/src/internal/AgenticaDefaultPrompt.ts +39 -0
  139. package/src/internal/AgenticaOperationComposer.ts +82 -0
  140. package/src/internal/AgenticaPromptFactory.ts +30 -0
  141. package/src/internal/AgenticaPromptTransformer.ts +83 -0
  142. package/src/internal/AgenticaSystemPrompt.ts +14 -0
  143. package/src/internal/MathUtil.ts +3 -0
  144. package/src/internal/Singleton.ts +22 -0
  145. package/src/internal/__map_take.ts +15 -0
  146. package/src/structures/IAgenticaConfig.ts +121 -0
  147. package/src/structures/IAgenticaContext.ts +128 -0
  148. package/src/structures/IAgenticaController.ts +130 -0
  149. package/src/structures/IAgenticaEvent.ts +224 -0
  150. package/src/structures/IAgenticaExecutor.ts +152 -0
  151. package/src/structures/IAgenticaOperation.ts +64 -0
  152. package/src/structures/IAgenticaOperationCollection.ts +50 -0
  153. package/src/structures/IAgenticaOperationSelection.ts +69 -0
  154. package/src/structures/IAgenticaPrompt.ts +173 -0
  155. package/src/structures/IAgenticaProps.ts +64 -0
  156. package/src/structures/IAgenticaProvider.ts +45 -0
  157. package/src/structures/IAgenticaSystemPrompt.ts +122 -0
  158. package/src/structures/IAgenticaTokenUsage.ts +52 -0
  159. package/src/structures/internal/__IChatCancelFunctionsApplication.ts +23 -0
  160. package/src/structures/internal/__IChatFunctionReference.ts +21 -0
  161. package/src/structures/internal/__IChatInitialApplication.ts +15 -0
  162. package/src/structures/internal/__IChatSelectFunctionsApplication.ts +24 -0
  163. package/src/typings/AgenticaSource.ts +6 -0
@@ -0,0 +1,271 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.Agentica = void 0;
13
+ const ChatGptAgent_1 = require("./chatgpt/ChatGptAgent");
14
+ const AgenticaCostAggregator_1 = require("./internal/AgenticaCostAggregator");
15
+ const AgenticaOperationComposer_1 = require("./internal/AgenticaOperationComposer");
16
+ const AgenticaPromptTransformer_1 = require("./internal/AgenticaPromptTransformer");
17
+ const __map_take_1 = require("./internal/__map_take");
18
+ /**
19
+ * Nestia A.I. chatbot agent.
20
+ *
21
+ * `Agentica` is a facade class for the super A.I. chatbot agent
22
+ * which performs the {@link converstate user's conversation function}
23
+ * with LLM (Large Language Model) function calling and manages the
24
+ * {@link getPromptHistories prompt histories}.
25
+ *
26
+ * To understand and compose the `Agentica` class exactly, reference
27
+ * below types concentrating on the documentation comments please.
28
+ * Especially, you have to be careful about the {@link IAgenticaProps}
29
+ * type which is used in the {@link constructor} function.
30
+ *
31
+ * - Constructors
32
+ * - {@link IAgenticaProps}
33
+ * - {@link IAgenticaProvider}
34
+ * - {@link IAgenticaController}
35
+ * - {@link IAgenticaConfig}
36
+ * - {@link IAgenticaSystemPrompt}
37
+ * - Accessors
38
+ * - {@link IAgenticaOperation}
39
+ * - {@link IAgenticaPrompt}
40
+ * - {@link IAgenticaEvent}
41
+ * - {@link IAgenticaTokenUsage}
42
+ *
43
+ * @author Samchon
44
+ */
45
+ class Agentica {
46
+ /* -----------------------------------------------------------
47
+ CONSTRUCTOR
48
+ ----------------------------------------------------------- */
49
+ /**
50
+ * Initializer constructor.
51
+ *
52
+ * @param props Properties to construct the agent
53
+ */
54
+ constructor(props) {
55
+ var _a, _b, _c, _d;
56
+ this.props = props;
57
+ // OPERATIONS
58
+ this.operations_ = AgenticaOperationComposer_1.AgenticaOperationComposer.compose({
59
+ controllers: props.controllers,
60
+ config: props.config,
61
+ });
62
+ // STATUS
63
+ this.stack_ = [];
64
+ this.listeners_ = new Map();
65
+ this.prompt_histories_ = ((_a = props.histories) !== null && _a !== void 0 ? _a : []).map((input) => AgenticaPromptTransformer_1.AgenticaPromptTransformer.transform({
66
+ operations: this.operations_.group,
67
+ input,
68
+ }));
69
+ // STATUS
70
+ this.token_usage_ = {
71
+ total: 0,
72
+ prompt: {
73
+ total: 0,
74
+ audio: 0,
75
+ cached: 0,
76
+ },
77
+ completion: {
78
+ total: 0,
79
+ accepted_prediction: 0,
80
+ audio: 0,
81
+ reasoning: 0,
82
+ rejected_prediction: 0,
83
+ },
84
+ };
85
+ this.ready_ = false;
86
+ this.executor_ =
87
+ typeof ((_b = props.config) === null || _b === void 0 ? void 0 : _b.executor) === "function"
88
+ ? props.config.executor
89
+ : ChatGptAgent_1.ChatGptAgent.execute((_d = (_c = props.config) === null || _c === void 0 ? void 0 : _c.executor) !== null && _d !== void 0 ? _d : null);
90
+ }
91
+ /**
92
+ * @internal
93
+ */
94
+ clone() {
95
+ var _a;
96
+ return new Agentica(Object.assign(Object.assign({}, this.props), { histories: (_a = this.props.histories) === null || _a === void 0 ? void 0 : _a.slice() }));
97
+ }
98
+ /* -----------------------------------------------------------
99
+ ACCESSORS
100
+ ----------------------------------------------------------- */
101
+ /**
102
+ * Conversate with the A.I. chatbot.
103
+ *
104
+ * User talks to the A.I. chatbot with the content.
105
+ *
106
+ * When the user's conversation implies the A.I. chatbot to execute a
107
+ * function calling, the returned chat prompts will contain the
108
+ * function calling information like {@link IAgenticaPrompt.IExecute}.
109
+ *
110
+ * @param content The content to talk
111
+ * @returns List of newly created chat prompts
112
+ */
113
+ conversate(content) {
114
+ return __awaiter(this, void 0, void 0, function* () {
115
+ const prompt = {
116
+ type: "text",
117
+ role: "user",
118
+ text: content,
119
+ };
120
+ yield this.dispatch(prompt);
121
+ const newbie = yield this.executor_(this.getContext({
122
+ prompt,
123
+ usage: this.token_usage_,
124
+ }));
125
+ this.prompt_histories_.push(prompt, ...newbie);
126
+ return [prompt, ...newbie];
127
+ });
128
+ }
129
+ /**
130
+ * Get configuration.
131
+ */
132
+ getConfig() {
133
+ return this.props.config;
134
+ }
135
+ /**
136
+ * Get LLM Provider.
137
+ */
138
+ getProvider() {
139
+ return this.props.provider;
140
+ }
141
+ /**
142
+ * Get controllers.
143
+ *
144
+ * Get list of controllers, which are the collection of functions that
145
+ * the "Super A.I. Chatbot" can execute.
146
+ */
147
+ getControllers() {
148
+ return this.props.controllers;
149
+ }
150
+ /**
151
+ * Get operations.
152
+ *
153
+ * Get list of operations, which has capsuled the pair of controller
154
+ * and function from the {@link getControllers controllers}.
155
+ *
156
+ * @returns
157
+ */
158
+ getOperations() {
159
+ return this.operations_.array;
160
+ }
161
+ /**
162
+ * Get the chatbot's prompt histories.
163
+ *
164
+ * Get list of chat prompts that the chatbot has been conversated.
165
+ *
166
+ * @returns List of chat prompts
167
+ */
168
+ getPromptHistories() {
169
+ return this.prompt_histories_;
170
+ }
171
+ /**
172
+ * Get token usage of the A.I. chatbot.
173
+ *
174
+ * Entire token usage of the A.I. chatbot during the conversating
175
+ * with the user by {@link conversate} method callings.
176
+ *
177
+ * @returns Cost of the A.I. chatbot
178
+ */
179
+ getTokenUsage() {
180
+ return this.token_usage_;
181
+ }
182
+ /**
183
+ * @internal
184
+ */
185
+ getContext(props) {
186
+ const dispatch = (event) => this.dispatch(event);
187
+ return {
188
+ // APPLICATION
189
+ operations: this.operations_,
190
+ config: this.props.config,
191
+ // STATES
192
+ histories: this.prompt_histories_,
193
+ stack: this.stack_,
194
+ ready: () => this.ready_,
195
+ prompt: props.prompt,
196
+ // HANDLERS
197
+ dispatch,
198
+ request: (source, body) => __awaiter(this, void 0, void 0, function* () {
199
+ // request information
200
+ const event = {
201
+ type: "request",
202
+ source,
203
+ body: Object.assign(Object.assign({}, body), { model: this.props.provider.model }),
204
+ options: this.props.provider.options,
205
+ };
206
+ yield dispatch(event);
207
+ // completion
208
+ const value = yield this.props.provider.api.chat.completions.create(event.body, event.options);
209
+ AgenticaCostAggregator_1.AgenticaCostAggregator.aggregate(props.usage, value);
210
+ yield dispatch({
211
+ type: "response",
212
+ source,
213
+ body: event.body,
214
+ options: event.options,
215
+ value,
216
+ });
217
+ return value;
218
+ }),
219
+ initialize: () => __awaiter(this, void 0, void 0, function* () {
220
+ this.ready_ = true;
221
+ yield dispatch({
222
+ type: "initialize",
223
+ });
224
+ }),
225
+ };
226
+ }
227
+ /* -----------------------------------------------------------
228
+ EVENT HANDLERS
229
+ ----------------------------------------------------------- */
230
+ /**
231
+ * Add an event listener.
232
+ *
233
+ * Add an event listener to be called whenever the event is emitted.
234
+ *
235
+ * @param type Type of event
236
+ * @param listener Callback function to be called whenever the event is emitted
237
+ */
238
+ on(type, listener) {
239
+ (0, __map_take_1.__map_take)(this.listeners_, type, () => new Set()).add(listener);
240
+ }
241
+ /**
242
+ * Erase an event listener.
243
+ *
244
+ * Erase an event listener to stop calling the callback function.
245
+ *
246
+ * @param type Type of event
247
+ * @param listener Callback function to erase
248
+ */
249
+ off(type, listener) {
250
+ const set = this.listeners_.get(type);
251
+ if (set) {
252
+ set.delete(listener);
253
+ if (set.size === 0)
254
+ this.listeners_.delete(type);
255
+ }
256
+ }
257
+ dispatch(event) {
258
+ return __awaiter(this, void 0, void 0, function* () {
259
+ const set = this.listeners_.get(event.type);
260
+ if (set)
261
+ yield Promise.all(Array.from(set).map((listener) => __awaiter(this, void 0, void 0, function* () {
262
+ try {
263
+ yield listener(event);
264
+ }
265
+ catch (_a) { }
266
+ })));
267
+ });
268
+ }
269
+ }
270
+ exports.Agentica = Agentica;
271
+ //# sourceMappingURL=Agentica.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":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KAAK,CAAC,CAAC;oBACxB,CAAC;oBAAC,WAAM,CAAC,CAAA,CAAC;gBACZ,CAAC,CAAA,CAAC,CACH,CAAC;QACN,CAAC;KAAA;CACF;AAnRD,4BAmRC"}
@@ -0,0 +1,6 @@
1
+ import { IAgenticaContext } from "../structures/IAgenticaContext";
2
+ import { IAgenticaExecutor } from "../structures/IAgenticaExecutor";
3
+ import { IAgenticaPrompt } from "../structures/IAgenticaPrompt";
4
+ export declare namespace ChatGptAgent {
5
+ const execute: (executor: Partial<IAgenticaExecutor> | null) => (ctx: IAgenticaContext) => Promise<IAgenticaPrompt[]>;
6
+ }
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.ChatGptAgent = void 0;
13
+ const ChatGptCallFunctionAgent_1 = require("./ChatGptCallFunctionAgent");
14
+ const ChatGptCancelFunctionAgent_1 = require("./ChatGptCancelFunctionAgent");
15
+ const ChatGptDescribeFunctionAgent_1 = require("./ChatGptDescribeFunctionAgent");
16
+ const ChatGptInitializeFunctionAgent_1 = require("./ChatGptInitializeFunctionAgent");
17
+ const ChatGptSelectFunctionAgent_1 = require("./ChatGptSelectFunctionAgent");
18
+ var ChatGptAgent;
19
+ (function (ChatGptAgent) {
20
+ ChatGptAgent.execute = (executor) => (ctx) => __awaiter(this, void 0, void 0, function* () {
21
+ var _a, _b, _c, _d, _e;
22
+ const histories = [];
23
+ // FUNCTIONS ARE NOT LISTED YET
24
+ if (ctx.ready() === false) {
25
+ if ((executor === null || executor === void 0 ? void 0 : executor.initialize) === null)
26
+ yield ctx.initialize();
27
+ else {
28
+ histories.push(...(yield ((_a = executor === null || executor === void 0 ? void 0 : executor.initialize) !== null && _a !== void 0 ? _a : ChatGptInitializeFunctionAgent_1.ChatGptInitializeFunctionAgent.execute)(ctx)));
29
+ if (ctx.ready() === false)
30
+ return histories;
31
+ }
32
+ }
33
+ // CANCEL CANDIDATE FUNCTIONS
34
+ if (ctx.stack.length !== 0)
35
+ histories.push(...(yield ((_b = executor === null || executor === void 0 ? void 0 : executor.cancel) !== null && _b !== void 0 ? _b : ChatGptCancelFunctionAgent_1.ChatGptCancelFunctionAgent.execute)(ctx)));
36
+ // SELECT CANDIDATE FUNCTIONS
37
+ histories.push(...(yield ((_c = executor === null || executor === void 0 ? void 0 : executor.select) !== null && _c !== void 0 ? _c : ChatGptSelectFunctionAgent_1.ChatGptSelectFunctionAgent.execute)(ctx)));
38
+ if (ctx.stack.length === 0)
39
+ return histories;
40
+ // FUNCTION CALLING LOOP
41
+ while (true) {
42
+ // EXECUTE FUNCTIONS
43
+ const prompts = yield ((_d = executor === null || executor === void 0 ? void 0 : executor.call) !== null && _d !== void 0 ? _d : ChatGptCallFunctionAgent_1.ChatGptCallFunctionAgent.execute)(ctx);
44
+ histories.push(...prompts);
45
+ // EXPLAIN RETURN VALUES
46
+ const executes = prompts.filter((prompt) => prompt.type === "execute");
47
+ for (const e of executes)
48
+ yield ChatGptCancelFunctionAgent_1.ChatGptCancelFunctionAgent.cancelFunction(ctx, {
49
+ reason: "completed",
50
+ name: e.function.name,
51
+ });
52
+ histories.push(...(yield ((_e = executor === null || executor === void 0 ? void 0 : executor.describe) !== null && _e !== void 0 ? _e : ChatGptDescribeFunctionAgent_1.ChatGptDescribeFunctionAgent.execute)(ctx, executes)));
53
+ if (executes.length === 0 || ctx.stack.length === 0)
54
+ break;
55
+ }
56
+ return histories;
57
+ });
58
+ })(ChatGptAgent || (exports.ChatGptAgent = ChatGptAgent = {}));
59
+ //# sourceMappingURL=ChatGptAgent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ChatGptAgent.js","sourceRoot":"","sources":["../../src/chatgpt/ChatGptAgent.ts"],"names":[],"mappings":";;;;;;;;;;;;AAGA,yEAAsE;AACtE,6EAA0E;AAC1E,iFAA8E;AAC9E,qFAAkF;AAClF,6EAA0E;AAE1E,IAAiB,YAAY,CA6D5B;AA7DD,WAAiB,YAAY;IACd,oBAAO,GAClB,CAAC,QAA2C,EAAE,EAAE,CAChD,CAAO,GAAqB,EAA8B,EAAE;;QAC1D,MAAM,SAAS,GAAsB,EAAE,CAAC;QAExC,+BAA+B;QAC/B,IAAI,GAAG,CAAC,KAAK,EAAE,KAAK,KAAK,EAAE,CAAC;YAC1B,IAAI,CAAA,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,UAAU,MAAK,IAAI;gBAAE,MAAM,GAAG,CAAC,UAAU,EAAE,CAAC;iBACrD,CAAC;gBACJ,SAAS,CAAC,IAAI,CACZ,GAAG,CAAC,MAAM,CACR,MAAA,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,UAAU,mCAAI,+DAA8B,CAAC,OAAO,CAC/D,CAAC,GAAG,CAAC,CAAC,CACR,CAAC;gBACF,IAAI,GAAG,CAAC,KAAK,EAAE,KAAK,KAAK;oBAAE,OAAO,SAAS,CAAC;YAC9C,CAAC;QACH,CAAC;QAED,6BAA6B;QAC7B,IAAI,GAAG,CAAC,KAAK,CAAC,MAAM,KAAK,CAAC;YACxB,SAAS,CAAC,IAAI,CACZ,GAAG,CAAC,MAAM,CAAC,MAAA,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,MAAM,mCAAI,uDAA0B,CAAC,OAAO,CAAC,CAChE,GAAG,CACJ,CAAC,CACH,CAAC;QAEJ,6BAA6B;QAC7B,SAAS,CAAC,IAAI,CACZ,GAAG,CAAC,MAA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"../structures/IAgenticaContext";
2
+ import { IAgenticaPrompt } from "../structures/IAgenticaPrompt";
3
+ export declare namespace ChatGptCallFunctionAgent {
4
+ const execute: (ctx: IAgenticaContext) => Promise<IAgenticaPrompt[]>;
5
+ }