Skip to content

Domain-Specific Recipes

Full GoalInput specs tailored to five roles. Each recipe uses prebuilt G6 pipeline templates — formal proofs, genetic optimisation, CSF hazard bounding, persistent indices, and counterexample-guided synthesis — for speed, reliability, and correctness over ad-hoc prompting.


Security Engineer

Goal: Audit REST API endpoints for injection vulnerabilities, formally verify authorization properties, and compute CSF hazard bounds.

{
  "goal": "Audit REST API for injection vulnerabilities and formally verify authorization invariants",
  "context": "FastAPI application with 47 endpoints. Handles user authentication, payment processing, and webhook ingestion. OWASP Top 10 compliance required for SOC 2 certification.",
  "constraints": [
    "All SQL queries must use parameterised statements (no string interpolation)",
    "Authorization formula must be SAT under propositional DPLL",
    "CSF epsilon must not exceed 0.20",
    "CVE search must cover the last 12 months"
  ],
  "resource_bounds": {
    "max_execution_seconds": 300,
    "max_tokens_per_hour": 150000
  },
  "guardrails": [
    {
      "name": "csf_code_execute",
      "predicate": "csf_hazard",
      "params": {"action": "code_execute", "max_prob": 0.10},
      "message": "Halt if code-execution hazard exceeds 10%"
    }
  ],
  "subtasks": [
    {
      "goal": "Search for relevant CVEs and known vulnerability patterns",
      "context": "Use ctx_search (DuckDuckGo) to find recent CVEs affecting FastAPI, Starlette, and Python async frameworks.",
      "constraints": ["max_results: 15", "Focus on injection and auth bypass CVEs"]
    },
    {
      "goal": "Formally verify authorization properties",
      "context": "Use formal_methods to prove: (authenticated AND authorized AND rate_limited) -> request_allowed. Verify contrapositive.",
      "constraints": ["Strategy: propositional", "Both directions must return SAT"]
    },
    {
      "goal": "Compute CSF hazard bounds across all endpoint actions",
      "context": "Use align_csf with G6 safety signature. Bound code_execute (0.10), external_api (0.08), llm_call (0.05).",
      "constraints": ["Union bound must stay within epsilon=0.20"]
    },
    {
      "goal": "Generate hardened endpoint stubs",
      "context": "Use meta_programming to generate parameterised query wrappers and decorator-based auth guards for flagged endpoints.",
      "constraints": ["Generate dataclass-based request validators", "Include rate limiting decorators"]
    }
  ]
}

Key components: ctx_search, formal_methods, align_csf, meta_programming

Formal Proofs for Audits

formal_methods returns SAT/UNSAT — a deterministic, reproducible result for the propositional formula as written. That makes the check repeatable audit evidence, but it proves only the formula you supplied, not that the formula faithfully captures your real authorization logic — read the formula yourself before relying on it (see Code Review for the full translation-faithfulness caveat).


Data Scientist

Goal: Build a reproducible ML experiment pipeline with genetic optimisation, multi-metric evaluation, and methodology grounding.

{
  "goal": "Build a reproducible churn prediction pipeline with genetic hyperparameter search and grounded methodology",
  "context": "Telco dataset, 7k records. Binary classification. Model drives automated retention campaigns — precision-recall tradeoff is business-critical.",
  "constraints": [
    "F1 must exceed 0.90",
    "Genetic search: 50 generations, population 20",
    "Methodology must be grounded against ai_ml domain (confidence >= 0.70)",
    "All metrics computed via pure Python (align_evals)"
  ],
  "resource_bounds": {
    "max_execution_seconds": 600,
    "max_tokens_per_hour": 200000
  },
  "subtasks": [
    {
      "goal": "Ingest and profile dataset with pandas",
      "context": "Use adapt_pandas for loading, profiling, and correlation analysis. Persist to SQLite for reuse.",
      "constraints": ["Drop columns with >30% missing", "Output numeric-only DataFrame"]
    },
    {
      "goal": "Train random forest with genetic hyperparameter search",
      "context": "Use adapt_sklearn for model training, adapt_pygad for genetic search over n_estimators, max_depth, min_samples_split.",
      "constraints": ["Population: 20", "Generations: 50", "Fitness: macro F1 on 5-fold CV"]
    },
    {
      "goal": "Optimise decision threshold",
      "context": "Use adapt_optimisation (scipy) to find the threshold maximising F1 on validation set.",
      "constraints": ["Threshold range: [0.3, 0.7]"]
    },
    {
      "goal": "Evaluate and ground the methodology",
      "context": "Use align_evals for accuracy, precision, recall, F1, MAE. Use grounding (domain: ai_ml) to check methodology against retrieved sources.",
      "constraints": ["All 5 metrics required", "Grounding confidence >= 0.70"]
    }
  ]
}

