@agentica/core 0.12.20 → 0.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (205) hide show
  1. package/README.md +50 -47
  2. package/lib/Agentica.d.ts +9 -9
  3. package/lib/Agentica.js +23 -16
  4. package/lib/Agentica.js.map +1 -1
  5. package/lib/chatgpt/ChatGptAgent.d.ts +7 -7
  6. package/lib/chatgpt/ChatGptAgent.js +17 -12
  7. package/lib/chatgpt/ChatGptAgent.js.map +1 -1
  8. package/lib/chatgpt/ChatGptCallFunctionAgent.d.ts +7 -6
  9. package/lib/chatgpt/ChatGptCallFunctionAgent.js +121 -81
  10. package/lib/chatgpt/ChatGptCallFunctionAgent.js.map +1 -1
  11. package/lib/chatgpt/ChatGptCancelFunctionAgent.d.ts +9 -7
  12. package/lib/chatgpt/ChatGptCancelFunctionAgent.js +177 -145
  13. package/lib/chatgpt/ChatGptCancelFunctionAgent.js.map +1 -1
  14. package/lib/chatgpt/ChatGptCompletionMessageUtil.d.ts +13 -8
  15. package/lib/chatgpt/ChatGptCompletionMessageUtil.js +499 -489
  16. package/lib/chatgpt/ChatGptCompletionMessageUtil.js.map +1 -1
  17. package/lib/chatgpt/ChatGptDescribeFunctionAgent.d.ts +7 -6
  18. package/lib/chatgpt/ChatGptDescribeFunctionAgent.js +33 -32
  19. package/lib/chatgpt/ChatGptDescribeFunctionAgent.js.map +1 -1
  20. package/lib/chatgpt/ChatGptHistoryDecoder.d.ts +7 -6
  21. package/lib/chatgpt/ChatGptHistoryDecoder.js +60 -56
  22. package/lib/chatgpt/ChatGptHistoryDecoder.js.map +1 -1
  23. package/lib/chatgpt/ChatGptInitializeFunctionAgent.d.ts +7 -6
  24. package/lib/chatgpt/ChatGptInitializeFunctionAgent.js +121 -116
  25. package/lib/chatgpt/ChatGptInitializeFunctionAgent.js.map +1 -1
  26. package/lib/chatgpt/ChatGptSelectFunctionAgent.d.ts +20 -5
  27. package/lib/chatgpt/ChatGptSelectFunctionAgent.js +183 -150
  28. package/lib/chatgpt/ChatGptSelectFunctionAgent.js.map +1 -1
  29. package/lib/chatgpt/ChatGptUsageAggregator.d.ts +9 -6
  30. package/lib/chatgpt/ChatGptUsageAggregator.js +46 -41
  31. package/lib/chatgpt/ChatGptUsageAggregator.js.map +1 -1
  32. package/lib/context/AgenticaCancelPrompt.d.ts +3 -3
  33. package/lib/context/AgenticaCancelPrompt.js +1 -1
  34. package/lib/context/AgenticaCancelPrompt.js.map +1 -1
  35. package/lib/context/AgenticaClassOperation.d.ts +1 -1
  36. package/lib/context/AgenticaClassOperation.js.map +1 -1
  37. package/lib/context/AgenticaContext.d.ts +9 -9
  38. package/lib/context/AgenticaHttpOperation.d.ts +1 -1
  39. package/lib/context/AgenticaHttpOperation.js.map +1 -1
  40. package/lib/context/AgenticaOperation.d.ts +4 -4
  41. package/lib/context/AgenticaOperationBase.d.ts +1 -1
  42. package/lib/context/AgenticaOperationCollection.d.ts +2 -2
  43. package/lib/context/AgenticaOperationSelection.d.ts +3 -3
  44. package/lib/context/AgenticaTokenUsage.d.ts +1 -1
  45. package/lib/context/AgenticaTokenUsage.js.map +1 -1
  46. package/lib/context/internal/AgenticaTokenUsageAggregator.d.ts +11 -10
  47. package/lib/context/internal/AgenticaTokenUsageAggregator.js +42 -43
  48. package/lib/context/internal/AgenticaTokenUsageAggregator.js.map +1 -1
  49. package/lib/context/internal/__IChatCancelFunctionsApplication.d.ts +2 -2
  50. package/lib/context/internal/__IChatInitialApplication.d.ts +2 -2
  51. package/lib/context/internal/__IChatSelectFunctionsApplication.d.ts +2 -2
  52. package/lib/events/AgenticaCallEvent.d.ts +3 -3
  53. package/lib/events/AgenticaCancelEvent.d.ts +3 -3
  54. package/lib/events/AgenticaDescribeEvent.d.ts +3 -3
  55. package/lib/events/AgenticaDescribeEvent.js +13 -2
  56. package/lib/events/AgenticaDescribeEvent.js.map +1 -1
  57. package/lib/events/AgenticaEvent.d.ts +12 -12
  58. package/lib/events/AgenticaExecuteEvent.d.ts +7 -7
  59. package/lib/events/AgenticaInitializeEvent.d.ts +1 -1
  60. package/lib/events/AgenticaRequestEvent.d.ts +3 -3
  61. package/lib/events/AgenticaRequestEvent.js.map +1 -1
  62. package/lib/events/AgenticaResponseEvent.d.ts +2 -2
  63. package/lib/events/AgenticaResponseEvent.js.map +1 -1
  64. package/lib/events/AgenticaSelectEvent.d.ts +3 -3
  65. package/lib/events/AgenticaSelectEvent.js.map +1 -1
  66. package/lib/events/AgenticaTextEvent.d.ts +1 -1
  67. package/lib/events/AgenticaTextEvent.js +12 -1
  68. package/lib/events/AgenticaTextEvent.js.map +1 -1
  69. package/lib/functional/assertHttpLlmApplication.d.ts +4 -3
  70. package/lib/functional/assertHttpLlmApplication.js +9339 -9338
  71. package/lib/functional/assertHttpLlmApplication.js.map +1 -1
  72. package/lib/functional/validateHttpLlmApplication.d.ts +5 -4
  73. package/lib/functional/validateHttpLlmApplication.js +19 -19
  74. package/lib/functional/validateHttpLlmApplication.js.map +1 -1
  75. package/lib/index.d.ts +19 -19
  76. package/lib/index.js +21 -21
  77. package/lib/index.js.map +1 -1
  78. package/lib/index.mjs +19211 -18997
  79. package/lib/index.mjs.map +1 -1
  80. package/lib/internal/AgenticaDefaultPrompt.d.ts +6 -5
  81. package/lib/internal/AgenticaDefaultPrompt.js +39 -19
  82. package/lib/internal/AgenticaDefaultPrompt.js.map +1 -1
  83. package/lib/internal/AgenticaOperationComposer.d.ts +11 -10
  84. package/lib/internal/AgenticaOperationComposer.js +60 -59
  85. package/lib/internal/AgenticaOperationComposer.js.map +1 -1
  86. package/lib/internal/AgenticaSystemPrompt.d.ts +8 -8
  87. package/lib/internal/AgenticaSystemPrompt.js +9 -9
  88. package/lib/internal/AgenticaSystemPrompt.js.map +1 -1
  89. package/lib/internal/AsyncQueue.d.ts +15 -0
  90. package/lib/internal/AsyncQueue.js +82 -0
  91. package/lib/internal/AsyncQueue.js.map +1 -0
  92. package/lib/internal/ByteArrayUtil.d.ts +1 -1
  93. package/lib/internal/ByteArrayUtil.js +3 -2
  94. package/lib/internal/ByteArrayUtil.js.map +1 -1
  95. package/lib/internal/MPSC.d.ts +10 -0
  96. package/lib/internal/MPSC.js +49 -0
  97. package/lib/internal/MPSC.js.map +1 -0
  98. package/lib/internal/Singleton.js +6 -5
  99. package/lib/internal/Singleton.js.map +1 -1
  100. package/lib/internal/StreamUtil.d.ts +16 -6
  101. package/lib/internal/StreamUtil.js +43 -29
  102. package/lib/internal/StreamUtil.js.map +1 -1
  103. package/lib/internal/__map_take.js +5 -5
  104. package/lib/internal/__map_take.js.map +1 -1
  105. package/lib/json/IAgenticaEventJson.d.ts +7 -7
  106. package/lib/json/IAgenticaOperationSelectionJson.d.ts +1 -1
  107. package/lib/json/IAgenticaPromptJson.d.ts +2 -2
  108. package/lib/prompts/AgenticaCancelPrompt.d.ts +3 -3
  109. package/lib/prompts/AgenticaCancelPrompt.js +1 -1
  110. package/lib/prompts/AgenticaCancelPrompt.js.map +1 -1
  111. package/lib/prompts/AgenticaDescribePrompt.d.ts +3 -3
  112. package/lib/prompts/AgenticaDescribePrompt.js +1 -1
  113. package/lib/prompts/AgenticaDescribePrompt.js.map +1 -1
  114. package/lib/prompts/AgenticaExecutePrompt.d.ts +5 -5
  115. package/lib/prompts/AgenticaExecutePrompt.js.map +1 -1
  116. package/lib/prompts/AgenticaPrompt.d.ts +6 -6
  117. package/lib/prompts/AgenticaSelectPrompt.d.ts +3 -3
  118. package/lib/prompts/AgenticaSelectPrompt.js +1 -1
  119. package/lib/prompts/AgenticaSelectPrompt.js.map +1 -1
  120. package/lib/prompts/AgenticaTextPrompt.d.ts +1 -1
  121. package/lib/structures/IAgenticaConfig.d.ts +5 -5
  122. package/lib/structures/IAgenticaController.d.ts +1 -1
  123. package/lib/structures/IAgenticaExecutor.d.ts +4 -4
  124. package/lib/structures/IAgenticaProps.d.ts +5 -5
  125. package/lib/structures/IAgenticaSystemPrompt.d.ts +4 -4
  126. package/lib/structures/IAgenticaVendor.d.ts +1 -1
  127. package/lib/transformers/AgenticaEventTransformer.d.ts +55 -37
  128. package/lib/transformers/AgenticaEventTransformer.js +105 -58
  129. package/lib/transformers/AgenticaEventTransformer.js.map +1 -1
  130. package/lib/transformers/AgenticaPromptTransformer.d.ts +35 -29
  131. package/lib/transformers/AgenticaPromptTransformer.js +74 -45
  132. package/lib/transformers/AgenticaPromptTransformer.js.map +1 -1
  133. package/package.json +20 -23
  134. package/prompts/cancel.md +1 -1
  135. package/prompts/common.md +1 -1
  136. package/prompts/describe.md +1 -1
  137. package/prompts/execute.md +1 -1
  138. package/prompts/initialize.md +1 -1
  139. package/prompts/select.md +1 -1
  140. package/src/Agentica.ts +41 -31
  141. package/src/chatgpt/ChatGptAgent.ts +63 -57
  142. package/src/chatgpt/ChatGptCallFunctionAgent.ts +363 -337
  143. package/src/chatgpt/ChatGptCancelFunctionAgent.ts +188 -164
  144. package/src/chatgpt/ChatGptCompletionMessageUtil.ts +136 -137
  145. package/src/chatgpt/ChatGptDescribeFunctionAgent.ts +105 -101
  146. package/src/chatgpt/ChatGptHistoryDecoder.ts +69 -65
  147. package/src/chatgpt/ChatGptInitializeFunctionAgent.ts +128 -123
  148. package/src/chatgpt/ChatGptSelectFunctionAgent.ts +215 -189
  149. package/src/chatgpt/ChatGptUsageAggregator.ts +49 -54
  150. package/src/context/AgenticaCancelPrompt.ts +4 -4
  151. package/src/context/AgenticaClassOperation.ts +5 -5
  152. package/src/context/AgenticaContext.ts +15 -15
  153. package/src/context/AgenticaHttpOperation.ts +5 -5
  154. package/src/context/AgenticaOperation.ts +4 -4
  155. package/src/context/AgenticaOperationBase.ts +1 -1
  156. package/src/context/AgenticaOperationCollection.ts +2 -2
  157. package/src/context/AgenticaOperationSelection.ts +3 -3
  158. package/src/context/AgenticaTokenUsage.ts +4 -3
  159. package/src/context/internal/AgenticaTokenUsageAggregator.ts +59 -59
  160. package/src/context/internal/__IChatCancelFunctionsApplication.ts +2 -2
  161. package/src/context/internal/__IChatInitialApplication.ts +2 -2
  162. package/src/context/internal/__IChatSelectFunctionsApplication.ts +2 -2
  163. package/src/events/AgenticaCallEvent.ts +3 -3
  164. package/src/events/AgenticaCancelEvent.ts +3 -3
  165. package/src/events/AgenticaDescribeEvent.ts +5 -5
  166. package/src/events/AgenticaEvent.ts +12 -12
  167. package/src/events/AgenticaExecuteEvent.ts +7 -7
  168. package/src/events/AgenticaInitializeEvent.ts +1 -1
  169. package/src/events/AgenticaRequestEvent.ts +3 -3
  170. package/src/events/AgenticaResponseEvent.ts +2 -2
  171. package/src/events/AgenticaSelectEvent.ts +4 -4
  172. package/src/events/AgenticaTextEvent.ts +2 -2
  173. package/src/functional/assertHttpLlmApplication.ts +9 -6
  174. package/src/functional/validateHttpLlmApplication.ts +14 -8
  175. package/src/index.ts +24 -24
  176. package/src/internal/AgenticaDefaultPrompt.ts +42 -28
  177. package/src/internal/AgenticaOperationComposer.ts +63 -61
  178. package/src/internal/AgenticaSystemPrompt.ts +15 -14
  179. package/src/internal/AsyncQueue.ts +67 -0
  180. package/src/internal/ByteArrayUtil.ts +2 -2
  181. package/src/internal/MPSC.ts +40 -0
  182. package/src/internal/Singleton.ts +8 -6
  183. package/src/internal/StreamUtil.ts +62 -53
  184. package/src/internal/__map_take.ts +5 -7
  185. package/src/json/IAgenticaEventJson.ts +7 -8
  186. package/src/json/IAgenticaOperationSelectionJson.ts +1 -1
  187. package/src/json/IAgenticaPromptJson.ts +2 -2
  188. package/src/prompts/AgenticaCancelPrompt.ts +4 -4
  189. package/src/prompts/AgenticaDescribePrompt.ts +4 -4
  190. package/src/prompts/AgenticaExecutePrompt.ts +6 -5
  191. package/src/prompts/AgenticaPrompt.ts +6 -6
  192. package/src/prompts/AgenticaSelectPrompt.ts +4 -4
  193. package/src/prompts/AgenticaTextPrompt.ts +1 -1
  194. package/src/structures/IAgenticaConfig.ts +5 -5
  195. package/src/structures/IAgenticaController.ts +14 -14
  196. package/src/structures/IAgenticaExecutor.ts +4 -4
  197. package/src/structures/IAgenticaProps.ts +5 -5
  198. package/src/structures/IAgenticaSystemPrompt.ts +4 -4
  199. package/src/structures/IAgenticaVendor.ts +1 -1
  200. package/src/transformers/AgenticaEventTransformer.ts +169 -136
  201. package/src/transformers/AgenticaPromptTransformer.ts +125 -103
  202. package/lib/internal/MPSCUtil.d.ts +0 -35
  203. package/lib/internal/MPSCUtil.js +0 -105
  204. package/lib/internal/MPSCUtil.js.map +0 -1
  205. package/src/internal/MPSCUtil.ts +0 -111
