@inkeep/agents-run-api 0.0.0-dev-20251109004542 → 0.0.0-dev-20251110174655
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/dist/{SandboxExecutorFactory-QVNCS6YN.js → SandboxExecutorFactory-UTX25H4J.js} +44 -47
- package/dist/{chunk-IMJLQGAX.js → chunk-6XLBN4GB.js} +5 -4
- package/dist/chunk-IVALDC72.js +204 -0
- package/dist/{conversations-V6DNH5MW.js → conversations-4VSL6EHK.js} +1 -1
- package/dist/index.cjs +453 -224
- package/dist/index.js +62 -55
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
var agentsCore = require('@inkeep/agents-core');
|
|
6
|
-
var
|
|
6
|
+
var z7 = require('zod');
|
|
7
7
|
var child_process = require('child_process');
|
|
8
8
|
var crypto = require('crypto');
|
|
9
9
|
var fs = require('fs');
|
|
@@ -45,7 +45,7 @@ var fetchToNode = require('fetch-to-node');
|
|
|
45
45
|
|
|
46
46
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
47
47
|
|
|
48
|
-
var
|
|
48
|
+
var z7__default = /*#__PURE__*/_interopDefault(z7);
|
|
49
49
|
var crypto__default = /*#__PURE__*/_interopDefault(crypto);
|
|
50
50
|
var jmespath__default = /*#__PURE__*/_interopDefault(jmespath);
|
|
51
51
|
var Ajv__default = /*#__PURE__*/_interopDefault(Ajv);
|
|
@@ -67,30 +67,30 @@ var envSchema, parseEnv, env;
|
|
|
67
67
|
var init_env = __esm({
|
|
68
68
|
"src/env.ts"() {
|
|
69
69
|
agentsCore.loadEnvironmentFiles();
|
|
70
|
-
envSchema =
|
|
71
|
-
NODE_ENV:
|
|
72
|
-
ENVIRONMENT:
|
|
73
|
-
DB_FILE_NAME:
|
|
74
|
-
TURSO_DATABASE_URL:
|
|
75
|
-
TURSO_AUTH_TOKEN:
|
|
76
|
-
AGENTS_RUN_API_URL:
|
|
77
|
-
LOG_LEVEL:
|
|
78
|
-
NANGO_SERVER_URL:
|
|
79
|
-
NANGO_SECRET_KEY:
|
|
80
|
-
ANTHROPIC_API_KEY:
|
|
81
|
-
OPENAI_API_KEY:
|
|
82
|
-
GOOGLE_GENERATIVE_AI_API_KEY:
|
|
83
|
-
INKEEP_AGENTS_RUN_API_BYPASS_SECRET:
|
|
84
|
-
INKEEP_AGENTS_JWT_SIGNING_SECRET:
|
|
85
|
-
OTEL_BSP_SCHEDULE_DELAY:
|
|
86
|
-
OTEL_BSP_MAX_EXPORT_BATCH_SIZE:
|
|
70
|
+
envSchema = z7.z.object({
|
|
71
|
+
NODE_ENV: z7.z.enum(["development", "production", "test"]).optional(),
|
|
72
|
+
ENVIRONMENT: z7.z.enum(["development", "production", "pentest", "test"]).optional().default("development"),
|
|
73
|
+
DB_FILE_NAME: z7.z.string().optional(),
|
|
74
|
+
TURSO_DATABASE_URL: z7.z.string().optional(),
|
|
75
|
+
TURSO_AUTH_TOKEN: z7.z.string().optional(),
|
|
76
|
+
AGENTS_RUN_API_URL: z7.z.string().optional().default("http://localhost:3003"),
|
|
77
|
+
LOG_LEVEL: z7.z.enum(["trace", "debug", "info", "warn", "error"]).optional().default("debug"),
|
|
78
|
+
NANGO_SERVER_URL: z7.z.string().optional().default("https://api.nango.dev"),
|
|
79
|
+
NANGO_SECRET_KEY: z7.z.string().optional(),
|
|
80
|
+
ANTHROPIC_API_KEY: z7.z.string(),
|
|
81
|
+
OPENAI_API_KEY: z7.z.string().optional(),
|
|
82
|
+
GOOGLE_GENERATIVE_AI_API_KEY: z7.z.string().optional(),
|
|
83
|
+
INKEEP_AGENTS_RUN_API_BYPASS_SECRET: z7.z.string().optional(),
|
|
84
|
+
INKEEP_AGENTS_JWT_SIGNING_SECRET: z7.z.string().optional(),
|
|
85
|
+
OTEL_BSP_SCHEDULE_DELAY: z7.z.coerce.number().optional().default(500),
|
|
86
|
+
OTEL_BSP_MAX_EXPORT_BATCH_SIZE: z7.z.coerce.number().optional().default(64)
|
|
87
87
|
});
|
|
88
88
|
parseEnv = () => {
|
|
89
89
|
try {
|
|
90
90
|
const parsedEnv = envSchema.parse(process.env);
|
|
91
91
|
return parsedEnv;
|
|
92
92
|
} catch (error) {
|
|
93
|
-
if (error instanceof
|
|
93
|
+
if (error instanceof z7.z.ZodError) {
|
|
94
94
|
const missingVars = error.issues.map((issue) => issue.path.join("."));
|
|
95
95
|
throw new Error(
|
|
96
96
|
`\u274C Invalid environment variables: ${missingVars.join(", ")}
|
|
@@ -147,6 +147,219 @@ var init_dbClient = __esm({
|
|
|
147
147
|
}
|
|
148
148
|
});
|
|
149
149
|
|
|
150
|
+
// src/constants/execution-limits/defaults.ts
|
|
151
|
+
var executionLimitsDefaults;
|
|
152
|
+
var init_defaults = __esm({
|
|
153
|
+
"src/constants/execution-limits/defaults.ts"() {
|
|
154
|
+
executionLimitsDefaults = {
|
|
155
|
+
// Sub Agent Turn Execution
|
|
156
|
+
// During a Sub Agent's turn, it makes decisions by calling the LLM (language model). Each decision
|
|
157
|
+
// point is called a "generation step" - for example, deciding to call a tool, transfer to another
|
|
158
|
+
// Sub Agent, delegate a subtask, or send a response to the user.
|
|
159
|
+
// AGENT_EXECUTION_MAX_CONSECUTIVE_ERRORS: Maximum errors tolerated during a single Sub Agent's turn before stopping execution
|
|
160
|
+
// AGENT_EXECUTION_MAX_GENERATION_STEPS: Maximum LLM inference calls allowed within a single Sub Agent turn
|
|
161
|
+
AGENT_EXECUTION_MAX_CONSECUTIVE_ERRORS: 3,
|
|
162
|
+
AGENT_EXECUTION_MAX_GENERATION_STEPS: 5,
|
|
163
|
+
// Sub Agent Decision-Making Timeouts
|
|
164
|
+
// These control how long to wait for the LLM to make decisions during a Sub Agent's turn.
|
|
165
|
+
// "First call" = initial decision at start of turn (may include tool results from previous actions)
|
|
166
|
+
// "Subsequent call" = follow-up decisions after executing tools within the same turn
|
|
167
|
+
// Streaming mode has longer timeout because it waits for the full streamed response to the user
|
|
168
|
+
// LLM_GENERATION_FIRST_CALL_TIMEOUT_MS_STREAMING: Timeout for initial streaming response to user
|
|
169
|
+
// LLM_GENERATION_FIRST_CALL_TIMEOUT_MS_NON_STREAMING: Timeout for initial non-streaming (internal) decision
|
|
170
|
+
// LLM_GENERATION_SUBSEQUENT_CALL_TIMEOUT_MS: Timeout for follow-up decisions after tool execution
|
|
171
|
+
// LLM_GENERATION_MAX_ALLOWED_TIMEOUT_MS: Maximum timeout allowed regardless of configuration
|
|
172
|
+
LLM_GENERATION_FIRST_CALL_TIMEOUT_MS_STREAMING: 27e4,
|
|
173
|
+
// 4.5 minutes
|
|
174
|
+
LLM_GENERATION_FIRST_CALL_TIMEOUT_MS_NON_STREAMING: 9e4,
|
|
175
|
+
// 1.5 minutes
|
|
176
|
+
LLM_GENERATION_SUBSEQUENT_CALL_TIMEOUT_MS: 9e4,
|
|
177
|
+
// 1.5 minutes
|
|
178
|
+
LLM_GENERATION_MAX_ALLOWED_TIMEOUT_MS: 6e5,
|
|
179
|
+
// 10 minutes
|
|
180
|
+
// Function Tool Execution (Sandboxed Environments)
|
|
181
|
+
// Function Tools are custom JavaScript functions that Sub Agents can call. They run in secure
|
|
182
|
+
// isolated sandboxes (containerized environments) to prevent malicious code execution.
|
|
183
|
+
// For performance, sandboxes are cached and reused across multiple tool calls until they expire.
|
|
184
|
+
// FUNCTION_TOOL_EXECUTION_TIMEOUT_MS_DEFAULT: Maximum execution time for a Function Tool call
|
|
185
|
+
// FUNCTION_TOOL_SANDBOX_VCPUS_DEFAULT: Virtual CPUs allocated to each sandbox (affects compute capacity)
|
|
186
|
+
// FUNCTION_TOOL_SANDBOX_POOL_TTL_MS: Time-to-live for cached sandboxes (after this, sandbox is discarded)
|
|
187
|
+
// FUNCTION_TOOL_SANDBOX_MAX_USE_COUNT: Maximum reuses of a sandbox before it's refreshed (prevents resource leaks)
|
|
188
|
+
// FUNCTION_TOOL_SANDBOX_MAX_OUTPUT_SIZE_BYTES: Maximum size of Function Tool output (prevents memory exhaustion)
|
|
189
|
+
// FUNCTION_TOOL_SANDBOX_QUEUE_WAIT_TIMEOUT_MS: Maximum wait time for sandbox to become available when pool is full
|
|
190
|
+
// FUNCTION_TOOL_SANDBOX_CLEANUP_INTERVAL_MS: How often to check for and remove expired sandboxes from the pool
|
|
191
|
+
FUNCTION_TOOL_EXECUTION_TIMEOUT_MS_DEFAULT: 3e4,
|
|
192
|
+
// 30 seconds
|
|
193
|
+
FUNCTION_TOOL_SANDBOX_VCPUS_DEFAULT: 4,
|
|
194
|
+
FUNCTION_TOOL_SANDBOX_POOL_TTL_MS: 3e5,
|
|
195
|
+
// 5 minutes
|
|
196
|
+
FUNCTION_TOOL_SANDBOX_MAX_USE_COUNT: 50,
|
|
197
|
+
FUNCTION_TOOL_SANDBOX_MAX_OUTPUT_SIZE_BYTES: 1048576,
|
|
198
|
+
// 1 MB
|
|
199
|
+
FUNCTION_TOOL_SANDBOX_QUEUE_WAIT_TIMEOUT_MS: 3e4,
|
|
200
|
+
// 30 seconds
|
|
201
|
+
FUNCTION_TOOL_SANDBOX_CLEANUP_INTERVAL_MS: 6e4,
|
|
202
|
+
// 1 minute
|
|
203
|
+
// MCP Tool Execution
|
|
204
|
+
// MCP (Model Context Protocol) Servers are external services that provide tools to Sub Agents.
|
|
205
|
+
// When a Sub Agent calls an MCP Tool, the request is sent to the external MCP Server.
|
|
206
|
+
// Note: MCP connection/retry constants are defined in @inkeep/agents-core/constants/execution-limits-shared
|
|
207
|
+
// MCP_TOOL_REQUEST_TIMEOUT_MS_DEFAULT: Maximum wait time for an MCP tool call to complete
|
|
208
|
+
MCP_TOOL_REQUEST_TIMEOUT_MS_DEFAULT: 6e4,
|
|
209
|
+
// 60 seconds
|
|
210
|
+
// Sub Agent Delegation (Retry Strategy)
|
|
211
|
+
// When a Sub Agent delegates a subtask to another Sub Agent, it uses the A2A (Agent-to-Agent)
|
|
212
|
+
// protocol to communicate. If the delegation request fails, these constants control the
|
|
213
|
+
// exponential backoff retry strategy. Formula: delay = min(INITIAL * EXPONENT^attempt, MAX)
|
|
214
|
+
// DELEGATION_TOOL_BACKOFF_INITIAL_INTERVAL_MS: Starting delay before first retry
|
|
215
|
+
// DELEGATION_TOOL_BACKOFF_MAX_INTERVAL_MS: Maximum delay between retries (caps exponential growth)
|
|
216
|
+
// DELEGATION_TOOL_BACKOFF_EXPONENT: Multiplier applied to delay after each retry (2 = doubles each time)
|
|
217
|
+
// DELEGATION_TOOL_BACKOFF_MAX_ELAPSED_TIME_MS: Total time to keep retrying before giving up
|
|
218
|
+
DELEGATION_TOOL_BACKOFF_INITIAL_INTERVAL_MS: 100,
|
|
219
|
+
DELEGATION_TOOL_BACKOFF_MAX_INTERVAL_MS: 1e4,
|
|
220
|
+
// 10 seconds
|
|
221
|
+
DELEGATION_TOOL_BACKOFF_EXPONENT: 2,
|
|
222
|
+
DELEGATION_TOOL_BACKOFF_MAX_ELAPSED_TIME_MS: 2e4,
|
|
223
|
+
// 20 seconds
|
|
224
|
+
// General Agent-to-Agent (A2A) Communication (Retry Strategy)
|
|
225
|
+
// These control retries for broader A2A protocol operations beyond delegation (e.g., status checks,
|
|
226
|
+
// conversation updates). Uses more conservative retry parameters than delegation-specific retries.
|
|
227
|
+
// A2A_BACKOFF_INITIAL_INTERVAL_MS: Starting delay before first retry
|
|
228
|
+
// A2A_BACKOFF_MAX_INTERVAL_MS: Maximum delay between retries
|
|
229
|
+
// A2A_BACKOFF_EXPONENT: Multiplier for exponential backoff (1.5 = grows 50% each retry)
|
|
230
|
+
// A2A_BACKOFF_MAX_ELAPSED_TIME_MS: Total time to keep retrying before giving up
|
|
231
|
+
A2A_BACKOFF_INITIAL_INTERVAL_MS: 500,
|
|
232
|
+
A2A_BACKOFF_MAX_INTERVAL_MS: 6e4,
|
|
233
|
+
// 1 minute
|
|
234
|
+
A2A_BACKOFF_EXPONENT: 1.5,
|
|
235
|
+
A2A_BACKOFF_MAX_ELAPSED_TIME_MS: 3e4,
|
|
236
|
+
// 30 seconds
|
|
237
|
+
// Artifact Processing
|
|
238
|
+
// Artifacts are tool outputs saved for later reference by Sub Agents or users. When a tool generates
|
|
239
|
+
// an artifact, the system automatically generates a human-readable name and description using the LLM.
|
|
240
|
+
// These constants control artifact name/description generation and context window management.
|
|
241
|
+
// ARTIFACT_GENERATION_MAX_RETRIES: Retry attempts for LLM-based artifact name/description generation
|
|
242
|
+
// ARTIFACT_SESSION_MAX_PENDING: Maximum unprocessed artifacts in queue (prevents unbounded growth)
|
|
243
|
+
// ARTIFACT_SESSION_MAX_PREVIOUS_SUMMARIES: Historical artifact summaries kept in context for reference
|
|
244
|
+
// ARTIFACT_GENERATION_BACKOFF_INITIAL_MS: Starting delay for retry backoff when generation fails
|
|
245
|
+
// ARTIFACT_GENERATION_BACKOFF_MAX_MS: Maximum delay between retries (formula: min(INITIAL * 2^attempt, MAX))
|
|
246
|
+
ARTIFACT_GENERATION_MAX_RETRIES: 3,
|
|
247
|
+
ARTIFACT_SESSION_MAX_PENDING: 100,
|
|
248
|
+
ARTIFACT_SESSION_MAX_PREVIOUS_SUMMARIES: 3,
|
|
249
|
+
ARTIFACT_GENERATION_BACKOFF_INITIAL_MS: 1e3,
|
|
250
|
+
// 1 second
|
|
251
|
+
ARTIFACT_GENERATION_BACKOFF_MAX_MS: 1e4,
|
|
252
|
+
// 10 seconds
|
|
253
|
+
// Conversation Session & Cache Management
|
|
254
|
+
// A "session" represents the state of an ongoing conversation with an Agent. Tool results are cached
|
|
255
|
+
// within the session for performance - this is especially important for artifact processing where the
|
|
256
|
+
// same tool outputs may be referenced multiple times across Sub Agent turns.
|
|
257
|
+
// SESSION_TOOL_RESULT_CACHE_TIMEOUT_MS: How long tool results are kept in cache before expiring
|
|
258
|
+
// SESSION_CLEANUP_INTERVAL_MS: How often to check for and remove expired cached tool results
|
|
259
|
+
SESSION_TOOL_RESULT_CACHE_TIMEOUT_MS: 3e5,
|
|
260
|
+
// 5 minutes
|
|
261
|
+
SESSION_CLEANUP_INTERVAL_MS: 6e4,
|
|
262
|
+
// 1 minute
|
|
263
|
+
// Status Updates
|
|
264
|
+
// Status Updates are real-time progress messages sent to users during longer Sub Agent operations.
|
|
265
|
+
// The system automatically generates status updates based on activity thresholds - either after a
|
|
266
|
+
// certain number of significant events OR after a time interval (whichever comes first).
|
|
267
|
+
// Events include: tool calls, Sub Agent transfers, delegations, or other significant activities.
|
|
268
|
+
// STATUS_UPDATE_DEFAULT_NUM_EVENTS: Number of significant events before triggering a status update
|
|
269
|
+
// STATUS_UPDATE_DEFAULT_INTERVAL_SECONDS: Time interval (in seconds) before generating status update
|
|
270
|
+
STATUS_UPDATE_DEFAULT_NUM_EVENTS: 1,
|
|
271
|
+
STATUS_UPDATE_DEFAULT_INTERVAL_SECONDS: 2,
|
|
272
|
+
// Response Streaming (Internal Buffering Limits)
|
|
273
|
+
// These are internal infrastructure limits for streaming responses to users. Streaming enables
|
|
274
|
+
// real-time updates as Sub Agents generate responses, Data Components, and Status Updates.
|
|
275
|
+
// STREAM_PARSER_MAX_SNAPSHOT_SIZE: Maximum Data Component snapshots buffered before clearing old ones
|
|
276
|
+
// STREAM_PARSER_MAX_STREAMED_SIZE: Maximum streamed component IDs tracked simultaneously
|
|
277
|
+
// STREAM_PARSER_MAX_COLLECTED_PARTS: Maximum accumulated stream parts before forcing flush
|
|
278
|
+
// STREAM_BUFFER_MAX_SIZE_BYTES: Maximum total buffer size in bytes (prevents memory exhaustion)
|
|
279
|
+
// STREAM_TEXT_GAP_THRESHOLD_MS: Time gap that triggers bundling text with artifact data vs separate send
|
|
280
|
+
// STREAM_MAX_LIFETIME_MS: Maximum duration a stream can stay open before forced closure
|
|
281
|
+
STREAM_PARSER_MAX_SNAPSHOT_SIZE: 100,
|
|
282
|
+
STREAM_PARSER_MAX_STREAMED_SIZE: 1e3,
|
|
283
|
+
STREAM_PARSER_MAX_COLLECTED_PARTS: 1e4,
|
|
284
|
+
STREAM_BUFFER_MAX_SIZE_BYTES: 5242880,
|
|
285
|
+
// 5 MB
|
|
286
|
+
STREAM_TEXT_GAP_THRESHOLD_MS: 2e3,
|
|
287
|
+
// 2 seconds
|
|
288
|
+
STREAM_MAX_LIFETIME_MS: 6e5,
|
|
289
|
+
// 10 minutes
|
|
290
|
+
// Conversation History Message Retrieval
|
|
291
|
+
// CONVERSATION_HISTORY_DEFAULT_LIMIT: Default number of recent conversation messages to retrieve
|
|
292
|
+
CONVERSATION_HISTORY_DEFAULT_LIMIT: 50
|
|
293
|
+
};
|
|
294
|
+
}
|
|
295
|
+
});
|
|
296
|
+
var constantsSchema, parseConstants, constants, AGENT_EXECUTION_MAX_CONSECUTIVE_ERRORS, AGENT_EXECUTION_MAX_GENERATION_STEPS, LLM_GENERATION_FIRST_CALL_TIMEOUT_MS_STREAMING, LLM_GENERATION_FIRST_CALL_TIMEOUT_MS_NON_STREAMING, LLM_GENERATION_SUBSEQUENT_CALL_TIMEOUT_MS, LLM_GENERATION_MAX_ALLOWED_TIMEOUT_MS, FUNCTION_TOOL_EXECUTION_TIMEOUT_MS_DEFAULT, FUNCTION_TOOL_SANDBOX_VCPUS_DEFAULT, FUNCTION_TOOL_SANDBOX_POOL_TTL_MS, FUNCTION_TOOL_SANDBOX_MAX_USE_COUNT, FUNCTION_TOOL_SANDBOX_MAX_OUTPUT_SIZE_BYTES, FUNCTION_TOOL_SANDBOX_QUEUE_WAIT_TIMEOUT_MS, FUNCTION_TOOL_SANDBOX_CLEANUP_INTERVAL_MS, MCP_TOOL_REQUEST_TIMEOUT_MS_DEFAULT, DELEGATION_TOOL_BACKOFF_INITIAL_INTERVAL_MS, DELEGATION_TOOL_BACKOFF_MAX_INTERVAL_MS, DELEGATION_TOOL_BACKOFF_EXPONENT, DELEGATION_TOOL_BACKOFF_MAX_ELAPSED_TIME_MS, A2A_BACKOFF_INITIAL_INTERVAL_MS, A2A_BACKOFF_MAX_INTERVAL_MS, A2A_BACKOFF_EXPONENT, A2A_BACKOFF_MAX_ELAPSED_TIME_MS, ARTIFACT_GENERATION_MAX_RETRIES, ARTIFACT_SESSION_MAX_PENDING, ARTIFACT_SESSION_MAX_PREVIOUS_SUMMARIES, ARTIFACT_GENERATION_BACKOFF_INITIAL_MS, ARTIFACT_GENERATION_BACKOFF_MAX_MS, SESSION_TOOL_RESULT_CACHE_TIMEOUT_MS, SESSION_CLEANUP_INTERVAL_MS, STATUS_UPDATE_DEFAULT_NUM_EVENTS, STATUS_UPDATE_DEFAULT_INTERVAL_SECONDS, STREAM_PARSER_MAX_SNAPSHOT_SIZE, STREAM_PARSER_MAX_STREAMED_SIZE, STREAM_PARSER_MAX_COLLECTED_PARTS, STREAM_BUFFER_MAX_SIZE_BYTES, STREAM_TEXT_GAP_THRESHOLD_MS, STREAM_MAX_LIFETIME_MS, CONVERSATION_HISTORY_DEFAULT_LIMIT;
|
|
297
|
+
var init_execution_limits = __esm({
|
|
298
|
+
"src/constants/execution-limits/index.ts"() {
|
|
299
|
+
init_defaults();
|
|
300
|
+
init_defaults();
|
|
301
|
+
agentsCore.loadEnvironmentFiles();
|
|
302
|
+
constantsSchema = z7.z.object(
|
|
303
|
+
Object.fromEntries(
|
|
304
|
+
Object.keys(executionLimitsDefaults).map((key) => [
|
|
305
|
+
`AGENTS_${key}`,
|
|
306
|
+
z7.z.coerce.number().optional()
|
|
307
|
+
])
|
|
308
|
+
)
|
|
309
|
+
);
|
|
310
|
+
parseConstants = () => {
|
|
311
|
+
const envOverrides = constantsSchema.parse(process.env);
|
|
312
|
+
return Object.fromEntries(
|
|
313
|
+
Object.entries(executionLimitsDefaults).map(([key, defaultValue]) => [
|
|
314
|
+
key,
|
|
315
|
+
envOverrides[`AGENTS_${key}`] ?? defaultValue
|
|
316
|
+
])
|
|
317
|
+
);
|
|
318
|
+
};
|
|
319
|
+
constants = parseConstants();
|
|
320
|
+
({
|
|
321
|
+
AGENT_EXECUTION_MAX_CONSECUTIVE_ERRORS,
|
|
322
|
+
AGENT_EXECUTION_MAX_GENERATION_STEPS,
|
|
323
|
+
LLM_GENERATION_FIRST_CALL_TIMEOUT_MS_STREAMING,
|
|
324
|
+
LLM_GENERATION_FIRST_CALL_TIMEOUT_MS_NON_STREAMING,
|
|
325
|
+
LLM_GENERATION_SUBSEQUENT_CALL_TIMEOUT_MS,
|
|
326
|
+
LLM_GENERATION_MAX_ALLOWED_TIMEOUT_MS,
|
|
327
|
+
FUNCTION_TOOL_EXECUTION_TIMEOUT_MS_DEFAULT,
|
|
328
|
+
FUNCTION_TOOL_SANDBOX_VCPUS_DEFAULT,
|
|
329
|
+
FUNCTION_TOOL_SANDBOX_POOL_TTL_MS,
|
|
330
|
+
FUNCTION_TOOL_SANDBOX_MAX_USE_COUNT,
|
|
331
|
+
FUNCTION_TOOL_SANDBOX_MAX_OUTPUT_SIZE_BYTES,
|
|
332
|
+
FUNCTION_TOOL_SANDBOX_QUEUE_WAIT_TIMEOUT_MS,
|
|
333
|
+
FUNCTION_TOOL_SANDBOX_CLEANUP_INTERVAL_MS,
|
|
334
|
+
MCP_TOOL_REQUEST_TIMEOUT_MS_DEFAULT,
|
|
335
|
+
DELEGATION_TOOL_BACKOFF_INITIAL_INTERVAL_MS,
|
|
336
|
+
DELEGATION_TOOL_BACKOFF_MAX_INTERVAL_MS,
|
|
337
|
+
DELEGATION_TOOL_BACKOFF_EXPONENT,
|
|
338
|
+
DELEGATION_TOOL_BACKOFF_MAX_ELAPSED_TIME_MS,
|
|
339
|
+
A2A_BACKOFF_INITIAL_INTERVAL_MS,
|
|
340
|
+
A2A_BACKOFF_MAX_INTERVAL_MS,
|
|
341
|
+
A2A_BACKOFF_EXPONENT,
|
|
342
|
+
A2A_BACKOFF_MAX_ELAPSED_TIME_MS,
|
|
343
|
+
ARTIFACT_GENERATION_MAX_RETRIES,
|
|
344
|
+
ARTIFACT_SESSION_MAX_PENDING,
|
|
345
|
+
ARTIFACT_SESSION_MAX_PREVIOUS_SUMMARIES,
|
|
346
|
+
ARTIFACT_GENERATION_BACKOFF_INITIAL_MS,
|
|
347
|
+
ARTIFACT_GENERATION_BACKOFF_MAX_MS,
|
|
348
|
+
SESSION_TOOL_RESULT_CACHE_TIMEOUT_MS,
|
|
349
|
+
SESSION_CLEANUP_INTERVAL_MS,
|
|
350
|
+
STATUS_UPDATE_DEFAULT_NUM_EVENTS,
|
|
351
|
+
STATUS_UPDATE_DEFAULT_INTERVAL_SECONDS,
|
|
352
|
+
STREAM_PARSER_MAX_SNAPSHOT_SIZE,
|
|
353
|
+
STREAM_PARSER_MAX_STREAMED_SIZE,
|
|
354
|
+
STREAM_PARSER_MAX_COLLECTED_PARTS,
|
|
355
|
+
STREAM_BUFFER_MAX_SIZE_BYTES,
|
|
356
|
+
STREAM_TEXT_GAP_THRESHOLD_MS,
|
|
357
|
+
STREAM_MAX_LIFETIME_MS,
|
|
358
|
+
CONVERSATION_HISTORY_DEFAULT_LIMIT
|
|
359
|
+
} = constants);
|
|
360
|
+
}
|
|
361
|
+
});
|
|
362
|
+
|
|
150
363
|
// src/data/conversations.ts
|
|
151
364
|
var conversations_exports = {};
|
|
152
365
|
__export(conversations_exports, {
|
|
@@ -161,10 +374,10 @@ __export(conversations_exports, {
|
|
|
161
374
|
function createDefaultConversationHistoryConfig(mode = "full") {
|
|
162
375
|
return {
|
|
163
376
|
mode,
|
|
164
|
-
limit:
|
|
377
|
+
limit: CONVERSATION_HISTORY_DEFAULT_LIMIT,
|
|
165
378
|
includeInternal: true,
|
|
166
379
|
messageTypes: ["chat"],
|
|
167
|
-
maxOutputTokens:
|
|
380
|
+
maxOutputTokens: agentsCore.CONVERSATION_HISTORY_MAX_OUTPUT_TOKENS_DEFAULT
|
|
168
381
|
};
|
|
169
382
|
}
|
|
170
383
|
function extractA2AMessageText(parts) {
|
|
@@ -253,7 +466,7 @@ async function getScopedHistory({
|
|
|
253
466
|
return [];
|
|
254
467
|
}
|
|
255
468
|
}
|
|
256
|
-
async function getUserFacingHistory(tenantId, projectId, conversationId, limit =
|
|
469
|
+
async function getUserFacingHistory(tenantId, projectId, conversationId, limit = CONVERSATION_HISTORY_DEFAULT_LIMIT) {
|
|
257
470
|
return await agentsCore.getConversationHistory(dbClient_default)({
|
|
258
471
|
scopes: { tenantId, projectId },
|
|
259
472
|
conversationId,
|
|
@@ -383,6 +596,7 @@ async function getConversationScopedArtifacts(params) {
|
|
|
383
596
|
}
|
|
384
597
|
var init_conversations = __esm({
|
|
385
598
|
"src/data/conversations.ts"() {
|
|
599
|
+
init_execution_limits();
|
|
386
600
|
init_dbClient();
|
|
387
601
|
}
|
|
388
602
|
});
|
|
@@ -438,10 +652,12 @@ var init_sandbox_utils = __esm({
|
|
|
438
652
|
var logger16, ExecutionSemaphore, _NativeSandboxExecutor, NativeSandboxExecutor;
|
|
439
653
|
var init_NativeSandboxExecutor = __esm({
|
|
440
654
|
"src/tools/NativeSandboxExecutor.ts"() {
|
|
655
|
+
init_execution_limits();
|
|
656
|
+
init_logger();
|
|
441
657
|
init_sandbox_utils();
|
|
442
658
|
logger16 = agentsCore.getLogger("native-sandbox-executor");
|
|
443
659
|
ExecutionSemaphore = class {
|
|
444
|
-
constructor(permits, maxWaitTimeMs =
|
|
660
|
+
constructor(permits, maxWaitTimeMs = FUNCTION_TOOL_SANDBOX_QUEUE_WAIT_TIMEOUT_MS) {
|
|
445
661
|
__publicField(this, "permits");
|
|
446
662
|
__publicField(this, "waitQueue", []);
|
|
447
663
|
__publicField(this, "maxWaitTime");
|
|
@@ -496,9 +712,6 @@ var init_NativeSandboxExecutor = __esm({
|
|
|
496
712
|
constructor() {
|
|
497
713
|
__publicField(this, "tempDir");
|
|
498
714
|
__publicField(this, "sandboxPool", {});
|
|
499
|
-
__publicField(this, "POOL_TTL", 5 * 60 * 1e3);
|
|
500
|
-
// 5 minutes
|
|
501
|
-
__publicField(this, "MAX_USE_COUNT", 50);
|
|
502
715
|
__publicField(this, "executionSemaphores", /* @__PURE__ */ new Map());
|
|
503
716
|
this.tempDir = path.join(os.tmpdir(), "inkeep-sandboxes");
|
|
504
717
|
this.ensureTempDir();
|
|
@@ -547,7 +760,7 @@ var init_NativeSandboxExecutor = __esm({
|
|
|
547
760
|
const sandbox = this.sandboxPool[poolKey];
|
|
548
761
|
if (sandbox && fs.existsSync(sandbox.sandboxDir)) {
|
|
549
762
|
const now = Date.now();
|
|
550
|
-
if (now - sandbox.lastUsed <
|
|
763
|
+
if (now - sandbox.lastUsed < FUNCTION_TOOL_SANDBOX_POOL_TTL_MS && sandbox.useCount < FUNCTION_TOOL_SANDBOX_MAX_USE_COUNT) {
|
|
551
764
|
sandbox.lastUsed = now;
|
|
552
765
|
sandbox.useCount++;
|
|
553
766
|
logger16.debug(
|
|
@@ -593,7 +806,7 @@ var init_NativeSandboxExecutor = __esm({
|
|
|
593
806
|
const now = Date.now();
|
|
594
807
|
const keysToDelete = [];
|
|
595
808
|
for (const [key, sandbox] of Object.entries(this.sandboxPool)) {
|
|
596
|
-
if (now - sandbox.lastUsed >
|
|
809
|
+
if (now - sandbox.lastUsed > FUNCTION_TOOL_SANDBOX_POOL_TTL_MS || sandbox.useCount >= FUNCTION_TOOL_SANDBOX_MAX_USE_COUNT) {
|
|
597
810
|
this.cleanupSandbox(sandbox.sandboxDir);
|
|
598
811
|
keysToDelete.push(key);
|
|
599
812
|
}
|
|
@@ -604,7 +817,7 @@ var init_NativeSandboxExecutor = __esm({
|
|
|
604
817
|
if (keysToDelete.length > 0) {
|
|
605
818
|
logger16.debug({ cleanedCount: keysToDelete.length }, "Cleaned up expired sandboxes");
|
|
606
819
|
}
|
|
607
|
-
},
|
|
820
|
+
}, FUNCTION_TOOL_SANDBOX_CLEANUP_INTERVAL_MS);
|
|
608
821
|
}
|
|
609
822
|
detectModuleType(executeCode, configuredRuntime) {
|
|
610
823
|
const esmPatterns = [
|
|
@@ -714,7 +927,7 @@ var init_NativeSandboxExecutor = __esm({
|
|
|
714
927
|
fs.writeFileSync(path.join(sandboxDir, `index.${fileExtension}`), executionCode, "utf8");
|
|
715
928
|
const result = await this.executeInSandbox(
|
|
716
929
|
sandboxDir,
|
|
717
|
-
config.sandboxConfig?.timeout ||
|
|
930
|
+
config.sandboxConfig?.timeout || FUNCTION_TOOL_EXECUTION_TIMEOUT_MS_DEFAULT,
|
|
718
931
|
moduleType,
|
|
719
932
|
config.sandboxConfig
|
|
720
933
|
);
|
|
@@ -779,13 +992,16 @@ var init_NativeSandboxExecutor = __esm({
|
|
|
779
992
|
let stdout = "";
|
|
780
993
|
let stderr = "";
|
|
781
994
|
let outputSize = 0;
|
|
782
|
-
const MAX_OUTPUT_SIZE = 1024 * 1024;
|
|
783
995
|
node.stdout?.on("data", (data) => {
|
|
784
996
|
const dataStr = data.toString();
|
|
785
997
|
outputSize += dataStr.length;
|
|
786
|
-
if (outputSize >
|
|
998
|
+
if (outputSize > FUNCTION_TOOL_SANDBOX_MAX_OUTPUT_SIZE_BYTES) {
|
|
787
999
|
node.kill("SIGTERM");
|
|
788
|
-
reject(
|
|
1000
|
+
reject(
|
|
1001
|
+
new Error(
|
|
1002
|
+
`Output size exceeded limit of ${FUNCTION_TOOL_SANDBOX_MAX_OUTPUT_SIZE_BYTES} bytes`
|
|
1003
|
+
)
|
|
1004
|
+
);
|
|
789
1005
|
return;
|
|
790
1006
|
}
|
|
791
1007
|
stdout += dataStr;
|
|
@@ -793,9 +1009,13 @@ var init_NativeSandboxExecutor = __esm({
|
|
|
793
1009
|
node.stderr?.on("data", (data) => {
|
|
794
1010
|
const dataStr = data.toString();
|
|
795
1011
|
outputSize += dataStr.length;
|
|
796
|
-
if (outputSize >
|
|
1012
|
+
if (outputSize > FUNCTION_TOOL_SANDBOX_MAX_OUTPUT_SIZE_BYTES) {
|
|
797
1013
|
node.kill("SIGTERM");
|
|
798
|
-
reject(
|
|
1014
|
+
reject(
|
|
1015
|
+
new Error(
|
|
1016
|
+
`Output size exceeded limit of ${FUNCTION_TOOL_SANDBOX_MAX_OUTPUT_SIZE_BYTES} bytes`
|
|
1017
|
+
)
|
|
1018
|
+
);
|
|
799
1019
|
return;
|
|
800
1020
|
}
|
|
801
1021
|
stderr += dataStr;
|
|
@@ -852,6 +1072,7 @@ var init_NativeSandboxExecutor = __esm({
|
|
|
852
1072
|
var logger17, _VercelSandboxExecutor, VercelSandboxExecutor;
|
|
853
1073
|
var init_VercelSandboxExecutor = __esm({
|
|
854
1074
|
"src/tools/VercelSandboxExecutor.ts"() {
|
|
1075
|
+
init_execution_limits();
|
|
855
1076
|
init_logger();
|
|
856
1077
|
init_sandbox_utils();
|
|
857
1078
|
logger17 = agentsCore.getLogger("VercelSandboxExecutor");
|
|
@@ -859,9 +1080,6 @@ var init_VercelSandboxExecutor = __esm({
|
|
|
859
1080
|
constructor(config) {
|
|
860
1081
|
__publicField(this, "config");
|
|
861
1082
|
__publicField(this, "sandboxPool", /* @__PURE__ */ new Map());
|
|
862
|
-
__publicField(this, "POOL_TTL", 5 * 60 * 1e3);
|
|
863
|
-
// 5 minutes
|
|
864
|
-
__publicField(this, "MAX_USE_COUNT", 50);
|
|
865
1083
|
__publicField(this, "cleanupInterval", null);
|
|
866
1084
|
this.config = config;
|
|
867
1085
|
logger17.info(
|
|
@@ -900,14 +1118,14 @@ var init_VercelSandboxExecutor = __esm({
|
|
|
900
1118
|
if (!cached) return null;
|
|
901
1119
|
const now = Date.now();
|
|
902
1120
|
const age = now - cached.createdAt;
|
|
903
|
-
if (age >
|
|
1121
|
+
if (age > FUNCTION_TOOL_SANDBOX_POOL_TTL_MS || cached.useCount >= FUNCTION_TOOL_SANDBOX_MAX_USE_COUNT) {
|
|
904
1122
|
logger17.debug(
|
|
905
1123
|
{
|
|
906
1124
|
dependencyHash,
|
|
907
1125
|
age,
|
|
908
1126
|
useCount: cached.useCount,
|
|
909
|
-
ttl:
|
|
910
|
-
maxUseCount:
|
|
1127
|
+
ttl: FUNCTION_TOOL_SANDBOX_POOL_TTL_MS,
|
|
1128
|
+
maxUseCount: FUNCTION_TOOL_SANDBOX_MAX_USE_COUNT
|
|
911
1129
|
},
|
|
912
1130
|
"Sandbox expired, will create new one"
|
|
913
1131
|
);
|
|
@@ -970,32 +1188,28 @@ var init_VercelSandboxExecutor = __esm({
|
|
|
970
1188
|
* Start periodic cleanup of expired sandboxes
|
|
971
1189
|
*/
|
|
972
1190
|
startPoolCleanup() {
|
|
973
|
-
this.cleanupInterval = setInterval(
|
|
974
|
-
()
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
toRemove.push(hash);
|
|
981
|
-
}
|
|
1191
|
+
this.cleanupInterval = setInterval(() => {
|
|
1192
|
+
const now = Date.now();
|
|
1193
|
+
const toRemove = [];
|
|
1194
|
+
for (const [hash, cached] of this.sandboxPool.entries()) {
|
|
1195
|
+
const age = now - cached.createdAt;
|
|
1196
|
+
if (age > FUNCTION_TOOL_SANDBOX_POOL_TTL_MS || cached.useCount >= FUNCTION_TOOL_SANDBOX_MAX_USE_COUNT) {
|
|
1197
|
+
toRemove.push(hash);
|
|
982
1198
|
}
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
1199
|
+
}
|
|
1200
|
+
if (toRemove.length > 0) {
|
|
1201
|
+
logger17.info(
|
|
1202
|
+
{
|
|
1203
|
+
count: toRemove.length,
|
|
1204
|
+
poolSize: this.sandboxPool.size
|
|
1205
|
+
},
|
|
1206
|
+
"Cleaning up expired sandboxes"
|
|
1207
|
+
);
|
|
1208
|
+
for (const hash of toRemove) {
|
|
1209
|
+
this.removeSandbox(hash);
|
|
994
1210
|
}
|
|
995
|
-
}
|
|
996
|
-
|
|
997
|
-
// Run every minute
|
|
998
|
-
);
|
|
1211
|
+
}
|
|
1212
|
+
}, FUNCTION_TOOL_SANDBOX_CLEANUP_INTERVAL_MS);
|
|
999
1213
|
}
|
|
1000
1214
|
/**
|
|
1001
1215
|
* Cleanup all sandboxes and stop cleanup interval
|
|
@@ -2552,14 +2766,13 @@ __publicField(_ModelFactory, "BUILT_IN_PROVIDERS", [
|
|
|
2552
2766
|
var ModelFactory = _ModelFactory;
|
|
2553
2767
|
|
|
2554
2768
|
// src/agents/ToolSessionManager.ts
|
|
2769
|
+
init_execution_limits();
|
|
2555
2770
|
init_logger();
|
|
2556
2771
|
var logger5 = agentsCore.getLogger("ToolSessionManager");
|
|
2557
2772
|
var _ToolSessionManager = class _ToolSessionManager {
|
|
2558
|
-
// 5 minutes
|
|
2559
2773
|
constructor() {
|
|
2560
2774
|
__publicField(this, "sessions", /* @__PURE__ */ new Map());
|
|
2561
|
-
|
|
2562
|
-
setInterval(() => this.cleanupExpiredSessions(), 6e4);
|
|
2775
|
+
setInterval(() => this.cleanupExpiredSessions(), SESSION_CLEANUP_INTERVAL_MS);
|
|
2563
2776
|
}
|
|
2564
2777
|
static getInstance() {
|
|
2565
2778
|
if (!_ToolSessionManager.instance) {
|
|
@@ -2704,7 +2917,7 @@ var _ToolSessionManager = class _ToolSessionManager {
|
|
|
2704
2917
|
const now = Date.now();
|
|
2705
2918
|
const expiredSessions = [];
|
|
2706
2919
|
for (const [sessionId, session] of this.sessions.entries()) {
|
|
2707
|
-
if (now - session.createdAt >
|
|
2920
|
+
if (now - session.createdAt > SESSION_TOOL_RESULT_CACHE_TIMEOUT_MS) {
|
|
2708
2921
|
expiredSessions.push(sessionId);
|
|
2709
2922
|
}
|
|
2710
2923
|
}
|
|
@@ -2722,6 +2935,7 @@ var ToolSessionManager = _ToolSessionManager;
|
|
|
2722
2935
|
var toolSessionManager = ToolSessionManager.getInstance();
|
|
2723
2936
|
|
|
2724
2937
|
// src/services/AgentSession.ts
|
|
2938
|
+
init_execution_limits();
|
|
2725
2939
|
init_conversations();
|
|
2726
2940
|
init_dbClient();
|
|
2727
2941
|
init_logger();
|
|
@@ -3889,8 +4103,8 @@ var AgentSession = class {
|
|
|
3889
4103
|
// Track pending artifact processing
|
|
3890
4104
|
__publicField(this, "artifactProcessingErrors", /* @__PURE__ */ new Map());
|
|
3891
4105
|
// Track errors per artifact
|
|
3892
|
-
__publicField(this, "MAX_ARTIFACT_RETRIES",
|
|
3893
|
-
__publicField(this, "MAX_PENDING_ARTIFACTS",
|
|
4106
|
+
__publicField(this, "MAX_ARTIFACT_RETRIES", ARTIFACT_GENERATION_MAX_RETRIES);
|
|
4107
|
+
__publicField(this, "MAX_PENDING_ARTIFACTS", ARTIFACT_SESSION_MAX_PENDING);
|
|
3894
4108
|
// Prevent unbounded growth
|
|
3895
4109
|
__publicField(this, "scheduledTimeouts");
|
|
3896
4110
|
// Track scheduled timeouts for cleanup
|
|
@@ -4010,8 +4224,8 @@ var AgentSession = class {
|
|
|
4010
4224
|
summarizerModel,
|
|
4011
4225
|
baseModel,
|
|
4012
4226
|
config: {
|
|
4013
|
-
numEvents: config.numEvents ||
|
|
4014
|
-
timeInSeconds: config.timeInSeconds ||
|
|
4227
|
+
numEvents: config.numEvents || STATUS_UPDATE_DEFAULT_NUM_EVENTS,
|
|
4228
|
+
timeInSeconds: config.timeInSeconds || STATUS_UPDATE_DEFAULT_INTERVAL_SECONDS,
|
|
4015
4229
|
...config
|
|
4016
4230
|
}
|
|
4017
4231
|
};
|
|
@@ -4354,7 +4568,7 @@ var AgentSession = class {
|
|
|
4354
4568
|
}
|
|
4355
4569
|
return;
|
|
4356
4570
|
}
|
|
4357
|
-
if (this.previousSummaries.length >
|
|
4571
|
+
if (this.previousSummaries.length > ARTIFACT_SESSION_MAX_PREVIOUS_SUMMARIES) {
|
|
4358
4572
|
this.previousSummaries.shift();
|
|
4359
4573
|
}
|
|
4360
4574
|
if (this.statusUpdateState) {
|
|
@@ -4467,9 +4681,8 @@ var AgentSession = class {
|
|
|
4467
4681
|
projectId: this.projectId,
|
|
4468
4682
|
conversationId: this.sessionId,
|
|
4469
4683
|
options: {
|
|
4470
|
-
limit:
|
|
4471
|
-
|
|
4472
|
-
maxOutputTokens: 2e3
|
|
4684
|
+
limit: agentsCore.CONVERSATION_HISTORY_DEFAULT_LIMIT,
|
|
4685
|
+
maxOutputTokens: agentsCore.CONVERSATION_HISTORY_MAX_OUTPUT_TOKENS_DEFAULT
|
|
4473
4686
|
},
|
|
4474
4687
|
filters: {}
|
|
4475
4688
|
});
|
|
@@ -4488,12 +4701,12 @@ ${conversationHistory}
|
|
|
4488
4701
|
Previous updates sent to user:
|
|
4489
4702
|
${previousSummaries.map((s, i) => `${i + 1}. ${s}`).join("\n")}
|
|
4490
4703
|
` : "";
|
|
4491
|
-
const selectionSchema =
|
|
4704
|
+
const selectionSchema = z7.z.object(
|
|
4492
4705
|
Object.fromEntries([
|
|
4493
4706
|
[
|
|
4494
4707
|
"no_relevant_updates",
|
|
4495
|
-
|
|
4496
|
-
no_updates:
|
|
4708
|
+
z7.z.object({
|
|
4709
|
+
no_updates: z7.z.boolean().default(true)
|
|
4497
4710
|
}).optional().describe(
|
|
4498
4711
|
"Use when nothing substantially new to report. Should only use on its own."
|
|
4499
4712
|
)
|
|
@@ -4625,8 +4838,8 @@ ${this.statusUpdateState?.config.prompt?.trim() || ""}`;
|
|
|
4625
4838
|
if (component.detailsSchema && "properties" in component.detailsSchema) {
|
|
4626
4839
|
return this.buildZodSchemaFromJson(component.detailsSchema);
|
|
4627
4840
|
}
|
|
4628
|
-
return
|
|
4629
|
-
label:
|
|
4841
|
+
return z7.z.object({
|
|
4842
|
+
label: z7.z.string().describe(
|
|
4630
4843
|
'A short 3-5 word phrase, that is a descriptive label for the update component. This Label must be EXTREMELY unique to represent the UNIQUE update we are providing. The ACTUAL finding or result, not the action. What specific information was discovered? (e.g., "Slack requires OAuth 2.0 setup", "Found 5 integration methods", "API rate limit is 100/minute"). Include the actual detail or insight, not just that you searched or processed. CRITICAL: Only use facts explicitly found in the activities - NEVER invent names, people, organizations, or details that are not present in the actual tool results.'
|
|
4631
4844
|
)
|
|
4632
4845
|
});
|
|
@@ -4636,56 +4849,56 @@ ${this.statusUpdateState?.config.prompt?.trim() || ""}`;
|
|
|
4636
4849
|
*/
|
|
4637
4850
|
buildZodSchemaFromJson(jsonSchema) {
|
|
4638
4851
|
const properties = {};
|
|
4639
|
-
properties.label =
|
|
4852
|
+
properties.label = z7.z.string().describe(
|
|
4640
4853
|
'A short 3-5 word phrase, that is a descriptive label for the update component. This Label must be EXTREMELY unique to represent the UNIQUE update we are providing. The SPECIFIC finding, result, or insight discovered (e.g., "Slack bot needs workspace admin role", "Found ingestion requires 3 steps", "Channel history limited to 10k messages"). State the ACTUAL information found, not that you searched. What did you LEARN or DISCOVER? What specific detail is now known? CRITICAL: Only use facts explicitly found in the activities - NEVER invent names, people, organizations, or details that are not present in the actual tool results.'
|
|
4641
4854
|
);
|
|
4642
4855
|
for (const [key, value] of Object.entries(jsonSchema.properties)) {
|
|
4643
4856
|
let zodType;
|
|
4644
4857
|
if (value.enum && Array.isArray(value.enum)) {
|
|
4645
4858
|
if (value.enum.length === 1) {
|
|
4646
|
-
zodType =
|
|
4859
|
+
zodType = z7.z.literal(value.enum[0]);
|
|
4647
4860
|
} else {
|
|
4648
4861
|
const [first, ...rest] = value.enum;
|
|
4649
|
-
zodType =
|
|
4862
|
+
zodType = z7.z.enum([first, ...rest]);
|
|
4650
4863
|
}
|
|
4651
4864
|
} else if (value.type === "string") {
|
|
4652
|
-
zodType =
|
|
4865
|
+
zodType = z7.z.string();
|
|
4653
4866
|
if (value.minLength) zodType = zodType.min(value.minLength);
|
|
4654
4867
|
if (value.maxLength) zodType = zodType.max(value.maxLength);
|
|
4655
4868
|
if (value.format === "email") zodType = zodType.email();
|
|
4656
4869
|
if (value.format === "url" || value.format === "uri")
|
|
4657
4870
|
zodType = zodType.url();
|
|
4658
4871
|
} else if (value.type === "number" || value.type === "integer") {
|
|
4659
|
-
zodType = value.type === "integer" ?
|
|
4872
|
+
zodType = value.type === "integer" ? z7.z.number().int() : z7.z.number();
|
|
4660
4873
|
if (value.minimum !== void 0) zodType = zodType.min(value.minimum);
|
|
4661
4874
|
if (value.maximum !== void 0) zodType = zodType.max(value.maximum);
|
|
4662
4875
|
} else if (value.type === "boolean") {
|
|
4663
|
-
zodType =
|
|
4876
|
+
zodType = z7.z.boolean();
|
|
4664
4877
|
} else if (value.type === "array") {
|
|
4665
4878
|
if (value.items) {
|
|
4666
4879
|
if (value.items.enum && Array.isArray(value.items.enum)) {
|
|
4667
4880
|
const [first, ...rest] = value.items.enum;
|
|
4668
|
-
zodType =
|
|
4881
|
+
zodType = z7.z.array(z7.z.enum([first, ...rest]));
|
|
4669
4882
|
} else if (value.items.type === "string") {
|
|
4670
|
-
zodType =
|
|
4883
|
+
zodType = z7.z.array(z7.z.string());
|
|
4671
4884
|
} else if (value.items.type === "number") {
|
|
4672
|
-
zodType =
|
|
4885
|
+
zodType = z7.z.array(z7.z.number());
|
|
4673
4886
|
} else if (value.items.type === "boolean") {
|
|
4674
|
-
zodType =
|
|
4887
|
+
zodType = z7.z.array(z7.z.boolean());
|
|
4675
4888
|
} else if (value.items.type === "object") {
|
|
4676
|
-
zodType =
|
|
4889
|
+
zodType = z7.z.array(z7.z.record(z7.z.string(), z7.z.any()));
|
|
4677
4890
|
} else {
|
|
4678
|
-
zodType =
|
|
4891
|
+
zodType = z7.z.array(z7.z.any());
|
|
4679
4892
|
}
|
|
4680
4893
|
} else {
|
|
4681
|
-
zodType =
|
|
4894
|
+
zodType = z7.z.array(z7.z.any());
|
|
4682
4895
|
}
|
|
4683
4896
|
if (value.minItems) zodType = zodType.min(value.minItems);
|
|
4684
4897
|
if (value.maxItems) zodType = zodType.max(value.maxItems);
|
|
4685
4898
|
} else if (value.type === "object") {
|
|
4686
|
-
zodType =
|
|
4899
|
+
zodType = z7.z.record(z7.z.string(), z7.z.any());
|
|
4687
4900
|
} else {
|
|
4688
|
-
zodType =
|
|
4901
|
+
zodType = z7.z.any();
|
|
4689
4902
|
}
|
|
4690
4903
|
if (value.description) {
|
|
4691
4904
|
zodType = zodType.describe(value.description);
|
|
@@ -4695,7 +4908,7 @@ ${this.statusUpdateState?.config.prompt?.trim() || ""}`;
|
|
|
4695
4908
|
}
|
|
4696
4909
|
properties[key] = zodType;
|
|
4697
4910
|
}
|
|
4698
|
-
return
|
|
4911
|
+
return z7.z.object(properties);
|
|
4699
4912
|
}
|
|
4700
4913
|
/**
|
|
4701
4914
|
* Extract user-visible activities with rich formatting and complete information
|
|
@@ -4926,9 +5139,9 @@ Make it specific and relevant.`;
|
|
|
4926
5139
|
};
|
|
4927
5140
|
} else {
|
|
4928
5141
|
const model = ModelFactory.createModel(modelToUse);
|
|
4929
|
-
const schema =
|
|
4930
|
-
name:
|
|
4931
|
-
description:
|
|
5142
|
+
const schema = z7.z.object({
|
|
5143
|
+
name: z7.z.string().describe("Concise, descriptive name for the artifact"),
|
|
5144
|
+
description: z7.z.string().describe("Brief description of the artifact's relevance to the user's question")
|
|
4932
5145
|
});
|
|
4933
5146
|
const { object } = await tracer.startActiveSpan(
|
|
4934
5147
|
"agent_session.generate_artifact_metadata",
|
|
@@ -4998,7 +5211,10 @@ Make it specific and relevant.`;
|
|
|
4998
5211
|
`Artifact name/description generation failed, attempt ${attempt}/${maxRetries}`
|
|
4999
5212
|
);
|
|
5000
5213
|
if (attempt < maxRetries) {
|
|
5001
|
-
const backoffMs = Math.min(
|
|
5214
|
+
const backoffMs = Math.min(
|
|
5215
|
+
ARTIFACT_GENERATION_BACKOFF_INITIAL_MS * 2 ** (attempt - 1),
|
|
5216
|
+
ARTIFACT_GENERATION_BACKOFF_MAX_MS
|
|
5217
|
+
);
|
|
5002
5218
|
await new Promise((resolve) => setTimeout(resolve, backoffMs));
|
|
5003
5219
|
}
|
|
5004
5220
|
}
|
|
@@ -5316,11 +5532,13 @@ async function resolveModelConfig(agentId, subAgent) {
|
|
|
5316
5532
|
}
|
|
5317
5533
|
|
|
5318
5534
|
// src/agents/Agent.ts
|
|
5535
|
+
init_execution_limits();
|
|
5319
5536
|
init_conversations();
|
|
5320
5537
|
init_dbClient();
|
|
5321
5538
|
init_logger();
|
|
5322
5539
|
|
|
5323
5540
|
// src/services/IncrementalStreamParser.ts
|
|
5541
|
+
init_execution_limits();
|
|
5324
5542
|
init_logger();
|
|
5325
5543
|
var logger10 = agentsCore.getLogger("IncrementalStreamParser");
|
|
5326
5544
|
var _IncrementalStreamParser = class _IncrementalStreamParser {
|
|
@@ -5715,11 +5933,11 @@ ${chunk}`;
|
|
|
5715
5933
|
}
|
|
5716
5934
|
}
|
|
5717
5935
|
};
|
|
5718
|
-
__publicField(_IncrementalStreamParser, "MAX_SNAPSHOT_SIZE",
|
|
5936
|
+
__publicField(_IncrementalStreamParser, "MAX_SNAPSHOT_SIZE", STREAM_PARSER_MAX_SNAPSHOT_SIZE);
|
|
5719
5937
|
// Max number of snapshots to keep
|
|
5720
|
-
__publicField(_IncrementalStreamParser, "MAX_STREAMED_SIZE",
|
|
5938
|
+
__publicField(_IncrementalStreamParser, "MAX_STREAMED_SIZE", STREAM_PARSER_MAX_STREAMED_SIZE);
|
|
5721
5939
|
// Max number of streamed component IDs to track
|
|
5722
|
-
__publicField(_IncrementalStreamParser, "MAX_COLLECTED_PARTS",
|
|
5940
|
+
__publicField(_IncrementalStreamParser, "MAX_COLLECTED_PARTS", STREAM_PARSER_MAX_COLLECTED_PARTS);
|
|
5723
5941
|
var IncrementalStreamParser = _IncrementalStreamParser;
|
|
5724
5942
|
|
|
5725
5943
|
// src/services/ResponseFormatter.ts
|
|
@@ -5925,7 +6143,7 @@ var logger12 = agentsCore.getLogger("DataComponentSchema");
|
|
|
5925
6143
|
function jsonSchemaToZod(jsonSchema) {
|
|
5926
6144
|
if (!jsonSchema || typeof jsonSchema !== "object") {
|
|
5927
6145
|
logger12.warn({ jsonSchema }, "Invalid JSON schema provided, using string fallback");
|
|
5928
|
-
return
|
|
6146
|
+
return z7.z.string();
|
|
5929
6147
|
}
|
|
5930
6148
|
switch (jsonSchema.type) {
|
|
5931
6149
|
case "object":
|
|
@@ -5934,22 +6152,22 @@ function jsonSchemaToZod(jsonSchema) {
|
|
|
5934
6152
|
for (const [key, prop] of Object.entries(jsonSchema.properties)) {
|
|
5935
6153
|
shape[key] = jsonSchemaToZod(prop);
|
|
5936
6154
|
}
|
|
5937
|
-
return
|
|
6155
|
+
return z7.z.object(shape);
|
|
5938
6156
|
}
|
|
5939
|
-
return
|
|
6157
|
+
return z7.z.record(z7.z.string(), z7.z.unknown());
|
|
5940
6158
|
case "array": {
|
|
5941
|
-
const itemSchema = jsonSchema.items ? jsonSchemaToZod(jsonSchema.items) :
|
|
5942
|
-
return
|
|
6159
|
+
const itemSchema = jsonSchema.items ? jsonSchemaToZod(jsonSchema.items) : z7.z.unknown();
|
|
6160
|
+
return z7.z.array(itemSchema);
|
|
5943
6161
|
}
|
|
5944
6162
|
case "string":
|
|
5945
|
-
return
|
|
6163
|
+
return z7.z.string();
|
|
5946
6164
|
case "number":
|
|
5947
6165
|
case "integer":
|
|
5948
|
-
return
|
|
6166
|
+
return z7.z.number();
|
|
5949
6167
|
case "boolean":
|
|
5950
|
-
return
|
|
6168
|
+
return z7.z.boolean();
|
|
5951
6169
|
case "null":
|
|
5952
|
-
return
|
|
6170
|
+
return z7.z.null();
|
|
5953
6171
|
default:
|
|
5954
6172
|
logger12.warn(
|
|
5955
6173
|
{
|
|
@@ -5958,7 +6176,7 @@ function jsonSchemaToZod(jsonSchema) {
|
|
|
5958
6176
|
},
|
|
5959
6177
|
"Unsupported JSON schema type, using unknown validation"
|
|
5960
6178
|
);
|
|
5961
|
-
return
|
|
6179
|
+
return z7.z.unknown();
|
|
5962
6180
|
}
|
|
5963
6181
|
}
|
|
5964
6182
|
|
|
@@ -6191,9 +6409,9 @@ var _ArtifactReferenceSchema = class _ArtifactReferenceSchema {
|
|
|
6191
6409
|
* Get the standard Zod schema for artifact reference components
|
|
6192
6410
|
*/
|
|
6193
6411
|
static getSchema() {
|
|
6194
|
-
return
|
|
6195
|
-
id:
|
|
6196
|
-
name:
|
|
6412
|
+
return z7.z.object({
|
|
6413
|
+
id: z7.z.string(),
|
|
6414
|
+
name: z7.z.literal("Artifact"),
|
|
6197
6415
|
props: jsonSchemaToZod(_ArtifactReferenceSchema.ARTIFACT_PROPS_SCHEMA)
|
|
6198
6416
|
});
|
|
6199
6417
|
}
|
|
@@ -6260,9 +6478,9 @@ var ArtifactCreateSchema = class {
|
|
|
6260
6478
|
},
|
|
6261
6479
|
required: ["id", "tool_call_id", "type", "base_selector"]
|
|
6262
6480
|
};
|
|
6263
|
-
return
|
|
6264
|
-
id:
|
|
6265
|
-
name:
|
|
6481
|
+
return z7.z.object({
|
|
6482
|
+
id: z7.z.string(),
|
|
6483
|
+
name: z7.z.literal(`ArtifactCreate_${component.name}`),
|
|
6266
6484
|
props: jsonSchemaToZod(propsSchema)
|
|
6267
6485
|
});
|
|
6268
6486
|
});
|
|
@@ -6934,10 +7152,12 @@ var A2AClient = class {
|
|
|
6934
7152
|
};
|
|
6935
7153
|
|
|
6936
7154
|
// src/agents/relationTools.ts
|
|
7155
|
+
init_execution_limits();
|
|
6937
7156
|
init_conversations();
|
|
6938
7157
|
init_dbClient();
|
|
6939
7158
|
init_logger();
|
|
6940
7159
|
var logger14 = agentsCore.getLogger("relationships Tools");
|
|
7160
|
+
var A2A_RETRY_STATUS_CODES = ["429", "500", "502", "503", "504"];
|
|
6941
7161
|
var generateTransferToolDescription = (config) => {
|
|
6942
7162
|
let toolsSection = "";
|
|
6943
7163
|
let transferSection = "";
|
|
@@ -7038,7 +7258,7 @@ var createTransferToAgentTool = ({
|
|
|
7038
7258
|
const toolDescription = generateTransferToolDescription(transferConfig);
|
|
7039
7259
|
return ai.tool({
|
|
7040
7260
|
description: toolDescription,
|
|
7041
|
-
inputSchema:
|
|
7261
|
+
inputSchema: z7__default.default.object({}),
|
|
7042
7262
|
execute: async () => {
|
|
7043
7263
|
const activeSpan = api.trace.getActiveSpan();
|
|
7044
7264
|
if (activeSpan) {
|
|
@@ -7093,7 +7313,7 @@ function createDelegateToAgentTool({
|
|
|
7093
7313
|
}) {
|
|
7094
7314
|
return ai.tool({
|
|
7095
7315
|
description: generateDelegateToolDescription(delegateConfig),
|
|
7096
|
-
inputSchema:
|
|
7316
|
+
inputSchema: z7__default.default.object({ message: z7__default.default.string() }),
|
|
7097
7317
|
execute: async (input, context) => {
|
|
7098
7318
|
const delegationId = `del_${agentsCore.generateId()}`;
|
|
7099
7319
|
const activeSpan = api.trace.getActiveSpan();
|
|
@@ -7190,13 +7410,12 @@ function createDelegateToAgentTool({
|
|
|
7190
7410
|
retryConfig: {
|
|
7191
7411
|
strategy: "backoff",
|
|
7192
7412
|
retryConnectionErrors: true,
|
|
7193
|
-
statusCodes: [
|
|
7413
|
+
statusCodes: [...A2A_RETRY_STATUS_CODES],
|
|
7194
7414
|
backoff: {
|
|
7195
|
-
initialInterval:
|
|
7196
|
-
maxInterval:
|
|
7197
|
-
exponent:
|
|
7198
|
-
maxElapsedTime:
|
|
7199
|
-
// 1 minute max retry time
|
|
7415
|
+
initialInterval: DELEGATION_TOOL_BACKOFF_INITIAL_INTERVAL_MS,
|
|
7416
|
+
maxInterval: DELEGATION_TOOL_BACKOFF_MAX_INTERVAL_MS,
|
|
7417
|
+
exponent: DELEGATION_TOOL_BACKOFF_EXPONENT,
|
|
7418
|
+
maxElapsedTime: DELEGATION_TOOL_BACKOFF_MAX_ELAPSED_TIME_MS
|
|
7200
7419
|
}
|
|
7201
7420
|
}
|
|
7202
7421
|
});
|
|
@@ -8371,12 +8590,6 @@ function hasToolCallWithPrefix(prefix) {
|
|
|
8371
8590
|
};
|
|
8372
8591
|
}
|
|
8373
8592
|
var logger19 = agentsCore.getLogger("Agent");
|
|
8374
|
-
var CONSTANTS = {
|
|
8375
|
-
MAX_GENERATION_STEPS: 12,
|
|
8376
|
-
PHASE_1_TIMEOUT_MS: 27e4,
|
|
8377
|
-
NON_STREAMING_PHASE_1_TIMEOUT_MS: 9e4,
|
|
8378
|
-
PHASE_2_TIMEOUT_MS: 9e4
|
|
8379
|
-
};
|
|
8380
8593
|
function validateModel(modelString, modelType) {
|
|
8381
8594
|
if (!modelString?.trim()) {
|
|
8382
8595
|
throw new Error(
|
|
@@ -8445,10 +8658,10 @@ var Agent = class {
|
|
|
8445
8658
|
}
|
|
8446
8659
|
/**
|
|
8447
8660
|
* Get the maximum number of generation steps for this agent
|
|
8448
|
-
* Uses agent's stopWhen.stepCountIs config or defaults to
|
|
8661
|
+
* Uses agent's stopWhen.stepCountIs config or defaults to AGENT_EXECUTION_MAX_GENERATION_STEPS
|
|
8449
8662
|
*/
|
|
8450
8663
|
getMaxGenerationSteps() {
|
|
8451
|
-
return this.config.stopWhen?.stepCountIs ??
|
|
8664
|
+
return this.config.stopWhen?.stepCountIs ?? AGENT_EXECUTION_MAX_GENERATION_STEPS;
|
|
8452
8665
|
}
|
|
8453
8666
|
/**
|
|
8454
8667
|
* Sanitizes tool names at runtime for AI SDK compatibility.
|
|
@@ -9004,8 +9217,8 @@ var Agent = class {
|
|
|
9004
9217
|
const defaultSandboxConfig = {
|
|
9005
9218
|
provider: "native",
|
|
9006
9219
|
runtime: "node22",
|
|
9007
|
-
timeout:
|
|
9008
|
-
vcpus:
|
|
9220
|
+
timeout: FUNCTION_TOOL_EXECUTION_TIMEOUT_MS_DEFAULT,
|
|
9221
|
+
vcpus: FUNCTION_TOOL_SANDBOX_VCPUS_DEFAULT
|
|
9009
9222
|
};
|
|
9010
9223
|
const result = await sandboxExecutor.executeFunctionTool(functionToolDef.id, args, {
|
|
9011
9224
|
description: functionToolDef.description || functionToolDef.name,
|
|
@@ -9306,9 +9519,9 @@ var Agent = class {
|
|
|
9306
9519
|
getArtifactTools() {
|
|
9307
9520
|
return ai.tool({
|
|
9308
9521
|
description: "Call this tool to get the complete artifact data with the given artifactId. This retrieves the full artifact content (not just the summary). Only use this when you need the complete artifact data and the summary shown in your context is insufficient.",
|
|
9309
|
-
inputSchema:
|
|
9310
|
-
artifactId:
|
|
9311
|
-
toolCallId:
|
|
9522
|
+
inputSchema: z7.z.object({
|
|
9523
|
+
artifactId: z7.z.string().describe("The unique identifier of the artifact to get."),
|
|
9524
|
+
toolCallId: z7.z.string().describe("The tool call ID associated with this artifact.")
|
|
9312
9525
|
}),
|
|
9313
9526
|
execute: async ({ artifactId, toolCallId }) => {
|
|
9314
9527
|
logger19.info({ artifactId, toolCallId }, "get_artifact_full executed");
|
|
@@ -9335,9 +9548,9 @@ var Agent = class {
|
|
|
9335
9548
|
createThinkingCompleteTool() {
|
|
9336
9549
|
return ai.tool({
|
|
9337
9550
|
description: "\u{1F6A8} CRITICAL: Call this tool IMMEDIATELY when you have gathered enough information to answer the user. This is MANDATORY - you CANNOT provide text responses in thinking mode, only tool calls. Call thinking_complete as soon as you have sufficient data to generate a structured response.",
|
|
9338
|
-
inputSchema:
|
|
9339
|
-
complete:
|
|
9340
|
-
summary:
|
|
9551
|
+
inputSchema: z7.z.object({
|
|
9552
|
+
complete: z7.z.boolean().describe("ALWAYS set to true - marks end of research phase"),
|
|
9553
|
+
summary: z7.z.string().describe(
|
|
9341
9554
|
"Brief summary of what information was gathered and why it is sufficient to answer the user"
|
|
9342
9555
|
)
|
|
9343
9556
|
}),
|
|
@@ -9694,15 +9907,14 @@ var Agent = class {
|
|
|
9694
9907
|
let textResponse;
|
|
9695
9908
|
const hasStructuredOutput = this.config.dataComponents && this.config.dataComponents.length > 0;
|
|
9696
9909
|
const shouldStreamPhase1 = this.getStreamingHelper() && !hasStructuredOutput;
|
|
9697
|
-
const
|
|
9698
|
-
const
|
|
9699
|
-
|
|
9700
|
-
if (modelSettings.maxDuration && modelSettings.maxDuration * 1e3 > MAX_ALLOWED_TIMEOUT_MS) {
|
|
9910
|
+
const configuredTimeout = modelSettings.maxDuration ? Math.min(modelSettings.maxDuration * 1e3, LLM_GENERATION_MAX_ALLOWED_TIMEOUT_MS) : shouldStreamPhase1 ? LLM_GENERATION_FIRST_CALL_TIMEOUT_MS_STREAMING : LLM_GENERATION_FIRST_CALL_TIMEOUT_MS_NON_STREAMING;
|
|
9911
|
+
const timeoutMs = Math.min(configuredTimeout, LLM_GENERATION_MAX_ALLOWED_TIMEOUT_MS);
|
|
9912
|
+
if (modelSettings.maxDuration && modelSettings.maxDuration * 1e3 > LLM_GENERATION_MAX_ALLOWED_TIMEOUT_MS) {
|
|
9701
9913
|
logger19.warn(
|
|
9702
9914
|
{
|
|
9703
9915
|
requestedTimeout: modelSettings.maxDuration * 1e3,
|
|
9704
9916
|
appliedTimeout: timeoutMs,
|
|
9705
|
-
maxAllowed:
|
|
9917
|
+
maxAllowed: LLM_GENERATION_MAX_ALLOWED_TIMEOUT_MS
|
|
9706
9918
|
},
|
|
9707
9919
|
"Requested timeout exceeded maximum allowed, capping to 10 minutes"
|
|
9708
9920
|
);
|
|
@@ -9978,9 +10190,9 @@ ${output}${structureHintsFormatted}`;
|
|
|
9978
10190
|
this.config.dataComponents.forEach((dc) => {
|
|
9979
10191
|
const propsSchema = jsonSchemaToZod(dc.props);
|
|
9980
10192
|
componentSchemas.push(
|
|
9981
|
-
|
|
9982
|
-
id:
|
|
9983
|
-
name:
|
|
10193
|
+
z7.z.object({
|
|
10194
|
+
id: z7.z.string(),
|
|
10195
|
+
name: z7.z.literal(dc.name),
|
|
9984
10196
|
props: propsSchema
|
|
9985
10197
|
})
|
|
9986
10198
|
);
|
|
@@ -9997,14 +10209,32 @@ ${output}${structureHintsFormatted}`;
|
|
|
9997
10209
|
if (componentSchemas.length === 1) {
|
|
9998
10210
|
dataComponentsSchema = componentSchemas[0];
|
|
9999
10211
|
} else {
|
|
10000
|
-
dataComponentsSchema =
|
|
10212
|
+
dataComponentsSchema = z7.z.union(
|
|
10001
10213
|
componentSchemas
|
|
10002
10214
|
);
|
|
10003
10215
|
}
|
|
10004
10216
|
const structuredModelSettings = ModelFactory.prepareGenerationConfig(
|
|
10005
10217
|
this.getStructuredOutputModel()
|
|
10006
10218
|
);
|
|
10007
|
-
const
|
|
10219
|
+
const configuredPhase2Timeout = structuredModelSettings.maxDuration ? Math.min(
|
|
10220
|
+
structuredModelSettings.maxDuration * 1e3,
|
|
10221
|
+
LLM_GENERATION_MAX_ALLOWED_TIMEOUT_MS
|
|
10222
|
+
) : LLM_GENERATION_SUBSEQUENT_CALL_TIMEOUT_MS;
|
|
10223
|
+
const phase2TimeoutMs = Math.min(
|
|
10224
|
+
configuredPhase2Timeout,
|
|
10225
|
+
LLM_GENERATION_MAX_ALLOWED_TIMEOUT_MS
|
|
10226
|
+
);
|
|
10227
|
+
if (structuredModelSettings.maxDuration && structuredModelSettings.maxDuration * 1e3 > LLM_GENERATION_MAX_ALLOWED_TIMEOUT_MS) {
|
|
10228
|
+
logger19.warn(
|
|
10229
|
+
{
|
|
10230
|
+
requestedTimeout: structuredModelSettings.maxDuration * 1e3,
|
|
10231
|
+
appliedTimeout: phase2TimeoutMs,
|
|
10232
|
+
maxAllowed: LLM_GENERATION_MAX_ALLOWED_TIMEOUT_MS,
|
|
10233
|
+
phase: "structured_generation"
|
|
10234
|
+
},
|
|
10235
|
+
"Phase 2 requested timeout exceeded maximum allowed, capping to 10 minutes"
|
|
10236
|
+
);
|
|
10237
|
+
}
|
|
10008
10238
|
const shouldStreamPhase2 = this.getStreamingHelper();
|
|
10009
10239
|
if (shouldStreamPhase2) {
|
|
10010
10240
|
const phase2Messages = [
|
|
@@ -10021,8 +10251,8 @@ ${output}${structureHintsFormatted}`;
|
|
|
10021
10251
|
const streamResult = ai.streamObject({
|
|
10022
10252
|
...structuredModelSettings,
|
|
10023
10253
|
messages: phase2Messages,
|
|
10024
|
-
schema:
|
|
10025
|
-
dataComponents:
|
|
10254
|
+
schema: z7.z.object({
|
|
10255
|
+
dataComponents: z7.z.array(dataComponentsSchema)
|
|
10026
10256
|
}),
|
|
10027
10257
|
experimental_telemetry: {
|
|
10028
10258
|
isEnabled: true,
|
|
@@ -10092,8 +10322,8 @@ ${output}${structureHintsFormatted}`;
|
|
|
10092
10322
|
withJsonPostProcessing2({
|
|
10093
10323
|
...structuredModelSettings,
|
|
10094
10324
|
messages: phase2Messages,
|
|
10095
|
-
schema:
|
|
10096
|
-
dataComponents:
|
|
10325
|
+
schema: z7.z.object({
|
|
10326
|
+
dataComponents: z7.z.array(dataComponentsSchema)
|
|
10097
10327
|
}),
|
|
10098
10328
|
experimental_telemetry: {
|
|
10099
10329
|
isEnabled: true,
|
|
@@ -10925,14 +11155,14 @@ app.openapi(
|
|
|
10925
11155
|
description: "Agent Card for A2A discovery",
|
|
10926
11156
|
content: {
|
|
10927
11157
|
"application/json": {
|
|
10928
|
-
schema:
|
|
10929
|
-
name:
|
|
10930
|
-
description:
|
|
10931
|
-
url:
|
|
10932
|
-
version:
|
|
10933
|
-
defaultInputModes:
|
|
10934
|
-
defaultOutputModes:
|
|
10935
|
-
skills:
|
|
11158
|
+
schema: z7.z.object({
|
|
11159
|
+
name: z7.z.string(),
|
|
11160
|
+
description: z7.z.string().optional(),
|
|
11161
|
+
url: z7.z.string(),
|
|
11162
|
+
version: z7.z.string(),
|
|
11163
|
+
defaultInputModes: z7.z.array(z7.z.string()),
|
|
11164
|
+
defaultOutputModes: z7.z.array(z7.z.string()),
|
|
11165
|
+
skills: z7.z.array(z7.z.any())
|
|
10936
11166
|
})
|
|
10937
11167
|
}
|
|
10938
11168
|
}
|
|
@@ -11179,8 +11409,12 @@ async function executeTransfer({
|
|
|
11179
11409
|
}
|
|
11180
11410
|
|
|
11181
11411
|
// src/handlers/executionHandler.ts
|
|
11412
|
+
init_execution_limits();
|
|
11182
11413
|
init_dbClient();
|
|
11183
11414
|
init_logger();
|
|
11415
|
+
|
|
11416
|
+
// src/utils/stream-helpers.ts
|
|
11417
|
+
init_execution_limits();
|
|
11184
11418
|
var SSEStreamHelper = class {
|
|
11185
11419
|
constructor(stream2, requestId2, timestamp) {
|
|
11186
11420
|
this.stream = stream2;
|
|
@@ -11353,7 +11587,6 @@ function createSSEStreamHelper(stream2, requestId2, timestamp) {
|
|
|
11353
11587
|
return new SSEStreamHelper(stream2, requestId2, timestamp);
|
|
11354
11588
|
}
|
|
11355
11589
|
var _VercelDataStreamHelper = class _VercelDataStreamHelper {
|
|
11356
|
-
// 10 minutes max lifetime
|
|
11357
11590
|
constructor(writer) {
|
|
11358
11591
|
this.writer = writer;
|
|
11359
11592
|
__publicField(this, "textId", null);
|
|
@@ -11363,18 +11596,14 @@ var _VercelDataStreamHelper = class _VercelDataStreamHelper {
|
|
|
11363
11596
|
__publicField(this, "completedItems", /* @__PURE__ */ new Set());
|
|
11364
11597
|
// Track completed items
|
|
11365
11598
|
__publicField(this, "sessionId");
|
|
11366
|
-
// 5MB limit (more generous during request)
|
|
11367
11599
|
__publicField(this, "isCompleted", false);
|
|
11368
11600
|
__publicField(this, "isTextStreaming", false);
|
|
11369
11601
|
__publicField(this, "queuedEvents", []);
|
|
11370
11602
|
__publicField(this, "lastTextEndTimestamp", 0);
|
|
11371
|
-
__publicField(this, "TEXT_GAP_THRESHOLD", 2e3);
|
|
11372
|
-
// milliseconds - if gap between text sequences is less than this, queue operations
|
|
11373
11603
|
__publicField(this, "connectionDropTimer");
|
|
11374
|
-
__publicField(this, "MAX_LIFETIME_MS", 6e5);
|
|
11375
11604
|
this.connectionDropTimer = setTimeout(() => {
|
|
11376
11605
|
this.forceCleanup("Connection lifetime exceeded");
|
|
11377
|
-
},
|
|
11606
|
+
}, STREAM_MAX_LIFETIME_MS);
|
|
11378
11607
|
}
|
|
11379
11608
|
setSessionId(sessionId) {
|
|
11380
11609
|
this.sessionId = sessionId;
|
|
@@ -11428,7 +11657,7 @@ var _VercelDataStreamHelper = class _VercelDataStreamHelper {
|
|
|
11428
11657
|
const id = this.textId;
|
|
11429
11658
|
const startTime = Date.now();
|
|
11430
11659
|
const gapFromLastSequence = this.lastTextEndTimestamp > 0 ? startTime - this.lastTextEndTimestamp : Number.MAX_SAFE_INTEGER;
|
|
11431
|
-
if (gapFromLastSequence >=
|
|
11660
|
+
if (gapFromLastSequence >= STREAM_TEXT_GAP_THRESHOLD_MS) {
|
|
11432
11661
|
await this.flushQueuedOperations();
|
|
11433
11662
|
}
|
|
11434
11663
|
this.isTextStreaming = true;
|
|
@@ -11462,7 +11691,7 @@ var _VercelDataStreamHelper = class _VercelDataStreamHelper {
|
|
|
11462
11691
|
if (type === "data-artifact") {
|
|
11463
11692
|
const now = Date.now();
|
|
11464
11693
|
const gapFromLastTextEnd = this.lastTextEndTimestamp > 0 ? now - this.lastTextEndTimestamp : Number.MAX_SAFE_INTEGER;
|
|
11465
|
-
if (this.isTextStreaming || gapFromLastTextEnd <
|
|
11694
|
+
if (this.isTextStreaming || gapFromLastTextEnd < STREAM_TEXT_GAP_THRESHOLD_MS) {
|
|
11466
11695
|
this.writer.write({
|
|
11467
11696
|
type: `${type}`,
|
|
11468
11697
|
data
|
|
@@ -11615,7 +11844,7 @@ var _VercelDataStreamHelper = class _VercelDataStreamHelper {
|
|
|
11615
11844
|
}
|
|
11616
11845
|
const now = Date.now();
|
|
11617
11846
|
const gapFromLastTextEnd = this.lastTextEndTimestamp > 0 ? now - this.lastTextEndTimestamp : Number.MAX_SAFE_INTEGER;
|
|
11618
|
-
if (this.isTextStreaming || gapFromLastTextEnd <
|
|
11847
|
+
if (this.isTextStreaming || gapFromLastTextEnd < STREAM_TEXT_GAP_THRESHOLD_MS) {
|
|
11619
11848
|
this.queuedEvents.push({ type: "data-summary", event: summary });
|
|
11620
11849
|
return;
|
|
11621
11850
|
}
|
|
@@ -11633,7 +11862,7 @@ var _VercelDataStreamHelper = class _VercelDataStreamHelper {
|
|
|
11633
11862
|
}
|
|
11634
11863
|
const now = Date.now();
|
|
11635
11864
|
const gapFromLastTextEnd = this.lastTextEndTimestamp > 0 ? now - this.lastTextEndTimestamp : Number.MAX_SAFE_INTEGER;
|
|
11636
|
-
if (this.isTextStreaming || gapFromLastTextEnd <
|
|
11865
|
+
if (this.isTextStreaming || gapFromLastTextEnd < STREAM_TEXT_GAP_THRESHOLD_MS) {
|
|
11637
11866
|
this.queuedEvents.push({ type: "data-operation", event: operation });
|
|
11638
11867
|
return;
|
|
11639
11868
|
}
|
|
@@ -11676,7 +11905,7 @@ var _VercelDataStreamHelper = class _VercelDataStreamHelper {
|
|
|
11676
11905
|
this.cleanup();
|
|
11677
11906
|
}
|
|
11678
11907
|
};
|
|
11679
|
-
__publicField(_VercelDataStreamHelper, "MAX_BUFFER_SIZE",
|
|
11908
|
+
__publicField(_VercelDataStreamHelper, "MAX_BUFFER_SIZE", STREAM_BUFFER_MAX_SIZE_BYTES);
|
|
11680
11909
|
var VercelDataStreamHelper = _VercelDataStreamHelper;
|
|
11681
11910
|
function createVercelStreamHelper(writer) {
|
|
11682
11911
|
return new VercelDataStreamHelper(writer);
|
|
@@ -11748,7 +11977,7 @@ var createMCPStreamHelper = createBufferingStreamHelper;
|
|
|
11748
11977
|
var logger24 = agentsCore.getLogger("ExecutionHandler");
|
|
11749
11978
|
var ExecutionHandler = class {
|
|
11750
11979
|
constructor() {
|
|
11751
|
-
__publicField(this, "MAX_ERRORS",
|
|
11980
|
+
__publicField(this, "MAX_ERRORS", AGENT_EXECUTION_MAX_CONSECUTIVE_ERRORS);
|
|
11752
11981
|
}
|
|
11753
11982
|
/**
|
|
11754
11983
|
* performs exeuction loop
|
|
@@ -11882,7 +12111,7 @@ var ExecutionHandler = class {
|
|
|
11882
12111
|
);
|
|
11883
12112
|
if (Array.isArray(task)) task = task[0];
|
|
11884
12113
|
let currentMessage = userMessage;
|
|
11885
|
-
const maxTransfers = agentConfig?.stopWhen?.transferCountIs ??
|
|
12114
|
+
const maxTransfers = agentConfig?.stopWhen?.transferCountIs ?? agentsCore.AGENT_EXECUTION_TRANSFER_COUNT_DEFAULT;
|
|
11886
12115
|
while (iterations < maxTransfers) {
|
|
11887
12116
|
iterations++;
|
|
11888
12117
|
logger24.info(
|
|
@@ -12204,36 +12433,36 @@ var chatCompletionsRoute = zodOpenapi.createRoute({
|
|
|
12204
12433
|
body: {
|
|
12205
12434
|
content: {
|
|
12206
12435
|
"application/json": {
|
|
12207
|
-
schema:
|
|
12208
|
-
model:
|
|
12209
|
-
messages:
|
|
12210
|
-
|
|
12211
|
-
role:
|
|
12212
|
-
content:
|
|
12213
|
-
|
|
12214
|
-
|
|
12215
|
-
|
|
12216
|
-
type:
|
|
12217
|
-
text:
|
|
12436
|
+
schema: z7.z.object({
|
|
12437
|
+
model: z7.z.string().describe("The model to use for the completion"),
|
|
12438
|
+
messages: z7.z.array(
|
|
12439
|
+
z7.z.object({
|
|
12440
|
+
role: z7.z.enum(["system", "user", "assistant", "function", "tool"]).describe("The role of the message"),
|
|
12441
|
+
content: z7.z.union([
|
|
12442
|
+
z7.z.string(),
|
|
12443
|
+
z7.z.array(
|
|
12444
|
+
z7.z.strictObject({
|
|
12445
|
+
type: z7.z.string(),
|
|
12446
|
+
text: z7.z.string().optional()
|
|
12218
12447
|
})
|
|
12219
12448
|
)
|
|
12220
12449
|
]).describe("The message content"),
|
|
12221
|
-
name:
|
|
12450
|
+
name: z7.z.string().optional().describe("The name of the message sender")
|
|
12222
12451
|
})
|
|
12223
12452
|
).describe("The conversation messages"),
|
|
12224
|
-
temperature:
|
|
12225
|
-
top_p:
|
|
12226
|
-
n:
|
|
12227
|
-
stream:
|
|
12228
|
-
max_tokens:
|
|
12229
|
-
presence_penalty:
|
|
12230
|
-
frequency_penalty:
|
|
12231
|
-
logit_bias:
|
|
12232
|
-
user:
|
|
12233
|
-
conversationId:
|
|
12234
|
-
tools:
|
|
12235
|
-
runConfig:
|
|
12236
|
-
headers:
|
|
12453
|
+
temperature: z7.z.number().optional().describe("Controls randomness (0-1)"),
|
|
12454
|
+
top_p: z7.z.number().optional().describe("Controls nucleus sampling"),
|
|
12455
|
+
n: z7.z.number().optional().describe("Number of completions to generate"),
|
|
12456
|
+
stream: z7.z.boolean().optional().describe("Whether to stream the response"),
|
|
12457
|
+
max_tokens: z7.z.number().optional().describe("Maximum tokens to generate"),
|
|
12458
|
+
presence_penalty: z7.z.number().optional().describe("Presence penalty (-2 to 2)"),
|
|
12459
|
+
frequency_penalty: z7.z.number().optional().describe("Frequency penalty (-2 to 2)"),
|
|
12460
|
+
logit_bias: z7.z.record(z7.z.string(), z7.z.number()).optional().describe("Token logit bias"),
|
|
12461
|
+
user: z7.z.string().optional().describe("User identifier"),
|
|
12462
|
+
conversationId: z7.z.string().optional().describe("Conversation ID for multi-turn chat"),
|
|
12463
|
+
tools: z7.z.array(z7.z.string()).optional().describe("Available tools"),
|
|
12464
|
+
runConfig: z7.z.record(z7.z.string(), z7.z.unknown()).optional().describe("Run configuration"),
|
|
12465
|
+
headers: z7.z.record(z7.z.string(), z7.z.unknown()).optional().describe(
|
|
12237
12466
|
"Headers data for template processing (validated against context config schema)"
|
|
12238
12467
|
)
|
|
12239
12468
|
})
|
|
@@ -12244,14 +12473,14 @@ var chatCompletionsRoute = zodOpenapi.createRoute({
|
|
|
12244
12473
|
responses: {
|
|
12245
12474
|
200: {
|
|
12246
12475
|
description: "Streaming chat completion response in Server-Sent Events format",
|
|
12247
|
-
headers:
|
|
12248
|
-
"Content-Type":
|
|
12249
|
-
"Cache-Control":
|
|
12250
|
-
Connection:
|
|
12476
|
+
headers: z7.z.object({
|
|
12477
|
+
"Content-Type": z7.z.string().default("text/event-stream"),
|
|
12478
|
+
"Cache-Control": z7.z.string().default("no-cache"),
|
|
12479
|
+
Connection: z7.z.string().default("keep-alive")
|
|
12251
12480
|
}),
|
|
12252
12481
|
content: {
|
|
12253
12482
|
"text/event-stream": {
|
|
12254
|
-
schema:
|
|
12483
|
+
schema: z7.z.string().describe("Server-Sent Events stream with chat completion chunks")
|
|
12255
12484
|
}
|
|
12256
12485
|
}
|
|
12257
12486
|
},
|
|
@@ -12259,13 +12488,13 @@ var chatCompletionsRoute = zodOpenapi.createRoute({
|
|
|
12259
12488
|
description: "Invalid request context or parameters",
|
|
12260
12489
|
content: {
|
|
12261
12490
|
"application/json": {
|
|
12262
|
-
schema:
|
|
12263
|
-
error:
|
|
12264
|
-
details:
|
|
12265
|
-
|
|
12266
|
-
field:
|
|
12267
|
-
message:
|
|
12268
|
-
value:
|
|
12491
|
+
schema: z7.z.object({
|
|
12492
|
+
error: z7.z.string(),
|
|
12493
|
+
details: z7.z.array(
|
|
12494
|
+
z7.z.object({
|
|
12495
|
+
field: z7.z.string(),
|
|
12496
|
+
message: z7.z.string(),
|
|
12497
|
+
value: z7.z.unknown().optional()
|
|
12269
12498
|
})
|
|
12270
12499
|
).optional()
|
|
12271
12500
|
})
|
|
@@ -12276,8 +12505,8 @@ var chatCompletionsRoute = zodOpenapi.createRoute({
|
|
|
12276
12505
|
description: "Agent or agent not found",
|
|
12277
12506
|
content: {
|
|
12278
12507
|
"application/json": {
|
|
12279
|
-
schema:
|
|
12280
|
-
error:
|
|
12508
|
+
schema: z7.z.object({
|
|
12509
|
+
error: z7.z.string()
|
|
12281
12510
|
})
|
|
12282
12511
|
}
|
|
12283
12512
|
}
|
|
@@ -12286,9 +12515,9 @@ var chatCompletionsRoute = zodOpenapi.createRoute({
|
|
|
12286
12515
|
description: "Internal server error",
|
|
12287
12516
|
content: {
|
|
12288
12517
|
"application/json": {
|
|
12289
|
-
schema:
|
|
12290
|
-
error:
|
|
12291
|
-
message:
|
|
12518
|
+
schema: z7.z.object({
|
|
12519
|
+
error: z7.z.string(),
|
|
12520
|
+
message: z7.z.string()
|
|
12292
12521
|
})
|
|
12293
12522
|
}
|
|
12294
12523
|
}
|
|
@@ -13000,7 +13229,7 @@ var getServer = async (headers2, executionContext, conversationId, credentialSto
|
|
|
13000
13229
|
"send-query-to-agent",
|
|
13001
13230
|
`Send a query to the ${agent.name} agent. The agent has the following description: ${agent.description}`,
|
|
13002
13231
|
{
|
|
13003
|
-
query:
|
|
13232
|
+
query: z7.z.string().describe("The query to send to the agent")
|
|
13004
13233
|
},
|
|
13005
13234
|
async ({ query }) => {
|
|
13006
13235
|
try {
|