predict_next_action
Predicts the next likely action based on context and previous actions to assist with task planning and workflow optimization.
Instructions
Predict the next likely action based on context
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| context | No | ||
| previousActions | No |
Implementation Reference
- mcp-self-learning-server.js:1028-1041 (registration)Registration of the 'predict_next_action' tool in the MCP server's listTools handler, including name, description, and input schema definition.{ name: 'predict_next_action', description: 'Predict the next likely action based on context', inputSchema: { type: 'object', properties: { context: { type: 'object' }, previousActions: { type: 'array', items: { type: 'string' } } } } },
- mcp-self-learning-server.js:1273-1301 (handler)The core handler function for the 'predict_next_action' tool. It matches the provided previousActions against learned tool sequences in patterns, predicts the next action, sorts by confidence, and returns top 5 predictions.async handlePredictNextAction(args) { const { context, previousActions = [] } = args; const predictions = []; // Find matching patterns for (const [key, pattern] of this.learningEngine.patterns) { const sequence = pattern.features?.toolSequence || []; // Check if previous actions match pattern prefix if (this.sequenceMatches(previousActions, sequence)) { if (sequence.length > previousActions.length) { predictions.push({ action: sequence[previousActions.length], confidence: pattern.confidence, pattern: key }); } } } // Sort by confidence predictions.sort((a, b) => b.confidence - a.confidence); return { success: true, predictions: predictions.slice(0, 5), context: context }; }
- Helper method used by handlePredictNextAction to determine if the previous actions match the prefix of a learned tool sequence.sequenceMatches(actions, sequence) { if (actions.length > sequence.length) return false; for (let i = 0; i < actions.length; i++) { if (actions[i] !== sequence[i]) return false; } return true; }