@autobe/agent 0.7.3 → 0.9.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.
Files changed (100) hide show
  1. package/lib/AutoBeAgent.d.ts +183 -12
  2. package/lib/AutoBeAgent.js +249 -65
  3. package/lib/AutoBeAgent.js.map +1 -1
  4. package/lib/constants/AutoBeSystemPromptConstant.d.ts +5 -4
  5. package/lib/constants/AutoBeSystemPromptConstant.js.map +1 -1
  6. package/lib/context/AutoBeContext.d.ts +2 -2
  7. package/lib/factory/index.d.ts +0 -1
  8. package/lib/factory/index.js +0 -1
  9. package/lib/factory/index.js.map +1 -1
  10. package/lib/index.mjs +1024 -663
  11. package/lib/index.mjs.map +1 -1
  12. package/lib/orchestrate/analyze/AutoBeAnalyzeAgent.js +7 -8
  13. package/lib/orchestrate/analyze/AutoBeAnalyzeAgent.js.map +1 -1
  14. package/lib/orchestrate/analyze/orchestrateAnalyze.js +2 -5
  15. package/lib/orchestrate/analyze/orchestrateAnalyze.js.map +1 -1
  16. package/lib/orchestrate/interface/orchestrateInterface.js +1 -1
  17. package/lib/orchestrate/interface/orchestrateInterface.js.map +1 -1
  18. package/lib/orchestrate/interface/orchestrateInterfaceComplement.js +6 -8
  19. package/lib/orchestrate/interface/orchestrateInterfaceComplement.js.map +1 -1
  20. package/lib/orchestrate/interface/orchestrateInterfaceComponents.js +9 -6
  21. package/lib/orchestrate/interface/orchestrateInterfaceComponents.js.map +1 -1
  22. package/lib/orchestrate/interface/orchestrateInterfaceEndpoints.js +3 -1
  23. package/lib/orchestrate/interface/orchestrateInterfaceEndpoints.js.map +1 -1
  24. package/lib/orchestrate/interface/orchestrateInterfaceOperations.js +5 -8
  25. package/lib/orchestrate/interface/orchestrateInterfaceOperations.js.map +1 -1
  26. package/lib/orchestrate/prisma/orchestratePrisma.js +1 -1
  27. package/lib/orchestrate/prisma/orchestratePrisma.js.map +1 -1
  28. package/lib/orchestrate/prisma/orchestratePrismaComponent.js +5 -1
  29. package/lib/orchestrate/prisma/orchestratePrismaComponent.js.map +1 -1
  30. package/lib/orchestrate/prisma/orchestratePrismaCorrect.js +3 -6
  31. package/lib/orchestrate/prisma/orchestratePrismaCorrect.js.map +1 -1
  32. package/lib/orchestrate/prisma/orchestratePrismaSchema.js +11 -7
  33. package/lib/orchestrate/prisma/orchestratePrismaSchema.js.map +1 -1
  34. package/lib/orchestrate/prisma/transformPrismaCorrectHistories.js +1 -1
  35. package/lib/orchestrate/prisma/transformPrismaCorrectHistories.js.map +1 -1
  36. package/lib/orchestrate/test/orchestrateTest.js +4 -8
  37. package/lib/orchestrate/test/orchestrateTest.js.map +1 -1
  38. package/lib/orchestrate/test/orchestrateTestCorrect.d.ts +2 -2
  39. package/lib/orchestrate/test/orchestrateTestCorrect.js +90 -60
  40. package/lib/orchestrate/test/orchestrateTestCorrect.js.map +1 -1
  41. package/lib/orchestrate/test/orchestrateTestProgress.d.ts +3 -2
  42. package/lib/orchestrate/test/orchestrateTestProgress.js +75 -50
  43. package/lib/orchestrate/test/orchestrateTestProgress.js.map +1 -1
  44. package/lib/orchestrate/test/orchestrateTestScenario.d.ts +1 -1
  45. package/lib/orchestrate/test/orchestrateTestScenario.js +617 -208
  46. package/lib/orchestrate/test/orchestrateTestScenario.js.map +1 -1
  47. package/lib/orchestrate/test/structures/IAutoBeTestScenarioApplication.d.ts +123 -0
  48. package/lib/orchestrate/test/structures/IAutoBeTestScenarioApplication.js +3 -0
  49. package/lib/orchestrate/test/structures/IAutoBeTestScenarioApplication.js.map +1 -0
  50. package/lib/orchestrate/test/transformTestCorrectHistories.d.ts +2 -1
  51. package/lib/orchestrate/test/transformTestCorrectHistories.js +14 -10
  52. package/lib/orchestrate/test/transformTestCorrectHistories.js.map +1 -1
  53. package/lib/orchestrate/test/transformTestProgressHistories.d.ts +7 -1
  54. package/lib/orchestrate/test/transformTestProgressHistories.js +20 -20
  55. package/lib/orchestrate/test/transformTestProgressHistories.js.map +1 -1
  56. package/lib/orchestrate/test/transformTestScenarioHistories.d.ts +1 -2
  57. package/lib/orchestrate/test/transformTestScenarioHistories.js +1 -77
  58. package/lib/orchestrate/test/transformTestScenarioHistories.js.map +1 -1
  59. package/lib/structures/IAutoBeConfig.d.ts +48 -10
  60. package/lib/structures/IAutoBeProps.d.ts +87 -0
  61. package/lib/structures/IAutoBeVendor.d.ts +64 -22
  62. package/lib/utils/backoffRetry.d.ts +7 -0
  63. package/lib/utils/backoffRetry.js +73 -0
  64. package/lib/utils/backoffRetry.js.map +1 -0
  65. package/lib/utils/enforceToolCall.d.ts +3 -0
  66. package/lib/utils/enforceToolCall.js +13 -0
  67. package/lib/utils/enforceToolCall.js.map +1 -0
  68. package/lib/utils/types/BackoffOptions.d.ts +12 -0
  69. package/lib/utils/types/BackoffOptions.js +3 -0
  70. package/lib/utils/types/BackoffOptions.js.map +1 -0
  71. package/package.json +5 -5
  72. package/src/AutoBeAgent.ts +252 -52
  73. package/src/constants/AutoBeSystemPromptConstant.ts +5 -4
  74. package/src/context/AutoBeContext.ts +7 -2
  75. package/src/factory/index.ts +0 -1
  76. package/src/orchestrate/analyze/AutoBeAnalyzeAgent.ts +5 -10
  77. package/src/orchestrate/analyze/orchestrateAnalyze.ts +2 -6
  78. package/src/orchestrate/interface/orchestrateInterface.ts +1 -1
  79. package/src/orchestrate/interface/orchestrateInterfaceComplement.ts +12 -11
  80. package/src/orchestrate/interface/orchestrateInterfaceComponents.ts +7 -6
  81. package/src/orchestrate/interface/orchestrateInterfaceEndpoints.ts +2 -1
  82. package/src/orchestrate/interface/orchestrateInterfaceOperations.ts +4 -9
  83. package/src/orchestrate/prisma/orchestratePrisma.ts +1 -0
  84. package/src/orchestrate/prisma/orchestratePrismaComponent.ts +4 -1
  85. package/src/orchestrate/prisma/orchestratePrismaCorrect.ts +6 -7
  86. package/src/orchestrate/prisma/orchestratePrismaSchema.ts +10 -7
  87. package/src/orchestrate/test/orchestrateTest.ts +6 -13
  88. package/src/orchestrate/test/orchestrateTestCorrect.ts +127 -78
  89. package/src/orchestrate/test/orchestrateTestProgress.ts +88 -47
  90. package/src/orchestrate/test/orchestrateTestScenario.ts +194 -105
  91. package/src/orchestrate/test/structures/IAutoBeTestScenarioApplication.ts +132 -0
  92. package/src/orchestrate/test/transformTestCorrectHistories.ts +14 -10
  93. package/src/orchestrate/test/transformTestProgressHistories.ts +25 -22
  94. package/src/orchestrate/test/transformTestScenarioHistories.ts +0 -79
  95. package/src/structures/IAutoBeConfig.ts +48 -10
  96. package/src/structures/IAutoBeProps.ts +91 -0
  97. package/src/structures/IAutoBeVendor.ts +64 -22
  98. package/src/utils/backoffRetry.ts +84 -0
  99. package/src/utils/enforceToolCall.ts +13 -0
  100. package/src/utils/types/BackoffOptions.ts +15 -0
