File size: 1,908 Bytes
a759596
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
from langchain_core.tools import tool
from pydantic import BaseModel, Field
from typing import Literal

class TransferCallArgs(BaseModel):
    destination: Literal["sales", "service", "parts"] = Field(
        description="The department the call is being transferred to."
    )

@tool(args_schema=TransferCallArgs)
def transfer_call(destination: str):
    """Transfer the call to a real person or department."""
    return f"Attempting to transfer call to {destination}..."

class LeaveMessageArgs(BaseModel):
    first_name: str = Field(description="The first name of the customer leaving the message.")
    last_name: str = Field(description="The last name or initial of the customer leaving the message.")
    phone_number: str = Field(description="The phone number of the customer, used for sending confirmation and any follow-up information.")
    message: str = Field(description="The content of the message left by the customer.")
    sms_consent: bool = Field(description="The customer's consent to receive confirmation and further communication via text about their message.")
    destination: str = Field(description="The department to which the message is being sent.")

@tool(args_schema=LeaveMessageArgs)
def leave_message(
    first_name: str,
    last_name: str,
    phone_number: str,
    message: str,
    sms_consent: bool,
    destination: str,
):
    """Allows a customer to leave a message for a department."""
    return f"Message for {destination} from {first_name} {last_name} ({phone_number}): '{message}'. SMS consent: {sms_consent}"

class GoToArgs(BaseModel):
    destination: Literal["customer_search_function", "service_intermediate"] = Field(
        description="The target node to transition to."
    )

@tool(args_schema=GoToArgs)
def go_to(destination: str):
    """Transition to another node in the conversation graph."""
    return f"Transitioning to {destination}..."