Skip to main content
Glama

complete_handoff

Finalize sequential delegation handoffs by recording verification outcomes including acceptance, rejection, or abortion status with performance metrics.

Instructions

Complete a sequential delegation handoff and record verification outcomes

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
handoffIdYes
outcomeYes
resultContextNo
attemptsNo
violationCountNo
tokenEstimateNo
latencyMsNo
summaryNo

Implementation Reference

  • The core logic of the complete_handoff tool, which validates the outcome, checks for an active handoff, optionally runs a verification loop, and writes the delegation completion event.
    function completeHandoff(params = {}) {
      const outcome = String(params.outcome || '').trim().toLowerCase();
      if (!HANDOFF_OUTCOMES.includes(outcome)) {
        throw createDelegationError(`Unsupported handoff outcome '${params.outcome}'`, 400);
      }
    
      const events = readDelegationEvents();
      const active = deriveActiveHandoffs(events).byHandoffId.get(params.handoffId);
      if (!active) {
        throw createDelegationError(`No active handoff found for '${params.handoffId}'`, 404);
      }
    
      const summary = normalizeText(params.summary);
      const resultContext = normalizeText(params.resultContext);
      const missingRequiredEvidence = outcome !== 'aborted' && !summary && !resultContext;
      let verification = null;
    
      if (outcome !== 'aborted' && resultContext) {
        verification = getVerificationLoopModule().runVerificationLoop({
          context: resultContext,
          tags: unique([
            'delegation',
            active.intentId ? `intent:${active.intentId}` : null,
            active.delegateProfile ? `delegate:${active.delegateProfile}` : null,
          ]),
          partnerProfile: active.partnerProfile || null,
          maxRetries: 0,
        });
      }
    
      const verificationAccepted = verification ? verification.accepted : null;
      const negativeOutcome = outcome !== 'accepted' || verificationAccepted === false || missingRequiredEvidence;
      const diagnosis = negativeOutcome
        ? buildDelegationDiagnosis(active, {
          outcome,
          reasonCode: missingRequiredEvidence ? 'missing_required_evidence' : null,
          verification,
        })
        : null;
    
      if (diagnosis && (!verification || !verification.persistedDiagnosis)) {
        getFeedbackLoopModule().appendDiagnosticRecord({
          source: 'delegation_runtime',
          step: diagnosis.criticalFailureStep || 'handoff_completion',
          context: resultContext || summary || active.context || '',
          diagnosis,
          metadata: {
            handoffId: active.handoffId,
            intentId: active.intentId,
            delegateProfile: active.delegateProfile,
            outcome,
          },
        });
      }
    
      if (missingRequiredEvidence) {
        promoteDelegationFailure('missing_required_evidence', {
          intentId: active.intentId,
          delegateProfile: active.delegateProfile,
        });
      }
    
      const { DELEGATION_LOG_PATH } = getDelegationPaths();
      const event = {
        eventType: 'completed',
        handoffId: active.handoffId,
        taskKey: active.taskKey,
        intentId: active.intentId,
        delegateProfile: active.delegateProfile,
        mcpProfile: active.mcpProfile,
        partnerProfile: active.partnerProfile,
        outcome,
        summary: summary || null,
        resultContext: resultContext || null,
        attempts: Number.isFinite(Number(params.attempts)) ? Number(params.attempts) : 1,
  • Tool definition and schema registration for complete_handoff.
    destructiveTool({
      name: 'complete_handoff',
      description: 'Complete a sequential delegation handoff and record verification outcomes',
      inputSchema: {
        type: 'object',
        required: ['handoffId', 'outcome'],
        properties: {
          handoffId: { type: 'string' },
          outcome: { type: 'string', enum: ['accepted', 'rejected', 'aborted'] },
          resultContext: { type: 'string' },
          attempts: { type: 'number' },
          violationCount: { type: 'number' },
          tokenEstimate: { type: 'number' },
          latencyMs: { type: 'number' },
          summary: { type: 'string' },
        },
      },
    }),
    readOnlyTool({
  • MCP server request handler route for 'complete_handoff'.
    case 'complete_handoff':
      return toTextResult(completeHandoff({

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