@agentica/core 0.7.0-dev.20250224

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (163) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +464 -0
  3. package/lib/Agentica.d.ts +124 -0
  4. package/lib/Agentica.js +271 -0
  5. package/lib/Agentica.js.map +1 -0
  6. package/lib/chatgpt/ChatGptAgent.d.ts +6 -0
  7. package/lib/chatgpt/ChatGptAgent.js +59 -0
  8. package/lib/chatgpt/ChatGptAgent.js.map +1 -0
  9. package/lib/chatgpt/ChatGptCallFunctionAgent.d.ts +5 -0
  10. package/lib/chatgpt/ChatGptCallFunctionAgent.js +362 -0
  11. package/lib/chatgpt/ChatGptCallFunctionAgent.js.map +1 -0
  12. package/lib/chatgpt/ChatGptCancelFunctionAgent.d.ts +8 -0
  13. package/lib/chatgpt/ChatGptCancelFunctionAgent.js +359 -0
  14. package/lib/chatgpt/ChatGptCancelFunctionAgent.js.map +1 -0
  15. package/lib/chatgpt/ChatGptDescribeFunctionAgent.d.ts +5 -0
  16. package/lib/chatgpt/ChatGptDescribeFunctionAgent.js +56 -0
  17. package/lib/chatgpt/ChatGptDescribeFunctionAgent.js.map +1 -0
  18. package/lib/chatgpt/ChatGptHistoryDecoder.d.ts +5 -0
  19. package/lib/chatgpt/ChatGptHistoryDecoder.js +77 -0
  20. package/lib/chatgpt/ChatGptHistoryDecoder.js.map +1 -0
  21. package/lib/chatgpt/ChatGptInitializeFunctionAgent.d.ts +5 -0
  22. package/lib/chatgpt/ChatGptInitializeFunctionAgent.js +1883 -0
  23. package/lib/chatgpt/ChatGptInitializeFunctionAgent.js.map +1 -0
  24. package/lib/chatgpt/ChatGptSelectFunctionAgent.d.ts +5 -0
  25. package/lib/chatgpt/ChatGptSelectFunctionAgent.js +381 -0
  26. package/lib/chatgpt/ChatGptSelectFunctionAgent.js.map +1 -0
  27. package/lib/functional/createHttpLlmApplication.d.ts +33 -0
  28. package/lib/functional/createHttpLlmApplication.js +7766 -0
  29. package/lib/functional/createHttpLlmApplication.js.map +1 -0
  30. package/lib/index.d.ts +16 -0
  31. package/lib/index.js +35 -0
  32. package/lib/index.js.map +1 -0
  33. package/lib/index.mjs +10366 -0
  34. package/lib/index.mjs.map +1 -0
  35. package/lib/internal/AgenticaConstant.d.ts +4 -0
  36. package/lib/internal/AgenticaConstant.js +9 -0
  37. package/lib/internal/AgenticaConstant.js.map +1 -0
  38. package/lib/internal/AgenticaCostAggregator.d.ts +5 -0
  39. package/lib/internal/AgenticaCostAggregator.js +30 -0
  40. package/lib/internal/AgenticaCostAggregator.js.map +1 -0
  41. package/lib/internal/AgenticaDefaultPrompt.d.ts +4 -0
  42. package/lib/internal/AgenticaDefaultPrompt.js +32 -0
  43. package/lib/internal/AgenticaDefaultPrompt.js.map +1 -0
  44. package/lib/internal/AgenticaOperationComposer.d.ts +9 -0
  45. package/lib/internal/AgenticaOperationComposer.js +58 -0
  46. package/lib/internal/AgenticaOperationComposer.js.map +1 -0
  47. package/lib/internal/AgenticaPromptFactory.d.ts +6 -0
  48. package/lib/internal/AgenticaPromptFactory.js +9 -0
  49. package/lib/internal/AgenticaPromptFactory.js.map +1 -0
  50. package/lib/internal/AgenticaPromptTransformer.d.ts +9 -0
  51. package/lib/internal/AgenticaPromptTransformer.js +58 -0
  52. package/lib/internal/AgenticaPromptTransformer.js.map +1 -0
  53. package/lib/internal/AgenticaSystemPrompt.d.ts +8 -0
  54. package/lib/internal/AgenticaSystemPrompt.js +13 -0
  55. package/lib/internal/AgenticaSystemPrompt.js.map +1 -0
  56. package/lib/internal/MathUtil.d.ts +3 -0
  57. package/lib/internal/MathUtil.js +8 -0
  58. package/lib/internal/MathUtil.js.map +1 -0
  59. package/lib/internal/Singleton.d.ts +1 -0
  60. package/lib/internal/Singleton.js +23 -0
  61. package/lib/internal/Singleton.js.map +1 -0
  62. package/lib/internal/__map_take.d.ts +1 -0
  63. package/lib/internal/__map_take.js +16 -0
  64. package/lib/internal/__map_take.js.map +1 -0
  65. package/lib/structures/IAgenticaConfig.d.ts +112 -0
  66. package/lib/structures/IAgenticaConfig.js +3 -0
  67. package/lib/structures/IAgenticaConfig.js.map +1 -0
  68. package/lib/structures/IAgenticaContext.d.ts +106 -0
  69. package/lib/structures/IAgenticaContext.js +3 -0
  70. package/lib/structures/IAgenticaContext.js.map +1 -0
  71. package/lib/structures/IAgenticaController.d.ts +110 -0
  72. package/lib/structures/IAgenticaController.js +3 -0
  73. package/lib/structures/IAgenticaController.js.map +1 -0
  74. package/lib/structures/IAgenticaEvent.d.ts +191 -0
  75. package/lib/structures/IAgenticaEvent.js +3 -0
  76. package/lib/structures/IAgenticaEvent.js.map +1 -0
  77. package/lib/structures/IAgenticaExecutor.d.ts +144 -0
  78. package/lib/structures/IAgenticaExecutor.js +3 -0
  79. package/lib/structures/IAgenticaExecutor.js.map +1 -0
  80. package/lib/structures/IAgenticaOperation.d.ts +48 -0
  81. package/lib/structures/IAgenticaOperation.js +3 -0
  82. package/lib/structures/IAgenticaOperation.js.map +1 -0
  83. package/lib/structures/IAgenticaOperationCollection.d.ts +46 -0
  84. package/lib/structures/IAgenticaOperationCollection.js +3 -0
  85. package/lib/structures/IAgenticaOperationCollection.js.map +1 -0
  86. package/lib/structures/IAgenticaOperationSelection.d.ts +51 -0
  87. package/lib/structures/IAgenticaOperationSelection.js +3 -0
  88. package/lib/structures/IAgenticaOperationSelection.js.map +1 -0
  89. package/lib/structures/IAgenticaPrompt.d.ts +139 -0
  90. package/lib/structures/IAgenticaPrompt.js +3 -0
  91. package/lib/structures/IAgenticaPrompt.js.map +1 -0
  92. package/lib/structures/IAgenticaProps.d.ts +59 -0
  93. package/lib/structures/IAgenticaProps.js +3 -0
  94. package/lib/structures/IAgenticaProps.js.map +1 -0
  95. package/lib/structures/IAgenticaProvider.d.ts +41 -0
  96. package/lib/structures/IAgenticaProvider.js +3 -0
  97. package/lib/structures/IAgenticaProvider.js.map +1 -0
  98. package/lib/structures/IAgenticaSystemPrompt.d.ts +116 -0
  99. package/lib/structures/IAgenticaSystemPrompt.js +3 -0
  100. package/lib/structures/IAgenticaSystemPrompt.js.map +1 -0
  101. package/lib/structures/IAgenticaTokenUsage.d.ts +50 -0
  102. package/lib/structures/IAgenticaTokenUsage.js +3 -0
  103. package/lib/structures/IAgenticaTokenUsage.js.map +1 -0
  104. package/lib/structures/internal/__IChatCancelFunctionsApplication.d.ts +22 -0
  105. package/lib/structures/internal/__IChatCancelFunctionsApplication.js +3 -0
  106. package/lib/structures/internal/__IChatCancelFunctionsApplication.js.map +1 -0
  107. package/lib/structures/internal/__IChatFunctionReference.d.ts +20 -0
  108. package/lib/structures/internal/__IChatFunctionReference.js +3 -0
  109. package/lib/structures/internal/__IChatFunctionReference.js.map +1 -0
  110. package/lib/structures/internal/__IChatInitialApplication.d.ts +14 -0
  111. package/lib/structures/internal/__IChatInitialApplication.js +3 -0
  112. package/lib/structures/internal/__IChatInitialApplication.js.map +1 -0
  113. package/lib/structures/internal/__IChatSelectFunctionsApplication.d.ts +23 -0
  114. package/lib/structures/internal/__IChatSelectFunctionsApplication.js +3 -0
  115. package/lib/structures/internal/__IChatSelectFunctionsApplication.js.map +1 -0
  116. package/lib/typings/AgenticaSource.d.ts +1 -0
  117. package/lib/typings/AgenticaSource.js +3 -0
  118. package/lib/typings/AgenticaSource.js.map +1 -0
  119. package/package.json +74 -0
  120. package/prompts/cancel.md +5 -0
  121. package/prompts/common.md +3 -0
  122. package/prompts/describe.md +7 -0
  123. package/prompts/execute.md +7 -0
  124. package/prompts/initialize.md +3 -0
  125. package/prompts/select.md +7 -0
  126. package/src/Agentica.ts +322 -0
  127. package/src/chatgpt/ChatGptAgent.ts +71 -0
  128. package/src/chatgpt/ChatGptCallFunctionAgent.ts +445 -0
  129. package/src/chatgpt/ChatGptCancelFunctionAgent.ts +283 -0
  130. package/src/chatgpt/ChatGptDescribeFunctionAgent.ts +51 -0
  131. package/src/chatgpt/ChatGptHistoryDecoder.ts +86 -0
  132. package/src/chatgpt/ChatGptInitializeFunctionAgent.ts +88 -0
  133. package/src/chatgpt/ChatGptSelectFunctionAgent.ts +316 -0
  134. package/src/functional/createHttpLlmApplication.ts +63 -0
  135. package/src/index.ts +19 -0
  136. package/src/internal/AgenticaConstant.ts +4 -0
  137. package/src/internal/AgenticaCostAggregator.ts +35 -0
  138. package/src/internal/AgenticaDefaultPrompt.ts +39 -0
  139. package/src/internal/AgenticaOperationComposer.ts +82 -0
  140. package/src/internal/AgenticaPromptFactory.ts +30 -0
  141. package/src/internal/AgenticaPromptTransformer.ts +83 -0
  142. package/src/internal/AgenticaSystemPrompt.ts +14 -0
  143. package/src/internal/MathUtil.ts +3 -0
  144. package/src/internal/Singleton.ts +22 -0
  145. package/src/internal/__map_take.ts +15 -0
  146. package/src/structures/IAgenticaConfig.ts +121 -0
  147. package/src/structures/IAgenticaContext.ts +128 -0
  148. package/src/structures/IAgenticaController.ts +130 -0
  149. package/src/structures/IAgenticaEvent.ts +224 -0
  150. package/src/structures/IAgenticaExecutor.ts +152 -0
  151. package/src/structures/IAgenticaOperation.ts +64 -0
  152. package/src/structures/IAgenticaOperationCollection.ts +50 -0
  153. package/src/structures/IAgenticaOperationSelection.ts +69 -0
  154. package/src/structures/IAgenticaPrompt.ts +173 -0
  155. package/src/structures/IAgenticaProps.ts +64 -0
  156. package/src/structures/IAgenticaProvider.ts +45 -0
  157. package/src/structures/IAgenticaSystemPrompt.ts +122 -0
  158. package/src/structures/IAgenticaTokenUsage.ts +52 -0
  159. package/src/structures/internal/__IChatCancelFunctionsApplication.ts +23 -0
  160. package/src/structures/internal/__IChatFunctionReference.ts +21 -0
  161. package/src/structures/internal/__IChatInitialApplication.ts +15 -0
  162. package/src/structures/internal/__IChatSelectFunctionsApplication.ts +24 -0
  163. package/src/typings/AgenticaSource.ts +6 -0
