@inkeep/agents-run-api 0.39.5 → 0.40.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/_virtual/_raw_/home/runner/work/agents/agents/agents-run-api/templates/v1/phase1/system-prompt.js +5 -0
- package/dist/_virtual/_raw_/home/runner/work/agents/agents/agents-run-api/templates/v1/phase1/thinking-preparation.js +5 -0
- package/dist/_virtual/_raw_/home/runner/work/agents/agents/agents-run-api/templates/v1/phase1/tool.js +5 -0
- package/dist/_virtual/_raw_/home/runner/work/agents/agents/agents-run-api/templates/v1/phase2/data-component.js +5 -0
- package/dist/_virtual/_raw_/home/runner/work/agents/agents/agents-run-api/templates/v1/phase2/data-components.js +5 -0
- package/dist/_virtual/_raw_/home/runner/work/agents/agents/agents-run-api/templates/v1/phase2/system-prompt.js +5 -0
- package/dist/_virtual/_raw_/home/runner/work/agents/agents/agents-run-api/templates/v1/shared/artifact-retrieval-guidance.js +5 -0
- package/dist/_virtual/_raw_/home/runner/work/agents/agents/agents-run-api/templates/v1/shared/artifact.js +5 -0
- package/dist/a2a/client.d.ts +184 -0
- package/dist/a2a/client.js +510 -0
- package/dist/a2a/handlers.d.ts +7 -0
- package/dist/a2a/handlers.js +560 -0
- package/dist/a2a/transfer.d.ts +22 -0
- package/dist/a2a/transfer.js +46 -0
- package/dist/a2a/types.d.ts +79 -0
- package/dist/a2a/types.js +22 -0
- package/dist/agents/Agent.d.ts +266 -0
- package/dist/agents/Agent.js +1927 -0
- package/dist/agents/ModelFactory.d.ts +63 -0
- package/dist/agents/ModelFactory.js +194 -0
- package/dist/agents/SystemPromptBuilder.d.ts +21 -0
- package/dist/agents/SystemPromptBuilder.js +48 -0
- package/dist/agents/ToolSessionManager.d.ts +63 -0
- package/dist/agents/ToolSessionManager.js +146 -0
- package/dist/agents/generateTaskHandler.d.ts +49 -0
- package/dist/agents/generateTaskHandler.js +521 -0
- package/dist/agents/relationTools.d.ts +57 -0
- package/dist/agents/relationTools.js +262 -0
- package/dist/agents/types.d.ts +28 -0
- package/dist/agents/types.js +1 -0
- package/dist/agents/versions/v1/Phase1Config.d.ts +27 -0
- package/dist/agents/versions/v1/Phase1Config.js +424 -0
- package/dist/agents/versions/v1/Phase2Config.d.ts +31 -0
- package/dist/agents/versions/v1/Phase2Config.js +330 -0
- package/dist/constants/execution-limits/defaults.d.ts +51 -0
- package/dist/constants/execution-limits/defaults.js +52 -0
- package/dist/constants/execution-limits/index.d.ts +6 -0
- package/dist/constants/execution-limits/index.js +21 -0
- package/dist/create-app.d.ts +9 -0
- package/dist/create-app.js +195 -0
- package/dist/data/agent.d.ts +7 -0
- package/dist/data/agent.js +72 -0
- package/dist/data/agents.d.ts +34 -0
- package/dist/data/agents.js +139 -0
- package/dist/data/conversations.d.ts +128 -0
- package/dist/data/conversations.js +522 -0
- package/dist/data/db/dbClient.d.ts +6 -0
- package/dist/data/db/dbClient.js +17 -0
- package/dist/env.d.ts +57 -0
- package/dist/env.js +1 -2
- package/dist/handlers/executionHandler.d.ts +39 -0
- package/dist/handlers/executionHandler.js +456 -0
- package/dist/index.d.ts +8 -29
- package/dist/index.js +5 -11386
- package/dist/instrumentation.d.ts +1 -2
- package/dist/instrumentation.js +66 -3
- package/dist/{logger2.js → logger.d.ts} +1 -2
- package/dist/logger.js +1 -1
- package/dist/middleware/api-key-auth.d.ts +26 -0
- package/dist/middleware/api-key-auth.js +240 -0
- package/dist/middleware/index.d.ts +2 -0
- package/dist/middleware/index.js +3 -0
- package/dist/openapi.d.ts +4 -0
- package/dist/openapi.js +54 -0
- package/dist/routes/agents.d.ts +12 -0
- package/dist/routes/agents.js +147 -0
- package/dist/routes/chat.d.ts +13 -0
- package/dist/routes/chat.js +293 -0
- package/dist/routes/chatDataStream.d.ts +13 -0
- package/dist/routes/chatDataStream.js +352 -0
- package/dist/routes/mcp.d.ts +13 -0
- package/dist/routes/mcp.js +495 -0
- package/dist/services/AgentSession.d.ts +356 -0
- package/dist/services/AgentSession.js +1208 -0
- package/dist/services/ArtifactParser.d.ts +105 -0
- package/dist/services/ArtifactParser.js +338 -0
- package/dist/services/ArtifactService.d.ts +123 -0
- package/dist/services/ArtifactService.js +612 -0
- package/dist/services/BaseCompressor.d.ts +183 -0
- package/dist/services/BaseCompressor.js +504 -0
- package/dist/services/ConversationCompressor.d.ts +32 -0
- package/dist/services/ConversationCompressor.js +91 -0
- package/dist/services/IncrementalStreamParser.d.ts +98 -0
- package/dist/services/IncrementalStreamParser.js +327 -0
- package/dist/services/MidGenerationCompressor.d.ts +63 -0
- package/dist/services/MidGenerationCompressor.js +104 -0
- package/dist/services/PendingToolApprovalManager.d.ts +62 -0
- package/dist/services/PendingToolApprovalManager.js +133 -0
- package/dist/services/ResponseFormatter.d.ts +39 -0
- package/dist/services/ResponseFormatter.js +152 -0
- package/dist/tools/NativeSandboxExecutor.d.ts +38 -0
- package/dist/tools/NativeSandboxExecutor.js +432 -0
- package/dist/tools/SandboxExecutorFactory.d.ts +36 -0
- package/dist/tools/SandboxExecutorFactory.js +80 -0
- package/dist/tools/VercelSandboxExecutor.d.ts +71 -0
- package/dist/tools/VercelSandboxExecutor.js +340 -0
- package/dist/tools/distill-conversation-history-tool.d.ts +62 -0
- package/dist/tools/distill-conversation-history-tool.js +206 -0
- package/dist/tools/distill-conversation-tool.d.ts +41 -0
- package/dist/tools/distill-conversation-tool.js +141 -0
- package/dist/tools/sandbox-utils.d.ts +18 -0
- package/dist/tools/sandbox-utils.js +53 -0
- package/dist/types/chat.d.ts +27 -0
- package/dist/types/chat.js +1 -0
- package/dist/types/execution-context.d.ts +46 -0
- package/dist/types/execution-context.js +27 -0
- package/dist/types/xml.d.ts +5 -0
- package/dist/utils/SchemaProcessor.d.ts +52 -0
- package/dist/utils/SchemaProcessor.js +182 -0
- package/dist/utils/agent-operations.d.ts +62 -0
- package/dist/utils/agent-operations.js +53 -0
- package/dist/utils/artifact-component-schema.d.ts +42 -0
- package/dist/utils/artifact-component-schema.js +186 -0
- package/dist/utils/cleanup.d.ts +21 -0
- package/dist/utils/cleanup.js +59 -0
- package/dist/utils/data-component-schema.d.ts +2 -0
- package/dist/utils/data-component-schema.js +3 -0
- package/dist/utils/default-status-schemas.d.ts +20 -0
- package/dist/utils/default-status-schemas.js +24 -0
- package/dist/utils/json-postprocessor.d.ts +13 -0
- package/dist/{json-postprocessor.cjs → utils/json-postprocessor.js} +1 -2
- package/dist/utils/model-context-utils.d.ts +39 -0
- package/dist/utils/model-context-utils.js +181 -0
- package/dist/utils/model-resolver.d.ts +6 -0
- package/dist/utils/model-resolver.js +34 -0
- package/dist/utils/schema-validation.d.ts +44 -0
- package/dist/utils/schema-validation.js +97 -0
- package/dist/utils/stream-helpers.d.ts +197 -0
- package/dist/utils/stream-helpers.js +518 -0
- package/dist/utils/stream-registry.d.ts +22 -0
- package/dist/utils/stream-registry.js +34 -0
- package/dist/utils/token-estimator.d.ts +69 -0
- package/dist/utils/token-estimator.js +53 -0
- package/dist/utils/tracer.d.ts +7 -0
- package/dist/utils/tracer.js +7 -0
- package/package.json +4 -20
- package/dist/SandboxExecutorFactory.cjs +0 -895
- package/dist/SandboxExecutorFactory.js +0 -893
- package/dist/SandboxExecutorFactory.js.map +0 -1
- package/dist/chunk-VBDAOXYI.cjs +0 -927
- package/dist/chunk-VBDAOXYI.js +0 -832
- package/dist/chunk-VBDAOXYI.js.map +0 -1
- package/dist/chunk.cjs +0 -34
- package/dist/conversations.cjs +0 -7
- package/dist/conversations.js +0 -7
- package/dist/conversations2.cjs +0 -209
- package/dist/conversations2.js +0 -180
- package/dist/conversations2.js.map +0 -1
- package/dist/dbClient.cjs +0 -9676
- package/dist/dbClient.js +0 -9670
- package/dist/dbClient.js.map +0 -1
- package/dist/dbClient2.cjs +0 -5
- package/dist/dbClient2.js +0 -5
- package/dist/env.cjs +0 -59
- package/dist/env.js.map +0 -1
- package/dist/execution-limits.cjs +0 -260
- package/dist/execution-limits.js +0 -63
- package/dist/execution-limits.js.map +0 -1
- package/dist/index.cjs +0 -11411
- package/dist/index.d.cts +0 -36
- package/dist/index.d.cts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/instrumentation.cjs +0 -12
- package/dist/instrumentation.d.cts +0 -18
- package/dist/instrumentation.d.cts.map +0 -1
- package/dist/instrumentation.d.ts.map +0 -1
- package/dist/instrumentation2.cjs +0 -116
- package/dist/instrumentation2.js +0 -69
- package/dist/instrumentation2.js.map +0 -1
- package/dist/json-postprocessor.js +0 -20
- package/dist/json-postprocessor.js.map +0 -1
- package/dist/logger.cjs +0 -5
- package/dist/logger2.cjs +0 -1
- package/dist/nodefs.cjs +0 -29
- package/dist/nodefs.js +0 -27
- package/dist/nodefs.js.map +0 -1
- package/dist/opfs-ahp.cjs +0 -367
- package/dist/opfs-ahp.js +0 -368
- package/dist/opfs-ahp.js.map +0 -1
|
@@ -0,0 +1,424 @@
|
|
|
1
|
+
import { getLogger } from "../../../logger.js";
|
|
2
|
+
import { calculateBreakdownTotal, createEmptyBreakdown, estimateTokens } from "../../../utils/token-estimator.js";
|
|
3
|
+
import system_prompt_default from "../../../_virtual/_raw_/home/runner/work/agents/agents/agents-run-api/templates/v1/phase1/system-prompt.js";
|
|
4
|
+
import thinking_preparation_default from "../../../_virtual/_raw_/home/runner/work/agents/agents/agents-run-api/templates/v1/phase1/thinking-preparation.js";
|
|
5
|
+
import tool_default from "../../../_virtual/_raw_/home/runner/work/agents/agents/agents-run-api/templates/v1/phase1/tool.js";
|
|
6
|
+
import artifact_default from "../../../_virtual/_raw_/home/runner/work/agents/agents/agents-run-api/templates/v1/shared/artifact.js";
|
|
7
|
+
import artifact_retrieval_guidance_default from "../../../_virtual/_raw_/home/runner/work/agents/agents/agents-run-api/templates/v1/shared/artifact-retrieval-guidance.js";
|
|
8
|
+
import { convertZodToJsonSchema, isZodSchema } from "@inkeep/agents-core/utils/schema-conversion";
|
|
9
|
+
|
|
10
|
+
//#region src/agents/versions/v1/Phase1Config.ts
|
|
11
|
+
getLogger("Phase1Config");
|
|
12
|
+
var Phase1Config = class Phase1Config {
|
|
13
|
+
loadTemplates() {
|
|
14
|
+
const templates = /* @__PURE__ */ new Map();
|
|
15
|
+
templates.set("system-prompt", system_prompt_default);
|
|
16
|
+
templates.set("tool", tool_default);
|
|
17
|
+
templates.set("artifact", artifact_default);
|
|
18
|
+
templates.set("artifact-retrieval-guidance", artifact_retrieval_guidance_default);
|
|
19
|
+
templates.set("thinking-preparation", thinking_preparation_default);
|
|
20
|
+
return templates;
|
|
21
|
+
}
|
|
22
|
+
static convertMcpToolsToToolData(mcpTools) {
|
|
23
|
+
if (!mcpTools || mcpTools.length === 0) return [];
|
|
24
|
+
const toolData = [];
|
|
25
|
+
for (const mcpTool of mcpTools) if (mcpTool.availableTools) for (const toolDef of mcpTool.availableTools) toolData.push({
|
|
26
|
+
name: toolDef.name,
|
|
27
|
+
description: toolDef.description || "No description available",
|
|
28
|
+
inputSchema: toolDef.inputSchema || {},
|
|
29
|
+
usageGuidelines: `Use this tool from ${mcpTool.name} server when appropriate.`
|
|
30
|
+
});
|
|
31
|
+
return toolData;
|
|
32
|
+
}
|
|
33
|
+
isToolDataArray(tools) {
|
|
34
|
+
if (!tools || tools.length === 0) return true;
|
|
35
|
+
const firstItem = tools[0];
|
|
36
|
+
return "usageGuidelines" in firstItem && !("config" in firstItem);
|
|
37
|
+
}
|
|
38
|
+
normalizeSchema(inputSchema) {
|
|
39
|
+
if (!inputSchema || typeof inputSchema !== "object") return inputSchema || {};
|
|
40
|
+
if (isZodSchema(inputSchema)) try {
|
|
41
|
+
return convertZodToJsonSchema(inputSchema);
|
|
42
|
+
} catch (error) {
|
|
43
|
+
return {};
|
|
44
|
+
}
|
|
45
|
+
return inputSchema;
|
|
46
|
+
}
|
|
47
|
+
assemble(templates, config) {
|
|
48
|
+
const breakdown = createEmptyBreakdown();
|
|
49
|
+
const systemPromptTemplateContent = templates.get("system-prompt");
|
|
50
|
+
if (!systemPromptTemplateContent) throw new Error("System prompt template not loaded");
|
|
51
|
+
breakdown.systemPromptTemplate = estimateTokens(systemPromptTemplateContent.replace("{{CORE_INSTRUCTIONS}}", "").replace("{{AGENT_CONTEXT_SECTION}}", "").replace("{{ARTIFACTS_SECTION}}", "").replace("{{TOOLS_SECTION}}", "").replace("{{THINKING_PREPARATION_INSTRUCTIONS}}", "").replace("{{TRANSFER_INSTRUCTIONS}}", "").replace("{{DELEGATION_INSTRUCTIONS}}", ""));
|
|
52
|
+
let systemPrompt = systemPromptTemplateContent;
|
|
53
|
+
if (config.corePrompt && config.corePrompt.trim()) {
|
|
54
|
+
breakdown.coreInstructions = estimateTokens(config.corePrompt);
|
|
55
|
+
systemPrompt = systemPrompt.replace("{{CORE_INSTRUCTIONS}}", config.corePrompt);
|
|
56
|
+
} else systemPrompt = systemPrompt.replace(/<core_instructions>\s*\{\{CORE_INSTRUCTIONS\}\}\s*<\/core_instructions>/g, "");
|
|
57
|
+
const agentContextSection = this.generateAgentContextSection(config.prompt);
|
|
58
|
+
breakdown.agentPrompt = estimateTokens(agentContextSection);
|
|
59
|
+
systemPrompt = systemPrompt.replace("{{AGENT_CONTEXT_SECTION}}", agentContextSection);
|
|
60
|
+
const toolData = (this.isToolDataArray(config.tools) ? config.tools : Phase1Config.convertMcpToolsToToolData(config.tools)).map((tool) => ({
|
|
61
|
+
...tool,
|
|
62
|
+
inputSchema: this.normalizeSchema(tool.inputSchema)
|
|
63
|
+
}));
|
|
64
|
+
const hasArtifactComponents = Boolean(config.artifactComponents && config.artifactComponents.length > 0);
|
|
65
|
+
const artifactsSection = this.generateArtifactsSection(templates, config.artifacts, hasArtifactComponents, config.artifactComponents, config.hasAgentArtifactComponents);
|
|
66
|
+
const artifactInstructionsTokens = this.getArtifactInstructionsTokens(templates, hasArtifactComponents, config.artifactComponents, config.hasAgentArtifactComponents, (config.artifacts?.length ?? 0) > 0);
|
|
67
|
+
breakdown.systemPromptTemplate += artifactInstructionsTokens;
|
|
68
|
+
breakdown.artifactsSection = estimateTokens(config.artifacts?.length > 0 ? config.artifacts.map((artifact) => this.generateArtifactXml(templates, artifact)).join("\n ") : "");
|
|
69
|
+
if (hasArtifactComponents) breakdown.artifactComponents = estimateTokens(this.getArtifactCreationInstructions(hasArtifactComponents, config.artifactComponents));
|
|
70
|
+
systemPrompt = systemPrompt.replace("{{ARTIFACTS_SECTION}}", artifactsSection);
|
|
71
|
+
const toolsSection = this.generateToolsSection(templates, toolData);
|
|
72
|
+
breakdown.toolsSection = estimateTokens(toolsSection);
|
|
73
|
+
systemPrompt = systemPrompt.replace("{{TOOLS_SECTION}}", toolsSection);
|
|
74
|
+
const thinkingPreparationSection = this.generateThinkingPreparationSection(templates, config.isThinkingPreparation);
|
|
75
|
+
breakdown.thinkingPreparation = estimateTokens(thinkingPreparationSection);
|
|
76
|
+
systemPrompt = systemPrompt.replace("{{THINKING_PREPARATION_INSTRUCTIONS}}", thinkingPreparationSection);
|
|
77
|
+
const transferSection = this.generateTransferInstructions(config.hasTransferRelations);
|
|
78
|
+
breakdown.transferInstructions = estimateTokens(transferSection);
|
|
79
|
+
systemPrompt = systemPrompt.replace("{{TRANSFER_INSTRUCTIONS}}", transferSection);
|
|
80
|
+
const delegationSection = this.generateDelegationInstructions(config.hasDelegateRelations);
|
|
81
|
+
breakdown.delegationInstructions = estimateTokens(delegationSection);
|
|
82
|
+
systemPrompt = systemPrompt.replace("{{DELEGATION_INSTRUCTIONS}}", delegationSection);
|
|
83
|
+
calculateBreakdownTotal(breakdown);
|
|
84
|
+
return {
|
|
85
|
+
prompt: systemPrompt,
|
|
86
|
+
breakdown
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
generateAgentContextSection(prompt) {
|
|
90
|
+
if (!prompt || prompt.trim() === "") return "";
|
|
91
|
+
return `
|
|
92
|
+
<agent_context>
|
|
93
|
+
${prompt}
|
|
94
|
+
</agent_context>`;
|
|
95
|
+
}
|
|
96
|
+
generateThinkingPreparationSection(templates, isThinkingPreparation) {
|
|
97
|
+
if (!isThinkingPreparation) return "";
|
|
98
|
+
const thinkingPreparationTemplate = templates.get("thinking-preparation");
|
|
99
|
+
if (!thinkingPreparationTemplate) throw new Error("Thinking preparation template not loaded");
|
|
100
|
+
return thinkingPreparationTemplate;
|
|
101
|
+
}
|
|
102
|
+
generateTransferInstructions(hasTransferRelations) {
|
|
103
|
+
if (!hasTransferRelations) return "";
|
|
104
|
+
return `You are part of a single unified assistant composed of specialized agents. To the user, you must always appear as one continuous, confident voice.
|
|
105
|
+
|
|
106
|
+
You have transfer_to_* tools that seamlessly continue the conversation. When you determine another agent should handle a request: ONLY call the appropriate transfer_to_* tool. Do not provide any substantive answer, limitation, or explanation before transferring. NEVER announce, describe, or apologize for a transfer.
|
|
107
|
+
|
|
108
|
+
Do NOT stream any text when transferring - call the transfer tool IMMEDIATELY. Do NOT acknowledge the request, do NOT say "Looking into that...", "Let me search...", "I'll help you find...", or provide ANY explanatory text. Place all reasoning or handoff details inside the transfer tool call, not in the user message. The tool call is sufficient - no additional text should be generated.
|
|
109
|
+
|
|
110
|
+
CRITICAL: When you receive a user message that ends with "Please continue from where this conversation was left off" - this indicates you are continuing a conversation that another agent started. You should:
|
|
111
|
+
- Review the conversation history to see what was already communicated to the user
|
|
112
|
+
- Continue seamlessly from where the previous response left off
|
|
113
|
+
- Do NOT repeat what was already said in the conversation history
|
|
114
|
+
- Do NOT announce what you're about to do ("Let me search...", "I'll look for...", etc.)
|
|
115
|
+
- Proceed directly with the appropriate tool or action
|
|
116
|
+
- Act as if you have been handling the conversation from the beginning
|
|
117
|
+
|
|
118
|
+
When receiving any transfer, act as if you have been engaged from the start. Continue the same tone, context, and style. Never reference other agents, tools, or roles.
|
|
119
|
+
|
|
120
|
+
Your goal: preserve the illusion of a single, seamless, intelligent assistant. All user-facing behavior must feel like one continuous conversation, regardless of internal transfers.
|
|
121
|
+
`;
|
|
122
|
+
}
|
|
123
|
+
generateDelegationInstructions(hasDelegateRelations) {
|
|
124
|
+
if (!hasDelegateRelations) return "";
|
|
125
|
+
return `- You have delegate_to_* tools that perform specialized tasks
|
|
126
|
+
- Treat these exactly like other tools - call them to get results
|
|
127
|
+
- Present results as YOUR work: "I found", "I've analyzed"
|
|
128
|
+
- NEVER say you're delegating or that another agent helped`;
|
|
129
|
+
}
|
|
130
|
+
getArtifactInstructionsTokens(templates, hasArtifactComponents, artifactComponents, hasAgentArtifactComponents, hasArtifacts) {
|
|
131
|
+
const shouldShowReferencingRules = hasAgentArtifactComponents || hasArtifacts;
|
|
132
|
+
const rules = this.getArtifactReferencingRules(hasArtifactComponents, templates, shouldShowReferencingRules);
|
|
133
|
+
return estimateTokens(`<available_artifacts description="${hasArtifacts ? "These are the artifacts available for you to use in generating responses." : "No artifacts are currently available, but you may create them during execution."}
|
|
134
|
+
|
|
135
|
+
${rules}
|
|
136
|
+
|
|
137
|
+
"></available_artifacts>`);
|
|
138
|
+
}
|
|
139
|
+
getArtifactCreationGuidance() {
|
|
140
|
+
return `🚨 MANDATORY ARTIFACT CREATION 🚨
|
|
141
|
+
You MUST create artifacts from tool results to provide citations. This is REQUIRED, not optional.
|
|
142
|
+
Every piece of information from tools MUST be backed by an artifact creation.
|
|
143
|
+
|
|
144
|
+
CRITICAL CITATION REQUIREMENTS FOR AGENTS WITH CREATION ABILITY:
|
|
145
|
+
- Information FROM tool results = MUST create artifact citation
|
|
146
|
+
- Information BASED ON tool results = MUST create artifact citation
|
|
147
|
+
- Analysis OF tool results = MUST create artifact citation
|
|
148
|
+
- Summaries OF tool results = MUST create artifact citation
|
|
149
|
+
- NO INFORMATION from tool results can be presented without creating artifact citation
|
|
150
|
+
|
|
151
|
+
CRITICAL: ARTIFACTS MUST BE CREATED FIRST
|
|
152
|
+
You MUST create an artifact before you can reference it. You cannot reference artifacts that don't exist yet.
|
|
153
|
+
|
|
154
|
+
CRITICAL CITATION PRINCIPLE:
|
|
155
|
+
Creating an artifact IS a citation. Only reference again when citing the SAME artifact for a different statement.
|
|
156
|
+
|
|
157
|
+
CRITICAL: ALWAYS SELECT SINGLE ITEMS, NEVER ARRAYS
|
|
158
|
+
|
|
159
|
+
SELECTOR REQUIREMENTS:
|
|
160
|
+
- MUST select ONE specific item, never an array
|
|
161
|
+
- Use filtering: result.items[?title=='API Guide']
|
|
162
|
+
- Use exact matching: result.documents[?name=='Setup Instructions']
|
|
163
|
+
- Target specific fields: result.content[?section=='authentication']
|
|
164
|
+
|
|
165
|
+
CRITICAL: SELECTOR HIERARCHY
|
|
166
|
+
- base_selector: Points to ONE specific item in the tool result
|
|
167
|
+
- details_selector: Contains JMESPath selectors RELATIVE to the base selector
|
|
168
|
+
- Example: If base="result.documents[?type=='api']" then details_selector uses "title" not "documents[0].title"
|
|
169
|
+
|
|
170
|
+
COMMON FAILURE POINTS (AVOID THESE):
|
|
171
|
+
1. **Array Selection**: result.items (returns array) ❌
|
|
172
|
+
→ Fix: result.items[?type=='guide'] (returns single item) ✅
|
|
173
|
+
|
|
174
|
+
2. **Similar Key Names**: "title" vs "name" vs "heading"
|
|
175
|
+
→ Always check the actual field names in tool results
|
|
176
|
+
|
|
177
|
+
3. **Repeated Keys**: Multiple items with same "title" field
|
|
178
|
+
→ Use more specific filters: [?title=='Guide' && section=='setup']
|
|
179
|
+
|
|
180
|
+
4. **Case Sensitivity**: 'Guide' vs 'guide'
|
|
181
|
+
→ Match exact case from tool results
|
|
182
|
+
|
|
183
|
+
5. **Missing Nested Levels**: "content.text" when it's "body.content.text"
|
|
184
|
+
→ Include all intermediate levels`;
|
|
185
|
+
}
|
|
186
|
+
getArtifactReferencingRules(hasArtifactComponents = false, templates, shouldShowReferencingRules = true) {
|
|
187
|
+
if (!shouldShowReferencingRules) return "";
|
|
188
|
+
const sharedGuidance = templates?.get("artifact-retrieval-guidance") || "";
|
|
189
|
+
if (hasArtifactComponents) return `${sharedGuidance}
|
|
190
|
+
|
|
191
|
+
ARTIFACT MANAGEMENT FOR TEXT RESPONSES:
|
|
192
|
+
|
|
193
|
+
You will create and reference artifacts using inline annotations in your text response.
|
|
194
|
+
|
|
195
|
+
CREATING ARTIFACTS (SERVES AS CITATION):
|
|
196
|
+
Use the artifact:create annotation to extract data from tool results. The creation itself serves as a citation.
|
|
197
|
+
Format: <artifact:create id="unique-id" tool="tool_call_id" type="TypeName" base="selector.path" details='{"key":"jmespath_selector"}' />
|
|
198
|
+
|
|
199
|
+
⚠️ IMPORTANT: Do not create artifacts from get_reference_artifact tool results - these are already compressed artifacts being retrieved. Only create artifacts from original research and analysis tools.
|
|
200
|
+
|
|
201
|
+
🚨 CRITICAL: DETAILS PROPS USE JMESPATH SELECTORS, NOT LITERAL VALUES! 🚨
|
|
202
|
+
|
|
203
|
+
❌ WRONG - Using literal values:
|
|
204
|
+
details='{"title":"API Documentation","type":"guide"}'
|
|
205
|
+
|
|
206
|
+
✅ CORRECT - Using JMESPath selectors (relative to base selector):
|
|
207
|
+
details='{"title":"metadata.title","doc_type":"document_type","description":"content.description","main_text":"content.text","author":"metadata.author"}'
|
|
208
|
+
|
|
209
|
+
The selectors extract actual field values from the data structure selected by your base selector.
|
|
210
|
+
|
|
211
|
+
THE details PROPERTY MUST CONTAIN JMESPATH SELECTORS THAT EXTRACT DATA FROM THE TOOL RESULT!
|
|
212
|
+
- details: Contains JMESPath selectors relative to the base selector that map to artifact schema fields
|
|
213
|
+
- These selectors are evaluated against the tool result to extract the actual values
|
|
214
|
+
- The system automatically determines which fields are preview vs full based on the artifact schema
|
|
215
|
+
- NEVER put literal values like "Inkeep" or "2023" - always use selectors like "metadata.company" or "founded_year"
|
|
216
|
+
|
|
217
|
+
🚫 FORBIDDEN JMESPATH PATTERNS:
|
|
218
|
+
❌ NEVER: [?title~'.*text.*'] (regex patterns with ~ operator)
|
|
219
|
+
❌ NEVER: [?field~'pattern.*'] (any ~ operator usage)
|
|
220
|
+
❌ NEVER: [?title~'Slack.*Discord.*'] (regex wildcards)
|
|
221
|
+
❌ NEVER: [?name~'https://.*'] (regex in URL matching)
|
|
222
|
+
❌ NEVER: [?text ~ contains(@, 'word')] (~ with @ operator)
|
|
223
|
+
❌ NEVER: contains(@, 'text') (@ operator usage)
|
|
224
|
+
❌ NEVER: [?field=="value"] (double quotes in filters)
|
|
225
|
+
❌ NEVER: [?field=='value'] (escaped quotes in filters)
|
|
226
|
+
❌ NEVER: [?field=='"'"'value'"'"'] (nightmare quote mixing)
|
|
227
|
+
❌ NEVER: result.items[?type=='doc'][?status=='active'] (chained filters)
|
|
228
|
+
|
|
229
|
+
✅ CORRECT JMESPATH SYNTAX:
|
|
230
|
+
✅ [?contains(title, 'text')] (contains function)
|
|
231
|
+
✅ [?title=='exact match'] (exact string matching)
|
|
232
|
+
✅ [?contains(title, 'Slack') && contains(title, 'Discord')] (compound conditions)
|
|
233
|
+
✅ [?starts_with(url, 'https://')] (starts_with function)
|
|
234
|
+
✅ [?type=='doc' && status=='active'] (single filter with &&)
|
|
235
|
+
✅ [?contains(text, 'Founder')] (contains haystack, needle format)
|
|
236
|
+
✅ source.content[?contains(text, 'Founder')].text (correct filter usage)
|
|
237
|
+
|
|
238
|
+
🚨 MANDATORY QUOTE PATTERN - FOLLOW EXACTLY:
|
|
239
|
+
- ALWAYS: base="path[?field=='value']" (double quotes outside, single inside)
|
|
240
|
+
- This is the ONLY allowed pattern - any other pattern WILL FAIL
|
|
241
|
+
- NEVER escape quotes, NEVER mix quote types, NEVER use complex quoting
|
|
242
|
+
|
|
243
|
+
🚨 CRITICAL: EXAMINE TOOL RESULTS BEFORE CREATING SELECTORS! 🚨
|
|
244
|
+
|
|
245
|
+
STEP 1: INSPECT THE ACTUAL DATA FIRST
|
|
246
|
+
- ALWAYS look at the tool result data before creating any selectors
|
|
247
|
+
- Check _structureHints.exampleSelectors for real working paths that you can copy
|
|
248
|
+
- Look at what titles, record_types, and field names actually exist in the data
|
|
249
|
+
- Don't assume field names or values based on the user's question
|
|
250
|
+
|
|
251
|
+
STEP 2: USE STRUCTURE HINTS AS YOUR SELECTOR GUIDE
|
|
252
|
+
- The _structureHints.exampleSelectors show you exactly what selectors work with this data
|
|
253
|
+
- Copy and modify the patterns from exampleSelectors that target your needed data
|
|
254
|
+
- Use the commonFields list to see what field names are available
|
|
255
|
+
- Follow the exact path structure indicated by the hints
|
|
256
|
+
|
|
257
|
+
STEP 3: MATCH ACTUAL VALUES, NOT ASSUMPTIONS
|
|
258
|
+
- Look for real titles in the data like "Inkeep", "Team", "About Us", "API Guide"
|
|
259
|
+
- Check actual record_type values like "site", "documentation", "blog"
|
|
260
|
+
- Use exact matches from the real data structure, not guessed patterns
|
|
261
|
+
- If looking for team info, it might be in a document titled "Inkeep" with record_type="site"
|
|
262
|
+
|
|
263
|
+
STEP 4: VALIDATE YOUR SELECTORS AGAINST THE DATA
|
|
264
|
+
- Your base selector must match actual documents in the result
|
|
265
|
+
- Test your logic: does result.structuredContent.content contain items with your target values?
|
|
266
|
+
- Use compound conditions when needed: [?title=='Inkeep' && record_type=='site']
|
|
267
|
+
|
|
268
|
+
EXAMPLE PATTERNS FOR BASE SELECTORS:
|
|
269
|
+
❌ WRONG: result.items[?contains(title, "guide")] (assumes field values + wrong quotes)
|
|
270
|
+
❌ WRONG: result.data[?type=="document"] (double quotes invalid in JMESPath)
|
|
271
|
+
✅ CORRECT: result.structuredContent.content[0] (select first item)
|
|
272
|
+
✅ CORRECT: result.items[?type=='document'][0] (filter by type, single quotes!)
|
|
273
|
+
✅ CORRECT: result.data[?category=='api'][0] (filter by category)
|
|
274
|
+
✅ CORRECT: result.documents[?status=='published'][0] (filter by status)
|
|
275
|
+
|
|
276
|
+
REFERENCING ARTIFACTS (WHEN CITING AGAIN):
|
|
277
|
+
Only use artifact:ref when you need to cite the SAME artifact again for a different statement or context.
|
|
278
|
+
Format: <artifact:ref id="artifact-id" tool="tool_call_id" />
|
|
279
|
+
|
|
280
|
+
EXAMPLE TEXT RESPONSE:
|
|
281
|
+
"I found the authentication documentation. <artifact:create id='auth-doc-1' tool='call_xyz789' type='APIDoc' base="result.documents[?type=='auth']" details='{"title":"metadata.title","endpoint":"api.endpoint","description":"content.description","parameters":"spec.parameters","examples":"examples.sample_code"}' /> The documentation explains OAuth 2.0 implementation in detail.
|
|
282
|
+
|
|
283
|
+
The process involves three main steps: registration, token exchange, and API calls. As mentioned in the authentication documentation <artifact:ref id='auth-doc-1' tool='call_xyz789' />, you'll need to register your application first."
|
|
284
|
+
|
|
285
|
+
${this.getArtifactCreationGuidance()}
|
|
286
|
+
|
|
287
|
+
ARTIFACT ANNOTATION PLACEMENT:
|
|
288
|
+
- ALWAYS place annotations AFTER complete sentences and punctuation
|
|
289
|
+
- Never interrupt the flow of a sentence with an annotation
|
|
290
|
+
- Complete your thought, add punctuation, then place the annotation
|
|
291
|
+
- This ensures professional, readable responses
|
|
292
|
+
|
|
293
|
+
IMPORTANT GUIDELINES:
|
|
294
|
+
- Create artifacts inline as you discuss the information
|
|
295
|
+
- Use exact tool_call_id from tool execution results
|
|
296
|
+
- Each artifact:create establishes a citable source
|
|
297
|
+
- Use artifact:ref for subsequent references to the same artifact
|
|
298
|
+
- Annotations are automatically converted to interactive elements`;
|
|
299
|
+
if (!hasArtifactComponents) return `${sharedGuidance}
|
|
300
|
+
|
|
301
|
+
ARTIFACT REFERENCING FOR TEXT RESPONSES:
|
|
302
|
+
|
|
303
|
+
You can reference existing artifacts but cannot create new ones.
|
|
304
|
+
|
|
305
|
+
HOW TO REFERENCE ARTIFACTS:
|
|
306
|
+
Use the artifact:ref annotation to reference existing artifacts.
|
|
307
|
+
Format: <artifact:ref id="artifact-id" tool="tool_call_id" />
|
|
308
|
+
|
|
309
|
+
EXAMPLE TEXT RESPONSE:
|
|
310
|
+
"Based on the authentication guide <artifact:ref id='existing-auth-guide' tool='call_previous456' /> that was previously collected, the API uses OAuth 2.0.
|
|
311
|
+
|
|
312
|
+
The implementation details show that you need to register your application first and obtain client credentials. <artifact:ref id='existing-impl-doc' tool='toolu_previous789' />
|
|
313
|
+
|
|
314
|
+
For error handling, you can refer to the comprehensive error documentation. <artifact:ref id='existing-error-doc' tool='call_previous012' /> This lists all possible authentication errors and their solutions."
|
|
315
|
+
|
|
316
|
+
EXAMPLE REFERENCING DELEGATION ARTIFACTS:
|
|
317
|
+
After receiving a delegation response with artifacts, reference them naturally:
|
|
318
|
+
|
|
319
|
+
"I've gathered the requested data for you. The analysis <artifact:ref id='analysis-results' tool='toolu_abc123' /> shows significant improvements across all metrics.
|
|
320
|
+
|
|
321
|
+
Looking at the detailed breakdown <artifact:ref id='performance-metrics' tool='toolu_def456' />, the processing time has decreased by 40% while maintaining accuracy."
|
|
322
|
+
|
|
323
|
+
IMPORTANT GUIDELINES:
|
|
324
|
+
- You can only reference artifacts that already exist or were returned from delegations
|
|
325
|
+
- Use artifact:ref annotations in your text with the exact artifactId and toolCallId
|
|
326
|
+
- References are automatically converted to interactive elements`;
|
|
327
|
+
return "";
|
|
328
|
+
}
|
|
329
|
+
getArtifactCreationInstructions(hasArtifactComponents, artifactComponents) {
|
|
330
|
+
if (!hasArtifactComponents || !artifactComponents || artifactComponents.length === 0) return "";
|
|
331
|
+
return `
|
|
332
|
+
AVAILABLE ARTIFACT TYPES:
|
|
333
|
+
|
|
334
|
+
${artifactComponents.map((ac) => {
|
|
335
|
+
let schemaDescription = "No schema defined";
|
|
336
|
+
if (ac.props?.properties) schemaDescription = `Fields: ${Object.entries(ac.props.properties).map(([key, value]) => {
|
|
337
|
+
const inPreview = value.inPreview ? " [PREVIEW]" : " [FULL]";
|
|
338
|
+
return `${key} (${value.description || value.type || "field"})${inPreview}`;
|
|
339
|
+
}).join(", ")}`;
|
|
340
|
+
return ` - "${ac.name}": ${ac.description || "No description available"}
|
|
341
|
+
${schemaDescription}`;
|
|
342
|
+
}).join("\n\n")}
|
|
343
|
+
|
|
344
|
+
🚨 CRITICAL: DETAILS PROPS MUST MATCH THE ARTIFACT SCHEMA! 🚨
|
|
345
|
+
- Only use property names that are defined in the artifact component schema above
|
|
346
|
+
- Do NOT make up arbitrary property names like "founders", "nick_details", "year"
|
|
347
|
+
- Each artifact type has specific fields defined in its schema
|
|
348
|
+
- Your JMESPath selectors must extract values for these exact schema-defined properties
|
|
349
|
+
- Example: If schema defines "title" and "url", use details='{"title":"title","url":"url"}' not made-up names
|
|
350
|
+
- The system will automatically determine which fields are preview vs full based on schema configuration
|
|
351
|
+
|
|
352
|
+
🚨 CRITICAL: USE EXACT ARTIFACT TYPE NAMES IN QUOTES! 🚨
|
|
353
|
+
- MUST use the exact type name shown in quotes above
|
|
354
|
+
- Copy the exact string between the quotes, including any capitalization
|
|
355
|
+
- The type= parameter in artifact:create MUST match exactly what is listed above
|
|
356
|
+
- Do NOT abbreviate, modify, or guess the type name
|
|
357
|
+
- Copy the exact quoted name from the "AVAILABLE ARTIFACT TYPES" list above`;
|
|
358
|
+
}
|
|
359
|
+
generateArtifactsSection(templates, artifacts, hasArtifactComponents = false, artifactComponents, hasAgentArtifactComponents) {
|
|
360
|
+
const shouldShowReferencingRules = hasAgentArtifactComponents || artifacts.length > 0;
|
|
361
|
+
const rules = this.getArtifactReferencingRules(hasArtifactComponents, templates, shouldShowReferencingRules);
|
|
362
|
+
const creationInstructions = this.getArtifactCreationInstructions(hasArtifactComponents, artifactComponents);
|
|
363
|
+
if (artifacts.length === 0) return `<available_artifacts description="No artifacts are currently available, but you may create them during execution.
|
|
364
|
+
|
|
365
|
+
${rules}
|
|
366
|
+
|
|
367
|
+
${creationInstructions}
|
|
368
|
+
|
|
369
|
+
"></available_artifacts>`;
|
|
370
|
+
return `<available_artifacts description="These are the artifacts available for you to use in generating responses.
|
|
371
|
+
|
|
372
|
+
${rules}
|
|
373
|
+
|
|
374
|
+
${creationInstructions}
|
|
375
|
+
|
|
376
|
+
">
|
|
377
|
+
${artifacts.map((artifact) => this.generateArtifactXml(templates, artifact)).join("\n ")}
|
|
378
|
+
</available_artifacts>`;
|
|
379
|
+
}
|
|
380
|
+
generateArtifactXml(templates, artifact) {
|
|
381
|
+
const artifactTemplate = templates.get("artifact");
|
|
382
|
+
if (!artifactTemplate) throw new Error("Artifact template not loaded");
|
|
383
|
+
let artifactXml = artifactTemplate;
|
|
384
|
+
const summaryData = artifact.parts?.map((part) => part.data?.summary).filter(Boolean) || [];
|
|
385
|
+
const artifactSummary = summaryData.length > 0 ? JSON.stringify(summaryData, null, 2) : "No summary data available";
|
|
386
|
+
artifactXml = artifactXml.replace("{{ARTIFACT_NAME}}", artifact.name || "");
|
|
387
|
+
artifactXml = artifactXml.replace("{{ARTIFACT_DESCRIPTION}}", artifact.description || "");
|
|
388
|
+
artifactXml = artifactXml.replace("{{TASK_ID}}", artifact.taskId || "");
|
|
389
|
+
artifactXml = artifactXml.replace("{{ARTIFACT_ID}}", artifact.artifactId || "");
|
|
390
|
+
artifactXml = artifactXml.replace("{{TOOL_CALL_ID}}", artifact.toolCallId || "unknown");
|
|
391
|
+
artifactXml = artifactXml.replace("{{ARTIFACT_SUMMARY}}", artifactSummary);
|
|
392
|
+
return artifactXml;
|
|
393
|
+
}
|
|
394
|
+
generateToolsSection(templates, tools) {
|
|
395
|
+
if (tools.length === 0) return "<available_tools description=\"No tools are currently available\"></available_tools>";
|
|
396
|
+
return `<available_tools description="These are the tools available for you to use to accomplish tasks">
|
|
397
|
+
${tools.map((tool) => this.generateToolXml(templates, tool)).join("\n ")}
|
|
398
|
+
</available_tools>`;
|
|
399
|
+
}
|
|
400
|
+
generateToolXml(templates, tool) {
|
|
401
|
+
const toolTemplate = templates.get("tool");
|
|
402
|
+
if (!toolTemplate) throw new Error("Tool template not loaded");
|
|
403
|
+
let toolXml = toolTemplate;
|
|
404
|
+
toolXml = toolXml.replace("{{TOOL_NAME}}", tool.name);
|
|
405
|
+
toolXml = toolXml.replace("{{TOOL_DESCRIPTION}}", tool.description || "No description available");
|
|
406
|
+
toolXml = toolXml.replace("{{TOOL_USAGE_GUIDELINES}}", tool.usageGuidelines || "Use this tool when appropriate.");
|
|
407
|
+
const parametersXml = this.generateParametersXml(tool.inputSchema);
|
|
408
|
+
toolXml = toolXml.replace("{{TOOL_PARAMETERS_SCHEMA}}", parametersXml);
|
|
409
|
+
return toolXml;
|
|
410
|
+
}
|
|
411
|
+
generateParametersXml(inputSchema) {
|
|
412
|
+
if (!inputSchema) return "<type>object</type>\n <properties>\n </properties>\n <required>[]</required>";
|
|
413
|
+
const schemaType = inputSchema.type || "object";
|
|
414
|
+
const properties = inputSchema.properties || {};
|
|
415
|
+
const required = inputSchema.required || [];
|
|
416
|
+
return `<type>${schemaType}</type>\n <properties>\n${Object.entries(properties).map(([key, value]) => {
|
|
417
|
+
const isRequired = required.includes(key);
|
|
418
|
+
return ` ${key}: {\n "type": "${value?.type || "string"}",\n "description": "${value?.description || "No description"}",\n "required": ${isRequired}\n }`;
|
|
419
|
+
}).join("\n")}\n </properties>\n <required>${JSON.stringify(required)}</required>`;
|
|
420
|
+
}
|
|
421
|
+
};
|
|
422
|
+
|
|
423
|
+
//#endregion
|
|
424
|
+
export { Phase1Config };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Artifact, ArtifactComponentApiInsert, ArtifactComponentApiSelect, DataComponentApiInsert } from "@inkeep/agents-core";
|
|
2
|
+
|
|
3
|
+
//#region src/agents/versions/v1/Phase2Config.d.ts
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Configuration for Phase 2 structured output generation
|
|
7
|
+
* Handles data components, artifact creation, and JSON formatting guidance
|
|
8
|
+
*/
|
|
9
|
+
declare class Phase2Config {
|
|
10
|
+
private getArtifactCreationGuidance;
|
|
11
|
+
private getStructuredArtifactGuidance;
|
|
12
|
+
private getArtifactCreationInstructions;
|
|
13
|
+
private generateDataComponentsSection;
|
|
14
|
+
private generateDataComponentXml;
|
|
15
|
+
private generateParametersXml;
|
|
16
|
+
private generateArtifactsSection;
|
|
17
|
+
private generateArtifactXml;
|
|
18
|
+
/**
|
|
19
|
+
* Assemble the complete Phase 2 system prompt for structured output generation
|
|
20
|
+
*/
|
|
21
|
+
assemblePhase2Prompt(config: {
|
|
22
|
+
corePrompt: string;
|
|
23
|
+
dataComponents: DataComponentApiInsert[];
|
|
24
|
+
artifactComponents?: Array<ArtifactComponentApiInsert | ArtifactComponentApiSelect>;
|
|
25
|
+
hasArtifactComponents: boolean;
|
|
26
|
+
hasAgentArtifactComponents?: boolean;
|
|
27
|
+
artifacts?: Artifact[];
|
|
28
|
+
}): string;
|
|
29
|
+
}
|
|
30
|
+
//#endregion
|
|
31
|
+
export { Phase2Config };
|