@inkeep/agents-run-api 0.18.1 → 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.cjs CHANGED
@@ -228,7 +228,7 @@ async function getScopedHistory({
228
228
  let matchesAgent = true;
229
229
  let matchesTask = true;
230
230
  if (filters.subAgentId) {
231
- matchesAgent = msg.role === "agent" && msg.visibility === "user-facing" || msg.toAgentId === filters.subAgentId || msg.fromAgentId === filters.subAgentId;
231
+ matchesAgent = msg.role === "agent" && msg.visibility === "user-facing" || msg.toSubAgentId === filters.subAgentId || msg.fromSubAgentId === filters.subAgentId;
232
232
  }
233
233
  if (filters.taskId) {
234
234
  matchesTask = msg.taskId === filters.taskId || msg.a2aTaskId === filters.taskId;
@@ -303,12 +303,12 @@ async function getFormattedConversationHistory({
303
303
  if (msg.role === "user") {
304
304
  roleLabel = "user";
305
305
  } else if (msg.role === "agent" && (msg.messageType === "a2a-request" || msg.messageType === "a2a-response")) {
306
- const fromAgent = msg.fromAgentId || msg.fromExternalAgentId || "unknown";
307
- const toAgent = msg.toAgentId || msg.toExternalAgentId || "unknown";
308
- roleLabel = `${fromAgent} to ${toAgent}`;
306
+ const fromSubAgent = msg.fromSubAgentId || msg.fromExternalAgentId || "unknown";
307
+ const toSubAgent = msg.toSubAgentId || msg.toExternalAgentId || "unknown";
308
+ roleLabel = `${fromSubAgent} to ${toSubAgent}`;
309
309
  } else if (msg.role === "agent" && msg.messageType === "chat") {
310
- const fromAgent = msg.fromAgentId || "unknown";
311
- roleLabel = `${fromAgent} to User`;
310
+ const fromSubAgent = msg.fromSubAgentId || "unknown";
311
+ roleLabel = `${fromSubAgent} to User`;
312
312
  } else {
313
313
  roleLabel = msg.role || "system";
314
314
  }
@@ -924,7 +924,7 @@ function createExecutionContext(params) {
924
924
  apiKey: params.apiKey,
925
925
  tenantId: params.tenantId,
926
926
  projectId: params.projectId,
927
- graphId: params.graphId,
927
+ agentId: params.agentId,
928
928
  baseUrl: params.baseUrl || process.env.API_URL || "http://localhost:3003",
929
929
  apiKeyId: params.apiKeyId,
930
930
  subAgentId: params.subAgentId
@@ -941,8 +941,8 @@ var apiKeyAuth = () => factory.createMiddleware(async (c, next) => {
941
941
  const authHeader = c.req.header("Authorization");
942
942
  const tenantId = c.req.header("x-inkeep-tenant-id");
943
943
  const projectId = c.req.header("x-inkeep-project-id");
944
- const graphId = c.req.header("x-inkeep-graph-id");
945
- const subAgentId = c.req.header("x-inkeep-agent-id");
944
+ const agentId = c.req.header("x-inkeep-agent-id");
945
+ const subAgentId = c.req.header("x-inkeep-sub-agent-id");
946
946
  const proto = c.req.header("x-forwarded-proto")?.split(",")[0].trim();
947
947
  const fwdHost = c.req.header("x-forwarded-host")?.split(",")[0].trim();
948
948
  const host = fwdHost ?? c.req.header("host");
@@ -960,7 +960,7 @@ var apiKeyAuth = () => factory.createMiddleware(async (c, next) => {
960
960
  apiKey: "development",
961
961
  tenantId: tenantId || "test-tenant",
962
962
  projectId: projectId || "test-project",
963
- graphId: graphId || "test-graph",
963
+ agentId: agentId || "test-agent",
964
964
  apiKeyId: "test-key",
965
965
  baseUrl,
966
966
  subAgentId
@@ -975,7 +975,7 @@ var apiKeyAuth = () => factory.createMiddleware(async (c, next) => {
975
975
  apiKey: "development",
976
976
  tenantId: tenantId || "test-tenant",
977
977
  projectId: projectId || "test-project",
978
- graphId: graphId || "test-graph",
978
+ agentId: agentId || "test-agent",
979
979
  apiKeyId: "test-key",
980
980
  baseUrl,
981
981
  subAgentId
@@ -997,16 +997,16 @@ var apiKeyAuth = () => factory.createMiddleware(async (c, next) => {
997
997
  const apiKey = authHeader.substring(7);
998
998
  if (env.INKEEP_AGENTS_RUN_API_BYPASS_SECRET) {
999
999
  if (apiKey === env.INKEEP_AGENTS_RUN_API_BYPASS_SECRET) {
1000
- if (!tenantId || !projectId || !graphId) {
1000
+ if (!tenantId || !projectId || !agentId) {
1001
1001
  throw new httpException.HTTPException(401, {
1002
- message: "Missing or invalid tenant, project, or graph ID"
1002
+ message: "Missing or invalid tenant, project, or agent ID"
1003
1003
  });
1004
1004
  }
1005
1005
  const executionContext = createExecutionContext({
1006
1006
  apiKey,
1007
1007
  tenantId,
1008
1008
  projectId,
1009
- graphId,
1009
+ agentId,
1010
1010
  apiKeyId: "bypass",
1011
1011
  baseUrl,
1012
1012
  subAgentId
@@ -1041,7 +1041,7 @@ var apiKeyAuth = () => factory.createMiddleware(async (c, next) => {
1041
1041
  {
1042
1042
  tenantId: executionContext.tenantId,
1043
1043
  projectId: executionContext.projectId,
1044
- graphId: executionContext.graphId,
1044
+ agentId: executionContext.agentId,
1045
1045
  subAgentId: executionContext.subAgentId
1046
1046
  },
1047
1047
  "API key authenticated successfully"
@@ -1068,7 +1068,7 @@ var extractContextFromApiKey = async (apiKey, baseUrl) => {
1068
1068
  apiKey,
1069
1069
  tenantId: apiKeyRecord.tenantId,
1070
1070
  projectId: apiKeyRecord.projectId,
1071
- graphId: apiKeyRecord.graphId,
1071
+ agentId: apiKeyRecord.agentId,
1072
1072
  apiKeyId: apiKeyRecord.id,
1073
1073
  baseUrl
1074
1074
  });
@@ -1171,7 +1171,7 @@ async function handleMessageSend(c, agent, request) {
1171
1171
  try {
1172
1172
  const params = request.params;
1173
1173
  const executionContext = agentsCore.getRequestExecutionContext(c);
1174
- const { graphId } = executionContext;
1174
+ const { agentId } = executionContext;
1175
1175
  const task = {
1176
1176
  id: nanoid.nanoid(),
1177
1177
  input: {
@@ -1185,7 +1185,7 @@ async function handleMessageSend(c, agent, request) {
1185
1185
  conversationId: params.message.contextId,
1186
1186
  metadata: {
1187
1187
  blocking: params.configuration?.blocking ?? false,
1188
- custom: { graph_id: graphId || "" },
1188
+ custom: { agent_id: agentId || "" },
1189
1189
  // Pass through streaming metadata from the original message
1190
1190
  ...params.message.metadata
1191
1191
  }
@@ -1246,7 +1246,7 @@ async function handleMessageSend(c, agent, request) {
1246
1246
  id: task.id,
1247
1247
  tenantId: agent.tenantId,
1248
1248
  projectId: agent.projectId,
1249
- graphId: graphId || "",
1249
+ agentId: agentId || "",
1250
1250
  contextId: effectiveContextId,
1251
1251
  status: "working",
1252
1252
  metadata: {
@@ -1254,8 +1254,8 @@ async function handleMessageSend(c, agent, request) {
1254
1254
  message_id: params.message.messageId || "",
1255
1255
  created_at: (/* @__PURE__ */ new Date()).toISOString(),
1256
1256
  updated_at: (/* @__PURE__ */ new Date()).toISOString(),
1257
- agent_id: agent.subAgentId,
1258
- graph_id: graphId || "",
1257
+ sub_agent_id: agent.subAgentId,
1258
+ agent_id: agentId || "",
1259
1259
  stream_request_id: params.message.metadata?.stream_request_id
1260
1260
  },
1261
1261
  subAgentId: agent.subAgentId,
@@ -1263,7 +1263,7 @@ async function handleMessageSend(c, agent, request) {
1263
1263
  updatedAt: (/* @__PURE__ */ new Date()).toISOString()
1264
1264
  });
1265
1265
  logger3.info({ metadata: params.message.metadata }, "message metadata");
1266
- if (params.message.metadata?.fromAgentId || params.message.metadata?.fromExternalAgentId) {
1266
+ if (params.message.metadata?.fromSubAgentId || params.message.metadata?.fromExternalAgentId) {
1267
1267
  const messageText = params.message.parts.filter((part) => part.kind === "text" && "text" in part && part.text).map((part) => part.text).join(" ");
1268
1268
  try {
1269
1269
  const messageData = {
@@ -1279,19 +1279,19 @@ async function handleMessageSend(c, agent, request) {
1279
1279
  messageType: "a2a-request",
1280
1280
  taskId: task.id
1281
1281
  };
1282
- if (params.message.metadata?.fromAgentId) {
1283
- messageData.fromAgentId = params.message.metadata.fromAgentId;
1284
- messageData.toAgentId = agent.subAgentId;
1282
+ if (params.message.metadata?.fromSubAgentId) {
1283
+ messageData.fromSubAgentId = params.message.metadata.fromSubAgentId;
1284
+ messageData.toSubAgentId = agent.subAgentId;
1285
1285
  } else if (params.message.metadata?.fromExternalAgentId) {
1286
1286
  messageData.fromExternalAgentId = params.message.metadata.fromExternalAgentId;
1287
- messageData.toAgentId = agent.subAgentId;
1287
+ messageData.toSubAgentId = agent.subAgentId;
1288
1288
  }
1289
1289
  await agentsCore.createMessage(dbClient_default)(messageData);
1290
1290
  logger3.info(
1291
1291
  {
1292
- fromAgentId: params.message.metadata.fromAgentId,
1292
+ fromSubAgentId: params.message.metadata.fromSubAgentId,
1293
1293
  fromExternalAgentId: params.message.metadata.fromExternalAgentId,
1294
- toAgentId: agent.subAgentId,
1294
+ toSubAgentId: agent.subAgentId,
1295
1295
  conversationId: effectiveContextId,
1296
1296
  messageType: "a2a-request",
1297
1297
  taskId: task.id
@@ -1302,9 +1302,9 @@ async function handleMessageSend(c, agent, request) {
1302
1302
  logger3.error(
1303
1303
  {
1304
1304
  error,
1305
- fromAgentId: params.message.metadata.fromAgentId,
1305
+ fromSubAgentId: params.message.metadata.fromSubAgentId,
1306
1306
  fromExternalAgentId: params.message.metadata.fromExternalAgentId,
1307
- toAgentId: agent.subAgentId,
1307
+ toSubAgentId: agent.subAgentId,
1308
1308
  conversationId: effectiveContextId
1309
1309
  },
1310
1310
  "Failed to store A2A message in database"
@@ -1321,8 +1321,8 @@ async function handleMessageSend(c, agent, request) {
1321
1321
  message_id: params.message.messageId || "",
1322
1322
  created_at: (/* @__PURE__ */ new Date()).toISOString(),
1323
1323
  updated_at: (/* @__PURE__ */ new Date()).toISOString(),
1324
- agent_id: agent.subAgentId,
1325
- graph_id: graphId || ""
1324
+ sub_agent_id: agent.subAgentId,
1325
+ agent_id: agentId || ""
1326
1326
  }
1327
1327
  }
1328
1328
  });
@@ -1355,7 +1355,8 @@ async function handleMessageSend(c, agent, request) {
1355
1355
  kind: "data",
1356
1356
  data: {
1357
1357
  type: "transfer",
1358
- targetSubAgentId: transferPart.data.target
1358
+ targetSubAgentId: transferPart.data.targetSubAgentId,
1359
+ fromSubAgentId: transferPart.data.fromSubAgentId
1359
1360
  }
1360
1361
  },
1361
1362
  {
@@ -1423,7 +1424,7 @@ async function handleMessageStream(c, agent, request) {
1423
1424
  try {
1424
1425
  const params = request.params;
1425
1426
  const executionContext = agentsCore.getRequestExecutionContext(c);
1426
- const { graphId } = executionContext;
1427
+ const { agentId } = executionContext;
1427
1428
  if (!agent.agentCard.capabilities.streaming) {
1428
1429
  return c.json({
1429
1430
  jsonrpc: "2.0",
@@ -1448,7 +1449,7 @@ async function handleMessageStream(c, agent, request) {
1448
1449
  metadata: {
1449
1450
  blocking: false,
1450
1451
  // Streaming is always non-blocking
1451
- custom: { graph_id: graphId || "" }
1452
+ custom: { agent_id: agentId || "" }
1452
1453
  }
1453
1454
  }
1454
1455
  };
@@ -1487,7 +1488,7 @@ async function handleMessageStream(c, agent, request) {
1487
1488
  jsonrpc: "2.0",
1488
1489
  result: {
1489
1490
  type: "transfer",
1490
- target: transferPart.data.target,
1491
+ target: transferPart.data.targetSubAgentId,
1491
1492
  task_id: task.id,
1492
1493
  reason: transferPart.data.reason || "Agent requested transfer",
1493
1494
  original_message: transferPart.data.original_message,
@@ -1719,129 +1720,6 @@ async function handleTasksResubscribe(c, agent, request) {
1719
1720
  }
1720
1721
  }
1721
1722
  init_dbClient();
1722
- function createAgentCard({
1723
- dbAgent,
1724
- baseUrl
1725
- }) {
1726
- const description = dbAgent.description || "AI Agent";
1727
- return {
1728
- name: dbAgent.name,
1729
- description,
1730
- url: baseUrl ? `${baseUrl}/a2a` : "",
1731
- version: "1.0.0",
1732
- capabilities: {
1733
- streaming: true,
1734
- // Enable streaming for A2A compliance
1735
- pushNotifications: false,
1736
- stateTransitionHistory: false
1737
- },
1738
- defaultInputModes: ["text", "text/plain"],
1739
- defaultOutputModes: ["text", "text/plain"],
1740
- skills: [],
1741
- // Add provider info if available
1742
- ...baseUrl && {
1743
- provider: {
1744
- organization: "Inkeep",
1745
- url: baseUrl
1746
- }
1747
- }
1748
- };
1749
- }
1750
- function generateDescriptionWithTransfers(baseDescription, internalRelations, externalRelations) {
1751
- const transfers = [
1752
- ...internalRelations.filter((rel) => rel.relationType === "transfer"),
1753
- ...externalRelations.filter((rel) => rel.relationType === "transfer")
1754
- ];
1755
- const delegates = [
1756
- ...internalRelations.filter((rel) => rel.relationType === "delegate"),
1757
- ...externalRelations.filter((rel) => rel.relationType === "delegate")
1758
- ];
1759
- if (transfers.length === 0 && delegates.length === 0) {
1760
- return baseDescription;
1761
- }
1762
- let enhancedDescription = baseDescription;
1763
- if (transfers.length > 0) {
1764
- const transferList = transfers.map((rel) => {
1765
- const name = rel.externalAgent?.name || rel.name;
1766
- const desc = rel.externalAgent?.description || rel.description || "";
1767
- return `- ${name}: ${desc}`;
1768
- }).join("\n");
1769
- enhancedDescription += `
1770
-
1771
- Can transfer to:
1772
- ${transferList}`;
1773
- }
1774
- if (delegates.length > 0) {
1775
- const delegateList = delegates.map((rel) => {
1776
- const name = rel.externalAgent?.name || rel.name;
1777
- const desc = rel.externalAgent?.description || rel.description || "";
1778
- return `- ${name}: ${desc}`;
1779
- }).join("\n");
1780
- enhancedDescription += `
1781
-
1782
- Can delegate to:
1783
- ${delegateList}`;
1784
- }
1785
- return enhancedDescription;
1786
- }
1787
- async function hydrateAgent({
1788
- dbAgent,
1789
- graphId,
1790
- baseUrl,
1791
- apiKey,
1792
- credentialStoreRegistry
1793
- }) {
1794
- try {
1795
- const taskHandlerConfig = await createTaskHandlerConfig({
1796
- tenantId: dbAgent.tenantId,
1797
- projectId: dbAgent.projectId,
1798
- graphId,
1799
- subAgentId: dbAgent.id,
1800
- baseUrl,
1801
- apiKey
1802
- });
1803
- const taskHandler = createTaskHandler(taskHandlerConfig, credentialStoreRegistry);
1804
- const agentCard = createAgentCard({
1805
- dbAgent,
1806
- baseUrl
1807
- });
1808
- return {
1809
- subAgentId: dbAgent.id,
1810
- tenantId: dbAgent.tenantId,
1811
- projectId: dbAgent.projectId,
1812
- graphId,
1813
- agentCard,
1814
- taskHandler
1815
- };
1816
- } catch (error) {
1817
- console.error(`\u274C Failed to hydrate agent ${dbAgent.id}:`, error);
1818
- throw error;
1819
- }
1820
- }
1821
- async function getRegisteredAgent(executionContext, credentialStoreRegistry) {
1822
- const { tenantId, projectId, graphId, subAgentId, baseUrl, apiKey } = executionContext;
1823
- if (!subAgentId) {
1824
- throw new Error("Agent ID is required");
1825
- }
1826
- const dbAgent = await agentsCore.getSubAgentById(dbClient_default)({
1827
- scopes: { tenantId, projectId, graphId },
1828
- subAgentId
1829
- });
1830
- if (!dbAgent) {
1831
- return null;
1832
- }
1833
- const agentFrameworkBaseUrl = `${baseUrl}/agents`;
1834
- return hydrateAgent({
1835
- dbAgent,
1836
- graphId,
1837
- baseUrl: agentFrameworkBaseUrl,
1838
- credentialStoreRegistry,
1839
- apiKey
1840
- });
1841
- }
1842
-
1843
- // src/agents/generateTaskHandler.ts
1844
- init_dbClient();
1845
1723
  init_logger();
1846
1724
 
1847
1725
  // src/agents/ModelFactory.ts
@@ -2060,7 +1938,7 @@ var _ToolSessionManager = class _ToolSessionManager {
2060
1938
  return this.createSessionWithId(sessionId, tenantId, projectId, contextId, taskId);
2061
1939
  }
2062
1940
  /**
2063
- * Create a new tool session with a specific ID (for coordination with GraphSession)
1941
+ * Create a new tool session with a specific ID (for coordination with AgentSession)
2064
1942
  */
2065
1943
  createSessionWithId(sessionId, tenantId, projectId, contextId, taskId) {
2066
1944
  const session = {
@@ -2086,17 +1964,17 @@ var _ToolSessionManager = class _ToolSessionManager {
2086
1964
  return sessionId;
2087
1965
  }
2088
1966
  /**
2089
- * Ensure a graph-scoped session exists (idempotent)
2090
- * All agents in the same graph execution share this session
1967
+ * Ensure an agent-scoped session exists (idempotent)
1968
+ * All agents in the same agent execution share this session
2091
1969
  */
2092
- ensureGraphSession(sessionId, tenantId, projectId, contextId, taskId) {
1970
+ ensureAgentSession(sessionId, tenantId, projectId, contextId, taskId) {
2093
1971
  if (this.sessions.has(sessionId)) {
2094
- logger5.debug({ sessionId }, "Graph session already exists, reusing");
1972
+ logger5.debug({ sessionId }, "Agent session already exists, reusing");
2095
1973
  return sessionId;
2096
1974
  }
2097
1975
  logger5.debug(
2098
1976
  { sessionId, tenantId, contextId, taskId },
2099
- "Creating new graph-scoped tool session"
1977
+ "Creating new agent-scoped tool session"
2100
1978
  );
2101
1979
  return this.createSessionWithId(sessionId, tenantId, projectId, contextId, taskId);
2102
1980
  }
@@ -2206,7 +2084,7 @@ __publicField(_ToolSessionManager, "instance");
2206
2084
  var ToolSessionManager = _ToolSessionManager;
2207
2085
  var toolSessionManager = ToolSessionManager.getInstance();
2208
2086
 
2209
- // src/services/GraphSession.ts
2087
+ // src/services/AgentSession.ts
2210
2088
  init_conversations();
2211
2089
  init_dbClient();
2212
2090
  init_logger();
@@ -2426,7 +2304,7 @@ var _ArtifactService = class _ArtifactService {
2426
2304
  async getArtifactSummary(artifactId, toolCallId, artifactMap) {
2427
2305
  const key = `${artifactId}:${toolCallId}`;
2428
2306
  if (this.context.streamRequestId) {
2429
- const cachedArtifact = await graphSessionManager.getArtifactCache(
2307
+ const cachedArtifact = await agentSessionManager.getArtifactCache(
2430
2308
  this.context.streamRequestId,
2431
2309
  key
2432
2310
  );
@@ -2472,7 +2350,7 @@ var _ArtifactService = class _ArtifactService {
2472
2350
  async getArtifactFull(artifactId, toolCallId, artifactMap) {
2473
2351
  const key = `${artifactId}:${toolCallId}`;
2474
2352
  if (this.context.streamRequestId) {
2475
- const cachedArtifact = await graphSessionManager.getArtifactCache(
2353
+ const cachedArtifact = await agentSessionManager.getArtifactCache(
2476
2354
  this.context.streamRequestId,
2477
2355
  key
2478
2356
  );
@@ -2539,12 +2417,12 @@ var _ArtifactService = class _ArtifactService {
2539
2417
  };
2540
2418
  }
2541
2419
  /**
2542
- * Persist artifact to database via graph session
2420
+ * Persist artifact to database vian agent session
2543
2421
  */
2544
2422
  async persistArtifact(request, summaryData, fullData, subAgentId) {
2545
2423
  const effectiveAgentId = subAgentId || this.context.subAgentId;
2546
2424
  if (this.context.streamRequestId && effectiveAgentId && this.context.taskId) {
2547
- await graphSessionManager.recordEvent(
2425
+ await agentSessionManager.recordEvent(
2548
2426
  this.context.streamRequestId,
2549
2427
  "artifact_saved",
2550
2428
  effectiveAgentId,
@@ -2596,7 +2474,7 @@ var _ArtifactService = class _ArtifactService {
2596
2474
  };
2597
2475
  this.createdArtifacts.set(cacheKey, artifactForCache);
2598
2476
  if (this.context.streamRequestId) {
2599
- await graphSessionManager.setArtifactCache(
2477
+ await agentSessionManager.setArtifactCache(
2600
2478
  this.context.streamRequestId,
2601
2479
  cacheKey,
2602
2480
  artifactForCache
@@ -2628,7 +2506,7 @@ var _ArtifactService = class _ArtifactService {
2628
2506
  }
2629
2507
  /**
2630
2508
  * Save an already-created artifact directly to the database
2631
- * Used by GraphSession to save artifacts after name/description generation
2509
+ * Used by AgentSession to save artifacts after name/description generation
2632
2510
  */
2633
2511
  async saveArtifact(artifact) {
2634
2512
  let summaryData = artifact.data;
@@ -3175,14 +3053,14 @@ __publicField(_ArtifactParser, "ARTIFACT_PATTERNS", [
3175
3053
  __publicField(_ArtifactParser, "INCOMPLETE_CREATE_REGEX", /<artifact:create(?![^>]*(?:\/>|<\/artifact:create>))/);
3176
3054
  var ArtifactParser = _ArtifactParser;
3177
3055
 
3178
- // src/services/GraphSession.ts
3179
- var logger9 = agentsCore.getLogger("GraphSession");
3180
- var GraphSession = class {
3056
+ // src/services/AgentSession.ts
3057
+ var logger9 = agentsCore.getLogger("AgentSession");
3058
+ var AgentSession = class {
3181
3059
  // Whether to send data operations
3182
- constructor(sessionId, messageId, graphId, tenantId, projectId, contextId) {
3060
+ constructor(sessionId, messageId, agentId, tenantId, projectId, contextId) {
3183
3061
  this.sessionId = sessionId;
3184
3062
  this.messageId = messageId;
3185
- this.graphId = graphId;
3063
+ this.agentId = agentId;
3186
3064
  this.tenantId = tenantId;
3187
3065
  this.projectId = projectId;
3188
3066
  this.contextId = contextId;
@@ -3209,7 +3087,7 @@ var GraphSession = class {
3209
3087
  __publicField(this, "artifactParser");
3210
3088
  // Session-scoped ArtifactParser instance
3211
3089
  __publicField(this, "isEmitOperations", false);
3212
- logger9.debug({ sessionId, messageId, graphId }, "GraphSession created");
3090
+ logger9.debug({ sessionId, messageId, agentId }, "AgentSession created");
3213
3091
  if (tenantId && projectId) {
3214
3092
  toolSessionManager.createSessionWithId(
3215
3093
  sessionId,
@@ -3245,7 +3123,7 @@ var GraphSession = class {
3245
3123
  this.isEmitOperations = true;
3246
3124
  logger9.info(
3247
3125
  { sessionId: this.sessionId },
3248
- "\u{1F50D} DEBUG: Emit operations enabled for GraphSession"
3126
+ "\u{1F50D} DEBUG: Emit operations enabled for AgentSession"
3249
3127
  );
3250
3128
  }
3251
3129
  /**
@@ -3518,7 +3396,7 @@ var GraphSession = class {
3518
3396
  return {
3519
3397
  sessionId: this.sessionId,
3520
3398
  messageId: this.messageId,
3521
- graphId: this.graphId,
3399
+ agentId: this.agentId,
3522
3400
  totalEvents: this.events.length,
3523
3401
  eventCounts,
3524
3402
  agentCounts,
@@ -3569,7 +3447,7 @@ var GraphSession = class {
3569
3447
  }
3570
3448
  }
3571
3449
  /**
3572
- * Generate and send a status update using graph-level summarizer
3450
+ * Generate and send a status update using agent-level summarizer
3573
3451
  */
3574
3452
  async generateAndSendUpdate() {
3575
3453
  if (this.isEnded) {
@@ -3594,8 +3472,8 @@ var GraphSession = class {
3594
3472
  logger9.warn({ sessionId: this.sessionId }, "No status update state - cannot generate update");
3595
3473
  return;
3596
3474
  }
3597
- if (!this.graphId) {
3598
- logger9.warn({ sessionId: this.sessionId }, "No graph ID - cannot generate update");
3475
+ if (!this.agentId) {
3476
+ logger9.warn({ sessionId: this.sessionId }, "No agent ID - cannot generate update");
3599
3477
  return;
3600
3478
  }
3601
3479
  const newEventCount = this.events.length - this.statusUpdateState.lastEventCount;
@@ -3747,10 +3625,10 @@ var GraphSession = class {
3747
3625
  */
3748
3626
  async generateStructuredStatusUpdate(newEvents, elapsedTime, statusComponents, summarizerModel, previousSummaries = []) {
3749
3627
  return tracer.startActiveSpan(
3750
- "graph_session.generate_structured_update",
3628
+ "agent_session.generate_structured_update",
3751
3629
  {
3752
3630
  attributes: {
3753
- "graph_session.id": this.sessionId,
3631
+ "agent_session.id": this.sessionId,
3754
3632
  "events.count": newEvents.length,
3755
3633
  "elapsed_time.seconds": Math.round(elapsedTime / 1e3),
3756
3634
  "llm.model": summarizerModel?.model,
@@ -3831,7 +3709,7 @@ CRITICAL - HIDE ALL INTERNAL SYSTEM OPERATIONS:
3831
3709
  - 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"
3832
3710
  - NEVER reveal internal architecture: No mentions of different agents, components, systems, or modules working together
3833
3711
  - NEVER mention artifact operations: Users don't need to know about data being saved, stored, or organized internally
3834
- - NEVER describe handoffs or transitions: Present everything as one seamless operation
3712
+ - NEVER describe transfers or transitions: Present everything as one seamless operation
3835
3713
  - If you see "transfer", "delegation_sent", "delegation_returned", or "artifact_saved" events - IGNORE THEM or translate to user-facing information only
3836
3714
  - Focus ONLY on actual discoveries, findings, and results that matter to the user
3837
3715
 
@@ -4053,10 +3931,10 @@ ${this.statusUpdateState?.config.prompt?.trim() || ""}`;
4053
3931
  */
4054
3932
  async processArtifact(artifactData) {
4055
3933
  return tracer.startActiveSpan(
4056
- "graph_session.process_artifact",
3934
+ "agent_session.process_artifact",
4057
3935
  {
4058
3936
  attributes: {
4059
- "graph_session.id": this.sessionId,
3937
+ "agent_session.id": this.sessionId,
4060
3938
  "artifact.id": artifactData.artifactId,
4061
3939
  "artifact.type": artifactData.artifactType || "unknown",
4062
3940
  "artifact.agent_id": artifactData.subAgentId || "unknown",
@@ -4124,7 +4002,7 @@ Make it specific and relevant.`;
4124
4002
  scopes: {
4125
4003
  tenantId: artifactData.tenantId,
4126
4004
  projectId: artifactData.projectId,
4127
- graphId: this.graphId || ""
4005
+ agentId: this.agentId || ""
4128
4006
  },
4129
4007
  subAgentId: artifactData.subAgentId
4130
4008
  });
@@ -4179,7 +4057,7 @@ Make it specific and relevant.`;
4179
4057
  description: z6.z.string().describe("Brief description of the artifact's relevance to the user's question")
4180
4058
  });
4181
4059
  const { object } = await tracer.startActiveSpan(
4182
- "graph_session.generate_artifact_metadata",
4060
+ "agent_session.generate_artifact_metadata",
4183
4061
  {
4184
4062
  attributes: {
4185
4063
  "llm.model": this.statusUpdateState?.summarizerModel?.model,
@@ -4389,20 +4267,20 @@ Make it specific and relevant.`;
4389
4267
  }
4390
4268
  }
4391
4269
  };
4392
- var GraphSessionManager = class {
4270
+ var AgentSessionManager = class {
4393
4271
  constructor() {
4394
4272
  __publicField(this, "sessions", /* @__PURE__ */ new Map());
4395
4273
  }
4396
4274
  /**
4397
4275
  * Create a new session for a message
4398
4276
  */
4399
- createSession(messageId, graphId, tenantId, projectId, contextId) {
4277
+ createSession(messageId, agentId, tenantId, projectId, contextId) {
4400
4278
  const sessionId = messageId;
4401
- const session = new GraphSession(sessionId, messageId, graphId, tenantId, projectId, contextId);
4279
+ const session = new AgentSession(sessionId, messageId, agentId, tenantId, projectId, contextId);
4402
4280
  this.sessions.set(sessionId, session);
4403
4281
  logger9.info(
4404
- { sessionId, messageId, graphId, tenantId, projectId, contextId },
4405
- "GraphSession created"
4282
+ { sessionId, messageId, agentId, tenantId, projectId, contextId },
4283
+ "AgentSession created"
4406
4284
  );
4407
4285
  return sessionId;
4408
4286
  }
@@ -4469,7 +4347,7 @@ var GraphSessionManager = class {
4469
4347
  }
4470
4348
  const events = session.getEvents();
4471
4349
  const summary = session.getSummary();
4472
- logger9.info({ sessionId, summary }, "GraphSession ended");
4350
+ logger9.info({ sessionId, summary }, "AgentSession ended");
4473
4351
  session.cleanup();
4474
4352
  this.sessions.delete(sessionId);
4475
4353
  return events;
@@ -4533,36 +4411,36 @@ var GraphSessionManager = class {
4533
4411
  }
4534
4412
  }
4535
4413
  };
4536
- var graphSessionManager = new GraphSessionManager();
4414
+ var agentSessionManager = new AgentSessionManager();
4537
4415
 
4538
4416
  // src/utils/model-resolver.ts
4539
4417
  init_dbClient();
4540
- async function resolveModelConfig(graphId, agent) {
4541
- if (agent.models?.base?.model) {
4418
+ async function resolveModelConfig(agentId, subAgent) {
4419
+ if (subAgent.models?.base?.model) {
4542
4420
  return {
4543
- base: agent.models.base,
4544
- structuredOutput: agent.models.structuredOutput || agent.models.base,
4545
- summarizer: agent.models.summarizer || agent.models.base
4421
+ base: subAgent.models.base,
4422
+ structuredOutput: subAgent.models.structuredOutput || subAgent.models.base,
4423
+ summarizer: subAgent.models.summarizer || subAgent.models.base
4546
4424
  };
4547
4425
  }
4548
- const graph = await agentsCore.getAgentGraphById(dbClient_default)({
4549
- scopes: { tenantId: agent.tenantId, projectId: agent.projectId, graphId }
4426
+ const agent = await agentsCore.getAgentById(dbClient_default)({
4427
+ scopes: { tenantId: subAgent.tenantId, projectId: subAgent.projectId, agentId }
4550
4428
  });
4551
- if (graph?.models?.base?.model) {
4429
+ if (agent?.models?.base?.model) {
4552
4430
  return {
4553
- base: graph.models.base,
4554
- structuredOutput: agent.models?.structuredOutput || graph.models.structuredOutput || graph.models.base,
4555
- summarizer: agent.models?.summarizer || graph.models.summarizer || graph.models.base
4431
+ base: agent.models.base,
4432
+ structuredOutput: subAgent.models?.structuredOutput || agent.models.structuredOutput || agent.models.base,
4433
+ summarizer: subAgent.models?.summarizer || agent.models.summarizer || agent.models.base
4556
4434
  };
4557
4435
  }
4558
4436
  const project = await agentsCore.getProject(dbClient_default)({
4559
- scopes: { tenantId: agent.tenantId, projectId: agent.projectId }
4437
+ scopes: { tenantId: subAgent.tenantId, projectId: subAgent.projectId }
4560
4438
  });
4561
4439
  if (project?.models?.base?.model) {
4562
4440
  return {
4563
4441
  base: project.models.base,
4564
- structuredOutput: agent.models?.structuredOutput || project.models.structuredOutput || project.models.base,
4565
- summarizer: agent.models?.summarizer || project.models.summarizer || project.models.base
4442
+ structuredOutput: subAgent.models?.structuredOutput || project.models.structuredOutput || project.models.base,
4443
+ summarizer: subAgent.models?.summarizer || project.models.summarizer || project.models.base
4566
4444
  };
4567
4445
  }
4568
4446
  throw new Error(
@@ -4599,7 +4477,7 @@ var _IncrementalStreamParser = class _IncrementalStreamParser {
4599
4477
  this.contextId = contextId;
4600
4478
  this.subAgentId = artifactParserOptions?.subAgentId;
4601
4479
  if (artifactParserOptions?.streamRequestId) {
4602
- const sessionParser = graphSessionManager.getArtifactParser(
4480
+ const sessionParser = agentSessionManager.getArtifactParser(
4603
4481
  artifactParserOptions.streamRequestId
4604
4482
  );
4605
4483
  if (sessionParser) {
@@ -4608,9 +4486,9 @@ var _IncrementalStreamParser = class _IncrementalStreamParser {
4608
4486
  }
4609
4487
  }
4610
4488
  let sharedArtifactService = null;
4611
- if (artifactParserOptions?.streamRequestId && typeof graphSessionManager.getArtifactService === "function") {
4489
+ if (artifactParserOptions?.streamRequestId && typeof agentSessionManager.getArtifactService === "function") {
4612
4490
  try {
4613
- sharedArtifactService = graphSessionManager.getArtifactService(
4491
+ sharedArtifactService = agentSessionManager.getArtifactService(
4614
4492
  artifactParserOptions.streamRequestId
4615
4493
  );
4616
4494
  } catch (error) {
@@ -4985,7 +4863,7 @@ var ResponseFormatter = class {
4985
4863
  __publicField(this, "subAgentId");
4986
4864
  this.subAgentId = artifactParserOptions?.subAgentId;
4987
4865
  if (artifactParserOptions?.streamRequestId) {
4988
- const sessionParser = graphSessionManager.getArtifactParser(
4866
+ const sessionParser = agentSessionManager.getArtifactParser(
4989
4867
  artifactParserOptions.streamRequestId
4990
4868
  );
4991
4869
  if (sessionParser) {
@@ -4994,9 +4872,9 @@ var ResponseFormatter = class {
4994
4872
  }
4995
4873
  }
4996
4874
  let sharedArtifactService = null;
4997
- if (artifactParserOptions?.streamRequestId && typeof graphSessionManager.getArtifactService === "function") {
4875
+ if (artifactParserOptions?.streamRequestId && typeof agentSessionManager.getArtifactService === "function") {
4998
4876
  try {
4999
- sharedArtifactService = graphSessionManager.getArtifactService(
4877
+ sharedArtifactService = agentSessionManager.getArtifactService(
5000
4878
  artifactParserOptions.streamRequestId
5001
4879
  );
5002
4880
  } catch (error) {
@@ -5138,12 +5016,12 @@ var ResponseFormatter = class {
5138
5016
  }
5139
5017
  }
5140
5018
  };
5141
- function agentInitializingOp(sessionId, graphId) {
5019
+ function agentInitializingOp(sessionId, agentId) {
5142
5020
  return {
5143
5021
  type: "agent_initializing",
5144
5022
  details: {
5145
5023
  sessionId,
5146
- graphId
5024
+ agentId
5147
5025
  }
5148
5026
  };
5149
5027
  }
@@ -6229,23 +6107,29 @@ var createTransferToAgentTool = ({
6229
6107
  logger14.info(
6230
6108
  {
6231
6109
  transferTo: transferConfig.id ?? "unknown",
6232
- fromAgent: callingAgentId
6110
+ fromSubAgent: callingAgentId
6233
6111
  },
6234
6112
  "invoked transferToAgentTool"
6235
6113
  );
6236
6114
  if (streamRequestId) {
6237
- graphSessionManager.recordEvent(streamRequestId, "transfer", callingAgentId, {
6115
+ agentSessionManager.recordEvent(streamRequestId, "transfer", callingAgentId, {
6238
6116
  fromSubAgent: callingAgentId,
6239
6117
  targetSubAgent: transferConfig.id ?? "unknown",
6240
6118
  reason: `Transfer to ${transferConfig.name || transferConfig.id}`
6241
6119
  });
6242
6120
  }
6243
- return {
6121
+ const transferResult = {
6244
6122
  type: "transfer",
6245
- target: transferConfig.id ?? "unknown",
6246
- fromAgentId: callingAgentId
6123
+ targetSubAgentId: transferConfig.id ?? "unknown",
6124
+ // Changed from "target" for type safety
6125
+ fromSubAgentId: callingAgentId
6247
6126
  // Include the calling agent ID for tracking
6248
6127
  };
6128
+ logger14.info({
6129
+ transferResult,
6130
+ transferResultKeys: Object.keys(transferResult)
6131
+ }, "[DEBUG] Transfer tool returning");
6132
+ return transferResult;
6249
6133
  }
6250
6134
  });
6251
6135
  };
@@ -6254,7 +6138,7 @@ function createDelegateToAgentTool({
6254
6138
  callingAgentId,
6255
6139
  tenantId,
6256
6140
  projectId,
6257
- graphId,
6141
+ agentId,
6258
6142
  contextId,
6259
6143
  metadata,
6260
6144
  sessionId,
@@ -6275,7 +6159,7 @@ function createDelegateToAgentTool({
6275
6159
  });
6276
6160
  }
6277
6161
  if (metadata.streamRequestId) {
6278
- graphSessionManager.recordEvent(
6162
+ agentSessionManager.recordEvent(
6279
6163
  metadata.streamRequestId,
6280
6164
  "delegation_sent",
6281
6165
  callingAgentId,
@@ -6294,7 +6178,7 @@ function createDelegateToAgentTool({
6294
6178
  scopes: {
6295
6179
  tenantId,
6296
6180
  projectId,
6297
- graphId
6181
+ agentId
6298
6182
  },
6299
6183
  subAgentId: delegateConfig.config.id
6300
6184
  });
@@ -6340,8 +6224,8 @@ function createDelegateToAgentTool({
6340
6224
  Authorization: `Bearer ${metadata.apiKey}`,
6341
6225
  "x-inkeep-tenant-id": tenantId,
6342
6226
  "x-inkeep-project-id": projectId,
6343
- "x-inkeep-graph-id": graphId,
6344
- "x-inkeep-agent-id": delegateConfig.config.id
6227
+ "x-inkeep-agent-id": agentId,
6228
+ "x-inkeep-sub-agent-id": delegateConfig.config.id
6345
6229
  };
6346
6230
  }
6347
6231
  const a2aClient = new A2AClient(delegateConfig.config.baseUrl, {
@@ -6372,7 +6256,7 @@ function createDelegateToAgentTool({
6372
6256
  // Flag to prevent streaming in delegated agents
6373
6257
  delegationId,
6374
6258
  // Include delegation ID for tracking
6375
- ...isInternal ? { fromAgentId: callingAgentId } : { fromExternalAgentId: callingAgentId }
6259
+ ...isInternal ? { fromSubAgentId: callingAgentId } : { fromExternalAgentId: callingAgentId }
6376
6260
  }
6377
6261
  };
6378
6262
  logger14.info({ messageToSend }, "messageToSend");
@@ -6388,7 +6272,7 @@ function createDelegateToAgentTool({
6388
6272
  visibility: isInternal ? "internal" : "external",
6389
6273
  messageType: "a2a-request",
6390
6274
  fromSubAgentId: callingAgentId,
6391
- ...isInternal ? { toAgentId: delegateConfig.config.id } : { toExternalAgentId: delegateConfig.config.id }
6275
+ ...isInternal ? { toSubAgentId: delegateConfig.config.id } : { toExternalAgentId: delegateConfig.config.id }
6392
6276
  });
6393
6277
  const response = await a2aClient.sendMessage({
6394
6278
  message: messageToSend
@@ -6416,7 +6300,7 @@ function createDelegateToAgentTool({
6416
6300
  toolSessionManager.recordToolResult(sessionId, toolResult);
6417
6301
  }
6418
6302
  if (metadata.streamRequestId) {
6419
- graphSessionManager.recordEvent(
6303
+ agentSessionManager.recordEvent(
6420
6304
  metadata.streamRequestId,
6421
6305
  "delegation_returned",
6422
6306
  callingAgentId,
@@ -6495,7 +6379,7 @@ var system_prompt_default = `<system_message>
6495
6379
  {{CORE_INSTRUCTIONS}}
6496
6380
  </core_instructions>
6497
6381
 
6498
- {{GRAPH_CONTEXT_SECTION}}
6382
+ {{AGENT_CONTEXT_SECTION}}
6499
6383
 
6500
6384
  {{ARTIFACTS_SECTION}}
6501
6385
  {{TOOLS_SECTION}}
@@ -6660,7 +6544,7 @@ When you use delegation tools, the response may include artifacts in the parts a
6660
6544
  These artifacts become immediately available for you to reference using the artifactId and toolCallId from the response.
6661
6545
  Present delegation results naturally without mentioning the delegation process itself.
6662
6546
 
6663
- 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.`;
6547
+ 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.`;
6664
6548
 
6665
6549
  // src/agents/versions/v1/Phase1Config.ts
6666
6550
  init_logger();
@@ -6706,8 +6590,8 @@ var Phase1Config = class _Phase1Config {
6706
6590
  }
6707
6591
  let systemPrompt = systemPromptTemplate;
6708
6592
  systemPrompt = systemPrompt.replace("{{CORE_INSTRUCTIONS}}", config.corePrompt);
6709
- const graphContextSection = this.generateGraphContextSection(config.graphPrompt);
6710
- systemPrompt = systemPrompt.replace("{{GRAPH_CONTEXT_SECTION}}", graphContextSection);
6593
+ const agentContextSection = this.generateAgentContextSection(config.agentPrompt);
6594
+ systemPrompt = systemPrompt.replace("{{AGENT_CONTEXT_SECTION}}", agentContextSection);
6711
6595
  const toolData = this.isToolDataArray(config.tools) ? config.tools : _Phase1Config.convertMcpToolsToToolData(config.tools);
6712
6596
  const hasArtifactComponents = config.artifactComponents && config.artifactComponents.length > 0;
6713
6597
  const artifactsSection = this.generateArtifactsSection(
@@ -6715,7 +6599,7 @@ var Phase1Config = class _Phase1Config {
6715
6599
  config.artifacts,
6716
6600
  hasArtifactComponents,
6717
6601
  config.artifactComponents,
6718
- config.hasGraphArtifactComponents
6602
+ config.hasAgentArtifactComponents
6719
6603
  );
6720
6604
  systemPrompt = systemPrompt.replace("{{ARTIFACTS_SECTION}}", artifactsSection);
6721
6605
  const toolsSection = this.generateToolsSection(templates, toolData);
@@ -6734,14 +6618,14 @@ var Phase1Config = class _Phase1Config {
6734
6618
  systemPrompt = systemPrompt.replace("{{DELEGATION_INSTRUCTIONS}}", delegationSection);
6735
6619
  return systemPrompt;
6736
6620
  }
6737
- generateGraphContextSection(graphPrompt) {
6738
- if (!graphPrompt) {
6621
+ generateAgentContextSection(agentPrompt) {
6622
+ if (!agentPrompt) {
6739
6623
  return "";
6740
6624
  }
6741
6625
  return `
6742
- <graph_context>
6743
- ${graphPrompt}
6744
- </graph_context>`;
6626
+ <agent_context>
6627
+ ${agentPrompt}
6628
+ </agent_context>`;
6745
6629
  }
6746
6630
  generateThinkingPreparationSection(templates, isThinkingPreparation) {
6747
6631
  if (!isThinkingPreparation) {
@@ -6759,7 +6643,7 @@ var Phase1Config = class _Phase1Config {
6759
6643
  }
6760
6644
  return `- You have transfer_to_* tools that seamlessly continue the conversation
6761
6645
  - NEVER announce transfers - just call the tool when needed
6762
- - The conversation continues naturally without any handoff language`;
6646
+ - The conversation continues naturally without any transfer language`;
6763
6647
  }
6764
6648
  generateDelegationInstructions(hasDelegateRelations) {
6765
6649
  if (!hasDelegateRelations) {
@@ -6993,8 +6877,8 @@ ${typeDescriptions}
6993
6877
  - Do NOT abbreviate, modify, or guess the type name
6994
6878
  - Copy the exact quoted name from the "AVAILABLE ARTIFACT TYPES" list above`;
6995
6879
  }
6996
- generateArtifactsSection(templates, artifacts, hasArtifactComponents = false, artifactComponents, hasGraphArtifactComponents) {
6997
- const shouldShowReferencingRules = hasGraphArtifactComponents || artifacts.length > 0;
6880
+ generateArtifactsSection(templates, artifacts, hasArtifactComponents = false, artifactComponents, hasAgentArtifactComponents) {
6881
+ const shouldShowReferencingRules = hasAgentArtifactComponents || artifacts.length > 0;
6998
6882
  const rules = this.getArtifactReferencingRules(
6999
6883
  hasArtifactComponents,
7000
6884
  templates,
@@ -7474,7 +7358,7 @@ ${artifact_retrieval_guidance_default}
7474
7358
  dataComponents,
7475
7359
  artifactComponents,
7476
7360
  hasArtifactComponents,
7477
- hasGraphArtifactComponents,
7361
+ hasAgentArtifactComponents,
7478
7362
  artifacts = []
7479
7363
  } = config;
7480
7364
  let allDataComponents = [...dataComponents];
@@ -7490,7 +7374,7 @@ ${artifact_retrieval_guidance_default}
7490
7374
  }
7491
7375
  const dataComponentsSection = this.generateDataComponentsSection(allDataComponents);
7492
7376
  const artifactsSection = this.generateArtifactsSection(artifacts);
7493
- const shouldShowReferencingRules = hasGraphArtifactComponents || artifacts.length > 0;
7377
+ const shouldShowReferencingRules = hasAgentArtifactComponents || artifacts.length > 0;
7494
7378
  const artifactGuidance = this.getStructuredArtifactGuidance(
7495
7379
  hasArtifactComponents,
7496
7380
  artifactComponents,
@@ -7695,7 +7579,7 @@ var Agent = class {
7695
7579
  return this.isDelegatedAgent ? void 0 : this.streamHelper;
7696
7580
  }
7697
7581
  /**
7698
- * Wraps a tool with streaming lifecycle tracking (start, complete, error) and GraphSession recording
7582
+ * Wraps a tool with streaming lifecycle tracking (start, complete, error) and AgentSession recording
7699
7583
  */
7700
7584
  wrapToolWithStreaming(toolName, toolDefinition, streamRequestId, toolType) {
7701
7585
  if (!toolDefinition || typeof toolDefinition !== "object" || !("execute" in toolDefinition)) {
@@ -7714,7 +7598,7 @@ var Agent = class {
7714
7598
  "tool.purpose": toolDefinition.description || "No description provided",
7715
7599
  "ai.toolType": toolType || "unknown",
7716
7600
  "ai.agentName": this.config.name || "unknown",
7717
- "graph.id": this.config.graphId || "unknown"
7601
+ "agent.id": this.config.agentId || "unknown"
7718
7602
  });
7719
7603
  }
7720
7604
  const isInternalTool = toolName.includes("save_tool_result") || toolName.includes("thinking_complete") || toolName.startsWith("transfer_to_") || toolName.startsWith("delegate_to_");
@@ -7722,7 +7606,7 @@ var Agent = class {
7722
7606
  const result = await originalExecute(args, context);
7723
7607
  const duration = Date.now() - startTime;
7724
7608
  if (streamRequestId && !isInternalTool) {
7725
- graphSessionManager.recordEvent(streamRequestId, "tool_execution", this.config.id, {
7609
+ agentSessionManager.recordEvent(streamRequestId, "tool_execution", this.config.id, {
7726
7610
  toolName,
7727
7611
  args,
7728
7612
  result,
@@ -7735,7 +7619,7 @@ var Agent = class {
7735
7619
  const duration = Date.now() - startTime;
7736
7620
  const errorMessage = error instanceof Error ? error.message : "Unknown error";
7737
7621
  if (streamRequestId && !isInternalTool) {
7738
- graphSessionManager.recordEvent(streamRequestId, "tool_execution", this.config.id, {
7622
+ agentSessionManager.recordEvent(streamRequestId, "tool_execution", this.config.id, {
7739
7623
  toolName,
7740
7624
  args,
7741
7625
  result: { error: errorMessage },
@@ -7780,7 +7664,7 @@ var Agent = class {
7780
7664
  callingAgentId: this.config.id,
7781
7665
  tenantId: this.config.tenantId,
7782
7666
  projectId: this.config.projectId,
7783
- graphId: this.config.graphId,
7667
+ agentId: this.config.agentId,
7784
7668
  contextId: runtimeContext?.contextId || "default",
7785
7669
  // fallback for compatibility
7786
7670
  metadata: runtimeContext?.metadata || {
@@ -7889,7 +7773,7 @@ var Agent = class {
7889
7773
  scopes: {
7890
7774
  tenantId: this.config.tenantId,
7891
7775
  projectId: this.config.projectId,
7892
- graphId: this.config.graphId,
7776
+ agentId: this.config.agentId,
7893
7777
  subAgentId: this.config.id
7894
7778
  }
7895
7779
  });
@@ -7995,26 +7879,26 @@ var Agent = class {
7995
7879
  "ai.toolCall.args": JSON.stringify({ operation: "mcp_tool_discovery" }),
7996
7880
  "ai.toolCall.result": JSON.stringify({
7997
7881
  status: "no_tools_available",
7998
- message: `MCP server has 0 effective tools. Double check the selected tools in your graph and the active tools in the MCP server configuration.`,
7882
+ message: `MCP server has 0 effective tools. Double check the selected tools in your agent and the active tools in the MCP server configuration.`,
7999
7883
  serverUrl: tool3.config.type === "mcp" ? tool3.config.mcp.server.url : "unknown",
8000
7884
  originalToolName: tool3.name
8001
7885
  }),
8002
7886
  "ai.toolType": "mcp",
8003
7887
  "ai.agentName": this.config.name || "unknown",
8004
7888
  "conversation.id": this.conversationId || "unknown",
8005
- "graph.id": this.config.graphId || "unknown",
7889
+ "agent.id": this.config.agentId || "unknown",
8006
7890
  "tenant.id": this.config.tenantId || "unknown",
8007
7891
  "project.id": this.config.projectId || "unknown"
8008
7892
  }
8009
7893
  },
8010
7894
  (span) => {
8011
7895
  agentsCore.setSpanWithError(span, new Error(`0 effective tools available for ${tool3.name}`));
8012
- graphSessionManager.recordEvent(streamRequestId, "tool_execution", this.config.id, {
7896
+ agentSessionManager.recordEvent(streamRequestId, "tool_execution", this.config.id, {
8013
7897
  toolName: tool3.name,
8014
7898
  args: { operation: "mcp_tool_discovery" },
8015
7899
  result: {
8016
7900
  status: "no_tools_available",
8017
- message: `MCP server has 0 effective tools. Double check the selected tools in your graph and the active tools in the MCP server configuration.`,
7901
+ message: `MCP server has 0 effective tools. Double check the selected tools in your agent and the active tools in the MCP server configuration.`,
8018
7902
  serverUrl: tool3.config.type === "mcp" ? tool3.config.mcp.server.url : "unknown"
8019
7903
  }
8020
7904
  });
@@ -8063,7 +7947,7 @@ var Agent = class {
8063
7947
  scopes: {
8064
7948
  tenantId: this.config.tenantId,
8065
7949
  projectId: this.config.projectId,
8066
- graphId: this.config.graphId
7950
+ agentId: this.config.agentId
8067
7951
  },
8068
7952
  subAgentId: this.config.id
8069
7953
  });
@@ -8157,14 +8041,14 @@ var Agent = class {
8157
8041
  async getResolvedContext(conversationId, headers) {
8158
8042
  try {
8159
8043
  if (!this.config.contextConfigId) {
8160
- logger18.debug({ graphId: this.config.graphId }, "No context config found for graph");
8044
+ logger18.debug({ agentId: this.config.agentId }, "No context config found for agent");
8161
8045
  return null;
8162
8046
  }
8163
8047
  const contextConfig = await agentsCore.getContextConfigById(dbClient_default)({
8164
8048
  scopes: {
8165
8049
  tenantId: this.config.tenantId,
8166
8050
  projectId: this.config.projectId,
8167
- graphId: this.config.graphId
8051
+ agentId: this.config.agentId
8168
8052
  },
8169
8053
  id: this.config.contextConfigId
8170
8054
  });
@@ -8211,67 +8095,67 @@ var Agent = class {
8211
8095
  }
8212
8096
  }
8213
8097
  /**
8214
- * Get the graph prompt for this agent's graph
8098
+ * Get the agent prompt for this agent's agent
8215
8099
  */
8216
- async getGraphPrompt() {
8100
+ async getAgentPrompt() {
8217
8101
  try {
8218
- const graphDefinition = await agentsCore.getFullGraphDefinition(dbClient_default)({
8102
+ const agentDefinition = await agentsCore.getFullAgentDefinition(dbClient_default)({
8219
8103
  scopes: {
8220
8104
  tenantId: this.config.tenantId,
8221
8105
  projectId: this.config.projectId,
8222
- graphId: this.config.graphId
8106
+ agentId: this.config.agentId
8223
8107
  }
8224
8108
  });
8225
- return graphDefinition?.graphPrompt || void 0;
8109
+ return agentDefinition?.prompt || void 0;
8226
8110
  } catch (error) {
8227
8111
  logger18.warn(
8228
8112
  {
8229
- graphId: this.config.graphId,
8113
+ agentId: this.config.agentId,
8230
8114
  error: error instanceof Error ? error.message : "Unknown error"
8231
8115
  },
8232
- "Failed to get graph prompt"
8116
+ "Failed to get agent prompt"
8233
8117
  );
8234
8118
  return void 0;
8235
8119
  }
8236
8120
  }
8237
8121
  /**
8238
- * Check if any agent in the graph has artifact components configured
8122
+ * Check if any agent in the agent has artifact components configured
8239
8123
  */
8240
- async hasGraphArtifactComponents() {
8124
+ async hasAgentArtifactComponents() {
8241
8125
  try {
8242
- const graphDefinition = await agentsCore.getFullGraphDefinition(dbClient_default)({
8126
+ const agentDefinition = await agentsCore.getFullAgentDefinition(dbClient_default)({
8243
8127
  scopes: {
8244
8128
  tenantId: this.config.tenantId,
8245
8129
  projectId: this.config.projectId,
8246
- graphId: this.config.graphId
8130
+ agentId: this.config.agentId
8247
8131
  }
8248
8132
  });
8249
- if (!graphDefinition) {
8133
+ if (!agentDefinition) {
8250
8134
  return false;
8251
8135
  }
8252
- return Object.values(graphDefinition.subAgents).some(
8136
+ return Object.values(agentDefinition.subAgents).some(
8253
8137
  (subAgent) => "artifactComponents" in subAgent && subAgent.artifactComponents && subAgent.artifactComponents.length > 0
8254
8138
  );
8255
8139
  } catch (error) {
8256
8140
  logger18.warn(
8257
8141
  {
8258
- graphId: this.config.graphId,
8142
+ agentId: this.config.agentId,
8259
8143
  tenantId: this.config.tenantId,
8260
8144
  projectId: this.config.projectId,
8261
8145
  error: error instanceof Error ? error.message : "Unknown error"
8262
8146
  },
8263
- "Failed to check graph artifact components, assuming none exist"
8147
+ "Failed to check agent artifact components, assuming none exist"
8264
8148
  );
8265
8149
  return this.artifactComponents.length > 0;
8266
8150
  }
8267
8151
  }
8268
8152
  /**
8269
8153
  * Build adaptive system prompt for Phase 2 structured output generation
8270
- * based on configured data components and artifact components across the graph
8154
+ * based on configured data components and artifact components across the agent
8271
8155
  */
8272
8156
  async buildPhase2SystemPrompt(runtimeContext) {
8273
8157
  const phase2Config = new Phase2Config();
8274
- const hasGraphArtifactComponents = await this.hasGraphArtifactComponents();
8158
+ const hasAgentArtifactComponents = await this.hasAgentArtifactComponents();
8275
8159
  const conversationId = runtimeContext?.metadata?.conversationId || runtimeContext?.contextId;
8276
8160
  const resolvedContext = conversationId ? await this.getResolvedContext(conversationId) : null;
8277
8161
  let processedPrompt = this.config.agentPrompt;
@@ -8311,7 +8195,7 @@ var Agent = class {
8311
8195
  dataComponents: this.config.dataComponents || [],
8312
8196
  artifactComponents: this.artifactComponents,
8313
8197
  hasArtifactComponents: this.artifactComponents && this.artifactComponents.length > 0,
8314
- hasGraphArtifactComponents,
8198
+ hasAgentArtifactComponents,
8315
8199
  artifacts: referenceArtifacts
8316
8200
  });
8317
8201
  }
@@ -8375,10 +8259,10 @@ var Agent = class {
8375
8259
  });
8376
8260
  const componentDataComponents = excludeDataComponents ? [] : this.config.dataComponents || [];
8377
8261
  const isThinkingPreparation = this.config.dataComponents && this.config.dataComponents.length > 0 && excludeDataComponents;
8378
- let graphPrompt = await this.getGraphPrompt();
8379
- if (graphPrompt && resolvedContext) {
8262
+ let agentPrompt = await this.getAgentPrompt();
8263
+ if (agentPrompt && resolvedContext) {
8380
8264
  try {
8381
- graphPrompt = agentsCore.TemplateEngine.render(graphPrompt, resolvedContext, {
8265
+ agentPrompt = agentsCore.TemplateEngine.render(agentPrompt, resolvedContext, {
8382
8266
  strict: false,
8383
8267
  preserveUnresolved: false
8384
8268
  });
@@ -8388,20 +8272,20 @@ var Agent = class {
8388
8272
  conversationId,
8389
8273
  error: error instanceof Error ? error.message : "Unknown error"
8390
8274
  },
8391
- "Failed to process graph prompt with context, using original"
8275
+ "Failed to process agent prompt with context, using original"
8392
8276
  );
8393
8277
  }
8394
8278
  }
8395
8279
  const shouldIncludeArtifactComponents = !excludeDataComponents;
8396
- const hasGraphArtifactComponents = await this.hasGraphArtifactComponents();
8280
+ const hasAgentArtifactComponents = await this.hasAgentArtifactComponents();
8397
8281
  const config = {
8398
8282
  corePrompt: processedPrompt,
8399
- graphPrompt,
8283
+ agentPrompt,
8400
8284
  tools: toolDefinitions,
8401
8285
  dataComponents: componentDataComponents,
8402
8286
  artifacts: referenceArtifacts,
8403
8287
  artifactComponents: shouldIncludeArtifactComponents ? this.artifactComponents : [],
8404
- hasGraphArtifactComponents,
8288
+ hasAgentArtifactComponents,
8405
8289
  isThinkingPreparation,
8406
8290
  hasTransferRelations: (this.config.transferRelations?.length ?? 0) > 0,
8407
8291
  hasDelegateRelations: (this.config.delegateRelations?.length ?? 0) > 0
@@ -8418,7 +8302,7 @@ var Agent = class {
8418
8302
  execute: async ({ artifactId, toolCallId }) => {
8419
8303
  logger18.info({ artifactId, toolCallId }, "get_artifact_full executed");
8420
8304
  const streamRequestId = this.getStreamRequestId();
8421
- const artifactService = graphSessionManager.getArtifactService(streamRequestId);
8305
+ const artifactService = agentSessionManager.getArtifactService(streamRequestId);
8422
8306
  if (!artifactService) {
8423
8307
  throw new Error(`ArtifactService not found for session ${streamRequestId}`);
8424
8308
  }
@@ -8452,7 +8336,7 @@ var Agent = class {
8452
8336
  // Provide a default tool set that is always available to the agent.
8453
8337
  async getDefaultTools(streamRequestId) {
8454
8338
  const defaultTools = {};
8455
- if (await this.graphHasArtifactComponents()) {
8339
+ if (await this.agentHasArtifactComponents()) {
8456
8340
  defaultTools.get_reference_artifact = this.getArtifactTools();
8457
8341
  }
8458
8342
  const hasStructuredOutput = this.config.dataComponents && this.config.dataComponents.length > 0;
@@ -8680,20 +8564,20 @@ var Agent = class {
8680
8564
  return result;
8681
8565
  }
8682
8566
  }
8683
- // Check if any agents in the graph have artifact components
8684
- async graphHasArtifactComponents() {
8567
+ // Check if any agents in the agent have artifact components
8568
+ async agentHasArtifactComponents() {
8685
8569
  try {
8686
- return await agentsCore.graphHasArtifactComponents(dbClient_default)({
8570
+ return await agentsCore.agentHasArtifactComponents(dbClient_default)({
8687
8571
  scopes: {
8688
8572
  tenantId: this.config.tenantId,
8689
8573
  projectId: this.config.projectId,
8690
- graphId: this.config.graphId
8574
+ agentId: this.config.agentId
8691
8575
  }
8692
8576
  });
8693
8577
  } catch (error) {
8694
8578
  logger18.error(
8695
- { error, graphId: this.config.graphId },
8696
- "Failed to check graph artifact components"
8579
+ { error, agentId: this.config.agentId },
8580
+ "Failed to check agent artifact components"
8697
8581
  );
8698
8582
  return false;
8699
8583
  }
@@ -8825,7 +8709,7 @@ var Agent = class {
8825
8709
  const last = steps.at(-1);
8826
8710
  if (last && "text" in last && last.text) {
8827
8711
  try {
8828
- await graphSessionManager.recordEvent(
8712
+ await agentSessionManager.recordEvent(
8829
8713
  this.getStreamRequestId(),
8830
8714
  "agent_reasoning",
8831
8715
  this.config.id,
@@ -8837,8 +8721,14 @@ var Agent = class {
8837
8721
  logger18.debug({ error }, "Failed to track agent reasoning");
8838
8722
  }
8839
8723
  }
8840
- if (last && "toolCalls" in last && last.toolCalls) {
8841
- return last.toolCalls.some((tc) => tc.toolName.startsWith("transfer_to_"));
8724
+ if (steps.length >= 2) {
8725
+ const previousStep = steps[steps.length - 2];
8726
+ if (previousStep && "toolCalls" in previousStep && previousStep.toolCalls) {
8727
+ const hasTransferCall = previousStep.toolCalls.some((tc) => tc.toolName.startsWith("transfer_to_"));
8728
+ if (hasTransferCall && "toolResults" in previousStep && previousStep.toolResults) {
8729
+ return true;
8730
+ }
8731
+ }
8842
8732
  }
8843
8733
  return steps.length >= this.getMaxGenerationSteps();
8844
8734
  },
@@ -8939,7 +8829,7 @@ var Agent = class {
8939
8829
  const last = steps.at(-1);
8940
8830
  if (last && "text" in last && last.text) {
8941
8831
  try {
8942
- await graphSessionManager.recordEvent(
8832
+ await agentSessionManager.recordEvent(
8943
8833
  this.getStreamRequestId(),
8944
8834
  "agent_reasoning",
8945
8835
  this.config.id,
@@ -8951,10 +8841,16 @@ var Agent = class {
8951
8841
  logger18.debug({ error }, "Failed to track agent reasoning");
8952
8842
  }
8953
8843
  }
8954
- if (last && "toolCalls" in last && last.toolCalls) {
8955
- return last.toolCalls.some(
8956
- (tc) => tc.toolName.startsWith("transfer_to_") || tc.toolName === "thinking_complete"
8957
- );
8844
+ if (steps.length >= 2) {
8845
+ const previousStep = steps[steps.length - 2];
8846
+ if (previousStep && "toolCalls" in previousStep && previousStep.toolCalls) {
8847
+ const hasStopTool = previousStep.toolCalls.some(
8848
+ (tc) => tc.toolName.startsWith("transfer_to_") || tc.toolName === "thinking_complete"
8849
+ );
8850
+ if (hasStopTool && "toolResults" in previousStep && previousStep.toolResults) {
8851
+ return true;
8852
+ }
8853
+ }
8958
8854
  }
8959
8855
  return steps.length >= this.getMaxGenerationSteps();
8960
8856
  },
@@ -9220,7 +9116,7 @@ ${output}${structureHintsFormatted}`;
9220
9116
  };
9221
9117
  if (streamRequestId) {
9222
9118
  const generationType = response.object ? "object_generation" : "text_generation";
9223
- graphSessionManager.recordEvent(streamRequestId, "agent_generate", this.config.id, {
9119
+ agentSessionManager.recordEvent(streamRequestId, "agent_generate", this.config.id, {
9224
9120
  parts: (formattedContent?.parts || []).map((part) => ({
9225
9121
  type: part.kind === "text" ? "text" : part.kind === "data" ? "tool_result" : "text",
9226
9122
  content: part.text || JSON.stringify(part.data)
@@ -9260,11 +9156,11 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
9260
9156
  dataComponents,
9261
9157
  artifactComponents
9262
9158
  ] = await Promise.all([
9263
- agentsCore.getRelatedAgentsForGraph(dbClient_default)({
9159
+ agentsCore.getRelatedAgentsForAgent(dbClient_default)({
9264
9160
  scopes: {
9265
9161
  tenantId: config.tenantId,
9266
9162
  projectId: config.projectId,
9267
- graphId: config.graphId
9163
+ agentId: config.agentId
9268
9164
  },
9269
9165
  subAgentId: config.subAgentId
9270
9166
  }),
@@ -9272,7 +9168,7 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
9272
9168
  scopes: {
9273
9169
  tenantId: config.tenantId,
9274
9170
  projectId: config.projectId,
9275
- graphId: config.graphId,
9171
+ agentId: config.agentId,
9276
9172
  subAgentId: config.subAgentId
9277
9173
  }
9278
9174
  }),
@@ -9280,7 +9176,7 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
9280
9176
  scopes: {
9281
9177
  tenantId: config.tenantId,
9282
9178
  projectId: config.projectId,
9283
- graphId: config.graphId,
9179
+ agentId: config.agentId,
9284
9180
  subAgentId: config.subAgentId
9285
9181
  }
9286
9182
  }),
@@ -9288,7 +9184,7 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
9288
9184
  scopes: {
9289
9185
  tenantId: config.tenantId,
9290
9186
  projectId: config.projectId,
9291
- graphId: config.graphId,
9187
+ agentId: config.agentId,
9292
9188
  subAgentId: config.subAgentId
9293
9189
  }
9294
9190
  })
@@ -9301,16 +9197,16 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
9301
9197
  scopes: {
9302
9198
  tenantId: config.tenantId,
9303
9199
  projectId: config.projectId,
9304
- graphId: config.graphId
9200
+ agentId: config.agentId
9305
9201
  },
9306
9202
  subAgentId: relation.id
9307
9203
  });
9308
9204
  if (relatedAgent) {
9309
- const relatedAgentRelations = await agentsCore.getRelatedAgentsForGraph(dbClient_default)({
9205
+ const relatedAgentRelations = await agentsCore.getRelatedAgentsForAgent(dbClient_default)({
9310
9206
  scopes: {
9311
9207
  tenantId: config.tenantId,
9312
9208
  projectId: config.projectId,
9313
- graphId: config.graphId
9209
+ agentId: config.agentId
9314
9210
  },
9315
9211
  subAgentId: relation.id
9316
9212
  });
@@ -9340,7 +9236,7 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
9340
9236
  id: config.subAgentId,
9341
9237
  tenantId: config.tenantId,
9342
9238
  projectId: config.projectId,
9343
- graphId: config.graphId,
9239
+ agentId: config.agentId,
9344
9240
  baseUrl: config.baseUrl,
9345
9241
  apiKey: config.apiKey,
9346
9242
  name: config.name,
@@ -9352,7 +9248,7 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
9352
9248
  id: relation.id,
9353
9249
  tenantId: config.tenantId,
9354
9250
  projectId: config.projectId,
9355
- graphId: config.graphId,
9251
+ agentId: config.agentId,
9356
9252
  baseUrl: config.baseUrl,
9357
9253
  apiKey: config.apiKey,
9358
9254
  name: relation.name,
@@ -9368,7 +9264,7 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
9368
9264
  id: relation.id,
9369
9265
  tenantId: config.tenantId,
9370
9266
  projectId: config.projectId,
9371
- graphId: config.graphId,
9267
+ agentId: config.agentId,
9372
9268
  name: relation.name,
9373
9269
  description: relation.description,
9374
9270
  agentPrompt: "",
@@ -9384,7 +9280,7 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
9384
9280
  id: relation.id,
9385
9281
  tenantId: config.tenantId,
9386
9282
  projectId: config.projectId,
9387
- graphId: config.graphId,
9283
+ agentId: config.agentId,
9388
9284
  baseUrl: config.baseUrl,
9389
9285
  apiKey: config.apiKey,
9390
9286
  name: relation.name,
@@ -9419,7 +9315,7 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
9419
9315
  );
9420
9316
  const artifactStreamRequestId = task.context?.metadata?.streamRequestId;
9421
9317
  if (artifactStreamRequestId && artifactComponents.length > 0) {
9422
- graphSessionManager.updateArtifactComponents(artifactStreamRequestId, artifactComponents);
9318
+ agentSessionManager.updateArtifactComponents(artifactStreamRequestId, artifactComponents);
9423
9319
  }
9424
9320
  let contextId = task.context?.conversationId;
9425
9321
  if (!contextId || contextId === "default" || contextId === "") {
@@ -9447,7 +9343,7 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
9447
9343
  "Delegated agent - streaming disabled"
9448
9344
  );
9449
9345
  if (streamRequestId && config.tenantId && config.projectId) {
9450
- toolSessionManager.ensureGraphSession(
9346
+ toolSessionManager.ensureAgentSession(
9451
9347
  streamRequestId,
9452
9348
  config.tenantId,
9453
9349
  config.projectId,
@@ -9479,17 +9375,42 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
9479
9375
  const toolResult = allToolResults.find(
9480
9376
  (result) => result.toolCallId === toolCall.toolCallId
9481
9377
  );
9378
+ logger19.info({
9379
+ toolCallName: toolCall.toolName,
9380
+ toolCallId: toolCall.toolCallId,
9381
+ hasToolResult: !!toolResult,
9382
+ toolResultOutput: toolResult?.output,
9383
+ toolResultKeys: toolResult?.output ? Object.keys(toolResult.output) : []
9384
+ }, "[DEBUG] Transfer tool result found");
9482
9385
  const isValidTransferResult = (output) => {
9483
- 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");
9386
+ return typeof output === "object" && output !== null && "type" in output && "targetSubAgentId" in output && output.type === "transfer" && typeof output.targetSubAgentId === "string";
9484
9387
  };
9485
9388
  const responseText = response.text || (response.object ? JSON.stringify(response.object) : "");
9486
9389
  const transferReason = responseText || allThoughts[allThoughts.length - 1]?.text || "Agent requested transfer. No reason provided.";
9487
9390
  if (toolResult?.output && isValidTransferResult(toolResult.output)) {
9488
9391
  const transferResult = toolResult.output;
9392
+ logger19.info({
9393
+ validationPassed: true,
9394
+ transferResult,
9395
+ targetSubAgentId: transferResult.targetSubAgentId,
9396
+ fromSubAgentId: transferResult.fromSubAgentId
9397
+ }, "[DEBUG] Transfer validation passed, extracted data");
9398
+ const artifactData = {
9399
+ type: "transfer",
9400
+ targetSubAgentId: transferResult.targetSubAgentId,
9401
+ fromSubAgentId: transferResult.fromSubAgentId,
9402
+ task_id: task.id,
9403
+ reason: transferReason,
9404
+ original_message: userMessage
9405
+ };
9406
+ logger19.info({
9407
+ artifactData,
9408
+ artifactDataKeys: Object.keys(artifactData)
9409
+ }, "[DEBUG] Artifact data being returned");
9489
9410
  return {
9490
9411
  status: {
9491
9412
  state: agentsCore.TaskState.Completed,
9492
- message: `Transfer requested to ${transferResult.target}`
9413
+ message: `Transfer requested to ${transferResult.targetSubAgentId}`
9493
9414
  },
9494
9415
  artifacts: [
9495
9416
  {
@@ -9497,18 +9418,19 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
9497
9418
  parts: [
9498
9419
  {
9499
9420
  kind: "data",
9500
- data: {
9501
- type: "transfer",
9502
- target: transferResult.target,
9503
- task_id: task.id,
9504
- reason: transferReason,
9505
- original_message: userMessage
9506
- }
9421
+ data: artifactData
9507
9422
  }
9508
9423
  ]
9509
9424
  }
9510
9425
  ]
9511
9426
  };
9427
+ } else {
9428
+ logger19.warn({
9429
+ hasToolResult: !!toolResult,
9430
+ hasOutput: !!toolResult?.output,
9431
+ validationPassed: false,
9432
+ output: toolResult?.output
9433
+ }, "[DEBUG] Transfer validation FAILED");
9512
9434
  }
9513
9435
  }
9514
9436
  }
@@ -9540,129 +9462,172 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
9540
9462
  };
9541
9463
  };
9542
9464
  var createTaskHandlerConfig = async (params) => {
9543
- const agent = await agentsCore.getSubAgentById(dbClient_default)({
9465
+ const subAgent = await agentsCore.getSubAgentById(dbClient_default)({
9544
9466
  scopes: {
9545
9467
  tenantId: params.tenantId,
9546
9468
  projectId: params.projectId,
9547
- graphId: params.graphId
9469
+ agentId: params.agentId
9548
9470
  },
9549
9471
  subAgentId: params.subAgentId
9550
9472
  });
9551
- const agentGraph = await agentsCore.getAgentGraphById(dbClient_default)({
9473
+ const agent = await agentsCore.getAgentById(dbClient_default)({
9552
9474
  scopes: {
9553
9475
  tenantId: params.tenantId,
9554
9476
  projectId: params.projectId,
9555
- graphId: params.graphId
9477
+ agentId: params.agentId
9556
9478
  }
9557
9479
  });
9558
- if (!agent) {
9480
+ if (!subAgent) {
9559
9481
  throw new Error(`Agent not found: ${params.subAgentId}`);
9560
9482
  }
9561
- const effectiveModels = await resolveModelConfig(params.graphId, agent);
9562
- const effectiveConversationHistoryConfig = agent.conversationHistoryConfig || { mode: "full" };
9483
+ const effectiveModels = await resolveModelConfig(params.agentId, subAgent);
9484
+ const effectiveConversationHistoryConfig = subAgent.conversationHistoryConfig || { mode: "full" };
9563
9485
  return {
9564
9486
  tenantId: params.tenantId,
9565
9487
  projectId: params.projectId,
9566
- graphId: params.graphId,
9488
+ agentId: params.agentId,
9567
9489
  subAgentId: params.subAgentId,
9568
9490
  agentSchema: {
9569
- id: agent.id,
9570
- name: agent.name,
9571
- description: agent.description,
9572
- prompt: agent.prompt,
9491
+ id: subAgent.id,
9492
+ name: subAgent.name,
9493
+ description: subAgent.description,
9494
+ prompt: subAgent.prompt,
9573
9495
  models: effectiveModels,
9574
9496
  conversationHistoryConfig: effectiveConversationHistoryConfig || null,
9575
- stopWhen: agent.stopWhen || null,
9576
- createdAt: agent.createdAt,
9577
- updatedAt: agent.updatedAt
9497
+ stopWhen: subAgent.stopWhen || null,
9498
+ createdAt: subAgent.createdAt,
9499
+ updatedAt: subAgent.updatedAt
9578
9500
  },
9579
9501
  baseUrl: params.baseUrl,
9580
9502
  apiKey: params.apiKey,
9581
- name: agent.name,
9582
- description: agent.description,
9503
+ name: subAgent.name,
9504
+ description: subAgent.description,
9583
9505
  conversationHistoryConfig: effectiveConversationHistoryConfig,
9584
- contextConfigId: agentGraph?.contextConfigId || void 0
9506
+ contextConfigId: agent?.contextConfigId || void 0
9585
9507
  };
9586
9508
  };
9587
9509
 
9588
- // src/data/agentGraph.ts
9510
+ // src/data/agents.ts
9589
9511
  init_dbClient();
9590
- async function hydrateGraph({
9591
- dbGraph,
9512
+ function createAgentCard({
9513
+ dbAgent,
9514
+ baseUrl
9515
+ }) {
9516
+ const description = dbAgent.description || "AI Agent";
9517
+ return {
9518
+ name: dbAgent.name,
9519
+ description,
9520
+ url: baseUrl ? `${baseUrl}/a2a` : "",
9521
+ version: "1.0.0",
9522
+ capabilities: {
9523
+ streaming: true,
9524
+ // Enable streaming for A2A compliance
9525
+ pushNotifications: false,
9526
+ stateTransitionHistory: false
9527
+ },
9528
+ defaultInputModes: ["text", "text/plain"],
9529
+ defaultOutputModes: ["text", "text/plain"],
9530
+ skills: [],
9531
+ // Add provider info if available
9532
+ ...baseUrl && {
9533
+ provider: {
9534
+ organization: "Inkeep",
9535
+ url: baseUrl
9536
+ }
9537
+ }
9538
+ };
9539
+ }
9540
+ function generateDescriptionWithTransfers(baseDescription, internalRelations, externalRelations) {
9541
+ const transfers = [
9542
+ ...internalRelations.filter((rel) => rel.relationType === "transfer"),
9543
+ ...externalRelations.filter((rel) => rel.relationType === "transfer")
9544
+ ];
9545
+ const delegates = [
9546
+ ...internalRelations.filter((rel) => rel.relationType === "delegate"),
9547
+ ...externalRelations.filter((rel) => rel.relationType === "delegate")
9548
+ ];
9549
+ if (transfers.length === 0 && delegates.length === 0) {
9550
+ return baseDescription;
9551
+ }
9552
+ let enhancedDescription = baseDescription;
9553
+ if (transfers.length > 0) {
9554
+ const transferList = transfers.map((rel) => {
9555
+ const name = rel.externalAgent?.name || rel.name;
9556
+ const desc = rel.externalAgent?.description || rel.description || "";
9557
+ return `- ${name}: ${desc}`;
9558
+ }).join("\n");
9559
+ enhancedDescription += `
9560
+
9561
+ Can transfer to:
9562
+ ${transferList}`;
9563
+ }
9564
+ if (delegates.length > 0) {
9565
+ const delegateList = delegates.map((rel) => {
9566
+ const name = rel.externalAgent?.name || rel.name;
9567
+ const desc = rel.externalAgent?.description || rel.description || "";
9568
+ return `- ${name}: ${desc}`;
9569
+ }).join("\n");
9570
+ enhancedDescription += `
9571
+
9572
+ Can delegate to:
9573
+ ${delegateList}`;
9574
+ }
9575
+ return enhancedDescription;
9576
+ }
9577
+ async function hydrateAgent({
9578
+ dbAgent,
9579
+ agentId,
9592
9580
  baseUrl,
9593
- apiKey
9581
+ apiKey,
9582
+ credentialStoreRegistry
9594
9583
  }) {
9595
9584
  try {
9596
- if (!dbGraph.defaultSubAgentId) {
9597
- throw new Error(`Graph ${dbGraph.id} does not have a default agent configured`);
9598
- }
9599
- const defaultSubAgent = await agentsCore.getSubAgentById(dbClient_default)({
9600
- scopes: {
9601
- tenantId: dbGraph.tenantId,
9602
- projectId: dbGraph.projectId,
9603
- graphId: dbGraph.id
9604
- },
9605
- subAgentId: dbGraph.defaultSubAgentId
9606
- });
9607
- if (!defaultSubAgent) {
9608
- throw new Error(
9609
- `Default agent ${dbGraph.defaultSubAgentId} not found for graph ${dbGraph.id}`
9610
- );
9611
- }
9612
9585
  const taskHandlerConfig = await createTaskHandlerConfig({
9613
- tenantId: dbGraph.tenantId,
9614
- projectId: dbGraph.projectId,
9615
- graphId: dbGraph.id,
9616
- subAgentId: dbGraph.defaultSubAgentId,
9586
+ tenantId: dbAgent.tenantId,
9587
+ projectId: dbAgent.projectId,
9588
+ agentId,
9589
+ subAgentId: dbAgent.id,
9617
9590
  baseUrl,
9618
9591
  apiKey
9619
9592
  });
9620
- const taskHandler = createTaskHandler(taskHandlerConfig);
9621
- const agentCard = {
9622
- name: dbGraph.name,
9623
- description: dbGraph.description || `Agent graph: ${dbGraph.name}`,
9624
- url: baseUrl ? `${baseUrl}/a2a` : "",
9625
- version: "1.0.0",
9626
- capabilities: {
9627
- streaming: true,
9628
- // Enable streaming for A2A compliance
9629
- pushNotifications: false,
9630
- stateTransitionHistory: false
9631
- },
9632
- defaultInputModes: ["text", "text/plain"],
9633
- defaultOutputModes: ["text", "text/plain"],
9634
- skills: [],
9635
- // TODO: Could aggregate skills from all agents in the graph
9636
- // Add provider info if available
9637
- ...baseUrl && {
9638
- provider: {
9639
- organization: "Inkeep",
9640
- url: baseUrl
9641
- }
9642
- }
9643
- };
9593
+ const taskHandler = createTaskHandler(taskHandlerConfig, credentialStoreRegistry);
9594
+ const agentCard = createAgentCard({
9595
+ dbAgent,
9596
+ baseUrl
9597
+ });
9644
9598
  return {
9645
- subAgentId: dbGraph.id,
9646
- // Use graph ID as agent ID for A2A purposes
9647
- tenantId: dbGraph.tenantId,
9648
- projectId: dbGraph.projectId,
9649
- graphId: dbGraph.id,
9599
+ subAgentId: dbAgent.id,
9600
+ tenantId: dbAgent.tenantId,
9601
+ projectId: dbAgent.projectId,
9602
+ agentId,
9650
9603
  agentCard,
9651
9604
  taskHandler
9652
9605
  };
9653
9606
  } catch (error) {
9654
- console.error(`\u274C Failed to hydrate graph ${dbGraph.id}:`, error);
9607
+ console.error(`\u274C Failed to hydrate agent ${dbAgent.id}:`, error);
9655
9608
  throw error;
9656
9609
  }
9657
9610
  }
9658
- async function getRegisteredGraph(executionContext) {
9659
- const { tenantId, projectId, graphId, baseUrl, apiKey } = executionContext;
9660
- const dbGraph = await agentsCore.getAgentGraphById(dbClient_default)({ scopes: { tenantId, projectId, graphId } });
9661
- if (!dbGraph) {
9611
+ async function getRegisteredAgent(executionContext, credentialStoreRegistry) {
9612
+ const { tenantId, projectId, agentId, subAgentId, baseUrl, apiKey } = executionContext;
9613
+ if (!subAgentId) {
9614
+ throw new Error("Agent ID is required");
9615
+ }
9616
+ const dbAgent = await agentsCore.getSubAgentById(dbClient_default)({
9617
+ scopes: { tenantId, projectId, agentId },
9618
+ subAgentId
9619
+ });
9620
+ if (!dbAgent) {
9662
9621
  return null;
9663
9622
  }
9664
9623
  const agentFrameworkBaseUrl = `${baseUrl}/agents`;
9665
- return hydrateGraph({ dbGraph, baseUrl: agentFrameworkBaseUrl, apiKey });
9624
+ return hydrateAgent({
9625
+ dbAgent,
9626
+ agentId,
9627
+ baseUrl: agentFrameworkBaseUrl,
9628
+ credentialStoreRegistry,
9629
+ apiKey
9630
+ });
9666
9631
  }
9667
9632
 
9668
9633
  // src/routes/agents.ts
@@ -9716,7 +9681,7 @@ app.openapi(
9716
9681
  "OpenTelemetry headers: well-known agent.json"
9717
9682
  );
9718
9683
  const executionContext = agentsCore.getRequestExecutionContext(c);
9719
- const { tenantId, projectId, graphId, subAgentId } = executionContext;
9684
+ const { tenantId, projectId, agentId, subAgentId } = executionContext;
9720
9685
  console.dir("executionContext", executionContext);
9721
9686
  if (subAgentId) {
9722
9687
  logger20.info(
@@ -9724,7 +9689,7 @@ app.openapi(
9724
9689
  message: "getRegisteredAgent (agent-level)",
9725
9690
  tenantId,
9726
9691
  projectId,
9727
- graphId,
9692
+ agentId,
9728
9693
  subAgentId
9729
9694
  },
9730
9695
  "agent-level well-known agent.json"
@@ -9742,21 +9707,21 @@ app.openapi(
9742
9707
  } else {
9743
9708
  logger20.info(
9744
9709
  {
9745
- message: "getRegisteredGraph (graph-level)",
9710
+ message: "getRegisteredAgent (agent-level)",
9746
9711
  tenantId,
9747
9712
  projectId,
9748
- graphId
9713
+ agentId
9749
9714
  },
9750
- "graph-level well-known agent.json"
9715
+ "agent-level well-known agent.json"
9751
9716
  );
9752
- const graph = await getRegisteredGraph(executionContext);
9753
- if (!graph) {
9717
+ const agent = await getRegisteredAgent(executionContext);
9718
+ if (!agent) {
9754
9719
  throw agentsCore.createApiError({
9755
9720
  code: "not_found",
9756
- message: "Graph not found"
9721
+ message: "Agent not found"
9757
9722
  });
9758
9723
  }
9759
- return c.json(graph.agentCard);
9724
+ return c.json(agent.agentCard);
9760
9725
  }
9761
9726
  }
9762
9727
  );
@@ -9775,14 +9740,14 @@ app.post("/a2a", async (c) => {
9775
9740
  "OpenTelemetry headers: a2a"
9776
9741
  );
9777
9742
  const executionContext = agentsCore.getRequestExecutionContext(c);
9778
- const { tenantId, projectId, graphId, subAgentId } = executionContext;
9743
+ const { tenantId, projectId, agentId, subAgentId } = executionContext;
9779
9744
  if (subAgentId) {
9780
9745
  logger20.info(
9781
9746
  {
9782
9747
  message: "a2a (agent-level)",
9783
9748
  tenantId,
9784
9749
  projectId,
9785
- graphId,
9750
+ agentId,
9786
9751
  subAgentId
9787
9752
  },
9788
9753
  "agent-level a2a endpoint"
@@ -9803,17 +9768,17 @@ app.post("/a2a", async (c) => {
9803
9768
  } else {
9804
9769
  logger20.info(
9805
9770
  {
9806
- message: "a2a (graph-level)",
9771
+ message: "a2a (agent-level)",
9807
9772
  tenantId,
9808
9773
  projectId,
9809
- graphId
9774
+ agentId
9810
9775
  },
9811
- "graph-level a2a endpoint"
9776
+ "agent-level a2a endpoint"
9812
9777
  );
9813
- const graph = await agentsCore.getAgentGraphWithDefaultSubAgent(dbClient_default)({
9814
- scopes: { tenantId, projectId, graphId }
9778
+ const agent = await agentsCore.getAgentWithDefaultSubAgent(dbClient_default)({
9779
+ scopes: { tenantId, projectId, agentId }
9815
9780
  });
9816
- if (!graph) {
9781
+ if (!agent) {
9817
9782
  return c.json(
9818
9783
  {
9819
9784
  jsonrpc: "2.0",
@@ -9823,17 +9788,17 @@ app.post("/a2a", async (c) => {
9823
9788
  404
9824
9789
  );
9825
9790
  }
9826
- if (!graph.defaultSubAgentId) {
9791
+ if (!agent.defaultSubAgentId) {
9827
9792
  return c.json(
9828
9793
  {
9829
9794
  jsonrpc: "2.0",
9830
- error: { code: -32004, message: "Graph does not have a default agent configured" },
9795
+ error: { code: -32004, message: "Agent does not have a default agent configured" },
9831
9796
  id: null
9832
9797
  },
9833
9798
  400
9834
9799
  );
9835
9800
  }
9836
- executionContext.subAgentId = graph.defaultSubAgentId;
9801
+ executionContext.subAgentId = agent.defaultSubAgentId;
9837
9802
  const credentialStores = c.get("credentialStores");
9838
9803
  const defaultSubAgent = await getRegisteredAgent(executionContext, credentialStores);
9839
9804
  if (!defaultSubAgent) {
@@ -9857,6 +9822,55 @@ init_dbClient();
9857
9822
  // src/a2a/transfer.ts
9858
9823
  init_dbClient();
9859
9824
  init_logger();
9825
+ function isTransferTask(result) {
9826
+ console.log(
9827
+ "[isTransferTask] Checking result:",
9828
+ JSON.stringify(
9829
+ {
9830
+ hasArtifacts: "artifacts" in result,
9831
+ artifactsLength: result.kind === "task" ? result.artifacts?.length : 0,
9832
+ firstArtifactParts: result.kind === "task" ? result.artifacts?.[0]?.parts?.length : 0,
9833
+ allParts: result.kind === "task" ? result.artifacts?.[0]?.parts?.map((p, i) => ({
9834
+ index: i,
9835
+ kind: p.kind,
9836
+ hasData: !!(p.kind === "data" && p.data),
9837
+ dataType: p.kind === "data" ? p.data?.type : void 0,
9838
+ dataKeys: p.kind === "data" ? Object.keys(p.data) : []
9839
+ })) : []
9840
+ },
9841
+ null,
9842
+ 2
9843
+ )
9844
+ );
9845
+ if (!("artifacts" in result) || !result.artifacts) {
9846
+ console.log("[isTransferTask] No artifacts found");
9847
+ return false;
9848
+ }
9849
+ const hasTransfer = result.artifacts.some(
9850
+ (artifact) => artifact.parts.some((part) => {
9851
+ if (part.kind !== "data" || !part.data) return false;
9852
+ const isTransfer = typeof part.data === "object" && "type" in part.data && part.data.type === "transfer";
9853
+ if (isTransfer) {
9854
+ console.log("[isTransferTask] Found transfer data:", JSON.stringify(part.data, null, 2));
9855
+ }
9856
+ return isTransfer;
9857
+ })
9858
+ );
9859
+ console.log("[isTransferTask] Result:", hasTransfer);
9860
+ return hasTransfer;
9861
+ }
9862
+ function extractTransferData(task) {
9863
+ for (const artifact of task.artifacts) {
9864
+ for (const part of artifact.parts) {
9865
+ if (part.kind === "data" && part.data?.type === "transfer") {
9866
+ return part.data;
9867
+ }
9868
+ }
9869
+ }
9870
+ return null;
9871
+ }
9872
+
9873
+ // src/a2a/transfer.ts
9860
9874
  var logger21 = agentsCore.getLogger("Transfer");
9861
9875
  async function executeTransfer({
9862
9876
  tenantId,
@@ -9864,19 +9878,25 @@ async function executeTransfer({
9864
9878
  projectId,
9865
9879
  targetSubAgentId
9866
9880
  }) {
9867
- logger21.info({ targetAgent: targetSubAgentId }, "Executing transfer to agent");
9868
- await agentsCore.setActiveAgentForThread(dbClient_default)({
9869
- scopes: { tenantId, projectId },
9881
+ logger21.info({
9882
+ targetAgent: targetSubAgentId,
9870
9883
  threadId,
9871
- subAgentId: targetSubAgentId
9872
- });
9884
+ tenantId,
9885
+ projectId
9886
+ }, "Executing transfer - calling setActiveAgentForThread");
9887
+ try {
9888
+ await agentsCore.setActiveAgentForThread(dbClient_default)({
9889
+ scopes: { tenantId, projectId },
9890
+ threadId,
9891
+ subAgentId: targetSubAgentId
9892
+ });
9893
+ logger21.info({ targetAgent: targetSubAgentId, threadId }, "Successfully updated active_sub_agent_id in database");
9894
+ } catch (error) {
9895
+ logger21.error({ error, targetAgent: targetSubAgentId, threadId }, "Failed to update active_sub_agent_id");
9896
+ throw error;
9897
+ }
9873
9898
  return { success: true, targetSubAgentId };
9874
9899
  }
9875
- function isTransferResponse(result) {
9876
- return result?.artifacts.some(
9877
- (artifact) => artifact.parts.some((part) => part.kind === "data" && part.data?.type === "transfer")
9878
- );
9879
- }
9880
9900
 
9881
9901
  // src/handlers/executionHandler.ts
9882
9902
  init_dbClient();
@@ -10480,24 +10500,26 @@ var ExecutionHandler = class {
10480
10500
  sseHelper,
10481
10501
  emitOperations
10482
10502
  } = params;
10483
- const { tenantId, projectId, graphId, apiKey, baseUrl } = executionContext;
10503
+ const { tenantId, projectId, agentId, apiKey, baseUrl } = executionContext;
10484
10504
  registerStreamHelper(requestId2, sseHelper);
10485
- graphSessionManager.createSession(requestId2, graphId, tenantId, projectId, conversationId);
10505
+ agentSessionManager.createSession(requestId2, agentId, tenantId, projectId, conversationId);
10486
10506
  if (emitOperations) {
10487
- graphSessionManager.enableEmitOperations(requestId2);
10507
+ agentSessionManager.enableEmitOperations(requestId2);
10488
10508
  }
10489
10509
  logger22.info(
10490
- { sessionId: requestId2, graphId, conversationId, emitOperations },
10491
- "Created GraphSession for message execution"
10510
+ { sessionId: requestId2, agentId, conversationId, emitOperations },
10511
+ "Created AgentSession for message execution"
10492
10512
  );
10493
- let graphConfig = null;
10513
+ let agentConfig = null;
10494
10514
  try {
10495
- graphConfig = await agentsCore.getFullGraph(dbClient_default)({ scopes: { tenantId, projectId, graphId } });
10496
- if (graphConfig?.statusUpdates && graphConfig.statusUpdates.enabled !== false) {
10497
- graphSessionManager.initializeStatusUpdates(
10515
+ agentConfig = await agentsCore.getFullAgent(dbClient_default)({
10516
+ scopes: { tenantId, projectId, agentId }
10517
+ });
10518
+ if (agentConfig?.statusUpdates && agentConfig.statusUpdates.enabled !== false) {
10519
+ agentSessionManager.initializeStatusUpdates(
10498
10520
  requestId2,
10499
- graphConfig.statusUpdates,
10500
- graphConfig.models?.summarizer
10521
+ agentConfig.statusUpdates,
10522
+ agentConfig.models?.summarizer
10501
10523
  );
10502
10524
  }
10503
10525
  } catch (error) {
@@ -10513,9 +10535,9 @@ var ExecutionHandler = class {
10513
10535
  let iterations = 0;
10514
10536
  let errorCount = 0;
10515
10537
  let task = null;
10516
- let fromAgentId;
10538
+ let fromSubAgentId;
10517
10539
  try {
10518
- await sseHelper.writeOperation(agentInitializingOp(requestId2, graphId));
10540
+ await sseHelper.writeOperation(agentInitializingOp(requestId2, agentId));
10519
10541
  const taskId = `task_${conversationId}-${requestId2}`;
10520
10542
  logger22.info(
10521
10543
  { taskId, currentAgentId, conversationId, requestId: requestId2 },
@@ -10526,7 +10548,7 @@ var ExecutionHandler = class {
10526
10548
  id: taskId,
10527
10549
  tenantId,
10528
10550
  projectId,
10529
- graphId,
10551
+ agentId,
10530
10552
  subAgentId: currentAgentId,
10531
10553
  contextId: conversationId,
10532
10554
  status: "pending",
@@ -10534,11 +10556,11 @@ var ExecutionHandler = class {
10534
10556
  conversation_id: conversationId,
10535
10557
  message_id: requestId2,
10536
10558
  stream_request_id: requestId2,
10537
- // This also serves as the GraphSession ID
10559
+ // This also serves as the AgentSession ID
10538
10560
  created_at: (/* @__PURE__ */ new Date()).toISOString(),
10539
10561
  updated_at: (/* @__PURE__ */ new Date()).toISOString(),
10540
- root_agent_id: initialAgentId,
10541
- agent_id: currentAgentId
10562
+ root_sub_agent_id: initialAgentId,
10563
+ sub_agent_id: currentAgentId
10542
10564
  }
10543
10565
  });
10544
10566
  logger22.info(
@@ -10575,6 +10597,7 @@ var ExecutionHandler = class {
10575
10597
  timestamp: (/* @__PURE__ */ new Date()).toISOString(),
10576
10598
  executionType: "create_initial_task",
10577
10599
  conversationId,
10600
+ agentId,
10578
10601
  requestId: requestId2,
10579
10602
  currentAgentId,
10580
10603
  taskId: Array.isArray(task) ? task[0]?.id : task?.id,
@@ -10585,12 +10608,12 @@ var ExecutionHandler = class {
10585
10608
  );
10586
10609
  if (Array.isArray(task)) task = task[0];
10587
10610
  let currentMessage = userMessage;
10588
- const maxTransfers = graphConfig?.stopWhen?.transferCountIs ?? 10;
10611
+ const maxTransfers = agentConfig?.stopWhen?.transferCountIs ?? 10;
10589
10612
  while (iterations < maxTransfers) {
10590
10613
  iterations++;
10591
10614
  logger22.info(
10592
- { iterations, currentAgentId, graphId, conversationId, fromAgentId },
10593
- `Execution loop iteration ${iterations} with agent ${currentAgentId}, transfer from: ${fromAgentId || "none"}`
10615
+ { iterations, currentAgentId, agentId, conversationId, fromSubAgentId },
10616
+ `Execution loop iteration ${iterations} with agent ${currentAgentId}, transfer from: ${fromSubAgentId || "none"}`
10594
10617
  );
10595
10618
  const activeAgent = await agentsCore.getActiveAgentForConversation(dbClient_default)({
10596
10619
  scopes: { tenantId, projectId },
@@ -10607,17 +10630,17 @@ var ExecutionHandler = class {
10607
10630
  Authorization: `Bearer ${apiKey}`,
10608
10631
  "x-inkeep-tenant-id": tenantId,
10609
10632
  "x-inkeep-project-id": projectId,
10610
- "x-inkeep-graph-id": graphId,
10611
- "x-inkeep-agent-id": currentAgentId
10633
+ "x-inkeep-agent-id": agentId,
10634
+ "x-inkeep-sub-agent-id": currentAgentId
10612
10635
  }
10613
10636
  });
10614
10637
  let messageResponse = null;
10615
10638
  const messageMetadata = {
10616
10639
  stream_request_id: requestId2
10617
- // This also serves as the GraphSession ID
10640
+ // This also serves as the AgentSession ID
10618
10641
  };
10619
- if (fromAgentId) {
10620
- messageMetadata.fromAgentId = fromAgentId;
10642
+ if (fromSubAgentId) {
10643
+ messageMetadata.fromSubAgentId = fromSubAgentId;
10621
10644
  }
10622
10645
  messageResponse = await a2aClient.sendMessage({
10623
10646
  message: {
@@ -10661,17 +10684,28 @@ var ExecutionHandler = class {
10661
10684
  }
10662
10685
  });
10663
10686
  }
10664
- graphSessionManager.endSession(requestId2);
10687
+ agentSessionManager.endSession(requestId2);
10665
10688
  unregisterStreamHelper(requestId2);
10666
10689
  return { success: false, error: errorMessage2, iterations };
10667
10690
  }
10668
10691
  continue;
10669
10692
  }
10670
- if (isTransferResponse(messageResponse.result)) {
10671
- const transferResponse = messageResponse.result;
10672
- const targetSubAgentId = transferResponse.artifacts?.[0]?.parts?.[0]?.data?.targetSubAgentId;
10673
- const transferReason = transferResponse.artifacts?.[0]?.parts?.[1]?.text;
10674
- logger22.info({ targetSubAgentId, transferReason }, "transfer response");
10693
+ if (isTransferTask(messageResponse.result)) {
10694
+ const transferData = extractTransferData(messageResponse.result);
10695
+ if (!transferData) {
10696
+ logger22.error(
10697
+ { result: messageResponse.result },
10698
+ "Transfer detected but no transfer data found"
10699
+ );
10700
+ continue;
10701
+ }
10702
+ const { targetSubAgentId, fromSubAgentId: transferFromAgent } = transferData;
10703
+ const firstArtifact = messageResponse.result.artifacts[0];
10704
+ const transferReason = firstArtifact?.parts[1]?.kind === "text" ? firstArtifact.parts[1].text : "Transfer initiated";
10705
+ logger22.info(
10706
+ { targetSubAgentId, transferReason, transferFromAgent },
10707
+ "Transfer response"
10708
+ );
10675
10709
  currentMessage = `<transfer_context> ${transferReason} </transfer_context>`;
10676
10710
  const { success, targetSubAgentId: newAgentId } = await executeTransfer({
10677
10711
  projectId,
@@ -10680,15 +10714,15 @@ var ExecutionHandler = class {
10680
10714
  targetSubAgentId
10681
10715
  });
10682
10716
  if (success) {
10683
- fromAgentId = currentAgentId;
10717
+ fromSubAgentId = currentAgentId;
10684
10718
  currentAgentId = newAgentId;
10685
10719
  logger22.info(
10686
10720
  {
10687
- transferFrom: fromAgentId,
10721
+ transferFrom: fromSubAgentId,
10688
10722
  transferTo: currentAgentId,
10689
10723
  reason: transferReason
10690
10724
  },
10691
- "Transfer executed, tracking fromAgentId for next iteration"
10725
+ "Transfer executed, tracking fromSubAgentId for next iteration"
10692
10726
  );
10693
10727
  }
10694
10728
  continue;
@@ -10710,10 +10744,10 @@ var ExecutionHandler = class {
10710
10744
  );
10711
10745
  }
10712
10746
  if (responseParts && responseParts.length > 0) {
10713
- const graphSessionData = graphSessionManager.getSession(requestId2);
10714
- if (graphSessionData) {
10715
- const sessionSummary = graphSessionData.getSummary();
10716
- logger22.info(sessionSummary, "GraphSession data after completion");
10747
+ const agentSessionData = agentSessionManager.getSession(requestId2);
10748
+ if (agentSessionData) {
10749
+ const sessionSummary = agentSessionData.getSummary();
10750
+ logger22.info(sessionSummary, "AgentSession data after completion");
10717
10751
  }
10718
10752
  let textContent = "";
10719
10753
  for (const part of responseParts) {
@@ -10772,8 +10806,8 @@ var ExecutionHandler = class {
10772
10806
  );
10773
10807
  await sseHelper.writeOperation(completionOp(currentAgentId, iterations));
10774
10808
  await sseHelper.complete();
10775
- logger22.info({}, "Ending GraphSession and cleaning up");
10776
- graphSessionManager.endSession(requestId2);
10809
+ logger22.info({}, "Ending AgentSession and cleaning up");
10810
+ agentSessionManager.endSession(requestId2);
10777
10811
  logger22.info({}, "Cleaning up streamHelper");
10778
10812
  unregisterStreamHelper(requestId2);
10779
10813
  let response;
@@ -10813,7 +10847,7 @@ var ExecutionHandler = class {
10813
10847
  }
10814
10848
  });
10815
10849
  }
10816
- graphSessionManager.endSession(requestId2);
10850
+ agentSessionManager.endSession(requestId2);
10817
10851
  unregisterStreamHelper(requestId2);
10818
10852
  return { success: false, error: errorMessage2, iterations };
10819
10853
  }
@@ -10834,7 +10868,7 @@ var ExecutionHandler = class {
10834
10868
  }
10835
10869
  });
10836
10870
  }
10837
- graphSessionManager.endSession(requestId2);
10871
+ agentSessionManager.endSession(requestId2);
10838
10872
  unregisterStreamHelper(requestId2);
10839
10873
  return { success: false, error: errorMessage, iterations };
10840
10874
  } catch (error) {
@@ -10856,7 +10890,7 @@ var ExecutionHandler = class {
10856
10890
  }
10857
10891
  });
10858
10892
  }
10859
- graphSessionManager.endSession(requestId2);
10893
+ agentSessionManager.endSession(requestId2);
10860
10894
  unregisterStreamHelper(requestId2);
10861
10895
  return { success: false, error: errorMessage, iterations };
10862
10896
  }
@@ -10872,7 +10906,7 @@ var chatCompletionsRoute = zodOpenapi.createRoute({
10872
10906
  path: "/completions",
10873
10907
  tags: ["chat"],
10874
10908
  summary: "Create chat completion",
10875
- description: "Creates a new chat completion with streaming SSE response using the configured agent graph",
10909
+ description: "Creates a new chat completion with streaming SSE response using the configured agent",
10876
10910
  security: [{ bearerAuth: [] }],
10877
10911
  request: {
10878
10912
  body: {
@@ -10947,7 +10981,7 @@ var chatCompletionsRoute = zodOpenapi.createRoute({
10947
10981
  }
10948
10982
  },
10949
10983
  404: {
10950
- description: "Agent graph or agent not found",
10984
+ description: "Agent or agent not found",
10951
10985
  content: {
10952
10986
  "application/json": {
10953
10987
  schema: z6.z.object({
@@ -10994,48 +11028,48 @@ app2.openapi(chatCompletionsRoute, async (c) => {
10994
11028
  );
10995
11029
  try {
10996
11030
  const executionContext = agentsCore.getRequestExecutionContext(c);
10997
- const { tenantId, projectId, graphId } = executionContext;
11031
+ const { tenantId, projectId, agentId } = executionContext;
10998
11032
  agentsCore.getLogger("chat").debug(
10999
11033
  {
11000
11034
  tenantId,
11001
- graphId
11035
+ agentId
11002
11036
  },
11003
11037
  "Extracted chat parameters from API key context"
11004
11038
  );
11005
11039
  const body = c.get("requestBody") || {};
11006
11040
  const conversationId = body.conversationId || agentsCore.getConversationId();
11007
- const fullGraph = await agentsCore.getFullGraph(dbClient_default)({
11008
- scopes: { tenantId, projectId, graphId }
11041
+ const fullAgent = await agentsCore.getFullAgent(dbClient_default)({
11042
+ scopes: { tenantId, projectId, agentId }
11009
11043
  });
11010
- let agentGraph;
11044
+ let agent;
11011
11045
  let defaultSubAgentId;
11012
- if (fullGraph) {
11013
- agentGraph = {
11014
- id: fullGraph.id,
11015
- name: fullGraph.name,
11046
+ if (fullAgent) {
11047
+ agent = {
11048
+ id: fullAgent.id,
11049
+ name: fullAgent.name,
11016
11050
  tenantId,
11017
11051
  projectId,
11018
- defaultSubAgentId: fullGraph.defaultSubAgentId
11052
+ defaultSubAgentId: fullAgent.defaultSubAgentId
11019
11053
  };
11020
- const agentKeys = Object.keys(fullGraph.subAgents || {});
11054
+ const agentKeys = Object.keys(fullAgent.subAgents || {});
11021
11055
  const firstAgentId = agentKeys.length > 0 ? agentKeys[0] : "";
11022
- defaultSubAgentId = fullGraph.defaultSubAgentId || firstAgentId;
11056
+ defaultSubAgentId = fullAgent.defaultSubAgentId || firstAgentId;
11023
11057
  } else {
11024
- agentGraph = await agentsCore.getAgentGraphWithDefaultSubAgent(dbClient_default)({
11025
- scopes: { tenantId, projectId, graphId }
11058
+ agent = await agentsCore.getAgentWithDefaultSubAgent(dbClient_default)({
11059
+ scopes: { tenantId, projectId, agentId }
11026
11060
  });
11027
- if (!agentGraph) {
11061
+ if (!agent) {
11028
11062
  throw agentsCore.createApiError({
11029
11063
  code: "not_found",
11030
- message: "Agent graph not found"
11064
+ message: "Agent not found"
11031
11065
  });
11032
11066
  }
11033
- defaultSubAgentId = agentGraph.defaultSubAgentId || "";
11067
+ defaultSubAgentId = agent.defaultSubAgentId || "";
11034
11068
  }
11035
11069
  if (!defaultSubAgentId) {
11036
11070
  throw agentsCore.createApiError({
11037
11071
  code: "not_found",
11038
- message: "No default agent found in graph"
11072
+ message: "No default agent found in agent"
11039
11073
  });
11040
11074
  }
11041
11075
  await agentsCore.createOrGetConversation(dbClient_default)({
@@ -11057,7 +11091,7 @@ app2.openapi(chatCompletionsRoute, async (c) => {
11057
11091
  }
11058
11092
  const subAgentId = activeAgent?.activeSubAgentId || defaultSubAgentId;
11059
11093
  const agentInfo = await agentsCore.getSubAgentById(dbClient_default)({
11060
- scopes: { tenantId, projectId, graphId },
11094
+ scopes: { tenantId, projectId, agentId },
11061
11095
  subAgentId
11062
11096
  });
11063
11097
  if (!agentInfo) {
@@ -11071,7 +11105,7 @@ app2.openapi(chatCompletionsRoute, async (c) => {
11071
11105
  await agentsCore.handleContextResolution({
11072
11106
  tenantId,
11073
11107
  projectId,
11074
- graphId,
11108
+ agentId,
11075
11109
  conversationId,
11076
11110
  headers: validatedContext,
11077
11111
  dbClient: dbClient_default,
@@ -11081,11 +11115,11 @@ app2.openapi(chatCompletionsRoute, async (c) => {
11081
11115
  {
11082
11116
  tenantId,
11083
11117
  projectId,
11084
- graphId,
11118
+ agentId,
11085
11119
  conversationId,
11086
11120
  defaultSubAgentId,
11087
11121
  activeSubAgentId: activeAgent?.activeSubAgentId || "none",
11088
- hasContextConfig: !!agentGraph.contextConfigId,
11122
+ hasContextConfig: !!agent.contextConfigId,
11089
11123
  hasHeaders: !!body.headers,
11090
11124
  hasValidatedContext: !!validatedContext,
11091
11125
  validatedContextKeys: Object.keys(validatedContext)
@@ -11254,8 +11288,8 @@ app3.use("/chat", agentsCore.contextValidationMiddleware(dbClient_default));
11254
11288
  app3.openapi(chatDataStreamRoute, async (c) => {
11255
11289
  try {
11256
11290
  const executionContext = agentsCore.getRequestExecutionContext(c);
11257
- const { tenantId, projectId, graphId } = executionContext;
11258
- agentsCore.loggerFactory.getLogger("chatDataStream").debug({ tenantId, projectId, graphId }, "Extracted chatDataStream parameters");
11291
+ const { tenantId, projectId, agentId } = executionContext;
11292
+ agentsCore.loggerFactory.getLogger("chatDataStream").debug({ tenantId, projectId, agentId }, "Extracted chatDataStream parameters");
11259
11293
  const body = c.get("requestBody") || {};
11260
11294
  const conversationId = body.conversationId || agentsCore.getConversationId();
11261
11295
  const activeSpan = api.trace.getActiveSpan();
@@ -11263,25 +11297,25 @@ app3.openapi(chatDataStreamRoute, async (c) => {
11263
11297
  activeSpan.setAttributes({
11264
11298
  "conversation.id": conversationId,
11265
11299
  "tenant.id": tenantId,
11266
- "graph.id": graphId,
11300
+ "agent.id": agentId,
11267
11301
  "project.id": projectId
11268
11302
  });
11269
11303
  }
11270
- const agentGraph = await agentsCore.getAgentGraphWithDefaultSubAgent(dbClient_default)({
11271
- scopes: { tenantId, projectId, graphId }
11304
+ const agent = await agentsCore.getAgentWithDefaultSubAgent(dbClient_default)({
11305
+ scopes: { tenantId, projectId, agentId }
11272
11306
  });
11273
- if (!agentGraph) {
11307
+ if (!agent) {
11274
11308
  throw agentsCore.createApiError({
11275
11309
  code: "not_found",
11276
- message: "Agent graph not found"
11310
+ message: "Agent not found"
11277
11311
  });
11278
11312
  }
11279
- const defaultSubAgentId = agentGraph.defaultSubAgentId;
11280
- const graphName = agentGraph.name;
11313
+ const defaultSubAgentId = agent.defaultSubAgentId;
11314
+ const agentName = agent.name;
11281
11315
  if (!defaultSubAgentId) {
11282
11316
  throw agentsCore.createApiError({
11283
11317
  code: "bad_request",
11284
- message: "Graph does not have a default agent configured"
11318
+ message: "Agent does not have a default agent configured"
11285
11319
  });
11286
11320
  }
11287
11321
  const activeAgent = await agentsCore.getActiveAgentForConversation(dbClient_default)({
@@ -11297,7 +11331,7 @@ app3.openapi(chatDataStreamRoute, async (c) => {
11297
11331
  }
11298
11332
  const subAgentId = activeAgent?.activeSubAgentId || defaultSubAgentId;
11299
11333
  const agentInfo = await agentsCore.getSubAgentById(dbClient_default)({
11300
- scopes: { tenantId, projectId, graphId },
11334
+ scopes: { tenantId, projectId, agentId },
11301
11335
  subAgentId
11302
11336
  });
11303
11337
  if (!agentInfo) {
@@ -11311,7 +11345,7 @@ app3.openapi(chatDataStreamRoute, async (c) => {
11311
11345
  await agentsCore.handleContextResolution({
11312
11346
  tenantId,
11313
11347
  projectId,
11314
- graphId,
11348
+ agentId,
11315
11349
  conversationId,
11316
11350
  headers: validatedContext,
11317
11351
  dbClient: dbClient_default,
@@ -11325,7 +11359,7 @@ app3.openapi(chatDataStreamRoute, async (c) => {
11325
11359
  messageSpan.setAttributes({
11326
11360
  "message.timestamp": (/* @__PURE__ */ new Date()).toISOString(),
11327
11361
  "message.content": userText,
11328
- "graph.name": graphName
11362
+ "agent.name": agentName
11329
11363
  });
11330
11364
  }
11331
11365
  await agentsCore.createMessage(dbClient_default)({
@@ -11465,7 +11499,7 @@ var spoofTransportInitialization = async (transport, req, sessionId, mcpProtocol
11465
11499
  logger25.warn({ sessionId, error: spoofError }, "Spoof initialization failed, continuing anyway");
11466
11500
  }
11467
11501
  };
11468
- var validateSession = async (req, res, body, tenantId, projectId, graphId) => {
11502
+ var validateSession = async (req, res, body, tenantId, projectId, agentId) => {
11469
11503
  const sessionId = req.headers["mcp-session-id"];
11470
11504
  logger25.info({ sessionId }, "Received MCP session ID");
11471
11505
  if (!sessionId) {
@@ -11500,12 +11534,12 @@ var validateSession = async (req, res, body, tenantId, projectId, graphId) => {
11500
11534
  sessionId,
11501
11535
  conversationFound: !!conversation,
11502
11536
  sessionType: conversation?.metadata?.sessionData?.sessionType,
11503
- storedGraphId: conversation?.metadata?.sessionData?.graphId,
11504
- requestGraphId: graphId
11537
+ storedAgentId: conversation?.metadata?.sessionData?.agentId,
11538
+ requestAgentId: agentId
11505
11539
  },
11506
11540
  "Conversation lookup result"
11507
11541
  );
11508
- if (!conversation || conversation.metadata?.sessionData?.sessionType !== "mcp" || conversation.metadata?.sessionData?.graphId !== graphId) {
11542
+ if (!conversation || conversation.metadata?.sessionData?.sessionType !== "mcp" || conversation.metadata?.sessionData?.agentId !== agentId) {
11509
11543
  logger25.info(
11510
11544
  { sessionId, conversationId: conversation?.id },
11511
11545
  "MCP session not found or invalid"
@@ -11524,13 +11558,13 @@ var validateSession = async (req, res, body, tenantId, projectId, graphId) => {
11524
11558
  }
11525
11559
  return conversation;
11526
11560
  };
11527
- var setupTracing = (conversationId, tenantId, graphId) => {
11561
+ var setupTracing = (conversationId, tenantId, agentId) => {
11528
11562
  const activeSpan = api.trace.getActiveSpan();
11529
11563
  if (activeSpan) {
11530
11564
  activeSpan.setAttributes({
11531
11565
  "conversation.id": conversationId,
11532
11566
  "tenant.id": tenantId,
11533
- "graph.id": graphId
11567
+ "agent.id": agentId
11534
11568
  });
11535
11569
  }
11536
11570
  };
@@ -11592,13 +11626,13 @@ var executeAgentQuery = async (executionContext, conversationId, query, defaultS
11592
11626
  };
11593
11627
  };
11594
11628
  var getServer = async (headers, executionContext, conversationId, credentialStores) => {
11595
- const { tenantId, projectId, graphId } = executionContext;
11596
- setupTracing(conversationId, tenantId, graphId);
11597
- const agentGraph = await agentsCore.getAgentGraphWithDefaultSubAgent(dbClient_default)({
11598
- scopes: { tenantId, projectId, graphId }
11629
+ const { tenantId, projectId, agentId } = executionContext;
11630
+ setupTracing(conversationId, tenantId, agentId);
11631
+ const agent = await agentsCore.getAgentWithDefaultSubAgent(dbClient_default)({
11632
+ scopes: { tenantId, projectId, agentId }
11599
11633
  });
11600
- if (!agentGraph) {
11601
- throw new Error("Agent graph not found");
11634
+ if (!agent) {
11635
+ throw new Error("Agent not found");
11602
11636
  }
11603
11637
  const server = new mcp_js.McpServer(
11604
11638
  {
@@ -11609,26 +11643,26 @@ var getServer = async (headers, executionContext, conversationId, credentialStor
11609
11643
  );
11610
11644
  server.tool(
11611
11645
  "send-query-to-agent",
11612
- `Send a query to the ${agentGraph.name} agent. The agent has the following description: ${agentGraph.description}`,
11646
+ `Send a query to the ${agent.name} agent. The agent has the following description: ${agent.description}`,
11613
11647
  {
11614
11648
  query: createMCPSchema(v3.z.string().describe("The query to send to the agent"))
11615
11649
  },
11616
11650
  async ({ query }) => {
11617
11651
  try {
11618
- if (!agentGraph.defaultSubAgentId) {
11652
+ if (!agent.defaultSubAgentId) {
11619
11653
  return {
11620
11654
  content: [
11621
11655
  {
11622
11656
  type: "text",
11623
- text: `Graph does not have a default agent configured`
11657
+ text: `Agent does not have a default agent configured`
11624
11658
  }
11625
11659
  ],
11626
11660
  isError: true
11627
11661
  };
11628
11662
  }
11629
- const defaultSubAgentId = agentGraph.defaultSubAgentId;
11663
+ const defaultSubAgentId = agent.defaultSubAgentId;
11630
11664
  const agentInfo = await agentsCore.getSubAgentById(dbClient_default)({
11631
- scopes: { tenantId, projectId, graphId },
11665
+ scopes: { tenantId, projectId, agentId },
11632
11666
  subAgentId: defaultSubAgentId
11633
11667
  });
11634
11668
  if (!agentInfo) {
@@ -11645,7 +11679,7 @@ var getServer = async (headers, executionContext, conversationId, credentialStor
11645
11679
  const resolvedContext = await agentsCore.handleContextResolution({
11646
11680
  tenantId,
11647
11681
  projectId,
11648
- graphId,
11682
+ agentId,
11649
11683
  conversationId,
11650
11684
  headers,
11651
11685
  dbClient: dbClient_default,
@@ -11655,9 +11689,9 @@ var getServer = async (headers, executionContext, conversationId, credentialStor
11655
11689
  {
11656
11690
  tenantId,
11657
11691
  projectId,
11658
- graphId,
11692
+ agentId,
11659
11693
  conversationId,
11660
- hasContextConfig: !!agentGraph.contextConfigId,
11694
+ hasContextConfig: !!agent.contextConfigId,
11661
11695
  hasHeaders: !!headers,
11662
11696
  hasValidatedContext: !!resolvedContext
11663
11697
  },
@@ -11690,8 +11724,8 @@ app4.use("/", async (c, next) => {
11690
11724
  var validateRequestParameters = (c) => {
11691
11725
  try {
11692
11726
  const executionContext = agentsCore.getRequestExecutionContext(c);
11693
- const { tenantId, projectId, graphId } = executionContext;
11694
- agentsCore.getLogger("mcp").debug({ tenantId, projectId, graphId }, "Extracted MCP entity parameters");
11727
+ const { tenantId, projectId, agentId } = executionContext;
11728
+ agentsCore.getLogger("mcp").debug({ tenantId, projectId, agentId }, "Extracted MCP entity parameters");
11695
11729
  return { valid: true, executionContext };
11696
11730
  } catch (error) {
11697
11731
  agentsCore.getLogger("chat").warn(
@@ -11712,27 +11746,27 @@ var validateRequestParameters = (c) => {
11712
11746
  }
11713
11747
  };
11714
11748
  var handleInitializationRequest = async (body, executionContext, validatedContext, req, res, c, credentialStores) => {
11715
- const { tenantId, projectId, graphId } = executionContext;
11749
+ const { tenantId, projectId, agentId } = executionContext;
11716
11750
  logger25.info({ body }, "Received initialization request");
11717
11751
  const sessionId = agentsCore.getConversationId();
11718
- const agentGraph = await agentsCore.getAgentGraphWithDefaultSubAgent(dbClient_default)({
11719
- scopes: { tenantId, projectId, graphId }
11752
+ const agent = await agentsCore.getAgentWithDefaultSubAgent(dbClient_default)({
11753
+ scopes: { tenantId, projectId, agentId }
11720
11754
  });
11721
- if (!agentGraph) {
11755
+ if (!agent) {
11722
11756
  return c.json(
11723
11757
  {
11724
11758
  jsonrpc: "2.0",
11725
- error: { code: -32001, message: "Agent graph not found" },
11759
+ error: { code: -32001, message: "Agent not found" },
11726
11760
  id: body.id || null
11727
11761
  },
11728
11762
  { status: 404 }
11729
11763
  );
11730
11764
  }
11731
- if (!agentGraph.defaultSubAgentId) {
11765
+ if (!agent.defaultSubAgentId) {
11732
11766
  return c.json(
11733
11767
  {
11734
11768
  jsonrpc: "2.0",
11735
- error: { code: -32001, message: "Graph does not have a default agent configured" },
11769
+ error: { code: -32001, message: "Agent does not have a default agent configured" },
11736
11770
  id: body.id || null
11737
11771
  },
11738
11772
  { status: 400 }
@@ -11742,10 +11776,10 @@ var handleInitializationRequest = async (body, executionContext, validatedContex
11742
11776
  id: sessionId,
11743
11777
  tenantId,
11744
11778
  projectId,
11745
- activeSubAgentId: agentGraph.defaultSubAgentId,
11779
+ activeSubAgentId: agent.defaultSubAgentId,
11746
11780
  metadata: {
11747
11781
  sessionData: {
11748
- graphId,
11782
+ agentId,
11749
11783
  sessionType: "mcp",
11750
11784
  mcpProtocolVersion: c.req.header("mcp-protocol-version"),
11751
11785
  initialized: false
@@ -11777,8 +11811,8 @@ var handleInitializationRequest = async (body, executionContext, validatedContex
11777
11811
  return fetchToNode.toFetchResponse(res);
11778
11812
  };
11779
11813
  var handleExistingSessionRequest = async (body, executionContext, validatedContext, req, res, credentialStores) => {
11780
- const { tenantId, projectId, graphId } = executionContext;
11781
- const conversation = await validateSession(req, res, body, tenantId, projectId, graphId);
11814
+ const { tenantId, projectId, agentId } = executionContext;
11815
+ const conversation = await validateSession(req, res, body, tenantId, projectId, agentId);
11782
11816
  if (!conversation) {
11783
11817
  return fetchToNode.toFetchResponse(res);
11784
11818
  }
@@ -11854,7 +11888,7 @@ app4.openapi(
11854
11888
  description: "Unauthorized - API key authentication required"
11855
11889
  },
11856
11890
  404: {
11857
- description: "Not Found - Agent graph not found"
11891
+ description: "Not Found - Agent not found"
11858
11892
  },
11859
11893
  500: {
11860
11894
  description: "Internal Server Error"
@@ -12072,7 +12106,7 @@ function createExecutionHono(serverConfig, credentialStores) {
12072
12106
  logger26.debug({}, "Empty execution context");
12073
12107
  return next();
12074
12108
  }
12075
- const { tenantId, projectId, graphId } = executionContext;
12109
+ const { tenantId, projectId, agentId } = executionContext;
12076
12110
  let conversationId;
12077
12111
  const requestBody = c.get("requestBody") || {};
12078
12112
  if (requestBody) {
@@ -12083,7 +12117,7 @@ function createExecutionHono(serverConfig, credentialStores) {
12083
12117
  }
12084
12118
  const entries = Object.fromEntries(
12085
12119
  Object.entries({
12086
- "graph.id": graphId,
12120
+ "agent.id": agentId,
12087
12121
  "tenant.id": tenantId,
12088
12122
  "project.id": projectId,
12089
12123
  "conversation.id": conversationId