@agentica/core 0.13.5 → 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.
- package/lib/Agentica.js +8 -10
- package/lib/Agentica.js.map +1 -1
- package/lib/context/AgenticaCancelPrompt.d.ts +4 -12
- package/lib/context/AgenticaCancelPrompt.js +0 -17
- package/lib/context/AgenticaCancelPrompt.js.map +1 -1
- package/lib/context/AgenticaOperationSelection.d.ts +4 -11
- package/lib/context/AgenticaOperationSelection.js +0 -14
- package/lib/context/AgenticaOperationSelection.js.map +1 -1
- package/lib/context/AgenticaTokenUsage.js.map +1 -1
- package/lib/context/internal/AgenticaTokenUsageAggregator.js.map +1 -1
- package/lib/events/AgenticaCallEvent.d.ts +23 -13
- package/lib/events/AgenticaCallEvent.js +0 -19
- package/lib/events/AgenticaCallEvent.js.map +1 -1
- package/lib/events/AgenticaCancelEvent.d.ts +4 -10
- package/lib/events/AgenticaCancelEvent.js +0 -15
- package/lib/events/AgenticaCancelEvent.js.map +1 -1
- package/lib/events/AgenticaDescribeEvent.d.ts +8 -27
- package/lib/events/AgenticaDescribeEvent.js +0 -52
- package/lib/events/AgenticaDescribeEvent.js.map +1 -1
- package/lib/events/AgenticaEvent.d.ts +13 -1
- package/lib/events/AgenticaEventBase.d.ts +5 -3
- package/lib/events/AgenticaEventBase.js +0 -7
- package/lib/events/AgenticaEventBase.js.map +1 -1
- package/lib/events/AgenticaExecuteEvent.d.ts +15 -15
- package/lib/events/AgenticaExecuteEvent.js +0 -30
- package/lib/events/AgenticaExecuteEvent.js.map +1 -1
- package/lib/events/AgenticaInitializeEvent.d.ts +3 -4
- package/lib/events/AgenticaInitializeEvent.js +0 -13
- package/lib/events/AgenticaInitializeEvent.js.map +1 -1
- package/lib/events/AgenticaRequestEvent.d.ts +5 -24
- package/lib/events/AgenticaRequestEvent.js +0 -19
- package/lib/events/AgenticaRequestEvent.js.map +1 -1
- package/lib/events/AgenticaResponseEvent.d.ts +22 -32
- package/lib/events/AgenticaResponseEvent.js +0 -13
- package/lib/events/AgenticaResponseEvent.js.map +1 -1
- package/lib/events/AgenticaSelectEvent.d.ts +6 -12
- package/lib/events/AgenticaSelectEvent.js +0 -23
- package/lib/events/AgenticaSelectEvent.js.map +1 -1
- package/lib/events/AgenticaTextEvent.d.ts +8 -27
- package/lib/events/AgenticaTextEvent.js +0 -52
- package/lib/events/AgenticaTextEvent.js.map +1 -1
- package/lib/events/AgenticaValidateEvent.d.ts +25 -0
- package/lib/events/AgenticaValidateEvent.js +3 -0
- package/lib/events/AgenticaValidateEvent.js.map +1 -0
- package/lib/factory/events.d.ts +65 -0
- package/lib/factory/events.js +173 -0
- package/lib/factory/events.js.map +1 -0
- package/lib/factory/index.d.ts +3 -0
- package/lib/factory/index.js +20 -0
- package/lib/factory/index.js.map +1 -0
- package/lib/factory/operations.d.ts +7 -0
- package/lib/factory/operations.js +14 -0
- package/lib/factory/operations.js.map +1 -0
- package/lib/factory/prompts.d.ts +30 -0
- package/lib/factory/prompts.js +76 -0
- package/lib/factory/prompts.js.map +1 -0
- package/lib/index.d.ts +2 -0
- package/lib/index.js +25 -4
- package/lib/index.js.map +1 -1
- package/lib/index.mjs +328 -347
- package/lib/index.mjs.map +1 -1
- package/lib/json/IAgenticaEventJson.d.ts +4 -2
- package/lib/json/IAgenticaPromptJson.d.ts +1 -1
- package/lib/orchestrate/ChatGptAgent.js.map +1 -0
- package/lib/{chatgpt → orchestrate}/ChatGptCallFunctionAgent.d.ts +2 -1
- package/lib/{chatgpt → orchestrate}/ChatGptCallFunctionAgent.js +33 -28
- package/lib/orchestrate/ChatGptCallFunctionAgent.js.map +1 -0
- package/lib/orchestrate/ChatGptCancelFunctionAgent.d.ts +12 -0
- package/lib/{chatgpt → orchestrate}/ChatGptCancelFunctionAgent.js +7 -9
- package/lib/orchestrate/ChatGptCancelFunctionAgent.js.map +1 -0
- package/lib/orchestrate/ChatGptCompletionMessageUtil.d.ts +14 -0
- package/lib/{chatgpt → orchestrate}/ChatGptCompletionMessageUtil.js +0 -5
- package/lib/orchestrate/ChatGptCompletionMessageUtil.js.map +1 -0
- package/lib/{chatgpt → orchestrate}/ChatGptDescribeFunctionAgent.d.ts +3 -2
- package/lib/{chatgpt → orchestrate}/ChatGptDescribeFunctionAgent.js +4 -5
- package/lib/orchestrate/ChatGptDescribeFunctionAgent.js.map +1 -0
- package/lib/{chatgpt → orchestrate}/ChatGptHistoryDecoder.d.ts +2 -1
- package/lib/{chatgpt → orchestrate}/ChatGptHistoryDecoder.js +0 -1
- package/lib/orchestrate/ChatGptHistoryDecoder.js.map +1 -0
- package/lib/{chatgpt → orchestrate}/ChatGptInitializeFunctionAgent.d.ts +2 -1
- package/lib/{chatgpt → orchestrate}/ChatGptInitializeFunctionAgent.js +4 -5
- package/lib/orchestrate/ChatGptInitializeFunctionAgent.js.map +1 -0
- package/lib/{chatgpt → orchestrate}/ChatGptSelectFunctionAgent.d.ts +1 -1
- package/lib/{chatgpt → orchestrate}/ChatGptSelectFunctionAgent.js +10 -13
- package/lib/orchestrate/ChatGptSelectFunctionAgent.js.map +1 -0
- package/lib/orchestrate/ChatGptUsageAggregator.d.ts +10 -0
- package/lib/{chatgpt → orchestrate}/ChatGptUsageAggregator.js +0 -3
- package/lib/orchestrate/ChatGptUsageAggregator.js.map +1 -0
- package/lib/orchestrate/index.d.ts +8 -0
- package/lib/orchestrate/index.js +25 -0
- package/lib/orchestrate/index.js.map +1 -0
- package/lib/prompts/AgenticaCancelPrompt.d.ts +4 -12
- package/lib/prompts/AgenticaCancelPrompt.js +0 -17
- package/lib/prompts/AgenticaCancelPrompt.js.map +1 -1
- package/lib/prompts/AgenticaDescribePrompt.d.ts +4 -12
- package/lib/prompts/AgenticaDescribePrompt.js +0 -17
- package/lib/prompts/AgenticaDescribePrompt.js.map +1 -1
- package/lib/prompts/AgenticaExecutePrompt.d.ts +42 -13
- package/lib/prompts/AgenticaExecutePrompt.js +0 -21
- package/lib/prompts/AgenticaExecutePrompt.js.map +1 -1
- package/lib/prompts/AgenticaPrompt.d.ts +10 -0
- package/lib/prompts/AgenticaPromptBase.d.ts +5 -6
- package/lib/prompts/AgenticaPromptBase.js +0 -19
- package/lib/prompts/AgenticaPromptBase.js.map +1 -1
- package/lib/prompts/AgenticaSelectPrompt.d.ts +4 -12
- package/lib/prompts/AgenticaSelectPrompt.js +0 -17
- package/lib/prompts/AgenticaSelectPrompt.js.map +1 -1
- package/lib/prompts/AgenticaTextPrompt.d.ts +4 -12
- package/lib/prompts/AgenticaTextPrompt.js +0 -17
- package/lib/prompts/AgenticaTextPrompt.js.map +1 -1
- package/lib/transformers/AgenticaEventTransformer.d.ts +16 -16
- package/lib/transformers/AgenticaEventTransformer.js +12 -30
- package/lib/transformers/AgenticaEventTransformer.js.map +1 -1
- package/lib/transformers/AgenticaPromptTransformer.d.ts +12 -11
- package/lib/transformers/AgenticaPromptTransformer.js +9 -19
- package/lib/transformers/AgenticaPromptTransformer.js.map +1 -1
- package/package.json +3 -3
- package/src/Agentica.ts +11 -11
- package/src/context/AgenticaCancelPrompt.ts +4 -25
- package/src/context/AgenticaContext.ts +0 -1
- package/src/context/AgenticaOperation.ts +0 -1
- package/src/context/AgenticaOperationCollection.ts +0 -1
- package/src/context/AgenticaOperationSelection.ts +4 -22
- package/src/context/AgenticaTokenUsage.ts +2 -2
- package/src/context/internal/AgenticaTokenUsageAggregator.ts +0 -1
- package/src/events/AgenticaCallEvent.ts +26 -29
- package/src/events/AgenticaCancelEvent.ts +4 -21
- package/src/events/AgenticaDescribeEvent.ts +8 -57
- package/src/events/AgenticaEvent.ts +14 -2
- package/src/events/AgenticaEventBase.ts +5 -6
- package/src/events/AgenticaExecuteEvent.ts +33 -41
- package/src/events/AgenticaInitializeEvent.ts +3 -11
- package/src/events/AgenticaRequestEvent.ts +5 -40
- package/src/events/AgenticaResponseEvent.ts +22 -39
- package/src/events/AgenticaSelectEvent.ts +6 -30
- package/src/events/AgenticaTextEvent.ts +11 -60
- package/src/events/AgenticaValidateEvent.ts +31 -0
- package/src/factory/events.ts +229 -0
- package/src/factory/index.ts +3 -0
- package/src/factory/operations.ts +17 -0
- package/src/factory/prompts.ts +104 -0
- package/src/index.ts +5 -6
- package/src/json/IAgenticaEventJson.ts +5 -3
- package/src/json/IAgenticaPromptJson.ts +1 -1
- package/src/{chatgpt → orchestrate}/ChatGptCallFunctionAgent.ts +62 -50
- package/src/{chatgpt → orchestrate}/ChatGptCancelFunctionAgent.ts +18 -16
- package/src/{chatgpt → orchestrate}/ChatGptCompletionMessageUtil.ts +7 -6
- package/src/{chatgpt → orchestrate}/ChatGptDescribeFunctionAgent.ts +7 -6
- package/src/{chatgpt → orchestrate}/ChatGptHistoryDecoder.ts +1 -2
- package/src/{chatgpt → orchestrate}/ChatGptInitializeFunctionAgent.ts +8 -7
- package/src/{chatgpt → orchestrate}/ChatGptSelectFunctionAgent.ts +18 -16
- package/src/{chatgpt → orchestrate}/ChatGptUsageAggregator.ts +3 -3
- package/src/orchestrate/index.ts +8 -0
- package/src/prompts/AgenticaCancelPrompt.ts +4 -25
- package/src/prompts/AgenticaDescribePrompt.ts +4 -25
- package/src/prompts/AgenticaExecutePrompt.ts +52 -44
- package/src/prompts/AgenticaPrompt.ts +10 -1
- package/src/prompts/AgenticaPromptBase.ts +5 -9
- package/src/prompts/AgenticaSelectPrompt.ts +4 -25
- package/src/prompts/AgenticaTextPrompt.ts +4 -26
- package/src/transformers/AgenticaEventTransformer.ts +30 -32
- package/src/transformers/AgenticaPromptTransformer.ts +22 -22
- package/lib/chatgpt/ChatGptAgent.js.map +0 -1
- package/lib/chatgpt/ChatGptCallFunctionAgent.js.map +0 -1
- package/lib/chatgpt/ChatGptCancelFunctionAgent.d.ts +0 -11
- package/lib/chatgpt/ChatGptCancelFunctionAgent.js.map +0 -1
- package/lib/chatgpt/ChatGptCompletionMessageUtil.d.ts +0 -13
- package/lib/chatgpt/ChatGptCompletionMessageUtil.js.map +0 -1
- package/lib/chatgpt/ChatGptDescribeFunctionAgent.js.map +0 -1
- package/lib/chatgpt/ChatGptHistoryDecoder.js.map +0 -1
- package/lib/chatgpt/ChatGptInitializeFunctionAgent.js.map +0 -1
- package/lib/chatgpt/ChatGptSelectFunctionAgent.js.map +0 -1
- package/lib/chatgpt/ChatGptUsageAggregator.d.ts +0 -9
- package/lib/chatgpt/ChatGptUsageAggregator.js.map +0 -1
- package/lib/context/AgenticaClassOperation.d.ts +0 -8
- package/lib/context/AgenticaClassOperation.js +0 -11
- package/lib/context/AgenticaClassOperation.js.map +0 -1
- package/lib/context/AgenticaHttpOperation.d.ts +0 -8
- package/lib/context/AgenticaHttpOperation.js +0 -11
- package/lib/context/AgenticaHttpOperation.js.map +0 -1
- package/lib/context/AgenticaOperationBase.d.ts +0 -29
- package/lib/context/AgenticaOperationBase.js +0 -21
- package/lib/context/AgenticaOperationBase.js.map +0 -1
- package/src/context/AgenticaClassOperation.ts +0 -23
- package/src/context/AgenticaHttpOperation.ts +0 -27
- package/src/context/AgenticaOperationBase.ts +0 -57
- package/lib/{chatgpt → orchestrate}/ChatGptAgent.d.ts +0 -0
- package/lib/{chatgpt → orchestrate}/ChatGptAgent.js +0 -0
- 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 {
|
|
14
|
-
import {
|
|
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"> =
|
|
129
|
+
const prompt: AgenticaTextPrompt<"user"> = createTextPrompt<"user">({
|
|
130
130
|
role: "user",
|
|
131
131
|
text: content,
|
|
132
132
|
});
|
|
133
133
|
await this.dispatch(
|
|
134
|
-
|
|
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 =
|
|
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(
|
|
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
|
|
6
|
+
export interface AgenticaCancelPrompt<
|
|
8
7
|
Model extends ILlmSchema.Model,
|
|
9
8
|
> extends AgenticaPromptBase<"cancel", IAgenticaPromptJson.ICancel> {
|
|
10
|
-
|
|
11
|
-
|
|
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,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
|
|
7
|
-
|
|
8
|
-
|
|
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,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
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
this.arguments = props.arguments;
|
|
19
|
-
}
|
|
18
|
+
/**
|
|
19
|
+
* Target operation to call.
|
|
20
|
+
*/
|
|
21
|
+
operation: AgenticaOperation<Model>;
|
|
20
22
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
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
|
|
6
|
+
export interface AgenticaCancelEvent<
|
|
8
7
|
Model extends ILlmSchema.Model,
|
|
9
8
|
> extends AgenticaEventBase<"cancel"> {
|
|
10
|
-
|
|
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 {
|
|
6
|
-
import { AgenticaEventBase } from "./AgenticaEventBase";
|
|
6
|
+
import type { AgenticaEventBase } from "./AgenticaEventBase";
|
|
7
7
|
|
|
8
|
-
export
|
|
8
|
+
export interface AgenticaDescribeEvent<
|
|
9
9
|
Model extends ILlmSchema.Model,
|
|
10
10
|
> extends AgenticaEventBase<"describe"> {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
public get text(): string {
|
|
14
|
-
return this.get_();
|
|
15
|
-
}
|
|
11
|
+
executes: AgenticaExecutePrompt<Model>[];
|
|
12
|
+
stream: ReadableStream<string>;
|
|
16
13
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
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
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
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:
|
|
35
|
+
operation: Operation;
|
|
47
36
|
arguments: Record<string, unknown>;
|
|
48
|
-
value:
|
|
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
|
|
5
|
-
|
|
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 {
|
|
3
|
+
import type { AgenticaEventBase } from "./AgenticaEventBase";
|
|
4
4
|
import type { AgenticaEventSource } from "./AgenticaEventSource";
|
|
5
|
-
import { AgenticaEventBase } from "./AgenticaEventBase";
|
|
6
5
|
|
|
7
|
-
export
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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
|
-
|
|
31
|
-
|
|
32
|
-
|
|
17
|
+
/**
|
|
18
|
+
* The text content stream.
|
|
19
|
+
*/
|
|
20
|
+
stream: ReadableStream<OpenAI.ChatCompletionChunk>;
|
|
33
21
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
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
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
}
|
|
27
|
+
/**
|
|
28
|
+
* Wait the completion.
|
|
29
|
+
*/
|
|
30
|
+
join: () => Promise<OpenAI.ChatCompletion>;
|
|
48
31
|
}
|