@inkeep/agents-run-api 0.0.0-dev-20250919020857 → 0.0.0-dev-20250919052931

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.
Files changed (3) hide show
  1. package/dist/index.cjs +169 -107
  2. package/dist/index.js +166 -104
  3. package/package.json +2 -2
package/dist/index.cjs CHANGED
@@ -1226,7 +1226,7 @@ async function getRegisteredAgent(executionContext, credentialStoreRegistry) {
1226
1226
  throw new Error("Agent ID is required");
1227
1227
  }
1228
1228
  const dbAgent = await agentsCore.getAgentById(dbClient_default)({
1229
- scopes: { tenantId, projectId },
1229
+ scopes: { tenantId, projectId, graphId },
1230
1230
  agentId
1231
1231
  });
1232
1232
  if (!dbAgent) {
@@ -1245,6 +1245,41 @@ async function getRegisteredAgent(executionContext, credentialStoreRegistry) {
1245
1245
  // src/agents/generateTaskHandler.ts
1246
1246
  init_dbClient();
1247
1247
 
1248
+ // src/utils/model-resolver.ts
1249
+ init_dbClient();
1250
+ async function resolveModelConfig(graphId, agent) {
1251
+ if (agent.models?.base?.model) {
1252
+ return {
1253
+ base: agent.models.base,
1254
+ structuredOutput: agent.models.structuredOutput || agent.models.base,
1255
+ summarizer: agent.models.summarizer || agent.models.base
1256
+ };
1257
+ }
1258
+ const graph = await agentsCore.getAgentGraphById(dbClient_default)({
1259
+ scopes: { tenantId: agent.tenantId, projectId: agent.projectId, graphId }
1260
+ });
1261
+ if (graph?.models?.base?.model) {
1262
+ return {
1263
+ base: graph.models.base,
1264
+ structuredOutput: agent.models?.structuredOutput || graph.models.structuredOutput || graph.models.base,
1265
+ summarizer: agent.models?.summarizer || graph.models.summarizer || graph.models.base
1266
+ };
1267
+ }
1268
+ const project = await agentsCore.getProject(dbClient_default)({
1269
+ scopes: { tenantId: agent.tenantId, projectId: agent.projectId }
1270
+ });
1271
+ if (project?.models?.base?.model) {
1272
+ return {
1273
+ base: project.models.base,
1274
+ structuredOutput: agent.models?.structuredOutput || project.models.structuredOutput || project.models.base,
1275
+ summarizer: agent.models?.summarizer || project.models.summarizer || project.models.base
1276
+ };
1277
+ }
1278
+ throw new Error(
1279
+ "Base model configuration is required. Please configure models at the project level."
1280
+ );
1281
+ }
1282
+
1248
1283
  // src/agents/Agent.ts
1249
1284
  init_conversations();
1250
1285
  init_dbClient();
@@ -1408,6 +1443,9 @@ var _ModelFactory = class _ModelFactory {
1408
1443
  );
1409
1444
  }
1410
1445
  const modelSettings = config;
1446
+ if (!modelSettings.model) {
1447
+ throw new Error("Model configuration is required");
1448
+ }
1411
1449
  const modelString = modelSettings.model.trim();
1412
1450
  const { provider, modelName } = _ModelFactory.parseModelString(modelString);
1413
1451
  logger5.debug(
@@ -2078,6 +2116,9 @@ ${this.statusUpdateState?.config.prompt?.trim() || ""}`;
2078
2116
  }
2079
2117
  modelToUse = this.statusUpdateState.baseModel;
2080
2118
  }
2119
+ if (!modelToUse) {
2120
+ throw new Error("No model configuration available");
2121
+ }
2081
2122
  const model = ModelFactory.createModel(modelToUse);
2082
2123
  const { text } = await ai.generateText({
2083
2124
  model,
@@ -2212,6 +2253,9 @@ ${this.statusUpdateState?.config.prompt?.trim() || ""}`;
2212
2253
  }
2213
2254
  modelToUse = this.statusUpdateState.baseModel;
2214
2255
  }
2256
+ if (!modelToUse) {
2257
+ throw new Error("No model configuration available");
2258
+ }
2215
2259
  const model = ModelFactory.createModel(modelToUse);
2216
2260
  const { object } = await ai.generateObject({
2217
2261
  model,
@@ -2502,6 +2546,9 @@ Make it specific and relevant.`;
2502
2546
  }
2503
2547
  modelToUse = this.statusUpdateState.baseModel;
2504
2548
  }
2549
+ if (!modelToUse) {
2550
+ throw new Error("No model configuration available");
2551
+ }
2505
2552
  const model = ModelFactory.createModel(modelToUse);
2506
2553
  const schema = z5.z.object({
2507
2554
  name: z5.z.string().max(50).describe("Concise, descriptive name for the artifact"),
@@ -2783,6 +2830,7 @@ var _ArtifactParser = class _ArtifactParser {
2783
2830
  }
2784
2831
  for (let i = matches.length - 1; i >= 0; i--) {
2785
2832
  const match = matches[i];
2833
+ if (match.index === void 0) continue;
2786
2834
  const startIdx = match.index;
2787
2835
  const textAfterMatch = text.slice(startIdx);
2788
2836
  if (!textAfterMatch.includes("/>")) {
@@ -2850,6 +2898,7 @@ var _ArtifactParser = class _ArtifactParser {
2850
2898
  let lastIndex = 0;
2851
2899
  for (const match of matches) {
2852
2900
  const [fullMatch, artifactId, taskId] = match;
2901
+ if (match.index === void 0) continue;
2853
2902
  const matchStart = match.index;
2854
2903
  if (matchStart > lastIndex) {
2855
2904
  const textBefore = text.slice(lastIndex, matchStart);
@@ -4670,7 +4719,8 @@ function createDelegateToAgentTool({
4670
4719
  const externalAgent = await agentsCore.getExternalAgent(dbClient_default)({
4671
4720
  scopes: {
4672
4721
  tenantId,
4673
- projectId
4722
+ projectId,
4723
+ graphId
4674
4724
  },
4675
4725
  agentId: delegateConfig.config.id
4676
4726
  });
@@ -5559,8 +5609,12 @@ var Agent = class {
5559
5609
  async getMcpTool(tool4) {
5560
5610
  const credentialReferenceId = tool4.credentialReferenceId;
5561
5611
  const toolsForAgent = await agentsCore.getToolsForAgent(dbClient_default)({
5562
- scopes: { tenantId: this.config.tenantId, projectId: this.config.projectId },
5563
- agentId: this.config.id
5612
+ scopes: {
5613
+ tenantId: this.config.tenantId,
5614
+ projectId: this.config.projectId,
5615
+ graphId: this.config.graphId,
5616
+ agentId: this.config.id
5617
+ }
5564
5618
  });
5565
5619
  const selectedTools = toolsForAgent.data.find((t) => t.toolId === tool4.id)?.selectedTools || void 0;
5566
5620
  let serverConfig;
@@ -5707,9 +5761,9 @@ var Agent = class {
5707
5761
  const graphDefinition = await agentsCore.getFullGraphDefinition(dbClient_default)({
5708
5762
  scopes: {
5709
5763
  tenantId: this.config.tenantId,
5710
- projectId: this.config.projectId
5711
- },
5712
- graphId: this.config.graphId
5764
+ projectId: this.config.projectId,
5765
+ graphId: this.config.graphId
5766
+ }
5713
5767
  });
5714
5768
  return graphDefinition?.graphPrompt || void 0;
5715
5769
  } catch (error) {
@@ -5731,14 +5785,16 @@ var Agent = class {
5731
5785
  const graphDefinition = await agentsCore.getFullGraphDefinition(dbClient_default)({
5732
5786
  scopes: {
5733
5787
  tenantId: this.config.tenantId,
5734
- projectId: this.config.projectId
5735
- },
5736
- graphId: this.config.graphId
5788
+ projectId: this.config.projectId,
5789
+ graphId: this.config.graphId
5790
+ }
5737
5791
  });
5738
5792
  if (!graphDefinition) {
5739
5793
  return false;
5740
5794
  }
5741
- return !!(graphDefinition.artifactComponents && Object.keys(graphDefinition.artifactComponents).length > 0);
5795
+ return Object.values(graphDefinition.agents).some(
5796
+ (agent) => "artifactComponents" in agent && agent.artifactComponents && agent.artifactComponents.length > 0
5797
+ );
5742
5798
  } catch (error) {
5743
5799
  logger15.warn(
5744
5800
  {
@@ -5937,9 +5993,9 @@ Key requirements:
5937
5993
  return await agentsCore.graphHasArtifactComponents(dbClient_default)({
5938
5994
  scopes: {
5939
5995
  tenantId: this.config.tenantId,
5940
- projectId: this.config.projectId
5941
- },
5942
- graphId: this.config.graphId
5996
+ projectId: this.config.projectId,
5997
+ graphId: this.config.graphId
5998
+ }
5943
5999
  });
5944
6000
  } catch (error) {
5945
6001
  logger15.error(
@@ -6418,45 +6474,6 @@ ${output}`;
6418
6474
  }
6419
6475
  };