@@ -1,28 +1,30 @@
1
- import { ILlmFunction, ILlmSchema } from "@samchon/openapi";
2
- import OpenAI from "openai";
3
- import typia from "typia";
1
+ import type { ILlmFunction, ILlmSchema } from "@samchon/openapi";
2
+ import type OpenAI from "openai";
3
+ import type { AgenticaContext } from "../context/AgenticaContext";
4
4
 
5
- import { AgenticaContext } from "../context/AgenticaContext";
6
- import { __IChatInitialApplication } from "../context/internal/__IChatInitialApplication";
5
+ import type { __IChatInitialApplication } from "../context/internal/__IChatInitialApplication";
6
+ import type { AgenticaPrompt } from "../prompts/AgenticaPrompt";
7
+ import typia from "typia";
7
8
  import { AgenticaTextEvent } from "../events/AgenticaTextEvent";
8
9
  import { AgenticaDefaultPrompt } from "../internal/AgenticaDefaultPrompt";
9
10
  import { AgenticaSystemPrompt } from "../internal/AgenticaSystemPrompt";
10
- import { MPSCUtil } from "../internal/MPSCUtil";
11
+ import { MPSC } from "../internal/MPSC";
11
12
  import { StreamUtil } from "../internal/StreamUtil";
12
- import { AgenticaPrompt } from "../prompts/AgenticaPrompt";
13
13
  import { AgenticaTextPrompt } from "../prompts/AgenticaTextPrompt";