Key components: adapt_pandas, adapt_sklearn, adapt_pygad, adapt_optimisation, align_evals, grounding

Persistent DataFrames

adapt_pandas backs data to SQLite (PANDAS_DB_PATH). Load once, query across sessions — no re-ingestion cost.


Research Analyst

Goal: Multi-source research synthesis with BM25 retrieval, dual-index search (TF-IDF + ColBERT), and formally verified conclusions.

{
  "goal": "Synthesise a grounded survey of transformer efficiency techniques with formally verified conclusions",
  "context": "Covering attention sparsification, knowledge distillation, quantisation, and mixture-of-experts. Target audience: ML infrastructure team evaluating deployment tradeoffs.",
  "constraints": [
    "Minimum 20 sources indexed",
    "BM25 retrieval for primary search, ColBERT for re-ranking",
    "Every claim grounded with confidence >= 0.70",
    "Logical consistency proved via propositional DPLL"
  ],
  "resource_bounds": {
    "max_execution_seconds": 300,
    "max_tokens_per_hour": 200000
  },
  "subtasks": [
    {
      "goal": "Search and scrape primary sources",
      "context": "Use ctx_search (DuckDuckGo, max_results: 25) then ctx_scrapling to extract full text from top results.",
      "constraints": ["Skip paywalled sources", "Extract title + body + date"]
    },
    {
      "goal": "Build dual retrieval index",
      "context": "Use ctx_rag (BM25) as primary index. Use ctx_colbert as secondary for re-ranking low-confidence results.",
      "constraints": ["Chunk by sentence boundaries", "BM25 top_k: 10", "ColBERT re-rank top 20"]
    },
    {
      "goal": "Ground all claims against the indexed knowledge base",
      "context": "Use grounding with domain ai_ml. Flag claims below 0.70 confidence for manual review.",
      "constraints": ["Minimum confidence: 0.70", "Domain: ai_ml"]
    },
    {
      "goal": "Prove logical consistency of conclusions",
      "context": "Use formal_methods to verify: (attention_sparse_valid AND distillation_proven AND quantisation_bounded) -> efficiency_claims_sound.",
      "constraints": ["Strategy: propositional", "Must return SAT"]
    }
  ]
}

Key components: ctx_search, ctx_scrapling, ctx_rag, ctx_colbert, grounding, formal_methods

Dual-Index Retrieval

ctx_rag provides fast BM25 retrieval over the full corpus. ctx_colbert re-ranks the top results using TF-IDF cosine similarity (with RAGatouille as optional backend). The combination gives you speed and precision.

What confidence >= 0.70 means here

The grounding confidence used in these recipes is the mean retrieval similarity between a claim and the retrieved seed facts (TF-IDF cosine, or keyword overlap in the fallback path) — not a measure that the claim is true or relevant to your problem. A >= 0.70 threshold therefore means "the retrieved facts are textually close to the claim," which is a useful routing signal: when it is low, escalate to secondary retrieval (ctx_colbert) or human review. A high score is not a correctness guarantee — treat it as retrieval quality, not trust.


Software Architect

Goal: Design a service architecture with formal contract verification, CEGIS-synthesised interface adapters, and CSF safety guarantees.