6420
6476
 
6421
- // src/utils/model-resolver.ts
6422
- init_dbClient();
6423
- async function resolveModelConfig(graphId, agent) {
6424
- if (agent.models?.base?.model) {
6425
- return {
6426
- base: agent.models.base,
6427
- structuredOutput: agent.models.structuredOutput || agent.models.base,
6428
- summarizer: agent.models.summarizer || agent.models.base
6429
- };
6430
- }
6431
- let graph = null;
6432
- if (graphId) {
6433
- graph = await agentsCore.getAgentGraph(dbClient_default)({
6434
- scopes: { tenantId: agent.tenantId, projectId: agent.projectId },
6435
- graphId
6436
- });
6437
- }
6438
- if (graph?.models?.base?.model) {
6439
- return {
6440
- base: graph.models.base,
6441
- structuredOutput: agent.models?.structuredOutput || graph.models.structuredOutput || graph.models.base,
6442
- summarizer: agent.models?.summarizer || graph.models.summarizer || graph.models.base
6443
- };
6444
- }
6445
- const project = await agentsCore.getProject(dbClient_default)({
6446
- scopes: { tenantId: agent.tenantId, projectId: agent.projectId }
6447
- });
6448
- if (project?.models?.base?.model) {
6449
- return {
6450
- base: project.models.base,
6451
- structuredOutput: agent.models?.structuredOutput || project.models.structuredOutput || project.models.base,
6452
- summarizer: agent.models?.summarizer || project.models.summarizer || project.models.base
6453
- };
6454
- }
6455
- throw new Error(
6456
- "Base model configuration is required. Please configure models at the project level."
6457
- );
6458
- }
6459
-
6460
6477
  // src/agents/generateTaskHandler.ts
6461
6478
  function parseEmbeddedJson(data) {
6462
6479
  return traverse__default.default(data).map(function(x) {
@@ -6491,31 +6508,34 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
6491
6508
  agentsCore.getRelatedAgentsForGraph(dbClient_default)({
6492
6509
  scopes: {
6493
6510
  tenantId: config.tenantId,
6494
- projectId: config.projectId
6511
+ projectId: config.projectId,
6512
+ graphId: config.graphId
6495
6513
  },
6496
- graphId: config.graphId,
6497
6514
  agentId: config.agentId
6498
6515
  }),
6499
6516
  agentsCore.getToolsForAgent(dbClient_default)({
6500
6517
  scopes: {
6501
6518
  tenantId: config.tenantId,
6502
- projectId: config.projectId
6503
- },
6504
- agentId: config.agentId
6519
+ projectId: config.projectId,
6520
+ graphId: config.graphId,
6521
+ agentId: config.agentId
6522
+ }
6505
6523
  }),
6506
6524
  agentsCore.getDataComponentsForAgent(dbClient_default)({
6507
6525
  scopes: {
6508
6526
  tenantId: config.tenantId,
6509
- projectId: config.projectId
6510
- },
6511
- agentId: config.agentId
6527
+ projectId: config.projectId,
6528
+ graphId: config.graphId,
6529
+ agentId: config.agentId
6530
+ }
6512
6531
  }),
6513
6532
  agentsCore.getArtifactComponentsForAgent(dbClient_default)({
6514
6533
  scopes: {
6515
6534
  tenantId: config.tenantId,
6516
- projectId: config.projectId
6517
- },
6518
- agentId: config.agentId
6535
+ projectId: config.projectId,
6536
+ graphId: config.graphId,
6537
+ agentId: config.agentId
6538
+ }
6519
6539
  })
6520
6540
  ]);
6521
6541
  logger16.info({ toolsForAgent, internalRelations, externalRelations }, "agent stuff");
