@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.
- package/LICENSE +21 -0
- package/README.md +464 -0
- package/lib/Agentica.d.ts +124 -0
- package/lib/Agentica.js +271 -0
- package/lib/Agentica.js.map +1 -0
- package/lib/chatgpt/ChatGptAgent.d.ts +6 -0
- package/lib/chatgpt/ChatGptAgent.js +59 -0
- package/lib/chatgpt/ChatGptAgent.js.map +1 -0
- package/lib/chatgpt/ChatGptCallFunctionAgent.d.ts +5 -0
- package/lib/chatgpt/ChatGptCallFunctionAgent.js +362 -0
- package/lib/chatgpt/ChatGptCallFunctionAgent.js.map +1 -0
- package/lib/chatgpt/ChatGptCancelFunctionAgent.d.ts +8 -0
- package/lib/chatgpt/ChatGptCancelFunctionAgent.js +359 -0
- package/lib/chatgpt/ChatGptCancelFunctionAgent.js.map +1 -0
- package/lib/chatgpt/ChatGptDescribeFunctionAgent.d.ts +5 -0
- package/lib/chatgpt/ChatGptDescribeFunctionAgent.js +56 -0
- package/lib/chatgpt/ChatGptDescribeFunctionAgent.js.map +1 -0
- package/lib/chatgpt/ChatGptHistoryDecoder.d.ts +5 -0
- package/lib/chatgpt/ChatGptHistoryDecoder.js +77 -0
- package/lib/chatgpt/ChatGptHistoryDecoder.js.map +1 -0
- package/lib/chatgpt/ChatGptInitializeFunctionAgent.d.ts +5 -0
- package/lib/chatgpt/ChatGptInitializeFunctionAgent.js +1883 -0
- package/lib/chatgpt/ChatGptInitializeFunctionAgent.js.map +1 -0
- package/lib/chatgpt/ChatGptSelectFunctionAgent.d.ts +5 -0
- package/lib/chatgpt/ChatGptSelectFunctionAgent.js +381 -0
- package/lib/chatgpt/ChatGptSelectFunctionAgent.js.map +1 -0
- package/lib/functional/createHttpLlmApplication.d.ts +33 -0
- package/lib/functional/createHttpLlmApplication.js +7766 -0
- package/lib/functional/createHttpLlmApplication.js.map +1 -0
- package/lib/index.d.ts +16 -0
- package/lib/index.js +35 -0
- package/lib/index.js.map +1 -0
- package/lib/index.mjs +10366 -0
- package/lib/index.mjs.map +1 -0
- package/lib/internal/AgenticaConstant.d.ts +4 -0
- package/lib/internal/AgenticaConstant.js +9 -0
- package/lib/internal/AgenticaConstant.js.map +1 -0
- package/lib/internal/AgenticaCostAggregator.d.ts +5 -0
- package/lib/internal/AgenticaCostAggregator.js +30 -0
- package/lib/internal/AgenticaCostAggregator.js.map +1 -0
- package/lib/internal/AgenticaDefaultPrompt.d.ts +4 -0
- package/lib/internal/AgenticaDefaultPrompt.js +32 -0
- package/lib/internal/AgenticaDefaultPrompt.js.map +1 -0
- package/lib/internal/AgenticaOperationComposer.d.ts +9 -0
- package/lib/internal/AgenticaOperationComposer.js +58 -0
- package/lib/internal/AgenticaOperationComposer.js.map +1 -0
- package/lib/internal/AgenticaPromptFactory.d.ts +6 -0
- package/lib/internal/AgenticaPromptFactory.js +9 -0
- package/lib/internal/AgenticaPromptFactory.js.map +1 -0
- package/lib/internal/AgenticaPromptTransformer.d.ts +9 -0
- package/lib/internal/AgenticaPromptTransformer.js +58 -0
- package/lib/internal/AgenticaPromptTransformer.js.map +1 -0
- package/lib/internal/AgenticaSystemPrompt.d.ts +8 -0
- package/lib/internal/AgenticaSystemPrompt.js +13 -0
- package/lib/internal/AgenticaSystemPrompt.js.map +1 -0
- package/lib/internal/MathUtil.d.ts +3 -0
- package/lib/internal/MathUtil.js +8 -0
- package/lib/internal/MathUtil.js.map +1 -0
- package/lib/internal/Singleton.d.ts +1 -0
- package/lib/internal/Singleton.js +23 -0
- package/lib/internal/Singleton.js.map +1 -0
- package/lib/internal/__map_take.d.ts +1 -0
- package/lib/internal/__map_take.js +16 -0
- package/lib/internal/__map_take.js.map +1 -0
- package/lib/structures/IAgenticaConfig.d.ts +112 -0
- package/lib/structures/IAgenticaConfig.js +3 -0
- package/lib/structures/IAgenticaConfig.js.map +1 -0
- package/lib/structures/IAgenticaContext.d.ts +106 -0
- package/lib/structures/IAgenticaContext.js +3 -0
- package/lib/structures/IAgenticaContext.js.map +1 -0
- package/lib/structures/IAgenticaController.d.ts +110 -0
- package/lib/structures/IAgenticaController.js +3 -0
- package/lib/structures/IAgenticaController.js.map +1 -0
- package/lib/structures/IAgenticaEvent.d.ts +191 -0
- package/lib/structures/IAgenticaEvent.js +3 -0
- package/lib/structures/IAgenticaEvent.js.map +1 -0
- package/lib/structures/IAgenticaExecutor.d.ts +144 -0
- package/lib/structures/IAgenticaExecutor.js +3 -0
- package/lib/structures/IAgenticaExecutor.js.map +1 -0
- package/lib/structures/IAgenticaOperation.d.ts +48 -0
- package/lib/structures/IAgenticaOperation.js +3 -0
- package/lib/structures/IAgenticaOperation.js.map +1 -0
- package/lib/structures/IAgenticaOperationCollection.d.ts +46 -0
- package/lib/structures/IAgenticaOperationCollection.js +3 -0
- package/lib/structures/IAgenticaOperationCollection.js.map +1 -0
- package/lib/structures/IAgenticaOperationSelection.d.ts +51 -0
- package/lib/structures/IAgenticaOperationSelection.js +3 -0
- package/lib/structures/IAgenticaOperationSelection.js.map +1 -0
- package/lib/structures/IAgenticaPrompt.d.ts +139 -0
- package/lib/structures/IAgenticaPrompt.js +3 -0
- package/lib/structures/IAgenticaPrompt.js.map +1 -0
- package/lib/structures/IAgenticaProps.d.ts +59 -0
- package/lib/structures/IAgenticaProps.js +3 -0
- package/lib/structures/IAgenticaProps.js.map +1 -0
- package/lib/structures/IAgenticaProvider.d.ts +41 -0
- package/lib/structures/IAgenticaProvider.js +3 -0
- package/lib/structures/IAgenticaProvider.js.map +1 -0
- package/lib/structures/IAgenticaSystemPrompt.d.ts +116 -0
- package/lib/structures/IAgenticaSystemPrompt.js +3 -0
- package/lib/structures/IAgenticaSystemPrompt.js.map +1 -0
- package/lib/structures/IAgenticaTokenUsage.d.ts +50 -0
- package/lib/structures/IAgenticaTokenUsage.js +3 -0
- package/lib/structures/IAgenticaTokenUsage.js.map +1 -0
- package/lib/structures/internal/__IChatCancelFunctionsApplication.d.ts +22 -0
- package/lib/structures/internal/__IChatCancelFunctionsApplication.js +3 -0
- package/lib/structures/internal/__IChatCancelFunctionsApplication.js.map +1 -0
- package/lib/structures/internal/__IChatFunctionReference.d.ts +20 -0
- package/lib/structures/internal/__IChatFunctionReference.js +3 -0
- package/lib/structures/internal/__IChatFunctionReference.js.map +1 -0
- package/lib/structures/internal/__IChatInitialApplication.d.ts +14 -0
- package/lib/structures/internal/__IChatInitialApplication.js +3 -0
- package/lib/structures/internal/__IChatInitialApplication.js.map +1 -0
- package/lib/structures/internal/__IChatSelectFunctionsApplication.d.ts +23 -0
- package/lib/structures/internal/__IChatSelectFunctionsApplication.js +3 -0
- package/lib/structures/internal/__IChatSelectFunctionsApplication.js.map +1 -0
- package/lib/typings/AgenticaSource.d.ts +1 -0
- package/lib/typings/AgenticaSource.js +3 -0
- package/lib/typings/AgenticaSource.js.map +1 -0
- package/package.json +74 -0
- package/prompts/cancel.md +5 -0
- package/prompts/common.md +3 -0
- package/prompts/describe.md +7 -0
- package/prompts/execute.md +7 -0
- package/prompts/initialize.md +3 -0
- package/prompts/select.md +7 -0
- package/src/Agentica.ts +322 -0
- package/src/chatgpt/ChatGptAgent.ts +71 -0
- package/src/chatgpt/ChatGptCallFunctionAgent.ts +445 -0
- package/src/chatgpt/ChatGptCancelFunctionAgent.ts +283 -0
- package/src/chatgpt/ChatGptDescribeFunctionAgent.ts +51 -0
- package/src/chatgpt/ChatGptHistoryDecoder.ts +86 -0
- package/src/chatgpt/ChatGptInitializeFunctionAgent.ts +88 -0
- package/src/chatgpt/ChatGptSelectFunctionAgent.ts +316 -0
- package/src/functional/createHttpLlmApplication.ts +63 -0
- package/src/index.ts +19 -0
- package/src/internal/AgenticaConstant.ts +4 -0
- package/src/internal/AgenticaCostAggregator.ts +35 -0
- package/src/internal/AgenticaDefaultPrompt.ts +39 -0
- package/src/internal/AgenticaOperationComposer.ts +82 -0
- package/src/internal/AgenticaPromptFactory.ts +30 -0
- package/src/internal/AgenticaPromptTransformer.ts +83 -0
- package/src/internal/AgenticaSystemPrompt.ts +14 -0
- package/src/internal/MathUtil.ts +3 -0
- package/src/internal/Singleton.ts +22 -0
- package/src/internal/__map_take.ts +15 -0
- package/src/structures/IAgenticaConfig.ts +121 -0
- package/src/structures/IAgenticaContext.ts +128 -0
- package/src/structures/IAgenticaController.ts +130 -0
- package/src/structures/IAgenticaEvent.ts +224 -0
- package/src/structures/IAgenticaExecutor.ts +152 -0
- package/src/structures/IAgenticaOperation.ts +64 -0
- package/src/structures/IAgenticaOperationCollection.ts +50 -0
- package/src/structures/IAgenticaOperationSelection.ts +69 -0
- package/src/structures/IAgenticaPrompt.ts +173 -0
- package/src/structures/IAgenticaProps.ts +64 -0
- package/src/structures/IAgenticaProvider.ts +45 -0
- package/src/structures/IAgenticaSystemPrompt.ts +122 -0
- package/src/structures/IAgenticaTokenUsage.ts +52 -0
- package/src/structures/internal/__IChatCancelFunctionsApplication.ts +23 -0
- package/src/structures/internal/__IChatFunctionReference.ts +21 -0
- package/src/structures/internal/__IChatInitialApplication.ts +15 -0
- package/src/structures/internal/__IChatSelectFunctionsApplication.ts +24 -0
- package/src/typings/AgenticaSource.ts +6 -0
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import OpenAI from "openai";
|
|
2
|
+
import { AgenticaSource } from "../typings/AgenticaSource";
|
|
3
|
+
import { IAgenticaConfig } from "./IAgenticaConfig";
|
|
4
|
+
import { IAgenticaEvent } from "./IAgenticaEvent";
|
|
5
|
+
import { IAgenticaOperationCollection } from "./IAgenticaOperationCollection";
|
|
6
|
+
import { IAgenticaOperationSelection } from "./IAgenticaOperationSelection";
|
|
7
|
+
import { IAgenticaPrompt } from "./IAgenticaPrompt";
|
|
8
|
+
/**
|
|
9
|
+
* Context of the Nestia A.I. agent.
|
|
10
|
+
*
|
|
11
|
+
* `IAgenticaContext` is a structure defining the context of the
|
|
12
|
+
* internal agents composing the {@link Agentica}, like function
|
|
13
|
+
* selector, executor, and describer, and so on. For example, if an
|
|
14
|
+
* agent has been configured to utilize the OpenAI, the context will
|
|
15
|
+
* be delivered to the below components.
|
|
16
|
+
*
|
|
17
|
+
* - {@link ChatGptAgent}
|
|
18
|
+
* - {@link ChatGptInitializeFunctionAgent}
|
|
19
|
+
* - {@link ChatGptSelectFunctionAgent}
|
|
20
|
+
* - {@link ChatGptExecuteFunctionAgent}
|
|
21
|
+
* - {@link ChatGptDescribeFunctionAgent}
|
|
22
|
+
* - {@link ChatGptCancelFunctionAgent}
|
|
23
|
+
*
|
|
24
|
+
* Also, as its name is context, it contains every information that
|
|
25
|
+
* is required to interact with the AI provider like OpenAI. It
|
|
26
|
+
* contains every operations for LLM function calling, and
|
|
27
|
+
* configuration used for the agent construction. And it contains
|
|
28
|
+
* the prompt histories, and facade controller functions for
|
|
29
|
+
* interacting with the {@link Agentica} like {@link dispatch}.
|
|
30
|
+
*
|
|
31
|
+
* In such reasons, if you're planning to customize some internal
|
|
32
|
+
* agents, or add new agents with new process routine, you have to
|
|
33
|
+
* understand this context structure. Otherwise you don't have any
|
|
34
|
+
* plan to customize the internal agents, this context information is
|
|
35
|
+
* not important for you.
|
|
36
|
+
*
|
|
37
|
+
* @author Samchon
|
|
38
|
+
*/
|
|
39
|
+
export interface IAgenticaContext {
|
|
40
|
+
/**
|
|
41
|
+
* Collection of operations.
|
|
42
|
+
*
|
|
43
|
+
* Collection of operations from every controllers, and their
|
|
44
|
+
* groups composed by the divide and conquer rule for the
|
|
45
|
+
* efficient operation selection if configured.
|
|
46
|
+
*/
|
|
47
|
+
operations: IAgenticaOperationCollection;
|
|
48
|
+
/**
|
|
49
|
+
* Configuration of the agent.
|
|
50
|
+
*
|
|
51
|
+
* Configuration of the agent, that is used when constructing the
|
|
52
|
+
* {@link Agentica} instance.
|
|
53
|
+
*
|
|
54
|
+
* @todo Write detaily after supporting the agent customization feature
|
|
55
|
+
*/
|
|
56
|
+
config: IAgenticaConfig | undefined;
|
|
57
|
+
/**
|
|
58
|
+
* Prompt histories.
|
|
59
|
+
*/
|
|
60
|
+
histories: IAgenticaPrompt[];
|
|
61
|
+
/**
|
|
62
|
+
* Stacked operations.
|
|
63
|
+
*
|
|
64
|
+
* In other words, list of candidate operations for the LLM function calling.
|
|
65
|
+
*/
|
|
66
|
+
stack: IAgenticaOperationSelection[];
|
|
67
|
+
/**
|
|
68
|
+
* Text prompt of the user.
|
|
69
|
+
*
|
|
70
|
+
* Text conversation written the by user through the
|
|
71
|
+
* {@link Agentica.conversate} function.
|
|
72
|
+
*/
|
|
73
|
+
prompt: IAgenticaPrompt.IText<"user">;
|
|
74
|
+
/**
|
|
75
|
+
* Whether the agent is ready.
|
|
76
|
+
*
|
|
77
|
+
* Returns a boolean value indicates whether the agent is ready to
|
|
78
|
+
* perform the function calling.
|
|
79
|
+
*
|
|
80
|
+
* If the agent has called the {@link IAgenticaContext.initialize},
|
|
81
|
+
* it returns `true`. Otherwise the {@link initialize} has never been
|
|
82
|
+
* called, returns `false`.
|
|
83
|
+
*/
|
|
84
|
+
ready: () => boolean;
|
|
85
|
+
/**
|
|
86
|
+
* Dispatch event.
|
|
87
|
+
*
|
|
88
|
+
* Dispatch event so that the agent can be handle the event
|
|
89
|
+
* through the {@link Agentica.on} function.
|
|
90
|
+
*
|
|
91
|
+
* @param event Event to deliver
|
|
92
|
+
*/
|
|
93
|
+
dispatch: (event: IAgenticaEvent) => Promise<void>;
|
|
94
|
+
/**
|
|
95
|
+
* Request to the OpenAI server.
|
|
96
|
+
*
|
|
97
|
+
* @param source The source agent of the agent
|
|
98
|
+
* @param body The request body to the OpenAI server
|
|
99
|
+
* @returns Response from the OpenAI server
|
|
100
|
+
*/
|
|
101
|
+
request: (source: AgenticaSource, body: Omit<OpenAI.ChatCompletionCreateParamsNonStreaming, "model">) => Promise<OpenAI.ChatCompletion>;
|
|
102
|
+
/**
|
|
103
|
+
* Initialize the agent.
|
|
104
|
+
*/
|
|
105
|
+
initialize: () => Promise<void>;
|
|
106
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IAgenticaContext.js","sourceRoot":"","sources":["../../src/structures/IAgenticaContext.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { IHttpConnection, IHttpLlmApplication, IHttpLlmFunction, IHttpResponse } from "@samchon/openapi";
|
|
2
|
+
import { ILlmApplicationOfValidate, ILlmFunctionOfValidate } from "typia";
|
|
3
|
+
/**
|
|
4
|
+
* Controller of the Nestia Agent.
|
|
5
|
+
*
|
|
6
|
+
* `IAgenticaController` is a type represents a controller of the
|
|
7
|
+
* {@link Agentica}, which serves a set of functions to be called
|
|
8
|
+
* by A.I. chatbot from LLM function calling.
|
|
9
|
+
*
|
|
10
|
+
* Also, `IAgenticaController` is an union type which can specify
|
|
11
|
+
* a subtype by checking the {@link protocol} property.
|
|
12
|
+
*
|
|
13
|
+
* - HTTP server: {@link IAgenticaController..IHttp}
|
|
14
|
+
* - TypeScript class: {@link IAgenticaController.IClass}
|
|
15
|
+
*
|
|
16
|
+
* @author Samchon
|
|
17
|
+
*/
|
|
18
|
+
export type IAgenticaController = IAgenticaController.IHttp | IAgenticaController.IClass;
|
|
19
|
+
export declare namespace IAgenticaController {
|
|
20
|
+
/**
|
|
21
|
+
* HTTP controller.
|
|
22
|
+
*
|
|
23
|
+
* You can make it by {@link createHttpLlmApplication} function with
|
|
24
|
+
* the Swagger or OpenAPI document.
|
|
25
|
+
*/
|
|
26
|
+
export interface IHttp extends IBase<"http", IHttpLlmApplication<"chatgpt">> {
|
|
27
|
+
/**
|
|
28
|
+
* Connection to the server.
|
|
29
|
+
*
|
|
30
|
+
* Connection to the API server including the URL and headers.
|
|
31
|
+
*/
|
|
32
|
+
connection: IHttpConnection;
|
|
33
|
+
/**
|
|
34
|
+
* Executor of the API function.
|
|
35
|
+
*
|
|
36
|
+
* @param props Properties of the API function call
|
|
37
|
+
* @returns HTTP response of the API function call
|
|
38
|
+
*/
|
|
39
|
+
execute?: (props: {
|
|
40
|
+
/**
|
|
41
|
+
* Connection to the server.
|
|
42
|
+
*/
|
|
43
|
+
connection: IHttpConnection;
|
|
44
|
+
/**
|
|
45
|
+
* Application schema.
|
|
46
|
+
*/
|
|
47
|
+
application: IHttpLlmApplication<"chatgpt">;
|
|
48
|
+
/**
|
|
49
|
+
* Function schema.
|
|
50
|
+
*/
|
|
51
|
+
function: IHttpLlmFunction<"chatgpt">;
|
|
52
|
+
/**
|
|
53
|
+
* Arguments of the function calling.
|
|
54
|
+
*
|
|
55
|
+
* It is an object of key-value pairs of the API function's parameters.
|
|
56
|
+
* The property keys are composed by below rules:
|
|
57
|
+
*
|
|
58
|
+
* - parameter names
|
|
59
|
+
* - query parameter as an object type if exists
|
|
60
|
+
* - body parameter if exists
|
|
61
|
+
*/
|
|
62
|
+
arguments: object;
|
|
63
|
+
}) => Promise<IHttpResponse>;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* TypeScript class controller.
|
|
67
|
+
*
|
|
68
|
+
* You can make it by `typia.llm.application<App, Model>()` function.
|
|
69
|
+
*
|
|
70
|
+
* - https://typia.io/docs/llm/application
|
|
71
|
+
*/
|
|
72
|
+
export interface IClass extends IBase<"class", ILlmApplicationOfValidate<"chatgpt">> {
|
|
73
|
+
/**
|
|
74
|
+
* Executor of the class function.
|
|
75
|
+
*
|
|
76
|
+
* Executor of the class function, by target class instance
|
|
77
|
+
* or callback function with given schema and arguments
|
|
78
|
+
* information.
|
|
79
|
+
*/
|
|
80
|
+
execute: object | ((props: {
|
|
81
|
+
/**
|
|
82
|
+
* Target application schema.
|
|
83
|
+
*/
|
|
84
|
+
application: ILlmApplicationOfValidate<"chatgpt">;
|
|
85
|
+
/**
|
|
86
|
+
* Target function schema.
|
|
87
|
+
*/
|
|
88
|
+
function: ILlmFunctionOfValidate<"chatgpt">;
|
|
89
|
+
/**
|
|
90
|
+
* Arguments of the function calling.
|
|
91
|
+
*/
|
|
92
|
+
arguments: object;
|
|
93
|
+
}) => Promise<unknown>);
|
|
94
|
+
}
|
|
95
|
+
interface IBase<Protocol, Application> {
|
|
96
|
+
/**
|
|
97
|
+
* Protocol discrminator.
|
|
98
|
+
*/
|
|
99
|
+
protocol: Protocol;
|
|
100
|
+
/**
|
|
101
|
+
* Name of the controller.
|
|
102
|
+
*/
|
|
103
|
+
name: string;
|
|
104
|
+
/**
|
|
105
|
+
* Application schema of function calling.
|
|
106
|
+
*/
|
|
107
|
+
application: Application;
|
|
108
|
+
}
|
|
109
|
+
export {};
|
|
110
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IAgenticaController.js","sourceRoot":"","sources":["../../src/structures/IAgenticaController.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
import OpenAI from "openai";
|
|
2
|
+
import { AgenticaSource } from "../typings/AgenticaSource";
|
|
3
|
+
import { IAgenticaOperation } from "./IAgenticaOperation";
|
|
4
|
+
import { IAgenticaPrompt } from "./IAgenticaPrompt";
|
|
5
|
+
/**
|
|
6
|
+
* Nestia A.I. chatbot event.
|
|
7
|
+
*
|
|
8
|
+
* `IAgenticaEvent` is an union type of all possible events that can
|
|
9
|
+
* be emitted by the A.I. chatbot of the {@link Agentica} class. You
|
|
10
|
+
* can discriminate the subtype by checking the {@link type} property.
|
|
11
|
+
*
|
|
12
|
+
* @author Samchon
|
|
13
|
+
*/
|
|
14
|
+
export type IAgenticaEvent = IAgenticaEvent.IInitialize | IAgenticaEvent.ISelect | IAgenticaEvent.ICancel | IAgenticaEvent.ICall | IAgenticaEvent.IExecute | IAgenticaEvent.IDescribe | IAgenticaEvent.IText | IAgenticaEvent.IRequest | IAgenticaEvent.IResponse;
|
|
15
|
+
export declare namespace IAgenticaEvent {
|
|
16
|
+
export type Type = IAgenticaEvent["type"];
|
|
17
|
+
export type Mapper = {
|
|
18
|
+
initialize: IInitialize;
|
|
19
|
+
select: ISelect;
|
|
20
|
+
cancel: ICancel;
|
|
21
|
+
call: ICall;
|
|
22
|
+
execute: IExecute;
|
|
23
|
+
describe: IDescribe;
|
|
24
|
+
text: IText;
|
|
25
|
+
request: IRequest;
|
|
26
|
+
response: IResponse;
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Event of initializing the chatbot.
|
|
30
|
+
*/
|
|
31
|
+
export interface IInitialize extends IBase<"initialize"> {
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Event of selecting a function to call.
|
|
35
|
+
*/
|
|
36
|
+
export interface ISelect extends IBase<"select"> {
|
|
37
|
+
/**
|
|
38
|
+
* Selected operation.
|
|
39
|
+
*
|
|
40
|
+
* Operation that has been selected to prepare LLM function calling.
|
|
41
|
+
*/
|
|
42
|
+
operation: IAgenticaOperation;
|
|
43
|
+
/**
|
|
44
|
+
* Reason of selecting the function.
|
|
45
|
+
*
|
|
46
|
+
* The A.I. chatbot will fill this property describing why the function
|
|
47
|
+
* has been selected.
|
|
48
|
+
*/
|
|
49
|
+
reason: string;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Event of canceling a function calling.
|
|
53
|
+
*/
|
|
54
|
+
export interface ICancel extends IBase<"cancel"> {
|
|
55
|
+
/**
|
|
56
|
+
* Selected operation to cancel.
|
|
57
|
+
*
|
|
58
|
+
* Operation that has been selected to prepare LLM function calling,
|
|
59
|
+
* but canceled due to no more required.
|
|
60
|
+
*/
|
|
61
|
+
operation: IAgenticaOperation;
|
|
62
|
+
/**
|
|
63
|
+
* Reason of selecting the function.
|
|
64
|
+
*
|
|
65
|
+
* The A.I. chatbot will fill this property describing why the function
|
|
66
|
+
* has been cancelled.
|
|
67
|
+
*
|
|
68
|
+
* For reference, if the A.I. chatbot successfully completes the LLM
|
|
69
|
+
* function calling, the reason of the function cancellation will be
|
|
70
|
+
* "complete".
|
|
71
|
+
*/
|
|
72
|
+
reason: string;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Event of calling a function.
|
|
76
|
+
*/
|
|
77
|
+
export interface ICall extends IBase<"call"> {
|
|
78
|
+
/**
|
|
79
|
+
* ID of the tool calling.
|
|
80
|
+
*/
|
|
81
|
+
id: string;
|
|
82
|
+
/**
|
|
83
|
+
* Target operation to call.
|
|
84
|
+
*/
|
|
85
|
+
operation: IAgenticaOperation;
|
|
86
|
+
/**
|
|
87
|
+
* Arguments of the function calling.
|
|
88
|
+
*
|
|
89
|
+
* If you modify this {@link arguments} property, it actually modifies
|
|
90
|
+
* the backend server's request. Therefore, be careful when you're
|
|
91
|
+
* trying to modify this property.
|
|
92
|
+
*/
|
|
93
|
+
arguments: object;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Event of function calling execution.
|
|
97
|
+
*/
|
|
98
|
+
export interface IExecute extends IBase<"execute"> {
|
|
99
|
+
/**
|
|
100
|
+
* ID of the tool calling.
|
|
101
|
+
*/
|
|
102
|
+
id: string;
|
|
103
|
+
/**
|
|
104
|
+
* Target operation had called.
|
|
105
|
+
*/
|
|
106
|
+
operation: IAgenticaOperation;
|
|
107
|
+
/**
|
|
108
|
+
* Arguments of the function calling.
|
|
109
|
+
*/
|
|
110
|
+
arguments: object;
|
|
111
|
+
/**
|
|
112
|
+
* Return value.
|
|
113
|
+
*/
|
|
114
|
+
value: any;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Event of description.
|
|
118
|
+
*
|
|
119
|
+
* Event describing return values of LLM function callings.
|
|
120
|
+
*/
|
|
121
|
+
export interface IDescribe extends IBase<"describe"> {
|
|
122
|
+
/**
|
|
123
|
+
* Executions of the LLM function calling.
|
|
124
|
+
*
|
|
125
|
+
* This prompt describes the return value of them.
|
|
126
|
+
*/
|
|
127
|
+
executions: IAgenticaPrompt.IExecute[];
|
|
128
|
+
/**
|
|
129
|
+
* Description text.
|
|
130
|
+
*/
|
|
131
|
+
text: string;
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Event of text message.
|
|
135
|
+
*/
|
|
136
|
+
export interface IText extends IBase<"text"> {
|
|
137
|
+
/**
|
|
138
|
+
* Role of the orator.
|
|
139
|
+
*/
|
|
140
|
+
role: "assistant" | "user";
|
|
141
|
+
/**
|
|
142
|
+
* The text content.
|
|
143
|
+
*/
|
|
144
|
+
text: string;
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Request event of LLM provider API.
|
|
148
|
+
*/
|
|
149
|
+
export interface IRequest extends IBase<"request"> {
|
|
150
|
+
/**
|
|
151
|
+
* The source agent of the request.
|
|
152
|
+
*/
|
|
153
|
+
source: AgenticaSource;
|
|
154
|
+
/**
|
|
155
|
+
* Request body.
|
|
156
|
+
*/
|
|
157
|
+
body: OpenAI.ChatCompletionCreateParamsNonStreaming;
|
|
158
|
+
/**
|
|
159
|
+
* Options for the request.
|
|
160
|
+
*/
|
|
161
|
+
options?: OpenAI.RequestOptions | undefined;
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Response event of LLM provider API.
|
|
165
|
+
*/
|
|
166
|
+
export interface IResponse extends IBase<"response"> {
|
|
167
|
+
/**
|
|
168
|
+
* The source agent of the response.
|
|
169
|
+
*/
|
|
170
|
+
source: AgenticaSource;
|
|
171
|
+
/**
|
|
172
|
+
* Request body.
|
|
173
|
+
*/
|
|
174
|
+
body: OpenAI.ChatCompletionCreateParamsNonStreaming;
|
|
175
|
+
/**
|
|
176
|
+
* Options for the request.
|
|
177
|
+
*/
|
|
178
|
+
options?: OpenAI.RequestOptions | undefined;
|
|
179
|
+
/**
|
|
180
|
+
* Return value from the LLM provider API.
|
|
181
|
+
*/
|
|
182
|
+
value: OpenAI.ChatCompletion;
|
|
183
|
+
}
|
|
184
|
+
interface IBase<Type extends string> {
|
|
185
|
+
/**
|
|
186
|
+
* Discriminator type.
|
|
187
|
+
*/
|
|
188
|
+
type: Type;
|
|
189
|
+
}
|
|
190
|
+
export {};
|
|
191
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IAgenticaEvent.js","sourceRoot":"","sources":["../../src/structures/IAgenticaEvent.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { IAgenticaContext } from "./IAgenticaContext";
|
|
2
|
+
import { IAgenticaPrompt } from "./IAgenticaPrompt";
|
|
3
|
+
/**
|
|
4
|
+
* Executor of the Agentic AI.
|
|
5
|
+
*
|
|
6
|
+
* `IAgenticaExecutor` represents an executor of the {@link Agentica},
|
|
7
|
+
* composing its internal agents to accomplish the Agentic AI through
|
|
8
|
+
* the LLM (Large Language Model) function calling.
|
|
9
|
+
*
|
|
10
|
+
* You can customize one of these internal agents by configuring
|
|
11
|
+
* properties of the `IAgenticaExecutor` type, and assigning it to the
|
|
12
|
+
* {@link IAgenticaConfig.executor} property. If you set the
|
|
13
|
+
* {@link initialize} as `null` value, the {@link Agentica} will skip
|
|
14
|
+
* the initialize process and directly go to the {@link select} process.
|
|
15
|
+
*
|
|
16
|
+
* By the way, when customizing the executor member, it would better to
|
|
17
|
+
* reference the guide documents of `@agentica/core`, and internal
|
|
18
|
+
* agents' implementation code. It's because if you take some mistake on
|
|
19
|
+
* the executor logic, it can entirely break the {@link Agentica}'s
|
|
20
|
+
* operation.
|
|
21
|
+
*
|
|
22
|
+
* @reference https://github.com/wrtnlabs/agentica?tab=readme-ov-file#principles
|
|
23
|
+
* @reference https://github.com/wrtnlabs/agentica/blob/main/packages/agent/src/chatgpt/ChatGptAgent.ts
|
|
24
|
+
* @author Samchon
|
|
25
|
+
*/
|
|
26
|
+
export interface IAgenticaExecutor {
|
|
27
|
+
/**
|
|
28
|
+
* Initializer agent listing up functions.
|
|
29
|
+
*
|
|
30
|
+
* `initialize` agent is the first agent that {@link Agentica}
|
|
31
|
+
* would meet which judges whether the user's conversation implies
|
|
32
|
+
* to call some function or not.
|
|
33
|
+
*
|
|
34
|
+
* And if the `initialize` agent judges the user's conversation
|
|
35
|
+
* implies to call some function, the `initialize` agent will
|
|
36
|
+
* call the {@link IAgenticaContext.initialize} function, and
|
|
37
|
+
* inform every functions enrolled in the {@link IAgenticaController}
|
|
38
|
+
* to the AI agent. And then, the `initialize` agent will not never
|
|
39
|
+
* be called again, and let {@link Agentica} to go to the next
|
|
40
|
+
* {@link select} agent.
|
|
41
|
+
*
|
|
42
|
+
* Otherwise the user's conversation does not imply the request of
|
|
43
|
+
* function calling, it would just work like plain chatbot, and just
|
|
44
|
+
* conversate with the user.
|
|
45
|
+
*
|
|
46
|
+
* By the way, if you wanna skip the `initialize` agent, you can
|
|
47
|
+
* do it by configuring the {@link IAgenticaConfig.executor} as
|
|
48
|
+
* `null` value. In that case, the `initialize` agent will never be
|
|
49
|
+
* called, and {@link Agentica} just starts from the {@link select}
|
|
50
|
+
* agent.
|
|
51
|
+
*
|
|
52
|
+
* @param ctx Context of the agent
|
|
53
|
+
* @returns List of prompts generated by the initializer
|
|
54
|
+
*/
|
|
55
|
+
initialize: null | ((ctx: IAgenticaContext) => Promise<IAgenticaPrompt[]>);
|
|
56
|
+
/**
|
|
57
|
+
* Function selector agent.
|
|
58
|
+
*
|
|
59
|
+
* `Select` agent finds candidate functions to call from the
|
|
60
|
+
* conversation context with the user. And the candidate functions
|
|
61
|
+
* would be enrolled to the {@link IAgenticaContext.stack}, and the
|
|
62
|
+
* next {@link call} agent will perform the LLM (Large Language Model)
|
|
63
|
+
* function calling.
|
|
64
|
+
*
|
|
65
|
+
* Note that, the `select` agent does not perform the LLM function
|
|
66
|
+
* calling. It ends with just finding the candidate functions to call.
|
|
67
|
+
*
|
|
68
|
+
* By the way, if the `select` agent can't specify a certain function
|
|
69
|
+
* to call due to lack of conversation context or homogeneity between
|
|
70
|
+
* heterogeneous functions, how `select` agent works? In that case,
|
|
71
|
+
* `select` agent it will just enroll every candidate functions to
|
|
72
|
+
* the stack, and let the next {@link call} agent to determine the
|
|
73
|
+
* proper function to call. And then let {@link cancel} agent to erase
|
|
74
|
+
* the other candidate functions from the stack.
|
|
75
|
+
*
|
|
76
|
+
* Additionally, if `select` agent could not find any candidate
|
|
77
|
+
* function from the conversation context with user, it would just
|
|
78
|
+
* act like plain chatbot conversating with the user.
|
|
79
|
+
*
|
|
80
|
+
* @param ctx Context of the agent
|
|
81
|
+
* @returns List of prompts generated by the selector
|
|
82
|
+
*/
|
|
83
|
+
select: (ctx: IAgenticaContext) => Promise<IAgenticaPrompt[]>;
|
|
84
|
+
/**
|
|
85
|
+
* Function caller agent.
|
|
86
|
+
*
|
|
87
|
+
* `Call` agent performs the LLM (Large Language Model) function
|
|
88
|
+
* calling from the candidate functions enrolled in the
|
|
89
|
+
* {@link IAgenticaContext.stack}. And the scope of function calling
|
|
90
|
+
* is, not only just arguments filling, but also actual executing
|
|
91
|
+
* the function and returning the result.
|
|
92
|
+
*
|
|
93
|
+
* By the way, conversation context with user can be not enough to
|
|
94
|
+
* filling the arguments of the candidate functions. In that case,
|
|
95
|
+
* the `call` agent will ask the user to fill the missing arguments.
|
|
96
|
+
*
|
|
97
|
+
* Otherwise the cpnversation context is enough, so that succeeded
|
|
98
|
+
* to call some candidate functions, the `call` agent will step to
|
|
99
|
+
* the {@link describe} agent to explain the result of the function
|
|
100
|
+
* calling to the user as markdown content.
|
|
101
|
+
*
|
|
102
|
+
* @param ctx Context of the agent
|
|
103
|
+
* @returns List of prompts generated by the caller
|
|
104
|
+
* @warning Recommend not to customize, due to its validation
|
|
105
|
+
* feedback strategy is working very well, and the `call`
|
|
106
|
+
* agent is the most general topic which can be universally
|
|
107
|
+
* applied to all domain fields.
|
|
108
|
+
*/
|
|
109
|
+
call: (ctx: IAgenticaContext) => Promise<IAgenticaPrompt[]>;
|
|
110
|
+
/**
|
|
111
|
+
* Describer agent of the function calling result.
|
|
112
|
+
*
|
|
113
|
+
* `Describe` agent explains the results of the function callings
|
|
114
|
+
* to the user as markdown content.
|
|
115
|
+
*
|
|
116
|
+
* @param ctx Context of the agent
|
|
117
|
+
* @param executes List of function calling results
|
|
118
|
+
* @returns List of prompts generated by the describer
|
|
119
|
+
*/
|
|
120
|
+
describe: (ctx: IAgenticaContext, executes: IAgenticaPrompt.IExecute[]) => Promise<IAgenticaPrompt[]>;
|
|
121
|
+
/**
|
|
122
|
+
* Function canceler agent.
|
|
123
|
+
*
|
|
124
|
+
* `Cancel` agent erases the candidate functions from the
|
|
125
|
+
* {@link IAgenticaContext.stack} by analyzing the conversation
|
|
126
|
+
* context with the user.
|
|
127
|
+
*
|
|
128
|
+
* For reference, the first reason of the cancelation is explicit
|
|
129
|
+
* order from user to the previous requested function. For example,
|
|
130
|
+
* user had requested to send an email to the agent, but suddenly
|
|
131
|
+
* user says to cancel the email sending.
|
|
132
|
+
*
|
|
133
|
+
* The seconod reason n of the cancelation is the multiple candidate
|
|
134
|
+
* functions had been selected at once by the {@link select} agent
|
|
135
|
+
* due to lack of conversation context or homogeneity between the
|
|
136
|
+
* heterogeneous functions. And in the multiple candidate functions,
|
|
137
|
+
* one thing is clearly determined by the {@link call} agent, so that
|
|
138
|
+
* drop the other candidate functions.
|
|
139
|
+
*
|
|
140
|
+
* @param ctx Context of the agent
|
|
141
|
+
* @returns List of prompts generated by the canceler
|
|
142
|
+
*/
|
|
143
|
+
cancel: (ctx: IAgenticaContext) => Promise<IAgenticaPrompt[]>;
|
|
144
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IAgenticaExecutor.js","sourceRoot":"","sources":["../../src/structures/IAgenticaExecutor.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { IHttpLlmFunction } from "@samchon/openapi";
|
|
2
|
+
import { ILlmFunctionOfValidate } from "typia";
|
|
3
|
+
import { IAgenticaController } from "./IAgenticaController";
|
|
4
|
+
/**
|
|
5
|
+
* Operation information in the Nestia Agent.
|
|
6
|
+
*
|
|
7
|
+
* `IAgenticaOperation` is a type represents an operation that would
|
|
8
|
+
* be selected by the A.I. chatbot of {@link Agentica} class to
|
|
9
|
+
* perform the LLM (Large Language Model) function calling.
|
|
10
|
+
*
|
|
11
|
+
* Also, it is an union type that is discriminated by the {@link protocol}
|
|
12
|
+
* property. If the protocol value is `http`, it means that the HTTP API
|
|
13
|
+
* operation would be called by the A.I. chatbot. Otherwise, if the protocol
|
|
14
|
+
* value is `class`, it means that the operation has come from a
|
|
15
|
+
* TypeScript class.
|
|
16
|
+
*
|
|
17
|
+
* @author Samchon
|
|
18
|
+
*/
|
|
19
|
+
export type IAgenticaOperation = IAgenticaOperation.IHttp | IAgenticaOperation.IClass;
|
|
20
|
+
export declare namespace IAgenticaOperation {
|
|
21
|
+
/**
|
|
22
|
+
* HTTP API operation.
|
|
23
|
+
*/
|
|
24
|
+
export type IHttp = IBase<"http", IAgenticaController.IHttp, IHttpLlmFunction<"chatgpt">>;
|
|
25
|
+
/**
|
|
26
|
+
* TypeScript class operation.
|
|
27
|
+
*/
|
|
28
|
+
export type IClass = IBase<"class", IAgenticaController.IClass, ILlmFunctionOfValidate<"chatgpt">>;
|
|
29
|
+
interface IBase<Protocol, Application, Function> {
|
|
30
|
+
/**
|
|
31
|
+
* Protocol discriminator.
|
|
32
|
+
*/
|
|
33
|
+
protocol: Protocol;
|
|
34
|
+
/**
|
|
35
|
+
* Belonged controller of the target function.
|
|
36
|
+
*/
|
|
37
|
+
controller: Application;
|
|
38
|
+
/**
|
|
39
|
+
* Target function to call.
|
|
40
|
+
*/
|
|
41
|
+
function: Function;
|
|
42
|
+
/**
|
|
43
|
+
* Identifier name.
|
|
44
|
+
*/
|
|
45
|
+
name: string;
|
|
46
|
+
}
|
|
47
|
+
export {};
|
|
48
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IAgenticaOperation.js","sourceRoot":"","sources":["../../src/structures/IAgenticaOperation.ts"],"names":[],"mappings":""}
|