@inkeep/agents-run-api 0.31.6 → 0.32.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/{SandboxExecutorFactory-QVNCS6YN.js → SandboxExecutorFactory-D3OSN652.js} +45 -48
- package/dist/{chunk-IMJLQGAX.js → chunk-54Z7AOV4.js} +7 -6
- package/dist/chunk-BYF2SHLS.js +13 -0
- package/dist/chunk-IVALDC72.js +204 -0
- package/dist/{chunk-Z4TYO3W3.js → chunk-N2FZD53W.js} +1 -3
- package/dist/{chunk-DWEFKQTA.js → chunk-YBBSNUL3.js} +1 -1
- package/dist/{conversations-V6DNH5MW.js → conversations-ZZI6XV2G.js} +1 -1
- package/dist/dbClient-XRZSZEYI.js +1 -0
- package/dist/index.cjs +723 -293
- package/dist/index.js +334 -111
- package/dist/instrumentation.cjs +1 -3
- package/dist/instrumentation.js +1 -1
- package/package.json +5 -4
- package/templates/v1/phase1/system-prompt.xml +2 -7
- package/dist/chunk-TRNLEUK2.js +0 -26
- package/dist/dbClient-PLEBWGM4.js +0 -1
package/dist/index.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { flushBatchProcessor } from './chunk-
|
|
2
|
-
import { getFormattedConversationHistory, createDefaultConversationHistoryConfig, saveA2AMessageResponse } from './chunk-
|
|
3
|
-
import { dbClient_default } from './chunk-
|
|
4
|
-
import { env } from './chunk-
|
|
1
|
+
import { flushBatchProcessor } from './chunk-YBBSNUL3.js';
|
|
2
|
+
import { getFormattedConversationHistory, createDefaultConversationHistoryConfig, saveA2AMessageResponse } from './chunk-54Z7AOV4.js';
|
|
3
|
+
import { dbClient_default } from './chunk-BYF2SHLS.js';
|
|
4
|
+
import { env } from './chunk-N2FZD53W.js';
|
|
5
5
|
import { getLogger } from './chunk-A2S7GSHL.js';
|
|
6
|
+
import { STREAM_PARSER_MAX_SNAPSHOT_SIZE, STREAM_PARSER_MAX_STREAMED_SIZE, STREAM_PARSER_MAX_COLLECTED_PARTS, STREAM_BUFFER_MAX_SIZE_BYTES, SESSION_CLEANUP_INTERVAL_MS, STREAM_MAX_LIFETIME_MS, STREAM_TEXT_GAP_THRESHOLD_MS, AGENT_EXECUTION_MAX_CONSECUTIVE_ERRORS, SESSION_TOOL_RESULT_CACHE_TIMEOUT_MS, ARTIFACT_GENERATION_MAX_RETRIES, ARTIFACT_SESSION_MAX_PENDING, STATUS_UPDATE_DEFAULT_INTERVAL_SECONDS, STATUS_UPDATE_DEFAULT_NUM_EVENTS, ARTIFACT_SESSION_MAX_PREVIOUS_SUMMARIES, ARTIFACT_GENERATION_BACKOFF_INITIAL_MS, ARTIFACT_GENERATION_BACKOFF_MAX_MS, AGENT_EXECUTION_MAX_GENERATION_STEPS, FUNCTION_TOOL_SANDBOX_VCPUS_DEFAULT, FUNCTION_TOOL_EXECUTION_TIMEOUT_MS_DEFAULT, LLM_GENERATION_MAX_ALLOWED_TIMEOUT_MS, LLM_GENERATION_FIRST_CALL_TIMEOUT_MS_STREAMING, LLM_GENERATION_FIRST_CALL_TIMEOUT_MS_NON_STREAMING, LLM_GENERATION_SUBSEQUENT_CALL_TIMEOUT_MS, DELEGATION_TOOL_BACKOFF_MAX_ELAPSED_TIME_MS, DELEGATION_TOOL_BACKOFF_EXPONENT, DELEGATION_TOOL_BACKOFF_MAX_INTERVAL_MS, DELEGATION_TOOL_BACKOFF_INITIAL_INTERVAL_MS } from './chunk-IVALDC72.js';
|
|
6
7
|
import { __publicField } from './chunk-PKBMQBKP.js';
|
|
7
|
-
import { getTracer, HeadersScopeSchema, getRequestExecutionContext, createApiError, getAgentWithDefaultSubAgent, contextValidationMiddleware, getConversationId, getFullAgent, createOrGetConversation, getActiveAgentForConversation, setActiveAgentForConversation, getSubAgentById, handleContextResolution, createMessage, generateId, commonGetErrorResponses, loggerFactory, createDefaultCredentialStores, CredentialStoreRegistry, listTaskIdsByContextId, getTask, getLedgerArtifacts, upsertLedgerArtifact, createTask, updateTask, setSpanWithError, updateConversation, handleApiError, TaskState, setActiveAgentForThread, getConversation, getAgentById, getRelatedAgentsForAgent, getExternalAgentsForSubAgent, getTeamAgentsForSubAgent, getToolsForAgent, getDataComponentsForAgent, getArtifactComponentsForAgent, dbResultToMcpTool, validateAndGetApiKey, verifyServiceToken, validateTargetAgent, getProject, ContextResolver, CredentialStuffer, MCPServerType, getCredentialReference, McpClient, getFunctionToolsForSubAgent, getFunction, getContextConfigById, getFullAgentDefinition, TemplateEngine, agentHasArtifactComponents, MCPTransportType, SPAN_KEYS, headers, generateServiceToken } from '@inkeep/agents-core';
|
|
8
|
+
import { getTracer, HeadersScopeSchema, getRequestExecutionContext, createApiError, getAgentWithDefaultSubAgent, contextValidationMiddleware, getConversationId, getFullAgent, createOrGetConversation, getActiveAgentForConversation, setActiveAgentForConversation, getSubAgentById, handleContextResolution, createMessage, generateId, commonGetErrorResponses, loggerFactory, createDefaultCredentialStores, CredentialStoreRegistry, listTaskIdsByContextId, getTask, getLedgerArtifacts, upsertLedgerArtifact, createTask, updateTask, setSpanWithError, AGENT_EXECUTION_TRANSFER_COUNT_DEFAULT, updateConversation, handleApiError, CONVERSATION_HISTORY_MAX_OUTPUT_TOKENS_DEFAULT, CONVERSATION_HISTORY_DEFAULT_LIMIT, TaskState, setActiveAgentForThread, getConversation, getAgentById, getRelatedAgentsForAgent, getExternalAgentsForSubAgent, getTeamAgentsForSubAgent, getToolsForAgent, getDataComponentsForAgent, getArtifactComponentsForAgent, dbResultToMcpTool, validateAndGetApiKey, verifyServiceToken, validateTargetAgent, getProject, ContextResolver, CredentialStuffer, MCPServerType, getCredentialReference, McpClient, getFunctionToolsForSubAgent, getFunction, getContextConfigById, getFullAgentDefinition, TemplateEngine, agentHasArtifactComponents, MCPTransportType, SPAN_KEYS, headers, generateServiceToken } from '@inkeep/agents-core';
|
|
8
9
|
import { otel } from '@hono/otel';
|
|
9
10
|
import { OpenAPIHono, createRoute, z as z$1 } from '@hono/zod-openapi';
|
|
10
11
|
import { trace, propagation, context, SpanStatusCode } from '@opentelemetry/api';
|
|
@@ -1120,11 +1121,9 @@ __publicField(_ModelFactory, "BUILT_IN_PROVIDERS", [
|
|
|
1120
1121
|
var ModelFactory = _ModelFactory;
|
|
1121
1122
|
var logger4 = getLogger("ToolSessionManager");
|
|
1122
1123
|
var _ToolSessionManager = class _ToolSessionManager {
|
|
1123
|
-
// 5 minutes
|
|
1124
1124
|
constructor() {
|
|
1125
1125
|
__publicField(this, "sessions", /* @__PURE__ */ new Map());
|
|
1126
|
-
|
|
1127
|
-
setInterval(() => this.cleanupExpiredSessions(), 6e4);
|
|
1126
|
+
setInterval(() => this.cleanupExpiredSessions(), SESSION_CLEANUP_INTERVAL_MS);
|
|
1128
1127
|
}
|
|
1129
1128
|
static getInstance() {
|
|
1130
1129
|
if (!_ToolSessionManager.instance) {
|
|
@@ -1269,7 +1268,7 @@ var _ToolSessionManager = class _ToolSessionManager {
|
|
|
1269
1268
|
const now = Date.now();
|
|
1270
1269
|
const expiredSessions = [];
|
|
1271
1270
|
for (const [sessionId, session] of this.sessions.entries()) {
|
|
1272
|
-
if (now - session.createdAt >
|
|
1271
|
+
if (now - session.createdAt > SESSION_TOOL_RESULT_CACHE_TIMEOUT_MS) {
|
|
1273
1272
|
expiredSessions.push(sessionId);
|
|
1274
1273
|
}
|
|
1275
1274
|
}
|
|
@@ -1534,7 +1533,16 @@ var _ArtifactService = class _ArtifactService {
|
|
|
1534
1533
|
);
|
|
1535
1534
|
return null;
|
|
1536
1535
|
}
|
|
1537
|
-
|
|
1536
|
+
let artifacts = [];
|
|
1537
|
+
artifacts = await getLedgerArtifacts(dbClient_default)({
|
|
1538
|
+
scopes: { tenantId: this.context.tenantId, projectId: this.context.projectId },
|
|
1539
|
+
artifactId,
|
|
1540
|
+
toolCallId
|
|
1541
|
+
});
|
|
1542
|
+
if (artifacts.length > 0) {
|
|
1543
|
+
return this.formatArtifactSummaryData(artifacts[0], artifactId, toolCallId);
|
|
1544
|
+
}
|
|
1545
|
+
artifacts = await getLedgerArtifacts(dbClient_default)({
|
|
1538
1546
|
scopes: { tenantId: this.context.tenantId, projectId: this.context.projectId },
|
|
1539
1547
|
artifactId,
|
|
1540
1548
|
taskId: this.context.taskId
|
|
@@ -1580,7 +1588,16 @@ var _ArtifactService = class _ArtifactService {
|
|
|
1580
1588
|
);
|
|
1581
1589
|
return null;
|
|
1582
1590
|
}
|
|
1583
|
-
|
|
1591
|
+
let artifacts = [];
|
|
1592
|
+
artifacts = await getLedgerArtifacts(dbClient_default)({
|
|
1593
|
+
scopes: { tenantId: this.context.tenantId, projectId: this.context.projectId },
|
|
1594
|
+
artifactId,
|
|
1595
|
+
toolCallId
|
|
1596
|
+
});
|
|
1597
|
+
if (artifacts.length > 0) {
|
|
1598
|
+
return this.formatArtifactFullData(artifacts[0], artifactId, toolCallId);
|
|
1599
|
+
}
|
|
1600
|
+
artifacts = await getLedgerArtifacts(dbClient_default)({
|
|
1584
1601
|
scopes: { tenantId: this.context.tenantId, projectId: this.context.projectId },
|
|
1585
1602
|
artifactId,
|
|
1586
1603
|
taskId: this.context.taskId
|
|
@@ -2423,8 +2440,8 @@ var AgentSession = class {
|
|
|
2423
2440
|
// Track pending artifact processing
|
|
2424
2441
|
__publicField(this, "artifactProcessingErrors", /* @__PURE__ */ new Map());
|
|
2425
2442
|
// Track errors per artifact
|
|
2426
|
-
__publicField(this, "MAX_ARTIFACT_RETRIES",
|
|
2427
|
-
__publicField(this, "MAX_PENDING_ARTIFACTS",
|
|
2443
|
+
__publicField(this, "MAX_ARTIFACT_RETRIES", ARTIFACT_GENERATION_MAX_RETRIES);
|
|
2444
|
+
__publicField(this, "MAX_PENDING_ARTIFACTS", ARTIFACT_SESSION_MAX_PENDING);
|
|
2428
2445
|
// Prevent unbounded growth
|
|
2429
2446
|
__publicField(this, "scheduledTimeouts");
|
|
2430
2447
|
// Track scheduled timeouts for cleanup
|
|
@@ -2544,8 +2561,8 @@ var AgentSession = class {
|
|
|
2544
2561
|
summarizerModel,
|
|
2545
2562
|
baseModel,
|
|
2546
2563
|
config: {
|
|
2547
|
-
numEvents: config.numEvents ||
|
|
2548
|
-
timeInSeconds: config.timeInSeconds ||
|
|
2564
|
+
numEvents: config.numEvents || STATUS_UPDATE_DEFAULT_NUM_EVENTS,
|
|
2565
|
+
timeInSeconds: config.timeInSeconds || STATUS_UPDATE_DEFAULT_INTERVAL_SECONDS,
|
|
2549
2566
|
...config
|
|
2550
2567
|
}
|
|
2551
2568
|
};
|
|
@@ -2888,7 +2905,7 @@ var AgentSession = class {
|
|
|
2888
2905
|
}
|
|
2889
2906
|
return;
|
|
2890
2907
|
}
|
|
2891
|
-
if (this.previousSummaries.length >
|
|
2908
|
+
if (this.previousSummaries.length > ARTIFACT_SESSION_MAX_PREVIOUS_SUMMARIES) {
|
|
2892
2909
|
this.previousSummaries.shift();
|
|
2893
2910
|
}
|
|
2894
2911
|
if (this.statusUpdateState) {
|
|
@@ -3001,9 +3018,8 @@ var AgentSession = class {
|
|
|
3001
3018
|
projectId: this.projectId,
|
|
3002
3019
|
conversationId: this.sessionId,
|
|
3003
3020
|
options: {
|
|
3004
|
-
limit:
|
|
3005
|
-
|
|
3006
|
-
maxOutputTokens: 2e3
|
|
3021
|
+
limit: CONVERSATION_HISTORY_DEFAULT_LIMIT,
|
|
3022
|
+
maxOutputTokens: CONVERSATION_HISTORY_MAX_OUTPUT_TOKENS_DEFAULT
|
|
3007
3023
|
},
|
|
3008
3024
|
filters: {}
|
|
3009
3025
|
});
|
|
@@ -3532,7 +3548,10 @@ Make it specific and relevant.`;
|
|
|
3532
3548
|
`Artifact name/description generation failed, attempt ${attempt}/${maxRetries}`
|
|
3533
3549
|
);
|
|
3534
3550
|
if (attempt < maxRetries) {
|
|
3535
|
-
const backoffMs = Math.min(
|
|
3551
|
+
const backoffMs = Math.min(
|
|
3552
|
+
ARTIFACT_GENERATION_BACKOFF_INITIAL_MS * 2 ** (attempt - 1),
|
|
3553
|
+
ARTIFACT_GENERATION_BACKOFF_MAX_MS
|
|
3554
|
+
);
|
|
3536
3555
|
await new Promise((resolve) => setTimeout(resolve, backoffMs));
|
|
3537
3556
|
}
|
|
3538
3557
|
}
|
|
@@ -3548,15 +3567,8 @@ Make it specific and relevant.`;
|
|
|
3548
3567
|
);
|
|
3549
3568
|
result = object;
|
|
3550
3569
|
}
|
|
3551
|
-
const artifactService = new ArtifactService({
|
|
3552
|
-
tenantId: artifactData.tenantId,
|
|
3553
|
-
projectId: artifactData.projectId,
|
|
3554
|
-
contextId: artifactData.contextId,
|
|
3555
|
-
taskId: artifactData.taskId,
|
|
3556
|
-
sessionId: this.sessionId
|
|
3557
|
-
});
|
|
3558
3570
|
try {
|
|
3559
|
-
await artifactService.saveArtifact({
|
|
3571
|
+
await this.artifactService.saveArtifact({
|
|
3560
3572
|
artifactId: artifactData.artifactId,
|
|
3561
3573
|
name: result.name,
|
|
3562
3574
|
description: result.description,
|
|
@@ -3585,14 +3597,14 @@ Make it specific and relevant.`;
|
|
|
3585
3597
|
if (!mainSaveSucceeded) {
|
|
3586
3598
|
try {
|
|
3587
3599
|
if (artifactData.tenantId && artifactData.projectId) {
|
|
3588
|
-
const
|
|
3600
|
+
const artifactService = new ArtifactService({
|
|
3589
3601
|
tenantId: artifactData.tenantId,
|
|
3590
3602
|
projectId: artifactData.projectId,
|
|
3591
3603
|
contextId: artifactData.contextId || "unknown",
|
|
3592
3604
|
taskId: artifactData.taskId,
|
|
3593
3605
|
sessionId: this.sessionId
|
|
3594
3606
|
});
|
|
3595
|
-
await
|
|
3607
|
+
await artifactService.saveArtifact({
|
|
3596
3608
|
artifactId: artifactData.artifactId,
|
|
3597
3609
|
name: `Artifact ${artifactData.artifactId.substring(0, 8)}`,
|
|
3598
3610
|
description: `${artifactData.artifactType || "Data"} from ${artifactData.metadata?.toolName || "tool results"}`,
|
|
@@ -4247,11 +4259,11 @@ ${chunk}`;
|
|
|
4247
4259
|
}
|
|
4248
4260
|
}
|
|
4249
4261
|
};
|
|
4250
|
-
__publicField(_IncrementalStreamParser, "MAX_SNAPSHOT_SIZE",
|
|
4262
|
+
__publicField(_IncrementalStreamParser, "MAX_SNAPSHOT_SIZE", STREAM_PARSER_MAX_SNAPSHOT_SIZE);
|
|
4251
4263
|
// Max number of snapshots to keep
|
|
4252
|
-
__publicField(_IncrementalStreamParser, "MAX_STREAMED_SIZE",
|
|
4264
|
+
__publicField(_IncrementalStreamParser, "MAX_STREAMED_SIZE", STREAM_PARSER_MAX_STREAMED_SIZE);
|
|
4253
4265
|
// Max number of streamed component IDs to track
|
|
4254
|
-
__publicField(_IncrementalStreamParser, "MAX_COLLECTED_PARTS",
|
|
4266
|
+
__publicField(_IncrementalStreamParser, "MAX_COLLECTED_PARTS", STREAM_PARSER_MAX_COLLECTED_PARTS);
|
|
4255
4267
|
var IncrementalStreamParser = _IncrementalStreamParser;
|
|
4256
4268
|
|
|
4257
4269
|
// src/services/ResponseFormatter.ts
|
|
@@ -5456,25 +5468,97 @@ var A2AClient = class {
|
|
|
5456
5468
|
|
|
5457
5469
|
// src/agents/relationTools.ts
|
|
5458
5470
|
var logger13 = getLogger("relationships Tools");
|
|
5471
|
+
var A2A_RETRY_STATUS_CODES = ["429", "500", "502", "503", "504"];
|
|
5459
5472
|
var generateTransferToolDescription = (config) => {
|
|
5460
|
-
|
|
5473
|
+
let toolsSection = "";
|
|
5474
|
+
let transferSection = "";
|
|
5475
|
+
if (config.transferRelations && config.transferRelations.length > 0) {
|
|
5476
|
+
const transferList = config.transferRelations.map(
|
|
5477
|
+
(transfer) => ` - ${transfer.name || transfer.id}: ${transfer.description || "No description available"}`
|
|
5478
|
+
).join("\n");
|
|
5479
|
+
transferSection = `
|
|
5480
|
+
|
|
5481
|
+
Can Transfer To:
|
|
5482
|
+
${transferList}`;
|
|
5483
|
+
}
|
|
5484
|
+
let delegateSection = "";
|
|
5485
|
+
if (config.delegateRelations && config.delegateRelations.length > 0) {
|
|
5486
|
+
const delegateList = config.delegateRelations.map(
|
|
5487
|
+
(delegate) => ` - ${delegate.config.name || delegate.config.id}: ${delegate.config.description || "No description available"} (${delegate.type})`
|
|
5488
|
+
).join("\n");
|
|
5489
|
+
delegateSection = `
|
|
5490
|
+
|
|
5491
|
+
Can Delegate To:
|
|
5492
|
+
${delegateList}`;
|
|
5493
|
+
}
|
|
5494
|
+
if (config.tools && config.tools.length > 0) {
|
|
5495
|
+
const toolDescriptions = config.tools.map((tool3) => {
|
|
5496
|
+
const toolsList = tool3.availableTools?.map((t) => ` - ${t.name}: ${t.description || "No description available"}`).join("\n") || "";
|
|
5497
|
+
return `MCP Server: ${tool3.name}
|
|
5498
|
+
${toolsList}`;
|
|
5499
|
+
}).join("\n\n");
|
|
5500
|
+
toolsSection = `
|
|
5501
|
+
|
|
5502
|
+
Available Tools & Capabilities:
|
|
5503
|
+
${toolDescriptions}`;
|
|
5504
|
+
}
|
|
5505
|
+
const finalDescription = `Hand off the conversation to agent ${config.id}.
|
|
5461
5506
|
|
|
5462
5507
|
Agent Information:
|
|
5463
5508
|
- ID: ${config.id}
|
|
5464
5509
|
- Name: ${config.name ?? "No name provided"}
|
|
5465
|
-
- Description: ${config.description ?? "No description provided"}
|
|
5510
|
+
- Description: ${config.description ?? "No description provided"}${toolsSection}${transferSection}${delegateSection}
|
|
5466
5511
|
|
|
5467
5512
|
Hand off the conversation to agent ${config.id} when the user's request would be better handled by this specialized agent.`;
|
|
5513
|
+
return finalDescription;
|
|
5468
5514
|
};
|
|
5469
|
-
var generateDelegateToolDescription = (
|
|
5470
|
-
|
|
5515
|
+
var generateDelegateToolDescription = (delegateRelation) => {
|
|
5516
|
+
const config = delegateRelation.config;
|
|
5517
|
+
let toolsSection = "";
|
|
5518
|
+
let transferSection = "";
|
|
5519
|
+
let delegateSection = "";
|
|
5520
|
+
if (delegateRelation.type === "internal" && "tools" in config) {
|
|
5521
|
+
const agentConfig = config;
|
|
5522
|
+
if (agentConfig.tools && agentConfig.tools.length > 0) {
|
|
5523
|
+
const toolDescriptions = agentConfig.tools.map((tool3) => {
|
|
5524
|
+
const toolsList = tool3.availableTools?.map((t) => ` - ${t.name}: ${t.description || "No description available"}`).join("\n") || "";
|
|
5525
|
+
return `MCP Server: ${tool3.name}
|
|
5526
|
+
${toolsList}`;
|
|
5527
|
+
}).join("\n\n");
|
|
5528
|
+
toolsSection = `
|
|
5529
|
+
|
|
5530
|
+
Available Tools & Capabilities:
|
|
5531
|
+
${toolDescriptions}`;
|
|
5532
|
+
}
|
|
5533
|
+
if (agentConfig.transferRelations && agentConfig.transferRelations.length > 0) {
|
|
5534
|
+
const transferList = agentConfig.transferRelations.map(
|
|
5535
|
+
(transfer) => ` - ${transfer.name || transfer.id}: ${transfer.description || "No description available"}`
|
|
5536
|
+
).join("\n");
|
|
5537
|
+
transferSection = `
|
|
5538
|
+
|
|
5539
|
+
Can Transfer To:
|
|
5540
|
+
${transferList}`;
|
|
5541
|
+
}
|
|
5542
|
+
if (agentConfig.delegateRelations && agentConfig.delegateRelations.length > 0) {
|
|
5543
|
+
const delegateList = agentConfig.delegateRelations.map(
|
|
5544
|
+
(delegate) => ` - ${delegate.config.name || delegate.config.id}: ${delegate.config.description || "No description available"} (${delegate.type})`
|
|
5545
|
+
).join("\n");
|
|
5546
|
+
delegateSection = `
|
|
5547
|
+
|
|
5548
|
+
Can Delegate To:
|
|
5549
|
+
${delegateList}`;
|
|
5550
|
+
}
|
|
5551
|
+
}
|
|
5552
|
+
const finalDescription = `Delegate a specific task to another agent.
|
|
5471
5553
|
|
|
5472
5554
|
Agent Information:
|
|
5473
5555
|
- ID: ${config.id}
|
|
5474
5556
|
- Name: ${config.name}
|
|
5475
5557
|
- Description: ${config.description || "No description provided"}
|
|
5558
|
+
- Type: ${delegateRelation.type}${toolsSection}${transferSection}${delegateSection}
|
|
5476
5559
|
|
|
5477
5560
|
Delegate a specific task to agent ${config.id} when it seems like the agent can do relevant work.`;
|
|
5561
|
+
return finalDescription;
|
|
5478
5562
|
};
|
|
5479
5563
|
var createTransferToAgentTool = ({
|
|
5480
5564
|
transferConfig,
|
|
@@ -5482,8 +5566,9 @@ var createTransferToAgentTool = ({
|
|
|
5482
5566
|
subAgent,
|
|
5483
5567
|
streamRequestId
|
|
5484
5568
|
}) => {
|
|
5569
|
+
const toolDescription = generateTransferToolDescription(transferConfig);
|
|
5485
5570
|
return tool({
|
|
5486
|
-
description:
|
|
5571
|
+
description: toolDescription,
|
|
5487
5572
|
inputSchema: z5.object({}),
|
|
5488
5573
|
execute: async () => {
|
|
5489
5574
|
const activeSpan = trace.getActiveSpan();
|
|
@@ -5538,7 +5623,7 @@ function createDelegateToAgentTool({
|
|
|
5538
5623
|
credentialStoreRegistry
|
|
5539
5624
|
}) {
|
|
5540
5625
|
return tool({
|
|
5541
|
-
description: generateDelegateToolDescription(delegateConfig
|
|
5626
|
+
description: generateDelegateToolDescription(delegateConfig),
|
|
5542
5627
|
inputSchema: z5.object({ message: z5.string() }),
|
|
5543
5628
|
execute: async (input, context) => {
|
|
5544
5629
|
const delegationId = `del_${generateId()}`;
|
|
@@ -5636,13 +5721,12 @@ function createDelegateToAgentTool({
|
|
|
5636
5721
|
retryConfig: {
|
|
5637
5722
|
strategy: "backoff",
|
|
5638
5723
|
retryConnectionErrors: true,
|
|
5639
|
-
statusCodes: [
|
|
5724
|
+
statusCodes: [...A2A_RETRY_STATUS_CODES],
|
|
5640
5725
|
backoff: {
|
|
5641
|
-
initialInterval:
|
|
5642
|
-
maxInterval:
|
|
5643
|
-
exponent:
|
|
5644
|
-
maxElapsedTime:
|
|
5645
|
-
// 1 minute max retry time
|
|
5726
|
+
initialInterval: DELEGATION_TOOL_BACKOFF_INITIAL_INTERVAL_MS,
|
|
5727
|
+
maxInterval: DELEGATION_TOOL_BACKOFF_MAX_INTERVAL_MS,
|
|
5728
|
+
exponent: DELEGATION_TOOL_BACKOFF_EXPONENT,
|
|
5729
|
+
maxElapsedTime: DELEGATION_TOOL_BACKOFF_MAX_ELAPSED_TIME_MS
|
|
5646
5730
|
}
|
|
5647
5731
|
}
|
|
5648
5732
|
});
|
|
@@ -5794,7 +5878,7 @@ var system_prompt_default = `<system_message>
|
|
|
5794
5878
|
- You ARE the user's assistant - there are no other agents, specialists, or experts
|
|
5795
5879
|
- NEVER say you are connecting them to anyone or anything
|
|
5796
5880
|
- Continue conversations as if you personally have been handling them the entire time
|
|
5797
|
-
- Answer questions directly without any transition phrases or transfer language
|
|
5881
|
+
- Answer questions directly without any transition phrases or transfer language except when transferring to another agent or delegating to another agent
|
|
5798
5882
|
{{TRANSFER_INSTRUCTIONS}}
|
|
5799
5883
|
{{DELEGATION_INSTRUCTIONS}}
|
|
5800
5884
|
</security>
|
|
@@ -5802,7 +5886,7 @@ var system_prompt_default = `<system_message>
|
|
|
5802
5886
|
<interaction_guidelines>
|
|
5803
5887
|
- Be helpful, accurate, and professional
|
|
5804
5888
|
- Use tools when appropriate to provide better assistance
|
|
5805
|
-
-
|
|
5889
|
+
- Use tools directly without announcing or explaining what you're doing ("Let me search...", "I'll look for...", etc.)
|
|
5806
5890
|
- Save important tool results as artifacts when they contain structured data that should be preserved and referenced
|
|
5807
5891
|
- Ask for clarification when requests are ambiguous
|
|
5808
5892
|
|
|
@@ -5820,11 +5904,6 @@ var system_prompt_default = `<system_message>
|
|
|
5820
5904
|
- NEVER mention delegation occurred: just present the results
|
|
5821
5905
|
- If delegation returns artifacts, reference them as if you created them
|
|
5822
5906
|
|
|
5823
|
-
\u{1F6A8} TRANSFER TOOL RULES - CRITICAL:
|
|
5824
|
-
- When calling transfer_to_* tools, call the tool IMMEDIATELY without any explanatory text
|
|
5825
|
-
- Do NOT explain the transfer, do NOT say "I'll hand this off", do NOT provide reasoning
|
|
5826
|
-
- Just call the transfer tool directly when you determine it's needed
|
|
5827
|
-
- The tool call is sufficient - no additional text should be generated
|
|
5828
5907
|
</interaction_guidelines>
|
|
5829
5908
|
|
|
5830
5909
|
{{THINKING_PREPARATION_INSTRUCTIONS}}
|
|
@@ -6042,9 +6121,24 @@ var Phase1Config = class _Phase1Config {
|
|
|
6042
6121
|
if (!hasTransferRelations) {
|
|
6043
6122
|
return "";
|
|
6044
6123
|
}
|
|
6045
|
-
return
|
|
6046
|
-
|
|
6047
|
-
|
|
6124
|
+
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.
|
|
6125
|
+
|
|
6126
|
+
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.
|
|
6127
|
+
|
|
6128
|
+
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.
|
|
6129
|
+
|
|
6130
|
+
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:
|
|
6131
|
+
- Review the conversation history to see what was already communicated to the user
|
|
6132
|
+
- Continue seamlessly from where the previous response left off
|
|
6133
|
+
- Do NOT repeat what was already said in the conversation history
|
|
6134
|
+
- Do NOT announce what you're about to do ("Let me search...", "I'll look for...", etc.)
|
|
6135
|
+
- Proceed directly with the appropriate tool or action
|
|
6136
|
+
- Act as if you have been handling the conversation from the beginning
|
|
6137
|
+
|
|
6138
|
+
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.
|
|
6139
|
+
|
|
6140
|
+
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.
|
|
6141
|
+
`;
|
|
6048
6142
|
}
|
|
6049
6143
|
generateDelegationInstructions(hasDelegateRelations) {
|
|
6050
6144
|
if (!hasDelegateRelations) {
|
|
@@ -6805,12 +6899,6 @@ function hasToolCallWithPrefix(prefix) {
|
|
|
6805
6899
|
};
|
|
6806
6900
|
}
|
|
6807
6901
|
var logger15 = getLogger("Agent");
|
|
6808
|
-
var CONSTANTS = {
|
|
6809
|
-
MAX_GENERATION_STEPS: 12,
|
|
6810
|
-
PHASE_1_TIMEOUT_MS: 27e4,
|
|
6811
|
-
NON_STREAMING_PHASE_1_TIMEOUT_MS: 9e4,
|
|
6812
|
-
PHASE_2_TIMEOUT_MS: 9e4
|
|
6813
|
-
};
|
|
6814
6902
|
function validateModel(modelString, modelType) {
|
|
6815
6903
|
if (!modelString?.trim()) {
|
|
6816
6904
|
throw new Error(
|
|
@@ -6879,10 +6967,10 @@ var Agent = class {
|
|
|
6879
6967
|
}
|
|
6880
6968
|
/**
|
|
6881
6969
|
* Get the maximum number of generation steps for this agent
|
|
6882
|
-
* Uses agent's stopWhen.stepCountIs config or defaults to
|
|
6970
|
+
* Uses agent's stopWhen.stepCountIs config or defaults to AGENT_EXECUTION_MAX_GENERATION_STEPS
|
|
6883
6971
|
*/
|
|
6884
6972
|
getMaxGenerationSteps() {
|
|
6885
|
-
return this.config.stopWhen?.stepCountIs ??
|
|
6973
|
+
return this.config.stopWhen?.stepCountIs ?? AGENT_EXECUTION_MAX_GENERATION_STEPS;
|
|
6886
6974
|
}
|
|
6887
6975
|
/**
|
|
6888
6976
|
* Sanitizes tool names at runtime for AI SDK compatibility.
|
|
@@ -7400,7 +7488,7 @@ var Agent = class {
|
|
|
7400
7488
|
if (functionToolsData.length === 0) {
|
|
7401
7489
|
return functionTools;
|
|
7402
7490
|
}
|
|
7403
|
-
const { SandboxExecutorFactory } = await import('./SandboxExecutorFactory-
|
|
7491
|
+
const { SandboxExecutorFactory } = await import('./SandboxExecutorFactory-D3OSN652.js');
|
|
7404
7492
|
const sandboxExecutor = SandboxExecutorFactory.getInstance();
|
|
7405
7493
|
for (const functionToolDef of functionToolsData) {
|
|
7406
7494
|
const functionId = functionToolDef.functionId;
|
|
@@ -7438,8 +7526,8 @@ var Agent = class {
|
|
|
7438
7526
|
const defaultSandboxConfig = {
|
|
7439
7527
|
provider: "native",
|
|
7440
7528
|
runtime: "node22",
|
|
7441
|
-
timeout:
|
|
7442
|
-
vcpus:
|
|
7529
|
+
timeout: FUNCTION_TOOL_EXECUTION_TIMEOUT_MS_DEFAULT,
|
|
7530
|
+
vcpus: FUNCTION_TOOL_SANDBOX_VCPUS_DEFAULT
|
|
7443
7531
|
};
|
|
7444
7532
|
const result = await sandboxExecutor.executeFunctionTool(functionToolDef.id, args, {
|
|
7445
7533
|
description: functionToolDef.description || functionToolDef.name,
|
|
@@ -7694,7 +7782,7 @@ var Agent = class {
|
|
|
7694
7782
|
inputSchema: tool3.inputSchema || tool3.parameters || {},
|
|
7695
7783
|
usageGuidelines: name.startsWith("transfer_to_") || name.startsWith("delegate_to_") ? `Use this tool to ${name.startsWith("transfer_to_") ? "transfer" : "delegate"} to another agent when appropriate.` : "Use this tool when appropriate for the task at hand."
|
|
7696
7784
|
}));
|
|
7697
|
-
const { getConversationScopedArtifacts } = await import('./conversations-
|
|
7785
|
+
const { getConversationScopedArtifacts } = await import('./conversations-ZZI6XV2G.js');
|
|
7698
7786
|
const historyConfig = this.config.conversationHistoryConfig ?? createDefaultConversationHistoryConfig();
|
|
7699
7787
|
const referenceArtifacts = await getConversationScopedArtifacts({
|
|
7700
7788
|
tenantId: this.config.tenantId,
|
|
@@ -8044,6 +8132,9 @@ var Agent = class {
|
|
|
8044
8132
|
try {
|
|
8045
8133
|
this.streamRequestId = streamRequestId;
|
|
8046
8134
|
this.streamHelper = streamRequestId ? getStreamHelper(streamRequestId) : void 0;
|
|
8135
|
+
if (streamRequestId && this.artifactComponents.length > 0) {
|
|
8136
|
+
agentSessionManager.updateArtifactComponents(streamRequestId, this.artifactComponents);
|
|
8137
|
+
}
|
|
8047
8138
|
const conversationId = runtimeContext?.metadata?.conversationId;
|
|
8048
8139
|
if (conversationId) {
|
|
8049
8140
|
this.setConversationId(conversationId);
|
|
@@ -8125,15 +8216,14 @@ var Agent = class {
|
|
|
8125
8216
|
let textResponse;
|
|
8126
8217
|
const hasStructuredOutput = this.config.dataComponents && this.config.dataComponents.length > 0;
|
|
8127
8218
|
const shouldStreamPhase1 = this.getStreamingHelper() && !hasStructuredOutput;
|
|
8128
|
-
const
|
|
8129
|
-
const
|
|
8130
|
-
|
|
8131
|
-
if (modelSettings.maxDuration && modelSettings.maxDuration * 1e3 > MAX_ALLOWED_TIMEOUT_MS) {
|
|
8219
|
+
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;
|
|
8220
|
+
const timeoutMs = Math.min(configuredTimeout, LLM_GENERATION_MAX_ALLOWED_TIMEOUT_MS);
|
|
8221
|
+
if (modelSettings.maxDuration && modelSettings.maxDuration * 1e3 > LLM_GENERATION_MAX_ALLOWED_TIMEOUT_MS) {
|
|
8132
8222
|
logger15.warn(
|
|
8133
8223
|
{
|
|
8134
8224
|
requestedTimeout: modelSettings.maxDuration * 1e3,
|
|
8135
8225
|
appliedTimeout: timeoutMs,
|
|
8136
|
-
maxAllowed:
|
|
8226
|
+
maxAllowed: LLM_GENERATION_MAX_ALLOWED_TIMEOUT_MS
|
|
8137
8227
|
},
|
|
8138
8228
|
"Requested timeout exceeded maximum allowed, capping to 10 minutes"
|
|
8139
8229
|
);
|
|
@@ -8435,7 +8525,25 @@ ${output}${structureHintsFormatted}`;
|
|
|
8435
8525
|
const structuredModelSettings = ModelFactory.prepareGenerationConfig(
|
|
8436
8526
|
this.getStructuredOutputModel()
|
|
8437
8527
|
);
|
|
8438
|
-
const
|
|
8528
|
+
const configuredPhase2Timeout = structuredModelSettings.maxDuration ? Math.min(
|
|
8529
|
+
structuredModelSettings.maxDuration * 1e3,
|
|
8530
|
+
LLM_GENERATION_MAX_ALLOWED_TIMEOUT_MS
|
|
8531
|
+
) : LLM_GENERATION_SUBSEQUENT_CALL_TIMEOUT_MS;
|
|
8532
|
+
const phase2TimeoutMs = Math.min(
|
|
8533
|
+
configuredPhase2Timeout,
|
|
8534
|
+
LLM_GENERATION_MAX_ALLOWED_TIMEOUT_MS
|
|
8535
|
+
);
|
|
8536
|
+
if (structuredModelSettings.maxDuration && structuredModelSettings.maxDuration * 1e3 > LLM_GENERATION_MAX_ALLOWED_TIMEOUT_MS) {
|
|
8537
|
+
logger15.warn(
|
|
8538
|
+
{
|
|
8539
|
+
requestedTimeout: structuredModelSettings.maxDuration * 1e3,
|
|
8540
|
+
appliedTimeout: phase2TimeoutMs,
|
|
8541
|
+
maxAllowed: LLM_GENERATION_MAX_ALLOWED_TIMEOUT_MS,
|
|
8542
|
+
phase: "structured_generation"
|
|
8543
|
+
},
|
|
8544
|
+
"Phase 2 requested timeout exceeded maximum allowed, capping to 10 minutes"
|
|
8545
|
+
);
|
|
8546
|
+
}
|
|
8439
8547
|
const shouldStreamPhase2 = this.getStreamingHelper();
|
|
8440
8548
|
if (shouldStreamPhase2) {
|
|
8441
8549
|
const phase2Messages = [
|
|
@@ -8791,9 +8899,14 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
|
|
|
8791
8899
|
const models = "models" in config.agentSchema ? config.agentSchema.models : void 0;
|
|
8792
8900
|
const stopWhen = "stopWhen" in config.agentSchema ? config.agentSchema.stopWhen : void 0;
|
|
8793
8901
|
const toolsForAgentResult = await Promise.all(
|
|
8794
|
-
toolsForAgent.data.map(
|
|
8795
|
-
|
|
8796
|
-
|
|
8902
|
+
toolsForAgent.data.map(async (item) => {
|
|
8903
|
+
const mcpTool = await dbResultToMcpTool(item.tool, dbClient_default, credentialStoreRegistry);
|
|
8904
|
+
if (item.selectedTools && item.selectedTools.length > 0) {
|
|
8905
|
+
const selectedToolsSet = new Set(item.selectedTools);
|
|
8906
|
+
mcpTool.availableTools = mcpTool.availableTools?.filter((tool3) => selectedToolsSet.has(tool3.name)) || [];
|
|
8907
|
+
}
|
|
8908
|
+
return mcpTool;
|
|
8909
|
+
})
|
|
8797
8910
|
) ?? [];
|
|
8798
8911
|
const agent = new Agent(
|
|
8799
8912
|
{
|
|
@@ -8822,20 +8935,112 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
|
|
|
8822
8935
|
subAgentRelations: [],
|
|
8823
8936
|
transferRelations: []
|
|
8824
8937
|
})),
|
|
8825
|
-
transferRelations:
|
|
8826
|
-
|
|
8827
|
-
|
|
8828
|
-
|
|
8829
|
-
|
|
8830
|
-
|
|
8831
|
-
|
|
8832
|
-
|
|
8833
|
-
|
|
8834
|
-
|
|
8835
|
-
|
|
8836
|
-
|
|
8837
|
-
|
|
8838
|
-
|
|
8938
|
+
transferRelations: await Promise.all(
|
|
8939
|
+
enhancedInternalRelations.filter((relation) => relation.relationType === "transfer").map(async (relation) => {
|
|
8940
|
+
const targetToolsForAgent = await getToolsForAgent(dbClient_default)({
|
|
8941
|
+
scopes: {
|
|
8942
|
+
tenantId: config.tenantId,
|
|
8943
|
+
projectId: config.projectId,
|
|
8944
|
+
agentId: config.agentId,
|
|
8945
|
+
subAgentId: relation.id
|
|
8946
|
+
}
|
|
8947
|
+
});
|
|
8948
|
+
let targetTransferRelations = { data: [] };
|
|
8949
|
+
let targetDelegateRelations = { data: [] };
|
|
8950
|
+
try {
|
|
8951
|
+
const [transferRel, delegateRel] = await Promise.all([
|
|
8952
|
+
getRelatedAgentsForAgent(dbClient_default)({
|
|
8953
|
+
scopes: {
|
|
8954
|
+
tenantId: config.tenantId,
|
|
8955
|
+
projectId: config.projectId,
|
|
8956
|
+
agentId: config.agentId
|
|
8957
|
+
},
|
|
8958
|
+
subAgentId: relation.id
|
|
8959
|
+
}),
|
|
8960
|
+
getExternalAgentsForSubAgent(dbClient_default)({
|
|
8961
|
+
scopes: {
|
|
8962
|
+
tenantId: config.tenantId,
|
|
8963
|
+
projectId: config.projectId,
|
|
8964
|
+
agentId: config.agentId,
|
|
8965
|
+
subAgentId: relation.id
|
|
8966
|
+
}
|
|
8967
|
+
})
|
|
8968
|
+
]);
|
|
8969
|
+
targetTransferRelations = transferRel;
|
|
8970
|
+
targetDelegateRelations = delegateRel;
|
|
8971
|
+
} catch (err) {
|
|
8972
|
+
logger16.info(
|
|
8973
|
+
{
|
|
8974
|
+
agentId: relation.id,
|
|
8975
|
+
error: err?.message || "Unknown error"
|
|
8976
|
+
},
|
|
8977
|
+
"Could not fetch relations for target agent (likely external/team agent), using basic info only"
|
|
8978
|
+
);
|
|
8979
|
+
}
|
|
8980
|
+
const targetAgentTools = await Promise.all(
|
|
8981
|
+
targetToolsForAgent.data.map(async (item) => {
|
|
8982
|
+
const mcpTool = await dbResultToMcpTool(
|
|
8983
|
+
item.tool,
|
|
8984
|
+
dbClient_default,
|
|
8985
|
+
credentialStoreRegistry
|
|
8986
|
+
);
|
|
8987
|
+
if (item.selectedTools && item.selectedTools.length > 0) {
|
|
8988
|
+
const selectedToolsSet = new Set(item.selectedTools);
|
|
8989
|
+
mcpTool.availableTools = mcpTool.availableTools?.filter(
|
|
8990
|
+
(tool3) => selectedToolsSet.has(tool3.name)
|
|
8991
|
+
) || [];
|
|
8992
|
+
}
|
|
8993
|
+
return mcpTool;
|
|
8994
|
+
})
|
|
8995
|
+
) ?? [];
|
|
8996
|
+
const targetTransferRelationsConfig = targetTransferRelations.data.filter((rel) => rel.relationType === "transfer").map((rel) => ({
|
|
8997
|
+
baseUrl: config.baseUrl,
|
|
8998
|
+
apiKey: config.apiKey,
|
|
8999
|
+
id: rel.id,
|
|
9000
|
+
tenantId: config.tenantId,
|
|
9001
|
+
projectId: config.projectId,
|
|
9002
|
+
agentId: config.agentId,
|
|
9003
|
+
name: rel.name,
|
|
9004
|
+
description: rel.description,
|
|
9005
|
+
prompt: "",
|
|
9006
|
+
delegateRelations: [],
|
|
9007
|
+
subAgentRelations: [],
|
|
9008
|
+
transferRelations: []
|
|
9009
|
+
// Note: Not including tools for nested relations to avoid infinite recursion
|
|
9010
|
+
}));
|
|
9011
|
+
const targetDelegateRelationsConfig = targetDelegateRelations.data.map(
|
|
9012
|
+
(rel) => ({
|
|
9013
|
+
type: "external",
|
|
9014
|
+
config: {
|
|
9015
|
+
id: rel.externalAgent.id,
|
|
9016
|
+
name: rel.externalAgent.name,
|
|
9017
|
+
description: rel.externalAgent.description || "",
|
|
9018
|
+
baseUrl: rel.externalAgent.baseUrl,
|
|
9019
|
+
headers: rel.headers,
|
|
9020
|
+
credentialReferenceId: rel.externalAgent.credentialReferenceId,
|
|
9021
|
+
relationId: rel.id,
|
|
9022
|
+
relationType: "delegate"
|
|
9023
|
+
}
|
|
9024
|
+
})
|
|
9025
|
+
);
|
|
9026
|
+
return {
|
|
9027
|
+
baseUrl: config.baseUrl,
|
|
9028
|
+
apiKey: config.apiKey,
|
|
9029
|
+
id: relation.id,
|
|
9030
|
+
tenantId: config.tenantId,
|
|
9031
|
+
projectId: config.projectId,
|
|
9032
|
+
agentId: config.agentId,
|
|
9033
|
+
name: relation.name,
|
|
9034
|
+
description: relation.description,
|
|
9035
|
+
prompt: "",
|
|
9036
|
+
delegateRelations: targetDelegateRelationsConfig,
|
|
9037
|
+
subAgentRelations: [],
|
|
9038
|
+
transferRelations: targetTransferRelationsConfig,
|
|
9039
|
+
tools: targetAgentTools
|
|
9040
|
+
// Include target agent's tools for transfer descriptions
|
|
9041
|
+
};
|
|
9042
|
+
})
|
|
9043
|
+
),
|
|
8839
9044
|
delegateRelations: [
|
|
8840
9045
|
...enhancedInternalRelations.filter((relation) => relation.relationType === "delegate").map((relation) => ({
|
|
8841
9046
|
type: "internal",
|
|
@@ -8850,8 +9055,11 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
|
|
|
8850
9055
|
description: relation.description,
|
|
8851
9056
|
prompt: "",
|
|
8852
9057
|
delegateRelations: [],
|
|
9058
|
+
// Simplified - no nested relations
|
|
8853
9059
|
subAgentRelations: [],
|
|
8854
|
-
transferRelations: []
|
|
9060
|
+
transferRelations: [],
|
|
9061
|
+
tools: []
|
|
9062
|
+
// Tools are defined in config files, not DB
|
|
8855
9063
|
}
|
|
8856
9064
|
})),
|
|
8857
9065
|
...externalRelations.data.map((relation) => ({
|
|
@@ -9669,7 +9877,6 @@ function createSSEStreamHelper(stream2, requestId2, timestamp) {
|
|
|
9669
9877
|
return new SSEStreamHelper(stream2, requestId2, timestamp);
|
|
9670
9878
|
}
|
|
9671
9879
|
var _VercelDataStreamHelper = class _VercelDataStreamHelper {
|
|
9672
|
-
// 10 minutes max lifetime
|
|
9673
9880
|
constructor(writer) {
|
|
9674
9881
|
this.writer = writer;
|
|
9675
9882
|
__publicField(this, "textId", null);
|
|
@@ -9679,18 +9886,14 @@ var _VercelDataStreamHelper = class _VercelDataStreamHelper {
|
|
|
9679
9886
|
__publicField(this, "completedItems", /* @__PURE__ */ new Set());
|
|
9680
9887
|
// Track completed items
|
|
9681
9888
|
__publicField(this, "sessionId");
|
|
9682
|
-
// 5MB limit (more generous during request)
|
|
9683
9889
|
__publicField(this, "isCompleted", false);
|
|
9684
9890
|
__publicField(this, "isTextStreaming", false);
|
|
9685
9891
|
__publicField(this, "queuedEvents", []);
|
|
9686
9892
|
__publicField(this, "lastTextEndTimestamp", 0);
|
|
9687
|
-
__publicField(this, "TEXT_GAP_THRESHOLD", 2e3);
|
|
9688
|
-
// milliseconds - if gap between text sequences is less than this, queue operations
|
|
9689
9893
|
__publicField(this, "connectionDropTimer");
|
|
9690
|
-
__publicField(this, "MAX_LIFETIME_MS", 6e5);
|
|
9691
9894
|
this.connectionDropTimer = setTimeout(() => {
|
|
9692
9895
|
this.forceCleanup("Connection lifetime exceeded");
|
|
9693
|
-
},
|
|
9896
|
+
}, STREAM_MAX_LIFETIME_MS);
|
|
9694
9897
|
}
|
|
9695
9898
|
setSessionId(sessionId) {
|
|
9696
9899
|
this.sessionId = sessionId;
|
|
@@ -9744,7 +9947,7 @@ var _VercelDataStreamHelper = class _VercelDataStreamHelper {
|
|
|
9744
9947
|
const id = this.textId;
|
|
9745
9948
|
const startTime = Date.now();
|
|
9746
9949
|
const gapFromLastSequence = this.lastTextEndTimestamp > 0 ? startTime - this.lastTextEndTimestamp : Number.MAX_SAFE_INTEGER;
|
|
9747
|
-
if (gapFromLastSequence >=
|
|
9950
|
+
if (gapFromLastSequence >= STREAM_TEXT_GAP_THRESHOLD_MS) {
|
|
9748
9951
|
await this.flushQueuedOperations();
|
|
9749
9952
|
}
|
|
9750
9953
|
this.isTextStreaming = true;
|
|
@@ -9778,7 +9981,7 @@ var _VercelDataStreamHelper = class _VercelDataStreamHelper {
|
|
|
9778
9981
|
if (type === "data-artifact") {
|
|
9779
9982
|
const now = Date.now();
|
|
9780
9983
|
const gapFromLastTextEnd = this.lastTextEndTimestamp > 0 ? now - this.lastTextEndTimestamp : Number.MAX_SAFE_INTEGER;
|
|
9781
|
-
if (this.isTextStreaming || gapFromLastTextEnd <
|
|
9984
|
+
if (this.isTextStreaming || gapFromLastTextEnd < STREAM_TEXT_GAP_THRESHOLD_MS) {
|
|
9782
9985
|
this.writer.write({
|
|
9783
9986
|
type: `${type}`,
|
|
9784
9987
|
data
|
|
@@ -9931,7 +10134,7 @@ var _VercelDataStreamHelper = class _VercelDataStreamHelper {
|
|
|
9931
10134
|
}
|
|
9932
10135
|
const now = Date.now();
|
|
9933
10136
|
const gapFromLastTextEnd = this.lastTextEndTimestamp > 0 ? now - this.lastTextEndTimestamp : Number.MAX_SAFE_INTEGER;
|
|
9934
|
-
if (this.isTextStreaming || gapFromLastTextEnd <
|
|
10137
|
+
if (this.isTextStreaming || gapFromLastTextEnd < STREAM_TEXT_GAP_THRESHOLD_MS) {
|
|
9935
10138
|
this.queuedEvents.push({ type: "data-summary", event: summary });
|
|
9936
10139
|
return;
|
|
9937
10140
|
}
|
|
@@ -9949,7 +10152,7 @@ var _VercelDataStreamHelper = class _VercelDataStreamHelper {
|
|
|
9949
10152
|
}
|
|
9950
10153
|
const now = Date.now();
|
|
9951
10154
|
const gapFromLastTextEnd = this.lastTextEndTimestamp > 0 ? now - this.lastTextEndTimestamp : Number.MAX_SAFE_INTEGER;
|
|
9952
|
-
if (this.isTextStreaming || gapFromLastTextEnd <
|
|
10155
|
+
if (this.isTextStreaming || gapFromLastTextEnd < STREAM_TEXT_GAP_THRESHOLD_MS) {
|
|
9953
10156
|
this.queuedEvents.push({ type: "data-operation", event: operation });
|
|
9954
10157
|
return;
|
|
9955
10158
|
}
|
|
@@ -9992,7 +10195,7 @@ var _VercelDataStreamHelper = class _VercelDataStreamHelper {
|
|
|
9992
10195
|
this.cleanup();
|
|
9993
10196
|
}
|
|
9994
10197
|
};
|
|
9995
|
-
__publicField(_VercelDataStreamHelper, "MAX_BUFFER_SIZE",
|
|
10198
|
+
__publicField(_VercelDataStreamHelper, "MAX_BUFFER_SIZE", STREAM_BUFFER_MAX_SIZE_BYTES);
|
|
9996
10199
|
var VercelDataStreamHelper = _VercelDataStreamHelper;
|
|
9997
10200
|
function createVercelStreamHelper(writer) {
|
|
9998
10201
|
return new VercelDataStreamHelper(writer);
|
|
@@ -10064,7 +10267,7 @@ var createMCPStreamHelper = createBufferingStreamHelper;
|
|
|
10064
10267
|
var logger20 = getLogger("ExecutionHandler");
|
|
10065
10268
|
var ExecutionHandler = class {
|
|
10066
10269
|
constructor() {
|
|
10067
|
-
__publicField(this, "MAX_ERRORS",
|
|
10270
|
+
__publicField(this, "MAX_ERRORS", AGENT_EXECUTION_MAX_CONSECUTIVE_ERRORS);
|
|
10068
10271
|
}
|
|
10069
10272
|
/**
|
|
10070
10273
|
* performs exeuction loop
|
|
@@ -10161,7 +10364,7 @@ var ExecutionHandler = class {
|
|
|
10161
10364
|
"Task created with metadata"
|
|
10162
10365
|
);
|
|
10163
10366
|
} catch (error) {
|
|
10164
|
-
if (error?.
|
|
10367
|
+
if (error?.cause?.code === "23505") {
|
|
10165
10368
|
logger20.info(
|
|
10166
10369
|
{ taskId, error: error.message },
|
|
10167
10370
|
"Task already exists, fetching existing task"
|
|
@@ -10184,7 +10387,7 @@ var ExecutionHandler = class {
|
|
|
10184
10387
|
}
|
|
10185
10388
|
logger20.debug(
|
|
10186
10389
|
{
|
|
10187
|
-
timestamp:
|
|
10390
|
+
timestamp: /* @__PURE__ */ new Date(),
|
|
10188
10391
|
executionType: "create_initial_task",
|
|
10189
10392
|
conversationId,
|
|
10190
10393
|
agentId,
|
|
@@ -10198,7 +10401,7 @@ var ExecutionHandler = class {
|
|
|
10198
10401
|
);
|
|
10199
10402
|
if (Array.isArray(task)) task = task[0];
|
|
10200
10403
|
let currentMessage = userMessage;
|
|
10201
|
-
const maxTransfers = agentConfig?.stopWhen?.transferCountIs ??
|
|
10404
|
+
const maxTransfers = agentConfig?.stopWhen?.transferCountIs ?? AGENT_EXECUTION_TRANSFER_COUNT_DEFAULT;
|
|
10202
10405
|
while (iterations < maxTransfers) {
|
|
10203
10406
|
iterations++;
|
|
10204
10407
|
logger20.info(
|
|
@@ -10293,7 +10496,27 @@ var ExecutionHandler = class {
|
|
|
10293
10496
|
const firstArtifact = messageResponse.result.artifacts[0];
|
|
10294
10497
|
const transferReason = firstArtifact?.parts[1]?.kind === "text" ? firstArtifact.parts[1].text : "Transfer initiated";
|
|
10295
10498
|
logger20.info({ targetSubAgentId, transferReason, transferFromAgent }, "Transfer response");
|
|
10296
|
-
|
|
10499
|
+
await createMessage(dbClient_default)({
|
|
10500
|
+
id: generateId(),
|
|
10501
|
+
tenantId,
|
|
10502
|
+
projectId,
|
|
10503
|
+
conversationId,
|
|
10504
|
+
role: "agent",
|
|
10505
|
+
content: {
|
|
10506
|
+
text: transferReason,
|
|
10507
|
+
parts: [
|
|
10508
|
+
{
|
|
10509
|
+
kind: "text",
|
|
10510
|
+
text: transferReason
|
|
10511
|
+
}
|
|
10512
|
+
]
|
|
10513
|
+
},
|
|
10514
|
+
visibility: "user-facing",
|
|
10515
|
+
messageType: "chat",
|
|
10516
|
+
fromSubAgentId: currentAgentId,
|
|
10517
|
+
taskId: task.id
|
|
10518
|
+
});
|
|
10519
|
+
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.";
|
|
10297
10520
|
const { success, targetSubAgentId: newAgentId } = await executeTransfer({
|
|
10298
10521
|
projectId,
|
|
10299
10522
|
tenantId,
|
|
@@ -10377,7 +10600,7 @@ var ExecutionHandler = class {
|
|
|
10377
10600
|
status: "completed",
|
|
10378
10601
|
metadata: {
|
|
10379
10602
|
...task.metadata,
|
|
10380
|
-
completed_at:
|
|
10603
|
+
completed_at: /* @__PURE__ */ new Date(),
|
|
10381
10604
|
response: {
|
|
10382
10605
|
text: textContent,
|
|
10383
10606
|
parts: responseParts,
|
|
@@ -10429,7 +10652,7 @@ var ExecutionHandler = class {
|
|
|
10429
10652
|
status: "failed",
|
|
10430
10653
|
metadata: {
|
|
10431
10654
|
...task.metadata,
|
|
10432
|
-
failed_at:
|
|
10655
|
+
failed_at: /* @__PURE__ */ new Date(),
|
|
10433
10656
|
error: errorMessage2
|
|
10434
10657
|
}
|
|
10435
10658
|
}
|
|
@@ -10450,7 +10673,7 @@ var ExecutionHandler = class {
|
|
|
10450
10673
|
status: "failed",
|
|
10451
10674
|
metadata: {
|
|
10452
10675
|
...task.metadata,
|
|
10453
|
-
failed_at:
|
|
10676
|
+
failed_at: /* @__PURE__ */ new Date(),
|
|
10454
10677
|
error: errorMessage
|
|
10455
10678
|
}
|
|
10456
10679
|
}
|
|
@@ -10472,7 +10695,7 @@ var ExecutionHandler = class {
|
|
|
10472
10695
|
status: "failed",
|
|
10473
10696
|
metadata: {
|
|
10474
10697
|
...task.metadata,
|
|
10475
|
-
failed_at:
|
|
10698
|
+
failed_at: /* @__PURE__ */ new Date(),
|
|
10476
10699
|
error: errorMessage
|
|
10477
10700
|
}
|
|
10478
10701
|
}
|