@agentica/core 0.10.4 → 0.11.1

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 (263) hide show
  1. package/lib/Agentica.d.ts +14 -14
  2. package/lib/Agentica.js +54 -31
  3. package/lib/Agentica.js.map +1 -1
  4. package/lib/chatgpt/ChatGptAgent.d.ts +3 -3
  5. package/lib/chatgpt/ChatGptAgent.js +1 -1
  6. package/lib/chatgpt/ChatGptAgent.js.map +1 -1
  7. package/lib/chatgpt/ChatGptCallFunctionAgent.d.ts +3 -3
  8. package/lib/chatgpt/ChatGptCallFunctionAgent.js +61 -63
  9. package/lib/chatgpt/ChatGptCallFunctionAgent.js.map +1 -1
  10. package/lib/chatgpt/ChatGptCancelFunctionAgent.d.ts +6 -6
  11. package/lib/chatgpt/ChatGptCancelFunctionAgent.js +28 -30
  12. package/lib/chatgpt/ChatGptCancelFunctionAgent.js.map +1 -1
  13. package/lib/chatgpt/ChatGptCompletionMessageUtil.d.ts +8 -0
  14. package/lib/chatgpt/ChatGptCompletionMessageUtil.js +536 -0
  15. package/lib/chatgpt/ChatGptCompletionMessageUtil.js.map +1 -0
  16. package/lib/chatgpt/ChatGptDescribeFunctionAgent.d.ts +4 -3
  17. package/lib/chatgpt/ChatGptDescribeFunctionAgent.js +56 -6
  18. package/lib/chatgpt/ChatGptDescribeFunctionAgent.js.map +1 -1
  19. package/lib/chatgpt/ChatGptHistoryDecoder.d.ts +2 -2
  20. package/lib/chatgpt/ChatGptHistoryDecoder.js +8 -8
  21. package/lib/chatgpt/ChatGptHistoryDecoder.js.map +1 -1
  22. package/lib/chatgpt/ChatGptInitializeFunctionAgent.d.ts +3 -3
  23. package/lib/chatgpt/ChatGptInitializeFunctionAgent.js +11 -5
  24. package/lib/chatgpt/ChatGptInitializeFunctionAgent.js.map +1 -1
  25. package/lib/chatgpt/ChatGptSelectFunctionAgent.d.ts +3 -3
  26. package/lib/chatgpt/ChatGptSelectFunctionAgent.js +39 -42
  27. package/lib/chatgpt/ChatGptSelectFunctionAgent.js.map +1 -1
  28. package/lib/chatgpt/ChatGptUsageAggregator.d.ts +6 -0
  29. package/lib/chatgpt/ChatGptUsageAggregator.js +48 -0
  30. package/lib/chatgpt/ChatGptUsageAggregator.js.map +1 -0
  31. package/lib/context/AgenticaCancelPrompt.d.ts +16 -0
  32. package/lib/context/AgenticaCancelPrompt.js +20 -0
  33. package/lib/context/AgenticaCancelPrompt.js.map +1 -0
  34. package/lib/context/AgenticaClassOperation.d.ts +8 -0
  35. package/lib/context/AgenticaClassOperation.js +11 -0
  36. package/lib/context/AgenticaClassOperation.js.map +1 -0
  37. package/lib/{structures/IAgenticaContext.d.ts → context/AgenticaContext.d.ts} +15 -14
  38. package/lib/{structures/IAgenticaPrompt.js → context/AgenticaContext.js} +1 -1
  39. package/lib/context/AgenticaContext.js.map +1 -0
  40. package/lib/context/AgenticaHttpOperation.d.ts +8 -0
  41. package/lib/context/AgenticaHttpOperation.js +11 -0
  42. package/lib/context/AgenticaHttpOperation.js.map +1 -0
  43. package/lib/context/AgenticaOperation.d.ts +46 -0
  44. package/lib/{structures/IAgenticaContext.js → context/AgenticaOperation.js} +1 -1
  45. package/lib/context/AgenticaOperation.js.map +1 -0
  46. package/lib/context/AgenticaOperationBase.d.ts +29 -0
  47. package/lib/context/AgenticaOperationBase.js +21 -0
  48. package/lib/context/AgenticaOperationBase.js.map +1 -0
  49. package/lib/{structures/IAgenticaOperationCollection.d.ts → context/AgenticaOperationCollection.d.ts} +6 -6
  50. package/lib/{structures/IAgenticaOperationSelection.js → context/AgenticaOperationCollection.js} +1 -1
  51. package/lib/context/AgenticaOperationCollection.js.map +1 -0
  52. package/lib/context/AgenticaOperationSelection.d.ts +15 -0
  53. package/lib/context/AgenticaOperationSelection.js +17 -0
  54. package/lib/context/AgenticaOperationSelection.js.map +1 -0
  55. package/lib/context/AgenticaTokenUsage.d.ts +82 -0
  56. package/lib/context/AgenticaTokenUsage.js +97 -0
  57. package/lib/context/AgenticaTokenUsage.js.map +1 -0
  58. package/lib/context/internal/AgenticaTokenUsageAggregator.d.ts +10 -0
  59. package/lib/{internal → context/internal}/AgenticaTokenUsageAggregator.js +0 -46
  60. package/lib/context/internal/AgenticaTokenUsageAggregator.js.map +1 -0
  61. package/lib/context/internal/__IChatCancelFunctionsApplication.js.map +1 -0
  62. package/lib/context/internal/__IChatFunctionReference.js.map +1 -0
  63. package/lib/context/internal/__IChatInitialApplication.js.map +1 -0
  64. package/lib/context/internal/__IChatSelectFunctionsApplication.js.map +1 -0
  65. package/lib/events/AgenticaCallEvent.d.ts +18 -0
  66. package/lib/events/AgenticaCallEvent.js +22 -0
  67. package/lib/events/AgenticaCallEvent.js.map +1 -0
  68. package/lib/events/AgenticaCancelEvent.d.ts +14 -0
  69. package/lib/events/AgenticaCancelEvent.js +18 -0
  70. package/lib/events/AgenticaCancelEvent.js.map +1 -0
  71. package/lib/events/AgenticaDescribeEvent.d.ts +27 -0
  72. package/lib/events/AgenticaDescribeEvent.js +40 -0
  73. package/lib/events/AgenticaDescribeEvent.js.map +1 -0
  74. package/lib/events/AgenticaEvent.d.ts +25 -0
  75. package/lib/{structures/IAgenticaEvent.js → events/AgenticaEvent.js} +1 -1
  76. package/lib/events/AgenticaEvent.js.map +1 -0
  77. package/lib/events/AgenticaEventBase.d.ts +4 -0
  78. package/lib/events/AgenticaEventBase.js +10 -0
  79. package/lib/events/AgenticaEventBase.js.map +1 -0
  80. package/lib/events/AgenticaEventSource.d.ts +1 -0
  81. package/lib/events/AgenticaEventSource.js +3 -0
  82. package/lib/events/AgenticaEventSource.js.map +1 -0
  83. package/lib/events/AgenticaExecuteEvent.d.ts +22 -0
  84. package/lib/events/AgenticaExecuteEvent.js +33 -0
  85. package/lib/events/AgenticaExecuteEvent.js.map +1 -0
  86. package/lib/events/AgenticaInitializeEvent.d.ts +6 -0
  87. package/lib/events/AgenticaInitializeEvent.js +16 -0
  88. package/lib/events/AgenticaInitializeEvent.js.map +1 -0
  89. package/lib/events/AgenticaRequestEvent.d.ts +27 -0
  90. package/lib/events/AgenticaRequestEvent.js +22 -0
  91. package/lib/events/AgenticaRequestEvent.js.map +1 -0
  92. package/lib/events/AgenticaResponseEvent.d.ts +35 -0
  93. package/lib/events/AgenticaResponseEvent.js +16 -0
  94. package/lib/events/AgenticaResponseEvent.js.map +1 -0
  95. package/lib/events/AgenticaSelectEvent.d.ts +16 -0
  96. package/lib/events/AgenticaSelectEvent.js +26 -0
  97. package/lib/events/AgenticaSelectEvent.js.map +1 -0
  98. package/lib/events/AgenticaTextEvent.d.ts +25 -0
  99. package/lib/events/AgenticaTextEvent.js +40 -0
  100. package/lib/events/AgenticaTextEvent.js.map +1 -0
  101. package/lib/index.d.ts +26 -8
  102. package/lib/index.js +29 -9
  103. package/lib/index.js.map +1 -1
  104. package/lib/index.mjs +1391 -306
  105. package/lib/index.mjs.map +1 -1
  106. package/lib/internal/AgenticaOperationComposer.d.ts +2 -2
  107. package/lib/internal/AgenticaOperationComposer.js +12 -0
  108. package/lib/internal/AgenticaOperationComposer.js.map +1 -1
  109. package/lib/internal/ByteArrayUtil.d.ts +3 -0
  110. package/lib/internal/ByteArrayUtil.js +10 -0
  111. package/lib/internal/ByteArrayUtil.js.map +1 -0
  112. package/lib/internal/MPSCUtil.d.ts +21 -0
  113. package/lib/internal/MPSCUtil.js +84 -0
  114. package/lib/internal/MPSCUtil.js.map +1 -0
  115. package/lib/internal/StreamUtil.d.ts +6 -0
  116. package/lib/internal/StreamUtil.js +65 -0
  117. package/lib/internal/StreamUtil.js.map +1 -0
  118. package/lib/json/IAgenticaEventJson.d.ts +149 -0
  119. package/lib/{structures/IAgenticaOperation.js → json/IAgenticaEventJson.js} +1 -1
  120. package/lib/json/IAgenticaEventJson.js.map +1 -0
  121. package/lib/json/IAgenticaOperationJson.d.ts +33 -0
  122. package/lib/json/IAgenticaOperationJson.js +3 -0
  123. package/lib/json/IAgenticaOperationJson.js.map +1 -0
  124. package/lib/json/IAgenticaOperationSelectionJson.d.ts +18 -0
  125. package/lib/{structures/IAgenticaOperationCollection.js → json/IAgenticaOperationSelectionJson.js} +1 -1
  126. package/lib/json/IAgenticaOperationSelectionJson.js.map +1 -0
  127. package/lib/json/IAgenticaPromptJson.d.ts +111 -0
  128. package/lib/json/IAgenticaPromptJson.js +3 -0
  129. package/lib/json/IAgenticaPromptJson.js.map +1 -0
  130. package/lib/{structures/IAgenticaTokenUsage.d.ts → json/IAgenticaTokenUsageJson.d.ts} +10 -10
  131. package/lib/json/IAgenticaTokenUsageJson.js +3 -0
  132. package/lib/json/IAgenticaTokenUsageJson.js.map +1 -0
  133. package/lib/prompts/AgenticaCancelPrompt.d.ts +16 -0
  134. package/lib/prompts/AgenticaCancelPrompt.js +20 -0
  135. package/lib/prompts/AgenticaCancelPrompt.js.map +1 -0
  136. package/lib/prompts/AgenticaDescribePrompt.d.ts +24 -0
  137. package/lib/prompts/AgenticaDescribePrompt.js +20 -0
  138. package/lib/prompts/AgenticaDescribePrompt.js.map +1 -0
  139. package/lib/prompts/AgenticaExecutePrompt.d.ts +20 -0
  140. package/lib/prompts/AgenticaExecutePrompt.js +24 -0
  141. package/lib/prompts/AgenticaExecutePrompt.js.map +1 -0
  142. package/lib/prompts/AgenticaPrompt.d.ts +7 -0
  143. package/lib/{typings/AgenticaSource.js → prompts/AgenticaPrompt.js} +1 -1
  144. package/lib/prompts/AgenticaPrompt.js.map +1 -0
  145. package/lib/prompts/AgenticaPromptBase.d.ts +22 -0
  146. package/lib/prompts/AgenticaPromptBase.js +22 -0
  147. package/lib/prompts/AgenticaPromptBase.js.map +1 -0
  148. package/lib/prompts/AgenticaSelectPrompt.d.ts +16 -0
  149. package/lib/prompts/AgenticaSelectPrompt.js +20 -0
  150. package/lib/prompts/AgenticaSelectPrompt.js.map +1 -0
  151. package/lib/prompts/AgenticaTextPrompt.d.ts +14 -0
  152. package/lib/prompts/AgenticaTextPrompt.js +20 -0
  153. package/lib/prompts/AgenticaTextPrompt.js.map +1 -0
  154. package/lib/structures/IAgenticaConfig.d.ts +3 -3
  155. package/lib/structures/IAgenticaExecutor.d.ts +12 -11
  156. package/lib/structures/IAgenticaProps.d.ts +2 -3
  157. package/lib/structures/IAgenticaSystemPrompt.d.ts +12 -11
  158. package/lib/transformers/AgenticaEventTransformer.d.ts +45 -0
  159. package/lib/transformers/AgenticaEventTransformer.js +127 -0
  160. package/lib/transformers/AgenticaEventTransformer.js.map +1 -0
  161. package/lib/transformers/AgenticaPromptTransformer.d.ts +34 -0
  162. package/lib/transformers/AgenticaPromptTransformer.js +90 -0
  163. package/lib/transformers/AgenticaPromptTransformer.js.map +1 -0
  164. package/package.json +1 -1
  165. package/src/Agentica.ts +93 -63
  166. package/src/chatgpt/ChatGptAgent.ts +8 -7
  167. package/src/chatgpt/ChatGptCallFunctionAgent.ts +90 -88
  168. package/src/chatgpt/ChatGptCancelFunctionAgent.ts +51 -58
  169. package/src/chatgpt/ChatGptCompletionMessageUtil.ts +166 -0
  170. package/src/chatgpt/ChatGptDescribeFunctionAgent.ts +81 -12
  171. package/src/chatgpt/ChatGptHistoryDecoder.ts +14 -14
  172. package/src/chatgpt/ChatGptInitializeFunctionAgent.ts +21 -13
  173. package/src/chatgpt/ChatGptSelectFunctionAgent.ts +66 -74
  174. package/src/chatgpt/ChatGptUsageAggregator.ts +62 -0
  175. package/src/context/AgenticaCancelPrompt.ts +32 -0
  176. package/src/context/AgenticaClassOperation.ts +23 -0
  177. package/src/{structures/IAgenticaContext.ts → context/AgenticaContext.ts} +17 -16
  178. package/src/context/AgenticaHttpOperation.ts +27 -0
  179. package/src/{structures/IAgenticaOperation.ts → context/AgenticaOperation.ts} +25 -22
  180. package/src/context/AgenticaOperationBase.ts +57 -0
  181. package/src/{structures/IAgenticaOperationCollection.ts → context/AgenticaOperationCollection.ts} +6 -6
  182. package/src/context/AgenticaOperationSelection.ts +27 -0
  183. package/src/context/AgenticaTokenUsage.ts +170 -0
  184. package/src/context/internal/AgenticaTokenUsageAggregator.ts +66 -0
  185. package/src/events/AgenticaCallEvent.ts +36 -0
  186. package/src/events/AgenticaCancelEvent.ts +28 -0
  187. package/src/events/AgenticaDescribeEvent.ts +61 -0
  188. package/src/events/AgenticaEvent.ts +36 -0
  189. package/src/events/AgenticaEventBase.ts +7 -0
  190. package/src/{typings/AgenticaSource.ts → events/AgenticaEventSource.ts} +1 -1
  191. package/src/events/AgenticaExecuteEvent.ts +50 -0
  192. package/src/events/AgenticaInitializeEvent.ts +14 -0
  193. package/src/events/AgenticaRequestEvent.ts +45 -0
  194. package/src/events/AgenticaResponseEvent.ts +48 -0
  195. package/src/events/AgenticaSelectEvent.ts +37 -0
  196. package/src/events/AgenticaTextEvent.ts +57 -0
  197. package/src/index.ts +33 -9
  198. package/src/internal/AgenticaOperationComposer.ts +24 -15
  199. package/src/internal/ByteArrayUtil.ts +5 -0
  200. package/src/internal/MPSCUtil.ts +75 -0
  201. package/src/internal/StreamUtil.ts +64 -0
  202. package/src/json/IAgenticaEventJson.ts +178 -0
  203. package/src/json/IAgenticaOperationJson.ts +36 -0
  204. package/src/json/IAgenticaOperationSelectionJson.ts +19 -0
  205. package/src/json/IAgenticaPromptJson.ts +130 -0
  206. package/src/{structures/IAgenticaTokenUsage.ts → json/IAgenticaTokenUsageJson.ts} +10 -10
  207. package/src/prompts/AgenticaCancelPrompt.ts +32 -0
  208. package/src/prompts/AgenticaDescribePrompt.ts +41 -0
  209. package/src/prompts/AgenticaExecutePrompt.ts +52 -0
  210. package/src/prompts/AgenticaPrompt.ts +14 -0
  211. package/src/prompts/AgenticaPromptBase.ts +27 -0
  212. package/src/prompts/AgenticaSelectPrompt.ts +32 -0
  213. package/src/prompts/AgenticaTextPrompt.ts +31 -0
  214. package/src/structures/IAgenticaConfig.ts +3 -3
  215. package/src/structures/IAgenticaExecutor.ts +14 -13
  216. package/src/structures/IAgenticaProps.ts +2 -3
  217. package/src/structures/IAgenticaSystemPrompt.ts +12 -11
  218. package/src/transformers/AgenticaEventTransformer.ts +165 -0
  219. package/src/transformers/AgenticaPromptTransformer.ts +134 -0
  220. package/lib/internal/AgenticaPromptFactory.d.ts +0 -7
  221. package/lib/internal/AgenticaPromptFactory.js +0 -9
  222. package/lib/internal/AgenticaPromptFactory.js.map +0 -1
  223. package/lib/internal/AgenticaPromptTransformer.d.ts +0 -10
  224. package/lib/internal/AgenticaPromptTransformer.js +0 -58
  225. package/lib/internal/AgenticaPromptTransformer.js.map +0 -1
  226. package/lib/internal/AgenticaTokenUsageAggregator.d.ts +0 -11
  227. package/lib/internal/AgenticaTokenUsageAggregator.js.map +0 -1
  228. package/lib/structures/IAgenticaContext.js.map +0 -1
  229. package/lib/structures/IAgenticaEvent.d.ts +0 -192
  230. package/lib/structures/IAgenticaEvent.js.map +0 -1
  231. package/lib/structures/IAgenticaOperation.d.ts +0 -47
  232. package/lib/structures/IAgenticaOperation.js.map +0 -1
  233. package/lib/structures/IAgenticaOperationCollection.js.map +0 -1
  234. package/lib/structures/IAgenticaOperationSelection.d.ts +0 -50
  235. package/lib/structures/IAgenticaOperationSelection.js.map +0 -1
  236. package/lib/structures/IAgenticaPrompt.d.ts +0 -138
  237. package/lib/structures/IAgenticaPrompt.js.map +0 -1
  238. package/lib/structures/IAgenticaTokenUsage.js +0 -3
  239. package/lib/structures/IAgenticaTokenUsage.js.map +0 -1
  240. package/lib/structures/internal/__IChatCancelFunctionsApplication.js.map +0 -1
  241. package/lib/structures/internal/__IChatFunctionReference.js.map +0 -1
  242. package/lib/structures/internal/__IChatInitialApplication.js.map +0 -1
  243. package/lib/structures/internal/__IChatSelectFunctionsApplication.js.map +0 -1
  244. package/lib/typings/AgenticaSource.d.ts +0 -1
  245. package/lib/typings/AgenticaSource.js.map +0 -1
  246. package/src/internal/AgenticaPromptFactory.ts +0 -32
  247. package/src/internal/AgenticaPromptTransformer.ts +0 -86
  248. package/src/internal/AgenticaTokenUsageAggregator.ts +0 -121
  249. package/src/structures/IAgenticaEvent.ts +0 -229
  250. package/src/structures/IAgenticaOperationSelection.ts +0 -68
  251. package/src/structures/IAgenticaPrompt.ts +0 -182
  252. /package/lib/{structures → context}/internal/__IChatCancelFunctionsApplication.d.ts +0 -0
  253. /package/lib/{structures → context}/internal/__IChatCancelFunctionsApplication.js +0 -0
  254. /package/lib/{structures → context}/internal/__IChatFunctionReference.d.ts +0 -0
  255. /package/lib/{structures → context}/internal/__IChatFunctionReference.js +0 -0
  256. /package/lib/{structures → context}/internal/__IChatInitialApplication.d.ts +0 -0
  257. /package/lib/{structures → context}/internal/__IChatInitialApplication.js +0 -0
  258. /package/lib/{structures → context}/internal/__IChatSelectFunctionsApplication.d.ts +0 -0
  259. /package/lib/{structures → context}/internal/__IChatSelectFunctionsApplication.js +0 -0
  260. /package/src/{structures → context}/internal/__IChatCancelFunctionsApplication.ts +0 -0
  261. /package/src/{structures → context}/internal/__IChatFunctionReference.ts +0 -0
  262. /package/src/{structures → context}/internal/__IChatInitialApplication.ts +0 -0
  263. /package/src/{structures → context}/internal/__IChatSelectFunctionsApplication.ts +0 -0
