@agentica/core 0.13.4 → 0.14.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 (189) hide show
  1. package/lib/Agentica.js +8 -10
  2. package/lib/Agentica.js.map +1 -1
  3. package/lib/context/AgenticaCancelPrompt.d.ts +4 -12
  4. package/lib/context/AgenticaCancelPrompt.js +0 -17
  5. package/lib/context/AgenticaCancelPrompt.js.map +1 -1
  6. package/lib/context/AgenticaOperationSelection.d.ts +4 -11
  7. package/lib/context/AgenticaOperationSelection.js +0 -14
  8. package/lib/context/AgenticaOperationSelection.js.map +1 -1
  9. package/lib/context/AgenticaTokenUsage.js.map +1 -1
  10. package/lib/context/internal/AgenticaTokenUsageAggregator.js.map +1 -1
  11. package/lib/events/AgenticaCallEvent.d.ts +23 -13
  12. package/lib/events/AgenticaCallEvent.js +0 -19
  13. package/lib/events/AgenticaCallEvent.js.map +1 -1
  14. package/lib/events/AgenticaCancelEvent.d.ts +4 -10
  15. package/lib/events/AgenticaCancelEvent.js +0 -15
  16. package/lib/events/AgenticaCancelEvent.js.map +1 -1
  17. package/lib/events/AgenticaDescribeEvent.d.ts +8 -27
  18. package/lib/events/AgenticaDescribeEvent.js +0 -52
  19. package/lib/events/AgenticaDescribeEvent.js.map +1 -1
  20. package/lib/events/AgenticaEvent.d.ts +13 -1
  21. package/lib/events/AgenticaEventBase.d.ts +5 -3
  22. package/lib/events/AgenticaEventBase.js +0 -7
  23. package/lib/events/AgenticaEventBase.js.map +1 -1
  24. package/lib/events/AgenticaExecuteEvent.d.ts +15 -15
  25. package/lib/events/AgenticaExecuteEvent.js +0 -30
  26. package/lib/events/AgenticaExecuteEvent.js.map +1 -1
  27. package/lib/events/AgenticaInitializeEvent.d.ts +3 -4
  28. package/lib/events/AgenticaInitializeEvent.js +0 -13
  29. package/lib/events/AgenticaInitializeEvent.js.map +1 -1
  30. package/lib/events/AgenticaRequestEvent.d.ts +5 -24
  31. package/lib/events/AgenticaRequestEvent.js +0 -19
  32. package/lib/events/AgenticaRequestEvent.js.map +1 -1
  33. package/lib/events/AgenticaResponseEvent.d.ts +22 -32
  34. package/lib/events/AgenticaResponseEvent.js +0 -13
  35. package/lib/events/AgenticaResponseEvent.js.map +1 -1
  36. package/lib/events/AgenticaSelectEvent.d.ts +6 -12
  37. package/lib/events/AgenticaSelectEvent.js +0 -23
  38. package/lib/events/AgenticaSelectEvent.js.map +1 -1
  39. package/lib/events/AgenticaTextEvent.d.ts +8 -27
  40. package/lib/events/AgenticaTextEvent.js +0 -52
  41. package/lib/events/AgenticaTextEvent.js.map +1 -1
  42. package/lib/events/AgenticaValidateEvent.d.ts +25 -0
  43. package/lib/events/AgenticaValidateEvent.js +3 -0
  44. package/lib/events/AgenticaValidateEvent.js.map +1 -0
  45. package/lib/factory/events.d.ts +65 -0
  46. package/lib/factory/events.js +173 -0
  47. package/lib/factory/events.js.map +1 -0
  48. package/lib/factory/index.d.ts +3 -0
  49. package/lib/factory/index.js +20 -0
  50. package/lib/factory/index.js.map +1 -0
  51. package/lib/factory/operations.d.ts +7 -0
  52. package/lib/factory/operations.js +14 -0
  53. package/lib/factory/operations.js.map +1 -0
  54. package/lib/factory/prompts.d.ts +30 -0
  55. package/lib/factory/prompts.js +76 -0
  56. package/lib/factory/prompts.js.map +1 -0
  57. package/lib/index.d.ts +2 -0
  58. package/lib/index.js +25 -4
  59. package/lib/index.js.map +1 -1
  60. package/lib/index.mjs +328 -347
  61. package/lib/index.mjs.map +1 -1
  62. package/lib/json/IAgenticaEventJson.d.ts +4 -2
  63. package/lib/json/IAgenticaPromptJson.d.ts +1 -1
  64. package/lib/orchestrate/ChatGptAgent.js.map +1 -0
  65. package/lib/{chatgpt → orchestrate}/ChatGptCallFunctionAgent.d.ts +2 -1
  66. package/lib/{chatgpt → orchestrate}/ChatGptCallFunctionAgent.js +33 -28
  67. package/lib/orchestrate/ChatGptCallFunctionAgent.js.map +1 -0
  68. package/lib/orchestrate/ChatGptCancelFunctionAgent.d.ts +12 -0
  69. package/lib/{chatgpt → orchestrate}/ChatGptCancelFunctionAgent.js +7 -9
  70. package/lib/orchestrate/ChatGptCancelFunctionAgent.js.map +1 -0
  71. package/lib/orchestrate/ChatGptCompletionMessageUtil.d.ts +14 -0
  72. package/lib/{chatgpt → orchestrate}/ChatGptCompletionMessageUtil.js +0 -5
  73. package/lib/orchestrate/ChatGptCompletionMessageUtil.js.map +1 -0
  74. package/lib/{chatgpt → orchestrate}/ChatGptDescribeFunctionAgent.d.ts +3 -2
  75. package/lib/{chatgpt → orchestrate}/ChatGptDescribeFunctionAgent.js +4 -5
  76. package/lib/orchestrate/ChatGptDescribeFunctionAgent.js.map +1 -0
  77. package/lib/{chatgpt → orchestrate}/ChatGptHistoryDecoder.d.ts +2 -1
  78. package/lib/{chatgpt → orchestrate}/ChatGptHistoryDecoder.js +0 -1
  79. package/lib/orchestrate/ChatGptHistoryDecoder.js.map +1 -0
  80. package/lib/{chatgpt → orchestrate}/ChatGptInitializeFunctionAgent.d.ts +2 -1
  81. package/lib/{chatgpt → orchestrate}/ChatGptInitializeFunctionAgent.js +4 -5
  82. package/lib/orchestrate/ChatGptInitializeFunctionAgent.js.map +1 -0
  83. package/lib/{chatgpt → orchestrate}/ChatGptSelectFunctionAgent.d.ts +1 -1
  84. package/lib/{chatgpt → orchestrate}/ChatGptSelectFunctionAgent.js +10 -13
  85. package/lib/orchestrate/ChatGptSelectFunctionAgent.js.map +1 -0
  86. package/lib/orchestrate/ChatGptUsageAggregator.d.ts +10 -0
  87. package/lib/{chatgpt → orchestrate}/ChatGptUsageAggregator.js +0 -3
  88. package/lib/orchestrate/ChatGptUsageAggregator.js.map +1 -0
  89. package/lib/orchestrate/index.d.ts +8 -0
  90. package/lib/orchestrate/index.js +25 -0
  91. package/lib/orchestrate/index.js.map +1 -0
  92. package/lib/prompts/AgenticaCancelPrompt.d.ts +4 -12
  93. package/lib/prompts/AgenticaCancelPrompt.js +0 -17
  94. package/lib/prompts/AgenticaCancelPrompt.js.map +1 -1
  95. package/lib/prompts/AgenticaDescribePrompt.d.ts +4 -12
  96. package/lib/prompts/AgenticaDescribePrompt.js +0 -17
  97. package/lib/prompts/AgenticaDescribePrompt.js.map +1 -1
  98. package/lib/prompts/AgenticaExecutePrompt.d.ts +42 -13
  99. package/lib/prompts/AgenticaExecutePrompt.js +0 -21
  100. package/lib/prompts/AgenticaExecutePrompt.js.map +1 -1
  101. package/lib/prompts/AgenticaPrompt.d.ts +10 -0
  102. package/lib/prompts/AgenticaPromptBase.d.ts +5 -6
  103. package/lib/prompts/AgenticaPromptBase.js +0 -19
  104. package/lib/prompts/AgenticaPromptBase.js.map +1 -1
  105. package/lib/prompts/AgenticaSelectPrompt.d.ts +4 -12
  106. package/lib/prompts/AgenticaSelectPrompt.js +0 -17
  107. package/lib/prompts/AgenticaSelectPrompt.js.map +1 -1
  108. package/lib/prompts/AgenticaTextPrompt.d.ts +4 -12
  109. package/lib/prompts/AgenticaTextPrompt.js +0 -17
  110. package/lib/prompts/AgenticaTextPrompt.js.map +1 -1
  111. package/lib/transformers/AgenticaEventTransformer.d.ts +16 -16
  112. package/lib/transformers/AgenticaEventTransformer.js +12 -30
  113. package/lib/transformers/AgenticaEventTransformer.js.map +1 -1
  114. package/lib/transformers/AgenticaPromptTransformer.d.ts +12 -11
  115. package/lib/transformers/AgenticaPromptTransformer.js +9 -19
  116. package/lib/transformers/AgenticaPromptTransformer.js.map +1 -1
  117. package/package.json +3 -3
  118. package/src/Agentica.ts +11 -11
  119. package/src/context/AgenticaCancelPrompt.ts +4 -25
  120. package/src/context/AgenticaContext.ts +0 -1
  121. package/src/context/AgenticaOperation.ts +0 -1
  122. package/src/context/AgenticaOperationCollection.ts +0 -1
  123. package/src/context/AgenticaOperationSelection.ts +4 -22
  124. package/src/context/AgenticaTokenUsage.ts +2 -2
  125. package/src/context/internal/AgenticaTokenUsageAggregator.ts +0 -1
  126. package/src/events/AgenticaCallEvent.ts +26 -29
  127. package/src/events/AgenticaCancelEvent.ts +4 -21
  128. package/src/events/AgenticaDescribeEvent.ts +8 -57
  129. package/src/events/AgenticaEvent.ts +14 -2
  130. package/src/events/AgenticaEventBase.ts +5 -6
  131. package/src/events/AgenticaExecuteEvent.ts +33 -41
  132. package/src/events/AgenticaInitializeEvent.ts +3 -11
  133. package/src/events/AgenticaRequestEvent.ts +5 -40
  134. package/src/events/AgenticaResponseEvent.ts +22 -39
  135. package/src/events/AgenticaSelectEvent.ts +6 -30
  136. package/src/events/AgenticaTextEvent.ts +11 -60
  137. package/src/events/AgenticaValidateEvent.ts +31 -0
  138. package/src/factory/events.ts +229 -0
  139. package/src/factory/index.ts +3 -0
  140. package/src/factory/operations.ts +17 -0
  141. package/src/factory/prompts.ts +104 -0
  142. package/src/index.ts +5 -6
  143. package/src/json/IAgenticaEventJson.ts +5 -3
  144. package/src/json/IAgenticaPromptJson.ts +1 -1
  145. package/src/{chatgpt → orchestrate}/ChatGptCallFunctionAgent.ts +62 -50
  146. package/src/{chatgpt → orchestrate}/ChatGptCancelFunctionAgent.ts +18 -16
  147. package/src/{chatgpt → orchestrate}/ChatGptCompletionMessageUtil.ts +7 -6
  148. package/src/{chatgpt → orchestrate}/ChatGptDescribeFunctionAgent.ts +7 -6
  149. package/src/{chatgpt → orchestrate}/ChatGptHistoryDecoder.ts +1 -2
  150. package/src/{chatgpt → orchestrate}/ChatGptInitializeFunctionAgent.ts +8 -7
  151. package/src/{chatgpt → orchestrate}/ChatGptSelectFunctionAgent.ts +18 -16
  152. package/src/{chatgpt → orchestrate}/ChatGptUsageAggregator.ts +3 -3
  153. package/src/orchestrate/index.ts +8 -0
  154. package/src/prompts/AgenticaCancelPrompt.ts +4 -25
  155. package/src/prompts/AgenticaDescribePrompt.ts +4 -25
  156. package/src/prompts/AgenticaExecutePrompt.ts +52 -44
  157. package/src/prompts/AgenticaPrompt.ts +10 -1
  158. package/src/prompts/AgenticaPromptBase.ts +5 -9
  159. package/src/prompts/AgenticaSelectPrompt.ts +4 -25
  160. package/src/prompts/AgenticaTextPrompt.ts +4 -26
  161. package/src/transformers/AgenticaEventTransformer.ts +30 -32
  162. package/src/transformers/AgenticaPromptTransformer.ts +22 -22
  163. package/lib/chatgpt/ChatGptAgent.js.map +0 -1
  164. package/lib/chatgpt/ChatGptCallFunctionAgent.js.map +0 -1
  165. package/lib/chatgpt/ChatGptCancelFunctionAgent.d.ts +0 -11
  166. package/lib/chatgpt/ChatGptCancelFunctionAgent.js.map +0 -1
  167. package/lib/chatgpt/ChatGptCompletionMessageUtil.d.ts +0 -13
  168. package/lib/chatgpt/ChatGptCompletionMessageUtil.js.map +0 -1
  169. package/lib/chatgpt/ChatGptDescribeFunctionAgent.js.map +0 -1
  170. package/lib/chatgpt/ChatGptHistoryDecoder.js.map +0 -1
  171. package/lib/chatgpt/ChatGptInitializeFunctionAgent.js.map +0 -1
  172. package/lib/chatgpt/ChatGptSelectFunctionAgent.js.map +0 -1
  173. package/lib/chatgpt/ChatGptUsageAggregator.d.ts +0 -9
  174. package/lib/chatgpt/ChatGptUsageAggregator.js.map +0 -1
  175. package/lib/context/AgenticaClassOperation.d.ts +0 -8
  176. package/lib/context/AgenticaClassOperation.js +0 -11
  177. package/lib/context/AgenticaClassOperation.js.map +0 -1
  178. package/lib/context/AgenticaHttpOperation.d.ts +0 -8
  179. package/lib/context/AgenticaHttpOperation.js +0 -11
  180. package/lib/context/AgenticaHttpOperation.js.map +0 -1
  181. package/lib/context/AgenticaOperationBase.d.ts +0 -29
  182. package/lib/context/AgenticaOperationBase.js +0 -21
  183. package/lib/context/AgenticaOperationBase.js.map +0 -1
  184. package/src/context/AgenticaClassOperation.ts +0 -23
  185. package/src/context/AgenticaHttpOperation.ts +0 -27
  186. package/src/context/AgenticaOperationBase.ts +0 -57
  187. package/lib/{chatgpt → orchestrate}/ChatGptAgent.d.ts +0 -0
  188. package/lib/{chatgpt → orchestrate}/ChatGptAgent.js +0 -0
  189. package/src/{chatgpt → orchestrate}/ChatGptAgent.ts +1 -1
