Agents
Read your agents and their settings, change them, check them and publish. Paths say `assistants`, the older name for agents. Requires `agents:read` to read and `agents:write` to change. Linking WhatsApp and the agent preview chat stay in the dashboard.
The Agent object
Returned by the agents endpoints.
SUCCESS{ "code": "SUCCESS", "message": "deleted" }
List agents
Requires `agents:read`. Returns every agent in the API key's workspace, in no particular order and without paging. Draft and unpublished agents are included; check `status`. `assistants` is `null`, not an empty list, when the workspace has no agents.
curl https://api.trycareflow.com/assistants \ -H "Authorization: Bearer sk_live_••••"
const Agent = await careflow.agents.list()
{ "code": "SUCCESS", "message": "ok", "data": { "assistants": [ { "_id": "66f1c2a9e4b0f1a2b3c4d5e6", "createdAt": "2026-03-02T09:14:00Z", "updatedAt": "2026-10-06T08:30:12Z", "businessId": "66f1c2a9e4b0f1a2b3c4d5a1", "name": "Harbourview front desk", "status": "published", "firstMessage": "Thanks for calling Harbourview Hotel, how can I help you today?", "toolIds": [ "66f1c2a9e4b0f1a2b3c4d5f0" ], "whatsApp": { "phoneNumberId": "", "verifyToken": "" }, "pipelineMode": "modular", "voiceConfig": { "sttProvider": "deepgram", "llmProvider": "openrouter", "voiceKey": "charlotte", "temperature": 0.6, "speed": 1 }, "promptMode": "structured", "compiledPrompt": "You are the front desk assistant for Harbourview Hotel...", "role": "service", "language": "en-GB", "tone": "warm_friendly", "greeting": "Good morning, Harbourview Hotel.", "signOff": "Enjoy your stay.", "alwaysSay": [ "Breakfast is served from 7am to 10:30am." ], "neverSay": [ "Room rates for other hotels" ], "useFillers": true, "interruptionHandling": "finish_sentence", "speakingPace": "normal", "timezone": "Europe/London", "activeHours": { "mon": { "start": "07:00", "end": "22:00" }, "tue": { "start": "07:00", "end": "22:00" }, "wed": { "start": "07:00", "end": "22:00" }, "thu": { "start": "07:00", "end": "22:00" }, "fri": { "start": "07:00", "end": "23:00" }, "sat": { "start": "08:00", "end": "23:00" } }, "outOfHoursBehavior": "take_message", "handoffs": [ { "routineId": "66f1c2a9e4b0f1a2b3c4d5b7", "triggers": [ "speak to a manager" ] } ], "recogniseReturning": true, "systemTools": { "knowledgeBase": true, "webSearch": true, "end": true } } ] } }
{ "code": "ERROR", "message": "invalid businessId in token", "error": "the parse error" }
{ "code": "ERROR", "message": "unauthorized", "error": "invalid or revoked API key" }
{ "code": "ERROR", "message": "insufficient_scope", "error": "this API key needs the knowledge:write scope" }
{ "code": "ERROR", "message": "too_many_requests", "error": "You have exceeded the rate limit for api. Please try again in 12s." }
{ "code": "ERROR", "message": "failed", "error": "the database error" }
{ "code": "ERROR", "message": "service_unavailable", "error": "key lookup failed" }
Create an agent
Requires `agents:write`. Creates an agent in the API key's workspace. The new agent is `inactive`: it doesn't answer calls, the web widget or WhatsApp until you publish it. In `structured` mode (the default) send `role`, `tone` and `language`; the agent's instructions are built from them. If you don't send `voiceConfig`, the agent gets the platform voice defaults and a recommended voice. If you do, it replaces those defaults, so include `temperature` and `speed` if you care about them.
structuredadvancedsalesserviceecommerceschedulingcustomcurl https://api.trycareflow.com/assistants \ -H "Authorization: Bearer sk_live_••••" \ -d name=Harbourview front desk \ -d firstMessage=Thanks for calling Harbourview Hotel, how can I help you today? \ -d promptMode=structured \ -d systemPrompt=value
const Agent = await careflow.agents.create({ name: 'Harbourview front desk', firstMessage: 'Thanks for calling Harbourview Hotel, how can I help you today?', promptMode: 'structured', systemPrompt: 'value', })
{ "code": "SUCCESS", "message": "created", "data": { "assistant": { "_id": "66f1c2a9e4b0f1a2b3c4d5e6", "createdAt": "2026-03-02T09:14:00Z", "updatedAt": "2026-03-02T09:14:00Z", "businessId": "66f1c2a9e4b0f1a2b3c4d5a1", "name": "Harbourview front desk", "status": "inactive", "firstMessage": "Thanks for calling Harbourview Hotel, how can I help you today?", "toolIds": [ "66f1c2a9e4b0f1a2b3c4d5f0" ], "whatsApp": { "phoneNumberId": "", "verifyToken": "" }, "pipelineMode": "modular", "voiceConfig": { "sttProvider": "deepgram", "llmProvider": "openrouter", "voiceKey": "charlotte", "temperature": 0.6, "speed": 1 }, "promptMode": "structured", "compiledPrompt": "You are the front desk assistant for Harbourview Hotel...", "role": "service", "language": "en-GB", "tone": "warm_friendly", "greeting": "Good morning, Harbourview Hotel.", "signOff": "Enjoy your stay.", "alwaysSay": [ "Breakfast is served from 7am to 10:30am." ], "neverSay": [ "Room rates for other hotels" ], "useFillers": true, "interruptionHandling": "finish_sentence", "speakingPace": "normal", "timezone": "Europe/London", "activeHours": { "mon": { "start": "07:00", "end": "22:00" }, "tue": { "start": "07:00", "end": "22:00" }, "wed": { "start": "07:00", "end": "22:00" }, "thu": { "start": "07:00", "end": "22:00" }, "fri": { "start": "07:00", "end": "23:00" }, "sat": { "start": "08:00", "end": "23:00" } }, "outOfHoursBehavior": "take_message", "handoffs": [ { "routineId": "66f1c2a9e4b0f1a2b3c4d5b7", "triggers": [ "speak to a manager" ] } ], "recogniseReturning": true, "systemTools": { "knowledgeBase": true, "webSearch": true, "end": true } } } }
{ "code": "ERROR", "message": "validation failed", "error": "invalid_payload (with `details`)" }
{ "code": "ERROR", "message": "unauthorized", "error": "invalid or revoked API key" }
{ "code": "ERROR", "message": "insufficient_scope", "error": "this API key needs the knowledge:write scope" }
{ "code": "ERROR", "message": "too_many_requests", "error": "You have exceeded the rate limit for api. Please try again in 12s." }
{ "code": "ERROR", "message": "failed to create", "error": "the database error" }
{ "code": "ERROR", "message": "service_unavailable", "error": "key lookup failed" }
Get an agent
Requires `agents:read`. Returns one agent from the API key's workspace.
curl https://api.trycareflow.com/assistants/value \ -H "Authorization: Bearer sk_live_••••"
const Agent = await careflow.agents.retrieve('value')
{ "code": "SUCCESS", "message": "ok", "data": { "assistant": { "_id": "66f1c2a9e4b0f1a2b3c4d5e6", "createdAt": "2026-03-02T09:14:00Z", "updatedAt": "2026-10-06T08:30:12Z", "businessId": "66f1c2a9e4b0f1a2b3c4d5a1", "name": "Harbourview front desk", "status": "published", "firstMessage": "Thanks for calling Harbourview Hotel, how can I help you today?", "toolIds": [ "66f1c2a9e4b0f1a2b3c4d5f0" ], "whatsApp": { "phoneNumberId": "", "verifyToken": "" }, "pipelineMode": "modular", "voiceConfig": { "sttProvider": "deepgram", "llmProvider": "openrouter", "voiceKey": "charlotte", "temperature": 0.6, "speed": 1 }, "promptMode": "structured", "compiledPrompt": "You are the front desk assistant for Harbourview Hotel...", "role": "service", "language": "en-GB", "tone": "warm_friendly", "greeting": "Good morning, Harbourview Hotel.", "signOff": "Enjoy your stay.", "alwaysSay": [ "Breakfast is served from 7am to 10:30am." ], "neverSay": [ "Room rates for other hotels" ], "useFillers": true, "interruptionHandling": "finish_sentence", "speakingPace": "normal", "timezone": "Europe/London", "activeHours": { "mon": { "start": "07:00", "end": "22:00" }, "tue": { "start": "07:00", "end": "22:00" }, "wed": { "start": "07:00", "end": "22:00" }, "thu": { "start": "07:00", "end": "22:00" }, "fri": { "start": "07:00", "end": "23:00" }, "sat": { "start": "08:00", "end": "23:00" } }, "outOfHoursBehavior": "take_message", "handoffs": [ { "routineId": "66f1c2a9e4b0f1a2b3c4d5b7", "triggers": [ "speak to a manager" ] } ], "recogniseReturning": true, "systemTools": { "knowledgeBase": true, "webSearch": true, "end": true } } } }
{ "code": "ERROR", "message": "invalid id", "error": "the parse error" }
{ "code": "ERROR", "message": "unauthorized", "error": "invalid or revoked API key" }
{ "code": "ERROR", "message": "insufficient_scope", "error": "this API key needs the knowledge:write scope" }
{ "code": "ERROR", "message": "not found", "error": "mongo: no documents in result" }
{ "code": "ERROR", "message": "too_many_requests", "error": "You have exceeded the rate limit for api. Please try again in 12s." }
{ "code": "ERROR", "message": "service_unavailable", "error": "key lookup failed" }
Update an agent
Requires `agents:write`. Changes the fields you send and leaves the rest alone. Objects such as `activeHours`, `voiceConfig` and `systemTools` are replaced as a whole, so send the complete object. To make the agent always open, send `"alwaysOpen": true`. Changes apply straight away, including on a published agent: there's no separate draft, and you don't need to publish again. You can't clear a value here: an empty string, `false` or an empty list is ignored when saving, even though the response shows it. Unlike create, this endpoint doesn't check `firstMessage` length or `role`. The response is the agent as the handler built it, which can differ from what was stored for those ignored values. Get the agent again if you need to be sure.
structuredadvancedsalesserviceecommerceschedulingcustominactivedisabledcurl -X PATCH https://api.trycareflow.com/assistants/value \ -H "Authorization: Bearer sk_live_••••" \ -d name=Harbourview front desk \ -d firstMessage=Thanks for calling Harbourview Hotel, how can I help you today? \ -d promptMode=structured \ -d systemPrompt=value
const Agent = await careflow.agents.update({ name: 'Harbourview front desk', firstMessage: 'Thanks for calling Harbourview Hotel, how can I help you today?', promptMode: 'structured', systemPrompt: 'value', })
{ "code": "SUCCESS", "message": "updated", "data": { "assistant": { "_id": "66f1c2a9e4b0f1a2b3c4d5e6", "createdAt": "2026-03-02T09:14:00Z", "updatedAt": "2026-10-06T08:30:12Z", "businessId": "66f1c2a9e4b0f1a2b3c4d5a1", "name": "Harbourview front desk", "status": "published", "firstMessage": "Thanks for calling Harbourview Hotel, how can I help you today?", "toolIds": [ "66f1c2a9e4b0f1a2b3c4d5f0" ], "whatsApp": { "phoneNumberId": "", "verifyToken": "" }, "pipelineMode": "modular", "voiceConfig": { "sttProvider": "deepgram", "llmProvider": "openrouter", "voiceKey": "charlotte", "temperature": 0.6, "speed": 1 }, "promptMode": "structured", "compiledPrompt": "You are the front desk assistant for Harbourview Hotel...", "role": "service", "language": "en-GB", "tone": "warm_friendly", "greeting": "Good morning, Harbourview Hotel.", "signOff": "Enjoy your stay.", "alwaysSay": [ "Breakfast is served from 7am to 10:30am." ], "neverSay": [ "Room rates for other hotels" ], "useFillers": true, "interruptionHandling": "finish_sentence", "speakingPace": "normal", "timezone": "Europe/London", "activeHours": { "mon": { "start": "07:00", "end": "22:00" }, "tue": { "start": "07:00", "end": "22:00" }, "wed": { "start": "07:00", "end": "22:00" }, "thu": { "start": "07:00", "end": "22:00" }, "fri": { "start": "07:00", "end": "23:00" }, "sat": { "start": "08:00", "end": "23:00" } }, "outOfHoursBehavior": "take_message", "handoffs": [ { "routineId": "66f1c2a9e4b0f1a2b3c4d5b7", "triggers": [ "speak to a manager" ] } ], "recogniseReturning": true, "systemTools": { "knowledgeBase": true, "webSearch": true, "end": true } } } }
{ "code": "ERROR", "message": "invalid id", "error": "the parse error" }
{ "code": "ERROR", "message": "unauthorized", "error": "invalid or revoked API key" }
{ "code": "ERROR", "message": "insufficient_scope", "error": "this API key needs the knowledge:write scope" }
{ "code": "ERROR", "message": "not found", "error": "mongo: no documents in result" }
{ "code": "ERROR", "message": "too_many_requests", "error": "You have exceeded the rate limit for api. Please try again in 12s." }
{ "code": "ERROR", "message": "failed to update", "error": "the database error" }
{ "code": "ERROR", "message": "service_unavailable", "error": "key lookup failed" }
Delete an agent
Requires `agents:write`. Deletes the agent for good. First, every phone number pointing at it is unlinked (numbers stay in your workspace, unassigned, and Twilio numbers have their call webhook cleared), and its web widget and other channel connections are removed. Its WhatsApp link goes with it. If a number can't be unlinked at the carrier, nothing is deleted and you get `502`; try again. Conversations already recorded stay in the Inbox. The success response has no `data`.
curl -X DELETE https://api.trycareflow.com/assistants/value \ -H "Authorization: Bearer sk_live_••••"
const Agent = await careflow.agents.del('value')
{ "code": "SUCCESS", "message": "deleted" }
{ "code": "ERROR", "message": "invalid id", "error": "the parse error" }
{ "code": "ERROR", "message": "unauthorized", "error": "invalid or revoked API key" }
{ "code": "ERROR", "message": "insufficient_scope", "error": "this API key needs the knowledge:write scope" }
{ "code": "ERROR", "message": "not found", "error": "mongo: no documents in result" }
{ "code": "ERROR", "message": "too_many_requests", "error": "You have exceeded the rate limit for api. Please try again in 12s." }
{ "code": "ERROR", "message": "failed to remove channels", "error": "the database error" }
{ "code": "ERROR", "message": "failed to release phone numbers", "error": "unlink +442071234567: <carrier error>" }
{ "code": "ERROR", "message": "service_unavailable", "error": "key lookup failed" }
Preview an agent's instructions
Requires `agents:read`. Returns the full instructions the agent would get if a conversation started now, built from its current settings, including whether it's open right now. Nothing is saved. In `advanced` mode this is `behaviorPrompt`, or `systemPrompt` when that's empty.
curl https://api.trycareflow.com/assistants/value/prompt-preview \ -H "Authorization: Bearer sk_live_••••"
const Agent = await careflow.agents.retrieve('value')
{ "code": "SUCCESS", "message": "ok", "data": { "prompt": "You are the front desk assistant for Harbourview Hotel. Speak in a warm, friendly, and conversational tone... Monday: 07:00 - 22:00 ... Sunday: Closed", "promptMode": "structured" } }
{ "code": "ERROR", "message": "invalid id", "error": "the parse error" }
{ "code": "ERROR", "message": "unauthorized", "error": "invalid or revoked API key" }
{ "code": "ERROR", "message": "insufficient_scope", "error": "this API key needs the knowledge:write scope" }
{ "code": "ERROR", "message": "not found", "error": "mongo: no documents in result" }
{ "code": "ERROR", "message": "too_many_requests", "error": "You have exceeded the rate limit for api. Please try again in 12s." }
{ "code": "ERROR", "message": "service_unavailable", "error": "key lookup failed" }
Publish an agent
Requires `agents:write`. Sets the agent's status to `published`, so it answers on every channel linked to it: phone numbers, the web widget and WhatsApp. There are no checks: an agent with no phone number or channel still publishes. Call the validate endpoint first if you want advice on its tools. Publishing an agent that's already published is safe and changes nothing else. Settings changes made with update are live as soon as they're saved, so you only need to publish to take an agent live. There's no unpublish endpoint for API keys; use update with `status` if you must. The first publish sends a "published" notification.
curl https://api.trycareflow.com/assistants/value/publish \ -H "Authorization: Bearer sk_live_••••"
const Agent = await careflow.agents.create('value')
{ "code": "SUCCESS", "message": "published", "data": { "assistant": { "_id": "66f1c2a9e4b0f1a2b3c4d5e6", "createdAt": "2026-03-02T09:14:00Z", "updatedAt": "2026-10-06T08:30:12Z", "businessId": "66f1c2a9e4b0f1a2b3c4d5a1", "name": "Harbourview front desk", "status": "published", "firstMessage": "Thanks for calling Harbourview Hotel, how can I help you today?", "toolIds": [ "66f1c2a9e4b0f1a2b3c4d5f0" ], "whatsApp": { "phoneNumberId": "", "verifyToken": "" }, "pipelineMode": "modular", "voiceConfig": { "sttProvider": "deepgram", "llmProvider": "openrouter", "voiceKey": "charlotte", "temperature": 0.6, "speed": 1 }, "promptMode": "structured", "compiledPrompt": "You are the front desk assistant for Harbourview Hotel...", "role": "service", "language": "en-GB", "tone": "warm_friendly", "greeting": "Good morning, Harbourview Hotel.", "signOff": "Enjoy your stay.", "alwaysSay": [ "Breakfast is served from 7am to 10:30am." ], "neverSay": [ "Room rates for other hotels" ], "useFillers": true, "interruptionHandling": "finish_sentence", "speakingPace": "normal", "timezone": "Europe/London", "activeHours": { "mon": { "start": "07:00", "end": "22:00" }, "tue": { "start": "07:00", "end": "22:00" }, "wed": { "start": "07:00", "end": "22:00" }, "thu": { "start": "07:00", "end": "22:00" }, "fri": { "start": "07:00", "end": "23:00" }, "sat": { "start": "08:00", "end": "23:00" } }, "outOfHoursBehavior": "take_message", "handoffs": [ { "routineId": "66f1c2a9e4b0f1a2b3c4d5b7", "triggers": [ "speak to a manager" ] } ], "recogniseReturning": true, "systemTools": { "knowledgeBase": true, "webSearch": true, "end": true } } } }
{ "code": "ERROR", "message": "invalid id", "error": "the parse error" }
{ "code": "ERROR", "message": "unauthorized", "error": "invalid or revoked API key" }
{ "code": "ERROR", "message": "insufficient_scope", "error": "this API key needs the knowledge:write scope" }
{ "code": "ERROR", "message": "not found", "error": "mongo: no documents in result" }
{ "code": "ERROR", "message": "too_many_requests", "error": "You have exceeded the rate limit for api. Please try again in 12s." }
{ "code": "ERROR", "message": "failed to publish", "error": "the database error" }
{ "code": "ERROR", "message": "service_unavailable", "error": "key lookup failed" }
Check an agent's tools
Requires `agents:write`. Looks at every tool the agent will be offered (its live tools, its workflows and the workspace's connected integrations) and reports problems that make agents behave badly: tools with no description, tools with confusingly similar names or descriptions, tools that look like steps of one process, and tools with identical parameters. It only reports. Nothing is changed, and publishing isn't blocked even when `valid` is `false`.
curl https://api.trycareflow.com/assistants/value/validate \ -H "Authorization: Bearer sk_live_••••"
const Agent = await careflow.agents.create('value')
{ "code": "SUCCESS", "message": "validated", "data": { "report": { "valid": true, "issues": [ { "severity": "warning", "message": "Tools 'check_booking' and 'check_booking_status' have similar names. The AI agent may confuse them.", "suggestion": "Consider merging these into a single workflow if they represent steps of one process, or make the names more distinct.", "affectedTools": [ "check_booking", "check_booking_status" ] } ] } } }
{ "code": "ERROR", "message": "invalid assistant ID", "error": "the parse error" }
{ "code": "ERROR", "message": "unauthorized", "error": "invalid or revoked API key" }
{ "code": "ERROR", "message": "insufficient_scope", "error": "this API key needs the knowledge:write scope" }
{ "code": "ERROR", "message": "assistant not found", "error": "mongo: no documents in result" }
{ "code": "ERROR", "message": "too_many_requests", "error": "You have exceeded the rate limit for api. Please try again in 12s." }
{ "code": "ERROR", "message": "failed to load tools", "error": "the error" }
{ "code": "ERROR", "message": "service_unavailable", "error": "key lookup failed" }