@@ -0,0 +1,152 @@
1
+ import { IAgenticaContext } from "./IAgenticaContext";
2
+ import { IAgenticaPrompt } from "./IAgenticaPrompt";
3
+
4
+ /**
5
+ * Executor of the Agentic AI.
6
+ *
7
+ * `IAgenticaExecutor` represents an executor of the {@link Agentica},
8
+ * composing its internal agents to accomplish the Agentic AI through
9
+ * the LLM (Large Language Model) function calling.
10
+ *
11
+ * You can customize one of these internal agents by configuring
12
+ * properties of the `IAgenticaExecutor` type, and assigning it to the
13
+ * {@link IAgenticaConfig.executor} property. If you set the
14
+ * {@link initialize} as `null` value, the {@link Agentica} will skip
15
+ * the initialize process and directly go to the {@link select} process.
16
+ *
17
+ * By the way, when customizing the executor member, it would better to
18
+ * reference the guide documents of `@agentica/core`, and internal
19
+ * agents' implementation code. It's because if you take some mistake on
20
+ * the executor logic, it can entirely break the {@link Agentica}'s
21
+ * operation.
22
+ *
23
+ * @reference https://github.com/wrtnlabs/agentica?tab=readme-ov-file#principles
24
+ * @reference https://github.com/wrtnlabs/agentica/blob/main/packages/agent/src/chatgpt/ChatGptAgent.ts
25
+ * @author Samchon
26
+ */
27
+ export interface IAgenticaExecutor {
28
+ /**
29
+ * Initializer agent listing up functions.
30
+ *
31
+ * `initialize` agent is the first agent that {@link Agentica}
32
+ * would meet which judges whether the user's conversation implies
33
+ * to call some function or not.
34
+ *
35
+ * And if the `initialize` agent judges the user's conversation
36
+ * implies to call some function, the `initialize` agent will
37
+ * call the {@link IAgenticaContext.initialize} function, and
38
+ * inform every functions enrolled in the {@link IAgenticaController}
39
+ * to the AI agent. And then, the `initialize` agent will not never
40
+ * be called again, and let {@link Agentica} to go to the next
41
+ * {@link select} agent.
42
+ *
43
+ * Otherwise the user's conversation does not imply the request of
44
+ * function calling, it would just work like plain chatbot, and just
45
+ * conversate with the user.
46
+ *
47
+ * By the way, if you wanna skip the `initialize` agent, you can
48
+ * do it by configuring the {@link IAgenticaConfig.executor} as
49
+ * `null` value. In that case, the `initialize` agent will never be
50
+ * called, and {@link Agentica} just starts from the {@link select}
51
+ * agent.
52
+ *
53
+ * @param ctx Context of the agent
54
+ * @returns List of prompts generated by the initializer
55
+ */
56
+ initialize: null | ((ctx: IAgenticaContext) => Promise<IAgenticaPrompt[]>);
57
+
58
+ /**
59
+ * Function selector agent.
60
+ *
61
+ * `Select` agent finds candidate functions to call from the
62
+ * conversation context with the user. And the candidate functions
63
+ * would be enrolled to the {@link IAgenticaContext.stack}, and the
64
+ * next {@link call} agent will perform the LLM (Large Language Model)
65
+ * function calling.
66
+ *
67
+ * Note that, the `select` agent does not perform the LLM function
68
+ * calling. It ends with just finding the candidate functions to call.
69
+ *
70
+ * By the way, if the `select` agent can't specify a certain function
71
+ * to call due to lack of conversation context or homogeneity between
72
+ * heterogeneous functions, how `select` agent works? In that case,
73
+ * `select` agent it will just enroll every candidate functions to
74
+ * the stack, and let the next {@link call} agent to determine the
75
+ * proper function to call. And then let {@link cancel} agent to erase
76
+ * the other candidate functions from the stack.
77
+ *
78
+ * Additionally, if `select` agent could not find any candidate
79
+ * function from the conversation context with user, it would just
80
+ * act like plain chatbot conversating with the user.
81
+ *
82
+ * @param ctx Context of the agent
83
+ * @returns List of prompts generated by the selector
84
+ */
85
+ select: (ctx: IAgenticaContext) => Promise<IAgenticaPrompt[]>;
86
+
87
+ /**
88
+ * Function caller agent.
89
+ *
90
+ * `Call` agent performs the LLM (Large Language Model) function
91
+ * calling from the candidate functions enrolled in the
92
+ * {@link IAgenticaContext.stack}. And the scope of function calling
93
+ * is, not only just arguments filling, but also actual executing
94
+ * the function and returning the result.
95
+ *
96
+ * By the way, conversation context with user can be not enough to
97
+ * filling the arguments of the candidate functions. In that case,
98
+ * the `call` agent will ask the user to fill the missing arguments.
99
+ *
100
+ * Otherwise the cpnversation context is enough, so that succeeded
101
+ * to call some candidate functions, the `call` agent will step to
102
+ * the {@link describe} agent to explain the result of the function
103
+ * calling to the user as markdown content.
104
+ *
105
+ * @param ctx Context of the agent
106
+ * @returns List of prompts generated by the caller
107
+ * @warning Recommend not to customize, due to its validation
108
+ * feedback strategy is working very well, and the `call`
109
+ * agent is the most general topic which can be universally
110
+ * applied to all domain fields.
111
+ */
112
+ call: (ctx: IAgenticaContext) => Promise<IAgenticaPrompt[]>;
113
+
114
+ /**
115
+ * Describer agent of the function calling result.
116
+ *
117
+ * `Describe` agent explains the results of the function callings
118
+ * to the user as markdown content.
119
+ *
120
+ * @param ctx Context of the agent
121
+ * @param executes List of function calling results
122
+ * @returns List of prompts generated by the describer
123
+ */
124
+ describe: (
125
+ ctx: IAgenticaContext,
126
+ executes: IAgenticaPrompt.IExecute[],
127
+ ) => Promise<IAgenticaPrompt[]>;
128
+
129
+ /**
130
+ * Function canceler agent.
131
+ *
132
+ * `Cancel` agent erases the candidate functions from the
133
+ * {@link IAgenticaContext.stack} by analyzing the conversation
134
+ * context with the user.
135
+ *
136
+ * For reference, the first reason of the cancelation is explicit
137
+ * order from user to the previous requested function. For example,
138
+ * user had requested to send an email to the agent, but suddenly
139
+ * user says to cancel the email sending.
140
+ *
141
+ * The seconod reason n of the cancelation is the multiple candidate
142
+ * functions had been selected at once by the {@link select} agent
143
+ * due to lack of conversation context or homogeneity between the
144
+ * heterogeneous functions. And in the multiple candidate functions,
145
+ * one thing is clearly determined by the {@link call} agent, so that
146
+ * drop the other candidate functions.
147
+ *
148
+ * @param ctx Context of the agent
149
+ * @returns List of prompts generated by the canceler
150
+ */
151
+ cancel: (ctx: IAgenticaContext) => Promise<IAgenticaPrompt[]>;
152
+ }
@@ -0,0 +1,64 @@
1
+ import { IHttpLlmFunction } from "@samchon/openapi";
2
+ import { ILlmFunctionOfValidate } from "typia";
3
+
4
+ import { IAgenticaController } from "./IAgenticaController";
5
+
6
+ /**
7
+ * Operation information in the Nestia Agent.
8
+ *
9
+ * `IAgenticaOperation` is a type represents an operation that would
10
+ * be selected by the A.I. chatbot of {@link Agentica} class to
11
+ * perform the LLM (Large Language Model) function calling.
12
+ *
13
+ * Also, it is an union type that is discriminated by the {@link protocol}
14
+ * property. If the protocol value is `http`, it means that the HTTP API
15
+ * operation would be called by the A.I. chatbot. Otherwise, if the protocol
16
+ * value is `class`, it means that the operation has come from a
17
+ * TypeScript class.
18
+ *
19
+ * @author Samchon
20
+ */
21
+ export type IAgenticaOperation =
22
+ | IAgenticaOperation.IHttp
23
+ | IAgenticaOperation.IClass;
24
+ export namespace IAgenticaOperation {
25
+ /**
26
+ * HTTP API operation.
27
+ */
28
+ export type IHttp = IBase<
29
+ "http",
30
+ IAgenticaController.IHttp,
31
+ IHttpLlmFunction<"chatgpt">
32
+ >;
33
+
34
+ /**
35
+ * TypeScript class operation.
36
+ */
37
+ export type IClass = IBase<
38
+ "class",
39
+ IAgenticaController.IClass,
40
+ ILlmFunctionOfValidate<"chatgpt">
41
+ >;
42
+
43
+ interface IBase<Protocol, Application, Function> {
44
+ /**
45
+ * Protocol discriminator.
46
+ */
47
+ protocol: Protocol;
48
+
49
+ /**
50
+ * Belonged controller of the target function.
51
+ */
52
+ controller: Application;
53
+
54
+ /**
55
+ * Target function to call.
56
+ */
57
+ function: Function;
58
+
59
+ /**
60
+ * Identifier name.
61
+ */
62
+ name: string;
63
+ }
64
+ }
@@ -0,0 +1,50 @@
1
+ import { IAgenticaOperation } from "./IAgenticaOperation";
2
+
3
+ /**
4
+ * Collection of operations used in the Nestia Agent.
5
+ *
6
+ * `IAgenticaOperationCollection` is an interface type representing
7
+ * a collection of operations for several purposes used in the
8
+ * {@link Agentica} internally.
9
+ *
10
+ * @author Samchon
11
+ */
12
+ export interface IAgenticaOperationCollection {
13
+ /**
14
+ * List of every operations.
15
+ */
16
+ array: IAgenticaOperation[];
17
+
18
+ /**
19
+ * Divided operations.
20
+ *
21
+ * If you've configured the {@link IAgenticaConfig.capacity} property,
22
+ * the A.I. chatbot ({@link Agentica}) will separate the operations
23
+ * into the several groups to divide and conquer and LLM function selecting
24
+ * for accuracy.
25
+ *
26
+ * In that case, this property `divided`'s length would be dtermined by
27
+ * dividing the number of operations ({@link array}'s length) by the
28
+ * {@link IAgenticaConfig.capacity}.
29
+ *
30
+ * Otherwise, if the {@link IAgenticaConfig.capacity} has not been
31
+ * configured, this `divided` property would be the `undefined` value.
32
+ */
33
+ divided?: IAgenticaOperation[][] | undefined;
34
+
35
+ /**
36
+ * Flat dictionary of operations.
37
+ *
38
+ * Dictionary of operations with their {@link IAgenticaOperation.name}.
39
+ */
40
+ flat: Map<string, IAgenticaOperation>;
41
+
42
+ /**
43
+ * Group dictionary of operations.
44
+ *
45
+ * Dictionary of operations with their
46
+ * {@link IAgenticaOperation.controller.name} and
47
+ * {@link IAgenticaOperation.function.name}.
48
+ */
49
+ group: Map<string, Map<string, IAgenticaOperation>>;
50
+ }
@@ -0,0 +1,69 @@
1
+ import { IHttpLlmFunction } from "@samchon/openapi";
2
+ import { ILlmFunctionOfValidate } from "typia";
3
+
4
+ import { IAgenticaController } from "./IAgenticaController";
5
+
6
+ /**
7
+ * Nestia agent operation selection.
8
+ *
9
+ * `IAgenticaOperationSelection` is a type represents an operation
10
+ * which has been selected by the A.I. chatbot of {@link Agentica}
11
+ * class for the LLM (Large Language Model) function calling with
12
+ * detailed {@link reason} of the selection (or cancellation).
13
+ *
14
+ * Also, `IAgenticaOperationSelection` is an union type that can
15
+ * specify a subtype by checking the {@link protocol} property.
16
+ *
17
+ * @author Samchon
18
+ */
19
+ export type IAgenticaOperationSelection =
20
+ | IAgenticaOperationSelection.IHttp
21
+ | IAgenticaOperationSelection.IClass;
22
+ export namespace IAgenticaOperationSelection {
23
+ export type IHttp = IBase<
24
+ "http",
25
+ IAgenticaController.IHttp,
26
+ IHttpLlmFunction<"chatgpt">
27
+ >;
28
+
29
+ export type IClass = IBase<
30
+ "class",
31
+ IAgenticaController.IClass,
32
+ ILlmFunctionOfValidate<"chatgpt">
33
+ >;
34
+
35
+ interface IBase<Protocol, Controller, Function> {
36
+ /**
37
+ * Discriminator protocol.
38
+ */
39
+ protocol: Protocol;
40
+
41
+ /**
42
+ * Belonged controller of the target function.
43
+ */
44
+ controller: Controller;
45
+
46
+ /**
47
+ * Target function.
48
+ *
49
+ * Function that has been selected to prepare LLM function calling,
50
+ * or canceled due to no more required.
51
+ */
52
+ function: Function;
53
+
54
+ /**
55
+ * Identifier name of the target function.
56
+ *
57
+ * If {@link Agentica} has multiple {@link IAgenticaController}s,
58
+ * the `name` can be different from target function's name.
59
+ */
60
+ name: string;
61
+
62
+ /**
63
+ * The reason of the function selection or cancellation.
64
+ */
65
+ reason: string;
66
+
67
+ toJSON(): Omit<IBase<Protocol, string, string>, "toJSON">;
68
+ }
69
+ }
@@ -0,0 +1,173 @@
1
+ import { IHttpLlmFunction, IHttpResponse } from "@samchon/openapi";
2
+ import { ILlmFunctionOfValidate } from "typia";
3
+
4
+ import { IAgenticaController } from "./IAgenticaController";
5
+ import { IAgenticaOperationSelection } from "./IAgenticaOperationSelection";
6
+
7
+ /**
8
+ * Nestia A.I. chatbot prompt.
9
+ *
10
+ * `IWrtnChatPrompt` is an union type of all possible prompts that can
11
+ * be generated by the A.I. chatbot of the {@link Agentica} class.
12
+ *
13
+ * In other words, `IWrtnChatPrompt` is a type of chat history that
14
+ * is occurred during the conversation between the user and the A.I. chatbot
15
+ * in the {@link Agentica} class.
16
+ *
17
+ * If you want to continue the previous A.I. chatbot session, you can
18
+ * accomplish it by assigning the {@link IAgenticaProps.histories}
19
+ * property when creating a new {@link Agentica} instance.
20
+ *
21
+ * @author Samchon
22
+ */
23
+ export type IAgenticaPrompt =
24
+ | IAgenticaPrompt.IText
25
+ | IAgenticaPrompt.ISelect
26
+ | IAgenticaPrompt.ICancel
27
+ | IAgenticaPrompt.IExecute
28
+ | IAgenticaPrompt.IDescribe;
29
+ export namespace IAgenticaPrompt {
30
+ /**
31
+ * Select prompt.
32
+ *
33
+ * Selection prompt about candidate functions to call.
34
+ */
35
+ export interface ISelect extends IBase<"select"> {
36
+ /**
37
+ * ID of the LLM tool call result.
38
+ */
39
+ id: string;
40
+
41
+ /**
42
+ * Operations that have been selected.
43
+ */
44
+ operations: IAgenticaOperationSelection[];
45
+ }
46
+
47
+ /**
48
+ * Cancel prompt.
49
+ *
50
+ * Cancellation prompt about the candidate functions to be discarded.
51
+ */
52
+ export interface ICancel extends IBase<"cancel"> {
53
+ /**
54
+ * ID of the LLM tool call result.
55
+ */
56
+ id: string;
57
+
58
+ /**
59
+ * Operations that have been cancelled.
60
+ */
61
+ operations: IAgenticaOperationSelection[];
62
+ }
63
+
64
+ /**
65
+ * Execute prompt.
66
+ *
67
+ * Execution prompt about the LLM function calling.
68
+ */
69
+ export type IExecute = IExecute.IHttp | IExecute.IClass;
70
+ export namespace IExecute {
71
+ export type IHttp = IBase<
72
+ "http",
73
+ IAgenticaController.IHttp,
74
+ IHttpLlmFunction<"chatgpt">,
75
+ IHttpResponse
76
+ >;
77
+ export type IClass = IBase<
78
+ "class",
79
+ IAgenticaController.IClass,
80
+ ILlmFunctionOfValidate<"chatgpt">,
81
+ any
82
+ >;
83
+ interface IBase<Protocol, Controller, Function, Value> {
84
+ /**
85
+ * Discriminator type.
86
+ */
87
+ type: "execute";
88
+
89
+ /**
90
+ * Protocol discriminator.
91
+ */
92
+ protocol: Protocol;
93
+
94
+ /**
95
+ * Belonged controller of the target function.
96
+ */
97
+ controller: Controller;
98
+
99
+ /**
100
+ * Target function to call.
101
+ */
102
+ function: Function;
103
+
104
+ /**
105
+ * ID of the LLM tool call result.
106
+ */
107
+ id: string;
108
+
109
+ /**
110
+ * Identifier name of the function.
111
+ *
112
+ * If {@link Agentica} has multiple {@link IAgenticaController}s,
113
+ * the `name` can be different from target function's name.
114
+ */
115
+ name: string;
116
+
117
+ /**
118
+ * Arguments of the LLM function calling.
119
+ */
120
+ arguments: object;
121
+
122
+ /**
123
+ * Return value.
124
+ */
125
+ value: Value;
126
+
127
+ toJSON(): Omit<IBase<Protocol, string, string, Value>, "toJSON">;
128
+ }
129
+ }
130
+
131
+ /**
132
+ * Description prompt.
133
+ *
134
+ * Description prompt about the return value of the LLM function calling.
135
+ */
136
+ export interface IDescribe extends IBase<"describe"> {
137
+ /**
138
+ * Executions of the LLM function calling.
139
+ *
140
+ * This prompt describes the return value of them.
141
+ */
142
+ executions: IExecute[];
143
+
144
+ /**
145
+ * Description text.
146
+ */
147
+ text: string;
148
+ }
149
+
150
+ /**
151
+ * Text prompt.
152
+ */
153
+ export interface IText<
154
+ Role extends "assistant" | "user" = "assistant" | "user",
155
+ > extends IBase<"text"> {
156
+ /**
157
+ * Role of the orator.
158
+ */
159
+ role: Role;
160
+
161
+ /**
162
+ * The text content.
163
+ */
164
+ text: string;
165
+ }
166
+
167
+ interface IBase<Type extends string> {
168
+ /**
169
+ * Discriminator type.
170
+ */
171
+ type: Type;
172
+ }
173
+ }
@@ -0,0 +1,64 @@
1
+ import { Primitive } from "typia";
2
+
3
+ import { IAgenticaConfig } from "./IAgenticaConfig";
4
+ import { IAgenticaController } from "./IAgenticaController";
5
+ import { IAgenticaPrompt } from "./IAgenticaPrompt";
6
+ import { IAgenticaProvider } from "./IAgenticaProvider";
7
+
8
+ /**
9
+ * Properties of the Nestia Agent.
10
+ *
11
+ * `IAgenticaProps` is an interface that defines the properties
12
+ * of the {@link Agentica.constructor}. In the `IAgenticaProps`,
13
+ * there're everything to prepare to create a Super A.I. chatbot
14
+ * performing the LLM (Large Language Model) function calling.
15
+ *
16
+ * At first, you have to specify the LLM service {@link provider} like
17
+ * OpenAI with its API key and client API. And then, you have to define
18
+ * the {@link controllers} serving the functions to call. The controllers
19
+ * are separated by two protocols; HTTP API and TypeScript class. At last,
20
+ * you can {@link config configure} the agent by setting the locale, timezone,
21
+ * and some of system prompts.
22
+ *
23
+ * Additionally, if you want to start from the previous A.I. chatbot
24
+ * session, you can accomplish it by assigning the previous prompt
25
+ * histories to the {@link histories} property.
26
+ *
27
+ * @author Samchon
28
+ */
29
+ export interface IAgenticaProps {
30
+ /**
31
+ * LLM service provider.
32
+ */
33
+ provider: IAgenticaProvider;
34
+
35
+ /**
36
+ * Controllers serving functions to call.
37
+ */
38
+ controllers: IAgenticaController[];
39
+
40
+ /**
41
+ * Configuration of agent.
42
+ *
43
+ * Configuration of A.I. chatbot agent including the user's locale,
44
+ * timezone, and some of system prompts. Also, you can affect to the
45
+ * LLM function selecting/calling logic by configuring additional
46
+ * properties.
47
+ *
48
+ * If you don't configure this property, these values would be default.
49
+ *
50
+ * - `locale`: your system's locale and timezone
51
+ * - `timezone`: your system's timezone
52
+ * - `systemPrompt`: default prompts written in markdown
53
+ * - https://github.com/samchon/nestia/tree/master/packages/agent/prompts
54
+ */
55
+ config?: IAgenticaConfig;
56
+
57
+ /**
58
+ * Prompt histories.
59
+ *
60
+ * If you're starting the conversation from an existing session,
61
+ * assign the previouis prompt histories to this property.
62
+ */
63
+ histories?: Primitive<IAgenticaPrompt>[];
64
+ }
@@ -0,0 +1,45 @@
1
+ import OpenAI from "openai";
2
+
3
+ /**
4
+ * LLM Provider for Nestia Chat.
5
+ *
6
+ * `IAgenticaProvider` is a type represents an LLM
7
+ * (Large Language Model) provider of the {@link Agentica}.
8
+ *
9
+ * Currently, {@link Agentica} is supporting only one provider OpenAI.
10
+ * You can specify the provider by configuring the `type` property as
11
+ * `"chatgpt"`. Also, you have to assign the OpenAI API client instance
12
+ * to the `api` property, and specify the `model` to use.
13
+ *
14
+ * If you want to use another LLM provider like Claude or Gemini,
15
+ * please write an issue or contribute to `nestia` please.
16
+ *
17
+ * @author Samchon
18
+ */
19
+ export type IAgenticaProvider = IAgenticaProvider.IChatGpt;
20
+ export namespace IAgenticaProvider {
21
+ /**
22
+ * OpenAI provider.
23
+ */
24
+ export interface IChatGpt {
25
+ /**
26
+ * Discriminator type.
27
+ */
28
+ type: "chatgpt";
29
+
30
+ /**
31
+ * OpenAI API instance.
32
+ */
33
+ api: OpenAI;
34
+
35
+ /**
36
+ * Chat model to be used.
37
+ */
38
+ model: OpenAI.ChatModel;
39
+
40
+ /**
41
+ * Options for the request.
42
+ */
43
+ options?: OpenAI.RequestOptions | undefined;
44
+ }
45
+ }