Untitled
def email_confirmation_tool(user_query, state: Annotated[dict, InjectedState], config: RunnableConfig) -> str: """ Tool that handles and confirms the details for sending an email, such as recipients (To), CC, subject, and the email body (reply content). Args: user_query (str): The user's request related to sending an email. state (dict): The current conversation state, including messages exchanged with the user for context. """ access_token = config["configurable"]["access_token"] workspace_user_details_url = f"{xnode_auth_url}/user/get_all_users" response = requests.request("GET", workspace_user_details_url, headers={'Authorization': f"Bearer {access_token}"}) if response.status_code == 200: user_data_json = response.json() user_to_email = {f"{user['first_name']} {user['last_name']}": user['email'] for user in user_data_json} else: return "Failed fetching user details" llm = model_categories["l_model"] # Prompt template for processing email details email_compose_prompt = PromptTemplate( template=""" You are a system that processes a user's request to send an email. The user said: {query}. the user_to_email map {user_to_email} and use the conversation {conversation_history} to clarify and confirm the following email details: 1. "To" (Primary Recipients): - If recipients are mentioned, list them clearly. - If not, ask the user to specify who they want to send this email to. - Allow the user to provide any custom email addresses. 2. "CC" (Optional Recipients): - If the user mentions CC recipients, list them out. - If not, clarify whether anyone should be CC'd. 3. "Subject": - Confirm the subject if it is provided. - If no subject is given, clarify the subject of the email. 4. "Email Body" (Reply Content): - If the user provided a body, confirm it. - If not, clarify the email body that needs to be sent. Make sure to resolve any missing or ambiguous information regarding recipients, CC, subject, or body. Do not include any greetings or sign-offs. If there is ambiguity about which user to send the email due to similar names, ask for clarification. If there is a closely matching name (e.g., the user says 'john' but only 'john_doe' exists), consider them as part of the primary recipients. """, input_variables=["query", "conversation_history","user_to_email"] ) # Build the chain to parse the user's request chain = email_compose_prompt | llm | StrOutputParser() # Invoke the chain with the necessary inputs response = chain.invoke({ "query": user_query, "conversation_history": state["messages"], "user_to_email":user_to_email, }) return response Can you fix the prompt
Leave a Comment