package/src/Agentica.ts CHANGED
@@ -1,22 +1,27 @@
1
1
  import { ILlmSchema } from "@samchon/openapi";
2
- import OpenAI from "openai";
3
2
 
4
3
  import { ChatGptAgent } from "./chatgpt/ChatGptAgent";
4
+ import { ChatGptCompletionMessageUtil } from "./chatgpt/ChatGptCompletionMessageUtil";
5
+ import { AgenticaContext } from "./context/AgenticaContext";
6
+ import { AgenticaOperation } from "./context/AgenticaOperation";
7
+ import { AgenticaOperationCollection } from "./context/AgenticaOperationCollection";
8
+ import { AgenticaOperationSelection } from "./context/AgenticaOperationSelection";
9
+ import { AgenticaTokenUsage } from "./context/AgenticaTokenUsage";
10
+ import { AgenticaTokenUsageAggregator } from "./context/internal/AgenticaTokenUsageAggregator";
11
+ import { AgenticaEvent } from "./events/AgenticaEvent";
12
+ import { AgenticaInitializeEvent } from "./events/AgenticaInitializeEvent";
13
+ import { AgenticaRequestEvent } from "./events/AgenticaRequestEvent";
14
+ import { AgenticaTextEvent } from "./events/AgenticaTextEvent";
5
15
  import { AgenticaOperationComposer } from "./internal/AgenticaOperationComposer";