{
  "goal": "Design a payment processing microservice with formally verified contracts and CEGIS-synthesised adapters",
  "context": "Decomposing a monolith into 5 microservices: auth, payments, notifications, audit-log, and gateway. Each service boundary needs explicit interface contracts. Adapter functions between services should be synthesised via CEGIS and checked against oracle tests plus any configured formal properties.",
  "constraints": [
    "All service contracts must be propositionally SAT",
    "CEGIS adapter synthesis must converge within 10 iterations",
    "CSF hazard bounds: code_execute <= 0.10, external_api <= 0.08",
    "Generated code must include type annotations"
  ],
  "resource_bounds": {
    "max_execution_seconds": 400,
    "max_tokens_per_hour": 200000
  },
  "breakpoints": [
    {
      "name": "pre_deploy_architecture",
      "description": "Pause for human review before finalising the microservice architecture",
      "active": true
    }
  ],
  "subtasks": [
    {
      "goal": "Analyse existing monolith code structure",
      "context": "Use meta_programming to extract all functions, classes, and dependency edges. Map the call graph from HTTP handlers to database queries.",
      "constraints": ["Extract full function signatures", "Identify coupling points between domains"]
    },
    {
      "goal": "Formally verify service boundary contracts",
      "context": "Use formal_methods to prove consistency of inter-service contracts. Verify: (auth_valid AND payment_intent_created AND idempotency_key_unique) -> payment_processed.",
      "constraints": ["Strategy: propositional", "Verify both direction and contrapositive"]
    },
    {
      "goal": "Synthesise interface adapters via CEGIS",
      "context": "Use cegis to synthesise adapter functions that transform data between service boundaries. Sketch: adapter with ?? holes for field mappings. Oracle: known input-output pairs from existing integration tests.",
      "constraints": ["Max CEGIS iterations: 10", "Agency start: CODE_AGENT (5)", "Verify each adapter with formal_methods"]
    },
    {
      "goal": "Bound safety hazards for the new architecture",
      "context": "Use align_csf with G6 safety signature to compute hazard bounds across all service interactions. Each inter-service call is an external_api action.",
      "constraints": ["5 services × external_api (0.08) = 0.40 — must partition to stay within epsilon=0.20 per service"]
    }
  ]
}

Key components: meta_programming, formal_methods, cegis, align_csf

CEGIS for Adapters

Instead of hand-writing adapters between services, CEGIS synthesises them from sketches with ?? holes. Each adapter is checked against oracle test cases and any configured formal properties — if a counterexample is found, the sketch is refined. Treat the result as machine-checked only for the properties actually specified and supported by the backend.


DevOps Engineer

Goal: Validate infrastructure configuration, formally verify deployment constraints, and configure self-healing with drift detection.

{
  "goal": "Validate Kubernetes deployment manifests, formally verify resource constraints, and configure DDM-based self-healing",
  "context": "Production cluster with 12 services. Recent incidents caused by resource limit misconfigurations and spec drift. Need formal verification of constraints plus automated drift detection and healing.",
  "constraints": [
    "All resource limits must satisfy: requests <= limits",
    "Formal verification: (resource_bounded AND health_check_passing AND replicas_available) -> service_healthy",
    "CSF hazard bound for rollback actions must remain below 0.001",
    "DDM drift detection configured for CPU and memory utilisation"
  ],
  "resource_bounds": {
    "max_execution_seconds": 240,
    "max_tokens_per_hour": 100000
  },
  "subtasks": [
    {
      "goal": "Formally verify deployment resource constraints",
      "context": "Use formal_methods to prove that all resource specifications satisfy: (cpu_request <= cpu_limit AND mem_request <= mem_limit AND replicas >= min_available) -> deployment_valid.",
      "constraints": ["Strategy: propositional", "Verify for all 12 services"]
    },
    {
      "goal": "Validate against compliance specifications",
      "context": "Use align_specs to verify manifests against internal deployment standards. Check: namespace isolation, resource quotas, network policies, and pod security standards.",
      "constraints": ["All specs must pass validation", "Flag non-compliant services"]
    },
    {
      "goal": "Bound safety hazards for rollback and deployment actions",
      "context": "Use align_csf to compute hazard bounds. Rollback (0.001) is the critical action — a failed rollback in production is catastrophic.",
      "constraints": ["rollback hazard <= 0.001", "code_execute hazard <= 0.10", "Total epsilon <= 0.20"]
    },
    {
      "goal": "Configure DDM drift detection and auto-healing",
      "context": "Use adapt_healing to set up DDM monitoring for CPU utilisation, memory utilisation, and error rates. Warning threshold triggers alert, drift threshold triggers rollback workflow. Configure assisted patching for transient errors, with verification and human review before deployment.",
      "constraints": [
        "DDM warning: mean + 2σ",
        "DDM drift: mean + 3σ triggers rollback",
        "Auto-patch: connection timeouts, transient 503s"
      ]
    }
  ]
}

Key components: formal_methods, align_specs, align_csf, adapt_healing

Self-Healing in Production

adapt_healing implements DDM (Drift Detection Method) from the Self_Healing_ML patterns. It tracks running mean and standard deviation of operational metrics. When drift is detected, it can trigger a rollback workflow. Production deployments should keep rollback approval, verification, backups, and CSF hazard bounds in the loop.