Agent Script Pattern: Enforce Required Workflows Through Topics In Multi Turn Conversations
Ensure your agent adheres to your topic sequencing rules through multi-turn conversations, even when your sequencing rules are complex. Use a step variable to control which topic the topic classifier selects. Within a topic, allow the agent to evaluate the customer's answer and set the step variable for the next step.
Use this pattern when:
- The agent must ask a long sequence of required questions and validate each answer before moving to the next question
- The next question asked depends on the previous question's answer
- The agent may spend many turns in a single topic, for example clarifying a specific salary requirement or explaining certification equivalency.
Use the simpler pattern in Enforce Required Workflows for a Topic when you only need a single prerequisite gate, such as verification before routing, or a one-topic prerequisite like collecting order_id before order help.
Pattern Examples:
- Screening or intake flows where each question gates the next one.
- Compliance-driven interviews where required questions must be asked in order.
- Qualification flows where invalid or incomplete answers require follow-up before progression.
In this pattern, start_agent uses the currentInterviewStep variable to select the current topic. In each topic, the agent asks the customer a specific set of questions. Based on the customer's response, the agent sets the value of the currentInterviewStep variable, controlling what the next topic in the sequence will be.
For example, in the permission topic, the agent asks the customer whether they have legal permission to work in the region.
- If the customer does have permission, the agent sets
currentInterviewSteptoEligibility, ensuring the topic classifier routes to theeligibilitytopic. - If the customer doesn't have permission, the agent the agent sets
currentInterviewSteptoEnd, ensuring the topic classifier routes to theend_interviewtopic.
- Keep one responsibility per topic: Design each topic to validate one required answer, then move to the next step.
- Use explicit step names: Use clear values like
permission,eligibility, andavailabilityso routing remains easy to read and maintain. - Let topics own completion logic: The topic should decide when an answer is satisfactory and continue asking follow-ups until it is.
- Pattern: Transitions
- Pattern: Conditionals
- Pattern: Enforce Required Workflows for a Topic