Skip to content

Examples Overview

Sema ships a corpus of worked example projects under examples/. Each one is a real, runnable Sema project — a directory with src/*.sema (entry: main() in main.sema) — not a snippet. Because they are projects, you can put each one through the full toolchain:

Terminal window
sema check examples/finops-ledger # static checks
SEMA_STRICT=1 sema run examples/finops-ledger # execute, failing hard on any degradation
sema assure examples/finops-ledger --grade gold # run tests + fuzz properties + mutation-test

They run hermetically under the opt-in deterministic engine ([engine] deterministic = true in sema.toml, or SEMA_DETERMINISTIC=1) — no model download, no network — so the deterministic core of every example is reproducible. Where a project uses generative constructs (simulate def, semantic.*, ~=), those calls are covered by contracts (ensure / check semantics) rather than by exact-output comparison.

Every top-level project also has a generated gallery page under Reference › Examples API, reflected directly from its source — signatures, effect rows, structs, and docstrings.

Regulated, high-stakes workflows: policy-confined capabilities, adversarial inputs, trust labeling, audit trails, and monitored public output.

  • finops-ledger — Regulated payment reconciliation and anomaly review. Adversarial documents, taint/endorsement, typed SQL, tap collectors, native config/DI, and native parallel map/search. Assured at gold.
  • trial-safety — Clinical-trial adverse-event review. PII policy, human adjudication, calibrated extraction, and a deliberate no-autonomous-medical-action stance. Assured at gold.
  • crisis-logistics — Multi-agency disaster-response dispatch. Cross-agency policy, semantic deduplication, route planning, and monitored public briefings.
  • robotics-cell — Warehouse robotics recovery and maintenance. Physical monitors, session-typed protocols, structured concurrency, and patch-scoped supervise/heal. Assured at gold.

Native typed agents, durable circuits, and the lower-level neurosymbolic pieces for building custom reasoning loops. Start with the Native Agents and Durable Circuits guide.

  • agent-research — Native research fan-out/fan-in with parallel [agent(x) for x in xs], bounded model calls, ordered evidence, and typed synthesis.

  • agent-software — An explorer→engineer→hardener circuit with an owned spawned task and typed patch handoff.

  • agent-scientific — A failed theorem/experiment path dynamically admits a bounded proof auditor under an AgentEnvelope; deterministic verification gates publication.

  • research-agent — A compact search-then-write pipeline built entirely on the Sema standard library: provenance citation ids, semantic.dedup, a belief-driven loop_until, ambient with meter, and typed-report rendering (std.document).

  • semantic-library — Book and paper knowledge operations. User-defined semantic operators, native prompt templates, and role-aware context state machines. Assured at gold.

Reusing existing ecosystems and driving real models through native Sema surfaces.

  • hybrid-interop — Existing Python/TypeScript/C code wrapped by Sema. Typed bridge membranes, inline foreign glue, holistic sem descriptors, and re-validation at the boundary. Assured at gold.
  • graphrag — A GraphRAG backend in Sema, one-to-one with a Python reference and bit-comparable. Proper module/namespace layout and in-process host entry points for a Python/TS bridge.
  • sdk-demo — Using the Sema SDK (ai.sema): text generation, embedding similarity, and a tool-using agent where your Sema functions are the tools.
  • sdk-multimodal — End-to-end multimodal via the SDK: captioning, OCR, VQA, and a TTS→STT speech round-trip behind native Sema functions (real small HF models once the extras are installed).

Focused tours of the surface syntax and the native AI capabilities.

  • polymorphism — The whole trait trio in one runnable program: header conformance, out-of-line impl, enum conformance, bounded generics, default methods, supertraits, and trait objects — in a functional style. No classes; traits and ADTs only.
  • ai-console — A deterministic tour of the native AI surface: prompt templates and composition debugging, multimodal messages, token streaming, batched/distributed generation, reduced-precision numeric widths, and operator overloading.

examples/neurosymbolic-port/ is a special corpus: it ports patterns from the Python SymbolicAI framework and a deep-research agent to Sema and proves the ports are equivalent to the originals on their deterministic cores. Each pattern lives in its own subproject with a src/main.sema whose main() returns a vector compared against a golden emitted by the Python reference (reference/<name>_ref.py), asserted in crates/sema-runtime/tests/equiv_neurosymbolic.rs — with no Python or network needed at test time.

The subprojects (belief/, provenance/, usage/, budget/, cache/, loop/, document/, meter/, dedup/, purify/) each replace a chunk of hand-threaded Python — a BeliefTracker, a MetadataTracker, (result, usage) tuples, a ~300-line agentic while-loop — with a Sema standard-library construct or a native scope. Because the ports now import from std.*, the equivalence tests prove the standard library itself matches the reference Python. Each subproject is a runnable Sema project:

Terminal window
sema run examples/neurosymbolic-port/loop
sema check examples/neurosymbolic-port/dedup