Agency vs TypeScript
Because Agency compiles to TypeScript, it has many similarities, but some things are different.
There are some syntactical differences. For example, Agency does not have (an incomplete list):
- A ternary operator (it has the single-line if expression)
for (let i = 0; i < n; i++)loops (it has a while loop and an iterative for loop)- Classes
- Lambdas (it has blocks)
- Conditional types
On the other hand, Agency has a lot of things built into the language that TypeScript doesn't. Most of them exist to make writing agents safe and easy:
- LLM calls as a first-class primitive —
llm(...)is part of the language, with structured output and tools that are just ordinary functions. - Interrupts — a function can pause execution to ask for approval or input before it does something risky, and resume right where it left off.
- Handlers —
handleblocks that decide how to respond to interrupts. These are Agency's core safety infrastructure. - Effects and
raises— the compiler statically tracks which effects (and interrupts) a function can trigger, so you can see and constrain what your code is allowed to do. - Policies — reusable rules for approving or rejecting interrupts.
- Checkpointing and resumability — execution state is snapshotted as the program runs, so you can rewind, retry, or resume a run after an interrupt (even from TypeScript).
- A graph-based execution model built on nodes.
- A built-in
Resulttype and error handling, with flow-sensitive narrowing so the compiler makes you handle failures. - Pattern matching with exhaustiveness checking.
- Guards — constrain and validate what an LLM is allowed to return.
- Runtime validation — assert that values match a schema at runtime, right in the type.
- Partial function application as a language feature.
- Built-in concurrency (
fork) that works correctly with interrupts and checkpoints. - A memory layer and message threads for managing LLM conversation history.
- An agent-focused standard library — web search, browsers, messaging, and more.
- Built-in tooling: a testing framework, observability and tracing, and an interactive debugger you can rewind.