Chapter 6: Invocation Protocol

6.1 Overview

The Invocation Protocol defines how skill consumers remotely invoke discovered skills. The protocol adopts an asynchronous invocation model that supports status querying and result retrieval.

6.2 Invocation Flow

Three-Step Invocation Model

StepHTTP MethodEndpointDescription
1. Initiate invocationPOST{invocation_endpoint}Submit invocation request, returns execution ID
2. Query statusGET{status_url}/{execution_id}Query execution status
3. Retrieve resultGET{result_url}/{execution_id}Retrieve execution result

Invocation Sequence

Consumer                              Provider
  │                                      │
  │── POST /invoke ──────────────────────→│
  │   {caller, skill_id, inputs}         │
  │                                      │
  │←── 202 Accepted ────────────────────│
  │   {execution_id, status: "accepted"} │
  │                                      │
  │── GET /status/{execution_id} ───────→│
  │                                      │
  │←── {status: "running"} ─────────────│
  │                                      │
  │── GET /status/{execution_id} ───────→│
  │                                      │
  │←── {status: "completed"} ───────────│
  │                                      │
  │── GET /result/{execution_id} ───────→│
  │                                      │
  │←── {output: {...}} ─────────────────│
  │                                      │

6.3 Invocation Request Format

{
  "caller": {
    "id": "ifay-instance-001",
    "type": "ifay",
    "credentials": {
      "api_key": "sk-xxxxx"
    }
  },
  "skill_id": "com.example.translate-v1",
  "inputs": {
    "text": "Hello, world!",
    "target_language": "zh-CN"
  },
  "context": {
    "trace_id": "trace-abc-123",
    "priority": "normal",
    "timeout_ms": 30000
  }
}

Request Fields

FieldTypeRequiredDescription
callerobjectYesCaller identity information
caller.idstringYesCaller unique identifier
caller.typestringYesCaller type (ifay/service/user)
caller.credentialsobjectNoAuthentication credentials
skill_idstringYesTarget skill ID
inputsobjectYesInput parameters (key-value pairs)
contextobjectNoInvocation context
context.trace_idstringNoTrace ID
context.prioritystringNoPriority (low/normal/high)
context.timeout_msnumberNoTimeout duration (milliseconds)

6.4 Invocation Response Format

{
  "execution_id": "exec-789-xyz",
  "status": "completed",
  "skill_id": "com.example.translate-v1",
  "output": {
    "translated_text": "你好,世界!",
    "source_language": "en",
    "target_language": "zh-CN",
    "confidence": 0.98
  },
  "timestamps": {
    "created_at": "2025-03-20T14:30:00Z",
    "updated_at": "2025-03-20T14:30:02Z",
    "completed_at": "2025-03-20T14:30:02Z"
  }
}

Response Fields

FieldTypeRequiredDescription
execution_idstringYesUnique execution identifier
statusExecutionStatusYesExecution status
skill_idstringYesTarget skill ID
outputanyNoOutput data (when completed)
errorobjectNoError information (when failed/timeout)
timestampsobjectYesTimestamp information

Execution Status Enum

StatusDescription
acceptedRequest received, awaiting execution
runningCurrently executing
completedExecution completed successfully
failedExecution failed
timeoutExecution timed out

6.5 Authentication Flow

Before invocation, the consumer checks the auth field in the Skill Descriptor:

Consumer                              Provider
  │                                      │
  │── Read descriptor.auth ──→           │
  │                                      │
  │   auth.type == "api_key"?            │
  │   → Attach API Key in Header         │
  │                                      │
  │   auth.type == "oauth2"?             │
  │   → Execute OAuth 2.0 flow for Token │
  │                                      │
  │   auth.type == "none"?               │
  │   → Invoke directly, no credentials  │
  │                                      │
  │── POST /invoke (with credentials) ──→│
  │                                      │

Authentication Failure Response

When valid credentials are not provided, a 401 error is returned:

{
  "error": {
    "code": "AUTH_REQUIRED",
    "message": "Authentication is required to invoke this skill",
    "details": {
      "required_auth_type": "oauth2",
      "authorization_url": "https://example.com/oauth/authorize"
    }
  }
}

6.6 Timeout and Retry

Timeout Handling

When skill execution exceeds the configured timeout_ms:

{
  "execution_id": "exec-789-xyz",
  "status": "timeout",
  "skill_id": "com.example.translate-v1",
  "error": {
    "code": "EXECUTION_TIMEOUT",
    "message": "Skill execution exceeded the configured timeout of 30000ms",
    "retry": {
      "suggested_delay_ms": 5000,
      "max_attempts": 3
    }
  },
  "timestamps": {
    "created_at": "2025-03-20T14:30:00Z",
    "updated_at": "2025-03-20T14:30:30Z"
  }
}

Retry Strategy

  • Timeout responses include suggested retry delay and maximum retry attempts
  • Consumers should implement exponential backoff retry strategies
  • For unreachable endpoints, exponential backoff is recommended (initial delay × 2^n)