Virtual Agent Assist

הכלי Virtual Agent Assist עוקב אחרי שיחה ומשתמש בנציג וירטואלי של Dialogflow כדי לספק תמיכה בתהליך העבודה לנציגים אנושיים ולזהות כוונות (intent) לניתוח נתונים. במדריך הזה נסביר איך להפעיל את התכונה Virtual Agent Assist באמצעות קריאה ישירה ל-API. במדריך למסוף של Virtual Agent Assist מוסבר איך משתמשים במסוף.

לפני שמתחילים

כדי להפעיל את Virtual Agent Assist, צריך להטמיע קודם תכונה אחת או יותר של Agent Assist לשימוש עם הנציג הווירטואלי. אפשר להשתמש בתכונות "תשובה מהירה", "עזרה בשאלות נפוצות", "הצעת מאמרים" ו"כתיבה מהירה" לבד עם Virtual Agent Assist או בכל שילוב. בקישורים הבאים מופיע מידע רלוונטי על ההטמעה.

יצירת שיחה

כשמתחיל דיאלוג בין משתמש קצה לבין נציג אנושי או וירטואלי, אתם יוצרים שיחה. כדי לראות הצעות, צריך גם ליצור משתתף שהוא משתמש קצה ומשתתף שהוא נציג אנושי, ולהוסיף אותם לשיחה. בקטעים הבאים מפורט התהליך הזה.

קודם כל, צריך ליצור שיחה:

REST

כדי ליצור שיחה, צריך להפעיל את ה-method‏ create במשאב Conversation.

לפני שמשתמשים בנתוני הבקשה, צריך להחליף את הנתונים הבאים:

  • ‫PROJECT_ID: מזהה הפרויקט בענן
  • ‫LOCATION_ID: מזהה המיקום שלכם
  • ‫CONVERSATION_PROFILE_ID: המזהה שקיבלתם כשיצרתם את פרופיל השיחה

ה-method של ה-HTTP וכתובת ה-URL:

POST https://dialogflow.googleapis.com/v2/projects/PROJECT_ID/locations/LOCATION_ID/conversations

תוכן בקשת JSON:

{
  "conversationProfile": "projects/PROJECT_ID/locations/LOCATION_ID/conversationProfiles/CONVERSATION_PROFILE_ID",
}

כדי לשלוח את הבקשה צריך להרחיב אחת מהאפשרויות הבאות:

אתם אמורים לקבל תגובת JSON שדומה לזו:

{
  "name": "projects/PROJECT_ID/locations/LOCATION_ID/conversations/CONVERSATION_ID",
  "lifecycleState": "IN_PROGRESS",
  "conversationProfile": "projects/PROJECT_ID/locations/LOCATION_ID/conversationProfiles/CONVERSATION_PROFILE_ID",
  "startTime": "2018-11-05T21:05:45.622Z"
}

החלק של הנתיב אחרי conversations מכיל את מזהה השיחה החדש.

Python

כדי לבצע אימות ב-Agent Assist, צריך להגדיר את Application Default Credentials. למידע נוסף, ראו הגדרת אימות לסביבת פיתוח מקומית.

def create_conversation(project_id, conversation_profile_id):
    """Creates a conversation with given values

    Args:
        project_id:  The GCP project linked with the conversation.
        conversation_profile_id: The conversation profile id used to create
        conversation."""

    client = dialogflow.ConversationsClient()
    conversation_profile_client = dialogflow.ConversationProfilesClient()
    project_path = client.common_project_path(project_id)
    conversation_profile_path = conversation_profile_client.conversation_profile_path(
        project_id, conversation_profile_id
    )
    conversation = {"conversation_profile": conversation_profile_path}
    response = client.create_conversation(
        parent=project_path, conversation=conversation
    )

    print("Life Cycle State: {}".format(response.lifecycle_state))
    print("Conversation Profile Name: {}".format(response.conversation_profile))
    print("Name: {}".format(response.name))
    return response

יצירת משתתף שהוא משתמש קצה

