Docs / built-apps / upsertSiteAgent

upsertSiteAgent

utilitysince 0.2.7not for built apps

Client function: create-or-replace a site agent persona.

import { upsertSiteAgent } from 'flowstack-sdk'

Non-React client function. POST /api/v1/sites/{siteId}/agents. Upsert semantics matching the casino_create_agent MCP tool: posting an existing name replaces that persona wholesale. Use updateSiteAgent when you only want to change some fields.

Signature

upsertSiteAgent(credentials, siteId, agent, config?): Promise<ApiResponse<{ site_id: string; agent: SiteAgent }>>

Parameters

ParamTypeNotesDescription
credentialsFlowstackCredentialsrequiredThe app owner's credentials (owner-scoped JWT).
siteIdstringrequiredThe site/app id to register the persona on.
agentSiteAgentInputrequiredThe full persona: name and system_prompt are required; capabilities, tools, description, route_when, cost_hint and model are optional.
configFlowstackClientConfigClient config (baseUrl, tenantId as needed).

Returns

FieldTypeDescription
Promise<ApiResponse<{ site_id: string; agent: SiteAgent }>>The stored persona.

Examples

Register a persona
const res = await upsertSiteAgent(credentials, siteId, {
  name: 'coach',
  system_prompt: 'You analyze the user’s training log and suggest next week’s plan.',
  capabilities: ['data_access'],
  model: 'claude-sonnet-4-6',
});
WarningOwner/management operation — call it with the app owner's credentials from a builder/dashboard/server context, not from inside the generated app's end-user runtime. builtAppSafe is false.
WarningThis is a replace, not a patch. Re-posting a persona with fields omitted drops those fields — a partial upsert silently wipes capabilities, tools or model. Use updateSiteAgent for field-level edits.

See also

updateSiteAgent · listSiteAgents · SiteAgent · useAgent

Source: src/api/client.ts (Site Ops, P0-156) · Also available in llms-full.txt and registry.json.