49.1 Abstract Base Class (Python)
from abc import ABC, abstractmethod
class DataSourcePlugin(ABC):
"""Contract for all data source plugins."""
@abstractmethod
def connect(self, config: dict) -> bool:
"""Establish connection to data source."""
@abstractmethod
def query(self, query: str, params: dict) -> list[dict]:
"""Execute a query and return results."""
@abstractmethod
def health_check(self) -> "HealthStatus":
"""Return current health status."""
@abstractmethod
def get_schema(self) -> "SchemaDefinition":
"""Return the schema of available data."""
def get_capabilities(self) -> list[str]:
"""Optional: declare supported capabilities."""
return ["read"]
49.2 gRPC / Protobuf Contracts
service ToolPlugin {
rpc Execute(ToolRequest) returns (ToolResponse);
rpc GetCapabilities(Empty) returns (CapabilityList);
rpc HealthCheck(Empty) returns (HealthStatus);
}
message ToolRequest {
string tool_name = 1;
map<string, string> parameters = 2;
string request_id = 3;
int32 timeout_ms = 4;
}
message ToolResponse {
bool success = 1;
string result = 2;
string error_message = 3;
map<string, string> metadata = 4;
}
49.3 OpenAPI / JSON Schema Contracts
{
"plugin": {
"name": "ticketing-connector",
"version": "2.1.0",
"capabilities": ["ticketing", "search"],
"tools": [
{
"name": "create_ticket",
"description": "Create a ticket in the ticketing system",
"parameters": {
"type": "object",
"properties": {
"title": {"type": "string", "required": true},
"description": {"type": "string"},
"priority": {"type": "string", "enum": ["P1","P2","P3","P4"]},
"project": {"type": "string", "required": true}
}
},
"returns": {
"type": "object",
"properties": {
"ticket_id": {"type": "string"},
"url": {"type": "string"}
}
}
}
]
}
}
Section 49 — Interview Q&A
Q1: When would you choose gRPC/Protobuf over an ABC-style in-process interface for a plugin contract? An in-process ABC works when plugins run in the same process/runtime as the host — lowest latency, simplest deployment, but no isolation (a misbehaving plugin can crash the host). gRPC/Protobuf is appropriate when plugins run as separate processes or services (for isolation, independent scaling, or polyglot plugin implementations) — it adds network/serialization overhead but gives strong typing across language boundaries, built-in versioning via proto field numbers, and process-level fault isolation. Choose based on whether isolation and polyglot support are worth the added deployment and latency cost.
Q2: What’s the advantage of an OpenAPI/JSON-Schema-based contract specifically for AI-agent-facing plugins? JSON Schema is exactly the format most LLM tool-calling APIs expect for parameter definitions, so a plugin manifest expressed this way can be translated into an LLM tool definition essentially directly, with no separate translation layer to maintain. It’s also self-describing and language-agnostic, which matters when a registry needs to generate tool descriptions for an AI agent dynamically without executing any plugin code.