Skip to content

The Sema standard library is a small set of neurosymbolic building blocks — calibrated confidence, memoization, structured reports, agentic loops, usage accounting, provenance, and collection helpers. What makes it unusual is what it is made of: the standard library is written in Sema. Every module you see here has a .sema source file that you can read, and the logic in it — a Beta prior, a token price, a render layout — is expressed in the language, not buried in the runtime.

Each module lives in stdlib/sema/<module>.sema and ships embedded in the compiler (injected via crates/sema-runtime/src/stdlib.rs). There is nothing to install. Any project can bring a module in with an explicit import:

from std.belief import Belief, prior
from std.cache import memoize
from std.document import Report, render
from std.agent_loop import loop_until

Sema draws a clean line between two kinds of dependency (spec §5.35). Effect capabilitiesfs, net, model, memory, … — are authorized by the !{...} effect row on a function and stay ambient. Standard-library modules are APIs you call, so they must be named in an explicit import, exactly as in Python. Using a std module without importing it is a NameError with an actionable hint, never a silent fallback.

Each module replaces code that AI applications otherwise hand-roll again and again — a bespoke confidence tracker, a pickle-path cache, regex repair of freeform model markdown, a 300-line while loop, (result, usage) tuple threading, citation-id bookkeeping. Standardizing these as small, verified, readable Sema components makes the neurosymbolic parts of a program legible and reusable instead of copy-pasted.

ModuleWhat it gives youNarrativeGenerated API
beliefBeta-Bernoulli calibrated confidencestd.beliefAPI
cacheMemoization decorators (in-run + on-disk)std.cacheAPI
collectionsSmall pure list/string helpersstd.collectionsAPI
documentTyped report IR + deterministic renderstd.documentAPI
agent_loopThe agentic loop as a combinatorstd.agent_loopAPI
usageModel usage accounting + pricingstd.usageAPI
provenanceCitation-id mapping + rewritestd.provenanceAPI

Every module has two pages. The narrative page (this section, /stdlib/…) motivates the module, shows the key types and functions with usage, and gives you the import line. The generated API reference (/reference/stdlib-api/…) is emitted by sema doc directly from the .sema source — it is the exact, never-drifting signature list (params, return types, effect rows, struct fields). Read the narrative to learn the module; consult the API for the precise surface.