6
- import { AgenticaPromptTransformer } from "./internal/AgenticaPromptTransformer";
7
- import { AgenticaTokenUsageAggregator } from "./internal/AgenticaTokenUsageAggregator";
16
+ import { StreamUtil } from "./internal/StreamUtil";
8
17
  import { __map_take } from "./internal/__map_take";
18
+ import { AgenticaPrompt } from "./prompts/AgenticaPrompt";
19
+ import { AgenticaTextPrompt } from "./prompts/AgenticaTextPrompt";
9
20
  import { IAgenticaConfig } from "./structures/IAgenticaConfig";
10
- import { IAgenticaContext } from "./structures/IAgenticaContext";
11
21
  import { IAgenticaController } from "./structures/IAgenticaController";
12
- import { IAgenticaEvent } from "./structures/IAgenticaEvent";
13
- import { IAgenticaOperation } from "./structures/IAgenticaOperation";
14
- import { IAgenticaOperationCollection } from "./structures/IAgenticaOperationCollection";
15
- import { IAgenticaOperationSelection } from "./structures/IAgenticaOperationSelection";
16
- import { IAgenticaPrompt } from "./structures/IAgenticaPrompt";
17
22
  import { IAgenticaProps } from "./structures/IAgenticaProps";
18
- import { IAgenticaTokenUsage } from "./structures/IAgenticaTokenUsage";
19
23
  import { IAgenticaVendor } from "./structures/IAgenticaVendor";
