Genesys 도구 구현 및 변수 액세스

이 주제는 Genesys Bot Connector(및 오디오 커넥터)용 Python 도구를 구현하는 방법과 Genesys Cloud 플랫폼에서 해당 도구 출력에 액세스하는 방법을 다룹니다.

필수 소프트웨어

Genesys Bot 커넥터(또는 오디오 커넥터) 설정

  • OAuth 인증 정보를 설정하고 watsonx Orchestrate 에 연결하세요
  • 인바운드 메시지 흐름을 설정하고, 해당 위치에서 봇 커넥터를 호출하세요

watsonx Orchestrate 에이전트 및 도구를 설정하는 방법을 숙지해야 합니다

세션 변수에 대한 간략한 개요 - 입력값

Genesys의 입력 변수들이 상담원의 컨텍스트로 전달됩니다. Genesys Bot Connector 구성에서 Genesys에서 watsonx Orchestrate 로 전달할 세션 변수(입력값)를 정의할 수 있습니다.

아래 예시에서 볼 수 있듯이, 이러한 변수들은 객체 context.channel.genesys_bot_connector.parameters 내에 중첩됩니다.

예:

context: {
    channel: {
        customer_id: 12345example,
        channel_type: genesys_bot_connector,
        genesys_bot_connector: {
            bot_session_id: 12345example,
            conversation_id: 12345example,
            parameters: { user_name: John Doe, phone: +1234567890 }
        }
    }

      

Python 도구 구현

도구 구조Python 의 도구들은 의 @tool 데코레이터를 사용하여 ibm_watsonx_orchestrate.agent_builder.tools 구현됩니다. 각 도구는 Genesys Bot Connector에서 처리할 수 있는 메타데이터를 반환합니다. 도구 이름에 transfer_to_human 또는 이 명시적으로 end_session포함되어야 합니다. 원한다면 어떤 접두사든 추가할 수 있습니다. 백엔드의 정규식 로직이 이를 처리해 줄 것입니다(예: conc_transfer_to_human (괜찮습니다). 예시 도구: ‘인간 도구’로 전송

from ibm_watsonx_orchestrate.agent_builder.tools import tool
from pydantic import BaseModel
from typing import Dict, Optional

class GenesysBotConnector(BaseModel):
    output_variables: Dict[str, str]

class ChannelOptions(BaseModel):
    genesys_bot_connector: Optional[GenesysBotConnector]
    genesys_audio_connector: Optional[GenesysBotConnector]

class TransferMetadata(BaseModel):
    channel_options: ChannelOptions


@tool(display_name="transfer_to_human")
def transfer_to_human(reason: str, summary: str, channel_type: str = "genesys_bot_connector") -> TransferMetadata:
    """
    Use to connect to a human representative, it provides metadata to use for transferring out the chat or call. The reason should be why the transfer as initiated. The summary is for a human agent to understand the nature of the transfer and include the conversational context. 

    :param reason: A reason as to why the transfer was initiated
    :param summary: A summary for a human agent to understand the nature of the transfer, include conversational context.
    :param channel_type: The current channel type that the agent is in which can be accessed in the context variable.

    :returns: An object to be passed to Genesys Cloud for further routing of the chat or call.
    """
    if channel_type == "genesys_bot_connector":
        channel_options = {
            "genesys_bot_connector": {
                "output_variables": {
                    "summary": summary,
                    "reason": reason,
                    "customVariable": "myCustomParameter"
                }
            },
            "genesys_audio_connector": None
        }

    elif channel_type == "genesys_audio_connector":
        channel_options = {
            "genesys_bot_connector": None,
            "genesys_audio_connector": {
                "output_variables": {
                    "summary": summary,
                    "reason": reason,
                    "customVariable": "myCustomParameter"
                }
            }
        }
    else:
        channel_options = {
            "genesys_bot_connector": None,
            "genesys_audio_connector": None
        }

    transfer_metadata = {
        "channel_options": channel_options
    }

    return TransferMetadata.model_validate(transfer_metadata, strict=False)
세션 종료 도구
from ibm_watsonx_orchestrate.agent_builder.tools import tool
from pydantic import BaseModel
from typing import Dict, Optional

class GenesysBotConnector(BaseModel):
    output_variables: Dict[str, str]

class ChannelOptions(BaseModel):
    genesys_bot_connector: Optional[GenesysBotConnector]
    genesys_audio_connector: Optional[GenesysBotConnector]

class EndSessionMetadata(BaseModel):
    channel_options: ChannelOptions

@tool(display_name="end_session")
def end_session(reason: str, summary: str, channel_type: str = "genesys_bot_connector") -> EndSessionMetadata:
    """
    Use to end the chat or call, it provides metadata to use for transferring out the chat or call. The reason should be why the chat was ended. The summary is just a couple of sentences describing why the chat was disconnected or ended.
    :param reason: A reason as to why the call was disconnected.
    :param summary: A summary of the conversation.
    :param channel_type: The current channel type that the agent is in which can be accessed in the context variable.

    :returns: An object to be passed to Genesys Cloud for further routing of the chat or call.
    """
    if channel_type == "genesys_bot_connector":
        channel_options = {
            "genesys_bot_connector": {
                "output_variables": {
                    "summary": summary,
                    "reason": reason,
                    "customVariable": "myCustomParameter"
                }
            },
            "genesys_audio_connector": None
        }

    elif channel_type == "genesys_audio_connector":
        channel_options = {
            "genesys_bot_connector": None,
            "genesys_audio_connector": {
                "output_variables": {
                    "summary": summary,
                    "reason": reason,
                    "customVariable": "myCustomParameter"
                }
            }
        }
    else:
        channel_options = {
            "genesys_bot_connector": None,
            "genesys_audio_connector": None
        }

    end_session_metadata = {
        "channel_options": channel_options
    }

    return EndSessionMetadata.model_validate(end_session_metadata, strict=False)
위의 도구들을 각각 파일로 저장한 다음 다음 명령을 실행하여 가져올 수 있습니다:
orchestrate tools import -k python -f /path_to/transfer_to_human.py
orchestrate tools import -k python -f /path_to/end_session.py
 

Genesys 채널 통합에서 도구 출력 데이터에 액세스하기

Python 도구의 output_variables 객체에는 Genesys Cloud로 세션 변수(Session Variables) - 출력값(Outputs) 으로 전달해야 하는 모든 키-값 쌍을 포함할 수 있습니다:
"output_variables": {
    "summary": summary,
    "reason": reason,
    "customVariable": "myCustomParameter",
    # Add any additional variables as needed
}
Genesys Cloud에서 전달된 변수에 접근하기

의도(transfer_to_human, end_session 등) 다음과 같은 방법으로 접근할 수 .Intent 있습니다: 접근하는 위치에 따라 또는 Flow.Intent State.Intent 등이 될 수 있습니다.

그런 다음 위와 같은 사례를 바탕으로 각 인텐트에 대해 어떻게 처리할지 결정할 수 있습니다.

도구 출력에서 전달된 키-값 쌍은 이와 유사한 방식으로 접근할 수 있습니다(예: State.summary (요약)

Genesys Audio 커넥터 통합에서 도구 출력 데이터에 액세스하기

입력 매개변수가 user_name: "Jon Snow"주어지면, 에이전트 지침은 다음과 같을 수 있습니다(라는 이름의 간단한 도구가 get_hello_message 있다고 가정합니다).

Bot Connector와의 주요 차이점호출된 도구를 확인하기 위해 를 intent 사용하는 Genesys Bot Connector와 달리, Genesys Audio Connector는 disconnectionReasondisconnectionInfo 를 사용합니다.

키 이름은 반드시 이어야 disconnectionReason 하며, 할당할 값은 사용자가 정할 수 있습니다. 예를 들어, Task.Disconnection사용된 스크린샷. 가능한 값은 다음과 같습니다.
  • "transfer_to_human" - transfer_to_human 도구가 호출될 때
  • "end_session" - end_session 도구가 호출될 때
  • "failed" - 오류가 발생할 때
  • "caller_hangup" - 발신자가 전화를 끊었을 때
이미지에 표시된 것처럼 switch (case) 블록에서 이 기능을 사용할 수 있습니다.

disconnectionInfo 접속하기

추가적인 맥락을 제공하기 위해 (특히 오류 발생 시 유용함):
  • key에서 disconnectionInfo 읽기 (설정 방법은 와 disconnectionReason동일함)
사용자 정의 변수 액세스
도구 출력에서 전달된 변수는 Bot Connector에서와 동일한 방식으로 액세스할 수 있습니다:
  • State.summary 요약 변수에 대해
  • State.reason 'reason' 변수에 대해
  • State.customVariable 사용자가 정의한 모든 사용자 정의 변수에 대해