@inkeep/agents-run-api 0.10.1 → 0.10.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -6090,7 +6090,7 @@ ${propertiesXml}
6090
6090
  };
6091
6091
 
6092
6092
  // 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>";
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 <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
6094
 
6095
6095
  // templates/v1/phase2/data-components.xml?raw
6096
6096
  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 +6422,7 @@ ${artifact_retrieval_guidance_default}
6422
6422
  * Assemble the complete Phase 2 system prompt for structured output generation
6423
6423
  */
6424
6424
  assemblePhase2Prompt(config) {
6425
- const { dataComponents, artifactComponents, hasArtifactComponents, hasGraphArtifactComponents, artifacts = [] } = config;
6425
+ const { corePrompt, dataComponents, artifactComponents, hasArtifactComponents, hasGraphArtifactComponents, artifacts = [] } = config;
6426
6426
  let allDataComponents = [...dataComponents];
6427
6427
  if (hasArtifactComponents && artifactComponents) {
6428
6428
  const artifactCreateComponents = ArtifactCreateSchema.getDataComponents(
@@ -6440,6 +6440,7 @@ ${artifact_retrieval_guidance_default}
6440
6440
  const artifactGuidance = this.getStructuredArtifactGuidance(hasArtifactComponents, artifactComponents, shouldShowReferencingRules);
6441
6441
  const artifactTypes = this.getArtifactCreationInstructions(hasArtifactComponents, artifactComponents);
6442
6442
  let phase2Prompt = system_prompt_default2;
6443
+ phase2Prompt = phase2Prompt.replace("{{CORE_INSTRUCTIONS}}", corePrompt);
6443
6444
  phase2Prompt = phase2Prompt.replace("{{DATA_COMPONENTS_SECTION}}", dataComponentsSection);
6444
6445
  phase2Prompt = phase2Prompt.replace("{{ARTIFACTS_SECTION}}", artifactsSection);
6445
6446
  phase2Prompt = phase2Prompt.replace("{{ARTIFACT_GUIDANCE_SECTION}}", artifactGuidance);
@@ -7020,9 +7021,29 @@ var Agent = class {
7020
7021
  * Build adaptive system prompt for Phase 2 structured output generation
7021
7022
  * based on configured data components and artifact components across the graph
7022
7023
  */
7023
- async buildPhase2SystemPrompt() {
7024
+ async buildPhase2SystemPrompt(runtimeContext) {
7024
7025
  const phase2Config = new Phase2Config();
7025
7026
  const hasGraphArtifactComponents = await this.hasGraphArtifactComponents();
7027
+ const conversationId = runtimeContext?.metadata?.conversationId || runtimeContext?.contextId;
7028
+ const resolvedContext = conversationId ? await this.getResolvedContext(conversationId) : null;
7029
+ let processedPrompt = this.config.agentPrompt;
7030
+ if (resolvedContext) {
7031
+ try {
7032
+ processedPrompt = agentsCore.TemplateEngine.render(this.config.agentPrompt, resolvedContext, {
7033
+ strict: false,
7034
+ preserveUnresolved: false
7035
+ });
7036
+ } catch (error) {
7037
+ logger15.error(
7038
+ {
7039
+ conversationId,
7040
+ error: error instanceof Error ? error.message : "Unknown error"
7041
+ },
7042
+ "Failed to process agent prompt with context for Phase 2, using original"
7043
+ );
7044
+ processedPrompt = this.config.agentPrompt;
7045
+ }
7046
+ }
7026
7047
  const referenceTaskIds = await agentsCore.listTaskIdsByContextId(dbClient_default)({
7027
7048
  contextId: this.conversationId || ""
7028
7049
  });
@@ -7038,6 +7059,7 @@ var Agent = class {
7038
7059
  referenceArtifacts.push(...artifacts);
7039
7060
  }
7040
7061
  return phase2Config.assemblePhase2Prompt({
7062
+ corePrompt: processedPrompt,
7041
7063
  dataComponents: this.config.dataComponents || [],
7042
7064
  artifactComponents: this.artifactComponents,
7043
7065
  hasArtifactComponents: this.artifactComponents && this.artifactComponents.length > 0,
@@ -7767,16 +7789,20 @@ ${output}${structureHintsFormatted}`;
7767
7789
  const phase2TimeoutMs = structuredModelSettings.maxDuration ? structuredModelSettings.maxDuration * 1e3 : CONSTANTS.PHASE_2_TIMEOUT_MS;
7768
7790
  const shouldStreamPhase2 = this.getStreamingHelper();
7769
7791
  if (shouldStreamPhase2) {
7792
+ const phase2Messages = [
7793
+ {
7794
+ role: "system",
7795
+ content: await this.buildPhase2SystemPrompt(runtimeContext)
7796
+ }
7797
+ ];
7798
+ if (conversationHistory.trim() !== "") {
7799
+ phase2Messages.push({ role: "user", content: conversationHistory });
7800
+ }
7801
+ phase2Messages.push({ role: "user", content: userMessage });
7802
+ phase2Messages.push(...reasoningFlow);
7770
7803
  const streamResult = ai.streamObject({
7771
7804
  ...structuredModelSettings,
7772
- messages: [
7773
- {
7774
- role: "system",
7775
- content: await this.buildPhase2SystemPrompt()
7776
- },
7777
- { role: "user", content: userMessage },
7778
- ...reasoningFlow
7779
- ],
7805
+ messages: phase2Messages,
7780
7806
  schema: z5.z.object({
7781
7807
  dataComponents: z5.z.array(dataComponentsSchema)
7782
7808
  }),
@@ -7834,14 +7860,18 @@ ${output}${structureHintsFormatted}`;
7834
7860
  textResponse = JSON.stringify(structuredResponse.object, null, 2);
7835
7861
  } else {
7836
7862
  const { withJsonPostProcessing: withJsonPostProcessing2 } = await Promise.resolve().then(() => (init_json_postprocessor(), json_postprocessor_exports));
7863
+ const phase2Messages = [
7864
+ { role: "system", content: await this.buildPhase2SystemPrompt(runtimeContext) }
7865
+ ];
7866
+ if (conversationHistory.trim() !== "") {
7867
+ phase2Messages.push({ role: "user", content: conversationHistory });
7868
+ }
7869
+ phase2Messages.push({ role: "user", content: userMessage });
7870
+ phase2Messages.push(...reasoningFlow);
7837
7871
  const structuredResponse = await ai.generateObject(
7838
7872
  withJsonPostProcessing2({
7839
7873
  ...structuredModelSettings,
7840
- messages: [
7841
- { role: "system", content: await this.buildPhase2SystemPrompt() },
7842
- { role: "user", content: userMessage },
7843
- ...reasoningFlow
7844
- ],
7874
+ messages: phase2Messages,
7845
7875
  schema: z5.z.object({
7846
7876
  dataComponents: z5.z.array(dataComponentsSchema)
7847
7877
  }),
package/dist/index.js CHANGED
@@ -5623,7 +5623,7 @@ ${propertiesXml}
5623
5623
  };
5624
5624
 
5625
5625
  // 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>";
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 <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
5627
 
5628
5628
  // templates/v1/phase2/data-components.xml?raw
5629
5629
  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 +5955,7 @@ ${artifact_retrieval_guidance_default}
5955
5955
  * Assemble the complete Phase 2 system prompt for structured output generation
5956
5956
  */
5957
5957
  assemblePhase2Prompt(config) {
5958
- const { dataComponents, artifactComponents, hasArtifactComponents, hasGraphArtifactComponents, artifacts = [] } = config;
5958
+ const { corePrompt, dataComponents, artifactComponents, hasArtifactComponents, hasGraphArtifactComponents, artifacts = [] } = config;
5959
5959
  let allDataComponents = [...dataComponents];
5960
5960
  if (hasArtifactComponents && artifactComponents) {
5961
5961
  const artifactCreateComponents = ArtifactCreateSchema.getDataComponents(
@@ -5973,6 +5973,7 @@ ${artifact_retrieval_guidance_default}
5973
5973
  const artifactGuidance = this.getStructuredArtifactGuidance(hasArtifactComponents, artifactComponents, shouldShowReferencingRules);
5974
5974
  const artifactTypes = this.getArtifactCreationInstructions(hasArtifactComponents, artifactComponents);
5975
5975
  let phase2Prompt = system_prompt_default2;
5976
+ phase2Prompt = phase2Prompt.replace("{{CORE_INSTRUCTIONS}}", corePrompt);
5976
5977
  phase2Prompt = phase2Prompt.replace("{{DATA_COMPONENTS_SECTION}}", dataComponentsSection);
5977
5978
  phase2Prompt = phase2Prompt.replace("{{ARTIFACTS_SECTION}}", artifactsSection);
5978
5979
  phase2Prompt = phase2Prompt.replace("{{ARTIFACT_GUIDANCE_SECTION}}", artifactGuidance);
@@ -6553,9 +6554,29 @@ var Agent = class {
6553
6554
  * Build adaptive system prompt for Phase 2 structured output generation
6554
6555
  * based on configured data components and artifact components across the graph
6555
6556
  */
6556
- async buildPhase2SystemPrompt() {
6557
+ async buildPhase2SystemPrompt(runtimeContext) {
6557
6558
  const phase2Config = new Phase2Config();
6558
6559
  const hasGraphArtifactComponents = await this.hasGraphArtifactComponents();
6560
+ const conversationId = runtimeContext?.metadata?.conversationId || runtimeContext?.contextId;
6561
+ const resolvedContext = conversationId ? await this.getResolvedContext(conversationId) : null;
6562
+ let processedPrompt = this.config.agentPrompt;
6563
+ if (resolvedContext) {
6564
+ try {
6565
+ processedPrompt = TemplateEngine.render(this.config.agentPrompt, resolvedContext, {
6566
+ strict: false,
6567
+ preserveUnresolved: false
6568
+ });
6569
+ } catch (error) {
6570
+ logger15.error(
6571
+ {
6572
+ conversationId,
6573
+ error: error instanceof Error ? error.message : "Unknown error"
6574
+ },
6575
+ "Failed to process agent prompt with context for Phase 2, using original"
6576
+ );
6577
+ processedPrompt = this.config.agentPrompt;
6578
+ }
6579
+ }
6559
6580
  const referenceTaskIds = await listTaskIdsByContextId(dbClient_default)({
6560
6581
  contextId: this.conversationId || ""
6561
6582
  });
@@ -6571,6 +6592,7 @@ var Agent = class {
6571
6592
  referenceArtifacts.push(...artifacts);
6572
6593
  }
6573
6594
  return phase2Config.assemblePhase2Prompt({
6595
+ corePrompt: processedPrompt,
6574
6596
  dataComponents: this.config.dataComponents || [],
6575
6597
  artifactComponents: this.artifactComponents,
6576
6598
  hasArtifactComponents: this.artifactComponents && this.artifactComponents.length > 0,
@@ -7300,16 +7322,20 @@ ${output}${structureHintsFormatted}`;
7300
7322
  const phase2TimeoutMs = structuredModelSettings.maxDuration ? structuredModelSettings.maxDuration * 1e3 : CONSTANTS.PHASE_2_TIMEOUT_MS;
7301
7323
  const shouldStreamPhase2 = this.getStreamingHelper();
7302
7324
  if (shouldStreamPhase2) {
7325
+ const phase2Messages = [
7326
+ {
7327
+ role: "system",
7328
+ content: await this.buildPhase2SystemPrompt(runtimeContext)
7329
+ }
7330
+ ];
7331
+ if (conversationHistory.trim() !== "") {
7332
+ phase2Messages.push({ role: "user", content: conversationHistory });
7333
+ }
7334
+ phase2Messages.push({ role: "user", content: userMessage });
7335
+ phase2Messages.push(...reasoningFlow);
7303
7336
  const streamResult = streamObject({
7304
7337
  ...structuredModelSettings,
7305
- messages: [
7306
- {
7307
- role: "system",
7308
- content: await this.buildPhase2SystemPrompt()
7309
- },
7310
- { role: "user", content: userMessage },
7311
- ...reasoningFlow
7312
- ],
7338
+ messages: phase2Messages,
7313
7339
  schema: z.object({
7314
7340
  dataComponents: z.array(dataComponentsSchema)
7315
7341
  }),
@@ -7367,14 +7393,18 @@ ${output}${structureHintsFormatted}`;
7367
7393
  textResponse = JSON.stringify(structuredResponse.object, null, 2);
7368
7394
  } else {
7369
7395
  const { withJsonPostProcessing } = await import('./json-postprocessor-VOMU4E5L.js');
7396
+ const phase2Messages = [
7397
+ { role: "system", content: await this.buildPhase2SystemPrompt(runtimeContext) }
7398
+ ];
7399
+ if (conversationHistory.trim() !== "") {
7400
+ phase2Messages.push({ role: "user", content: conversationHistory });
7401
+ }
7402
+ phase2Messages.push({ role: "user", content: userMessage });
7403
+ phase2Messages.push(...reasoningFlow);
7370
7404
  const structuredResponse = await generateObject(
7371
7405
  withJsonPostProcessing({
7372
7406
  ...structuredModelSettings,
7373
- messages: [
7374
- { role: "system", content: await this.buildPhase2SystemPrompt() },
7375
- { role: "user", content: userMessage },
7376
- ...reasoningFlow
7377
- ],
7407
+ messages: phase2Messages,
7378
7408
  schema: z.object({
7379
7409
  dataComponents: z.array(dataComponentsSchema)
7380
7410
  }),
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.10.2",
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.10.2"
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