Lisp·LLM primitives·Rust runtime

A Lisp with LLM primitives.

Sema is a Scheme-like Lisp with built-in agents, typed tools, budgets, replay, and tracing. It runs on a Rust bytecode VM and builds to one standalone executable.

$curl -fsSL https://sema-lang.com/install.sh | sh
Windows, Homebrew, Cargo, and other install methods

MIT · macOS, Linux, and Windows

The defining difference

The whole agent fits on one screen.

Model calls, tools, conversations, and agents are language values. The runtime owns the repetitive work around them, so the source stays focused on the program you meant to write.

  • Tools have schemas.deftool connects a description and input schema to an ordinary Sema function.
  • The agent loop is built in.defagent declares the prompt, tools, and turn limit; agent/run handles calls and tool results.
  • Limits are scoped. Token caps and known-price cost limits apply to every model call inside llm/with-budget.
  • Runs can be replayed. A cassette records provider traffic once, then reuses the exact responses in local development and tests.
Explore agents and tools
weather.sematool · agent · controls
(deftool get-weather
  "Get weather for a city"
  {:city {:type :string}}
  (lambda (city)
    (http/get f"https://weather.test/${city}")))

(defagent guide
  {:system "Give a short forecast."
   :tools [get-weather]
   :max-turns 3})

(llm/with-cassette
  "weather.jsonl" {:mode :auto}
  (lambda ()
    (llm/with-budget
      {:max-cost-usd 0.10}
      (lambda ()
        (agent/run guide
          "Weather in Oslo?")))))

The language

Small enough to learn. Complete enough to use.

Sema keeps Scheme's lexical scope, functions, macros, and tail calls, then adds the data forms people expect in current programs.

surface.semaone syntax rule
(define tickets
  [{:id 101 :priority :high}
   {:id 102 :priority :low}])

(define urgent-ids
  (->> tickets
    (filter
      #(equal? (:priority %) :high))
    (map :id)))

(match urgent-ids
  ([]       "nothing urgent")
  ([id & _] f"start with ticket ${id}"))
Scheme core
Lexical scope, first-class functions, tail-call optimization, quasiquote macros, and structured exceptions.
Clojure-flavored data
Keywords, maps, vectors, short lambdas, threading macros, destructuring, pattern matching, and f-strings.
One runtime
REPL, formatter, LSP, debugger, notebook, MCP server, compiler, and executable builder ship in the sema binary.
Designed for generated code
A uniform syntax and a concise agent guide give coding agents a small, stable target. Read the guide →

What it is for

From one model call to a complete workflow.

Start with a script. Add tools, structure, persistence, or an interactive notebook without changing the language or runtime.

01

Agents and tools

Run bounded tool loops with typed inputs, callbacks, and recoverable tool errors.

Agents
02

Structured extraction

Turn unstructured model output into validated maps, lists, and scalar values.

Extraction
03

Journaled workflows

Split long work into phases, record checkpoints, bound fan-out, and resume a run.

Workflows
04

Notebooks

Develop in shared-state cells, inspect rich output, then run the same code as a script.

Notebook

Then ship it

A script in. One executable out.

sema build traces imports, bundles declared assets, and writes a standalone executable. The target machine does not need Sema, Cargo, or another language runtime.

  • Cross-platform builds. Target macOS, Linux, and Windows from the same source.
  • Capability sandbox. Restrict filesystem, network, shell, process, environment, and LLM access at the CLI boundary.
  • Embeddable when needed. Run Sema inside Rust, JavaScript, or a browser through the same VM.
See standalone executables
terminal
$ sema build weather.sema -o weather
  traced imports and bundled assets
  built ./weather

$ scp weather server:
$ ssh server ./weather Oslo
  runs without a Sema installation

Provider choice

Switch models without rewriting the program.

Sema auto-configures providers from environment variables. Your tools, agents, budgets, and traces stay the same whether a run uses a hosted model, a local model, or an ordered fallback chain.

See all providers
Built-in chat
  • Anthropic
  • OpenAI
  • Gemini
  • Ollama
Compatible chat
  • Groq
  • xAI
  • Mistral
  • DeepSeek
  • OpenRouter
  • Together
  • and more
Embed & rerank
  • OpenAI
  • Jina
  • Voyage
  • Cohere
  • Nomic
  • Fireworks
provider.semaordered fallback
(llm/with-fallback
  [:anthropic :openai :ollama]
  (lambda ()
    (agent/run guide question)))

Start with one file

Build your next LLM program in Sema.

Try it in the browser, follow the quickstart, or give the concise language guide to your coding agent.

curl$curl -fsSL https://sema-lang.com/install.sh | sh
brew$brew install helgesverre/tap/sema-lang
agent$curl -fsSL https://sema-lang.com/docs/for-agents.md >> AGENTS.md