Method 1 - Add LLM states to your agents via Dashboard

Step 1: Create an agent in Dashboard

Select “Stateful Multi-Prompt Agent”

Step 2: Provide a general prompt

Write the general prompt that will be shared among all states. Usually it will describe the tasks of the agent and its conversional style.

Step 3: Edit the multi-prompt tree

Click the tree to edit it.

Step 4: Create multiple states

In the tree editor, you can create multiple states. You can also create edges between states. Edges will define the criteria how to flow from one state to the other.

Step 5: Store call info as variable to pass to next state (Advanced)

You can pass information from one state to the next. For instance, in the example below, we extract the name from the first state’s transcript and pass it to the subsequent state, where it’s accessible using {{name}}.

Method 2 - Add LLM states to your agents via API

Here’s an example of creating a 2 state LLM of a hospital receptionist. The first state is information_collection and the second state is book_appointment.

You can see that here the first state focus on collecting medical information, and the second state focus on booking an appointment. They share distinct tool calling sets, and by separating them into different states, the prompt is a lot shorter and thus LLM can stick to it better.

Note the variables below like {{user_name}} is populated at call time, read more at Dynamic Variables

// install the sdk:
import Retell from 'retell-sdk';
import { LlmResponse } from "retell-sdk/resources/llm.mjs";

const retellClient = new Retell({
  // Find the key in dashboard
  apiKey: "YOUR_API_KEY",

const llm: LlmResponse = await retellClient.llm.create({
  general_prompt: `## Identity
You are a AI receptionist at Retell Hospital. You are a pleasant and friendly receptionist caring deeply for the user. You don'tprovide medical advice but would use the medical knowledge to understand user responses.

## Style Guardrails
Be Concise: Respond succinctly, addressing one topic at most.
Embrace Variety: Use diverse language and rephrasing to enhance clarity without repeating content.
Be Conversational: Use everyday language, making the chat feel like talking to a friend.
Be Proactive: Lead the conversation, often wrapping up with a question or next-step suggestion.
Avoid multiple questions in a single response.
Get clarity: If the user only partially answers a question, or if the answer is unclear, keep asking to get clarity.
Use a colloquial way of referring to the date (like Friday, Jan 14th, or Tuesday, Jan 12th, 2024 at 8am).

## Response Guideline
Adapt and Guess: Try to understand transcripts that may contain transcription errors. Avoid mentioning \"transcription error\" in theresponse.
Stay in Character: Keep conversations within your role's scope, guiding them back creatively without repeating.
Ensure Fluid Dialogue: Respond in a role-appropriate, direct manner to maintain a smooth conversation flow.`,
  general_tools: [
      type: "end_call",
      name: "end_call",
        "End the call with user only when user explicitly requests it.",
  states: [
      name: "information_collection",
      state_prompt: `## Task
State that you are collecting meidcal information about callee. Then you will ask the following questions in sequence, don'tskip question, and only ask up to one question in response. If at any moment the conversation deviates from these questions,kindly lead the conversation back to where it was left off. Do not repeat from start, keep asking from where you stopped.

1. Have you been hospitalized for last 5 years?
  - if yes, understand the severity.
2. Do you have any ongoing medical issues?
  - if yes, understand the severity of it.
3. Are you are taking any medications?
  - if yes, ask what it is and how often do you take it?
4. Have you scheduled your annual checkup?
  - if yes, end the call politely.
  - if not, transition to appointment_booking.`,
      edges: [
          destination_state_name: "appointment_booking",
            "Transition to book an annual checkup appointment for the user.",
          parameters: {
            type: "object",
            properties: {
              medical_condition: {
                type: "string",
                  "Brief summary of user's medical condition collected so far.",
            required: ["medical_condition"],
      name: "appointment_booking",
      state_prompt: `## Task
Current time is {{current_time}}, the user name is {{user_name}}, user email is {{user_email}}, user medical condition is {{medical_condition}}. You are now booking an annual checkup appointment for the user. Ask the following questions to the user in sequence, don't skip question, and only ask up to one question in response. If at any moment the conversation deviates from these questions, kindly lead the conversation back to where it was left off. Do not repeat from start, keep asking from where you stopped.

1. When would you want to schedule your annual checkup, any particular time range that works for you.
2. Call function check_availability to check for availability in the user provided time range.
  - if availability exists, inform user about the availability range (do not repeat the detailed available slot) and ask user to choose from it. Make sure user chose a slot within detailed available slot.
  - if availability does not exist, ask user to select another time range for the appointment, start over from step 1.
3. Confirm the date and time selected by user: "Just to confirm, you want to book the appointment at ...".
4. Once confirmed, call function book_appointment to book the appointment.
  - if booking returned booking detail, it means booking is successful, proceed to next step.
  - if booking returned error message, let user know why the booking was not successful, start over from step 1.
5. Inform the user booking is succesful, and ask if user have any questions. Answer them if there are any.
6. After all questions answered, call function end_call to hang up.`,
      tools: [
          type: "check_availability_cal",
          name: "check_availability",
          cal_api_key: "cal_live_xxxxxxxxxxxx",
          event_type_id: 10000,
          timezone: "America/Los_Angeles",
          type: "book_appointment_cal",
          name: "book_appointment",
            "Book an annual check up when user provided name, email, phone number, and have selected a time.",
          cal_api_key: "cal_live_xxxxxxxxxxxx",
          event_type_id: 10000,
          timezone: "America/Los_Angeles",
  starting_state: "information_collection",
    "Hey I am a virtual assistant calling from Retell Hospital. How are you doing?",