@inkeep/agents-run-api 0.0.0-dev-20251108014948 → 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 +716 -271
- package/dist/index.js +325 -102
- package/package.json +2 -2
- package/templates/v1/phase1/system-prompt.xml +2 -7
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();
|
|
@@ -2982,7 +3196,16 @@ var _ArtifactService = class _ArtifactService {
|
|
|
2982
3196
|
);
|
|
2983
3197
|
return null;
|
|
2984
3198
|
}
|
|
2985
|
-
|
|
3199
|
+
let artifacts = [];
|
|
3200
|
+
artifacts = await agentsCore.getLedgerArtifacts(dbClient_default)({
|
|
3201
|
+
scopes: { tenantId: this.context.tenantId, projectId: this.context.projectId },
|
|
3202
|
+
artifactId,
|
|
3203
|
+
toolCallId
|
|
3204
|
+
});
|
|
3205
|
+
if (artifacts.length > 0) {
|
|
3206
|
+
return this.formatArtifactSummaryData(artifacts[0], artifactId, toolCallId);
|
|
3207
|
+
}
|
|
3208
|
+
artifacts = await agentsCore.getLedgerArtifacts(dbClient_default)({
|
|
2986
3209
|
scopes: { tenantId: this.context.tenantId, projectId: this.context.projectId },
|
|
2987
3210
|
artifactId,
|
|
2988
3211
|
taskId: this.context.taskId
|
|
@@ -3028,7 +3251,16 @@ var _ArtifactService = class _ArtifactService {
|
|
|
3028
3251
|
);
|
|
3029
3252
|
return null;
|
|
3030
3253
|
}
|
|
3031
|
-
|
|
3254
|
+
let artifacts = [];
|
|
3255
|
+
artifacts = await agentsCore.getLedgerArtifacts(dbClient_default)({
|
|
3256
|
+
scopes: { tenantId: this.context.tenantId, projectId: this.context.projectId },
|
|
3257
|
+
artifactId,
|
|
3258
|
+
toolCallId
|
|
3259
|
+
});
|
|
3260
|
+
if (artifacts.length > 0) {
|
|
3261
|
+
return this.formatArtifactFullData(artifacts[0], artifactId, toolCallId);
|
|
3262
|
+
}
|
|
3263
|
+
artifacts = await agentsCore.getLedgerArtifacts(dbClient_default)({
|
|
3032
3264
|
scopes: { tenantId: this.context.tenantId, projectId: this.context.projectId },
|
|
3033
3265
|
artifactId,
|
|
3034
3266
|
taskId: this.context.taskId
|
|
@@ -3871,8 +4103,8 @@ var AgentSession = class {
|
|
|
3871
4103
|
// Track pending artifact processing
|
|
3872
4104
|
__publicField(this, "artifactProcessingErrors", /* @__PURE__ */ new Map());
|
|
3873
4105
|
// Track errors per artifact
|
|
3874
|
-
__publicField(this, "MAX_ARTIFACT_RETRIES",
|
|
3875
|
-
__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);
|
|
3876
4108
|
// Prevent unbounded growth
|
|
3877
4109
|
__publicField(this, "scheduledTimeouts");
|
|
3878
4110
|
// Track scheduled timeouts for cleanup
|
|
@@ -3992,8 +4224,8 @@ var AgentSession = class {
|
|
|
3992
4224
|
summarizerModel,
|
|
3993
4225
|
baseModel,
|
|
3994
4226
|
config: {
|
|
3995
|
-
numEvents: config.numEvents ||
|
|
3996
|
-
timeInSeconds: config.timeInSeconds ||
|
|
4227
|
+
numEvents: config.numEvents || STATUS_UPDATE_DEFAULT_NUM_EVENTS,
|
|
4228
|
+
timeInSeconds: config.timeInSeconds || STATUS_UPDATE_DEFAULT_INTERVAL_SECONDS,
|
|
3997
4229
|
...config
|
|
3998
4230
|
}
|
|
3999
4231
|
};
|
|
@@ -4336,7 +4568,7 @@ var AgentSession = class {
|
|
|
4336
4568
|
}
|
|
4337
4569
|
return;
|
|
4338
4570
|
}
|
|
4339
|
-
if (this.previousSummaries.length >
|
|
4571
|
+
if (this.previousSummaries.length > ARTIFACT_SESSION_MAX_PREVIOUS_SUMMARIES) {
|
|
4340
4572
|
this.previousSummaries.shift();
|
|
4341
4573
|
}
|
|
4342
4574
|
if (this.statusUpdateState) {
|
|
@@ -4449,9 +4681,8 @@ var AgentSession = class {
|
|
|
4449
4681
|
projectId: this.projectId,
|
|
4450
4682
|
conversationId: this.sessionId,
|
|
4451
4683
|
options: {
|
|
4452
|
-
limit:
|
|
4453
|
-
|
|
4454
|
-
maxOutputTokens: 2e3
|
|
4684
|
+
limit: agentsCore.CONVERSATION_HISTORY_DEFAULT_LIMIT,
|
|
4685
|
+
maxOutputTokens: agentsCore.CONVERSATION_HISTORY_MAX_OUTPUT_TOKENS_DEFAULT
|
|
4455
4686
|
},
|
|
4456
4687
|
filters: {}
|
|
4457
4688
|
});
|
|
@@ -4470,12 +4701,12 @@ ${conversationHistory}
|
|
|
4470
4701
|
Previous updates sent to user:
|
|
4471
4702
|
${previousSummaries.map((s, i) => `${i + 1}. ${s}`).join("\n")}
|
|
4472
4703
|
` : "";
|
|
4473
|
-
const selectionSchema =
|
|
4704
|
+
const selectionSchema = z7.z.object(
|
|
4474
4705
|
Object.fromEntries([
|
|
4475
4706
|
[
|
|
4476
4707
|
"no_relevant_updates",
|
|
4477
|
-
|
|
4478
|
-
no_updates:
|
|
4708
|
+
z7.z.object({
|
|
4709
|
+
no_updates: z7.z.boolean().default(true)
|
|
4479
4710
|
}).optional().describe(
|
|
4480
4711
|
"Use when nothing substantially new to report. Should only use on its own."
|
|
4481
4712
|
)
|
|
@@ -4607,8 +4838,8 @@ ${this.statusUpdateState?.config.prompt?.trim() || ""}`;
|
|
|
4607
4838
|
if (component.detailsSchema && "properties" in component.detailsSchema) {
|
|
4608
4839
|
return this.buildZodSchemaFromJson(component.detailsSchema);
|
|
4609
4840
|
}
|
|
4610
|
-
return
|
|
4611
|
-
label:
|
|
4841
|
+
return z7.z.object({
|
|
4842
|
+
label: z7.z.string().describe(
|
|
4612
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.'
|
|
4613
4844
|
)
|
|
4614
4845
|
});
|
|
@@ -4618,56 +4849,56 @@ ${this.statusUpdateState?.config.prompt?.trim() || ""}`;
|
|
|
4618
4849
|
*/
|
|
4619
4850
|
buildZodSchemaFromJson(jsonSchema) {
|
|
4620
4851
|
const properties = {};
|
|
4621
|
-
properties.label =
|
|
4852
|
+
properties.label = z7.z.string().describe(
|
|
4622
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.'
|
|
4623
4854
|
);
|
|
4624
4855
|
for (const [key, value] of Object.entries(jsonSchema.properties)) {
|
|
4625
4856
|
let zodType;
|
|
4626
4857
|
if (value.enum && Array.isArray(value.enum)) {
|
|
4627
4858
|
if (value.enum.length === 1) {
|
|
4628
|
-
zodType =
|
|
4859
|
+
zodType = z7.z.literal(value.enum[0]);
|
|
4629
4860
|
} else {
|
|
4630
4861
|
const [first, ...rest] = value.enum;
|
|
4631
|
-
zodType =
|
|
4862
|
+
zodType = z7.z.enum([first, ...rest]);
|
|
4632
4863
|
}
|
|
4633
4864
|
} else if (value.type === "string") {
|
|
4634
|
-
zodType =
|
|
4865
|
+
zodType = z7.z.string();
|
|
4635
4866
|
if (value.minLength) zodType = zodType.min(value.minLength);
|
|
4636
4867
|
if (value.maxLength) zodType = zodType.max(value.maxLength);
|
|
4637
4868
|
if (value.format === "email") zodType = zodType.email();
|
|
4638
4869
|
if (value.format === "url" || value.format === "uri")
|
|
4639
4870
|
zodType = zodType.url();
|
|
4640
4871
|
} else if (value.type === "number" || value.type === "integer") {
|
|
4641
|
-
zodType = value.type === "integer" ?
|
|
4872
|
+
zodType = value.type === "integer" ? z7.z.number().int() : z7.z.number();
|
|
4642
4873
|
if (value.minimum !== void 0) zodType = zodType.min(value.minimum);
|
|
4643
4874
|
if (value.maximum !== void 0) zodType = zodType.max(value.maximum);
|
|
4644
4875
|
} else if (value.type === "boolean") {
|
|
4645
|
-
zodType =
|
|
4876
|
+
zodType = z7.z.boolean();
|
|
4646
4877
|
} else if (value.type === "array") {
|
|
4647
4878
|
if (value.items) {
|
|
4648
4879
|
if (value.items.enum && Array.isArray(value.items.enum)) {
|
|
4649
4880
|
const [first, ...rest] = value.items.enum;
|
|
4650
|
-
zodType =
|
|
4881
|
+
zodType = z7.z.array(z7.z.enum([first, ...rest]));
|
|
4651
4882
|
} else if (value.items.type === "string") {
|
|
4652
|
-
zodType =
|
|
4883
|
+
zodType = z7.z.array(z7.z.string());
|
|
4653
4884
|
} else if (value.items.type === "number") {
|
|
4654
|
-
zodType =
|
|
4885
|
+
zodType = z7.z.array(z7.z.number());
|
|
4655
4886
|
} else if (value.items.type === "boolean") {
|
|
4656
|
-
zodType =
|
|
4887
|
+
zodType = z7.z.array(z7.z.boolean());
|
|
4657
4888
|
} else if (value.items.type === "object") {
|
|
4658
|
-
zodType =
|
|
4889
|
+
zodType = z7.z.array(z7.z.record(z7.z.string(), z7.z.any()));
|
|
4659
4890
|
} else {
|
|
4660
|
-
zodType =
|
|
4891
|
+
zodType = z7.z.array(z7.z.any());
|
|
4661
4892
|
}
|
|
4662
4893
|
} else {
|
|
4663
|
-
zodType =
|
|
4894
|
+
zodType = z7.z.array(z7.z.any());
|
|
4664
4895
|
}
|
|
4665
4896
|
if (value.minItems) zodType = zodType.min(value.minItems);
|
|
4666
4897
|
if (value.maxItems) zodType = zodType.max(value.maxItems);
|
|
4667
4898
|
} else if (value.type === "object") {
|
|
4668
|
-
zodType =
|
|
4899
|
+
zodType = z7.z.record(z7.z.string(), z7.z.any());
|
|
4669
4900
|
} else {
|
|
4670
|
-
zodType =
|
|
4901
|
+
zodType = z7.z.any();
|
|
4671
4902
|
}
|
|
4672
4903
|
if (value.description) {
|
|
4673
4904
|
zodType = zodType.describe(value.description);
|
|
@@ -4677,7 +4908,7 @@ ${this.statusUpdateState?.config.prompt?.trim() || ""}`;
|
|
|
4677
4908
|
}
|
|
4678
4909
|
properties[key] = zodType;
|
|
4679
4910
|
}
|
|
4680
|
-
return
|
|
4911
|
+
return z7.z.object(properties);
|
|
4681
4912
|
}
|
|
4682
4913
|
/**
|
|
4683
4914
|
* Extract user-visible activities with rich formatting and complete information
|
|
@@ -4908,9 +5139,9 @@ Make it specific and relevant.`;
|
|
|
4908
5139
|
};
|
|
4909
5140
|
} else {
|
|
4910
5141
|
const model = ModelFactory.createModel(modelToUse);
|
|
4911
|
-
const schema =
|
|
4912
|
-
name:
|
|
4913
|
-
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")
|
|
4914
5145
|
});
|
|
4915
5146
|
const { object } = await tracer.startActiveSpan(
|
|
4916
5147
|
"agent_session.generate_artifact_metadata",
|
|
@@ -4980,7 +5211,10 @@ Make it specific and relevant.`;
|
|
|
4980
5211
|
`Artifact name/description generation failed, attempt ${attempt}/${maxRetries}`
|
|
4981
5212
|
);
|
|
4982
5213
|
if (attempt < maxRetries) {
|
|
4983
|
-
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
|
+
);
|
|
4984
5218
|
await new Promise((resolve) => setTimeout(resolve, backoffMs));
|
|
4985
5219
|
}
|
|
4986
5220
|
}
|
|
@@ -4996,15 +5230,8 @@ Make it specific and relevant.`;
|
|
|
4996
5230
|
);
|
|
4997
5231
|
result = object;
|
|
4998
5232
|
}
|
|
4999
|
-
const artifactService = new ArtifactService({
|
|
5000
|
-
tenantId: artifactData.tenantId,
|
|
5001
|
-
projectId: artifactData.projectId,
|
|
5002
|
-
contextId: artifactData.contextId,
|
|
5003
|
-
taskId: artifactData.taskId,
|
|
5004
|
-
sessionId: this.sessionId
|
|
5005
|
-
});
|
|
5006
5233
|
try {
|
|
5007
|
-
await artifactService.saveArtifact({
|
|
5234
|
+
await this.artifactService.saveArtifact({
|
|
5008
5235
|
artifactId: artifactData.artifactId,
|
|
5009
5236
|
name: result.name,
|
|
5010
5237
|
description: result.description,
|
|
@@ -5033,14 +5260,14 @@ Make it specific and relevant.`;
|
|
|
5033
5260
|
if (!mainSaveSucceeded) {
|
|
5034
5261
|
try {
|
|
5035
5262
|
if (artifactData.tenantId && artifactData.projectId) {
|
|
5036
|
-
const
|
|
5263
|
+
const artifactService = new ArtifactService({
|
|
5037
5264
|
tenantId: artifactData.tenantId,
|
|
5038
5265
|
projectId: artifactData.projectId,
|
|
5039
5266
|
contextId: artifactData.contextId || "unknown",
|
|
5040
5267
|
taskId: artifactData.taskId,
|
|
5041
5268
|
sessionId: this.sessionId
|
|
5042
5269
|
});
|
|
5043
|
-
await
|
|
5270
|
+
await artifactService.saveArtifact({
|
|
5044
5271
|
artifactId: artifactData.artifactId,
|
|
5045
5272
|
name: `Artifact ${artifactData.artifactId.substring(0, 8)}`,
|
|
5046
5273
|
description: `${artifactData.artifactType || "Data"} from ${artifactData.metadata?.toolName || "tool results"}`,
|
|
@@ -5305,11 +5532,13 @@ async function resolveModelConfig(agentId, subAgent) {
|
|
|
5305
5532
|
}
|
|
5306
5533
|
|
|
5307
5534
|
// src/agents/Agent.ts
|
|
5535
|
+
init_execution_limits();
|
|
5308
5536
|
init_conversations();
|
|
5309
5537
|
init_dbClient();
|
|
5310
5538
|
init_logger();
|
|
5311
5539
|
|
|
5312
5540
|
// src/services/IncrementalStreamParser.ts
|
|
5541
|
+
init_execution_limits();
|
|
5313
5542
|
init_logger();
|
|
5314
5543
|
var logger10 = agentsCore.getLogger("IncrementalStreamParser");
|
|
5315
5544
|
var _IncrementalStreamParser = class _IncrementalStreamParser {
|
|
@@ -5704,11 +5933,11 @@ ${chunk}`;
|
|
|
5704
5933
|
}
|
|
5705
5934
|
}
|
|
5706
5935
|
};
|
|
5707
|
-
__publicField(_IncrementalStreamParser, "MAX_SNAPSHOT_SIZE",
|
|
5936
|
+
__publicField(_IncrementalStreamParser, "MAX_SNAPSHOT_SIZE", STREAM_PARSER_MAX_SNAPSHOT_SIZE);
|
|
5708
5937
|
// Max number of snapshots to keep
|
|
5709
|
-
__publicField(_IncrementalStreamParser, "MAX_STREAMED_SIZE",
|
|
5938
|
+
__publicField(_IncrementalStreamParser, "MAX_STREAMED_SIZE", STREAM_PARSER_MAX_STREAMED_SIZE);
|
|
5710
5939
|
// Max number of streamed component IDs to track
|
|
5711
|
-
__publicField(_IncrementalStreamParser, "MAX_COLLECTED_PARTS",
|
|
5940
|
+
__publicField(_IncrementalStreamParser, "MAX_COLLECTED_PARTS", STREAM_PARSER_MAX_COLLECTED_PARTS);
|
|
5712
5941
|
var IncrementalStreamParser = _IncrementalStreamParser;
|
|
5713
5942
|
|
|
5714
5943
|
// src/services/ResponseFormatter.ts
|
|
@@ -5914,7 +6143,7 @@ var logger12 = agentsCore.getLogger("DataComponentSchema");
|
|
|
5914
6143
|
function jsonSchemaToZod(jsonSchema) {
|
|
5915
6144
|
if (!jsonSchema || typeof jsonSchema !== "object") {
|
|
5916
6145
|
logger12.warn({ jsonSchema }, "Invalid JSON schema provided, using string fallback");
|
|
5917
|
-
return
|
|
6146
|
+
return z7.z.string();
|
|
5918
6147
|
}
|
|
5919
6148
|
switch (jsonSchema.type) {
|
|
5920
6149
|
case "object":
|
|
@@ -5923,22 +6152,22 @@ function jsonSchemaToZod(jsonSchema) {
|
|
|
5923
6152
|
for (const [key, prop] of Object.entries(jsonSchema.properties)) {
|
|
5924
6153
|
shape[key] = jsonSchemaToZod(prop);
|
|
5925
6154
|
}
|
|
5926
|
-
return
|
|
6155
|
+
return z7.z.object(shape);
|
|
5927
6156
|
}
|
|
5928
|
-
return
|
|
6157
|
+
return z7.z.record(z7.z.string(), z7.z.unknown());
|
|
5929
6158
|
case "array": {
|
|
5930
|
-
const itemSchema = jsonSchema.items ? jsonSchemaToZod(jsonSchema.items) :
|
|
5931
|
-
return
|
|
6159
|
+
const itemSchema = jsonSchema.items ? jsonSchemaToZod(jsonSchema.items) : z7.z.unknown();
|
|
6160
|
+
return z7.z.array(itemSchema);
|
|
5932
6161
|
}
|
|
5933
6162
|
case "string":
|
|
5934
|
-
return
|
|
6163
|
+
return z7.z.string();
|
|
5935
6164
|
case "number":
|
|
5936
6165
|
case "integer":
|
|
5937
|
-
return
|
|
6166
|
+
return z7.z.number();
|
|
5938
6167
|
case "boolean":
|
|
5939
|
-
return
|
|
6168
|
+
return z7.z.boolean();
|
|
5940
6169
|
case "null":
|
|
5941
|
-
return
|
|
6170
|
+
return z7.z.null();
|
|
5942
6171
|
default:
|
|
5943
6172
|
logger12.warn(
|
|
5944
6173
|
{
|
|
@@ -5947,7 +6176,7 @@ function jsonSchemaToZod(jsonSchema) {
|
|
|
5947
6176
|
},
|
|
5948
6177
|
"Unsupported JSON schema type, using unknown validation"
|
|
5949
6178
|
);
|
|
5950
|
-
return
|
|
6179
|
+
return z7.z.unknown();
|
|
5951
6180
|
}
|
|
5952
6181
|
}
|
|
5953
6182
|
|
|
@@ -6180,9 +6409,9 @@ var _ArtifactReferenceSchema = class _ArtifactReferenceSchema {
|
|
|
6180
6409
|
* Get the standard Zod schema for artifact reference components
|
|
6181
6410
|
*/
|
|
6182
6411
|
static getSchema() {
|
|
6183
|
-
return
|
|
6184
|
-
id:
|
|
6185
|
-
name:
|
|
6412
|
+
return z7.z.object({
|
|
6413
|
+
id: z7.z.string(),
|
|
6414
|
+
name: z7.z.literal("Artifact"),
|
|
6186
6415
|
props: jsonSchemaToZod(_ArtifactReferenceSchema.ARTIFACT_PROPS_SCHEMA)
|
|
6187
6416
|
});
|
|
6188
6417
|
}
|
|
@@ -6249,9 +6478,9 @@ var ArtifactCreateSchema = class {
|
|
|
6249
6478
|
},
|
|
6250
6479
|
required: ["id", "tool_call_id", "type", "base_selector"]
|
|
6251
6480
|
};
|
|
6252
|
-
return
|
|
6253
|
-
id:
|
|
6254
|
-
name:
|
|
6481
|
+
return z7.z.object({
|
|
6482
|
+
id: z7.z.string(),
|
|
6483
|
+
name: z7.z.literal(`ArtifactCreate_${component.name}`),
|
|
6255
6484
|
props: jsonSchemaToZod(propsSchema)
|
|
6256
6485
|
});
|
|
6257
6486
|
});
|
|
@@ -6923,29 +7152,102 @@ var A2AClient = class {
|
|
|
6923
7152
|
};
|
|
6924
7153
|
|
|
6925
7154
|
// src/agents/relationTools.ts
|
|
7155
|
+
init_execution_limits();
|
|
6926
7156
|
init_conversations();
|
|
6927
7157
|
init_dbClient();
|
|
6928
7158
|
init_logger();
|
|
6929
7159
|
var logger14 = agentsCore.getLogger("relationships Tools");
|
|
7160
|
+
var A2A_RETRY_STATUS_CODES = ["429", "500", "502", "503", "504"];
|
|
6930
7161
|
var generateTransferToolDescription = (config) => {
|
|
6931
|
-
|
|
7162
|
+
let toolsSection = "";
|
|
7163
|
+
let transferSection = "";
|
|
7164
|
+
if (config.transferRelations && config.transferRelations.length > 0) {
|
|
7165
|
+
const transferList = config.transferRelations.map(
|
|
7166
|
+
(transfer) => ` - ${transfer.name || transfer.id}: ${transfer.description || "No description available"}`
|
|
7167
|
+
).join("\n");
|
|
7168
|
+
transferSection = `
|
|
7169
|
+
|
|
7170
|
+
Can Transfer To:
|
|
7171
|
+
${transferList}`;
|
|
7172
|
+
}
|
|
7173
|
+
let delegateSection = "";
|
|
7174
|
+
if (config.delegateRelations && config.delegateRelations.length > 0) {
|
|
7175
|
+
const delegateList = config.delegateRelations.map(
|
|
7176
|
+
(delegate) => ` - ${delegate.config.name || delegate.config.id}: ${delegate.config.description || "No description available"} (${delegate.type})`
|
|
7177
|
+
).join("\n");
|
|
7178
|
+
delegateSection = `
|
|
7179
|
+
|
|
7180
|
+
Can Delegate To:
|
|
7181
|
+
${delegateList}`;
|
|
7182
|
+
}
|
|
7183
|
+
if (config.tools && config.tools.length > 0) {
|
|
7184
|
+
const toolDescriptions = config.tools.map((tool3) => {
|
|
7185
|
+
const toolsList = tool3.availableTools?.map((t) => ` - ${t.name}: ${t.description || "No description available"}`).join("\n") || "";
|
|
7186
|
+
return `MCP Server: ${tool3.name}
|
|
7187
|
+
${toolsList}`;
|
|
7188
|
+
}).join("\n\n");
|
|
7189
|
+
toolsSection = `
|
|
7190
|
+
|
|
7191
|
+
Available Tools & Capabilities:
|
|
7192
|
+
${toolDescriptions}`;
|
|
7193
|
+
}
|
|
7194
|
+
const finalDescription = `Hand off the conversation to agent ${config.id}.
|
|
6932
7195
|
|
|
6933
7196
|
Agent Information:
|
|
6934
7197
|
- ID: ${config.id}
|
|
6935
7198
|
- Name: ${config.name ?? "No name provided"}
|
|
6936
|
-
- Description: ${config.description ?? "No description provided"}
|
|
7199
|
+
- Description: ${config.description ?? "No description provided"}${toolsSection}${transferSection}${delegateSection}
|
|
6937
7200
|
|
|
6938
7201
|
Hand off the conversation to agent ${config.id} when the user's request would be better handled by this specialized agent.`;
|
|
7202
|
+
return finalDescription;
|
|
6939
7203
|
};
|
|
6940
|
-
var generateDelegateToolDescription = (
|
|
6941
|
-
|
|
7204
|
+
var generateDelegateToolDescription = (delegateRelation) => {
|
|
7205
|
+
const config = delegateRelation.config;
|
|
7206
|
+
let toolsSection = "";
|
|
7207
|
+
let transferSection = "";
|
|
7208
|
+
let delegateSection = "";
|
|
7209
|
+
if (delegateRelation.type === "internal" && "tools" in config) {
|
|
7210
|
+
const agentConfig = config;
|
|
7211
|
+
if (agentConfig.tools && agentConfig.tools.length > 0) {
|
|
7212
|
+
const toolDescriptions = agentConfig.tools.map((tool3) => {
|
|
7213
|
+
const toolsList = tool3.availableTools?.map((t) => ` - ${t.name}: ${t.description || "No description available"}`).join("\n") || "";
|
|
7214
|
+
return `MCP Server: ${tool3.name}
|
|
7215
|
+
${toolsList}`;
|
|
7216
|
+
}).join("\n\n");
|
|
7217
|
+
toolsSection = `
|
|
7218
|
+
|
|
7219
|
+
Available Tools & Capabilities:
|
|
7220
|
+
${toolDescriptions}`;
|
|
7221
|
+
}
|
|
7222
|
+
if (agentConfig.transferRelations && agentConfig.transferRelations.length > 0) {
|
|
7223
|
+
const transferList = agentConfig.transferRelations.map(
|
|
7224
|
+
(transfer) => ` - ${transfer.name || transfer.id}: ${transfer.description || "No description available"}`
|
|
7225
|
+
).join("\n");
|
|
7226
|
+
transferSection = `
|
|
7227
|
+
|
|
7228
|
+
Can Transfer To:
|
|
7229
|
+
${transferList}`;
|
|
7230
|
+
}
|
|
7231
|
+
if (agentConfig.delegateRelations && agentConfig.delegateRelations.length > 0) {
|
|
7232
|
+
const delegateList = agentConfig.delegateRelations.map(
|
|
7233
|
+
(delegate) => ` - ${delegate.config.name || delegate.config.id}: ${delegate.config.description || "No description available"} (${delegate.type})`
|
|
7234
|
+
).join("\n");
|
|
7235
|
+
delegateSection = `
|
|
7236
|
+
|
|
7237
|
+
Can Delegate To:
|
|
7238
|
+
${delegateList}`;
|
|
7239
|
+
}
|
|
7240
|
+
}
|
|
7241
|
+
const finalDescription = `Delegate a specific task to another agent.
|
|
6942
7242
|
|
|
6943
7243
|
Agent Information:
|
|
6944
7244
|
- ID: ${config.id}
|
|
6945
7245
|
- Name: ${config.name}
|
|
6946
7246
|
- Description: ${config.description || "No description provided"}
|
|
7247
|
+
- Type: ${delegateRelation.type}${toolsSection}${transferSection}${delegateSection}
|
|
6947
7248
|
|
|
6948
7249
|
Delegate a specific task to agent ${config.id} when it seems like the agent can do relevant work.`;
|
|
7250
|
+
return finalDescription;
|
|
6949
7251
|
};
|
|
6950
7252
|
var createTransferToAgentTool = ({
|
|
6951
7253
|
transferConfig,
|
|
@@ -6953,9 +7255,10 @@ var createTransferToAgentTool = ({
|
|
|
6953
7255
|
subAgent,
|
|
6954
7256
|
streamRequestId
|
|
6955
7257
|
}) => {
|
|
7258
|
+
const toolDescription = generateTransferToolDescription(transferConfig);
|
|
6956
7259
|
return ai.tool({
|
|
6957
|
-
description:
|
|
6958
|
-
inputSchema:
|
|
7260
|
+
description: toolDescription,
|
|
7261
|
+
inputSchema: z7__default.default.object({}),
|
|
6959
7262
|
execute: async () => {
|
|
6960
7263
|
const activeSpan = api.trace.getActiveSpan();
|
|
6961
7264
|
if (activeSpan) {
|
|
@@ -7009,8 +7312,8 @@ function createDelegateToAgentTool({
|
|
|
7009
7312
|
credentialStoreRegistry
|
|
7010
7313
|
}) {
|
|
7011
7314
|
return ai.tool({
|
|
7012
|
-
description: generateDelegateToolDescription(delegateConfig
|
|
7013
|
-
inputSchema:
|
|
7315
|
+
description: generateDelegateToolDescription(delegateConfig),
|
|
7316
|
+
inputSchema: z7__default.default.object({ message: z7__default.default.string() }),
|
|
7014
7317
|
execute: async (input, context) => {
|
|
7015
7318
|
const delegationId = `del_${agentsCore.generateId()}`;
|
|
7016
7319
|
const activeSpan = api.trace.getActiveSpan();
|
|
@@ -7107,13 +7410,12 @@ function createDelegateToAgentTool({
|
|
|
7107
7410
|
retryConfig: {
|
|
7108
7411
|
strategy: "backoff",
|
|
7109
7412
|
retryConnectionErrors: true,
|
|
7110
|
-
statusCodes: [
|
|
7413
|
+
statusCodes: [...A2A_RETRY_STATUS_CODES],
|
|
7111
7414
|
backoff: {
|
|
7112
|
-
initialInterval:
|
|
7113
|
-
maxInterval:
|
|
7114
|
-
exponent:
|
|
7115
|
-
maxElapsedTime:
|
|
7116
|
-
// 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
|
|
7117
7419
|
}
|
|
7118
7420
|
}
|
|
7119
7421
|
});
|
|
@@ -7266,7 +7568,7 @@ var system_prompt_default = `<system_message>
|
|
|
7266
7568
|
- You ARE the user's assistant - there are no other agents, specialists, or experts
|
|
7267
7569
|
- NEVER say you are connecting them to anyone or anything
|
|
7268
7570
|
- Continue conversations as if you personally have been handling them the entire time
|
|
7269
|
-
- Answer questions directly without any transition phrases or transfer language
|
|
7571
|
+
- Answer questions directly without any transition phrases or transfer language except when transferring to another agent or delegating to another agent
|
|
7270
7572
|
{{TRANSFER_INSTRUCTIONS}}
|
|
7271
7573
|
{{DELEGATION_INSTRUCTIONS}}
|
|
7272
7574
|
</security>
|
|
@@ -7274,7 +7576,7 @@ var system_prompt_default = `<system_message>
|
|
|
7274
7576
|
<interaction_guidelines>
|
|
7275
7577
|
- Be helpful, accurate, and professional
|
|
7276
7578
|
- Use tools when appropriate to provide better assistance
|
|
7277
|
-
-
|
|
7579
|
+
- Use tools directly without announcing or explaining what you're doing ("Let me search...", "I'll look for...", etc.)
|
|
7278
7580
|
- Save important tool results as artifacts when they contain structured data that should be preserved and referenced
|
|
7279
7581
|
- Ask for clarification when requests are ambiguous
|
|
7280
7582
|
|
|
@@ -7292,11 +7594,6 @@ var system_prompt_default = `<system_message>
|
|
|
7292
7594
|
- NEVER mention delegation occurred: just present the results
|
|
7293
7595
|
- If delegation returns artifacts, reference them as if you created them
|
|
7294
7596
|
|
|
7295
|
-
\u{1F6A8} TRANSFER TOOL RULES - CRITICAL:
|
|
7296
|
-
- When calling transfer_to_* tools, call the tool IMMEDIATELY without any explanatory text
|
|
7297
|
-
- Do NOT explain the transfer, do NOT say "I'll hand this off", do NOT provide reasoning
|
|
7298
|
-
- Just call the transfer tool directly when you determine it's needed
|
|
7299
|
-
- The tool call is sufficient - no additional text should be generated
|
|
7300
7597
|
</interaction_guidelines>
|
|
7301
7598
|
|
|
7302
7599
|
{{THINKING_PREPARATION_INSTRUCTIONS}}
|
|
@@ -7515,9 +7812,24 @@ var Phase1Config = class _Phase1Config {
|
|
|
7515
7812
|
if (!hasTransferRelations) {
|
|
7516
7813
|
return "";
|
|
7517
7814
|
}
|
|
7518
|
-
return
|
|
7519
|
-
|
|
7520
|
-
|
|
7815
|
+
return `You are part of a single unified assistant composed of specialized agents. To the user, you must always appear as one continuous, confident voice.
|
|
7816
|
+
|
|
7817
|
+
You have transfer_to_* tools that seamlessly continue the conversation. When you determine another agent should handle a request: ONLY call the appropriate transfer_to_* tool. Do not provide any substantive answer, limitation, or explanation before transferring. NEVER announce, describe, or apologize for a transfer.
|
|
7818
|
+
|
|
7819
|
+
Do NOT stream any text when transferring - call the transfer tool IMMEDIATELY. Do NOT acknowledge the request, do NOT say "Looking into that...", "Let me search...", "I'll help you find...", or provide ANY explanatory text. Place all reasoning or handoff details inside the transfer tool call, not in the user message. The tool call is sufficient - no additional text should be generated.
|
|
7820
|
+
|
|
7821
|
+
CRITICAL: When you receive a user message that ends with "Please continue from where this conversation was left off" - this indicates you are continuing a conversation that another agent started. You should:
|
|
7822
|
+
- Review the conversation history to see what was already communicated to the user
|
|
7823
|
+
- Continue seamlessly from where the previous response left off
|
|
7824
|
+
- Do NOT repeat what was already said in the conversation history
|
|
7825
|
+
- Do NOT announce what you're about to do ("Let me search...", "I'll look for...", etc.)
|
|
7826
|
+
- Proceed directly with the appropriate tool or action
|
|
7827
|
+
- Act as if you have been handling the conversation from the beginning
|
|
7828
|
+
|
|
7829
|
+
When receiving any transfer, act as if you have been engaged from the start. Continue the same tone, context, and style. Never reference other agents, tools, or roles.
|
|
7830
|
+
|
|
7831
|
+
Your goal: preserve the illusion of a single, seamless, intelligent assistant. All user-facing behavior must feel like one continuous conversation, regardless of internal transfers.
|
|
7832
|
+
`;
|
|
7521
7833
|
}
|
|
7522
7834
|
generateDelegationInstructions(hasDelegateRelations) {
|
|
7523
7835
|
if (!hasDelegateRelations) {
|
|
@@ -8278,12 +8590,6 @@ function hasToolCallWithPrefix(prefix) {
|
|
|
8278
8590
|
};
|
|
8279
8591
|
}
|
|
8280
8592
|
var logger19 = agentsCore.getLogger("Agent");
|
|
8281
|
-
var CONSTANTS = {
|
|
8282
|
-
MAX_GENERATION_STEPS: 12,
|
|
8283
|
-
PHASE_1_TIMEOUT_MS: 27e4,
|
|
8284
|
-
NON_STREAMING_PHASE_1_TIMEOUT_MS: 9e4,
|
|
8285
|
-
PHASE_2_TIMEOUT_MS: 9e4
|
|
8286
|
-
};
|
|
8287
8593
|
function validateModel(modelString, modelType) {
|
|
8288
8594
|
if (!modelString?.trim()) {
|
|
8289
8595
|
throw new Error(
|
|
@@ -8352,10 +8658,10 @@ var Agent = class {
|
|
|
8352
8658
|
}
|
|
8353
8659
|
/**
|
|
8354
8660
|
* Get the maximum number of generation steps for this agent
|
|
8355
|
-
* Uses agent's stopWhen.stepCountIs config or defaults to
|
|
8661
|
+
* Uses agent's stopWhen.stepCountIs config or defaults to AGENT_EXECUTION_MAX_GENERATION_STEPS
|
|
8356
8662
|
*/
|
|
8357
8663
|
getMaxGenerationSteps() {
|
|
8358
|
-
return this.config.stopWhen?.stepCountIs ??
|
|
8664
|
+
return this.config.stopWhen?.stepCountIs ?? AGENT_EXECUTION_MAX_GENERATION_STEPS;
|
|
8359
8665
|
}
|
|
8360
8666
|
/**
|
|
8361
8667
|
* Sanitizes tool names at runtime for AI SDK compatibility.
|
|
@@ -8911,8 +9217,8 @@ var Agent = class {
|
|
|
8911
9217
|
const defaultSandboxConfig = {
|
|
8912
9218
|
provider: "native",
|
|
8913
9219
|
runtime: "node22",
|
|
8914
|
-
timeout:
|
|
8915
|
-
vcpus:
|
|
9220
|
+
timeout: FUNCTION_TOOL_EXECUTION_TIMEOUT_MS_DEFAULT,
|
|
9221
|
+
vcpus: FUNCTION_TOOL_SANDBOX_VCPUS_DEFAULT
|
|
8916
9222
|
};
|
|
8917
9223
|
const result = await sandboxExecutor.executeFunctionTool(functionToolDef.id, args, {
|
|
8918
9224
|
description: functionToolDef.description || functionToolDef.name,
|
|
@@ -9213,9 +9519,9 @@ var Agent = class {
|
|
|
9213
9519
|
getArtifactTools() {
|
|
9214
9520
|
return ai.tool({
|
|
9215
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.",
|
|
9216
|
-
inputSchema:
|
|
9217
|
-
artifactId:
|
|
9218
|
-
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.")
|
|
9219
9525
|
}),
|
|
9220
9526
|
execute: async ({ artifactId, toolCallId }) => {
|
|
9221
9527
|
logger19.info({ artifactId, toolCallId }, "get_artifact_full executed");
|
|
@@ -9242,9 +9548,9 @@ var Agent = class {
|
|
|
9242
9548
|
createThinkingCompleteTool() {
|
|
9243
9549
|
return ai.tool({
|
|
9244
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.",
|
|
9245
|
-
inputSchema:
|
|
9246
|
-
complete:
|
|
9247
|
-
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(
|
|
9248
9554
|
"Brief summary of what information was gathered and why it is sufficient to answer the user"
|
|
9249
9555
|
)
|
|
9250
9556
|
}),
|
|
@@ -9517,6 +9823,9 @@ var Agent = class {
|
|
|
9517
9823
|
try {
|
|
9518
9824
|
this.streamRequestId = streamRequestId;
|
|
9519
9825
|
this.streamHelper = streamRequestId ? getStreamHelper(streamRequestId) : void 0;
|
|
9826
|
+
if (streamRequestId && this.artifactComponents.length > 0) {
|
|
9827
|
+
agentSessionManager.updateArtifactComponents(streamRequestId, this.artifactComponents);
|
|
9828
|
+
}
|
|
9520
9829
|
const conversationId = runtimeContext?.metadata?.conversationId;
|
|
9521
9830
|
if (conversationId) {
|
|
9522
9831
|
this.setConversationId(conversationId);
|
|
@@ -9598,15 +9907,14 @@ var Agent = class {
|
|
|
9598
9907
|
let textResponse;
|
|
9599
9908
|
const hasStructuredOutput = this.config.dataComponents && this.config.dataComponents.length > 0;
|
|
9600
9909
|
const shouldStreamPhase1 = this.getStreamingHelper() && !hasStructuredOutput;
|
|
9601
|
-
const
|
|
9602
|
-
const
|
|
9603
|
-
|
|
9604
|
-
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) {
|
|
9605
9913
|
logger19.warn(
|
|
9606
9914
|
{
|
|
9607
9915
|
requestedTimeout: modelSettings.maxDuration * 1e3,
|
|
9608
9916
|
appliedTimeout: timeoutMs,
|
|
9609
|
-
maxAllowed:
|
|
9917
|
+
maxAllowed: LLM_GENERATION_MAX_ALLOWED_TIMEOUT_MS
|
|
9610
9918
|
},
|
|
9611
9919
|
"Requested timeout exceeded maximum allowed, capping to 10 minutes"
|
|
9612
9920
|
);
|
|
@@ -9882,9 +10190,9 @@ ${output}${structureHintsFormatted}`;
|
|
|
9882
10190
|
this.config.dataComponents.forEach((dc) => {
|
|
9883
10191
|
const propsSchema = jsonSchemaToZod(dc.props);
|
|
9884
10192
|
componentSchemas.push(
|
|
9885
|
-
|
|
9886
|
-
id:
|
|
9887
|
-
name:
|
|
10193
|
+
z7.z.object({
|
|
10194
|
+
id: z7.z.string(),
|
|
10195
|
+
name: z7.z.literal(dc.name),
|
|
9888
10196
|
props: propsSchema
|
|
9889
10197
|
})
|
|
9890
10198
|
);
|
|
@@ -9901,14 +10209,32 @@ ${output}${structureHintsFormatted}`;
|
|
|
9901
10209
|
if (componentSchemas.length === 1) {
|
|
9902
10210
|
dataComponentsSchema = componentSchemas[0];
|
|
9903
10211
|
} else {
|
|
9904
|
-
dataComponentsSchema =
|
|
10212
|
+
dataComponentsSchema = z7.z.union(
|
|
9905
10213
|
componentSchemas
|
|
9906
10214
|
);
|
|
9907
10215
|
}
|
|
9908
10216
|
const structuredModelSettings = ModelFactory.prepareGenerationConfig(
|
|
9909
10217
|
this.getStructuredOutputModel()
|
|
9910
10218
|
);
|
|
9911
|
-
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
|
+
}
|
|
9912
10238
|
const shouldStreamPhase2 = this.getStreamingHelper();
|
|
9913
10239
|
if (shouldStreamPhase2) {
|
|
9914
10240
|
const phase2Messages = [
|
|
@@ -9925,8 +10251,8 @@ ${output}${structureHintsFormatted}`;
|
|
|
9925
10251
|
const streamResult = ai.streamObject({
|
|
9926
10252
|
...structuredModelSettings,
|
|
9927
10253
|
messages: phase2Messages,
|
|
9928
|
-
schema:
|
|
9929
|
-
dataComponents:
|
|
10254
|
+
schema: z7.z.object({
|
|
10255
|
+
dataComponents: z7.z.array(dataComponentsSchema)
|
|
9930
10256
|
}),
|
|
9931
10257
|
experimental_telemetry: {
|
|
9932
10258
|
isEnabled: true,
|
|
@@ -9996,8 +10322,8 @@ ${output}${structureHintsFormatted}`;
|
|
|
9996
10322
|
withJsonPostProcessing2({
|
|
9997
10323
|
...structuredModelSettings,
|
|
9998
10324
|
messages: phase2Messages,
|
|
9999
|
-
schema:
|
|
10000
|
-
dataComponents:
|
|
10325
|
+
schema: z7.z.object({
|
|
10326
|
+
dataComponents: z7.z.array(dataComponentsSchema)
|
|
10001
10327
|
}),
|
|
10002
10328
|
experimental_telemetry: {
|
|
10003
10329
|
isEnabled: true,
|
|
@@ -10264,9 +10590,14 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
|
|
|
10264
10590
|
const models = "models" in config.agentSchema ? config.agentSchema.models : void 0;
|
|
10265
10591
|
const stopWhen = "stopWhen" in config.agentSchema ? config.agentSchema.stopWhen : void 0;
|
|
10266
10592
|
const toolsForAgentResult = await Promise.all(
|
|
10267
|
-
toolsForAgent.data.map(
|
|
10268
|
-
|
|
10269
|
-
|
|
10593
|
+
toolsForAgent.data.map(async (item) => {
|
|
10594
|
+
const mcpTool = await agentsCore.dbResultToMcpTool(item.tool, dbClient_default, credentialStoreRegistry);
|
|
10595
|
+
if (item.selectedTools && item.selectedTools.length > 0) {
|
|
10596
|
+
const selectedToolsSet = new Set(item.selectedTools);
|
|
10597
|
+
mcpTool.availableTools = mcpTool.availableTools?.filter((tool3) => selectedToolsSet.has(tool3.name)) || [];
|
|
10598
|
+
}
|
|
10599
|
+
return mcpTool;
|
|
10600
|
+
})
|
|
10270
10601
|
) ?? [];
|
|
10271
10602
|
const agent = new Agent(
|
|
10272
10603
|
{
|
|
@@ -10295,20 +10626,112 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
|
|
|
10295
10626
|
subAgentRelations: [],
|
|
10296
10627
|
transferRelations: []
|
|
10297
10628
|
})),
|
|
10298
|
-
transferRelations:
|
|
10299
|
-
|
|
10300
|
-
|
|
10301
|
-
|
|
10302
|
-
|
|
10303
|
-
|
|
10304
|
-
|
|
10305
|
-
|
|
10306
|
-
|
|
10307
|
-
|
|
10308
|
-
|
|
10309
|
-
|
|
10310
|
-
|
|
10311
|
-
|
|
10629
|
+
transferRelations: await Promise.all(
|
|
10630
|
+
enhancedInternalRelations.filter((relation) => relation.relationType === "transfer").map(async (relation) => {
|
|
10631
|
+
const targetToolsForAgent = await agentsCore.getToolsForAgent(dbClient_default)({
|
|
10632
|
+
scopes: {
|
|
10633
|
+
tenantId: config.tenantId,
|
|
10634
|
+
projectId: config.projectId,
|
|
10635
|
+
agentId: config.agentId,
|
|
10636
|
+
subAgentId: relation.id
|
|
10637
|
+
}
|
|
10638
|
+
});
|
|
10639
|
+
let targetTransferRelations = { data: [] };
|
|
10640
|
+
let targetDelegateRelations = { data: [] };
|
|
10641
|
+
try {
|
|
10642
|
+
const [transferRel, delegateRel] = await Promise.all([
|
|
10643
|
+
agentsCore.getRelatedAgentsForAgent(dbClient_default)({
|
|
10644
|
+
scopes: {
|
|
10645
|
+
tenantId: config.tenantId,
|
|
10646
|
+
projectId: config.projectId,
|
|
10647
|
+
agentId: config.agentId
|
|
10648
|
+
},
|
|
10649
|
+
subAgentId: relation.id
|
|
10650
|
+
}),
|
|
10651
|
+
agentsCore.getExternalAgentsForSubAgent(dbClient_default)({
|
|
10652
|
+
scopes: {
|
|
10653
|
+
tenantId: config.tenantId,
|
|
10654
|
+
projectId: config.projectId,
|
|
10655
|
+
agentId: config.agentId,
|
|
10656
|
+
subAgentId: relation.id
|
|
10657
|
+
}
|
|
10658
|
+
})
|
|
10659
|
+
]);
|
|
10660
|
+
targetTransferRelations = transferRel;
|
|
10661
|
+
targetDelegateRelations = delegateRel;
|
|
10662
|
+
} catch (err) {
|
|
10663
|
+
logger20.info(
|
|
10664
|
+
{
|
|
10665
|
+
agentId: relation.id,
|
|
10666
|
+
error: err?.message || "Unknown error"
|
|
10667
|
+
},
|
|
10668
|
+
"Could not fetch relations for target agent (likely external/team agent), using basic info only"
|
|
10669
|
+
);
|
|
10670
|
+
}
|
|
10671
|
+
const targetAgentTools = await Promise.all(
|
|
10672
|
+
targetToolsForAgent.data.map(async (item) => {
|
|
10673
|
+
const mcpTool = await agentsCore.dbResultToMcpTool(
|
|
10674
|
+
item.tool,
|
|
10675
|
+
dbClient_default,
|
|
10676
|
+
credentialStoreRegistry
|
|
10677
|
+
);
|
|
10678
|
+
if (item.selectedTools && item.selectedTools.length > 0) {
|
|
10679
|
+
const selectedToolsSet = new Set(item.selectedTools);
|
|
10680
|
+
mcpTool.availableTools = mcpTool.availableTools?.filter(
|
|
10681
|
+
(tool3) => selectedToolsSet.has(tool3.name)
|
|
10682
|
+
) || [];
|
|
10683
|
+
}
|
|
10684
|
+
return mcpTool;
|
|
10685
|
+
})
|
|
10686
|
+
) ?? [];
|
|
10687
|
+
const targetTransferRelationsConfig = targetTransferRelations.data.filter((rel) => rel.relationType === "transfer").map((rel) => ({
|
|
10688
|
+
baseUrl: config.baseUrl,
|
|
10689
|
+
apiKey: config.apiKey,
|
|
10690
|
+
id: rel.id,
|
|
10691
|
+
tenantId: config.tenantId,
|
|
10692
|
+
projectId: config.projectId,
|
|
10693
|
+
agentId: config.agentId,
|
|
10694
|
+
name: rel.name,
|
|
10695
|
+
description: rel.description,
|
|
10696
|
+
prompt: "",
|
|
10697
|
+
delegateRelations: [],
|
|
10698
|
+
subAgentRelations: [],
|
|
10699
|
+
transferRelations: []
|
|
10700
|
+
// Note: Not including tools for nested relations to avoid infinite recursion
|
|
10701
|
+
}));
|
|
10702
|
+
const targetDelegateRelationsConfig = targetDelegateRelations.data.map(
|
|
10703
|
+
(rel) => ({
|
|
10704
|
+
type: "external",
|
|
10705
|
+
config: {
|
|
10706
|
+
id: rel.externalAgent.id,
|
|
10707
|
+
name: rel.externalAgent.name,
|
|
10708
|
+
description: rel.externalAgent.description || "",
|
|
10709
|
+
baseUrl: rel.externalAgent.baseUrl,
|
|
10710
|
+
headers: rel.headers,
|
|
10711
|
+
credentialReferenceId: rel.externalAgent.credentialReferenceId,
|
|
10712
|
+
relationId: rel.id,
|
|
10713
|
+
relationType: "delegate"
|
|
10714
|
+
}
|
|
10715
|
+
})
|
|
10716
|
+
);
|
|
10717
|
+
return {
|
|
10718
|
+
baseUrl: config.baseUrl,
|
|
10719
|
+
apiKey: config.apiKey,
|
|
10720
|
+
id: relation.id,
|
|
10721
|
+
tenantId: config.tenantId,
|
|
10722
|
+
projectId: config.projectId,
|
|
10723
|
+
agentId: config.agentId,
|
|
10724
|
+
name: relation.name,
|
|
10725
|
+
description: relation.description,
|
|
10726
|
+
prompt: "",
|
|
10727
|
+
delegateRelations: targetDelegateRelationsConfig,
|
|
10728
|
+
subAgentRelations: [],
|
|
10729
|
+
transferRelations: targetTransferRelationsConfig,
|
|
10730
|
+
tools: targetAgentTools
|
|
10731
|
+
// Include target agent's tools for transfer descriptions
|
|
10732
|
+
};
|
|
10733
|
+
})
|
|
10734
|
+
),
|
|
10312
10735
|
delegateRelations: [
|
|
10313
10736
|
...enhancedInternalRelations.filter((relation) => relation.relationType === "delegate").map((relation) => ({
|
|
10314
10737
|
type: "internal",
|
|
@@ -10323,8 +10746,11 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
|
|
|
10323
10746
|
description: relation.description,
|
|
10324
10747
|
prompt: "",
|
|
10325
10748
|
delegateRelations: [],
|
|
10749
|
+
// Simplified - no nested relations
|
|
10326
10750
|
subAgentRelations: [],
|
|
10327
|
-
transferRelations: []
|
|
10751
|
+
transferRelations: [],
|
|
10752
|
+
tools: []
|
|
10753
|
+
// Tools are defined in config files, not DB
|
|
10328
10754
|
}
|
|
10329
10755
|
})),
|
|
10330
10756
|
...externalRelations.data.map((relation) => ({
|
|
@@ -10729,14 +11155,14 @@ app.openapi(
|
|
|
10729
11155
|
description: "Agent Card for A2A discovery",
|
|
10730
11156
|
content: {
|
|
10731
11157
|
"application/json": {
|
|
10732
|
-
schema:
|
|
10733
|
-
name:
|
|
10734
|
-
description:
|
|
10735
|
-
url:
|
|
10736
|
-
version:
|
|
10737
|
-
defaultInputModes:
|
|
10738
|
-
defaultOutputModes:
|
|
10739
|
-
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())
|
|
10740
11166
|
})
|
|
10741
11167
|
}
|
|
10742
11168
|
}
|
|
@@ -10983,8 +11409,12 @@ async function executeTransfer({
|
|
|
10983
11409
|
}
|
|
10984
11410
|
|
|
10985
11411
|
// src/handlers/executionHandler.ts
|
|
11412
|
+
init_execution_limits();
|
|
10986
11413
|
init_dbClient();
|
|
10987
11414
|
init_logger();
|
|
11415
|
+
|
|
11416
|
+
// src/utils/stream-helpers.ts
|
|
11417
|
+
init_execution_limits();
|
|
10988
11418
|
var SSEStreamHelper = class {
|
|
10989
11419
|
constructor(stream2, requestId2, timestamp) {
|
|
10990
11420
|
this.stream = stream2;
|
|
@@ -11157,7 +11587,6 @@ function createSSEStreamHelper(stream2, requestId2, timestamp) {
|
|
|
11157
11587
|
return new SSEStreamHelper(stream2, requestId2, timestamp);
|
|
11158
11588
|
}
|
|
11159
11589
|
var _VercelDataStreamHelper = class _VercelDataStreamHelper {
|
|
11160
|
-
// 10 minutes max lifetime
|
|
11161
11590
|
constructor(writer) {
|
|
11162
11591
|
this.writer = writer;
|
|
11163
11592
|
__publicField(this, "textId", null);
|
|
@@ -11167,18 +11596,14 @@ var _VercelDataStreamHelper = class _VercelDataStreamHelper {
|
|
|
11167
11596
|
__publicField(this, "completedItems", /* @__PURE__ */ new Set());
|
|
11168
11597
|
// Track completed items
|
|
11169
11598
|
__publicField(this, "sessionId");
|
|
11170
|
-
// 5MB limit (more generous during request)
|
|
11171
11599
|
__publicField(this, "isCompleted", false);
|
|
11172
11600
|
__publicField(this, "isTextStreaming", false);
|
|
11173
11601
|
__publicField(this, "queuedEvents", []);
|
|
11174
11602
|
__publicField(this, "lastTextEndTimestamp", 0);
|
|
11175
|
-
__publicField(this, "TEXT_GAP_THRESHOLD", 2e3);
|
|
11176
|
-
// milliseconds - if gap between text sequences is less than this, queue operations
|
|
11177
11603
|
__publicField(this, "connectionDropTimer");
|
|
11178
|
-
__publicField(this, "MAX_LIFETIME_MS", 6e5);
|
|
11179
11604
|
this.connectionDropTimer = setTimeout(() => {
|
|
11180
11605
|
this.forceCleanup("Connection lifetime exceeded");
|
|
11181
|
-
},
|
|
11606
|
+
}, STREAM_MAX_LIFETIME_MS);
|
|
11182
11607
|
}
|
|
11183
11608
|
setSessionId(sessionId) {
|
|
11184
11609
|
this.sessionId = sessionId;
|
|
@@ -11232,7 +11657,7 @@ var _VercelDataStreamHelper = class _VercelDataStreamHelper {
|
|
|
11232
11657
|
const id = this.textId;
|
|
11233
11658
|
const startTime = Date.now();
|
|
11234
11659
|
const gapFromLastSequence = this.lastTextEndTimestamp > 0 ? startTime - this.lastTextEndTimestamp : Number.MAX_SAFE_INTEGER;
|
|
11235
|
-
if (gapFromLastSequence >=
|
|
11660
|
+
if (gapFromLastSequence >= STREAM_TEXT_GAP_THRESHOLD_MS) {
|
|
11236
11661
|
await this.flushQueuedOperations();
|
|
11237
11662
|
}
|
|
11238
11663
|
this.isTextStreaming = true;
|
|
@@ -11266,7 +11691,7 @@ var _VercelDataStreamHelper = class _VercelDataStreamHelper {
|
|
|
11266
11691
|
if (type === "data-artifact") {
|
|
11267
11692
|
const now = Date.now();
|
|
11268
11693
|
const gapFromLastTextEnd = this.lastTextEndTimestamp > 0 ? now - this.lastTextEndTimestamp : Number.MAX_SAFE_INTEGER;
|
|
11269
|
-
if (this.isTextStreaming || gapFromLastTextEnd <
|
|
11694
|
+
if (this.isTextStreaming || gapFromLastTextEnd < STREAM_TEXT_GAP_THRESHOLD_MS) {
|
|
11270
11695
|
this.writer.write({
|
|
11271
11696
|
type: `${type}`,
|
|
11272
11697
|
data
|
|
@@ -11419,7 +11844,7 @@ var _VercelDataStreamHelper = class _VercelDataStreamHelper {
|
|
|
11419
11844
|
}
|
|
11420
11845
|
const now = Date.now();
|
|
11421
11846
|
const gapFromLastTextEnd = this.lastTextEndTimestamp > 0 ? now - this.lastTextEndTimestamp : Number.MAX_SAFE_INTEGER;
|
|
11422
|
-
if (this.isTextStreaming || gapFromLastTextEnd <
|
|
11847
|
+
if (this.isTextStreaming || gapFromLastTextEnd < STREAM_TEXT_GAP_THRESHOLD_MS) {
|
|
11423
11848
|
this.queuedEvents.push({ type: "data-summary", event: summary });
|
|
11424
11849
|
return;
|
|
11425
11850
|
}
|
|
@@ -11437,7 +11862,7 @@ var _VercelDataStreamHelper = class _VercelDataStreamHelper {
|
|
|
11437
11862
|
}
|
|
11438
11863
|
const now = Date.now();
|
|
11439
11864
|
const gapFromLastTextEnd = this.lastTextEndTimestamp > 0 ? now - this.lastTextEndTimestamp : Number.MAX_SAFE_INTEGER;
|
|
11440
|
-
if (this.isTextStreaming || gapFromLastTextEnd <
|
|
11865
|
+
if (this.isTextStreaming || gapFromLastTextEnd < STREAM_TEXT_GAP_THRESHOLD_MS) {
|
|
11441
11866
|
this.queuedEvents.push({ type: "data-operation", event: operation });
|
|
11442
11867
|
return;
|
|
11443
11868
|
}
|
|
@@ -11480,7 +11905,7 @@ var _VercelDataStreamHelper = class _VercelDataStreamHelper {
|
|
|
11480
11905
|
this.cleanup();
|
|
11481
11906
|
}
|
|
11482
11907
|
};
|
|
11483
|
-
__publicField(_VercelDataStreamHelper, "MAX_BUFFER_SIZE",
|
|
11908
|
+
__publicField(_VercelDataStreamHelper, "MAX_BUFFER_SIZE", STREAM_BUFFER_MAX_SIZE_BYTES);
|
|
11484
11909
|
var VercelDataStreamHelper = _VercelDataStreamHelper;
|
|
11485
11910
|
function createVercelStreamHelper(writer) {
|
|
11486
11911
|
return new VercelDataStreamHelper(writer);
|
|
@@ -11552,7 +11977,7 @@ var createMCPStreamHelper = createBufferingStreamHelper;
|
|
|
11552
11977
|
var logger24 = agentsCore.getLogger("ExecutionHandler");
|
|
11553
11978
|
var ExecutionHandler = class {
|
|
11554
11979
|
constructor() {
|
|
11555
|
-
__publicField(this, "MAX_ERRORS",
|
|
11980
|
+
__publicField(this, "MAX_ERRORS", AGENT_EXECUTION_MAX_CONSECUTIVE_ERRORS);
|
|
11556
11981
|
}
|
|
11557
11982
|
/**
|
|
11558
11983
|
* performs exeuction loop
|
|
@@ -11686,7 +12111,7 @@ var ExecutionHandler = class {
|
|
|
11686
12111
|
);
|
|
11687
12112
|
if (Array.isArray(task)) task = task[0];
|
|
11688
12113
|
let currentMessage = userMessage;
|
|
11689
|
-
const maxTransfers = agentConfig?.stopWhen?.transferCountIs ??
|
|
12114
|
+
const maxTransfers = agentConfig?.stopWhen?.transferCountIs ?? agentsCore.AGENT_EXECUTION_TRANSFER_COUNT_DEFAULT;
|
|
11690
12115
|
while (iterations < maxTransfers) {
|
|
11691
12116
|
iterations++;
|
|
11692
12117
|
logger24.info(
|
|
@@ -11781,7 +12206,27 @@ var ExecutionHandler = class {
|
|
|
11781
12206
|
const firstArtifact = messageResponse.result.artifacts[0];
|
|
11782
12207
|
const transferReason = firstArtifact?.parts[1]?.kind === "text" ? firstArtifact.parts[1].text : "Transfer initiated";
|
|
11783
12208
|
logger24.info({ targetSubAgentId, transferReason, transferFromAgent }, "Transfer response");
|
|
11784
|
-
|
|
12209
|
+
await agentsCore.createMessage(dbClient_default)({
|
|
12210
|
+
id: agentsCore.generateId(),
|
|
12211
|
+
tenantId,
|
|
12212
|
+
projectId,
|
|
12213
|
+
conversationId,
|
|
12214
|
+
role: "agent",
|
|
12215
|
+
content: {
|
|
12216
|
+
text: transferReason,
|
|
12217
|
+
parts: [
|
|
12218
|
+
{
|
|
12219
|
+
kind: "text",
|
|
12220
|
+
text: transferReason
|
|
12221
|
+
}
|
|
12222
|
+
]
|
|
12223
|
+
},
|
|
12224
|
+
visibility: "user-facing",
|
|
12225
|
+
messageType: "chat",
|
|
12226
|
+
fromSubAgentId: currentAgentId,
|
|
12227
|
+
taskId: task.id
|
|
12228
|
+
});
|
|
12229
|
+
currentMessage = currentMessage + "\n\nPlease continue this conversation seamlessly. The previous response in conversation history was from another internal agent, but you must continue as if YOU made that response. All responses must appear as one unified agent - do not repeat what was already communicated.";
|
|
11785
12230
|
const { success, targetSubAgentId: newAgentId } = await executeTransfer({
|
|
11786
12231
|
projectId,
|
|
11787
12232
|
tenantId,
|
|
@@ -11988,36 +12433,36 @@ var chatCompletionsRoute = zodOpenapi.createRoute({
|
|
|
11988
12433
|
body: {
|
|
11989
12434
|
content: {
|
|
11990
12435
|
"application/json": {
|
|
11991
|
-
schema:
|
|
11992
|
-
model:
|
|
11993
|
-
messages:
|
|
11994
|
-
|
|
11995
|
-
role:
|
|
11996
|
-
content:
|
|
11997
|
-
|
|
11998
|
-
|
|
11999
|
-
|
|
12000
|
-
type:
|
|
12001
|
-
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()
|
|
12002
12447
|
})
|
|
12003
12448
|
)
|
|
12004
12449
|
]).describe("The message content"),
|
|
12005
|
-
name:
|
|
12450
|
+
name: z7.z.string().optional().describe("The name of the message sender")
|
|
12006
12451
|
})
|
|
12007
12452
|
).describe("The conversation messages"),
|
|
12008
|
-
temperature:
|
|
12009
|
-
top_p:
|
|
12010
|
-
n:
|
|
12011
|
-
stream:
|
|
12012
|
-
max_tokens:
|
|
12013
|
-
presence_penalty:
|
|
12014
|
-
frequency_penalty:
|
|
12015
|
-
logit_bias:
|
|
12016
|
-
user:
|
|
12017
|
-
conversationId:
|
|
12018
|
-
tools:
|
|
12019
|
-
runConfig:
|
|
12020
|
-
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(
|
|
12021
12466
|
"Headers data for template processing (validated against context config schema)"
|
|
12022
12467
|
)
|
|
12023
12468
|
})
|
|
@@ -12028,14 +12473,14 @@ var chatCompletionsRoute = zodOpenapi.createRoute({
|
|
|
12028
12473
|
responses: {
|
|
12029
12474
|
200: {
|
|
12030
12475
|
description: "Streaming chat completion response in Server-Sent Events format",
|
|
12031
|
-
headers:
|
|
12032
|
-
"Content-Type":
|
|
12033
|
-
"Cache-Control":
|
|
12034
|
-
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")
|
|
12035
12480
|
}),
|
|
12036
12481
|
content: {
|
|
12037
12482
|
"text/event-stream": {
|
|
12038
|
-
schema:
|
|
12483
|
+
schema: z7.z.string().describe("Server-Sent Events stream with chat completion chunks")
|
|
12039
12484
|
}
|
|
12040
12485
|
}
|
|
12041
12486
|
},
|
|
@@ -12043,13 +12488,13 @@ var chatCompletionsRoute = zodOpenapi.createRoute({
|
|
|
12043
12488
|
description: "Invalid request context or parameters",
|
|
12044
12489
|
content: {
|
|
12045
12490
|
"application/json": {
|
|
12046
|
-
schema:
|
|
12047
|
-
error:
|
|
12048
|
-
details:
|
|
12049
|
-
|
|
12050
|
-
field:
|
|
12051
|
-
message:
|
|
12052
|
-
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()
|
|
12053
12498
|
})
|
|
12054
12499
|
).optional()
|
|
12055
12500
|
})
|
|
@@ -12060,8 +12505,8 @@ var chatCompletionsRoute = zodOpenapi.createRoute({
|
|
|
12060
12505
|
description: "Agent or agent not found",
|
|
12061
12506
|
content: {
|
|
12062
12507
|
"application/json": {
|
|
12063
|
-
schema:
|
|
12064
|
-
error:
|
|
12508
|
+
schema: z7.z.object({
|
|
12509
|
+
error: z7.z.string()
|
|
12065
12510
|
})
|
|
12066
12511
|
}
|
|
12067
12512
|
}
|
|
@@ -12070,9 +12515,9 @@ var chatCompletionsRoute = zodOpenapi.createRoute({
|
|
|
12070
12515
|
description: "Internal server error",
|
|
12071
12516
|
content: {
|
|
12072
12517
|
"application/json": {
|
|
12073
|
-
schema:
|
|
12074
|
-
error:
|
|
12075
|
-
message:
|
|
12518
|
+
schema: z7.z.object({
|
|
12519
|
+
error: z7.z.string(),
|
|
12520
|
+
message: z7.z.string()
|
|
12076
12521
|
})
|
|
12077
12522
|
}
|
|
12078
12523
|
}
|
|
@@ -12784,7 +13229,7 @@ var getServer = async (headers2, executionContext, conversationId, credentialSto
|
|
|
12784
13229
|
"send-query-to-agent",
|
|
12785
13230
|
`Send a query to the ${agent.name} agent. The agent has the following description: ${agent.description}`,
|
|
12786
13231
|
{
|
|
12787
|
-
query:
|
|
13232
|
+
query: z7.z.string().describe("The query to send to the agent")
|
|
12788
13233
|
},
|
|
12789
13234
|
async ({ query }) => {
|
|
12790
13235
|
try {
|