כדי לראות הצעות, צריך להוסיף לשיחה גם משתמשי קצה וגם נציגים אנושיים. קודם כל, מוסיפים את משתמש הקצה לשיחה:

REST

כדי ליצור משתתף שהוא משתמש קצה, צריך להפעיל את ה-method‏ create במשאב Participant.

לפני שמשתמשים בנתוני הבקשה, צריך להחליף את הנתונים הבאים:

  • ‫PROJECT_ID: מזהה הפרויקט בענן
  • ‫LOCATION_ID: מזהה המיקום שלכם
  • ‫CONVERSATION_ID: מזהה השיחה

ה-method של ה-HTTP וכתובת ה-URL:

POST https://dialogflow.googleapis.com/v2/projects/PROJECT_ID/locations/LOCATION_ID/conversations/CONVERSATION_ID/participants

תוכן בקשת JSON:

{
  "role": "END_USER",
}

כדי לשלוח את הבקשה צריך להרחיב אחת מהאפשרויות הבאות:

אתם אמורים לקבל תגובת JSON שדומה לזו:

{
  "name": "projects/PROJECT_ID/locations/LOCATION_ID/conversations/CONVERSATION_ID/participants/PARTICIPANT_ID",
  "role": "END_USER"
}

החלק של הנתיב אחרי participants מכיל את המזהה החדש של משתתף הקצה.

Python

כדי לבצע אימות ב-Agent Assist, צריך להגדיר את Application Default Credentials. למידע נוסף, ראו הגדרת אימות לסביבת פיתוח מקומית.

def create_participant(project_id: str, conversation_id: str, role: str):
    from google.cloud import dialogflow_v2beta1 as dialogflow

    """Creates a participant in a given conversation.

    Args:
        project_id: The GCP project linked with the conversation profile.
        conversation_id: Id of the conversation.
        participant: participant to be created."""

    client = dialogflow.ParticipantsClient()
    conversation_path = dialogflow.ConversationsClient.conversation_path(
        project_id, conversation_id
    )
    if role in ROLES:
        response = client.create_participant(
            parent=conversation_path, participant={"role": role}, timeout=600
        )
        print("Participant Created.")
        print(f"Role: {response.role}")
        print(f"Name: {response.name}")

        return response

יצירת משתתף שהוא נציג אנושי

כדי לצרף נציג אנושי לשיחה:

REST

כדי ליצור משתתף שהוא נציג אנושי, מפעילים את ה-method‏ create במשאב Participant.

לפני שמשתמשים בנתוני הבקשה, צריך להחליף את הנתונים הבאים:

  • ‫PROJECT_ID: מזהה הפרויקט בענן
  • ‫LOCATION_ID: מזהה המיקום שלכם
  • ‫CONVERSATION_ID: מזהה השיחה

ה-method של ה-HTTP וכתובת ה-URL:

POST https://dialogflow.googleapis.com/v2/projects/PROJECT_ID/locations/LOCATION_ID/conversations/CONVERSATION_ID/participants

תוכן בקשת JSON:

{
  "role": "HUMAN_AGENT",
}

כדי לשלוח את הבקשה צריך להרחיב אחת מהאפשרויות הבאות:

אתם אמורים לקבל תגובת JSON שדומה לזו:

{
  "name": "projects/PROJECT_ID/locations/LOCATION_ID/conversations/CONVERSATION_ID/participants/PARTICIPANT_ID",
  "role": "HUMAN_AGENT"
}

החלק של הנתיב אחרי participants מכיל את המזהה החדש של הנציג האנושי המשתתף.

Python

כדי לבצע אימות ב-Agent Assist, צריך להגדיר את Application Default Credentials. למידע נוסף, ראו הגדרת אימות לסביבת פיתוח מקומית.

def create_participant(project_id: str, conversation_id: str, role: str):
    from google.cloud import dialogflow_v2beta1 as dialogflow

    """Creates a participant in a given conversation.

    Args:
        project_id: The GCP project linked with the conversation profile.
        conversation_id: Id of the conversation.
        participant: participant to be created."""

    client = dialogflow.ParticipantsClient()
    conversation_path = dialogflow.ConversationsClient.conversation_path(
        project_id, conversation_id
    )
    if role in ROLES:
        response = client.create_participant(
            parent=conversation_path, participant={"role": role}, timeout=600
        )
        print("Participant Created.")
        print(f"Role: {response.role}")
        print(f"Name: {response.name}")

        return response

