@talosjs/ai package lets you build agents: a model, a set of system prompts, the tools it can call, and the middleware that observes or shapes each run, all described by a small typed class. The base Chat class owns the agent loop (call the model, run the tools it asks for, feed the results back, repeat until done) and exposes two surfaces: run for a single result and stream for token-by-token events.
Under the hood, agents run on TanStack AI with the OpenRouter adapter, so any provider/model available on OpenRouter is a one-line change.
What the package gives you
You subclassChat, implement four getters, and the base class wires them into the agent loop. Agents, tools, and middleware are all registered with a decorator and resolved from the DI container, so their dependencies inject without extra plumbing. A tool’s input schema is an ArkType assertion, and arguments are validated before your handler runs.
Middleware can observe or transform every stage of a run: config, chunks, tool calls, usage, and the terminal outcome. When you need data instead of prose, pass an output schema and the run returns a validated, typed object. And for common jobs there are ready-made tools for web search, encyclopedia, biomedical, and Linear lookups, so you don’t have to write those yourself.
The building blocks
Installation
Quick example
Describe the agent as a class, register it with thedecorator.chat() decorator, then resolve and run it from the container:
The model identifier is an OpenRouter
provider/model string, e.g. anthropic/claude-sonnet-4.5, openai/gpt-5, or google/gemini-2.5-pro. Switch providers by changing that one line.