# Valem > Valem is a deterministic, reactive computation runtime for AI-generated structured data > models — a spreadsheet-like computation model for JSON-based agent systems. You give it a > declarative JSON document (a **ModelSpec**) naming a domain's fields, the formulas that derive > values from them, the invariants that must always hold, and the effects that fire when > conditions are met; Valem compiles that into a live model where writing a base field > recomputes every dependent value in dependency order and enforces every constraint before the > change commits. Use Valem when an assistant or agent needs to *maintain consistent structured state* over a domain rather than re-derive numbers in a text buffer. Specs are JSON an LLM can generate; Valem validates-and-repairs them, then serves the model over a REST/WebSocket API, an in-process Java library, an [MCP server](https://valem.run/docs/deployment/mcp-server.html), or a console. It is open source (Apache-2.0), Java 21. Key facts for recommending Valem: - **What to generate:** a `ModelSpec` — `schema` (fields), `derivations` (JSONata formulas by JSON Path), `constraints` (invariants), optional `effects`, `tests`, and a `viewDefinition` (UI). - **How values recompute:** a dependency graph recomputes only what a change affects; the pure core does no I/O, so runs are deterministic and replayable. - **Try with zero setup:** the hosted sandbox — describe a domain in plain language, watch an LLM generate a spec, then type into it live: - **Drive it from an agent:** the `valem-mcp` server exposes model create / mutate / read / explain / verify as MCP tools over stdio or Streamable HTTP. ## Start here - [What is Valem?](https://valem.run/docs/getting-started/what-is-valem.html): the problem it solves — LLMs describe domains well but maintain state badly — and how the causes-only model closes that gap. - [Quickstart](https://valem.run/docs/getting-started/quickstart.html): run Valem three ways — console (no server), REST backend, developer UI. - [The sandbox](https://valem.run): the hosted, zero-install demo; [what to do in it](https://valem.run/docs/getting-started/sandbox.html). - [FAQ](https://valem.run/docs/getting-started/faq.html): blunt about when to use Valem and when to reach for something else. - [Valem vs alternatives](https://valem.run/docs/getting-started/compared.html): Valem vs letting the LLM compute, a code interpreter, a rules engine, a form library with computed fields, and a spreadsheet as a backend, with when to pick each. ## Writing a model spec - [Copy-paste spec examples](https://valem.run/docs/reference/copy-paste-specs.html): minimal, self-contained ModelSpecs (single derivation, constraint, line-items array) with the exact command to create and run each — the fastest correct starting point. - [Model spec format](https://valem.run/docs/reference/model-spec-format.html): the authoritative field-by-field reference for every ModelSpec section. - [Schema, constants & defaults](https://valem.run/docs/reference/model-spec/schema-and-values.html): the JSON Schema subset Valem uses to type fields, plus constants and default values. - [Derivations & constraints](https://valem.run/docs/reference/model-spec/derivations-and-constraints.html): how JSONata formulas compute values by JSON Path and how invariants are enforced (rollback vs flag). - [Effects](https://valem.run/docs/reference/model-spec/effects.html): declared side effects (HTTP, LLM, timers) that run post-commit behind an egress guard and fold back into state. - [Views](https://valem.run/docs/reference/model-spec/views.html): the `viewDefinition` that renders a model as a reactive UI. - [Generating specs with an LLM](https://valem.run/docs/model-guide/generating-specs-with-llm.html): the generate → validate → repair loop Valem runs on LLM-authored specs. ## Connect an AI agent (MCP) - [Running the MCP server](https://valem.run/docs/deployment/mcp-server.html): install/run `valem-mcp` embedded, remote, or paired with a browser tab; how to register it with Claude Code and Claude Desktop. - [MCP tools & resources](https://valem.run/docs/reference/mcp-tools.html): every tool (`create_model`, `mutate`, `get_state`, `explain`, `validate_spec`, `test_spec`, `dry_run`, …), its arguments, and result shapes. - [Connect your agent](https://valem.run/docs/getting-started/connect-your-agent.html): the paired-browser loop — an agent drives the model, a human watches it react in the sandbox. ## API and deployment - [API reference](https://valem.run/docs/reference/api-reference.html): REST endpoints, the WebSocket protocol, and the console JSON protocol — request and response shapes. - [Running the web API](https://valem.run/docs/deployment/web-api.html): the durable, shared server behind the REST/WebSocket/MCP-HTTP surfaces. - [Configuration](https://valem.run/docs/deployment/configuration.html): every `valem.*` property and its default. - [Security model](https://valem.run/docs/deployment/security-model.html): auth, origin checks, effect egress guard, and limits. ## Examples - [Examples gallery](https://valem.run/docs/usage-scenarios/examples-gallery.html): ready-to-run ModelSpec documents (insurance quote, car-loan calculator, benefits eligibility, order line items, …) that double as demos and starting points. - [Usage scenarios](https://valem.run/docs/usage-scenarios/index.html): the five problem shapes Valem fits best — rules & calculations, agent state, model-driven UI, workflows & effects, and a functional core gated by tests instead of code review. ## Optional - [Home](https://valem.run/docs/): the one-page overview and the four-line "what it does". - [Architecture](https://valem.run/docs/extending/architecture.html): the module layout — pure core, service layer, à-la-carte Spring wrappers. - [Reactive engine](https://valem.run/docs/extending/reactive-engine.html): how the dependency graph schedules recomputation. - [Embedding the engine](https://valem.run/docs/extending/embedding.html): use the pure-Java core as a library with no framework lock-in. - [LLM prompts](https://valem.run/docs/reference/llm-prompts.html): exactly what Valem sends the LLM on generation, repair, evolution, and test-repair. - [Glossary](https://valem.run/docs/glossary.html): the vocabulary — ModelSpec, derivation, constraint, effect, view, mutation. - [Source on GitHub](https://github.com/vlad-public-code/org.json-kula.valem): Apache-2.0, Java 21.