Skip to main content

The Cloud Harness. Reference Cognitive State Machine engine for the Hybrid Cognitive Sync Protocol: FastAPI + LangGraph + pgvector.

Project description

@moolam/cloud-orchestrator

The cloud engine: reference Cognitive State Machine implementation for the Hybrid Cognitive Sync Protocol. Python (FastAPI + LangGraph + pgvector). Any engine that honors the wire contract may replace this one.

Architecture

Domain-agnostic runtime components, each isolated from HTTP concerns:

Module Responsibility
agent_runtime.py Composes router, state store, and memory into one agent turn
task_router.py Cyclical prerequisite-graph routing (LangGraph state machine)
planner.py Goal decomposition and cyclic plan revision (Python twin of the planning contract)
memory_graph.py pgvector-backed long-term subject memory (MCE) with kind-aware decay
sync_service.py CRDT reconciliation over master state documents
contract_models.py Pydantic mirrors of the canonical TypeScript wire contract
crdt_merge.py Join-semilattice merge, byte-identical twin of the TS resolver
main.py FastAPI transport: /v1/sync, /v1/agent/turn, /v1/agent/turn/stream (SSE), /v1/subjects/{id}/state, /v1/subjects/{id}/sync-audit, /v1/health
auth.py Pluggable AuthVerifier seam + reference API-key / permissive-dev verifiers

No module knows about any profession. Domain configuration (task graphs, charters, tool packs) lives in domains/ and is loaded as data.

AuthN / AuthZ (pluggable)

Default-deny on /v1/* except /v1/health. Self-hosters inject an AuthVerifier at startup — Sutra does not ship an IdP.

Operator guide: docs/pluggable-auth-deployment.md (API-key setup, JWT sketch, mTLS-at-proxy pattern).

Quick API-key mode:

export SUTRA_AUTH_VERIFIER=api_key
export SUTRA_API_KEYS_JSON='{"sk_demo":{"principalId":"ops-1","subjectScope":"*"}}'
uvicorn sutra_orchestrator.main:app --app-dir src

Public API

The HTTP surface is defined by the wire contract in packages/sync-protocol/src/contract.ts. The Pydantic models here must stay field-for-field identical; CI compares generated JSON Schemas.

Quick start

pip install -e ".[dev]"
uvicorn sutra_orchestrator.main:app --reload --app-dir src
# with persistence:
SUTRA_PG_DSN=postgresql://sutra:sutra@localhost:5432/sutra uvicorn sutra_orchestrator.main:app --app-dir src

Or via the repo root: pnpm infra:up (see infra/docker-compose.yml).

Task graph pack (production)

Boot loads a versioned JSON pack via resolve_production_task_graph (not an inline demo graph):

# Optional override (compose sets this to the bundled pack path):
export TASK_GRAPH_PACK=/path/to/task-graph.v1.json
uvicorn sutra_orchestrator.main:app --app-dir src

When unset, the bundled sutra_orchestrator/packs/teacher-cbse-slice.json is used (same bytes as @moolam/domain-loader / playground). Override with TASK_GRAPH_PACK for alternate packs (e.g. demo-math-sd-slice.json). Postgres row injection is supported by the same resolver (pack_row=…) with threshold fallback when the row omits thresholds.

Operator runbooks:

Live verification (compose): bash packages/cloud-orchestrator/scripts/verify_operator_surfaces_compose.sh (HEALMETREN-003 + OPERRUNB-004).

All three link metrics (/v1/metrics) and the event catalog.

Dependency-light smoke test (pydantic only):

python smoke_test.py

Versioning

Distribution semver and the wire PROTOCOL_VERSION constant move together at release. See docs/protocol/VERSION-LOCKSTEP.md for the file list, bump procedure, and PyPI/npm alignment rules.

Contributing notes

  • Never change contract_models.py without changing contract.ts in the same PR (contract-parity checklist in the PR template).
  • The merge in crdt_merge.py must remain commutative, associative, and idempotent; the smoke test asserts this on every run.
  • Keep runtime components free of domain vocabulary; see docs/adr/0005-runtime.md.

Examples

examples/cloud-sync/ exercises the same merge algebra from TypeScript; smoke_test.py covers the Python side including the planner.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sutra_sdk-1.0.0.tar.gz (94.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sutra_sdk-1.0.0-py3-none-any.whl (109.4 kB view details)

Uploaded Python 3

File details

Details for the file sutra_sdk-1.0.0.tar.gz.

File metadata

  • Download URL: sutra_sdk-1.0.0.tar.gz
  • Upload date:
  • Size: 94.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for sutra_sdk-1.0.0.tar.gz
Algorithm Hash digest
SHA256 c354cc1b7db33d9491db50e634acee912e032edcd7a4384bf51c444793d64b0a
MD5 8c0b02de65e0268987a827df32ddcb4b
BLAKE2b-256 5f488b27478f40307ee96ba914dfc2e36d7550ce592c32c08b8f0a12e7f94554

See more details on using hashes here.

File details

Details for the file sutra_sdk-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: sutra_sdk-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 109.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for sutra_sdk-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e5d821df891a55be7e946c84a5bb52773653b833b92f29617331274c7ca3dd73
MD5 1f0ef8788d4d42db2119e9c97a9bd629
BLAKE2b-256 b8e14ded37466f317478edb2cb6b6c70c34b4ffac1399cabcc781abd61aab150

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page