package/src/Agentica.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  import type { ILlmSchema } from "@samchon/openapi";
2
-
3
2
  import type { AgenticaContext } from "./context/AgenticaContext";
4
3
  import type { AgenticaOperation } from "./context/AgenticaOperation";
5
4
  import type { AgenticaOperationCollection } from "./context/AgenticaOperationCollection";
@@ -10,18 +9,19 @@ import type { IAgenticaConfig } from "./structures/IAgenticaConfig";
10
9
  import type { IAgenticaController } from "./structures/IAgenticaController";
11
10
  import type { IAgenticaProps } from "./structures/IAgenticaProps";
12
11
  import type { IAgenticaVendor } from "./structures/IAgenticaVendor";
13
- import { ChatGptAgent } from "./chatgpt/ChatGptAgent";
14
- import { ChatGptCompletionMessageUtil } from "./chatgpt/ChatGptCompletionMessageUtil";
12
+ import type { AgenticaTextPrompt } from "./prompts/AgenticaTextPrompt";
13
+ import type { AgenticaRequestEvent } from "./events/AgenticaRequestEvent";
14
+
15
+ import { ChatGptAgent } from "./orchestrate/ChatGptAgent";
16
+ import { ChatGptCompletionMessageUtil } from "./orchestrate/ChatGptCompletionMessageUtil";
15
17
  import { AgenticaTokenUsage } from "./context/AgenticaTokenUsage";
