@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
|
@@ -1,37 +1,13 @@
|
|
|
1
1
|
import type { ILlmSchema } from "@samchon/openapi";
|
|
2
2
|
import type { AgenticaOperationSelection } from "../context/AgenticaOperationSelection";
|
|
3
|
-
|
|
4
3
|
import type { IAgenticaEventJson } from "../json/IAgenticaEventJson";
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import { AgenticaEventBase } from "./AgenticaEventBase";
|
|
4
|
+
import type { AgenticaSelectPrompt } from "../prompts/AgenticaSelectPrompt";
|
|
5
|
+
import type { AgenticaEventBase } from "./AgenticaEventBase";
|
|
8
6
|
|
|
9
|
-
export
|
|
7
|
+
export interface AgenticaSelectEvent<
|
|
10
8
|
Model extends ILlmSchema.Model,
|
|
11
9
|
> extends AgenticaEventBase<"select"> {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
super("select");
|
|
16
|
-
this.selection = props.selection;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
public toJSON(): IAgenticaEventJson.ISelect {
|
|
20
|
-
return {
|
|
21
|
-
type: "select",
|
|
22
|
-
selection: this.selection.toJSON(),
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
public toPrompt(): AgenticaSelectPrompt<Model> {
|
|
27
|
-
return new AgenticaSelectPrompt({
|
|
28
|
-
id: v4(),
|
|
29
|
-
selections: [this.selection],
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
export namespace AgenticaSelectEvent {
|
|
34
|
-
export interface IProps<Model extends ILlmSchema.Model> {
|
|
35
|
-
selection: AgenticaOperationSelection<Model>;
|
|
36
|
-
}
|
|
10
|
+
selection: AgenticaOperationSelection<Model>;
|
|
11
|
+
toJSON: () => IAgenticaEventJson.ISelect;
|
|
12
|
+
toPrompt: () => AgenticaSelectPrompt<Model>;
|
|
37
13
|
}
|
|
@@ -1,62 +1,13 @@
|
|
|
1
1
|
import type { IAgenticaEventJson } from "../json/IAgenticaEventJson";
|
|
2
|
-
import { AgenticaTextPrompt } from "../prompts/AgenticaTextPrompt";
|
|
3
|
-
import { AgenticaEventBase } from "./AgenticaEventBase";
|
|
4
|
-
|
|
5
|
-
export
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
* Check if the join method can return a response immediately.
|
|
14
|
-
* Returns true if the response is ready to be returned by the join method.
|
|
15
|
-
*/
|
|
16
|
-
public get done(): boolean {
|
|
17
|
-
return this.done_();
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
public constructor(props: AgenticaTextEvent.IProps) {
|
|
21
|
-
super("text");
|
|
22
|
-
this.role = props.role;
|
|
23
|
-
this.stream = props.stream;
|
|
24
|
-
|
|
25
|
-
this.done_ = props.done;
|
|
26
|
-
this.get_ = props.get;
|
|
27
|
-
this.join_ = props.join;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
public async join(): Promise<string> {
|
|
31
|
-
return this.join_();
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
public toJSON(): IAgenticaEventJson.IText {
|
|
35
|
-
return {
|
|
36
|
-
type: "text",
|
|
37
|
-
role: this.role,
|
|
38
|
-
text: this.text,
|
|
39
|
-
done: this.done,
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
public toPrompt(): AgenticaTextPrompt {
|
|
44
|
-
return new AgenticaTextPrompt({
|
|
45
|
-
role: this.role,
|
|
46
|
-
text: this.text,
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
private readonly done_: () => boolean;
|
|
51
|
-
private readonly get_: () => string;
|
|
52
|
-
private readonly join_: () => Promise<string>;
|
|
53
|
-
}
|
|
54
|
-
export namespace AgenticaTextEvent {
|
|
55
|
-
export interface IProps {
|
|
56
|
-
role: "assistant" | "user";
|
|
57
|
-
stream: ReadableStream<string>;
|
|
58
|
-
done: () => boolean;
|
|
59
|
-
get: () => string;
|
|
60
|
-
join: () => Promise<string>;
|
|
61
|
-
}
|
|
2
|
+
import type { AgenticaTextPrompt } from "../prompts/AgenticaTextPrompt";
|
|
3
|
+
import type { AgenticaEventBase } from "./AgenticaEventBase";
|
|
4
|
+
|
|
5
|
+
export interface AgenticaTextEvent<
|
|
6
|
+
Role extends "assistant" | "user" = "assistant" | "user",
|
|
7
|
+
> extends AgenticaEventBase<"text"> {
|
|
8
|
+
role: Role;
|
|
9
|
+
stream: ReadableStream<string>;
|
|
10
|
+
join: () => Promise<string>;
|
|
11
|
+
toJSON: () => IAgenticaEventJson.IText;
|
|
12
|
+
toPrompt: () => AgenticaTextPrompt;
|
|
62
13
|
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { ILlmSchema } from "@samchon/openapi";
|
|
2
|
+
import type { IValidation } from "typia";
|
|
3
|
+
import type { AgenticaEventBase } from "./AgenticaEventBase";
|
|
4
|
+
import type { AgenticaOperation } from "../context/AgenticaOperation";
|
|
5
|
+
import type { IAgenticaEventJson } from "../json/IAgenticaEventJson";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Event of a validation feedback.
|
|
9
|
+
*
|
|
10
|
+
* @author Samchon
|
|
11
|
+
*/
|
|
12
|
+
export interface AgenticaValidateEvent<
|
|
13
|
+
Model extends ILlmSchema.Model,
|
|
14
|
+
> extends AgenticaEventBase<"validate"> {
|
|
15
|
+
/**
|
|
16
|
+
* ID of the tool calling.
|
|
17
|
+
*/
|
|
18
|
+
id: string;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Target operation to call.
|
|
22
|
+
*/
|
|
23
|
+
operation: AgenticaOperation<Model>;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Validation result as a failure.
|
|
27
|
+
*/
|
|
28
|
+
result: IValidation.IFailure;
|
|
29
|
+
|
|
30
|
+
toJSON: () => IAgenticaEventJson.IValidate;
|
|
31
|
+
}
|
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
import { v4 } from "uuid";
|
|
2
|
+
|
|
3
|
+
import type { ILlmSchema, IValidation } from "@samchon/openapi";
|
|
4
|
+
import type OpenAI from "openai";
|
|
5
|
+
import type { AgenticaOperation } from "../context/AgenticaOperation";
|
|
6
|
+
import type { AgenticaOperationSelection } from "../context/AgenticaOperationSelection";
|
|
7
|
+
import type { AgenticaCallEvent } from "../events/AgenticaCallEvent";
|
|
8
|
+
import type { AgenticaCancelEvent } from "../events/AgenticaCancelEvent";
|
|
9
|
+
import type { AgenticaDescribeEvent } from "../events/AgenticaDescribeEvent";
|
|
10
|
+
import type { AgenticaEventSource } from "../events/AgenticaEventSource";
|
|
11
|
+
import type { AgenticaInitializeEvent } from "../events/AgenticaInitializeEvent";
|
|
12
|
+
import type { AgenticaRequestEvent } from "../events/AgenticaRequestEvent";
|
|
13
|
+
import type { AgenticaResponseEvent } from "../events/AgenticaResponseEvent";
|
|
14
|
+
import type { AgenticaTextEvent } from "../events/AgenticaTextEvent";
|
|
15
|
+
import type { IAgenticaEventJson } from "../json/IAgenticaEventJson";
|
|
16
|
+
import type { AgenticaExecutePrompt } from "../prompts/AgenticaExecutePrompt";
|
|
17
|
+
import type { AgenticaExecuteEvent } from "../events/AgenticaExecuteEvent";
|
|
18
|
+
import type { AgenticaSelectEvent } from "../events/AgenticaSelectEvent";
|
|
19
|
+
import type { AgenticaValidateEvent } from "../events/AgenticaValidateEvent";
|
|
20
|
+
|
|
21
|
+
import { createExecutePrompt, createSelectPrompt } from "./prompts";
|
|
22
|
+
|
|
23
|
+
/* -----------------------------------------------------------
|
|
24
|
+
FUNCTION SELECTS
|
|
25
|
+
----------------------------------------------------------- */
|
|
26
|
+
export function createInitializeEvent(): AgenticaInitializeEvent {
|
|
27
|
+
const event: IAgenticaEventJson.IInitialize = {
|
|
28
|
+
type: "initialize",
|
|
29
|
+
};
|
|
30
|
+
return {
|
|
31
|
+
type: event.type,
|
|
32
|
+
toJSON: () => event,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function createSelectEvent<Model extends ILlmSchema.Model>(props: {
|
|
37
|
+
selection: AgenticaOperationSelection<Model>;
|
|
38
|
+
}): AgenticaSelectEvent<Model> {
|
|
39
|
+
return {
|
|
40
|
+
type: "select",
|
|
41
|
+
selection: props.selection,
|
|
42
|
+
toJSON: () => ({
|
|
43
|
+
type: "select",
|
|
44
|
+
selection: props.selection.toJSON(),
|
|
45
|
+
}),
|
|
46
|
+
toPrompt: () => createSelectPrompt({
|
|
47
|
+
id: v4(),
|
|
48
|
+
selections: [props.selection],
|
|
49
|
+
}),
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export function createCancelEvent<Model extends ILlmSchema.Model>(props: {
|
|
54
|
+
selection: AgenticaOperationSelection<Model>;
|
|
55
|
+
}): AgenticaCancelEvent<Model> {
|
|
56
|
+
return {
|
|
57
|
+
type: "cancel",
|
|
58
|
+
selection: props.selection,
|
|
59
|
+
toJSON: () => ({
|
|
60
|
+
type: "cancel",
|
|
61
|
+
selection: props.selection.toJSON(),
|
|
62
|
+
}),
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/* -----------------------------------------------------------
|
|
67
|
+
FUNCTION CALLS
|
|
68
|
+
----------------------------------------------------------- */
|
|
69
|
+
export function createCallEvent<Model extends ILlmSchema.Model>(props: {
|
|
70
|
+
id: string;
|
|
71
|
+
operation: AgenticaOperation<Model>;
|
|
72
|
+
arguments: Record<string, any>;
|
|
73
|
+
}): AgenticaCallEvent<Model> {
|
|
74
|
+
return {
|
|
75
|
+
type: "call",
|
|
76
|
+
id: props.id,
|
|
77
|
+
operation: props.operation,
|
|
78
|
+
arguments: props.arguments,
|
|
79
|
+
toJSON: () => ({
|
|
80
|
+
type: "call",
|
|
81
|
+
id: props.id,
|
|
82
|
+
operation: props.operation.toJSON(),
|
|
83
|
+
arguments: props.arguments,
|
|
84
|
+
}),
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export function createValidateEvent<Model extends ILlmSchema.Model>(props: {
|
|
89
|
+
id: string;
|
|
90
|
+
operation: AgenticaOperation<Model>;
|
|
91
|
+
result: IValidation.IFailure;
|
|
92
|
+
}): AgenticaValidateEvent<Model> {
|
|
93
|
+
return {
|
|
94
|
+
type: "validate",
|
|
95
|
+
id: props.id,
|
|
96
|
+
operation: props.operation,
|
|
97
|
+
result: props.result,
|
|
98
|
+
toJSON: () => ({
|
|
99
|
+
type: "validate",
|
|
100
|
+
id: props.id,
|
|
101
|
+
operation: props.operation.toJSON(),
|
|
102
|
+
result: props.result,
|
|
103
|
+
}),
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export function createExecuteEvent<Model extends ILlmSchema.Model>(props: {
|
|
108
|
+
id: string;
|
|
109
|
+
operation: AgenticaOperation<Model>;
|
|
110
|
+
arguments: Record<string, unknown>;
|
|
111
|
+
value: unknown;
|
|
112
|
+
}): AgenticaExecuteEvent<Model> {
|
|
113
|
+
return {
|
|
114
|
+
type: "execute",
|
|
115
|
+
protocol: props.operation.protocol as "class",
|
|
116
|
+
id: props.id,
|
|
117
|
+
operation: props.operation as AgenticaOperation.Class<Model>,
|
|
118
|
+
arguments: props.arguments,
|
|
119
|
+
value: props.value as any,
|
|
120
|
+
toJSON: () => ({
|
|
121
|
+
type: "execute",
|
|
122
|
+
protocol: props.operation.protocol as "class",
|
|
123
|
+
id: props.id,
|
|
124
|
+
operation: props.operation.toJSON(),
|
|
125
|
+
arguments: props.arguments,
|
|
126
|
+
value: props.value,
|
|
127
|
+
}),
|
|
128
|
+
toPrompt: () =>
|
|
129
|
+
createExecutePrompt(props) as AgenticaExecutePrompt.Class<Model>,
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/* -----------------------------------------------------------
|
|
134
|
+
TEXT STEAMING
|
|
135
|
+
----------------------------------------------------------- */
|
|
136
|
+
export function createTextEvent<Role extends "user" | "assistant">(props: {
|
|
137
|
+
role: Role;
|
|
138
|
+
stream: ReadableStream<string>;
|
|
139
|
+
done: () => boolean;
|
|
140
|
+
get: () => string;
|
|
141
|
+
join: () => Promise<string>;
|
|
142
|
+
}): AgenticaTextEvent<Role> {
|
|
143
|
+
return {
|
|
144
|
+
type: "text",
|
|
145
|
+
role: props.role,
|
|
146
|
+
stream: props.stream,
|
|
147
|
+
join: props.join,
|
|
148
|
+
toJSON: () => ({
|
|
149
|
+
type: "text",
|
|
150
|
+
role: props.role,
|
|
151
|
+
done: props.done(),
|
|
152
|
+
text: props.get(),
|
|
153
|
+
}),
|
|
154
|
+
toPrompt: () => ({
|
|
155
|
+
type: "text",
|
|
156
|
+
role: props.role,
|
|
157
|
+
text: props.get(),
|
|
158
|
+
toJSON: () => ({
|
|
159
|
+
type: "text",
|
|
160
|
+
role: props.role,
|
|
161
|
+
text: props.get(),
|
|
162
|
+
}),
|
|
163
|
+
}),
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
export function createDescribeEvent<Model extends ILlmSchema.Model>(props: {
|
|
168
|
+
executes: AgenticaExecutePrompt<Model>[];
|
|
169
|
+
stream: ReadableStream<string>;
|
|
170
|
+
done: () => boolean;
|
|
171
|
+
get: () => string;
|
|
172
|
+
join: () => Promise<string>;
|
|
173
|
+
}): AgenticaDescribeEvent<Model> {
|
|
174
|
+
return {
|
|
175
|
+
type: "describe",
|
|
176
|
+
executes: props.executes,
|
|
177
|
+
stream: props.stream,
|
|
178
|
+
join: props.join,
|
|
179
|
+
toJSON: () => ({
|
|
180
|
+
type: "describe",
|
|
181
|
+
executes: props.executes.map(execute => execute.toJSON()),
|
|
182
|
+
done: props.done(),
|
|
183
|
+
text: props.get(),
|
|
184
|
+
}),
|
|
185
|
+
toPrompt: () => ({
|
|
186
|
+
type: "describe",
|
|
187
|
+
executes: props.executes,
|
|
188
|
+
text: props.get(),
|
|
189
|
+
toJSON: () => ({
|
|
190
|
+
type: "describe",
|
|
191
|
+
executes: props.executes.map(execute => execute.toJSON()),
|
|
192
|
+
text: props.get(),
|
|
193
|
+
}),
|
|
194
|
+
}),
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/* -----------------------------------------------------------
|
|
199
|
+
API REQUESTS
|
|
200
|
+
----------------------------------------------------------- */
|
|
201
|
+
export function createRequestEvent(props: {
|
|
202
|
+
source: AgenticaEventSource;
|
|
203
|
+
body: OpenAI.ChatCompletionCreateParamsStreaming;
|
|
204
|
+
options?: OpenAI.RequestOptions | undefined;
|
|
205
|
+
}): AgenticaRequestEvent {
|
|
206
|
+
return {
|
|
207
|
+
type: "request",
|
|
208
|
+
source: props.source,
|
|
209
|
+
body: props.body,
|
|
210
|
+
options: props.options,
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
export function createResponseEvent(props: {
|
|
215
|
+
source: AgenticaEventSource;
|
|
216
|
+
body: OpenAI.ChatCompletionCreateParamsStreaming;
|
|
217
|
+
options?: OpenAI.RequestOptions | undefined;
|
|
218
|
+
stream: ReadableStream<OpenAI.ChatCompletionChunk>;
|
|
219
|
+
join: () => Promise<OpenAI.ChatCompletion>;
|
|
220
|
+
}): AgenticaResponseEvent {
|
|
221
|
+
return {
|
|
222
|
+
type: "response",
|
|
223
|
+
source: props.source,
|
|
224
|
+
body: props.body,
|
|
225
|
+
options: props.options,
|
|
226
|
+
stream: props.stream,
|
|
227
|
+
join: props.join,
|
|
228
|
+
};
|
|
229
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { ILlmSchema } from "@samchon/openapi";
|
|
2
|
+
import type { AgenticaOperation } from "../context/AgenticaOperation";
|
|
3
|
+
import type { AgenticaOperationSelection } from "../context/AgenticaOperationSelection";
|
|
4
|
+
|
|
5
|
+
export function createOperationSelection<Model extends ILlmSchema.Model>(props: {
|
|
6
|
+
operation: AgenticaOperation<Model>;
|
|
7
|
+
reason: string;
|
|
8
|
+
}): AgenticaOperationSelection<Model> {
|
|
9
|
+
return {
|
|
10
|
+
operation: props.operation,
|
|
11
|
+
reason: props.reason,
|
|
12
|
+
toJSON: () => ({
|
|
13
|
+
operation: props.operation.toJSON(),
|
|
14
|
+
reason: props.reason,
|
|
15
|
+
}),
|
|
16
|
+
};
|
|
17
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import type { ILlmSchema } from "@samchon/openapi";
|
|
2
|
+
import type { AgenticaTextPrompt } from "../prompts/AgenticaTextPrompt";
|
|
3
|
+
import type { IAgenticaPromptJson } from "../json/IAgenticaPromptJson";
|
|
4
|
+
import type { AgenticaDescribePrompt } from "../prompts/AgenticaDescribePrompt";
|
|
5
|
+
import type { AgenticaExecutePrompt } from "../prompts/AgenticaExecutePrompt";
|
|
6
|
+
import type { AgenticaOperationSelection } from "../context/AgenticaOperationSelection";
|
|
7
|
+
import type { AgenticaSelectPrompt } from "../prompts/AgenticaSelectPrompt";
|
|
8
|
+
import type { AgenticaCancelPrompt } from "../context/AgenticaCancelPrompt";
|
|
9
|
+
import type { AgenticaOperation } from "../context/AgenticaOperation";
|
|
10
|
+
|
|
11
|
+
/* -----------------------------------------------------------
|
|
12
|
+
TEXT PROMPTS
|
|
13
|
+
----------------------------------------------------------- */
|
|
14
|
+
export function createTextPrompt<Role extends "assistant" | "user" = "assistant" | "user">(props: {
|
|
15
|
+
role: Role;
|
|
16
|
+
text: string;
|
|
17
|
+
}): AgenticaTextPrompt<Role> {
|
|
18
|
+
const prompt: IAgenticaPromptJson.IText<Role> = {
|
|
19
|
+
type: "text",
|
|
20
|
+
role: props.role,
|
|
21
|
+
text: props.text,
|
|
22
|
+
};
|
|
23
|
+
return {
|
|
24
|
+
...prompt,
|
|
25
|
+
toJSON: () => prompt,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function createDescribePrompt<Model extends ILlmSchema.Model>(props: {
|
|
30
|
+
executes: AgenticaExecutePrompt<Model>[];
|
|
31
|
+
text: string;
|
|
32
|
+
}): AgenticaDescribePrompt<Model> {
|
|
33
|
+
return {
|
|
34
|
+
type: "describe",
|
|
35
|
+
text: props.text,
|
|
36
|
+
executes: props.executes,
|
|
37
|
+
toJSON: () => ({
|
|
38
|
+
type: "describe",
|
|
39
|
+
text: props.text,
|
|
40
|
+
executes: props.executes.map(execute => execute.toJSON()),
|
|
41
|
+
}),
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/* -----------------------------------------------------------
|
|
46
|
+
FUNCTION CALLING PROMPTS
|
|
47
|
+
----------------------------------------------------------- */
|
|
48
|
+
export function createSelectPrompt<Model extends ILlmSchema.Model>(props: {
|
|
49
|
+
id: string;
|
|
50
|
+
selections: AgenticaOperationSelection<Model>[];
|
|
51
|
+
}): AgenticaSelectPrompt<Model> {
|
|
52
|
+
return {
|
|
53
|
+
type: "select",
|
|
54
|
+
id: props.id,
|
|
55
|
+
selections: props.selections,
|
|
56
|
+
toJSON: () => ({
|
|
57
|
+
type: "select",
|
|
58
|
+
id: props.id,
|
|
59
|
+
selections: props.selections.map(selection => selection.toJSON()),
|
|
60
|
+
}),
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export function createCancelPrompt<Model extends ILlmSchema.Model>(props: {
|
|
65
|
+
id: string;
|
|
66
|
+
selections: AgenticaOperationSelection<Model>[];
|
|
67
|
+
}): AgenticaCancelPrompt<Model> {
|
|
68
|
+
return {
|
|
69
|
+
type: "cancel",
|
|
70
|
+
id: props.id,
|
|
71
|
+
selections: props.selections,
|
|
72
|
+
toJSON: () => ({
|
|
73
|
+
type: "cancel",
|
|
74
|
+
id: props.id,
|
|
75
|
+
selections: props.selections.map(selection => selection.toJSON()),
|
|
76
|
+
}),
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export function createExecutePrompt<
|
|
81
|
+
Model extends ILlmSchema.Model,
|
|
82
|
+
>(props: {
|
|
83
|
+
id: string;
|
|
84
|
+
operation: AgenticaOperation<Model>;
|
|
85
|
+
arguments: Record<string, any>;
|
|
86
|
+
value: unknown;
|
|
87
|
+
}): AgenticaExecutePrompt<Model> {
|
|
88
|
+
return {
|
|
89
|
+
type: "execute",
|
|
90
|
+
protocol: props.operation.protocol as "class",
|
|
91
|
+
id: props.id,
|
|
92
|
+
operation: props.operation as AgenticaOperation.Class<Model>,
|
|
93
|
+
arguments: props.arguments,
|
|
94
|
+
value: props.value,
|
|
95
|
+
toJSON: () => ({
|
|
96
|
+
type: "execute",
|
|
97
|
+
protocol: props.operation.protocol,
|
|
98
|
+
id: props.id,
|
|
99
|
+
operation: props.operation.toJSON(),
|
|
100
|
+
arguments: props.arguments,
|
|
101
|
+
value: props.value,
|
|
102
|
+
}),
|
|
103
|
+
};
|
|
104
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export * from "./Agentica";
|
|
2
|
-
|
|
2
|
+
|
|
3
3
|
export * from "./context/AgenticaContext";
|
|
4
4
|
export * from "./context/AgenticaOperation";
|
|
5
5
|
export * from "./context/AgenticaOperationCollection";
|
|
@@ -9,17 +9,15 @@ export * from "./context/AgenticaTokenUsage";
|
|
|
9
9
|
export * from "./events/AgenticaCallEvent";
|
|
10
10
|
export * from "./events/AgenticaCancelEvent";
|
|
11
11
|
export * from "./events/AgenticaDescribeEvent";
|
|
12
|
-
// EVENTS
|
|
13
12
|
export * from "./events/AgenticaEvent";
|
|
14
13
|
export * from "./events/AgenticaEventSource";
|
|
15
|
-
|
|
16
14
|
export * from "./events/AgenticaExecuteEvent";
|
|
17
15
|
export * from "./events/AgenticaRequestEvent";
|
|
18
16
|
export * from "./events/AgenticaResponseEvent";
|
|
19
17
|
export * from "./events/AgenticaSelectEvent";
|
|
20
18
|
export * from "./events/AgenticaTextEvent";
|
|
19
|
+
export * as factory from "./factory";
|
|
21
20
|
|
|
22
|
-
// FACADE CLASS
|
|
23
21
|
export * from "./functional/assertHttpLlmApplication";
|
|
24
22
|
export * from "./functional/validateHttpLlmApplication";
|
|
25
23
|
export * from "./json/IAgenticaEventJson";
|
|
@@ -28,17 +26,18 @@ export * from "./json/IAgenticaOperationSelectionJson";
|
|
|
28
26
|
export * from "./json/IAgenticaPromptJson";
|
|
29
27
|
|
|
30
28
|
export * from "./json/IAgenticaTokenUsageJson";
|
|
29
|
+
export * as orchestrate from "./orchestrate";
|
|
31
30
|
export * from "./prompts/AgenticaCancelPrompt";
|
|
32
31
|
export * from "./prompts/AgenticaDescribePrompt";
|
|
33
32
|
export * from "./prompts/AgenticaExecutePrompt";
|
|
34
33
|
export * from "./prompts/AgenticaPrompt";
|
|
35
34
|
export * from "./prompts/AgenticaSelectPrompt";
|
|
35
|
+
|
|
36
36
|
export * from "./prompts/AgenticaTextPrompt";
|
|
37
|
-
// STRUCTURES
|
|
38
37
|
export * from "./structures/IAgenticaConfig";
|
|
39
38
|
export * from "./structures/IAgenticaController";
|
|
40
39
|
export * from "./structures/IAgenticaExecutor";
|
|
41
|
-
|
|
42
40
|
export * from "./structures/IAgenticaProps";
|
|
43
41
|
export * from "./structures/IAgenticaSystemPrompt";
|
|
42
|
+
|
|
44
43
|
export * from "./structures/IAgenticaVendor";
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type OpenAI from "openai";
|
|
2
|
-
|
|
3
2
|
import type { AgenticaEventSource } from "../events/AgenticaEventSource";
|
|
4
3
|
import type { IAgenticaOperationJson } from "./IAgenticaOperationJson";
|
|
5
4
|
import type { IAgenticaOperationSelectionJson } from "./IAgenticaOperationSelectionJson";
|
|
@@ -22,7 +21,8 @@ export type IAgenticaEventJson =
|
|
|
22
21
|
| IAgenticaEventJson.IInitialize
|
|
23
22
|
| IAgenticaEventJson.IRequest
|
|
24
23
|
| IAgenticaEventJson.ISelect
|
|
25
|
-
| IAgenticaEventJson.IText
|
|
24
|
+
| IAgenticaEventJson.IText
|
|
25
|
+
| IAgenticaEventJson.IValidate;
|
|
26
26
|
export namespace IAgenticaEventJson {
|
|
27
27
|
export type Type = IAgenticaEventJson["type"];
|
|
28
28
|
export interface Mapper {
|
|
@@ -79,6 +79,8 @@ export namespace IAgenticaEventJson {
|
|
|
79
79
|
arguments: Record<string, any>;
|
|
80
80
|
}
|
|
81
81
|
|
|
82
|
+
export interface IValidate extends IBase<"validate"> {}
|
|
83
|
+
|
|
82
84
|
/**
|
|
83
85
|
* Event of function calling execution.
|
|
84
86
|
*/
|
|
@@ -96,7 +98,7 @@ export namespace IAgenticaEventJson {
|
|
|
96
98
|
/**
|
|
97
99
|
* Arguments of the function calling.
|
|
98
100
|
*/
|
|
99
|
-
arguments:
|
|
101
|
+
arguments: Record<string, unknown>;
|
|
100
102
|
|
|
101
103
|
/**
|
|
102
104
|
* Return value.
|