@agentica/core 0.8.2 → 0.8.3-dev.20250227

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.
Files changed (53) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +404 -404
  3. package/lib/Agentica.js +1 -4
  4. package/lib/Agentica.js.map +1 -1
  5. package/lib/index.mjs +8 -13
  6. package/lib/index.mjs.map +1 -1
  7. package/lib/internal/AgenticaTokenUsageAggregator.js +7 -9
  8. package/lib/internal/AgenticaTokenUsageAggregator.js.map +1 -1
  9. package/lib/structures/IAgenticaTokenUsage.d.ts +7 -11
  10. package/package.json +1 -1
  11. package/prompts/cancel.md +4 -4
  12. package/prompts/common.md +2 -2
  13. package/prompts/describe.md +6 -6
  14. package/prompts/execute.md +6 -6
  15. package/prompts/initialize.md +2 -2
  16. package/prompts/select.md +6 -6
  17. package/src/Agentica.ts +318 -322
  18. package/src/chatgpt/ChatGptAgent.ts +71 -71
  19. package/src/chatgpt/ChatGptCallFunctionAgent.ts +445 -445
  20. package/src/chatgpt/ChatGptCancelFunctionAgent.ts +283 -283
  21. package/src/chatgpt/ChatGptDescribeFunctionAgent.ts +51 -51
  22. package/src/chatgpt/ChatGptHistoryDecoder.ts +87 -87
  23. package/src/chatgpt/ChatGptInitializeFunctionAgent.ts +88 -88
  24. package/src/chatgpt/ChatGptSelectFunctionAgent.ts +318 -318
  25. package/src/functional/createHttpLlmApplication.ts +63 -63
  26. package/src/index.ts +19 -19
  27. package/src/internal/AgenticaConstant.ts +4 -4
  28. package/src/internal/AgenticaDefaultPrompt.ts +39 -39
  29. package/src/internal/AgenticaOperationComposer.ts +82 -82
  30. package/src/internal/AgenticaPromptFactory.ts +30 -30
  31. package/src/internal/AgenticaPromptTransformer.ts +83 -83
  32. package/src/internal/AgenticaTokenUsageAggregator.ts +115 -123
  33. package/src/internal/MathUtil.ts +3 -3
  34. package/src/internal/Singleton.ts +22 -22
  35. package/src/internal/__map_take.ts +15 -15
  36. package/src/structures/IAgenticaConfig.ts +121 -121
  37. package/src/structures/IAgenticaContext.ts +128 -128
  38. package/src/structures/IAgenticaController.ts +130 -130
  39. package/src/structures/IAgenticaEvent.ts +224 -224
  40. package/src/structures/IAgenticaExecutor.ts +152 -152
  41. package/src/structures/IAgenticaOperation.ts +64 -64
  42. package/src/structures/IAgenticaOperationCollection.ts +50 -50
  43. package/src/structures/IAgenticaOperationSelection.ts +69 -69
  44. package/src/structures/IAgenticaPrompt.ts +173 -173
  45. package/src/structures/IAgenticaProps.ts +64 -64
  46. package/src/structures/IAgenticaProvider.ts +45 -45
  47. package/src/structures/IAgenticaSystemPrompt.ts +122 -122
  48. package/src/structures/IAgenticaTokenUsage.ts +107 -112
  49. package/src/structures/internal/__IChatCancelFunctionsApplication.ts +23 -23
  50. package/src/structures/internal/__IChatFunctionReference.ts +21 -21
  51. package/src/structures/internal/__IChatInitialApplication.ts +15 -15
  52. package/src/structures/internal/__IChatSelectFunctionsApplication.ts +24 -24
  53. package/src/typings/AgenticaSource.ts +6 -6
