113 lines
4.2 KiB
Python
113 lines
4.2 KiB
Python
# from langchain_core.tools import tool
|
|
from langchain_community.tools.gmail.utils import (
|
|
build_resource_service,
|
|
get_gmail_credentials,
|
|
)
|
|
from langchain_community.agent_toolkits import GmailToolkit
|
|
from langchain import hub
|
|
from langchain_community.tools.tavily_search import TavilySearchResults
|
|
from dotenv import load_dotenv
|
|
from langchain.agents import AgentExecutor, create_openai_functions_agent
|
|
from langchain_tools.agent_tools import (
|
|
multiply, redact_email, list_calendar_events,
|
|
create_calendar_event,
|
|
# create_quick_add_event,
|
|
send_message, get_company_info,
|
|
get_current_date_and_time
|
|
)
|
|
|
|
|
|
class AgentTools:
|
|
|
|
def load_tools(self) -> list:
|
|
|
|
toolkit = GmailToolkit()
|
|
|
|
# Can review scopes here
|
|
# https://developers.google.com/gmail/api/auth/scopes
|
|
# For instance, readonly scope is
|
|
# 'https://www.googleapis.com/auth/gmail.readonly'
|
|
credentials = get_gmail_credentials(
|
|
token_file="token.json",
|
|
scopes=["https://mail.google.com/"],
|
|
client_secrets_file="credentials.json",)
|
|
api_resource = build_resource_service(credentials=credentials)
|
|
toolkit = GmailToolkit(api_resource=api_resource)
|
|
|
|
# creamos la lista de herramientas de gmail
|
|
tools = toolkit.get_tools()
|
|
|
|
load_dotenv()
|
|
|
|
# Agregamos otras tools
|
|
search = TavilySearchResults(max_results=1)
|
|
|
|
tools.append(search)
|
|
tools.append(multiply)
|
|
tools.append(redact_email)
|
|
tools.append(list_calendar_events)
|
|
tools.append(create_calendar_event)
|
|
tools.append(send_message)
|
|
tools.append(get_company_info),
|
|
tools.append(get_current_date_and_time)
|
|
# tools.append(create_quick_add_event)
|
|
|
|
return tools
|
|
|
|
def load_agent(self, llm, tools):
|
|
instructions = """
|
|
You are the virtual assistant of OneCluster, a company specialized in
|
|
providing custom development services focused on creating personalized
|
|
technological solutions for businesses and companies.
|
|
Your mission is to offer a warm, friendly,
|
|
and collaborative service that always
|
|
reflects OneCluster's core values.
|
|
|
|
**User Interactions:**
|
|
1. **Initial Greeting:** When starting an interaction with a user,
|
|
greet them courteously and identify who you have the pleasure of
|
|
speaking with. Once you know the user's name, address them respectfully
|
|
throughout the conversation.
|
|
|
|
2. **Providing Information:** You have the ability to offer clear and
|
|
detailed information about the services provided by OneCluster.
|
|
Make sure to be concise yet informative,
|
|
adapting the information to the user's needs.
|
|
|
|
3. **Appointment Scheduling:** You are responsible for scheduling
|
|
appointments for clients. Before confirming an appointment,
|
|
always check the availability on OneCluster's
|
|
calendar to ensure there is space,
|
|
and check the current date and time so that
|
|
you have a clear sense of time.
|
|
Request an email address from the user to schedule the appointment.
|
|
|
|
4. **Handling Unanswered Questions:** If you do not know how to
|
|
answer a question, politely ask for the client's contact information
|
|
and clearly identify the problem to be resolved.
|
|
Then, send this information to oneclustererp@gmail.com with the subject
|
|
"Unresolved customer query by the agent."
|
|
Inform the client that you do not have the information at your
|
|
disposal but that you can escalate the request to the support team,
|
|
who will respond promptly.
|
|
|
|
**Style and Tone:**
|
|
Maintain a tone that is always friendly, approachable, and
|
|
professional. Each interaction should reflect OneCluster's
|
|
commitment to innovation, adaptability, and ongoing collaboration.
|
|
"""
|
|
|
|
base_prompt = hub.pull("langchain-ai/openai-functions-template")
|
|
|
|
prompt = base_prompt.partial(instructions=instructions)
|
|
|
|
agent = create_openai_functions_agent(llm, tools, prompt)
|
|
|
|
agent_executor = AgentExecutor(
|
|
agent=agent,
|
|
tools=tools,
|
|
verbose=True,
|
|
)
|
|
|
|
return agent_executor
|