@inkeep/agents-run-api 0.16.3 → 0.18.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/dist/{LocalSandboxExecutor-JI4X2Z3N.js → LocalSandboxExecutor-PQIRECLQ.js} +19 -6
- package/dist/{chunk-5GUNCN5X.js → chunk-DQQRVSJS.js} +10 -8
- package/dist/{conversations-6HJ4FX5F.js → conversations-JSORLLWS.js} +1 -1
- package/dist/index.cjs +696 -587
- package/dist/index.js +650 -556
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -198,8 +198,8 @@ async function saveA2AMessageResponse(response, params) {
|
|
|
198
198
|
},
|
|
199
199
|
visibility: params.visibility,
|
|
200
200
|
messageType: params.messageType,
|
|
201
|
-
|
|
202
|
-
|
|
201
|
+
fromSubAgentId: params.fromSubAgentId,
|
|
202
|
+
toSubAgentId: params.toSubAgentId,
|
|
203
203
|
fromExternalAgentId: params.fromExternalAgentId,
|
|
204
204
|
toExternalAgentId: params.toExternalAgentId,
|
|
205
205
|
a2aTaskId: params.a2aTaskId,
|
|
@@ -220,23 +220,23 @@ async function getScopedHistory({
|
|
|
220
220
|
conversationId,
|
|
221
221
|
options
|
|
222
222
|
});
|
|
223
|
-
if (!filters || !filters.
|
|
223
|
+
if (!filters || !filters.subAgentId && !filters.taskId) {
|
|
224
224
|
return messages;
|
|
225
225
|
}
|
|
226
226
|
const relevantMessages = messages.filter((msg) => {
|
|
227
227
|
if (msg.role === "user") return true;
|
|
228
228
|
let matchesAgent = true;
|
|
229
229
|
let matchesTask = true;
|
|
230
|
-
if (filters.
|
|
231
|
-
matchesAgent = msg.role === "agent" && msg.visibility === "user-facing" || msg.toAgentId === filters.
|
|
230
|
+
if (filters.subAgentId) {
|
|
231
|
+
matchesAgent = msg.role === "agent" && msg.visibility === "user-facing" || msg.toAgentId === filters.subAgentId || msg.fromAgentId === filters.subAgentId;
|
|
232
232
|
}
|
|
233
233
|
if (filters.taskId) {
|
|
234
234
|
matchesTask = msg.taskId === filters.taskId || msg.a2aTaskId === filters.taskId;
|
|
235
235
|
}
|
|
236
|
-
if (filters.
|
|
236
|
+
if (filters.subAgentId && filters.taskId) {
|
|
237
237
|
return matchesAgent && matchesTask;
|
|
238
238
|
}
|
|
239
|
-
if (filters.
|
|
239
|
+
if (filters.subAgentId) {
|
|
240
240
|
return matchesAgent;
|
|
241
241
|
}
|
|
242
242
|
if (filters.taskId) {
|
|
@@ -337,7 +337,9 @@ async function getConversationScopedArtifacts(params) {
|
|
|
337
337
|
if (visibleMessages.length === 0) {
|
|
338
338
|
return [];
|
|
339
339
|
}
|
|
340
|
-
const visibleMessageIds = visibleMessages.filter(
|
|
340
|
+
const visibleMessageIds = visibleMessages.filter(
|
|
341
|
+
(msg) => !(msg.messageType === "system" && msg.content?.text?.includes("Previous conversation history truncated"))
|
|
342
|
+
).map((msg) => msg.id);
|
|
341
343
|
if (visibleMessageIds.length === 0) {
|
|
342
344
|
return [];
|
|
343
345
|
}
|
|
@@ -352,8 +354,8 @@ async function getConversationScopedArtifacts(params) {
|
|
|
352
354
|
});
|
|
353
355
|
referenceArtifacts.push(...artifacts);
|
|
354
356
|
}
|
|
355
|
-
const
|
|
356
|
-
|
|
357
|
+
const logger27 = (await Promise.resolve().then(() => (init_logger(), logger_exports))).getLogger("conversations");
|
|
358
|
+
logger27.debug(
|
|
357
359
|
{
|
|
358
360
|
conversationId,
|
|
359
361
|
visibleMessages: visibleMessages.length,
|
|
@@ -365,8 +367,8 @@ async function getConversationScopedArtifacts(params) {
|
|
|
365
367
|
);
|
|
366
368
|
return referenceArtifacts;
|
|
367
369
|
} catch (error) {
|
|
368
|
-
const
|
|
369
|
-
|
|
370
|
+
const logger27 = (await Promise.resolve().then(() => (init_logger(), logger_exports))).getLogger("conversations");
|
|
371
|
+
logger27.error(
|
|
370
372
|
{
|
|
371
373
|
error: error instanceof Error ? error.message : "Unknown error",
|
|
372
374
|
conversationId
|
|
@@ -387,10 +389,10 @@ var LocalSandboxExecutor_exports = {};
|
|
|
387
389
|
__export(LocalSandboxExecutor_exports, {
|
|
388
390
|
LocalSandboxExecutor: () => LocalSandboxExecutor
|
|
389
391
|
});
|
|
390
|
-
var
|
|
392
|
+
var logger17, _LocalSandboxExecutor, LocalSandboxExecutor;
|
|
391
393
|
var init_LocalSandboxExecutor = __esm({
|
|
392
394
|
"src/tools/LocalSandboxExecutor.ts"() {
|
|
393
|
-
|
|
395
|
+
logger17 = agentsCore.getLogger("local-sandbox-executor");
|
|
394
396
|
_LocalSandboxExecutor = class _LocalSandboxExecutor {
|
|
395
397
|
constructor() {
|
|
396
398
|
__publicField(this, "tempDir");
|
|
@@ -426,7 +428,7 @@ var init_LocalSandboxExecutor = __esm({
|
|
|
426
428
|
if (now - sandbox.lastUsed < this.POOL_TTL && sandbox.useCount < this.MAX_USE_COUNT) {
|
|
427
429
|
sandbox.lastUsed = now;
|
|
428
430
|
sandbox.useCount++;
|
|
429
|
-
|
|
431
|
+
logger17.debug(
|
|
430
432
|
{
|
|
431
433
|
poolKey,
|
|
432
434
|
useCount: sandbox.useCount,
|
|
@@ -454,14 +456,14 @@ var init_LocalSandboxExecutor = __esm({
|
|
|
454
456
|
useCount: 1,
|
|
455
457
|
dependencies
|
|
456
458
|
};
|
|
457
|
-
|
|
459
|
+
logger17.debug({ poolKey, sandboxDir }, "Added sandbox to pool");
|
|
458
460
|
}
|
|
459
461
|
cleanupSandbox(sandboxDir) {
|
|
460
462
|
try {
|
|
461
463
|
fs.rmSync(sandboxDir, { recursive: true, force: true });
|
|
462
|
-
|
|
464
|
+
logger17.debug({ sandboxDir }, "Cleaned up sandbox");
|
|
463
465
|
} catch (error) {
|
|
464
|
-
|
|
466
|
+
logger17.warn({ sandboxDir, error }, "Failed to clean up sandbox");
|
|
465
467
|
}
|
|
466
468
|
}
|
|
467
469
|
startPoolCleanup() {
|
|
@@ -478,7 +480,7 @@ var init_LocalSandboxExecutor = __esm({
|
|
|
478
480
|
delete this.sandboxPool[key];
|
|
479
481
|
});
|
|
480
482
|
if (keysToDelete.length > 0) {
|
|
481
|
-
|
|
483
|
+
logger17.debug({ cleanedCount: keysToDelete.length }, "Cleaned up expired sandboxes");
|
|
482
484
|
}
|
|
483
485
|
}, 6e4);
|
|
484
486
|
}
|
|
@@ -504,7 +506,7 @@ var init_LocalSandboxExecutor = __esm({
|
|
|
504
506
|
const hasEsmSyntax = esmPatterns.some((pattern) => pattern.test(executeCode));
|
|
505
507
|
const hasCjsSyntax = cjsPatterns.some((pattern) => pattern.test(executeCode));
|
|
506
508
|
if (hasEsmSyntax && hasCjsSyntax) {
|
|
507
|
-
|
|
509
|
+
logger17.warn(
|
|
508
510
|
{ executeCode: `${executeCode.substring(0, 100)}...` },
|
|
509
511
|
"Both ESM and CommonJS syntax detected, defaulting to ESM"
|
|
510
512
|
);
|
|
@@ -521,7 +523,7 @@ var init_LocalSandboxExecutor = __esm({
|
|
|
521
523
|
async executeFunctionTool(toolId, args, config) {
|
|
522
524
|
const dependencies = config.dependencies || {};
|
|
523
525
|
const dependencyHash = this.generateDependencyHash(dependencies);
|
|
524
|
-
|
|
526
|
+
logger17.debug(
|
|
525
527
|
{
|
|
526
528
|
toolId,
|
|
527
529
|
dependencies,
|
|
@@ -536,7 +538,7 @@ var init_LocalSandboxExecutor = __esm({
|
|
|
536
538
|
sandboxDir = path.join(this.tempDir, `sandbox-${dependencyHash}-${Date.now()}`);
|
|
537
539
|
fs.mkdirSync(sandboxDir, { recursive: true });
|
|
538
540
|
isNewSandbox = true;
|
|
539
|
-
|
|
541
|
+
logger17.debug(
|
|
540
542
|
{
|
|
541
543
|
toolId,
|
|
542
544
|
dependencyHash,
|
|
@@ -595,15 +597,15 @@ var init_LocalSandboxExecutor = __esm({
|
|
|
595
597
|
});
|
|
596
598
|
npm.on("close", (code) => {
|
|
597
599
|
if (code === 0) {
|
|
598
|
-
|
|
600
|
+
logger17.debug({ sandboxDir }, "Dependencies installed successfully");
|
|
599
601
|
resolve();
|
|
600
602
|
} else {
|
|
601
|
-
|
|
603
|
+
logger17.error({ sandboxDir, code, stderr }, "Failed to install dependencies");
|
|
602
604
|
reject(new Error(`npm install failed with code ${code}: ${stderr}`));
|
|
603
605
|
}
|
|
604
606
|
});
|
|
605
607
|
npm.on("error", (err) => {
|
|
606
|
-
|
|
608
|
+
logger17.error({ sandboxDir, error: err }, "Failed to spawn npm install");
|
|
607
609
|
reject(err);
|
|
608
610
|
});
|
|
609
611
|
});
|
|
@@ -644,7 +646,7 @@ var init_LocalSandboxExecutor = __esm({
|
|
|
644
646
|
stderr += dataStr;
|
|
645
647
|
});
|
|
646
648
|
const timeoutId = setTimeout(() => {
|
|
647
|
-
|
|
649
|
+
logger17.warn({ sandboxDir, timeout }, "Function execution timed out, killing process");
|
|
648
650
|
node.kill("SIGTERM");
|
|
649
651
|
setTimeout(() => {
|
|
650
652
|
try {
|
|
@@ -665,18 +667,18 @@ var init_LocalSandboxExecutor = __esm({
|
|
|
665
667
|
reject(new Error(result.error || "Function execution failed"));
|
|
666
668
|
}
|
|
667
669
|
} catch (parseError) {
|
|
668
|
-
|
|
670
|
+
logger17.error({ stdout, stderr, parseError }, "Failed to parse function result");
|
|
669
671
|
reject(new Error(`Invalid function result: ${stdout}`));
|
|
670
672
|
}
|
|
671
673
|
} else {
|
|
672
674
|
const errorMsg = signal ? `Function execution killed by signal ${signal}: ${stderr}` : `Function execution failed with code ${code}: ${stderr}`;
|
|
673
|
-
|
|
675
|
+
logger17.error({ code, signal, stderr }, "Function execution failed");
|
|
674
676
|
reject(new Error(errorMsg));
|
|
675
677
|
}
|
|
676
678
|
});
|
|
677
679
|
node.on("error", (error) => {
|
|
678
680
|
clearTimeout(timeoutId);
|
|
679
|
-
|
|
681
|
+
logger17.error({ sandboxDir, error }, "Failed to spawn node process");
|
|
680
682
|
reject(error);
|
|
681
683
|
});
|
|
682
684
|
});
|
|
@@ -687,13 +689,26 @@ var init_LocalSandboxExecutor = __esm({
|
|
|
687
689
|
const execute = ${executeCode};
|
|
688
690
|
const args = ${JSON.stringify(args)};
|
|
689
691
|
|
|
690
|
-
|
|
691
|
-
|
|
692
|
+
try {
|
|
693
|
+
const result = execute(args);
|
|
694
|
+
|
|
695
|
+
// Handle both sync and async functions
|
|
696
|
+
if (result && typeof result.then === 'function') {
|
|
697
|
+
// Async function - result is a Promise
|
|
698
|
+
result
|
|
699
|
+
.then(result => {
|
|
700
|
+
console.log(JSON.stringify({ success: true, result }));
|
|
701
|
+
})
|
|
702
|
+
.catch(error => {
|
|
703
|
+
console.log(JSON.stringify({ success: false, error: error.message }));
|
|
704
|
+
});
|
|
705
|
+
} else {
|
|
706
|
+
// Sync function - result is immediate
|
|
692
707
|
console.log(JSON.stringify({ success: true, result }));
|
|
693
|
-
}
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
708
|
+
}
|
|
709
|
+
} catch (error) {
|
|
710
|
+
console.log(JSON.stringify({ success: false, error: error.message }));
|
|
711
|
+
}
|
|
697
712
|
`;
|
|
698
713
|
}
|
|
699
714
|
};
|
|
@@ -807,7 +822,7 @@ function createExecutionContext(params) {
|
|
|
807
822
|
graphId: params.graphId,
|
|
808
823
|
baseUrl: params.baseUrl || process.env.API_URL || "http://localhost:3003",
|
|
809
824
|
apiKeyId: params.apiKeyId,
|
|
810
|
-
|
|
825
|
+
subAgentId: params.subAgentId
|
|
811
826
|
};
|
|
812
827
|
}
|
|
813
828
|
|
|
@@ -822,16 +837,18 @@ var apiKeyAuth = () => factory.createMiddleware(async (c, next) => {
|
|
|
822
837
|
const tenantId = c.req.header("x-inkeep-tenant-id");
|
|
823
838
|
const projectId = c.req.header("x-inkeep-project-id");
|
|
824
839
|
const graphId = c.req.header("x-inkeep-graph-id");
|
|
825
|
-
const
|
|
826
|
-
const proto = c.req.header("x-forwarded-proto")
|
|
827
|
-
const
|
|
828
|
-
const
|
|
840
|
+
const subAgentId = c.req.header("x-inkeep-agent-id");
|
|
841
|
+
const proto = c.req.header("x-forwarded-proto")?.split(",")[0].trim();
|
|
842
|
+
const fwdHost = c.req.header("x-forwarded-host")?.split(",")[0].trim();
|
|
843
|
+
const host = fwdHost ?? c.req.header("host");
|
|
844
|
+
const reqUrl = new URL(c.req.url);
|
|
845
|
+
const baseUrl = proto && host ? `${proto}://${host}` : host ? `${reqUrl.protocol}//${host}` : `${reqUrl.origin}`;
|
|
829
846
|
if (process.env.ENVIRONMENT === "development" || process.env.ENVIRONMENT === "test") {
|
|
830
847
|
let executionContext;
|
|
831
848
|
if (authHeader?.startsWith("Bearer ")) {
|
|
832
849
|
try {
|
|
833
850
|
executionContext = await extractContextFromApiKey(authHeader.substring(7), baseUrl);
|
|
834
|
-
executionContext.
|
|
851
|
+
executionContext.subAgentId = subAgentId;
|
|
835
852
|
logger2.info({}, "Development/test environment - API key authenticated successfully");
|
|
836
853
|
} catch {
|
|
837
854
|
executionContext = createExecutionContext({
|
|
@@ -841,7 +858,7 @@ var apiKeyAuth = () => factory.createMiddleware(async (c, next) => {
|
|
|
841
858
|
graphId: graphId || "test-graph",
|
|
842
859
|
apiKeyId: "test-key",
|
|
843
860
|
baseUrl,
|
|
844
|
-
|
|
861
|
+
subAgentId
|
|
845
862
|
});
|
|
846
863
|
logger2.info(
|
|
847
864
|
{},
|
|
@@ -856,7 +873,7 @@ var apiKeyAuth = () => factory.createMiddleware(async (c, next) => {
|
|
|
856
873
|
graphId: graphId || "test-graph",
|
|
857
874
|
apiKeyId: "test-key",
|
|
858
875
|
baseUrl,
|
|
859
|
-
|
|
876
|
+
subAgentId
|
|
860
877
|
});
|
|
861
878
|
logger2.info(
|
|
862
879
|
{},
|
|
@@ -887,7 +904,7 @@ var apiKeyAuth = () => factory.createMiddleware(async (c, next) => {
|
|
|
887
904
|
graphId,
|
|
888
905
|
apiKeyId: "bypass",
|
|
889
906
|
baseUrl,
|
|
890
|
-
|
|
907
|
+
subAgentId
|
|
891
908
|
});
|
|
892
909
|
c.set("executionContext", executionContext);
|
|
893
910
|
logger2.info({}, "Bypass secret authenticated successfully");
|
|
@@ -895,7 +912,7 @@ var apiKeyAuth = () => factory.createMiddleware(async (c, next) => {
|
|
|
895
912
|
return;
|
|
896
913
|
} else if (apiKey) {
|
|
897
914
|
const executionContext = await extractContextFromApiKey(apiKey, baseUrl);
|
|
898
|
-
executionContext.
|
|
915
|
+
executionContext.subAgentId = subAgentId;
|
|
899
916
|
c.set("executionContext", executionContext);
|
|
900
917
|
logger2.info({}, "API key authenticated successfully");
|
|
901
918
|
await next();
|
|
@@ -913,14 +930,14 @@ var apiKeyAuth = () => factory.createMiddleware(async (c, next) => {
|
|
|
913
930
|
}
|
|
914
931
|
try {
|
|
915
932
|
const executionContext = await extractContextFromApiKey(apiKey, baseUrl);
|
|
916
|
-
executionContext.
|
|
933
|
+
executionContext.subAgentId = subAgentId;
|
|
917
934
|
c.set("executionContext", executionContext);
|
|
918
935
|
logger2.debug(
|
|
919
936
|
{
|
|
920
937
|
tenantId: executionContext.tenantId,
|
|
921
938
|
projectId: executionContext.projectId,
|
|
922
939
|
graphId: executionContext.graphId,
|
|
923
|
-
|
|
940
|
+
subAgentId: executionContext.subAgentId
|
|
924
941
|
},
|
|
925
942
|
"API key authenticated successfully"
|
|
926
943
|
);
|
|
@@ -1095,7 +1112,7 @@ async function handleMessageSend(c, agent, request) {
|
|
|
1095
1112
|
logger3.warn(
|
|
1096
1113
|
{
|
|
1097
1114
|
taskId: task.id,
|
|
1098
|
-
|
|
1115
|
+
subAgentId: agent.subAgentId,
|
|
1099
1116
|
originalMessage: params.message
|
|
1100
1117
|
},
|
|
1101
1118
|
"Created fallback message content for empty delegation message"
|
|
@@ -1116,7 +1133,7 @@ async function handleMessageSend(c, agent, request) {
|
|
|
1116
1133
|
taskContextId: task.context?.conversationId,
|
|
1117
1134
|
metadataContextId: params.message.metadata?.conversationId,
|
|
1118
1135
|
finalContextId: effectiveContextId,
|
|
1119
|
-
|
|
1136
|
+
subAgentId: agent.subAgentId
|
|
1120
1137
|
},
|
|
1121
1138
|
"A2A contextId resolution for delegation"
|
|
1122
1139
|
);
|
|
@@ -1132,11 +1149,11 @@ async function handleMessageSend(c, agent, request) {
|
|
|
1132
1149
|
message_id: params.message.messageId || "",
|
|
1133
1150
|
created_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1134
1151
|
updated_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1135
|
-
agent_id: agent.
|
|
1152
|
+
agent_id: agent.subAgentId,
|
|
1136
1153
|
graph_id: graphId || "",
|
|
1137
1154
|
stream_request_id: params.message.metadata?.stream_request_id
|
|
1138
1155
|
},
|
|
1139
|
-
|
|
1156
|
+
subAgentId: agent.subAgentId,
|
|
1140
1157
|
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1141
1158
|
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
1142
1159
|
});
|
|
@@ -1159,17 +1176,17 @@ async function handleMessageSend(c, agent, request) {
|
|
|
1159
1176
|
};
|
|
1160
1177
|
if (params.message.metadata?.fromAgentId) {
|
|
1161
1178
|
messageData.fromAgentId = params.message.metadata.fromAgentId;
|
|
1162
|
-
messageData.toAgentId = agent.
|
|
1179
|
+
messageData.toAgentId = agent.subAgentId;
|
|
1163
1180
|
} else if (params.message.metadata?.fromExternalAgentId) {
|
|
1164
1181
|
messageData.fromExternalAgentId = params.message.metadata.fromExternalAgentId;
|
|
1165
|
-
messageData.toAgentId = agent.
|
|
1182
|
+
messageData.toAgentId = agent.subAgentId;
|
|
1166
1183
|
}
|
|
1167
1184
|
await agentsCore.createMessage(dbClient_default)(messageData);
|
|
1168
1185
|
logger3.info(
|
|
1169
1186
|
{
|
|
1170
1187
|
fromAgentId: params.message.metadata.fromAgentId,
|
|
1171
1188
|
fromExternalAgentId: params.message.metadata.fromExternalAgentId,
|
|
1172
|
-
toAgentId: agent.
|
|
1189
|
+
toAgentId: agent.subAgentId,
|
|
1173
1190
|
conversationId: effectiveContextId,
|
|
1174
1191
|
messageType: "a2a-request",
|
|
1175
1192
|
taskId: task.id
|
|
@@ -1182,7 +1199,7 @@ async function handleMessageSend(c, agent, request) {
|
|
|
1182
1199
|
error,
|
|
1183
1200
|
fromAgentId: params.message.metadata.fromAgentId,
|
|
1184
1201
|
fromExternalAgentId: params.message.metadata.fromExternalAgentId,
|
|
1185
|
-
toAgentId: agent.
|
|
1202
|
+
toAgentId: agent.subAgentId,
|
|
1186
1203
|
conversationId: effectiveContextId
|
|
1187
1204
|
},
|
|
1188
1205
|
"Failed to store A2A message in database"
|
|
@@ -1199,7 +1216,7 @@ async function handleMessageSend(c, agent, request) {
|
|
|
1199
1216
|
message_id: params.message.messageId || "",
|
|
1200
1217
|
created_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1201
1218
|
updated_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1202
|
-
agent_id: agent.
|
|
1219
|
+
agent_id: agent.subAgentId,
|
|
1203
1220
|
graph_id: graphId || ""
|
|
1204
1221
|
}
|
|
1205
1222
|
}
|
|
@@ -1233,7 +1250,7 @@ async function handleMessageSend(c, agent, request) {
|
|
|
1233
1250
|
kind: "data",
|
|
1234
1251
|
data: {
|
|
1235
1252
|
type: "transfer",
|
|
1236
|
-
|
|
1253
|
+
targetSubAgentId: transferPart.data.target
|
|
1237
1254
|
}
|
|
1238
1255
|
},
|
|
1239
1256
|
{
|
|
@@ -1533,7 +1550,7 @@ async function handleGetCapabilities(c, agent, request) {
|
|
|
1533
1550
|
async function handleGetStatus(c, agent, request) {
|
|
1534
1551
|
return c.json({
|
|
1535
1552
|
jsonrpc: "2.0",
|
|
1536
|
-
result: { status: "ready",
|
|
1553
|
+
result: { status: "ready", subAgentId: agent.subAgentId },
|
|
1537
1554
|
id: request.id
|
|
1538
1555
|
});
|
|
1539
1556
|
}
|
|
@@ -1597,7 +1614,6 @@ async function handleTasksResubscribe(c, agent, request) {
|
|
|
1597
1614
|
}
|
|
1598
1615
|
}
|
|
1599
1616
|
init_dbClient();
|
|
1600
|
-
agentsCore.getLogger("agents");
|
|
1601
1617
|
function createAgentCard({
|
|
1602
1618
|
dbAgent,
|
|
1603
1619
|
baseUrl
|
|
@@ -1675,7 +1691,7 @@ async function hydrateAgent({
|
|
|
1675
1691
|
tenantId: dbAgent.tenantId,
|
|
1676
1692
|
projectId: dbAgent.projectId,
|
|
1677
1693
|
graphId,
|
|
1678
|
-
|
|
1694
|
+
subAgentId: dbAgent.id,
|
|
1679
1695
|
baseUrl,
|
|
1680
1696
|
apiKey
|
|
1681
1697
|
});
|
|
@@ -1685,7 +1701,7 @@ async function hydrateAgent({
|
|
|
1685
1701
|
baseUrl
|
|
1686
1702
|
});
|
|
1687
1703
|
return {
|
|
1688
|
-
|
|
1704
|
+
subAgentId: dbAgent.id,
|
|
1689
1705
|
tenantId: dbAgent.tenantId,
|
|
1690
1706
|
projectId: dbAgent.projectId,
|
|
1691
1707
|
graphId,
|
|
@@ -1698,13 +1714,13 @@ async function hydrateAgent({
|
|
|
1698
1714
|
}
|
|
1699
1715
|
}
|
|
1700
1716
|
async function getRegisteredAgent(executionContext, credentialStoreRegistry) {
|
|
1701
|
-
const { tenantId, projectId, graphId,
|
|
1702
|
-
if (!
|
|
1717
|
+
const { tenantId, projectId, graphId, subAgentId, baseUrl, apiKey } = executionContext;
|
|
1718
|
+
if (!subAgentId) {
|
|
1703
1719
|
throw new Error("Agent ID is required");
|
|
1704
1720
|
}
|
|
1705
|
-
const dbAgent = await agentsCore.
|
|
1721
|
+
const dbAgent = await agentsCore.getSubAgentById(dbClient_default)({
|
|
1706
1722
|
scopes: { tenantId, projectId, graphId },
|
|
1707
|
-
|
|
1723
|
+
subAgentId
|
|
1708
1724
|
});
|
|
1709
1725
|
if (!dbAgent) {
|
|
1710
1726
|
return null;
|
|
@@ -1725,7 +1741,7 @@ init_logger();
|
|
|
1725
1741
|
|
|
1726
1742
|
// src/agents/ModelFactory.ts
|
|
1727
1743
|
init_logger();
|
|
1728
|
-
var
|
|
1744
|
+
var logger4 = agentsCore.getLogger("ModelFactory");
|
|
1729
1745
|
var _ModelFactory = class _ModelFactory {
|
|
1730
1746
|
/**
|
|
1731
1747
|
* Create a provider instance with custom configuration
|
|
@@ -1787,7 +1803,7 @@ var _ModelFactory = class _ModelFactory {
|
|
|
1787
1803
|
}
|
|
1788
1804
|
const modelString = modelSettings.model.trim();
|
|
1789
1805
|
const { provider, modelName } = _ModelFactory.parseModelString(modelString);
|
|
1790
|
-
|
|
1806
|
+
logger4.debug(
|
|
1791
1807
|
{
|
|
1792
1808
|
provider,
|
|
1793
1809
|
model: modelName,
|
|
@@ -1798,7 +1814,7 @@ var _ModelFactory = class _ModelFactory {
|
|
|
1798
1814
|
);
|
|
1799
1815
|
const providerConfig = _ModelFactory.extractProviderConfig(modelSettings.providerOptions);
|
|
1800
1816
|
if (Object.keys(providerConfig).length > 0) {
|
|
1801
|
-
|
|
1817
|
+
logger4.info({ config: providerConfig }, `Applying custom ${provider} provider configuration`);
|
|
1802
1818
|
const customProvider = _ModelFactory.createProvider(provider, providerConfig);
|
|
1803
1819
|
return customProvider.languageModel(modelName);
|
|
1804
1820
|
}
|
|
@@ -1917,7 +1933,7 @@ var ModelFactory = _ModelFactory;
|
|
|
1917
1933
|
|
|
1918
1934
|
// src/agents/ToolSessionManager.ts
|
|
1919
1935
|
init_logger();
|
|
1920
|
-
var
|
|
1936
|
+
var logger5 = agentsCore.getLogger("ToolSessionManager");
|
|
1921
1937
|
var _ToolSessionManager = class _ToolSessionManager {
|
|
1922
1938
|
// 5 minutes
|
|
1923
1939
|
constructor() {
|
|
@@ -1952,7 +1968,7 @@ var _ToolSessionManager = class _ToolSessionManager {
|
|
|
1952
1968
|
createdAt: Date.now()
|
|
1953
1969
|
};
|
|
1954
1970
|
this.sessions.set(sessionId, session);
|
|
1955
|
-
|
|
1971
|
+
logger5.debug(
|
|
1956
1972
|
{
|
|
1957
1973
|
sessionId,
|
|
1958
1974
|
tenantId,
|
|
@@ -1970,10 +1986,10 @@ var _ToolSessionManager = class _ToolSessionManager {
|
|
|
1970
1986
|
*/
|
|
1971
1987
|
ensureGraphSession(sessionId, tenantId, projectId, contextId, taskId) {
|
|
1972
1988
|
if (this.sessions.has(sessionId)) {
|
|
1973
|
-
|
|
1989
|
+
logger5.debug({ sessionId }, "Graph session already exists, reusing");
|
|
1974
1990
|
return sessionId;
|
|
1975
1991
|
}
|
|
1976
|
-
|
|
1992
|
+
logger5.debug(
|
|
1977
1993
|
{ sessionId, tenantId, contextId, taskId },
|
|
1978
1994
|
"Creating new graph-scoped tool session"
|
|
1979
1995
|
);
|
|
@@ -1985,7 +2001,7 @@ var _ToolSessionManager = class _ToolSessionManager {
|
|
|
1985
2001
|
recordToolResult(sessionId, toolResult) {
|
|
1986
2002
|
const session = this.sessions.get(sessionId);
|
|
1987
2003
|
if (!session) {
|
|
1988
|
-
|
|
2004
|
+
logger5.warn(
|
|
1989
2005
|
{
|
|
1990
2006
|
sessionId,
|
|
1991
2007
|
toolCallId: toolResult.toolCallId,
|
|
@@ -1997,7 +2013,7 @@ var _ToolSessionManager = class _ToolSessionManager {
|
|
|
1997
2013
|
return;
|
|
1998
2014
|
}
|
|
1999
2015
|
session.toolResults.set(toolResult.toolCallId, toolResult);
|
|
2000
|
-
|
|
2016
|
+
logger5.debug(
|
|
2001
2017
|
{
|
|
2002
2018
|
sessionId,
|
|
2003
2019
|
toolCallId: toolResult.toolCallId,
|
|
@@ -2012,7 +2028,7 @@ var _ToolSessionManager = class _ToolSessionManager {
|
|
|
2012
2028
|
getToolResult(sessionId, toolCallId) {
|
|
2013
2029
|
const session = this.sessions.get(sessionId);
|
|
2014
2030
|
if (!session) {
|
|
2015
|
-
|
|
2031
|
+
logger5.warn(
|
|
2016
2032
|
{
|
|
2017
2033
|
sessionId,
|
|
2018
2034
|
toolCallId,
|
|
@@ -2025,7 +2041,7 @@ var _ToolSessionManager = class _ToolSessionManager {
|
|
|
2025
2041
|
}
|
|
2026
2042
|
const result = session.toolResults.get(toolCallId);
|
|
2027
2043
|
if (!result) {
|
|
2028
|
-
|
|
2044
|
+
logger5.warn(
|
|
2029
2045
|
{
|
|
2030
2046
|
sessionId,
|
|
2031
2047
|
toolCallId,
|
|
@@ -2035,7 +2051,7 @@ var _ToolSessionManager = class _ToolSessionManager {
|
|
|
2035
2051
|
"Tool result not found"
|
|
2036
2052
|
);
|
|
2037
2053
|
} else {
|
|
2038
|
-
|
|
2054
|
+
logger5.debug(
|
|
2039
2055
|
{
|
|
2040
2056
|
sessionId,
|
|
2041
2057
|
toolCallId,
|
|
@@ -2074,10 +2090,10 @@ var _ToolSessionManager = class _ToolSessionManager {
|
|
|
2074
2090
|
}
|
|
2075
2091
|
for (const sessionId of expiredSessions) {
|
|
2076
2092
|
this.sessions.delete(sessionId);
|
|
2077
|
-
|
|
2093
|
+
logger5.debug({ sessionId }, "Cleaned up expired tool session");
|
|
2078
2094
|
}
|
|
2079
2095
|
if (expiredSessions.length > 0) {
|
|
2080
|
-
|
|
2096
|
+
logger5.info({ expiredCount: expiredSessions.length }, "Cleaned up expired tool sessions");
|
|
2081
2097
|
}
|
|
2082
2098
|
}
|
|
2083
2099
|
};
|
|
@@ -2160,7 +2176,7 @@ function extractFullFields(schema) {
|
|
|
2160
2176
|
}
|
|
2161
2177
|
|
|
2162
2178
|
// src/services/ArtifactService.ts
|
|
2163
|
-
var
|
|
2179
|
+
var logger7 = agentsCore.getLogger("ArtifactService");
|
|
2164
2180
|
var _ArtifactService = class _ArtifactService {
|
|
2165
2181
|
constructor(context) {
|
|
2166
2182
|
this.context = context;
|
|
@@ -2192,7 +2208,7 @@ var _ArtifactService = class _ArtifactService {
|
|
|
2192
2208
|
id: taskId
|
|
2193
2209
|
});
|
|
2194
2210
|
if (!task) {
|
|
2195
|
-
|
|
2211
|
+
logger7.warn({ taskId }, "Task not found when fetching artifacts");
|
|
2196
2212
|
continue;
|
|
2197
2213
|
}
|
|
2198
2214
|
const taskArtifacts = await agentsCore.getLedgerArtifacts(dbClient_default)({
|
|
@@ -2210,21 +2226,21 @@ var _ArtifactService = class _ArtifactService {
|
|
|
2210
2226
|
}
|
|
2211
2227
|
}
|
|
2212
2228
|
} catch (error) {
|
|
2213
|
-
|
|
2229
|
+
logger7.error({ error, contextId }, "Error loading context artifacts");
|
|
2214
2230
|
}
|
|
2215
2231
|
return artifacts;
|
|
2216
2232
|
}
|
|
2217
2233
|
/**
|
|
2218
2234
|
* Create artifact from tool result and request data
|
|
2219
2235
|
*/
|
|
2220
|
-
async createArtifact(request,
|
|
2236
|
+
async createArtifact(request, subAgentId) {
|
|
2221
2237
|
if (!this.context.sessionId) {
|
|
2222
|
-
|
|
2238
|
+
logger7.warn({ request }, "No session ID available for artifact creation");
|
|
2223
2239
|
return null;
|
|
2224
2240
|
}
|
|
2225
2241
|
const toolResult = toolSessionManager.getToolResult(this.context.sessionId, request.toolCallId);
|
|
2226
2242
|
if (!toolResult) {
|
|
2227
|
-
|
|
2243
|
+
logger7.warn(
|
|
2228
2244
|
{ request, sessionId: this.context.sessionId },
|
|
2229
2245
|
"Tool result not found for artifact"
|
|
2230
2246
|
);
|
|
@@ -2240,7 +2256,7 @@ var _ArtifactService = class _ArtifactService {
|
|
|
2240
2256
|
selectedData = selectedData.length > 0 ? selectedData[0] : {};
|
|
2241
2257
|
}
|
|
2242
2258
|
if (!selectedData) {
|
|
2243
|
-
|
|
2259
|
+
logger7.warn(
|
|
2244
2260
|
{
|
|
2245
2261
|
request,
|
|
2246
2262
|
baseSelector: request.baseSelector
|
|
@@ -2285,7 +2301,7 @@ var _ArtifactService = class _ArtifactService {
|
|
|
2285
2301
|
type: request.type,
|
|
2286
2302
|
data: cleanedSummaryData
|
|
2287
2303
|
};
|
|
2288
|
-
await this.persistArtifact(request, cleanedSummaryData, cleanedFullData,
|
|
2304
|
+
await this.persistArtifact(request, cleanedSummaryData, cleanedFullData, subAgentId);
|
|
2289
2305
|
await this.cacheArtifact(
|
|
2290
2306
|
request.artifactId,
|
|
2291
2307
|
request.toolCallId,
|
|
@@ -2294,7 +2310,7 @@ var _ArtifactService = class _ArtifactService {
|
|
|
2294
2310
|
);
|
|
2295
2311
|
return artifactData;
|
|
2296
2312
|
} catch (error) {
|
|
2297
|
-
|
|
2313
|
+
logger7.error({ error, request }, "Failed to create artifact");
|
|
2298
2314
|
const errorMessage = error instanceof Error ? error.message : "Unknown error";
|
|
2299
2315
|
throw new Error(`Artifact creation failed for ${request.artifactId}: ${errorMessage}`);
|
|
2300
2316
|
}
|
|
@@ -2323,7 +2339,7 @@ var _ArtifactService = class _ArtifactService {
|
|
|
2323
2339
|
}
|
|
2324
2340
|
try {
|
|
2325
2341
|
if (!this.context.projectId || !this.context.taskId) {
|
|
2326
|
-
|
|
2342
|
+
logger7.warn(
|
|
2327
2343
|
{ artifactId, toolCallId },
|
|
2328
2344
|
"No projectId or taskId available for artifact lookup"
|
|
2329
2345
|
);
|
|
@@ -2338,7 +2354,7 @@ var _ArtifactService = class _ArtifactService {
|
|
|
2338
2354
|
return this.formatArtifactSummaryData(artifacts[0], artifactId, toolCallId);
|
|
2339
2355
|
}
|
|
2340
2356
|
} catch (error) {
|
|
2341
|
-
|
|
2357
|
+
logger7.warn(
|
|
2342
2358
|
{ artifactId, toolCallId, taskId: this.context.taskId, error },
|
|
2343
2359
|
"Failed to fetch artifact"
|
|
2344
2360
|
);
|
|
@@ -2369,7 +2385,7 @@ var _ArtifactService = class _ArtifactService {
|
|
|
2369
2385
|
}
|
|
2370
2386
|
try {
|
|
2371
2387
|
if (!this.context.projectId || !this.context.taskId) {
|
|
2372
|
-
|
|
2388
|
+
logger7.warn(
|
|
2373
2389
|
{ artifactId, toolCallId },
|
|
2374
2390
|
"No projectId or taskId available for artifact lookup"
|
|
2375
2391
|
);
|
|
@@ -2384,7 +2400,7 @@ var _ArtifactService = class _ArtifactService {
|
|
|
2384
2400
|
return this.formatArtifactFullData(artifacts[0], artifactId, toolCallId);
|
|
2385
2401
|
}
|
|
2386
2402
|
} catch (error) {
|
|
2387
|
-
|
|
2403
|
+
logger7.warn(
|
|
2388
2404
|
{ artifactId, toolCallId, taskId: this.context.taskId, error },
|
|
2389
2405
|
"Failed to fetch artifact"
|
|
2390
2406
|
);
|
|
@@ -2420,8 +2436,8 @@ var _ArtifactService = class _ArtifactService {
|
|
|
2420
2436
|
/**
|
|
2421
2437
|
* Persist artifact to database via graph session
|
|
2422
2438
|
*/
|
|
2423
|
-
async persistArtifact(request, summaryData, fullData,
|
|
2424
|
-
const effectiveAgentId =
|
|
2439
|
+
async persistArtifact(request, summaryData, fullData, subAgentId) {
|
|
2440
|
+
const effectiveAgentId = subAgentId || this.context.subAgentId;
|
|
2425
2441
|
if (this.context.streamRequestId && effectiveAgentId && this.context.taskId) {
|
|
2426
2442
|
await graphSessionManager.recordEvent(
|
|
2427
2443
|
this.context.streamRequestId,
|
|
@@ -2434,7 +2450,7 @@ var _ArtifactService = class _ArtifactService {
|
|
|
2434
2450
|
artifactType: request.type,
|
|
2435
2451
|
summaryData,
|
|
2436
2452
|
data: fullData,
|
|
2437
|
-
|
|
2453
|
+
subAgentId: effectiveAgentId,
|
|
2438
2454
|
metadata: {
|
|
2439
2455
|
toolCallId: request.toolCallId,
|
|
2440
2456
|
baseSelector: request.baseSelector,
|
|
@@ -2449,14 +2465,14 @@ var _ArtifactService = class _ArtifactService {
|
|
|
2449
2465
|
}
|
|
2450
2466
|
);
|
|
2451
2467
|
} else {
|
|
2452
|
-
|
|
2468
|
+
logger7.warn(
|
|
2453
2469
|
{
|
|
2454
2470
|
artifactId: request.artifactId,
|
|
2455
2471
|
hasStreamRequestId: !!this.context.streamRequestId,
|
|
2456
2472
|
hasAgentId: !!effectiveAgentId,
|
|
2457
2473
|
hasTaskId: !!this.context.taskId,
|
|
2458
|
-
passedAgentId:
|
|
2459
|
-
contextAgentId: this.context.
|
|
2474
|
+
passedAgentId: subAgentId,
|
|
2475
|
+
contextAgentId: this.context.subAgentId
|
|
2460
2476
|
},
|
|
2461
2477
|
"Skipping artifact_saved event - missing required context"
|
|
2462
2478
|
);
|
|
@@ -2524,7 +2540,7 @@ var _ArtifactService = class _ArtifactService {
|
|
|
2524
2540
|
summaryData = this.filterBySchema(artifact.data, previewSchema);
|
|
2525
2541
|
fullData = this.filterBySchema(artifact.data, fullSchema);
|
|
2526
2542
|
} catch (error) {
|
|
2527
|
-
|
|
2543
|
+
logger7.warn(
|
|
2528
2544
|
{
|
|
2529
2545
|
artifactType: artifact.type,
|
|
2530
2546
|
error: error instanceof Error ? error.message : "Unknown error"
|
|
@@ -2562,7 +2578,7 @@ var _ArtifactService = class _ArtifactService {
|
|
|
2562
2578
|
artifact: artifactToSave
|
|
2563
2579
|
});
|
|
2564
2580
|
if (!result.created && result.existing) {
|
|
2565
|
-
|
|
2581
|
+
logger7.debug(
|
|
2566
2582
|
{
|
|
2567
2583
|
artifactId: artifact.artifactId,
|
|
2568
2584
|
taskId: this.context.taskId
|
|
@@ -2615,7 +2631,7 @@ var _ArtifactService = class _ArtifactService {
|
|
|
2615
2631
|
extracted[propName] = this.cleanEscapedContent(rawValue);
|
|
2616
2632
|
}
|
|
2617
2633
|
} catch (error) {
|
|
2618
|
-
|
|
2634
|
+
logger7.warn(
|
|
2619
2635
|
{ propName, selector, error: error instanceof Error ? error.message : "Unknown error" },
|
|
2620
2636
|
"Failed to extract property"
|
|
2621
2637
|
);
|
|
@@ -2647,7 +2663,7 @@ var _ArtifactService = class _ArtifactService {
|
|
|
2647
2663
|
extracted[fieldName] = this.cleanEscapedContent(rawValue);
|
|
2648
2664
|
}
|
|
2649
2665
|
} catch (error) {
|
|
2650
|
-
|
|
2666
|
+
logger7.warn(
|
|
2651
2667
|
{ fieldName, error: error instanceof Error ? error.message : "Unknown error" },
|
|
2652
2668
|
"Failed to extract schema field"
|
|
2653
2669
|
);
|
|
@@ -2678,7 +2694,7 @@ __publicField(_ArtifactService, "selectorCache", /* @__PURE__ */ new Map());
|
|
|
2678
2694
|
var ArtifactService = _ArtifactService;
|
|
2679
2695
|
|
|
2680
2696
|
// src/services/ArtifactParser.ts
|
|
2681
|
-
var
|
|
2697
|
+
var logger8 = agentsCore.getLogger("ArtifactParser");
|
|
2682
2698
|
var _ArtifactParser = class _ArtifactParser {
|
|
2683
2699
|
constructor(tenantId, options) {
|
|
2684
2700
|
__publicField(this, "artifactService");
|
|
@@ -2766,7 +2782,7 @@ var _ArtifactParser = class _ArtifactParser {
|
|
|
2766
2782
|
attrs[key] = value;
|
|
2767
2783
|
}
|
|
2768
2784
|
if (!attrs.id || !attrs.tool || !attrs.type || !attrs.base) {
|
|
2769
|
-
|
|
2785
|
+
logger8.warn({ attrs, attrString }, "Missing required attributes in artifact annotation");
|
|
2770
2786
|
return null;
|
|
2771
2787
|
}
|
|
2772
2788
|
return {
|
|
@@ -2797,7 +2813,7 @@ var _ArtifactParser = class _ArtifactParser {
|
|
|
2797
2813
|
/**
|
|
2798
2814
|
* Extract artifact data from a create annotation - delegates to service
|
|
2799
2815
|
*/
|
|
2800
|
-
async extractFromCreateAnnotation(annotation,
|
|
2816
|
+
async extractFromCreateAnnotation(annotation, subAgentId) {
|
|
2801
2817
|
const request = {
|
|
2802
2818
|
artifactId: annotation.artifactId,
|
|
2803
2819
|
toolCallId: annotation.toolCallId,
|
|
@@ -2805,21 +2821,21 @@ var _ArtifactParser = class _ArtifactParser {
|
|
|
2805
2821
|
baseSelector: annotation.baseSelector,
|
|
2806
2822
|
detailsSelector: annotation.detailsSelector
|
|
2807
2823
|
};
|
|
2808
|
-
return this.artifactService.createArtifact(request,
|
|
2824
|
+
return this.artifactService.createArtifact(request, subAgentId);
|
|
2809
2825
|
}
|
|
2810
2826
|
/**
|
|
2811
2827
|
* Parse text with artifact markers into parts array
|
|
2812
2828
|
* Handles both artifact:ref and artifact:create tags
|
|
2813
2829
|
* Can work with or without pre-fetched artifact map
|
|
2814
2830
|
*/
|
|
2815
|
-
async parseText(text, artifactMap,
|
|
2831
|
+
async parseText(text, artifactMap, subAgentId) {
|
|
2816
2832
|
let processedText = text;
|
|
2817
2833
|
const createAnnotations = this.parseCreateAnnotations(text);
|
|
2818
2834
|
const createdArtifactData = /* @__PURE__ */ new Map();
|
|
2819
2835
|
const failedAnnotations = [];
|
|
2820
2836
|
for (const annotation of createAnnotations) {
|
|
2821
2837
|
try {
|
|
2822
|
-
const artifactData = await this.extractFromCreateAnnotation(annotation,
|
|
2838
|
+
const artifactData = await this.extractFromCreateAnnotation(annotation, subAgentId);
|
|
2823
2839
|
if (artifactData && annotation.raw) {
|
|
2824
2840
|
createdArtifactData.set(annotation.raw, artifactData);
|
|
2825
2841
|
} else if (annotation.raw) {
|
|
@@ -2827,7 +2843,7 @@ var _ArtifactParser = class _ArtifactParser {
|
|
|
2827
2843
|
`Failed to create artifact "${annotation.artifactId}": Missing or invalid data`
|
|
2828
2844
|
);
|
|
2829
2845
|
processedText = processedText.replace(annotation.raw, "");
|
|
2830
|
-
|
|
2846
|
+
logger8.warn(
|
|
2831
2847
|
{ annotation, artifactData },
|
|
2832
2848
|
"Removed failed artifact:create annotation from output"
|
|
2833
2849
|
);
|
|
@@ -2838,11 +2854,11 @@ var _ArtifactParser = class _ArtifactParser {
|
|
|
2838
2854
|
if (annotation.raw) {
|
|
2839
2855
|
processedText = processedText.replace(annotation.raw, "");
|
|
2840
2856
|
}
|
|
2841
|
-
|
|
2857
|
+
logger8.error({ annotation, error }, "Failed to extract artifact from create annotation");
|
|
2842
2858
|
}
|
|
2843
2859
|
}
|
|
2844
2860
|
if (failedAnnotations.length > 0) {
|
|
2845
|
-
|
|
2861
|
+
logger8.warn(
|
|
2846
2862
|
{
|
|
2847
2863
|
failedCount: failedAnnotations.length,
|
|
2848
2864
|
failures: failedAnnotations
|
|
@@ -2906,7 +2922,7 @@ var _ArtifactParser = class _ArtifactParser {
|
|
|
2906
2922
|
/**
|
|
2907
2923
|
* Process object/dataComponents for artifact components
|
|
2908
2924
|
*/
|
|
2909
|
-
async parseObject(obj, artifactMap,
|
|
2925
|
+
async parseObject(obj, artifactMap, subAgentId) {
|
|
2910
2926
|
if (obj?.dataComponents && Array.isArray(obj.dataComponents)) {
|
|
2911
2927
|
const parts = [];
|
|
2912
2928
|
for (const component of obj.dataComponents) {
|
|
@@ -2930,7 +2946,7 @@ var _ArtifactParser = class _ArtifactParser {
|
|
|
2930
2946
|
});
|
|
2931
2947
|
}
|
|
2932
2948
|
} else if (this.isArtifactCreateComponent(component)) {
|
|
2933
|
-
const createData = await this.extractFromArtifactCreateComponent(component,
|
|
2949
|
+
const createData = await this.extractFromArtifactCreateComponent(component, subAgentId);
|
|
2934
2950
|
if (createData) {
|
|
2935
2951
|
parts.push({
|
|
2936
2952
|
kind: "data",
|
|
@@ -2971,7 +2987,7 @@ var _ArtifactParser = class _ArtifactParser {
|
|
|
2971
2987
|
] : [];
|
|
2972
2988
|
}
|
|
2973
2989
|
if (this.isArtifactCreateComponent(obj)) {
|
|
2974
|
-
const createData = await this.extractFromArtifactCreateComponent(obj,
|
|
2990
|
+
const createData = await this.extractFromArtifactCreateComponent(obj, subAgentId);
|
|
2975
2991
|
return createData ? [
|
|
2976
2992
|
{
|
|
2977
2993
|
kind: "data",
|
|
@@ -3003,7 +3019,7 @@ var _ArtifactParser = class _ArtifactParser {
|
|
|
3003
3019
|
/**
|
|
3004
3020
|
* Extract artifact from ArtifactCreate component
|
|
3005
3021
|
*/
|
|
3006
|
-
async extractFromArtifactCreateComponent(component,
|
|
3022
|
+
async extractFromArtifactCreateComponent(component, subAgentId) {
|
|
3007
3023
|
const props = component.props;
|
|
3008
3024
|
if (!props) {
|
|
3009
3025
|
return null;
|
|
@@ -3015,7 +3031,7 @@ var _ArtifactParser = class _ArtifactParser {
|
|
|
3015
3031
|
baseSelector: props.base_selector,
|
|
3016
3032
|
detailsSelector: props.details_selector || {}
|
|
3017
3033
|
};
|
|
3018
|
-
return await this.extractFromCreateAnnotation(annotation,
|
|
3034
|
+
return await this.extractFromCreateAnnotation(annotation, subAgentId);
|
|
3019
3035
|
}
|
|
3020
3036
|
/**
|
|
3021
3037
|
* Get artifact data - delegates to service
|
|
@@ -3055,7 +3071,7 @@ __publicField(_ArtifactParser, "INCOMPLETE_CREATE_REGEX", /<artifact:create(?![^
|
|
|
3055
3071
|
var ArtifactParser = _ArtifactParser;
|
|
3056
3072
|
|
|
3057
3073
|
// src/services/GraphSession.ts
|
|
3058
|
-
var
|
|
3074
|
+
var logger9 = agentsCore.getLogger("GraphSession");
|
|
3059
3075
|
var GraphSession = class {
|
|
3060
3076
|
// Whether to send data operations
|
|
3061
3077
|
constructor(sessionId, messageId, graphId, tenantId, projectId, contextId) {
|
|
@@ -3088,7 +3104,7 @@ var GraphSession = class {
|
|
|
3088
3104
|
__publicField(this, "artifactParser");
|
|
3089
3105
|
// Session-scoped ArtifactParser instance
|
|
3090
3106
|
__publicField(this, "isEmitOperations", false);
|
|
3091
|
-
|
|
3107
|
+
logger9.debug({ sessionId, messageId, graphId }, "GraphSession created");
|
|
3092
3108
|
if (tenantId && projectId) {
|
|
3093
3109
|
toolSessionManager.createSessionWithId(
|
|
3094
3110
|
sessionId,
|
|
@@ -3102,7 +3118,6 @@ var GraphSession = class {
|
|
|
3102
3118
|
tenantId,
|
|
3103
3119
|
projectId,
|
|
3104
3120
|
sessionId,
|
|
3105
|
-
// Same ID as ToolSession
|
|
3106
3121
|
contextId,
|
|
3107
3122
|
taskId: `task_${contextId}-${messageId}`,
|
|
3108
3123
|
streamRequestId: sessionId
|
|
@@ -3123,7 +3138,7 @@ var GraphSession = class {
|
|
|
3123
3138
|
*/
|
|
3124
3139
|
enableEmitOperations() {
|
|
3125
3140
|
this.isEmitOperations = true;
|
|
3126
|
-
|
|
3141
|
+
logger9.info(
|
|
3127
3142
|
{ sessionId: this.sessionId },
|
|
3128
3143
|
"\u{1F50D} DEBUG: Emit operations enabled for GraphSession"
|
|
3129
3144
|
);
|
|
@@ -3140,14 +3155,14 @@ var GraphSession = class {
|
|
|
3140
3155
|
label: this.generateEventLabel(event),
|
|
3141
3156
|
details: {
|
|
3142
3157
|
timestamp: event.timestamp,
|
|
3143
|
-
|
|
3158
|
+
subAgentId: event.subAgentId,
|
|
3144
3159
|
data: event.data
|
|
3145
3160
|
}
|
|
3146
3161
|
};
|
|
3147
3162
|
await streamHelper.writeOperation(formattedOperation);
|
|
3148
3163
|
}
|
|
3149
3164
|
} catch (error) {
|
|
3150
|
-
|
|
3165
|
+
logger9.error(
|
|
3151
3166
|
{
|
|
3152
3167
|
sessionId: this.sessionId,
|
|
3153
3168
|
eventType: event.eventType,
|
|
@@ -3163,29 +3178,19 @@ var GraphSession = class {
|
|
|
3163
3178
|
generateEventLabel(event) {
|
|
3164
3179
|
switch (event.eventType) {
|
|
3165
3180
|
case "agent_generate":
|
|
3166
|
-
return `Agent ${event.
|
|
3181
|
+
return `Agent ${event.subAgentId} generating response`;
|
|
3167
3182
|
case "agent_reasoning":
|
|
3168
|
-
return `Agent ${event.
|
|
3169
|
-
case "tool_execution":
|
|
3170
|
-
|
|
3171
|
-
|
|
3172
|
-
|
|
3173
|
-
case "
|
|
3174
|
-
|
|
3175
|
-
|
|
3176
|
-
|
|
3177
|
-
case "
|
|
3178
|
-
|
|
3179
|
-
return `Task delegated: ${delegationData.fromAgent} \u2192 ${delegationData.targetAgent}`;
|
|
3180
|
-
}
|
|
3181
|
-
case "delegation_returned": {
|
|
3182
|
-
const returnData = event.data;
|
|
3183
|
-
return `Task completed: ${returnData.targetAgent} \u2192 ${returnData.fromAgent}`;
|
|
3184
|
-
}
|
|
3185
|
-
case "artifact_saved": {
|
|
3186
|
-
const artifactData = event.data;
|
|
3187
|
-
return `Artifact saved: ${artifactData.artifactType || "unknown type"}`;
|
|
3188
|
-
}
|
|
3183
|
+
return `Agent ${event.subAgentId} reasoning through request`;
|
|
3184
|
+
case "tool_execution":
|
|
3185
|
+
return `Tool execution: ${event.data.toolName || "unknown"}`;
|
|
3186
|
+
case "transfer":
|
|
3187
|
+
return `Agent transfer: ${event.data.fromSubAgent} \u2192 ${event.data.targetSubAgent}`;
|
|
3188
|
+
case "delegation_sent":
|
|
3189
|
+
return `Task delegated: ${event.data.fromSubAgent} \u2192 ${event.data.targetSubAgent}`;
|
|
3190
|
+
case "delegation_returned":
|
|
3191
|
+
return `Task completed: ${event.data.targetSubAgent} \u2192 ${event.data.fromSubAgent}`;
|
|
3192
|
+
case "artifact_saved":
|
|
3193
|
+
return `Artifact saved: ${event.data.artifactType || "unknown type"}`;
|
|
3189
3194
|
default:
|
|
3190
3195
|
return `${event.eventType} event`;
|
|
3191
3196
|
}
|
|
@@ -3210,7 +3215,7 @@ var GraphSession = class {
|
|
|
3210
3215
|
if (this.statusUpdateState.config.timeInSeconds) {
|
|
3211
3216
|
this.statusUpdateTimer = setInterval(async () => {
|
|
3212
3217
|
if (!this.statusUpdateState || this.isEnded) {
|
|
3213
|
-
|
|
3218
|
+
logger9.debug(
|
|
3214
3219
|
{ sessionId: this.sessionId },
|
|
3215
3220
|
"Timer triggered but session already cleaned up or ended"
|
|
3216
3221
|
);
|
|
@@ -3222,7 +3227,7 @@ var GraphSession = class {
|
|
|
3222
3227
|
}
|
|
3223
3228
|
await this.checkAndSendTimeBasedUpdate();
|
|
3224
3229
|
}, this.statusUpdateState.config.timeInSeconds * 1e3);
|
|
3225
|
-
|
|
3230
|
+
logger9.info(
|
|
3226
3231
|
{
|
|
3227
3232
|
sessionId: this.sessionId,
|
|
3228
3233
|
intervalMs: this.statusUpdateState.config.timeInSeconds * 1e3
|
|
@@ -3233,22 +3238,24 @@ var GraphSession = class {
|
|
|
3233
3238
|
}
|
|
3234
3239
|
/**
|
|
3235
3240
|
* Record an event in the session and trigger status updates if configured
|
|
3241
|
+
* Generic type parameter T ensures eventType and data are correctly paired
|
|
3236
3242
|
*/
|
|
3237
|
-
recordEvent(eventType,
|
|
3243
|
+
recordEvent(eventType, subAgentId, data) {
|
|
3238
3244
|
if (this.isEmitOperations) {
|
|
3239
|
-
|
|
3245
|
+
const dataOpEvent = {
|
|
3240
3246
|
timestamp: Date.now(),
|
|
3241
3247
|
eventType,
|
|
3242
|
-
|
|
3248
|
+
subAgentId,
|
|
3243
3249
|
data
|
|
3244
|
-
}
|
|
3250
|
+
};
|
|
3251
|
+
this.sendDataOperation(dataOpEvent);
|
|
3245
3252
|
}
|
|
3246
3253
|
if (this.isEnded) {
|
|
3247
|
-
|
|
3254
|
+
logger9.debug(
|
|
3248
3255
|
{
|
|
3249
3256
|
sessionId: this.sessionId,
|
|
3250
3257
|
eventType,
|
|
3251
|
-
|
|
3258
|
+
subAgentId
|
|
3252
3259
|
},
|
|
3253
3260
|
"Event received after session ended - ignoring"
|
|
3254
3261
|
);
|
|
@@ -3257,59 +3264,62 @@ var GraphSession = class {
|
|
|
3257
3264
|
const event = {
|
|
3258
3265
|
timestamp: Date.now(),
|
|
3259
3266
|
eventType,
|
|
3260
|
-
|
|
3267
|
+
subAgentId,
|
|
3261
3268
|
data
|
|
3262
3269
|
};
|
|
3263
3270
|
this.events.push(event);
|
|
3264
|
-
if (eventType === "artifact_saved"
|
|
3265
|
-
const
|
|
3266
|
-
if (
|
|
3267
|
-
|
|
3268
|
-
|
|
3269
|
-
|
|
3270
|
-
|
|
3271
|
-
|
|
3272
|
-
|
|
3273
|
-
|
|
3274
|
-
|
|
3275
|
-
|
|
3276
|
-
|
|
3277
|
-
|
|
3278
|
-
|
|
3279
|
-
|
|
3280
|
-
|
|
3281
|
-
|
|
3282
|
-
|
|
3283
|
-
this.
|
|
3284
|
-
}).catch((error) => {
|
|
3285
|
-
const errorCount = (this.artifactProcessingErrors.get(artifactId) || 0) + 1;
|
|
3286
|
-
this.artifactProcessingErrors.set(artifactId, errorCount);
|
|
3287
|
-
if (errorCount >= this.MAX_ARTIFACT_RETRIES) {
|
|
3271
|
+
if (eventType === "artifact_saved") {
|
|
3272
|
+
const artifactData = data;
|
|
3273
|
+
if (artifactData.pendingGeneration) {
|
|
3274
|
+
const artifactId = artifactData.artifactId;
|
|
3275
|
+
if (this.pendingArtifacts.size >= this.MAX_PENDING_ARTIFACTS) {
|
|
3276
|
+
logger9.warn(
|
|
3277
|
+
{
|
|
3278
|
+
sessionId: this.sessionId,
|
|
3279
|
+
artifactId,
|
|
3280
|
+
pendingCount: this.pendingArtifacts.size,
|
|
3281
|
+
maxAllowed: this.MAX_PENDING_ARTIFACTS
|
|
3282
|
+
},
|
|
3283
|
+
"Too many pending artifacts, skipping processing"
|
|
3284
|
+
);
|
|
3285
|
+
return;
|
|
3286
|
+
}
|
|
3287
|
+
this.pendingArtifacts.add(artifactId);
|
|
3288
|
+
setImmediate(() => {
|
|
3289
|
+
const artifactDataWithAgent = { ...artifactData, subAgentId };
|
|
3290
|
+
this.processArtifact(artifactDataWithAgent).then(() => {
|
|
3288
3291
|
this.pendingArtifacts.delete(artifactId);
|
|
3289
|
-
|
|
3290
|
-
|
|
3291
|
-
|
|
3292
|
-
|
|
3293
|
-
|
|
3294
|
-
|
|
3295
|
-
|
|
3296
|
-
|
|
3297
|
-
|
|
3298
|
-
|
|
3299
|
-
|
|
3300
|
-
|
|
3301
|
-
|
|
3302
|
-
|
|
3303
|
-
|
|
3304
|
-
|
|
3305
|
-
|
|
3306
|
-
|
|
3307
|
-
|
|
3308
|
-
|
|
3309
|
-
|
|
3310
|
-
|
|
3292
|
+
this.artifactProcessingErrors.delete(artifactId);
|
|
3293
|
+
}).catch((error) => {
|
|
3294
|
+
const errorCount = (this.artifactProcessingErrors.get(artifactId) || 0) + 1;
|
|
3295
|
+
this.artifactProcessingErrors.set(artifactId, errorCount);
|
|
3296
|
+
if (errorCount >= this.MAX_ARTIFACT_RETRIES) {
|
|
3297
|
+
this.pendingArtifacts.delete(artifactId);
|
|
3298
|
+
logger9.error(
|
|
3299
|
+
{
|
|
3300
|
+
sessionId: this.sessionId,
|
|
3301
|
+
artifactId,
|
|
3302
|
+
errorCount,
|
|
3303
|
+
maxRetries: this.MAX_ARTIFACT_RETRIES,
|
|
3304
|
+
error: error instanceof Error ? error.message : "Unknown error",
|
|
3305
|
+
stack: error instanceof Error ? error.stack : void 0
|
|
3306
|
+
},
|
|
3307
|
+
"Artifact processing failed after max retries, giving up"
|
|
3308
|
+
);
|
|
3309
|
+
} else {
|
|
3310
|
+
logger9.warn(
|
|
3311
|
+
{
|
|
3312
|
+
sessionId: this.sessionId,
|
|
3313
|
+
artifactId,
|
|
3314
|
+
errorCount,
|
|
3315
|
+
error: error instanceof Error ? error.message : "Unknown error"
|
|
3316
|
+
},
|
|
3317
|
+
"Artifact processing failed, may retry"
|
|
3318
|
+
);
|
|
3319
|
+
}
|
|
3320
|
+
});
|
|
3311
3321
|
});
|
|
3312
|
-
}
|
|
3322
|
+
}
|
|
3313
3323
|
}
|
|
3314
3324
|
if (!this.isEnded) {
|
|
3315
3325
|
this.checkStatusUpdates();
|
|
@@ -3320,14 +3330,14 @@ var GraphSession = class {
|
|
|
3320
3330
|
*/
|
|
3321
3331
|
checkStatusUpdates() {
|
|
3322
3332
|
if (this.isEnded) {
|
|
3323
|
-
|
|
3333
|
+
logger9.debug(
|
|
3324
3334
|
{ sessionId: this.sessionId },
|
|
3325
3335
|
"Session has ended - skipping status update check"
|
|
3326
3336
|
);
|
|
3327
3337
|
return;
|
|
3328
3338
|
}
|
|
3329
3339
|
if (!this.statusUpdateState) {
|
|
3330
|
-
|
|
3340
|
+
logger9.debug({ sessionId: this.sessionId }, "No status update state - skipping check");
|
|
3331
3341
|
return;
|
|
3332
3342
|
}
|
|
3333
3343
|
const statusUpdateState = this.statusUpdateState;
|
|
@@ -3338,11 +3348,11 @@ var GraphSession = class {
|
|
|
3338
3348
|
*/
|
|
3339
3349
|
async checkAndSendTimeBasedUpdate() {
|
|
3340
3350
|
if (this.isEnded) {
|
|
3341
|
-
|
|
3351
|
+
logger9.debug({ sessionId: this.sessionId }, "Session has ended - skipping time-based update");
|
|
3342
3352
|
return;
|
|
3343
3353
|
}
|
|
3344
3354
|
if (!this.statusUpdateState) {
|
|
3345
|
-
|
|
3355
|
+
logger9.debug(
|
|
3346
3356
|
{ sessionId: this.sessionId },
|
|
3347
3357
|
"No status updates configured for time-based check"
|
|
3348
3358
|
);
|
|
@@ -3355,7 +3365,7 @@ var GraphSession = class {
|
|
|
3355
3365
|
try {
|
|
3356
3366
|
await this.generateAndSendUpdate();
|
|
3357
3367
|
} catch (error) {
|
|
3358
|
-
|
|
3368
|
+
logger9.error(
|
|
3359
3369
|
{
|
|
3360
3370
|
sessionId: this.sessionId,
|
|
3361
3371
|
error: error instanceof Error ? error.message : "Unknown error"
|
|
@@ -3379,8 +3389,8 @@ var GraphSession = class {
|
|
|
3379
3389
|
/**
|
|
3380
3390
|
* Get events filtered by agent
|
|
3381
3391
|
*/
|
|
3382
|
-
getEventsByAgent(
|
|
3383
|
-
return this.events.filter((event) => event.
|
|
3392
|
+
getEventsByAgent(subAgentId) {
|
|
3393
|
+
return this.events.filter((event) => event.subAgentId === subAgentId);
|
|
3384
3394
|
}
|
|
3385
3395
|
/**
|
|
3386
3396
|
* Get summary of session activity
|
|
@@ -3395,7 +3405,7 @@ var GraphSession = class {
|
|
|
3395
3405
|
);
|
|
3396
3406
|
const agentCounts = this.events.reduce(
|
|
3397
3407
|
(counts, event) => {
|
|
3398
|
-
counts[event.
|
|
3408
|
+
counts[event.subAgentId] = (counts[event.subAgentId] || 0) + 1;
|
|
3399
3409
|
return counts;
|
|
3400
3410
|
},
|
|
3401
3411
|
{}
|
|
@@ -3458,29 +3468,29 @@ var GraphSession = class {
|
|
|
3458
3468
|
*/
|
|
3459
3469
|
async generateAndSendUpdate() {
|
|
3460
3470
|
if (this.isEnded) {
|
|
3461
|
-
|
|
3471
|
+
logger9.debug({ sessionId: this.sessionId }, "Session has ended - not generating update");
|
|
3462
3472
|
return;
|
|
3463
3473
|
}
|
|
3464
3474
|
if (this.isTextStreaming) {
|
|
3465
|
-
|
|
3475
|
+
logger9.debug(
|
|
3466
3476
|
{ sessionId: this.sessionId },
|
|
3467
3477
|
"Text is currently streaming - skipping status update"
|
|
3468
3478
|
);
|
|
3469
3479
|
return;
|
|
3470
3480
|
}
|
|
3471
3481
|
if (this.isGeneratingUpdate) {
|
|
3472
|
-
|
|
3482
|
+
logger9.debug(
|
|
3473
3483
|
{ sessionId: this.sessionId },
|
|
3474
3484
|
"Update already in progress - skipping duplicate generation"
|
|
3475
3485
|
);
|
|
3476
3486
|
return;
|
|
3477
3487
|
}
|
|
3478
3488
|
if (!this.statusUpdateState) {
|
|
3479
|
-
|
|
3489
|
+
logger9.warn({ sessionId: this.sessionId }, "No status update state - cannot generate update");
|
|
3480
3490
|
return;
|
|
3481
3491
|
}
|
|
3482
3492
|
if (!this.graphId) {
|
|
3483
|
-
|
|
3493
|
+
logger9.warn({ sessionId: this.sessionId }, "No graph ID - cannot generate update");
|
|
3484
3494
|
return;
|
|
3485
3495
|
}
|
|
3486
3496
|
const newEventCount = this.events.length - this.statusUpdateState.lastEventCount;
|
|
@@ -3492,7 +3502,7 @@ var GraphSession = class {
|
|
|
3492
3502
|
try {
|
|
3493
3503
|
const streamHelper = getStreamHelper(this.sessionId);
|
|
3494
3504
|
if (!streamHelper) {
|
|
3495
|
-
|
|
3505
|
+
logger9.warn(
|
|
3496
3506
|
{ sessionId: this.sessionId },
|
|
3497
3507
|
"No stream helper found - cannot send status update"
|
|
3498
3508
|
);
|
|
@@ -3512,7 +3522,7 @@ var GraphSession = class {
|
|
|
3512
3522
|
if (result.summaries && result.summaries.length > 0) {
|
|
3513
3523
|
for (const summary of result.summaries) {
|
|
3514
3524
|
if (!summary || !summary.type || !summary.data || !summary.data.label || Object.keys(summary.data).length === 0) {
|
|
3515
|
-
|
|
3525
|
+
logger9.warn(
|
|
3516
3526
|
{
|
|
3517
3527
|
sessionId: this.sessionId,
|
|
3518
3528
|
summary
|
|
@@ -3549,7 +3559,7 @@ var GraphSession = class {
|
|
|
3549
3559
|
this.statusUpdateState.lastEventCount = this.events.length;
|
|
3550
3560
|
}
|
|
3551
3561
|
} catch (error) {
|
|
3552
|
-
|
|
3562
|
+
logger9.error(
|
|
3553
3563
|
{
|
|
3554
3564
|
sessionId: this.sessionId,
|
|
3555
3565
|
error: error instanceof Error ? error.message : "Unknown error",
|
|
@@ -3587,7 +3597,7 @@ var GraphSession = class {
|
|
|
3587
3597
|
this.releaseUpdateLock();
|
|
3588
3598
|
}
|
|
3589
3599
|
} catch (error) {
|
|
3590
|
-
|
|
3600
|
+
logger9.error(
|
|
3591
3601
|
{
|
|
3592
3602
|
sessionId: this.sessionId,
|
|
3593
3603
|
error: error instanceof Error ? error.message : "Unknown error"
|
|
@@ -3665,7 +3675,7 @@ User's Question/Context:
|
|
|
3665
3675
|
${conversationHistory}
|
|
3666
3676
|
` : "";
|
|
3667
3677
|
} catch (error) {
|
|
3668
|
-
|
|
3678
|
+
logger9.warn(
|
|
3669
3679
|
{ sessionId: this.sessionId, error },
|
|
3670
3680
|
"Failed to fetch conversation history for structured status update"
|
|
3671
3681
|
);
|
|
@@ -3799,7 +3809,7 @@ ${this.statusUpdateState?.config.prompt?.trim() || ""}`;
|
|
|
3799
3809
|
return { summaries };
|
|
3800
3810
|
} catch (error) {
|
|
3801
3811
|
agentsCore.setSpanWithError(span, error instanceof Error ? error : new Error(String(error)));
|
|
3802
|
-
|
|
3812
|
+
logger9.error({ error }, "Failed to generate structured update, using fallback");
|
|
3803
3813
|
return { summaries: [] };
|
|
3804
3814
|
} finally {
|
|
3805
3815
|
span.end();
|
|
@@ -3825,7 +3835,7 @@ ${this.statusUpdateState?.config.prompt?.trim() || ""}`;
|
|
|
3825
3835
|
*/
|
|
3826
3836
|
buildZodSchemaFromJson(jsonSchema) {
|
|
3827
3837
|
const properties = {};
|
|
3828
|
-
properties
|
|
3838
|
+
properties.label = z6.z.string().describe(
|
|
3829
3839
|
'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.'
|
|
3830
3840
|
);
|
|
3831
3841
|
for (const [key, value] of Object.entries(jsonSchema.properties)) {
|
|
@@ -3894,11 +3904,10 @@ ${this.statusUpdateState?.config.prompt?.trim() || ""}`;
|
|
|
3894
3904
|
for (const event of events) {
|
|
3895
3905
|
switch (event.eventType) {
|
|
3896
3906
|
case "tool_execution": {
|
|
3897
|
-
const
|
|
3898
|
-
const resultStr = JSON.stringify(data.result);
|
|
3907
|
+
const resultStr = JSON.stringify(event.data.result);
|
|
3899
3908
|
activities.push(
|
|
3900
|
-
`\u{1F527} **${data.toolName}** ${data.duration ? `(${data.duration}ms)` : ""}
|
|
3901
|
-
\u{1F4E5} Input: ${JSON.stringify(data.args)}
|
|
3909
|
+
`\u{1F527} **${event.data.toolName}** ${event.data.duration ? `(${event.data.duration}ms)` : ""}
|
|
3910
|
+
\u{1F4E5} Input: ${JSON.stringify(event.data.args)}
|
|
3902
3911
|
\u{1F4E4} Output: ${resultStr}`
|
|
3903
3912
|
);
|
|
3904
3913
|
break;
|
|
@@ -3910,23 +3919,24 @@ ${this.statusUpdateState?.config.prompt?.trim() || ""}`;
|
|
|
3910
3919
|
case "artifact_saved":
|
|
3911
3920
|
break;
|
|
3912
3921
|
case "agent_reasoning": {
|
|
3913
|
-
const data = event.data;
|
|
3914
3922
|
activities.push(
|
|
3915
3923
|
`\u2699\uFE0F **Analyzing request**
|
|
3916
|
-
Details: ${JSON.stringify(data.parts, null, 2)}`
|
|
3924
|
+
Details: ${JSON.stringify(event.data.parts, null, 2)}`
|
|
3917
3925
|
);
|
|
3918
3926
|
break;
|
|
3919
3927
|
}
|
|
3920
3928
|
case "agent_generate": {
|
|
3921
|
-
const data = event.data;
|
|
3922
3929
|
activities.push(
|
|
3923
3930
|
`\u2699\uFE0F **Preparing response**
|
|
3924
|
-
Details: ${JSON.stringify(data.parts, null, 2)}`
|
|
3931
|
+
Details: ${JSON.stringify(event.data.parts, null, 2)}`
|
|
3925
3932
|
);
|
|
3926
3933
|
break;
|
|
3927
3934
|
}
|
|
3928
3935
|
default: {
|
|
3929
|
-
|
|
3936
|
+
const safeEvent = event;
|
|
3937
|
+
activities.push(
|
|
3938
|
+
`\u{1F4CB} **${safeEvent.eventType}**: ${JSON.stringify(safeEvent.data, null, 2)}`
|
|
3939
|
+
);
|
|
3930
3940
|
break;
|
|
3931
3941
|
}
|
|
3932
3942
|
}
|
|
@@ -3944,7 +3954,7 @@ ${this.statusUpdateState?.config.prompt?.trim() || ""}`;
|
|
|
3944
3954
|
"graph_session.id": this.sessionId,
|
|
3945
3955
|
"artifact.id": artifactData.artifactId,
|
|
3946
3956
|
"artifact.type": artifactData.artifactType || "unknown",
|
|
3947
|
-
"artifact.agent_id": artifactData.
|
|
3957
|
+
"artifact.agent_id": artifactData.subAgentId || "unknown",
|
|
3948
3958
|
"artifact.tool_call_id": artifactData.metadata?.toolCallId || "unknown",
|
|
3949
3959
|
"artifact.data": JSON.stringify(artifactData.data, null, 2),
|
|
3950
3960
|
"tenant.id": artifactData.tenantId || "unknown",
|
|
@@ -4003,34 +4013,34 @@ Make it specific and relevant.`;
|
|
|
4003
4013
|
let modelToUse = this.statusUpdateState?.summarizerModel;
|
|
4004
4014
|
if (!modelToUse?.model?.trim()) {
|
|
4005
4015
|
if (!this.statusUpdateState?.baseModel?.model?.trim()) {
|
|
4006
|
-
if (artifactData.
|
|
4016
|
+
if (artifactData.subAgentId && artifactData.tenantId && artifactData.projectId) {
|
|
4007
4017
|
try {
|
|
4008
|
-
const agentData = await agentsCore.
|
|
4018
|
+
const agentData = await agentsCore.getSubAgentById(dbClient_default)({
|
|
4009
4019
|
scopes: {
|
|
4010
4020
|
tenantId: artifactData.tenantId,
|
|
4011
4021
|
projectId: artifactData.projectId,
|
|
4012
4022
|
graphId: this.graphId || ""
|
|
4013
4023
|
},
|
|
4014
|
-
|
|
4024
|
+
subAgentId: artifactData.subAgentId
|
|
4015
4025
|
});
|
|
4016
4026
|
if (agentData && "models" in agentData && agentData.models?.base?.model) {
|
|
4017
4027
|
modelToUse = agentData.models.base;
|
|
4018
|
-
|
|
4028
|
+
logger9.info(
|
|
4019
4029
|
{
|
|
4020
4030
|
sessionId: this.sessionId,
|
|
4021
4031
|
artifactId: artifactData.artifactId,
|
|
4022
|
-
|
|
4032
|
+
subAgentId: artifactData.subAgentId,
|
|
4023
4033
|
model: modelToUse.model
|
|
4024
4034
|
},
|
|
4025
4035
|
"Using agent model configuration for artifact name generation"
|
|
4026
4036
|
);
|
|
4027
4037
|
}
|
|
4028
4038
|
} catch (error) {
|
|
4029
|
-
|
|
4039
|
+
logger9.warn(
|
|
4030
4040
|
{
|
|
4031
4041
|
sessionId: this.sessionId,
|
|
4032
4042
|
artifactId: artifactData.artifactId,
|
|
4033
|
-
|
|
4043
|
+
subAgentId: artifactData.subAgentId,
|
|
4034
4044
|
error: error instanceof Error ? error.message : "Unknown error"
|
|
4035
4045
|
},
|
|
4036
4046
|
"Failed to get agent model configuration"
|
|
@@ -4038,7 +4048,7 @@ Make it specific and relevant.`;
|
|
|
4038
4048
|
}
|
|
4039
4049
|
}
|
|
4040
4050
|
if (!modelToUse?.model?.trim()) {
|
|
4041
|
-
|
|
4051
|
+
logger9.warn(
|
|
4042
4052
|
{
|
|
4043
4053
|
sessionId: this.sessionId,
|
|
4044
4054
|
artifactId: artifactData.artifactId
|
|
@@ -4120,7 +4130,7 @@ Make it specific and relevant.`;
|
|
|
4120
4130
|
return result2;
|
|
4121
4131
|
} catch (error) {
|
|
4122
4132
|
lastError = error instanceof Error ? error : new Error(String(error));
|
|
4123
|
-
|
|
4133
|
+
logger9.warn(
|
|
4124
4134
|
{
|
|
4125
4135
|
sessionId: this.sessionId,
|
|
4126
4136
|
artifactId: artifactData.artifactId,
|
|
@@ -4172,7 +4182,7 @@ Make it specific and relevant.`;
|
|
|
4172
4182
|
});
|
|
4173
4183
|
span.setStatus({ code: api.SpanStatusCode.OK });
|
|
4174
4184
|
} catch (saveError) {
|
|
4175
|
-
|
|
4185
|
+
logger9.error(
|
|
4176
4186
|
{
|
|
4177
4187
|
sessionId: this.sessionId,
|
|
4178
4188
|
artifactId: artifactData.artifactId,
|
|
@@ -4200,7 +4210,7 @@ Make it specific and relevant.`;
|
|
|
4200
4210
|
metadata: artifactData.metadata || {},
|
|
4201
4211
|
toolCallId: artifactData.toolCallId
|
|
4202
4212
|
});
|
|
4203
|
-
|
|
4213
|
+
logger9.info(
|
|
4204
4214
|
{
|
|
4205
4215
|
sessionId: this.sessionId,
|
|
4206
4216
|
artifactId: artifactData.artifactId
|
|
@@ -4211,7 +4221,7 @@ Make it specific and relevant.`;
|
|
|
4211
4221
|
} catch (fallbackError) {
|
|
4212
4222
|
const isDuplicateError = fallbackError instanceof Error && (fallbackError.message?.includes("UNIQUE") || fallbackError.message?.includes("duplicate"));
|
|
4213
4223
|
if (isDuplicateError) ; else {
|
|
4214
|
-
|
|
4224
|
+
logger9.error(
|
|
4215
4225
|
{
|
|
4216
4226
|
sessionId: this.sessionId,
|
|
4217
4227
|
artifactId: artifactData.artifactId,
|
|
@@ -4224,7 +4234,7 @@ Make it specific and relevant.`;
|
|
|
4224
4234
|
}
|
|
4225
4235
|
} catch (error) {
|
|
4226
4236
|
agentsCore.setSpanWithError(span, error instanceof Error ? error : new Error(String(error)));
|
|
4227
|
-
|
|
4237
|
+
logger9.error(
|
|
4228
4238
|
{
|
|
4229
4239
|
sessionId: this.sessionId,
|
|
4230
4240
|
artifactId: artifactData.artifactId,
|
|
@@ -4243,7 +4253,7 @@ Make it specific and relevant.`;
|
|
|
4243
4253
|
*/
|
|
4244
4254
|
setArtifactCache(key, artifact) {
|
|
4245
4255
|
this.artifactCache.set(key, artifact);
|
|
4246
|
-
|
|
4256
|
+
logger9.debug({ sessionId: this.sessionId, key }, "Artifact cached in session");
|
|
4247
4257
|
}
|
|
4248
4258
|
/**
|
|
4249
4259
|
* Get session-scoped ArtifactService instance
|
|
@@ -4262,7 +4272,7 @@ Make it specific and relevant.`;
|
|
|
4262
4272
|
*/
|
|
4263
4273
|
getArtifactCache(key) {
|
|
4264
4274
|
const artifact = this.artifactCache.get(key);
|
|
4265
|
-
|
|
4275
|
+
logger9.debug({ sessionId: this.sessionId, key, found: !!artifact }, "Artifact cache lookup");
|
|
4266
4276
|
return artifact || null;
|
|
4267
4277
|
}
|
|
4268
4278
|
/**
|
|
@@ -4285,7 +4295,7 @@ var GraphSessionManager = class {
|
|
|
4285
4295
|
const sessionId = messageId;
|
|
4286
4296
|
const session = new GraphSession(sessionId, messageId, graphId, tenantId, projectId, contextId);
|
|
4287
4297
|
this.sessions.set(sessionId, session);
|
|
4288
|
-
|
|
4298
|
+
logger9.info(
|
|
4289
4299
|
{ sessionId, messageId, graphId, tenantId, projectId, contextId },
|
|
4290
4300
|
"GraphSession created"
|
|
4291
4301
|
);
|
|
@@ -4299,7 +4309,7 @@ var GraphSessionManager = class {
|
|
|
4299
4309
|
if (session) {
|
|
4300
4310
|
session.initializeStatusUpdates(config, summarizerModel);
|
|
4301
4311
|
} else {
|
|
4302
|
-
|
|
4312
|
+
logger9.error(
|
|
4303
4313
|
{
|
|
4304
4314
|
sessionId,
|
|
4305
4315
|
availableSessions: Array.from(this.sessions.keys())
|
|
@@ -4316,7 +4326,7 @@ var GraphSessionManager = class {
|
|
|
4316
4326
|
if (session) {
|
|
4317
4327
|
session.enableEmitOperations();
|
|
4318
4328
|
} else {
|
|
4319
|
-
|
|
4329
|
+
logger9.error(
|
|
4320
4330
|
{
|
|
4321
4331
|
sessionId,
|
|
4322
4332
|
availableSessions: Array.from(this.sessions.keys())
|
|
@@ -4333,14 +4343,15 @@ var GraphSessionManager = class {
|
|
|
4333
4343
|
}
|
|
4334
4344
|
/**
|
|
4335
4345
|
* Record an event in a session
|
|
4346
|
+
* Generic type parameter T ensures eventType and data are correctly paired
|
|
4336
4347
|
*/
|
|
4337
|
-
recordEvent(sessionId, eventType,
|
|
4348
|
+
recordEvent(sessionId, eventType, subAgentId, data) {
|
|
4338
4349
|
const session = this.sessions.get(sessionId);
|
|
4339
4350
|
if (!session) {
|
|
4340
|
-
|
|
4351
|
+
logger9.warn({ sessionId }, "Attempted to record event in non-existent session");
|
|
4341
4352
|
return;
|
|
4342
4353
|
}
|
|
4343
|
-
session.recordEvent(eventType,
|
|
4354
|
+
session.recordEvent(eventType, subAgentId, data);
|
|
4344
4355
|
}
|
|
4345
4356
|
/**
|
|
4346
4357
|
* End a session and return the final event data
|
|
@@ -4348,12 +4359,12 @@ var GraphSessionManager = class {
|
|
|
4348
4359
|
endSession(sessionId) {
|
|
4349
4360
|
const session = this.sessions.get(sessionId);
|
|
4350
4361
|
if (!session) {
|
|
4351
|
-
|
|
4362
|
+
logger9.warn({ sessionId }, "Attempted to end non-existent session");
|
|
4352
4363
|
return [];
|
|
4353
4364
|
}
|
|
4354
4365
|
const events = session.getEvents();
|
|
4355
4366
|
const summary = session.getSummary();
|
|
4356
|
-
|
|
4367
|
+
logger9.info({ sessionId, summary }, "GraphSession ended");
|
|
4357
4368
|
session.cleanup();
|
|
4358
4369
|
this.sessions.delete(sessionId);
|
|
4359
4370
|
return events;
|
|
@@ -4461,7 +4472,7 @@ init_logger();
|
|
|
4461
4472
|
|
|
4462
4473
|
// src/services/IncrementalStreamParser.ts
|
|
4463
4474
|
init_logger();
|
|
4464
|
-
var
|
|
4475
|
+
var logger10 = agentsCore.getLogger("IncrementalStreamParser");
|
|
4465
4476
|
var _IncrementalStreamParser = class _IncrementalStreamParser {
|
|
4466
4477
|
// Max number of collected parts to prevent unbounded growth
|
|
4467
4478
|
constructor(streamHelper, tenantId, contextId, artifactParserOptions) {
|
|
@@ -4477,10 +4488,11 @@ var _IncrementalStreamParser = class _IncrementalStreamParser {
|
|
|
4477
4488
|
__publicField(this, "lastStreamedComponents", /* @__PURE__ */ new Map());
|
|
4478
4489
|
__publicField(this, "componentSnapshots", /* @__PURE__ */ new Map());
|
|
4479
4490
|
__publicField(this, "artifactMap");
|
|
4480
|
-
__publicField(this, "
|
|
4491
|
+
__publicField(this, "subAgentId");
|
|
4492
|
+
__publicField(this, "allStreamedContent", []);
|
|
4481
4493
|
this.streamHelper = streamHelper;
|
|
4482
4494
|
this.contextId = contextId;
|
|
4483
|
-
this.
|
|
4495
|
+
this.subAgentId = artifactParserOptions?.subAgentId;
|
|
4484
4496
|
if (artifactParserOptions?.streamRequestId) {
|
|
4485
4497
|
const sessionParser = graphSessionManager.getArtifactParser(
|
|
4486
4498
|
artifactParserOptions.streamRequestId
|
|
@@ -4513,7 +4525,7 @@ var _IncrementalStreamParser = class _IncrementalStreamParser {
|
|
|
4513
4525
|
async initializeArtifactMap() {
|
|
4514
4526
|
try {
|
|
4515
4527
|
this.artifactMap = await this.artifactParser.getContextArtifacts(this.contextId);
|
|
4516
|
-
|
|
4528
|
+
logger10.debug(
|
|
4517
4529
|
{
|
|
4518
4530
|
contextId: this.contextId,
|
|
4519
4531
|
artifactMapSize: this.artifactMap.size
|
|
@@ -4521,7 +4533,7 @@ var _IncrementalStreamParser = class _IncrementalStreamParser {
|
|
|
4521
4533
|
"Initialized artifact map for streaming"
|
|
4522
4534
|
);
|
|
4523
4535
|
} catch (error) {
|
|
4524
|
-
|
|
4536
|
+
logger10.warn({ error, contextId: this.contextId }, "Failed to initialize artifact map");
|
|
4525
4537
|
this.artifactMap = /* @__PURE__ */ new Map();
|
|
4526
4538
|
}
|
|
4527
4539
|
}
|
|
@@ -4596,10 +4608,12 @@ var _IncrementalStreamParser = class _IncrementalStreamParser {
|
|
|
4596
4608
|
this.hasStartedRole = true;
|
|
4597
4609
|
}
|
|
4598
4610
|
await this.streamHelper.streamText(newText, 50);
|
|
4599
|
-
|
|
4611
|
+
const textPart = {
|
|
4600
4612
|
kind: "text",
|
|
4601
4613
|
text: newText
|
|
4602
|
-
}
|
|
4614
|
+
};
|
|
4615
|
+
this.collectedParts.push(textPart);
|
|
4616
|
+
this.allStreamedContent.push(textPart);
|
|
4603
4617
|
}
|
|
4604
4618
|
continue;
|
|
4605
4619
|
}
|
|
@@ -4623,7 +4637,7 @@ var _IncrementalStreamParser = class _IncrementalStreamParser {
|
|
|
4623
4637
|
dataComponents: [component]
|
|
4624
4638
|
},
|
|
4625
4639
|
this.artifactMap,
|
|
4626
|
-
this.
|
|
4640
|
+
this.subAgentId
|
|
4627
4641
|
);
|
|
4628
4642
|
if (!Array.isArray(parts)) {
|
|
4629
4643
|
console.warn("parseObject returned non-array:", parts);
|
|
@@ -4699,7 +4713,7 @@ var _IncrementalStreamParser = class _IncrementalStreamParser {
|
|
|
4699
4713
|
dataComponents: [component]
|
|
4700
4714
|
},
|
|
4701
4715
|
this.artifactMap,
|
|
4702
|
-
this.
|
|
4716
|
+
this.subAgentId
|
|
4703
4717
|
);
|
|
4704
4718
|
for (const part of parts) {
|
|
4705
4719
|
await this.streamPart(part);
|
|
@@ -4725,10 +4739,12 @@ var _IncrementalStreamParser = class _IncrementalStreamParser {
|
|
|
4725
4739
|
if (this.pendingTextBuffer) {
|
|
4726
4740
|
const cleanedText = this.pendingTextBuffer.replace(/<\/?artifact:ref(?:\s[^>]*)?>\/?>/g, "").replace(/<\/?artifact(?:\s[^>]*)?>\/?>/g, "").replace(/<\/artifact:ref>/g, "").replace(/<\/(?:\w+:)?artifact>/g, "");
|
|
4727
4741
|
if (cleanedText) {
|
|
4728
|
-
|
|
4742
|
+
const textPart = {
|
|
4729
4743
|
kind: "text",
|
|
4730
4744
|
text: cleanedText
|
|
4731
|
-
}
|
|
4745
|
+
};
|
|
4746
|
+
this.collectedParts.push(textPart);
|
|
4747
|
+
this.allStreamedContent.push(textPart);
|
|
4732
4748
|
await this.streamHelper.streamText(cleanedText, 50);
|
|
4733
4749
|
}
|
|
4734
4750
|
this.pendingTextBuffer = "";
|
|
@@ -4743,6 +4759,12 @@ var _IncrementalStreamParser = class _IncrementalStreamParser {
|
|
|
4743
4759
|
getCollectedParts() {
|
|
4744
4760
|
return [...this.collectedParts];
|
|
4745
4761
|
}
|
|
4762
|
+
/**
|
|
4763
|
+
* Get all streamed content that was actually sent to the user
|
|
4764
|
+
*/
|
|
4765
|
+
getAllStreamedContent() {
|
|
4766
|
+
return [...this.allStreamedContent];
|
|
4767
|
+
}
|
|
4746
4768
|
/**
|
|
4747
4769
|
* Parse buffer for complete artifacts and text parts (for text streaming)
|
|
4748
4770
|
*/
|
|
@@ -4753,7 +4775,11 @@ var _IncrementalStreamParser = class _IncrementalStreamParser {
|
|
|
4753
4775
|
const safeEnd = this.artifactParser.findSafeTextBoundary(workingBuffer);
|
|
4754
4776
|
if (safeEnd > 0) {
|
|
4755
4777
|
const safeText = workingBuffer.slice(0, safeEnd);
|
|
4756
|
-
const parts2 = await this.artifactParser.parseText(
|
|
4778
|
+
const parts2 = await this.artifactParser.parseText(
|
|
4779
|
+
safeText,
|
|
4780
|
+
this.artifactMap,
|
|
4781
|
+
this.subAgentId
|
|
4782
|
+
);
|
|
4757
4783
|
completeParts.push(...parts2);
|
|
4758
4784
|
return {
|
|
4759
4785
|
completeParts,
|
|
@@ -4768,7 +4794,7 @@ var _IncrementalStreamParser = class _IncrementalStreamParser {
|
|
|
4768
4794
|
const parts = await this.artifactParser.parseText(
|
|
4769
4795
|
workingBuffer,
|
|
4770
4796
|
this.artifactMap,
|
|
4771
|
-
this.
|
|
4797
|
+
this.subAgentId
|
|
4772
4798
|
);
|
|
4773
4799
|
if (parts.length > 0 && parts[parts.length - 1].kind === "text") {
|
|
4774
4800
|
const lastPart = parts[parts.length - 1];
|
|
@@ -4798,10 +4824,15 @@ var _IncrementalStreamParser = class _IncrementalStreamParser {
|
|
|
4798
4824
|
*/
|
|
4799
4825
|
async streamPart(part) {
|
|
4800
4826
|
this.collectedParts.push({ ...part });
|
|
4827
|
+
this.allStreamedContent.push({ ...part });
|
|
4801
4828
|
if (this.collectedParts.length > _IncrementalStreamParser.MAX_COLLECTED_PARTS) {
|
|
4802
4829
|
const excess = this.collectedParts.length - _IncrementalStreamParser.MAX_COLLECTED_PARTS;
|
|
4803
4830
|
this.collectedParts.splice(0, excess);
|
|
4804
4831
|
}
|
|
4832
|
+
if (this.allStreamedContent.length > _IncrementalStreamParser.MAX_COLLECTED_PARTS) {
|
|
4833
|
+
const excess = this.allStreamedContent.length - _IncrementalStreamParser.MAX_COLLECTED_PARTS;
|
|
4834
|
+
this.allStreamedContent.splice(0, excess);
|
|
4835
|
+
}
|
|
4805
4836
|
if (!this.hasStartedRole) {
|
|
4806
4837
|
await this.streamHelper.writeRole("assistant");
|
|
4807
4838
|
this.hasStartedRole = true;
|
|
@@ -4842,12 +4873,12 @@ var IncrementalStreamParser = _IncrementalStreamParser;
|
|
|
4842
4873
|
|
|
4843
4874
|
// src/services/ResponseFormatter.ts
|
|
4844
4875
|
init_logger();
|
|
4845
|
-
var
|
|
4876
|
+
var logger11 = agentsCore.getLogger("ResponseFormatter");
|
|
4846
4877
|
var ResponseFormatter = class {
|
|
4847
4878
|
constructor(tenantId, artifactParserOptions) {
|
|
4848
4879
|
__publicField(this, "artifactParser");
|
|
4849
|
-
__publicField(this, "
|
|
4850
|
-
this.
|
|
4880
|
+
__publicField(this, "subAgentId");
|
|
4881
|
+
this.subAgentId = artifactParserOptions?.subAgentId;
|
|
4851
4882
|
if (artifactParserOptions?.streamRequestId) {
|
|
4852
4883
|
const sessionParser = graphSessionManager.getArtifactParser(
|
|
4853
4884
|
artifactParserOptions.streamRequestId
|
|
@@ -4886,7 +4917,7 @@ var ResponseFormatter = class {
|
|
|
4886
4917
|
const parts = await this.artifactParser.parseObject(
|
|
4887
4918
|
responseObject,
|
|
4888
4919
|
artifactMap,
|
|
4889
|
-
this.
|
|
4920
|
+
this.subAgentId
|
|
4890
4921
|
);
|
|
4891
4922
|
const uniqueArtifacts = this.countUniqueArtifacts(parts);
|
|
4892
4923
|
span.setAttributes({
|
|
@@ -4901,7 +4932,7 @@ var ResponseFormatter = class {
|
|
|
4901
4932
|
return { parts };
|
|
4902
4933
|
} catch (error) {
|
|
4903
4934
|
agentsCore.setSpanWithError(span, error instanceof Error ? error : new Error(String(error)));
|
|
4904
|
-
|
|
4935
|
+
logger11.error({ error, responseObject }, "Error formatting object response");
|
|
4905
4936
|
return {
|
|
4906
4937
|
parts: [{ kind: "data", data: responseObject }]
|
|
4907
4938
|
};
|
|
@@ -4933,7 +4964,11 @@ var ResponseFormatter = class {
|
|
|
4933
4964
|
"response.type": "text",
|
|
4934
4965
|
"response.availableArtifacts": artifactMap.size
|
|
4935
4966
|
});
|
|
4936
|
-
const parts = await this.artifactParser.parseText(
|
|
4967
|
+
const parts = await this.artifactParser.parseText(
|
|
4968
|
+
responseText,
|
|
4969
|
+
artifactMap,
|
|
4970
|
+
this.subAgentId
|
|
4971
|
+
);
|
|
4937
4972
|
if (parts.length === 1 && parts[0].kind === "text") {
|
|
4938
4973
|
return { text: parts[0].text };
|
|
4939
4974
|
}
|
|
@@ -4953,7 +4988,7 @@ var ResponseFormatter = class {
|
|
|
4953
4988
|
return { parts };
|
|
4954
4989
|
} catch (error) {
|
|
4955
4990
|
agentsCore.setSpanWithError(span, error instanceof Error ? error : new Error(String(error)));
|
|
4956
|
-
|
|
4991
|
+
logger11.error({ error, responseText }, "Error formatting response");
|
|
4957
4992
|
return { text: responseText };
|
|
4958
4993
|
} finally {
|
|
4959
4994
|
span.end();
|
|
@@ -5007,20 +5042,20 @@ function agentInitializingOp(sessionId, graphId) {
|
|
|
5007
5042
|
}
|
|
5008
5043
|
};
|
|
5009
5044
|
}
|
|
5010
|
-
function completionOp(
|
|
5045
|
+
function completionOp(subAgentId, iterations) {
|
|
5011
5046
|
return {
|
|
5012
5047
|
type: "completion",
|
|
5013
5048
|
details: {
|
|
5014
|
-
agent:
|
|
5049
|
+
agent: subAgentId,
|
|
5015
5050
|
iteration: iterations
|
|
5016
5051
|
}
|
|
5017
5052
|
};
|
|
5018
5053
|
}
|
|
5019
|
-
function errorOp(message,
|
|
5054
|
+
function errorOp(message, subAgentId, severity = "error", code) {
|
|
5020
5055
|
return {
|
|
5021
5056
|
type: "error",
|
|
5022
5057
|
message,
|
|
5023
|
-
agent:
|
|
5058
|
+
agent: subAgentId,
|
|
5024
5059
|
severity,
|
|
5025
5060
|
code,
|
|
5026
5061
|
timestamp: Date.now()
|
|
@@ -5035,10 +5070,10 @@ init_logger();
|
|
|
5035
5070
|
|
|
5036
5071
|
// src/utils/data-component-schema.ts
|
|
5037
5072
|
init_logger();
|
|
5038
|
-
var
|
|
5073
|
+
var logger12 = agentsCore.getLogger("DataComponentSchema");
|
|
5039
5074
|
function jsonSchemaToZod(jsonSchema) {
|
|
5040
5075
|
if (!jsonSchema || typeof jsonSchema !== "object") {
|
|
5041
|
-
|
|
5076
|
+
logger12.warn({ jsonSchema }, "Invalid JSON schema provided, using string fallback");
|
|
5042
5077
|
return z6.z.string();
|
|
5043
5078
|
}
|
|
5044
5079
|
switch (jsonSchema.type) {
|
|
@@ -5065,7 +5100,7 @@ function jsonSchemaToZod(jsonSchema) {
|
|
|
5065
5100
|
case "null":
|
|
5066
5101
|
return z6.z.null();
|
|
5067
5102
|
default:
|
|
5068
|
-
|
|
5103
|
+
logger12.warn(
|
|
5069
5104
|
{
|
|
5070
5105
|
unsupportedType: jsonSchema.type,
|
|
5071
5106
|
schema: jsonSchema
|
|
@@ -5432,7 +5467,7 @@ function parseEmbeddedJson(data) {
|
|
|
5432
5467
|
|
|
5433
5468
|
// src/a2a/client.ts
|
|
5434
5469
|
init_logger();
|
|
5435
|
-
var
|
|
5470
|
+
var logger13 = agentsCore.getLogger("a2aClient");
|
|
5436
5471
|
var DEFAULT_BACKOFF = {
|
|
5437
5472
|
initialInterval: 500,
|
|
5438
5473
|
maxInterval: 6e4,
|
|
@@ -5638,7 +5673,7 @@ var A2AClient = class {
|
|
|
5638
5673
|
try {
|
|
5639
5674
|
const res = await fn();
|
|
5640
5675
|
if (attempt > 0) {
|
|
5641
|
-
|
|
5676
|
+
logger13.info(
|
|
5642
5677
|
{
|
|
5643
5678
|
attempts: attempt + 1,
|
|
5644
5679
|
elapsedTime: Date.now() - start
|
|
@@ -5653,7 +5688,7 @@ var A2AClient = class {
|
|
|
5653
5688
|
}
|
|
5654
5689
|
const elapsed = Date.now() - start;
|
|
5655
5690
|
if (elapsed > maxElapsedTime) {
|
|
5656
|
-
|
|
5691
|
+
logger13.warn(
|
|
5657
5692
|
{
|
|
5658
5693
|
attempts: attempt + 1,
|
|
5659
5694
|
elapsedTime: elapsed,
|
|
@@ -5674,7 +5709,7 @@ var A2AClient = class {
|
|
|
5674
5709
|
retryInterval = initialInterval * attempt ** exponent + Math.random() * 1e3;
|
|
5675
5710
|
}
|
|
5676
5711
|
const delayMs = Math.min(retryInterval, maxInterval);
|
|
5677
|
-
|
|
5712
|
+
logger13.info(
|
|
5678
5713
|
{
|
|
5679
5714
|
attempt: attempt + 1,
|
|
5680
5715
|
delayMs,
|
|
@@ -5759,7 +5794,7 @@ var A2AClient = class {
|
|
|
5759
5794
|
}
|
|
5760
5795
|
const rpcResponse = await httpResponse.json();
|
|
5761
5796
|
if (rpcResponse.id !== requestId2) {
|
|
5762
|
-
|
|
5797
|
+
logger13.warn(
|
|
5763
5798
|
{
|
|
5764
5799
|
method,
|
|
5765
5800
|
expectedId: requestId2,
|
|
@@ -5958,7 +5993,7 @@ var A2AClient = class {
|
|
|
5958
5993
|
try {
|
|
5959
5994
|
while (true) {
|
|
5960
5995
|
const { done, value } = await reader.read();
|
|
5961
|
-
|
|
5996
|
+
logger13.info({ done, value }, "parseA2ASseStream");
|
|
5962
5997
|
if (done) {
|
|
5963
5998
|
if (eventDataBuffer.trim()) {
|
|
5964
5999
|
const result = this._processSseEventData(
|
|
@@ -6048,7 +6083,7 @@ var A2AClient = class {
|
|
|
6048
6083
|
init_conversations();
|
|
6049
6084
|
init_dbClient();
|
|
6050
6085
|
init_logger();
|
|
6051
|
-
var
|
|
6086
|
+
var logger14 = agentsCore.getLogger("relationships Tools");
|
|
6052
6087
|
var generateTransferToolDescription = (config) => {
|
|
6053
6088
|
return `Hand off the conversation to agent ${config.id}.
|
|
6054
6089
|
|
|
@@ -6072,7 +6107,7 @@ Delegate a specific task to agent ${config.id} when it seems like the agent can
|
|
|
6072
6107
|
var createTransferToAgentTool = ({
|
|
6073
6108
|
transferConfig,
|
|
6074
6109
|
callingAgentId,
|
|
6075
|
-
|
|
6110
|
+
subAgent,
|
|
6076
6111
|
streamRequestId
|
|
6077
6112
|
}) => {
|
|
6078
6113
|
return ai.tool({
|
|
@@ -6082,11 +6117,11 @@ var createTransferToAgentTool = ({
|
|
|
6082
6117
|
const activeSpan = api.trace.getActiveSpan();
|
|
6083
6118
|
if (activeSpan) {
|
|
6084
6119
|
activeSpan.setAttributes({
|
|
6085
|
-
|
|
6086
|
-
|
|
6120
|
+
[agentsCore.SPAN_KEYS.TRANSFER_FROM_SUB_AGENT_ID]: callingAgentId,
|
|
6121
|
+
[agentsCore.SPAN_KEYS.TRANSFER_TO_SUB_AGENT_ID]: transferConfig.id ?? "unknown"
|
|
6087
6122
|
});
|
|
6088
6123
|
}
|
|
6089
|
-
|
|
6124
|
+
logger14.info(
|
|
6090
6125
|
{
|
|
6091
6126
|
transferTo: transferConfig.id ?? "unknown",
|
|
6092
6127
|
fromAgent: callingAgentId
|
|
@@ -6095,8 +6130,8 @@ var createTransferToAgentTool = ({
|
|
|
6095
6130
|
);
|
|
6096
6131
|
if (streamRequestId) {
|
|
6097
6132
|
graphSessionManager.recordEvent(streamRequestId, "transfer", callingAgentId, {
|
|
6098
|
-
|
|
6099
|
-
|
|
6133
|
+
fromSubAgent: callingAgentId,
|
|
6134
|
+
targetSubAgent: transferConfig.id ?? "unknown",
|
|
6100
6135
|
reason: `Transfer to ${transferConfig.name || transferConfig.id}`
|
|
6101
6136
|
});
|
|
6102
6137
|
}
|
|
@@ -6118,7 +6153,7 @@ function createDelegateToAgentTool({
|
|
|
6118
6153
|
contextId,
|
|
6119
6154
|
metadata,
|
|
6120
6155
|
sessionId,
|
|
6121
|
-
|
|
6156
|
+
subAgent,
|
|
6122
6157
|
credentialStoreRegistry
|
|
6123
6158
|
}) {
|
|
6124
6159
|
return ai.tool({
|
|
@@ -6129,9 +6164,9 @@ function createDelegateToAgentTool({
|
|
|
6129
6164
|
const activeSpan = api.trace.getActiveSpan();
|
|
6130
6165
|
if (activeSpan) {
|
|
6131
6166
|
activeSpan.setAttributes({
|
|
6132
|
-
|
|
6133
|
-
|
|
6134
|
-
|
|
6167
|
+
[agentsCore.SPAN_KEYS.DELEGATION_FROM_SUB_AGENT_ID]: callingAgentId,
|
|
6168
|
+
[agentsCore.SPAN_KEYS.DELEGATION_TO_SUB_AGENT_ID]: delegateConfig.config.id ?? "unknown",
|
|
6169
|
+
[agentsCore.SPAN_KEYS.DELEGATION_ID]: delegationId
|
|
6135
6170
|
});
|
|
6136
6171
|
}
|
|
6137
6172
|
if (metadata.streamRequestId) {
|
|
@@ -6141,8 +6176,8 @@ function createDelegateToAgentTool({
|
|
|
6141
6176
|
callingAgentId,
|
|
6142
6177
|
{
|
|
6143
6178
|
delegationId,
|
|
6144
|
-
|
|
6145
|
-
|
|
6179
|
+
fromSubAgent: callingAgentId,
|
|
6180
|
+
targetSubAgent: delegateConfig.config.id,
|
|
6146
6181
|
taskDescription: input.message
|
|
6147
6182
|
}
|
|
6148
6183
|
);
|
|
@@ -6156,7 +6191,7 @@ function createDelegateToAgentTool({
|
|
|
6156
6191
|
projectId,
|
|
6157
6192
|
graphId
|
|
6158
6193
|
},
|
|
6159
|
-
|
|
6194
|
+
subAgentId: delegateConfig.config.id
|
|
6160
6195
|
});
|
|
6161
6196
|
if (externalAgent && (externalAgent.credentialReferenceId || externalAgent.headers) && credentialStoreRegistry) {
|
|
6162
6197
|
const contextResolver = new agentsCore.ContextResolver(
|
|
@@ -6235,7 +6270,7 @@ function createDelegateToAgentTool({
|
|
|
6235
6270
|
...isInternal ? { fromAgentId: callingAgentId } : { fromExternalAgentId: callingAgentId }
|
|
6236
6271
|
}
|
|
6237
6272
|
};
|
|
6238
|
-
|
|
6273
|
+
logger14.info({ messageToSend }, "messageToSend");
|
|
6239
6274
|
await agentsCore.createMessage(dbClient_default)({
|
|
6240
6275
|
id: nanoid.nanoid(),
|
|
6241
6276
|
tenantId,
|
|
@@ -6247,7 +6282,7 @@ function createDelegateToAgentTool({
|
|
|
6247
6282
|
},
|
|
6248
6283
|
visibility: isInternal ? "internal" : "external",
|
|
6249
6284
|
messageType: "a2a-request",
|
|
6250
|
-
|
|
6285
|
+
fromSubAgentId: callingAgentId,
|
|
6251
6286
|
...isInternal ? { toAgentId: delegateConfig.config.id } : { toExternalAgentId: delegateConfig.config.id }
|
|
6252
6287
|
});
|
|
6253
6288
|
const response = await a2aClient.sendMessage({
|
|
@@ -6262,8 +6297,8 @@ function createDelegateToAgentTool({
|
|
|
6262
6297
|
conversationId: contextId,
|
|
6263
6298
|
messageType: "a2a-response",
|
|
6264
6299
|
visibility: isInternal ? "internal" : "external",
|
|
6265
|
-
|
|
6266
|
-
...isInternal ? {
|
|
6300
|
+
toSubAgentId: callingAgentId,
|
|
6301
|
+
...isInternal ? { fromSubAgentId: delegateConfig.config.id } : { fromExternalAgentId: delegateConfig.config.id }
|
|
6267
6302
|
});
|
|
6268
6303
|
if (sessionId && context?.toolCallId) {
|
|
6269
6304
|
const toolResult = {
|
|
@@ -6282,8 +6317,8 @@ function createDelegateToAgentTool({
|
|
|
6282
6317
|
callingAgentId,
|
|
6283
6318
|
{
|
|
6284
6319
|
delegationId,
|
|
6285
|
-
|
|
6286
|
-
|
|
6320
|
+
fromSubAgent: delegateConfig.config.id,
|
|
6321
|
+
targetSubAgent: callingAgentId,
|
|
6287
6322
|
result: response.result
|
|
6288
6323
|
}
|
|
6289
6324
|
);
|
|
@@ -6298,7 +6333,7 @@ function createDelegateToAgentTool({
|
|
|
6298
6333
|
|
|
6299
6334
|
// src/agents/SystemPromptBuilder.ts
|
|
6300
6335
|
init_logger();
|
|
6301
|
-
var
|
|
6336
|
+
var logger15 = agentsCore.getLogger("SystemPromptBuilder");
|
|
6302
6337
|
var SystemPromptBuilder = class {
|
|
6303
6338
|
constructor(version, versionConfig) {
|
|
6304
6339
|
this.version = version;
|
|
@@ -6314,12 +6349,12 @@ var SystemPromptBuilder = class {
|
|
|
6314
6349
|
this.templates.set(name, content);
|
|
6315
6350
|
}
|
|
6316
6351
|
this.loaded = true;
|
|
6317
|
-
|
|
6352
|
+
logger15.debug(
|
|
6318
6353
|
{ templateCount: this.templates.size, version: this.version },
|
|
6319
6354
|
`Loaded ${this.templates.size} templates for version ${this.version}`
|
|
6320
6355
|
);
|
|
6321
6356
|
} catch (error) {
|
|
6322
|
-
|
|
6357
|
+
logger15.error({ error }, `Failed to load templates for version ${this.version}`);
|
|
6323
6358
|
throw new Error(`Template loading failed: ${error}`);
|
|
6324
6359
|
}
|
|
6325
6360
|
}
|
|
@@ -7380,7 +7415,7 @@ function hasToolCallWithPrefix(prefix) {
|
|
|
7380
7415
|
return false;
|
|
7381
7416
|
};
|
|
7382
7417
|
}
|
|
7383
|
-
var
|
|
7418
|
+
var logger18 = agentsCore.getLogger("Agent");
|
|
7384
7419
|
var CONSTANTS = {
|
|
7385
7420
|
MAX_GENERATION_STEPS: 12,
|
|
7386
7421
|
PHASE_1_TIMEOUT_MS: 27e4,
|
|
@@ -7610,7 +7645,7 @@ var Agent = class {
|
|
|
7610
7645
|
}
|
|
7611
7646
|
getRelationTools(runtimeContext, sessionId) {
|
|
7612
7647
|
const { transferRelations = [], delegateRelations = [] } = this.config;
|
|
7613
|
-
const createToolName = (prefix,
|
|
7648
|
+
const createToolName = (prefix, subAgentId) => `${prefix}_to_${subAgentId.toLowerCase().replace(/\s+/g, "_")}`;
|
|
7614
7649
|
return Object.fromEntries([
|
|
7615
7650
|
...transferRelations.map((agentConfig) => {
|
|
7616
7651
|
const toolName = createToolName("transfer", agentConfig.id);
|
|
@@ -7621,7 +7656,7 @@ var Agent = class {
|
|
|
7621
7656
|
createTransferToAgentTool({
|
|
7622
7657
|
transferConfig: agentConfig,
|
|
7623
7658
|
callingAgentId: this.config.id,
|
|
7624
|
-
|
|
7659
|
+
subAgent: this,
|
|
7625
7660
|
streamRequestId: runtimeContext?.metadata?.streamRequestId
|
|
7626
7661
|
}),
|
|
7627
7662
|
runtimeContext?.metadata?.streamRequestId,
|
|
@@ -7650,7 +7685,7 @@ var Agent = class {
|
|
|
7650
7685
|
apiKey: runtimeContext?.metadata?.apiKey
|
|
7651
7686
|
},
|
|
7652
7687
|
sessionId,
|
|
7653
|
-
|
|
7688
|
+
subAgent: this,
|
|
7654
7689
|
credentialStoreRegistry: this.credentialStoreRegistry
|
|
7655
7690
|
}),
|
|
7656
7691
|
runtimeContext?.metadata?.streamRequestId,
|
|
@@ -7684,14 +7719,14 @@ var Agent = class {
|
|
|
7684
7719
|
for (const toolSet of tools) {
|
|
7685
7720
|
for (const [toolName, originalTool] of Object.entries(toolSet)) {
|
|
7686
7721
|
if (!isValidTool(originalTool)) {
|
|
7687
|
-
|
|
7722
|
+
logger18.error({ toolName }, "Invalid MCP tool structure - missing required properties");
|
|
7688
7723
|
continue;
|
|
7689
7724
|
}
|
|
7690
7725
|
const sessionWrappedTool = ai.tool({
|
|
7691
7726
|
description: originalTool.description,
|
|
7692
7727
|
inputSchema: originalTool.inputSchema,
|
|
7693
7728
|
execute: async (args, { toolCallId }) => {
|
|
7694
|
-
|
|
7729
|
+
logger18.debug({ toolName, toolCallId }, "MCP Tool Called");
|
|
7695
7730
|
try {
|
|
7696
7731
|
const rawResult = await originalTool.execute(args, { toolCallId });
|
|
7697
7732
|
const parsedResult = parseEmbeddedJson(rawResult);
|
|
@@ -7705,7 +7740,7 @@ var Agent = class {
|
|
|
7705
7740
|
});
|
|
7706
7741
|
return { result: enhancedResult, toolCallId };
|
|
7707
7742
|
} catch (error) {
|
|
7708
|
-
|
|
7743
|
+
logger18.error({ toolName, toolCallId, error }, "MCP tool execution failed");
|
|
7709
7744
|
throw error;
|
|
7710
7745
|
}
|
|
7711
7746
|
}
|
|
@@ -7750,7 +7785,7 @@ var Agent = class {
|
|
|
7750
7785
|
tenantId: this.config.tenantId,
|
|
7751
7786
|
projectId: this.config.projectId,
|
|
7752
7787
|
graphId: this.config.graphId,
|
|
7753
|
-
|
|
7788
|
+
subAgentId: this.config.id
|
|
7754
7789
|
}
|
|
7755
7790
|
});
|
|
7756
7791
|
const agentToolRelationHeaders = toolsForAgent.data.find((t) => t.toolId === tool3.id)?.headers || void 0;
|
|
@@ -7806,7 +7841,7 @@ var Agent = class {
|
|
|
7806
7841
|
headers: agentToolRelationHeaders
|
|
7807
7842
|
};
|
|
7808
7843
|
}
|
|
7809
|
-
|
|
7844
|
+
logger18.info(
|
|
7810
7845
|
{
|
|
7811
7846
|
toolName: tool3.name,
|
|
7812
7847
|
credentialReferenceId,
|
|
@@ -7831,10 +7866,10 @@ var Agent = class {
|
|
|
7831
7866
|
this.mcpClientCache.set(cacheKey, client);
|
|
7832
7867
|
} catch (error) {
|
|
7833
7868
|
this.mcpConnectionLocks.delete(cacheKey);
|
|
7834
|
-
|
|
7869
|
+
logger18.error(
|
|
7835
7870
|
{
|
|
7836
7871
|
toolName: tool3.name,
|
|
7837
|
-
|
|
7872
|
+
subAgentId: this.config.id,
|
|
7838
7873
|
cacheKey,
|
|
7839
7874
|
error: error instanceof Error ? error.message : String(error)
|
|
7840
7875
|
},
|
|
@@ -7844,6 +7879,45 @@ var Agent = class {
|
|
|
7844
7879
|
}
|
|
7845
7880
|
}
|
|
7846
7881
|
const tools = await client.tools();
|
|
7882
|
+
if (!tools || Object.keys(tools).length === 0) {
|
|
7883
|
+
const streamRequestId = this.getStreamRequestId();
|
|
7884
|
+
if (streamRequestId) {
|
|
7885
|
+
tracer.startActiveSpan(
|
|
7886
|
+
"ai.toolCall",
|
|
7887
|
+
{
|
|
7888
|
+
attributes: {
|
|
7889
|
+
"ai.toolCall.name": tool3.name,
|
|
7890
|
+
"ai.toolCall.args": JSON.stringify({ operation: "mcp_tool_discovery" }),
|
|
7891
|
+
"ai.toolCall.result": JSON.stringify({
|
|
7892
|
+
status: "no_tools_available",
|
|
7893
|
+
message: `MCP server has 0 effective tools. Double check the selected tools in your graph and the active tools in the MCP server configuration.`,
|
|
7894
|
+
serverUrl: tool3.config.type === "mcp" ? tool3.config.mcp.server.url : "unknown",
|
|
7895
|
+
originalToolName: tool3.name
|
|
7896
|
+
}),
|
|
7897
|
+
"ai.toolType": "mcp",
|
|
7898
|
+
"ai.agentName": this.config.name || "unknown",
|
|
7899
|
+
"conversation.id": this.conversationId || "unknown",
|
|
7900
|
+
"graph.id": this.config.graphId || "unknown",
|
|
7901
|
+
"tenant.id": this.config.tenantId || "unknown",
|
|
7902
|
+
"project.id": this.config.projectId || "unknown"
|
|
7903
|
+
}
|
|
7904
|
+
},
|
|
7905
|
+
(span) => {
|
|
7906
|
+
agentsCore.setSpanWithError(span, new Error(`0 effective tools available for ${tool3.name}`));
|
|
7907
|
+
graphSessionManager.recordEvent(streamRequestId, "tool_execution", this.config.id, {
|
|
7908
|
+
toolName: tool3.name,
|
|
7909
|
+
args: { operation: "mcp_tool_discovery" },
|
|
7910
|
+
result: {
|
|
7911
|
+
status: "no_tools_available",
|
|
7912
|
+
message: `MCP server has 0 effective tools. Double check the selected tools in your graph and the active tools in the MCP server configuration.`,
|
|
7913
|
+
serverUrl: tool3.config.type === "mcp" ? tool3.config.mcp.server.url : "unknown"
|
|
7914
|
+
}
|
|
7915
|
+
});
|
|
7916
|
+
span.end();
|
|
7917
|
+
}
|
|
7918
|
+
);
|
|
7919
|
+
}
|
|
7920
|
+
}
|
|
7847
7921
|
return tools;
|
|
7848
7922
|
}
|
|
7849
7923
|
async createMcpConnection(tool3, serverConfig) {
|
|
@@ -7855,99 +7929,110 @@ var Agent = class {
|
|
|
7855
7929
|
await client.connect();
|
|
7856
7930
|
return client;
|
|
7857
7931
|
} catch (error) {
|
|
7858
|
-
|
|
7932
|
+
logger18.error(
|
|
7859
7933
|
{
|
|
7860
7934
|
toolName: tool3.name,
|
|
7861
|
-
|
|
7935
|
+
subAgentId: this.config.id,
|
|
7862
7936
|
error: error instanceof Error ? error.message : String(error)
|
|
7863
7937
|
},
|
|
7864
7938
|
"Agent failed to connect to MCP server"
|
|
7865
7939
|
);
|
|
7940
|
+
if (error instanceof Error) {
|
|
7941
|
+
if (error?.cause && JSON.stringify(error.cause).includes("ECONNREFUSED")) {
|
|
7942
|
+
const errorMessage = "Connection refused. Please check if the MCP server is running.";
|
|
7943
|
+
throw new Error(errorMessage);
|
|
7944
|
+
} else if (error.message.includes("404")) {
|
|
7945
|
+
const errorMessage = "Error accessing endpoint (HTTP 404)";
|
|
7946
|
+
throw new Error(errorMessage);
|
|
7947
|
+
} else {
|
|
7948
|
+
throw new Error(`MCP server connection failed: ${error.message}`);
|
|
7949
|
+
}
|
|
7950
|
+
}
|
|
7866
7951
|
throw error;
|
|
7867
7952
|
}
|
|
7868
7953
|
}
|
|
7869
7954
|
async getFunctionTools(sessionId, streamRequestId) {
|
|
7870
7955
|
const functionTools = {};
|
|
7871
7956
|
try {
|
|
7872
|
-
const
|
|
7957
|
+
const functionToolsForAgent = await agentsCore.getFunctionToolsForSubAgent(dbClient_default)({
|
|
7873
7958
|
scopes: {
|
|
7874
|
-
tenantId: this.config.tenantId
|
|
7875
|
-
projectId: this.config.projectId
|
|
7876
|
-
graphId: this.config.graphId
|
|
7877
|
-
|
|
7878
|
-
|
|
7959
|
+
tenantId: this.config.tenantId,
|
|
7960
|
+
projectId: this.config.projectId,
|
|
7961
|
+
graphId: this.config.graphId
|
|
7962
|
+
},
|
|
7963
|
+
subAgentId: this.config.id
|
|
7879
7964
|
});
|
|
7880
|
-
const
|
|
7881
|
-
|
|
7882
|
-
if (functionToolDefs.length === 0) {
|
|
7965
|
+
const functionToolsData = functionToolsForAgent.data || [];
|
|
7966
|
+
if (functionToolsData.length === 0) {
|
|
7883
7967
|
return functionTools;
|
|
7884
7968
|
}
|
|
7885
7969
|
const { LocalSandboxExecutor: LocalSandboxExecutor2 } = await Promise.resolve().then(() => (init_LocalSandboxExecutor(), LocalSandboxExecutor_exports));
|
|
7886
7970
|
const sandboxExecutor = LocalSandboxExecutor2.getInstance();
|
|
7887
|
-
for (const
|
|
7888
|
-
|
|
7889
|
-
|
|
7890
|
-
|
|
7891
|
-
|
|
7892
|
-
|
|
7971
|
+
for (const functionToolDef of functionToolsData) {
|
|
7972
|
+
const functionId = functionToolDef.functionId;
|
|
7973
|
+
if (!functionId) {
|
|
7974
|
+
logger18.warn(
|
|
7975
|
+
{ functionToolId: functionToolDef.id },
|
|
7976
|
+
"Function tool missing functionId reference"
|
|
7977
|
+
);
|
|
7978
|
+
continue;
|
|
7979
|
+
}
|
|
7980
|
+
const functionData = await agentsCore.getFunction(dbClient_default)({
|
|
7981
|
+
functionId,
|
|
7982
|
+
scopes: {
|
|
7983
|
+
tenantId: this.config.tenantId || "default",
|
|
7984
|
+
projectId: this.config.projectId || "default"
|
|
7893
7985
|
}
|
|
7894
|
-
|
|
7895
|
-
|
|
7896
|
-
|
|
7897
|
-
|
|
7898
|
-
|
|
7899
|
-
|
|
7900
|
-
|
|
7901
|
-
|
|
7902
|
-
|
|
7903
|
-
|
|
7904
|
-
|
|
7986
|
+
});
|
|
7987
|
+
if (!functionData) {
|
|
7988
|
+
logger18.warn(
|
|
7989
|
+
{ functionId, functionToolId: functionToolDef.id },
|
|
7990
|
+
"Function not found in functions table"
|
|
7991
|
+
);
|
|
7992
|
+
continue;
|
|
7993
|
+
}
|
|
7994
|
+
const zodSchema = jsonSchemaToZod(functionData.inputSchema);
|
|
7995
|
+
const aiTool = ai.tool({
|
|
7996
|
+
description: functionToolDef.description || functionToolDef.name,
|
|
7997
|
+
inputSchema: zodSchema,
|
|
7998
|
+
execute: async (args, { toolCallId }) => {
|
|
7999
|
+
logger18.debug(
|
|
8000
|
+
{ toolName: functionToolDef.name, toolCallId, args },
|
|
8001
|
+
"Function Tool Called"
|
|
7905
8002
|
);
|
|
7906
|
-
|
|
7907
|
-
|
|
7908
|
-
|
|
7909
|
-
|
|
7910
|
-
|
|
7911
|
-
|
|
7912
|
-
|
|
7913
|
-
|
|
7914
|
-
|
|
7915
|
-
|
|
8003
|
+
try {
|
|
8004
|
+
const result = await sandboxExecutor.executeFunctionTool(functionToolDef.id, args, {
|
|
8005
|
+
description: functionToolDef.description || functionToolDef.name,
|
|
8006
|
+
inputSchema: functionData.inputSchema || {},
|
|
8007
|
+
executeCode: functionData.executeCode,
|
|
8008
|
+
dependencies: functionData.dependencies || {}
|
|
8009
|
+
});
|
|
8010
|
+
toolSessionManager.recordToolResult(sessionId || "", {
|
|
8011
|
+
toolCallId,
|
|
8012
|
+
toolName: functionToolDef.name,
|
|
8013
|
+
args,
|
|
8014
|
+
result,
|
|
8015
|
+
timestamp: Date.now()
|
|
8016
|
+
});
|
|
8017
|
+
return { result, toolCallId };
|
|
8018
|
+
} catch (error) {
|
|
8019
|
+
logger18.error(
|
|
8020
|
+
{ toolName: functionToolDef.name, toolCallId, error },
|
|
8021
|
+
"Function tool execution failed"
|
|
7916
8022
|
);
|
|
7917
|
-
|
|
7918
|
-
const result = await sandboxExecutor.executeFunctionTool(toolDef.tool.id, args, {
|
|
7919
|
-
description: toolDef.tool.description || toolDef.tool.name,
|
|
7920
|
-
inputSchema: functionData.inputSchema || {},
|
|
7921
|
-
executeCode: functionData.executeCode,
|
|
7922
|
-
dependencies: functionData.dependencies || {}
|
|
7923
|
-
});
|
|
7924
|
-
toolSessionManager.recordToolResult(sessionId || "", {
|
|
7925
|
-
toolCallId,
|
|
7926
|
-
toolName: toolDef.tool.name,
|
|
7927
|
-
args,
|
|
7928
|
-
result,
|
|
7929
|
-
timestamp: Date.now()
|
|
7930
|
-
});
|
|
7931
|
-
return { result, toolCallId };
|
|
7932
|
-
} catch (error) {
|
|
7933
|
-
logger19.error(
|
|
7934
|
-
{ toolName: toolDef.tool.name, toolCallId, error },
|
|
7935
|
-
"Function tool execution failed"
|
|
7936
|
-
);
|
|
7937
|
-
throw error;
|
|
7938
|
-
}
|
|
8023
|
+
throw error;
|
|
7939
8024
|
}
|
|
7940
|
-
}
|
|
7941
|
-
|
|
7942
|
-
|
|
7943
|
-
|
|
7944
|
-
|
|
7945
|
-
|
|
7946
|
-
|
|
7947
|
-
|
|
8025
|
+
}
|
|
8026
|
+
});
|
|
8027
|
+
functionTools[functionToolDef.name] = this.wrapToolWithStreaming(
|
|
8028
|
+
functionToolDef.name,
|
|
8029
|
+
aiTool,
|
|
8030
|
+
streamRequestId || "",
|
|
8031
|
+
"tool"
|
|
8032
|
+
);
|
|
7948
8033
|
}
|
|
7949
8034
|
} catch (error) {
|
|
7950
|
-
|
|
8035
|
+
logger18.error({ error }, "Failed to load function tools from database");
|
|
7951
8036
|
}
|
|
7952
8037
|
return functionTools;
|
|
7953
8038
|
}
|
|
@@ -7957,7 +8042,7 @@ var Agent = class {
|
|
|
7957
8042
|
async getResolvedContext(conversationId, headers) {
|
|
7958
8043
|
try {
|
|
7959
8044
|
if (!this.config.contextConfigId) {
|
|
7960
|
-
|
|
8045
|
+
logger18.debug({ graphId: this.config.graphId }, "No context config found for graph");
|
|
7961
8046
|
return null;
|
|
7962
8047
|
}
|
|
7963
8048
|
const contextConfig = await agentsCore.getContextConfigById(dbClient_default)({
|
|
@@ -7969,7 +8054,7 @@ var Agent = class {
|
|
|
7969
8054
|
id: this.config.contextConfigId
|
|
7970
8055
|
});
|
|
7971
8056
|
if (!contextConfig) {
|
|
7972
|
-
|
|
8057
|
+
logger18.warn({ contextConfigId: this.config.contextConfigId }, "Context config not found");
|
|
7973
8058
|
return null;
|
|
7974
8059
|
}
|
|
7975
8060
|
if (!this.contextResolver) {
|
|
@@ -7986,7 +8071,7 @@ var Agent = class {
|
|
|
7986
8071
|
$now: (/* @__PURE__ */ new Date()).toISOString(),
|
|
7987
8072
|
$env: process.env
|
|
7988
8073
|
};
|
|
7989
|
-
|
|
8074
|
+
logger18.debug(
|
|
7990
8075
|
{
|
|
7991
8076
|
conversationId,
|
|
7992
8077
|
contextConfigId: contextConfig.id,
|
|
@@ -8000,7 +8085,7 @@ var Agent = class {
|
|
|
8000
8085
|
);
|
|
8001
8086
|
return contextWithBuiltins;
|
|
8002
8087
|
} catch (error) {
|
|
8003
|
-
|
|
8088
|
+
logger18.error(
|
|
8004
8089
|
{
|
|
8005
8090
|
conversationId,
|
|
8006
8091
|
error: error instanceof Error ? error.message : "Unknown error"
|
|
@@ -8024,7 +8109,7 @@ var Agent = class {
|
|
|
8024
8109
|
});
|
|
8025
8110
|
return graphDefinition?.graphPrompt || void 0;
|
|
8026
8111
|
} catch (error) {
|
|
8027
|
-
|
|
8112
|
+
logger18.warn(
|
|
8028
8113
|
{
|
|
8029
8114
|
graphId: this.config.graphId,
|
|
8030
8115
|
error: error instanceof Error ? error.message : "Unknown error"
|
|
@@ -8049,11 +8134,11 @@ var Agent = class {
|
|
|
8049
8134
|
if (!graphDefinition) {
|
|
8050
8135
|
return false;
|
|
8051
8136
|
}
|
|
8052
|
-
return Object.values(graphDefinition.
|
|
8053
|
-
(
|
|
8137
|
+
return Object.values(graphDefinition.subAgents).some(
|
|
8138
|
+
(subAgent) => "artifactComponents" in subAgent && subAgent.artifactComponents && subAgent.artifactComponents.length > 0
|
|
8054
8139
|
);
|
|
8055
8140
|
} catch (error) {
|
|
8056
|
-
|
|
8141
|
+
logger18.warn(
|
|
8057
8142
|
{
|
|
8058
8143
|
graphId: this.config.graphId,
|
|
8059
8144
|
tenantId: this.config.tenantId,
|
|
@@ -8082,7 +8167,7 @@ var Agent = class {
|
|
|
8082
8167
|
preserveUnresolved: false
|
|
8083
8168
|
});
|
|
8084
8169
|
} catch (error) {
|
|
8085
|
-
|
|
8170
|
+
logger18.error(
|
|
8086
8171
|
{
|
|
8087
8172
|
conversationId,
|
|
8088
8173
|
error: error instanceof Error ? error.message : "Unknown error"
|
|
@@ -8129,7 +8214,7 @@ var Agent = class {
|
|
|
8129
8214
|
preserveUnresolved: false
|
|
8130
8215
|
});
|
|
8131
8216
|
} catch (error) {
|
|
8132
|
-
|
|
8217
|
+
logger18.error(
|
|
8133
8218
|
{
|
|
8134
8219
|
conversationId,
|
|
8135
8220
|
error: error instanceof Error ? error.message : "Unknown error"
|
|
@@ -8144,7 +8229,7 @@ var Agent = class {
|
|
|
8144
8229
|
const functionTools = await this.getFunctionTools(streamRequestId || "");
|
|
8145
8230
|
const relationTools = this.getRelationTools(runtimeContext);
|
|
8146
8231
|
const allTools = { ...mcpTools, ...functionTools, ...relationTools };
|
|
8147
|
-
|
|
8232
|
+
logger18.info(
|
|
8148
8233
|
{
|
|
8149
8234
|
mcpTools: Object.keys(mcpTools),
|
|
8150
8235
|
functionTools: Object.keys(functionTools),
|
|
@@ -8183,7 +8268,7 @@ var Agent = class {
|
|
|
8183
8268
|
preserveUnresolved: false
|
|
8184
8269
|
});
|
|
8185
8270
|
} catch (error) {
|
|
8186
|
-
|
|
8271
|
+
logger18.error(
|
|
8187
8272
|
{
|
|
8188
8273
|
conversationId,
|
|
8189
8274
|
error: error instanceof Error ? error.message : "Unknown error"
|
|
@@ -8216,7 +8301,7 @@ var Agent = class {
|
|
|
8216
8301
|
toolCallId: z6.z.string().describe("The tool call ID associated with this artifact.")
|
|
8217
8302
|
}),
|
|
8218
8303
|
execute: async ({ artifactId, toolCallId }) => {
|
|
8219
|
-
|
|
8304
|
+
logger18.info({ artifactId, toolCallId }, "get_artifact_full executed");
|
|
8220
8305
|
const streamRequestId = this.getStreamRequestId();
|
|
8221
8306
|
const artifactService = graphSessionManager.getArtifactService(streamRequestId);
|
|
8222
8307
|
if (!artifactService) {
|
|
@@ -8250,7 +8335,7 @@ var Agent = class {
|
|
|
8250
8335
|
});
|
|
8251
8336
|
}
|
|
8252
8337
|
// Provide a default tool set that is always available to the agent.
|
|
8253
|
-
async getDefaultTools(
|
|
8338
|
+
async getDefaultTools(streamRequestId) {
|
|
8254
8339
|
const defaultTools = {};
|
|
8255
8340
|
if (await this.graphHasArtifactComponents()) {
|
|
8256
8341
|
defaultTools.get_reference_artifact = this.getArtifactTools();
|
|
@@ -8476,7 +8561,7 @@ var Agent = class {
|
|
|
8476
8561
|
};
|
|
8477
8562
|
return enhanced;
|
|
8478
8563
|
} catch (error) {
|
|
8479
|
-
|
|
8564
|
+
logger18.warn({ error }, "Failed to enhance tool result with structure hints");
|
|
8480
8565
|
return result;
|
|
8481
8566
|
}
|
|
8482
8567
|
}
|
|
@@ -8491,7 +8576,7 @@ var Agent = class {
|
|
|
8491
8576
|
}
|
|
8492
8577
|
});
|
|
8493
8578
|
} catch (error) {
|
|
8494
|
-
|
|
8579
|
+
logger18.error(
|
|
8495
8580
|
{ error, graphId: this.config.graphId },
|
|
8496
8581
|
"Failed to check graph artifact components"
|
|
8497
8582
|
);
|
|
@@ -8536,7 +8621,7 @@ var Agent = class {
|
|
|
8536
8621
|
// Thinking prompt without data components
|
|
8537
8622
|
this.getFunctionTools(sessionId, streamRequestId),
|
|
8538
8623
|
Promise.resolve(this.getRelationTools(runtimeContext, sessionId)),
|
|
8539
|
-
this.getDefaultTools(
|
|
8624
|
+
this.getDefaultTools(streamRequestId)
|
|
8540
8625
|
]);
|
|
8541
8626
|
childSpan.setStatus({ code: api.SpanStatusCode.OK });
|
|
8542
8627
|
return result;
|
|
@@ -8576,7 +8661,7 @@ var Agent = class {
|
|
|
8576
8661
|
currentMessage: userMessage,
|
|
8577
8662
|
options: historyConfig,
|
|
8578
8663
|
filters: {
|
|
8579
|
-
|
|
8664
|
+
subAgentId: this.config.id,
|
|
8580
8665
|
taskId
|
|
8581
8666
|
}
|
|
8582
8667
|
});
|
|
@@ -8592,7 +8677,7 @@ var Agent = class {
|
|
|
8592
8677
|
const configuredTimeout = modelSettings.maxDuration ? Math.min(modelSettings.maxDuration * 1e3, MAX_ALLOWED_TIMEOUT_MS) : shouldStreamPhase1 ? CONSTANTS.PHASE_1_TIMEOUT_MS : CONSTANTS.NON_STREAMING_PHASE_1_TIMEOUT_MS;
|
|
8593
8678
|
const timeoutMs = Math.min(configuredTimeout, MAX_ALLOWED_TIMEOUT_MS);
|
|
8594
8679
|
if (modelSettings.maxDuration && modelSettings.maxDuration * 1e3 > MAX_ALLOWED_TIMEOUT_MS) {
|
|
8595
|
-
|
|
8680
|
+
logger18.warn(
|
|
8596
8681
|
{
|
|
8597
8682
|
requestedTimeout: modelSettings.maxDuration * 1e3,
|
|
8598
8683
|
appliedTimeout: timeoutMs,
|
|
@@ -8634,7 +8719,7 @@ var Agent = class {
|
|
|
8634
8719
|
}
|
|
8635
8720
|
);
|
|
8636
8721
|
} catch (error) {
|
|
8637
|
-
|
|
8722
|
+
logger18.debug({ error }, "Failed to track agent reasoning");
|
|
8638
8723
|
}
|
|
8639
8724
|
}
|
|
8640
8725
|
if (last && "toolCalls" in last && last.toolCalls) {
|
|
@@ -8661,7 +8746,7 @@ var Agent = class {
|
|
|
8661
8746
|
projectId: session?.projectId,
|
|
8662
8747
|
artifactComponents: this.artifactComponents,
|
|
8663
8748
|
streamRequestId: this.getStreamRequestId(),
|
|
8664
|
-
|
|
8749
|
+
subAgentId: this.config.id
|
|
8665
8750
|
};
|
|
8666
8751
|
const parser = new IncrementalStreamParser(
|
|
8667
8752
|
streamHelper,
|
|
@@ -8706,6 +8791,16 @@ var Agent = class {
|
|
|
8706
8791
|
}))
|
|
8707
8792
|
};
|
|
8708
8793
|
}
|
|
8794
|
+
const streamedContent = parser.getAllStreamedContent();
|
|
8795
|
+
if (streamedContent.length > 0) {
|
|
8796
|
+
response.streamedContent = {
|
|
8797
|
+
parts: streamedContent.map((part) => ({
|
|
8798
|
+
kind: part.kind,
|
|
8799
|
+
...part.kind === "text" && { text: part.text },
|
|
8800
|
+
...part.kind === "data" && { data: part.data }
|
|
8801
|
+
}))
|
|
8802
|
+
};
|
|
8803
|
+
}
|
|
8709
8804
|
} else {
|
|
8710
8805
|
let genConfig;
|
|
8711
8806
|
if (hasStructuredOutput) {
|
|
@@ -8738,7 +8833,7 @@ var Agent = class {
|
|
|
8738
8833
|
}
|
|
8739
8834
|
);
|
|
8740
8835
|
} catch (error) {
|
|
8741
|
-
|
|
8836
|
+
logger18.debug({ error }, "Failed to track agent reasoning");
|
|
8742
8837
|
}
|
|
8743
8838
|
}
|
|
8744
8839
|
if (last && "toolCalls" in last && last.toolCalls) {
|
|
@@ -8910,7 +9005,7 @@ ${output}${structureHintsFormatted}`;
|
|
|
8910
9005
|
projectId: session?.projectId,
|
|
8911
9006
|
artifactComponents: this.artifactComponents,
|
|
8912
9007
|
streamRequestId: this.getStreamRequestId(),
|
|
8913
|
-
|
|
9008
|
+
subAgentId: this.config.id
|
|
8914
9009
|
};
|
|
8915
9010
|
const parser = new IncrementalStreamParser(
|
|
8916
9011
|
streamHelper,
|
|
@@ -8993,7 +9088,7 @@ ${output}${structureHintsFormatted}`;
|
|
|
8993
9088
|
contextId,
|
|
8994
9089
|
artifactComponents: this.artifactComponents,
|
|
8995
9090
|
streamRequestId: this.getStreamRequestId(),
|
|
8996
|
-
|
|
9091
|
+
subAgentId: this.config.id
|
|
8997
9092
|
});
|
|
8998
9093
|
if (response.object) {
|
|
8999
9094
|
formattedContent = await responseFormatter.formatObjectResponse(
|
|
@@ -9030,7 +9125,7 @@ ${output}${structureHintsFormatted}`;
|
|
|
9030
9125
|
};
|
|
9031
9126
|
|
|
9032
9127
|
// src/agents/generateTaskHandler.ts
|
|
9033
|
-
var
|
|
9128
|
+
var logger19 = agentsCore.getLogger("generateTaskHandler");
|
|
9034
9129
|
var createTaskHandler = (config, credentialStoreRegistry) => {
|
|
9035
9130
|
return async (task) => {
|
|
9036
9131
|
try {
|
|
@@ -9056,14 +9151,14 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
|
|
|
9056
9151
|
projectId: config.projectId,
|
|
9057
9152
|
graphId: config.graphId
|
|
9058
9153
|
},
|
|
9059
|
-
|
|
9154
|
+
subAgentId: config.subAgentId
|
|
9060
9155
|
}),
|
|
9061
9156
|
agentsCore.getToolsForAgent(dbClient_default)({
|
|
9062
9157
|
scopes: {
|
|
9063
9158
|
tenantId: config.tenantId,
|
|
9064
9159
|
projectId: config.projectId,
|
|
9065
9160
|
graphId: config.graphId,
|
|
9066
|
-
|
|
9161
|
+
subAgentId: config.subAgentId
|
|
9067
9162
|
}
|
|
9068
9163
|
}),
|
|
9069
9164
|
agentsCore.getDataComponentsForAgent(dbClient_default)({
|
|
@@ -9071,7 +9166,7 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
|
|
|
9071
9166
|
tenantId: config.tenantId,
|
|
9072
9167
|
projectId: config.projectId,
|
|
9073
9168
|
graphId: config.graphId,
|
|
9074
|
-
|
|
9169
|
+
subAgentId: config.subAgentId
|
|
9075
9170
|
}
|
|
9076
9171
|
}),
|
|
9077
9172
|
agentsCore.getArtifactComponentsForAgent(dbClient_default)({
|
|
@@ -9079,21 +9174,21 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
|
|
|
9079
9174
|
tenantId: config.tenantId,
|
|
9080
9175
|
projectId: config.projectId,
|
|
9081
9176
|
graphId: config.graphId,
|
|
9082
|
-
|
|
9177
|
+
subAgentId: config.subAgentId
|
|
9083
9178
|
}
|
|
9084
9179
|
})
|
|
9085
9180
|
]);
|
|
9086
|
-
|
|
9181
|
+
logger19.info({ toolsForAgent, internalRelations, externalRelations }, "agent stuff");
|
|
9087
9182
|
const enhancedInternalRelations = await Promise.all(
|
|
9088
9183
|
internalRelations.map(async (relation) => {
|
|
9089
9184
|
try {
|
|
9090
|
-
const relatedAgent = await agentsCore.
|
|
9185
|
+
const relatedAgent = await agentsCore.getSubAgentById(dbClient_default)({
|
|
9091
9186
|
scopes: {
|
|
9092
9187
|
tenantId: config.tenantId,
|
|
9093
9188
|
projectId: config.projectId,
|
|
9094
9189
|
graphId: config.graphId
|
|
9095
9190
|
},
|
|
9096
|
-
|
|
9191
|
+
subAgentId: relation.id
|
|
9097
9192
|
});
|
|
9098
9193
|
if (relatedAgent) {
|
|
9099
9194
|
const relatedAgentRelations = await agentsCore.getRelatedAgentsForGraph(dbClient_default)({
|
|
@@ -9102,7 +9197,7 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
|
|
|
9102
9197
|
projectId: config.projectId,
|
|
9103
9198
|
graphId: config.graphId
|
|
9104
9199
|
},
|
|
9105
|
-
|
|
9200
|
+
subAgentId: relation.id
|
|
9106
9201
|
});
|
|
9107
9202
|
const enhancedDescription = generateDescriptionWithTransfers(
|
|
9108
9203
|
relation.description || "",
|
|
@@ -9112,7 +9207,7 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
|
|
|
9112
9207
|
return { ...relation, description: enhancedDescription };
|
|
9113
9208
|
}
|
|
9114
9209
|
} catch (error) {
|
|
9115
|
-
|
|
9210
|
+
logger19.warn({ subAgentId: relation.id, error }, "Failed to enhance agent description");
|
|
9116
9211
|
}
|
|
9117
9212
|
return relation;
|
|
9118
9213
|
})
|
|
@@ -9127,7 +9222,7 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
|
|
|
9127
9222
|
) ?? [];
|
|
9128
9223
|
const agent = new Agent(
|
|
9129
9224
|
{
|
|
9130
|
-
id: config.
|
|
9225
|
+
id: config.subAgentId,
|
|
9131
9226
|
tenantId: config.tenantId,
|
|
9132
9227
|
projectId: config.projectId,
|
|
9133
9228
|
graphId: config.graphId,
|
|
@@ -9138,7 +9233,7 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
|
|
|
9138
9233
|
agentPrompt,
|
|
9139
9234
|
models: models || void 0,
|
|
9140
9235
|
stopWhen: stopWhen || void 0,
|
|
9141
|
-
|
|
9236
|
+
subAgentRelations: enhancedInternalRelations.map((relation) => ({
|
|
9142
9237
|
id: relation.id,
|
|
9143
9238
|
tenantId: config.tenantId,
|
|
9144
9239
|
projectId: config.projectId,
|
|
@@ -9149,7 +9244,7 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
|
|
|
9149
9244
|
description: relation.description,
|
|
9150
9245
|
agentPrompt: "",
|
|
9151
9246
|
delegateRelations: [],
|
|
9152
|
-
|
|
9247
|
+
subAgentRelations: [],
|
|
9153
9248
|
transferRelations: []
|
|
9154
9249
|
})),
|
|
9155
9250
|
transferRelations: enhancedInternalRelations.filter((relation) => relation.relationType === "transfer").map((relation) => ({
|
|
@@ -9163,7 +9258,7 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
|
|
|
9163
9258
|
description: relation.description,
|
|
9164
9259
|
agentPrompt: "",
|
|
9165
9260
|
delegateRelations: [],
|
|
9166
|
-
|
|
9261
|
+
subAgentRelations: [],
|
|
9167
9262
|
transferRelations: []
|
|
9168
9263
|
})),
|
|
9169
9264
|
delegateRelations: [
|
|
@@ -9181,7 +9276,7 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
|
|
|
9181
9276
|
description: relation.description,
|
|
9182
9277
|
agentPrompt: "",
|
|
9183
9278
|
delegateRelations: [],
|
|
9184
|
-
|
|
9279
|
+
subAgentRelations: [],
|
|
9185
9280
|
transferRelations: []
|
|
9186
9281
|
}
|
|
9187
9282
|
})),
|
|
@@ -9216,11 +9311,11 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
|
|
|
9216
9311
|
const taskIdMatch = task.id.match(/^task_([^-]+-[^-]+-\d+)-/);
|
|
9217
9312
|
if (taskIdMatch) {
|
|
9218
9313
|
contextId = taskIdMatch[1];
|
|
9219
|
-
|
|
9314
|
+
logger19.info(
|
|
9220
9315
|
{
|
|
9221
9316
|
taskId: task.id,
|
|
9222
9317
|
extractedContextId: contextId,
|
|
9223
|
-
|
|
9318
|
+
subAgentId: config.subAgentId
|
|
9224
9319
|
},
|
|
9225
9320
|
"Extracted contextId from task ID for delegation"
|
|
9226
9321
|
);
|
|
@@ -9232,8 +9327,8 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
|
|
|
9232
9327
|
const isDelegation = task.context?.metadata?.isDelegation === true;
|
|
9233
9328
|
agent.setDelegationStatus(isDelegation);
|
|
9234
9329
|
if (isDelegation) {
|
|
9235
|
-
|
|
9236
|
-
{
|
|
9330
|
+
logger19.info(
|
|
9331
|
+
{ subAgentId: config.subAgentId, taskId: task.id },
|
|
9237
9332
|
"Delegated agent - streaming disabled"
|
|
9238
9333
|
);
|
|
9239
9334
|
if (streamRequestId && config.tenantId && config.projectId) {
|
|
@@ -9330,13 +9425,13 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
|
|
|
9330
9425
|
};
|
|
9331
9426
|
};
|
|
9332
9427
|
var createTaskHandlerConfig = async (params) => {
|
|
9333
|
-
const agent = await agentsCore.
|
|
9428
|
+
const agent = await agentsCore.getSubAgentById(dbClient_default)({
|
|
9334
9429
|
scopes: {
|
|
9335
9430
|
tenantId: params.tenantId,
|
|
9336
9431
|
projectId: params.projectId,
|
|
9337
9432
|
graphId: params.graphId
|
|
9338
9433
|
},
|
|
9339
|
-
|
|
9434
|
+
subAgentId: params.subAgentId
|
|
9340
9435
|
});
|
|
9341
9436
|
const agentGraph = await agentsCore.getAgentGraphById(dbClient_default)({
|
|
9342
9437
|
scopes: {
|
|
@@ -9346,7 +9441,7 @@ var createTaskHandlerConfig = async (params) => {
|
|
|
9346
9441
|
}
|
|
9347
9442
|
});
|
|
9348
9443
|
if (!agent) {
|
|
9349
|
-
throw new Error(`Agent not found: ${params.
|
|
9444
|
+
throw new Error(`Agent not found: ${params.subAgentId}`);
|
|
9350
9445
|
}
|
|
9351
9446
|
const effectiveModels = await resolveModelConfig(params.graphId, agent);
|
|
9352
9447
|
const effectiveConversationHistoryConfig = agent.conversationHistoryConfig || { mode: "full" };
|
|
@@ -9354,7 +9449,7 @@ var createTaskHandlerConfig = async (params) => {
|
|
|
9354
9449
|
tenantId: params.tenantId,
|
|
9355
9450
|
projectId: params.projectId,
|
|
9356
9451
|
graphId: params.graphId,
|
|
9357
|
-
|
|
9452
|
+
subAgentId: params.subAgentId,
|
|
9358
9453
|
agentSchema: {
|
|
9359
9454
|
id: agent.id,
|
|
9360
9455
|
name: agent.name,
|
|
@@ -9383,25 +9478,27 @@ async function hydrateGraph({
|
|
|
9383
9478
|
apiKey
|
|
9384
9479
|
}) {
|
|
9385
9480
|
try {
|
|
9386
|
-
if (!dbGraph.
|
|
9481
|
+
if (!dbGraph.defaultSubAgentId) {
|
|
9387
9482
|
throw new Error(`Graph ${dbGraph.id} does not have a default agent configured`);
|
|
9388
9483
|
}
|
|
9389
|
-
const
|
|
9484
|
+
const defaultSubAgent = await agentsCore.getSubAgentById(dbClient_default)({
|
|
9390
9485
|
scopes: {
|
|
9391
9486
|
tenantId: dbGraph.tenantId,
|
|
9392
9487
|
projectId: dbGraph.projectId,
|
|
9393
9488
|
graphId: dbGraph.id
|
|
9394
9489
|
},
|
|
9395
|
-
|
|
9490
|
+
subAgentId: dbGraph.defaultSubAgentId
|
|
9396
9491
|
});
|
|
9397
|
-
if (!
|
|
9398
|
-
throw new Error(
|
|
9492
|
+
if (!defaultSubAgent) {
|
|
9493
|
+
throw new Error(
|
|
9494
|
+
`Default agent ${dbGraph.defaultSubAgentId} not found for graph ${dbGraph.id}`
|
|
9495
|
+
);
|
|
9399
9496
|
}
|
|
9400
9497
|
const taskHandlerConfig = await createTaskHandlerConfig({
|
|
9401
9498
|
tenantId: dbGraph.tenantId,
|
|
9402
9499
|
projectId: dbGraph.projectId,
|
|
9403
9500
|
graphId: dbGraph.id,
|
|
9404
|
-
|
|
9501
|
+
subAgentId: dbGraph.defaultSubAgentId,
|
|
9405
9502
|
baseUrl,
|
|
9406
9503
|
apiKey
|
|
9407
9504
|
});
|
|
@@ -9430,7 +9527,7 @@ async function hydrateGraph({
|
|
|
9430
9527
|
}
|
|
9431
9528
|
};
|
|
9432
9529
|
return {
|
|
9433
|
-
|
|
9530
|
+
subAgentId: dbGraph.id,
|
|
9434
9531
|
// Use graph ID as agent ID for A2A purposes
|
|
9435
9532
|
tenantId: dbGraph.tenantId,
|
|
9436
9533
|
projectId: dbGraph.projectId,
|
|
@@ -9457,7 +9554,7 @@ async function getRegisteredGraph(executionContext) {
|
|
|
9457
9554
|
init_dbClient();
|
|
9458
9555
|
init_logger();
|
|
9459
9556
|
var app = new zodOpenapi.OpenAPIHono();
|
|
9460
|
-
var
|
|
9557
|
+
var logger20 = agentsCore.getLogger("agents");
|
|
9461
9558
|
app.openapi(
|
|
9462
9559
|
zodOpenapi.createRoute({
|
|
9463
9560
|
method: "get",
|
|
@@ -9495,7 +9592,7 @@ app.openapi(
|
|
|
9495
9592
|
tracestate: c.req.header("tracestate"),
|
|
9496
9593
|
baggage: c.req.header("baggage")
|
|
9497
9594
|
};
|
|
9498
|
-
|
|
9595
|
+
logger20.info(
|
|
9499
9596
|
{
|
|
9500
9597
|
otelHeaders,
|
|
9501
9598
|
path: c.req.path,
|
|
@@ -9504,22 +9601,22 @@ app.openapi(
|
|
|
9504
9601
|
"OpenTelemetry headers: well-known agent.json"
|
|
9505
9602
|
);
|
|
9506
9603
|
const executionContext = agentsCore.getRequestExecutionContext(c);
|
|
9507
|
-
const { tenantId, projectId, graphId,
|
|
9604
|
+
const { tenantId, projectId, graphId, subAgentId } = executionContext;
|
|
9508
9605
|
console.dir("executionContext", executionContext);
|
|
9509
|
-
if (
|
|
9510
|
-
|
|
9606
|
+
if (subAgentId) {
|
|
9607
|
+
logger20.info(
|
|
9511
9608
|
{
|
|
9512
9609
|
message: "getRegisteredAgent (agent-level)",
|
|
9513
9610
|
tenantId,
|
|
9514
9611
|
projectId,
|
|
9515
9612
|
graphId,
|
|
9516
|
-
|
|
9613
|
+
subAgentId
|
|
9517
9614
|
},
|
|
9518
9615
|
"agent-level well-known agent.json"
|
|
9519
9616
|
);
|
|
9520
9617
|
const credentialStores = c.get("credentialStores");
|
|
9521
9618
|
const agent = await getRegisteredAgent(executionContext, credentialStores);
|
|
9522
|
-
|
|
9619
|
+
logger20.info({ agent }, "agent registered: well-known agent.json");
|
|
9523
9620
|
if (!agent) {
|
|
9524
9621
|
throw agentsCore.createApiError({
|
|
9525
9622
|
code: "not_found",
|
|
@@ -9528,7 +9625,7 @@ app.openapi(
|
|
|
9528
9625
|
}
|
|
9529
9626
|
return c.json(agent.agentCard);
|
|
9530
9627
|
} else {
|
|
9531
|
-
|
|
9628
|
+
logger20.info(
|
|
9532
9629
|
{
|
|
9533
9630
|
message: "getRegisteredGraph (graph-level)",
|
|
9534
9631
|
tenantId,
|
|
@@ -9554,7 +9651,7 @@ app.post("/a2a", async (c) => {
|
|
|
9554
9651
|
tracestate: c.req.header("tracestate"),
|
|
9555
9652
|
baggage: c.req.header("baggage")
|
|
9556
9653
|
};
|
|
9557
|
-
|
|
9654
|
+
logger20.info(
|
|
9558
9655
|
{
|
|
9559
9656
|
otelHeaders,
|
|
9560
9657
|
path: c.req.path,
|
|
@@ -9563,15 +9660,15 @@ app.post("/a2a", async (c) => {
|
|
|
9563
9660
|
"OpenTelemetry headers: a2a"
|
|
9564
9661
|
);
|
|
9565
9662
|
const executionContext = agentsCore.getRequestExecutionContext(c);
|
|
9566
|
-
const { tenantId, projectId, graphId,
|
|
9567
|
-
if (
|
|
9568
|
-
|
|
9663
|
+
const { tenantId, projectId, graphId, subAgentId } = executionContext;
|
|
9664
|
+
if (subAgentId) {
|
|
9665
|
+
logger20.info(
|
|
9569
9666
|
{
|
|
9570
9667
|
message: "a2a (agent-level)",
|
|
9571
9668
|
tenantId,
|
|
9572
9669
|
projectId,
|
|
9573
9670
|
graphId,
|
|
9574
|
-
|
|
9671
|
+
subAgentId
|
|
9575
9672
|
},
|
|
9576
9673
|
"agent-level a2a endpoint"
|
|
9577
9674
|
);
|
|
@@ -9589,7 +9686,7 @@ app.post("/a2a", async (c) => {
|
|
|
9589
9686
|
}
|
|
9590
9687
|
return a2aHandler(c, agent);
|
|
9591
9688
|
} else {
|
|
9592
|
-
|
|
9689
|
+
logger20.info(
|
|
9593
9690
|
{
|
|
9594
9691
|
message: "a2a (graph-level)",
|
|
9595
9692
|
tenantId,
|
|
@@ -9598,7 +9695,7 @@ app.post("/a2a", async (c) => {
|
|
|
9598
9695
|
},
|
|
9599
9696
|
"graph-level a2a endpoint"
|
|
9600
9697
|
);
|
|
9601
|
-
const graph = await agentsCore.
|
|
9698
|
+
const graph = await agentsCore.getAgentGraphWithDefaultSubAgent(dbClient_default)({
|
|
9602
9699
|
scopes: { tenantId, projectId, graphId }
|
|
9603
9700
|
});
|
|
9604
9701
|
if (!graph) {
|
|
@@ -9611,7 +9708,7 @@ app.post("/a2a", async (c) => {
|
|
|
9611
9708
|
404
|
|
9612
9709
|
);
|
|
9613
9710
|
}
|
|
9614
|
-
if (!graph.
|
|
9711
|
+
if (!graph.defaultSubAgentId) {
|
|
9615
9712
|
return c.json(
|
|
9616
9713
|
{
|
|
9617
9714
|
jsonrpc: "2.0",
|
|
@@ -9621,10 +9718,10 @@ app.post("/a2a", async (c) => {
|
|
|
9621
9718
|
400
|
|
9622
9719
|
);
|
|
9623
9720
|
}
|
|
9624
|
-
executionContext.
|
|
9721
|
+
executionContext.subAgentId = graph.defaultSubAgentId;
|
|
9625
9722
|
const credentialStores = c.get("credentialStores");
|
|
9626
|
-
const
|
|
9627
|
-
if (!
|
|
9723
|
+
const defaultSubAgent = await getRegisteredAgent(executionContext, credentialStores);
|
|
9724
|
+
if (!defaultSubAgent) {
|
|
9628
9725
|
return c.json(
|
|
9629
9726
|
{
|
|
9630
9727
|
jsonrpc: "2.0",
|
|
@@ -9634,7 +9731,7 @@ app.post("/a2a", async (c) => {
|
|
|
9634
9731
|
404
|
|
9635
9732
|
);
|
|
9636
9733
|
}
|
|
9637
|
-
return a2aHandler(c,
|
|
9734
|
+
return a2aHandler(c, defaultSubAgent);
|
|
9638
9735
|
}
|
|
9639
9736
|
});
|
|
9640
9737
|
var agents_default = app;
|
|
@@ -9645,20 +9742,20 @@ init_dbClient();
|
|
|
9645
9742
|
// src/a2a/transfer.ts
|
|
9646
9743
|
init_dbClient();
|
|
9647
9744
|
init_logger();
|
|
9648
|
-
var
|
|
9745
|
+
var logger21 = agentsCore.getLogger("Transfer");
|
|
9649
9746
|
async function executeTransfer({
|
|
9650
9747
|
tenantId,
|
|
9651
9748
|
threadId,
|
|
9652
9749
|
projectId,
|
|
9653
|
-
|
|
9750
|
+
targetSubAgentId
|
|
9654
9751
|
}) {
|
|
9655
|
-
|
|
9752
|
+
logger21.info({ targetAgent: targetSubAgentId }, "Executing transfer to agent");
|
|
9656
9753
|
await agentsCore.setActiveAgentForThread(dbClient_default)({
|
|
9657
9754
|
scopes: { tenantId, projectId },
|
|
9658
9755
|
threadId,
|
|
9659
|
-
|
|
9756
|
+
subAgentId: targetSubAgentId
|
|
9660
9757
|
});
|
|
9661
|
-
return { success: true,
|
|
9758
|
+
return { success: true, targetSubAgentId };
|
|
9662
9759
|
}
|
|
9663
9760
|
function isTransferResponse(result) {
|
|
9664
9761
|
return result?.artifacts.some(
|
|
@@ -10238,7 +10335,7 @@ function createMCPStreamHelper() {
|
|
|
10238
10335
|
}
|
|
10239
10336
|
|
|
10240
10337
|
// src/handlers/executionHandler.ts
|
|
10241
|
-
var
|
|
10338
|
+
var logger22 = agentsCore.getLogger("ExecutionHandler");
|
|
10242
10339
|
var ExecutionHandler = class {
|
|
10243
10340
|
constructor() {
|
|
10244
10341
|
// Hardcoded error limit - separate from configurable stopWhen
|
|
@@ -10274,7 +10371,7 @@ var ExecutionHandler = class {
|
|
|
10274
10371
|
if (emitOperations) {
|
|
10275
10372
|
graphSessionManager.enableEmitOperations(requestId2);
|
|
10276
10373
|
}
|
|
10277
|
-
|
|
10374
|
+
logger22.info(
|
|
10278
10375
|
{ sessionId: requestId2, graphId, conversationId, emitOperations },
|
|
10279
10376
|
"Created GraphSession for message execution"
|
|
10280
10377
|
);
|
|
@@ -10289,7 +10386,7 @@ var ExecutionHandler = class {
|
|
|
10289
10386
|
);
|
|
10290
10387
|
}
|
|
10291
10388
|
} catch (error) {
|
|
10292
|
-
|
|
10389
|
+
logger22.error(
|
|
10293
10390
|
{
|
|
10294
10391
|
error: error instanceof Error ? error.message : "Unknown error",
|
|
10295
10392
|
stack: error instanceof Error ? error.stack : void 0
|
|
@@ -10305,7 +10402,7 @@ var ExecutionHandler = class {
|
|
|
10305
10402
|
try {
|
|
10306
10403
|
await sseHelper.writeOperation(agentInitializingOp(requestId2, graphId));
|
|
10307
10404
|
const taskId = `task_${conversationId}-${requestId2}`;
|
|
10308
|
-
|
|
10405
|
+
logger22.info(
|
|
10309
10406
|
{ taskId, currentAgentId, conversationId, requestId: requestId2 },
|
|
10310
10407
|
"Attempting to create or reuse existing task"
|
|
10311
10408
|
);
|
|
@@ -10315,7 +10412,7 @@ var ExecutionHandler = class {
|
|
|
10315
10412
|
tenantId,
|
|
10316
10413
|
projectId,
|
|
10317
10414
|
graphId,
|
|
10318
|
-
|
|
10415
|
+
subAgentId: currentAgentId,
|
|
10319
10416
|
contextId: conversationId,
|
|
10320
10417
|
status: "pending",
|
|
10321
10418
|
metadata: {
|
|
@@ -10329,7 +10426,7 @@ var ExecutionHandler = class {
|
|
|
10329
10426
|
agent_id: currentAgentId
|
|
10330
10427
|
}
|
|
10331
10428
|
});
|
|
10332
|
-
|
|
10429
|
+
logger22.info(
|
|
10333
10430
|
{
|
|
10334
10431
|
taskId,
|
|
10335
10432
|
createdTaskMetadata: Array.isArray(task) ? task[0]?.metadata : task?.metadata
|
|
@@ -10338,27 +10435,27 @@ var ExecutionHandler = class {
|
|
|
10338
10435
|
);
|
|
10339
10436
|
} catch (error) {
|
|
10340
10437
|
if (error?.message?.includes("UNIQUE constraint failed") || error?.message?.includes("PRIMARY KEY constraint failed") || error?.code === "SQLITE_CONSTRAINT_PRIMARYKEY") {
|
|
10341
|
-
|
|
10438
|
+
logger22.info(
|
|
10342
10439
|
{ taskId, error: error.message },
|
|
10343
10440
|
"Task already exists, fetching existing task"
|
|
10344
10441
|
);
|
|
10345
10442
|
const existingTask = await agentsCore.getTask(dbClient_default)({ id: taskId });
|
|
10346
10443
|
if (existingTask) {
|
|
10347
10444
|
task = existingTask;
|
|
10348
|
-
|
|
10445
|
+
logger22.info(
|
|
10349
10446
|
{ taskId, existingTask },
|
|
10350
10447
|
"Successfully reused existing task from race condition"
|
|
10351
10448
|
);
|
|
10352
10449
|
} else {
|
|
10353
|
-
|
|
10450
|
+
logger22.error({ taskId, error }, "Task constraint failed but task not found");
|
|
10354
10451
|
throw error;
|
|
10355
10452
|
}
|
|
10356
10453
|
} else {
|
|
10357
|
-
|
|
10454
|
+
logger22.error({ taskId, error }, "Failed to create task due to non-constraint error");
|
|
10358
10455
|
throw error;
|
|
10359
10456
|
}
|
|
10360
10457
|
}
|
|
10361
|
-
|
|
10458
|
+
logger22.debug(
|
|
10362
10459
|
{
|
|
10363
10460
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
10364
10461
|
executionType: "create_initial_task",
|
|
@@ -10376,7 +10473,7 @@ var ExecutionHandler = class {
|
|
|
10376
10473
|
const maxTransfers = graphConfig?.stopWhen?.transferCountIs ?? 10;
|
|
10377
10474
|
while (iterations < maxTransfers) {
|
|
10378
10475
|
iterations++;
|
|
10379
|
-
|
|
10476
|
+
logger22.info(
|
|
10380
10477
|
{ iterations, currentAgentId, graphId, conversationId, fromAgentId },
|
|
10381
10478
|
`Execution loop iteration ${iterations} with agent ${currentAgentId}, transfer from: ${fromAgentId || "none"}`
|
|
10382
10479
|
);
|
|
@@ -10384,10 +10481,10 @@ var ExecutionHandler = class {
|
|
|
10384
10481
|
scopes: { tenantId, projectId },
|
|
10385
10482
|
conversationId
|
|
10386
10483
|
});
|
|
10387
|
-
|
|
10388
|
-
if (activeAgent && activeAgent.
|
|
10389
|
-
currentAgentId = activeAgent.
|
|
10390
|
-
|
|
10484
|
+
logger22.info({ activeAgent }, "activeAgent");
|
|
10485
|
+
if (activeAgent && activeAgent.activeSubAgentId !== currentAgentId) {
|
|
10486
|
+
currentAgentId = activeAgent.activeSubAgentId;
|
|
10487
|
+
logger22.info({ currentAgentId }, `Updated current agent to: ${currentAgentId}`);
|
|
10391
10488
|
}
|
|
10392
10489
|
const agentBaseUrl = `${baseUrl}/agents`;
|
|
10393
10490
|
const a2aClient = new A2AClient(agentBaseUrl, {
|
|
@@ -10428,13 +10525,13 @@ var ExecutionHandler = class {
|
|
|
10428
10525
|
});
|
|
10429
10526
|
if (!messageResponse?.result) {
|
|
10430
10527
|
errorCount++;
|
|
10431
|
-
|
|
10528
|
+
logger22.error(
|
|
10432
10529
|
{ currentAgentId, iterations, errorCount },
|
|
10433
10530
|
`No response from agent ${currentAgentId} on iteration ${iterations} (error ${errorCount}/${this.MAX_ERRORS})`
|
|
10434
10531
|
);
|
|
10435
10532
|
if (errorCount >= this.MAX_ERRORS) {
|
|
10436
10533
|
const errorMessage2 = `Maximum error limit (${this.MAX_ERRORS}) reached`;
|
|
10437
|
-
|
|
10534
|
+
logger22.error({ maxErrors: this.MAX_ERRORS, errorCount }, errorMessage2);
|
|
10438
10535
|
await sseHelper.writeOperation(errorOp(errorMessage2, currentAgentId || "system"));
|
|
10439
10536
|
if (task) {
|
|
10440
10537
|
await agentsCore.updateTask(dbClient_default)({
|
|
@@ -10457,20 +10554,20 @@ var ExecutionHandler = class {
|
|
|
10457
10554
|
}
|
|
10458
10555
|
if (isTransferResponse(messageResponse.result)) {
|
|
10459
10556
|
const transferResponse = messageResponse.result;
|
|
10460
|
-
const
|
|
10557
|
+
const targetSubAgentId = transferResponse.artifacts?.[0]?.parts?.[0]?.data?.targetSubAgentId;
|
|
10461
10558
|
const transferReason = transferResponse.artifacts?.[0]?.parts?.[1]?.text;
|
|
10462
|
-
|
|
10559
|
+
logger22.info({ targetSubAgentId, transferReason }, "transfer response");
|
|
10463
10560
|
currentMessage = `<transfer_context> ${transferReason} </transfer_context>`;
|
|
10464
|
-
const { success,
|
|
10561
|
+
const { success, targetSubAgentId: newAgentId } = await executeTransfer({
|
|
10465
10562
|
projectId,
|
|
10466
10563
|
tenantId,
|
|
10467
10564
|
threadId: conversationId,
|
|
10468
|
-
|
|
10565
|
+
targetSubAgentId
|
|
10469
10566
|
});
|
|
10470
10567
|
if (success) {
|
|
10471
10568
|
fromAgentId = currentAgentId;
|
|
10472
10569
|
currentAgentId = newAgentId;
|
|
10473
|
-
|
|
10570
|
+
logger22.info(
|
|
10474
10571
|
{
|
|
10475
10572
|
transferFrom: fromAgentId,
|
|
10476
10573
|
transferTo: currentAgentId,
|
|
@@ -10481,14 +10578,27 @@ var ExecutionHandler = class {
|
|
|
10481
10578
|
}
|
|
10482
10579
|
continue;
|
|
10483
10580
|
}
|
|
10484
|
-
|
|
10485
|
-
|
|
10486
|
-
|
|
10581
|
+
let responseParts = [];
|
|
10582
|
+
if (messageResponse.result.streamedContent?.parts) {
|
|
10583
|
+
responseParts = messageResponse.result.streamedContent.parts;
|
|
10584
|
+
logger22.info(
|
|
10585
|
+
{ partsCount: responseParts.length },
|
|
10586
|
+
"Using streamed content for conversation history"
|
|
10587
|
+
);
|
|
10588
|
+
} else {
|
|
10589
|
+
responseParts = messageResponse.result.artifacts?.flatMap(
|
|
10590
|
+
(artifact) => artifact.parts || []
|
|
10591
|
+
) || [];
|
|
10592
|
+
logger22.info(
|
|
10593
|
+
{ partsCount: responseParts.length },
|
|
10594
|
+
"Using artifacts for conversation history (fallback)"
|
|
10595
|
+
);
|
|
10596
|
+
}
|
|
10487
10597
|
if (responseParts && responseParts.length > 0) {
|
|
10488
10598
|
const graphSessionData = graphSessionManager.getSession(requestId2);
|
|
10489
10599
|
if (graphSessionData) {
|
|
10490
10600
|
const sessionSummary = graphSessionData.getSummary();
|
|
10491
|
-
|
|
10601
|
+
logger22.info(sessionSummary, "GraphSession data after completion");
|
|
10492
10602
|
}
|
|
10493
10603
|
let textContent = "";
|
|
10494
10604
|
for (const part of responseParts) {
|
|
@@ -10520,8 +10630,7 @@ var ExecutionHandler = class {
|
|
|
10520
10630
|
},
|
|
10521
10631
|
visibility: "user-facing",
|
|
10522
10632
|
messageType: "chat",
|
|
10523
|
-
|
|
10524
|
-
fromAgentId: currentAgentId,
|
|
10633
|
+
fromSubAgentId: currentAgentId,
|
|
10525
10634
|
taskId: task.id
|
|
10526
10635
|
});
|
|
10527
10636
|
const updateTaskStart = Date.now();
|
|
@@ -10542,22 +10651,22 @@ var ExecutionHandler = class {
|
|
|
10542
10651
|
}
|
|
10543
10652
|
});
|
|
10544
10653
|
const updateTaskEnd = Date.now();
|
|
10545
|
-
|
|
10654
|
+
logger22.info(
|
|
10546
10655
|
{ duration: updateTaskEnd - updateTaskStart },
|
|
10547
10656
|
"Completed updateTask operation"
|
|
10548
10657
|
);
|
|
10549
10658
|
await sseHelper.writeOperation(completionOp(currentAgentId, iterations));
|
|
10550
10659
|
await sseHelper.complete();
|
|
10551
|
-
|
|
10660
|
+
logger22.info({}, "Ending GraphSession and cleaning up");
|
|
10552
10661
|
graphSessionManager.endSession(requestId2);
|
|
10553
|
-
|
|
10662
|
+
logger22.info({}, "Cleaning up streamHelper");
|
|
10554
10663
|
unregisterStreamHelper(requestId2);
|
|
10555
10664
|
let response;
|
|
10556
10665
|
if (sseHelper instanceof MCPStreamHelper) {
|
|
10557
10666
|
const captured = sseHelper.getCapturedResponse();
|
|
10558
10667
|
response = captured.text || "No response content";
|
|
10559
10668
|
}
|
|
10560
|
-
|
|
10669
|
+
logger22.info({}, "ExecutionHandler returning success");
|
|
10561
10670
|
return { success: true, iterations, response };
|
|
10562
10671
|
} catch (error) {
|
|
10563
10672
|
agentsCore.setSpanWithError(span, error instanceof Error ? error : new Error(String(error)));
|
|
@@ -10568,13 +10677,13 @@ var ExecutionHandler = class {
|
|
|
10568
10677
|
});
|
|
10569
10678
|
}
|
|
10570
10679
|
errorCount++;
|
|
10571
|
-
|
|
10680
|
+
logger22.warn(
|
|
10572
10681
|
{ iterations, errorCount },
|
|
10573
10682
|
`No valid response or transfer on iteration ${iterations} (error ${errorCount}/${this.MAX_ERRORS})`
|
|
10574
10683
|
);
|
|
10575
10684
|
if (errorCount >= this.MAX_ERRORS) {
|
|
10576
10685
|
const errorMessage2 = `Maximum error limit (${this.MAX_ERRORS}) reached`;
|
|
10577
|
-
|
|
10686
|
+
logger22.error({ maxErrors: this.MAX_ERRORS, errorCount }, errorMessage2);
|
|
10578
10687
|
await sseHelper.writeOperation(errorOp(errorMessage2, currentAgentId || "system"));
|
|
10579
10688
|
if (task) {
|
|
10580
10689
|
await agentsCore.updateTask(dbClient_default)({
|
|
@@ -10595,7 +10704,7 @@ var ExecutionHandler = class {
|
|
|
10595
10704
|
}
|
|
10596
10705
|
}
|
|
10597
10706
|
const errorMessage = `Maximum transfer limit (${maxTransfers}) reached without completion`;
|
|
10598
|
-
|
|
10707
|
+
logger22.error({ maxTransfers, iterations }, errorMessage);
|
|
10599
10708
|
await sseHelper.writeOperation(errorOp(errorMessage, currentAgentId || "system"));
|
|
10600
10709
|
if (task) {
|
|
10601
10710
|
await agentsCore.updateTask(dbClient_default)({
|
|
@@ -10614,7 +10723,7 @@ var ExecutionHandler = class {
|
|
|
10614
10723
|
unregisterStreamHelper(requestId2);
|
|
10615
10724
|
return { success: false, error: errorMessage, iterations };
|
|
10616
10725
|
} catch (error) {
|
|
10617
|
-
|
|
10726
|
+
logger22.error({ error }, "Error in execution handler");
|
|
10618
10727
|
const errorMessage = error instanceof Error ? error.message : "Unknown execution error";
|
|
10619
10728
|
await sseHelper.writeOperation(
|
|
10620
10729
|
errorOp(`Execution error: ${errorMessage}`, currentAgentId || "system")
|
|
@@ -10642,7 +10751,7 @@ var ExecutionHandler = class {
|
|
|
10642
10751
|
// src/routes/chat.ts
|
|
10643
10752
|
init_logger();
|
|
10644
10753
|
var app2 = new zodOpenapi.OpenAPIHono();
|
|
10645
|
-
var
|
|
10754
|
+
var logger23 = agentsCore.getLogger("completionsHandler");
|
|
10646
10755
|
var chatCompletionsRoute = zodOpenapi.createRoute({
|
|
10647
10756
|
method: "post",
|
|
10648
10757
|
path: "/completions",
|
|
@@ -10760,7 +10869,7 @@ app2.openapi(chatCompletionsRoute, async (c) => {
|
|
|
10760
10869
|
tracestate: c.req.header("tracestate"),
|
|
10761
10870
|
baggage: c.req.header("baggage")
|
|
10762
10871
|
};
|
|
10763
|
-
|
|
10872
|
+
logger23.info(
|
|
10764
10873
|
{
|
|
10765
10874
|
otelHeaders,
|
|
10766
10875
|
path: c.req.path,
|
|
@@ -10784,20 +10893,20 @@ app2.openapi(chatCompletionsRoute, async (c) => {
|
|
|
10784
10893
|
scopes: { tenantId, projectId, graphId }
|
|
10785
10894
|
});
|
|
10786
10895
|
let agentGraph;
|
|
10787
|
-
let
|
|
10896
|
+
let defaultSubAgentId;
|
|
10788
10897
|
if (fullGraph) {
|
|
10789
10898
|
agentGraph = {
|
|
10790
10899
|
id: fullGraph.id,
|
|
10791
10900
|
name: fullGraph.name,
|
|
10792
10901
|
tenantId,
|
|
10793
10902
|
projectId,
|
|
10794
|
-
|
|
10903
|
+
defaultSubAgentId: fullGraph.defaultSubAgentId
|
|
10795
10904
|
};
|
|
10796
|
-
const agentKeys = Object.keys(fullGraph.
|
|
10905
|
+
const agentKeys = Object.keys(fullGraph.subAgents || {});
|
|
10797
10906
|
const firstAgentId = agentKeys.length > 0 ? agentKeys[0] : "";
|
|
10798
|
-
|
|
10907
|
+
defaultSubAgentId = fullGraph.defaultSubAgentId || firstAgentId;
|
|
10799
10908
|
} else {
|
|
10800
|
-
agentGraph = await agentsCore.
|
|
10909
|
+
agentGraph = await agentsCore.getAgentGraphWithDefaultSubAgent(dbClient_default)({
|
|
10801
10910
|
scopes: { tenantId, projectId, graphId }
|
|
10802
10911
|
});
|
|
10803
10912
|
if (!agentGraph) {
|
|
@@ -10806,9 +10915,9 @@ app2.openapi(chatCompletionsRoute, async (c) => {
|
|
|
10806
10915
|
message: "Agent graph not found"
|
|
10807
10916
|
});
|
|
10808
10917
|
}
|
|
10809
|
-
|
|
10918
|
+
defaultSubAgentId = agentGraph.defaultSubAgentId || "";
|
|
10810
10919
|
}
|
|
10811
|
-
if (!
|
|
10920
|
+
if (!defaultSubAgentId) {
|
|
10812
10921
|
throw agentsCore.createApiError({
|
|
10813
10922
|
code: "not_found",
|
|
10814
10923
|
message: "No default agent found in graph"
|
|
@@ -10818,7 +10927,7 @@ app2.openapi(chatCompletionsRoute, async (c) => {
|
|
|
10818
10927
|
tenantId,
|
|
10819
10928
|
projectId,
|
|
10820
10929
|
id: conversationId,
|
|
10821
|
-
|
|
10930
|
+
activeSubAgentId: defaultSubAgentId
|
|
10822
10931
|
});
|
|
10823
10932
|
const activeAgent = await agentsCore.getActiveAgentForConversation(dbClient_default)({
|
|
10824
10933
|
scopes: { tenantId, projectId },
|
|
@@ -10828,13 +10937,13 @@ app2.openapi(chatCompletionsRoute, async (c) => {
|
|
|
10828
10937
|
agentsCore.setActiveAgentForConversation(dbClient_default)({
|
|
10829
10938
|
scopes: { tenantId, projectId },
|
|
10830
10939
|
conversationId,
|
|
10831
|
-
|
|
10940
|
+
subAgentId: defaultSubAgentId
|
|
10832
10941
|
});
|
|
10833
10942
|
}
|
|
10834
|
-
const
|
|
10835
|
-
const agentInfo = await agentsCore.
|
|
10943
|
+
const subAgentId = activeAgent?.activeSubAgentId || defaultSubAgentId;
|
|
10944
|
+
const agentInfo = await agentsCore.getSubAgentById(dbClient_default)({
|
|
10836
10945
|
scopes: { tenantId, projectId, graphId },
|
|
10837
|
-
|
|
10946
|
+
subAgentId
|
|
10838
10947
|
});
|
|
10839
10948
|
if (!agentInfo) {
|
|
10840
10949
|
throw agentsCore.createApiError({
|
|
@@ -10853,14 +10962,14 @@ app2.openapi(chatCompletionsRoute, async (c) => {
|
|
|
10853
10962
|
dbClient: dbClient_default,
|
|
10854
10963
|
credentialStores
|
|
10855
10964
|
});
|
|
10856
|
-
|
|
10965
|
+
logger23.info(
|
|
10857
10966
|
{
|
|
10858
10967
|
tenantId,
|
|
10859
10968
|
projectId,
|
|
10860
10969
|
graphId,
|
|
10861
10970
|
conversationId,
|
|
10862
|
-
|
|
10863
|
-
|
|
10971
|
+
defaultSubAgentId,
|
|
10972
|
+
activeSubAgentId: activeAgent?.activeSubAgentId || "none",
|
|
10864
10973
|
hasContextConfig: !!agentGraph.contextConfigId,
|
|
10865
10974
|
hasHeaders: !!body.headers,
|
|
10866
10975
|
hasValidatedContext: !!validatedContext,
|
|
@@ -10901,7 +11010,7 @@ app2.openapi(chatCompletionsRoute, async (c) => {
|
|
|
10901
11010
|
try {
|
|
10902
11011
|
const sseHelper = createSSEStreamHelper(stream2, requestId2, timestamp);
|
|
10903
11012
|
await sseHelper.writeRole();
|
|
10904
|
-
|
|
11013
|
+
logger23.info({ subAgentId }, "Starting execution");
|
|
10905
11014
|
const emitOperationsHeader = c.req.header("x-emit-operations");
|
|
10906
11015
|
const emitOperations = emitOperationsHeader === "true";
|
|
10907
11016
|
const executionHandler = new ExecutionHandler();
|
|
@@ -10909,12 +11018,12 @@ app2.openapi(chatCompletionsRoute, async (c) => {
|
|
|
10909
11018
|
executionContext,
|
|
10910
11019
|
conversationId,
|
|
10911
11020
|
userMessage,
|
|
10912
|
-
initialAgentId:
|
|
11021
|
+
initialAgentId: subAgentId,
|
|
10913
11022
|
requestId: requestId2,
|
|
10914
11023
|
sseHelper,
|
|
10915
11024
|
emitOperations
|
|
10916
11025
|
});
|
|
10917
|
-
|
|
11026
|
+
logger23.info(
|
|
10918
11027
|
{ result },
|
|
10919
11028
|
`Execution completed: ${result.success ? "success" : "failed"} after ${result.iterations} iterations`
|
|
10920
11029
|
);
|
|
@@ -10928,7 +11037,7 @@ app2.openapi(chatCompletionsRoute, async (c) => {
|
|
|
10928
11037
|
}
|
|
10929
11038
|
await sseHelper.complete();
|
|
10930
11039
|
} catch (error) {
|
|
10931
|
-
|
|
11040
|
+
logger23.error(
|
|
10932
11041
|
{
|
|
10933
11042
|
error: error instanceof Error ? error.message : error,
|
|
10934
11043
|
stack: error instanceof Error ? error.stack : void 0
|
|
@@ -10945,12 +11054,12 @@ app2.openapi(chatCompletionsRoute, async (c) => {
|
|
|
10945
11054
|
);
|
|
10946
11055
|
await sseHelper.complete();
|
|
10947
11056
|
} catch (streamError) {
|
|
10948
|
-
|
|
11057
|
+
logger23.error({ streamError }, "Failed to write error to stream");
|
|
10949
11058
|
}
|
|
10950
11059
|
}
|
|
10951
11060
|
});
|
|
10952
11061
|
} catch (error) {
|
|
10953
|
-
|
|
11062
|
+
logger23.error(
|
|
10954
11063
|
{
|
|
10955
11064
|
error: error instanceof Error ? error.message : error,
|
|
10956
11065
|
stack: error instanceof Error ? error.stack : void 0
|
|
@@ -10978,7 +11087,7 @@ var chat_default = app2;
|
|
|
10978
11087
|
init_dbClient();
|
|
10979
11088
|
init_logger();
|
|
10980
11089
|
var app3 = new zodOpenapi.OpenAPIHono();
|
|
10981
|
-
var
|
|
11090
|
+
var logger24 = agentsCore.getLogger("chatDataStream");
|
|
10982
11091
|
var chatDataStreamRoute = zodOpenapi.createRoute({
|
|
10983
11092
|
method: "post",
|
|
10984
11093
|
path: "/chat",
|
|
@@ -11043,7 +11152,7 @@ app3.openapi(chatDataStreamRoute, async (c) => {
|
|
|
11043
11152
|
"project.id": projectId
|
|
11044
11153
|
});
|
|
11045
11154
|
}
|
|
11046
|
-
const agentGraph = await agentsCore.
|
|
11155
|
+
const agentGraph = await agentsCore.getAgentGraphWithDefaultSubAgent(dbClient_default)({
|
|
11047
11156
|
scopes: { tenantId, projectId, graphId }
|
|
11048
11157
|
});
|
|
11049
11158
|
if (!agentGraph) {
|
|
@@ -11052,9 +11161,9 @@ app3.openapi(chatDataStreamRoute, async (c) => {
|
|
|
11052
11161
|
message: "Agent graph not found"
|
|
11053
11162
|
});
|
|
11054
11163
|
}
|
|
11055
|
-
const
|
|
11164
|
+
const defaultSubAgentId = agentGraph.defaultSubAgentId;
|
|
11056
11165
|
const graphName = agentGraph.name;
|
|
11057
|
-
if (!
|
|
11166
|
+
if (!defaultSubAgentId) {
|
|
11058
11167
|
throw agentsCore.createApiError({
|
|
11059
11168
|
code: "bad_request",
|
|
11060
11169
|
message: "Graph does not have a default agent configured"
|
|
@@ -11068,13 +11177,13 @@ app3.openapi(chatDataStreamRoute, async (c) => {
|
|
|
11068
11177
|
agentsCore.setActiveAgentForConversation(dbClient_default)({
|
|
11069
11178
|
scopes: { tenantId, projectId },
|
|
11070
11179
|
conversationId,
|
|
11071
|
-
|
|
11180
|
+
subAgentId: defaultSubAgentId
|
|
11072
11181
|
});
|
|
11073
11182
|
}
|
|
11074
|
-
const
|
|
11075
|
-
const agentInfo = await agentsCore.
|
|
11183
|
+
const subAgentId = activeAgent?.activeSubAgentId || defaultSubAgentId;
|
|
11184
|
+
const agentInfo = await agentsCore.getSubAgentById(dbClient_default)({
|
|
11076
11185
|
scopes: { tenantId, projectId, graphId },
|
|
11077
|
-
|
|
11186
|
+
subAgentId
|
|
11078
11187
|
});
|
|
11079
11188
|
if (!agentInfo) {
|
|
11080
11189
|
throw agentsCore.createApiError({
|
|
@@ -11095,7 +11204,7 @@ app3.openapi(chatDataStreamRoute, async (c) => {
|
|
|
11095
11204
|
});
|
|
11096
11205
|
const lastUserMessage = body.messages.filter((m) => m.role === "user").slice(-1)[0];
|
|
11097
11206
|
const userText = typeof lastUserMessage?.content === "string" ? lastUserMessage.content : lastUserMessage?.parts?.map((p) => p.text).join("") || "";
|
|
11098
|
-
|
|
11207
|
+
logger24.info({ userText, lastUserMessage }, "userText");
|
|
11099
11208
|
const messageSpan = api.trace.getActiveSpan();
|
|
11100
11209
|
if (messageSpan) {
|
|
11101
11210
|
messageSpan.setAttributes({
|
|
@@ -11131,7 +11240,7 @@ app3.openapi(chatDataStreamRoute, async (c) => {
|
|
|
11131
11240
|
executionContext,
|
|
11132
11241
|
conversationId,
|
|
11133
11242
|
userMessage: userText,
|
|
11134
|
-
initialAgentId:
|
|
11243
|
+
initialAgentId: subAgentId,
|
|
11135
11244
|
requestId: `chatds-${Date.now()}`,
|
|
11136
11245
|
sseHelper: streamHelper,
|
|
11137
11246
|
emitOperations
|
|
@@ -11140,7 +11249,7 @@ app3.openapi(chatDataStreamRoute, async (c) => {
|
|
|
11140
11249
|
await streamHelper.writeOperation(errorOp("Unable to process request", "system"));
|
|
11141
11250
|
}
|
|
11142
11251
|
} catch (err) {
|
|
11143
|
-
|
|
11252
|
+
logger24.error({ err }, "Streaming error");
|
|
11144
11253
|
await streamHelper.writeOperation(errorOp("Internal server error", "system"));
|
|
11145
11254
|
} finally {
|
|
11146
11255
|
if ("cleanup" in streamHelper && typeof streamHelper.cleanup === "function") {
|
|
@@ -11161,7 +11270,7 @@ app3.openapi(chatDataStreamRoute, async (c) => {
|
|
|
11161
11270
|
)
|
|
11162
11271
|
);
|
|
11163
11272
|
} catch (error) {
|
|
11164
|
-
|
|
11273
|
+
logger24.error({ error }, "chatDataStream error");
|
|
11165
11274
|
throw agentsCore.createApiError({
|
|
11166
11275
|
code: "internal_server_error",
|
|
11167
11276
|
message: "Failed to process chat completion"
|
|
@@ -11176,7 +11285,7 @@ init_logger();
|
|
|
11176
11285
|
function createMCPSchema(schema) {
|
|
11177
11286
|
return schema;
|
|
11178
11287
|
}
|
|
11179
|
-
var
|
|
11288
|
+
var logger25 = agentsCore.getLogger("mcp");
|
|
11180
11289
|
var _MockResponseSingleton = class _MockResponseSingleton {
|
|
11181
11290
|
constructor() {
|
|
11182
11291
|
__publicField(this, "mockRes");
|
|
@@ -11231,21 +11340,21 @@ var createSpoofInitMessage = (mcpProtocolVersion) => ({
|
|
|
11231
11340
|
id: 0
|
|
11232
11341
|
});
|
|
11233
11342
|
var spoofTransportInitialization = async (transport, req, sessionId, mcpProtocolVersion) => {
|
|
11234
|
-
|
|
11343
|
+
logger25.info({ sessionId }, "Spoofing initialization message to set transport state");
|
|
11235
11344
|
const spoofInitMessage = createSpoofInitMessage(mcpProtocolVersion);
|
|
11236
11345
|
const mockRes = MockResponseSingleton.getInstance().getMockResponse();
|
|
11237
11346
|
try {
|
|
11238
11347
|
await transport.handleRequest(req, mockRes, spoofInitMessage);
|
|
11239
|
-
|
|
11348
|
+
logger25.info({ sessionId }, "Successfully spoofed initialization");
|
|
11240
11349
|
} catch (spoofError) {
|
|
11241
|
-
|
|
11350
|
+
logger25.warn({ sessionId, error: spoofError }, "Spoof initialization failed, continuing anyway");
|
|
11242
11351
|
}
|
|
11243
11352
|
};
|
|
11244
11353
|
var validateSession = async (req, res, body, tenantId, projectId, graphId) => {
|
|
11245
11354
|
const sessionId = req.headers["mcp-session-id"];
|
|
11246
|
-
|
|
11355
|
+
logger25.info({ sessionId }, "Received MCP session ID");
|
|
11247
11356
|
if (!sessionId) {
|
|
11248
|
-
|
|
11357
|
+
logger25.info({ body }, "Missing session ID");
|
|
11249
11358
|
res.writeHead(400).end(
|
|
11250
11359
|
JSON.stringify({
|
|
11251
11360
|
jsonrpc: "2.0",
|
|
@@ -11271,7 +11380,7 @@ var validateSession = async (req, res, body, tenantId, projectId, graphId) => {
|
|
|
11271
11380
|
scopes: { tenantId, projectId },
|
|
11272
11381
|
conversationId: sessionId
|
|
11273
11382
|
});
|
|
11274
|
-
|
|
11383
|
+
logger25.info(
|
|
11275
11384
|
{
|
|
11276
11385
|
sessionId,
|
|
11277
11386
|
conversationFound: !!conversation,
|
|
@@ -11282,7 +11391,7 @@ var validateSession = async (req, res, body, tenantId, projectId, graphId) => {
|
|
|
11282
11391
|
"Conversation lookup result"
|
|
11283
11392
|
);
|
|
11284
11393
|
if (!conversation || conversation.metadata?.sessionData?.sessionType !== "mcp" || conversation.metadata?.sessionData?.graphId !== graphId) {
|
|
11285
|
-
|
|
11394
|
+
logger25.info(
|
|
11286
11395
|
{ sessionId, conversationId: conversation?.id },
|
|
11287
11396
|
"MCP session not found or invalid"
|
|
11288
11397
|
);
|
|
@@ -11331,7 +11440,7 @@ var processUserMessage = async (tenantId, projectId, conversationId, query) => {
|
|
|
11331
11440
|
messageType: "chat"
|
|
11332
11441
|
});
|
|
11333
11442
|
};
|
|
11334
|
-
var executeAgentQuery = async (executionContext, conversationId, query,
|
|
11443
|
+
var executeAgentQuery = async (executionContext, conversationId, query, defaultSubAgentId) => {
|
|
11335
11444
|
const requestId2 = `mcp-${Date.now()}`;
|
|
11336
11445
|
const mcpStreamHelper = createMCPStreamHelper();
|
|
11337
11446
|
const executionHandler = new ExecutionHandler();
|
|
@@ -11339,11 +11448,11 @@ var executeAgentQuery = async (executionContext, conversationId, query, defaultA
|
|
|
11339
11448
|
executionContext,
|
|
11340
11449
|
conversationId,
|
|
11341
11450
|
userMessage: query,
|
|
11342
|
-
initialAgentId:
|
|
11451
|
+
initialAgentId: defaultSubAgentId,
|
|
11343
11452
|
requestId: requestId2,
|
|
11344
11453
|
sseHelper: mcpStreamHelper
|
|
11345
11454
|
});
|
|
11346
|
-
|
|
11455
|
+
logger25.info(
|
|
11347
11456
|
{ result },
|
|
11348
11457
|
`Execution completed: ${result.success ? "success" : "failed"} after ${result.iterations} iterations`
|
|
11349
11458
|
);
|
|
@@ -11370,7 +11479,7 @@ var executeAgentQuery = async (executionContext, conversationId, query, defaultA
|
|
|
11370
11479
|
var getServer = async (headers, executionContext, conversationId, credentialStores) => {
|
|
11371
11480
|
const { tenantId, projectId, graphId } = executionContext;
|
|
11372
11481
|
setupTracing(conversationId, tenantId, graphId);
|
|
11373
|
-
const agentGraph = await agentsCore.
|
|
11482
|
+
const agentGraph = await agentsCore.getAgentGraphWithDefaultSubAgent(dbClient_default)({
|
|
11374
11483
|
scopes: { tenantId, projectId, graphId }
|
|
11375
11484
|
});
|
|
11376
11485
|
if (!agentGraph) {
|
|
@@ -11391,7 +11500,7 @@ var getServer = async (headers, executionContext, conversationId, credentialStor
|
|
|
11391
11500
|
},
|
|
11392
11501
|
async ({ query }) => {
|
|
11393
11502
|
try {
|
|
11394
|
-
if (!agentGraph.
|
|
11503
|
+
if (!agentGraph.defaultSubAgentId) {
|
|
11395
11504
|
return {
|
|
11396
11505
|
content: [
|
|
11397
11506
|
{
|
|
@@ -11402,10 +11511,10 @@ var getServer = async (headers, executionContext, conversationId, credentialStor
|
|
|
11402
11511
|
isError: true
|
|
11403
11512
|
};
|
|
11404
11513
|
}
|
|
11405
|
-
const
|
|
11406
|
-
const agentInfo = await agentsCore.
|
|
11514
|
+
const defaultSubAgentId = agentGraph.defaultSubAgentId;
|
|
11515
|
+
const agentInfo = await agentsCore.getSubAgentById(dbClient_default)({
|
|
11407
11516
|
scopes: { tenantId, projectId, graphId },
|
|
11408
|
-
|
|
11517
|
+
subAgentId: defaultSubAgentId
|
|
11409
11518
|
});
|
|
11410
11519
|
if (!agentInfo) {
|
|
11411
11520
|
return {
|
|
@@ -11427,7 +11536,7 @@ var getServer = async (headers, executionContext, conversationId, credentialStor
|
|
|
11427
11536
|
dbClient: dbClient_default,
|
|
11428
11537
|
credentialStores
|
|
11429
11538
|
});
|
|
11430
|
-
|
|
11539
|
+
logger25.info(
|
|
11431
11540
|
{
|
|
11432
11541
|
tenantId,
|
|
11433
11542
|
projectId,
|
|
@@ -11440,7 +11549,7 @@ var getServer = async (headers, executionContext, conversationId, credentialStor
|
|
|
11440
11549
|
"parameters"
|
|
11441
11550
|
);
|
|
11442
11551
|
await processUserMessage(tenantId, projectId, conversationId, query);
|
|
11443
|
-
return executeAgentQuery(executionContext, conversationId, query,
|
|
11552
|
+
return executeAgentQuery(executionContext, conversationId, query, defaultSubAgentId);
|
|
11444
11553
|
} catch (error) {
|
|
11445
11554
|
return {
|
|
11446
11555
|
content: [
|
|
@@ -11489,9 +11598,9 @@ var validateRequestParameters = (c) => {
|
|
|
11489
11598
|
};
|
|
11490
11599
|
var handleInitializationRequest = async (body, executionContext, validatedContext, req, res, c, credentialStores) => {
|
|
11491
11600
|
const { tenantId, projectId, graphId } = executionContext;
|
|
11492
|
-
|
|
11601
|
+
logger25.info({ body }, "Received initialization request");
|
|
11493
11602
|
const sessionId = agentsCore.getConversationId();
|
|
11494
|
-
const agentGraph = await agentsCore.
|
|
11603
|
+
const agentGraph = await agentsCore.getAgentGraphWithDefaultSubAgent(dbClient_default)({
|
|
11495
11604
|
scopes: { tenantId, projectId, graphId }
|
|
11496
11605
|
});
|
|
11497
11606
|
if (!agentGraph) {
|
|
@@ -11504,7 +11613,7 @@ var handleInitializationRequest = async (body, executionContext, validatedContex
|
|
|
11504
11613
|
{ status: 404 }
|
|
11505
11614
|
);
|
|
11506
11615
|
}
|
|
11507
|
-
if (!agentGraph.
|
|
11616
|
+
if (!agentGraph.defaultSubAgentId) {
|
|
11508
11617
|
return c.json(
|
|
11509
11618
|
{
|
|
11510
11619
|
jsonrpc: "2.0",
|
|
@@ -11518,7 +11627,7 @@ var handleInitializationRequest = async (body, executionContext, validatedContex
|
|
|
11518
11627
|
id: sessionId,
|
|
11519
11628
|
tenantId,
|
|
11520
11629
|
projectId,
|
|
11521
|
-
|
|
11630
|
+
activeSubAgentId: agentGraph.defaultSubAgentId,
|
|
11522
11631
|
metadata: {
|
|
11523
11632
|
sessionData: {
|
|
11524
11633
|
graphId,
|
|
@@ -11529,7 +11638,7 @@ var handleInitializationRequest = async (body, executionContext, validatedContex
|
|
|
11529
11638
|
}
|
|
11530
11639
|
}
|
|
11531
11640
|
});
|
|
11532
|
-
|
|
11641
|
+
logger25.info(
|
|
11533
11642
|
{ sessionId, conversationId: conversation.id },
|
|
11534
11643
|
"Created MCP session as conversation"
|
|
11535
11644
|
);
|
|
@@ -11538,9 +11647,9 @@ var handleInitializationRequest = async (body, executionContext, validatedContex
|
|
|
11538
11647
|
});
|
|
11539
11648
|
const server = await getServer(validatedContext, executionContext, sessionId, credentialStores);
|
|
11540
11649
|
await server.connect(transport);
|
|
11541
|
-
|
|
11650
|
+
logger25.info({ sessionId }, "Server connected for initialization");
|
|
11542
11651
|
res.setHeader("Mcp-Session-Id", sessionId);
|
|
11543
|
-
|
|
11652
|
+
logger25.info(
|
|
11544
11653
|
{
|
|
11545
11654
|
sessionId,
|
|
11546
11655
|
bodyMethod: body?.method,
|
|
@@ -11549,7 +11658,7 @@ var handleInitializationRequest = async (body, executionContext, validatedContex
|
|
|
11549
11658
|
"About to handle initialization request"
|
|
11550
11659
|
);
|
|
11551
11660
|
await transport.handleRequest(req, res, body);
|
|
11552
|
-
|
|
11661
|
+
logger25.info({ sessionId }, "Successfully handled initialization request");
|
|
11553
11662
|
return fetchToNode.toFetchResponse(res);
|
|
11554
11663
|
};
|
|
11555
11664
|
var handleExistingSessionRequest = async (body, executionContext, validatedContext, req, res, credentialStores) => {
|
|
@@ -11577,8 +11686,8 @@ var handleExistingSessionRequest = async (body, executionContext, validatedConte
|
|
|
11577
11686
|
sessionId,
|
|
11578
11687
|
conversation.metadata?.session_data?.mcpProtocolVersion
|
|
11579
11688
|
);
|
|
11580
|
-
|
|
11581
|
-
|
|
11689
|
+
logger25.info({ sessionId }, "Server connected and transport initialized");
|
|
11690
|
+
logger25.info(
|
|
11582
11691
|
{
|
|
11583
11692
|
sessionId,
|
|
11584
11693
|
bodyKeys: Object.keys(body || {}),
|
|
@@ -11592,9 +11701,9 @@ var handleExistingSessionRequest = async (body, executionContext, validatedConte
|
|
|
11592
11701
|
);
|
|
11593
11702
|
try {
|
|
11594
11703
|
await transport.handleRequest(req, res, body);
|
|
11595
|
-
|
|
11704
|
+
logger25.info({ sessionId }, "Successfully handled MCP request");
|
|
11596
11705
|
} catch (transportError) {
|
|
11597
|
-
|
|
11706
|
+
logger25.error(
|
|
11598
11707
|
{
|
|
11599
11708
|
sessionId,
|
|
11600
11709
|
error: transportError,
|
|
@@ -11645,13 +11754,13 @@ app4.openapi(
|
|
|
11645
11754
|
}
|
|
11646
11755
|
const { executionContext } = paramValidation;
|
|
11647
11756
|
const body = c.get("requestBody") || {};
|
|
11648
|
-
|
|
11757
|
+
logger25.info({ body, bodyKeys: Object.keys(body || {}) }, "Parsed request body");
|
|
11649
11758
|
const isInitRequest = body.method === "initialize";
|
|
11650
11759
|
const { req, res } = fetchToNode.toReqRes(c.req.raw);
|
|
11651
11760
|
const validatedContext = c.get("validatedContext") || {};
|
|
11652
11761
|
const credentialStores = c.get("credentialStores");
|
|
11653
|
-
|
|
11654
|
-
|
|
11762
|
+
logger25.info({ validatedContext }, "Validated context");
|
|
11763
|
+
logger25.info({ req }, "request");
|
|
11655
11764
|
if (isInitRequest) {
|
|
11656
11765
|
return await handleInitializationRequest(
|
|
11657
11766
|
body,
|
|
@@ -11673,7 +11782,7 @@ app4.openapi(
|
|
|
11673
11782
|
);
|
|
11674
11783
|
}
|
|
11675
11784
|
} catch (e) {
|
|
11676
|
-
|
|
11785
|
+
logger25.error(
|
|
11677
11786
|
{
|
|
11678
11787
|
error: e instanceof Error ? e.message : e,
|
|
11679
11788
|
stack: e instanceof Error ? e.stack : void 0
|
|
@@ -11685,7 +11794,7 @@ app4.openapi(
|
|
|
11685
11794
|
}
|
|
11686
11795
|
);
|
|
11687
11796
|
app4.get("/", async (c) => {
|
|
11688
|
-
|
|
11797
|
+
logger25.info({}, "Received GET MCP request");
|
|
11689
11798
|
return c.json(
|
|
11690
11799
|
{
|
|
11691
11800
|
jsonrpc: "2.0",
|
|
@@ -11699,7 +11808,7 @@ app4.get("/", async (c) => {
|
|
|
11699
11808
|
);
|
|
11700
11809
|
});
|
|
11701
11810
|
app4.delete("/", async (c) => {
|
|
11702
|
-
|
|
11811
|
+
logger25.info({}, "Received DELETE MCP request");
|
|
11703
11812
|
return c.json(
|
|
11704
11813
|
{
|
|
11705
11814
|
jsonrpc: "2.0",
|
|
@@ -11712,7 +11821,7 @@ app4.delete("/", async (c) => {
|
|
|
11712
11821
|
var mcp_default = app4;
|
|
11713
11822
|
|
|
11714
11823
|
// src/app.ts
|
|
11715
|
-
var
|
|
11824
|
+
var logger26 = agentsCore.getLogger("agents-run-api");
|
|
11716
11825
|
function createExecutionHono(serverConfig, credentialStores) {
|
|
11717
11826
|
const app6 = new zodOpenapi.OpenAPIHono();
|
|
11718
11827
|
app6.use("*", otel.otel());
|
|
@@ -11728,7 +11837,7 @@ function createExecutionHono(serverConfig, credentialStores) {
|
|
|
11728
11837
|
const body = await c.req.json();
|
|
11729
11838
|
c.set("requestBody", body);
|
|
11730
11839
|
} catch (error) {
|
|
11731
|
-
|
|
11840
|
+
logger26.debug({ error }, "Failed to parse JSON body, continuing without parsed body");
|
|
11732
11841
|
}
|
|
11733
11842
|
}
|
|
11734
11843
|
return next();
|
|
@@ -11779,8 +11888,8 @@ function createExecutionHono(serverConfig, credentialStores) {
|
|
|
11779
11888
|
if (!isExpectedError) {
|
|
11780
11889
|
const errorMessage = err instanceof Error ? err.message : String(err);
|
|
11781
11890
|
const errorStack = err instanceof Error ? err.stack : void 0;
|
|
11782
|
-
if (
|
|
11783
|
-
|
|
11891
|
+
if (logger26) {
|
|
11892
|
+
logger26.error(
|
|
11784
11893
|
{
|
|
11785
11894
|
error: err,
|
|
11786
11895
|
message: errorMessage,
|
|
@@ -11792,8 +11901,8 @@ function createExecutionHono(serverConfig, credentialStores) {
|
|
|
11792
11901
|
);
|
|
11793
11902
|
}
|
|
11794
11903
|
} else {
|
|
11795
|
-
if (
|
|
11796
|
-
|
|
11904
|
+
if (logger26) {
|
|
11905
|
+
logger26.error(
|
|
11797
11906
|
{
|
|
11798
11907
|
error: err,
|
|
11799
11908
|
path: c.req.path,
|
|
@@ -11810,8 +11919,8 @@ function createExecutionHono(serverConfig, credentialStores) {
|
|
|
11810
11919
|
const response = err.getResponse();
|
|
11811
11920
|
return response;
|
|
11812
11921
|
} catch (responseError) {
|
|
11813
|
-
if (
|
|
11814
|
-
|
|
11922
|
+
if (logger26) {
|
|
11923
|
+
logger26.error({ error: responseError }, "Error while handling HTTPException response");
|
|
11815
11924
|
}
|
|
11816
11925
|
}
|
|
11817
11926
|
}
|
|
@@ -11845,7 +11954,7 @@ function createExecutionHono(serverConfig, credentialStores) {
|
|
|
11845
11954
|
app6.use("*", async (c, next) => {
|
|
11846
11955
|
const executionContext = c.get("executionContext");
|
|
11847
11956
|
if (!executionContext) {
|
|
11848
|
-
|
|
11957
|
+
logger26.debug({}, "Empty execution context");
|
|
11849
11958
|
return next();
|
|
11850
11959
|
}
|
|
11851
11960
|
const { tenantId, projectId, graphId } = executionContext;
|
|
@@ -11854,7 +11963,7 @@ function createExecutionHono(serverConfig, credentialStores) {
|
|
|
11854
11963
|
if (requestBody) {
|
|
11855
11964
|
conversationId = requestBody.conversationId;
|
|
11856
11965
|
if (!conversationId) {
|
|
11857
|
-
|
|
11966
|
+
logger26.debug({ requestBody }, "No conversation ID found in request body");
|
|
11858
11967
|
}
|
|
11859
11968
|
}
|
|
11860
11969
|
const entries = Object.fromEntries(
|
|
@@ -11869,7 +11978,7 @@ function createExecutionHono(serverConfig, credentialStores) {
|
|
|
11869
11978
|
})
|
|
11870
11979
|
);
|
|
11871
11980
|
if (!Object.keys(entries).length) {
|
|
11872
|
-
|
|
11981
|
+
logger26.debug({}, "Empty entries for baggage");
|
|
11873
11982
|
return next();
|
|
11874
11983
|
}
|
|
11875
11984
|
const bag = Object.entries(entries).reduce(
|