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.
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), achanged_atstamp, and every mirrored business column nullable. - The trigger (
trg_ai_actions_history/trg_ai_steps_history, inddl/0023_forge_action_registry.sql) fires on update, snapshotsOLD.*into the mirror, and stampschanged_at = NOW().ai_step_historymirrors the JSONoutput_schema/required_keystoo, so a prior step definition is fully recoverable. ai_action_stepsis 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.
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 inpipeline.pyare authoritative for the table/column shapes. - Post-create step
ddl/0023_forge_action_registry.sqladds the twoAFTER UPDATEhistory triggers (idempotentDROP ... 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 checkagainst this metadata.