14
14
  import { ChatGptCompletionMessageUtil } from "./ChatGptCompletionMessageUtil";
15
15
  import { ChatGptHistoryDecoder } from "./ChatGptHistoryDecoder";
16
16
 
17
- export namespace ChatGptInitializeFunctionAgent {
18
- export const execute = async <Model extends ILlmSchema.Model>(
19
- ctx: AgenticaContext<Model>,
20
- ): Promise<AgenticaPrompt<Model>[]> => {
21
- //----
22
- // EXECUTE CHATGPT API
23
- //----
24
- const completionStream = await ctx.request("initialize", {
25
- messages: [
17
+ const FUNCTION: ILlmFunction<"chatgpt"> = typia.llm.application<
18
+ __IChatInitialApplication,
19
+ "chatgpt"
20
+ >().functions[0]!;
21
+
22
+ export async function execute<Model extends ILlmSchema.Model>(ctx: AgenticaContext<Model>): Promise<AgenticaPrompt<Model>[]> {
23
+ // ----
24
+ // EXECUTE CHATGPT API
25
+ // ----
26
+ const completionStream = await ctx.request("initialize", {
27
+ messages: [
26
28
  // COMMON SYSTEM PROMPT
27
29
  {
28
30
  role: "system",
@@ -39,126 +41,129 @@ export namespace ChatGptInitializeFunctionAgent {
39
41
  // SYSTEM PROMPT
40
42
  role: "system",
41
43
  content:
42
- ctx.config?.systemPrompt?.initialize?.(ctx.histories) ??
43
- AgenticaSystemPrompt.INITIALIZE,
44
+ ctx.config?.systemPrompt?.initialize?.(ctx.histories)
45
+ ?? AgenticaSystemPrompt.INITIALIZE,
44
46
  },
45
- ],
46
- // GETTER FUNCTION
47
- tools: [
48
- {
49
- type: "function",
50
- function: {
51
- name: FUNCTION.name,
52
- description: FUNCTION.description,
53
- parameters: FUNCTION.parameters as any,
54
- },
47
+ ],
48
+ // GETTER FUNCTION
49
+ tools: [
50
+ {
51
+ type: "function",
52
+ function: {
53
+ name: FUNCTION.name,
54
+ description: FUNCTION.description,
55
+ /**
56
+ * @TODO fix it
57
+ * The property and value have a type mismatch, but it works.
58
+ */
59
+ parameters: FUNCTION.parameters as unknown as Record<string, unknown>,
55
60
  },
56
- ],
57
- tool_choice: "auto",
58
- parallel_tool_calls: false,
59
- });
60
-
61
- const textContext: ({
62
- content: string;
63
- } & ReturnType<typeof MPSCUtil.create<string>>)[] = [];
64
-
65
- const completion = await StreamUtil.reduce<
66
- OpenAI.ChatCompletionChunk,
67
- Promise<OpenAI.ChatCompletion>
68
- >(completionStream, async (accPromise, chunk) => {
69
- const acc = await accPromise;
70
- const registerContext = (
71
- choices: OpenAI.ChatCompletionChunk.Choice[],
72
- ) => {
73
- for (const choice of choices) {
74
- if (choice.finish_reason) {
75
- textContext[choice.index]?.close();
76
- continue;
77
- }
78
- if (!choice.delta.content) {
79
- continue;
80
- }
81
-
82
- if (textContext[choice.index]) {
83
- textContext[choice.index]!.content += choice.delta.content;
84
- textContext[choice.index]!.produce(choice.delta.content);
85
- continue;
86
- }
87
-
88
- const { consumer, produce, close, waitClosed, waitUntilEmpty, done } =
89
- MPSCUtil.create<string>();
90
-
91
- textContext[choice.index] = {
92
- content: choice.delta.content,
93
- consumer,
94
- produce,
95
- close,
96
- waitClosed,
97
- waitUntilEmpty,
98
- done,
99
- };
100
- produce(choice.delta.content);
101
-
102
- void ctx.dispatch(
103
- new AgenticaTextEvent({
104
- role: "assistant",
105
- stream: consumer,
106
- done,
107
- get: () => textContext[choice.index]?.content ?? "",
108
- join: async () => {
109
- await waitClosed();
110
- return textContext[choice.index]!.content;
111
- },
112
- }),
113
- );
61
+ },
62
+ ],
63
+ tool_choice: "auto",
64
+ parallel_tool_calls: false,
65
+ });
66
+
67
+ const textContext: ({
68
+ content: string;
69
+ mpsc: MPSC<string>;
70
+ })[] = [];
71
+
72
+ const completion = await StreamUtil.reduce<
73
+ OpenAI.ChatCompletionChunk,
74
+ Promise<OpenAI.ChatCompletion>
75
+ >(completionStream, async (accPromise, chunk) => {
76
+ const acc = await accPromise;
77
+ const registerContext = (
78
+ choices: OpenAI.ChatCompletionChunk.Choice[],
79
+ ) => {
80
+ for (const choice of choices) {
81
+ /**
82
+ * @TODO fix it
83
+ * Sometimes, the complete message arrives along with a finish reason.
84
+ */
85
+ if (choice.finish_reason != null) {
86
+ textContext[choice.index]?.mpsc.close();
87
+ continue;
114
88
  }
115
- };
116
89
 
117
- if (acc.object === "chat.completion.chunk") {
118
- registerContext([acc, chunk].flatMap((v) => v.choices));
119
- return ChatGptCompletionMessageUtil.merge([acc, chunk]);
120
- }
90
+ if (choice.delta.content == null) {
91
+ continue;
92
+ }
121
93
 
122
- registerContext(chunk.choices);
123
- return ChatGptCompletionMessageUtil.accumulate(acc, chunk);
124
- });
94
+ if (textContext[choice.index] != null) {
95
+ textContext[choice.index]!.content += choice.delta.content;
96
+ textContext[choice.index]!.mpsc.produce(choice.delta.content);
97
+ continue;
98
+ }
125
99
 
126
- if (!completion) {
127
- throw new Error("No completion received");
128
- }
100
+ const mpsc = new MPSC<string>();
101
+
102
+ textContext[choice.index] = {
103
+ content: choice.delta.content,
104
+ mpsc,
105
+ };
106
+ mpsc.produce(choice.delta.content);
129
107
 
130
- //----
131
- // PROCESS COMPLETION
132
- //----
133
- const prompts: AgenticaPrompt<Model>[] = [];
134
- for (const choice of completion.choices) {
135
- if (
136
- choice.message.role === "assistant" &&
137
- !!choice.message.content?.length
138
- ) {
139
- prompts.push(
140
- new AgenticaTextPrompt({
108
+ void ctx.dispatch(
109
+ new AgenticaTextEvent({
141
110
  role: "assistant",
142
- text: choice.message.content,
111
+ stream: mpsc.consumer,
112
+ done: () => mpsc.done(),
113
+ get: () => textContext[choice.index]!.content,
114
+ join: async () => {
115
+ await mpsc.waitClosed();
116
+ return textContext[choice.index]!.content;
117
+ },
143
118
  }),
144
119
  );
145
120
  }
121
+ };
122
+
123
+ if (acc.object === "chat.completion.chunk") {
124
+ registerContext([acc, chunk].flatMap(v => v.choices));
125
+ return ChatGptCompletionMessageUtil.merge([acc, chunk]);
146
126
  }
127
+
128
+ registerContext(chunk.choices);
129
+ return ChatGptCompletionMessageUtil.accumulate(acc, chunk);
130
+ });
131
+
132
+ if (completion === null) {
133
+ throw new Error("No completion received");
134
+ }
135
+
136
+ // ----
137
+ // PROCESS COMPLETION
138
+ // ----
139
+ const prompts: AgenticaPrompt<Model>[] = [];
140
+ for (const choice of completion.choices) {
147
141
  if (
148
- completion.choices.some(
149
- (c) =>
150
- !!c.message.tool_calls?.some(
151
- (tc) =>
152
- tc.type === "function" && tc.function.name === FUNCTION.name,
153
- ),
154
- )
142
+ choice.message.role === "assistant"
143
+ && choice.message.content != null
144
+ ) {
145
+ prompts.push(
146
+ new AgenticaTextPrompt({
147
+ role: "assistant",
148
+ text: choice.message.content,
149
+ }),
150
+ );
151
+ }
152
+ }
153
+ if (
154
+ completion.choices.some(
155
+ c =>
156
+ c.message.tool_calls != null
157
+ && c.message.tool_calls.some(
158
+ tc =>
159
+ tc.type === "function" && tc.function.name === FUNCTION.name,
160
+ ),
155
161
  )
156
- await ctx.initialize();
157
- return prompts;
158
- };
162
+ ) { await ctx.initialize(); }
163
+
164
+ return prompts;
159
165
  }
160
166
 
161
- const FUNCTION: ILlmFunction<"chatgpt"> = typia.llm.application<
162
- __IChatInitialApplication,
163
- "chatgpt"
164
- >().functions[0]!;
167
+ export const ChatGptInitializeFunctionAgent = {
168
+ execute,
169
+ };