Skip to main content

01 — Flow: when goals start, end, and hand off

1.1 Goal lifecycle at a glance​

eligible ──▶ agent attempts to say it ──▶ performed ──▶ value collected ──▶ complete
▲ │
└── blocked: conditions unmet · cooling down · disqualified · not selected (choice) ◀────┘
  • eligible — passes every gate in §1.2–§1.4; re-checked every turn.
  • triggered — selected as the active goal; triggered-timing tools fire (03-tools §3.2).
  • performed — the agent actually said the goal's message. The engine verifies this against the generated reply; if the model skipped the message, the goal is not performed and may retry.
  • value collected — an ask goal collected its value (02-dialogue §2.4). Eligible goals with built-in answer types collect silently the moment the contact mentions the value, without ever being asked (02-dialogue §2.6).
  • complete — everything that applies is met (§1.5); completed-timing tools fire; complete goals are skipped by proactive order.
  • stopped — the flow moved past it unfinished (§1.5); it may retry after a cooldown.
  • blocked — unmet conditions, an active cooldown (after being ignored or refused, 02 §2.7), or being an unpicked choice.

1.2 Trigger proactively (proactive order)​

Default forward motion when nothing reactive claimed the turn: the engine continues the active goal if it should still run, then its children, then its siblings (walking up through parents once the current goal is complete or stopped), and finally rescans the whole tree from the top. The first eligible goal wins. "First" is document order — so flow design is mostly ordering goals and gating them with conditions.

Trigger proactively off = proactive: false: the goal never starts on its own; it starts only via trigger phrases, transitions, or event tools. Use for detour/branch goals — and always wire a way in: a proactive: false goal that no transition targets and no trigger phrase starts is unreachable.

1.3 Conditions​

Conditions (conditions, string), under the goal's Goal triggers, is the eligibility gate — and it is re-evaluated every turn, not just at start: a goal can become eligible late, or stop being eligible mid-flow (which also lets proactive order move past it to its parent's siblings). Syntax and operators: 04-variables-and-conditions §4.3.

{ "name": "book demo", "conditions": "company size > 20", ... }

Gate only what flow order can't already guarantee — see the branch conventions in §1.8 before conditioning goals on an earlier answer.

1.4 Trigger in reaction to phrases​

  • Trigger phrases (triggers, string array): sample statements that — if the contact says something matching — start the goal immediately, from anywhere the scope allows. Detection also validates the match semantically, so a handful of representative phrasings is enough. Usually unnecessary: answer detection already matches goal names and choices; add phrases only where that fails.
  • Counterexamples (negative_triggers): near-miss statements that must not start the goal ("I don't want to cancel" vs "I want to cancel"). A matched counterexample also vetoes the goal's proactive start for that turn.
  • Active during (trigger_scope): "global" (default) — phrases work anywhere in the call; or a goal's name — phrases work only while that goal is the active goal or an ancestor of it (the UI's "Only during ‹parent›" writes the parent goal's name; "Only specified goal" writes any goal's name). Any goal in the script is accepted as a scope, but prefer "global" or a parent of the reactive goal — a disjoint goal's name works, and makes the script hard to follow.
  • Placement: don't nest a reactive goal under the ask or transfer goal it interrupts. To co-locate them, wrap that goal and the reactive goal as siblings in one sequence (§1.8) and scope the phrases to the wrapper.

A reactive start wins over proactive order for the turn. The triggering utterance itself is also checked as a possible answer to the ask goal's question (02-dialogue §2.6).

1.5 Ending: complete vs. stopped​

A goal ends one of two ways.

