@mcpc-tech/core 0.2.7-beta.1 → 0.2.7-beta.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/index.mjs +60 -37
- package/package.json +1 -1
package/index.mjs
CHANGED
|
@@ -1059,7 +1059,7 @@ var SystemPrompts = {
|
|
|
1059
1059
|
4. **Collect feedback** from each action result
|
|
1060
1060
|
5. **Decide** next step:
|
|
1061
1061
|
- **proceed**: More work needed
|
|
1062
|
-
- **complete**: Question answered
|
|
1062
|
+
- **complete**: Question answered (do NOT provide action field)
|
|
1063
1063
|
- **retry**: Current action failed
|
|
1064
1064
|
6. **Provide** parameter object matching action name
|
|
1065
1065
|
7. **Continue** until complete
|
|
@@ -1068,9 +1068,16 @@ var SystemPrompts = {
|
|
|
1068
1068
|
\`\`\`json
|
|
1069
1069
|
{
|
|
1070
1070
|
"action": "tool_name",
|
|
1071
|
-
"decision": "proceed|retry
|
|
1071
|
+
"decision": "proceed|retry",
|
|
1072
1072
|
"tool_name": { /* tool parameters */ }
|
|
1073
1073
|
}
|
|
1074
|
+
\`\`\`
|
|
1075
|
+
|
|
1076
|
+
**When task is complete:**
|
|
1077
|
+
\`\`\`json
|
|
1078
|
+
{
|
|
1079
|
+
"decision": "complete"
|
|
1080
|
+
}
|
|
1074
1081
|
\`\`\``,
|
|
1075
1082
|
/**
|
|
1076
1083
|
* Workflow execution system prompt
|
|
@@ -1110,14 +1117,22 @@ var SystemPrompts = {
|
|
|
1110
1117
|
- Continue until question answered
|
|
1111
1118
|
|
|
1112
1119
|
## JSON Response Format
|
|
1120
|
+
**During execution:**
|
|
1113
1121
|
\`\`\`json
|
|
1114
1122
|
{
|
|
1115
1123
|
"action": "tool_name",
|
|
1116
|
-
"decision": "proceed|retry
|
|
1124
|
+
"decision": "proceed|retry",
|
|
1117
1125
|
"tool_name": { /* tool parameters */ }
|
|
1118
1126
|
}
|
|
1119
1127
|
\`\`\`
|
|
1120
1128
|
|
|
1129
|
+
**When task is complete (do NOT include action):**
|
|
1130
|
+
\`\`\`json
|
|
1131
|
+
{
|
|
1132
|
+
"decision": "complete"
|
|
1133
|
+
}
|
|
1134
|
+
\`\`\`
|
|
1135
|
+
|
|
1121
1136
|
## Available Tools
|
|
1122
1137
|
{toolList}`,
|
|
1123
1138
|
/**
|
|
@@ -1152,9 +1167,12 @@ You MUST respond with a JSON object for workflow execution:
|
|
|
1152
1167
|
|
|
1153
1168
|
**For Step Execution (Subsequent Calls):**
|
|
1154
1169
|
- action: "{toolName}"
|
|
1155
|
-
- decision: "proceed" (advance), "retry" (retry)
|
|
1170
|
+
- decision: "proceed" (advance), "retry" (retry)
|
|
1156
1171
|
- [step parameters]: Tool-specific parameters you autonomously determine for current step
|
|
1157
1172
|
|
|
1173
|
+
**When Workflow is Complete (do NOT include action):**
|
|
1174
|
+
- decision: "complete"
|
|
1175
|
+
|
|
1158
1176
|
**\u{1F3AF} AGENTIC WORKFLOW CONSTRAINTS:**
|
|
1159
1177
|
- Response must be pure JSON demonstrating autonomous decision-making within workflow structure
|
|
1160
1178
|
- Invalid JSON indicates failure in agentic workflow reasoning
|
|
@@ -2097,7 +2115,7 @@ var BaseSamplingExecutor = class {
|
|
|
2097
2115
|
role: "user",
|
|
2098
2116
|
content: {
|
|
2099
2117
|
type: "text",
|
|
2100
|
-
text: 'Return ONE AND ONLY ONE raw JSON object (no code fences, explanations, or multiple objects).
|
|
2118
|
+
text: 'Return ONE AND ONLY ONE raw JSON object (no code fences, explanations, or multiple objects). During execution provide: {"action":"<tool>","decision":"proceed|retry","<tool>":{}}. When complete provide: {"decision":"complete"}'
|
|
2101
2119
|
}
|
|
2102
2120
|
}
|
|
2103
2121
|
];
|
|
@@ -2141,7 +2159,41 @@ var BaseSamplingExecutor = class {
|
|
|
2141
2159
|
}
|
|
2142
2160
|
});
|
|
2143
2161
|
const action = parsedData["action"];
|
|
2144
|
-
const
|
|
2162
|
+
const decision = parsedData["decision"];
|
|
2163
|
+
if (typeof decision !== "string") {
|
|
2164
|
+
this.conversationHistory.push({
|
|
2165
|
+
role: "user",
|
|
2166
|
+
content: {
|
|
2167
|
+
type: "text",
|
|
2168
|
+
text: 'Missing required field "decision". Provide: {"action":"<tool>","decision":"proceed|retry","<tool>":{}} or {"decision":"complete"}'
|
|
2169
|
+
}
|
|
2170
|
+
});
|
|
2171
|
+
if (iterationSpan) endSpan(iterationSpan);
|
|
2172
|
+
continue;
|
|
2173
|
+
}
|
|
2174
|
+
if (decision === "complete" && action) {
|
|
2175
|
+
this.conversationHistory.push({
|
|
2176
|
+
role: "user",
|
|
2177
|
+
content: {
|
|
2178
|
+
type: "text",
|
|
2179
|
+
text: 'Invalid: Cannot have both "decision":"complete" and "action" field. When complete, only provide {"decision":"complete"}.'
|
|
2180
|
+
}
|
|
2181
|
+
});
|
|
2182
|
+
if (iterationSpan) endSpan(iterationSpan);
|
|
2183
|
+
continue;
|
|
2184
|
+
}
|
|
2185
|
+
if (decision !== "complete" && !action) {
|
|
2186
|
+
this.conversationHistory.push({
|
|
2187
|
+
role: "user",
|
|
2188
|
+
content: {
|
|
2189
|
+
type: "text",
|
|
2190
|
+
text: 'Missing required field "action". When executing, provide: {"action":"<tool>","decision":"proceed|retry","<tool>":{}}'
|
|
2191
|
+
}
|
|
2192
|
+
});
|
|
2193
|
+
if (iterationSpan) endSpan(iterationSpan);
|
|
2194
|
+
continue;
|
|
2195
|
+
}
|
|
2196
|
+
const actionStr = decision === "complete" ? "completion" : action && typeof action === "string" ? String(action) : "unknown_action";
|
|
2145
2197
|
const spanName = `mcpc.sampling_iteration.${actionStr}`;
|
|
2146
2198
|
iterationSpan = this.tracingEnabled ? startSpan(spanName, {
|
|
2147
2199
|
iteration: this.currentIteration + 1,
|
|
@@ -2152,17 +2204,6 @@ var BaseSamplingExecutor = class {
|
|
|
2152
2204
|
maxIterations: this.maxIterations,
|
|
2153
2205
|
messages: JSON.stringify(this.conversationHistory)
|
|
2154
2206
|
}, loopSpan ?? void 0) : null;
|
|
2155
|
-
if (!action || typeof parsedData["decision"] !== "string") {
|
|
2156
|
-
this.conversationHistory.push({
|
|
2157
|
-
role: "user",
|
|
2158
|
-
content: {
|
|
2159
|
-
type: "text",
|
|
2160
|
-
text: 'Required fields missing: action or decision. Return ONLY raw JSON, no code fences or explanations. Example: {"action":"<tool>","decision":"proceed|complete","<tool>":{}}'
|
|
2161
|
-
}
|
|
2162
|
-
});
|
|
2163
|
-
if (iterationSpan) endSpan(iterationSpan);
|
|
2164
|
-
continue;
|
|
2165
|
-
}
|
|
2166
2207
|
const result = await this.processAction(parsedData, schema, state, iterationSpan);
|
|
2167
2208
|
this.logIterationProgress(parsedData, result, model, stopReason, role);
|
|
2168
2209
|
if (iterationSpan) {
|
|
@@ -2178,6 +2219,7 @@ var BaseSamplingExecutor = class {
|
|
|
2178
2219
|
maxIterations: this.maxIterations,
|
|
2179
2220
|
parsed: rawJson,
|
|
2180
2221
|
action: typeof action === "string" ? action : String(action),
|
|
2222
|
+
decision: typeof decision === "string" ? decision : String(decision),
|
|
2181
2223
|
samplingResponse: responseContent,
|
|
2182
2224
|
toolResult: JSON.stringify(result),
|
|
2183
2225
|
model,
|
|
@@ -2443,15 +2485,6 @@ var SamplingExecutor = class extends BaseSamplingExecutor {
|
|
|
2443
2485
|
}
|
|
2444
2486
|
async processAction(parsedData, schema, _state, parentSpan) {
|
|
2445
2487
|
const toolCallData = parsedData;
|
|
2446
|
-
const isComplete = toolCallData.decision === "complete";
|
|
2447
|
-
const actionName = toolCallData.action;
|
|
2448
|
-
if (isComplete && actionName && actionName !== "complete") {
|
|
2449
|
-
this.logger.debug({
|
|
2450
|
-
message: "Decision is 'complete' with action present, treating as 'proceed'",
|
|
2451
|
-
action: actionName
|
|
2452
|
-
});
|
|
2453
|
-
toolCallData.decision = "proceed";
|
|
2454
|
-
}
|
|
2455
2488
|
if (toolCallData.decision === "complete") {
|
|
2456
2489
|
return await this.createCompletionResult("Task completed", parentSpan);
|
|
2457
2490
|
}
|
|
@@ -2499,8 +2532,7 @@ ${JSON.stringify(context2, null, 2)}`;
|
|
|
2499
2532
|
## Current Task
|
|
2500
2533
|
You will now use agentic sampling to complete the following task: "${userRequest}"${contextInfo}
|
|
2501
2534
|
|
|
2502
|
-
When you need to use a tool, specify the tool name in 'action' and provide tool-specific parameters as additional properties
|
|
2503
|
-
When the task is complete, use "action": "complete".`;
|
|
2535
|
+
When you need to use a tool, specify the tool name in 'action' and provide tool-specific parameters as additional properties.`;
|
|
2504
2536
|
return this.injectJsonInstruction({
|
|
2505
2537
|
prompt: basePrompt + taskPrompt,
|
|
2506
2538
|
schema: agenticSchema
|
|
@@ -3072,15 +3104,6 @@ var WorkflowSamplingExecutor = class extends BaseSamplingExecutor {
|
|
|
3072
3104
|
throw new Error("WorkflowState is required for workflow");
|
|
3073
3105
|
}
|
|
3074
3106
|
const toolCallData = parsedData;
|
|
3075
|
-
const isComplete = toolCallData.decision === "complete";
|
|
3076
|
-
const actionName = toolCallData.action;
|
|
3077
|
-
if (isComplete && actionName && actionName !== "complete") {
|
|
3078
|
-
this.logger.debug({
|
|
3079
|
-
message: "Decision is 'complete' with action present, treating as 'proceed'",
|
|
3080
|
-
action: actionName
|
|
3081
|
-
});
|
|
3082
|
-
toolCallData.decision = "proceed";
|
|
3083
|
-
}
|
|
3084
3107
|
if (toolCallData.decision === "complete") {
|
|
3085
3108
|
return await this.createCompletionResult("Task completed", parentSpan);
|
|
3086
3109
|
}
|