@@ -6523,13 +6543,16 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
6523
6543
  internalRelations.map(async (relation) => {
6524
6544
  try {
6525
6545
  const relatedAgent = await agentsCore.getAgentById(dbClient_default)({
6526
- scopes: { tenantId: config.tenantId, projectId: config.projectId },
6546
+ scopes: {
6547
+ tenantId: config.tenantId,
6548
+ projectId: config.projectId,
6549
+ graphId: config.graphId
6550
+ },
6527
6551
  agentId: relation.id
6528
6552
  });
6529
6553
  if (relatedAgent) {
6530
6554
  const relatedAgentRelations = await agentsCore.getRelatedAgentsForGraph(dbClient_default)({
6531
- scopes: { tenantId: config.tenantId, projectId: config.projectId },
6532
- graphId: config.graphId,
6555
+ scopes: { tenantId: config.tenantId, projectId: config.projectId, graphId: config.graphId },
6533
6556
  agentId: relation.id
6534
6557
  });
6535
6558
  const enhancedDescription = generateDescriptionWithTransfers(
@@ -6752,16 +6775,17 @@ var createTaskHandlerConfig = async (params) => {
6752
6775
  const agent = await agentsCore.getAgentById(dbClient_default)({
6753
6776
  scopes: {
6754
6777
  tenantId: params.tenantId,
6755
- projectId: params.projectId
6778
+ projectId: params.projectId,
6779
+ graphId: params.graphId
6756
6780
  },
6757
6781
  agentId: params.agentId
6758
6782
  });
6759
- const agentGraph = await agentsCore.getAgentGraph(dbClient_default)({
6783
+ const agentGraph = await agentsCore.getAgentGraphById(dbClient_default)({
6760
6784
  scopes: {
6761
6785
  tenantId: params.tenantId,
6762
- projectId: params.projectId
6763
- },
6764
- graphId: params.graphId
6786
+ projectId: params.projectId,
6787
+ graphId: params.graphId
6788
+ }
6765
6789
  });
6766
6790
  if (!agent) {
6767
6791
  throw new Error(`Agent not found: ${params.agentId}`);
@@ -6801,10 +6825,14 @@ async function hydrateGraph({
6801
6825
  apiKey
6802
6826
  }) {
6803
6827
  try {
6828
+ if (!dbGraph.defaultAgentId) {
6829
+ throw new Error(`Graph ${dbGraph.id} does not have a default agent configured`);
6830
+ }
6804
6831
  const defaultAgent = await agentsCore.getAgentById(dbClient_default)({
6805
6832
  scopes: {
6806
6833
  tenantId: dbGraph.tenantId,
6807
- projectId: dbGraph.projectId
6834
+ projectId: dbGraph.projectId,
6835
+ graphId: dbGraph.id
6808
6836
  },
6809
6837
  agentId: dbGraph.defaultAgentId
6810
6838
  });
@@ -6859,7 +6887,7 @@ async function hydrateGraph({
6859
6887
  }
6860
6888
  async function getRegisteredGraph(executionContext) {
6861
6889
  const { tenantId, projectId, graphId, baseUrl, apiKey } = executionContext;
6862
- const dbGraph = await agentsCore.getAgentGraph(dbClient_default)({ scopes: { tenantId, projectId }, graphId });
6890
+ const dbGraph = await agentsCore.getAgentGraphById(dbClient_default)({ scopes: { tenantId, projectId, graphId } });
6863
6891
  if (!dbGraph) {
6864
6892
  return null;
6865
6893
  }
@@ -6918,6 +6946,7 @@ app.openapi(
6918
6946
  );
6919
6947
  const executionContext = agentsCore.getRequestExecutionContext(c);
6920
6948
  const { tenantId, projectId, graphId, agentId } = executionContext;
6949
+ console.dir("executionContext", executionContext);
6921
6950
  if (agentId) {
6922
6951
  logger17.info(
6923
6952
  {
@@ -7005,8 +7034,7 @@ app.post("/a2a", async (c) => {
7005
7034
  "graph-level a2a endpoint"
7006
7035
  );
7007
7036
  const graph = await agentsCore.getAgentGraphWithDefaultAgent(dbClient_default)({
7008
- scopes: { tenantId, projectId },
7009
- graphId
7037
+ scopes: { tenantId, projectId, graphId }
7010
7038
  });
7011
7039
  if (!graph) {
7012
7040
  return c.json(
@@ -7018,6 +7046,16 @@ app.post("/a2a", async (c) => {
7018
7046
  404
7019
7047
  );
7020
7048
  }
7049
+ if (!graph.defaultAgentId) {
7050
+ return c.json(
7051
+ {
7052
+ jsonrpc: "2.0",
7053
+ error: { code: -32004, message: "Graph does not have a default agent configured" },
7054
+ id: null
7055
+ },
7056
+ 400
7057
+ );
7058
+ }
7021
7059
  executionContext.agentId = graph.defaultAgentId;
7022
7060
  const credentialStores = c.get("credentialStores");
7023
7061
  const defaultAgent = await getRegisteredAgent(executionContext, credentialStores);
@@ -7061,6 +7099,9 @@ function isTransferResponse(result) {
7061
7099
  (artifact) => artifact.parts.some((part) => part.kind === "data" && part.data?.type === "transfer")
7062
7100
  );
7063
7101
  }
7102
+
7103
+ // src/handlers/executionHandler.ts
7104
+ init_dbClient();
7064
7105
  var SSEStreamHelper = class {
7065
7106
  constructor(stream2, requestId2, timestamp) {
7066
7107
  this.stream = stream2;
@@ -7374,8 +7415,8 @@ var _VercelDataStreamHelper = class _VercelDataStreamHelper {
7374
7415
  });
7375
7416
  } else {
7376
7417
  this.writer.write({
7377
- type: "error",
7378
- ...error
7418
+ ...error,
7419
+ type: "error"
7379
7420
  });
7380
7421
  }
7381
7422
  }
@@ -7630,7 +7671,6 @@ function createMCPStreamHelper() {
7630
7671
  }
7631
7672
 
7632
7673
  // src/handlers/executionHandler.ts
7633
- init_dbClient();
7634
7674
  var logger19 = agentsCore.getLogger("ExecutionHandler");
7635
7675
  var ExecutionHandler = class {
7636
7676
  constructor() {
@@ -7659,7 +7699,7 @@ var ExecutionHandler = class {
7659
7699
  logger19.info({ sessionId: requestId2, graphId }, "Created GraphSession for message execution");
7660
7700
  let graphConfig = null;
7661
7701
  try {
7662
- graphConfig = await agentsCore.getFullGraph(dbClient_default)({ scopes: { tenantId, projectId }, graphId });
7702
+ graphConfig = await agentsCore.getFullGraph(dbClient_default)({ scopes: { tenantId, projectId, graphId } });
7663
7703
  if (graphConfig?.statusUpdates && graphConfig.statusUpdates.enabled !== false) {
7664
7704
  graphSessionManager.initializeStatusUpdates(
7665
7705
  requestId2,
@@ -8156,8 +8196,7 @@ app2.openapi(chatCompletionsRoute, async (c) => {
8156
8196
  const body = c.get("requestBody") || {};
8157
8197
  const conversationId = body.conversationId || nanoid.nanoid();
8158
8198
  const fullGraph = await agentsCore.getFullGraph(dbClient_default)({
8159
- scopes: { tenantId, projectId },
8160
- graphId
8199
+ scopes: { tenantId, projectId, graphId }
8161
8200
  });
8162
8201
  let agentGraph;
8163
8202
  let defaultAgentId;
@@ -8174,8 +8213,7 @@ app2.openapi(chatCompletionsRoute, async (c) => {
8174
8213
  defaultAgentId = fullGraph.defaultAgentId || firstAgentId;
8175
8214
  } else {
8176
8215
  agentGraph = await agentsCore.getAgentGraphWithDefaultAgent(dbClient_default)({
8177
- scopes: { tenantId, projectId },
8178
- graphId
8216
+ scopes: { tenantId, projectId, graphId }
8179
8217
  });
8180
8218
  if (!agentGraph) {
8181
8219
  return c.json({ error: "Agent graph not found" }, 404);
@@ -8204,7 +8242,7 @@ app2.openapi(chatCompletionsRoute, async (c) => {
8204
8242
  }
8205
8243
  const agentId = activeAgent?.activeAgentId || defaultAgentId;
8206
8244
  const agentInfo = await agentsCore.getAgentById(dbClient_default)({
8207
- scopes: { tenantId, projectId },
8245
+ scopes: { tenantId, projectId, graphId },
8208
8246
  agentId
8209
8247
  });
8210
8248
  if (!agentInfo) {
@@ -8212,18 +8250,19 @@ app2.openapi(chatCompletionsRoute, async (c) => {
8212
8250
  }
8213
8251
  const validatedContext = c.get("validatedContext") || body.requestContext || {};
8214
8252
  const credentialStores = c.get("credentialStores");
8215
- await agentsCore.handleContextResolution(
8253
+ await agentsCore.handleContextResolution({
8216
8254
  tenantId,
8217
8255
  projectId,
8218
- conversationId,
8219
8256
  graphId,
8220
- validatedContext,
8221
- dbClient_default,
8257
+ conversationId,
8258
+ requestContext: validatedContext,
8259
+ dbClient: dbClient_default,
8222
8260
  credentialStores
8223
- );
8261
+ });
8224
8262
  logger20.info(
8225
8263
  {
8226
8264
  tenantId,
8265
+ projectId,
8227
8266
  graphId,
8228
8267
  conversationId,
8229
8268
  defaultAgentId,
@@ -8366,6 +8405,7 @@ app3.openapi(chatDataStreamRoute, async (c) => {
8366
8405
  try {
8367
8406
  const executionContext = agentsCore.getRequestExecutionContext(c);
8368
8407
  const { tenantId, projectId, graphId } = executionContext;
8408
+ agentsCore.loggerFactory.getLogger("chatDataStream").debug({ tenantId, projectId, graphId }, "Extracted chatDataStream parameters");
8369
8409
  const body = c.get("requestBody") || {};
8370
8410
  const conversationId = body.conversationId || nanoid.nanoid();
8371
8411
  const activeSpan = api.trace.getActiveSpan();
@@ -8378,14 +8418,16 @@ app3.openapi(chatDataStreamRoute, async (c) => {
8378
8418
  });
8379
8419
  }
8380
8420
  const agentGraph = await agentsCore.getAgentGraphWithDefaultAgent(dbClient_default)({
8381
- scopes: { tenantId, projectId },
8382
- graphId
8421
+ scopes: { tenantId, projectId, graphId }
8383
8422
  });
8384
8423
  if (!agentGraph) {
8385
8424
  return c.json({ error: "Agent graph not found" }, 404);
8386
8425
  }
8387
8426
  const defaultAgentId = agentGraph.defaultAgentId;
8388
8427
  const graphName = agentGraph.name;
8428
+ if (!defaultAgentId) {
8429
+ return c.json({ error: "Graph does not have a default agent configured" }, 400);
8430
+ }
8389
8431
  const activeAgent = await agentsCore.getActiveAgentForConversation(dbClient_default)({
8390
8432
  scopes: { tenantId, projectId },
8391
8433
  conversationId
@@ -8399,7 +8441,7 @@ app3.openapi(chatDataStreamRoute, async (c) => {
8399
8441
  }
8400
8442
  const agentId = activeAgent?.activeAgentId || defaultAgentId;
8401
8443
  const agentInfo = await agentsCore.getAgentById(dbClient_default)({
8402
- scopes: { tenantId, projectId },
8444
+ scopes: { tenantId, projectId, graphId },
8403
8445
  agentId
8404
8446
  });
8405
8447
  if (!agentInfo) {
@@ -8407,15 +8449,15 @@ app3.openapi(chatDataStreamRoute, async (c) => {
8407
8449
  }
8408
8450
  const validatedContext = c.get("validatedContext") || body.requestContext || {};
8409
8451
  const credentialStores = c.get("credentialStores");
8410
- await agentsCore.handleContextResolution(
8452
+ await agentsCore.handleContextResolution({
8411
8453
  tenantId,
8412
8454
  projectId,
8413
- conversationId,
8414
8455
  graphId,
8415
- validatedContext,
8416
- dbClient_default,
8456
+ conversationId,
8457
+ requestContext: validatedContext,
8458
+ dbClient: dbClient_default,
8417
8459
  credentialStores
8418
- );
8460
+ });
8419
8461
  const lastUserMessage = body.messages.filter((m) => m.role === "user").slice(-1)[0];
8420
8462
  const userText = typeof lastUserMessage?.content === "string" ? lastUserMessage.content : lastUserMessage?.parts?.map((p) => p.text).join("") || "";
8421
8463
  logger21.info({ userText, lastUserMessage }, "userText");
@@ -8687,8 +8729,7 @@ var getServer = async (requestContext, executionContext, conversationId, credent
8687
8729
  const { tenantId, projectId, graphId } = executionContext;
8688
8730
  setupTracing(conversationId, tenantId, graphId);
8689
8731
  const agentGraph = await agentsCore.getAgentGraphWithDefaultAgent(dbClient_default)({
8690
- scopes: { tenantId, projectId },
8691
- graphId
8732
+ scopes: { tenantId, projectId, graphId }
8692
8733
  });
8693
8734
  if (!agentGraph) {
8694
8735
  throw new Error("Agent graph not found");
@@ -8708,9 +8749,20 @@ var getServer = async (requestContext, executionContext, conversationId, credent
8708
8749
  },
8709
8750
  async ({ query }) => {
8710
8751
  try {
8752
+ if (!agentGraph.defaultAgentId) {
8753
+ return {
8754
+ content: [
8755
+ {
8756
+ type: "text",
8757
+ text: `Graph does not have a default agent configured`
8758
+ }
8759
+ ],
8760
+ isError: true
8761
+ };
8762
+ }
8711
8763
  const defaultAgentId = agentGraph.defaultAgentId;
8712
8764
  const agentInfo = await agentsCore.getAgentById(dbClient_default)({
8713
- scopes: { tenantId, projectId },
8765
+ scopes: { tenantId, projectId, graphId },
8714
8766
  agentId: defaultAgentId
8715
8767
  });
8716
8768
  if (!agentInfo) {
@@ -8724,18 +8776,19 @@ var getServer = async (requestContext, executionContext, conversationId, credent
8724
8776
  isError: true
8725
8777
  };
8726
8778
  }
8727
- const resolvedContext = await agentsCore.handleContextResolution(
8779
+ const resolvedContext = await agentsCore.handleContextResolution({
8728
8780
  tenantId,
8729
8781
  projectId,
8730
- conversationId,
8731
8782
  graphId,
8783
+ conversationId,
8732
8784
  requestContext,
8733
- dbClient_default,
8785
+ dbClient: dbClient_default,
8734
8786
  credentialStores
8735
- );
8787
+ });
8736
8788
  logger22.info(
8737
8789
  {
8738
8790
  tenantId,
8791
+ projectId,
8739
8792
  graphId,
8740
8793
  conversationId,
8741
8794
  hasContextConfig: !!agentGraph.contextConfigId,
@@ -8797,8 +8850,7 @@ var handleInitializationRequest = async (body, executionContext, validatedContex
8797
8850
  logger22.info({ body }, "Received initialization request");
8798
8851
  const sessionId = nanoid.nanoid();
8799
8852
  const agentGraph = await agentsCore.getAgentGraphWithDefaultAgent(dbClient_default)({
8800
- scopes: { tenantId, projectId },
8801
- graphId
8853
+ scopes: { tenantId, projectId, graphId }
8802
8854
  });
8803
8855
  if (!agentGraph) {
8804
8856
  return c.json(
@@ -8810,6 +8862,16 @@ var handleInitializationRequest = async (body, executionContext, validatedContex
8810
8862
  { status: 404 }
8811
8863
  );
8812
8864
  }
8865
+ if (!agentGraph.defaultAgentId) {
8866
+ return c.json(
8867
+ {
8868
+ jsonrpc: "2.0",
8869
+ error: { code: -32001, message: "Graph does not have a default agent configured" },
8870
+ id: body.id || null
8871
+ },
8872
+ { status: 400 }
8873
+ );
8874
+ }
8813
8875
  const conversation = await agentsCore.createOrGetConversation(dbClient_default)({
8814
8876
  id: sessionId,
8815
8877
  tenantId,
package/dist/index.js CHANGED
@@ -8,7 +8,7 @@ import { resourceFromAttributes } from '@opentelemetry/resources';
8
8
  import { NodeSDK } from '@opentelemetry/sdk-node';
9
9
  import { BatchSpanProcessor } from '@opentelemetry/sdk-trace-base';
10
10
  import { ATTR_SERVICE_NAME } from '@opentelemetry/semantic-conventions';
11
- import { getLogger, getTracer, HeadersScopeSchema, getRequestExecutionContext, getAgentGraphWithDefaultAgent, contextValidationMiddleware, getFullGraph, createOrGetConversation, getActiveAgentForConversation, setActiveAgentForConversation, getAgentById, handleContextResolution, createMessage, commonGetErrorResponses, createDefaultCredentialStores, CredentialStoreRegistry, listTaskIdsByContextId, getTask, getLedgerArtifacts, getAgentGraph, createTask, updateTask, setSpanWithError, updateConversation, handleApiError, TaskState, setActiveAgentForThread, getConversation, getRelatedAgentsForGraph, getToolsForAgent, getDataComponentsForAgent, getArtifactComponentsForAgent, validateAndGetApiKey, getProject, ContextResolver, CredentialStuffer, MCPServerType, getCredentialReference, McpClient, getContextConfigById, getFullGraphDefinition, TemplateEngine, graphHasArtifactComponents, MCPTransportType, getExternalAgent } from '@inkeep/agents-core';
11
+ import { getLogger, getTracer, HeadersScopeSchema, getRequestExecutionContext, getAgentGraphWithDefaultAgent, contextValidationMiddleware, getFullGraph, createOrGetConversation, getActiveAgentForConversation, setActiveAgentForConversation, getAgentById, handleContextResolution, createMessage, commonGetErrorResponses, loggerFactory, createDefaultCredentialStores, CredentialStoreRegistry, listTaskIdsByContextId, getTask, getLedgerArtifacts, getAgentGraphById, createTask, updateTask, setSpanWithError, updateConversation, handleApiError, TaskState, setActiveAgentForThread, getConversation, getRelatedAgentsForGraph, getToolsForAgent, getDataComponentsForAgent, getArtifactComponentsForAgent, validateAndGetApiKey, getProject, ContextResolver, CredentialStuffer, MCPServerType, getCredentialReference, McpClient, getContextConfigById, getFullGraphDefinition, TemplateEngine, graphHasArtifactComponents, MCPTransportType, getExternalAgent } from '@inkeep/agents-core';
12
12
  import { OpenAPIHono, createRoute, z as z$1 } from '@hono/zod-openapi';
13
13
  import { trace, propagation, context, SpanStatusCode } from '@opentelemetry/api';
14
14
  import { Hono } from 'hono';
@@ -965,7 +965,7 @@ async function getRegisteredAgent(executionContext, credentialStoreRegistry) {
965
965
  throw new Error("Agent ID is required");
966
966
  }
967
967
  const dbAgent = await getAgentById(dbClient_default)({
968
- scopes: { tenantId, projectId },
968
+ scopes: { tenantId, projectId, graphId },
969
969
  agentId
970
970
  });
971
971
  if (!dbAgent) {
@@ -980,6 +980,38 @@ async function getRegisteredAgent(executionContext, credentialStoreRegistry) {
980
980
  apiKey
981
981
  });
982
982
  }
983
+ async function resolveModelConfig(graphId, agent) {
984
+ if (agent.models?.base?.model) {
985
+ return {
986
+ base: agent.models.base,
987
+ structuredOutput: agent.models.structuredOutput || agent.models.base,
988
+ summarizer: agent.models.summarizer || agent.models.base
989
+ };
990
+ }
991
+ const graph = await getAgentGraphById(dbClient_default)({
992
+ scopes: { tenantId: agent.tenantId, projectId: agent.projectId, graphId }
993
+ });
994
+ if (graph?.models?.base?.model) {
995
+ return {
996
+ base: graph.models.base,
997
+ structuredOutput: agent.models?.structuredOutput || graph.models.structuredOutput || graph.models.base,
998
+ summarizer: agent.models?.summarizer || graph.models.summarizer || graph.models.base
999
+ };
1000
+ }
1001
+ const project = await getProject(dbClient_default)({
1002
+ scopes: { tenantId: agent.tenantId, projectId: agent.projectId }
1003
+ });
1004
+ if (project?.models?.base?.model) {
1005
+ return {
1006
+ base: project.models.base,
1007
+ structuredOutput: agent.models?.structuredOutput || project.models.structuredOutput || project.models.base,
1008
+ summarizer: agent.models?.summarizer || project.models.summarizer || project.models.base
1009
+ };
1010
+ }
1011
+ throw new Error(
1012
+ "Base model configuration is required. Please configure models at the project level."
1013
+ );
1014
+ }
983
1015
  function agentInitializingOp(sessionId, graphId) {
984
1016
  return {
985
1017
  type: "agent_initializing",
@@ -1140,6 +1172,9 @@ var _ModelFactory = class _ModelFactory {
1140
1172
  );
1141
1173
  }
1142
1174
  const modelSettings = config;
1175
+ if (!modelSettings.model) {
1176
+ throw new Error("Model configuration is required");
1177
+ }
1143
1178
  const modelString = modelSettings.model.trim();
1144
1179
  const { provider, modelName } = _ModelFactory.parseModelString(modelString);
1145
1180
  logger5.debug(
@@ -1806,6 +1841,9 @@ ${this.statusUpdateState?.config.prompt?.trim() || ""}`;
1806
1841
  }
1807
1842
  modelToUse = this.statusUpdateState.baseModel;
1808
1843
  }
1844
+ if (!modelToUse) {
1845
+ throw new Error("No model configuration available");
1846
+ }
1809
1847
  const model = ModelFactory.createModel(modelToUse);
1810
1848
  const { text } = await generateText({
1811
1849
  model,
@@ -1940,6 +1978,9 @@ ${this.statusUpdateState?.config.prompt?.trim() || ""}`;
1940
1978
  }
1941
1979
  modelToUse = this.statusUpdateState.baseModel;
1942
1980
  }
1981
+ if (!modelToUse) {
1982
+ throw new Error("No model configuration available");
1983
+ }
1943
1984
  const model = ModelFactory.createModel(modelToUse);
1944
1985
  const { object } = await generateObject({
1945
1986
  model,
@@ -2230,6 +2271,9 @@ Make it specific and relevant.`;
2230
2271
  }
2231
2272
  modelToUse = this.statusUpdateState.baseModel;
2232
2273
  }
2274
+ if (!modelToUse) {
2275
+ throw new Error("No model configuration available");
2276
+ }
2233
2277
  const model = ModelFactory.createModel(modelToUse);
2234
2278
  const schema = z.object({
2235
2279
  name: z.string().max(50).describe("Concise, descriptive name for the artifact"),
@@ -2508,6 +2552,7 @@ var _ArtifactParser = class _ArtifactParser {
2508
2552
  }
2509
2553
  for (let i = matches.length - 1; i >= 0; i--) {
2510
2554
  const match = matches[i];
2555
+ if (match.index === void 0) continue;
2511
2556
  const startIdx = match.index;
2512
2557
  const textAfterMatch = text.slice(startIdx);
2513
2558
  if (!textAfterMatch.includes("/>")) {
@@ -2575,6 +2620,7 @@ var _ArtifactParser = class _ArtifactParser {
2575
2620
  let lastIndex = 0;
2576
2621
  for (const match of matches) {
2577
2622
  const [fullMatch, artifactId, taskId] = match;
2623
+ if (match.index === void 0) continue;
2578
2624
  const matchStart = match.index;
2579
2625
  if (matchStart > lastIndex) {
2580
2626
  const textBefore = text.slice(lastIndex, matchStart);
@@ -4393,7 +4439,8 @@ function createDelegateToAgentTool({
4393
4439
  const externalAgent = await getExternalAgent(dbClient_default)({
4394
4440
  scopes: {
4395
4441
  tenantId,
4396
- projectId
4442
+ projectId,
4443
+ graphId
4397
4444
  },
4398
4445
  agentId: delegateConfig.config.id
4399
4446
  });
@@ -5282,8 +5329,12 @@ var Agent = class {
5282
5329
  async getMcpTool(tool4) {
5283
5330
  const credentialReferenceId = tool4.credentialReferenceId;
5284
5331
  const toolsForAgent = await getToolsForAgent(dbClient_default)({
5285
- scopes: { tenantId: this.config.tenantId, projectId: this.config.projectId },
5286
- agentId: this.config.id
5332
+ scopes: {
5333
+ tenantId: this.config.tenantId,
5334
+ projectId: this.config.projectId,
5335
+ graphId: this.config.graphId,
5336
+ agentId: this.config.id
5337
+ }
5287
5338
  });
5288
5339
  const selectedTools = toolsForAgent.data.find((t) => t.toolId === tool4.id)?.selectedTools || void 0;
5289
5340
  let serverConfig;
@@ -5430,9 +5481,9 @@ var Agent = class {
5430
5481
  const graphDefinition = await getFullGraphDefinition(dbClient_default)({
5431
5482
  scopes: {
5432
5483
  tenantId: this.config.tenantId,
5433
- projectId: this.config.projectId
5434
- },
5435
- graphId: this.config.graphId
5484
+ projectId: this.config.projectId,
5485
+ graphId: this.config.graphId
5486
+ }
5436
5487
  });
5437
5488
  return graphDefinition?.graphPrompt || void 0;
5438
5489
  } catch (error) {
@@ -5454,14 +5505,16 @@ var Agent = class {
5454
5505
  const graphDefinition = await getFullGraphDefinition(dbClient_default)({
5455
5506
  scopes: {
5456
5507
  tenantId: this.config.tenantId,
5457
- projectId: this.config.projectId
5458
- },
5459
- graphId: this.config.graphId
5508
+ projectId: this.config.projectId,
5509
+ graphId: this.config.graphId
5510
+ }
5460
5511
  });
5461
5512
  if (!graphDefinition) {
5462
5513
  return false;
5463
5514
  }
5464
- return !!(graphDefinition.artifactComponents && Object.keys(graphDefinition.artifactComponents).length > 0);
5515
+ return Object.values(graphDefinition.agents).some(
5516
+ (agent) => "artifactComponents" in agent && agent.artifactComponents && agent.artifactComponents.length > 0
5517
+ );
5465
5518
  } catch (error) {
5466
5519
  logger15.warn(
5467
5520
  {
@@ -5660,9 +5713,9 @@ Key requirements:
5660
5713
  return await graphHasArtifactComponents(dbClient_default)({
5661
5714
  scopes: {
5662
5715
  tenantId: this.config.tenantId,
5663
- projectId: this.config.projectId
5664
- },
5665
- graphId: this.config.graphId
5716
+ projectId: this.config.projectId,
5717
+ graphId: this.config.graphId
5718
+ }
5666
5719
  });
5667
5720
  } catch (error) {
5668
5721
  logger15.error(
@@ -6140,42 +6193,6 @@ ${output}`;
6140
6193
  });
6141
6194
  }
6142
6195
  };
6143
- async function resolveModelConfig(graphId, agent) {
6144
- if (agent.models?.base?.model) {
6145
- return {
6146
- base: agent.models.base,
6147
- structuredOutput: agent.models.structuredOutput || agent.models.base,
6148
- summarizer: agent.models.summarizer || agent.models.base
6149
- };
6150
- }
6151
- let graph = null;
6152
- if (graphId) {
6153
- graph = await getAgentGraph(dbClient_default)({
6154
- scopes: { tenantId: agent.tenantId, projectId: agent.projectId },
6155
- graphId
6156
- });
6157
- }
6158
- if (graph?.models?.base?.model) {
6159
- return {
6160
- base: graph.models.base,
6161
- structuredOutput: agent.models?.structuredOutput || graph.models.structuredOutput || graph.models.base,
6162
- summarizer: agent.models?.summarizer || graph.models.summarizer || graph.models.base
6163
- };
6164
- }
6165
- const project = await getProject(dbClient_default)({
6166
- scopes: { tenantId: agent.tenantId, projectId: agent.projectId }
6167
- });
6168
- if (project?.models?.base?.model) {
6169
- return {
6170
- base: project.models.base,
6171
- structuredOutput: agent.models?.structuredOutput || project.models.structuredOutput || project.models.base,
6172
- summarizer: agent.models?.summarizer || project.models.summarizer || project.models.base
6173
- };
6174
- }
6175
- throw new Error(
6176
- "Base model configuration is required. Please configure models at the project level."
6177
- );
6178
- }
6179
6196
 
6180
6197
  // src/agents/generateTaskHandler.ts
6181
6198
  function parseEmbeddedJson(data) {
@@ -6211,31 +6228,34 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
6211
6228
  getRelatedAgentsForGraph(dbClient_default)({
6212
6229
  scopes: {
6213
6230
  tenantId: config.tenantId,
6214
- projectId: config.projectId
6231
+ projectId: config.projectId,
6232
+ graphId: config.graphId
6215
6233
  },
6216
- graphId: config.graphId,
6217
6234
  agentId: config.agentId
6218
6235
  }),
6219
6236
  getToolsForAgent(dbClient_default)({
6220
6237
  scopes: {
6221
6238
  tenantId: config.tenantId,
6222
- projectId: config.projectId
6223
- },
6224
- agentId: config.agentId
6239
+ projectId: config.projectId,
6240
+ graphId: config.graphId,
6241
+ agentId: config.agentId
6242
+ }
6225
6243
  }),
6226
6244
  getDataComponentsForAgent(dbClient_default)({
6227
6245
  scopes: {
6228
6246
  tenantId: config.tenantId,
6229
- projectId: config.projectId
6230
- },
6231
- agentId: config.agentId
6247
+ projectId: config.projectId,
6248
+ graphId: config.graphId,
6249
+ agentId: config.agentId
6250
+ }
6232
6251
  }),
6233
6252
  getArtifactComponentsForAgent(dbClient_default)({
6234
6253
  scopes: {
6235
6254
  tenantId: config.tenantId,
6236
- projectId: config.projectId
6237
- },
6238
- agentId: config.agentId
6255
+ projectId: config.projectId,
6256
+ graphId: config.graphId,
6257
+ agentId: config.agentId
6258
+ }
6239
6259
  })
6240
6260
  ]);
6241
6261
  logger16.info({ toolsForAgent, internalRelations, externalRelations }, "agent stuff");
@@ -6243,13 +6263,16 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
6243
6263
  internalRelations.map(async (relation) => {
6244
6264
  try {
6245
6265
  const relatedAgent = await getAgentById(dbClient_default)({
6246
- scopes: { tenantId: config.tenantId, projectId: config.projectId },
6266
+ scopes: {
6267
+ tenantId: config.tenantId,
6268
+ projectId: config.projectId,
6269
+ graphId: config.graphId
6270
+ },
6247
6271
  agentId: relation.id
6248
6272
  });
6249
6273
  if (relatedAgent) {
6250
6274
  const relatedAgentRelations = await getRelatedAgentsForGraph(dbClient_default)({
6251
- scopes: { tenantId: config.tenantId, projectId: config.projectId },
6252
- graphId: config.graphId,
6275
+ scopes: { tenantId: config.tenantId, projectId: config.projectId, graphId: config.graphId },
6253
6276
  agentId: relation.id
6254
6277
  });
6255
6278
  const enhancedDescription = generateDescriptionWithTransfers(
@@ -6472,16 +6495,17 @@ var createTaskHandlerConfig = async (params) => {
6472
6495
  const agent = await getAgentById(dbClient_default)({
6473
6496
  scopes: {
6474
6497
  tenantId: params.tenantId,
6475
- projectId: params.projectId
6498
+ projectId: params.projectId,
6499
+ graphId: params.graphId
6476
6500
  },
6477
6501
  agentId: params.agentId
6478
6502
  });
6479
- const agentGraph = await getAgentGraph(dbClient_default)({
6503
+ const agentGraph = await getAgentGraphById(dbClient_default)({
6480
6504
  scopes: {
6481
6505
  tenantId: params.tenantId,
6482
- projectId: params.projectId
6483
- },
6484
- graphId: params.graphId
6506
+ projectId: params.projectId,
6507
+ graphId: params.graphId
6508
+ }
6485
6509
  });
6486
6510
  if (!agent) {
6487
6511
  throw new Error(`Agent not found: ${params.agentId}`);
@@ -6520,10 +6544,14 @@ async function hydrateGraph({
6520
6544
  apiKey
6521
6545
  }) {
6522
6546
  try {
6547
+ if (!dbGraph.defaultAgentId) {
6548
+ throw new Error(`Graph ${dbGraph.id} does not have a default agent configured`);
6549
+ }
6523
6550
  const defaultAgent = await getAgentById(dbClient_default)({
6524
6551
  scopes: {
6525
6552
  tenantId: dbGraph.tenantId,
6526
- projectId: dbGraph.projectId
6553
+ projectId: dbGraph.projectId,
6554
+ graphId: dbGraph.id
6527
6555
  },
6528
6556
  agentId: dbGraph.defaultAgentId
6529
6557
  });
@@ -6578,7 +6606,7 @@ async function hydrateGraph({
6578
6606
  }
6579
6607
  async function getRegisteredGraph(executionContext) {
6580
6608
  const { tenantId, projectId, graphId, baseUrl, apiKey } = executionContext;
6581
- const dbGraph = await getAgentGraph(dbClient_default)({ scopes: { tenantId, projectId }, graphId });
6609
+ const dbGraph = await getAgentGraphById(dbClient_default)({ scopes: { tenantId, projectId, graphId } });
6582
6610
  if (!dbGraph) {
6583
6611
  return null;
6584
6612
  }
@@ -6636,6 +6664,7 @@ app.openapi(
6636
6664
  );
6637
6665
  const executionContext = getRequestExecutionContext(c);
6638
6666
  const { tenantId, projectId, graphId, agentId } = executionContext;
6667
+ console.dir("executionContext", executionContext);
6639
6668
  if (agentId) {
6640
6669
  logger17.info(
6641
6670
  {
@@ -6723,8 +6752,7 @@ app.post("/a2a", async (c) => {
6723
6752
  "graph-level a2a endpoint"
6724
6753
  );
6725
6754
  const graph = await getAgentGraphWithDefaultAgent(dbClient_default)({
6726
- scopes: { tenantId, projectId },
6727
- graphId
6755
+ scopes: { tenantId, projectId, graphId }
6728
6756
  });
6729
6757
  if (!graph) {
6730
6758
  return c.json(
@@ -6736,6 +6764,16 @@ app.post("/a2a", async (c) => {
6736
6764
  404
6737
6765
  );
6738
6766
  }
6767
+ if (!graph.defaultAgentId) {
6768
+ return c.json(
6769
+ {
6770
+ jsonrpc: "2.0",
6771
+ error: { code: -32004, message: "Graph does not have a default agent configured" },
6772
+ id: null
6773
+ },
6774
+ 400
6775
+ );
6776
+ }
6739
6777
  executionContext.agentId = graph.defaultAgentId;
6740
6778
  const credentialStores = c.get("credentialStores");
6741
6779
  const defaultAgent = await getRegisteredAgent(executionContext, credentialStores);
@@ -7086,8 +7124,8 @@ var _VercelDataStreamHelper = class _VercelDataStreamHelper {
7086
7124
  });
7087
7125
  } else {
7088
7126
  this.writer.write({
7089
- type: "error",
7090
- ...error
7127
+ ...error,
7128
+ type: "error"
7091
7129
  });
7092
7130
  }
7093
7131
  }
@@ -7340,6 +7378,8 @@ var MCPStreamHelper = class {
7340
7378
  function createMCPStreamHelper() {
7341
7379
  return new MCPStreamHelper();
7342
7380
  }
7381
+
7382
+ // src/handlers/executionHandler.ts
7343
7383
  var logger19 = getLogger("ExecutionHandler");
7344
7384
  var ExecutionHandler = class {
7345
7385
  constructor() {
@@ -7368,7 +7408,7 @@ var ExecutionHandler = class {
7368
7408
  logger19.info({ sessionId: requestId2, graphId }, "Created GraphSession for message execution");
7369
7409
  let graphConfig = null;
7370
7410
  try {
7371
- graphConfig = await getFullGraph(dbClient_default)({ scopes: { tenantId, projectId }, graphId });
7411
+ graphConfig = await getFullGraph(dbClient_default)({ scopes: { tenantId, projectId, graphId } });
7372
7412
  if (graphConfig?.statusUpdates && graphConfig.statusUpdates.enabled !== false) {
7373
7413
  graphSessionManager.initializeStatusUpdates(
7374
7414
  requestId2,
@@ -7865,8 +7905,7 @@ app2.openapi(chatCompletionsRoute, async (c) => {
7865
7905
  const body = c.get("requestBody") || {};
7866
7906
  const conversationId = body.conversationId || nanoid();
7867
7907
  const fullGraph = await getFullGraph(dbClient_default)({
7868
- scopes: { tenantId, projectId },
7869
- graphId
7908
+ scopes: { tenantId, projectId, graphId }
7870
7909
  });
7871
7910
  let agentGraph;
7872
7911
  let defaultAgentId;
@@ -7883,8 +7922,7 @@ app2.openapi(chatCompletionsRoute, async (c) => {
7883
7922
  defaultAgentId = fullGraph.defaultAgentId || firstAgentId;
7884
7923
  } else {
7885
7924
  agentGraph = await getAgentGraphWithDefaultAgent(dbClient_default)({
7886
- scopes: { tenantId, projectId },
7887
- graphId
7925
+ scopes: { tenantId, projectId, graphId }
7888
7926
  });
7889
7927
  if (!agentGraph) {
7890
7928
  return c.json({ error: "Agent graph not found" }, 404);
@@ -7913,7 +7951,7 @@ app2.openapi(chatCompletionsRoute, async (c) => {
7913
7951
  }
7914
7952
  const agentId = activeAgent?.activeAgentId || defaultAgentId;
7915
7953
  const agentInfo = await getAgentById(dbClient_default)({
7916
- scopes: { tenantId, projectId },
7954
+ scopes: { tenantId, projectId, graphId },
7917
7955
  agentId
7918
7956
  });
7919
7957
  if (!agentInfo) {
@@ -7921,18 +7959,19 @@ app2.openapi(chatCompletionsRoute, async (c) => {
7921
7959
  }
7922
7960
  const validatedContext = c.get("validatedContext") || body.requestContext || {};
7923
7961
  const credentialStores = c.get("credentialStores");
7924
- await handleContextResolution(
7962
+ await handleContextResolution({
7925
7963
  tenantId,
7926
7964
  projectId,
7927
- conversationId,
7928
7965
  graphId,
7929
- validatedContext,
7930
- dbClient_default,
7966
+ conversationId,
7967
+ requestContext: validatedContext,
7968
+ dbClient: dbClient_default,
7931
7969
  credentialStores
7932
- );
7970
+ });
7933
7971
  logger20.info(
7934
7972
  {
7935
7973
  tenantId,
7974
+ projectId,
7936
7975
  graphId,
7937
7976
  conversationId,
7938
7977
  defaultAgentId,
@@ -8072,6 +8111,7 @@ app3.openapi(chatDataStreamRoute, async (c) => {
8072
8111
  try {
8073
8112
  const executionContext = getRequestExecutionContext(c);
8074
8113
  const { tenantId, projectId, graphId } = executionContext;
8114
+ loggerFactory.getLogger("chatDataStream").debug({ tenantId, projectId, graphId }, "Extracted chatDataStream parameters");
8075
8115
  const body = c.get("requestBody") || {};
8076
8116
  const conversationId = body.conversationId || nanoid();
8077
8117
  const activeSpan = trace.getActiveSpan();
@@ -8084,14 +8124,16 @@ app3.openapi(chatDataStreamRoute, async (c) => {
8084
8124
  });
8085
8125
  }
8086
8126
  const agentGraph = await getAgentGraphWithDefaultAgent(dbClient_default)({
8087
- scopes: { tenantId, projectId },
8088
- graphId
8127
+ scopes: { tenantId, projectId, graphId }
8089
8128
  });
8090
8129
  if (!agentGraph) {
8091
8130
  return c.json({ error: "Agent graph not found" }, 404);
8092
8131
  }
8093
8132
  const defaultAgentId = agentGraph.defaultAgentId;
8094
8133
  const graphName = agentGraph.name;
8134
+ if (!defaultAgentId) {
8135
+ return c.json({ error: "Graph does not have a default agent configured" }, 400);
8136
+ }
8095
8137
  const activeAgent = await getActiveAgentForConversation(dbClient_default)({
8096
8138
  scopes: { tenantId, projectId },
8097
8139
  conversationId
@@ -8105,7 +8147,7 @@ app3.openapi(chatDataStreamRoute, async (c) => {
8105
8147
  }
8106
8148
  const agentId = activeAgent?.activeAgentId || defaultAgentId;
8107
8149
  const agentInfo = await getAgentById(dbClient_default)({
8108
- scopes: { tenantId, projectId },
8150
+ scopes: { tenantId, projectId, graphId },
8109
8151
  agentId
8110
8152
  });
8111
8153
  if (!agentInfo) {
@@ -8113,15 +8155,15 @@ app3.openapi(chatDataStreamRoute, async (c) => {
8113
8155
  }
8114
8156
  const validatedContext = c.get("validatedContext") || body.requestContext || {};
8115
8157
  const credentialStores = c.get("credentialStores");
8116
- await handleContextResolution(
8158
+ await handleContextResolution({
8117
8159
  tenantId,
8118
8160
  projectId,
8119
- conversationId,
8120
8161
  graphId,
8121
- validatedContext,
8122
- dbClient_default,
8162
+ conversationId,
8163
+ requestContext: validatedContext,
8164
+ dbClient: dbClient_default,
8123
8165
  credentialStores
8124
- );
8166
+ });
8125
8167
  const lastUserMessage = body.messages.filter((m) => m.role === "user").slice(-1)[0];
8126
8168
  const userText = typeof lastUserMessage?.content === "string" ? lastUserMessage.content : lastUserMessage?.parts?.map((p) => p.text).join("") || "";
8127
8169
  logger21.info({ userText, lastUserMessage }, "userText");
@@ -8390,8 +8432,7 @@ var getServer = async (requestContext, executionContext, conversationId, credent
8390
8432
  const { tenantId, projectId, graphId } = executionContext;
8391
8433
  setupTracing(conversationId, tenantId, graphId);
8392
8434
  const agentGraph = await getAgentGraphWithDefaultAgent(dbClient_default)({
8393
- scopes: { tenantId, projectId },
8394
- graphId
8435
+ scopes: { tenantId, projectId, graphId }
8395
8436
  });
8396
8437
  if (!agentGraph) {
8397
8438
  throw new Error("Agent graph not found");
@@ -8411,9 +8452,20 @@ var getServer = async (requestContext, executionContext, conversationId, credent
8411
8452
  },
8412
8453
  async ({ query }) => {
8413
8454
  try {
8455
+ if (!agentGraph.defaultAgentId) {
8456
+ return {
8457
+ content: [
8458
+ {
8459
+ type: "text",
8460
+ text: `Graph does not have a default agent configured`
8461
+ }
8462
+ ],
8463
+ isError: true
8464
+ };
8465
+ }
8414
8466
  const defaultAgentId = agentGraph.defaultAgentId;
8415
8467
  const agentInfo = await getAgentById(dbClient_default)({
8416
- scopes: { tenantId, projectId },
8468
+ scopes: { tenantId, projectId, graphId },
8417
8469
  agentId: defaultAgentId
8418
8470
  });
8419
8471
  if (!agentInfo) {
@@ -8427,18 +8479,19 @@ var getServer = async (requestContext, executionContext, conversationId, credent
8427
8479
  isError: true
8428
8480
  };
8429
8481
  }
8430
- const resolvedContext = await handleContextResolution(
8482
+ const resolvedContext = await handleContextResolution({
8431
8483
  tenantId,
8432
8484
  projectId,
8433
- conversationId,
8434
8485
  graphId,
8486
+ conversationId,
8435
8487
  requestContext,
8436
- dbClient_default,
8488
+ dbClient: dbClient_default,
8437
8489
  credentialStores
8438
- );
8490
+ });
8439
8491
  logger22.info(
8440
8492
  {
8441
8493
  tenantId,
8494
+ projectId,
8442
8495
  graphId,
8443
8496
  conversationId,
8444
8497
  hasContextConfig: !!agentGraph.contextConfigId,
@@ -8500,8 +8553,7 @@ var handleInitializationRequest = async (body, executionContext, validatedContex
8500
8553
  logger22.info({ body }, "Received initialization request");
8501
8554
  const sessionId = nanoid();
8502
8555
  const agentGraph = await getAgentGraphWithDefaultAgent(dbClient_default)({
8503
- scopes: { tenantId, projectId },
8504
- graphId
8556
+ scopes: { tenantId, projectId, graphId }
8505
8557
  });
8506
8558
  if (!agentGraph) {
8507
8559
  return c.json(
@@ -8513,6 +8565,16 @@ var handleInitializationRequest = async (body, executionContext, validatedContex
8513
8565
  { status: 404 }
8514
8566
  );
8515
8567
  }
8568
+ if (!agentGraph.defaultAgentId) {
8569
+ return c.json(
8570
+ {
8571
+ jsonrpc: "2.0",
8572
+ error: { code: -32001, message: "Graph does not have a default agent configured" },
8573
+ id: body.id || null
8574
+ },
8575
+ { status: 400 }
8576
+ );
8577
+ }
8516
8578
  const conversation = await createOrGetConversation(dbClient_default)({
8517
8579
  id: sessionId,
8518
8580
  tenantId,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inkeep/agents-run-api",
3
- "version": "0.0.0-dev-20250919020857",
3
+ "version": "0.0.0-dev-20250919052931",
4
4
  "description": "Agents Run API for Inkeep Agent Framework - handles chat, agent execution, and streaming",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -45,7 +45,7 @@
45
45
  "traverse": "^0.6.11",
46
46
  "ts-pattern": "^5.7.1",
47
47
  "zod": "^4.1.5",
48
- "@inkeep/agents-core": "^0.0.0-dev-20250919020857"
48
+ "@inkeep/agents-core": "^0.0.0-dev-20250919052931"
49
49
  },
50
50
  "devDependencies": {
51
51
  "@hono/vite-dev-server": "^0.20.1",