Skip to content

Action registry (forge generation recipe)

The action registry moves cms-ai-forge's generation recipe out of hardcoded Python and into cms_db. Three tables carry it, managed through the cms-api /admin/v1 admin block and consumed by the forge planner (AISD-177) and executor (AISD-178). The design is config-driven composition, code-driven execution: the database holds which steps run, in what order, producing what schema, with what prompt and provider; the task state machine and the provider-call / coercion logic stay in code.

Defined in hq/sql_models/pipeline.py (epic AISD-174, task AISD-175).

The three tables

Table Model class What it holds
ai_actions Action A named workflow -- the intent key an ai-forge job requests (e.g. site_scaffold, article_batch).
ai_steps Step A reusable step definition: an entity_type, the output_schema a provider result must satisfy, an optional prompt and provider kind.
ai_action_steps ActionStep The ordered join binding a step into an action at a position, with a chain flag and per-binding params.

Because a step is reusable, the relationship is many-to-many resolved through the join: one action has many bindings; one step is bound into many actions. The unique constraint (action_id, position) means an action has exactly one step per slot.

Entity relationships · cms_dbPK → FK, with audit mirrors
CONFIG TABLES · OPERATOR-EDITABLE ai_actions idINT PK nameVARCHAR(100) UNIQUE descriptionVARCHAR(255) is_activeTINYINT(1) ai_steps idINT PK slugVARCHAR(100) UNIQUE entity_typeVARCHAR(50) output_schemaJSON NOT NULL required_keysJSON null prompt_templateTEXT null provider_kindVARCHAR(50) null ai_action_steps idINT PK action_idFK → actions.id step_idFK → steps.id positionINT chainTINYINT(1) paramsJSON null 1 N 1 N UNIQUE (action_id, position) — one step per slot AUDIT MIRRORS · WRITTEN ONLY BY AFTER UPDATE TRIGGER ai_action_history action_idINT (no FK), indexed changed_atDATETIME name · description · is_active ai_step_history step_idINT (no FK), indexed changed_atDATETIME slug · entity_type · output_schema required_keys · prompt · provider · is_active trg_ai_actions_history trg_ai_steps_history ai_action_steps is a junction — no history table, no trigger
ordered junctionconfig tableaudit mirror (no FK)

Column & constraint reference

Table Key columns Constraints
ai_actions name (intent key), description, is_active name UNIQUE; history mirror + trg_ai_actions_history
ai_steps slug, entity_type, output_schema (JSON NOT NULL), required_keys, prompt_template, provider_kind slug UNIQUE; entity_type indexed; history mirror + trg_ai_steps_history
ai_action_steps action_id FK, step_id FK, position, chain, params UNIQUE (action_id, position); both FKs indexed; no history

The registry is standalone configuration -- it is deliberately not foreign-keyed to sites or content. The forge reads it to decide how to generate, then writes the produced entities into the content graph through the cms-api admin block.

History mirrors & triggers

ai_actions and ai_steps are operator-editable, so each gets a flat *_history mirror plus an AFTER UPDATE trigger, following the styles-registry pattern used across cms_db (see Data model overview):

  • The mirror has its own surrogate id, a plain indexed id column pointing back at the live row with no foreign key (so history survives a delete), a changed_at stamp, and every mirrored business column nullable.
  • The trigger (trg_ai_actions_history / trg_ai_steps_history, in ddl/0023_forge_action_registry.sql) fires on update, snapshots OLD.* into the mirror, and stamps changed_at = NOW(). ai_step_history mirrors the JSON output_schema / required_keys too, so a prior step definition is fully recoverable.
  • ai_action_steps is a junction and has no history table or trigger.

The trigger and the model stay in lock-step

The mirror model's column list is kept identical to the trigger's INSERT. Changing a mirrored column means editing both pipeline.py and the trigger in ddl/0023.

How the forge resolves and drives an action

At runtime the forge does not read a hardcoded step list. It asks cms-api to resolve the action by name; the response is the action plus its steps flattened and ordered by position. The planner fans the ordered steps into tasks and stamps each task's params["_step_slug"]; the executor reads that slug back to pull the step's output_schema / prompt_template / provider_kind straight from the registry -- the _step_slug is the planner-to-executor hand-off.

Resolve → plan → execute → publishember path = registry-driven
CMS-AI-FORGE CMS-API /ADMIN/V1 · CMS_DB POST /jobs intent = action name planner.plan_job resolve + fan out entity_worker reads _step_slug generate provider → validate publish GET actions/resolve/{name} ActionResolvedOut id · name · description · is_active steps: ResolvedStepOut[] — ordered by position slug · entity_type · output_schema · required_keys · prompt_template · provider_kind · chain · params ai_actions —< ai_action_steps >— ai_steps _effective_* graceful fallback on miss / outage / bad JSON catches CmsPublisherError, httpx.HTTPError, ValueError → hardcoded Generator path
registry-driven stepresolve payloadterminal okfallback path

The resolve endpoint (GET /admin/v1/actions/resolve/{name}) returns the action plus its steps, each step definition flattened onto its ordered binding:

{
  "id": 3, "name": "site_scaffold", "is_active": true,
  "steps": [
    {
      "action_step_id": 12, "step_id": 7, "position": 0, "chain": false,
      "slug": "generate_settings", "entity_type": "settings",
      "provider_kind": "openai_text",
      "output_schema": { },
      "required_keys": ["meta_title", "nav"],
      "prompt_template": "You are setting up ...",
      "params": null
    }
  ]
}

A zero-step action resolves to a 404, so the planner never fans out an empty recipe. On any resolve miss, outage, or malformed schema the forge degrades to its hardcoded generator path -- the registry accelerates the pipeline, it never becomes a hard dependency. See the cms-ai-forge docs for the consuming side and cms-api docs for the full admin surface.

How the tables are built

  • Built from Base.metadata.create_all() -- the models in pipeline.py are authoritative for the table/column shapes.
  • Post-create step ddl/0023_forge_action_registry.sql adds the two AFTER UPDATE history triggers (idempotent DROP ... IF EXISTS + CREATE). There is no seed data in the DDL; seeding today's intents as action/step rows is a separate concern (hq/scripts/seed_action_registry.py, AISD-179/181).
  • Drift-checked by hq.cms.db check against this metadata.