Requirements
- Node.js 22.19 or newer (
engines.nodeinpackage.json; the built-inhttptool depends onundici@8, which needs it). - TypeScript is optional but recommended - the SDK ships full type definitions.
Install the package
ai (the Vercel AI SDK: ^4.3.19, ^6.0.0 or ^7.0.0) and zod
(^3.25.76 || ^4.0.0) are required peer dependencies. ai 5 is not supported.
Schemas from either zod major work everywhere the SDK takes one
(defineTool({ input }), structured output, MCP tools), including zod 4
schemas from zod/v4 while zod 3.25 is installed and zod 3 schemas from
zod/v3 on zod 4. A defineTool input can also be another
Standard Schema library’s schema if it exposes its
JSON Schema (~standard.jsonSchema); the model needs a JSON Schema, so a
Standard Schema without one is rejected (use zod for those tools). ai 4’s
provider packages declare zod 3 as a peer, so pair zod 4 with ai 6 or 7.
Provider packages
Each real LLM provider is backed by an optional peer dependency, in the major that pairs with yourai major. Install the pair from one row:
For example, on the current
ai major:
ai 6/7 needs zod 4. ollama-ai-provider-v2 (the Ollama package
for ai 6 and 7) declares zod ^4 as a peer. The SDK accepts zod 4,
so install it with zod 4, for example
npm install ai@^7.0.0 ollama-ai-provider-v2@^4.0.0 zod@^4.0.0. With zod 3,
use ai@^4.3.19 with ollama-ai-provider@^1.2.0 (what
lousho init --provider ollama scaffolds).
Peers are loaded on demand: importing @lousho/build-ai-agent (or any of
its sub-entries) never loads a provider package, so you only need to install
the ones you use. Each provider package is loaded the first time that
provider makes a call; if it is missing, that call fails with a
MissingPeerDependencyError that carries the exact command to run, for the
ai major you have installed. With ai 4:
Optional peers
These packages are optional peers too. A project that never uses Docker sandboxing, MCP, OpenTelemetry tracing, the React or Vue bindings,lousho build
or the lousho init questions installs none of them:
Like the provider packages, each is loaded on first use, never at import
time, and a missing one fails that call with a
MissingPeerDependencyError
that names the feature and the exact command, for example:
npm create lousho-agent installs prompts itself, so scaffolding with it
needs nothing extra. lousho doctor lists every optional peer, what it
enables and whether it is installed (a missing dockerode is an error only
when the agent spec uses a sandboxed tool).
undici and yaml stay regular dependencies. yaml parses agent specs,
agent.yaml files and skills, and Node has no built-in YAML parser. undici
is only loaded by the http tool when a request sets validateSSL: false
(a per-request TLS setting that the global fetch cannot express); every
other request uses the runtime’s global fetch.
Entry points share code (ESM and CJS)
The package entries (., ./hooks, ./tools, ./mcp, …) are built with code
splitting: they import shared chunks from dist/, so a class or singleton such
as HookRegistry, SDKError or globalToolRegistry is the same object whichever
entry you import it from, in ESM and in CJS. An ESM import and a CJS require
of the package in one process still load two separate copies (Node’s dual-package
hazard), so a class from one is not === the other. instanceof SDKError and
instanceof HookRegistry are safe across the two copies (they check a
Symbol.for brand); for other classes, use one module format per process.
Installing from a local build
To try an unreleased commit, build and pack the SDK from a checkout of this repository, then install the tarball into your project - the same approachlousho init --sdk-path uses for the projects it generates. This is verified
in CI by npm run pack-smoke, which installs the packed tarball into a fresh
project and loads every entry point, in ESM and CJS:
node bin/lousho.js init ../my-agent --sdk-path ..
npm install github:LinuxDevil/agent-sdk does not work: dist/ is not in
git and the repository has no prepare build step, so the install has no
entry points.
Scaffolding a new project
lousho init creates a ready-to-run project: package.json (ESM, depending
on this SDK by version range), a strict tsconfig.json, src/agent.ts calling
createAgent({ model, instructions }) with an example defineTool() tool, an
offline src/agent.test.ts using mockModel, a .env.example naming your
provider’s key variable, .gitignore and a README. It then installs the
dependencies and runs git init.
create-lousho-agent (packages/create-lousho-agent) is a thin wrapper that
runs lousho init with the same arguments.
The lousho CLI
Installing the package also installs the lousho command: init, doctor,
dev, chat, acp, add, mcp, eval, build and studio. See
CLI for what each one does and its flags. Building needs tsup,
an optional peer (see the table above): npm install --save-dev tsup.
Troubleshooting: lousho doctor
Runnpx lousho doctor right after installing. It prints one line per check
with a status (ok, warn, FAIL), what it found, and, for anything that is
not ok, the command to run or the setting to change:
- Your Node version against the package’s
engines.node. - The required peers
aiandzod: installed, and within the SDK’speerDependenciesrange (resolved from the current directory). - The optional provider packages (
@ai-sdk/openai,@ai-sdk/anthropic, andollama-ai-provideronai4 orollama-ai-provider-v2onai6/7), with thenpm installcommand for each missing one. A provider package that does not pair with the installedai(for exampleai7 with@ai-sdk/openai1.x) is flagged with the version to install instead. - Whether each provider’s API key variable is set. Only the variable name and
set/not setare printed, never the value. It also shows which providercreateAgent()would pick by default with your environment. - With a spec path (
lousho doctor agent.yaml): the spec is validated with field paths for every error, its provider package and key are checked (missing ones become failures), itstoolsmust be built-in tools, and anymcpServerscommand must be resolvable. - Ollama reachability, only when the spec uses Ollama or
OLLAMA_HOSTis set. - Docker availability, a warning only when the spec uses a sandboxed tool.
1 if any check fails and 0 otherwise (warnings do not
fail), so it can gate CI. Add --json for machine-readable output. Colour is
used only when stdout is a terminal and NO_COLOR is unset.
Next: Quick Start.