הוספת הודעה ממשתמש הקצה וקבלת הצעות

כדי להוסיף ולנתח הודעה של משתמש קצה בשיחה, צריך להפעיל את ה-method‏ analyzeContent במשאב Participant. התשובה כוללת את השדה dialogflowAssistAnswers, שמכיל את הנתונים הבאים:

  • ‫intentSuggestion: מכיל מידע על הכוונה התואמת, כמו השם המוצג שלה.
  • ‫answerRecord: שם המשאב הייחודי של רשומת התשובה להצעה.

בוחרים את ההצעה.

כשנציג אנושי מקבל הצעה, הוא יכול לבחור אותה כדי להתחיל את המילוי של אותה כוונה. כדי לבחור הצעה , קוראים שוב ל-method‏ analyzeContent עם המשתתף שהוא נציג אנושי. בגוף הבקשה של Dialogflow CX, מגדירים את השדה suggestionInput עם הערך answerRecord שקיבלתם מההצעה. בחירה בהצעה מפעילה את המילוי ומחזירה את הודעת התגובה של המילוי. ‫Dialogflow ES מעריך את המילוי כשההצעה נוצרת ומוחזרת ב-queryResult. קריאה ל-analyzeContent עם suggestionInput מעדכנת רק את הקשר הסשן.

אם הנציג האנושי עורך את ההצעה לפני שהוא שולח אותה למשתמש הקצה, אפשר גם לציין את השדה האופציונלי textOverride. בדוגמה הבאה מוסבר איך להגדיר את השדה suggestionInput:

{
  "answerRecord": "answer-record",
  "textOverride": {
    "text" : "Yes, there will be ponies.",
    "languageCode": "en-US"
  }
}

לסיים את השיחה

כשהשיחה מסתיימת, משתמשים ב-API כדי להשלים את השיחה.

REST

כדי לסיים את השיחה, צריך לבצע קריאה ל-method‏ complete במשאב conversations.

לפני שמשתמשים בנתוני הבקשה, צריך להחליף את הנתונים הבאים:

  • ‫PROJECT_ID: מזהה הפרויקט ב-GCP
  • ‫CONVERSATION_ID: המזהה שקיבלתם כשיצרתם את השיחה

ה-method של ה-HTTP וכתובת ה-URL:

POST https://dialogflow.googleapis.com/v2/projects/PROJECT_ID/conversations/CONVERSATION_ID:complete

כדי לשלוח את הבקשה צריך להרחיב אחת מהאפשרויות הבאות:

אתם אמורים לקבל תגובת JSON שדומה לזו:

{
  "name": "projects/PROJECT_ID/conversations/CONVERSATION_ID",
  "lifecycleState": "COMPLETED",
  "conversationProfile": "projects/PROJECT_ID/conversationProfiles/CONVERSATION_PROFILE_ID",
  "startTime": "2018-11-05T21:05:45.622Z",
  "endTime": "2018-11-06T03:50:26.930Z"
}

Python

כדי לבצע אימות ב-Agent Assist, צריך להגדיר את Application Default Credentials. למידע נוסף, ראו הגדרת אימות לסביבת פיתוח מקומית.

def complete_conversation(project_id, conversation_id):
    """Completes the specified conversation. Finished conversations are purged from the database after 30 days.

    Args:
        project_id: The GCP project linked with the conversation.
        conversation_id: Id of the conversation."""

    client = dialogflow.ConversationsClient()
    conversation_path = client.conversation_path(project_id, conversation_id)
    conversation = client.complete_conversation(name=conversation_path)
    print("Completed Conversation.")
    print("Life Cycle State: {}".format(conversation.lifecycle_state))
    print("Conversation Profile Name: {}".format(conversation.conversation_profile))
    print("Name: {}".format(conversation.name))
    return conversation