@@ -1,71 +1,71 @@
1
- import { IAgenticaContext } from "../structures/IAgenticaContext";
2
- import { IAgenticaExecutor } from "../structures/IAgenticaExecutor";
3
- import { IAgenticaPrompt } from "../structures/IAgenticaPrompt";
4
- import { ChatGptCallFunctionAgent } from "./ChatGptCallFunctionAgent";
5
- import { ChatGptCancelFunctionAgent } from "./ChatGptCancelFunctionAgent";
6
- import { ChatGptDescribeFunctionAgent } from "./ChatGptDescribeFunctionAgent";
7
- import { ChatGptInitializeFunctionAgent } from "./ChatGptInitializeFunctionAgent";
8
- import { ChatGptSelectFunctionAgent } from "./ChatGptSelectFunctionAgent";
9
-
10
- export namespace ChatGptAgent {
11
- export const execute =
12
- (executor: Partial<IAgenticaExecutor> | null) =>
13
- async (ctx: IAgenticaContext): Promise<IAgenticaPrompt[]> => {
14
- const histories: IAgenticaPrompt[] = [];
15
-
16
- // FUNCTIONS ARE NOT LISTED YET
17
- if (ctx.ready() === false) {
18
- if (executor?.initialize === null) await ctx.initialize();
19
- else {
20
- histories.push(
21
- ...(await (
22
- executor?.initialize ?? ChatGptInitializeFunctionAgent.execute
23
- )(ctx)),
24
- );
25
- if (ctx.ready() === false) return histories;
26
- }
27
- }
28
-
29
- // CANCEL CANDIDATE FUNCTIONS
30
- if (ctx.stack.length !== 0)
31
- histories.push(
32
- ...(await (executor?.cancel ?? ChatGptCancelFunctionAgent.execute)(
33
- ctx,
34
- )),
35
- );
36
-
37
- // SELECT CANDIDATE FUNCTIONS
38
- histories.push(
39
- ...(await (executor?.select ?? ChatGptSelectFunctionAgent.execute)(
40
- ctx,
41
- )),
42
- );
43
- if (ctx.stack.length === 0) return histories;
44
-
45
- // FUNCTION CALLING LOOP
46
- while (true) {
47
- // EXECUTE FUNCTIONS
48
- const prompts: IAgenticaPrompt[] = await (
49
- executor?.call ?? ChatGptCallFunctionAgent.execute
50
- )(ctx);
51
- histories.push(...prompts);
52
-
53
- // EXPLAIN RETURN VALUES
54
- const executes: IAgenticaPrompt.IExecute[] = prompts.filter(
55
- (prompt) => prompt.type === "execute",
56
- );
57
- for (const e of executes)
58
- await ChatGptCancelFunctionAgent.cancelFunction(ctx, {
59
- reason: "completed",
60
- name: e.function.name,
61
- });
62
- histories.push(
63
- ...(await (
64
- executor?.describe ?? ChatGptDescribeFunctionAgent.execute
65
- )(ctx, executes)),
66
- );
67
- if (executes.length === 0 || ctx.stack.length === 0) break;
68
- }
69
- return histories;
70
- };
71
- }
1
+ import { IAgenticaContext } from "../structures/IAgenticaContext";
2
+ import { IAgenticaExecutor } from "../structures/IAgenticaExecutor";
3
+ import { IAgenticaPrompt } from "../structures/IAgenticaPrompt";
4
+ import { ChatGptCallFunctionAgent } from "./ChatGptCallFunctionAgent";
5
+ import { ChatGptCancelFunctionAgent } from "./ChatGptCancelFunctionAgent";
6
+ import { ChatGptDescribeFunctionAgent } from "./ChatGptDescribeFunctionAgent";
7
+ import { ChatGptInitializeFunctionAgent } from "./ChatGptInitializeFunctionAgent";
8
+ import { ChatGptSelectFunctionAgent } from "./ChatGptSelectFunctionAgent";
9
+
10
+ export namespace ChatGptAgent {
11
+ export const execute =
12
+ (executor: Partial<IAgenticaExecutor> | null) =>
13
+ async (ctx: IAgenticaContext): Promise<IAgenticaPrompt[]> => {
14
+ const histories: IAgenticaPrompt[] = [];
15
+
16
+ // FUNCTIONS ARE NOT LISTED YET
17
+ if (ctx.ready() === false) {
18
+ if (executor?.initialize === null) await ctx.initialize();
19
+ else {
20
+ histories.push(
21
+ ...(await (
22
+ executor?.initialize ?? ChatGptInitializeFunctionAgent.execute
23
+ )(ctx)),
24
+ );
25
+ if (ctx.ready() === false) return histories;
26
+ }
27
+ }
28
+
29
+ // CANCEL CANDIDATE FUNCTIONS
30
+ if (ctx.stack.length !== 0)
31
+ histories.push(
32
+ ...(await (executor?.cancel ?? ChatGptCancelFunctionAgent.execute)(
33
+ ctx,
34
+ )),
35
+ );
36
+
37
+ // SELECT CANDIDATE FUNCTIONS
38
+ histories.push(
39
+ ...(await (executor?.select ?? ChatGptSelectFunctionAgent.execute)(
40
+ ctx,
41
+ )),
42
+ );
43
+ if (ctx.stack.length === 0) return histories;
44
+
45
+ // FUNCTION CALLING LOOP
46
+ while (true) {
47
+ // EXECUTE FUNCTIONS
48
+ const prompts: IAgenticaPrompt[] = await (
49
+ executor?.call ?? ChatGptCallFunctionAgent.execute
50
+ )(ctx);
51
+ histories.push(...prompts);
52
+
53
+ // EXPLAIN RETURN VALUES
54
+ const executes: IAgenticaPrompt.IExecute[] = prompts.filter(
55
+ (prompt) => prompt.type === "execute",
56
+ );
57
+ for (const e of executes)
58
+ await ChatGptCancelFunctionAgent.cancelFunction(ctx, {
59
+ reason: "completed",
60
+ name: e.function.name,
61
+ });
62
+ histories.push(
63
+ ...(await (
64
+ executor?.describe ?? ChatGptDescribeFunctionAgent.execute
65
+ )(ctx, executes)),
66
+ );
67
+ if (executes.length === 0 || ctx.stack.length === 0) break;
68
+ }
69
+ return histories;
70
+ };
71
+ }