@mcpc-tech/core 0.2.6 → 0.2.7-beta.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/index.mjs +66 -12
- 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
|
|
@@ -1497,13 +1515,13 @@ var AgenticExecutor = class {
|
|
|
1497
1515
|
this.tracingEnabled = false;
|
|
1498
1516
|
}
|
|
1499
1517
|
}
|
|
1500
|
-
async execute(args, schema) {
|
|
1518
|
+
async execute(args, schema, parentSpan) {
|
|
1501
1519
|
const executeSpan = this.tracingEnabled ? startSpan("mcpc.agentic_execute", {
|
|
1502
1520
|
agent: this.name,
|
|
1503
1521
|
action: String(args[this.ACTION_KEY] ?? "unknown"),
|
|
1504
1522
|
nextAction: String(args[this.NEXT_ACTION_KEY] ?? "none"),
|
|
1505
1523
|
args: JSON.stringify(args)
|
|
1506
|
-
}) : null;
|
|
1524
|
+
}, parentSpan ?? void 0) : null;
|
|
1507
1525
|
try {
|
|
1508
1526
|
const validationResult = this.validate(args, schema);
|
|
1509
1527
|
if (!validationResult.valid) {
|
|
@@ -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
|
];
|
|
@@ -2157,13 +2175,24 @@ var BaseSamplingExecutor = class {
|
|
|
2157
2175
|
role: "user",
|
|
2158
2176
|
content: {
|
|
2159
2177
|
type: "text",
|
|
2160
|
-
text: 'Required fields missing
|
|
2178
|
+
text: 'Required fields missing. During execution provide: {"action":"<tool>","decision":"proceed|retry","<tool>":{}}. When complete provide: {"decision":"complete"}'
|
|
2179
|
+
}
|
|
2180
|
+
});
|
|
2181
|
+
if (iterationSpan) endSpan(iterationSpan);
|
|
2182
|
+
continue;
|
|
2183
|
+
}
|
|
2184
|
+
if (parsedData["decision"] === "complete" && action) {
|
|
2185
|
+
this.conversationHistory.push({
|
|
2186
|
+
role: "user",
|
|
2187
|
+
content: {
|
|
2188
|
+
type: "text",
|
|
2189
|
+
text: 'Invalid: Cannot have both "decision":"complete" and "action" field. When complete, only provide {"decision":"complete"}.'
|
|
2161
2190
|
}
|
|
2162
2191
|
});
|
|
2163
2192
|
if (iterationSpan) endSpan(iterationSpan);
|
|
2164
2193
|
continue;
|
|
2165
2194
|
}
|
|
2166
|
-
const result = await this.processAction(parsedData, schema, state,
|
|
2195
|
+
const result = await this.processAction(parsedData, schema, state, iterationSpan);
|
|
2167
2196
|
this.logIterationProgress(parsedData, result, model, stopReason, role);
|
|
2168
2197
|
if (iterationSpan) {
|
|
2169
2198
|
let rawJson = "{}";
|
|
@@ -2443,12 +2472,25 @@ var SamplingExecutor = class extends BaseSamplingExecutor {
|
|
|
2443
2472
|
}
|
|
2444
2473
|
async processAction(parsedData, schema, _state, parentSpan) {
|
|
2445
2474
|
const toolCallData = parsedData;
|
|
2475
|
+
const isComplete = toolCallData.decision === "complete";
|
|
2476
|
+
const actionName = toolCallData.action;
|
|
2477
|
+
if (isComplete && actionName) {
|
|
2478
|
+
return {
|
|
2479
|
+
content: [
|
|
2480
|
+
{
|
|
2481
|
+
type: "text",
|
|
2482
|
+
text: 'Invalid: Cannot have both "decision":"complete" and "action" field. When complete, only provide {"decision":"complete"}. When executing, provide {"action":"<tool>","decision":"proceed|retry","<tool>":{}}.'
|
|
2483
|
+
}
|
|
2484
|
+
],
|
|
2485
|
+
isError: true
|
|
2486
|
+
};
|
|
2487
|
+
}
|
|
2446
2488
|
if (toolCallData.decision === "complete") {
|
|
2447
2489
|
return await this.createCompletionResult("Task completed", parentSpan);
|
|
2448
2490
|
}
|
|
2449
2491
|
try {
|
|
2450
2492
|
const { action: _action, decision: _decision, ..._toolArgs } = toolCallData;
|
|
2451
|
-
const toolResult = await this.agenticExecutor.execute(toolCallData, schema);
|
|
2493
|
+
const toolResult = await this.agenticExecutor.execute(toolCallData, schema, parentSpan);
|
|
2452
2494
|
const resultText = toolResult.content?.filter((content) => content.type === "text")?.map((content) => content.text)?.join("\n") || "No result";
|
|
2453
2495
|
this.conversationHistory.push({
|
|
2454
2496
|
role: "assistant",
|
|
@@ -2490,8 +2532,7 @@ ${JSON.stringify(context2, null, 2)}`;
|
|
|
2490
2532
|
## Current Task
|
|
2491
2533
|
You will now use agentic sampling to complete the following task: "${userRequest}"${contextInfo}
|
|
2492
2534
|
|
|
2493
|
-
When you need to use a tool, specify the tool name in 'action' and provide tool-specific parameters as additional properties
|
|
2494
|
-
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.`;
|
|
2495
2536
|
return this.injectJsonInstruction({
|
|
2496
2537
|
prompt: basePrompt + taskPrompt,
|
|
2497
2538
|
schema: agenticSchema
|
|
@@ -3063,6 +3104,19 @@ var WorkflowSamplingExecutor = class extends BaseSamplingExecutor {
|
|
|
3063
3104
|
throw new Error("WorkflowState is required for workflow");
|
|
3064
3105
|
}
|
|
3065
3106
|
const toolCallData = parsedData;
|
|
3107
|
+
const isComplete = toolCallData.decision === "complete";
|
|
3108
|
+
const actionName = toolCallData.action;
|
|
3109
|
+
if (isComplete && actionName) {
|
|
3110
|
+
return {
|
|
3111
|
+
content: [
|
|
3112
|
+
{
|
|
3113
|
+
type: "text",
|
|
3114
|
+
text: 'Invalid: Cannot have both "decision":"complete" and "action" field. When complete, only provide {"decision":"complete"}. When executing, provide {"action":"<tool>","decision":"proceed|retry","<tool>":{}}.'
|
|
3115
|
+
}
|
|
3116
|
+
],
|
|
3117
|
+
isError: true
|
|
3118
|
+
};
|
|
3119
|
+
}
|
|
3066
3120
|
if (toolCallData.decision === "complete") {
|
|
3067
3121
|
return await this.createCompletionResult("Task completed", parentSpan);
|
|
3068
3122
|
}
|