Extend Service with App plugins
Package and install trusted Python App plugins to add custom APIs, Console pages, database tables, Harness plugins, and metrics to Service.
App plugins extend Service with domain APIs (/api/v1/apps/<app_id>/...), organization background sweeps, Harness plugin factories, PostgreSQL tables, and Console UI pages while reusing Service's authentication, workspaces, and agent runtime.
App plugins run in-process with Service permissions. Install identical package versions across all control and worker processes (or all), and enable each App per organization.
Scaffold and run an App locally
Generate a standalone project from the App plugin template and start the local stack:
uvx cookiecutter gh:converge-ai-labs/agent-foundation --checkout template/app-plugin
cd my-service-app
make devmake dev starts PostgreSQL, Redis, and S3, runs migrations, and launches Service with hot reload. Sign in to Console, open Settings → Organization → App plugins, and enable your App. See examples/service-app-plugin for a complete reference implementation.
Register an App definition
Expose a zero-argument factory under a13n_service.app_plugins matching AppDefinition.app_id:
[project.entry-points."a13n_service.app_plugins"]
"acme.reports" = "acme_reports.app:definition"from a13n_service.app_definitions import AppDefinition
from a13n_service.tenancy.app_plugins import app_router
from a13n_service.tenancy.requests import Actor, WorkspaceId
router = app_router("acme.reports")
@router.get("/summary", name="get_acme_report_summary", openapi_extra={"x-a13n-mcp": True})
async def summary(actor: Actor, workspace_id: WorkspaceId) -> dict[str, str]:
return {"workspace_id": workspace_id, "requested_by": actor.id}
def definition() -> AppDefinition:
return AppDefinition(app_id="acme.reports", name="Reports", routers=(router,))factory_keys: Claim owned Harness plugin factories (registered undera13n_harness.plugins; see Plugins and extensions), e.g.factory_keys=frozenset({"acme.audit"}).OrganizationSweep&startup: Usestartup(runtime, stack)for per-process resources andOrganizationSweepfor replica-safe periodic background work on enabled organizations.
Use the in-process App SDK and Run seals
Import a13n_service.app_sdk to manage native Threads, Schedules, and App-owned egress credentials atomically alongside your business tables:
- Threads & submissions: Call
threads.prepare_admission(session, runtime, workspace_id, principal_id, app_id=...)before locking App rows, then callthreads.create_thread_in_transactionorthreads.submit_message_in_transactionusing a workspace Service Account withrunpermission. Usethreads.update_thread_resourcesto update a root Thread and its shared-Environment descendants. - App-owned egress credentials: Manage tokens with
egress.create_app_credential,rotate_app_credential, andrevoke_app_credential(or their*_in_transactionvariants to commit with App state; active Sessions are notified after commit). - Thread egress bindings: Call
threads.update_app_egress_secretswithset_secrets(egress.SecretReference) orremove_envson an idle shared Thread subtree while preserving existing destinations and other owners' secrets. When initializing an unset binding, passinitial_destinations(such asAllowlistDestinations(mode="allowlist", hosts=("api.example.com",))froma13n_envd_client.eip.v1). - Run seals: Subscribe to terminal or
waitingRun completions viaRunSealSubscription(callback, timeout=5)onAppDefinition(run_seals=(...,)). Treat seal hints as at-least-once/best-effort wakeups and reconcile durable state in anOrganizationSweep.
Persist business data
Use AppDatabase to manage App tables in PostgreSQL (public schema with an isolated table/migration prefix) and join native Service rows on the same pool:
from a13n_service.app_database import AppDatabase
from a13n_service.tenancy.tables import WorkspaceRow
from sqlalchemy import ForeignKey
from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column
database = AppDatabase("acme.reports", migrations="acme_reports:migrations")
database.reference(WorkspaceRow.__table__)
class Base(DeclarativeBase):
metadata = database.metadata
class Note(Base):
__tablename__ = database.name("notes")
id: Mapped[int] = mapped_column(primary_key=True)
workspace_id: Mapped[str] = mapped_column(ForeignKey("workspaces.id"), index=True)
body: Mapped[str]Pass database=database to AppDefinition, then author and verify migrations against a scratch PostgreSQL URL:
a13n-service apps db init --app acme.reports
a13n-service apps db revision --app acme.reports -m "create notes" --scratch-url "$APP_TEST_POSTGRES_URL"
a13n-service apps db check --app acme.reports --scratch-url "$APP_TEST_POSTGRES_URL"Use short_session(runtime.storage) or transaction(runtime.storage) from a13n_service.infra.db for short async queries. control, all, or a13n-service migrate upgrades Core and installed App schemas before worker replicas start.
Add a Console page
Bundle a frontend ESM entry with @a13n/console externalized, export an AppContribution as the default export, and attach Frontend to AppDefinition:
import { React, useApp, useQuery } from "@a13n/console";
import type { AppContribution } from "@a13n/console";
function ReportsPage() {
const app = useApp();
const summary = useQuery({
queryKey: app.queryKey("summary"),
queryFn: async ({ signal }) => (await app.request("/summary", { signal })).json(),
});
return <div>{summary.data?.workspace_id}</div>;
}
export default {
pages: [{ path: "reports", label: { en: "Reports", "zh-CN": "报告" }, component: ReportsPage }],
} satisfies AppContribution;from a13n_service.app_plugins import Frontend
frontend = Frontend(
package="acme_reports", directory="static", entry="index.js", styles=("index.css",)
)Export TypeScript declarations for editor completion and make typecheck with:
python -m a13n_service.console_sdk frontend/.console-sdk/index.d.tsReport custom metrics
Emit custom business metrics with opentelemetry-api under your App's prefix; Service exports them on its /metrics endpoint alongside host metrics:
from opentelemetry import metrics
meter = metrics.get_meter("acme.reports")
previews = meter.create_counter("acme.reports.previews", description="Report previews completed")Keep attribute values bounded—never attach workspace, user, or run IDs, raw URLs, or secrets as metric labels.
Deploy and enable Apps
- Install the exact same App wheel versions into every
controlandworkerenvironment (and runa13n-service migrateif auto-migrate is disabled). - Optionally enable Apps on first bootstrap via
service.toml:
[plugins]
bootstrap_enabled_apps = ["acme.reports"]- Enable or disable an installed App for an organization in Settings → Organization → App plugins or via API (
GETthe organization ETag, thenPUT /api/v1/organizations/{org_id}/app-plugins/acme.reportswithIf-Matchand{"enabled": true}). Accepted runs retain their enabled-App snapshot until completion.