Build with the Framework

From Architecture
to Deployment

A practical path from architecture to deployment. Each step produces a concrete delivery output — a validated user journey, a governance decision, a workflow definition, or a configuration artifact. The sequence mirrors how public services are actually delivered: from a clearly defined user need, through governance and system design, to deployment, measurement, and iterative improvement.

Before You Begin

Entry Conditions for Governments

Before applying this playbook, governments should ensure a minimum set of institutional and operational conditions are in place. These are not prerequisites for full-scale deployment, but they are necessary to run a credible, governed, and accountable implementation.

🏛️
Legally accountable service owner

A ministry or agency responsible for the end-to-end service, including outcomes, user experience, and AI-assisted decisions.

📋
Clear administrative or legal basis

Authority to operate the service, including data use, decision-making authority, and compliance requirements.

⚖️
Operational accountability mechanisms

Including auditability, escalation paths, and grievance redress processes.

👥
Cross-functional delivery team

Spanning policy, legal, operational, and technical roles — not just engineers.

🔗
Access to at least one existing DPI rail

Such as digital identity, data exchange, or a sector registry. The service is designed to reuse existing infrastructure, not operate in isolation.

Assessing your starting point: Before defining the use case, assess your current readiness across technology, governance, data, and institutional capability. The DIAL AI–DPI Nexus self-assessment tool provides a structured way to evaluate these dimensions. Understanding the starting point clarifies which constraints are technical, which are institutional, and which are legal — and prevents over-scoping.
Implementation Roadmap

9 Steps to Implement the DPI-AI Framework

Each step corresponds to a concrete delivery output — such as a validated user journey, a governance decision, a workflow definition, or a configuration artifact. The steps are intentionally ordered: later steps rely on decisions and artifacts produced earlier. Skipping steps typically results in weak governance, fragile automation, or unclear accountability. In the absence of clear ownership and accountability, AI-enabled services risk becoming technically functional but institutionally ungovernable.

Phase 1 · Design
1
Design · Step 1 of 9
🗺️ Identify the use case and user journey
Choose a specific, bounded service — not a sector. Define it from the citizen's point of view: who initiates it, what they need, what the government needs to verify or do, and how the interaction ends. Walk through the journey step-by-step before writing a single line of configuration. The precision of this step determines the quality of everything downstream.
2
Design · Step 2 of 9
🧩 Identify AI Blocks, DPI dependencies, and DPGs
Map each step of the user journey to the AI Blocks and DPI systems it requires. Which registry is the source of truth for identity? Which payment rail will disburse? Which AI Block handles eligibility? Document the dependencies — a workflow that assumes a DPI component you don't yet have deployed is a pilot waiting to fail. This inventory also determines your procurement and integration roadmap.
3
Design · Step 3 of 9
🛡️ Define governance, safeguards, and human-in-the-loop controls
Before writing any workflow, decide: who owns this service legally? What confidence threshold triggers human review? How does a citizen escalate if the AI is wrong? How is PII handled in logs? Where is consent captured and verified? These decisions must be made by policy and legal teams — not configured by engineers at deployment time. Governance built in from the start is enforcement; governance bolted on later is theatre.
Phase 2 · Build
4
Build · Step 4 of 9
⚙️ Create the DPI Workflow from the user journey
Translate the citizen journey and governance spec into a formal DPI Workflow — a YAML-defined sequence of steps, blocks, confidence rules, escalation paths, and audit configuration. This is the machine-readable definition of your service. The workflow spec is not just technical documentation — it is the authoritative governance record. Publish it in version control. The YAML spec is a governance-level artifact (engine-agnostic) that is then translated into engine-specific configuration at Step 7. See the YAML format below →
5
Build · Step 5 of 9
🤖 Define the Public Agent
Configure the citizen-facing layer: which channels it supports (WhatsApp, USSD, web, voice), which languages it speaks, which workflows it is permitted to activate, and what happens at the edge of its scope. The Public Agent spec must be declared as explicitly as the workflow spec — it is a governance document as much as a configuration file. The agent is the face; the workflow is the authority. See the full agent configuration guide below →
6
Build · Step 6 of 9
📊 Define metrics and operational signals
Before going live, decide what success looks like and how you'll know if something is wrong. Define your monitoring signals: AI block confidence distribution, escalation rate, journey completion rate, fallback channel usage, audit log completeness, and citizen satisfaction. These metrics must be observable from day one — not designed retrospectively. An unmonitored AI service is an ungoverned one.
Phase 3 · Operate
7
Operate · Step 7 of 9
🚀 Implement the service — configuration and deployment
Deploy the workflow and agent using the approach that matches your team's capacity. Code-first teams run the YAML spec on a workflow engine (OpenFn, n8n, Prefect). No-code teams configure visually. Either way, the result must match the governance spec — the deployment is an execution of the document, not a departure from it. Start with a narrow pilot population before broadening access. See implementation approaches below →
8
Operate · Step 8 of 9
✅ Test and validation
Run structured tests across all paths — happy path, edge cases, and failure modes. Test every language and channel. Validate that low-confidence outputs correctly escalate to humans. Confirm that audit logs are complete and PII is redacted. Test the fallback channel end-to-end. Do not expose citizens to untested interactions — this is the pre-launch gate. See the pre-launch checklist below →
9
Operate · Step 9 of 9
🔄 Fine-tune and improve the service over time
After launch, use operational signals to drive systematic improvement. Review confidence distributions weekly — a rising escalation rate is an early warning. Retrain or swap AI Blocks when accuracy drifts. Publish updated workflow versions in version control with a change log. Treat the service like a living product, not a completed project. The governance spec and metrics from Steps 3 and 6 are your operational constitution.
Choose your approach

