@inkeep/agents-run-api 0.18.0 → 0.19.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/index.js CHANGED
@@ -1,10 +1,10 @@
1
1
  import { flushBatchProcessor } from './chunk-XO4RG36I.js';
2
2
  import { getLogger } from './chunk-A2S7GSHL.js';
3
- import { getFormattedConversationHistory, createDefaultConversationHistoryConfig, saveA2AMessageResponse } from './chunk-DQQRVSJS.js';
3
+ import { getFormattedConversationHistory, createDefaultConversationHistoryConfig, saveA2AMessageResponse } from './chunk-QRT6EIUX.js';
4
4
  import { dbClient_default } from './chunk-7IMXW4RD.js';
5
5
  import { env } from './chunk-NZHNG4A3.js';
6
6
  import { __publicField } from './chunk-PKBMQBKP.js';
7
- import { getTracer, HeadersScopeSchema, getRequestExecutionContext, createApiError, getAgentGraphWithDefaultSubAgent, contextValidationMiddleware, getConversationId, getFullGraph, createOrGetConversation, getActiveAgentForConversation, setActiveAgentForConversation, getSubAgentById, handleContextResolution, createMessage, commonGetErrorResponses, loggerFactory, createDefaultCredentialStores, CredentialStoreRegistry, listTaskIdsByContextId, getTask, getLedgerArtifacts, upsertLedgerArtifact, getAgentGraphById, createTask, updateTask, setSpanWithError, updateConversation, handleApiError, TaskState, setActiveAgentForThread, getConversation, getRelatedAgentsForGraph, getToolsForAgent, getDataComponentsForAgent, getArtifactComponentsForAgent, dbResultToMcpTool, validateAndGetApiKey, getProject, ContextResolver, CredentialStuffer, MCPServerType, getCredentialReference, McpClient, getFunctionToolsForSubAgent, getFunction, getContextConfigById, getFullGraphDefinition, TemplateEngine, graphHasArtifactComponents, MCPTransportType, SPAN_KEYS, getExternalAgent } from '@inkeep/agents-core';
7
+ import { getTracer, HeadersScopeSchema, getRequestExecutionContext, createApiError, getAgentWithDefaultSubAgent, contextValidationMiddleware, getConversationId, getFullAgent, createOrGetConversation, getActiveAgentForConversation, setActiveAgentForConversation, getSubAgentById, handleContextResolution, createMessage, commonGetErrorResponses, loggerFactory, createDefaultCredentialStores, CredentialStoreRegistry, listTaskIdsByContextId, getTask, getLedgerArtifacts, upsertLedgerArtifact, createTask, updateTask, setSpanWithError, updateConversation, handleApiError, TaskState, setActiveAgentForThread, getConversation, getAgentById, getRelatedAgentsForAgent, getToolsForAgent, getDataComponentsForAgent, getArtifactComponentsForAgent, dbResultToMcpTool, validateAndGetApiKey, getProject, ContextResolver, CredentialStuffer, MCPServerType, getCredentialReference, McpClient, getFunctionToolsForSubAgent, getFunction, getContextConfigById, getFullAgentDefinition, TemplateEngine, agentHasArtifactComponents, MCPTransportType, SPAN_KEYS, getExternalAgent } from '@inkeep/agents-core';
8
8
  import { otel } from '@hono/otel';
9
9
  import { OpenAPIHono, createRoute, z as z$1 } from '@hono/zod-openapi';
10
10
  import { trace, propagation, context, SpanStatusCode } from '@opentelemetry/api';
