Installation
Install the package and peer dependencies needed for agent and chat integrations.
Install the AI package in an app or package that already uses Tulip core.
pnpm add @tulip-systems/ai ai @orpc/serverThe chat UI needs react and @ai-sdk/react, optional peer dependencies: useAssistantChat wraps
the useChat of @ai-sdk/react. Install them, and @tulip-systems/ui for the chat components,
only when the app uses @tulip-systems/ai/chat/client or @tulip-systems/ai/context/client.
pnpm add react @ai-sdk/react @tulip-systems/uiPick what you need
The package has three services, each with its own tables. They share only the tools, so an app sets up what it uses and nothing else:
| The app wants | What to write | Tables | Extra peers |
|---|---|---|---|
| An MCP server | a tool base, tools, Mcp.init | 0 or 1 | @modelcontextprotocol/server |
| Background agents | a tool base, tools, defineAgent, Agents.init | 3 | none |
| An assistant chat | the row above, plus Chat.init and the chat UI | 5 | react, @ai-sdk/react, @tulip-systems/ui |
| Everything | all three services | 6 | all of the above |
Chat needs Agents: a chat turn is a run of an agent. Mcp needs neither, and without a database
it serves the tools with their default settings.
Server-only imports
Tools, agents and the three services are server-only:
import { toolBuilder } from "@tulip-systems/ai/tools/server";
import { Agents, defineAgent } from "@tulip-systems/ai/agents/server";
import { Chat } from "@tulip-systems/ai/chat/server";
import { Mcp } from "@tulip-systems/ai/mcp/server";Keep these imports out of client components.
Database
The services store runs, approvals, agent states, chats and MCP app settings in the app's database, each through its own adapter:
import {
aiAgentsDrizzleAdapter,
aiChatDrizzleAdapter,
aiMcpDrizzleAdapter,
} from "@tulip-systems/ai/drizzle";The Drizzle adapters need drizzle-orm, an optional peer dependency: install it only when you use
@tulip-systems/ai/drizzle.
pnpm add drizzle-orm@tulip-systems/ai/mcp/server needs @modelcontextprotocol/server, also an optional peer: install
it only when the app has an MCP route.
pnpm add @modelcontextprotocol/serverClient imports
The chat hook, the chat components and the page context are client-safe:
"use client";
import { ChatComposer, ChatThread, useAssistantChat } from "@tulip-systems/ai/chat/client";
import { AgentContext, useAgentContext } from "@tulip-systems/ai/context/client";Import types in client code from @tulip-systems/ai/types, not from a server entry:
import type { AgentPolicy, AiChatRequest, AiRunStatus } from "@tulip-systems/ai/types";Model providers
The package does not prescribe a provider. Use any AI SDK-compatible model:
import { createOpenRouter } from "@openrouter/ai-sdk-provider";
export const openrouter = createOpenRouter({
apiKey: process.env.OPENROUTER_API_KEY,
compatibility: "strict",
});Then pass the model to an agent:
model: openrouter("openai/gpt-5-mini")