@agentica/core 0.12.2-dev.20250314 → 0.12.4
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 -21
- package/README.md +461 -461
- package/lib/context/AgenticaTokenUsage.d.ts +6 -6
- package/package.json +1 -1
- package/prompts/cancel.md +4 -4
- package/prompts/common.md +2 -2
- package/prompts/describe.md +6 -6
- package/prompts/execute.md +6 -6
- package/prompts/initialize.md +2 -2
- package/prompts/select.md +6 -6
- package/src/Agentica.ts +359 -359
- package/src/chatgpt/ChatGptAgent.ts +76 -76
- package/src/chatgpt/ChatGptCallFunctionAgent.ts +466 -466
- package/src/chatgpt/ChatGptCancelFunctionAgent.ts +280 -280
- package/src/chatgpt/ChatGptCompletionMessageUtil.ts +166 -166
- package/src/chatgpt/ChatGptDescribeFunctionAgent.ts +122 -122
- package/src/chatgpt/ChatGptHistoryDecoder.ts +88 -88
- package/src/chatgpt/ChatGptInitializeFunctionAgent.ts +96 -96
- package/src/chatgpt/ChatGptSelectFunctionAgent.ts +311 -311
- package/src/chatgpt/ChatGptUsageAggregator.ts +62 -62
- package/src/context/AgenticaCancelPrompt.ts +32 -32
- package/src/context/AgenticaClassOperation.ts +23 -23
- package/src/context/AgenticaContext.ts +130 -130
- package/src/context/AgenticaHttpOperation.ts +27 -27
- package/src/context/AgenticaOperation.ts +66 -66
- package/src/context/AgenticaOperationBase.ts +57 -57
- package/src/context/AgenticaOperationCollection.ts +52 -52
- package/src/context/AgenticaOperationSelection.ts +27 -27
- package/src/context/AgenticaTokenUsage.ts +170 -170
- package/src/context/internal/AgenticaTokenUsageAggregator.ts +66 -66
- package/src/context/internal/__IChatCancelFunctionsApplication.ts +23 -23
- package/src/context/internal/__IChatFunctionReference.ts +21 -21
- package/src/context/internal/__IChatInitialApplication.ts +15 -15
- package/src/context/internal/__IChatSelectFunctionsApplication.ts +24 -24
- package/src/events/AgenticaCallEvent.ts +36 -36
- package/src/events/AgenticaCancelEvent.ts +28 -28
- package/src/events/AgenticaDescribeEvent.ts +66 -66
- package/src/events/AgenticaEvent.ts +36 -36
- package/src/events/AgenticaEventBase.ts +7 -7
- package/src/events/AgenticaEventSource.ts +6 -6
- package/src/events/AgenticaExecuteEvent.ts +50 -50
- package/src/events/AgenticaInitializeEvent.ts +14 -14
- package/src/events/AgenticaRequestEvent.ts +45 -45
- package/src/events/AgenticaResponseEvent.ts +48 -48
- package/src/events/AgenticaSelectEvent.ts +37 -37
- package/src/events/AgenticaTextEvent.ts +62 -62
- package/src/functional/assertHttpLlmApplication.ts +55 -55
- package/src/functional/validateHttpLlmApplication.ts +66 -66
- package/src/index.ts +44 -44
- package/src/internal/AgenticaConstant.ts +4 -4
- package/src/internal/AgenticaDefaultPrompt.ts +43 -43
- package/src/internal/AgenticaOperationComposer.ts +96 -96
- package/src/internal/ByteArrayUtil.ts +5 -5
- package/src/internal/MPSCUtil.ts +111 -111
- package/src/internal/MathUtil.ts +3 -3
- package/src/internal/Singleton.ts +22 -22
- package/src/internal/StreamUtil.ts +64 -64
- package/src/internal/__map_take.ts +15 -15
- package/src/json/IAgenticaEventJson.ts +178 -178
- package/src/json/IAgenticaOperationJson.ts +36 -36
- package/src/json/IAgenticaOperationSelectionJson.ts +19 -19
- package/src/json/IAgenticaPromptJson.ts +130 -130
- package/src/json/IAgenticaTokenUsageJson.ts +107 -107
- package/src/prompts/AgenticaCancelPrompt.ts +32 -32
- package/src/prompts/AgenticaDescribePrompt.ts +41 -41
- package/src/prompts/AgenticaExecutePrompt.ts +52 -52
- package/src/prompts/AgenticaPrompt.ts +14 -14
- package/src/prompts/AgenticaPromptBase.ts +27 -27
- package/src/prompts/AgenticaSelectPrompt.ts +32 -32
- package/src/prompts/AgenticaTextPrompt.ts +31 -31
- package/src/structures/IAgenticaConfig.ts +123 -123
- package/src/structures/IAgenticaController.ts +133 -133
- package/src/structures/IAgenticaExecutor.ts +157 -157
- package/src/structures/IAgenticaProps.ts +69 -69
- package/src/structures/IAgenticaSystemPrompt.ts +125 -125
- package/src/structures/IAgenticaVendor.ts +39 -39
- package/src/transformers/AgenticaEventTransformer.ts +165 -165
- package/src/transformers/AgenticaPromptTransformer.ts +134 -134
|
@@ -1,76 +1,76 @@
|
|
|
1
|
-
import { ILlmSchema } from "@samchon/openapi";
|
|
2
|
-
|
|
3
|
-
import { AgenticaContext } from "../context/AgenticaContext";
|
|
4
|
-
import { AgenticaExecutePrompt } from "../prompts/AgenticaExecutePrompt";
|
|
5
|
-
import { AgenticaPrompt } from "../prompts/AgenticaPrompt";
|
|
6
|
-
import { IAgenticaExecutor } from "../structures/IAgenticaExecutor";
|
|
7
|
-
import { ChatGptCallFunctionAgent } from "./ChatGptCallFunctionAgent";
|
|
8
|
-
import { ChatGptCancelFunctionAgent } from "./ChatGptCancelFunctionAgent";
|
|
9
|
-
import { ChatGptDescribeFunctionAgent } from "./ChatGptDescribeFunctionAgent";
|
|
10
|
-
import { ChatGptInitializeFunctionAgent } from "./ChatGptInitializeFunctionAgent";
|
|
11
|
-
import { ChatGptSelectFunctionAgent } from "./ChatGptSelectFunctionAgent";
|
|
12
|
-
|
|
13
|
-
export namespace ChatGptAgent {
|
|
14
|
-
export const execute =
|
|
15
|
-
<Model extends ILlmSchema.Model>(
|
|
16
|
-
executor: Partial<IAgenticaExecutor<Model>> | null,
|
|
17
|
-
) =>
|
|
18
|
-
async (ctx: AgenticaContext<Model>): Promise<AgenticaPrompt<Model>[]> => {
|
|
19
|
-
const histories: AgenticaPrompt<Model>[] = [];
|
|
20
|
-
|
|
21
|
-
// FUNCTIONS ARE NOT LISTED YET
|
|
22
|
-
if (ctx.ready() === false) {
|
|
23
|
-
if (executor?.initialize === null) await ctx.initialize();
|
|
24
|
-
else {
|
|
25
|
-
histories.push(
|
|
26
|
-
...(await (
|
|
27
|
-
executor?.initialize ?? ChatGptInitializeFunctionAgent.execute
|
|
28
|
-
)(ctx)),
|
|
29
|
-
);
|
|
30
|
-
if (ctx.ready() === false) return histories;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
// CANCEL CANDIDATE FUNCTIONS
|
|
35
|
-
if (ctx.stack.length !== 0)
|
|
36
|
-
histories.push(
|
|
37
|
-
...(await (executor?.cancel ?? ChatGptCancelFunctionAgent.execute)(
|
|
38
|
-
ctx,
|
|
39
|
-
)),
|
|
40
|
-
);
|
|
41
|
-
|
|
42
|
-
// SELECT CANDIDATE FUNCTIONS
|
|
43
|
-
histories.push(
|
|
44
|
-
...(await (executor?.select ?? ChatGptSelectFunctionAgent.execute)(
|
|
45
|
-
ctx,
|
|
46
|
-
)),
|
|
47
|
-
);
|
|
48
|
-
if (ctx.stack.length === 0) return histories;
|
|
49
|
-
|
|
50
|
-
// FUNCTION CALLING LOOP
|
|
51
|
-
while (true) {
|
|
52
|
-
// EXECUTE FUNCTIONS
|
|
53
|
-
const prompts: AgenticaPrompt<Model>[] = await (
|
|
54
|
-
executor?.call ?? ChatGptCallFunctionAgent.execute
|
|
55
|
-
)(ctx);
|
|
56
|
-
histories.push(...prompts);
|
|
57
|
-
|
|
58
|
-
// EXPLAIN RETURN VALUES
|
|
59
|
-
const executes: AgenticaExecutePrompt<Model>[] = prompts.filter(
|
|
60
|
-
(prompt) => prompt.type === "execute",
|
|
61
|
-
);
|
|
62
|
-
for (const e of executes)
|
|
63
|
-
await ChatGptCancelFunctionAgent.cancelFunction(ctx, {
|
|
64
|
-
reason: "completed",
|
|
65
|
-
name: e.operation.name,
|
|
66
|
-
});
|
|
67
|
-
histories.push(
|
|
68
|
-
...(await (
|
|
69
|
-
executor?.describe ?? ChatGptDescribeFunctionAgent.execute
|
|
70
|
-
)(ctx, executes)),
|
|
71
|
-
);
|
|
72
|
-
if (executes.length === 0 || ctx.stack.length === 0) break;
|
|
73
|
-
}
|
|
74
|
-
return histories;
|
|
75
|
-
};
|
|
76
|
-
}
|
|
1
|
+
import { ILlmSchema } from "@samchon/openapi";
|
|
2
|
+
|
|
3
|
+
import { AgenticaContext } from "../context/AgenticaContext";
|
|
4
|
+
import { AgenticaExecutePrompt } from "../prompts/AgenticaExecutePrompt";
|
|
5
|
+
import { AgenticaPrompt } from "../prompts/AgenticaPrompt";
|
|
6
|
+
import { IAgenticaExecutor } from "../structures/IAgenticaExecutor";
|
|
7
|
+
import { ChatGptCallFunctionAgent } from "./ChatGptCallFunctionAgent";
|
|
8
|
+
import { ChatGptCancelFunctionAgent } from "./ChatGptCancelFunctionAgent";
|
|
9
|
+
import { ChatGptDescribeFunctionAgent } from "./ChatGptDescribeFunctionAgent";
|
|
10
|
+
import { ChatGptInitializeFunctionAgent } from "./ChatGptInitializeFunctionAgent";
|
|
11
|
+
import { ChatGptSelectFunctionAgent } from "./ChatGptSelectFunctionAgent";
|
|
12
|
+
|
|
13
|
+
export namespace ChatGptAgent {
|
|
14
|
+
export const execute =
|
|
15
|
+
<Model extends ILlmSchema.Model>(
|
|
16
|
+
executor: Partial<IAgenticaExecutor<Model>> | null,
|
|
17
|
+
) =>
|
|
18
|
+
async (ctx: AgenticaContext<Model>): Promise<AgenticaPrompt<Model>[]> => {
|
|
19
|
+
const histories: AgenticaPrompt<Model>[] = [];
|
|
20
|
+
|
|
21
|
+
// FUNCTIONS ARE NOT LISTED YET
|
|
22
|
+
if (ctx.ready() === false) {
|
|
23
|
+
if (executor?.initialize === null) await ctx.initialize();
|
|
24
|
+
else {
|
|
25
|
+
histories.push(
|
|
26
|
+
...(await (
|
|
27
|
+
executor?.initialize ?? ChatGptInitializeFunctionAgent.execute
|
|
28
|
+
)(ctx)),
|
|
29
|
+
);
|
|
30
|
+
if (ctx.ready() === false) return histories;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// CANCEL CANDIDATE FUNCTIONS
|
|
35
|
+
if (ctx.stack.length !== 0)
|
|
36
|
+
histories.push(
|
|
37
|
+
...(await (executor?.cancel ?? ChatGptCancelFunctionAgent.execute)(
|
|
38
|
+
ctx,
|
|
39
|
+
)),
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
// SELECT CANDIDATE FUNCTIONS
|
|
43
|
+
histories.push(
|
|
44
|
+
...(await (executor?.select ?? ChatGptSelectFunctionAgent.execute)(
|
|
45
|
+
ctx,
|
|
46
|
+
)),
|
|
47
|
+
);
|
|
48
|
+
if (ctx.stack.length === 0) return histories;
|
|
49
|
+
|
|
50
|
+
// FUNCTION CALLING LOOP
|
|
51
|
+
while (true) {
|
|
52
|
+
// EXECUTE FUNCTIONS
|
|
53
|
+
const prompts: AgenticaPrompt<Model>[] = await (
|
|
54
|
+
executor?.call ?? ChatGptCallFunctionAgent.execute
|
|
55
|
+
)(ctx);
|
|
56
|
+
histories.push(...prompts);
|
|
57
|
+
|
|
58
|
+
// EXPLAIN RETURN VALUES
|
|
59
|
+
const executes: AgenticaExecutePrompt<Model>[] = prompts.filter(
|
|
60
|
+
(prompt) => prompt.type === "execute",
|
|
61
|
+
);
|
|
62
|
+
for (const e of executes)
|
|
63
|
+
await ChatGptCancelFunctionAgent.cancelFunction(ctx, {
|
|
64
|
+
reason: "completed",
|
|
65
|
+
name: e.operation.name,
|
|
66
|
+
});
|
|
67
|
+
histories.push(
|
|
68
|
+
...(await (
|
|
69
|
+
executor?.describe ?? ChatGptDescribeFunctionAgent.execute
|
|
70
|
+
)(ctx, executes)),
|
|
71
|
+
);
|
|
72
|
+
if (executes.length === 0 || ctx.stack.length === 0) break;
|
|
73
|
+
}
|
|
74
|
+
return histories;
|
|
75
|
+
};
|
|
76
|
+
}
|