@agentica/core 0.8.3-dev.20250227 → 0.8.3

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 (46) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +404 -404
  3. package/package.json +1 -1
  4. package/prompts/cancel.md +4 -4
  5. package/prompts/common.md +2 -2
  6. package/prompts/describe.md +6 -6
  7. package/prompts/execute.md +6 -6
  8. package/prompts/initialize.md +2 -2
  9. package/prompts/select.md +6 -6
  10. package/src/Agentica.ts +318 -318
  11. package/src/chatgpt/ChatGptAgent.ts +71 -71
  12. package/src/chatgpt/ChatGptCallFunctionAgent.ts +445 -445
  13. package/src/chatgpt/ChatGptCancelFunctionAgent.ts +283 -283
  14. package/src/chatgpt/ChatGptDescribeFunctionAgent.ts +51 -51
  15. package/src/chatgpt/ChatGptHistoryDecoder.ts +87 -87
  16. package/src/chatgpt/ChatGptInitializeFunctionAgent.ts +88 -88
  17. package/src/chatgpt/ChatGptSelectFunctionAgent.ts +318 -318
  18. package/src/functional/createHttpLlmApplication.ts +63 -63
  19. package/src/index.ts +19 -19
  20. package/src/internal/AgenticaConstant.ts +4 -4
  21. package/src/internal/AgenticaDefaultPrompt.ts +39 -39
  22. package/src/internal/AgenticaOperationComposer.ts +82 -82
  23. package/src/internal/AgenticaPromptFactory.ts +30 -30
  24. package/src/internal/AgenticaPromptTransformer.ts +83 -83
  25. package/src/internal/AgenticaTokenUsageAggregator.ts +115 -115
  26. package/src/internal/MathUtil.ts +3 -3
  27. package/src/internal/Singleton.ts +22 -22
  28. package/src/internal/__map_take.ts +15 -15
  29. package/src/structures/IAgenticaConfig.ts +121 -121
  30. package/src/structures/IAgenticaContext.ts +128 -128
  31. package/src/structures/IAgenticaController.ts +130 -130
  32. package/src/structures/IAgenticaEvent.ts +224 -224
  33. package/src/structures/IAgenticaExecutor.ts +152 -152
  34. package/src/structures/IAgenticaOperation.ts +64 -64
  35. package/src/structures/IAgenticaOperationCollection.ts +50 -50
  36. package/src/structures/IAgenticaOperationSelection.ts +69 -69
  37. package/src/structures/IAgenticaPrompt.ts +173 -173
  38. package/src/structures/IAgenticaProps.ts +64 -64
  39. package/src/structures/IAgenticaProvider.ts +45 -45
  40. package/src/structures/IAgenticaSystemPrompt.ts +122 -122
  41. package/src/structures/IAgenticaTokenUsage.ts +107 -107
  42. package/src/structures/internal/__IChatCancelFunctionsApplication.ts +23 -23
  43. package/src/structures/internal/__IChatFunctionReference.ts +21 -21
  44. package/src/structures/internal/__IChatInitialApplication.ts +15 -15
  45. package/src/structures/internal/__IChatSelectFunctionsApplication.ts +24 -24
  46. package/src/typings/AgenticaSource.ts +6 -6
@@ -1,152 +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
- }
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
+ }
@@ -1,64 +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
- }
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
+ }
@@ -1,50 +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
- }
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
+ }