Skip to main content
Glama
thinking.ts3.02 kB
import { z } from "zod"; export const sequentialThinkingSchema = { name: "sequential_thinking", description: "A tool to facilitate sequential, structured thinking. It forces the AI to break down complex problems into steps, validating each before moving to the next. Use this when facing a complex coding task or architectural decision.", inputSchema: z.object({ thought: z .string() .describe("The current thought or step in the reasoning process."), step: z.number().describe("The current step number (1-indexed)."), total_steps: z.number().describe("The estimated total number of steps."), is_revision: z .boolean() .optional() .describe("Set to true if revising a previous step."), next_action: z .enum(["CONTINUE", "REVISE", "The final conclusion or answer"]) .describe( "What to do next: continue thinking, revise previous thoughts, or provide the final answer.", ), }), }; export function sequentialThinkingHandler(args: any) { // Logic to analyze "thought" depth and offer simple guidance const { thought, step, total_steps, next_action, is_revision } = args; const complexityScore = thought.length; const complexityLevel = complexityScore > 500 ? "High" : complexityScore > 100 ? "Medium" : "Low"; const warnings: string[] = []; const suggestions: string[] = []; // 1. Validation Logic if (step > total_steps) { warnings.push( `Current step (${step}) exceeds total steps (${total_steps}). Increase total_steps if more work is needed.`, ); } if (step === total_steps && next_action === "CONTINUE") { warnings.push( "You are at the final step but chose CONTINUE. Did you mean to conclude or do you need more steps?", ); } if (is_revision && next_action !== "REVISE" && next_action !== "CONTINUE") { // If we are revising, we might conclude, but usually we continue after revision. // This is just a weak check. } // 2. Thought Quality Check if ( complexityLevel === "Low" && next_action === "The final conclusion or answer" ) { suggestions.push( "Your calculation/thought process seems short. Ensure you have covered all edge cases before concluding.", ); } if (complexityLevel === "High" && next_action !== "REVISE") { suggestions.push( "This step is complex. Consider breaking it down further or using REVISE to double-check key assumptions.", ); } const assessment = { valid: warnings.length === 0, quality: complexityLevel, warnings, suggestions: suggestions.length > 0 ? suggestions : ["Proceed with next step."], }; return { content: [ { type: "text", text: JSON.stringify( { status: "THOUGHT_RECORDED", step, total_steps, thought_complexity: complexityLevel, assessment, next_action, }, null, 2, ), }, ], }; }

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/millsydotdev/Code-MCP'

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