24
+ import { AgenticaPromptTransformer } from "./transformers/AgenticaPromptTransformer";
20
25
 
21
26
  /**
22
27
  * Nestia A.I. chatbot agent.
@@ -39,27 +44,27 @@ import { IAgenticaVendor } from "./structures/IAgenticaVendor";
39
44
  * - {@link IAgenticaSystemPrompt}
40
45
  * - Accessors
41
46
  * - {@link IAgenticaOperation}
42
- * - {@link IAgenticaPrompt}
43
- * - {@link IAgenticaEvent}
44
- * - {@link IAgenticaTokenUsage}
47
+ * - {@link IAgenticaPromptJson}
48
+ * - {@link IAgenticaEventJson}
49
+ * - {@link IAgenticaTokenUsageJson}
45
50
  *
46
51
  * @author Samchon
47
52
  */
48
53
  export class Agentica<Model extends ILlmSchema.Model> {
49
54
  // THE OPERATIONS
50
- private readonly operations_: IAgenticaOperationCollection<Model>;
55
+ private readonly operations_: AgenticaOperationCollection<Model>;
51
56
 
52
57
  // STACK
53
- private readonly stack_: IAgenticaOperationSelection<Model>[];
54
- private readonly prompt_histories_: IAgenticaPrompt<Model>[];
58
+ private readonly stack_: AgenticaOperationSelection<Model>[];
59
+ private readonly prompt_histories_: AgenticaPrompt<Model>[];
55
60
  private readonly listeners_: Map<string, Set<Function>>;
56
61
 
57
62
  // STATUS
58
- private readonly token_usage_: IAgenticaTokenUsage;
63
+ private readonly token_usage_: AgenticaTokenUsage;
59
64
  private ready_: boolean;
60
65
  private readonly executor_: (
61
- ctx: IAgenticaContext<Model>,
62
- ) => Promise<IAgenticaPrompt<Model>[]>;
66
+ ctx: AgenticaContext<Model>,
67
+ ) => Promise<AgenticaPrompt<Model>[]>;
63
68
 