16
18
  import { AgenticaTokenUsageAggregator } from "./context/internal/AgenticaTokenUsageAggregator";
17
- import { AgenticaInitializeEvent } from "./events/AgenticaInitializeEvent";
18
- import { AgenticaRequestEvent } from "./events/AgenticaRequestEvent";
19
- import { AgenticaTextEvent } from "./events/AgenticaTextEvent";
20
19
  import { __map_take } from "./internal/__map_take";
21
20
  import { AgenticaOperationComposer } from "./internal/AgenticaOperationComposer";
22
21
  import { StreamUtil } from "./internal/StreamUtil";
23
- import { AgenticaTextPrompt } from "./prompts/AgenticaTextPrompt";
24
22
  import { AgenticaPromptTransformer } from "./transformers/AgenticaPromptTransformer";
23
+ import { createTextPrompt } from "./factory/prompts";
24
+ import { createInitializeEvent, createRequestEvent, createTextEvent } from "./factory/events";
25
25
 
26
26
  /**
27
27
  * Nestia A.I. chatbot agent.
@@ -126,12 +126,12 @@ export class Agentica<Model extends ILlmSchema.Model> {
126
126
  * @returns List of newly created chat prompts
127
127
  */
128
128
  public async conversate(content: string): Promise<AgenticaPrompt<Model>[]> {
129
- const prompt: AgenticaTextPrompt<"user"> = new AgenticaTextPrompt({
129
+ const prompt: AgenticaTextPrompt<"user"> = createTextPrompt<"user">({
130
130
  role: "user",
131
131
  text: content,
132
132
  });
133
133
  await this.dispatch(
134
- new AgenticaTextEvent({
134
+ createTextEvent({
135
135
  role: "user",
136
136
  stream: StreamUtil.to(content),
137
137
  done: () => true,
@@ -232,7 +232,7 @@ export class Agentica<Model extends ILlmSchema.Model> {
232
232
  dispatch: async event => this.dispatch(event),
233
233
  request: async (source, body) => {
234
234
  // request information
235
- const event: AgenticaRequestEvent = new AgenticaRequestEvent({
235
+ const event: AgenticaRequestEvent = createRequestEvent({
236
236
  source,
237
237
  body: {
238
238
  ...body,
@@ -294,7 +294,7 @@ export class Agentica<Model extends ILlmSchema.Model> {
294
294
  },
295
295
  initialize: async () => {
296
296
  this.ready_ = true;
297
- await dispatch(new AgenticaInitializeEvent());
297
+ await dispatch(createInitializeEvent());
298
298
  },
299
299
  };
300
300
  }
@@ -1,32 +1,11 @@
1
1
  import type { ILlmSchema } from "@samchon/openapi";
2
-
3
2
  import type { IAgenticaPromptJson } from "../json/IAgenticaPromptJson";
3
+ import type { AgenticaPromptBase } from "../prompts/AgenticaPromptBase";
4
4
  import type { AgenticaOperationSelection } from "./AgenticaOperationSelection";
5
- import { AgenticaPromptBase } from "../prompts/AgenticaPromptBase";
6
5
 
7
- export class AgenticaCancelPrompt<
6
+ export interface AgenticaCancelPrompt<
8
7
  Model extends ILlmSchema.Model,
9
8
  > extends AgenticaPromptBase<"cancel", IAgenticaPromptJson.ICancel> {
10
- public readonly id: string;
11
- public readonly selections: AgenticaOperationSelection<Model>[];
12
-
13
- public constructor(props: AgenticaCancelPrompt.IProps<Model>) {
14
- super("cancel");
15
- this.id = props.id;
16
- this.selections = props.selections;
17
- }
18
-
19
- public toJSON(): IAgenticaPromptJson.ICancel {
20
- return {
21
- type: this.type,
22
- id: this.id,
23
- selections: this.selections.map(s => s.toJSON()),
24
- };
25
- }
26
- }
27
- export namespace AgenticaCancelPrompt {
28
- export interface IProps<Model extends ILlmSchema.Model> {
29
- id: string;
30
- selections: AgenticaOperationSelection<Model>[];
31
- }
9
+ id: string;
10
+ selections: AgenticaOperationSelection<Model>[];
32
11
  }
@@ -1,6 +1,5 @@
1
1
  import type { ILlmSchema } from "@samchon/openapi";
2
2
  import type OpenAI from "openai";
3
-
4
3
  import type { AgenticaEvent } from "../events/AgenticaEvent";
5
4
  import type { AgenticaEventSource } from "../events/AgenticaEventSource";
6
5
  import type { AgenticaPrompt } from "../prompts/AgenticaPrompt";
@@ -1,5 +1,4 @@
1
1
  import type { IHttpLlmFunction, ILlmFunction, ILlmSchema } from "@samchon/openapi";
2
-
3
2
  import type { IAgenticaOperationJson } from "../json/IAgenticaOperationJson";
4
3
  import type { IAgenticaController } from "../structures/IAgenticaController";
5
4
 
@@ -1,5 +1,4 @@
1
1
  import type { ILlmSchema } from "@samchon/openapi";
2
-
3
2
  import type { AgenticaOperation } from "./AgenticaOperation";
4
3
 
5
4
  /**
@@ -1,27 +1,9 @@
1
1
  import type { ILlmSchema } from "@samchon/openapi";
2
-
3
2
  import type { IAgenticaOperationSelectionJson } from "../json/IAgenticaOperationSelectionJson";
4
3
  import type { AgenticaOperation } from "./AgenticaOperation";
5
4
 
6
- export class AgenticaOperationSelection<Model extends ILlmSchema.Model> {
7
- public readonly operation: AgenticaOperation<Model>;
8
- public readonly reason: string;
9
-
10
- public constructor(props: AgenticaOperationSelection.IProps<Model>) {
11
- this.operation = props.operation;
12
- this.reason = props.reason;
13
- }
14
-
15
- public toJSON(): IAgenticaOperationSelectionJson {
16
- return {
17
- operation: this.operation.toJSON(),
18
- reason: this.reason,
19
- };
20
- }
21
- }
22
- export namespace AgenticaOperationSelection {
23
- export interface IProps<Model extends ILlmSchema.Model> {
24
- operation: AgenticaOperation<Model>;
25
- reason: string;
26
- }
5
+ export interface AgenticaOperationSelection<Model extends ILlmSchema.Model> {
6
+ operation: AgenticaOperation<Model>;
7
+ reason: string;
8
+ toJSON: () => IAgenticaOperationSelectionJson;
27
9
  }
@@ -1,7 +1,7 @@
1
- import type { IAgenticaTokenUsageJson } from "../json/IAgenticaTokenUsageJson";
2
-
3
1
  import typia from "typia";
4
2
 
3
+ import type { IAgenticaTokenUsageJson } from "../json/IAgenticaTokenUsageJson";
4
+
5
5
  export class AgenticaTokenUsage implements IAgenticaTokenUsageJson {
6
6
  /**
7
7
  * Aggregated token usage.
@@ -1,5 +1,4 @@
1
1
  import type { CompletionUsage } from "openai/resources";
2
-
3
2
  import type { IAgenticaTokenUsageJson } from "../../json/IAgenticaTokenUsageJson";
4
3
  import type { AgenticaTokenUsage } from "../AgenticaTokenUsage";
5
4
 
@@ -1,36 +1,33 @@
1
1
  import type { ILlmSchema } from "@samchon/openapi";
2
-
3
2
  import type { AgenticaOperation } from "../context/AgenticaOperation";
4
3
  import type { IAgenticaEventJson } from "../json/IAgenticaEventJson";
5
- import { AgenticaEventBase } from "./AgenticaEventBase";
4
+ import type { AgenticaEventBase } from "./AgenticaEventBase";
6
5
 
7
- export class AgenticaCallEvent<
8
- Model extends ILlmSchema.Model,
9
- > extends AgenticaEventBase<"call"> {
10
- public readonly id: string;
11
- public readonly operation: AgenticaOperation<Model>;
12
- public arguments: Record<string, any>;
6
+ /**
7
+ * Event of a function calling.
8
+ *
9
+ * @author Samchon
10
+ */
11
+ export interface AgenticaCallEvent<Model extends ILlmSchema.Model>
12
+ extends AgenticaEventBase<"call"> {
13
+ /**
14
+ * ID of the tool calling.
15
+ */
16
+ id: string;
13
17
 
14
- public constructor(props: AgenticaCallEvent.IProps<Model>) {
15
- super("call");
16
- this.id = props.id;
17
- this.operation = props.operation;
18
- this.arguments = props.arguments;
19
- }
18
+ /**
19
+ * Target operation to call.
20
+ */
21
+ operation: AgenticaOperation<Model>;
20
22
 
21
- public toJSON(): IAgenticaEventJson.ICall {
22
- return {
23
- type: "call",
24
- id: this.id,
25
- operation: this.operation.toJSON(),
26
- arguments: this.arguments,
27
- };
28
- }
29
- }
30
- export namespace AgenticaCallEvent {
31
- export interface IProps<Model extends ILlmSchema.Model> {
32
- id: string;
33
- operation: AgenticaOperation<Model>;
34
- arguments: Record<string, any>;
35
- }
23
+ /**
24
+ * Arguments of the function calling.
25
+ *
26
+ * If you modify this {@link arguments} property, it actually modifies
27
+ * the backend server's request. Therefore, be careful when you're
28
+ * trying to modify this property.
29
+ */
30
+ arguments: Record<string, any>;
31
+
32
+ toJSON: () => IAgenticaEventJson.ICall;
36
33
  }
@@ -1,28 +1,11 @@
1
1
  import type { ILlmSchema } from "@samchon/openapi";
2
-
3
2
  import type { AgenticaOperationSelection } from "../context/AgenticaOperationSelection";
4
3
  import type { IAgenticaEventJson } from "../json/IAgenticaEventJson";
5
- import { AgenticaEventBase } from "./AgenticaEventBase";
4
+ import type { AgenticaEventBase } from "./AgenticaEventBase";
6
5
 
7
- export class AgenticaCancelEvent<
6
+ export interface AgenticaCancelEvent<
8
7
  Model extends ILlmSchema.Model,
9
8
  > extends AgenticaEventBase<"cancel"> {
10
- public readonly selection: AgenticaOperationSelection<Model>;
11
-
12
- public constructor(props: AgenticaCancelEvent.IProps<Model>) {
13
- super("cancel");
14
- this.selection = props.selection;
15
- }
16
-
17
- public toJSON(): IAgenticaEventJson.ICancel {
18
- return {
19
- type: "cancel",
20
- selection: this.selection.toJSON(),
21
- };
22
- }
23
- }
24
- export namespace AgenticaCancelEvent {
25
- export interface IProps<Model extends ILlmSchema.Model> {
26
- selection: AgenticaOperationSelection<Model>;
27
- }
9
+ selection: AgenticaOperationSelection<Model>;
10
+ toJSON: () => IAgenticaEventJson.ICancel;
28
11
  }
@@ -1,66 +1,17 @@
1
1
  import type { ILlmSchema } from "@samchon/openapi";
2
2
 
3
3
  import type { IAgenticaEventJson } from "../json/IAgenticaEventJson";
4
+ import type { AgenticaDescribePrompt } from "../prompts/AgenticaDescribePrompt";
4
5
  import type { AgenticaExecutePrompt } from "../prompts/AgenticaExecutePrompt";
5
- import { AgenticaDescribePrompt } from "../prompts/AgenticaDescribePrompt";
6
- import { AgenticaEventBase } from "./AgenticaEventBase";
6
+ import type { AgenticaEventBase } from "./AgenticaEventBase";
7
7
 
8
- export class AgenticaDescribeEvent<
8
+ export interface AgenticaDescribeEvent<
9
9
  Model extends ILlmSchema.Model,
10
10
  > extends AgenticaEventBase<"describe"> {
11
- public readonly executes: AgenticaExecutePrompt<Model>[];
12
- public readonly stream: ReadableStream<string>;
13
- public get text(): string {
14
- return this.get_();
15
- }
11
+ executes: AgenticaExecutePrompt<Model>[];
12
+ stream: ReadableStream<string>;
16
13
 
17
- /**
18
- * Check if the join method can return a response immediately.
19
- * Returns true if the response is ready to be returned by the join method.
20
- */
21
- public get done(): boolean {
22
- return this.done_();
23
- }
24
-
25
- public constructor(props: AgenticaDescribeEvent.IProps<Model>) {
26
- super("describe");
27
- this.stream = props.stream;
28
- this.executes = props.executes;
29
- this.done_ = props.done;
30
- this.get_ = props.get;
31
- this.join_ = props.join;
32
- }
33
-
34
- public async join(): Promise<string> {
35
- return this.join_();
36
- }
37
-
38
- public toJSON(): IAgenticaEventJson.IDescribe {
39
- return {
40
- type: "describe",
41
- executes: this.executes.map(e => e.toJSON()),
42
- text: this.text,
43
- done: this.done,
44
- };
45
- }
46
-
47
- public toPrompt(): AgenticaDescribePrompt<Model> {
48
- return new AgenticaDescribePrompt({
49
- executes: this.executes,
50
- text: this.text,
51
- });
52
- }
53
-
54
- private readonly done_: () => boolean;
55
- private readonly get_: () => string;
56
- private readonly join_: () => Promise<string>;
57
- }
58
- export namespace AgenticaDescribeEvent {
59
- export interface IProps<Model extends ILlmSchema.Model> {
60
- executes: AgenticaExecutePrompt<Model>[];
61
- stream: ReadableStream<string>;
62
- done: () => boolean;
63
- get: () => string;
64
- join: () => Promise<string>;
65
- }
14
+ join: () => Promise<string>;
15
+ toJSON: () => IAgenticaEventJson.IDescribe;
16
+ toPrompt: () => AgenticaDescribePrompt<Model>;
66
17
  }
@@ -1,5 +1,4 @@
1
1
  import type { ILlmSchema } from "@samchon/openapi";
2
-
3
2
  import type { AgenticaCallEvent } from "./AgenticaCallEvent";
4
3
  import type { AgenticaCancelEvent } from "./AgenticaCancelEvent";
5
4
  import type { AgenticaDescribeEvent } from "./AgenticaDescribeEvent";
@@ -9,7 +8,18 @@ import type { AgenticaRequestEvent } from "./AgenticaRequestEvent";
9
8
  import type { AgenticaResponseEvent } from "./AgenticaResponseEvent";
10
9
  import type { AgenticaSelectEvent } from "./AgenticaSelectEvent";
11
10
  import type { AgenticaTextEvent } from "./AgenticaTextEvent";
11
+ import type { AgenticaValidateEvent } from "./AgenticaValidateEvent";
12
12
 
13
+ /**
14
+ * Agentica agent event.
15
+ *
16
+ * `AgenticaEvent` is an union type of all possible events that can
17
+ * be emitted by the AI chatbot of the {@link Agentica} class.
18
+ *
19
+ * You can discriminate the subtype by checking the {@link type} property.
20
+ *
21
+ * @author Samchon
22
+ */
13
23
  export type AgenticaEvent<Model extends ILlmSchema.Model> =
14
24
  | AgenticaCallEvent<Model>
15
25
  | AgenticaCancelEvent<Model>
@@ -19,7 +29,8 @@ export type AgenticaEvent<Model extends ILlmSchema.Model> =
19
29
  | AgenticaRequestEvent
20
30
  | AgenticaResponseEvent
21
31
  | AgenticaSelectEvent<Model>
22
- | AgenticaTextEvent;
32
+ | AgenticaTextEvent
33
+ | AgenticaValidateEvent<Model>;
23
34
  export namespace AgenticaEvent {
24
35
  export type Type = AgenticaEvent<any>["type"];
25
36
  export interface Mapper<Model extends ILlmSchema.Model> {
@@ -32,5 +43,6 @@ export namespace AgenticaEvent {
32
43
  response: AgenticaResponseEvent;
33
44
  select: AgenticaSelectEvent<Model>;
34
45
  text: AgenticaTextEvent;
46
+ validate: AgenticaValidateEvent<Model>;
35
47
  }
36
48
  }
@@ -1,7 +1,6 @@
1
- export abstract class AgenticaEventBase<Type extends string> {
2
- public readonly type: Type;
3
-
4
- public constructor(type: Type) {
5
- this.type = type;
6
- }
1
+ export interface AgenticaEventBase<Type extends string> {
2
+ /**
3
+ * Discriminator type.
4
+ */
5
+ type: Type;
7
6
  }
@@ -1,50 +1,42 @@
1
- import type { ILlmSchema } from "@samchon/openapi";
2
-
1
+ import type { IHttpResponse, ILlmSchema } from "@samchon/openapi";
3
2
  import type { AgenticaOperation } from "../context/AgenticaOperation";
4
3
  import type { IAgenticaEventJson } from "../json/IAgenticaEventJson";
5
- import { AgenticaExecutePrompt } from "../prompts/AgenticaExecutePrompt";
6
- import { AgenticaEventBase } from "./AgenticaEventBase";
7
-
8
- export class AgenticaExecuteEvent<
9
- Model extends ILlmSchema.Model,
10
- > extends AgenticaEventBase<"execute"> {
11
- public readonly id: string;
12
- public readonly operation: AgenticaOperation<Model>;
13
- public readonly arguments: Record<string, unknown>;
14
- public readonly value: unknown;
4
+ import type { AgenticaExecutePrompt } from "../prompts/AgenticaExecutePrompt";
5
+ import type { AgenticaEventBase } from "./AgenticaEventBase";
15
6
 
16
- public constructor(props: AgenticaExecuteEvent.IProps<Model>) {
17
- super("execute");
18
- this.id = props.id;
19
- this.operation = props.operation;
20
- this.arguments = props.arguments;
21
- this.value = props.value;
22
- }
7
+ export type AgenticaExecuteEvent<Model extends ILlmSchema.Model> =
8
+ | AgenticaExecuteEvent.Class<Model>
9
+ | AgenticaExecuteEvent.Protocol<Model>;
10
+ export namespace AgenticaExecuteEvent {
11
+ export interface Class<Model extends ILlmSchema.Model>
12
+ extends Base<
13
+ "class",
14
+ AgenticaOperation.Class<Model>,
15
+ AgenticaExecutePrompt.Class<Model>,
16
+ unknown
17
+ > {}
23
18
 
24
- public toJSON(): IAgenticaEventJson.IExecute {
25
- return {
26
- type: "execute",
27
- id: this.id,
28
- operation: this.operation.toJSON(),
29
- arguments: this.arguments,
30
- value: this.value,
31
- };
32
- }
19
+ export interface Protocol<Model extends ILlmSchema.Model>
20
+ extends Base<
21
+ "http",
22
+ AgenticaOperation.Http<Model>,
23
+ AgenticaExecutePrompt.Http<Model>,
24
+ IHttpResponse
25
+ > {}
33
26
 
34
- public toPrompt(): AgenticaExecutePrompt<Model> {
35
- return new AgenticaExecutePrompt({
36
- id: this.id,
37
- operation: this.operation,
38
- arguments: this.arguments,
39
- value: this.value,
40
- });
41
- }
42
- }
43
- export namespace AgenticaExecuteEvent {
44
- export interface IProps<Model extends ILlmSchema.Model> {
27
+ interface Base<
28
+ Protocol extends "http" | "class",
29
+ Operation extends AgenticaOperation<any>,
30
+ Prompt extends AgenticaExecutePrompt<any>,
31
+ Value,
32
+ > extends AgenticaEventBase<"execute"> {
33
+ protocol: Protocol;
45
34
  id: string;
46
- operation: AgenticaOperation<Model>;
35
+ operation: Operation;
47
36
  arguments: Record<string, unknown>;
48
- value: unknown;
37
+ value: Value;
38
+
39
+ toJSON: () => IAgenticaEventJson.IExecute;
40
+ toPrompt: () => Prompt;
49
41
  }
50
42
  }
@@ -1,14 +1,6 @@
1
1
  import type { IAgenticaEventJson } from "../json/IAgenticaEventJson";
2
- import { AgenticaEventBase } from "./AgenticaEventBase";
2
+ import type { AgenticaEventBase } from "./AgenticaEventBase";
3
3
 
4
- export class AgenticaInitializeEvent extends AgenticaEventBase<"initialize"> {
5
- public constructor() {
6
- super("initialize");
7
- }
8
-
9
- public toJSON(): IAgenticaEventJson.IInitialize {
10
- return {
11
- type: "initialize",
12
- };
13
- }
4
+ export interface AgenticaInitializeEvent extends AgenticaEventBase<"initialize"> {
5
+ toJSON: () => IAgenticaEventJson.IInitialize;
14
6
  }
@@ -1,45 +1,10 @@
1
1
  import type OpenAI from "openai";
2
2
 
3
- import type { IAgenticaEventJson } from "../json/IAgenticaEventJson";
3
+ import type { AgenticaEventBase } from "./AgenticaEventBase";
4
4
  import type { AgenticaEventSource } from "./AgenticaEventSource";
5
- import { AgenticaEventBase } from "./AgenticaEventBase";
6
5
 
7
- export class AgenticaRequestEvent extends AgenticaEventBase<"request"> {
8
- public readonly source: AgenticaEventSource;
9
- public readonly body: OpenAI.ChatCompletionCreateParamsStreaming;
10
- public readonly options?: OpenAI.RequestOptions | undefined;
11
-
12
- public constructor(props: AgenticaRequestEvent.IProps) {
13
- super("request");
14
- this.source = props.source;
15
- this.body = props.body;
16
- this.options = props.options;
17
- }
18
-
19
- public toJSON(): IAgenticaEventJson.IRequest {
20
- return {
21
- type: "request",
22
- source: this.source,
23
- body: this.body,
24
- options: this.options,
25
- };
26
- }
27
- }
28
- export namespace AgenticaRequestEvent {
29
- export interface IProps {
30
- /**
31
- * The source agent of the request.
32
- */
33
- source: AgenticaEventSource;
34
-
35
- /**
36
- * Request body.
37
- */
38
- body: OpenAI.ChatCompletionCreateParamsStreaming;
39
-
40
- /**
41
- * Options for the request.
42
- */
43
- options?: OpenAI.RequestOptions | undefined;
44
- }
6
+ export interface AgenticaRequestEvent extends AgenticaEventBase<"request"> {
7
+ source: AgenticaEventSource;
8
+ body: OpenAI.ChatCompletionCreateParamsStreaming;
9
+ options?: OpenAI.RequestOptions | undefined;
45
10
  }
@@ -1,48 +1,31 @@
1
1
  import type OpenAI from "openai";
2
2
 
3
+ import type { AgenticaEventBase } from "./AgenticaEventBase";
3
4
  import type { AgenticaEventSource } from "./AgenticaEventSource";
4
- import { AgenticaEventBase } from "./AgenticaEventBase";
5
5
 
6
- export class AgenticaResponseEvent extends AgenticaEventBase<"response"> {
7
- public readonly source: AgenticaEventSource;
8
- public readonly body: OpenAI.ChatCompletionCreateParamsStreaming;
9
- public readonly stream: ReadableStream<OpenAI.ChatCompletionChunk>;
10
- public readonly options?: OpenAI.RequestOptions | undefined;
11
- public readonly join: () => Promise<OpenAI.ChatCompletion>;
6
+ export interface AgenticaResponseEvent extends AgenticaEventBase<"response"> {
7
+ /**
8
+ * The source agent of the response.
9
+ */
10
+ source: AgenticaEventSource;
12
11
 
13
- public constructor(props: AgenticaResponseEvent.IProps) {
14
- super("response");
15
- this.source = props.source;
16
- this.body = props.body;
17
- this.stream = props.stream;
18
- this.options = props.options;
19
- this.join = props.join;
20
- }
21
- }
22
- export namespace AgenticaResponseEvent {
23
- export interface IProps {
24
- /**
25
- * The source agent of the response.
26
- */
27
- source: AgenticaEventSource;
12
+ /**
13
+ * Request body.
14
+ */
15
+ body: OpenAI.ChatCompletionCreateParamsStreaming;
28
16
 
29
- /**
30
- * Request body.
31
- */
32
- body: OpenAI.ChatCompletionCreateParamsStreaming;
17
+ /**
18
+ * The text content stream.
19
+ */
20
+ stream: ReadableStream<OpenAI.ChatCompletionChunk>;
33
21
 
34
- /**
35
- * Options for the request.
36
- */
37
- options?: OpenAI.RequestOptions | undefined;
38
- /**
39
- * The text content stream.
40
- */
41
- stream: ReadableStream<OpenAI.ChatCompletionChunk>;
22
+ /**
23
+ * Options for the request.
24
+ */
25
+ options?: OpenAI.RequestOptions | undefined;
42
26
 
43
- /**
44
- * Get the description text.
45
- */
46
- join: () => Promise<OpenAI.ChatCompletion>;
47
- }
27
+ /**
28
+ * Wait the completion.
29
+ */
30
+ join: () => Promise<OpenAI.ChatCompletion>;
48
31
  }