Rasa Form Handling: 자동화된 Slot Filling 이해하기

엔케이·2025년 2월 5일
0
post-thumbnail

Rasa Form Handling: 자동화된 Slot Filling 이해하기

Rasa를 사용하면서 domain.yml에 정의된 utter들이 stories.yml에 명시되지 않았음에도 불구하고 정상적으로 응답되는 이유에 대해 고민해 본 적이 있나요? 이번 글에서는 Form과 Slot Filling 메커니즘을 통해 이 과정을 상세히 설명합니다.

📚 출처: Rasa Forms 공식 문서


📋 1. 폼(Form) 활성화 과정

먼저, provide_travel_info 인텐트가 감지되면 rules.yml"Activate travel form" 규칙이 트리거됩니다.

- rule: Activate travel form
  steps:
    - intent: provide_travel_info
    - action: travel_form
    - active_loop: travel_form

이 규칙에 따라 travel_form이 활성화되고, 대화의 흐름은 Slot Filling 단계로 넘어갑니다.

🔗 Rasa Rule Policy 설명


🔄 2. Required Slots와 자동 메시지 처리

domain.yml에는 travel_form이 정의되어 있으며, locationdays라는 필수 슬롯(required_slots)이 포함되어 있습니다.

forms:
  travel_form:
    required_slots:
      - location
      - days

🤖 슬롯 채우기 자동화

  • 슬롯이 채워지지 않은 경우:
    • location이 비어 있으면 → utter_ask_location 호출
    • days가 비어 있으면 → utter_ask_days 호출

이렇게 utter_ask_{slot_name} 패턴은 Rasa가 폼 실행 시 자동으로 호출하는 규칙입니다. 그래서 stories.yml에 명시적으로 작성하지 않아도 자동으로 실행됩니다.

📄 Rasa Slot Mapping 공식 문서


✅ 3. 예제 시나리오로 이해하기

케이스 1: location과 days 모두 입력된 경우

  • 사용자: "서울로 3일 여행 가고 싶어"
    • location = 서울
    • days = 3
  • 모든 슬롯이 채워졌기 때문에 travel_form은 즉시 제출됩니다.
  • rules.yml"Submit travel form" 규칙에 따라 utter_confirm_travel이 호출됩니다.

케이스 2: location만 입력된 경우

  • 사용자: "서울로 여행 가고 싶어"
    • location = 서울
    • days = (없음)
  • travel_formdays를 채워야 하므로 자동으로 utter_ask_days를 호출합니다.
  • 사용자가 "3일이요"라고 답하면 폼이 제출됩니다.

케이스 3: 아무 슬롯도 없는 경우

  • 사용자: "여행 가고 싶어"
    • location = (없음)
    • days = (없음)
  • travel_form은 먼저 utter_ask_location을 호출하여 위치를 요청합니다.
  • 위치를 받은 후에는 utter_ask_days를 호출하여 기간을 요청합니다.

🗂️ Form Action 동작 방식


🚀 4. 내부 동작 요약

  1. 폼 활성화required_slots 확인
  2. 비어 있는 슬롯 발견utter_ask_{slot_name} 자동 호출
  3. 슬롯 모두 채워짐 → 폼 제출 → utter_confirm_travel 호출

따라서 utter_ask_locationutter_ask_daysstories.yml에 없어도 자동으로 호출되는 것입니다. 🎯

📊 Rasa 대화 흐름 관리 문서


🗂️ 전체 YML 파일 예제

domain.yml

recipe: default.v1
assistant_id: 20250115-115620-chief-level

intents:
  - provide_travel_info

entities:
  - location
  - days

slots:
  location:
    type: text
    influence_conversation: true
    mappings:
      - type: from_entity
        entity: location
  days:
    type: text
    influence_conversation: true
    mappings:
      - type: from_entity
        entity: days

forms:
  travel_form:
    required_slots:
      - location
      - days

responses:
  utter_ask_location:
    - text: "어디로 여행가고 싶어?😄"
  utter_ask_days:
    - text: "몇 일동안 머무를 예정이야?🧐"
  utter_confirm_travel:
    - text: "좋아요😍 {location}으로 {days}일동안 여행할 일정을 계획해볼게요😎"

rules.yml

rules:
  - rule: Activate travel form
    steps:
      - intent: provide_travel_info
      - action: travel_form
      - active_loop: travel_form

  - rule: Submit travel form
    condition:
      - active_loop: travel_form
    steps:
      - action: travel_form
      - active_loop: null
      - action: utter_confirm_travel

stories.yml

stories:
  - story: Complete travel booking
    steps:
      - intent: provide_travel_info
      - action: travel_form
      - active_loop: travel_form
      - active_loop: null
      - action: utter_confirm_travel

✍️ 마무리

Rasa의 Form 기능은 Slot Filling을 자동화하여 개발자의 수고를 덜어줍니다. 이 메커니즘을 잘 활용하면 효율적인 챗봇 개발이 가능합니다. 🚀

📖 더 알아보기: Rasa 공식 문서

profile
FE 개발자

0개의 댓글