64
69
  /* -----------------------------------------------------------
65
70
  CONSTRUCTOR
@@ -82,12 +87,12 @@ export class Agentica<Model extends ILlmSchema.Model> {
82
87
  this.prompt_histories_ = (props.histories ?? []).map((input) =>
83
88
  AgenticaPromptTransformer.transform({
84
89
  operations: this.operations_.group,
85
- input,
90
+ prompt: input,
86
91
  }),
87
92
  );
88
93
 
89
94
  // STATUS
90
- this.token_usage_ = AgenticaTokenUsageAggregator.zero();
95
+ this.token_usage_ = AgenticaTokenUsage.zero();
91
96
  this.ready_ = false;
92
97
  this.executor_ =
93
98
  typeof props.config?.executor === "function"
@@ -115,20 +120,27 @@ export class Agentica<Model extends ILlmSchema.Model> {
115
120
  *
116
121
  * When the user's conversation implies the A.I. chatbot to execute a
117
122
  * function calling, the returned chat prompts will contain the
118
- * function calling information like {@link IAgenticaPrompt.IExecute}.
123
+ * function calling information like {@link IAgenticaPromptJson.IExecute}.
119
124
  *
120
125
  * @param content The content to talk
121
126
  * @returns List of newly created chat prompts
122
127
  */
