Update an agent from your system
Push opening hours and settings from your own records to an agent, then publish it, with a key that has `agents:write`.
Your agent's settings often repeat facts your business already keeps somewhere else. A hotel's property system knows when the front desk is staffed, and a shop's back office knows its holiday hours. Rather than retyping those into the dashboard, your system can send them to the agent whenever they change.
This walkthrough updates a hotel agent's opening hours and what it does out of hours, then makes sure the agent is live. You need an API key with Read & write on Agents, which a Manager sets under What this key can do. See API keys.
1. Find the agent
List your agents and pick the one to change. The paths say assistants, the older name for agents.
curl https://api.trycareflow.com/assistants \
-H "Authorization: Bearer sk_live_xxx"
{
"code": "SUCCESS",
"message": "ok",
"data": {
"assistants": [
{
"_id": "66f1c2a9e4b0f1a2b3c4d5e6",
"name": "Harbourview front desk",
"status": "published",
"timezone": "Europe/London"
}
]
}
}
The response is trimmed here. Each agent comes back with all its settings. Keep the _id in your configuration, since it doesn't change. It's also the long value in the address bar when you open the agent in the dashboard.
2. Read its current settings
Fetch the one agent before you change it, so you know what's there:
curl https://api.trycareflow.com/assistants/66f1c2a9e4b0f1a2b3c4d5e6 \
-H "Authorization: Bearer sk_live_xxx"
The agent is in data.assistant. The fields this walkthrough touches are timezone, activeHours and outOfHoursBehavior.
3. Send the new hours
PATCH /assistants/{id} changes only the fields you send. Everything else stays as it was.
curl -X PATCH https://api.trycareflow.com/assistants/66f1c2a9e4b0f1a2b3c4d5e6 \
-H "Authorization: Bearer sk_live_xxx" \
-H "Content-Type: application/json" \
-d '{
"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" },
"sun": { "start": "09:00", "end": "18:00" }
},
"outOfHoursBehavior": "take_message"
}'
const AGENT_ID = "66f1c2a9e4b0f1a2b3c4d5e6";
const res = await fetch(`https://api.trycareflow.com/assistants/${AGENT_ID}`, {
method: "PATCH",
headers: {
Authorization: `Bearer ${process.env.CAREFLOW_API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
timezone: "Europe/London",
activeHours: hoursFromYourSystem, // { mon: { start, end }, ... }
outOfHoursBehavior: "take_message",
}),
});
const body = await res.json();
if (body.code !== "SUCCESS") throw new Error(body.error || body.message);
const agent = body.data.assistant;
The response is 200 with message set to updated and the agent in data.assistant.
How hours work
Times are 24-hour HH:MM in the agent's timezone, which is a time zone name such as Europe/London or America/New_York. Each day runs from start to end on the same day, so a range can't cross midnight. A day you leave out is closed.
activeHours replaces the whole week, not single days. To change Sunday, send all seven days with Sunday's new times. To drop the schedule and treat the agent as always open, send { "alwaysOpen": true } instead.
Hours don't stop calls or messages from reaching the agent. They tell the agent whether you're open right now and when you next open, and outOfHoursBehavior says what it does when you're closed: take_message, play_hours to tell people when you open, or voicemail on calls.
Other settings you can send
The same request can change the agent's persona and behaviour: name, firstMessage, greeting, signOff, tone, language, the alwaysSay and neverSay lists, and the tools it can use in toolIds. The API Reference lists every field.
A few fields replace a whole group rather than merging into it. voiceConfig replaces the entire voice setup, and systemTools replaces all its switches. Read the agent first, change the values you need, and send the whole group back.
4. Check the result
To see how the agent will read its new hours, fetch the instructions Careflow builds from its settings:
curl https://api.trycareflow.com/assistants/66f1c2a9e4b0f1a2b3c4d5e6/prompt-preview \
-H "Authorization: Bearer sk_live_xxx"
data.prompt is the text the agent works from, with the hours written out day by day.
5. Publish the agent
Changes to a published agent apply straight away, from the next conversation. A new agent, or one that was taken offline, needs publishing before it answers phone calls, the web widget or WhatsApp:
curl -X POST https://api.trycareflow.com/assistants/66f1c2a9e4b0f1a2b3c4d5e6/publish \
-H "Authorization: Bearer sk_live_xxx"
The response is 200 with message set to published and status set to published on the agent. Publishing an agent that's already live is harmless, so a sync job can always end with this call. Use the publish endpoint rather than setting status yourself, so the publish shows in the audit log.
Each change is recorded in Audit logs under API key: and your key's name.
Run it whenever your hours change
Call steps 3 and 5 from wherever your hours are edited: a webhook from your property system, or a nightly job that compares the two. Send the full week each time, and leave a few seconds between agents if you update many at once, because your key has 100 requests a minute for everything it does. See Rate limits.
Where to go next
- Keep your knowledge in sync for policies and FAQs.
- Change agent settings covers the same hours in the dashboard.
- Errors covers
403 insufficient_scopeand the rest.