@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,359 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
36
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
37
+ return new (P || (P = Promise))(function (resolve, reject) {
38
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
39
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
40
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
41
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
42
+ });
43
+ };
44
+ var __importDefault = (this && this.__importDefault) || function (mod) {
45
+ return (mod && mod.__esModule) ? mod : { "default": mod };
46
+ };
47
+ Object.defineProperty(exports, "__esModule", { value: true });
48
+ exports.ChatGptCancelFunctionAgent = void 0;
49
+ const __typia_transform__validateReport = __importStar(require("typia/lib/internal/_validateReport.js"));
50
+ const typia_1 = __importDefault(require("typia"));
51
+ const uuid_1 = require("uuid");
52
+ const AgenticaConstant_1 = require("../internal/AgenticaConstant");
53
+ const AgenticaDefaultPrompt_1 = require("../internal/AgenticaDefaultPrompt");
54
+ const AgenticaPromptFactory_1 = require("../internal/AgenticaPromptFactory");
55
+ const AgenticaSystemPrompt_1 = require("../internal/AgenticaSystemPrompt");
56
+ const ChatGptHistoryDecoder_1 = require("./ChatGptHistoryDecoder");
57
+ var ChatGptCancelFunctionAgent;
58
+ (function (ChatGptCancelFunctionAgent) {
59
+ ChatGptCancelFunctionAgent.execute = (ctx) => __awaiter(this, void 0, void 0, function* () {
60
+ var _a, _b;
61
+ if (ctx.operations.divided === undefined)
62
+ return step(ctx, ctx.operations.array, 0);
63
+ const stacks = ctx.operations.divided.map(() => []);
64
+ const events = [];
65
+ const prompts = yield Promise.all(ctx.operations.divided.map((operations, i) => step(Object.assign(Object.assign({}, ctx), { stack: stacks[i], dispatch: (e) => __awaiter(this, void 0, void 0, function* () {
66
+ events.push(e);
67
+ }) }), operations, 0)));
68
+ // NO FUNCTION SELECTION, SO THAT ONLY TEXT LEFT
69
+ if (stacks.every((s) => s.length === 0))
70
+ return prompts[0];
71
+ // ELITICISM
72
+ else if (((_b = (_a = ctx.config) === null || _a === void 0 ? void 0 : _a.eliticism) !== null && _b !== void 0 ? _b : AgenticaConstant_1.AgenticaConstant.ELITICISM) === true)
73
+ return step(ctx, stacks
74
+ .flat()
75
+ .map((s) => ctx.operations.group
76
+ .get(s.controller.name)
77
+ .get(s.function.name)), 0);
78
+ // RE-COLLECT SELECT FUNCTION EVENTS
79
+ const collection = {
80
+ id: (0, uuid_1.v4)(),
81
+ type: "cancel",
82
+ operations: [],
83
+ };
84
+ for (const e of events)
85
+ if (e.type === "select") {
86
+ collection.operations.push(AgenticaPromptFactory_1.AgenticaPromptFactory.selection({
87
+ protocol: e.operation.protocol,
88
+ controller: e.operation.controller,
89
+ function: e.operation.function,
90
+ reason: e.reason,
91
+ name: e.operation.name,
92
+ }));
93
+ yield ChatGptCancelFunctionAgent.cancelFunction(ctx, {
94
+ name: e.operation.name,
95
+ reason: e.reason,
96
+ });
97
+ }
98
+ return [collection];
99
+ });
100
+ ChatGptCancelFunctionAgent.cancelFunction = (ctx, reference) => __awaiter(this, void 0, void 0, function* () {
101
+ const index = ctx.stack.findIndex((item) => item.name === reference.name);
102
+ if (index === -1)
103
+ return null;
104
+ const item = ctx.stack[index];
105
+ ctx.stack.splice(index, 1);
106
+ yield ctx.dispatch({
107
+ type: "cancel",
108
+ operation: item,
109
+ reason: reference.reason,
110
+ });
111
+ return item;
112
+ });
113
+ const step = (ctx, operations, retry, failures) => __awaiter(this, void 0, void 0, function* () {
114
+ var _a, _b, _c, _d, _e, _f, _g;
115
+ //----
116
+ // EXECUTE CHATGPT API
117
+ //----
118
+ const completion = yield ctx.request("cancel", {
119
+ messages: [
120
+ // COMMON SYSTEM PROMPT
121
+ {
122
+ role: "system",
123
+ content: AgenticaDefaultPrompt_1.AgenticaDefaultPrompt.write(ctx.config),
124
+ },
125
+ // CANDIDATE FUNCTIONS
126
+ {
127
+ role: "assistant",
128
+ tool_calls: [
129
+ {
130
+ type: "function",
131
+ id: "getApiFunctions",
132
+ function: {
133
+ name: "getApiFunctions",
134
+ arguments: JSON.stringify({}),
135
+ },
136
+ },
137
+ ],
138
+ },
139
+ {
140
+ role: "tool",
141
+ tool_call_id: "getApiFunctions",
142
+ content: JSON.stringify(operations.map((op) => (Object.assign({ name: op.name, description: op.function.description }, (op.protocol === "http"
143
+ ? {
144
+ method: op.function.method,
145
+ path: op.function.path,
146
+ tags: op.function.tags,
147
+ }
148
+ : {}))))),
149
+ },
150
+ // PREVIOUS HISTORIES
151
+ ...ctx.histories.map(ChatGptHistoryDecoder_1.ChatGptHistoryDecoder.decode).flat(),
152
+ // USER INPUT
153
+ {
154
+ role: "user",
155
+ content: ctx.prompt.text,
156
+ },
157
+ // SYSTEM PROMPT
158
+ {
159
+ role: "system",
160
+ content: (_d = (_c = (_b = (_a = ctx.config) === null || _a === void 0 ? void 0 : _a.systemPrompt) === null || _b === void 0 ? void 0 : _b.cancel) === null || _c === void 0 ? void 0 : _c.call(_b, ctx.histories)) !== null && _d !== void 0 ? _d : AgenticaSystemPrompt_1.AgenticaSystemPrompt.CANCEL,
161
+ },
162
+ // TYPE CORRECTIONS
163
+ ...emendMessages(failures !== null && failures !== void 0 ? failures : []),
164
+ ],
165
+ // STACK FUNCTIONS
166
+ tools: CONTAINER.functions.map((func) => ({
167
+ type: "function",
168
+ function: {
169
+ name: func.name,
170
+ description: func.description,
171
+ parameters: func.parameters,
172
+ },
173
+ })),
174
+ tool_choice: "auto",
175
+ parallel_tool_calls: true,
176
+ });
177
+ //----
178
+ // VALIDATION
179
+ //----
180
+ if (retry++ < ((_f = (_e = ctx.config) === null || _e === void 0 ? void 0 : _e.retry) !== null && _f !== void 0 ? _f : AgenticaConstant_1.AgenticaConstant.RETRY)) {
181
+ const failures = [];
182
+ for (const choice of completion.choices)
183
+ for (const tc of (_g = choice.message.tool_calls) !== null && _g !== void 0 ? _g : []) {
184
+ if (tc.function.name !== "cancelFunctions")
185
+ continue;
186
+ const input = JSON.parse(tc.function.arguments);
187
+ const validation = (() => { const _io0 = input => Array.isArray(input.functions) && input.functions.every(elem => "object" === typeof elem && null !== elem && _io1(elem)); const _io1 = input => "string" === typeof input.reason && "string" === typeof input.name; const _vo0 = (input, _path, _exceptionable = true) => [(Array.isArray(input.functions) || _report(_exceptionable, {
188
+ path: _path + ".functions",
189
+ expected: "Array<___IChatFunctionReference>",
190
+ value: input.functions
191
+ })) && input.functions.map((elem, _index2) => ("object" === typeof elem && null !== elem || _report(_exceptionable, {
192
+ path: _path + ".functions[" + _index2 + "]",
193
+ expected: "___IChatFunctionReference",
194
+ value: elem
195
+ })) && _vo1(elem, _path + ".functions[" + _index2 + "]", true && _exceptionable) || _report(_exceptionable, {
196
+ path: _path + ".functions[" + _index2 + "]",
197
+ expected: "___IChatFunctionReference",
198
+ value: elem
199
+ })).every(flag => flag) || _report(_exceptionable, {
200
+ path: _path + ".functions",
201
+ expected: "Array<___IChatFunctionReference>",
202
+ value: input.functions
203
+ })].every(flag => flag); const _vo1 = (input, _path, _exceptionable = true) => ["string" === typeof input.reason || _report(_exceptionable, {
204
+ path: _path + ".reason",
205
+ expected: "string",
206
+ value: input.reason
207
+ }), "string" === typeof input.name || _report(_exceptionable, {
208
+ path: _path + ".name",
209
+ expected: "string",
210
+ value: input.name
211
+ })].every(flag => flag); const __is = input => "object" === typeof input && null !== input && _io0(input); let errors; let _report; return input => {
212
+ if (false === __is(input)) {
213
+ errors = [];
214
+ _report = __typia_transform__validateReport._validateReport(errors);
215
+ ((input, _path, _exceptionable = true) => ("object" === typeof input && null !== input || _report(true, {
216
+ path: _path + "",
217
+ expected: "__IChatFunctionReference.IProps",
218
+ value: input
219
+ })) && _vo0(input, _path + "", true) || _report(true, {
220
+ path: _path + "",
221
+ expected: "__IChatFunctionReference.IProps",
222
+ value: input
223
+ }))(input, "$input", true);
224
+ const success = 0 === errors.length;
225
+ return success ? {
226
+ success,
227
+ data: input
228
+ } : {
229
+ success,
230
+ errors,
231
+ data: input
232
+ };
233
+ }
234
+ return {
235
+ success: true,
236
+ data: input
237
+ };
238
+ }; })()(input);
239
+ if (validation.success === false)
240
+ failures.push({
241
+ id: tc.id,
242
+ name: tc.function.name,
243
+ validation,
244
+ });
245
+ }
246
+ if (failures.length > 0)
247
+ return step(ctx, operations, retry, failures);
248
+ }
249
+ //----
250
+ // PROCESS COMPLETION
251
+ //----
252
+ const prompts = [];
253
+ for (const choice of completion.choices) {
254
+ // TOOL CALLING HANDLER
255
+ if (choice.message.tool_calls)
256
+ for (const tc of choice.message.tool_calls) {
257
+ if (tc.type !== "function")
258
+ continue;
259
+ const input = JSON.parse(tc.function.arguments);
260
+ if ((() => { const _io0 = input => Array.isArray(input.functions) && input.functions.every(elem => "object" === typeof elem && null !== elem && _io1(elem)); const _io1 = input => "string" === typeof input.reason && "string" === typeof input.name; return input => "object" === typeof input && null !== input && _io0(input); })()(input) === false)
261
+ continue;
262
+ else if (tc.function.name === "cancelFunctions") {
263
+ const collection = {
264
+ id: tc.id,
265
+ type: "cancel",
266
+ operations: [],
267
+ };
268
+ for (const reference of input.functions) {
269
+ const operation = yield ChatGptCancelFunctionAgent.cancelFunction(ctx, reference);
270
+ if (operation !== null)
271
+ collection.operations.push(operation);
272
+ }
273
+ if (collection.operations.length !== 0)
274
+ prompts.push(collection);
275
+ }
276
+ }
277
+ }
278
+ return prompts;
279
+ });
280
+ const emendMessages = (failures) => failures
281
+ .map((f) => [
282
+ {
283
+ role: "assistant",
284
+ tool_calls: [
285
+ {
286
+ type: "function",
287
+ id: f.id,
288
+ function: {
289
+ name: f.name,
290
+ arguments: JSON.stringify(f.validation.data),
291
+ },
292
+ },
293
+ ],
294
+ },
295
+ {
296
+ role: "tool",
297
+ content: JSON.stringify(f.validation.errors),
298
+ tool_call_id: f.id,
299
+ },
300
+ {
301
+ role: "system",
302
+ content: [
303
+ "You A.I. assistant has composed wrong typed arguments.",
304
+ "",
305
+ "Correct it at the next function calling.",
306
+ ].join("\n"),
307
+ },
308
+ ])
309
+ .flat();
310
+ })(ChatGptCancelFunctionAgent || (exports.ChatGptCancelFunctionAgent = ChatGptCancelFunctionAgent = {}));
311
+ const CONTAINER = {
312
+ model: "chatgpt",
313
+ options: {
314
+ reference: false,
315
+ strict: false,
316
+ separate: null
317
+ },
318
+ functions: [
319
+ {
320
+ name: "cancelFunctions",
321
+ parameters: {
322
+ type: "object",
323
+ properties: {
324
+ functions: {
325
+ title: "List of target functions",
326
+ description: "List of target functions.",
327
+ type: "array",
328
+ items: {
329
+ type: "object",
330
+ properties: {
331
+ reason: {
332
+ title: "The reason of the function selection",
333
+ description: "The reason of the function selection.\n\nJust write the reason why you've determined to select this function.",
334
+ type: "string"
335
+ },
336
+ name: {
337
+ title: "Name of the target function to call",
338
+ description: "Name of the target function to call.",
339
+ type: "string"
340
+ }
341
+ },
342
+ required: [
343
+ "reason",
344
+ "name"
345
+ ]
346
+ }
347
+ }
348
+ },
349
+ required: [
350
+ "functions"
351
+ ],
352
+ additionalProperties: false,
353
+ $defs: {}
354
+ },
355
+ description: "Cancel a function from the candidate list to call.\n\nIf you A.I. agent has understood that the user wants to cancel\nsome candidate functions to call from the conversation, please cancel\nthem through this function.\n\nAlso, when you A.I. find a function that has been selected by the candidate\npooling, cancel the function by calling this function. For reference, the\ncandidate pooling means that user wants only one function to call, but you A.I.\nagent selects multiple candidate functions because the A.I. agent can't specify\nonly one thing due to lack of specificity or homogeneity of candidate functions.\n\nAdditionally, if you A.I. agent wants to cancel same function multiply, you can\ndo it by assigning the same function name multiply in the `functions` property."
356
+ }
357
+ ]
358
+ };
359
+ //# sourceMappingURL=ChatGptCancelFunctionAgent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ChatGptCancelFunctionAgent.js","sourceRoot":"","sources":["../../src/chatgpt/ChatGptCancelFunctionAgent.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,kDAA2C;AAC3C,+BAA0B;AAE1B,mEAAgE;AAChE,6EAA0E;AAC1E,6EAA0E;AAC1E,2EAAwE;AASxE,mEAAgE;AAEhE,IAAiB,0BAA0B,CA4P1C;AA5PD,WAAiB,0BAA0B;IAC5B,kCAAO,GAAG,CACrB,GAAqB,EACe,EAAE;;QACtC,IAAI,GAAG,CAAC,UAAU,CAAC,OAAO,KAAK,SAAS;YACtC,OAAO,IAAI,CAAC,GAAG,EAAE,GAAG,CAAC,UAAU,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;QAE5C,MAAM,MAAM,GAAoC,GAAG,CAAC,UAAU,CAAC,OAAO,CAAC,GAAG,CACxE,GAAG,EAAE,CAAC,EAAE,CACT,CAAC;QACF,MAA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AU,CAAC,MAAM,KAAK,CAAC;4BAAE,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;oBACnE,CAAC;gBACH,CAAC;QACL,CAAC;QACD,OAAO,OAAO,CAAC;IACjB,CAAC,CAAA,CAAC;IAEF,MAAM,aAAa,GAAG,CACpB,QAAoB,EACiB,EAAE,CACvC,QAAQ;SACL,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC;QACV;YACE,IAAI,EAAE,WAAW;YACjB,UAAU,EAAE;gBACV;oBACE,IAAI,EAAE,UAAU;oBAChB,EAAE,EAAE,CAAC,CAAC,EAAE;oBACR,QAAQ,EAAE;wBACR,IAAI,EAAE,CAAC,CAAC,IAAI;wBACZ,SAAS,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC;qBAC7C;iBACF;aACF;SACmD;QACtD;YACE,IAAI,EAAE,MAAM;YACZ,OAAO,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,UAAU,CAAC,MAAM,CAAC;YAC5C,YAAY,EAAE,CAAC,CAAC,EAAE;SAC6B;QACjD;YACE,IAAI,EAAE,QAAQ;YACd,OAAO,EAAE;gBACP,wDAAwD;gBACxD,EAAE;gBACF,0CAA0C;aAC3C,CAAC,IAAI,CAAC,IAAI,CAAC;SACqC;KACpD,CAAC;SACD,IAAI,EAAE,CAAC;AACd,CAAC,EA5PgB,0BAA0B,0CAA1B,0BAA0B,QA4P1C;AAED,MAAM,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAGZ,CAAC"}
@@ -0,0 +1,5 @@
1
+ import { IAgenticaContext } from "../structures/IAgenticaContext";
2
+ import { IAgenticaPrompt } from "../structures/IAgenticaPrompt";
3
+ export declare namespace ChatGptDescribeFunctionAgent {
4
+ const execute: (ctx: IAgenticaContext, histories: IAgenticaPrompt.IExecute[]) => Promise<IAgenticaPrompt.IDescribe[]>;
5
+ }
@@ -0,0 +1,56 @@
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.ChatGptDescribeFunctionAgent = void 0;
13
+ const AgenticaDefaultPrompt_1 = require("../internal/AgenticaDefaultPrompt");
14
+ const AgenticaSystemPrompt_1 = require("../internal/AgenticaSystemPrompt");
15
+ const ChatGptHistoryDecoder_1 = require("./ChatGptHistoryDecoder");
16
+ var ChatGptDescribeFunctionAgent;
17
+ (function (ChatGptDescribeFunctionAgent) {
18
+ ChatGptDescribeFunctionAgent.execute = (ctx, histories) => __awaiter(this, void 0, void 0, function* () {
19
+ var _a, _b, _c, _d;
20
+ if (histories.length === 0)
21
+ return [];
22
+ const completion = yield ctx.request("describe", {
23
+ messages: [
24
+ // COMMON SYSTEM PROMPT
25
+ {
26
+ role: "system",
27
+ content: AgenticaDefaultPrompt_1.AgenticaDefaultPrompt.write(ctx.config),
28
+ },
29
+ // FUNCTION CALLING HISTORIES
30
+ ...histories.map(ChatGptHistoryDecoder_1.ChatGptHistoryDecoder.decode).flat(),
31
+ // SYSTEM PROMPT
32
+ {
33
+ role: "system",
34
+ content: (_d = (_c = (_b = (_a = ctx.config) === null || _a === void 0 ? void 0 : _a.systemPrompt) === null || _b === void 0 ? void 0 : _b.describe) === null || _c === void 0 ? void 0 : _c.call(_b, histories)) !== null && _d !== void 0 ? _d : AgenticaSystemPrompt_1.AgenticaSystemPrompt.DESCRIBE,
35
+ },
36
+ ],
37
+ });
38
+ const descriptions = completion.choices
39
+ .map((choice) => {
40
+ var _a;
41
+ return choice.message.role === "assistant" && !!((_a = choice.message.content) === null || _a === void 0 ? void 0 : _a.length)
42
+ ? choice.message.content
43
+ : null;
44
+ })
45
+ .filter((str) => str !== null)
46
+ .map((content) => ({
47
+ type: "describe",
48
+ executions: histories,
49
+ text: content,
50
+ }));
51
+ for (const describe of descriptions)
52
+ yield ctx.dispatch(describe);
53
+ return descriptions;
54
+ });
55
+ })(ChatGptDescribeFunctionAgent || (exports.ChatGptDescribeFunctionAgent = ChatGptDescribeFunctionAgent = {}));
56
+ //# sourceMappingURL=ChatGptDescribeFunctionAgent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ChatGptDescribeFunctionAgent.js","sourceRoot":"","sources":["../../src/chatgpt/ChatGptDescribeFunctionAgent.ts"],"names":[],"mappings":";;;;;;;;;;;;AAEA,6EAA0E;AAC1E,2EAAwE;AAGxE,mEAAgE;AAEhE,IAAiB,4BAA4B,CA0C5C;AA1CD,WAAiB,4BAA4B;IAC9B,oCAAO,GAAG,CACrB,GAAqB,EACrB,SAAqC,EACC,EAAE;;QACxC,IAAI,SAAS,CAAC,MAAM,KAAK,CAAC;YAAE,OAAO,EAAE,CAAC;QACtC,MAAM,UAAU,GAA0B,MAAM,GAAG,CAAC,OAAO,CAAC,UAAU,EAAE;YACtE,QAAQ,EAAE;gBACR,uBAAuB;gBACvB;oBACE,IAAI,EAAE,QAAQ;oBACd,OAAO,EAAE,6CAAqB,CAAC,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC;iBACC;gBACnD,6BAA6B;gBAC7B,GAAG,SAAS,CAAC,GAAG,CAAC,6CAAqB,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE;gBACrD,gBAAgB;gBAChB;oBACE,IAAI,EAAE,QAAQ;oBACd,OAAO,EACL,MAAA,MAAA,MAAA,MAAA,GAAG,CAAC,MAAM,0CAAE,YAAY,0CAAE,QAAQ,mDAAG,SAAS,CAAC,mCAC/C,2CAAoB,CAAC,QAAQ;iBAChC;aACF;SACF,CAAC,CAAC;QACH,MAAM,YAAY,GAAgC,UAAU,CAAC,OAAO;aACjE,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE;;YACd,OAAA,MAAM,CAAC,OAAO,CAAC,IAAI,KAAK,WAAW,IAAI,CAAC,CAAC,CAAA,MAAA,MAAM,CAAC,OAAO,CAAC,OAAO,0CAAE,MAAM,CAAA;gBACrE,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,OAAO;gBACxB,CAAC,CAAC,IAAI,CAAA;SAAA,CACT;aACA,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,KAAK,IAAI,CAAC;aAC7B,GAAG,CACF,CAAC,OAAO,EAAE,EAAE,CACV,CAAC;YACC,IAAI,EAAE,UAAU;YAChB,UAAU,EAAE,SAAS;YACrB,IAAI,EAAE,OAAO;SACd,CAAqC,CACzC,CAAC;QACJ,KAAK,MAAM,QAAQ,IAAI,YAAY;YAAE,MAAM,GAAG,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;QAClE,OAAO,YAAY,CAAC;IACtB,CAAC,CAAA,CAAC;AACJ,CAAC,EA1CgB,4BAA4B,4CAA5B,4BAA4B,QA0C5C"}
@@ -0,0 +1,5 @@
1
+ import OpenAI from "openai";
2
+ import { IAgenticaPrompt } from "../structures/IAgenticaPrompt";
3
+ export declare namespace ChatGptHistoryDecoder {
4
+ const decode: (history: IAgenticaPrompt) => OpenAI.ChatCompletionMessageParam[];
5
+ }
@@ -0,0 +1,77 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ChatGptHistoryDecoder = void 0;
4
+ var ChatGptHistoryDecoder;
5
+ (function (ChatGptHistoryDecoder) {
6
+ ChatGptHistoryDecoder.decode = (history) => {
7
+ // NO NEED TO DECODE DESCRIBE
8
+ if (history.type === "describe")
9
+ return [];
10
+ else if (history.type === "text")
11
+ return [
12
+ {
13
+ role: history.role,
14
+ content: history.text,
15
+ },
16
+ ];
17
+ else if (history.type === "select" || history.type === "cancel")
18
+ return [
19
+ {
20
+ role: "assistant",
21
+ tool_calls: [
22
+ {
23
+ type: "function",
24
+ id: history.id,
25
+ function: {
26
+ name: `${history.type}Functions`,
27
+ arguments: JSON.stringify({
28
+ functions: history.operations.map((t) => ({
29
+ name: t.function.name,
30
+ reason: t.reason,
31
+ })),
32
+ }),
33
+ },
34
+ },
35
+ ],
36
+ },
37
+ {
38
+ role: "tool",
39
+ tool_call_id: history.id,
40
+ content: "",
41
+ },
42
+ ];
43
+ return [
44
+ {
45
+ role: "assistant",
46
+ tool_calls: [
47
+ {
48
+ type: "function",
49
+ id: history.id,
50
+ function: {
51
+ name: history.function.name,
52
+ arguments: JSON.stringify(history.arguments),
53
+ },
54
+ },
55
+ ],
56
+ },
57
+ {
58
+ role: "tool",
59
+ tool_call_id: history.id,
60
+ content: JSON.stringify(Object.assign({ function: Object.assign({ protocol: history.protocol, description: history.function.description, parameters: history.function.parameters, output: history.function.output }, (history.protocol === "http"
61
+ ? {
62
+ method: history.function.method,
63
+ path: history.function.path,
64
+ }
65
+ : {})) }, (history.protocol === "http"
66
+ ? {
67
+ status: history.value.status,
68
+ data: history.value.body,
69
+ }
70
+ : {
71
+ value: history.value,
72
+ }))),
73
+ },
74
+ ];
75
+ };
76
+ })(ChatGptHistoryDecoder || (exports.ChatGptHistoryDecoder = ChatGptHistoryDecoder = {}));
77
+ //# sourceMappingURL=ChatGptHistoryDecoder.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ChatGptHistoryDecoder.js","sourceRoot":"","sources":["../../src/chatgpt/ChatGptHistoryDecoder.ts"],"names":[],"mappings":";;;AAIA,IAAiB,qBAAqB,CAiFrC;AAjFD,WAAiB,qBAAqB;IACvB,4BAAM,GAAG,CACpB,OAAwB,EACa,EAAE;QACvC,6BAA6B;QAC7B,IAAI,OAAO,CAAC,IAAI,KAAK,UAAU;YAAE,OAA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B,QAAQ,kBACN,QAAQ,EAAE,OAAO,CAAC,QAAQ,EAC1B,WAAW,EAAE,OAAO,CAAC,QAAQ,CAAC,WAAW,EACzC,UAAU,EAAE,OAAO,CAAC,QAAQ,CAAC,UAAU,EACvC,MAAM,EAAE,OAAO,CAAC,QAAQ,CAAC,MAAM,IAC5B,CAAC,OAAO,CAAC,QAAQ,KAAK,MAAM;wBAC7B,CAAC,CAAC;4BACE,MAAM,EAAE,OAAO,CAAC,QAAQ,CAAC,MAAM;4BAC/B,IAAI,EAAE,OAAO,CAAC,QAAQ,CAAC,IAAI;yBAC5B;wBACH,CAAC,CAAC,EAAE,CAAC,KAEN,CAAC,OAAO,CAAC,QAAQ,KAAK,MAAM;oBAC7B,CAAC,CAAC;wBACE,MAAM,EAAE,OAAO,CAAC,KAAK,CAAC,MAAM;wBAC5B,IAAI,EAAE,OAAO,CAAC,KAAK,CAAC,IAAI;qBACzB;oBACH,CAAC,CAAC;wBACE,KAAK,EAAE,OAAO,CAAC,KAAK;qBACrB,CAAC,EACN;aACH;SACF,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC,EAjFgB,qBAAqB,qCAArB,qBAAqB,QAiFrC"}
@@ -0,0 +1,5 @@
1
+ import { IAgenticaContext } from "../structures/IAgenticaContext";
2
+ import { IAgenticaPrompt } from "../structures/IAgenticaPrompt";
3
+ export declare namespace ChatGptInitializeFunctionAgent {
4
+ const execute: (ctx: IAgenticaContext) => Promise<IAgenticaPrompt[]>;
5
+ }