Skip to main content
Glama

break_down_problem

Break complex problems into manageable sub-problems using sequential, hierarchical, or dependency-based approaches to simplify analysis and solution development.

Instructions

break down|divide|split into parts|decompose|step by step|subdivide - Break complex problems into sub-problems

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
problemYesComplex problem to break down
maxDepthNoMaximum breakdown depth
approachNoBreakdown approach

Implementation Reference

  • The main handler function implementing the `break_down_problem` tool. It parses code using TypeScript AST if applicable, generates hierarchical sub-problems recursively, and formats the output as a structured breakdown with execution order.
    export async function breakDownProblem(args: { problem: string; maxDepth?: number; approach?: string }): Promise<ToolResult> {
      const { problem: breakdownProblem, maxDepth = 3, approach = 'hierarchical' } = args;
      
      // If input appears to be code, attempt AST-based structure decomposition
      let codeStructureSubProblems: SubProblem[] | null = null;
      if (breakdownProblem.includes('function') || breakdownProblem.includes('class') || breakdownProblem.includes('=>')) {
        try {
          const sourceFile = AST_PROJECT.createSourceFile('temp.ts', breakdownProblem, {
            overwrite: true,
            scriptKind: ScriptKind.TS
          });
          const funcs = sourceFile.getFunctions();
          const classes = sourceFile.getClasses();
          const vars = sourceFile.getVariableDeclarations();
          codeStructureSubProblems = [];
          funcs.forEach((f, i) => {
            codeStructureSubProblems!.push({
              id: `codeFunc${i+1}`,
              title: `Function analysis: ${f.getName() || 'anonymous function'}`,
              description: f.getText().slice(0, 100) + (f.getText().length > 100 ? '...' : ''),
              complexity: 'medium',
              priority: 'high',
              dependencies: []
            });
          });
          classes.forEach((c, i) => {
            codeStructureSubProblems!.push({
              id: `codeClass${i+1}`,
              title: `Class analysis: ${c.getName() || 'anonymous class'}`,
              description: c.getText().slice(0, 100) + (c.getText().length > 100 ? '...' : ''),
              complexity: 'high',
              priority: 'high',
              dependencies: []
            });
          });
          vars.forEach((v, i) => {
            codeStructureSubProblems!.push({
              id: `codeVar${i+1}`,
              title: `Variable analysis: ${v.getName()}`,
              description: v.getText().slice(0, 100) + (v.getText().length > 100 ? '...' : ''),
              complexity: 'low',
              priority: 'medium',
              dependencies: []
            });
          });
          if (codeStructureSubProblems.length === 0) codeStructureSubProblems = null;
        } catch (e) {
          codeStructureSubProblems = null;
        }
      }
      
      const generateSubProblems = (parentProblem: string, depth: number, maxDepth: number): SubProblem[] | null => {
        if (depth >= maxDepth) return null;
        
        const subProblems: SubProblem[] = [
          {
            id: `${depth}.1`,
            title: `Understanding ${parentProblem}`,
            description: `Analyze and understand the core aspects of ${parentProblem}`,
            complexity: 'low' as const,
            priority: 'high' as const,
            dependencies: []
          },
          {
            id: `${depth}.2`, 
            title: `Planning solution for ${parentProblem}`,
            description: `Create detailed plan to solve ${parentProblem}`,
            complexity: 'medium' as const,
            priority: 'high' as const,
            dependencies: [`${depth}.1`]
          },
          {
            id: `${depth}.3`,
            title: `Implementing solution for ${parentProblem}`,
            description: `Execute the planned solution for ${parentProblem}`,
            complexity: 'high' as const,
            priority: 'medium' as const,
            dependencies: [`${depth}.2`]
          }
        ];
        
        if (depth < maxDepth - 1) {
          subProblems.forEach((subProblem: SubProblem) => {
            subProblem.subProblems = generateSubProblems(subProblem.title, depth + 1, maxDepth);
          });
        }
        
        return subProblems;
      };
      
      const problemBreakdown = {
        action: 'break_down_problem',
        problem: breakdownProblem,
        approach,
        maxDepth,
        breakdown: {
          rootProblem: {
            id: '0',
            title: breakdownProblem,
            description: `Root problem: ${breakdownProblem}`,
            complexity: 'high',
            subProblems: codeStructureSubProblems || generateSubProblems(breakdownProblem, 1, maxDepth)
          }
        },
        executionOrder: approach === 'dependency-based' ? 
          ['Understanding phase', 'Planning phase', 'Implementation phase'] :
          approach === 'sequential' ?
          ['Step 1', 'Step 2', 'Step 3', '...'] :
          ['Top-level analysis', 'Mid-level breakdown', 'Detailed tasks'],
        status: 'success'
      };
      
      const formatSubProblems = (subs: SubProblem[] | null, indent = 0): string => {
        if (!subs) return '';
        return subs.map(s => `${'  '.repeat(indent)}- ${s.title} (${s.complexity}, ${s.priority})${s.subProblems ? '\n' + formatSubProblems(s.subProblems, indent + 1) : ''}`).join('\n');
      };
    
      return {
        content: [{ type: 'text', text: `Problem: ${breakdownProblem}\nApproach: ${approach}\nMax Depth: ${maxDepth}\n\nBreakdown:\n${formatSubProblems(problemBreakdown.breakdown.rootProblem.subProblems)}\n\nExecution: ${problemBreakdown.executionOrder.join(' → ')}` }]
      };
    }
  • The ToolDefinition object defining the schema, description, and annotations for the `break_down_problem` tool.
    export const breakDownProblemDefinition: ToolDefinition = {
      name: 'break_down_problem',
      description: 'break down|divide|split into parts|decompose|step by step|subdivide - Break complex problems into sub-problems',
      inputSchema: {
        type: 'object',
        properties: {
          problem: { type: 'string', description: 'Complex problem to break down' },
          maxDepth: { type: 'number', description: 'Maximum breakdown depth' },
          approach: { type: 'string', description: 'Breakdown approach', enum: ['sequential', 'hierarchical', 'dependency-based'] }
        },
        required: ['problem']
      },
      annotations: {
        title: 'Break Down Problem',
        audience: ['user', 'assistant']
      }
    };
  • src/index.ts:622-623 (registration)
    The switch case in the tool execution dispatcher that routes calls to `break_down_problem` to the handler function.
    case 'break_down_problem':
      return await breakDownProblem(args as any) as CallToolResult;
  • src/index.ts:116-116 (registration)
    Inclusion of the tool definition in the central `tools` array used for listing available tools.
    breakDownProblemDefinition,
  • src/index.ts:80-80 (registration)
    Import statement bringing in the handler and definition for use in the main server.
    import { breakDownProblem, breakDownProblemDefinition } from './tools/thinking/breakDownProblem.js';

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/ssdeanx/ssd-ai'

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