# Sema > The AI-native, neurosymbolic programming language. Models, contracts, effects, and semantics are language constructs — not library calls. Most LLMs have not been trained on Sema; this file and the linked Markdown teach it. Full corpus in one file: [llms-full.txt](https://sema.49.12.246.95.sslip.io/llms-full.txt). Install language support for your agent: [install-skill](https://sema.49.12.246.95.sslip.io/install-skill/). ## Start Here - [Your First Program](https://sema.49.12.246.95.sslip.io/start/first-program.md): A ten-minute runnable walkthrough — create a Sema project, check it, run it, then add a neurosymbolic touch and re-check. - [Installation](https://sema.49.12.246.95.sslip.io/start/installation.md): Build the Sema reference implementation from source with Cargo, put the CLI on your PATH, verify it, and run your first example project. - [Mental Model](https://sema.49.12.246.95.sslip.io/start/mental-model.md): The core idea behind Sema — the deterministic core versus the generative edge, the gradual guarantee lattice, verification by default, and no silent no-ops. - [Project Layout](https://sema.49.12.246.95.sslip.io/start/project-layout.md): How a Sema project is organized — the src/ tree, modules and imports, visibility, the sema.toml manifest, and Python and native Sema packages. - [Toolchain](https://sema.49.12.246.95.sslip.io/start/toolchain.md): A complete reference to the sema command — check, run, assure, doc, repl, parse, and the package and editor commands — with an example invocation for each. - [Why Sema](https://sema.49.12.246.95.sslip.io/start/why-sema.md): The problem Sema solves — untyped glue around model calls — and the bet it makes: one language where the deterministic core and the generative edge share one verification story. ## Language - [Control Flow](https://sema.49.12.246.95.sslip.io/language/control-flow.md): Sema's control constructs — if/elif/else, for, while, scoped with, and the declarative loop … until for bounded agent loops. - [Equations, Symbolic Algebra & Tensors](https://sema.49.12.246.95.sslip.io/language/equations.md): Sema's equation blocks transcribe mathematical notation directly, plus opt-in symbolic algebra and a first-class native tensor type. - [Error Handling](https://sema.49.12.246.95.sslip.io/language/error-handling.md): Sema has no exceptions — failures are typed values propagated with ?, handled with flat expect/except arms, and combinators. No cascade tax. - [Functions & Effects](https://sema.49.12.246.95.sslip.io/language/functions-and-effects.md): How Sema functions declare capability rows — the typed effect system that makes the deterministic core provable and authority conspicuous. - [Modules & Imports](https://sema.49.12.246.95.sslip.io/language/modules.md): How Sema code is organized — one file is a module, a package is a sema.toml tree, pub marks the public surface, and stdlib imports are explicit. - [Operators & Semantic Algebra](https://sema.49.12.246.95.sslip.io/language/operators.md): The equality-operator family (==, is, ~=, matches, in), why ~= returns a graded Sim, and typed, effect-checked operator overloading. - [Language Overview](https://sema.49.12.246.95.sslip.io/language/overview.md): A tour of Sema's core language — scalars, ADTs, traits, generics, effects, and static typing with local inference. - [Pattern Matching & Interpolated Literals](https://sema.49.12.246.95.sslip.io/language/pattern-matching.md): match/case over structs, enums, tuples, and regex captures — with guards, or-patterns, exhaustiveness — plus f-strings and typed SQL templates. - [Traits, Enums & Generics](https://sema.49.12.246.95.sslip.io/language/traits-enums-generics.md): Sema's answer to classes — traits with default methods, algebraic enums with payloads, bounded generics, and trait objects. No inheritance. - [Types, Bindings & Value Semantics](https://sema.49.12.246.95.sslip.io/language/types.md): Scalars, sized numerics, no-null Option/Result, homogeneous collections, and Sema's immutable-by-default value semantics. ## Neurosymbolic Core - [Contracts](https://sema.49.12.246.95.sslip.io/neurosymbolic/contracts.md): Hard contracts (require / ensure / invariant) raise ContractViolation; soft contracts (check, check semantics) are monitored and never block. Where each runs. - [Schemas and Structured Output](https://sema.49.12.246.95.sslip.io/neurosymbolic/schemas.md): There is no schema keyword — the struct is the schema. Typed decode from models, deterministic serialization, and the decode-and-repair self-repair ladder. - [Semantic Operations](https://sema.49.12.246.95.sslip.io/neurosymbolic/semantic-operations.md): The semantic verb namespace (filter, rank, map, classify, summarize, cluster, dedup, and more), the ~ sigil operator family, and processing pipelines. - [Semantic Values](https://sema.49.12.246.95.sslip.io/neurosymbolic/semantic-values.md): Every Sema value carries a cached embedding beside its exact representation. Canonical flattening and boundary contracts at the deterministic-generative edge. - [Similarity and the Sim Type](https://sema.49.12.246.95.sslip.io/neurosymbolic/similarity.md): a ~= b returns a graded Sim, not a bool. Calibration, statistical(alpha) guards, and semantics(...) as typed natural-language predicates. - [simulate — Generative Interfaces](https://sema.49.12.246.95.sslip.io/neurosymbolic/simulate.md): A model implements the function body. simulate def ... by with sem descriptors, token budgets, ensure/check contracts, and first-class model bindings. - [Verification and assure](https://sema.49.12.246.95.sslip.io/neurosymbolic/verification.md): Verification is default-on (testable is retired). sema assure bronze|silver|gold — ensure property fuzzing, counterexamples, mutation testing, and test blocks. ## Governance & Ops - [Budgets & Metering](https://sema.49.12.246.95.sslip.io/governance/budget.md): Ambient usage metering and hard spend caps in Sema — with meter as u, with budget(tokens=, calls=), and the scheduler that batches and distributes model calls. - [Collectors & Taps](https://sema.49.12.246.95.sslip.io/governance/collectors.md): Non-interfering instrumentation in Sema — collector blocks, the |> tap pipe that records a value without changing it, bounded retention, and async export. - [Effects & Capabilities](https://sema.49.12.246.95.sslip.io/governance/effects.md): How Sema types the authority a function may use — capability rows, the effect-free deterministic core, inferred-not-wildcard rows, and the guarantee lattice. - [Events](https://sema.49.12.246.95.sslip.io/governance/events.md): Typed domain signals in Sema — event declarations with contract-checked payloads, emit, and subscriber handlers with bounded queues and journaled delivery. - [Monitors & Drift](https://sema.49.12.246.95.sslip.io/governance/monitor.md): Native distribution tracking in Sema — monitor declarations, conformal-martingale drift detection with anytime-valid bounds, and on-drifted reactions. - [Policies](https://sema.49.12.246.95.sslip.io/governance/policy.md): Native capability governance in Sema — policy blocks with allow/forbid/examples verified at load, @Policy decorators, and authority-shrinking scopes. - [Protocols & Sessions](https://sema.49.12.246.95.sslip.io/governance/protocols.md): Session-typed generative exchanges in Sema — protocol declarations compiled to state machines, transition checking, and structured concurrency. - [Provenance & Trust](https://sema.49.12.246.95.sslip.io/governance/provenance.md): Trust labels and information-flow tracking in Sema — the untrusted/validated/trusted lattice, sticky taint by meet, and the two endorsement doors. - [Supervise & Heal](https://sema.49.12.246.95.sslip.io/governance/supervise.md): Governed self-healing in Sema — supervise scopes with enforced restart and heal budgets, an acceptance gauntlet over real predicates, staged/live/persistent patch application, and a journal record for every step. ## Standard Library - [std.overview](https://sema.49.12.246.95.sslip.io/stdlib/overview.md): How the Sema standard library works — written in Sema, embedded in the compiler, imported via from std. import …. - [std.belief](https://sema.49.12.246.95.sslip.io/stdlib/belief.md): Beta-Bernoulli calibrated-confidence tracking — soft Bernoulli updates over a parametrizable prior, as a first-class Sema type. - [std.cache](https://sema.49.12.246.95.sslip.io/stdlib/cache.md): Memoization as ordinary Sema decorators — memoize caches within a run, memoize_disk persists across runs. - [std.collections](https://sema.49.12.246.95.sslip.io/stdlib/collections.md): Small pure list and string helpers used across the Sema standard library — joins, stable rounding, and order-preserving de-duplication. - [std.document](https://sema.49.12.246.95.sslip.io/stdlib/document.md): A typed report IR the model fills and a pure, deterministic render to markdown — no regex repair of freeform LLM output. - [std.agent_loop](https://sema.49.12.246.95.sslip.io/stdlib/agent_loop.md): The agentic do-until loop as a reusable combinator — loop_until(init, max_iters, step, done) over immutable state. - [std.usage](https://sema.49.12.246.95.sslip.io/stdlib/usage.md): Model usage accounting — accumulate token counts across calls and price them with caller-supplied rates. Complements the ambient with meter scope. - [std.provenance](https://sema.49.12.246.95.sslip.io/stdlib/provenance.md): Citation-id mapping and rewrite — assign each unique source a stable global id and rewrite local [n] markers across documents. ## Guides - [Building an Agent Loop](https://sema.49.12.246.95.sslip.io/guides/agent-loops.md): Build a bounded agent in Sema with loop … until, ambient budgets, drift monitors, and governed tool calls — end to end. - [Native Agents and Durable Circuits](https://sema.49.12.246.95.sslip.io/guides/agents-and-circuits.md): Declare typed agents, compose durable multi-agent circuits, fan work out with parallel, and admit dynamic specialists without widening authority. - [Documents & Reports](https://sema.49.12.246.95.sslip.io/guides/documents.md): Generate structured, auditable reports in Sema — a typed Report the model fills and a deterministic renderer, plus docs as a reflected artifact. - [Multimodal](https://sema.49.12.246.95.sslip.io/guides/multimodal.md): Treat images, audio, and files as first-class message parts in Sema — one composable Prompt that even a text-only model can see and hear. - [Packaging & Providers](https://sema.49.12.246.95.sslip.io/guides/packaging.md): Install packages with sema add, ship native Sema packages, configure sema.toml, wire typed config + DI, and override any model backend with @provides. - [Python Interop](https://sema.49.12.246.95.sslip.io/guides/python-interop.md): Reuse the whole Python ecosystem from Sema — live objects and classes via the persistent worker, plus governed bridges and verified ports. - [Reflection & Staged Code](https://sema.49.12.246.95.sslip.io/guides/reflection.md): Read a program's own shape with reflect, generate typed Code[T] instead of eval, and turn any error into an LLM-ready repair packet with trace. - [Constraint Solving](https://sema.49.12.246.95.sslip.io/guides/solve.md): Search over discrete choices in Sema with the native solve block — variables over finite domains, boolean constraints, first-solution or all-solutions. - [Long-Stream Processing](https://sema.49.12.246.95.sslip.io/guides/streams.md): Handle unbounded data in Sema — generators and Stream[T], bounded-memory pipelines, live token/speech streaming, and whole-document folds with compaction. - [Tools, Skills & MCP](https://sema.49.12.246.95.sslip.io/guides/tools-and-mcp.md): Give a model capabilities in Sema — a function is a tool, Markdown skills and MCP servers load through one uniform surface, all governed by effect rows. ## Examples - [Examples Overview](https://sema.49.12.246.95.sslip.io/examples/overview.md): A tour of the worked Sema projects — governance and finance, agents and reasoning, interop and the SDK, and language features — each a runnable project you can check, run, and assure. ## Reference - [agent-research](https://sema.49.12.246.95.sslip.io/reference/examples-api/agent-research.md): The agent-research worked example. - [§1. Design principles](https://sema.49.12.246.95.sslip.io/reference/language-spec/01-design-principles.md): Sema language specification — §1 Design principles. - [Builtins](https://sema.49.12.246.95.sslip.io/reference/native-api/native-builtins.md): Ambient constructors, tensor operations, and numeric builtins. - [std.agent_loop](https://sema.49.12.246.95.sslip.io/reference/stdlib-api/agent_loop.md): Reflected API reference for the Sema standard-library module std.agent_loop. - [agent-scientific](https://sema.49.12.246.95.sslip.io/reference/examples-api/agent-scientific.md): The agent-scientific worked example. - [Equation operators](https://sema.49.12.246.95.sslip.io/reference/native-api/native-equation.md): Differential and symbolic operators available inside equation blocks. - [std.agents](https://sema.49.12.246.95.sslip.io/reference/stdlib-api/agents.md): Reflected API reference for the Sema standard-library module std.agents. - [agent-software](https://sema.49.12.246.95.sslip.io/reference/examples-api/agent-software.md): The agent-software worked example. - [latex](https://sema.49.12.246.95.sslip.io/reference/native-api/native-latex.md): Native bounded LaTeX rendering operations. - [std.belief](https://sema.49.12.246.95.sslip.io/reference/stdlib-api/belief.md): Reflected API reference for the Sema standard-library module std.belief. - [ai-console](https://sema.49.12.246.95.sslip.io/reference/examples-api/ai-console.md): An interactive AI console — simulate, semantic ops, and streaming in a REPL-shaped app. - [lean](https://sema.49.12.246.95.sslip.io/reference/native-api/native-lean.md): Native bounded Lean theorem-prover adapter operations. - [std.cache](https://sema.49.12.246.95.sslip.io/reference/stdlib-api/cache.md): Reflected API reference for the Sema standard-library module std.cache. - [autogen-arithmetic-agent](https://sema.49.12.246.95.sslip.io/reference/examples-api/autogen-arithmetic-agent.md): The autogen-arithmetic-agent worked example. - [math](https://sema.49.12.246.95.sslip.io/reference/native-api/native-math.md): Native scalar and tensor scientific-math operations. - [std.circuits](https://sema.49.12.246.95.sslip.io/reference/stdlib-api/circuits.md): Reflected API reference for the Sema standard-library module std.circuits. - [complex-tensors](https://sema.49.12.246.95.sslip.io/reference/examples-api/complex-tensors.md): The complex-tensors worked example. - [std.collections](https://sema.49.12.246.95.sslip.io/reference/stdlib-api/collections.md): Reflected API reference for the Sema standard-library module std.collections. - [crisis-logistics](https://sema.49.12.246.95.sslip.io/reference/examples-api/crisis-logistics.md): Constraint-solving under pressure: solve, policy, and budgeted planning for relief routing. - [std.completion](https://sema.49.12.246.95.sslip.io/reference/stdlib-api/completion.md): Reflected API reference for the Sema standard-library module std.completion. - [dense-linalg-solvers](https://sema.49.12.246.95.sslip.io/reference/examples-api/dense-linalg-solvers.md): The dense-linalg-solvers worked example. - [std.document](https://sema.49.12.246.95.sslip.io/reference/stdlib-api/document.md): Reflected API reference for the Sema standard-library module std.document. - [dentate-os-simulator](https://sema.49.12.246.95.sslip.io/reference/examples-api/dentate-os-simulator.md): The dentate-os-simulator worked example. - [std.provenance](https://sema.49.12.246.95.sslip.io/reference/stdlib-api/provenance.md): Reflected API reference for the Sema standard-library module std.provenance. - [finite-sets-logic](https://sema.49.12.246.95.sslip.io/reference/examples-api/finite-sets-logic.md): The finite-sets-logic worked example. - [std.usage](https://sema.49.12.246.95.sslip.io/reference/stdlib-api/usage.md): Reflected API reference for the Sema standard-library module std.usage. - [finops-ledger](https://sema.49.12.246.95.sslip.io/reference/examples-api/finops-ledger.md): A governed financial reconciliation ledger — contracts, policy, supervision, and provenance. - [§2. Surface syntax decision](https://sema.49.12.246.95.sslip.io/reference/language-spec/02-surface-syntax-decision.md): Sema language specification — §2 Surface syntax decision. - [std.web](https://sema.49.12.246.95.sslip.io/reference/stdlib-api/web.md): Reflected API reference for the Sema standard-library module std.web. - [graphrag](https://sema.49.12.246.95.sslip.io/reference/examples-api/graphrag.md): Graph-structured retrieval-augmented generation with semantic operations over a knowledge graph. - [hybrid-interop](https://sema.49.12.246.95.sslip.io/reference/examples-api/hybrid-interop.md): Sema ↔ Python interop: reuse the Python ecosystem, classes and all. - [langgraph-orchestrator-worker](https://sema.49.12.246.95.sslip.io/reference/examples-api/langgraph-orchestrator-worker.md): The langgraph-orchestrator-worker worked example. - [os-simulator-world-model](https://sema.49.12.246.95.sslip.io/reference/examples-api/os-simulator-world-model.md): The os-simulator-world-model worked example. - [polymorphism](https://sema.49.12.246.95.sslip.io/reference/examples-api/polymorphism.md): Traits, enums, and generics — Sema polymorphism without classes or inheritance. - [prime-sequence](https://sema.49.12.246.95.sslip.io/reference/examples-api/prime-sequence.md): The prime-sequence worked example. - [proof-polynomial](https://sema.49.12.246.95.sslip.io/reference/examples-api/proof-polynomial.md): The proof-polynomial worked example. - [quarks-workflow-engine](https://sema.49.12.246.95.sslip.io/reference/examples-api/quarks-workflow-engine.md): The quarks-workflow-engine worked example. - [research-agent](https://sema.49.12.246.95.sslip.io/reference/examples-api/research-agent.md): A bounded research agent: loop … until, budgets, monitors, and tool calling. - [robotics-cell](https://sema.49.12.246.95.sslip.io/reference/examples-api/robotics-cell.md): A robotics work-cell controller with protocols, supervision, and self-healing. - [§3. Type system](https://sema.49.12.246.95.sslip.io/reference/language-spec/03-type-system.md): Sema language specification — §3 Type system. - [scientific-domains](https://sema.49.12.246.95.sslip.io/reference/examples-api/scientific-domains.md): The scientific-domains worked example. - [sdk-demo](https://sema.49.12.246.95.sslip.io/reference/examples-api/sdk-demo.md): Embedding Sema via the SDK — driving the runtime from a host program. - [sdk-multimodal](https://sema.49.12.246.95.sslip.io/reference/examples-api/sdk-multimodal.md): Multimodal messages through the SDK — images and text as first-class content. - [semantic-library](https://sema.49.12.246.95.sslip.io/reference/examples-api/semantic-library.md): A semantic library/catalog built on ~=, semantic.rank, and belief tracking. - [trial-safety](https://sema.49.12.246.95.sslip.io/reference/examples-api/trial-safety.md): Clinical-trial safety triage — contracts + semantics() guards over sensitive decisions. - [§4. Execution model overview](https://sema.49.12.246.95.sslip.io/reference/language-spec/04-execution-model-overview.md): Sema language specification — §4 Execution model overview. - [§5. Construct catalog](https://sema.49.12.246.95.sslip.io/reference/language-spec/05-construct-catalog.md): Sema language specification — §5 Construct catalog. - [§6. Core grammar sketch (EBNF)](https://sema.49.12.246.95.sslip.io/reference/language-spec/06-core-grammar-sketch-ebnf.md): Sema language specification — §6 Core grammar sketch (EBNF). - [§7. Worked example — the article-embedding tracker](https://sema.49.12.246.95.sslip.io/reference/language-spec/07-worked-example-the-article-embedding-tracker.md): Sema language specification — §7 Worked example — the article-embedding tracker. - [§8. Decision record](https://sema.49.12.246.95.sslip.io/reference/language-spec/08-decision-record.md): Sema language specification — §8 Decision record. - [§9. Open questions](https://sema.49.12.246.95.sslip.io/reference/language-spec/09-open-questions.md): Sema language specification — §9 Open questions. - [CLI Reference](https://sema.49.12.246.95.sslip.io/reference/cli.md): The complete, verified reference for the sema command — check, run, assure, doc, parse, tokens, repl, infer, packages, and the editor servers — with the exact flags and an example for each. - [Decision Log](https://sema.49.12.246.95.sslip.io/reference/decision-log.md): A readable summary of Sema's language design decisions — why Python-shaped, why no classes, why typed effects, why default-on verification — with the rationale behind each. - [Effects Catalog](https://sema.49.12.246.95.sslip.io/reference/effects-catalog.md): The canonical catalog of Sema's built-in effect capabilities — every enforced effect path, the operations that carry it, where it is checked, and how custom capabilities extend the open row vocabulary. - [Grammar (EBNF)](https://sema.49.12.246.95.sslip.io/reference/grammar.md): The complete Sema grammar in EBNF, generated from grammar/sema.ebnf.