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:
- Human-in-the-loop support through interrupts and checkpointing. These let you pause a run, ask a human for input, and then resume the run from the same point. Also see interrupts, part 2.
- Handlers, Effects and
raises— all of these offer safety guarantees that TypeScript doesn't have. - Pattern matching with exhaustiveness checking.
- Guards — set time and cost limits on LLM calls.
- Runtime validation — do runtime validation using your types, no need to write separate Zod schemas.
- Partial function application as a language feature.
- Blocks.
- State isolation.
- A huge, agent-focused standard library — web search, browsers, messaging, and more.
And of course you can easily call TypeScript code from Agency, so you can use the best of both worlds. Agency compiles to TypeScript or JavaScript, so it fits right in with your existing stack.
See Why Agency? for a more detailed discussion.