Vega SDK — Provider API

Provider API

BaseCapabilityProvider, provider protocols, and lifecycle types. Prefer top-level imports from vega_capability_sdk in Capability implementation code.

Import

python
from vega_capability_sdk import (
BaseCapabilityProvider,
CancellableProvider,
CapabilityProvider,
PausableProvider,
ProviderLifecycleError,
ProviderLifecycleState,
ReloadableProvider,
ResumableProvider,
)

The same symbols are exported from vega_capability_sdk.provider.

BaseCapabilityProvider

python
class BaseCapabilityProvider:
async def initialize(self, context: ProviderInitializationContext) -> None: ...
async def execute(
self,
request: CapabilityExecutionRequest,
context: CapabilityExecutionContext,
) -> CapabilityExecutionResult: ...
async def health_check(self) -> CapabilityHealthResult: ...
async def shutdown(self) -> None: ...

Convenience base class for a Capability Provider. Override its on_* hooks, not its public lifecycle methods, unless an integration has a specific reason to replace the standard lifecycle behavior. The constructor takes no arguments; a subclass that defines__init__ should call super().__init__().

Properties

TermMeaning
lifecycle_stateCurrent base-provider ProviderLifecycleState.
init_contextProviderInitializationContext from the most recent successful initialization. Raises RuntimeError before initialization or after shutdown.

Override hooks

TermMeaning
on_initialize(context) -> NoneInitialize Provider-owned dependencies.
on_execute(request, context) -> CapabilityExecutionResultImplement an Action execution. Default raises NotImplementedError.
on_health_check() -> CapabilityHealthResultReturn a side-effect-free health result. Default is CapabilityHealthResult.healthy().
on_shutdown() -> NoneRelease Provider-owned resources. Default does nothing.

Lifecycle method behavior

TermMeaning
initialize(context)Allowed from new, stopped, or failed. On success stores context and moves to ready; an exception moves to failed and is re-raised.
execute(request, context)Requires ready. Validates matching execution IDs. Re-raises CapabilityError; wraps other Exception values in ProviderInternalError.
health_check()Returns unknown when not ready. Exceptions from the health hook are contained and reported as unknown.
shutdown()Idempotent after stopped. Cancels tasks created by create_background_task, calls the shutdown hook, clears initialization context, and ends in stopped.

create_background_task

python
def create_background_task(
self,
coroutine: Coroutine[Any, Any, T],
*,
name: str | None = None,
) -> asyncio.Task[T]: ...

Creates a Provider-managed task while the Provider is ready. The task is cancelled and awaited during shutdown. Calling it outside ready closes the provided coroutine and raises ProviderLifecycleError. Completed tasks are removed from the managed set.

Provider protocols

Protocols are runtime-checkable structural interfaces. A class need not inherit from them; it must provide the required members. CapabilityProvider is the minimum contract (initialize, execute, health_check, shutdown).

TermMeaning
CancellableProviderasync cancel(execution_id: str) -> None
PausableProviderasync pause(execution_id: str) -> None
ResumableProviderasync resume(execution_id: str) -> None
ReloadableProviderasync reload_configuration(context: ProviderInitializationContext) -> None
These protocols declare Python capabilities only. They do not add transport, scheduling, or Runtime behavior.

Lifecycle types

ProviderLifecycleState is a StrEnum with new, initializing,ready, stopping, stopped, and failed.ProviderLifecycleError is a RuntimeError subclass raised when an operation is invoked in an invalid Provider lifecycle state.

Example

python
from vega_capability_sdk import (
BaseCapabilityProvider,
CapabilityExecutionResult,
CapabilityHealthResult,
)
class EchoProvider(BaseCapabilityProvider):
async def on_initialize(self, context) -> None:
self._prefix = context.configuration.get("prefix", "")
async def on_execute(self, request, context):
context.cancellation.raise_if_cancelled()
return CapabilityExecutionResult(
output={"text": f"{self._prefix}{request.inputs['text']}"}
)
async def on_health_check(self):
return CapabilityHealthResult.healthy()
async def on_shutdown(self) -> None:
self._prefix = ""