ai-powered-conversational-intelligence

PROMPT 45 — PROMPT AGENT REGISTRY

Role

Act as a Principal AI Architect, Enterprise Data Platform Architect and Senior Product Engineer.

Mission

Create a governed registry for prompts, agents and analytical policies. Inventory existing prompt templates and agent definitions first. Version artifacts, owners, variables, required tools, compatible models, evaluation suites and deployment status. Validate unsafe composition, missing variables and unapproved tools. Support draft/test/approved/deployed/retired states and rollback. Add regression tests proving prompt changes cannot weaken security or semantic governance.

Mandatory workflow

INSPECT → PLAN → IMPLEMENT → TEST → REVIEW → FIX → DOCUMENT → REPORT

Mandatory controls


OUTCOME

1. INSPECT — what already existed

The single most important inspection finding: Prompt 44 had already built the registry’s entire lifecycle, one session earlier. governance_center/ (commit c86d1f7) ships GovernanceStage (draft → testing → evaluating → approved → deployed, plus rolled_back/rejected/retired), VALID_STAGE_TRANSITIONS, a real rollback action, per-version rows on identity.models.GovernanceAssetVersion with owner/version/stage, an append-only GovernanceEvent audit trail, tenant-scoped ABAC (governance_center/policy.py), two RBAC permissions, and 17 REST routes — across seven asset types that already include prompt, agent and policy.

So this mission’s “version artifacts, owners, deployment status” and “support draft/test/approved/deployed/retired states and rollback” clauses were already satisfied. Building a second registry would have violated the first mandatory control outright.

What genuinely did not exist:

Mission clause State before this prompt
“Inventory existing prompt templates and agent definitions first” Nothing enumerated them. Prompts were 15 private constants scattered across 8 modules; agent definitions lived in one dict nothing else read.
“variables, required tools, compatible models, evaluation suites” GovernanceAssetVersionSnapshot.config is deliberately free-form JSON, documented as “stored and displayed, never evaluated”. No typed field for any of these.
“Validate unsafe composition, missing variables and unapproved tools” No validation of any kind existed for artifact content.
“Regression tests proving prompt changes cannot weaken security or semantic governance” No test anywhere asserted anything about a live prompt’s content.

Also inspected and reused rather than reimplemented: security/injection_patterns.py (the shared pattern dict, 4 existing consumers), agent.multiagent.agents.SPECS (13 live specialists), agent.multiagent.tools’ TOOL_* names and agent.tools.definitions.build_default_registry (two separate tool registries, 18 names between them), agent.model_registry’s notion of an allowed model, db.schema_introspection’s sha256-prefix fingerprint convention, and agent.provenance.DataTruthLevel.

2. What was built

Three new modules inside governance_center/ — not a new package, because this is the existing registry’s typed-artifact layer, not a second registry:

API surface (api/governance.py, api/governance_schemas.py):

3. Two real bugs found by this prompt’s own tests

(a) The validator rejected this codebase’s most security-conscious prompt. Running INJECTION_PATTERNS as a blocking check over prompt templates flagged agent.llm_client._system_prompt three times — for quoting the attacks it defends against ('ignore previous instructions', 'you are now in developer mode') and for prohibiting a connection string in generated SQL. All three were defensive mentions. That pattern set is tuned for untrusted user input, where a match means someone is attempting the attack; an authored prompt discussing security is the opposite context, and no fixed pattern list distinguishes the two reliably. Fixed by stripping quoted spans before scanning and downgrading the finding to a warning; UNSAFE_COMPOSITION (phrased around imperative instructions, zero false positives across all 15 live prompts) carries the blocking weight instead. See validation._scan_for_injection_mentions.