Complete — it finished the job: everything that applies is met.

  • its value is collected (ask goals — a passively collected value counts even if the question was never asked);
  • its message was performed (say goals; with appended: true the message rides on the adjacent goal's turn, 02 §2.3);
  • all its child goals are complete — a child that never becomes eligible blocks this: the flow walks past (§1.2), but the parent never completes and its completed tools never fire;
  • no repeat or pushback round is still owed (02-dialogue §2.7).

So a plain say goal is complete once said; an ask goal with children needs the value and the children.

Stopped — the flow moved past it unfinished: it became ineligible (§1.3), another goal pulled the flow — a trigger phrase or a transition took the call elsewhere (§1.4, §1.6) — or the contact refused (02-dialogue §2.7). A stopped goal may be retried later (cooldown) or never (exhausted refusal) — and its completed-timing tools do not fire (03-tools §3.2); hang must-run tools on performed/collected instead.

Repeat goal sets how long a goal keeps running:

  • Until the field is collected (ask goals) or Until the contact replies (say goals): the default; leave repeat absent.
  • Until the agent says the message: appended: true on a say goal (02-dialogue §2.3).
  • A set number of times: repeat as a number, shown as At most N times. The goal runs at most N times; an ask goal still stops once its field is collected.
  • Indefinitely: repeat: true. The goal re-runs every turn and never completes; a transition stops it. The standard shape for persisting instructions (02-dialogue §2.2). The panel also writes repeat_conditions: true, which keeps an ask goal running after its field is collected.

To loop an ask goal until a specific answer, set repeat_conditions to a condition string in the JSON view, e.g. "repeat_conditions": "agrees != yes".

1.6 Transitions​

Two storage forms, one concept: leave this goal for a named target. The transition's Transition trigger picks the form.

  • Agent decided (transitions[]): {name, prompt, target, conditions}. At runtime each becomes an LLM tool — name is the function name, prompt the description the agent uses to decide when to take it, target the goal name to jump to, conditions gates availability. Entries with an empty name or target are dropped at load. An optional properties map (JSON-schema, like a tool's parameters) makes the agent fill values when it takes the transition — each lands as a state variable; subagent phases use this to emit what they collected (flows/subagent.md).
"transitions": [{ "name": "go_to_human", "prompt": "the contact asks to speak with a person",
"target": "transfer to representative" }]
  • On an event: a fulfillment entry whose only action is trigger — {timing, trigger: "<goal name>", conditions}. Taken when the engine event fires (03-tools §3.2). Entries are evaluated top-to-bottom and each overrides the previous, so the last stored entry takes precedence.
  • When no transition is picked: proactive order resumes (§1.2) — unless the goal has repeat_mode: "passive" (After goal completes: Return to where the call left off, under Trigger in reaction to phrases): after it runs (typically a trigger-phrase detour), the engine resumes the goal that was active before it, instead of treating this goal as the new position.

Decision rule for one turn: a fired event transition or agent-decided transition claims the next goal; otherwise return mode or proactive order.

Placement: on a goal with choices, answer-dependent routing belongs in the choices' branch bodies (§1.8) — goal-level transitions are only for exits that don't depend on the answer (busy, wants a human).

1.7 Detours and coming back​

When a reactive interrupt takes over (a triggered goal, a contact question, a built-in), the engine afterwards resumes: the interrupted ask goal if still unanswered, else its remaining children, else forward motion from the detour's position — unless the detour goal is in return mode (§1.6), which restores the previous position exactly.

  • Ignored question: if the contact answers something else, the ask goal cools down briefly and is retried on a later turn once nothing else claims the turn.
  • Refused question: pushback runs first; exhausted refusals put the goal into a long, growing cooldown — effectively taking it out of the call (02-dialogue §2.7).
  • Gating on an answer: to make goals depend on an answer, gate them with conditions on the collected value (interested in offer = yes) or nest them inside the matching choice — needed only when a negative path leaves the call running; when the other choices are all handled, rely on flow order instead (§1.8). A blocked-out goal simply never becomes eligible.

1.8 Sequences and branches​

  • Sequences (goals): a container goal with child goals and no messages or value_type of its own; children run in array order and the sequence completes when all of them do. By convention such goals are written with goal_type: "container" — a display label with no engine meaning; the shape (children, no dialogue) is what makes it a sequence. Nesting the flow this way scopes trigger phrases ("Only during ‹parent›") and makes detour-resume behavior predictable.

  • Choices as branches: a choice's nested goals run only when that choice is picked (02-dialogue §2.5) — the engine gates each choice's children on the parent's collected value equaling the choice name. Two conventions:

    • The happy path is never nested inside a choice — it stays the primary sequence; only the negative choices carry nested handling (not interested → goodbye → hang up).
    • Don't gate the happy path on a handled choice. When every negative choice is terminal (hang up, callback, transfer) or branches back into the happy path, the goals after the ask need no conditions on its answer — reaching them already means the happy path, and "conditions": "interested in offer = yes" on each following goal is noise. Gate on the answer only when a negative path leaves the call running outside the happy path, so a blocked-out goal must stay blocked (§1.3). The running example in 00 §0.3 is the shape.
  • Negative paths without choices (numeric and sentinel answers, 02-dialogue §2.4): don't nest goals under the ask goal — the canvas can't add children there. Wrap the question and its negative paths in one sequence:

    { "name": "company sizing", "goal_type": "container", "goals": [
    { "name": "company size", "goal_type": "ask", "value_type": "number", ... },
    { "name": "too small goodbye", "conditions": "company size <= 20", ... }
    ]}

    The happy-path rule applies at the container's boundary: goals after it stay ungated when the negative paths are terminal. On the happy path the conditioned child never becomes eligible, so the container never completes — the flow just walks past it (§1.5); don't hang completed tools on it.

  • A goal may carry choices or goals, never both — the engine refuses to load a goal with both.