Why Turn
Turn is a language for a specific kind of software — software that reasons. Before learning the syntax, it is worth understanding what problem Turn is actually solving.
The Standard Approach Doesn't Work
The most common pattern for building an LLM agent today looks like this:
while not done:
response = llm.chat(messages)
messages.append(response) # Unbounded list
if "TOOL_CALL" in response:
result = run_tool(response) # Untyped output
messages.append(result)
if is_done(response): # Brittle string match
done = TrueThis works for demos. It fails in production. Here's why:
The Five Failure Modes
1. Context Overflows Silently
You append to a messages list. At some point, the model starts confusing old context with new instructions. It hallucinates information from 50 messages ago. There is no runtime signal — the list is just too long and the model does its best.
There is no language primitive enforcing context bounds. You have to manually trim, summarize, and evict — and every project reinvents this machinery differently.
2. Inference Outputs Are Untyped
The model returns a string. You json.loads() that string and hope the schema matched. When it doesn't, you get a KeyError at runtime that has nothing to do with your business logic — it's a symptom of an unvalidated contract between your code and the model.
There is no compile-time contract between your type system and the LLM output.
3. State Is Smeared Everywhere
What does the agent "know" at any given moment? You have to trace through the messages list, the external database, the in-memory cache, the tool results stitched into the loop. There is no single, inspectable state.
There is no first-class concept of agent state. State is an emergent property of your loop's side effects.
4. A "Turn" Is Not a Language Concept
The most fundamental unit of agentic work — a single cycle of observe → reason → act — has no representation in the language. It's just a loop iteration. You cannot serialize it, suspend it, or resume it after a crash.
There is no durable execution model. Long-running agents die with their process.
5. The Mental Model Doesn't Match the Code
You think in agents, turns, context windows, and memory. You code in lists, strings, loops, and dictionaries. The gap between how you reason about the problem and how you implement it is where bugs live. The abstraction mismatch is structural, not a skill issue.
What Turn Does Differently
Turn closes each of these gaps not with a better library, but by making them language-level constructs.
| Failure Mode | Turn Solution |
|---|---|
| Context overflows silently | context.append() is token-metered by the VM. Overflow triggers auto-eviction with Priority Stack semantics. |
| Inference outputs are untyped | infer Struct { prompt } generates a JSON Schema at compile time and validates the LLM response against it. You get a typed value. |
| State is smeared everywhere | Turn process state is a well-defined tuple: (env, context, memory, mailbox). It is serializable and inspectable. |
| No durable execution model | suspend checkpoints the full VM state to disk. The agent resumes exactly where it stopped — across restarts, crashes, and deployments. |
| Mental model mismatch | turn { } is a first-class language construct. Turns, context, memory, and inference are primitives, not patterns. |
The Core Insight
Turn starts from a simple observation:
An agent is a process, not a loop. It has bounded context, persistent memory, a mailbox, and a lifecycle. If you encode those constraints in the language, the runtime can enforce them. If you encode them as application logic, you're always fighting the model.
The Turn VM is an implementation of this insight. Every primitive in the language — infer, remember, recall, suspend, spawn, send — exists to make the inherent structure of agentic computation explicit, enforced, and composable.
TIP
If you've ever had an agent "forget" something halfway through a long conversation, or silently produce malformed JSON from a model, or fail to resume after a crash — those are the problems Turn was built to eliminate.
What Turn Is Not
Turn is not a general-purpose programming language. It does not replace Python for data science or Rust for systems. It is a domain-specific language for agentic computation — the way SQL is a domain-specific language for relational queries.
Turn programs are small, focused, and declarative about their intelligence. They call tools and infer results. The host—whether a Rust VM, a Docker container, or a cloud orchestrator—provides the execution environment.
Next Step
Now that you understand the problem, see how to install Turn and run your first intelligent program.