{
  "title": "Beth integration contract register",
  "revision": "2026-10-12.2",
  "status": "Proposed engineering baseline; target-stack proof pending",
  "canonical_url": "https://beth2.top/integration",
  "scope_source": "https://beth2.top/scope?audience=technical#stack",
  "contracts": [
    {
      "id": "I01",
      "title": "Web chat \u2192 Beth API",
      "owner_role": "Backend + frontend engineer",
      "work_packages": [
        "P14.1",
        "P14.2",
        "P16.1"
      ],
      "transport": "Beth HTTPS API; one chosen event transport",
      "input": "Verify the session and case access on the server. Generate request_id, run_id and a monotonically ordered event sequence. Accept a client message ID only as an idempotency reference within its authorised account.",
      "output": "Persist the user message and run state; return normalised message events and a terminal outcome. A disconnected browser can request the stored run outcome. Reconnect must not create a second appointment or duplicate a turn.",
      "failure_policy": "Do not expose model keys, Langflow flow IDs or arbitrary tool URLs to the browser. A partial reply remains incomplete until validation and finalisation. Sensitive factual claims must pass the evidence checks before presentation.",
      "acceptance_test": "Disconnect and reconnect during a turn; verify one user message, one run and one final answer. Repeat the same submission; no duplicate business action.",
      "status": "proposed; not executed",
      "official_reference": "https://docs.ag-ui.com/concepts/events"
    },
    {
      "id": "I02",
      "title": "Beth API \u2192 Langflow",
      "owner_role": "AI engineer + backend engineer",
      "work_packages": [
        "P14.1",
        "P14.2"
      ],
      "transport": "Private authenticated flow-run HTTP API",
      "input": "Resolve an approved, pinned flow on the server. Supply scoped conversation context and approved evidence. Map the chosen output component into Beth\u2019s response schema; reject empty, malformed or error outputs.",
      "output": "Bounded AI stage only. Langflow does not own booking status, publication approval, billing rules or case permissions. Persist flow version and the run outcome in Beth.",
      "failure_policy": "Baseline: POST /api/v1/run/{flow_id}, x-api-key header, explicit session_id. Never forward browser-supplied global-variable headers. Streaming needs a tested event adapter; it does not by itself guarantee saved conversation recovery.",
      "acceptance_test": "Run the same fixture against the pinned flow; check schema, empty output, cancellation, timeout and a second worker if scaling is enabled.",
      "status": "proposed; not executed",
      "official_reference": "https://docs.langflow.org/api-flows-run"
    },
    {
      "id": "I03",
      "title": "Langflow \u2192 LiteLLM \u2192 approved model",
      "owner_role": "AI engineer + operations engineer",
      "work_packages": [
        "P14.2",
        "P15.2"
      ],
      "transport": "OpenAI-compatible gateway HTTP",
      "input": "Use a server-controlled model alias such as beth-advice. Limit providers, region requirements, token budget and deadline. Use a restricted gateway credential.",
      "output": "LiteLLM owns provider selection and bounded model retries. Beth owns the final response validation. Record each attempt, provider, model, usage and cost in a correlated trace.",
      "failure_policy": "Disable overlapping caller retries. Client-supplied retry or model overrides are not trusted. An embedding alias must stay compatible with the active index dimension and embedding version.",
      "acceptance_test": "Simulate provider timeout and quota exhaustion; prove the attempt ceiling, approved fallback, recorded usage and bounded user wait.",
      "status": "proposed; not executed",
      "official_reference": "https://docs.litellm.ai/docs/proxy/quick_start"
    },
    {
      "id": "I04",
      "title": "Directus \u2192 Beth publication registry",
      "owner_role": "Knowledge editor + backend engineer",
      "work_packages": [
        "P10.1",
        "P10.2",
        "P10.3",
        "P04.1"
      ],
      "transport": "Scoped Directus REST + Beth publication command",
      "input": "Directus is the staff authoring and review surface. Read only required collections/fields. The proposed document collection contains stable source ID, draft revision, authority URL, jurisdiction, applicability dates and review evidence.",
      "output": "The authorised publish command records a desired revision and durable work record in Beth. A webhook wakes the processor; periodic reconciliation also compares the desired and processed revisions.",
      "failure_policy": "A Directus event alone is not a durable queue. A submitted or parsed PDF is not approved knowledge. Retirement blocks retrieval immediately in the registry, before background index deletion completes.",
      "acceptance_test": "Lose a webhook; reconciliation finds the missing update. Test an unauthorised publish, delayed old revision and immediate retirement exclusion.",
      "status": "proposed; not executed",
      "official_reference": "https://directus.com/docs/api/items"
    },
    {
      "id": "I05",
      "title": "Durable work \u2192 Temporal \u2192 document worker",
      "owner_role": "Data engineer + operations engineer",
      "work_packages": [
        "P04.3",
        "P10.3",
        "P15.1"
      ],
      "transport": "Temporal SDK in a service/worker; queued activities",
      "input": "Use source_id + desired_revision as the stable ingestion identity. Store stage receipts and a deadline. Keep network, parsing, embedding and model calls in activities rather than deterministic workflow code.",
      "output": "A worker may run again. It checks receipts, retries transient failures and holds permanent failures for review. Temporal manages execution history; Beth\u2019s knowledge registry owns the published status.",
      "failure_policy": "Use an atomic desired-revision/outbox transaction and a reconciler. Full case automation is a later phase; durable knowledge processing is brought forward in the current scope. A workflow cancellation is not proof that an external write never happened.",
      "acceptance_test": "Kill the worker between parsing and indexing; restart and prove safe continuation, no duplicate release and rejection of an obsolete revision.",
      "status": "proposed; not executed",
      "official_reference": "https://temporal.io/blog/idempotency-and-durable-execution",
      "stage": "Pilot knowledge pipeline; L03 is separate broader case extension",
      "delivery_note": "Knowledge-worker durability is owned by P04.3 in S12 and publication acceptance by P10.3 in S13. P15.1 in S16 owns later notification delivery; it is not a prerequisite for the knowledge worker. L03 owns later multi-day case workflows."
    },
    {
      "id": "I06",
      "title": "PDF worker \u2192 Docling/LlamaIndex \u2192 PostgreSQL + pgvector",
      "owner_role": "Data engineer + expert reviewer",
      "work_packages": [
        "P04.1",
        "P04.2",
        "P04.3",
        "P16.2"
      ],
      "transport": "Libraries inside one worker; database + private object storage",
      "input": "Keep the original PDF, content hash, parser version and page/section references. Extract text and tables; check OCR and missing pages. Chunk against headings and legal boundaries, with immutable source_version metadata.",
      "output": "Build a candidate index. Validate keyword + vector retrieval against expert-labelled questions. Activate one approved release pointer only after completeness, applicability and citation tests pass.",
      "failure_policy": "A semantic match is not legal verification. Neither PDF parsing nor a confidence score proves the rule is current. Approved original evidence stays retrievable for citations and rollback. Only compatible embedding versions share an index.",
      "acceptance_test": "Use a scanned PDF, a table, an amended rule and a retired document; prove exact evidence locations and exclusion of invalid versions.",
      "status": "proposed; not executed",
      "official_reference": "https://docling-project.github.io/docling/usage/"
    },
    {
      "id": "I07",
      "title": "Beth retrieval \u2192 answer evidence gate",
      "owner_role": "Knowledge analyst + AI engineer",
      "work_packages": [
        "P04.2",
        "P04.3",
        "P11.2"
      ],
      "transport": "Beth read API; bounded allowlisted source fetch when needed",
      "input": "Retrieve candidates only from approved, accessible, applicable versions. Combine exact references and keyword search with semantic retrieval; rerank and check applicability again before answering.",
      "output": "Return evidence IDs, quoted supporting spans, page/section, authority URL, effective date and checked_at. Verify that each material claim is supported and applies to the founder\u2019s facts.",
      "failure_policy": "A source website being reachable does not prove there is no later amendment. Consult the tracked amendment/replacement relationship and freshness policy. If verification is unavailable, explain the uncertainty and route consequential advice to review.",
      "acceptance_test": "Ask historical and current questions about the same amended rule; verify different appropriate evidence. Test unsupported claims, conflicting sources and authority downtime.",
      "status": "proposed; not executed",
      "official_reference": "https://github.com/pgvector/pgvector"
    },
    {
      "id": "I08",
      "title": "Beth API \u2192 Chatwoot \u2192 human specialist",
      "owner_role": "Backend engineer + service manager",
      "work_packages": [
        "P09.1",
        "P09.2",
        "P09.3"
      ],
      "transport": "Documented Chatwoot webhooks + conversation API",
      "input": "Map verified Beth identity to the inbox conversation. Dedupe provider event IDs and ignore outbound echoes. Record conversation owner and owner_epoch in Beth before handoff.",
      "output": "Human ownership suppresses bot dispatch, including already queued replies. Keep an open case ticket, consented contact details and a follow-up task if no specialist answers.",
      "failure_policy": "Chatwoot uses pending conversations for agent bots and open for human handoff. Beth must still enforce its own dispatch ownership. Verify webhook authentication supported by the selected version; never assume an HMAC header exists.",
      "acceptance_test": "Let a specialist take over while a model reply is delayed. No late bot answer appears. Replay the webhook and simulate no specialist response; one case remains actionable.",
      "status": "proposed; not executed",
      "official_reference": "https://www.chatwoot.com/hc/user-guide/articles/1677497472-how-to-use-agent-bots"
    },
    {
      "id": "I09",
      "title": "Authorised Beth action \u2192 OpenConnector \u2192 external tool",
      "owner_role": "Backend engineer + connector engineer",
      "work_packages": [
        "P14.3",
        "P17.1",
        "P17.2",
        "L02.2"
      ],
      "transport": "Selected connector MCP or runtime HTTP API",
      "input": "Beth tools check identity, consent, capability and arguments. Use a scoped connection token restricted to permitted connection IDs. Prove two existing provider actions before depending on the catalogue.",
      "output": "Record action_id, payload hash, consent and provider receipt. Pilot consultations are staff-confirmed requests; connected calendar booking belongs to L02.2 in broader launch.",
      "failure_policy": "Inspect outer and inner provider outcome; a gateway HTTP 200 can wrap a failed provider call. Timeout after a write is UNKNOWN: reconcile by receipt/provider lookup, rather than making a second booking blindly.",
      "acceptance_test": "Double-click confirm and lose the response after the provider write. Prove one booking or a visible unresolved receipt awaiting reconciliation. Test revoked access and a provider conflict.",
      "status": "proposed; not executed",
      "official_reference": "https://github.com/oomol-lab/open-connector/blob/main/docs/runtime-api.md",
      "stage": "Pilot connector proof; external calendar at broader launch"
    },
    {
      "id": "I10",
      "title": "Every handoff \u2192 trace + audit + operations",
      "owner_role": "Operations engineer + QA lead",
      "work_packages": [
        "P15.1",
        "P15.2",
        "D05.3"
      ],
      "transport": "OpenTelemetry correlation + Langfuse; Beth database audit",
      "input": "Carry trace context across HTTP and activities. Correlate request, run, source release and action IDs without putting contact details or credentials in trace baggage.",
      "output": "Langfuse provides AI traces/evaluation; hosting health alerts cover runtime failures. Beth retains approval and action audit records independently. Redact inputs before export and control retention.",
      "failure_policy": "Telemetry failure normally must not stop a valid answer. Bound buffers and alert on loss. Use one owner for model instrumentation so duplicate spans do not inflate cost totals. Restore tests cover database, originals and release/index consistency.",
      "acceptance_test": "Follow a turn and ingestion through all components; deliberately break telemetry, worker and storage access. Show redacted traces, alerts and an actual recovery record.",
      "status": "proposed; not executed",
      "official_reference": "https://opentelemetry.io/docs/concepts/context-propagation/"
    }
  ],
  "example_internal_command": {
    "schema_version": "beth.command.v1",
    "request_id": "req_demo_001",
    "run_id": "run_demo_001",
    "account_id": "acct_demo",
    "case_id": "case_demo",
    "action_id": "act_demo_001",
    "operation": "appointment.request",
    "payload_hash": "sha256:<canonical-payload-hash>",
    "consent_reference": "consent_demo",
    "expected_owner_epoch": 7,
    "evidence_release_id": "release_demo_03",
    "deadline_at": "<UTC timestamp>",
    "traceparent": "<W3C trace context>",
    "payload": {
      "specialist_id": "specialist_demo",
      "requested_start": "<ISO timestamp>",
      "timezone": "Asia/Manila"
    }
  },
  "acceptance_tests": [
    {
      "id": "T01",
      "trigger": "Reconnect / duplicate message",
      "expected": "One run and final outcome; no repeated write.",
      "contract": "I01",
      "work_package": "P14.2",
      "status": "not executed"
    },
    {
      "id": "T02",
      "trigger": "Model timeout / quota limit",
      "expected": "Bounded attempts; approved fallback or clear recoverable outcome; usage recorded.",
      "contract": "I03",
      "work_package": "P14.2",
      "status": "not executed"
    },
    {
      "id": "T03",
      "trigger": "Missing source-update webhook",
      "expected": "Reconciler finds desired revision; one processed candidate.",
      "contract": "I04",
      "work_package": "P04.3",
      "status": "not executed"
    },
    {
      "id": "T04",
      "trigger": "Crash mid-ingestion / delayed old job",
      "expected": "Safe continuation; obsolete revision never becomes active.",
      "contract": "I05",
      "work_package": "P04.3",
      "status": "not executed"
    },
    {
      "id": "T05",
      "trigger": "Amendment / retirement / OCR defect",
      "expected": "Applicable evidence only; questionable extraction held for review.",
      "contract": "I06",
      "work_package": "P04.2",
      "status": "not executed"
    },
    {
      "id": "T06",
      "trigger": "Authority down / conflicting rule",
      "expected": "Dated permitted evidence or expert review; no false freshness claim.",
      "contract": "I07",
      "work_package": "P04.3",
      "status": "not executed"
    },
    {
      "id": "T07",
      "trigger": "Specialist takes over during generation",
      "expected": "No late bot dispatch; contact and case remain actionable.",
      "contract": "I08",
      "work_package": "P09.2",
      "status": "not executed"
    },
    {
      "id": "T08",
      "trigger": "Calendar response lost after write",
      "expected": "One confirmed event or UNKNOWN requiring reconciliation.",
      "contract": "I09",
      "work_package": "L02.2",
      "status": "not executed",
      "stage": "Broader launch calendar acceptance"
    },
    {
      "id": "T09",
      "trigger": "Cross-account access / revoked connector",
      "expected": "Denied without leaking data or performing a write.",
      "contract": "I09",
      "work_package": "P14.3",
      "status": "not executed",
      "supporting_work_packages": [
        "P16.1"
      ],
      "stage": "P16.1 approves access policy in S04; P14.3 proves connector isolation and revocation in S06."
    },
    {
      "id": "T10",
      "trigger": "Telemetry failure / restore exercise",
      "expected": "Valid service behaviour, alert, redacted trace and restored release consistency.",
      "contract": "I10",
      "work_package": "D05.3",
      "status": "not executed",
      "supporting_work_packages": [
        "P15.2",
        "P04.3",
        "P11.2",
        "L04.2"
      ],
      "stage": "D05.3 proves the existing cloud restore in S05; P15.2 proves telemetry controls in S05; repeat on the integrated target build for P11.2 in S13 and broader scale for L04.2 in S23\u2013S24."
    }
  ],
  "compatibility_manifest": [
    {
      "component": "Beth API",
      "version": null,
      "digest": null,
      "api_path": null,
      "proof_link": null,
      "approved_by": null,
      "status": "pending selected-version proof"
    },
    {
      "component": "Langflow",
      "version": null,
      "digest": null,
      "api_path": null,
      "proof_link": null,
      "approved_by": null,
      "status": "pending selected-version proof"
    },
    {
      "component": "LiteLLM",
      "version": null,
      "digest": null,
      "api_path": null,
      "proof_link": null,
      "approved_by": null,
      "status": "pending selected-version proof"
    },
    {
      "component": "Directus",
      "version": null,
      "digest": null,
      "api_path": null,
      "proof_link": null,
      "approved_by": null,
      "status": "pending selected-version proof"
    },
    {
      "component": "Temporal server/SDK",
      "version": null,
      "digest": null,
      "api_path": null,
      "proof_link": null,
      "approved_by": null,
      "status": "pending selected-version proof"
    },
    {
      "component": "Docling",
      "version": null,
      "digest": null,
      "api_path": null,
      "proof_link": null,
      "approved_by": null,
      "status": "pending selected-version proof"
    },
    {
      "component": "LlamaIndex",
      "version": null,
      "digest": null,
      "api_path": null,
      "proof_link": null,
      "approved_by": null,
      "status": "pending selected-version proof"
    },
    {
      "component": "PostgreSQL/pgvector",
      "version": null,
      "digest": null,
      "api_path": null,
      "proof_link": null,
      "approved_by": null,
      "status": "pending selected-version proof"
    },
    {
      "component": "Chatwoot/Redis",
      "version": null,
      "digest": null,
      "api_path": null,
      "proof_link": null,
      "approved_by": null,
      "status": "pending selected-version proof"
    },
    {
      "component": "OpenConnector",
      "version": null,
      "digest": null,
      "api_path": null,
      "proof_link": null,
      "approved_by": null,
      "status": "pending selected-version proof"
    },
    {
      "component": "Langfuse/SDK",
      "version": null,
      "digest": null,
      "api_path": null,
      "proof_link": null,
      "approved_by": null,
      "status": "pending selected-version proof"
    }
  ],
  "task_flow_revision": "2026-10-13.1",
  "task_flow_url": "https://beth2.top/integration#task-flow"
}