Untitled
@tool 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. config (RunnableConfig): Configuration details (e.g., user timezone) if needed. No initial API call is performed in this tool. Workflow: 1. Gathers recipients for the "To" field: - Allows for custom email addresses if the user provides them. - If no addresses are specified, asks the user to clarify who should receive the email. 2. Gathers recipients for the "CC" field: - Treats it as optional. - If no CC is specified, prompts the user to confirm whether or not they want to CC anyone. 3. Confirms or generates the email subject: - If a subject is provided, confirms it. - If missing, proposes one based on the context and asks the user for confirmation. 4. Confirms or generates the email body (reply content): - If a body is provided, confirms it. - If missing, proposes content based on the context and asks the user for confirmation. The tool returns a response that clarifies all missing or ambiguous details before finalizing the email. It does not include sign-offs or greetings, and it does not make an API call to send the email. """ 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}. Use the conversation history {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, propose one based on the conversation context and ask for confirmation. 4. "Email Body" (Reply Content): - If the user provided a body, confirm it. - If not, generate a brief body based on the context and request confirmation. Make sure to resolve any missing or ambiguous information regarding recipients, CC, subject, or body. Do not include any greetings or sign-offs. """, input_variables=["query", "conversation_history"] ) # 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"], }) return response
Leave a Comment