Skip to content

Commit

Permalink
feat: update ExecutorAgent
Browse files Browse the repository at this point in the history
  • Loading branch information
FacerAin committed Dec 7, 2023
1 parent 235ebe7 commit eab2cfb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
16 changes: 12 additions & 4 deletions app/agent/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down
4 changes: 3 additions & 1 deletion app/agent/prompts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down

0 comments on commit eab2cfb

Please sign in to comment.