Code-first or no-code — both work

The DPI-AI Framework is implementation-agnostic. What matters is that workflows are governed, auditable, and use open standards. Whether you write YAML by hand or build visually in OpenFn or n8n, the governance principles remain the same.

🖥️

Code-First

Define workflows as YAML or JSON. Run on any workflow engine (OpenFn, n8n, Prefect). Full control over every step, condition, and governance parameter.

  • Version-controlled, diff-able workflows
  • Maximum flexibility and composability
  • Share as open templates on GitHub/GitLab
  • Integrate with any CI/CD pipeline
  • Best for: engineering teams, complex multi-step services
🎨

No-Code / Low-Code

Visual workflow builder. OpenFn for DPI-native workflows, n8n for broader integrations. Drag-and-drop steps, built-in connectors to DPGs, visual governance configuration.

  • Accessible to non-engineers (policy teams, service designers)
  • OpenFn has native DPG connectors (OpenCRVS, DHIS2, Mojaloop)
  • n8n offers 400+ pre-built integrations
  • Workflows can still be exported as code
  • Best for: rapid pilots, multi-stakeholder teams, social sector
Code-First Implementation

YAML-defined DPI Workflows

Define your workflow as a YAML specification. This is the source of truth — it declares the steps, the AI Blocks invoked, the governance rules, and the audit configuration. Any compliant workflow engine can run it.

