@inkeep/agents-run-api 0.10.1 → 0.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -29,18 +29,16 @@ This API handles the execution layer of the Inkeep Agent Framework:
29
29
  ## Development
30
30
 
31
31
  ### Setup
32
- If you do not have the db setup:
33
- ```bash
34
- cd packages/core
35
- pnpm db:push
36
- ```
37
-
38
- Then:
39
32
  ```bash
40
33
  cd agents-run-api
41
34
  pnpm install
42
35
  ```
43
36
 
37
+ If you do not have the database setup, run migrations from the monorepo root:
38
+ ```bash
39
+ pnpm db:migrate
40
+ ```
41
+
44
42
 
45
43
  ### Environment Variables
46
44
  ```env
package/dist/index.cjs CHANGED
@@ -769,6 +769,7 @@ async function handleMessageSend(c, agent, request) {
769
769
  id: task.id,
770
770
  tenantId: agent.tenantId,
771
771
  projectId: agent.projectId,
772
+ graphId: graphId || "",
772
773
  contextId: effectiveContextId,
773
774
  status: "working",
774
775
  metadata: {
@@ -6090,7 +6091,7 @@ ${propertiesXml}
6090
6091
  };
6091
6092
 
6092
6093
  // templates/v1/phase2/system-prompt.xml?raw
6093
- var system_prompt_default2 = "<phase2_system_message>\n <instruction>\n Generate the final structured JSON response using the configured data components and artifact creation capabilities.\n </instruction>\n\n {{ARTIFACTS_SECTION}}\n {{DATA_COMPONENTS_SECTION}}\n\n {{ARTIFACT_GUIDANCE_SECTION}}\n\n {{ARTIFACT_TYPES_SECTION}}\n\n <requirements>\n <key_requirements>\n - Create artifacts from tool results to support your information with citations\n - Mix artifact creation and references naturally throughout your dataComponents array\n - Each artifact creation must use EXACT tool_call_id from tool outputs\n - Use appropriate ArtifactCreate_[Type] components for each artifact type\n - IMPORTANT: In Text components, write naturally as if having a conversation - do NOT mention components, schemas, JSON, structured data, or any technical implementation details\n </key_requirements>\n </requirements>\n</phase2_system_message>";
6094
+ var system_prompt_default2 = "<phase2_system_message>\n <instruction>\n Generate the final structured JSON response using the configured data components and artifact creation capabilities.\n </instruction>\n\n <core_instructions>\n {{CORE_INSTRUCTIONS}}\n </core_instructions>\n\n {{ARTIFACTS_SECTION}}\n {{DATA_COMPONENTS_SECTION}}\n\n {{ARTIFACT_GUIDANCE_SECTION}}\n\n {{ARTIFACT_TYPES_SECTION}}\n\n <requirements>\n <key_requirements>\n - Create artifacts from tool results to support your information with citations\n - Mix artifact creation and references naturally throughout your dataComponents array\n - Each artifact creation must use EXACT tool_call_id from tool outputs\n - Use appropriate ArtifactCreate_[Type] components for each artifact type\n - IMPORTANT: In Text components, write naturally as if having a conversation - do NOT mention components, schemas, JSON, structured data, or any technical implementation details\n </key_requirements>\n </requirements>\n</phase2_system_message>";
6094
6095
 
6095
6096
  // templates/v1/phase2/data-components.xml?raw
6096
6097
  var data_components_default = '<data_components_section description="These are the data components available for you to use in generating responses. Each component represents a single structured piece of information. You can create multiple instances of the same component type when needed.\n\n***MANDATORY JSON RESPONSE FORMAT - ABSOLUTELY CRITICAL***:\n- WHEN DATA COMPONENTS ARE AVAILABLE, YOU MUST RESPOND IN JSON FORMAT ONLY\n- DO NOT respond with plain text when data components are defined\n- YOUR RESPONSE MUST BE STRUCTURED JSON WITH dataComponents ARRAY\n- THIS IS NON-NEGOTIABLE - JSON FORMAT IS REQUIRED\n\nCRITICAL JSON FORMATTING RULES - MUST FOLLOW EXACTLY:\n1. Each data component must include id, name, and props fields\n2. The id and name should match the exact component definition\n3. The props field contains the actual component data using exact property names from the schema\n4. NEVER omit the id and name fields\n\nCORRECT: [{\\"id\\": \\"component1\\", \\"name\\": \\"Component1\\", \\"props\\": {\\"field1\\": \\"value1\\", \\"field2\\": \\"value2\\"}}, {\\"id\\": \\"component2\\", \\"name\\": \\"Component2\\", \\"props\\": {\\"field3\\": \\"value3\\"}}]\nWRONG: [{\\"field1\\": \\"value1\\", \\"field2\\": \\"value2\\"}, {\\"field3\\": \\"value3\\"}]\n\nAVAILABLE DATA COMPONENTS: {{DATA_COMPONENTS_LIST}}">\n\n{{DATA_COMPONENTS_XML}}\n\n</data_components_section>';
@@ -6422,7 +6423,7 @@ ${artifact_retrieval_guidance_default}
6422
6423
  * Assemble the complete Phase 2 system prompt for structured output generation
6423
6424
  */
6424
6425
  assemblePhase2Prompt(config) {
6425
- const { dataComponents, artifactComponents, hasArtifactComponents, hasGraphArtifactComponents, artifacts = [] } = config;
6426
+ const { corePrompt, dataComponents, artifactComponents, hasArtifactComponents, hasGraphArtifactComponents, artifacts = [] } = config;
6426
6427
  let allDataComponents = [...dataComponents];
6427
6428
  if (hasArtifactComponents && artifactComponents) {
6428
6429
  const artifactCreateComponents = ArtifactCreateSchema.getDataComponents(
@@ -6440,6 +6441,7 @@ ${artifact_retrieval_guidance_default}
6440
6441
  const artifactGuidance = this.getStructuredArtifactGuidance(hasArtifactComponents, artifactComponents, shouldShowReferencingRules);
6441
6442
  const artifactTypes = this.getArtifactCreationInstructions(hasArtifactComponents, artifactComponents);
6442
6443
  let phase2Prompt = system_prompt_default2;
6444
+ phase2Prompt = phase2Prompt.replace("{{CORE_INSTRUCTIONS}}", corePrompt);
6443
6445
  phase2Prompt = phase2Prompt.replace("{{DATA_COMPONENTS_SECTION}}", dataComponentsSection);
6444
6446
  phase2Prompt = phase2Prompt.replace("{{ARTIFACTS_SECTION}}", artifactsSection);
6445
6447
  phase2Prompt = phase2Prompt.replace("{{ARTIFACT_GUIDANCE_SECTION}}", artifactGuidance);
@@ -7020,9 +7022,29 @@ var Agent = class {
7020
7022
  * Build adaptive system prompt for Phase 2 structured output generation
7021
7023
  * based on configured data components and artifact components across the graph
7022
7024
  */
7023
- async buildPhase2SystemPrompt() {
7025
+ async buildPhase2SystemPrompt(runtimeContext) {
7024
7026
  const phase2Config = new Phase2Config();
7025
7027
  const hasGraphArtifactComponents = await this.hasGraphArtifactComponents();
7028
+ const conversationId = runtimeContext?.metadata?.conversationId || runtimeContext?.contextId;
7029
+ const resolvedContext = conversationId ? await this.getResolvedContext(conversationId) : null;
7030
+ let processedPrompt = this.config.agentPrompt;
7031
+ if (resolvedContext) {
7032
+ try {
7033
+ processedPrompt = agentsCore.TemplateEngine.render(this.config.agentPrompt, resolvedContext, {
7034
+ strict: false,
7035
+ preserveUnresolved: false
7036
+ });
7037
+ } catch (error) {
7038
+ logger15.error(
7039
+ {
7040
+ conversationId,
7041
+ error: error instanceof Error ? error.message : "Unknown error"
7042
+ },
7043
+ "Failed to process agent prompt with context for Phase 2, using original"
7044
+ );
7045
+ processedPrompt = this.config.agentPrompt;
7046
+ }
7047
+ }
7026
7048
  const referenceTaskIds = await agentsCore.listTaskIdsByContextId(dbClient_default)({
7027
7049
  contextId: this.conversationId || ""
7028
7050
  });
@@ -7038,6 +7060,7 @@ var Agent = class {
7038
7060
  referenceArtifacts.push(...artifacts);
7039
7061
  }
7040
7062
  return phase2Config.assemblePhase2Prompt({
7063
+ corePrompt: processedPrompt,
7041
7064
  dataComponents: this.config.dataComponents || [],
7042
7065
  artifactComponents: this.artifactComponents,
7043
7066
  hasArtifactComponents: this.artifactComponents && this.artifactComponents.length > 0,
@@ -7767,16 +7790,20 @@ ${output}${structureHintsFormatted}`;
7767
7790
  const phase2TimeoutMs = structuredModelSettings.maxDuration ? structuredModelSettings.maxDuration * 1e3 : CONSTANTS.PHASE_2_TIMEOUT_MS;
