Skip to main content
Glama
cyqlelabs

MCP Dual-Cycle Reasoner

by cyqlelabs

store_experience

Capture and store problem-solution pairs with outcomes to enhance AI reasoning and recovery using case-based reasoning within the MCP Dual-Cycle Reasoner framework.

Instructions

Store a case for future case-based reasoning

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
outcomeYesWhether the solution was successful
problem_descriptionYesSimple description of the problem
solutionYesWhat action resolved the issue

Implementation Reference

  • The handler function in the Adjudicator class that implements the core logic for storing an experience case: extracts semantic features, computes confidence scores, checks for duplicates, enhances the case, and stores it in the case base with pruning.
    async storeExperience(case_: Case): Promise<void> { if (!this.isInitialized) { await this.initialize(); } // Extract semantic features for better retrieval try { // Check if semantic analyzer is available if (!semanticAnalyzer.isReady()) { throw new Error('SemanticAnalyzer is not ready'); } const problemFeatures = await semanticAnalyzer.extractSemanticFeatures( case_.problem_description, this.semanticIntents ); const solutionFeatures = await semanticAnalyzer.extractSemanticFeatures( case_.solution, this.semanticIntents ); // Combine features from both problem and solution const combinedFeatures = { intents: [...(problemFeatures.intents || []), ...(solutionFeatures.intents || [])], sentiment: case_.outcome ? 'positive' : 'negative', keywords: this.extractKeywords(case_.problem_description + ' ' + case_.solution), }; // Calculate initial confidence score based on various factors const confidenceScore = this.calculateCaseConfidence( case_, problemFeatures, solutionFeatures ); // Enhance the case with computed features const enhancedCase: Case = { ...case_, semantic_features: combinedFeatures as any, confidence_score: confidenceScore, usage_count: 0, success_rate: case_.outcome ? 1.0 : 0.0, }; // Check for duplicates and quality if (this.isDuplicateCase(enhancedCase)) { this.updateExistingCase(enhancedCase); return; } if (confidenceScore < 0.3) { console.warn('Case rejected due to low confidence score:', confidenceScore); return; } // Store the case this.caseBase.push(enhancedCase); this.updateIndex(enhancedCase); // Manage case base size with intelligent pruning if (this.caseBase.length > 1000) { this.pruneeCaseBase(); } } catch (error) { console.error('Error storing experience:', error); // Fallback to simple storage this.caseBase.push(case_); } }
  • Zod schema defining the input parameters for the store_experience tool, including problem_description, solution, outcome, context, and difficulty_level.
    export const StoreExperienceInputSchema = z.object({ problem_description: z.string().describe(DESCRIPTIONS.PROBLEM_DESCRIPTION), solution: z.string().describe(DESCRIPTIONS.SOLUTION), outcome: z.boolean().describe(DESCRIPTIONS.OUTCOME), context: z.string().optional().describe('The context in which this case occurred'), difficulty_level: z .enum(['low', 'medium', 'high']) .optional() .describe('The difficulty level of this case'), });
  • src/server.ts:470-524 (registration)
    Registers the 'store_experience' tool with FastMCP server, including schema (overridden but references StoreExperienceInputSchema), description, and execute handler that validates input, constructs Case, and delegates to Adjudicator.storeExperience.
    private addStoreExperienceTool(): void { this.server.addTool({ name: 'store_experience', description: 'Store a case for future case-based reasoning', parameters: z.object({ problem_description: z.string().describe(DESCRIPTIONS.PROBLEM_DESCRIPTION), solution: z.string().describe(DESCRIPTIONS.SOLUTION), outcome: z.boolean().describe(DESCRIPTIONS.OUTCOME), }), annotations: { title: 'Store Experience Case', readOnlyHint: false, destructiveHint: false, idempotentHint: false, openWorldHint: false, }, execute: async (args, { log, session }) => { try { const sessionEngine = this.getSessionEngine(session); const sessionId = this.sessionIds.get(session); const validatedArgs = StoreExperienceInputSchema.parse(args); log.info('Storing experience case', { problemDescription: validatedArgs.problem_description, solution: validatedArgs.solution, outcome: validatedArgs.outcome, sessionId, }); const caseData = { problem_description: validatedArgs.problem_description, solution: validatedArgs.solution, outcome: validatedArgs.outcome, context: validatedArgs.context, difficulty_level: validatedArgs.difficulty_level, }; const adjudicator = (sessionEngine as any).adjudicator; const storedCase = CaseSchema.parse(caseData); await adjudicator.storeExperience(storedCase); log.info('Experience case stored successfully', { caseId: storedCase.id || 'new', outcome: storedCase.outcome ? 'success' : 'failure', }); return `✅ Experience stored: Case ${storedCase.id || 'new'} added to case base`; } catch (error) { const errorMessage = error instanceof Error ? error.message : String(error); log.error('Failed to store experience', { error: errorMessage }); throw new UserError(`Failed to store experience: ${errorMessage}`); } }, }); }

Other Tools

Related Tools

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/cyqlelabs/mcp-dual-cycle-reasoner'

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