Skip to main content
Glama

start_handoff

Destructive

Begin a sequential delegation handoff from an intent plan that has been approved for delegation. This passes control to the next delegate in the chain to continue execution.

Instructions

Start a sequential delegation handoff from a delegation-eligible intent plan

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
intentIdYes
contextNo
mcpProfileNo
bundleIdNo
partnerProfileNo
approvedNo
repoPathNo
delegateProfileNo
plannedChecksNo

Implementation Reference

  • The startHandoff function implements the core tool logic: evaluates delegation eligibility, validates MCP profile constraints (dispatch/locked), checks delegate profile consistency, scores reliability, persists a 'started' event, and returns the handoffId, taskKey, status, delegateProfile, and handoffContract.
    function startHandoff(params = {}) {
      const evaluation = evaluateDelegation({
        delegationMode: 'sequential',
        plan: params.plan,
        mcpProfile: params.mcpProfile,
        context: params.context,
        repoPath: params.repoPath,
        plannedChecks: params.plannedChecks,
      });
    
      if (String(params.mcpProfile || '').trim() === 'dispatch') {
        persistRejectedStart({
          taskKey: evaluation.taskKey,
          intentId: params.plan && params.plan.intent ? params.plan.intent.id : null,
          delegateProfile: null,
          mcpProfile: params.mcpProfile,
          partnerProfile: params.partnerProfile,
          reasonCode: 'dispatch_profile',
          reason: 'Dispatch MCP profile may not start handoffs.',
          context: params.context,
          repoPath: params.repoPath,
        });
        throw createDelegationError('Dispatch MCP profile may not start handoffs.', 403);
      }
    
      if (String(params.mcpProfile || '').trim() === 'locked') {
        persistRejectedStart({
          taskKey: evaluation.taskKey,
          intentId: params.plan && params.plan.intent ? params.plan.intent.id : null,
          delegateProfile: null,
          mcpProfile: params.mcpProfile,
          partnerProfile: params.partnerProfile,
          reasonCode: 'locked_profile',
          reason: 'Locked MCP profile may not start handoffs.',
          context: params.context,
          repoPath: params.repoPath,
        });
        throw createDelegationError('Locked MCP profile may not start handoffs.', 403);
      }
    
      if (!evaluation.delegationEligible || evaluation.executionMode !== 'sequential_delegate') {
        persistRejectedStart({
          taskKey: evaluation.taskKey,
          intentId: params.plan && params.plan.intent ? params.plan.intent.id : null,
          delegateProfile: evaluation.delegateProfile,
          mcpProfile: params.mcpProfile,
          partnerProfile: params.partnerProfile,
          reasonCode: evaluation.reasonCode,
          reason: evaluation.delegationReason,
          context: params.context,
          repoPath: params.repoPath,
        });
        throw createDelegationError(evaluation.delegationReason, evaluation.reasonCode === 'unresolved_handoff_exists' ? 409 : 422, {
          reasonCode: evaluation.reasonCode,
        });
      }
    
      if (params.delegateProfile && params.delegateProfile !== evaluation.delegateProfile) {
        persistRejectedStart({
          taskKey: evaluation.taskKey,
          intentId: params.plan && params.plan.intent ? params.plan.intent.id : null,
          delegateProfile: params.delegateProfile,
          mcpProfile: params.mcpProfile,
          partnerProfile: params.partnerProfile,
          reasonCode: 'delegate_profile_mismatch',
          reason: 'Requested delegateProfile does not match the planner-selected profile.',
          context: params.context,
          repoPath: params.repoPath,
        });
        throw createDelegationError('Requested delegateProfile does not match the planner-selected profile.', 400);
      }
    
      const { DELEGATION_LOG_PATH } = getDelegationPaths();
      const handoffId = `handoff_${Date.now()}_${Math.random().toString(36).slice(2, 8)}`;
      const event = {
        eventType: 'started',
        handoffId,
        taskKey: evaluation.taskKey,
        intentId: params.plan.intent.id,
        delegateProfile: evaluation.delegateProfile,
        mcpProfile: params.mcpProfile,
        partnerProfile: params.partnerProfile || null,
        context: normalizeText(params.context || params.plan.context || ''),
        repoPath: params.repoPath || null,
        plannedChecks: unique([
          ...(Array.isArray(params.plannedChecks) ? params.plannedChecks : []),
          ...(evaluation.handoffContract && Array.isArray(evaluation.handoffContract.requiredChecks)
            ? evaluation.handoffContract.requiredChecks
            : []),
        ]),
        contract: evaluation.handoffContract,
        delegationScore: evaluation.delegationScore,
        timestamp: new Date().toISOString(),
      };
    
      appendJSONL(DELEGATION_LOG_PATH, event);
    
      return {
        handoffId,
        taskKey: event.taskKey,
        status: 'started',
        executionMode: 'sequential_delegate',
        delegateProfile: event.delegateProfile,
        handoffContract: event.contract,
      };
    }
  • MCP server handler for 'start_handoff': loads the intentRouter and delegationRuntime modules, plans the intent, then calls delegationRuntime.startHandoff() with plan, context, mcpProfile, partnerProfile, repoPath, delegateProfile, and plannedChecks.
    case 'start_handoff':
      {
        const intentRouter = loadPrivateMcpModule('intentRouter');
        const delegationRuntime = loadPrivateMcpModule('delegationRuntime');
        if (!intentRouter || !delegationRuntime) return unavailablePrivateMcpFeature('start_handoff');
        return toTextResult(delegationRuntime.startHandoff({
          plan: intentRouter.planIntent({
            intentId: args.intentId,
            context: args.context || '',
            mcpProfile: args.mcpProfile,
            bundleId: args.bundleId,
            partnerProfile: args.partnerProfile,
            delegationMode: 'sequential',
            approved: args.approved === true,
            repoPath: args.repoPath,
          }),
          context: args.context || '',
          mcpProfile: args.mcpProfile || getActiveMcpProfile(),
          partnerProfile: args.partnerProfile || null,
          repoPath: args.repoPath,
          delegateProfile: args.delegateProfile || null,
          plannedChecks: Array.isArray(args.plannedChecks) ? args.plannedChecks : [],
        }));
      }
  • evaluateDelegation function evaluates whether a handoff is eligible based on delegationMode, semantic phases, delegate profile compatibility, context budget, active handoffs, recent failures, and reliability score threshold (>=0.6). Returns delegationEligible, executionMode, delegateProfile, handoffContract, score, and reasonCode.
    function evaluateDelegation(params = {}) {
      const delegationMode = normalizeDelegationMode(params.delegationMode);
      const plan = params.plan || {};
      const mcpProfile = String(params.mcpProfile || plan.mcpProfile || 'default').trim();
      const context = String(params.context || plan.context || '');
      const repoPath = params.repoPath || null;
      const taskKey = buildTaskKey({
        intentId: plan.intent && plan.intent.id,
        repoPath,
        context,
      });
      const semanticPhases = deriveSemanticPhases(plan.actions);
      const hasEvidence = semanticPhases.some((phase) => phase.kind === 'evidence');
      const hasMutation = semanticPhases.some((phase) => phase.kind === 'mutation');
      const contextDigest = buildContextDigest(plan, context);
      const contextChars = contextDigest.length;
      const selection = selectDelegateProfile({ mcpProfile, plan, contextChars });
      const { DELEGATION_MODEL_PATH } = getDelegationPaths();
      const model = loadDelegationModel(DELEGATION_MODEL_PATH);
      const events = readDelegationEvents();
      const activeHandoffs = deriveActiveHandoffs(events);
      const activeHandoff = activeHandoffs.byTaskKey.get(taskKey) || null;
      const reliabilityBias = selection.delegateProfile
        ? getReliabilityBias(model, [
          'delegation_global',
          `intent_${plan.intent && plan.intent.id}`,
          `profile_${selection.delegateProfile}`,
        ])
        : 0;
      const recentFailure = selection.delegateProfile
        ? hasRecentSimilarFailure(events, plan.intent && plan.intent.id, selection.delegateProfile)
        : false;
    
      let score = 0;
      if (semanticPhases.length >= 2) score += 0.25;
      else score -= 0.30;
    
      if (hasEvidence && hasMutation) score += 0.15;
      if (selection.delegateProfile) score += 0.15;
      if (plan.codegraphImpact && plan.codegraphImpact.enabled && Array.isArray(plan.codegraphImpact.verificationHints) && plan.codegraphImpact.verificationHints.length > 0) {
        score += 0.10;
      }
      if (selection.contextFits) score += 0.10;
      else if (selection.delegateProfile) score -= 0.20;
      score += reliabilityBias;
      if (recentFailure) score -= 0.25;
    
      score = Number(Math.max(0, Math.min(1, score)).toFixed(3));
    
      let reasonCode = 'delegation_disabled';
      let delegationReason = 'Delegation is disabled for this plan.';
      let delegationEligible = false;
      let executionMode = 'single_agent';
      let delegateProfile = null;
      let handoffContract = null;
    
      if (delegationMode !== 'off') {
        if (plan.status !== 'ready') {
          reasonCode = 'checkpoint_required';
          delegationReason = 'Delegation is blocked until the required approval checkpoint is cleared.';
        } else if (mcpProfile === 'dispatch') {
          reasonCode = 'dispatch_profile';
          delegationReason = 'Dispatch MCP profile may inspect plans and metrics, but remote handoffs stay disabled.';
        } else if (mcpProfile === 'locked') {
          reasonCode = 'locked_profile';
          delegationReason = 'Locked MCP profile may inspect the plan but cannot start a handoff.';
        } else if (semanticPhases.length < 2) {
          reasonCode = 'single_phase_task';
          delegationReason = 'Delegation was skipped because the task collapses into a single semantic phase.';
        } else if ((plan.actions || []).length < 3) {
          reasonCode = 'insufficient_actions';
          delegationReason = 'Delegation was skipped because the task does not have enough action surface to justify a handoff.';
        } else if (!selection.delegateProfile) {
          reasonCode = 'no_compatible_delegate';
          delegationReason = 'Delegation was skipped because no existing delegate profile can execute the required actions within policy.';
        } else if (!selection.contextFits) {
          reasonCode = 'budget_exceeded';
          delegationReason = 'Delegation was skipped because the context exceeds the selected delegate profile budget.';
        } else if (activeHandoff) {
          reasonCode = 'unresolved_handoff_exists';
          delegationReason = 'Delegation is blocked because an unresolved handoff already exists for this task.';
        } else if (recentFailure) {
          reasonCode = 'recent_failure';
          delegationReason = 'Delegation confidence was reduced by a recent similar failure, so the planner kept the task single-agent.';
        } else if (score < 0.6) {
          reasonCode = 'low_score';
          delegationReason = 'Delegation was considered but the reliability score did not clear the handoff threshold.';
        } else {
          reasonCode = 'delegation_selected';
          delegationReason = 'Delegation cleared the structural, budget, and reliability checks.';
          delegationEligible = true;
          executionMode = 'sequential_delegate';
          delegateProfile = selection.delegateProfile;
          handoffContract = buildHandoffContract({
            plan,
            delegateProfile,
            plannedChecks: params.plannedChecks,
          });
        }
      }
    
      return {
        delegationMode,
        executionMode,
        delegationEligible,
        delegationScore: executionMode === 'sequential_delegate' ? score : 0,
        delegationReason,
        delegateProfile,
        handoffContract,
        reasonCode,
        rawDelegationScore: score,
        taskKey,
        activeHandoffId: activeHandoff ? activeHandoff.handoffId : null,
        semanticPhases,
        contextChars,
      };
    }
  • buildHandoffContract is called within evaluateDelegation to construct the handoff contract including required checks.
        plannedChecks: params.plannedChecks,
      });
    }
  • PRIVATE_MCP_MODULES mapping that resolves 'delegationRuntime' to scripts/delegation-runtime.js, loaded dynamically in the start_handoff handler.
    const PRIVATE_MCP_MODULES = Object.freeze({
      intentRouter: path.resolve(__dirname, '../../scripts/intent-router.js'),
      delegationRuntime: path.resolve(__dirname, '../../scripts/delegation-runtime.js'),
      orgDashboard: path.resolve(__dirname, '../../scripts/org-dashboard.js'),
      reflectorAgent: path.resolve(__dirname, '../../scripts/reflector-agent.js'),
      swarmCoordinator: path.resolve(__dirname, '../../scripts/swarm-coordinator.js'),
      sessionReport: path.resolve(__dirname, '../../scripts/session-report.js'),
      operatorArtifacts: path.resolve(__dirname, '../../scripts/operator-artifacts.js'),
      managedLessonAgent: path.resolve(__dirname, '../../scripts/managed-lesson-agent.js'),
      semanticLayer: path.resolve(__dirname, '../../scripts/semantic-layer.js'),
      lessonInference: path.resolve(__dirname, '../../scripts/lesson-inference.js'),
      lessonSearch: path.resolve(__dirname, '../../scripts/lesson-search.js'),
    });
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

The description adds little beyond the tool's name. Although annotations indicate destructiveHint: true, the description does not explain what is destroyed, side effects, permissions, or post-conditions. For a mutation tool, more behavioral context is expected.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, focused sentence with no redundancy. It efficiently communicates the core action, though it could be expanded with parameter guidance without losing conciseness.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness1/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given 9 parameters, no output schema, and only a brief sentence, the description is severely incomplete. It fails to explain the handoff flow, parameter roles, or expected outcomes, making it insufficient for an agent to use the tool correctly.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters1/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

With 9 parameters and 0% schema description coverage, the description provides no explanation of any parameter. Even key fields like context, mcpProfile, or bundleId remain undefined, leaving the agent to guess their meaning.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action (start), mechanism (sequential delegation handoff), and context (delegation-eligible intent plan), effectively distinguishing from sibling tools like complete_handoff or session_handoff.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No guidance on when to use this tool versus alternatives such as complete_handoff or session_handoff. The description does not provide context for choosing this over other handoff-related tools.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other 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/IgorGanapolsky/ThumbGate'

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