Key principle: The YAML spec is not just configuration — it is governance documentation. Every block invoked, every confidence threshold, every escalation rule is declared here. This is what you publish as a reusable template for other governments to adopt.
# Social Protection — Eligibility & Disbursement Workflow # Designed for reuse: adapt governance params for your context workflow: id: "social_protection_eligibility_v1" version: "1.0.0" domain: social_protection governance: owner_agency: "<Ministry of Social Welfare>" legal_basis: "<Social Protection Act — reference your country's law>" audit_logging: true human_oversight: {required: true, escalation_to: caseworker} # Step 1: Authenticate the citizen via national ID steps: - id: authenticate type: dpi_block block: identity.verify inputs: {identifier: "{{citizen.id}}", consent_token: "{{session.consent}}"} on_fail: notify_failure # Step 2: Run AI eligibility check - id: eligibility type: ai_block block: ai.eligibility_verify_v1 inputs: citizen_id: "{{steps.authenticate.output.verified_id}}" benefit_code: "{{request.benefit_code}}" confidence_threshold: 0.85 on_low_confidence: human_review # < 85%: human caseworker on_high_confidence: disburse # > 85%: auto-proceed # Step 3a: Human review (low confidence path) - id: human_review type: human_task assign_to: caseworker timeout: 48h on_approve: disburse on_reject: notify_rejection # Step 3b: Disburse (high confidence or approved path) - id: disburse type: dpi_block block: payments.disburse inputs: recipient_id: "{{steps.authenticate.output.verified_id}}" amount: "{{benefit.amount}}" audit: {log: true, immutable: true} - id: notify type: notification template: "benefit_confirmation" channel: "{{citizen.preferred_channel}}"

Running the workflow

Deploy to any workflow engine that can parse this spec. Recommended open-source engines:

# Option A: Run with Prefect (Python) pip install prefect dpi-ai-runner dpi-ai run --workflow social_protection_eligibility_v1.yaml \ --env production \ --audit-log s3://gov-audit/workflows/ # Option B: Run with the OpenFn CLI (if using OpenFn as engine) openfn run social_protection_eligibility_v1.yaml \ --state state.json --log-level debug # Option C: Docker-based deployment docker run -v ./workflows:/workflows \ ghcr.io/cdpi/dpi-workflow-engine:latest \ run /workflows/social_protection_eligibility_v1.yaml
No-Code / Low-Code Implementation

Visual workflow tools

For teams without deep engineering capacity, or for rapid pilots, visual workflow builders let you compose DPI Workflows without writing code. Both OpenFn and n8n can implement the DPI-AI Framework patterns.

OpenFn — DPI-Native Workflow Platform

DPG DPI-Native Open Source Recommended for Social Sector

OpenFn is a Digital Public Good designed specifically for social sector data integration and workflow automation. It has pre-built "adaptors" (connectors) to leading DPGs: OpenCRVS, DHIS2, Mojaloop, Kobo Toolbox, CommCare, Salesforce, and more.

Why it fits the DPI-AI Framework: OpenFn workflows can be version-controlled as code (OpenFn v2 uses a portable workflow spec), run human-in-the-loop steps, integrate with identity and payments DPGs, and log every interaction for audit. You can also call AI Blocks via HTTP adaptors.

openfn.org → Documentation → DPG Adaptors on GitHub →

n8n — Open Workflow Automation

Open Source 400+ Integrations Self-Hostable

n8n is an open-source workflow automation tool that can be self-hosted on government infrastructure. With 400+ built-in nodes and an HTTP request node for custom integrations, it can connect to any AI Block via REST API and orchestrate complex multi-step workflows visually.

Why it fits the DPI-AI Framework: n8n supports conditional branching (low-confidence → human review), webhook triggers (citizen-initiated), error handling, and logging. Workflows can be exported as JSON for version control and sharing.

n8n.io → Documentation → GitHub →
Choose based on your team: Policy and programme teams → OpenFn. Engineering teams doing integrations → n8n or custom YAML. Data engineering and batch processing (bulk eligibility checks, crisis disbursements, registry reconciliation) → Prefect. All produce governance-embedded, auditable workflows compatible with DPI-AI Framework principles.
Element 03 · Implementation Deep Dive

How to configure a Public Agent

A Public Agent is a constrained AI-enabled interface — not an autonomous AI system. It can only activate approved workflows, must always offer human escalation, and cannot access data without consent. Here is how to design, configure, and govern one.

Step 1 — Define scope and constraints

Before writing any code, define in plain language what the agent CAN and CANNOT do. This becomes the governance specification.

