Tulip Logo IconTulip
Concepts

Agents

Define agents in code, let them run for a user or as themselves, and manage them per workspace.

An agent says who does the work and what it can do: a model, instructions and tools. Agents are defined in code with defineAgent() and given to Agents. When an agent runs is up to the caller: a chat message, a button, an event or a schedule (see Runs).

Create an agent

import "server-cli-only";

import { defineAgent } from "@tulip-systems/ai/agents/server";
import { capabilities } from "../capabilities";
import { webSearchTool } from "../tools/web_search/tool.server";
import { instructions } from "./instructions";
import { openrouter } from "./providers";

export const assistantAgent = defineAgent({
  name: "assistant",
  title: "Assistent",
  model: openrouter("openai/gpt-5-mini"),
  instructions,
  tools: { ...capabilities, web_search: webSearchTool },
});

It takes the ToolLoopAgent settings (model, instructions and the rest), except prepareCall, toolApproval and stopWhen, which it sets itself, plus:

OptionWhat it does
nameIdentifies the agent: runs, settings and approvals refer to it. It is unique in the app.
titleWhat users see, for example in the agents list and on approval pages.
toolsTulip tool definitions and plain AI SDK tools, by the name the model calls them.
outputAn AI SDK Output, such as Output.object({ schema }), for a typed result instead of text.
identityLets the agent run as itself, with its own grants and approvers. Without it, it only runs for a user.
maxStepsThe most steps (model calls) one run takes. Defaults to 10.

The agent forwards the run's tool call to every tool, asks for approval by each tool's confirmation, adds the page the user opened the chat from to the instructions, and stops after maxSteps.

For a user, or as itself

A run uses the permissions of its principal:

  • For a user. The agent acts for the user who clicked, chatted or caused the event, and may do what that user may do. This is the default, and the right choice for anything a user starts.
  • As itself. For work nobody started, such as an event listener or a schedule, give the agent an identity. Then it has only its own grants, like a role, and the user's permissions play no part.
export const triageAgent = defineAgent({
  name: "task_triage",
  title: "Taaktriage",
  model,
  instructions,
  tools: { get_project_context: getProjectContext, estimate_task: estimateTask },
  identity: {
    grants: { project: ["view"], task: ["view", "update"] },
    // Who decides on its tool calls that wait for an approval.
    approvers: async (run) => (await listPlanners()).map((user) => user.id),
  },
});

An agent running as itself that calls a tool needing approval asks its approvers. Without approvers that run fails instead of waiting (see Approvals).

Register and activate

Give every agent to Agents.init({ agents }). Runs are started by an agent's name:

export const agents = Agents.init({
  agents: [assistantAgent, triageAgent],
  database: aiAgentsDrizzleAdapter({ db, schema: { aiAgentStates, aiRuns, aiApprovals } }),
});

A registered agent does not run yet. An admin activates it for the workspace, and can turn it off again. The configuration stays in code; the database only stores the state:

StatusMeaning
newIn code, never activated. It does not run.
activeActivated. It runs.
offTurned off by an admin. It does not run.
removedIt has a state, but is no longer in code.

A turned off or new agent starts no runs (agents.run and agents.start return null), its queued runs fail, and its chat refuses messages. Deploying an agent and putting it to work are two decisions.

What it may do per tool

Once active, an admin sets per tool what the agent may do, for the whole workspace:

Tool's confirmationChoicesDefault
noneAllow, Don't allowAllow
approvalAllow, Ask first, Don't allowAsk first
passkeyAsk first, Don't allowAsk first

A tool can be made stricter than its confirmation in code, never looser: one that needs a passkey is never allowed without asking. The settings apply to every run of the agent, in the chat and outside it.

await agents.setActive("task_triage", true);
await agents.setPolicy("task_triage", "estimate_task", "allow");

const agent = await agents.get("task_triage");
// { name, title, grants, status, lastRunAt, tools: [{ name, title, kind, confirmation, policy, options }] }

See Manage agents for the admin page.

Instructions

Keep the instructions in an instructions.ts next to the agent and export them as a string:

  • role and scope
  • operating principles
  • the tools and when to use them
  • mutation safety rules
  • clarification rules
  • response style

One agent or several

Start with one agent and give it the tools it needs. Create another agent only when the job needs something a shared agent cannot give it:

  • its own permissions: an agent that runs as itself on events gets only the grants of that job;
  • its own trigger and control: an admin can turn triage off without touching the chat;
  • its own output or model: typed JSON, or a cheap model for a simple rewrite;
  • focus: a short prompt with a few tools when one agent's prompt grows too large.

On this page