Agents
Saved assistants with their own instructions, model, tools, connectors and knowledge, shared in an organization or a public store with installs and ratings.
The agents block stores assistants that users build and share. An agent
has a slug, instructions, an optional model, the tools and connectors it
may use, the knowledge scopes it searches and starter prompts.
better-supabase add agents # adds tenant and access as well| Table | Holds |
|---|---|
agents | One agent per organization and slug, with its visibility |
agent_installs | Which users installed an agent |
agent_ratings | One rating (1 to 5) and comment per agent and user |
agent_skills | Skill references an agent loads from a provider |
An agent starts private: only its owner sees it. Publishing it makes it
visible to the organization's members (organization) or to every
signed-in user (public). Moderators see and change every agent in the
organization.
| Permission | Lets a member | Default roles |
|---|---|---|
agents.read | see the organization's agents | owner, admin, member |
agents.write | create agents | owner, admin, member |
agents.publish | publish an agent | owner, admin, member |
agents.moderate | change or archive any agent | owner, admin |
Purging an agent needs agents.purge, which falls back to agents.moderate
until you set blocks.agents.permissions.purge; the owner needs it too.
Rename the keys with blocks.agents.permissions.read, .create,
.publish, .moderate and .purge. The maxInstructions option (100,000
characters by default) limits the instructions.
Server
Server code calls the agents instance on db, in the caller's organization. With gen.hooks set, better-supabase gen writes the hooks:
export const { useList: useAgents } = defineDataHooks(
"agents",
(db: AppDb) => db.agents,
);const rows = await db.agents.list({ limit: 50 }).orThrow();"use client";
import { useAgents } from "@/lib/supabase/hooks";
const rows = useAgents({ limit: 50 });const agent = await agents
.create(organizationId, {
slug: "release-notes",
name: "Release notes",
instructions: "Write release notes from the merged pull requests.",
tools: ["search_knowledge"],
knowledgeScopes: [{ scope: "agent" }],
})
.orThrow();
await agents.publish(agent.id, "organization").orThrow();| Method | Does |
|---|---|
create, update | Change the caller's agents |
archive, restore | Hide an agent from the store and lists, or bring it back |
purge | Delete an agent for good (needs agents.purge) |
get, bySlug | Read one agent the caller can see |
list(organizationId, filter) | store (published), mine (owned) or installed |
publish(id, visibility) | Set private, organization or public |
install, rate | Install or uninstall, and rate from 1 to 5 with a comment |
setSkills | Replace the skill references |
An archived agent leaves the store and list (list({ includeArchived: true })
shows it), and update, publish, install and rate refuse it with
AGENT_ARCHIVED until restore. Its installs, ratings and skills stay, and
get still reads it by id, with archivedAt set.
Each agent carries installCount, ratingCount, the average rating,
and for the caller installed and myRating. A slug that is taken in the
organization fails with a conflict error.
Paging agents
agents.page pages agents by keyset (ADR 1077), with facets and count. filters.mode takes store (the default), mine or installed, and includeArchived is a flag filter (["true"] also reads archived agents). visibility filters by a list of values and is also the facet. Sorts are updatedAt, createdAt, name and installCount, and q searches the name and the description. list keeps working and is deprecated.
const mine = await agents
.page({
organizationId,
filters: { mode: ["mine"] },
sort: { by: "name" },
q: "support",
})
.orThrow();A cursor belongs to the sort it came from, so start again from the first page when sort changes. A sort, filter, facet or text the entity does not declare returns an invalid_input error. Block lists describes the options every block list shares.
AI SDK
better-supabase/ai-sdk/agents turns an agent into
a ToolLoopAgent with its tools, approvals and knowledge search.
Your own fields
Columns you add to agents with alter table in your own schema files are fields of the block (details):,
keyed by column name with their SQL type. Pass createAgents a Standard Schema
for them as fields: create, update take them next to the block's own keys and
validate them (a bad value is a validation error), and every agent read return them
parsed. A column the module already uses is refused. See
your own fields.
const client = createAgents({
transport,
fields: z.object({ priority: z.number().int().positive().nullable() }),
});Without the client
db.agents is this client. Code that does not go through bsb.db() builds it with a transport and an organization id:
import { createAgents, rpcTransport } from "better-supabase/blocks/agents";
export const agentsFor = (supabase: SupabaseClient) =>
createAgents({ transport: rpcTransport(supabase) });Calling agents from other agents (A2A)
agentCard builds an A2A 1.0 Agent Card with one skill per public agent, and
agentCardResponse serves it with an ETag. Organization agents appear only
with includeOrganization. Serve it at /.well-known/agent-card.json.
import {
A2A_CARD_PATH,
agentCard,
agentCardResponse,
} from "better-supabase/blocks/agents";
const card = agentCard(await agents.list().orThrow(), {
name: "Acme agents",
description: "The agents of Acme",
version: "1.0.0",
url: "https://acme.example/a2a",
});
export const GET = (request: Request) => agentCardResponse(request, card);createA2AHandler is a JSON-RPC endpoint for SendMessage,
SendStreamingMessage, GetTask and CancelTask. A task is an
ai-chat run and its context is the chat. resolve
returns a chat client that acts as the caller, or nothing for a 401, and start
runs the model for the chat and returns the run id, so your app keeps the AI SDK
and the stream claim. Clients must send A2A-Version: 1.0. A streamed task polls
the run and closes when it ends.
import { createA2AHandler } from "better-supabase/blocks/agents";
export const POST = createA2AHandler({
resolve: async (request) => {
const user = await authenticate(request);
return (
user && {
chat: aiChatFor(user),
organizationId: user.organizationId,
start: ({ chatId, agent }) => runChat(user, chatId, agent),
}
);
},
});Only text parts and the JSON-RPC binding are supported, and push notifications
are not. Pass the agent's slug as params.metadata.agent to pick one skill.
Last updated on
Memory
Core memory files the model edits with Anthropic's memory tool commands, archival facts found by similarity, and recall over a user's earlier messages.
AI schedules
Prompts a user schedules on a cron in their time zone, a scheduler that queues each run, and a run log with the chat each run wrote to.