Skip to main content
Glama

plan_intent

Generate execution plans with policy checkpoints to coordinate and manage intent workflows through memory gateway capabilities.

Instructions

Generate an intent execution plan with policy checkpoints

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
intentIdYes
contextNo
mcpProfileNo
bundleIdNo
partnerProfileNo
delegationModeNo
approvedNo
repoPathNo

Implementation Reference

  • The planIntent function is the core logic for the 'plan_intent' MCP tool. It loads policy bundles, validates intents, ranks actions based on strategy, checks code graph impact, and evaluates delegation.
    function planIntent(options = {}) {
      const bundle = loadPolicyBundle(options.bundleId);
      const profile = assertKnownMcpProfile(options.mcpProfile || getActiveMcpProfile());
      const intentId = String(options.intentId || '').trim();
      const context = String(options.context || '').trim();
      const approved = options.approved === true;
      const tokenBudget = resolveTokenBudget(options.tokenBudget);
      const delegationMode = normalizeDelegationMode(options.delegationMode);
    
      if (!intentId) {
        throw new Error('intentId is required');
      }
    
      const intent = bundle.intents.find((item) => item.id === intentId);
      if (!intent) {
        throw new Error(`Unknown intent: ${intentId}`);
      }
    
      const requiredRisks = getRequiredApprovalRisks(bundle, profile);
      const requiresApproval = requiredRisks.includes(intent.risk);
      const checkpointRequired = requiresApproval && !approved;
      const partnerStrategy = buildPartnerStrategy({
        partnerProfile: options.partnerProfile,
        tokenBudget,
      });
      const rankedActions = rankActions(intent.actions, {
        modelPath: options.modelPath,
        partnerStrategy,
      });
      const plannedActions = partnerStrategy.profile === 'balanced'
        ? intent.actions
        : rankedActions.ranked;
      const phases = decomposeActions(plannedActions);
      const codegraphImpact = analyzeCodeGraphImpact({
        intentId,
        context,
        repoPath: options.repoPath,
      });
      const partnerChecks = mergeUnique([
        ...partnerStrategy.recommendedChecks,
        ...codegraphImpact.verificationHints,
      ]);
      const enrichedPartnerStrategy = {
        ...partnerStrategy,
        recommendedChecks: partnerChecks,
      };
      const basePlan = {
        bundleId: bundle.bundleId,
        mcpProfile: profile,
        partnerProfile: enrichedPartnerStrategy.profile,
        generatedAt: new Date().toISOString(),
        status: checkpointRequired ? 'checkpoint_required' : 'ready',
        intent: {
          id: intent.id,
          description: intent.description,
          risk: intent.risk,
        },
        context,
        requiresApproval,
        approved,
        checkpoint: checkpointRequired
          ? {
            type: 'human_approval',
            reason: `Intent '${intent.id}' has risk '${intent.risk}' under profile '${profile}'.`,
            requiredForRiskLevels: requiredRisks,
          }
          : null,
        actions: plannedActions,
        phases,
        tokenBudget: enrichedPartnerStrategy.tokenBudget || tokenBudget,
        partnerStrategy: enrichedPartnerStrategy,
        actionScores: rankedActions.scores,
        codegraphImpact,
        killSwitches: loadGatesConfig().gates
          .filter((g) => {
            const isHighRisk = ['high', 'critical'].includes(intent.risk);
            if (isHighRisk && (g.severity === 'high' || g.severity === 'critical')) return true;
    
            const actionNames = plannedActions.map((a) => a.name);
            return g.trigger && actionNames.some((name) => g.trigger.toLowerCase().includes(name.toLowerCase()));
          })
          .map((g) => ({
            id: g.id,
            layer: g.layer || 'Execution',
            action: g.action,
            severity: g.severity,
          })),
      };
      const delegation = evaluateDelegation({
        delegationMode,
        plan: basePlan,
        mcpProfile: profile,
        context,
        repoPath: options.repoPath,
      });
    
      return {
        ...basePlan,
        executionMode: delegation.executionMode,
        delegationEligible: delegation.delegationEligible,
        delegationScore: delegation.delegationScore,
        delegationReason: delegation.delegationReason,
        delegateProfile: delegation.delegateProfile,
        handoffContract: delegation.handoffContract,
      };
    }
  • The MCP handler registration for 'plan_intent' calls the planIntent function imported from intent-router.js.
    case 'plan_intent':
      return toTextResult(planIntent({
        intentId: args.intentId,
        context: args.context || '',
        mcpProfile: args.mcpProfile,
        bundleId: args.bundleId,
        partnerProfile: args.partnerProfile,
        delegationMode: args.delegationMode,
        approved: args.approved === true,
        repoPath: args.repoPath,
      }));

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/IgorGanapolsky/mcp-memory-gateway'

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