Skip to main content
Glama

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
NameRequiredDescriptionDefault
contextNo
previousActionsNo

Implementation Reference

  • 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' } } } } },
  • 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; }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/saralegui-solutions/mcp-self-learning-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server