@inkeep/agents-run-api 0.18.1 → 0.19.1

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