Common Patterns
Create an agent, assign tools and knowledge bases, then use the streaming endpoint for conversations. Pass session_id to continue multi-turn conversations. For human-in-the-loop workflows, configure hooks and use the approve endpoint when approval_requested events are received.Which key. Agent CRUD, tool, knowledge-base, MCP-server and hook routes require the project’s service role key. The conversation routes under Execution (listing, creating and deleting sessions,
/run, /run/stream, reading a run, and approving a run) also accept a signed-in user’s access token, scoped to that user’s own sessions and runs, with the run-body limits noted below. See Which key for which route.Agent CRUD
GET /api/agents
List all agents.POST /api/agents
Create a new agent.GET /api/agents/
Get an agent by ID.string
required
Agent ID
PATCH /api/agents/
Update an agent’s name, model, system prompt, or settings.string
required
Agent ID
DELETE /api/agents/
Delete an agent.string
required
Agent ID
Tool Assignments
POST /api/agents//tools
Assign a tool to the agent.string
required
Agent ID
GET /api/agents//tools
List tool assignments for the agent.string
required
Agent ID
PATCH /api/agents//tools/
Update a tool assignment’sconfig_override.
string
required
Agent ID
string
required
Assignment ID
object
required
The full
config_override object. Tool-specific shape; for database tools include schemas: { <schema_name>: [<table_name>, ...] }.The body MUST use the key
config_override. Passing config (or any other top-level key) is a silent no-op: the route returns 200 with the unchanged assignment because the handler only inspects config_override.How config_override works per tool type:-
Database tools (
database_query,database_write):config_override.schemas: { <schema>: [<table>, ...] }is the table list, and it’s everything the tools can reach:database_writerejects tables outside it, anddatabase_queryparses each query and rejects any reference to a table outside it. Only plain tables, partitioned tables and views createdWITH (security_invoker = true)may be listed; a view withoutsecurity_invoker, a materialized view or a foreign table answers400. What the tools act as depends on who started the run (see Data tool access and limits). Schemas must be a dict, schema names must match^[a-zA-Z_][a-zA-Z0-9_]{0,63}$, system schemas (ai,auth,storage,pg_*, etc.) are rejected, and each value must be a list of valid table names. -
All other builtin tools (
web_search,web_scrape,http_request,code_execute,storage_read,storage_write): any key inconfig_overridewhose name matches a parameter in the tool’sinput_schemais force-injected into every call’s arguments. Keys not in the schema are silently dropped (no error, no warning). For example, settingconfig_override: { "max_results": 3, "include_domains": ["example.com"] }on aweb_searchassignment locks every search the agent does to 3 results fromexample.com. This constrains a tool without changing what the agent is told about it: the LLM still sees the full schema, but its requested values for those keys are overridden. -
Custom tools:
config_overrideis not used. Custom-tool behavior is controlled via theToolrow’s ownconfig(endpoint, method, headers) at create time. -
MCP tools:
config_overrideis not used. MCP-tool behavior is controlled via theAgentMcpServerrow’sheadersandenabledflag.
DELETE /api/agents//tools/
Remove a tool assignment from the agent.string
required
Agent ID
string
required
Assignment ID
Knowledge Base Assignments
POST /api/agents//knowledge-bases
Link a knowledge base to the agent. Creates a dynamic search tool.string
required
Agent ID
GET /api/agents//knowledge-bases
List knowledge base assignments for the agent.string
required
Agent ID
DELETE /api/agents//knowledge-bases/
Remove a knowledge base from the agent.string
required
Agent ID
string
required
Assignment ID
MCP Servers
POST /api/agents//mcp-servers
Add an MCP server to the agent.string
required
Agent ID
GET /api/agents//mcp-servers
List MCP servers for the agent.string
required
Agent ID
PUT /api/agents//mcp-servers/
Update an MCP server configuration.string
required
Agent ID
string
required
MCP Server ID
DELETE /api/agents//mcp-servers/
Remove an MCP server from the agent.string
required
Agent ID
string
required
MCP Server ID
Hooks
Intercept agent execution at lifecycle boundaries. For the full event/type semantics, the webhook request/response contract, and the streaming caveat, see Hooks & Middleware.POST /api/agents//hooks
Add a hook to the agent.string
required
Agent ID
string
required
When the hook fires. One of:
OnRunStart, PreToolUse, OnDelegation, PostToolUse, PreResponse, OnRunComplete. Stored verbatim and not validated; an unrecognized value is saved but never fires.string
required
What the hook does. One of:
http (POST to a webhook URL), rule (local condition evaluation), approval (human-in-the-loop gate). Also stored verbatim and not validated.object
required
Type-specific configuration (may be
{}). For http: url (required), optional headers, timeout_seconds (default 5). For approval: optional message, timeout (default 300). For rule: a condition string or a rules array.string
Tool name to target. Omit to match all tools (or for non-tool events).
boolean
default:"true"
Whether the hook is active.
integer
default:"0"
Execution order among the agent’s hooks (ascending).
Hooks are immutable; there is no update endpoint. To change a hook,
DELETE it and create a new one.GET /api/agents//hooks
List hooks for the agent.string
required
Agent ID
DELETE /api/agents//hooks/
Remove a hook from the agent.string
required
Agent ID
string
required
Hook ID
Execution
GET /api/agents//sessions
List chat sessions for the agent. With the service role key, you get every session of the agent; with an end user’s access token, only that user’s own sessions.string
required
Agent ID
POST /api/agents//sessions
Create a session for the agent and return its generated id. This is how an end user starts a conversation before the first run; they can also omitsession_id on the first run instead. Accepts the service role key or an end user’s access token.
string
required
Agent ID
string
The user who owns the session (a UUID). Service role key only; an end user who sends it gets
403. With an end user’s token, the session is always owned by that user. With the service role key and no user_id, the session belongs to no end user, so only the service role key can read or continue it.array
Optional seed conversation (for imports and handoffs), as
[{ "role": "user", "content": "..." }, { "role": "assistant", "content": "..." }, ...]: user/assistant pairs, alternating and starting with user, at most 200 messages of at most 20,000 characters each. Seeding with the service role key requires user_id.{ "session_id": "..." }
DELETE /api/agents//sessions/
Delete a session of this agent and its runs. Accepts the service role key or an end user’s access token; an end user can delete only their own sessions. A session that doesn’t exist, belongs to someone else, or belongs to a different agent answers404.
string
required
Agent ID
string
required
Session ID
POST /api/agents//run
Run agent synchronously, returning the full response as JSON. No streaming, no tools, no ReAct loop: a single LLM call against the conversation context. Useful for question-answering. If you need tool use, use/run/stream.
The endpoint accepts the same context-selection surface as /run/stream: you can attach ad-hoc retrieval (knowledge_bases), a pre-built context (context_handler_id), a raw context string (context_override), or by-reference items (context_items). Only one context source may be provided per request; sending more than one returns 400. runtime_knowledge_bases is not accepted here (it requires the tool loop) — sending it returns 400 pointing you to /run/stream.
string
required
Agent ID
Calling with an end user’s access token. This route and
/run/stream accept a signed-in user’s token. Their run uses the knowledge bases configured on the agent: knowledge_bases, runtime_knowledge_bases, context_handler_id and by-reference context_items answer 403. They can continue only an existing session of their own and can’t name a new one. The agent’s data tools act as that user. See Rules for end-user runs.POST /api/agents//run/stream
Run agent with streaming SSE. Supports tools, the ReAct loop, and multi-turn via session_id. SSE event types include start, chunk, tool_call, tool_result, reasoning, reasoning_summary, and complete; the reasoning events surface the model’s internal thought stream when reasoning is enabled. Set reasoning_requested=true to request reasoning output for this run. The streaming endpoint accepts the same context-selection surface as/run above (knowledge_bases / context_handler_id / context_override / context_items, mutually exclusive), plus all the same max_context_tokens, citations_enabled, temperature, and response_format fields. See Streaming for the full SSE event catalog.
Runtime knowledge base references
runtime_knowledge_bases gives the agent a real knowledge_search tool over knowledge bases you name for this one request — agentic search (the model decides when and what to search, and can search repeatedly), without attaching anything to the agent. Use it when a query should be grounded in a document set that isn’t part of the agent’s permanent configuration.
Behavior to know:
- Strictly per-request. Nothing is persisted — follow-up messages in the same session must re-send the field.
- Merges with attached KBs into the run’s single
knowledge_searchtool. An entry naming a KB that is also attached overrides that attachment’s config for the run (e.g. tightentop_kor scopesource_idsfor one query). - Validated before the stream opens. Unknown ids, out-of-range knobs, unknown entry keys (typos like
top_Kare rejected, not ignored), more than 10 entries, or duplicate ids all return400— no billing, no stream. - Combinable with the context fields above (it adds a tool, not injected context). Combined with the preload
knowledge_basesfield, the preload retrieval runs up front, plus eachknowledge_searchcall the model makes — both billed, no dedup. - Streaming only. The non-streaming
/runhas no tool loop and rejects the field with400. - Service role key only. The field can name any KB in the project, so an end user’s run that sends it answers
403; their runs use the knowledge bases configured on the agent. See Rules for end-user runs.
string
required
Agent ID
GET /api/agents/runs/
Fetch a single agent run byrun_id, independent of session context. Returns: id, run_id, session_id, parent_orchestration_run_id, parent_workflow_execution_id, status, input_messages, output_messages, content, usage, retrieved_context, error, started_at, completed_at, steps, events, tool_calls, reasoning_steps, and created_at. The parent fields are null for top-level runs; session_id is null for delegated or workflow-block runs.
Accepts the service role key or an end user’s access token. An end user can read only runs in their own sessions; a run in someone else’s session, or in a session your backend created without a user_id, answers 404 rather than 403, to avoid leaking existence.
string
required
Run ID
POST /api/agents/runs//approve
Approve or deny a pending tool call (human-in-the-loop). Accepts the service role key or an end user’s access token. An end user can approve or reject only paused runs they started themselves. A run your backend started with the service role key has no end-user owner, even in a session owned by that user, so only the service role key can approve it: relay the user’s decision from your backend.string
required
Run ID
Error Responses
Agent routes return{"error": "<message>"}.