YAML — Public Agent Spec
public_agent:
  name: kilimo-bot
  version: "1.0.0"
  owner: ministry_of_agriculture
  legal_basis: "Agricultural Support Act 2025, §12"

  channels:
    primary: whatsapp_business
    fallback: [ussd, sms]
    languages: [sw-KE, sw-TZ, en]

  scope:
    can_activate:
      - agri_benefit_eligibility_workflow
      - farmer_registration_workflow
      - support_inquiry_workflow
    cannot_activate:
      - payment_reversal
      - registry_write_direct
      - any_workflow_not_listed

  constraints:
    data_access: consent_required_per_session
    human_escalation: always_available
    escalation_channels: [human_agent_chat, phone_0800724666]
    max_session_turns: 12
    pii_in_logs: redacted
    audit_log: required

  governance:
    confidence_threshold: 0.82
    below_threshold: escalate_to_human
    response_language: match_user_language
    fallback_message: "I'm not able to help with that. Call 0800 724 666."

Step 2 — Choose channels and language

Design for the lowest-connectivity citizen first. Build WhatsApp → USSD → SMS as your fallback stack.

💬WhatsApp Business APIPRIMARY

Supports voice messages (critical for low-literacy users), images, and text. Use WhatsApp Business API with a verified government number. Required: Meta verification, local telecom agreement.

📟USSDFALLBACK

Works on any phone with no internet. Session-based (≤182 chars per screen). Design menus first, not conversation flows. Works offline, real-time. Required: USSD short code from telecoms regulator.

📱SMSNOTIFY

Use for notifications only — confirmation, case ID, payment alert. Not suitable for multi-turn conversation. Keep under 160 chars. Use shortcodes for replies.

Language principle: The agent must match the user's language — not require the user to match the government's language. Use the translate() AI Block to convert all inputs to your processing language and outputs back to the citizen's language.

Step 3 — Select and declare the model

Model selection is a governance decision, not just a technical one. Every AI Block — including those powering your Public Agent — must declare the model it uses, where it runs, and under what conditions it can be replaced.

🌐
Cloud API Models
OpenAI · Anthropic · Google
OpenAI: GPT-5, GPT-5.4, o3, o4-mini
Anthropic: Claude Opus 4, Sonnet 4, Haiku 4
Google: Gemini 2.5 Pro / Flash, Gemini 3 Pro

Fastest to deploy. Frontier capability for complex language and reasoning tasks. Data leaves your infrastructure — unsuitable for PII-heavy tasks without data processing agreements and legal basis.

✓ Use for: translation, summarisation, intent extraction (non-PII)
✗ Avoid for: eligibility decisions, identity matching with PII
🏠
Self-Hosted Open Models
Llama 3 · Mistral · Qwen · Aya

Data stays on your infrastructure. Full sovereignty. Requires GPU servers (A100 or equivalent) for 70B+ models. Smaller 8B models run on consumer GPUs.

✓ Use for: all tasks with citizen PII, eligibility, identity context
⚠ Requires: GPU infrastructure, model serving team
Small Language Models (SLMs)
Phi-3 · Gemma 2B · SmolLM · Qwen2-1.5B

Run on a single CPU server or Raspberry Pi. Ideal for single-purpose tasks: classification, entity extraction, intent detection. Cheap, fast, governable. Best choice for low-resource deployments.

✓ Best for: narrowly defined, high-frequency tasks at low cost
✓ Recommended for most DPI-AI pilots
🎯
Fine-tuned Domain Models
Custom-trained on local language & domain data

Start from an open base model and fine-tune on local dialect data, government forms, and domain-specific terminology. Highest accuracy for local contexts but requires labelled data and ML expertise.

