diff --git a/app/agent/agent.py b/app/agent/agent.py index 274c8a7..6f6473f 100644 --- a/app/agent/agent.py +++ b/app/agent/agent.py @@ -8,7 +8,7 @@ from langchain_core.messages import SystemMessage from app.agent.parser import CustomAgentOutputParser -from app.agent.prompts import retriever_prompt_template, system_message +from app.agent.prompts import AgentPromptTemplate, agent_prompt_template, retriever_prompt_template from app.agent.retriever import PineconeRetriever from app.agent.tools import get_meal_info, get_today_date from app.core.config import settings @@ -41,12 +41,20 @@ def __init__(self): ), ] - self.agent_prompt = OpenAIFunctionsAgent.create_prompt(system_message=SystemMessage(content=system_message)) + self.agent_prompt = AgentPromptTemplate( + template=agent_prompt_template, + tools=self.tools, + input_variables=["input", "intermediate_steps"], + ) self.output_parser = CustomAgentOutputParser() - self.agent = OpenAIFunctionsAgent(llm=self.llm, tools=self.tools, prompt=self.agent_prompt) + llm_chain = LLMChain(llm=self.llm, prompt=self.agent_prompt) + tool_names = [tool.name for tool in self.tools] + self.agent = LLMSingleActionAgent( + llm_chain=llm_chain, output_parser=self.output_parser, stop=["\nObservation:"], allowed_tools=tool_names + ) self.executor = AgentExecutor.from_agent_and_tools( - agent=self.agent, tools=self.tools, verbose=True, max_iterations=2 + agent=self.agent, tools=self.tools, verbose=True, max_iterations=5 ) def run(self, query): diff --git a/app/agent/prompts.py b/app/agent/prompts.py index 2398b90..535f1c5 100644 --- a/app/agent/prompts.py +++ b/app/agent/prompts.py @@ -5,11 +5,13 @@ system_message = """You are a helpful assistant for Kyung Hee University students. Answer the following questions as best you can. If a page_url is provided in the document, please also provide a link to the related page. -Remember to speak in a korean when giving your final answer. +Remember to speak in a korean when giving your final answer. Don’t change ‘컴퓨터공학과’ to '콘피유터공학과' when searching. Use words that are likely to be advantageous for information retrieval. +If the user includes a specific date in the question, use the today_date tool to search using the date including numbers. """ agent_prompt_template = """You are a helpful assistant for Kyung Hee University students. Answer the following questions as best you can. If a page_url is provided in the document, please also provide a link to the related page. +If the user includes a specific date in the question, use the today_date tool to search using the date including numbers. like '내년' -> 2024년, '올해' -> 2023년 You have access to the following tools: {tools}