Agent Script Reference: Before and After Reasoning

before_reasoning and after_reasoning are optional blocks inside a topic. They can contain logic, actions, transitions, or other directives that run either before or after the topic runs.

When calling transitions in before or after reasoning, use transition to rather than @utils.transition to. For example:

The before_reasoning and after_reasoning blocks don't support the | (pipe) command.

A topic's before_reasoning block runs before the topic's reasoning block starts, on every request. Typical use cases are to set customer-entered information into variables, transition to a different topic under certain conditions, or run an action.

You can use before_reasoning, or you can add the same logic to the beginning of a topic's instructions.

For example, this before_reasoning block sets the appointment duration based on the urgency level.

A topic's after_reasoning block runs when the reasoning block completes, on every request. Typical use cases are to set customer-entered information into variables, transition to a different topic, or run an action.

If a topic transitions to a new topic partway through execution, the original topic's after_reasoning block isn't run.