✓ Use for: local language speech-to-text, domain-specific classification
⚠ Requires: local language dataset, fine-tuning pipeline
YAML — Model Declaration in AI Block Spec
provenance:
  model: "qwen2.5-3b-instruct"            # Declare the specific model and version
  model_version: "3B-q4_K_M"
  hosting: on_prem                         # sovereign_cloud | on_prem | external_api
  infrastructure: "Ministry data centre, Nairobi"
  replaceable: true                        # Can swap without rebuilding workflow
  replaceability_conditions:
    - "performance_below_threshold: accuracy < 0.88"
    - "model_deprecated_by_vendor"
    - "sovereignty_policy_change"
  last_evaluated: "2026-03-01"
  evaluation_dataset: "agri-sw-KE-test-v2"

Step 4 — Build safeguards into the workflow

Safeguards are not optional features to add later. They are structural components of the DPI Workflow, designed to prevent silent AI failures from reaching citizens. Every one of these must be in place before citizen contact.

⚠️Confidence Thresholds

Every AI Block must declare a minimum confidence score. Below the threshold, the system automatically escalates to a human — never delivers a low-confidence answer silently to a citizen.

confidence_threshold: 0.85
below_threshold_action: human_escalate
👤Human Escalation as First-Class

Escalation is not a fallback — it is a primary workflow step. Every agent interaction must have a defined escalation path with a case ID so the citizen can follow up. Never a dead end.

escalation_path: human_agent
case_id: auto_generated
timeout_before_escalate: 90s
Consent as a Callable Step

Consent is not a checkbox in a form — it is a step in the workflow. Check it before any data access. Make it explicit, specific to purpose, and revocable.

consent.verify(citizen_id, purpose)
# blocks workflow if consent not given
📋Tamper-Evident Audit Logging

Every AI inference, input hash, output, confidence score, and human decision must be logged. Logs must be immutable, time-stamped, and accessible for algorithmic audits.

audit.log(session_id, action,
confidence, outcome, actor)
🔒PII Redaction at Capture

Strip personally identifiable data from all logs at the point of capture — not in post-processing. ID numbers, names, and contact details must never appear in plain text in logs.

pii_handling: redact_from_logs
log_citizen_id: hashed_only
🔄Model Replaceability

Any model in any AI Block must be replaceable without rebuilding the workflow. Declare this explicitly and test it. Digital sovereignty depends on it — vendor lock-in starts here.

replaceable: true
hosting: on_prem | sovereign_cloud
The governance principle:

AI operates inside the DPI Workflow — not outside it. The workflow is the single source of truth. No AI output modifies a government record, triggers a payment, or affects a citizen's status without passing through the workflow's governance rules. The agent is the face. The workflow is the authority.

Step 8 · Test & Validation

Before you launch a DPI-AI service

Entry conditions (must have)

  • Named service owner with clear mandate
  • Legal basis for the service and AI use
  • Cross-functional team (policy + tech + legal)
  • Access to at least one DPI rail (identity, payments, or registry)
  • Human escalation path defined
  • Consent mechanism designed
  • Audit logging configured

Before citizen contact (must test)

  • End-to-end test with synthetic data per supported language
  • Eligibility pass and fail scenarios
  • Identity verification failure → enrollment fallback
  • Low-confidence output → human escalation validated
  • USSD / fallback channel tested
  • Audit log completeness verified
  • PII redaction in logs confirmed

These test criteria correspond to the governance controls defined in Steps 3 and 6 of the roadmap. Every item maps to a governance specification that should already exist before deployment.

🧪

Try it before you build it

The Implementation Sandbox lets you apply these 9 steps interactively — design your service with the built-in tools, walk step-by-step through the implementation journey, and watch a complete working demonstration of the framework before writing a single line of code.

🛠️
Design Tools

Build your DPI Workflow visually with the AI Block Composer, or walk through all 9 steps with the Service Architect wizard.

Open Design Tools →
🔍
Scenario Explorer

Walk through each of the 9 implementation steps in detail — what each step involves, the key decisions to make, and the governance requirements at every stage.

Explore the 9 Steps →
🌾
Practical Demonstration

Watch a full end-to-end service delivery — AI Blocks, DPI systems, human approval, and payment — step by step on a simulated WhatsApp interface.

Step Through the Demo →
Open the Sandbox →