@inkeep/agents-run-api 0.31.7 → 0.32.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/README.md +2 -2
- package/dist/{SandboxExecutorFactory-QVNCS6YN.js → SandboxExecutorFactory-D3OSN652.js} +45 -48
- package/dist/{chunk-IMJLQGAX.js → chunk-54Z7AOV4.js} +7 -6
- package/dist/chunk-BYF2SHLS.js +13 -0
- package/dist/chunk-IVALDC72.js +204 -0
- package/dist/{chunk-Z4TYO3W3.js → chunk-N2FZD53W.js} +1 -3
- package/dist/{chunk-DWEFKQTA.js → chunk-YBBSNUL3.js} +1 -1
- package/dist/{conversations-V6DNH5MW.js → conversations-ZZI6XV2G.js} +1 -1
- package/dist/dbClient-XRZSZEYI.js +1 -0
- package/dist/index.cjs +460 -246
- package/dist/index.js +71 -64
- package/dist/instrumentation.cjs +1 -3
- package/dist/instrumentation.js +1 -1
- package/package.json +5 -4
- package/dist/chunk-TRNLEUK2.js +0 -26
- package/dist/dbClient-PLEBWGM4.js +0 -1
package/README.md
CHANGED
|
@@ -44,7 +44,7 @@ pnpm db:migrate
|
|
|
44
44
|
```env
|
|
45
45
|
ENVIRONMENT=development|production|test
|
|
46
46
|
PORT=3003
|
|
47
|
-
|
|
47
|
+
DATABASE_URL=postgresql://dbuser:secretpassword@database.server.com:3211/mydb
|
|
48
48
|
ANTHROPIC_API_KEY=required
|
|
49
49
|
OPENAI_API_KEY=optional
|
|
50
50
|
LOG_LEVEL=debug|info|warn|error
|
|
@@ -73,7 +73,7 @@ pnpm test src/__tests__/a2a/ # Run A2A-specific tests
|
|
|
73
73
|
|
|
74
74
|
The API uses environment-based configuration with defaults for local development. Key configuration areas:
|
|
75
75
|
|
|
76
|
-
- **Database**:
|
|
76
|
+
- **Database**: PostgreSQL connection via `DATABASE_URL`
|
|
77
77
|
- **AI Models**: Anthropic and OpenAI API keys
|
|
78
78
|
- **Observability**: OpenTelemetry tracing support
|
|
79
79
|
- **CORS**: Configurable for web clients
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { getLogger
|
|
1
|
+
import { getLogger } from './chunk-A2S7GSHL.js';
|
|
2
|
+
import { FUNCTION_TOOL_SANDBOX_POOL_TTL_MS, FUNCTION_TOOL_SANDBOX_MAX_USE_COUNT, FUNCTION_TOOL_SANDBOX_CLEANUP_INTERVAL_MS, FUNCTION_TOOL_EXECUTION_TIMEOUT_MS_DEFAULT, FUNCTION_TOOL_SANDBOX_MAX_OUTPUT_SIZE_BYTES, FUNCTION_TOOL_SANDBOX_QUEUE_WAIT_TIMEOUT_MS } from './chunk-IVALDC72.js';
|
|
2
3
|
import { __publicField } from './chunk-PKBMQBKP.js';
|
|
3
4
|
import { spawn } from 'child_process';
|
|
4
5
|
import crypto, { createHash } from 'crypto';
|
|
5
6
|
import { mkdirSync, existsSync, rmSync, writeFileSync } from 'fs';
|
|
6
7
|
import { tmpdir } from 'os';
|
|
7
8
|
import { join } from 'path';
|
|
8
|
-
import { getLogger } from '@inkeep/agents-core';
|
|
9
9
|
import { Sandbox } from '@vercel/sandbox';
|
|
10
10
|
|
|
11
11
|
// src/tools/sandbox-utils.ts
|
|
@@ -56,7 +56,7 @@ function parseExecutionResult(stdout, functionId, logger4) {
|
|
|
56
56
|
// src/tools/NativeSandboxExecutor.ts
|
|
57
57
|
var logger = getLogger("native-sandbox-executor");
|
|
58
58
|
var ExecutionSemaphore = class {
|
|
59
|
-
constructor(permits, maxWaitTimeMs =
|
|
59
|
+
constructor(permits, maxWaitTimeMs = FUNCTION_TOOL_SANDBOX_QUEUE_WAIT_TIMEOUT_MS) {
|
|
60
60
|
__publicField(this, "permits");
|
|
61
61
|
__publicField(this, "waitQueue", []);
|
|
62
62
|
__publicField(this, "maxWaitTime");
|
|
@@ -111,9 +111,6 @@ var _NativeSandboxExecutor = class _NativeSandboxExecutor {
|
|
|
111
111
|
constructor() {
|
|
112
112
|
__publicField(this, "tempDir");
|
|
113
113
|
__publicField(this, "sandboxPool", {});
|
|
114
|
-
__publicField(this, "POOL_TTL", 5 * 60 * 1e3);
|
|
115
|
-
// 5 minutes
|
|
116
|
-
__publicField(this, "MAX_USE_COUNT", 50);
|
|
117
114
|
__publicField(this, "executionSemaphores", /* @__PURE__ */ new Map());
|
|
118
115
|
this.tempDir = join(tmpdir(), "inkeep-sandboxes");
|
|
119
116
|
this.ensureTempDir();
|
|
@@ -162,7 +159,7 @@ var _NativeSandboxExecutor = class _NativeSandboxExecutor {
|
|
|
162
159
|
const sandbox = this.sandboxPool[poolKey];
|
|
163
160
|
if (sandbox && existsSync(sandbox.sandboxDir)) {
|
|
164
161
|
const now = Date.now();
|
|
165
|
-
if (now - sandbox.lastUsed <
|
|
162
|
+
if (now - sandbox.lastUsed < FUNCTION_TOOL_SANDBOX_POOL_TTL_MS && sandbox.useCount < FUNCTION_TOOL_SANDBOX_MAX_USE_COUNT) {
|
|
166
163
|
sandbox.lastUsed = now;
|
|
167
164
|
sandbox.useCount++;
|
|
168
165
|
logger.debug(
|
|
@@ -170,7 +167,7 @@ var _NativeSandboxExecutor = class _NativeSandboxExecutor {
|
|
|
170
167
|
poolKey,
|
|
171
168
|
useCount: sandbox.useCount,
|
|
172
169
|
sandboxDir: sandbox.sandboxDir,
|
|
173
|
-
lastUsed: new Date(sandbox.lastUsed)
|
|
170
|
+
lastUsed: new Date(sandbox.lastUsed)
|
|
174
171
|
},
|
|
175
172
|
"Reusing cached sandbox"
|
|
176
173
|
);
|
|
@@ -208,7 +205,7 @@ var _NativeSandboxExecutor = class _NativeSandboxExecutor {
|
|
|
208
205
|
const now = Date.now();
|
|
209
206
|
const keysToDelete = [];
|
|
210
207
|
for (const [key, sandbox] of Object.entries(this.sandboxPool)) {
|
|
211
|
-
if (now - sandbox.lastUsed >
|
|
208
|
+
if (now - sandbox.lastUsed > FUNCTION_TOOL_SANDBOX_POOL_TTL_MS || sandbox.useCount >= FUNCTION_TOOL_SANDBOX_MAX_USE_COUNT) {
|
|
212
209
|
this.cleanupSandbox(sandbox.sandboxDir);
|
|
213
210
|
keysToDelete.push(key);
|
|
214
211
|
}
|
|
@@ -219,7 +216,7 @@ var _NativeSandboxExecutor = class _NativeSandboxExecutor {
|
|
|
219
216
|
if (keysToDelete.length > 0) {
|
|
220
217
|
logger.debug({ cleanedCount: keysToDelete.length }, "Cleaned up expired sandboxes");
|
|
221
218
|
}
|
|
222
|
-
},
|
|
219
|
+
}, FUNCTION_TOOL_SANDBOX_CLEANUP_INTERVAL_MS);
|
|
223
220
|
}
|
|
224
221
|
detectModuleType(executeCode, configuredRuntime) {
|
|
225
222
|
const esmPatterns = [
|
|
@@ -329,7 +326,7 @@ var _NativeSandboxExecutor = class _NativeSandboxExecutor {
|
|
|
329
326
|
writeFileSync(join(sandboxDir, `index.${fileExtension}`), executionCode, "utf8");
|
|
330
327
|
const result = await this.executeInSandbox(
|
|
331
328
|
sandboxDir,
|
|
332
|
-
config.sandboxConfig?.timeout ||
|
|
329
|
+
config.sandboxConfig?.timeout || FUNCTION_TOOL_EXECUTION_TIMEOUT_MS_DEFAULT,
|
|
333
330
|
moduleType,
|
|
334
331
|
config.sandboxConfig
|
|
335
332
|
);
|
|
@@ -394,13 +391,16 @@ var _NativeSandboxExecutor = class _NativeSandboxExecutor {
|
|
|
394
391
|
let stdout = "";
|
|
395
392
|
let stderr = "";
|
|
396
393
|
let outputSize = 0;
|
|
397
|
-
const MAX_OUTPUT_SIZE = 1024 * 1024;
|
|
398
394
|
node.stdout?.on("data", (data) => {
|
|
399
395
|
const dataStr = data.toString();
|
|
400
396
|
outputSize += dataStr.length;
|
|
401
|
-
if (outputSize >
|
|
397
|
+
if (outputSize > FUNCTION_TOOL_SANDBOX_MAX_OUTPUT_SIZE_BYTES) {
|
|
402
398
|
node.kill("SIGTERM");
|
|
403
|
-
reject(
|
|
399
|
+
reject(
|
|
400
|
+
new Error(
|
|
401
|
+
`Output size exceeded limit of ${FUNCTION_TOOL_SANDBOX_MAX_OUTPUT_SIZE_BYTES} bytes`
|
|
402
|
+
)
|
|
403
|
+
);
|
|
404
404
|
return;
|
|
405
405
|
}
|
|
406
406
|
stdout += dataStr;
|
|
@@ -408,9 +408,13 @@ var _NativeSandboxExecutor = class _NativeSandboxExecutor {
|
|
|
408
408
|
node.stderr?.on("data", (data) => {
|
|
409
409
|
const dataStr = data.toString();
|
|
410
410
|
outputSize += dataStr.length;
|
|
411
|
-
if (outputSize >
|
|
411
|
+
if (outputSize > FUNCTION_TOOL_SANDBOX_MAX_OUTPUT_SIZE_BYTES) {
|
|
412
412
|
node.kill("SIGTERM");
|
|
413
|
-
reject(
|
|
413
|
+
reject(
|
|
414
|
+
new Error(
|
|
415
|
+
`Output size exceeded limit of ${FUNCTION_TOOL_SANDBOX_MAX_OUTPUT_SIZE_BYTES} bytes`
|
|
416
|
+
)
|
|
417
|
+
);
|
|
414
418
|
return;
|
|
415
419
|
}
|
|
416
420
|
stderr += dataStr;
|
|
@@ -462,14 +466,11 @@ var _NativeSandboxExecutor = class _NativeSandboxExecutor {
|
|
|
462
466
|
};
|
|
463
467
|
__publicField(_NativeSandboxExecutor, "instance", null);
|
|
464
468
|
var NativeSandboxExecutor = _NativeSandboxExecutor;
|
|
465
|
-
var logger2 = getLogger
|
|
469
|
+
var logger2 = getLogger("VercelSandboxExecutor");
|
|
466
470
|
var _VercelSandboxExecutor = class _VercelSandboxExecutor {
|
|
467
471
|
constructor(config) {
|
|
468
472
|
__publicField(this, "config");
|
|
469
473
|
__publicField(this, "sandboxPool", /* @__PURE__ */ new Map());
|
|
470
|
-
__publicField(this, "POOL_TTL", 5 * 60 * 1e3);
|
|
471
|
-
// 5 minutes
|
|
472
|
-
__publicField(this, "MAX_USE_COUNT", 50);
|
|
473
474
|
__publicField(this, "cleanupInterval", null);
|
|
474
475
|
this.config = config;
|
|
475
476
|
logger2.info(
|
|
@@ -508,14 +509,14 @@ var _VercelSandboxExecutor = class _VercelSandboxExecutor {
|
|
|
508
509
|
if (!cached) return null;
|
|
509
510
|
const now = Date.now();
|
|
510
511
|
const age = now - cached.createdAt;
|
|
511
|
-
if (age >
|
|
512
|
+
if (age > FUNCTION_TOOL_SANDBOX_POOL_TTL_MS || cached.useCount >= FUNCTION_TOOL_SANDBOX_MAX_USE_COUNT) {
|
|
512
513
|
logger2.debug(
|
|
513
514
|
{
|
|
514
515
|
dependencyHash,
|
|
515
516
|
age,
|
|
516
517
|
useCount: cached.useCount,
|
|
517
|
-
ttl:
|
|
518
|
-
maxUseCount:
|
|
518
|
+
ttl: FUNCTION_TOOL_SANDBOX_POOL_TTL_MS,
|
|
519
|
+
maxUseCount: FUNCTION_TOOL_SANDBOX_MAX_USE_COUNT
|
|
519
520
|
},
|
|
520
521
|
"Sandbox expired, will create new one"
|
|
521
522
|
);
|
|
@@ -578,32 +579,28 @@ var _VercelSandboxExecutor = class _VercelSandboxExecutor {
|
|
|
578
579
|
* Start periodic cleanup of expired sandboxes
|
|
579
580
|
*/
|
|
580
581
|
startPoolCleanup() {
|
|
581
|
-
this.cleanupInterval = setInterval(
|
|
582
|
-
()
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
toRemove.push(hash);
|
|
589
|
-
}
|
|
582
|
+
this.cleanupInterval = setInterval(() => {
|
|
583
|
+
const now = Date.now();
|
|
584
|
+
const toRemove = [];
|
|
585
|
+
for (const [hash, cached] of this.sandboxPool.entries()) {
|
|
586
|
+
const age = now - cached.createdAt;
|
|
587
|
+
if (age > FUNCTION_TOOL_SANDBOX_POOL_TTL_MS || cached.useCount >= FUNCTION_TOOL_SANDBOX_MAX_USE_COUNT) {
|
|
588
|
+
toRemove.push(hash);
|
|
590
589
|
}
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
590
|
+
}
|
|
591
|
+
if (toRemove.length > 0) {
|
|
592
|
+
logger2.info(
|
|
593
|
+
{
|
|
594
|
+
count: toRemove.length,
|
|
595
|
+
poolSize: this.sandboxPool.size
|
|
596
|
+
},
|
|
597
|
+
"Cleaning up expired sandboxes"
|
|
598
|
+
);
|
|
599
|
+
for (const hash of toRemove) {
|
|
600
|
+
this.removeSandbox(hash);
|
|
602
601
|
}
|
|
603
|
-
}
|
|
604
|
-
|
|
605
|
-
// Run every minute
|
|
606
|
-
);
|
|
602
|
+
}
|
|
603
|
+
}, FUNCTION_TOOL_SANDBOX_CLEANUP_INTERVAL_MS);
|
|
607
604
|
}
|
|
608
605
|
/**
|
|
609
606
|
* Cleanup all sandboxes and stop cleanup interval
|
|
@@ -863,7 +860,7 @@ __publicField(_VercelSandboxExecutor, "instance");
|
|
|
863
860
|
var VercelSandboxExecutor = _VercelSandboxExecutor;
|
|
864
861
|
|
|
865
862
|
// src/tools/SandboxExecutorFactory.ts
|
|
866
|
-
var logger3 = getLogger
|
|
863
|
+
var logger3 = getLogger("SandboxExecutorFactory");
|
|
867
864
|
var _SandboxExecutorFactory = class _SandboxExecutorFactory {
|
|
868
865
|
constructor() {
|
|
869
866
|
__publicField(this, "nativeExecutor", null);
|
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
import { dbClient_default } from './chunk-
|
|
2
|
-
import {
|
|
1
|
+
import { dbClient_default } from './chunk-BYF2SHLS.js';
|
|
2
|
+
import { CONVERSATION_HISTORY_DEFAULT_LIMIT } from './chunk-IVALDC72.js';
|
|
3
|
+
import { CONVERSATION_HISTORY_MAX_OUTPUT_TOKENS_DEFAULT, createMessage, generateId, getConversationHistory } from '@inkeep/agents-core';
|
|
3
4
|
|
|
4
5
|
function createDefaultConversationHistoryConfig(mode = "full") {
|
|
5
6
|
return {
|
|
6
7
|
mode,
|
|
7
|
-
limit:
|
|
8
|
+
limit: CONVERSATION_HISTORY_DEFAULT_LIMIT,
|
|
8
9
|
includeInternal: true,
|
|
9
10
|
messageTypes: ["chat"],
|
|
10
|
-
maxOutputTokens:
|
|
11
|
+
maxOutputTokens: CONVERSATION_HISTORY_MAX_OUTPUT_TOKENS_DEFAULT
|
|
11
12
|
};
|
|
12
13
|
}
|
|
13
14
|
function extractA2AMessageText(parts) {
|
|
@@ -96,7 +97,7 @@ async function getScopedHistory({
|
|
|
96
97
|
return [];
|
|
97
98
|
}
|
|
98
99
|
}
|
|
99
|
-
async function getUserFacingHistory(tenantId, projectId, conversationId, limit =
|
|
100
|
+
async function getUserFacingHistory(tenantId, projectId, conversationId, limit = CONVERSATION_HISTORY_DEFAULT_LIMIT) {
|
|
100
101
|
return await getConversationHistory(dbClient_default)({
|
|
101
102
|
scopes: { tenantId, projectId },
|
|
102
103
|
conversationId,
|
|
@@ -190,7 +191,7 @@ async function getConversationScopedArtifacts(params) {
|
|
|
190
191
|
return [];
|
|
191
192
|
}
|
|
192
193
|
const { getLedgerArtifacts } = await import('@inkeep/agents-core');
|
|
193
|
-
const dbClient = (await import('./dbClient-
|
|
194
|
+
const dbClient = (await import('./dbClient-XRZSZEYI.js')).default;
|
|
194
195
|
const visibleTaskIds = visibleMessages.map((msg) => msg.taskId).filter((taskId) => Boolean(taskId));
|
|
195
196
|
const referenceArtifacts = [];
|
|
196
197
|
for (const taskId of visibleTaskIds) {
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { env } from './chunk-N2FZD53W.js';
|
|
2
|
+
import { createDatabaseClient } from '@inkeep/agents-core';
|
|
3
|
+
|
|
4
|
+
var getDbConfig = () => {
|
|
5
|
+
if (env.ENVIRONMENT === "test") {
|
|
6
|
+
return {};
|
|
7
|
+
}
|
|
8
|
+
return { connectionString: env.DATABASE_URL };
|
|
9
|
+
};
|
|
10
|
+
var dbClient = createDatabaseClient(getDbConfig());
|
|
11
|
+
var dbClient_default = dbClient;
|
|
12
|
+
|
|
13
|
+
export { dbClient_default };
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
import { loadEnvironmentFiles } from '@inkeep/agents-core';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
// src/constants/execution-limits/index.ts
|
|
5
|
+
|
|
6
|
+
// src/constants/execution-limits/defaults.ts
|
|
7
|
+
var executionLimitsDefaults = {
|
|
8
|
+
// Sub Agent Turn Execution
|
|
9
|
+
// During a Sub Agent's turn, it makes decisions by calling the LLM (language model). Each decision
|
|
10
|
+
// point is called a "generation step" - for example, deciding to call a tool, transfer to another
|
|
11
|
+
// Sub Agent, delegate a subtask, or send a response to the user.
|
|
12
|
+
// AGENT_EXECUTION_MAX_CONSECUTIVE_ERRORS: Maximum errors tolerated during a single Sub Agent's turn before stopping execution
|
|
13
|
+
// AGENT_EXECUTION_MAX_GENERATION_STEPS: Maximum LLM inference calls allowed within a single Sub Agent turn
|
|
14
|
+
AGENT_EXECUTION_MAX_CONSECUTIVE_ERRORS: 3,
|
|
15
|
+
AGENT_EXECUTION_MAX_GENERATION_STEPS: 5,
|
|
16
|
+
// Sub Agent Decision-Making Timeouts
|
|
17
|
+
// These control how long to wait for the LLM to make decisions during a Sub Agent's turn.
|
|
18
|
+
// "First call" = initial decision at start of turn (may include tool results from previous actions)
|
|
19
|
+
// "Subsequent call" = follow-up decisions after executing tools within the same turn
|
|
20
|
+
// Streaming mode has longer timeout because it waits for the full streamed response to the user
|
|
21
|
+
// LLM_GENERATION_FIRST_CALL_TIMEOUT_MS_STREAMING: Timeout for initial streaming response to user
|
|
22
|
+
// LLM_GENERATION_FIRST_CALL_TIMEOUT_MS_NON_STREAMING: Timeout for initial non-streaming (internal) decision
|
|
23
|
+
// LLM_GENERATION_SUBSEQUENT_CALL_TIMEOUT_MS: Timeout for follow-up decisions after tool execution
|
|
24
|
+
// LLM_GENERATION_MAX_ALLOWED_TIMEOUT_MS: Maximum timeout allowed regardless of configuration
|
|
25
|
+
LLM_GENERATION_FIRST_CALL_TIMEOUT_MS_STREAMING: 27e4,
|
|
26
|
+
// 4.5 minutes
|
|
27
|
+
LLM_GENERATION_FIRST_CALL_TIMEOUT_MS_NON_STREAMING: 9e4,
|
|
28
|
+
// 1.5 minutes
|
|
29
|
+
LLM_GENERATION_SUBSEQUENT_CALL_TIMEOUT_MS: 9e4,
|
|
30
|
+
// 1.5 minutes
|
|
31
|
+
LLM_GENERATION_MAX_ALLOWED_TIMEOUT_MS: 6e5,
|
|
32
|
+
// 10 minutes
|
|
33
|
+
// Function Tool Execution (Sandboxed Environments)
|
|
34
|
+
// Function Tools are custom JavaScript functions that Sub Agents can call. They run in secure
|
|
35
|
+
// isolated sandboxes (containerized environments) to prevent malicious code execution.
|
|
36
|
+
// For performance, sandboxes are cached and reused across multiple tool calls until they expire.
|
|
37
|
+
// FUNCTION_TOOL_EXECUTION_TIMEOUT_MS_DEFAULT: Maximum execution time for a Function Tool call
|
|
38
|
+
// FUNCTION_TOOL_SANDBOX_VCPUS_DEFAULT: Virtual CPUs allocated to each sandbox (affects compute capacity)
|
|
39
|
+
// FUNCTION_TOOL_SANDBOX_POOL_TTL_MS: Time-to-live for cached sandboxes (after this, sandbox is discarded)
|
|
40
|
+
// FUNCTION_TOOL_SANDBOX_MAX_USE_COUNT: Maximum reuses of a sandbox before it's refreshed (prevents resource leaks)
|
|
41
|
+
// FUNCTION_TOOL_SANDBOX_MAX_OUTPUT_SIZE_BYTES: Maximum size of Function Tool output (prevents memory exhaustion)
|
|
42
|
+
// FUNCTION_TOOL_SANDBOX_QUEUE_WAIT_TIMEOUT_MS: Maximum wait time for sandbox to become available when pool is full
|
|
43
|
+
// FUNCTION_TOOL_SANDBOX_CLEANUP_INTERVAL_MS: How often to check for and remove expired sandboxes from the pool
|
|
44
|
+
FUNCTION_TOOL_EXECUTION_TIMEOUT_MS_DEFAULT: 3e4,
|
|
45
|
+
// 30 seconds
|
|
46
|
+
FUNCTION_TOOL_SANDBOX_VCPUS_DEFAULT: 4,
|
|
47
|
+
FUNCTION_TOOL_SANDBOX_POOL_TTL_MS: 3e5,
|
|
48
|
+
// 5 minutes
|
|
49
|
+
FUNCTION_TOOL_SANDBOX_MAX_USE_COUNT: 50,
|
|
50
|
+
FUNCTION_TOOL_SANDBOX_MAX_OUTPUT_SIZE_BYTES: 1048576,
|
|
51
|
+
// 1 MB
|
|
52
|
+
FUNCTION_TOOL_SANDBOX_QUEUE_WAIT_TIMEOUT_MS: 3e4,
|
|
53
|
+
// 30 seconds
|
|
54
|
+
FUNCTION_TOOL_SANDBOX_CLEANUP_INTERVAL_MS: 6e4,
|
|
55
|
+
// 1 minute
|
|
56
|
+
// MCP Tool Execution
|
|
57
|
+
// MCP (Model Context Protocol) Servers are external services that provide tools to Sub Agents.
|
|
58
|
+
// When a Sub Agent calls an MCP Tool, the request is sent to the external MCP Server.
|
|
59
|
+
// Note: MCP connection/retry constants are defined in @inkeep/agents-core/constants/execution-limits-shared
|
|
60
|
+
// MCP_TOOL_REQUEST_TIMEOUT_MS_DEFAULT: Maximum wait time for an MCP tool call to complete
|
|
61
|
+
MCP_TOOL_REQUEST_TIMEOUT_MS_DEFAULT: 6e4,
|
|
62
|
+
// 60 seconds
|
|
63
|
+
// Sub Agent Delegation (Retry Strategy)
|
|
64
|
+
// When a Sub Agent delegates a subtask to another Sub Agent, it uses the A2A (Agent-to-Agent)
|
|
65
|
+
// protocol to communicate. If the delegation request fails, these constants control the
|
|
66
|
+
// exponential backoff retry strategy. Formula: delay = min(INITIAL * EXPONENT^attempt, MAX)
|
|
67
|
+
// DELEGATION_TOOL_BACKOFF_INITIAL_INTERVAL_MS: Starting delay before first retry
|
|
68
|
+
// DELEGATION_TOOL_BACKOFF_MAX_INTERVAL_MS: Maximum delay between retries (caps exponential growth)
|
|
69
|
+
// DELEGATION_TOOL_BACKOFF_EXPONENT: Multiplier applied to delay after each retry (2 = doubles each time)
|
|
70
|
+
// DELEGATION_TOOL_BACKOFF_MAX_ELAPSED_TIME_MS: Total time to keep retrying before giving up
|
|
71
|
+
DELEGATION_TOOL_BACKOFF_INITIAL_INTERVAL_MS: 100,
|
|
72
|
+
DELEGATION_TOOL_BACKOFF_MAX_INTERVAL_MS: 1e4,
|
|
73
|
+
// 10 seconds
|
|
74
|
+
DELEGATION_TOOL_BACKOFF_EXPONENT: 2,
|
|
75
|
+
DELEGATION_TOOL_BACKOFF_MAX_ELAPSED_TIME_MS: 2e4,
|
|
76
|
+
// 20 seconds
|
|
77
|
+
// General Agent-to-Agent (A2A) Communication (Retry Strategy)
|
|
78
|
+
// These control retries for broader A2A protocol operations beyond delegation (e.g., status checks,
|
|
79
|
+
// conversation updates). Uses more conservative retry parameters than delegation-specific retries.
|
|
80
|
+
// A2A_BACKOFF_INITIAL_INTERVAL_MS: Starting delay before first retry
|
|
81
|
+
// A2A_BACKOFF_MAX_INTERVAL_MS: Maximum delay between retries
|
|
82
|
+
// A2A_BACKOFF_EXPONENT: Multiplier for exponential backoff (1.5 = grows 50% each retry)
|
|
83
|
+
// A2A_BACKOFF_MAX_ELAPSED_TIME_MS: Total time to keep retrying before giving up
|
|
84
|
+
A2A_BACKOFF_INITIAL_INTERVAL_MS: 500,
|
|
85
|
+
A2A_BACKOFF_MAX_INTERVAL_MS: 6e4,
|
|
86
|
+
// 1 minute
|
|
87
|
+
A2A_BACKOFF_EXPONENT: 1.5,
|
|
88
|
+
A2A_BACKOFF_MAX_ELAPSED_TIME_MS: 3e4,
|
|
89
|
+
// 30 seconds
|
|
90
|
+
// Artifact Processing
|
|
91
|
+
// Artifacts are tool outputs saved for later reference by Sub Agents or users. When a tool generates
|
|
92
|
+
// an artifact, the system automatically generates a human-readable name and description using the LLM.
|
|
93
|
+
// These constants control artifact name/description generation and context window management.
|
|
94
|
+
// ARTIFACT_GENERATION_MAX_RETRIES: Retry attempts for LLM-based artifact name/description generation
|
|
95
|
+
// ARTIFACT_SESSION_MAX_PENDING: Maximum unprocessed artifacts in queue (prevents unbounded growth)
|
|
96
|
+
// ARTIFACT_SESSION_MAX_PREVIOUS_SUMMARIES: Historical artifact summaries kept in context for reference
|
|
97
|
+
// ARTIFACT_GENERATION_BACKOFF_INITIAL_MS: Starting delay for retry backoff when generation fails
|
|
98
|
+
// ARTIFACT_GENERATION_BACKOFF_MAX_MS: Maximum delay between retries (formula: min(INITIAL * 2^attempt, MAX))
|
|
99
|
+
ARTIFACT_GENERATION_MAX_RETRIES: 3,
|
|
100
|
+
ARTIFACT_SESSION_MAX_PENDING: 100,
|
|
101
|
+
ARTIFACT_SESSION_MAX_PREVIOUS_SUMMARIES: 3,
|
|
102
|
+
ARTIFACT_GENERATION_BACKOFF_INITIAL_MS: 1e3,
|
|
103
|
+
// 1 second
|
|
104
|
+
ARTIFACT_GENERATION_BACKOFF_MAX_MS: 1e4,
|
|
105
|
+
// 10 seconds
|
|
106
|
+
// Conversation Session & Cache Management
|
|
107
|
+
// A "session" represents the state of an ongoing conversation with an Agent. Tool results are cached
|
|
108
|
+
// within the session for performance - this is especially important for artifact processing where the
|
|
109
|
+
// same tool outputs may be referenced multiple times across Sub Agent turns.
|
|
110
|
+
// SESSION_TOOL_RESULT_CACHE_TIMEOUT_MS: How long tool results are kept in cache before expiring
|
|
111
|
+
// SESSION_CLEANUP_INTERVAL_MS: How often to check for and remove expired cached tool results
|
|
112
|
+
SESSION_TOOL_RESULT_CACHE_TIMEOUT_MS: 3e5,
|
|
113
|
+
// 5 minutes
|
|
114
|
+
SESSION_CLEANUP_INTERVAL_MS: 6e4,
|
|
115
|
+
// 1 minute
|
|
116
|
+
// Status Updates
|
|
117
|
+
// Status Updates are real-time progress messages sent to users during longer Sub Agent operations.
|
|
118
|
+
// The system automatically generates status updates based on activity thresholds - either after a
|
|
119
|
+
// certain number of significant events OR after a time interval (whichever comes first).
|
|
120
|
+
// Events include: tool calls, Sub Agent transfers, delegations, or other significant activities.
|
|
121
|
+
// STATUS_UPDATE_DEFAULT_NUM_EVENTS: Number of significant events before triggering a status update
|
|
122
|
+
// STATUS_UPDATE_DEFAULT_INTERVAL_SECONDS: Time interval (in seconds) before generating status update
|
|
123
|
+
STATUS_UPDATE_DEFAULT_NUM_EVENTS: 1,
|
|
124
|
+
STATUS_UPDATE_DEFAULT_INTERVAL_SECONDS: 2,
|
|
125
|
+
// Response Streaming (Internal Buffering Limits)
|
|
126
|
+
// These are internal infrastructure limits for streaming responses to users. Streaming enables
|
|
127
|
+
// real-time updates as Sub Agents generate responses, Data Components, and Status Updates.
|
|
128
|
+
// STREAM_PARSER_MAX_SNAPSHOT_SIZE: Maximum Data Component snapshots buffered before clearing old ones
|
|
129
|
+
// STREAM_PARSER_MAX_STREAMED_SIZE: Maximum streamed component IDs tracked simultaneously
|
|
130
|
+
// STREAM_PARSER_MAX_COLLECTED_PARTS: Maximum accumulated stream parts before forcing flush
|
|
131
|
+
// STREAM_BUFFER_MAX_SIZE_BYTES: Maximum total buffer size in bytes (prevents memory exhaustion)
|
|
132
|
+
// STREAM_TEXT_GAP_THRESHOLD_MS: Time gap that triggers bundling text with artifact data vs separate send
|
|
133
|
+
// STREAM_MAX_LIFETIME_MS: Maximum duration a stream can stay open before forced closure
|
|
134
|
+
STREAM_PARSER_MAX_SNAPSHOT_SIZE: 100,
|
|
135
|
+
STREAM_PARSER_MAX_STREAMED_SIZE: 1e3,
|
|
136
|
+
STREAM_PARSER_MAX_COLLECTED_PARTS: 1e4,
|
|
137
|
+
STREAM_BUFFER_MAX_SIZE_BYTES: 5242880,
|
|
138
|
+
// 5 MB
|
|
139
|
+
STREAM_TEXT_GAP_THRESHOLD_MS: 2e3,
|
|
140
|
+
// 2 seconds
|
|
141
|
+
STREAM_MAX_LIFETIME_MS: 6e5,
|
|
142
|
+
// 10 minutes
|
|
143
|
+
// Conversation History Message Retrieval
|
|
144
|
+
// CONVERSATION_HISTORY_DEFAULT_LIMIT: Default number of recent conversation messages to retrieve
|
|
145
|
+
CONVERSATION_HISTORY_DEFAULT_LIMIT: 50
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
// src/constants/execution-limits/index.ts
|
|
149
|
+
loadEnvironmentFiles();
|
|
150
|
+
var constantsSchema = z.object(
|
|
151
|
+
Object.fromEntries(
|
|
152
|
+
Object.keys(executionLimitsDefaults).map((key) => [
|
|
153
|
+
`AGENTS_${key}`,
|
|
154
|
+
z.coerce.number().optional()
|
|
155
|
+
])
|
|
156
|
+
)
|
|
157
|
+
);
|
|
158
|
+
var parseConstants = () => {
|
|
159
|
+
const envOverrides = constantsSchema.parse(process.env);
|
|
160
|
+
return Object.fromEntries(
|
|
161
|
+
Object.entries(executionLimitsDefaults).map(([key, defaultValue]) => [
|
|
162
|
+
key,
|
|
163
|
+
envOverrides[`AGENTS_${key}`] ?? defaultValue
|
|
164
|
+
])
|
|
165
|
+
);
|
|
166
|
+
};
|
|
167
|
+
var constants = parseConstants();
|
|
168
|
+
var {
|
|
169
|
+
AGENT_EXECUTION_MAX_CONSECUTIVE_ERRORS,
|
|
170
|
+
AGENT_EXECUTION_MAX_GENERATION_STEPS,
|
|
171
|
+
LLM_GENERATION_FIRST_CALL_TIMEOUT_MS_STREAMING,
|
|
172
|
+
LLM_GENERATION_FIRST_CALL_TIMEOUT_MS_NON_STREAMING,
|
|
173
|
+
LLM_GENERATION_SUBSEQUENT_CALL_TIMEOUT_MS,
|
|
174
|
+
LLM_GENERATION_MAX_ALLOWED_TIMEOUT_MS,
|
|
175
|
+
FUNCTION_TOOL_EXECUTION_TIMEOUT_MS_DEFAULT,
|
|
176
|
+
FUNCTION_TOOL_SANDBOX_VCPUS_DEFAULT,
|
|
177
|
+
FUNCTION_TOOL_SANDBOX_POOL_TTL_MS,
|
|
178
|
+
FUNCTION_TOOL_SANDBOX_MAX_USE_COUNT,
|
|
179
|
+
FUNCTION_TOOL_SANDBOX_MAX_OUTPUT_SIZE_BYTES,
|
|
180
|
+
FUNCTION_TOOL_SANDBOX_QUEUE_WAIT_TIMEOUT_MS,
|
|
181
|
+
FUNCTION_TOOL_SANDBOX_CLEANUP_INTERVAL_MS,
|
|
182
|
+
DELEGATION_TOOL_BACKOFF_INITIAL_INTERVAL_MS,
|
|
183
|
+
DELEGATION_TOOL_BACKOFF_MAX_INTERVAL_MS,
|
|
184
|
+
DELEGATION_TOOL_BACKOFF_EXPONENT,
|
|
185
|
+
DELEGATION_TOOL_BACKOFF_MAX_ELAPSED_TIME_MS,
|
|
186
|
+
ARTIFACT_GENERATION_MAX_RETRIES,
|
|
187
|
+
ARTIFACT_SESSION_MAX_PENDING,
|
|
188
|
+
ARTIFACT_SESSION_MAX_PREVIOUS_SUMMARIES,
|
|
189
|
+
ARTIFACT_GENERATION_BACKOFF_INITIAL_MS,
|
|
190
|
+
ARTIFACT_GENERATION_BACKOFF_MAX_MS,
|
|
191
|
+
SESSION_TOOL_RESULT_CACHE_TIMEOUT_MS,
|
|
192
|
+
SESSION_CLEANUP_INTERVAL_MS,
|
|
193
|
+
STATUS_UPDATE_DEFAULT_NUM_EVENTS,
|
|
194
|
+
STATUS_UPDATE_DEFAULT_INTERVAL_SECONDS,
|
|
195
|
+
STREAM_PARSER_MAX_SNAPSHOT_SIZE,
|
|
196
|
+
STREAM_PARSER_MAX_STREAMED_SIZE,
|
|
197
|
+
STREAM_PARSER_MAX_COLLECTED_PARTS,
|
|
198
|
+
STREAM_BUFFER_MAX_SIZE_BYTES,
|
|
199
|
+
STREAM_TEXT_GAP_THRESHOLD_MS,
|
|
200
|
+
STREAM_MAX_LIFETIME_MS,
|
|
201
|
+
CONVERSATION_HISTORY_DEFAULT_LIMIT
|
|
202
|
+
} = constants;
|
|
203
|
+
|
|
204
|
+
export { AGENT_EXECUTION_MAX_CONSECUTIVE_ERRORS, AGENT_EXECUTION_MAX_GENERATION_STEPS, ARTIFACT_GENERATION_BACKOFF_INITIAL_MS, ARTIFACT_GENERATION_BACKOFF_MAX_MS, ARTIFACT_GENERATION_MAX_RETRIES, ARTIFACT_SESSION_MAX_PENDING, ARTIFACT_SESSION_MAX_PREVIOUS_SUMMARIES, CONVERSATION_HISTORY_DEFAULT_LIMIT, DELEGATION_TOOL_BACKOFF_EXPONENT, DELEGATION_TOOL_BACKOFF_INITIAL_INTERVAL_MS, DELEGATION_TOOL_BACKOFF_MAX_ELAPSED_TIME_MS, DELEGATION_TOOL_BACKOFF_MAX_INTERVAL_MS, FUNCTION_TOOL_EXECUTION_TIMEOUT_MS_DEFAULT, FUNCTION_TOOL_SANDBOX_CLEANUP_INTERVAL_MS, FUNCTION_TOOL_SANDBOX_MAX_OUTPUT_SIZE_BYTES, FUNCTION_TOOL_SANDBOX_MAX_USE_COUNT, FUNCTION_TOOL_SANDBOX_POOL_TTL_MS, FUNCTION_TOOL_SANDBOX_QUEUE_WAIT_TIMEOUT_MS, FUNCTION_TOOL_SANDBOX_VCPUS_DEFAULT, LLM_GENERATION_FIRST_CALL_TIMEOUT_MS_NON_STREAMING, LLM_GENERATION_FIRST_CALL_TIMEOUT_MS_STREAMING, LLM_GENERATION_MAX_ALLOWED_TIMEOUT_MS, LLM_GENERATION_SUBSEQUENT_CALL_TIMEOUT_MS, SESSION_CLEANUP_INTERVAL_MS, SESSION_TOOL_RESULT_CACHE_TIMEOUT_MS, STATUS_UPDATE_DEFAULT_INTERVAL_SECONDS, STATUS_UPDATE_DEFAULT_NUM_EVENTS, STREAM_BUFFER_MAX_SIZE_BYTES, STREAM_MAX_LIFETIME_MS, STREAM_PARSER_MAX_COLLECTED_PARTS, STREAM_PARSER_MAX_SNAPSHOT_SIZE, STREAM_PARSER_MAX_STREAMED_SIZE, STREAM_TEXT_GAP_THRESHOLD_MS };
|
|
@@ -6,9 +6,7 @@ loadEnvironmentFiles();
|
|
|
6
6
|
var envSchema = z.object({
|
|
7
7
|
NODE_ENV: z.enum(["development", "production", "test"]).optional(),
|
|
8
8
|
ENVIRONMENT: z.enum(["development", "production", "pentest", "test"]).optional().default("development"),
|
|
9
|
-
|
|
10
|
-
TURSO_DATABASE_URL: z.string().optional(),
|
|
11
|
-
TURSO_AUTH_TOKEN: z.string().optional(),
|
|
9
|
+
DATABASE_URL: z.string().optional(),
|
|
12
10
|
AGENTS_RUN_API_URL: z.string().optional().default("http://localhost:3003"),
|
|
13
11
|
LOG_LEVEL: z.enum(["trace", "debug", "info", "warn", "error"]).optional().default("debug"),
|
|
14
12
|
NANGO_SERVER_URL: z.string().optional().default("https://api.nango.dev"),
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { env } from './chunk-
|
|
1
|
+
import { env } from './chunk-N2FZD53W.js';
|
|
2
2
|
import { getLogger } from './chunk-A2S7GSHL.js';
|
|
3
3
|
import { getNodeAutoInstrumentations } from '@opentelemetry/auto-instrumentations-node';
|
|
4
4
|
import { BaggageSpanProcessor, ALLOW_ALL_BAGGAGE_KEYS } from '@opentelemetry/baggage-span-processor';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { createDefaultConversationHistoryConfig, getConversationScopedArtifacts, getFormattedConversationHistory, getFullConversationContext, getScopedHistory, getUserFacingHistory, saveA2AMessageResponse } from './chunk-
|
|
1
|
+
export { createDefaultConversationHistoryConfig, getConversationScopedArtifacts, getFormattedConversationHistory, getFullConversationContext, getScopedHistory, getUserFacingHistory, saveA2AMessageResponse } from './chunk-54Z7AOV4.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { dbClient_default as default } from './chunk-BYF2SHLS.js';
|