@agentica/core 0.10.1-dev.20250302 → 0.10.1
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 +419 -419
- 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 +323 -323
- package/src/chatgpt/ChatGptAgent.ts +75 -75
- package/src/chatgpt/ChatGptCallFunctionAgent.ts +464 -464
- package/src/chatgpt/ChatGptCancelFunctionAgent.ts +287 -287
- package/src/chatgpt/ChatGptDescribeFunctionAgent.ts +52 -52
- package/src/chatgpt/ChatGptHistoryDecoder.ts +88 -88
- package/src/chatgpt/ChatGptInitializeFunctionAgent.ts +88 -88
- package/src/chatgpt/ChatGptSelectFunctionAgent.ts +319 -319
- package/src/functional/createHttpLlmApplication.ts +63 -63
- package/src/index.ts +19 -19
- package/src/internal/AgenticaConstant.ts +4 -4
- package/src/internal/AgenticaDefaultPrompt.ts +43 -43
- package/src/internal/AgenticaOperationComposer.ts +87 -87
- package/src/internal/AgenticaPromptFactory.ts +32 -32
- package/src/internal/AgenticaPromptTransformer.ts +86 -86
- package/src/internal/AgenticaTokenUsageAggregator.ts +115 -115
- package/src/internal/MathUtil.ts +3 -3
- package/src/internal/Singleton.ts +22 -22
- package/src/internal/__map_take.ts +15 -15
- package/src/structures/IAgenticaConfig.ts +123 -123
- package/src/structures/IAgenticaContext.ts +129 -129
- package/src/structures/IAgenticaController.ts +133 -133
- package/src/structures/IAgenticaEvent.ts +229 -229
- package/src/structures/IAgenticaExecutor.ts +156 -156
- package/src/structures/IAgenticaOperation.ts +63 -63
- package/src/structures/IAgenticaOperationCollection.ts +52 -52
- package/src/structures/IAgenticaOperationSelection.ts +68 -68
- package/src/structures/IAgenticaPrompt.ts +182 -182
- package/src/structures/IAgenticaProps.ts +70 -70
- package/src/structures/IAgenticaSystemPrompt.ts +124 -124
- package/src/structures/IAgenticaTokenUsage.ts +107 -107
- package/src/structures/IAgenticaVendor.ts +39 -39
- package/src/structures/internal/__IChatCancelFunctionsApplication.ts +23 -23
- package/src/structures/internal/__IChatFunctionReference.ts +21 -21
- package/src/structures/internal/__IChatInitialApplication.ts +15 -15
- package/src/structures/internal/__IChatSelectFunctionsApplication.ts +24 -24
- package/src/typings/AgenticaSource.ts +6 -6
|
@@ -1,75 +1,75 @@
|
|
|
1
|
-
import { ILlmSchema } from "@samchon/openapi";
|
|
2
|
-
|
|
3
|
-
import { IAgenticaContext } from "../structures/IAgenticaContext";
|
|
4
|
-
import { IAgenticaExecutor } from "../structures/IAgenticaExecutor";
|
|
5
|
-
import { IAgenticaPrompt } from "../structures/IAgenticaPrompt";
|
|
6
|
-
import { ChatGptCallFunctionAgent } from "./ChatGptCallFunctionAgent";
|
|
7
|
-
import { ChatGptCancelFunctionAgent } from "./ChatGptCancelFunctionAgent";
|
|
8
|
-
import { ChatGptDescribeFunctionAgent } from "./ChatGptDescribeFunctionAgent";
|
|
9
|
-
import { ChatGptInitializeFunctionAgent } from "./ChatGptInitializeFunctionAgent";
|
|
10
|
-
import { ChatGptSelectFunctionAgent } from "./ChatGptSelectFunctionAgent";
|
|
11
|
-
|
|
12
|
-
export namespace ChatGptAgent {
|
|
13
|
-
export const execute =
|
|
14
|
-
<Model extends ILlmSchema.Model>(
|
|
15
|
-
executor: Partial<IAgenticaExecutor<Model>> | null,
|
|
16
|
-
) =>
|
|
17
|
-
async (ctx: IAgenticaContext<Model>): Promise<IAgenticaPrompt<Model>[]> => {
|
|
18
|
-
const histories: IAgenticaPrompt<Model>[] = [];
|
|
19
|
-
|
|
20
|
-
// FUNCTIONS ARE NOT LISTED YET
|
|
21
|
-
if (ctx.ready() === false) {
|
|
22
|
-
if (executor?.initialize === null) await ctx.initialize();
|
|
23
|
-
else {
|
|
24
|
-
histories.push(
|
|
25
|
-
...(await (
|
|
26
|
-
executor?.initialize ?? ChatGptInitializeFunctionAgent.execute
|
|
27
|
-
)(ctx)),
|
|
28
|
-
);
|
|
29
|
-
if (ctx.ready() === false) return histories;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
// CANCEL CANDIDATE FUNCTIONS
|
|
34
|
-
if (ctx.stack.length !== 0)
|
|
35
|
-
histories.push(
|
|
36
|
-
...(await (executor?.cancel ?? ChatGptCancelFunctionAgent.execute)(
|
|
37
|
-
ctx,
|
|
38
|
-
)),
|
|
39
|
-
);
|
|
40
|
-
|
|
41
|
-
// SELECT CANDIDATE FUNCTIONS
|
|
42
|
-
histories.push(
|
|
43
|
-
...(await (executor?.select ?? ChatGptSelectFunctionAgent.execute)(
|
|
44
|
-
ctx,
|
|
45
|
-
)),
|
|
46
|
-
);
|
|
47
|
-
if (ctx.stack.length === 0) return histories;
|
|
48
|
-
|
|
49
|
-
// FUNCTION CALLING LOOP
|
|
50
|
-
while (true) {
|
|
51
|
-
// EXECUTE FUNCTIONS
|
|
52
|
-
const prompts: IAgenticaPrompt<Model>[] = await (
|
|
53
|
-
executor?.call ?? ChatGptCallFunctionAgent.execute
|
|
54
|
-
)(ctx);
|
|
55
|
-
histories.push(...prompts);
|
|
56
|
-
|
|
57
|
-
// EXPLAIN RETURN VALUES
|
|
58
|
-
const executes: IAgenticaPrompt.IExecute<Model>[] = prompts.filter(
|
|
59
|
-
(prompt) => prompt.type === "execute",
|
|
60
|
-
);
|
|
61
|
-
for (const e of executes)
|
|
62
|
-
await ChatGptCancelFunctionAgent.cancelFunction(ctx, {
|
|
63
|
-
reason: "completed",
|
|
64
|
-
name: e.function.name,
|
|
65
|
-
});
|
|
66
|
-
histories.push(
|
|
67
|
-
...(await (
|
|
68
|
-
executor?.describe ?? ChatGptDescribeFunctionAgent.execute
|
|
69
|
-
)(ctx, executes)),
|
|
70
|
-
);
|
|
71
|
-
if (executes.length === 0 || ctx.stack.length === 0) break;
|
|
72
|
-
}
|
|
73
|
-
return histories;
|
|
74
|
-
};
|
|
75
|
-
}
|
|
1
|
+
import { ILlmSchema } from "@samchon/openapi";
|
|
2
|
+
|
|
3
|
+
import { IAgenticaContext } from "../structures/IAgenticaContext";
|
|
4
|
+
import { IAgenticaExecutor } from "../structures/IAgenticaExecutor";
|
|
5
|
+
import { IAgenticaPrompt } from "../structures/IAgenticaPrompt";
|
|
6
|
+
import { ChatGptCallFunctionAgent } from "./ChatGptCallFunctionAgent";
|
|
7
|
+
import { ChatGptCancelFunctionAgent } from "./ChatGptCancelFunctionAgent";
|
|
8
|
+
import { ChatGptDescribeFunctionAgent } from "./ChatGptDescribeFunctionAgent";
|
|
9
|
+
import { ChatGptInitializeFunctionAgent } from "./ChatGptInitializeFunctionAgent";
|
|
10
|
+
import { ChatGptSelectFunctionAgent } from "./ChatGptSelectFunctionAgent";
|
|
11
|
+
|
|
12
|
+
export namespace ChatGptAgent {
|
|
13
|
+
export const execute =
|
|
14
|
+
<Model extends ILlmSchema.Model>(
|
|
15
|
+
executor: Partial<IAgenticaExecutor<Model>> | null,
|
|
16
|
+
) =>
|
|
17
|
+
async (ctx: IAgenticaContext<Model>): Promise<IAgenticaPrompt<Model>[]> => {
|
|
18
|
+
const histories: IAgenticaPrompt<Model>[] = [];
|
|
19
|
+
|
|
20
|
+
// FUNCTIONS ARE NOT LISTED YET
|
|
21
|
+
if (ctx.ready() === false) {
|
|
22
|
+
if (executor?.initialize === null) await ctx.initialize();
|
|
23
|
+
else {
|
|
24
|
+
histories.push(
|
|
25
|
+
...(await (
|
|
26
|
+
executor?.initialize ?? ChatGptInitializeFunctionAgent.execute
|
|
27
|
+
)(ctx)),
|
|
28
|
+
);
|
|
29
|
+
if (ctx.ready() === false) return histories;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// CANCEL CANDIDATE FUNCTIONS
|
|
34
|
+
if (ctx.stack.length !== 0)
|
|
35
|
+
histories.push(
|
|
36
|
+
...(await (executor?.cancel ?? ChatGptCancelFunctionAgent.execute)(
|
|
37
|
+
ctx,
|
|
38
|
+
)),
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
// SELECT CANDIDATE FUNCTIONS
|
|
42
|
+
histories.push(
|
|
43
|
+
...(await (executor?.select ?? ChatGptSelectFunctionAgent.execute)(
|
|
44
|
+
ctx,
|
|
45
|
+
)),
|
|
46
|
+
);
|
|
47
|
+
if (ctx.stack.length === 0) return histories;
|
|
48
|
+
|
|
49
|
+
// FUNCTION CALLING LOOP
|
|
50
|
+
while (true) {
|
|
51
|
+
// EXECUTE FUNCTIONS
|
|
52
|
+
const prompts: IAgenticaPrompt<Model>[] = await (
|
|
53
|
+
executor?.call ?? ChatGptCallFunctionAgent.execute
|
|
54
|
+
)(ctx);
|
|
55
|
+
histories.push(...prompts);
|
|
56
|
+
|
|
57
|
+
// EXPLAIN RETURN VALUES
|
|
58
|
+
const executes: IAgenticaPrompt.IExecute<Model>[] = prompts.filter(
|
|
59
|
+
(prompt) => prompt.type === "execute",
|
|
60
|
+
);
|
|
61
|
+
for (const e of executes)
|
|
62
|
+
await ChatGptCancelFunctionAgent.cancelFunction(ctx, {
|
|
63
|
+
reason: "completed",
|
|
64
|
+
name: e.function.name,
|
|
65
|
+
});
|
|
66
|
+
histories.push(
|
|
67
|
+
...(await (
|
|
68
|
+
executor?.describe ?? ChatGptDescribeFunctionAgent.execute
|
|
69
|
+
)(ctx, executes)),
|
|
70
|
+
);
|
|
71
|
+
if (executes.length === 0 || ctx.stack.length === 0) break;
|
|
72
|
+
}
|
|
73
|
+
return histories;
|
|
74
|
+
};
|
|
75
|
+
}
|