@@ -38,7 +38,7 @@ function createExecutionContext(params) {
38
38
  apiKey: params.apiKey,
39
39
  tenantId: params.tenantId,
40
40
  projectId: params.projectId,
41
- graphId: params.graphId,
41
+ agentId: params.agentId,
42
42
  baseUrl: params.baseUrl || process.env.API_URL || "http://localhost:3003",
43
43
  apiKeyId: params.apiKeyId,
44
44
  subAgentId: params.subAgentId
@@ -55,8 +55,8 @@ var apiKeyAuth = () => createMiddleware(async (c, next) => {
55
55
  const authHeader = c.req.header("Authorization");
56
56
  const tenantId = c.req.header("x-inkeep-tenant-id");
57
57
  const projectId = c.req.header("x-inkeep-project-id");
58
- const graphId = c.req.header("x-inkeep-graph-id");
59
- const subAgentId = c.req.header("x-inkeep-agent-id");
58
+ const agentId = c.req.header("x-inkeep-agent-id");
59
+ const subAgentId = c.req.header("x-inkeep-sub-agent-id");
60
60
  const proto = c.req.header("x-forwarded-proto")?.split(",")[0].trim();
61
61
  const fwdHost = c.req.header("x-forwarded-host")?.split(",")[0].trim();
62
62
  const host = fwdHost ?? c.req.header("host");
@@ -74,7 +74,7 @@ var apiKeyAuth = () => createMiddleware(async (c, next) => {
74
74
  apiKey: "development",
75
75
  tenantId: tenantId || "test-tenant",
76
76
  projectId: projectId || "test-project",
77
- graphId: graphId || "test-graph",
77
+ agentId: agentId || "test-agent",
78
78
  apiKeyId: "test-key",
79
79
  baseUrl,
80
80
  subAgentId
@@ -89,7 +89,7 @@ var apiKeyAuth = () => createMiddleware(async (c, next) => {
89
89
  apiKey: "development",
90
90
  tenantId: tenantId || "test-tenant",
91
91
  projectId: projectId || "test-project",
92
- graphId: graphId || "test-graph",
92
+ agentId: agentId || "test-agent",
93
93
  apiKeyId: "test-key",
94
94
  baseUrl,
95
95
  subAgentId
@@ -111,16 +111,16 @@ var apiKeyAuth = () => createMiddleware(async (c, next) => {
111
111
  const apiKey = authHeader.substring(7);
112
112
  if (env.INKEEP_AGENTS_RUN_API_BYPASS_SECRET) {
113
113
  if (apiKey === env.INKEEP_AGENTS_RUN_API_BYPASS_SECRET) {
114
- if (!tenantId || !projectId || !graphId) {
114
+ if (!tenantId || !projectId || !agentId) {
115
115
  throw new HTTPException(401, {
116
- message: "Missing or invalid tenant, project, or graph ID"
116
+ message: "Missing or invalid tenant, project, or agent ID"
117
117
  });
118
118
  }
119
119
  const executionContext = createExecutionContext({
120
120
  apiKey,
121
121
  tenantId,
122
122
  projectId,
123
- graphId,
123
+ agentId,
124
124
  apiKeyId: "bypass",
125
125
  baseUrl,
126
126
  subAgentId
@@ -155,7 +155,7 @@ var apiKeyAuth = () => createMiddleware(async (c, next) => {
155
155
  {
156
156
  tenantId: executionContext.tenantId,
157
157
  projectId: executionContext.projectId,
158
- graphId: executionContext.graphId,
158
+ agentId: executionContext.agentId,
159
159
  subAgentId: executionContext.subAgentId
160
160
  },
161
161
  "API key authenticated successfully"
@@ -182,7 +182,7 @@ var extractContextFromApiKey = async (apiKey, baseUrl) => {
182
182
  apiKey,
183
183
  tenantId: apiKeyRecord.tenantId,
184
184
  projectId: apiKeyRecord.projectId,
185
- graphId: apiKeyRecord.graphId,
185
+ agentId: apiKeyRecord.agentId,
186
186
  apiKeyId: apiKeyRecord.id,
187
187
  baseUrl
188
188
  });
@@ -278,7 +278,7 @@ async function handleMessageSend(c, agent, request) {
278
278
  try {
279
279
  const params = request.params;
280
280
  const executionContext = getRequestExecutionContext(c);
281
- const { graphId } = executionContext;
281
+ const { agentId } = executionContext;
282
282
  const task = {
283
283
  id: nanoid(),
284
284
  input: {
@@ -292,7 +292,7 @@ async function handleMessageSend(c, agent, request) {
292
292
  conversationId: params.message.contextId,
293
293
  metadata: {
294
294
  blocking: params.configuration?.blocking ?? false,
295
- custom: { graph_id: graphId || "" },
295
+ custom: { agent_id: agentId || "" },
296
296
  // Pass through streaming metadata from the original message
297
297
  ...params.message.metadata
298
298
  }
@@ -353,7 +353,7 @@ async function handleMessageSend(c, agent, request) {
353
353
  id: task.id,
354
354
  tenantId: agent.tenantId,
355
355
  projectId: agent.projectId,
356
- graphId: graphId || "",
356
+ agentId: agentId || "",
357
357
  contextId: effectiveContextId,
358
358
  status: "working",
359
359
  metadata: {
@@ -361,8 +361,8 @@ async function handleMessageSend(c, agent, request) {
361
361
  message_id: params.message.messageId || "",
362
362
  created_at: (/* @__PURE__ */ new Date()).toISOString(),
363
363
  updated_at: (/* @__PURE__ */ new Date()).toISOString(),
364
- agent_id: agent.subAgentId,
365
- graph_id: graphId || "",
364
+ sub_agent_id: agent.subAgentId,
365
+ agent_id: agentId || "",
366
366
  stream_request_id: params.message.metadata?.stream_request_id
367
367
  },
368
368
  subAgentId: agent.subAgentId,
@@ -370,7 +370,7 @@ async function handleMessageSend(c, agent, request) {
370
370
  updatedAt: (/* @__PURE__ */ new Date()).toISOString()
371
371
  });
372
372
  logger2.info({ metadata: params.message.metadata }, "message metadata");
373
- if (params.message.metadata?.fromAgentId || params.message.metadata?.fromExternalAgentId) {
373
+ if (params.message.metadata?.fromSubAgentId || params.message.metadata?.fromExternalAgentId) {
374
374
  const messageText = params.message.parts.filter((part) => part.kind === "text" && "text" in part && part.text).map((part) => part.text).join(" ");
375
375
  try {
376
376
  const messageData = {
@@ -386,19 +386,19 @@ async function handleMessageSend(c, agent, request) {
386
386
  messageType: "a2a-request",
387
387
  taskId: task.id
388
388
  };
389
- if (params.message.metadata?.fromAgentId) {
390
- messageData.fromAgentId = params.message.metadata.fromAgentId;
391
- messageData.toAgentId = agent.subAgentId;
389
+ if (params.message.metadata?.fromSubAgentId) {
390
+ messageData.fromSubAgentId = params.message.metadata.fromSubAgentId;
391
+ messageData.toSubAgentId = agent.subAgentId;
392
392
  } else if (params.message.metadata?.fromExternalAgentId) {
393
393
  messageData.fromExternalAgentId = params.message.metadata.fromExternalAgentId;
394
- messageData.toAgentId = agent.subAgentId;
394
+ messageData.toSubAgentId = agent.subAgentId;
395
395
  }
396
396
  await createMessage(dbClient_default)(messageData);
397
397
  logger2.info(
398
398
  {
399
- fromAgentId: params.message.metadata.fromAgentId,
399
+ fromSubAgentId: params.message.metadata.fromSubAgentId,
400
400
  fromExternalAgentId: params.message.metadata.fromExternalAgentId,
401
- toAgentId: agent.subAgentId,
401
+ toSubAgentId: agent.subAgentId,
402
402
  conversationId: effectiveContextId,
403
403
  messageType: "a2a-request",
404
404
  taskId: task.id
@@ -409,9 +409,9 @@ async function handleMessageSend(c, agent, request) {
409
409
  logger2.error(
410
410
  {
411
411
  error,
412
- fromAgentId: params.message.metadata.fromAgentId,
412
+ fromSubAgentId: params.message.metadata.fromSubAgentId,
413
413
  fromExternalAgentId: params.message.metadata.fromExternalAgentId,
414
- toAgentId: agent.subAgentId,
414
+ toSubAgentId: agent.subAgentId,
415
415
  conversationId: effectiveContextId
416
416
  },
417
417
  "Failed to store A2A message in database"
@@ -428,8 +428,8 @@ async function handleMessageSend(c, agent, request) {
428
428
  message_id: params.message.messageId || "",
429
429
  created_at: (/* @__PURE__ */ new Date()).toISOString(),
430
430
  updated_at: (/* @__PURE__ */ new Date()).toISOString(),
431
- agent_id: agent.subAgentId,
432
- graph_id: graphId || ""
431
+ sub_agent_id: agent.subAgentId,
432
+ agent_id: agentId || ""
433
433
  }
434
434
  }
435
435
  });
@@ -462,7 +462,8 @@ async function handleMessageSend(c, agent, request) {
462
462
  kind: "data",
463
463
  data: {
464
464
  type: "transfer",
465
- targetSubAgentId: transferPart.data.target
465
+ targetSubAgentId: transferPart.data.targetSubAgentId,
466
+ fromSubAgentId: transferPart.data.fromSubAgentId
466
467
  }
467
468
  },
468
469
  {
@@ -530,7 +531,7 @@ async function handleMessageStream(c, agent, request) {
530
531
  try {
531
532
  const params = request.params;
532
533
  const executionContext = getRequestExecutionContext(c);
533
- const { graphId } = executionContext;
534
+ const { agentId } = executionContext;
534
535
  if (!agent.agentCard.capabilities.streaming) {
535
536
  return c.json({
536
537
  jsonrpc: "2.0",
@@ -555,7 +556,7 @@ async function handleMessageStream(c, agent, request) {
555
556
  metadata: {
556
557
  blocking: false,
557
558
  // Streaming is always non-blocking
558
- custom: { graph_id: graphId || "" }
559
+ custom: { agent_id: agentId || "" }
559
560
  }
560
561
  }
561
562
  };
@@ -594,7 +595,7 @@ async function handleMessageStream(c, agent, request) {
594
595
  jsonrpc: "2.0",
595
596
  result: {
596
597
  type: "transfer",
597
- target: transferPart.data.target,
598
+ target: transferPart.data.targetSubAgentId,
598
599
  task_id: task.id,
599
600
  reason: transferPart.data.reason || "Agent requested transfer",
600
601
  original_message: transferPart.data.original_message,
@@ -825,126 +826,6 @@ async function handleTasksResubscribe(c, agent, request) {
825
826
  });
826
827
  }
827
828
  }
828
- function createAgentCard({
829
- dbAgent,
830
- baseUrl
831
- }) {
832
- const description = dbAgent.description || "AI Agent";
833
- return {
834
- name: dbAgent.name,
835
- description,
836
- url: baseUrl ? `${baseUrl}/a2a` : "",
837
- version: "1.0.0",
838
- capabilities: {
839
- streaming: true,
840
- // Enable streaming for A2A compliance
841
- pushNotifications: false,
842
- stateTransitionHistory: false
843
- },
844
- defaultInputModes: ["text", "text/plain"],
845
- defaultOutputModes: ["text", "text/plain"],
846
- skills: [],
847
- // Add provider info if available
848
- ...baseUrl && {
849
- provider: {
850
- organization: "Inkeep",
851
- url: baseUrl
852
- }
853
- }
854
- };
855
- }
856
- function generateDescriptionWithTransfers(baseDescription, internalRelations, externalRelations) {
857
- const transfers = [
858
- ...internalRelations.filter((rel) => rel.relationType === "transfer"),
859
- ...externalRelations.filter((rel) => rel.relationType === "transfer")
860
- ];
861
- const delegates = [
862
- ...internalRelations.filter((rel) => rel.relationType === "delegate"),
863
- ...externalRelations.filter((rel) => rel.relationType === "delegate")
864
- ];
865
- if (transfers.length === 0 && delegates.length === 0) {
866
- return baseDescription;
867
- }
868
- let enhancedDescription = baseDescription;
869
- if (transfers.length > 0) {
870
- const transferList = transfers.map((rel) => {
871
- const name = rel.externalAgent?.name || rel.name;
872
- const desc = rel.externalAgent?.description || rel.description || "";
873
- return `- ${name}: ${desc}`;
874
- }).join("\n");
875
- enhancedDescription += `
876
-
877
- Can transfer to:
878
- ${transferList}`;
879
- }
880
- if (delegates.length > 0) {
881
- const delegateList = delegates.map((rel) => {
882
- const name = rel.externalAgent?.name || rel.name;
883
- const desc = rel.externalAgent?.description || rel.description || "";
884
- return `- ${name}: ${desc}`;
885
- }).join("\n");
886
- enhancedDescription += `
887
-
888
- Can delegate to:
889
- ${delegateList}`;
890
- }
891
- return enhancedDescription;
892
- }
893
- async function hydrateAgent({
894
- dbAgent,
895
- graphId,
896
- baseUrl,
897
- apiKey,
898
- credentialStoreRegistry
899
- }) {
900
- try {
901
- const taskHandlerConfig = await createTaskHandlerConfig({
902
- tenantId: dbAgent.tenantId,
903
- projectId: dbAgent.projectId,
904
- graphId,
905
- subAgentId: dbAgent.id,
906
- baseUrl,
907
- apiKey
908
- });
909
- const taskHandler = createTaskHandler(taskHandlerConfig, credentialStoreRegistry);
910
- const agentCard = createAgentCard({
911
- dbAgent,
912
- baseUrl
913
- });
914
- return {
915
- subAgentId: dbAgent.id,
916
- tenantId: dbAgent.tenantId,
917
- projectId: dbAgent.projectId,
918
- graphId,
919
- agentCard,
920
- taskHandler
921
- };
922
- } catch (error) {
923
- console.error(`\u274C Failed to hydrate agent ${dbAgent.id}:`, error);
924
- throw error;
925
- }
926
- }
927
- async function getRegisteredAgent(executionContext, credentialStoreRegistry) {
928
- const { tenantId, projectId, graphId, subAgentId, baseUrl, apiKey } = executionContext;
929
- if (!subAgentId) {
930
- throw new Error("Agent ID is required");
931
- }
932
- const dbAgent = await getSubAgentById(dbClient_default)({
933
- scopes: { tenantId, projectId, graphId },
934
- subAgentId
935
- });
936
- if (!dbAgent) {
937
- return null;
938
- }
939
- const agentFrameworkBaseUrl = `${baseUrl}/agents`;
940
- return hydrateAgent({
941
- dbAgent,
942
- graphId,
943
- baseUrl: agentFrameworkBaseUrl,
944
- credentialStoreRegistry,
945
- apiKey
946
- });
947
- }
948
829
  var logger3 = getLogger("ModelFactory");
949
830
  var _ModelFactory = class _ModelFactory {
950
831
  /**
@@ -1156,7 +1037,7 @@ var _ToolSessionManager = class _ToolSessionManager {
1156
1037
  return this.createSessionWithId(sessionId, tenantId, projectId, contextId, taskId);
1157
1038
  }
1158
1039
  /**
1159
- * Create a new tool session with a specific ID (for coordination with GraphSession)
1040
+ * Create a new tool session with a specific ID (for coordination with AgentSession)
1160
1041
  */
1161
1042
  createSessionWithId(sessionId, tenantId, projectId, contextId, taskId) {
1162
1043
  const session = {
@@ -1182,17 +1063,17 @@ var _ToolSessionManager = class _ToolSessionManager {
1182
1063
  return sessionId;
1183
1064
  }
1184
1065
  /**
1185
- * Ensure a graph-scoped session exists (idempotent)
1186
- * All agents in the same graph execution share this session
1066
+ * Ensure an agent-scoped session exists (idempotent)
1067
+ * All agents in the same agent execution share this session
1187
1068
  */
1188
- ensureGraphSession(sessionId, tenantId, projectId, contextId, taskId) {
1069
+ ensureAgentSession(sessionId, tenantId, projectId, contextId, taskId) {
1189
1070
  if (this.sessions.has(sessionId)) {
1190
- logger4.debug({ sessionId }, "Graph session already exists, reusing");
1071
+ logger4.debug({ sessionId }, "Agent session already exists, reusing");
1191
1072
  return sessionId;
1192
1073
  }
1193
1074
  logger4.debug(
1194
1075
  { sessionId, tenantId, contextId, taskId },
1195
- "Creating new graph-scoped tool session"
1076
+ "Creating new agent-scoped tool session"
1196
1077
  );
1197
1078
  return this.createSessionWithId(sessionId, tenantId, projectId, contextId, taskId);
1198
1079
  }
@@ -1509,7 +1390,7 @@ var _ArtifactService = class _ArtifactService {
1509
1390
  async getArtifactSummary(artifactId, toolCallId, artifactMap) {
1510
1391
  const key = `${artifactId}:${toolCallId}`;
1511
1392
  if (this.context.streamRequestId) {
1512
- const cachedArtifact = await graphSessionManager.getArtifactCache(
1393
+ const cachedArtifact = await agentSessionManager.getArtifactCache(
1513
1394
  this.context.streamRequestId,
1514
1395
  key
1515
1396
  );
@@ -1555,7 +1436,7 @@ var _ArtifactService = class _ArtifactService {
1555
1436
  async getArtifactFull(artifactId, toolCallId, artifactMap) {
1556
1437
  const key = `${artifactId}:${toolCallId}`;
1557
1438
  if (this.context.streamRequestId) {
1558
- const cachedArtifact = await graphSessionManager.getArtifactCache(
1439
+ const cachedArtifact = await agentSessionManager.getArtifactCache(
1559
1440
  this.context.streamRequestId,
1560
1441
  key
1561
1442
  );
@@ -1622,12 +1503,12 @@ var _ArtifactService = class _ArtifactService {
1622
1503
  };
1623
1504
  }
1624
1505
  /**
1625
- * Persist artifact to database via graph session
1506
+ * Persist artifact to database vian agent session
1626
1507
  */
1627
1508
  async persistArtifact(request, summaryData, fullData, subAgentId) {
1628
1509
  const effectiveAgentId = subAgentId || this.context.subAgentId;
1629
1510
  if (this.context.streamRequestId && effectiveAgentId && this.context.taskId) {
1630
- await graphSessionManager.recordEvent(
1511
+ await agentSessionManager.recordEvent(
1631
1512
  this.context.streamRequestId,
1632
1513
  "artifact_saved",
1633
1514
  effectiveAgentId,
@@ -1679,7 +1560,7 @@ var _ArtifactService = class _ArtifactService {
1679
1560
  };
1680
1561
  this.createdArtifacts.set(cacheKey, artifactForCache);
1681
1562
  if (this.context.streamRequestId) {
1682
- await graphSessionManager.setArtifactCache(
1563
+ await agentSessionManager.setArtifactCache(
1683
1564
  this.context.streamRequestId,
1684
1565
  cacheKey,
1685
1566
  artifactForCache
@@ -1711,7 +1592,7 @@ var _ArtifactService = class _ArtifactService {
1711
1592
  }
1712
1593
  /**
1713
1594
  * Save an already-created artifact directly to the database
1714
- * Used by GraphSession to save artifacts after name/description generation
1595
+ * Used by AgentSession to save artifacts after name/description generation
1715
1596
  */
1716
1597
  async saveArtifact(artifact) {
1717
1598
  let summaryData = artifact.data;
@@ -2258,14 +2139,14 @@ __publicField(_ArtifactParser, "ARTIFACT_PATTERNS", [
2258
2139
  __publicField(_ArtifactParser, "INCOMPLETE_CREATE_REGEX", /<artifact:create(?![^>]*(?:\/>|<\/artifact:create>))/);
2259
2140
  var ArtifactParser = _ArtifactParser;
2260
2141
 
2261
- // src/services/GraphSession.ts
2262
- var logger8 = getLogger("GraphSession");
2263
- var GraphSession = class {
2142
+ // src/services/AgentSession.ts
2143
+ var logger8 = getLogger("AgentSession");
2144
+ var AgentSession = class {
2264
2145
  // Whether to send data operations
2265
- constructor(sessionId, messageId, graphId, tenantId, projectId, contextId) {
2146
+ constructor(sessionId, messageId, agentId, tenantId, projectId, contextId) {
2266
2147
  this.sessionId = sessionId;
2267
2148
  this.messageId = messageId;
2268
- this.graphId = graphId;
2149
+ this.agentId = agentId;
2269
2150
  this.tenantId = tenantId;
2270
2151
  this.projectId = projectId;
2271
2152
  this.contextId = contextId;
@@ -2292,7 +2173,7 @@ var GraphSession = class {
2292
2173
  __publicField(this, "artifactParser");
2293
2174
  // Session-scoped ArtifactParser instance
2294
2175
  __publicField(this, "isEmitOperations", false);
2295
- logger8.debug({ sessionId, messageId, graphId }, "GraphSession created");
2176
+ logger8.debug({ sessionId, messageId, agentId }, "AgentSession created");
2296
2177
  if (tenantId && projectId) {
2297
2178
  toolSessionManager.createSessionWithId(
2298
2179
  sessionId,
@@ -2328,7 +2209,7 @@ var GraphSession = class {
2328
2209
  this.isEmitOperations = true;
2329
2210
  logger8.info(
2330
2211
  { sessionId: this.sessionId },
2331
- "\u{1F50D} DEBUG: Emit operations enabled for GraphSession"
2212
+ "\u{1F50D} DEBUG: Emit operations enabled for AgentSession"
2332
2213
  );
2333
2214
  }
2334
2215
  /**
@@ -2601,7 +2482,7 @@ var GraphSession = class {
2601
2482
  return {
2602
2483
  sessionId: this.sessionId,
2603
2484
  messageId: this.messageId,
2604
- graphId: this.graphId,
2485
+ agentId: this.agentId,
2605
2486
  totalEvents: this.events.length,
2606
2487
  eventCounts,
2607
2488
  agentCounts,
@@ -2652,7 +2533,7 @@ var GraphSession = class {
2652
2533
  }
2653
2534
  }
2654
2535
  /**
2655
- * Generate and send a status update using graph-level summarizer
2536
+ * Generate and send a status update using agent-level summarizer
2656
2537
  */
2657
2538
  async generateAndSendUpdate() {
2658
2539
  if (this.isEnded) {
@@ -2677,8 +2558,8 @@ var GraphSession = class {
2677
2558
  logger8.warn({ sessionId: this.sessionId }, "No status update state - cannot generate update");
2678
2559
  return;
2679
2560
  }
2680
- if (!this.graphId) {
2681
- logger8.warn({ sessionId: this.sessionId }, "No graph ID - cannot generate update");
2561
+ if (!this.agentId) {
2562
+ logger8.warn({ sessionId: this.sessionId }, "No agent ID - cannot generate update");
2682
2563
  return;
2683
2564
  }
2684
2565
  const newEventCount = this.events.length - this.statusUpdateState.lastEventCount;
@@ -2830,10 +2711,10 @@ var GraphSession = class {
2830
2711
  */
2831
2712
  async generateStructuredStatusUpdate(newEvents, elapsedTime, statusComponents, summarizerModel, previousSummaries = []) {
2832
2713
  return tracer.startActiveSpan(
2833
- "graph_session.generate_structured_update",
2714
+ "agent_session.generate_structured_update",
2834
2715
  {
2835
2716
  attributes: {
2836
- "graph_session.id": this.sessionId,
2717
+ "agent_session.id": this.sessionId,
2837
2718
  "events.count": newEvents.length,
2838
2719
  "elapsed_time.seconds": Math.round(elapsedTime / 1e3),
2839
2720
  "llm.model": summarizerModel?.model,
@@ -2914,7 +2795,7 @@ CRITICAL - HIDE ALL INTERNAL SYSTEM OPERATIONS:
2914
2795
  - ABSOLUTELY FORBIDDEN WORDS/PHRASES: "transfer", "transferring", "delegation", "delegating", "delegate", "agent", "routing", "route", "artifact", "saving artifact", "stored artifact", "artifact saved", "continuing", "passing to", "handing off", "switching to"
2915
2796
  - NEVER reveal internal architecture: No mentions of different agents, components, systems, or modules working together
2916
2797
  - NEVER mention artifact operations: Users don't need to know about data being saved, stored, or organized internally
2917
- - NEVER describe handoffs or transitions: Present everything as one seamless operation
2798
+ - NEVER describe transfers or transitions: Present everything as one seamless operation
2918
2799
  - If you see "transfer", "delegation_sent", "delegation_returned", or "artifact_saved" events - IGNORE THEM or translate to user-facing information only
2919
2800
  - Focus ONLY on actual discoveries, findings, and results that matter to the user
2920
2801
 
@@ -3136,10 +3017,10 @@ ${this.statusUpdateState?.config.prompt?.trim() || ""}`;
3136
3017
  */
3137
3018
  async processArtifact(artifactData) {
3138
3019
  return tracer.startActiveSpan(
3139
- "graph_session.process_artifact",
3020
+ "agent_session.process_artifact",
3140
3021
  {
3141
3022
  attributes: {
3142
- "graph_session.id": this.sessionId,
3023
+ "agent_session.id": this.sessionId,
3143
3024
  "artifact.id": artifactData.artifactId,
3144
3025
  "artifact.type": artifactData.artifactType || "unknown",
3145
3026
  "artifact.agent_id": artifactData.subAgentId || "unknown",
@@ -3207,7 +3088,7 @@ Make it specific and relevant.`;
3207
3088
  scopes: {
3208
3089
  tenantId: artifactData.tenantId,
3209
3090
  projectId: artifactData.projectId,
3210
- graphId: this.graphId || ""
3091
+ agentId: this.agentId || ""
3211
3092
  },
3212
3093
  subAgentId: artifactData.subAgentId
3213
3094
  });
@@ -3262,7 +3143,7 @@ Make it specific and relevant.`;
3262
3143
  description: z.string().describe("Brief description of the artifact's relevance to the user's question")
3263
3144
  });
3264
3145
  const { object } = await tracer.startActiveSpan(
3265
- "graph_session.generate_artifact_metadata",
3146
+ "agent_session.generate_artifact_metadata",
3266
3147
  {
3267
3148
  attributes: {
3268
3149
  "llm.model": this.statusUpdateState?.summarizerModel?.model,
@@ -3472,20 +3353,20 @@ Make it specific and relevant.`;
3472
3353
  }
3473
3354
  }
3474
3355
  };
3475
- var GraphSessionManager = class {
3356
+ var AgentSessionManager = class {
3476
3357
  constructor() {
3477
3358
  __publicField(this, "sessions", /* @__PURE__ */ new Map());
3478
3359
  }
3479
3360
  /**
3480
3361
  * Create a new session for a message
3481
3362
  */
3482
- createSession(messageId, graphId, tenantId, projectId, contextId) {
3363
+ createSession(messageId, agentId, tenantId, projectId, contextId) {
3483
3364
  const sessionId = messageId;
3484
- const session = new GraphSession(sessionId, messageId, graphId, tenantId, projectId, contextId);
3365
+ const session = new AgentSession(sessionId, messageId, agentId, tenantId, projectId, contextId);
3485
3366
  this.sessions.set(sessionId, session);
3486
3367
  logger8.info(
3487
- { sessionId, messageId, graphId, tenantId, projectId, contextId },
3488
- "GraphSession created"
3368
+ { sessionId, messageId, agentId, tenantId, projectId, contextId },
3369
+ "AgentSession created"
3489
3370
  );
3490
3371
  return sessionId;
3491
3372
  }
@@ -3552,7 +3433,7 @@ var GraphSessionManager = class {
3552
3433
  }
3553
3434
  const events = session.getEvents();
3554
3435
  const summary = session.getSummary();
3555
- logger8.info({ sessionId, summary }, "GraphSession ended");
3436
+ logger8.info({ sessionId, summary }, "AgentSession ended");
3556
3437
  session.cleanup();
3557
3438
  this.sessions.delete(sessionId);
3558
3439
  return events;
@@ -3616,33 +3497,33 @@ var GraphSessionManager = class {
3616
3497
  }
3617
3498
  }
3618
3499
  };
3619
- var graphSessionManager = new GraphSessionManager();
3620
- async function resolveModelConfig(graphId, agent) {
3621
- if (agent.models?.base?.model) {
3500
+ var agentSessionManager = new AgentSessionManager();
3501
+ async function resolveModelConfig(agentId, subAgent) {
3502
+ if (subAgent.models?.base?.model) {
3622
3503
  return {
3623
- base: agent.models.base,
3624
- structuredOutput: agent.models.structuredOutput || agent.models.base,
3625
- summarizer: agent.models.summarizer || agent.models.base
3504
+ base: subAgent.models.base,
3505
+ structuredOutput: subAgent.models.structuredOutput || subAgent.models.base,
3506
+ summarizer: subAgent.models.summarizer || subAgent.models.base
3626
3507
  };
3627
3508
  }
3628
- const graph = await getAgentGraphById(dbClient_default)({
3629
- scopes: { tenantId: agent.tenantId, projectId: agent.projectId, graphId }
3509
+ const agent = await getAgentById(dbClient_default)({
3510
+ scopes: { tenantId: subAgent.tenantId, projectId: subAgent.projectId, agentId }
3630
3511
  });
3631
- if (graph?.models?.base?.model) {
3512
+ if (agent?.models?.base?.model) {
3632
3513
  return {
3633
- base: graph.models.base,
3634
- structuredOutput: agent.models?.structuredOutput || graph.models.structuredOutput || graph.models.base,
3635
- summarizer: agent.models?.summarizer || graph.models.summarizer || graph.models.base
3514
+ base: agent.models.base,
3515
+ structuredOutput: subAgent.models?.structuredOutput || agent.models.structuredOutput || agent.models.base,
3516
+ summarizer: subAgent.models?.summarizer || agent.models.summarizer || agent.models.base
3636
3517
  };
3637
3518
  }
3638
3519
  const project = await getProject(dbClient_default)({
3639
- scopes: { tenantId: agent.tenantId, projectId: agent.projectId }
3520
+ scopes: { tenantId: subAgent.tenantId, projectId: subAgent.projectId }
3640
3521
  });
3641
3522
  if (project?.models?.base?.model) {
3642
3523
  return {
3643
3524
  base: project.models.base,
3644
- structuredOutput: agent.models?.structuredOutput || project.models.structuredOutput || project.models.base,
3645
- summarizer: agent.models?.summarizer || project.models.summarizer || project.models.base
3525
+ structuredOutput: subAgent.models?.structuredOutput || project.models.structuredOutput || project.models.base,
3526
+ summarizer: subAgent.models?.summarizer || project.models.summarizer || project.models.base
3646
3527
  };
3647
3528
  }
3648
3529
  throw new Error(
@@ -3673,7 +3554,7 @@ var _IncrementalStreamParser = class _IncrementalStreamParser {
3673
3554
  this.contextId = contextId;
3674
3555
  this.subAgentId = artifactParserOptions?.subAgentId;
3675
3556
  if (artifactParserOptions?.streamRequestId) {
3676
- const sessionParser = graphSessionManager.getArtifactParser(
3557
+ const sessionParser = agentSessionManager.getArtifactParser(
3677
3558
  artifactParserOptions.streamRequestId
3678
3559
  );
3679
3560
  if (sessionParser) {
@@ -3682,9 +3563,9 @@ var _IncrementalStreamParser = class _IncrementalStreamParser {
3682
3563
  }
3683
3564
  }
3684
3565
  let sharedArtifactService = null;
3685
- if (artifactParserOptions?.streamRequestId && typeof graphSessionManager.getArtifactService === "function") {
3566
+ if (artifactParserOptions?.streamRequestId && typeof agentSessionManager.getArtifactService === "function") {
3686
3567
  try {
3687
- sharedArtifactService = graphSessionManager.getArtifactService(
3568
+ sharedArtifactService = agentSessionManager.getArtifactService(
3688
3569
  artifactParserOptions.streamRequestId
3689
3570
  );
3690
3571
  } catch (error) {
@@ -4058,7 +3939,7 @@ var ResponseFormatter = class {
4058
3939
  __publicField(this, "subAgentId");
4059
3940
  this.subAgentId = artifactParserOptions?.subAgentId;
4060
3941
  if (artifactParserOptions?.streamRequestId) {
4061
- const sessionParser = graphSessionManager.getArtifactParser(
3942
+ const sessionParser = agentSessionManager.getArtifactParser(
4062
3943
  artifactParserOptions.streamRequestId
4063
3944
  );
4064
3945
  if (sessionParser) {
@@ -4067,9 +3948,9 @@ var ResponseFormatter = class {
4067
3948
  }
4068
3949
  }
4069
3950
  let sharedArtifactService = null;
4070
- if (artifactParserOptions?.streamRequestId && typeof graphSessionManager.getArtifactService === "function") {
3951
+ if (artifactParserOptions?.streamRequestId && typeof agentSessionManager.getArtifactService === "function") {
4071
3952
  try {
4072
- sharedArtifactService = graphSessionManager.getArtifactService(
3953
+ sharedArtifactService = agentSessionManager.getArtifactService(
4073
3954
  artifactParserOptions.streamRequestId
4074
3955
  );
4075
3956
  } catch (error) {
@@ -4211,12 +4092,12 @@ var ResponseFormatter = class {
4211
4092
  }
4212
4093
  }
4213
4094
  };
4214
- function agentInitializingOp(sessionId, graphId) {
4095
+ function agentInitializingOp(sessionId, agentId) {
4215
4096
  return {
4216
4097
  type: "agent_initializing",
4217
4098
  details: {
4218
4099
  sessionId,
4219
- graphId
4100
+ agentId
4220
4101
  }
4221
4102
  };
4222
4103
  }
@@ -5289,23 +5170,29 @@ var createTransferToAgentTool = ({
5289
5170
  logger13.info(
5290
5171
  {
5291
5172
  transferTo: transferConfig.id ?? "unknown",
5292
- fromAgent: callingAgentId
5173
+ fromSubAgent: callingAgentId
5293
5174
  },
5294
5175
  "invoked transferToAgentTool"
5295
5176
  );
5296
5177
  if (streamRequestId) {
5297
- graphSessionManager.recordEvent(streamRequestId, "transfer", callingAgentId, {
5178
+ agentSessionManager.recordEvent(streamRequestId, "transfer", callingAgentId, {
5298
5179
  fromSubAgent: callingAgentId,
5299
5180
  targetSubAgent: transferConfig.id ?? "unknown",
5300
5181
  reason: `Transfer to ${transferConfig.name || transferConfig.id}`
5301
5182
  });
5302
5183
  }
5303
- return {
5184
+ const transferResult = {
5304
5185
  type: "transfer",
5305
- target: transferConfig.id ?? "unknown",
5306
- fromAgentId: callingAgentId
5186
+ targetSubAgentId: transferConfig.id ?? "unknown",
5187
+ // Changed from "target" for type safety
5188
+ fromSubAgentId: callingAgentId
5307
5189
  // Include the calling agent ID for tracking
5308
5190
  };
5191
+ logger13.info({
5192
+ transferResult,
5193
+ transferResultKeys: Object.keys(transferResult)
5194
+ }, "[DEBUG] Transfer tool returning");
5195
+ return transferResult;
5309
5196
  }
5310
5197
  });
5311
5198
  };
@@ -5314,7 +5201,7 @@ function createDelegateToAgentTool({
5314
5201
  callingAgentId,
5315
5202
  tenantId,
5316
5203
  projectId,
5317
- graphId,
5204
+ agentId,
5318
5205
  contextId,
5319
5206
  metadata,
5320
5207
  sessionId,
@@ -5335,7 +5222,7 @@ function createDelegateToAgentTool({
5335
5222
  });
5336
5223
  }
5337
5224
  if (metadata.streamRequestId) {
5338
- graphSessionManager.recordEvent(
5225
+ agentSessionManager.recordEvent(
5339
5226
  metadata.streamRequestId,
5340
5227
  "delegation_sent",
5341
5228
  callingAgentId,
@@ -5354,7 +5241,7 @@ function createDelegateToAgentTool({
5354
5241
  scopes: {
5355
5242
  tenantId,
5356
5243
  projectId,
5357
- graphId
5244
+ agentId
5358
5245
  },
5359
5246
  subAgentId: delegateConfig.config.id
5360
5247
  });
@@ -5400,8 +5287,8 @@ function createDelegateToAgentTool({
5400
5287
  Authorization: `Bearer ${metadata.apiKey}`,
5401
5288
  "x-inkeep-tenant-id": tenantId,
5402
5289
  "x-inkeep-project-id": projectId,
5403
- "x-inkeep-graph-id": graphId,
5404
- "x-inkeep-agent-id": delegateConfig.config.id
5290
+ "x-inkeep-agent-id": agentId,
5291
+ "x-inkeep-sub-agent-id": delegateConfig.config.id
5405
5292
  };
5406
5293
  }
5407
5294
  const a2aClient = new A2AClient(delegateConfig.config.baseUrl, {
@@ -5432,7 +5319,7 @@ function createDelegateToAgentTool({
5432
5319
  // Flag to prevent streaming in delegated agents
5433
5320
  delegationId,
5434
5321
  // Include delegation ID for tracking
5435
- ...isInternal ? { fromAgentId: callingAgentId } : { fromExternalAgentId: callingAgentId }
5322
+ ...isInternal ? { fromSubAgentId: callingAgentId } : { fromExternalAgentId: callingAgentId }
5436
5323
  }
5437
5324
  };
5438
5325
  logger13.info({ messageToSend }, "messageToSend");
@@ -5448,7 +5335,7 @@ function createDelegateToAgentTool({
5448
5335
  visibility: isInternal ? "internal" : "external",
5449
5336
  messageType: "a2a-request",
5450
5337
  fromSubAgentId: callingAgentId,
5451
- ...isInternal ? { toAgentId: delegateConfig.config.id } : { toExternalAgentId: delegateConfig.config.id }
5338
+ ...isInternal ? { toSubAgentId: delegateConfig.config.id } : { toExternalAgentId: delegateConfig.config.id }
5452
5339
  });
5453
5340
  const response = await a2aClient.sendMessage({
5454
5341
  message: messageToSend
@@ -5476,7 +5363,7 @@ function createDelegateToAgentTool({
5476
5363
  toolSessionManager.recordToolResult(sessionId, toolResult);
5477
5364
  }
5478
5365
  if (metadata.streamRequestId) {
5479
- graphSessionManager.recordEvent(
5366
+ agentSessionManager.recordEvent(
5480
5367
  metadata.streamRequestId,
5481
5368
  "delegation_returned",
5482
5369
  callingAgentId,
@@ -5554,7 +5441,7 @@ var system_prompt_default = `<system_message>
5554
5441
  {{CORE_INSTRUCTIONS}}
5555
5442
  </core_instructions>
5556
5443
 
5557
- {{GRAPH_CONTEXT_SECTION}}
5444
+ {{AGENT_CONTEXT_SECTION}}
5558
5445
 
5559
5446
  {{ARTIFACTS_SECTION}}
5560
5447
  {{TOOLS_SECTION}}
@@ -5719,7 +5606,7 @@ When you use delegation tools, the response may include artifacts in the parts a
5719
5606
  These artifacts become immediately available for you to reference using the artifactId and toolCallId from the response.
5720
5607
  Present delegation results naturally without mentioning the delegation process itself.
5721
5608
 
5722
- IMPORTANT: All agents can retrieve and use information from existing artifacts when the graph has artifact components, regardless of whether the individual agent can create new artifacts.`;
5609
+ IMPORTANT: All sub-agents can retrieve and use information from existing artifacts when the agent has artifact components, regardless of whether the individual agent or sub-agents can create new artifacts.`;
5723
5610
 
5724
5611
  // src/agents/versions/v1/Phase1Config.ts
5725
5612
  getLogger("Phase1Config");
@@ -5764,8 +5651,8 @@ var Phase1Config = class _Phase1Config {
5764
5651
  }
5765
5652
  let systemPrompt = systemPromptTemplate;
5766
5653
  systemPrompt = systemPrompt.replace("{{CORE_INSTRUCTIONS}}", config.corePrompt);
5767
- const graphContextSection = this.generateGraphContextSection(config.graphPrompt);
5768
- systemPrompt = systemPrompt.replace("{{GRAPH_CONTEXT_SECTION}}", graphContextSection);
5654
+ const agentContextSection = this.generateAgentContextSection(config.agentPrompt);
5655
+ systemPrompt = systemPrompt.replace("{{AGENT_CONTEXT_SECTION}}", agentContextSection);
5769
5656
  const toolData = this.isToolDataArray(config.tools) ? config.tools : _Phase1Config.convertMcpToolsToToolData(config.tools);
5770
5657
  const hasArtifactComponents = config.artifactComponents && config.artifactComponents.length > 0;
5771
5658
  const artifactsSection = this.generateArtifactsSection(
@@ -5773,7 +5660,7 @@ var Phase1Config = class _Phase1Config {
5773
5660
  config.artifacts,
5774
5661
  hasArtifactComponents,
5775
5662
  config.artifactComponents,
5776
- config.hasGraphArtifactComponents
5663
+ config.hasAgentArtifactComponents
5777
5664
  );
5778
5665
  systemPrompt = systemPrompt.replace("{{ARTIFACTS_SECTION}}", artifactsSection);
5779
5666
  const toolsSection = this.generateToolsSection(templates, toolData);
@@ -5792,14 +5679,14 @@ var Phase1Config = class _Phase1Config {
5792
5679
  systemPrompt = systemPrompt.replace("{{DELEGATION_INSTRUCTIONS}}", delegationSection);
5793
5680
  return systemPrompt;
5794
5681
  }
5795
- generateGraphContextSection(graphPrompt) {
5796
- if (!graphPrompt) {
5682
+ generateAgentContextSection(agentPrompt) {
5683
+ if (!agentPrompt) {
5797
5684
  return "";
5798
5685
  }
5799
5686
  return `
5800
- <graph_context>
5801
- ${graphPrompt}
5802
- </graph_context>`;
5687
+ <agent_context>
5688
+ ${agentPrompt}
5689
+ </agent_context>`;
5803
5690
  }
5804
5691
  generateThinkingPreparationSection(templates, isThinkingPreparation) {
5805
5692
  if (!isThinkingPreparation) {
@@ -5817,7 +5704,7 @@ var Phase1Config = class _Phase1Config {
5817
5704
  }
5818
5705
  return `- You have transfer_to_* tools that seamlessly continue the conversation
5819
5706
  - NEVER announce transfers - just call the tool when needed
5820
- - The conversation continues naturally without any handoff language`;
5707
+ - The conversation continues naturally without any transfer language`;
5821
5708
  }
5822
5709
  generateDelegationInstructions(hasDelegateRelations) {
5823
5710
  if (!hasDelegateRelations) {
@@ -6051,8 +5938,8 @@ ${typeDescriptions}
6051
5938
  - Do NOT abbreviate, modify, or guess the type name
6052
5939
  - Copy the exact quoted name from the "AVAILABLE ARTIFACT TYPES" list above`;
6053
5940
  }
6054
- generateArtifactsSection(templates, artifacts, hasArtifactComponents = false, artifactComponents, hasGraphArtifactComponents) {
6055
- const shouldShowReferencingRules = hasGraphArtifactComponents || artifacts.length > 0;
5941
+ generateArtifactsSection(templates, artifacts, hasArtifactComponents = false, artifactComponents, hasAgentArtifactComponents) {
5942
+ const shouldShowReferencingRules = hasAgentArtifactComponents || artifacts.length > 0;
6056
5943
  const rules = this.getArtifactReferencingRules(
6057
5944
  hasArtifactComponents,
6058
5945
  templates,
@@ -6532,7 +6419,7 @@ ${artifact_retrieval_guidance_default}
6532
6419
  dataComponents,
6533
6420
  artifactComponents,
6534
6421
  hasArtifactComponents,
6535
- hasGraphArtifactComponents,
6422
+ hasAgentArtifactComponents,
6536
6423
  artifacts = []
6537
6424
  } = config;
6538
6425
  let allDataComponents = [...dataComponents];
@@ -6548,7 +6435,7 @@ ${artifact_retrieval_guidance_default}
6548
6435
  }
6549
6436
  const dataComponentsSection = this.generateDataComponentsSection(allDataComponents);
6550
6437
  const artifactsSection = this.generateArtifactsSection(artifacts);
6551
- const shouldShowReferencingRules = hasGraphArtifactComponents || artifacts.length > 0;
6438
+ const shouldShowReferencingRules = hasAgentArtifactComponents || artifacts.length > 0;
6552
6439
  const artifactGuidance = this.getStructuredArtifactGuidance(
6553
6440
  hasArtifactComponents,
6554
6441
  artifactComponents,
@@ -6753,7 +6640,7 @@ var Agent = class {
6753
6640
  return this.isDelegatedAgent ? void 0 : this.streamHelper;
6754
6641
  }
6755
6642
  /**
6756
- * Wraps a tool with streaming lifecycle tracking (start, complete, error) and GraphSession recording
6643
+ * Wraps a tool with streaming lifecycle tracking (start, complete, error) and AgentSession recording
6757
6644
  */
6758
6645
  wrapToolWithStreaming(toolName, toolDefinition, streamRequestId, toolType) {
6759
6646
  if (!toolDefinition || typeof toolDefinition !== "object" || !("execute" in toolDefinition)) {
@@ -6772,7 +6659,7 @@ var Agent = class {
6772
6659
  "tool.purpose": toolDefinition.description || "No description provided",
6773
6660
  "ai.toolType": toolType || "unknown",
6774
6661
  "ai.agentName": this.config.name || "unknown",
6775
- "graph.id": this.config.graphId || "unknown"
6662
+ "agent.id": this.config.agentId || "unknown"
6776
6663
  });
6777
6664
  }
6778
6665
  const isInternalTool = toolName.includes("save_tool_result") || toolName.includes("thinking_complete") || toolName.startsWith("transfer_to_") || toolName.startsWith("delegate_to_");
@@ -6780,7 +6667,7 @@ var Agent = class {
6780
6667
  const result = await originalExecute(args, context);
6781
6668
  const duration = Date.now() - startTime;
6782
6669
  if (streamRequestId && !isInternalTool) {
6783
- graphSessionManager.recordEvent(streamRequestId, "tool_execution", this.config.id, {
6670
+ agentSessionManager.recordEvent(streamRequestId, "tool_execution", this.config.id, {
6784
6671
  toolName,
6785
6672
  args,
6786
6673
  result,
@@ -6793,7 +6680,7 @@ var Agent = class {
6793
6680
  const duration = Date.now() - startTime;
6794
6681
  const errorMessage = error instanceof Error ? error.message : "Unknown error";
6795
6682
  if (streamRequestId && !isInternalTool) {
6796
- graphSessionManager.recordEvent(streamRequestId, "tool_execution", this.config.id, {
6683
+ agentSessionManager.recordEvent(streamRequestId, "tool_execution", this.config.id, {
6797
6684
  toolName,
6798
6685
  args,
6799
6686
  result: { error: errorMessage },
@@ -6838,7 +6725,7 @@ var Agent = class {
6838
6725
  callingAgentId: this.config.id,
6839
6726
  tenantId: this.config.tenantId,
6840
6727
  projectId: this.config.projectId,
6841
- graphId: this.config.graphId,
6728
+ agentId: this.config.agentId,
6842
6729
  contextId: runtimeContext?.contextId || "default",
6843
6730
  // fallback for compatibility
6844
6731
  metadata: runtimeContext?.metadata || {
@@ -6947,7 +6834,7 @@ var Agent = class {
6947
6834
  scopes: {
6948
6835
  tenantId: this.config.tenantId,
6949
6836
  projectId: this.config.projectId,
6950
- graphId: this.config.graphId,
6837
+ agentId: this.config.agentId,
6951
6838
  subAgentId: this.config.id
6952
6839
  }
6953
6840
  });
@@ -7053,26 +6940,26 @@ var Agent = class {
7053
6940
  "ai.toolCall.args": JSON.stringify({ operation: "mcp_tool_discovery" }),
7054
6941
  "ai.toolCall.result": JSON.stringify({
7055
6942
  status: "no_tools_available",
7056
- message: `MCP server has 0 effective tools. Double check the selected tools in your graph and the active tools in the MCP server configuration.`,
6943
+ message: `MCP server has 0 effective tools. Double check the selected tools in your agent and the active tools in the MCP server configuration.`,
7057
6944
  serverUrl: tool3.config.type === "mcp" ? tool3.config.mcp.server.url : "unknown",
7058
6945
  originalToolName: tool3.name
7059
6946
  }),
7060
6947
  "ai.toolType": "mcp",
7061
6948
  "ai.agentName": this.config.name || "unknown",
7062
6949
  "conversation.id": this.conversationId || "unknown",
7063
- "graph.id": this.config.graphId || "unknown",
6950
+ "agent.id": this.config.agentId || "unknown",
7064
6951
  "tenant.id": this.config.tenantId || "unknown",
7065
6952
  "project.id": this.config.projectId || "unknown"
7066
6953
  }
7067
6954
  },
7068
6955
  (span) => {
7069
6956
  setSpanWithError(span, new Error(`0 effective tools available for ${tool3.name}`));
7070
- graphSessionManager.recordEvent(streamRequestId, "tool_execution", this.config.id, {
6957
+ agentSessionManager.recordEvent(streamRequestId, "tool_execution", this.config.id, {
7071
6958
  toolName: tool3.name,
7072
6959
  args: { operation: "mcp_tool_discovery" },
7073
6960
  result: {
7074
6961
  status: "no_tools_available",
7075
- message: `MCP server has 0 effective tools. Double check the selected tools in your graph and the active tools in the MCP server configuration.`,
6962
+ message: `MCP server has 0 effective tools. Double check the selected tools in your agent and the active tools in the MCP server configuration.`,
7076
6963
  serverUrl: tool3.config.type === "mcp" ? tool3.config.mcp.server.url : "unknown"
7077
6964
  }
7078
6965
  });
@@ -7121,7 +7008,7 @@ var Agent = class {
7121
7008
  scopes: {
7122
7009
  tenantId: this.config.tenantId,
7123
7010
  projectId: this.config.projectId,
7124
- graphId: this.config.graphId
7011
+ agentId: this.config.agentId
7125
7012
  },
7126
7013
  subAgentId: this.config.id
7127
7014
  });
@@ -7129,7 +7016,7 @@ var Agent = class {
7129
7016
  if (functionToolsData.length === 0) {
7130
7017
  return functionTools;
7131
7018
  }
7132
- const { LocalSandboxExecutor } = await import('./LocalSandboxExecutor-PQIRECLQ.js');
7019
+ const { LocalSandboxExecutor } = await import('./LocalSandboxExecutor-2UQ32ZZH.js');
7133
7020
  const sandboxExecutor = LocalSandboxExecutor.getInstance();
7134
7021
  for (const functionToolDef of functionToolsData) {
7135
7022
  const functionId = functionToolDef.functionId;
@@ -7164,11 +7051,21 @@ var Agent = class {
7164
7051
  "Function Tool Called"
7165
7052
  );
7166
7053
  try {
7054
+ const project = await getProject(dbClient_default)({
7055
+ scopes: { tenantId: this.config.tenantId, projectId: this.config.projectId }
7056
+ });
7057
+ const defaultSandboxConfig = {
7058
+ provider: "local",
7059
+ runtime: "node22",
7060
+ timeout: 3e4,
7061
+ vcpus: 1
7062
+ };
7167
7063
  const result = await sandboxExecutor.executeFunctionTool(functionToolDef.id, args, {
7168
7064
  description: functionToolDef.description || functionToolDef.name,
7169
7065
  inputSchema: functionData.inputSchema || {},
7170
7066
  executeCode: functionData.executeCode,
7171
- dependencies: functionData.dependencies || {}
7067
+ dependencies: functionData.dependencies || {},
7068
+ sandboxConfig: project?.sandboxConfig || defaultSandboxConfig
7172
7069
  });
7173
7070
  toolSessionManager.recordToolResult(sessionId || "", {
7174
7071
  toolCallId,
@@ -7205,14 +7102,14 @@ var Agent = class {
7205
7102
  async getResolvedContext(conversationId, headers) {
7206
7103
  try {
7207
7104
  if (!this.config.contextConfigId) {
7208
- logger16.debug({ graphId: this.config.graphId }, "No context config found for graph");
7105
+ logger16.debug({ agentId: this.config.agentId }, "No context config found for agent");
7209
7106
  return null;
7210
7107
  }
7211
7108
  const contextConfig = await getContextConfigById(dbClient_default)({
7212
7109
  scopes: {
7213
7110
  tenantId: this.config.tenantId,
7214
7111
  projectId: this.config.projectId,
7215
- graphId: this.config.graphId
7112
+ agentId: this.config.agentId
7216
7113
  },
7217
7114
  id: this.config.contextConfigId
7218
7115
  });
@@ -7259,67 +7156,67 @@ var Agent = class {
7259
7156
  }
7260
7157
  }
7261
7158
  /**
7262
- * Get the graph prompt for this agent's graph
7159
+ * Get the agent prompt for this agent's agent
7263
7160
  */
7264
- async getGraphPrompt() {
7161
+ async getAgentPrompt() {
7265
7162
  try {
7266
- const graphDefinition = await getFullGraphDefinition(dbClient_default)({
7163
+ const agentDefinition = await getFullAgentDefinition(dbClient_default)({
7267
7164
  scopes: {
7268
7165
  tenantId: this.config.tenantId,
7269
7166
  projectId: this.config.projectId,
7270
- graphId: this.config.graphId
7167
+ agentId: this.config.agentId
7271
7168
  }
7272
7169
  });
7273
- return graphDefinition?.graphPrompt || void 0;
7170
+ return agentDefinition?.prompt || void 0;
7274
7171
  } catch (error) {
7275
7172
  logger16.warn(
7276
7173
  {
7277
- graphId: this.config.graphId,
7174
+ agentId: this.config.agentId,
7278
7175
  error: error instanceof Error ? error.message : "Unknown error"
7279
7176
  },
7280
- "Failed to get graph prompt"
7177
+ "Failed to get agent prompt"
7281
7178
  );
7282
7179
  return void 0;
7283
7180
  }
7284
7181
  }
7285
7182
  /**
7286
- * Check if any agent in the graph has artifact components configured
7183
+ * Check if any agent in the agent has artifact components configured
7287
7184
  */
7288
- async hasGraphArtifactComponents() {
7185
+ async hasAgentArtifactComponents() {
7289
7186
  try {
7290
- const graphDefinition = await getFullGraphDefinition(dbClient_default)({
7187
+ const agentDefinition = await getFullAgentDefinition(dbClient_default)({
7291
7188
  scopes: {
7292
7189
  tenantId: this.config.tenantId,
7293
7190
  projectId: this.config.projectId,
7294
- graphId: this.config.graphId
7191
+ agentId: this.config.agentId
7295
7192
  }
7296
7193
  });
7297
- if (!graphDefinition) {
7194
+ if (!agentDefinition) {
7298
7195
  return false;
7299
7196
  }
7300
- return Object.values(graphDefinition.subAgents).some(
7197
+ return Object.values(agentDefinition.subAgents).some(
7301
7198
  (subAgent) => "artifactComponents" in subAgent && subAgent.artifactComponents && subAgent.artifactComponents.length > 0
7302
7199
  );
7303
7200
  } catch (error) {
7304
7201
  logger16.warn(
7305
7202
  {
7306
- graphId: this.config.graphId,
7203
+ agentId: this.config.agentId,
7307
7204
  tenantId: this.config.tenantId,
7308
7205
  projectId: this.config.projectId,
7309
7206
  error: error instanceof Error ? error.message : "Unknown error"
7310
7207
  },
7311
- "Failed to check graph artifact components, assuming none exist"
7208
+ "Failed to check agent artifact components, assuming none exist"
7312
7209
  );
7313
7210
  return this.artifactComponents.length > 0;
7314
7211
  }
7315
7212
  }
7316
7213
  /**
7317
7214
  * Build adaptive system prompt for Phase 2 structured output generation
7318
- * based on configured data components and artifact components across the graph
7215
+ * based on configured data components and artifact components across the agent
7319
7216
  */
7320
7217
  async buildPhase2SystemPrompt(runtimeContext) {
7321
7218
  const phase2Config = new Phase2Config();
7322
- const hasGraphArtifactComponents = await this.hasGraphArtifactComponents();
7219
+ const hasAgentArtifactComponents = await this.hasAgentArtifactComponents();
7323
7220
  const conversationId = runtimeContext?.metadata?.conversationId || runtimeContext?.contextId;
7324
7221
  const resolvedContext = conversationId ? await this.getResolvedContext(conversationId) : null;
7325
7222
  let processedPrompt = this.config.agentPrompt;
@@ -7359,7 +7256,7 @@ var Agent = class {
7359
7256
  dataComponents: this.config.dataComponents || [],
7360
7257
  artifactComponents: this.artifactComponents,
7361
7258
  hasArtifactComponents: this.artifactComponents && this.artifactComponents.length > 0,
7362
- hasGraphArtifactComponents,
7259
+ hasAgentArtifactComponents,
7363
7260
  artifacts: referenceArtifacts
7364
7261
  });
7365
7262
  }
@@ -7413,7 +7310,7 @@ var Agent = class {
7413
7310
  inputSchema: tool3.inputSchema || tool3.parameters || {},
7414
7311
  usageGuidelines: name.startsWith("transfer_to_") || name.startsWith("delegate_to_") ? `Use this tool to ${name.startsWith("transfer_to_") ? "transfer" : "delegate"} to another agent when appropriate.` : "Use this tool when appropriate for the task at hand."
7415
7312
  }));
7416
- const { getConversationScopedArtifacts } = await import('./conversations-JSORLLWS.js');
7313
+ const { getConversationScopedArtifacts } = await import('./conversations-OFIM2WLJ.js');
7417
7314
  const historyConfig = this.config.conversationHistoryConfig ?? createDefaultConversationHistoryConfig();
7418
7315
  const referenceArtifacts = await getConversationScopedArtifacts({
7419
7316
  tenantId: this.config.tenantId,
@@ -7423,10 +7320,10 @@ var Agent = class {
7423
7320
  });
7424
7321
  const componentDataComponents = excludeDataComponents ? [] : this.config.dataComponents || [];
7425
7322
  const isThinkingPreparation = this.config.dataComponents && this.config.dataComponents.length > 0 && excludeDataComponents;
7426
- let graphPrompt = await this.getGraphPrompt();
7427
- if (graphPrompt && resolvedContext) {
7323
+ let agentPrompt = await this.getAgentPrompt();
7324
+ if (agentPrompt && resolvedContext) {
7428
7325
  try {
7429
- graphPrompt = TemplateEngine.render(graphPrompt, resolvedContext, {
7326
+ agentPrompt = TemplateEngine.render(agentPrompt, resolvedContext, {
7430
7327
  strict: false,
7431
7328
  preserveUnresolved: false
7432
7329
  });
@@ -7436,20 +7333,20 @@ var Agent = class {
7436
7333
  conversationId,
7437
7334
  error: error instanceof Error ? error.message : "Unknown error"
7438
7335
  },
7439
- "Failed to process graph prompt with context, using original"
7336
+ "Failed to process agent prompt with context, using original"
7440
7337
  );
7441
7338
  }
7442
7339
  }
7443
7340
  const shouldIncludeArtifactComponents = !excludeDataComponents;
7444
- const hasGraphArtifactComponents = await this.hasGraphArtifactComponents();
7341
+ const hasAgentArtifactComponents = await this.hasAgentArtifactComponents();
7445
7342
  const config = {
7446
7343
  corePrompt: processedPrompt,
7447
- graphPrompt,
7344
+ agentPrompt,
7448
7345
  tools: toolDefinitions,
7449
7346
  dataComponents: componentDataComponents,
7450
7347
  artifacts: referenceArtifacts,
7451
7348
  artifactComponents: shouldIncludeArtifactComponents ? this.artifactComponents : [],
7452
- hasGraphArtifactComponents,
7349
+ hasAgentArtifactComponents,
7453
7350
  isThinkingPreparation,
7454
7351
  hasTransferRelations: (this.config.transferRelations?.length ?? 0) > 0,
7455
7352
  hasDelegateRelations: (this.config.delegateRelations?.length ?? 0) > 0
@@ -7466,7 +7363,7 @@ var Agent = class {
7466
7363
  execute: async ({ artifactId, toolCallId }) => {
7467
7364
  logger16.info({ artifactId, toolCallId }, "get_artifact_full executed");
7468
7365
  const streamRequestId = this.getStreamRequestId();
7469
- const artifactService = graphSessionManager.getArtifactService(streamRequestId);
7366
+ const artifactService = agentSessionManager.getArtifactService(streamRequestId);
7470
7367
  if (!artifactService) {
7471
7368
  throw new Error(`ArtifactService not found for session ${streamRequestId}`);
7472
7369
  }
@@ -7500,7 +7397,7 @@ var Agent = class {
7500
7397
  // Provide a default tool set that is always available to the agent.
7501
7398
  async getDefaultTools(streamRequestId) {
7502
7399
  const defaultTools = {};
7503
- if (await this.graphHasArtifactComponents()) {
7400
+ if (await this.agentHasArtifactComponents()) {
7504
7401
  defaultTools.get_reference_artifact = this.getArtifactTools();
7505
7402
  }
7506
7403
  const hasStructuredOutput = this.config.dataComponents && this.config.dataComponents.length > 0;
@@ -7728,20 +7625,20 @@ var Agent = class {
7728
7625
  return result;
7729
7626
  }
7730
7627
  }
7731
- // Check if any agents in the graph have artifact components
7732
- async graphHasArtifactComponents() {
7628
+ // Check if any agents in the agent have artifact components
7629
+ async agentHasArtifactComponents() {
7733
7630
  try {
7734
- return await graphHasArtifactComponents(dbClient_default)({
7631
+ return await agentHasArtifactComponents(dbClient_default)({
7735
7632
  scopes: {
7736
7633
  tenantId: this.config.tenantId,
7737
7634
  projectId: this.config.projectId,
7738
- graphId: this.config.graphId
7635
+ agentId: this.config.agentId
7739
7636
  }
7740
7637
  });
7741
7638
  } catch (error) {
7742
7639
  logger16.error(
7743
- { error, graphId: this.config.graphId },
7744
- "Failed to check graph artifact components"
7640
+ { error, agentId: this.config.agentId },
7641
+ "Failed to check agent artifact components"
7745
7642
  );
7746
7643
  return false;
7747
7644
  }
@@ -7873,7 +7770,7 @@ var Agent = class {
7873
7770
  const last = steps.at(-1);
7874
7771
  if (last && "text" in last && last.text) {
7875
7772
  try {
7876
- await graphSessionManager.recordEvent(
7773
+ await agentSessionManager.recordEvent(
7877
7774
  this.getStreamRequestId(),
7878
7775
  "agent_reasoning",
7879
7776
  this.config.id,
@@ -7885,8 +7782,14 @@ var Agent = class {
7885
7782
  logger16.debug({ error }, "Failed to track agent reasoning");
7886
7783
  }
7887
7784
  }
7888
- if (last && "toolCalls" in last && last.toolCalls) {
7889
- return last.toolCalls.some((tc) => tc.toolName.startsWith("transfer_to_"));
7785
+ if (steps.length >= 2) {
7786
+ const previousStep = steps[steps.length - 2];
7787
+ if (previousStep && "toolCalls" in previousStep && previousStep.toolCalls) {
7788
+ const hasTransferCall = previousStep.toolCalls.some((tc) => tc.toolName.startsWith("transfer_to_"));
7789
+ if (hasTransferCall && "toolResults" in previousStep && previousStep.toolResults) {
7790
+ return true;
7791
+ }
7792
+ }
7890
7793
  }
7891
7794
  return steps.length >= this.getMaxGenerationSteps();
7892
7795
  },
@@ -7987,7 +7890,7 @@ var Agent = class {
7987
7890
  const last = steps.at(-1);
7988
7891
  if (last && "text" in last && last.text) {
7989
7892
  try {
7990
- await graphSessionManager.recordEvent(
7893
+ await agentSessionManager.recordEvent(
7991
7894
  this.getStreamRequestId(),
7992
7895
  "agent_reasoning",
7993
7896
  this.config.id,
@@ -7999,10 +7902,16 @@ var Agent = class {
7999
7902
  logger16.debug({ error }, "Failed to track agent reasoning");
8000
7903
  }
8001
7904
  }
8002
- if (last && "toolCalls" in last && last.toolCalls) {
8003
- return last.toolCalls.some(
8004
- (tc) => tc.toolName.startsWith("transfer_to_") || tc.toolName === "thinking_complete"
8005
- );
7905
+ if (steps.length >= 2) {
7906
+ const previousStep = steps[steps.length - 2];
7907
+ if (previousStep && "toolCalls" in previousStep && previousStep.toolCalls) {
7908
+ const hasStopTool = previousStep.toolCalls.some(
7909
+ (tc) => tc.toolName.startsWith("transfer_to_") || tc.toolName === "thinking_complete"
7910
+ );
7911
+ if (hasStopTool && "toolResults" in previousStep && previousStep.toolResults) {
7912
+ return true;
7913
+ }
7914
+ }
8006
7915
  }
8007
7916
  return steps.length >= this.getMaxGenerationSteps();
8008
7917
  },
@@ -8268,7 +8177,7 @@ ${output}${structureHintsFormatted}`;
8268
8177
  };
8269
8178
  if (streamRequestId) {
8270
8179
  const generationType = response.object ? "object_generation" : "text_generation";
8271
- graphSessionManager.recordEvent(streamRequestId, "agent_generate", this.config.id, {
8180
+ agentSessionManager.recordEvent(streamRequestId, "agent_generate", this.config.id, {
8272
8181
  parts: (formattedContent?.parts || []).map((part) => ({
8273
8182
  type: part.kind === "text" ? "text" : part.kind === "data" ? "tool_result" : "text",
8274
8183
  content: part.text || JSON.stringify(part.data)
@@ -8308,11 +8217,11 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
8308
8217
  dataComponents,
8309
8218
  artifactComponents
8310
8219
  ] = await Promise.all([
8311
- getRelatedAgentsForGraph(dbClient_default)({
8220
+ getRelatedAgentsForAgent(dbClient_default)({
8312
8221
  scopes: {
8313
8222
  tenantId: config.tenantId,
8314
8223
  projectId: config.projectId,
8315
- graphId: config.graphId
8224
+ agentId: config.agentId
8316
8225
  },
8317
8226
  subAgentId: config.subAgentId
8318
8227
  }),
@@ -8320,7 +8229,7 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
8320
8229
  scopes: {
8321
8230
  tenantId: config.tenantId,
8322
8231
  projectId: config.projectId,
8323
- graphId: config.graphId,
8232
+ agentId: config.agentId,
8324
8233
  subAgentId: config.subAgentId
8325
8234
  }
8326
8235
  }),
@@ -8328,7 +8237,7 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
8328
8237
  scopes: {
8329
8238
  tenantId: config.tenantId,
8330
8239
  projectId: config.projectId,
8331
- graphId: config.graphId,
8240
+ agentId: config.agentId,
8332
8241
  subAgentId: config.subAgentId
8333
8242
  }
8334
8243
  }),
@@ -8336,7 +8245,7 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
8336
8245
  scopes: {
8337
8246
  tenantId: config.tenantId,
8338
8247
  projectId: config.projectId,
8339
- graphId: config.graphId,
8248
+ agentId: config.agentId,
8340
8249
  subAgentId: config.subAgentId
8341
8250
  }
8342
8251
  })
@@ -8349,16 +8258,16 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
8349
8258
  scopes: {
8350
8259
  tenantId: config.tenantId,
8351
8260
  projectId: config.projectId,
8352
- graphId: config.graphId
8261
+ agentId: config.agentId
8353
8262
  },
8354
8263
  subAgentId: relation.id
8355
8264
  });
8356
8265
  if (relatedAgent) {
8357
- const relatedAgentRelations = await getRelatedAgentsForGraph(dbClient_default)({
8266
+ const relatedAgentRelations = await getRelatedAgentsForAgent(dbClient_default)({
8358
8267
  scopes: {
8359
8268
  tenantId: config.tenantId,
8360
8269
  projectId: config.projectId,
8361
- graphId: config.graphId
8270
+ agentId: config.agentId
8362
8271
  },
8363
8272
  subAgentId: relation.id
8364
8273
  });
@@ -8388,7 +8297,7 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
8388
8297
  id: config.subAgentId,
8389
8298
  tenantId: config.tenantId,
8390
8299
  projectId: config.projectId,
8391
- graphId: config.graphId,
8300
+ agentId: config.agentId,
8392
8301
  baseUrl: config.baseUrl,
8393
8302
  apiKey: config.apiKey,
8394
8303
  name: config.name,
@@ -8400,7 +8309,7 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
8400
8309
  id: relation.id,
8401
8310
  tenantId: config.tenantId,
8402
8311
  projectId: config.projectId,
8403
- graphId: config.graphId,
8312
+ agentId: config.agentId,
8404
8313
  baseUrl: config.baseUrl,
8405
8314
  apiKey: config.apiKey,
8406
8315
  name: relation.name,
@@ -8416,7 +8325,7 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
8416
8325
  id: relation.id,
8417
8326
  tenantId: config.tenantId,
8418
8327
  projectId: config.projectId,
8419
- graphId: config.graphId,
8328
+ agentId: config.agentId,
8420
8329
  name: relation.name,
8421
8330
  description: relation.description,
8422
8331
  agentPrompt: "",
@@ -8432,7 +8341,7 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
8432
8341
  id: relation.id,
8433
8342
  tenantId: config.tenantId,
8434
8343
  projectId: config.projectId,
8435
- graphId: config.graphId,
8344
+ agentId: config.agentId,
8436
8345
  baseUrl: config.baseUrl,
8437
8346
  apiKey: config.apiKey,
8438
8347
  name: relation.name,
@@ -8467,7 +8376,7 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
8467
8376
  );
8468
8377
  const artifactStreamRequestId = task.context?.metadata?.streamRequestId;
8469
8378
  if (artifactStreamRequestId && artifactComponents.length > 0) {
8470
- graphSessionManager.updateArtifactComponents(artifactStreamRequestId, artifactComponents);
8379
+ agentSessionManager.updateArtifactComponents(artifactStreamRequestId, artifactComponents);
8471
8380
  }
8472
8381
  let contextId = task.context?.conversationId;
8473
8382
  if (!contextId || contextId === "default" || contextId === "") {
@@ -8495,7 +8404,7 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
8495
8404
  "Delegated agent - streaming disabled"
8496
8405
  );
8497
8406
  if (streamRequestId && config.tenantId && config.projectId) {
8498
- toolSessionManager.ensureGraphSession(
8407
+ toolSessionManager.ensureAgentSession(
8499
8408
  streamRequestId,
8500
8409
  config.tenantId,
8501
8410
  config.projectId,
@@ -8527,17 +8436,42 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
8527
8436
  const toolResult = allToolResults.find(
8528
8437
  (result) => result.toolCallId === toolCall.toolCallId
8529
8438
  );
8439
+ logger17.info({
8440
+ toolCallName: toolCall.toolName,
8441
+ toolCallId: toolCall.toolCallId,
8442
+ hasToolResult: !!toolResult,
8443
+ toolResultOutput: toolResult?.output,
8444
+ toolResultKeys: toolResult?.output ? Object.keys(toolResult.output) : []
8445
+ }, "[DEBUG] Transfer tool result found");
8530
8446
  const isValidTransferResult = (output) => {
8531
- return typeof output === "object" && output !== null && "type" in output && "target" in output && output.type === "transfer" && typeof output.target === "string" && (output.reason === void 0 || typeof output.reason === "string");
8447
+ return typeof output === "object" && output !== null && "type" in output && "targetSubAgentId" in output && output.type === "transfer" && typeof output.targetSubAgentId === "string";
8532
8448
  };
8533
8449
  const responseText = response.text || (response.object ? JSON.stringify(response.object) : "");
8534
8450
  const transferReason = responseText || allThoughts[allThoughts.length - 1]?.text || "Agent requested transfer. No reason provided.";
8535
8451
  if (toolResult?.output && isValidTransferResult(toolResult.output)) {
8536
8452
  const transferResult = toolResult.output;
8453
+ logger17.info({
8454
+ validationPassed: true,
8455
+ transferResult,
8456
+ targetSubAgentId: transferResult.targetSubAgentId,
8457
+ fromSubAgentId: transferResult.fromSubAgentId
8458
+ }, "[DEBUG] Transfer validation passed, extracted data");
8459
+ const artifactData = {
8460
+ type: "transfer",
8461
+ targetSubAgentId: transferResult.targetSubAgentId,
8462
+ fromSubAgentId: transferResult.fromSubAgentId,
8463
+ task_id: task.id,
8464
+ reason: transferReason,
8465
+ original_message: userMessage
8466
+ };
8467
+ logger17.info({
8468
+ artifactData,
8469
+ artifactDataKeys: Object.keys(artifactData)
8470
+ }, "[DEBUG] Artifact data being returned");
8537
8471
  return {
8538
8472
  status: {
8539
8473
  state: TaskState.Completed,
8540
- message: `Transfer requested to ${transferResult.target}`
8474
+ message: `Transfer requested to ${transferResult.targetSubAgentId}`
8541
8475
  },
8542
8476
  artifacts: [
8543
8477
  {
@@ -8545,18 +8479,19 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
8545
8479
  parts: [
8546
8480
  {
8547
8481
  kind: "data",
8548
- data: {
8549
- type: "transfer",
8550
- target: transferResult.target,
8551
- task_id: task.id,
8552
- reason: transferReason,
8553
- original_message: userMessage
8554
- }
8482
+ data: artifactData
8555
8483
  }
8556
8484
  ]
8557
8485
  }
8558
8486
  ]
8559
8487
  };
8488
+ } else {
8489
+ logger17.warn({
8490
+ hasToolResult: !!toolResult,
8491
+ hasOutput: !!toolResult?.output,
8492
+ validationPassed: false,
8493
+ output: toolResult?.output
8494
+ }, "[DEBUG] Transfer validation FAILED");
8560
8495
  }
8561
8496
  }
8562
8497
  }
@@ -8588,128 +8523,171 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
8588
8523
  };
8589
8524
  };
8590
8525
  var createTaskHandlerConfig = async (params) => {
8591
- const agent = await getSubAgentById(dbClient_default)({
8526
+ const subAgent = await getSubAgentById(dbClient_default)({
8592
8527
  scopes: {
8593
8528
  tenantId: params.tenantId,
8594
8529
  projectId: params.projectId,
8595
- graphId: params.graphId
8530
+ agentId: params.agentId
8596
8531
  },
8597
8532
  subAgentId: params.subAgentId
8598
8533
  });
8599
- const agentGraph = await getAgentGraphById(dbClient_default)({
8534
+ const agent = await getAgentById(dbClient_default)({
8600
8535
  scopes: {
8601
8536
  tenantId: params.tenantId,
8602
8537
  projectId: params.projectId,
8603
- graphId: params.graphId
8538
+ agentId: params.agentId
8604
8539
  }
8605
8540
  });
8606
- if (!agent) {
8541
+ if (!subAgent) {
8607
8542
  throw new Error(`Agent not found: ${params.subAgentId}`);
8608
8543
  }
8609
- const effectiveModels = await resolveModelConfig(params.graphId, agent);
8610
- const effectiveConversationHistoryConfig = agent.conversationHistoryConfig || { mode: "full" };
8544
+ const effectiveModels = await resolveModelConfig(params.agentId, subAgent);
8545
+ const effectiveConversationHistoryConfig = subAgent.conversationHistoryConfig || { mode: "full" };
8611
8546
  return {
8612
8547
  tenantId: params.tenantId,
8613
8548
  projectId: params.projectId,
8614
- graphId: params.graphId,
8549
+ agentId: params.agentId,
8615
8550
  subAgentId: params.subAgentId,
8616
8551
  agentSchema: {
8617
- id: agent.id,
8618
- name: agent.name,
8619
- description: agent.description,
8620
- prompt: agent.prompt,
8552
+ id: subAgent.id,
8553
+ name: subAgent.name,
8554
+ description: subAgent.description,
8555
+ prompt: subAgent.prompt,
8621
8556
  models: effectiveModels,
8622
8557
  conversationHistoryConfig: effectiveConversationHistoryConfig || null,
8623
- stopWhen: agent.stopWhen || null,
8624
- createdAt: agent.createdAt,
8625
- updatedAt: agent.updatedAt
8558
+ stopWhen: subAgent.stopWhen || null,
8559
+ createdAt: subAgent.createdAt,
8560
+ updatedAt: subAgent.updatedAt
8626
8561
  },
8627
8562
  baseUrl: params.baseUrl,
8628
8563
  apiKey: params.apiKey,
8629
- name: agent.name,
8630
- description: agent.description,
8564
+ name: subAgent.name,
8565
+ description: subAgent.description,
8631
8566
  conversationHistoryConfig: effectiveConversationHistoryConfig,
8632
- contextConfigId: agentGraph?.contextConfigId || void 0
8567
+ contextConfigId: agent?.contextConfigId || void 0
8633
8568
  };
8634
8569
  };
8635
8570
 
8636
- // src/data/agentGraph.ts
8637
- async function hydrateGraph({
8638
- dbGraph,
8571
+ // src/data/agents.ts
8572
+ function createAgentCard({
8573
+ dbAgent,
8574
+ baseUrl
8575
+ }) {
8576
+ const description = dbAgent.description || "AI Agent";
8577
+ return {
8578
+ name: dbAgent.name,
8579
+ description,
8580
+ url: baseUrl ? `${baseUrl}/a2a` : "",
8581
+ version: "1.0.0",
8582
+ capabilities: {
8583
+ streaming: true,
8584
+ // Enable streaming for A2A compliance
8585
+ pushNotifications: false,
8586
+ stateTransitionHistory: false
8587
+ },
8588
+ defaultInputModes: ["text", "text/plain"],
8589
+ defaultOutputModes: ["text", "text/plain"],
8590
+ skills: [],
8591
+ // Add provider info if available
8592
+ ...baseUrl && {
8593
+ provider: {
8594
+ organization: "Inkeep",
8595
+ url: baseUrl
8596
+ }
8597
+ }
8598
+ };
8599
+ }
8600
+ function generateDescriptionWithTransfers(baseDescription, internalRelations, externalRelations) {
8601
+ const transfers = [
8602
+ ...internalRelations.filter((rel) => rel.relationType === "transfer"),
8603
+ ...externalRelations.filter((rel) => rel.relationType === "transfer")
8604
+ ];
8605
+ const delegates = [
8606
+ ...internalRelations.filter((rel) => rel.relationType === "delegate"),
8607
+ ...externalRelations.filter((rel) => rel.relationType === "delegate")
8608
+ ];
8609
+ if (transfers.length === 0 && delegates.length === 0) {
8610
+ return baseDescription;
8611
+ }
8612
+ let enhancedDescription = baseDescription;
8613
+ if (transfers.length > 0) {
8614
+ const transferList = transfers.map((rel) => {
8615
+ const name = rel.externalAgent?.name || rel.name;
8616
+ const desc = rel.externalAgent?.description || rel.description || "";
8617
+ return `- ${name}: ${desc}`;
8618
+ }).join("\n");
8619
+ enhancedDescription += `
8620
+
8621
+ Can transfer to:
8622
+ ${transferList}`;
8623
+ }
8624
+ if (delegates.length > 0) {
8625
+ const delegateList = delegates.map((rel) => {
8626
+ const name = rel.externalAgent?.name || rel.name;
8627
+ const desc = rel.externalAgent?.description || rel.description || "";
8628
+ return `- ${name}: ${desc}`;
8629
+ }).join("\n");
8630
+ enhancedDescription += `
8631
+
8632
+ Can delegate to:
8633
+ ${delegateList}`;
8634
+ }
8635
+ return enhancedDescription;
8636
+ }
8637
+ async function hydrateAgent({
8638
+ dbAgent,
8639
+ agentId,
8639
8640
  baseUrl,
8640
- apiKey
8641
+ apiKey,
8642
+ credentialStoreRegistry
8641
8643
  }) {
8642
8644
  try {
8643
- if (!dbGraph.defaultSubAgentId) {
8644
- throw new Error(`Graph ${dbGraph.id} does not have a default agent configured`);
8645
- }
8646
- const defaultSubAgent = await getSubAgentById(dbClient_default)({
8647
- scopes: {
8648
- tenantId: dbGraph.tenantId,
8649
- projectId: dbGraph.projectId,
8650
- graphId: dbGraph.id
8651
- },
8652
- subAgentId: dbGraph.defaultSubAgentId
8653
- });
8654
- if (!defaultSubAgent) {
8655
- throw new Error(
8656
- `Default agent ${dbGraph.defaultSubAgentId} not found for graph ${dbGraph.id}`
8657
- );
8658
- }
8659
8645
  const taskHandlerConfig = await createTaskHandlerConfig({
8660
- tenantId: dbGraph.tenantId,
8661
- projectId: dbGraph.projectId,
8662
- graphId: dbGraph.id,
8663
- subAgentId: dbGraph.defaultSubAgentId,
8646
+ tenantId: dbAgent.tenantId,
8647
+ projectId: dbAgent.projectId,
8648
+ agentId,
8649
+ subAgentId: dbAgent.id,
8664
8650
  baseUrl,
8665
8651
  apiKey
8666
8652
  });
8667
- const taskHandler = createTaskHandler(taskHandlerConfig);
8668
- const agentCard = {
8669
- name: dbGraph.name,
8670
- description: dbGraph.description || `Agent graph: ${dbGraph.name}`,
8671
- url: baseUrl ? `${baseUrl}/a2a` : "",
8672
- version: "1.0.0",
8673
- capabilities: {
8674
- streaming: true,
8675
- // Enable streaming for A2A compliance
8676
- pushNotifications: false,
8677
- stateTransitionHistory: false
8678
- },
8679
- defaultInputModes: ["text", "text/plain"],
8680
- defaultOutputModes: ["text", "text/plain"],
8681
- skills: [],
8682
- // TODO: Could aggregate skills from all agents in the graph
8683
- // Add provider info if available
8684
- ...baseUrl && {
8685
- provider: {
8686
- organization: "Inkeep",
8687
- url: baseUrl
8688
- }
8689
- }
8690
- };
8653
+ const taskHandler = createTaskHandler(taskHandlerConfig, credentialStoreRegistry);
8654
+ const agentCard = createAgentCard({
8655
+ dbAgent,
8656
+ baseUrl
8657
+ });
8691
8658
  return {
8692
- subAgentId: dbGraph.id,
8693
- // Use graph ID as agent ID for A2A purposes
8694
- tenantId: dbGraph.tenantId,
8695
- projectId: dbGraph.projectId,
8696
- graphId: dbGraph.id,
8659
+ subAgentId: dbAgent.id,
8660
+ tenantId: dbAgent.tenantId,
8661
+ projectId: dbAgent.projectId,
8662
+ agentId,
8697
8663
  agentCard,
8698
8664
  taskHandler
8699
8665
  };
8700
8666
  } catch (error) {
8701
- console.error(`\u274C Failed to hydrate graph ${dbGraph.id}:`, error);
8667
+ console.error(`\u274C Failed to hydrate agent ${dbAgent.id}:`, error);
8702
8668
  throw error;
8703
8669
  }
8704
8670
  }
8705
- async function getRegisteredGraph(executionContext) {
8706
- const { tenantId, projectId, graphId, baseUrl, apiKey } = executionContext;
8707
- const dbGraph = await getAgentGraphById(dbClient_default)({ scopes: { tenantId, projectId, graphId } });
8708
- if (!dbGraph) {
8671
+ async function getRegisteredAgent(executionContext, credentialStoreRegistry) {
8672
+ const { tenantId, projectId, agentId, subAgentId, baseUrl, apiKey } = executionContext;
8673
+ if (!subAgentId) {
8674
+ throw new Error("Agent ID is required");
8675
+ }
8676
+ const dbAgent = await getSubAgentById(dbClient_default)({
8677
+ scopes: { tenantId, projectId, agentId },
8678
+ subAgentId
8679
+ });
8680
+ if (!dbAgent) {
8709
8681
  return null;
8710
8682
  }
8711
8683
  const agentFrameworkBaseUrl = `${baseUrl}/agents`;
8712
- return hydrateGraph({ dbGraph, baseUrl: agentFrameworkBaseUrl, apiKey });
8684
+ return hydrateAgent({
8685
+ dbAgent,
8686
+ agentId,
8687
+ baseUrl: agentFrameworkBaseUrl,
8688
+ credentialStoreRegistry,
8689
+ apiKey
8690
+ });
8713
8691
  }
8714
8692
 
8715
8693
  // src/routes/agents.ts
@@ -8761,7 +8739,7 @@ app.openapi(
8761
8739
  "OpenTelemetry headers: well-known agent.json"
8762
8740
  );
8763
8741
  const executionContext = getRequestExecutionContext(c);
8764
- const { tenantId, projectId, graphId, subAgentId } = executionContext;
8742
+ const { tenantId, projectId, agentId, subAgentId } = executionContext;
8765
8743
  console.dir("executionContext", executionContext);
8766
8744
  if (subAgentId) {
8767
8745
  logger18.info(
@@ -8769,7 +8747,7 @@ app.openapi(
8769
8747
  message: "getRegisteredAgent (agent-level)",
8770
8748
  tenantId,
8771
8749
  projectId,
8772
- graphId,
8750
+ agentId,
8773
8751
  subAgentId
8774
8752
  },
8775
8753
  "agent-level well-known agent.json"
@@ -8787,21 +8765,21 @@ app.openapi(
8787
8765
  } else {
8788
8766
  logger18.info(
8789
8767
  {
8790
- message: "getRegisteredGraph (graph-level)",
8768
+ message: "getRegisteredAgent (agent-level)",
8791
8769
  tenantId,
8792
8770
  projectId,
8793
- graphId
8771
+ agentId
8794
8772
  },
8795
- "graph-level well-known agent.json"
8773
+ "agent-level well-known agent.json"
8796
8774
  );
8797
- const graph = await getRegisteredGraph(executionContext);
8798
- if (!graph) {
8775
+ const agent = await getRegisteredAgent(executionContext);
8776
+ if (!agent) {
8799
8777
  throw createApiError({
8800
8778
  code: "not_found",
8801
- message: "Graph not found"
8779
+ message: "Agent not found"
8802
8780
  });
8803
8781
  }
8804
- return c.json(graph.agentCard);
8782
+ return c.json(agent.agentCard);
8805
8783
  }
8806
8784
  }
8807
8785
  );
@@ -8820,14 +8798,14 @@ app.post("/a2a", async (c) => {
8820
8798
  "OpenTelemetry headers: a2a"
8821
8799
  );
8822
8800
  const executionContext = getRequestExecutionContext(c);
8823
- const { tenantId, projectId, graphId, subAgentId } = executionContext;
8801
+ const { tenantId, projectId, agentId, subAgentId } = executionContext;
8824
8802
  if (subAgentId) {
8825
8803
  logger18.info(
8826
8804
  {
8827
8805
  message: "a2a (agent-level)",
8828
8806
  tenantId,
8829
8807
  projectId,
8830
- graphId,
8808
+ agentId,
8831
8809
  subAgentId
8832
8810
  },
8833
8811
  "agent-level a2a endpoint"
@@ -8848,17 +8826,17 @@ app.post("/a2a", async (c) => {
8848
8826
  } else {
8849
8827
  logger18.info(
8850
8828
  {
8851
- message: "a2a (graph-level)",
8829
+ message: "a2a (agent-level)",
8852
8830
  tenantId,
8853
8831
  projectId,
8854
- graphId
8832
+ agentId
8855
8833
  },
8856
- "graph-level a2a endpoint"
8834
+ "agent-level a2a endpoint"
8857
8835
  );
8858
- const graph = await getAgentGraphWithDefaultSubAgent(dbClient_default)({
8859
- scopes: { tenantId, projectId, graphId }
8836
+ const agent = await getAgentWithDefaultSubAgent(dbClient_default)({
8837
+ scopes: { tenantId, projectId, agentId }
8860
8838
  });
8861
- if (!graph) {
8839
+ if (!agent) {
8862
8840
  return c.json(
8863
8841
  {
8864
8842
  jsonrpc: "2.0",
@@ -8868,17 +8846,17 @@ app.post("/a2a", async (c) => {
8868
8846
  404
8869
8847
  );
8870
8848
  }
8871
- if (!graph.defaultSubAgentId) {
8849
+ if (!agent.defaultSubAgentId) {
8872
8850
  return c.json(
8873
8851
  {
8874
8852
  jsonrpc: "2.0",
8875
- error: { code: -32004, message: "Graph does not have a default agent configured" },
8853
+ error: { code: -32004, message: "Agent does not have a default agent configured" },
8876
8854
  id: null
8877
8855
  },
8878
8856
  400
8879
8857
  );
8880
8858
  }
8881
- executionContext.subAgentId = graph.defaultSubAgentId;
8859
+ executionContext.subAgentId = agent.defaultSubAgentId;
8882
8860
  const credentialStores = c.get("credentialStores");
8883
8861
  const defaultSubAgent = await getRegisteredAgent(executionContext, credentialStores);
8884
8862
  if (!defaultSubAgent) {
@@ -8895,6 +8873,55 @@ app.post("/a2a", async (c) => {
8895
8873
  }
8896
8874
  });
8897
8875
  var agents_default = app;
8876
+ function isTransferTask(result) {
8877
+ console.log(
8878
+ "[isTransferTask] Checking result:",
8879
+ JSON.stringify(
8880
+ {
8881
+ hasArtifacts: "artifacts" in result,
8882
+ artifactsLength: result.kind === "task" ? result.artifacts?.length : 0,
8883
+ firstArtifactParts: result.kind === "task" ? result.artifacts?.[0]?.parts?.length : 0,
8884
+ allParts: result.kind === "task" ? result.artifacts?.[0]?.parts?.map((p, i) => ({
8885
+ index: i,
8886
+ kind: p.kind,
8887
+ hasData: !!(p.kind === "data" && p.data),
8888
+ dataType: p.kind === "data" ? p.data?.type : void 0,
8889
+ dataKeys: p.kind === "data" ? Object.keys(p.data) : []
8890
+ })) : []
8891
+ },
8892
+ null,
8893
+ 2
8894
+ )
8895
+ );
8896
+ if (!("artifacts" in result) || !result.artifacts) {
8897
+ console.log("[isTransferTask] No artifacts found");
8898
+ return false;
8899
+ }
8900
+ const hasTransfer = result.artifacts.some(
8901
+ (artifact) => artifact.parts.some((part) => {
8902
+ if (part.kind !== "data" || !part.data) return false;
8903
+ const isTransfer = typeof part.data === "object" && "type" in part.data && part.data.type === "transfer";
8904
+ if (isTransfer) {
8905
+ console.log("[isTransferTask] Found transfer data:", JSON.stringify(part.data, null, 2));
8906
+ }
8907
+ return isTransfer;
8908
+ })
8909
+ );
8910
+ console.log("[isTransferTask] Result:", hasTransfer);
8911
+ return hasTransfer;
8912
+ }
8913
+ function extractTransferData(task) {
8914
+ for (const artifact of task.artifacts) {
8915
+ for (const part of artifact.parts) {
8916
+ if (part.kind === "data" && part.data?.type === "transfer") {
8917
+ return part.data;
8918
+ }
8919
+ }
8920
+ }
8921
+ return null;
8922
+ }
8923
+
8924
+ // src/a2a/transfer.ts
8898
8925
  var logger19 = getLogger("Transfer");
8899
8926
  async function executeTransfer({
8900
8927
  tenantId,
@@ -8902,19 +8929,25 @@ async function executeTransfer({
8902
8929
  projectId,
8903
8930
  targetSubAgentId
8904
8931
  }) {
8905
- logger19.info({ targetAgent: targetSubAgentId }, "Executing transfer to agent");
8906
- await setActiveAgentForThread(dbClient_default)({
8907
- scopes: { tenantId, projectId },
8932
+ logger19.info({
8933
+ targetAgent: targetSubAgentId,
8908
8934
  threadId,
8909
- subAgentId: targetSubAgentId
8910
- });
8935
+ tenantId,
8936
+ projectId
8937
+ }, "Executing transfer - calling setActiveAgentForThread");
8938
+ try {
8939
+ await setActiveAgentForThread(dbClient_default)({
8940
+ scopes: { tenantId, projectId },
8941
+ threadId,
8942
+ subAgentId: targetSubAgentId
8943
+ });
8944
+ logger19.info({ targetAgent: targetSubAgentId, threadId }, "Successfully updated active_sub_agent_id in database");
8945
+ } catch (error) {
8946
+ logger19.error({ error, targetAgent: targetSubAgentId, threadId }, "Failed to update active_sub_agent_id");
8947
+ throw error;
8948
+ }
8911
8949
  return { success: true, targetSubAgentId };
8912
8950
  }
8913
- function isTransferResponse(result) {
8914
- return result?.artifacts.some(
8915
- (artifact) => artifact.parts.some((part) => part.kind === "data" && part.data?.type === "transfer")
8916
- );
8917
- }
8918
8951
  var SSEStreamHelper = class {
8919
8952
  constructor(stream2, requestId2, timestamp) {
8920
8953
  this.stream = stream2;
@@ -9514,24 +9547,26 @@ var ExecutionHandler = class {
9514
9547
  sseHelper,
9515
9548
  emitOperations
9516
9549
  } = params;
9517
- const { tenantId, projectId, graphId, apiKey, baseUrl } = executionContext;
9550
+ const { tenantId, projectId, agentId, apiKey, baseUrl } = executionContext;
9518
9551
  registerStreamHelper(requestId2, sseHelper);
9519
- graphSessionManager.createSession(requestId2, graphId, tenantId, projectId, conversationId);
9552
+ agentSessionManager.createSession(requestId2, agentId, tenantId, projectId, conversationId);
9520
9553
  if (emitOperations) {
9521
- graphSessionManager.enableEmitOperations(requestId2);
9554
+ agentSessionManager.enableEmitOperations(requestId2);
9522
9555
  }
9523
9556
  logger20.info(
9524
- { sessionId: requestId2, graphId, conversationId, emitOperations },
9525
- "Created GraphSession for message execution"
9557
+ { sessionId: requestId2, agentId, conversationId, emitOperations },
9558
+ "Created AgentSession for message execution"
9526
9559
  );
9527
- let graphConfig = null;
9560
+ let agentConfig = null;
9528
9561
  try {
9529
- graphConfig = await getFullGraph(dbClient_default)({ scopes: { tenantId, projectId, graphId } });
9530
- if (graphConfig?.statusUpdates && graphConfig.statusUpdates.enabled !== false) {
9531
- graphSessionManager.initializeStatusUpdates(
9562
+ agentConfig = await getFullAgent(dbClient_default)({
9563
+ scopes: { tenantId, projectId, agentId }
9564
+ });
9565
+ if (agentConfig?.statusUpdates && agentConfig.statusUpdates.enabled !== false) {
9566
+ agentSessionManager.initializeStatusUpdates(
9532
9567
  requestId2,
9533
- graphConfig.statusUpdates,
9534
- graphConfig.models?.summarizer
9568
+ agentConfig.statusUpdates,
9569
+ agentConfig.models?.summarizer
9535
9570
  );
9536
9571
  }
9537
9572
  } catch (error) {
@@ -9547,9 +9582,9 @@ var ExecutionHandler = class {
9547
9582
  let iterations = 0;
9548
9583
  let errorCount = 0;
9549
9584
  let task = null;
9550
- let fromAgentId;
9585
+ let fromSubAgentId;
9551
9586
  try {
9552
- await sseHelper.writeOperation(agentInitializingOp(requestId2, graphId));
9587
+ await sseHelper.writeOperation(agentInitializingOp(requestId2, agentId));
9553
9588
  const taskId = `task_${conversationId}-${requestId2}`;
9554
9589
  logger20.info(
9555
9590
  { taskId, currentAgentId, conversationId, requestId: requestId2 },
@@ -9560,7 +9595,7 @@ var ExecutionHandler = class {
9560
9595
  id: taskId,
9561
9596
  tenantId,
9562
9597
  projectId,
9563
- graphId,
9598
+ agentId,
9564
9599
  subAgentId: currentAgentId,
9565
9600
  contextId: conversationId,
9566
9601
  status: "pending",
@@ -9568,11 +9603,11 @@ var ExecutionHandler = class {
9568
9603
  conversation_id: conversationId,
9569
9604
  message_id: requestId2,
9570
9605
  stream_request_id: requestId2,
9571
- // This also serves as the GraphSession ID
9606
+ // This also serves as the AgentSession ID
9572
9607
  created_at: (/* @__PURE__ */ new Date()).toISOString(),
9573
9608
  updated_at: (/* @__PURE__ */ new Date()).toISOString(),
9574
- root_agent_id: initialAgentId,
9575
- agent_id: currentAgentId
9609
+ root_sub_agent_id: initialAgentId,
9610
+ sub_agent_id: currentAgentId
9576
9611
  }
9577
9612
  });
9578
9613
  logger20.info(
@@ -9609,6 +9644,7 @@ var ExecutionHandler = class {
9609
9644
  timestamp: (/* @__PURE__ */ new Date()).toISOString(),
9610
9645
  executionType: "create_initial_task",
9611
9646
  conversationId,
9647
+ agentId,
9612
9648
  requestId: requestId2,
9613
9649
  currentAgentId,
9614
9650
  taskId: Array.isArray(task) ? task[0]?.id : task?.id,
@@ -9619,12 +9655,12 @@ var ExecutionHandler = class {
9619
9655
  );
9620
9656
  if (Array.isArray(task)) task = task[0];
9621
9657
  let currentMessage = userMessage;
9622
- const maxTransfers = graphConfig?.stopWhen?.transferCountIs ?? 10;
9658
+ const maxTransfers = agentConfig?.stopWhen?.transferCountIs ?? 10;
9623
9659
  while (iterations < maxTransfers) {
9624
9660
  iterations++;
9625
9661
  logger20.info(
9626
- { iterations, currentAgentId, graphId, conversationId, fromAgentId },
9627
- `Execution loop iteration ${iterations} with agent ${currentAgentId}, transfer from: ${fromAgentId || "none"}`
9662
+ { iterations, currentAgentId, agentId, conversationId, fromSubAgentId },
9663
+ `Execution loop iteration ${iterations} with agent ${currentAgentId}, transfer from: ${fromSubAgentId || "none"}`
9628
9664
  );
9629
9665
  const activeAgent = await getActiveAgentForConversation(dbClient_default)({
9630
9666
  scopes: { tenantId, projectId },
@@ -9641,17 +9677,17 @@ var ExecutionHandler = class {
9641
9677
  Authorization: `Bearer ${apiKey}`,
9642
9678
  "x-inkeep-tenant-id": tenantId,
9643
9679
  "x-inkeep-project-id": projectId,
9644
- "x-inkeep-graph-id": graphId,
9645
- "x-inkeep-agent-id": currentAgentId
9680
+ "x-inkeep-agent-id": agentId,
9681
+ "x-inkeep-sub-agent-id": currentAgentId
9646
9682
  }
9647
9683
  });
9648
9684
  let messageResponse = null;
9649
9685
  const messageMetadata = {
9650
9686
  stream_request_id: requestId2
9651
- // This also serves as the GraphSession ID
9687
+ // This also serves as the AgentSession ID
9652
9688
  };
9653
- if (fromAgentId) {
9654
- messageMetadata.fromAgentId = fromAgentId;
9689
+ if (fromSubAgentId) {
9690
+ messageMetadata.fromSubAgentId = fromSubAgentId;
9655
9691
  }
9656
9692
  messageResponse = await a2aClient.sendMessage({
9657
9693
  message: {
@@ -9695,17 +9731,28 @@ var ExecutionHandler = class {
9695
9731
  }
9696
9732
  });
9697
9733
  }
9698
- graphSessionManager.endSession(requestId2);
9734
+ agentSessionManager.endSession(requestId2);
9699
9735
  unregisterStreamHelper(requestId2);
9700
9736
  return { success: false, error: errorMessage2, iterations };
9701
9737
  }
9702
9738
  continue;
9703
9739
  }
9704
- if (isTransferResponse(messageResponse.result)) {
9705
- const transferResponse = messageResponse.result;
9706
- const targetSubAgentId = transferResponse.artifacts?.[0]?.parts?.[0]?.data?.targetSubAgentId;
9707
- const transferReason = transferResponse.artifacts?.[0]?.parts?.[1]?.text;
9708
- logger20.info({ targetSubAgentId, transferReason }, "transfer response");
9740
+ if (isTransferTask(messageResponse.result)) {
9741
+ const transferData = extractTransferData(messageResponse.result);
9742
+ if (!transferData) {
9743
+ logger20.error(
9744
+ { result: messageResponse.result },
9745
+ "Transfer detected but no transfer data found"
9746
+ );
9747
+ continue;
9748
+ }
9749
+ const { targetSubAgentId, fromSubAgentId: transferFromAgent } = transferData;
9750
+ const firstArtifact = messageResponse.result.artifacts[0];
9751
+ const transferReason = firstArtifact?.parts[1]?.kind === "text" ? firstArtifact.parts[1].text : "Transfer initiated";
9752
+ logger20.info(
9753
+ { targetSubAgentId, transferReason, transferFromAgent },
9754
+ "Transfer response"
9755
+ );
9709
9756
  currentMessage = `<transfer_context> ${transferReason} </transfer_context>`;
9710
9757
  const { success, targetSubAgentId: newAgentId } = await executeTransfer({
9711
9758
  projectId,
@@ -9714,15 +9761,15 @@ var ExecutionHandler = class {
9714
9761
  targetSubAgentId
9715
9762
  });
9716
9763
  if (success) {
9717
- fromAgentId = currentAgentId;
9764
+ fromSubAgentId = currentAgentId;
9718
9765
  currentAgentId = newAgentId;
9719
9766
  logger20.info(
9720
9767
  {
9721
- transferFrom: fromAgentId,
9768
+ transferFrom: fromSubAgentId,
9722
9769
  transferTo: currentAgentId,
9723
9770
  reason: transferReason
9724
9771
  },
9725
- "Transfer executed, tracking fromAgentId for next iteration"
9772
+ "Transfer executed, tracking fromSubAgentId for next iteration"
9726
9773
  );
9727
9774
  }
9728
9775
  continue;
@@ -9744,10 +9791,10 @@ var ExecutionHandler = class {
9744
9791
  );
9745
9792
  }
9746
9793
  if (responseParts && responseParts.length > 0) {
9747
- const graphSessionData = graphSessionManager.getSession(requestId2);
9748
- if (graphSessionData) {
9749
- const sessionSummary = graphSessionData.getSummary();
9750
- logger20.info(sessionSummary, "GraphSession data after completion");
9794
+ const agentSessionData = agentSessionManager.getSession(requestId2);
9795
+ if (agentSessionData) {
9796
+ const sessionSummary = agentSessionData.getSummary();
9797
+ logger20.info(sessionSummary, "AgentSession data after completion");
9751
9798
  }
9752
9799
  let textContent = "";
9753
9800
  for (const part of responseParts) {
@@ -9806,8 +9853,8 @@ var ExecutionHandler = class {
9806
9853
  );
9807
9854
  await sseHelper.writeOperation(completionOp(currentAgentId, iterations));
9808
9855
  await sseHelper.complete();
9809
- logger20.info({}, "Ending GraphSession and cleaning up");
9810
- graphSessionManager.endSession(requestId2);
9856
+ logger20.info({}, "Ending AgentSession and cleaning up");
9857
+ agentSessionManager.endSession(requestId2);
9811
9858
  logger20.info({}, "Cleaning up streamHelper");
9812
9859
  unregisterStreamHelper(requestId2);
9813
9860
  let response;
@@ -9847,7 +9894,7 @@ var ExecutionHandler = class {
9847
9894
  }
9848
9895
  });
9849
9896
  }
9850
- graphSessionManager.endSession(requestId2);
9897
+ agentSessionManager.endSession(requestId2);
9851
9898
  unregisterStreamHelper(requestId2);
9852
9899
  return { success: false, error: errorMessage2, iterations };
9853
9900
  }
@@ -9868,7 +9915,7 @@ var ExecutionHandler = class {
9868
9915
  }
9869
9916
  });
9870
9917
  }
9871
- graphSessionManager.endSession(requestId2);
9918
+ agentSessionManager.endSession(requestId2);
9872
9919
  unregisterStreamHelper(requestId2);
9873
9920
  return { success: false, error: errorMessage, iterations };
9874
9921
  } catch (error) {
@@ -9890,7 +9937,7 @@ var ExecutionHandler = class {
9890
9937
  }
9891
9938
  });
9892
9939
  }
9893
- graphSessionManager.endSession(requestId2);
9940
+ agentSessionManager.endSession(requestId2);
9894
9941
  unregisterStreamHelper(requestId2);
9895
9942
  return { success: false, error: errorMessage, iterations };
9896
9943
  }
@@ -9905,7 +9952,7 @@ var chatCompletionsRoute = createRoute({
9905
9952
  path: "/completions",
9906
9953
  tags: ["chat"],
9907
9954
  summary: "Create chat completion",
9908
- description: "Creates a new chat completion with streaming SSE response using the configured agent graph",
9955
+ description: "Creates a new chat completion with streaming SSE response using the configured agent",
9909
9956
  security: [{ bearerAuth: [] }],
9910
9957
  request: {
9911
9958
  body: {
@@ -9980,7 +10027,7 @@ var chatCompletionsRoute = createRoute({
9980
10027
  }
9981
10028
  },
9982
10029
  404: {
9983
- description: "Agent graph or agent not found",
10030
+ description: "Agent or agent not found",
9984
10031
  content: {
9985
10032
  "application/json": {
9986
10033
  schema: z.object({
@@ -10027,48 +10074,48 @@ app2.openapi(chatCompletionsRoute, async (c) => {
10027
10074
  );
10028
10075
  try {
10029
10076
  const executionContext = getRequestExecutionContext(c);
10030
- const { tenantId, projectId, graphId } = executionContext;
10077
+ const { tenantId, projectId, agentId } = executionContext;
10031
10078
  getLogger("chat").debug(
10032
10079
  {
10033
10080
  tenantId,
10034
- graphId
10081
+ agentId
10035
10082
  },
10036
10083
  "Extracted chat parameters from API key context"
10037
10084
  );
10038
10085
  const body = c.get("requestBody") || {};
10039
10086
  const conversationId = body.conversationId || getConversationId();
10040
- const fullGraph = await getFullGraph(dbClient_default)({
10041
- scopes: { tenantId, projectId, graphId }
10087
+ const fullAgent = await getFullAgent(dbClient_default)({
10088
+ scopes: { tenantId, projectId, agentId }
10042
10089
  });
10043
- let agentGraph;
10090
+ let agent;
10044
10091
  let defaultSubAgentId;
10045
- if (fullGraph) {
10046
- agentGraph = {
10047
- id: fullGraph.id,
10048
- name: fullGraph.name,
10092
+ if (fullAgent) {
10093
+ agent = {
10094
+ id: fullAgent.id,
10095
+ name: fullAgent.name,
10049
10096
  tenantId,
10050
10097
  projectId,
10051
- defaultSubAgentId: fullGraph.defaultSubAgentId
10098
+ defaultSubAgentId: fullAgent.defaultSubAgentId
10052
10099
  };
10053
- const agentKeys = Object.keys(fullGraph.subAgents || {});
10100
+ const agentKeys = Object.keys(fullAgent.subAgents || {});
10054
10101
  const firstAgentId = agentKeys.length > 0 ? agentKeys[0] : "";
10055
- defaultSubAgentId = fullGraph.defaultSubAgentId || firstAgentId;
10102
+ defaultSubAgentId = fullAgent.defaultSubAgentId || firstAgentId;
10056
10103
  } else {
10057
- agentGraph = await getAgentGraphWithDefaultSubAgent(dbClient_default)({
10058
- scopes: { tenantId, projectId, graphId }
10104
+ agent = await getAgentWithDefaultSubAgent(dbClient_default)({
10105
+ scopes: { tenantId, projectId, agentId }
10059
10106
  });
10060
- if (!agentGraph) {
10107
+ if (!agent) {
10061
10108
  throw createApiError({
10062
10109
  code: "not_found",
10063
- message: "Agent graph not found"
10110
+ message: "Agent not found"
10064
10111
  });
10065
10112
  }
10066
- defaultSubAgentId = agentGraph.defaultSubAgentId || "";
10113
+ defaultSubAgentId = agent.defaultSubAgentId || "";
10067
10114
  }
10068
10115
  if (!defaultSubAgentId) {
10069
10116
  throw createApiError({
10070
10117
  code: "not_found",
10071
- message: "No default agent found in graph"
10118
+ message: "No default agent found in agent"
10072
10119
  });
10073
10120
  }
10074
10121
  await createOrGetConversation(dbClient_default)({
@@ -10090,7 +10137,7 @@ app2.openapi(chatCompletionsRoute, async (c) => {
10090
10137
  }
10091
10138
  const subAgentId = activeAgent?.activeSubAgentId || defaultSubAgentId;
10092
10139
  const agentInfo = await getSubAgentById(dbClient_default)({
10093
- scopes: { tenantId, projectId, graphId },
10140
+ scopes: { tenantId, projectId, agentId },
10094
10141
  subAgentId
10095
10142
  });
10096
10143
  if (!agentInfo) {
@@ -10104,7 +10151,7 @@ app2.openapi(chatCompletionsRoute, async (c) => {
10104
10151
  await handleContextResolution({
10105
10152
  tenantId,
10106
10153
  projectId,
10107
- graphId,
10154
+ agentId,
10108
10155
  conversationId,
10109
10156
  headers: validatedContext,
10110
10157
  dbClient: dbClient_default,
@@ -10114,11 +10161,11 @@ app2.openapi(chatCompletionsRoute, async (c) => {
10114
10161
  {
10115
10162
  tenantId,
10116
10163
  projectId,
10117
- graphId,
10164
+ agentId,
10118
10165
  conversationId,
10119
10166
  defaultSubAgentId,
10120
10167
  activeSubAgentId: activeAgent?.activeSubAgentId || "none",
10121
- hasContextConfig: !!agentGraph.contextConfigId,
10168
+ hasContextConfig: !!agent.contextConfigId,
10122
10169
  hasHeaders: !!body.headers,
10123
10170
  hasValidatedContext: !!validatedContext,
10124
10171
  validatedContextKeys: Object.keys(validatedContext)
@@ -10283,8 +10330,8 @@ app3.use("/chat", contextValidationMiddleware(dbClient_default));
10283
10330
  app3.openapi(chatDataStreamRoute, async (c) => {
10284
10331
  try {
10285
10332
  const executionContext = getRequestExecutionContext(c);
10286
- const { tenantId, projectId, graphId } = executionContext;
10287
- loggerFactory.getLogger("chatDataStream").debug({ tenantId, projectId, graphId }, "Extracted chatDataStream parameters");
10333
+ const { tenantId, projectId, agentId } = executionContext;
10334
+ loggerFactory.getLogger("chatDataStream").debug({ tenantId, projectId, agentId }, "Extracted chatDataStream parameters");
10288
10335
  const body = c.get("requestBody") || {};
10289
10336
  const conversationId = body.conversationId || getConversationId();
10290
10337
  const activeSpan = trace.getActiveSpan();
@@ -10292,25 +10339,25 @@ app3.openapi(chatDataStreamRoute, async (c) => {
10292
10339
  activeSpan.setAttributes({
10293
10340
  "conversation.id": conversationId,
10294
10341
  "tenant.id": tenantId,
10295
- "graph.id": graphId,
10342
+ "agent.id": agentId,
10296
10343
  "project.id": projectId
10297
10344
  });
10298
10345
  }
10299
- const agentGraph = await getAgentGraphWithDefaultSubAgent(dbClient_default)({
10300
- scopes: { tenantId, projectId, graphId }
10346
+ const agent = await getAgentWithDefaultSubAgent(dbClient_default)({
10347
+ scopes: { tenantId, projectId, agentId }
10301
10348
  });
10302
- if (!agentGraph) {
10349
+ if (!agent) {
10303
10350
  throw createApiError({
10304
10351
  code: "not_found",
10305
- message: "Agent graph not found"
10352
+ message: "Agent not found"
10306
10353
  });
10307
10354
  }
10308
- const defaultSubAgentId = agentGraph.defaultSubAgentId;
10309
- const graphName = agentGraph.name;
10355
+ const defaultSubAgentId = agent.defaultSubAgentId;
10356
+ const agentName = agent.name;
10310
10357
  if (!defaultSubAgentId) {
10311
10358
  throw createApiError({
10312
10359
  code: "bad_request",
10313
- message: "Graph does not have a default agent configured"
10360
+ message: "Agent does not have a default agent configured"
10314
10361
  });
10315
10362
  }
10316
10363
  const activeAgent = await getActiveAgentForConversation(dbClient_default)({
@@ -10326,7 +10373,7 @@ app3.openapi(chatDataStreamRoute, async (c) => {
10326
10373
  }
10327
10374
  const subAgentId = activeAgent?.activeSubAgentId || defaultSubAgentId;
10328
10375
  const agentInfo = await getSubAgentById(dbClient_default)({
10329
- scopes: { tenantId, projectId, graphId },
10376
+ scopes: { tenantId, projectId, agentId },
10330
10377
  subAgentId
10331
10378
  });
10332
10379
  if (!agentInfo) {
@@ -10340,7 +10387,7 @@ app3.openapi(chatDataStreamRoute, async (c) => {
10340
10387
  await handleContextResolution({
10341
10388
  tenantId,
10342
10389
  projectId,
10343
- graphId,
10390
+ agentId,
10344
10391
  conversationId,
10345
10392
  headers: validatedContext,
10346
10393
  dbClient: dbClient_default,
@@ -10354,7 +10401,7 @@ app3.openapi(chatDataStreamRoute, async (c) => {
10354
10401
  messageSpan.setAttributes({
10355
10402
  "message.timestamp": (/* @__PURE__ */ new Date()).toISOString(),
10356
10403
  "message.content": userText,
10357
- "graph.name": graphName
10404
+ "agent.name": agentName
10358
10405
  });
10359
10406
  }
10360
10407
  await createMessage(dbClient_default)({
@@ -10490,7 +10537,7 @@ var spoofTransportInitialization = async (transport, req, sessionId, mcpProtocol
10490
10537
  logger23.warn({ sessionId, error: spoofError }, "Spoof initialization failed, continuing anyway");
10491
10538
  }
10492
10539
  };
10493
- var validateSession = async (req, res, body, tenantId, projectId, graphId) => {
10540
+ var validateSession = async (req, res, body, tenantId, projectId, agentId) => {
10494
10541
  const sessionId = req.headers["mcp-session-id"];
10495
10542
  logger23.info({ sessionId }, "Received MCP session ID");
10496
10543
  if (!sessionId) {
@@ -10525,12 +10572,12 @@ var validateSession = async (req, res, body, tenantId, projectId, graphId) => {
10525
10572
  sessionId,
10526
10573
  conversationFound: !!conversation,
10527
10574
  sessionType: conversation?.metadata?.sessionData?.sessionType,
10528
- storedGraphId: conversation?.metadata?.sessionData?.graphId,
10529
- requestGraphId: graphId
10575
+ storedAgentId: conversation?.metadata?.sessionData?.agentId,
10576
+ requestAgentId: agentId
10530
10577
  },
10531
10578
  "Conversation lookup result"
10532
10579
  );
10533
- if (!conversation || conversation.metadata?.sessionData?.sessionType !== "mcp" || conversation.metadata?.sessionData?.graphId !== graphId) {
10580
+ if (!conversation || conversation.metadata?.sessionData?.sessionType !== "mcp" || conversation.metadata?.sessionData?.agentId !== agentId) {
10534
10581
  logger23.info(
10535
10582
  { sessionId, conversationId: conversation?.id },
10536
10583
  "MCP session not found or invalid"
@@ -10549,13 +10596,13 @@ var validateSession = async (req, res, body, tenantId, projectId, graphId) => {
10549
10596
  }
10550
10597
  return conversation;
10551
10598
  };
10552
- var setupTracing = (conversationId, tenantId, graphId) => {
10599
+ var setupTracing = (conversationId, tenantId, agentId) => {
10553
10600
  const activeSpan = trace.getActiveSpan();
10554
10601
  if (activeSpan) {
10555
10602
  activeSpan.setAttributes({
10556
10603
  "conversation.id": conversationId,
10557
10604
  "tenant.id": tenantId,
10558
- "graph.id": graphId
10605
+ "agent.id": agentId
10559
10606
  });
10560
10607
  }
10561
10608
  };
@@ -10617,13 +10664,13 @@ var executeAgentQuery = async (executionContext, conversationId, query, defaultS
10617
10664
  };
10618
10665
  };
10619
10666
  var getServer = async (headers, executionContext, conversationId, credentialStores) => {
10620
- const { tenantId, projectId, graphId } = executionContext;
10621
- setupTracing(conversationId, tenantId, graphId);
10622
- const agentGraph = await getAgentGraphWithDefaultSubAgent(dbClient_default)({
10623
- scopes: { tenantId, projectId, graphId }
10667
+ const { tenantId, projectId, agentId } = executionContext;
10668
+ setupTracing(conversationId, tenantId, agentId);
10669
+ const agent = await getAgentWithDefaultSubAgent(dbClient_default)({
10670
+ scopes: { tenantId, projectId, agentId }
10624
10671
  });
10625
- if (!agentGraph) {
10626
- throw new Error("Agent graph not found");
10672
+ if (!agent) {
10673
+ throw new Error("Agent not found");
10627
10674
  }
10628
10675
  const server = new McpServer(
10629
10676
  {
@@ -10634,26 +10681,26 @@ var getServer = async (headers, executionContext, conversationId, credentialStor
10634
10681
  );
10635
10682
  server.tool(
10636
10683
  "send-query-to-agent",
10637
- `Send a query to the ${agentGraph.name} agent. The agent has the following description: ${agentGraph.description}`,
10684
+ `Send a query to the ${agent.name} agent. The agent has the following description: ${agent.description}`,
10638
10685
  {
10639
10686
  query: createMCPSchema(z$2.string().describe("The query to send to the agent"))
10640
10687
  },
10641
10688
  async ({ query }) => {
10642
10689
  try {
10643
- if (!agentGraph.defaultSubAgentId) {
10690
+ if (!agent.defaultSubAgentId) {
10644
10691
  return {
10645
10692
  content: [
10646
10693
  {
10647
10694
  type: "text",
10648
- text: `Graph does not have a default agent configured`
10695
+ text: `Agent does not have a default agent configured`
10649
10696
  }
10650
10697
  ],
10651
10698
  isError: true
10652
10699
  };
10653
10700
  }
10654
- const defaultSubAgentId = agentGraph.defaultSubAgentId;
10701
+ const defaultSubAgentId = agent.defaultSubAgentId;
10655
10702
  const agentInfo = await getSubAgentById(dbClient_default)({
10656
- scopes: { tenantId, projectId, graphId },
10703
+ scopes: { tenantId, projectId, agentId },
10657
10704
  subAgentId: defaultSubAgentId
10658
10705
  });
10659
10706
  if (!agentInfo) {
@@ -10670,7 +10717,7 @@ var getServer = async (headers, executionContext, conversationId, credentialStor
10670
10717
  const resolvedContext = await handleContextResolution({
10671
10718
  tenantId,
10672
10719
  projectId,
10673
- graphId,
10720
+ agentId,
10674
10721
  conversationId,
10675
10722
  headers,
10676
10723
  dbClient: dbClient_default,
@@ -10680,9 +10727,9 @@ var getServer = async (headers, executionContext, conversationId, credentialStor
10680
10727
  {
10681
10728
  tenantId,
10682
10729
  projectId,
10683
- graphId,
10730
+ agentId,
10684
10731
  conversationId,
10685
- hasContextConfig: !!agentGraph.contextConfigId,
10732
+ hasContextConfig: !!agent.contextConfigId,
10686
10733
  hasHeaders: !!headers,
10687
10734
  hasValidatedContext: !!resolvedContext
10688
10735
  },
@@ -10715,8 +10762,8 @@ app4.use("/", async (c, next) => {
10715
10762
  var validateRequestParameters = (c) => {
10716
10763
  try {
10717
10764
  const executionContext = getRequestExecutionContext(c);
10718
- const { tenantId, projectId, graphId } = executionContext;
10719
- getLogger("mcp").debug({ tenantId, projectId, graphId }, "Extracted MCP entity parameters");
10765
+ const { tenantId, projectId, agentId } = executionContext;
10766
+ getLogger("mcp").debug({ tenantId, projectId, agentId }, "Extracted MCP entity parameters");
10720
10767
  return { valid: true, executionContext };
10721
10768
  } catch (error) {
10722
10769
  getLogger("chat").warn(
@@ -10737,27 +10784,27 @@ var validateRequestParameters = (c) => {
10737
10784
  }
10738
10785
  };
10739
10786
  var handleInitializationRequest = async (body, executionContext, validatedContext, req, res, c, credentialStores) => {
10740
- const { tenantId, projectId, graphId } = executionContext;
10787
+ const { tenantId, projectId, agentId } = executionContext;
10741
10788
  logger23.info({ body }, "Received initialization request");
10742
10789
  const sessionId = getConversationId();
10743
- const agentGraph = await getAgentGraphWithDefaultSubAgent(dbClient_default)({
10744
- scopes: { tenantId, projectId, graphId }
10790
+ const agent = await getAgentWithDefaultSubAgent(dbClient_default)({
10791
+ scopes: { tenantId, projectId, agentId }
10745
10792
  });
10746
- if (!agentGraph) {
10793
+ if (!agent) {
10747
10794
  return c.json(
10748
10795
  {
10749
10796
  jsonrpc: "2.0",
10750
- error: { code: -32001, message: "Agent graph not found" },
10797
+ error: { code: -32001, message: "Agent not found" },
10751
10798
  id: body.id || null
10752
10799
  },
10753
10800
  { status: 404 }
10754
10801
  );
10755
10802
  }
10756
- if (!agentGraph.defaultSubAgentId) {
10803
+ if (!agent.defaultSubAgentId) {
10757
10804
  return c.json(
10758
10805
  {
10759
10806
  jsonrpc: "2.0",
10760
- error: { code: -32001, message: "Graph does not have a default agent configured" },
10807
+ error: { code: -32001, message: "Agent does not have a default agent configured" },
10761
10808
  id: body.id || null
10762
10809
  },
10763
10810
  { status: 400 }
@@ -10767,10 +10814,10 @@ var handleInitializationRequest = async (body, executionContext, validatedContex
10767
10814
  id: sessionId,
10768
10815
  tenantId,
10769
10816
  projectId,
10770
- activeSubAgentId: agentGraph.defaultSubAgentId,
10817
+ activeSubAgentId: agent.defaultSubAgentId,
10771
10818
  metadata: {
10772
10819
  sessionData: {
10773
- graphId,
10820
+ agentId,
10774
10821
  sessionType: "mcp",
10775
10822
  mcpProtocolVersion: c.req.header("mcp-protocol-version"),
10776
10823
  initialized: false
@@ -10802,8 +10849,8 @@ var handleInitializationRequest = async (body, executionContext, validatedContex
10802
10849
  return toFetchResponse(res);
10803
10850
  };
10804
10851
  var handleExistingSessionRequest = async (body, executionContext, validatedContext, req, res, credentialStores) => {
10805
- const { tenantId, projectId, graphId } = executionContext;
10806
- const conversation = await validateSession(req, res, body, tenantId, projectId, graphId);
10852
+ const { tenantId, projectId, agentId } = executionContext;
10853
+ const conversation = await validateSession(req, res, body, tenantId, projectId, agentId);
10807
10854
  if (!conversation) {
10808
10855
  return toFetchResponse(res);
10809
10856
  }
@@ -10879,7 +10926,7 @@ app4.openapi(
10879
10926
  description: "Unauthorized - API key authentication required"
10880
10927
  },
10881
10928
  404: {
10882
- description: "Not Found - Agent graph not found"
10929
+ description: "Not Found - Agent not found"
10883
10930
  },
10884
10931
  500: {
10885
10932
  description: "Internal Server Error"
@@ -11097,7 +11144,7 @@ function createExecutionHono(serverConfig, credentialStores) {
11097
11144
  logger24.debug({}, "Empty execution context");
11098
11145
  return next();
11099
11146
  }
11100
- const { tenantId, projectId, graphId } = executionContext;
11147
+ const { tenantId, projectId, agentId } = executionContext;
11101
11148
  let conversationId;
11102
11149
  const requestBody = c.get("requestBody") || {};
11103
11150
  if (requestBody) {
@@ -11108,7 +11155,7 @@ function createExecutionHono(serverConfig, credentialStores) {
11108
11155
  }
11109
11156
  const entries = Object.fromEntries(
11110
11157
  Object.entries({
11111
- "graph.id": graphId,
11158
+ "agent.id": agentId,
11112
11159
  "tenant.id": tenantId,
11113
11160
  "project.id": projectId,
11114
11161
  "conversation.id": conversationId