Agents
ToolLoopAgent, built-in tools, and tRPC-as-tools for the in-app chat agent.
The in-app chat uses a ToolLoopAgent from the Vercel AI SDK — not the MCP server. Agents can call built-in demo tools and, on the web chat route, authenticated tRPC procedures exposed as tools.
Core agent (@zts/ai)
createZtsAgent() in packages/ai/src/create-zts-agent.ts wraps ToolLoopAgent:
| Option | Default |
|---|---|
| Agent id | "zts-assistant" |
| Stop condition | stepCountIs(20) — up to 20 tool-loop steps |
| Instructions | Help users build and ship with Zero To Shipped |
Default instructions encourage concise answers and tool use when accuracy requires it.
Built-in tools
createZtsAgentTools() in packages/ai/src/tools/index.ts:
| Tool | Purpose |
|---|---|
getCurrentTime | Current ISO timestamp + server timezone |
getUserContext | Signed-in user name/email + configured provider names |
calculate | Safe evaluation of basic arithmetic expressions |
These are demos — replace or extend them for your product.
Adding a built-in tool
Pass custom tools via createZtsAgent({ tools: { ...createZtsAgentTools(ctx), ...myTools } }).
tRPC-as-tools (web chat only)
apps/web/src/server/trpc-agent-tools.ts uses trpc-to-mcp's extractToolsFromProcedures(appRouter) to turn authenticated tRPC procedures into agent tools.
In apps/web/src/app/api/chat/route.ts, tools are merged:
This lets the in-app agent call the same business logic as the web app (e.g. update preferences, fetch profile) without duplicating HTTP clients.
Scope: These are session-scoped tRPC tools — different from MCP tools, which use API keys and only expose apiExposure() procedures.
Language model + intelligence
Before creating the agent, the chat route:
resolveUserAiProvider— pick provider + key from preferencescreateLanguageModel—@ai-sdk/*model instanceresolveIntelligenceForModel— clamp thinking level to what the model supports
See Providers for catalog and intelligence details.
Customizing agent behavior
Instructions
Override default system prompt:
Or edit ZTS_AGENT_INSTRUCTIONS in create-zts-agent.ts for a global default.
Step limit
Adjust stopWhen in create-zts-agent.ts if 20 steps is too many or too few for your tool graph.
Separate agents
For multiple agent personas (support vs. codegen), create factory functions that return different ToolLoopAgent instances with distinct instructions and tools sets, then route to them from separate API routes.
MCP tools vs in-app agent tools
MCP (/api/mcp) | In-app ToolLoopAgent | |
|---|---|---|
| Host | Cursor, external agents | Web chat UI |
| Auth | API key / MCP OAuth | Session cookie |
| Tool source | apiExposure() procedures only | Built-in tools + optional full tRPC router |
| Transport | MCP protocol | POST /api/chat streaming |
| Docs | MCP | This page |
Testing
apps/web/src/app/api/chat/route.test.ts covers the chat route. Vitest aliases @zts/ai to packages/ai/src/index.ts via apps/web/vitest.config.ts.