Concepts
Concepts
How agents, tools, runs, approvals, chat and MCP fit together.
The AI package is built around a few ideas that hold for every way an agent is used: in the in-app chat, from a button, on a domain event, on a schedule, or as tools for an MCP app.
| Idea | What it is |
|---|---|
| Tool | One action in the app, defined once with tool(): what it does, its permission, how it is confirmed. |
| Agent | Who does the work: a model, instructions and tools, made with defineAgent. Defined in code. |
| Principal | Whose permissions a run uses: a user's, or the agent's own grants when it runs as itself. |
| Trigger | What started a run: a chat, an MCP app, a user action, an event or a schedule. |
| Run | One time an agent did a job: its principal, trigger, status, output and error. |
| Approval | A tool call that waits for a person, in the chat or outside it. |
How a run is checked
Every tool call goes through the same checks, whatever started the run:
- The agent is active. Agents are defined in code, but only run once an admin activated them
for the workspace (
Agents). - The principal may do it. For a user, the tool base's
authorizechecks the tool's permission. For an agent running as itself, only its ownidentity.grantscount. - The agent may do it. The workspace's setting for the agent and tool: allowed, asked first, or not allowed. MCP apps are set per user instead.
- It is confirmed. A tool that is asked first waits for an approval; one that needs a passkey only runs with a verified proof.
Where the pieces live
tools: the tool base (toolBuilder) and tool definitions.agents:defineAgent, andAgents: runs, approvals and what agents may do.chat:Chatfor saved chats on the server, and the chat hook and components.mcp:Mcp, serving the tools to MCP apps with per-user settings.drizzle: the database adapters for the services' tables.context: the page the user opened the chat from.types: the types server and client share.
Agents, Chat and Mcp are independent services: Chat needs Agents, Mcp needs neither. See
Services.