123
- public async conversate(content: string): Promise<IAgenticaPrompt<Model>[]> {
124
- const prompt: IAgenticaPrompt.IText<"user"> = {
125
- type: "text",
128
+ public async conversate(content: string): Promise<AgenticaPrompt<Model>[]> {
129
+ const prompt: AgenticaTextPrompt<"user"> = new AgenticaTextPrompt({
126
130
  role: "user",
127
131
  text: content,
128
- };
129
- await this.dispatch(prompt);
132
+ });
133
+ await this.dispatch(
134
+ new AgenticaTextEvent({
135
+ role: "user",
136
+ stream: StreamUtil.to(content),
137
+ done: () => true,
138
+ get: () => content,
139
+ join: () => Promise.resolve(content),
140
+ }),
141
+ );
130
142
 
131
- const newbie: IAgenticaPrompt<Model>[] = await this.executor_(
143
+ const newbie: AgenticaPrompt<Model>[] = await this.executor_(
132
144
  this.getContext({
133
145
  prompt,
134
146
  usage: this.token_usage_,
@@ -170,7 +182,7 @@ export class Agentica<Model extends ILlmSchema.Model> {
170
182
  *
171
183
  * @returns
172
184
  */
173
- public getOperations(): ReadonlyArray<IAgenticaOperation<Model>> {
185
+ public getOperations(): ReadonlyArray<AgenticaOperation<Model>> {
174
186
  return this.operations_.array;
175
187
  }
176
188
 
@@ -181,7 +193,7 @@ export class Agentica<Model extends ILlmSchema.Model> {
181
193
  *
182
194
  * @returns List of chat prompts
183
195
  */
184
- public getPromptHistories(): IAgenticaPrompt<Model>[] {
196
+ public getPromptHistories(): AgenticaPrompt<Model>[] {
185
197
  return this.prompt_histories_;
186
198
  }
187
199
 
@@ -193,7 +205,7 @@ export class Agentica<Model extends ILlmSchema.Model> {
193
205
  *
194
206
  * @returns Cost of the A.I. chatbot
195
207
  */
196
- public getTokenUsage(): IAgenticaTokenUsage {
208
+ public getTokenUsage(): AgenticaTokenUsage {
197
209
  return this.token_usage_;
198
210
  }
199
211
 
@@ -201,10 +213,10 @@ export class Agentica<Model extends ILlmSchema.Model> {
201
213
  * @internal
202
214
  */
203
215
  public getContext(props: {
204
- prompt: IAgenticaPrompt.IText<"user">;
205
- usage: IAgenticaTokenUsage;
206
- }): IAgenticaContext<Model> {
207
- const dispatch = (event: IAgenticaEvent<Model>) => this.dispatch(event);
216
+ prompt: AgenticaTextPrompt<"user">;
217
+ usage: AgenticaTokenUsage;
218
+ }): AgenticaContext<Model> {
219
+ const dispatch = (event: AgenticaEvent<Model>) => this.dispatch(event);
208
220
  return {
209
221
  // APPLICATION
210
222
  operations: this.operations_,
@@ -218,47 +230,65 @@ export class Agentica<Model extends ILlmSchema.Model> {
218
230
 
219
231
  // HANDLERS
220
232
  dispatch: (event) => this.dispatch(event),
221
- request: async (kind, body) => {
233
+ request: async (source, body) => {
222
234
  // request information
223
- const event: IAgenticaEvent.IRequest = {
224
- type: "request",
225
- source: kind,
235
+ const event: AgenticaRequestEvent = new AgenticaRequestEvent({
236
+ source,
226
237
  body: {
227
238
  ...body,
228
239
  model: this.props.vendor.model,
240
+ stream: true,
229
241
  },
230
242
  options: this.props.vendor.options,
231
- };
243
+ });
232
244
  await dispatch(event);
233
245
 
234
246
  // completion
235
- const completion: OpenAI.ChatCompletion =
236
- await this.props.vendor.api.chat.completions.create(
237
- event.body,
238
- event.options,
239
- );
247
+ const completion = await this.props.vendor.api.chat.completions.create(
248
+ event.body,
249
+ event.options,
250
+ );
251
+
252
+ const [streamForEvent, temporaryStream] = StreamUtil.transform(
253
+ completion.toReadableStream() as ReadableStream<Uint8Array>,
254
+ (value) =>
255
+ ChatGptCompletionMessageUtil.transformCompletionChunk(value),
256
+ ).tee();
257
+
258
+ const [streamForAggregate, streamForReturn] = temporaryStream.tee();
259
+
260
+ void (async () => {
261
+ const reader = streamForAggregate.getReader();
262
+ while (true) {
263
+ const chunk = await reader.read();
264
+ if (chunk.done) break;
265
+ if (chunk.value.usage) {
266
+ AgenticaTokenUsageAggregator.aggregate({
267
+ kind: source,
268
+ completionUsage: chunk.value.usage,
269
+ usage: props.usage,
270
+ });
271
+ }
272
+ }
273
+ })();
240
274
 
241
- if (completion.usage) {
242
- AgenticaTokenUsageAggregator.aggregate({
243
- kind,
244
- completionUsage: completion.usage,
245
- usage: props.usage,
246
- });
247
- }
248
275
  await dispatch({
249
276
  type: "response",
250
- source: kind,
277
+ source: source,
278
+ stream: streamForEvent,
251
279
  body: event.body,
252
280
  options: event.options,
253
- value: completion,
281
+ join: async () => {
282
+ const chunks = await StreamUtil.readAll(streamForEvent);
283
+ return ChatGptCompletionMessageUtil.merge(chunks);
284
+ },
254
285
  });
255
- return completion;
286
+
287
+ return streamForReturn;
256
288
  },
257
289
  initialize: async () => {
258
290
  this.ready_ = true;
259
- await dispatch({
260
- type: "initialize",
261
- });
291
+ await dispatch(new AgenticaInitializeEvent());
262
292
  },
263
293
  };
264
294
  }
@@ -274,10 +304,10 @@ export class Agentica<Model extends ILlmSchema.Model> {
274
304
  * @param type Type of event
275
305
  * @param listener Callback function to be called whenever the event is emitted
276
306
  */
277
- public on<Type extends IAgenticaEvent.Type>(
307
+ public on<Type extends AgenticaEvent.Type>(
278
308
  type: Type,
279
309
  listener: (
280
- event: IAgenticaEvent.Mapper<Model>[Type],
310
+ event: AgenticaEvent.Mapper<Model>[Type],
281
311
  ) => void | Promise<void>,
282
312
  ): this {
283
313
  __map_take(this.listeners_, type, () => new Set()).add(listener);
@@ -292,10 +322,10 @@ export class Agentica<Model extends ILlmSchema.Model> {
292
322
  * @param type Type of event
293
323
  * @param listener Callback function to erase
294
324
  */
295
- public off<Type extends IAgenticaEvent.Type>(
325
+ public off<Type extends AgenticaEvent.Type>(
296
326
  type: Type,
297
327
  listener: (
298
- event: IAgenticaEvent.Mapper<Model>[Type],
328
+ event: AgenticaEvent.Mapper<Model>[Type],
299
329
  ) => void | Promise<void>,
300
330
  ): this {
301
331
  const set = this.listeners_.get(type);
@@ -306,7 +336,7 @@ export class Agentica<Model extends ILlmSchema.Model> {
306
336
  return this;
307
337
  }
308
338
 
309
- private async dispatch<Event extends IAgenticaEvent<Model>>(
339
+ private async dispatch<Event extends AgenticaEvent<Model>>(
310
340
  event: Event,
311
341
  ): Promise<void> {
312
342
  const set = this.listeners_.get(event.type);
@@ -1,8 +1,9 @@
1
1
  import { ILlmSchema } from "@samchon/openapi";
2
2
 
3
- import { IAgenticaContext } from "../structures/IAgenticaContext";
3
+ import { AgenticaContext } from "../context/AgenticaContext";
4
+ import { AgenticaExecutePrompt } from "../prompts/AgenticaExecutePrompt";
5
+ import { AgenticaPrompt } from "../prompts/AgenticaPrompt";
4
6
  import { IAgenticaExecutor } from "../structures/IAgenticaExecutor";
5
- import { IAgenticaPrompt } from "../structures/IAgenticaPrompt";
6
7
  import { ChatGptCallFunctionAgent } from "./ChatGptCallFunctionAgent";
7
8
  import { ChatGptCancelFunctionAgent } from "./ChatGptCancelFunctionAgent";
8
9
  import { ChatGptDescribeFunctionAgent } from "./ChatGptDescribeFunctionAgent";
@@ -14,8 +15,8 @@ export namespace ChatGptAgent {
14
15
  <Model extends ILlmSchema.Model>(
15
16
  executor: Partial<IAgenticaExecutor<Model>> | null,
16
17
  ) =>
17
- async (ctx: IAgenticaContext<Model>): Promise<IAgenticaPrompt<Model>[]> => {
18
- const histories: IAgenticaPrompt<Model>[] = [];
18
+ async (ctx: AgenticaContext<Model>): Promise<AgenticaPrompt<Model>[]> => {
19
+ const histories: AgenticaPrompt<Model>[] = [];
19
20
 
20
21
  // FUNCTIONS ARE NOT LISTED YET
21
22
  if (ctx.ready() === false) {
@@ -49,19 +50,19 @@ export namespace ChatGptAgent {
49
50
  // FUNCTION CALLING LOOP
50
51
  while (true) {
51
52
  // EXECUTE FUNCTIONS
52
- const prompts: IAgenticaPrompt<Model>[] = await (
53
+ const prompts: AgenticaPrompt<Model>[] = await (
53
54
  executor?.call ?? ChatGptCallFunctionAgent.execute
54
55
  )(ctx);
55
56
  histories.push(...prompts);
56
57
 
57
58
  // EXPLAIN RETURN VALUES
58
- const executes: IAgenticaPrompt.IExecute<Model>[] = prompts.filter(
59
+ const executes: AgenticaExecutePrompt<Model>[] = prompts.filter(
59
60
  (prompt) => prompt.type === "execute",
60
61
  );
61
62
  for (const e of executes)
62
63
  await ChatGptCancelFunctionAgent.cancelFunction(ctx, {
63
64
  reason: "completed",
64
- name: e.function.name,
65
+ name: e.operation.name,
65
66
  });
66
67
  histories.push(
67
68
  ...(await (
@@ -9,25 +9,33 @@ import {
9
9
  import OpenAI from "openai";
10
10
  import { IValidation } from "typia";
11
11
 
12
+ import { AgenticaCancelPrompt } from "../context/AgenticaCancelPrompt";
13
+ import { AgenticaContext } from "../context/AgenticaContext";
14
+ import { AgenticaOperation } from "../context/AgenticaOperation";
15
+ import { AgenticaOperationSelection } from "../context/AgenticaOperationSelection";
16
+ import { AgenticaCallEvent } from "../events/AgenticaCallEvent";
17
+ import { AgenticaCancelEvent } from "../events/AgenticaCancelEvent";
18
+ import { AgenticaExecuteEvent } from "../events/AgenticaExecuteEvent";
19
+ import { AgenticaTextEvent } from "../events/AgenticaTextEvent";
12
20
  import { AgenticaConstant } from "../internal/AgenticaConstant";
13
21
  import { AgenticaDefaultPrompt } from "../internal/AgenticaDefaultPrompt";
14
- import { AgenticaPromptFactory } from "../internal/AgenticaPromptFactory";
15
22
  import { AgenticaSystemPrompt } from "../internal/AgenticaSystemPrompt";
16
- import { IAgenticaContext } from "../structures/IAgenticaContext";
17
- import { IAgenticaEvent } from "../structures/IAgenticaEvent";
18
- import { IAgenticaOperation } from "../structures/IAgenticaOperation";
19
- import { IAgenticaPrompt } from "../structures/IAgenticaPrompt";
23
+ import { StreamUtil } from "../internal/StreamUtil";
24
+ import { AgenticaExecutePrompt } from "../prompts/AgenticaExecutePrompt";
25
+ import { AgenticaPrompt } from "../prompts/AgenticaPrompt";
26
+ import { AgenticaTextPrompt } from "../prompts/AgenticaTextPrompt";
20
27
  import { ChatGptCancelFunctionAgent } from "./ChatGptCancelFunctionAgent";
28
+ import { ChatGptCompletionMessageUtil } from "./ChatGptCompletionMessageUtil";
21
29
  import { ChatGptHistoryDecoder } from "./ChatGptHistoryDecoder";
22
30
 
23
31
  export namespace ChatGptCallFunctionAgent {
24
32
  export const execute = async <Model extends ILlmSchema.Model>(
25
- ctx: IAgenticaContext<Model>,
26
- ): Promise<IAgenticaPrompt<Model>[]> => {
33
+ ctx: AgenticaContext<Model>,
34
+ ): Promise<AgenticaPrompt<Model>[]> => {
27
35
  //----
28
36
  // EXECUTE CHATGPT API
29
37
  //----
30
- const completion: OpenAI.ChatCompletion = await ctx.request("call", {
38
+ const completionStream = await ctx.request("call", {
31
39
  messages: [
32
40
  // COMMON SYSTEM PROMPT
33
41
  {
@@ -51,14 +59,14 @@ export namespace ChatGptCallFunctionAgent {
51
59
  ],
52
60
  // STACKED FUNCTIONS
53
61
  tools: ctx.stack.map(
54
- (op) =>
62
+ (s) =>
55
63
  ({
56
64
  type: "function",
57
65
  function: {
58
- name: op.name,
59
- description: op.function.description,
60
- parameters: (op.function.separated
61
- ? (op.function.separated.llm ??
66
+ name: s.operation.name,
67
+ description: s.operation.function.description,
68
+ parameters: (s.operation.function.separated
69
+ ? (s.operation.function.separated.llm ??
62
70
  ({
63
71
  type: "object",
64
72
  properties: {},
@@ -66,7 +74,7 @@ export namespace ChatGptCallFunctionAgent {
66
74
  additionalProperties: false,
67
75
  $defs: {},
68
76
  } satisfies IChatGptSchema.IParameters))
69
- : op.function.parameters) as Record<string, any>,
77
+ : s.operation.function.parameters) as Record<string, any>,
70
78
  },
71
79
  }) as OpenAI.ChatCompletionTool,
72
80
  ),
@@ -80,28 +88,31 @@ export namespace ChatGptCallFunctionAgent {
80
88
  const closures: Array<
81
89
  () => Promise<
82
90
  Array<
83
- | IAgenticaPrompt.IExecute<Model>
84
- | IAgenticaPrompt.ICancel<Model>
85
- | IAgenticaPrompt.IText
91
+ | AgenticaExecutePrompt<Model>
92
+ | AgenticaCancelPrompt<Model>
93
+ | AgenticaTextPrompt
86
94
  >
87
95
  >
88
96
  > = [];
97
+
98
+ const chunks = await StreamUtil.readAll(completionStream);
99
+ const completion = ChatGptCompletionMessageUtil.merge(chunks);
100
+
89
101
  for (const choice of completion.choices) {
90
102
  for (const tc of choice.message.tool_calls ?? []) {
91
103
  if (tc.type === "function") {
92
- const operation: IAgenticaOperation<Model> | undefined =
104
+ const operation: AgenticaOperation<Model> | undefined =
93
105
  ctx.operations.flat.get(tc.function.name);
94
106
  if (operation === undefined) continue;
95
107
  closures.push(
96
108
  async (): Promise<
97
- [IAgenticaPrompt.IExecute<Model>, IAgenticaPrompt.ICancel<Model>]
109
+ [AgenticaExecutePrompt<Model>, AgenticaCancelPrompt<Model>]
98
110
  > => {
99
- const call: IAgenticaEvent.ICall<Model> = {
100
- type: "call",
111
+ const call: AgenticaCallEvent<Model> = new AgenticaCallEvent({
101
112
  id: tc.id,
102
113
  operation,
103
114
  arguments: JSON.parse(tc.function.arguments),
104
- };
115
+ });
105
116
  if (call.operation.protocol === "http")
106
117
  fillHttpArguments({
107
118
  operation: call.operation,
@@ -109,40 +120,43 @@ export namespace ChatGptCallFunctionAgent {
109
120
  });
110
121
  await ctx.dispatch(call);
111
122
 
112
- const execute: IAgenticaPrompt.IExecute<Model> = await propagate(
123
+ const execute: AgenticaExecutePrompt<Model> = await propagate(
113
124
  ctx,
114
125
  call,
115
126
  0,
116
127
  );
117
- await ctx.dispatch({
118
- type: "execute",
119
- id: call.id,
120
- operation: call.operation,
121
- arguments: execute.arguments,
122
- value: execute.value,
123
- });
128
+ await ctx.dispatch(
129
+ new AgenticaExecuteEvent({
130
+ id: call.id,
131
+ operation: call.operation,
132
+ arguments: execute.arguments,
133
+ value: execute.value,
134
+ }),
135
+ );
124
136
 
125
137
  await ChatGptCancelFunctionAgent.cancelFunction(ctx, {
126
138
  name: call.operation.name,
127
139
  reason: "completed",
128
140
  });
129
- await ctx.dispatch({
130
- type: "cancel",
131
- operation: call.operation,
132
- reason: "complete",
133
- });
141
+ await ctx.dispatch(
142
+ new AgenticaCancelEvent({
143
+ selection: new AgenticaOperationSelection({
144
+ operation: call.operation,
145
+ reason: "complete",
146
+ }),
147
+ }),
148
+ );
134
149
  return [
135
150
  execute,
136
- {
137
- type: "cancel",
151
+ new AgenticaCancelPrompt({
138
152
  id: call.id,
139
- operations: [
140
- AgenticaPromptFactory.selection({
141
- ...call.operation,
153
+ selections: [
154
+ new AgenticaOperationSelection({
155
+ operation: call.operation,
142
156
  reason: "complete",
143
157
  }),
144
158
  ],
145
- } satisfies IAgenticaPrompt.ICancel<Model>,
159
+ }),
146
160
  ] as const;
147
161
  },
148
162
  );
@@ -153,12 +167,19 @@ export namespace ChatGptCallFunctionAgent {
153
167
  !!choice.message.content?.length
154
168
  )
155
169
  closures.push(async () => {
156
- const value: IAgenticaPrompt.IText = {
157
- type: "text",
170
+ const value: AgenticaTextPrompt = new AgenticaTextPrompt({
158
171
  role: "assistant",
159
172
  text: choice.message.content!,
160
- };
161
- await ctx.dispatch(value);
173
+ });
174
+ await ctx.dispatch(
175
+ new AgenticaTextEvent({
176
+ role: "assistant",
177
+ get: () => value.text,
178
+ done: () => true,
179
+ stream: StreamUtil.to(value.text),
180
+ join: () => Promise.resolve(value.text),
181
+ }),
182
+ );
162
183
  return [value];
163
184
  });
164
185
  }
@@ -166,10 +187,10 @@ export namespace ChatGptCallFunctionAgent {
166
187
  };
167
188
 
168
189
  const propagate = async <Model extends ILlmSchema.Model>(
169
- ctx: IAgenticaContext<Model>,
170
- call: IAgenticaEvent.ICall<Model>,
190
+ ctx: AgenticaContext<Model>,
191
+ call: AgenticaCallEvent<Model>,
171
192
  retry: number,
172
- ): Promise<IAgenticaPrompt.IExecute<Model>> => {
193
+ ): Promise<AgenticaExecutePrompt<Model>> => {
173
194
  if (call.operation.protocol === "http") {
174
195
  //----
175
196
  // HTTP PROTOCOL
@@ -182,7 +203,7 @@ export namespace ChatGptCallFunctionAgent {
182
203
  check.success === false &&
183
204
  retry++ < (ctx.config?.retry ?? AgenticaConstant.RETRY)
184
205
  ) {
185
- const trial: IAgenticaPrompt.IExecute<Model> | null = await correct(
206
+ const trial: AgenticaExecutePrompt<Model> | null = await correct(
186
207
  ctx,
187
208
  call,
188
209
  retry,
@@ -217,26 +238,18 @@ export namespace ChatGptCallFunctionAgent {
217
238
  (success === false
218
239
  ? await correct(ctx, call, retry, response.body)
219
240
  : null) ??
220
- (await AgenticaPromptFactory.execute({
221
- type: "execute",
222
- protocol: "http",
223
- controller: call.operation.controller,
224
- function: call.operation.function,
241
+ new AgenticaExecutePrompt({
242
+ operation: call.operation,
225
243
  id: call.id,
226
- name: call.operation.name,
227
244
  arguments: call.arguments,
228
245
  value: response,
229
- }))
246
+ })
230
247
  );
231
248
  } catch (error) {
232
249
  // DISPATCH ERROR
233
- return AgenticaPromptFactory.execute({
234
- type: "execute",
235
- protocol: "http",
236
- controller: call.operation.controller,
237
- function: call.operation.function,
250
+ return new AgenticaExecutePrompt({
251
+ operation: call.operation,
238
252
  id: call.id,
239
- name: call.operation.name,
240
253
  arguments: call.arguments,
241
254
  value: {
242
255
  status: 500,
@@ -265,13 +278,9 @@ export namespace ChatGptCallFunctionAgent {
265
278
  (retry++ < (ctx.config?.retry ?? AgenticaConstant.RETRY)
266
279
  ? await correct(ctx, call, retry, check.errors)
267
280
  : null) ??
268
- AgenticaPromptFactory.execute({
269
- type: "execute",
270
- protocol: "class",
271
- controller: call.operation.controller,
272
- function: call.operation.function,
281
+ new AgenticaExecutePrompt({
273
282
  id: call.id,
274
- name: call.operation.name,
283
+ operation: call.operation,
275
284
  arguments: call.arguments,
276
285
  value: {
277
286
  name: "TypeGuardError",
@@ -292,24 +301,16 @@ export namespace ChatGptCallFunctionAgent {
292
301
  : await (call.operation.controller.execute as any)[
293
302
  call.operation.function.name
294
303
  ](call.arguments);
295
- return AgenticaPromptFactory.execute({
296
- type: "execute",
297
- protocol: "class",
298
- controller: call.operation.controller,
299
- function: call.operation.function,
304
+ return new AgenticaExecutePrompt({
300
305
  id: call.id,
301
- name: call.operation.name,
306
+ operation: call.operation,
302
307
  arguments: call.arguments,
303
308
  value,
304
309
  });
305
310
  } catch (error) {
306
- return AgenticaPromptFactory.execute({
307
- type: "execute",
308
- protocol: "class",
309
- controller: call.operation.controller,
310
- function: call.operation.function,
311
+ return new AgenticaExecutePrompt({
311
312
  id: call.id,
312
- name: call.operation.name,
313
+ operation: call.operation,
313
314
  arguments: call.arguments,
314
315
  value:
315
316
  error instanceof Error
@@ -325,15 +326,15 @@ export namespace ChatGptCallFunctionAgent {
325
326
  };
326
327
 
327
328
  const correct = async <Model extends ILlmSchema.Model>(
328
- ctx: IAgenticaContext<Model>,
329
- call: IAgenticaEvent.ICall<Model>,
329
+ ctx: AgenticaContext<Model>,
330
+ call: AgenticaCallEvent<Model>,
330
331
  retry: number,
331
332
  error: unknown,
332
- ): Promise<IAgenticaPrompt.IExecute<Model> | null> => {
333
+ ): Promise<AgenticaExecutePrompt<Model> | null> => {
333
334
  //----
334
335
  // EXECUTE CHATGPT API
335
336
  //----
336
- const completion: OpenAI.ChatCompletion = await ctx.request("call", {
337
+ const completionStream = await ctx.request("call", {
337
338
  messages: [
338
339
  // COMMON SYSTEM PROMPT
339
340
  {
@@ -405,6 +406,8 @@ export namespace ChatGptCallFunctionAgent {
405
406
  parallel_tool_calls: false,
406
407
  });
407
408
 
409
+ const chunks = await StreamUtil.readAll(completionStream);
410
+ const completion = ChatGptCompletionMessageUtil.merge(chunks);
408
411
  //----
409
412
  // PROCESS COMPLETION
410
413
  //----
@@ -417,18 +420,17 @@ export namespace ChatGptCallFunctionAgent {
417
420
  if (toolCall === undefined) return null;
418
421
  return propagate(
419
422
  ctx,
420
- {
423
+ new AgenticaCallEvent({
421
424
  id: toolCall.id,
422
- type: "call",
423
425
  operation: call.operation,
424
426
  arguments: JSON.parse(toolCall.function.arguments),
425
- },
427
+ }),
426
428
  retry,
427
429
  );
428
430
  };
429
431
 
430
432
  const fillHttpArguments = <Model extends ILlmSchema.Model>(props: {
431
- operation: IAgenticaOperation<Model>;
433
+ operation: AgenticaOperation<Model>;
432
434
  arguments: object;
433
435
  }): void => {
434
436
  if (props.operation.protocol !== "http") return;