@salesforce/magen-mcp-workflow 0.0.1 → 0.0.3
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/common/graphConfig.d.ts +26 -0
- package/dist/{tools/utilities/inputExtraction/index.js → common/graphConfig.js} +2 -4
- package/dist/common/graphConfig.js.map +1 -0
- package/dist/common/metadata.d.ts +51 -10
- package/dist/common/metadata.js +9 -0
- package/dist/common/metadata.js.map +1 -1
- package/dist/execution/commandRunner.d.ts +28 -0
- package/dist/execution/commandRunner.js +162 -0
- package/dist/execution/commandRunner.js.map +1 -0
- package/dist/execution/index.d.ts +3 -0
- package/dist/execution/index.js +9 -0
- package/dist/execution/index.js.map +1 -0
- package/dist/execution/progressReporter.d.ts +33 -0
- package/dist/execution/progressReporter.js +58 -0
- package/dist/execution/progressReporter.js.map +1 -0
- package/dist/execution/types.d.ts +54 -0
- package/dist/execution/types.js +8 -0
- package/dist/execution/types.js.map +1 -0
- package/dist/index.d.ts +4 -2
- package/dist/index.js +5 -7
- package/dist/index.js.map +1 -1
- package/dist/nodes/abstractBaseNode.d.ts +29 -3
- package/dist/nodes/abstractBaseNode.js +26 -2
- package/dist/nodes/abstractBaseNode.js.map +1 -1
- package/dist/nodes/abstractToolNode.d.ts +5 -3
- package/dist/nodes/abstractToolNode.js +5 -3
- package/dist/nodes/abstractToolNode.js.map +1 -1
- package/dist/nodes/getUserInput/factory.js +2 -2
- package/dist/nodes/getUserInput/factory.js.map +1 -1
- package/dist/nodes/getUserInput/node.d.ts +19 -1
- package/dist/nodes/getUserInput/node.js +2 -2
- package/dist/nodes/getUserInput/node.js.map +1 -1
- package/dist/nodes/toolExecutor.d.ts +5 -4
- package/dist/nodes/toolExecutor.js +2 -2
- package/dist/nodes/toolExecutor.js.map +1 -1
- package/dist/routers/checkPropertiesFulfilledRouter.js +2 -2
- package/dist/routers/checkPropertiesFulfilledRouter.js.map +1 -1
- package/dist/services/abstractService.d.ts +5 -5
- package/dist/services/abstractService.js +5 -5
- package/dist/services/abstractService.js.map +1 -1
- package/dist/services/getInputService.d.ts +10 -2
- package/dist/services/getInputService.js +50 -15
- package/dist/services/getInputService.js.map +1 -1
- package/dist/services/inputExtractionService.d.ts +11 -2
- package/dist/services/inputExtractionService.js +94 -18
- package/dist/services/inputExtractionService.js.map +1 -1
- package/dist/tools/orchestrator/metadata.d.ts +49 -3
- package/dist/tools/orchestrator/metadata.js +31 -4
- package/dist/tools/orchestrator/metadata.js.map +1 -1
- package/dist/tools/orchestrator/orchestratorTool.d.ts +44 -3
- package/dist/tools/orchestrator/orchestratorTool.js +138 -13
- package/dist/tools/orchestrator/orchestratorTool.js.map +1 -1
- package/dist/tools/utilities/getInput/index.d.ts +0 -2
- package/dist/tools/utilities/getInput/index.js +0 -2
- package/dist/tools/utilities/getInput/index.js.map +1 -1
- package/dist/tools/utilities/getInput/metadata.d.ts +2 -68
- package/dist/tools/utilities/getInput/metadata.js +2 -30
- package/dist/tools/utilities/getInput/metadata.js.map +1 -1
- package/dist/tools/utilities/index.d.ts +0 -1
- package/dist/tools/utilities/index.js +0 -1
- package/dist/tools/utilities/index.js.map +1 -1
- package/dist/utils/toolExecutionUtils.d.ts +6 -6
- package/dist/utils/toolExecutionUtils.js +7 -7
- package/dist/utils/toolExecutionUtils.js.map +1 -1
- package/package.json +3 -3
- package/dist/tools/utilities/getInput/factory.d.ts +0 -43
- package/dist/tools/utilities/getInput/factory.js +0 -32
- package/dist/tools/utilities/getInput/factory.js.map +0 -1
- package/dist/tools/utilities/getInput/tool.d.ts +0 -89
- package/dist/tools/utilities/getInput/tool.js +0 -69
- package/dist/tools/utilities/getInput/tool.js.map +0 -1
- package/dist/tools/utilities/inputExtraction/factory.d.ts +0 -43
- package/dist/tools/utilities/inputExtraction/factory.js +0 -32
- package/dist/tools/utilities/inputExtraction/factory.js.map +0 -1
- package/dist/tools/utilities/inputExtraction/index.d.ts +0 -3
- package/dist/tools/utilities/inputExtraction/index.js.map +0 -1
- package/dist/tools/utilities/inputExtraction/metadata.d.ts +0 -66
- package/dist/tools/utilities/inputExtraction/metadata.js +0 -52
- package/dist/tools/utilities/inputExtraction/metadata.js.map +0 -1
- package/dist/tools/utilities/inputExtraction/tool.d.ts +0 -82
- package/dist/tools/utilities/inputExtraction/tool.js +0 -71
- package/dist/tools/utilities/inputExtraction/tool.js.map +0 -1
|
@@ -5,14 +5,13 @@
|
|
|
5
5
|
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
6
6
|
*/
|
|
7
7
|
import z from 'zod';
|
|
8
|
-
import { zodToJsonSchema } from 'zod-to-json-schema';
|
|
9
8
|
import { AbstractService } from './abstractService.js';
|
|
10
|
-
import { createInputExtractionMetadata, } from '../tools/utilities/index.js';
|
|
11
9
|
/**
|
|
12
10
|
* Service for extracting structured properties from user input.
|
|
13
11
|
*
|
|
14
|
-
* This service
|
|
15
|
-
*
|
|
12
|
+
* This service uses direct guidance mode (NodeGuidanceData) to have the orchestrator
|
|
13
|
+
* generate property extraction prompts directly, eliminating the need for an
|
|
14
|
+
* intermediate tool call.
|
|
16
15
|
*/
|
|
17
16
|
export class InputExtractionService extends AbstractService {
|
|
18
17
|
toolId;
|
|
@@ -34,21 +33,20 @@ export class InputExtractionService extends AbstractService {
|
|
|
34
33
|
});
|
|
35
34
|
const propertiesToExtract = this.preparePropertiesForExtraction(properties);
|
|
36
35
|
const resultSchema = this.preparePropertyResultsSchema(properties);
|
|
37
|
-
|
|
38
|
-
const
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
},
|
|
36
|
+
// Build a concrete example based on the actual properties being requested
|
|
37
|
+
const exampleProperties = propertiesToExtract.reduce((acc, prop) => {
|
|
38
|
+
acc[prop.propertyName] = `<extracted ${prop.propertyName} value or null>`;
|
|
39
|
+
return acc;
|
|
40
|
+
}, {});
|
|
41
|
+
// Create NodeGuidanceData for direct guidance mode
|
|
42
|
+
const nodeGuidanceData = {
|
|
43
|
+
nodeId: this.toolId,
|
|
44
|
+
taskGuidance: this.generateTaskGuidance(userInput, propertiesToExtract),
|
|
45
|
+
resultSchema: resultSchema,
|
|
46
|
+
// Provide example to help LLM understand the expected extractedProperties wrapper
|
|
47
|
+
exampleOutput: JSON.stringify({ extractedProperties: exampleProperties }),
|
|
50
48
|
};
|
|
51
|
-
const validatedResult = this.executeToolWithLogging(
|
|
49
|
+
const validatedResult = this.executeToolWithLogging(nodeGuidanceData, resultSchema, (rawResult, schema) => this.validateAndFilterResult(rawResult, properties, schema));
|
|
52
50
|
this.logger.info('Property extraction completed', {
|
|
53
51
|
extractedCount: Object.keys(validatedResult.extractedProperties).length,
|
|
54
52
|
properties: Object.keys(validatedResult.extractedProperties),
|
|
@@ -129,5 +127,83 @@ export class InputExtractionService extends AbstractService {
|
|
|
129
127
|
}
|
|
130
128
|
return { extractedProperties: validatedProperties };
|
|
131
129
|
}
|
|
130
|
+
/**
|
|
131
|
+
* Generates the task guidance for input extraction.
|
|
132
|
+
*
|
|
133
|
+
* @param userUtterance - The raw user input to analyze
|
|
134
|
+
* @param propertiesToExtract - Array of properties to extract
|
|
135
|
+
* @returns The guidance prompt string
|
|
136
|
+
*/
|
|
137
|
+
generateTaskGuidance(userUtterance, propertiesToExtract) {
|
|
138
|
+
return `
|
|
139
|
+
# ROLE
|
|
140
|
+
You are a **conservative** data extraction tool. Your primary directive is to ONLY extract
|
|
141
|
+
values that are EXPLICITLY and LITERALLY stated in the user's input. You never guess,
|
|
142
|
+
assume, infer, or fill in missing information.
|
|
143
|
+
|
|
144
|
+
# CRITICAL CONSTRAINT
|
|
145
|
+
|
|
146
|
+
**When in doubt, output \`null\`.** It is ALWAYS better to return \`null\` for a property
|
|
147
|
+
than to guess or infer a value. Guessing causes downstream errors. Missing values can be
|
|
148
|
+
collected later. There is NO penalty for returning \`null\`, but there IS a penalty for
|
|
149
|
+
inventing values.
|
|
150
|
+
|
|
151
|
+
---
|
|
152
|
+
# TASK
|
|
153
|
+
|
|
154
|
+
Analyze the user utterance below and extract ONLY values that are EXPLICITLY stated.
|
|
155
|
+
For each property, output either:
|
|
156
|
+
- The EXACT value found in the text, OR
|
|
157
|
+
- \`null\` if the value is not explicitly present
|
|
158
|
+
|
|
159
|
+
---
|
|
160
|
+
# CONTEXT
|
|
161
|
+
|
|
162
|
+
## USER UTTERANCE TO ANALYZE
|
|
163
|
+
${JSON.stringify(userUtterance)}
|
|
164
|
+
|
|
165
|
+
## PROPERTIES TO EXTRACT
|
|
166
|
+
\`\`\`json
|
|
167
|
+
${JSON.stringify(propertiesToExtract)}
|
|
168
|
+
\`\`\`
|
|
169
|
+
|
|
170
|
+
---
|
|
171
|
+
# INSTRUCTIONS
|
|
172
|
+
|
|
173
|
+
1. Read the "USER UTTERANCE TO ANALYZE" carefully.
|
|
174
|
+
2. For each property in "PROPERTIES TO EXTRACT":
|
|
175
|
+
- Search for an EXPLICIT, LITERAL value in the user's text
|
|
176
|
+
- If found verbatim or with trivial transformation, extract it
|
|
177
|
+
- If NOT found, you MUST output \`null\`
|
|
178
|
+
3. Ensure output keys exactly match the \`propertyName\` values from the input list.
|
|
179
|
+
|
|
180
|
+
---
|
|
181
|
+
# EXAMPLES OF CORRECT BEHAVIOR
|
|
182
|
+
|
|
183
|
+
**Example 1 - Partial Information:**
|
|
184
|
+
User says: "I want to build an iOS app"
|
|
185
|
+
Properties: platform, projectName
|
|
186
|
+
Correct output: { "platform": "iOS", "projectName": null }
|
|
187
|
+
WRONG output: { "platform": "iOS", "projectName": "MyApp" } // "MyApp" was NEVER mentioned!
|
|
188
|
+
|
|
189
|
+
**Example 2 - No Relevant Information:**
|
|
190
|
+
User says: "Hello, I need help"
|
|
191
|
+
Properties: platform, projectName
|
|
192
|
+
Correct output: { "platform": null, "projectName": null }
|
|
193
|
+
WRONG output: { "platform": "iOS", "projectName": "App" } // Both are fabricated!
|
|
194
|
+
|
|
195
|
+
**Example 3 - Complete Information:**
|
|
196
|
+
User says: "Create an Android app called WeatherTracker"
|
|
197
|
+
Properties: platform, projectName
|
|
198
|
+
Correct output: { "platform": "Android", "projectName": "WeatherTracker" }
|
|
199
|
+
|
|
200
|
+
---
|
|
201
|
+
# FINAL REMINDER
|
|
202
|
+
|
|
203
|
+
**DO NOT GUESS. DO NOT INFER. DO NOT ASSUME.**
|
|
204
|
+
If a value is not EXPLICITLY stated in the user utterance, output \`null\`.
|
|
205
|
+
When uncertain, \`null\` is ALWAYS the correct answer.
|
|
206
|
+
`;
|
|
207
|
+
}
|
|
132
208
|
}
|
|
133
209
|
//# sourceMappingURL=inputExtractionService.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"inputExtractionService.js","sourceRoot":"","sources":["../../src/services/inputExtractionService.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,CAAC,MAAM,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"inputExtractionService.js","sourceRoot":"","sources":["../../src/services/inputExtractionService.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,CAAC,MAAM,KAAK,CAAC;AAEpB,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AA4BvD;;;;;;GAMG;AACH,MAAM,OAAO,sBACX,SAAQ,eAAe;IAWJ;IARnB;;;;;;OAMG;IACH,YACmB,MAAc,EAC/B,YAA2B,EAC3B,MAAe;QAEf,KAAK,CAAC,wBAAwB,EAAE,YAAY,EAAE,MAAM,CAAC,CAAC;QAJrC,WAAM,GAAN,MAAM,CAAQ;IAKjC,CAAC;IAED,iBAAiB,CAAC,SAAkB,EAAE,UAAsC;QAC1E,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,8BAA8B,EAAE;YAChD,SAAS;YACT,aAAa,EAAE,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,MAAM;SAC9C,CAAC,CAAC;QAEH,MA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AM,CAAC,KAAK,CAAC,CAAC;oBACxE,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,mCAAmC,YAAY,KAAK,QAAQ,EAAE,CAAC,CAAC;oBAClF,MAAM,KAAK,CAAC;gBACd,CAAC;YACH,CAAC;QACH,CAAC;QAED,IAAI,iBAAiB,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACjC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,mCAAmC,EAAE;gBACpD,iBAAiB;gBACjB,UAAU,EAAE,MAAM,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAC,MAAM;aACpD,CAAC,CAAC;QACL,CAAC;QAED,OAAO,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,CAAC;IACtD,CAAC;IAED;;;;;;OAMG;IACK,oBAAoB,CAC1B,aAAsB,EACtB,mBAAyE;QAEzE,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;EAyBT,IAAI,CAAC,SAAS,CAAC,aAAa,CAAC;;;;EAI7B,IAAI,CAAC,SAAS,CAAC,mBAAmB,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAuCpC,CAAC;IACA,CAAC;CACF"}
|
|
@@ -1,14 +1,56 @@
|
|
|
1
1
|
import z from 'zod';
|
|
2
2
|
import { ToolMetadata } from '../../common/metadata.js';
|
|
3
3
|
import type { OrchestratorConfig } from './config.js';
|
|
4
|
+
/**
|
|
5
|
+
* Schema for the initial user request when starting a new workflow.
|
|
6
|
+
* This is the expected format when calling the orchestrator for the first time.
|
|
7
|
+
*/
|
|
8
|
+
export declare const INITIAL_USER_REQUEST_SCHEMA: z.ZodObject<{
|
|
9
|
+
request: z.ZodString;
|
|
10
|
+
}, "strip", z.ZodTypeAny, {
|
|
11
|
+
request: string;
|
|
12
|
+
}, {
|
|
13
|
+
request: string;
|
|
14
|
+
}>;
|
|
15
|
+
/**
|
|
16
|
+
* Schema for resumption user input when continuing an existing workflow.
|
|
17
|
+
* This allows any structured data returned from previous tool executions.
|
|
18
|
+
*/
|
|
19
|
+
export declare const RESUMPTION_USER_INPUT_SCHEMA: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
20
|
+
/**
|
|
21
|
+
* Combined user input schema that accepts either:
|
|
22
|
+
* - Initial request format: { request: "user's request string" } - for starting new workflows
|
|
23
|
+
* - Resumption format: any object - for continuing workflows with tool results
|
|
24
|
+
*/
|
|
25
|
+
export declare const USER_INPUT_SCHEMA: z.ZodUnion<[z.ZodObject<{
|
|
26
|
+
request: z.ZodString;
|
|
27
|
+
}, "strip", z.ZodTypeAny, {
|
|
28
|
+
request: string;
|
|
29
|
+
}, {
|
|
30
|
+
request: string;
|
|
31
|
+
}>, z.ZodRecord<z.ZodString, z.ZodUnknown>]>;
|
|
4
32
|
/**
|
|
5
33
|
* Orchestrator input schema
|
|
6
34
|
*
|
|
7
35
|
* Note: The workflow state data is optional/defaulted because the orchestrator
|
|
8
36
|
* can start new workflows (where it doesn't exist yet) or continue existing ones.
|
|
37
|
+
*
|
|
38
|
+
* For initial calls (starting a new workflow):
|
|
39
|
+
* - userInput should be { request: "your request string" }
|
|
40
|
+
* - workflowStateData should be omitted or have empty thread_id
|
|
41
|
+
*
|
|
42
|
+
* For resumption calls (continuing an existing workflow):
|
|
43
|
+
* - userInput should contain the structured output from the previous tool execution
|
|
44
|
+
* - workflowStateData must contain the thread_id from the previous response
|
|
9
45
|
*/
|
|
10
46
|
export declare const ORCHESTRATOR_INPUT_SCHEMA: z.ZodObject<{
|
|
11
|
-
userInput: z.ZodOptional<z.
|
|
47
|
+
userInput: z.ZodOptional<z.ZodUnion<[z.ZodObject<{
|
|
48
|
+
request: z.ZodString;
|
|
49
|
+
}, "strip", z.ZodTypeAny, {
|
|
50
|
+
request: string;
|
|
51
|
+
}, {
|
|
52
|
+
request: string;
|
|
53
|
+
}>, z.ZodRecord<z.ZodString, z.ZodUnknown>]>>;
|
|
12
54
|
workflowStateData: z.ZodDefault<z.ZodObject<{
|
|
13
55
|
thread_id: z.ZodString;
|
|
14
56
|
}, "strip", z.ZodTypeAny, {
|
|
@@ -20,12 +62,16 @@ export declare const ORCHESTRATOR_INPUT_SCHEMA: z.ZodObject<{
|
|
|
20
62
|
workflowStateData: {
|
|
21
63
|
thread_id: string;
|
|
22
64
|
};
|
|
23
|
-
userInput?: Record<string, unknown> |
|
|
65
|
+
userInput?: Record<string, unknown> | {
|
|
66
|
+
request: string;
|
|
67
|
+
} | undefined;
|
|
24
68
|
}, {
|
|
25
69
|
workflowStateData?: {
|
|
26
70
|
thread_id: string;
|
|
27
71
|
} | undefined;
|
|
28
|
-
userInput?: Record<string, unknown> |
|
|
72
|
+
userInput?: Record<string, unknown> | {
|
|
73
|
+
request: string;
|
|
74
|
+
} | undefined;
|
|
29
75
|
}>;
|
|
30
76
|
export type OrchestratorInput = z.infer<typeof ORCHESTRATOR_INPUT_SCHEMA>;
|
|
31
77
|
/**
|
|
@@ -6,17 +6,44 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import z from 'zod';
|
|
8
8
|
import { WORKFLOW_PROPERTY_NAMES, WORKFLOW_STATE_DATA_SCHEMA, } from '../../common/metadata.js';
|
|
9
|
+
/**
|
|
10
|
+
* Schema for the initial user request when starting a new workflow.
|
|
11
|
+
* This is the expected format when calling the orchestrator for the first time.
|
|
12
|
+
*/
|
|
13
|
+
export const INITIAL_USER_REQUEST_SCHEMA = z.object({
|
|
14
|
+
request: z.string().describe("The user's initial request to start the workflow"),
|
|
15
|
+
});
|
|
16
|
+
/**
|
|
17
|
+
* Schema for resumption user input when continuing an existing workflow.
|
|
18
|
+
* This allows any structured data returned from previous tool executions.
|
|
19
|
+
*/
|
|
20
|
+
export const RESUMPTION_USER_INPUT_SCHEMA = z
|
|
21
|
+
.record(z.string(), z.unknown())
|
|
22
|
+
.describe('Used for structured input generated from the results of previous tool calls.');
|
|
23
|
+
/**
|
|
24
|
+
* Combined user input schema that accepts either:
|
|
25
|
+
* - Initial request format: { request: "user's request string" } - for starting new workflows
|
|
26
|
+
* - Resumption format: any object - for continuing workflows with tool results
|
|
27
|
+
*/
|
|
28
|
+
export const USER_INPUT_SCHEMA = z
|
|
29
|
+
.union([INITIAL_USER_REQUEST_SCHEMA, RESUMPTION_USER_INPUT_SCHEMA])
|
|
30
|
+
.describe('User input - for initial calls use { request: "your request" }, for resumption calls use the structured output from the previous tool');
|
|
9
31
|
/**
|
|
10
32
|
* Orchestrator input schema
|
|
11
33
|
*
|
|
12
34
|
* Note: The workflow state data is optional/defaulted because the orchestrator
|
|
13
35
|
* can start new workflows (where it doesn't exist yet) or continue existing ones.
|
|
36
|
+
*
|
|
37
|
+
* For initial calls (starting a new workflow):
|
|
38
|
+
* - userInput should be { request: "your request string" }
|
|
39
|
+
* - workflowStateData should be omitted or have empty thread_id
|
|
40
|
+
*
|
|
41
|
+
* For resumption calls (continuing an existing workflow):
|
|
42
|
+
* - userInput should contain the structured output from the previous tool execution
|
|
43
|
+
* - workflowStateData must contain the thread_id from the previous response
|
|
14
44
|
*/
|
|
15
45
|
export const ORCHESTRATOR_INPUT_SCHEMA = z.object({
|
|
16
|
-
[WORKFLOW_PROPERTY_NAMES.userInput]:
|
|
17
|
-
.record(z.string(), z.unknown())
|
|
18
|
-
.optional()
|
|
19
|
-
.describe('User input - can be any data structure from initial request or previously executed MCP tool'),
|
|
46
|
+
[WORKFLOW_PROPERTY_NAMES.userInput]: USER_INPUT_SCHEMA.optional(),
|
|
20
47
|
[WORKFLOW_PROPERTY_NAMES.workflowStateData]: WORKFLOW_STATE_DATA_SCHEMA.default({
|
|
21
48
|
thread_id: '',
|
|
22
49
|
}).describe('Opaque workflow state data. Do not populate unless explicitly instructed to do so.'),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"metadata.js","sourceRoot":"","sources":["../../../src/tools/orchestrator/metadata.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,CAAC,MAAM,KAAK,CAAC;AACpB,OAAO,EAEL,uBAAuB,EACvB,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C;CACtF,CAAC,CAAC;AAaH;;;;;;;GAOG;AACH,MAAM,UAAU,8BAA8B,CAC5C,MAA0B;IAE1B,OAAO;QACL,MAAM,EAAE,MAAM,CAAC,MAAM;QACrB,KAAK,EAAE,MAAM,CAAC,KAAK;QACnB,WAAW,EAAE,MAAM,CAAC,WAAW;QAC/B,WAAW,EAAE,yBAAyB;QACtC,YAAY,EAAE,0BAA0B;KACzC,CAAC;AACJ,CAAC"}
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
2
|
+
import type { ServerRequest, ServerNotification } from '@modelcontextprotocol/sdk/types.js';
|
|
3
|
+
import type { RequestHandlerExtra } from '@modelcontextprotocol/sdk/shared/protocol.js';
|
|
2
4
|
import { AbstractTool } from '../base/abstractTool.js';
|
|
5
|
+
import type { WorkflowRunnableConfig } from '../../common/graphConfig.js';
|
|
6
|
+
import { type ProgressReporter } from '../../execution/progressReporter.js';
|
|
3
7
|
import { OrchestratorConfig } from './config.js';
|
|
4
|
-
import { OrchestratorInput, OrchestratorToolMetadata } from './metadata.js';
|
|
8
|
+
import { OrchestratorInput, OrchestratorOutput, OrchestratorToolMetadata } from './metadata.js';
|
|
5
9
|
/**
|
|
6
10
|
* Orchestrator Tool
|
|
7
11
|
*
|
|
@@ -18,11 +22,12 @@ import { OrchestratorInput, OrchestratorToolMetadata } from './metadata.js';
|
|
|
18
22
|
export declare class OrchestratorTool extends AbstractTool<OrchestratorToolMetadata> {
|
|
19
23
|
private readonly config;
|
|
20
24
|
private readonly stateManager;
|
|
25
|
+
private currentProgressReporter;
|
|
21
26
|
constructor(server: McpServer, config: OrchestratorConfig);
|
|
22
27
|
/**
|
|
23
28
|
* Handle orchestrator requests - manages workflow state and execution
|
|
24
29
|
*/
|
|
25
|
-
handleRequest: (input: OrchestratorInput) => Promise<{
|
|
30
|
+
handleRequest: (input: OrchestratorInput, extra: RequestHandlerExtra<ServerRequest, ServerNotification>) => Promise<{
|
|
26
31
|
content: {
|
|
27
32
|
type: "text";
|
|
28
33
|
text: string;
|
|
@@ -31,9 +36,45 @@ export declare class OrchestratorTool extends AbstractTool<OrchestratorToolMetad
|
|
|
31
36
|
orchestrationInstructionsPrompt: string;
|
|
32
37
|
};
|
|
33
38
|
}>;
|
|
34
|
-
|
|
39
|
+
/**
|
|
40
|
+
* Creates a progress reporter from MCP request context.
|
|
41
|
+
*
|
|
42
|
+
* Subclasses can override this to provide custom progress reporting behavior.
|
|
43
|
+
*
|
|
44
|
+
* @param extra - The MCP request context containing sendNotification and metadata
|
|
45
|
+
* @returns A progress reporter instance, or undefined if progress reporting is disabled
|
|
46
|
+
*/
|
|
47
|
+
protected createProgressReporter(extra: RequestHandlerExtra<ServerRequest, ServerNotification>): ProgressReporter | undefined;
|
|
48
|
+
protected processRequest(input: OrchestratorInput): Promise<OrchestratorOutput>;
|
|
49
|
+
/**
|
|
50
|
+
* Create the thread configuration for LangGraph workflow invocation.
|
|
51
|
+
*
|
|
52
|
+
* Subclasses can override this method to add additional properties to
|
|
53
|
+
* `configurable`, such as progressReporter for long-running operations.
|
|
54
|
+
*
|
|
55
|
+
* @param threadId - The thread ID for checkpointing
|
|
56
|
+
* @param progressReporter - Optional progress reporter for long-running operations
|
|
57
|
+
* @returns Configuration object for workflow invocation
|
|
58
|
+
*/
|
|
59
|
+
protected createThreadConfig(threadId: string, progressReporter?: ProgressReporter): WorkflowRunnableConfig;
|
|
60
|
+
/**
|
|
61
|
+
* Get the progress reporter for the current request.
|
|
62
|
+
*
|
|
63
|
+
* @returns The progress reporter created from the current MCP request context, or undefined
|
|
64
|
+
*/
|
|
65
|
+
protected getProgressReporter(): ProgressReporter | undefined;
|
|
35
66
|
/**
|
|
36
67
|
* Create orchestration prompt for LLM with embedded tool invocation data and workflow state
|
|
68
|
+
* Used in delegate mode - instructs LLM to call a separate MCP tool.
|
|
37
69
|
*/
|
|
38
70
|
private createOrchestrationPrompt;
|
|
71
|
+
/**
|
|
72
|
+
* Create a direct guidance prompt for the LLM.
|
|
73
|
+
* Used in direct guidance mode - provides guidance inline without an intermediate tool call.
|
|
74
|
+
*
|
|
75
|
+
* @param nodeGuidanceData - The node guidance data containing task guidance and schemas
|
|
76
|
+
* @param workflowStateData - The workflow state data to round-trip back to the orchestrator
|
|
77
|
+
* @returns A prompt with the task guidance and post-task instructions
|
|
78
|
+
*/
|
|
79
|
+
private createDirectGuidancePrompt;
|
|
39
80
|
}
|
|
@@ -8,7 +8,8 @@ import { zodToJsonSchema } from 'zod-to-json-schema';
|
|
|
8
8
|
import { Command } from '@langchain/langgraph';
|
|
9
9
|
import { createWorkflowLogger } from '../../logging/logger.js';
|
|
10
10
|
import { AbstractTool } from '../base/abstractTool.js';
|
|
11
|
-
import { WORKFLOW_PROPERTY_NAMES, } from '../../common/metadata.js';
|
|
11
|
+
import { isNodeGuidanceData, WORKFLOW_PROPERTY_NAMES, } from '../../common/metadata.js';
|
|
12
|
+
import { MCPProgressReporter } from '../../execution/progressReporter.js';
|
|
12
13
|
import { WorkflowStateManager } from '../../checkpointing/workflowStateManager.js';
|
|
13
14
|
import { createOrchestratorToolMetadata, } from './metadata.js';
|
|
14
15
|
/**
|
|
@@ -33,6 +34,7 @@ function generateUniqueThreadId() {
|
|
|
33
34
|
export class OrchestratorTool extends AbstractTool {
|
|
34
35
|
config;
|
|
35
36
|
stateManager;
|
|
37
|
+
currentProgressReporter;
|
|
36
38
|
constructor(server, config) {
|
|
37
39
|
// Use provided logger or create workflow logger with component name
|
|
38
40
|
const effectiveLogger = config.logger || createWorkflowLogger('OrchestratorTool');
|
|
@@ -45,7 +47,9 @@ export class OrchestratorTool extends AbstractTool {
|
|
|
45
47
|
/**
|
|
46
48
|
* Handle orchestrator requests - manages workflow state and execution
|
|
47
49
|
*/
|
|
48
|
-
handleRequest = async (input) => {
|
|
50
|
+
handleRequest = async (input, extra) => {
|
|
51
|
+
// Create progress reporter from MCP context
|
|
52
|
+
this.currentProgressReporter = this.createProgressReporter(extra);
|
|
49
53
|
this.logger.debug('Orchestrator tool called with input', input);
|
|
50
54
|
try {
|
|
51
55
|
const result = await this.processRequest(input);
|
|
@@ -64,7 +68,24 @@ export class OrchestratorTool extends AbstractTool {
|
|
|
64
68
|
this.logger.error('Error in orchestrator tool execution', error);
|
|
65
69
|
throw error;
|
|
66
70
|
}
|
|
71
|
+
finally {
|
|
72
|
+
// Clear progress reporter after request completes
|
|
73
|
+
this.currentProgressReporter = undefined;
|
|
74
|
+
}
|
|
67
75
|
};
|
|
76
|
+
/**
|
|
77
|
+
* Creates a progress reporter from MCP request context.
|
|
78
|
+
*
|
|
79
|
+
* Subclasses can override this to provide custom progress reporting behavior.
|
|
80
|
+
*
|
|
81
|
+
* @param extra - The MCP request context containing sendNotification and metadata
|
|
82
|
+
* @returns A progress reporter instance, or undefined if progress reporting is disabled
|
|
83
|
+
*/
|
|
84
|
+
createProgressReporter(extra) {
|
|
85
|
+
const { sendNotification, _meta } = extra;
|
|
86
|
+
const progressToken = _meta?.progressToken ? String(_meta.progressToken) : undefined;
|
|
87
|
+
return new MCPProgressReporter(sendNotification, progressToken);
|
|
88
|
+
}
|
|
68
89
|
async processRequest(input) {
|
|
69
90
|
// Generate or use existing thread ID for workflow session
|
|
70
91
|
let threadId = '';
|
|
@@ -84,8 +105,8 @@ export class OrchestratorTool extends AbstractTool {
|
|
|
84
105
|
hasUserInput: !!input.userInput,
|
|
85
106
|
isResumption: !!input.workflowStateData?.thread_id,
|
|
86
107
|
});
|
|
87
|
-
// Thread configuration for LangGraph
|
|
88
|
-
const threadConfig =
|
|
108
|
+
// Thread configuration for LangGraph - includes optional progress reporter
|
|
109
|
+
const threadConfig = this.createThreadConfig(threadId, this.getProgressReporter());
|
|
89
110
|
// Get checkpointer from state manager
|
|
90
111
|
const checkpointer = await this.stateManager.createCheckpointer();
|
|
91
112
|
// Compile workflow with checkpointer
|
|
@@ -114,18 +135,27 @@ export class OrchestratorTool extends AbstractTool {
|
|
|
114
135
|
graphState = await compiledWorkflow.getState(threadConfig);
|
|
115
136
|
if (graphState.next.length > 0) {
|
|
116
137
|
// There are more nodes to execute.
|
|
117
|
-
const
|
|
138
|
+
const interruptData = '__interrupt__' in result
|
|
118
139
|
? result.__interrupt__[0].value
|
|
119
140
|
: undefined;
|
|
120
|
-
if (!
|
|
121
|
-
this.logger.error('Workflow completed without expected
|
|
141
|
+
if (!interruptData) {
|
|
142
|
+
this.logger.error('Workflow completed without expected interrupt data.');
|
|
122
143
|
throw new Error('FATAL: Unexpected workflow state without an interrupt');
|
|
123
144
|
}
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
145
|
+
// Determine mode and create appropriate prompt
|
|
146
|
+
let orchestrationPrompt;
|
|
147
|
+
if (isNodeGuidanceData(interruptData)) {
|
|
148
|
+
this.logger.info('Using direct guidance mode', {
|
|
149
|
+
nodeId: interruptData.nodeId,
|
|
150
|
+
});
|
|
151
|
+
orchestrationPrompt = this.createDirectGuidancePrompt(interruptData, workflowStateData);
|
|
152
|
+
}
|
|
153
|
+
else {
|
|
154
|
+
this.logger.info('Using delegate mode', {
|
|
155
|
+
toolName: interruptData.llmMetadata?.name,
|
|
156
|
+
});
|
|
157
|
+
orchestrationPrompt = this.createOrchestrationPrompt(interruptData, workflowStateData);
|
|
158
|
+
}
|
|
129
159
|
// Save the workflow state.
|
|
130
160
|
await this.stateManager.saveCheckpointerState(checkpointer);
|
|
131
161
|
return {
|
|
@@ -137,8 +167,35 @@ export class OrchestratorTool extends AbstractTool {
|
|
|
137
167
|
orchestrationInstructionsPrompt: 'The workflow has concluded. No further workflow actions are forthcoming.',
|
|
138
168
|
};
|
|
139
169
|
}
|
|
170
|
+
/**
|
|
171
|
+
* Create the thread configuration for LangGraph workflow invocation.
|
|
172
|
+
*
|
|
173
|
+
* Subclasses can override this method to add additional properties to
|
|
174
|
+
* `configurable`, such as progressReporter for long-running operations.
|
|
175
|
+
*
|
|
176
|
+
* @param threadId - The thread ID for checkpointing
|
|
177
|
+
* @param progressReporter - Optional progress reporter for long-running operations
|
|
178
|
+
* @returns Configuration object for workflow invocation
|
|
179
|
+
*/
|
|
180
|
+
createThreadConfig(threadId, progressReporter) {
|
|
181
|
+
return {
|
|
182
|
+
configurable: {
|
|
183
|
+
thread_id: threadId,
|
|
184
|
+
progressReporter,
|
|
185
|
+
},
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Get the progress reporter for the current request.
|
|
190
|
+
*
|
|
191
|
+
* @returns The progress reporter created from the current MCP request context, or undefined
|
|
192
|
+
*/
|
|
193
|
+
getProgressReporter() {
|
|
194
|
+
return this.currentProgressReporter;
|
|
195
|
+
}
|
|
140
196
|
/**
|
|
141
197
|
* Create orchestration prompt for LLM with embedded tool invocation data and workflow state
|
|
198
|
+
* Used in delegate mode - instructs LLM to call a separate MCP tool.
|
|
142
199
|
*/
|
|
143
200
|
createOrchestrationPrompt(mcpToolInvocationData, workflowStateData) {
|
|
144
201
|
return `
|
|
@@ -156,7 +213,7 @@ Invoke the following MCP server tool:
|
|
|
156
213
|
**MCP Server Tool Name**: ${mcpToolInvocationData.llmMetadata?.name}
|
|
157
214
|
**MCP Server Tool Input Schema**:
|
|
158
215
|
\`\`\`json
|
|
159
|
-
${JSON.stringify(zodToJsonSchema(mcpToolInvocationData.llmMetadata
|
|
216
|
+
${JSON.stringify(zodToJsonSchema(mcpToolInvocationData.llmMetadata.inputSchema))}
|
|
160
217
|
\`\`\`
|
|
161
218
|
**MCP Server Tool Input Values**:
|
|
162
219
|
\`\`\`json
|
|
@@ -180,6 +237,74 @@ specified by the next MCP server tool invocation.
|
|
|
180
237
|
|
|
181
238
|
The MCP server tool you invoke will respond with its output, along with further
|
|
182
239
|
instructions for continuing the workflow.
|
|
240
|
+
`;
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* Create a direct guidance prompt for the LLM.
|
|
244
|
+
* Used in direct guidance mode - provides guidance inline without an intermediate tool call.
|
|
245
|
+
*
|
|
246
|
+
* @param nodeGuidanceData - The node guidance data containing task guidance and schemas
|
|
247
|
+
* @param workflowStateData - The workflow state data to round-trip back to the orchestrator
|
|
248
|
+
* @returns A prompt with the task guidance and post-task instructions
|
|
249
|
+
*/
|
|
250
|
+
createDirectGuidancePrompt(nodeGuidanceData, workflowStateData) {
|
|
251
|
+
const resultSchemaJson = JSON.stringify(zodToJsonSchema(nodeGuidanceData.resultSchema), null, 2);
|
|
252
|
+
// Build example section if provided
|
|
253
|
+
const exampleSection = nodeGuidanceData.exampleOutput
|
|
254
|
+
? `
|
|
255
|
+
For example, a properly formatted result should look like:
|
|
256
|
+
|
|
257
|
+
\`\`\`json
|
|
258
|
+
${nodeGuidanceData.exampleOutput}
|
|
259
|
+
\`\`\`
|
|
260
|
+
`
|
|
261
|
+
: '';
|
|
262
|
+
return `
|
|
263
|
+
# ROLE
|
|
264
|
+
|
|
265
|
+
You are participating in a workflow orchestration process. The orchestrator is providing
|
|
266
|
+
you with direct guidance for the current task.
|
|
267
|
+
|
|
268
|
+
# TASK GUIDANCE
|
|
269
|
+
|
|
270
|
+
${nodeGuidanceData.taskGuidance}
|
|
271
|
+
|
|
272
|
+
# CRITICAL: REQUIRED NEXT STEP
|
|
273
|
+
|
|
274
|
+
After completing the task above, you **MUST** invoke the \`${this.toolMetadata.toolId}\` tool
|
|
275
|
+
to continue the workflow. The workflow CANNOT proceed without this tool call.
|
|
276
|
+
|
|
277
|
+
**DO NOT:**
|
|
278
|
+
- Simply respond with text
|
|
279
|
+
- Skip the tool call
|
|
280
|
+
- Forget to include the required parameters
|
|
281
|
+
|
|
282
|
+
**YOU MUST** call the \`${this.toolMetadata.toolId}\` tool with EXACTLY these parameters:
|
|
283
|
+
|
|
284
|
+
| Parameter | Value |
|
|
285
|
+
|-----------|-------|
|
|
286
|
+
| \`${WORKFLOW_PROPERTY_NAMES.userInput}\` | Your formatted result (see OUTPUT FORMAT below) |
|
|
287
|
+
| \`${WORKFLOW_PROPERTY_NAMES.workflowStateData}\` | \`${JSON.stringify(workflowStateData)}\` |
|
|
288
|
+
|
|
289
|
+
# OUTPUT FORMAT
|
|
290
|
+
|
|
291
|
+
The \`${WORKFLOW_PROPERTY_NAMES.userInput}\` parameter MUST be a JSON object conforming to this schema:
|
|
292
|
+
|
|
293
|
+
\`\`\`json
|
|
294
|
+
${resultSchemaJson}
|
|
295
|
+
\`\`\`
|
|
296
|
+
${exampleSection}
|
|
297
|
+
|
|
298
|
+
# EXAMPLE TOOL CALL
|
|
299
|
+
|
|
300
|
+
Here is an example of the EXACT format your tool call should follow:
|
|
301
|
+
|
|
302
|
+
\`\`\`
|
|
303
|
+
Tool: ${this.toolMetadata.toolId}
|
|
304
|
+
Parameters:
|
|
305
|
+
${WORKFLOW_PROPERTY_NAMES.userInput}: ${nodeGuidanceData.exampleOutput ? nodeGuidanceData.exampleOutput.replaceAll('\n', '\n ') : '{ /* your result object here */ }'}
|
|
306
|
+
${WORKFLOW_PROPERTY_NAMES.workflowStateData}: ${JSON.stringify(workflowStateData)}
|
|
307
|
+
\`\`\`
|
|
183
308
|
`;
|
|
184
309
|
}
|
|
185
310
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"orchestratorTool.js","sourceRoot":"","sources":["../../../src/tools/orchestrator/orchestratorTool.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"orchestratorTool.js","sourceRoot":"","sources":["../../../src/tools/orchestrator/orchestratorTool.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAIrD,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAC/C,OAAO,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AAC/D,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;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,IAAI,CAAC,SAAS,CACrC,eAAe,CAAC,gBAAgB,CAAC,YAAY,CAAC,EAC9C,IAAI,EACJ,CAAC,CACF,CAAC;QAEF,oCAAoC;QACpC,MAAM,cAAc,GAAG,gBAAgB,CAAC,aAAa;YACnD,CAAC,CAAC;;;;EAIN,gBAAgB,CAAC,aAAa;;CAE/B;YACK,CAAC,CAAC,EAAE,CAAC;QAEP,OAAO;;;;;;;;EAQT,gBAAgB,CAAC,YAAY;;;;6DAI8B,IAAI,CAAC,YAAY,CAAC,MAAM;;;;;;;;0BAQ3D,IAAI,CAAC,YAAY,CAAC,MAAM;;;;MAI5C,uBAAuB,CAAC,SAAS;MACjC,uBAAuB,CAAC,iBAAiB,UAAU,IAAI,CAAC,SAAS,CAAC,iBAAiB,CAAC;;;;QAIlF,uBAAuB,CAAC,SAAS;;;EAGvC,gBAAgB;;EAEhB,cAAc;;;;;;;QAOR,IAAI,CAAC,YAAY,CAAC,MAAM;;IAE5B,uBAAuB,CAAC,SAAS,KAAK,gBAAgB,CAAC,aAAa,CAAC,CAAC,CAAC,gBAAgB,CAAC,aAAa,CAAC,UAAU,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC,mCAAmC;IACtK,uBAAuB,CAAC,iBAAiB,KAAK,IAAI,CAAC,SAAS,CAAC,iBAAiB,CAAC;;CAElF,CAAC;IACA,CAAC;CACF"}
|
|
@@ -4,7 +4,5 @@
|
|
|
4
4
|
* SPDX-License-Identifier: MIT
|
|
5
5
|
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
6
6
|
*/
|
|
7
|
-
export * from './tool.js';
|
|
8
7
|
export * from './metadata.js';
|
|
9
|
-
export * from './factory.js';
|
|
10
8
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/tools/utilities/getInput/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,cAAc,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/tools/utilities/getInput/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,cAAc,eAAe,CAAC"}
|