Workflows
Steps the agent walks through, and intents that interrupt them from anywhere in the call.
A workflow is a graph the agent walks while it talks: named steps, each with a line to say and the branches leading out of it. It replaces the flat system prompt as the source of truth for what happens next.
The difference shows up under pressure. A flat prompt asks a model to remember its agenda while improvising. A workflow makes the agenda structural: the same call runs the same way twice, and every branch is inspectable before you dial.
Steps
Each step carries a say line delivered verbatim and an instruction for what to do with the answer. Most also declare slots — small typed values the model extracts from the caller's reply.
{
"id": "confirm_time",
"kind": "message",
"say": "Does Thursday at 2pm still work for you?",
"slots": [
{ "key": "keeps_slot", "type": "enum", "enum": ["yes", "no", "question"] }
]
}A say line is delivered verbatim, so no instruction can make it come out in another language. A step that has to speak in more than one carries sayByLanguage and instructionByLanguage alongside the base text — see Multilingual agents.
Slots are what the step routes on. An edge is a condition plus a destination:
{ "id": "e_ask", "from": "confirm_time", "to": "answer_question",
"condition": { "type": "expression", "expr": "keeps_slot == 'question'" } }Each step also has one unconditional edge — where the call goes when nothing more specific matches.
Branching on call direction
Three call-context values are in the state store before the first turn, with no slot to declare: direction (inbound, outbound or scheduled_callback), caller_number and dialed_number. They carry the same values as the {{system.direction}}, {{system.caller_number}} and {{system.dialed_number}} prompt variables, and {{caller_number}} renders in a step's say line too. On a browser session with no phone leg they are absent, so !caller_number is true and any comparison against them is false.
An expression edge out of the entry step chooses the opening path. One agent can run a scripted outbound call and, when the same person calls back after a missed call, open by asking for a callback code instead:
{ "id": "e_callback", "from": "entry", "to": "ask_callback_code",
"condition": { "type": "expression", "expr": "direction == 'inbound'" } }The entry step's unconditional edge remains the outbound path. A slot or variable you declare under one of these names takes precedence over the builtin.
Branching on the time of the call
The clock is in the state store too. The platform reads it once, when the call starts, in the agent's timezone (UTC when the agent has none).
| Key | Value | Example at 5:30 PM on a Friday |
|---|---|---|
local_weekday | monday to sunday | friday |
local_hour | 0 to 23 | 17 |
local_hhmm | hour × 100 + minute | 1730 |
Route business hours with expression edges, not by asking the model what time it is. An expression holds one comparison, so list one edge per closed condition and let the unconditional edge be the open path. This step is closed on weekends, before 9:00 AM and from 5:00 PM:
[
{ "id": "e_sat", "from": "wants_callback", "to": "callback_closed",
"condition": { "type": "expression", "expr": "local_weekday == 'saturday'" } },
{ "id": "e_sun", "from": "wants_callback", "to": "callback_closed",
"condition": { "type": "expression", "expr": "local_weekday == 'sunday'" } },
{ "id": "e_early", "from": "wants_callback", "to": "callback_closed",
"condition": { "type": "expression", "expr": "local_hhmm < 900" } },
{ "id": "e_late", "from": "wants_callback", "to": "callback_closed",
"condition": { "type": "expression", "expr": "local_hhmm >= 1700" } },
{ "id": "e_open", "from": "wants_callback", "to": "callback_open",
"condition": { "type": "unconditional" } }
]Give callback_open and callback_closed each a fixed say line, and the caller hears the right one every time. The values do not change during the call: a call that starts at 4:58 PM stays open until it ends. A slot or variable you declare under one of these names takes precedence, which lets a test call pin the clock.
Globals: intents from any step
A normal edge belongs to one step. A global edge has no from, so it is evaluated from every step in the workflow. Declare an intent once and it is live for the whole call.
{
"globalEdges": [
{ "id": "g_cancel", "to": "cancel_booking",
"condition": { "type": "llm", "when": "asks to cancel the appointment" } },
{ "id": "g_human", "to": "transfer",
"condition": { "type": "llm", "when": "asks to speak to a person" } }
]
}Without one, a caller can only cancel at the step that happens to ask about it:
agent Please arrive ten minutes early and bring your insurance card…
caller Actually, I need to cancel it.
agent Parking is behind the building, and the entrance is on Oak Street… ← kept reading its script
caller I need to cancel the appointment.
agent Does Thursday at 2pm still work for you? ← finally the step that asksWith g_cancel declared, the same sentence lands wherever it is said:
agent Please arrive ten minutes early and bring your insurance card…
caller Actually, I need to cancel it.
agent No problem — Thursday at 2pm is cancelled. You'll get a text confirming it.A workflow may declare up to 8 global edges.
Which wins, the step or the global
The step's own edges are resolved first, but only on a turn that actually filled one of its slots. If the caller answered the step's question, the step keeps the turn. If they said something else, a matching global takes it.
That ordering matters in both directions. Globals evaluated last are unreachable mid-script. Globals evaluated first steal turns the step understood perfectly well — a caller answering "no" to do you have a referral? is not cancelling the appointment.
An expression edge pointing at the same step your unconditional edge already points at changes no routing, but it does claim the turn — which silently suppresses every global from that step. Delete it; the default already goes there.
Excluding a step
Where a global would misread a step's own answers, name that step in exceptNodeIds and the global stops firing there.
{ "id": "g_cancel", "to": "cancel_booking",
"condition": { "type": "llm", "when": "asks to cancel the appointment" },
"exceptNodeIds": ["answer_question", "cancel_booking"] }Branching on what a tool returned
A tool step can branch on the values its call returned, not only on whether it succeeded. After a successful call, the step's expression edges are checked first, in edge order, against the values its outputBindings captured. The first match wins. If none match, the tool_result success edge runs.
A question fetch that answers {"question": ""} when the list runs out can go straight to the wrap-up:
{ "id": "e_no_more", "from": "get_q", "to": "submit",
"condition": { "type": "expression", "expr": "question == ''" } }A binding the call did not return counts as missing for this check, so !question also matches a response with no question at all. Failure still takes the failure edge. Your tool doesn't need to throw to end the list.
Lines the caller must hear
A caller can talk over a step's say line, or the line can fail to reach them. The agent re-reads it: up to three times if the caller talked over it, once if it never played. After that it gives up, counts the line as asked, and takes the step's usual edges.
For an interview question, giving up means the call moves on to the next question with this one never heard. Set mustBeHeard on the step. When the agent gives up on that line, the call goes to unheardFallback and never takes the step's own edges:
{
"id": "say_q",
"kind": "message",
"say": "{{question}}",
"mustBeHeard": true,
"unheardFallback": "line_trouble"
}Point the fallback at a step that records the missed contact and ends the call:
{
"nodes": [
{ "id": "line_trouble", "kind": "tool", "label": "Log no contact",
"toolName": "No_Contact", "toolArgs": { "conversation_id": "{{session_id}}" } },
{ "id": "line_end", "kind": "end", "label": "Call back later",
"say": "Sorry, the line keeps breaking up. We'll call you back. Goodbye." }
],
"edges": [
{ "id": "e_lt_ok", "from": "line_trouble", "to": "line_end",
"condition": { "type": "tool_result", "on": "success" } },
{ "id": "e_lt_fail", "from": "line_trouble", "to": "line_end",
"condition": { "type": "tool_result", "on": "failure" } }
]
}mustBeHeard is off by default. A line the caller hears routes as usual. Without an unheardFallback, or with one that names no step, the agent gives up as before, and the write returns a warning naming the step.
How long an answer a step expects
With AssemblyAI as the speech-to-text provider, a step can set how long the caller may pause before their turn ends. Set answerLength on a message step:
open: a free answer, like an interview question. A pause after a full sentence does not end the turn (AssemblyAI turn silence min 1300 ms, max 3600 ms).medium: an answer with a pause of about a second, like an address or a phone number (AssemblyAI turn silence min 800 ms, max 1600 ms).short: a yes/no or one-word reply. The agent's own STT turn settings apply, so the reply comes fast.
{
"id": "say_q",
"kind": "message",
"say": "{{question}}",
"answerLength": "open"
}Unset, the step picks for itself: a free-text slot makes it open, slots that are all choices make it short, and a step with no slots whose line asks the caller to tell, describe or explain is open. Everything else is short. The setting switches when the step starts, before its line plays. Other STT providers ignore it. Pair it with turnHandling.turnDetection: "stt" so the STT's end of turn decides when the caller is done.
Waiting for the caller to go on
A step that sets answerLength: "open" itself also waits after each caller turn before it moves on. This works with every STT provider:
- After the caller stops, the step waits up to 3 seconds for them to continue. If they speak again, it keeps listening and judges the whole answer once they finish. If they stay quiet, it moves on.
- The agent replies a little later on these steps. Set
answerLength: "open"only where callers give long answers, such as interview questions. - A step that is only
openbecause it was left unset does not get this wait. A free-text slot like "What's your name?" still replies at normal speed.
Every scripted step also handles a caller who asks for time ("let me think about that", "give me a moment", "just a sec"). It waits up to 10 seconds without re-asking, then judges the answer together with the request. If the caller stays quiet, it offers the question again gently.
Safety defaults on a generated workflow
To generate a workflow, Speko first plans the call from your system prompt: the kinds of caller it expects and the details each one needs. When the prompt leaves its steps to a workflow, the plan adds only the details a promised outcome needs, such as a callback number for a callback. Every planned detail becomes a question in the workflow. Review the questions in the editor before you go live.
A workflow Speko generates from your system prompt starts with these settings. Each is an explicit value you can change in the editor. Values already set are kept, and workflows you saved are never changed.
-
The opening question is a real step. No caller turn is heard at the
entry, so an entry that collects slots or branches on the caller's answer becomes the first step after a bare start. -
One question per step. A step that only collects details (every way out is unconditional) and asks several questions is split into one step per question, chained in order. A step moves on after the first answer it hears, so a five-question step would otherwise take one answer and skip the rest. A step that branches on answers (for example "is it urgent?") asks its other questions first, then each answer it branches on as its own step, in branch order. A step whose branches on one answer are interleaved with branches on another stays whole. Opening steps and steps with plain-language branches are left whole. A question asked only sometimes ("pain description, if any") stays with the question before it instead of becoming its own required step.
-
Catch-all branches last. An expression branch on a catch-all value such as
otherorunknownis ordered after the specific branches, so it only matches when nothing else does. -
A closing line on every end and transfer step. The last line is spoken word for word. A step with only an instruction ("Say goodbye and end the call.") gets "Thanks for calling. Goodbye!" (or "One moment, I'll connect you now." for a transfer), and a warning asks you to write your own.
-
Globals that end the call. An
llmglobal into anendstep fires only at the entry and the first question. Every other step goes in itsexceptNodeIds, so a misheard word mid-call cannot hang up on a caller. If the call can return to the first question later, that step is excluded too, and a warning says so. The editor's Anytime intents panel lists these steps; click one to allow the intent there again. -
answerLength, from each slot's key:- address, zip, phone, callback number or digits:
medium; - choices, and facts like name, brand, time or day:
short; - a request to describe, tell or explain:
open.
Other free-text slots stay unset.
- address, zip, phone, callback number or digits:
-
Optional questions that ask how the caller heard about you get
maxReasks: 0: an unclear answer is marked<slot>_unclearand the call moves on. -
Name slots (
name,first_name,caller_nameand similar) get a rule to stay empty when the answer is not a person's name.
The seed response lists each change in safety.changes. safety.warnings names what it left to you, such as a name or callback number that some route to the end of the call never reads back. Read-backs are your wording, so none are added for you.
Reading and writing a workflow
GET /v1/agents/{id}/graph returns the live workflow, its version, and a revision you send back on write. PUT publishes a new one:
curl -X PUT https://api.speko.dev/v1/agents/$AGENT_ID/graph \
-H "Authorization: Bearer $SPEKO_API_KEY" \
-H 'Content-Type: application/json' \
-d '{ "version": 12, "ifRevision": 3, "graph": { "entryNodeId": "intro", "nodes": [], "edges": [] } }'version is the version you edited from. Publishing cuts a new agent version, so a workflow change moves the same number a config change does — which is how rollback can reach a previous workflow. A stale ifRevision answers 412 rather than overwriting whoever published in between.