Agent Script Example: Use a Step Variable to Enforce Topic Workflows
To ensure that your agent follows your required topic workflow during a multi-turn conversation, use a step variable to set the current topic. Within a topic, let the agent evaluate the customer's answer and set the step variable's next value accordingly.
Use this example when your agent must:
- Ask all required questions in order, where the order can depend on previous answers.
- Evaluate whether each answer is complete and valid.
- Ask follow-up or clarifying questions when needed.
- Move to the next step only when the current step is complete.
- End early when a disqualifying answer is provided.
This pattern gives you predictable routing and topic-level flexibility.
- Download the InterviewAgent.agent.
- In Agent Script, in the upper right, click the down arrow next to New Agent and select New from Script.
- Paste the Interview Agent Script code into your new agent.
- Click your agent to open it, then select Preview.
- Enter something like
I'd like to apply for the positionand test your agent.
This agent provides an example of using step variables. It is not a production-ready agent.
The start_agent topic acts as a router. It checks the value of the currentInterviewStep variable and transitions to the corresponding topic. For example, if the value of currentInterviewStep is Permission, this transition runs:
This example uses these values for currentInterviewStep:
Permission: Confirm candidate has the legal right to work in Wonderland.Eligibility: Ask if the candidate has passed their NCLEX-RN exam.Availability: Identify the candidate's earliest possible start date.Competency: Ask a question about Alice in Wonderland to ensure the candidate has read the book.Salary: Ask about expected salary and compensation preferences.Human: Candidate has passed the screen and questions are passed to a human for follow-up.End: Candidate doesn’t meet qualifications; end the interview.
In each topic, the agent can call @utils.setVariables to update currentInterviewStep based on its evaluation of the candidate's response. For example, in the Eligibility topic, the agent can set:
Availability- if the candidate indicates they’ve passed the NCLEX-RN exam.End- if the candidate hasn’t passed the NCLEX-RN exam.
This diagram shows the interview agent's workflow when selecting the topics determined by the step variable.