7768
7791
  const shouldStreamPhase2 = this.getStreamingHelper();
7769
7792
  if (shouldStreamPhase2) {
7793
+ const phase2Messages = [
7794
+ {
7795
+ role: "system",
7796
+ content: await this.buildPhase2SystemPrompt(runtimeContext)
7797
+ }
7798
+ ];
7799
+ if (conversationHistory.trim() !== "") {
7800
+ phase2Messages.push({ role: "user", content: conversationHistory });
7801
+ }
7802
+ phase2Messages.push({ role: "user", content: userMessage });
7803
+ phase2Messages.push(...reasoningFlow);
7770
7804
  const streamResult = ai.streamObject({
7771
7805
  ...structuredModelSettings,
7772
- messages: [
7773
- {
7774
- role: "system",
7775
- content: await this.buildPhase2SystemPrompt()
7776
- },
7777
- { role: "user", content: userMessage },
7778
- ...reasoningFlow
7779
- ],
7806
+ messages: phase2Messages,
7780
7807
  schema: z5.z.object({
7781
7808
  dataComponents: z5.z.array(dataComponentsSchema)
7782
7809
  }),
@@ -7834,14 +7861,18 @@ ${output}${structureHintsFormatted}`;
7834
7861
  textResponse = JSON.stringify(structuredResponse.object, null, 2);
7835
7862
  } else {
7836
7863
  const { withJsonPostProcessing: withJsonPostProcessing2 } = await Promise.resolve().then(() => (init_json_postprocessor(), json_postprocessor_exports));
7864
+ const phase2Messages = [
7865
+ { role: "system", content: await this.buildPhase2SystemPrompt(runtimeContext) }
7866
+ ];
7867
+ if (conversationHistory.trim() !== "") {
7868
+ phase2Messages.push({ role: "user", content: conversationHistory });
7869
+ }
7870
+ phase2Messages.push({ role: "user", content: userMessage });
7871
+ phase2Messages.push(...reasoningFlow);
7837
7872
  const structuredResponse = await ai.generateObject(
7838
7873
  withJsonPostProcessing2({
7839
7874
  ...structuredModelSettings,
7840
- messages: [
7841
- { role: "system", content: await this.buildPhase2SystemPrompt() },
7842
- { role: "user", content: userMessage },
7843
- ...reasoningFlow
7844
- ],
7875
+ messages: phase2Messages,
7845
7876
  schema: z5.z.object({
7846
7877
  dataComponents: z5.z.array(dataComponentsSchema)
7847
7878
  }),
@@ -9186,6 +9217,7 @@ var ExecutionHandler = class {
9186
9217
  id: taskId,
9187
9218
  tenantId,
9188
9219
  projectId,
9220
+ graphId,
9189
9221
  agentId: currentAgentId,
9190
9222
  contextId: conversationId,
9191
9223
  status: "pending",
package/dist/index.js CHANGED
@@ -346,6 +346,7 @@ async function handleMessageSend(c, agent, request) {
346
346
  id: task.id,
347
347
  tenantId: agent.tenantId,
348
348
  projectId: agent.projectId,
349
+ graphId: graphId || "",
349
350
  contextId: effectiveContextId,
350
351
  status: "working",
351
352
  metadata: {
@@ -5623,7 +5624,7 @@ ${propertiesXml}
5623
5624
  };
5624
5625
 
5625
5626
  // templates/v1/phase2/system-prompt.xml?raw
5626
- var system_prompt_default2 = "<phase2_system_message>\n <instruction>\n Generate the final structured JSON response using the configured data components and artifact creation capabilities.\n </instruction>\n\n {{ARTIFACTS_SECTION}}\n {{DATA_COMPONENTS_SECTION}}\n\n {{ARTIFACT_GUIDANCE_SECTION}}\n\n {{ARTIFACT_TYPES_SECTION}}\n\n <requirements>\n <key_requirements>\n - Create artifacts from tool results to support your information with citations\n - Mix artifact creation and references naturally throughout your dataComponents array\n - Each artifact creation must use EXACT tool_call_id from tool outputs\n - Use appropriate ArtifactCreate_[Type] components for each artifact type\n - IMPORTANT: In Text components, write naturally as if having a conversation - do NOT mention components, schemas, JSON, structured data, or any technical implementation details\n </key_requirements>\n </requirements>\n</phase2_system_message>";
5627
+ var system_prompt_default2 = "<phase2_system_message>\n <instruction>\n Generate the final structured JSON response using the configured data components and artifact creation capabilities.\n </instruction>\n\n <core_instructions>\n {{CORE_INSTRUCTIONS}}\n </core_instructions>\n\n {{ARTIFACTS_SECTION}}\n {{DATA_COMPONENTS_SECTION}}\n\n {{ARTIFACT_GUIDANCE_SECTION}}\n\n {{ARTIFACT_TYPES_SECTION}}\n\n <requirements>\n <key_requirements>\n - Create artifacts from tool results to support your information with citations\n - Mix artifact creation and references naturally throughout your dataComponents array\n - Each artifact creation must use EXACT tool_call_id from tool outputs\n - Use appropriate ArtifactCreate_[Type] components for each artifact type\n - IMPORTANT: In Text components, write naturally as if having a conversation - do NOT mention components, schemas, JSON, structured data, or any technical implementation details\n </key_requirements>\n </requirements>\n</phase2_system_message>";
5627
5628
 
5628
5629
  // templates/v1/phase2/data-components.xml?raw
5629
5630
  var data_components_default = '<data_components_section description="These are the data components available for you to use in generating responses. Each component represents a single structured piece of information. You can create multiple instances of the same component type when needed.\n\n***MANDATORY JSON RESPONSE FORMAT - ABSOLUTELY CRITICAL***:\n- WHEN DATA COMPONENTS ARE AVAILABLE, YOU MUST RESPOND IN JSON FORMAT ONLY\n- DO NOT respond with plain text when data components are defined\n- YOUR RESPONSE MUST BE STRUCTURED JSON WITH dataComponents ARRAY\n- THIS IS NON-NEGOTIABLE - JSON FORMAT IS REQUIRED\n\nCRITICAL JSON FORMATTING RULES - MUST FOLLOW EXACTLY:\n1. Each data component must include id, name, and props fields\n2. The id and name should match the exact component definition\n3. The props field contains the actual component data using exact property names from the schema\n4. NEVER omit the id and name fields\n\nCORRECT: [{\\"id\\": \\"component1\\", \\"name\\": \\"Component1\\", \\"props\\": {\\"field1\\": \\"value1\\", \\"field2\\": \\"value2\\"}}, {\\"id\\": \\"component2\\", \\"name\\": \\"Component2\\", \\"props\\": {\\"field3\\": \\"value3\\"}}]\nWRONG: [{\\"field1\\": \\"value1\\", \\"field2\\": \\"value2\\"}, {\\"field3\\": \\"value3\\"}]\n\nAVAILABLE DATA COMPONENTS: {{DATA_COMPONENTS_LIST}}">\n\n{{DATA_COMPONENTS_XML}}\n\n</data_components_section>';
@@ -5955,7 +5956,7 @@ ${artifact_retrieval_guidance_default}
5955
5956
  * Assemble the complete Phase 2 system prompt for structured output generation
5956
5957
  */
5957
5958
  assemblePhase2Prompt(config) {
5958
- const { dataComponents, artifactComponents, hasArtifactComponents, hasGraphArtifactComponents, artifacts = [] } = config;
5959
+ const { corePrompt, dataComponents, artifactComponents, hasArtifactComponents, hasGraphArtifactComponents, artifacts = [] } = config;
5959
5960
  let allDataComponents = [...dataComponents];
5960
5961
  if (hasArtifactComponents && artifactComponents) {
5961
5962
  const artifactCreateComponents = ArtifactCreateSchema.getDataComponents(
@@ -5973,6 +5974,7 @@ ${artifact_retrieval_guidance_default}
5973
5974
  const artifactGuidance = this.getStructuredArtifactGuidance(hasArtifactComponents, artifactComponents, shouldShowReferencingRules);
5974
5975
  const artifactTypes = this.getArtifactCreationInstructions(hasArtifactComponents, artifactComponents);
5975
5976
  let phase2Prompt = system_prompt_default2;
5977
+ phase2Prompt = phase2Prompt.replace("{{CORE_INSTRUCTIONS}}", corePrompt);
5976
5978
  phase2Prompt = phase2Prompt.replace("{{DATA_COMPONENTS_SECTION}}", dataComponentsSection);
5977
5979
  phase2Prompt = phase2Prompt.replace("{{ARTIFACTS_SECTION}}", artifactsSection);
5978
5980
  phase2Prompt = phase2Prompt.replace("{{ARTIFACT_GUIDANCE_SECTION}}", artifactGuidance);
@@ -6553,9 +6555,29 @@ var Agent = class {
6553
6555
  * Build adaptive system prompt for Phase 2 structured output generation
6554
6556
  * based on configured data components and artifact components across the graph
6555
6557
  */
6556
- async buildPhase2SystemPrompt() {
6558
+ async buildPhase2SystemPrompt(runtimeContext) {
6557
6559
  const phase2Config = new Phase2Config();
6558
6560
  const hasGraphArtifactComponents = await this.hasGraphArtifactComponents();
6561
+ const conversationId = runtimeContext?.metadata?.conversationId || runtimeContext?.contextId;
6562
+ const resolvedContext = conversationId ? await this.getResolvedContext(conversationId) : null;
6563
+ let processedPrompt = this.config.agentPrompt;
6564
+ if (resolvedContext) {
6565
+ try {
6566
+ processedPrompt = TemplateEngine.render(this.config.agentPrompt, resolvedContext, {
6567
+ strict: false,
6568
+ preserveUnresolved: false
6569
+ });
6570
+ } catch (error) {
6571
+ logger15.error(
6572
+ {
6573
+ conversationId,
6574
+ error: error instanceof Error ? error.message : "Unknown error"
6575
+ },
6576
+ "Failed to process agent prompt with context for Phase 2, using original"
6577
+ );
6578
+ processedPrompt = this.config.agentPrompt;
6579
+ }
6580
+ }
6559
6581
  const referenceTaskIds = await listTaskIdsByContextId(dbClient_default)({
6560
6582
  contextId: this.conversationId || ""
6561
6583
  });
@@ -6571,6 +6593,7 @@ var Agent = class {
6571
6593
  referenceArtifacts.push(...artifacts);
6572
6594
  }
6573
6595
  return phase2Config.assemblePhase2Prompt({
6596
+ corePrompt: processedPrompt,
6574
6597
  dataComponents: this.config.dataComponents || [],
6575
6598
  artifactComponents: this.artifactComponents,
6576
6599
  hasArtifactComponents: this.artifactComponents && this.artifactComponents.length > 0,
@@ -7300,16 +7323,20 @@ ${output}${structureHintsFormatted}`;
7300
7323
  const phase2TimeoutMs = structuredModelSettings.maxDuration ? structuredModelSettings.maxDuration * 1e3 : CONSTANTS.PHASE_2_TIMEOUT_MS;
7301
7324
  const shouldStreamPhase2 = this.getStreamingHelper();
7302
7325
  if (shouldStreamPhase2) {
7326
+ const phase2Messages = [
7327
+ {
7328
+ role: "system",
7329
+ content: await this.buildPhase2SystemPrompt(runtimeContext)
7330
+ }
7331
+ ];
7332
+ if (conversationHistory.trim() !== "") {
7333
+ phase2Messages.push({ role: "user", content: conversationHistory });
7334
+ }
7335
+ phase2Messages.push({ role: "user", content: userMessage });
7336
+ phase2Messages.push(...reasoningFlow);
7303
7337
  const streamResult = streamObject({
7304
7338
  ...structuredModelSettings,
7305
- messages: [
7306
- {
7307
- role: "system",
7308
- content: await this.buildPhase2SystemPrompt()
7309
- },
7310
- { role: "user", content: userMessage },
7311
- ...reasoningFlow
7312
- ],
7339
+ messages: phase2Messages,
7313
7340
  schema: z.object({
7314
7341
  dataComponents: z.array(dataComponentsSchema)
7315
7342
  }),
@@ -7367,14 +7394,18 @@ ${output}${structureHintsFormatted}`;
7367
7394
  textResponse = JSON.stringify(structuredResponse.object, null, 2);
7368
7395
  } else {
7369
7396
  const { withJsonPostProcessing } = await import('./json-postprocessor-VOMU4E5L.js');
7397
+ const phase2Messages = [
7398
+ { role: "system", content: await this.buildPhase2SystemPrompt(runtimeContext) }
7399
+ ];
7400
+ if (conversationHistory.trim() !== "") {
7401
+ phase2Messages.push({ role: "user", content: conversationHistory });
7402
+ }
7403
+ phase2Messages.push({ role: "user", content: userMessage });
7404
+ phase2Messages.push(...reasoningFlow);
7370
7405
  const structuredResponse = await generateObject(
7371
7406
  withJsonPostProcessing({
7372
7407
  ...structuredModelSettings,
7373
- messages: [
7374
- { role: "system", content: await this.buildPhase2SystemPrompt() },
7375
- { role: "user", content: userMessage },
7376
- ...reasoningFlow
7377
- ],
7408
+ messages: phase2Messages,
7378
7409
  schema: z.object({
7379
7410
  dataComponents: z.array(dataComponentsSchema)
7380
7411
  }),
@@ -8705,6 +8736,7 @@ var ExecutionHandler = class {
8705
8736
  id: taskId,
8706
8737
  tenantId,
8707
8738
  projectId,
8739
+ graphId,
8708
8740
  agentId: currentAgentId,
8709
8741
  contextId: conversationId,
8710
8742
  status: "pending",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inkeep/agents-run-api",
3
- "version": "0.10.1",
3
+ "version": "0.11.0",
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",
@@ -51,7 +51,7 @@
51
51
  "traverse": "^0.6.11",
52
52
  "ts-pattern": "^5.7.1",
53
53
  "zod": "^4.1.5",
54
- "@inkeep/agents-core": "^0.10.1"
54
+ "@inkeep/agents-core": "^0.11.0"
55
55
  },
56
56
  "optionalDependencies": {
57
57
  "keytar": "^7.9.0"
@@ -3,6 +3,10 @@
3
3
  Generate the final structured JSON response using the configured data components and artifact creation capabilities.
4
4
  </instruction>
5
5
 
6
+ <core_instructions>
7
+ {{CORE_INSTRUCTIONS}}
8
+ </core_instructions>
9
+
6
10
  {{ARTIFACTS_SECTION}}
7
11
  {{DATA_COMPONENTS_SECTION}}
8
12