@@ -0,0 +1,84 @@
1
+ import { RetryOptions } from "./types/BackoffOptions";
2
+
3
+ /**
4
+ * @param fn Function to Apply the retry logic.
5
+ * @param maxRetries How many time to try. Max Retry is 5.
6
+ * @returns
7
+ */
8
+ export async function randomBackoffRetry<T>(
9
+ fn: () => Promise<T>,
10
+ options: Partial<RetryOptions> = {},
11
+ ): Promise<T> {
12
+ const {
13
+ maxRetries = 5,
14
+ baseDelay = 4_000,
15
+ maxDelay = 60_000,
16
+ jitter = 0.8,
17
+ handleError = isRetryError,
18
+ } = options;
19
+
20
+ let lastError: unknown;
21
+
22
+ for (let attempt = 0; attempt < maxRetries; attempt++) {
23
+ try {
24
+ return await fn();
25
+ } catch (err) {
26
+ lastError = err;
27
+
28
+ if (attempt === maxRetries - 1) throw err;
29
+
30
+ if (!handleError(err)) throw err;
31
+
32
+ const tempDelay = Math.min(baseDelay * 2 ** attempt, maxDelay);
33
+ const delay = tempDelay * (1 + Math.random() * jitter);
34
+
35
+ await new Promise((res) => setTimeout(res, delay));
36
+ }
37
+ }
38
+
39
+ throw lastError;
40
+ }
41
+
42
+ function isRetryError(error: any): boolean {
43
+ // 1) Quota exceeded → No retry
44
+ if (
45
+ error?.code === "insufficient_quota" ||
46
+ error?.error?.type === "insufficient_quota"
47
+ ) {
48
+ return false;
49
+ }
50
+
51
+ // 2) 5xx / server_error → Retry
52
+ if (
53
+ (typeof error?.status === "number" && error.status >= 500) ||
54
+ error?.error?.type === "server_error"
55
+ ) {
56
+ return true;
57
+ }
58
+
59
+ // 3) HTTP 429
60
+ if (error?.status === 429) {
61
+ return true;
62
+ }
63
+
64
+ // 4) undici / network related
65
+ const code = error?.code || error?.cause?.code;
66
+ if (
67
+ [
68
+ "UND_ERR_SOCKET",
69
+ "UND_ERR_CONNECT_TIMEOUT",
70
+ "ETIMEDOUT",
71
+ "ECONNRESET",
72
+ "EPIPE",
73
+ ].includes(code)
74
+ ) {
75
+ return true;
76
+ }
77
+
78
+ // 5) fetch abort
79
+ if (error?.message === "terminated" || error?.name === "AbortError") {
80
+ return true;
81
+ }
82
+
83
+ return false;
84
+ }
@@ -0,0 +1,13 @@
1
+ import { MicroAgentica } from "@agentica/core";
2
+ import { ILlmSchema } from "@samchon/openapi";
3
+
4
+ export function enforceToolCall<Model extends ILlmSchema.Model>(
5
+ agent: MicroAgentica<Model>,
6
+ ): MicroAgentica<Model> {
7
+ agent.on("request", (event) => {
8
+ if (event.body.tools) event.body.tool_choice = "required";
9
+ if (event.body.parallel_tool_calls !== undefined)
10
+ delete event.body.parallel_tool_calls;
11
+ });
12
+ return agent;
13
+ }
@@ -0,0 +1,15 @@
1
+ /*
2
+ * Random exponential backoff retry utility for handling rate limits
3
+ */
4
+ export interface RetryOptions {
5
+ /** Maximum number of retry attempts (default: 5) */
6
+ maxRetries: number;
7
+ /** Base delay in milliseconds (default: 2000) */
8
+ baseDelay: number;
9
+ /** Maximum delay in milliseconds (default: 60_000) */
10
+ maxDelay: number;
11
+ /** Jitter factor for randomization (0-1, default: 0.3) */
12
+ jitter: number;
13
+ /** Function to determine if error should trigger retry (default: isRetryError) */
14
+ handleError: (error: any) => boolean;
15
+ }