(b) Deleting the declaration escaped the dropped-invariant check. Version N declares untrusted_data_framing; version N+1 declares nothing and carries nothing — so nothing was “dropped” relative to its own empty declaration, and it passed. This defeated the mission’s central requirement. Fixed by making the required set monotonic across versions: _enforce_artifact_validity takes a predecessor_config (the stored draft being edited, or the currently-deployed version of the same asset key) and folds its declared and carried invariants into the required set, so a successor can only ever add. Pinned by four tests in TestSuccessorVersionsInheritTheirPredecessorsControls.

A third issue was found and left alone deliberately — see §6.

4. Tests

File Cases Scope
tests/test_governance_registry.py 60 Typed specs, template-variable extraction, every safety detector, the live inventory, and every validation rule. Fully offline.
tests/security/test_prompt_registry_cannot_weaken_security.py 41 The mission’s own required regression suite, in two halves (below).

The security suite’s two halves:

  1. Drift in the live prompts. EXPECTED_LIVE_INVARIANTS pins, per prompt, which invariants it must carry — pinned explicitly rather than derived from the live text, because a derived expectation would pass no matter what the prompts said. Editing agent/llm_client.py to drop the untrusted-data framing now fails CI with a diff naming the dropped control. Also asserts that no live prompt contains a weakening instruction, that every SQL-pipeline prompt carries the untrusted-data framing as a group, that governed-metric precedence is still stated somewhere live, and that every live artifact validates against itself without errors (the assertion that caught bug (a)).
  2. A weakened candidate reaching production. Real HTTP, real identity database, real tenants/users/RBAC. A candidate that drops a control, subverts one, overrides governed metrics, names an unapproved tool, or escalates an agent’s tools/truth ceiling is refused. test_the_deploy_gate_revalidates_the_stored_config weakens a row directly in the database, bypassing the API’s edit gate entirely — the only way to distinguish “deploy re-validates” from “deploy trusts that creation validated”.

Plus: both new routes reject unauthenticated and non-governance callers; the inventory never returns live prompt template text (asserted against a 60-character probe of every real template — shipping the prompt set over HTTP would make every prompt’s own NO_PROMPT_DISCLOSURE rule pointless); a refusal never echoes the submitted template back; and cross-tenant access to the new paths stays a 404.

5. Security and tenant review

6. Limitations, disclosed

7. One pre-existing test changed, intentionally

tests/test_api_governance.py::test_list_filters_by_asset_type created a prompt-typed draft with {"provider": "ollama"} — a model’s config. That is now correctly a 422. The test’s own assertion (list filtering by asset type) is unchanged; only its fixture config was corrected, with a comment explaining why. This is an intentional, disclosed behavior change for the three typed asset types.

8. Unrelated in-progress work left untouched

The working tree contains a prior session’s partially-finished work in eval/component_benchmark/: runner.py imports four new cases_*.py modules (cases_anomaly_root_cause, cases_calculations, cases_forecasting, cases_groundedness) but registers none of them in _DOMAIN_MODULES, so ruff reports four unused imports and the cases never run. An edit this prompt had briefly made to that file was backed out, and the inconsistency is not part of this change — it is reported for a deliberate decision rather than silently completed or deleted. governance_center.inventory.known_evaluation_suites discovers suites by globbing instead, which needs no edit to that file.

9. Performance and cost

Zero LLM calls, zero database queries in the validator, and zero network access anywhere in this feature. The inventory reads in-process module state plus the already-cached Settings. GET /governance/inventory and POST /governance/assets/validate perform no query beyond the permission lookup every governance route already does. The four lifecycle gates add one sha256 per prompt plus a bounded set of regex scans — microseconds against a request that was already doing a database write. create_draft adds one indexed get_current_deployed lookup.

Prompt 46 — close the two unframed RAG prompts and wire the registry’s drift detection into CI. Specifically: add untrusted-data framing to rag.retriever._GRADE_SYSTEM_PROMPT (and re-pin EXPECTED_LIVE_INVARIANTS), and add a CI step that fails on any live prompt fingerprint change not accompanied by an updated expectation, so prompt drift is caught at review time rather than only by a test a developer might not run. A second, independent candidate is the component-benchmark inconsistency in §8.