Build with the Framework

Implementation Guide

Two paths to implementing DPI Workflows: code-first for engineering teams, and no-code for practitioners. Both produce governed, auditable, interoperable services.

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 (Prefect, Airflow, custom). 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 β†’

Apache Airflow β€” Pipeline Orchestration

Open Source Code-Based DAGs Production-Grade

Apache Airflow defines workflows as Python Directed Acyclic Graphs (DAGs). Excellent for batch processing use cases β€” bulk eligibility checks, crisis disbursements, registry reconciliation β€” where workflows run on a schedule rather than triggered by individual citizens.

airflow.apache.org β†’
Choose based on your team: Policy and programme teams β†’ OpenFn. Engineering teams doing integrations β†’ n8n or custom YAML. Data engineering / batch processing β†’ Airflow. All produce governance-embedded, auditable workflows compatible with DPI-AI Framework principles.
Implementation Checklist

Before you launch a DPI-AI pilot

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

⬇ Download the full Implementation Playbook (PDF) β†’

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
GPT-4o Β· Claude Β· Gemini

Fastest to deploy. Most capable for complex language tasks. Data leaves your infrastructure β€” unsuitable for PII-heavy tasks without data processing agreements.

βœ“ 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: "phi-3-mini-4k-instruct"         # Declare the specific model
  model_version: "3.8B-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.

πŸ§ͺ Try the live farmer demo in the Sandbox β†’