Update research_agent.py
Browse files- research_agent.py +7 -9
research_agent.py
CHANGED
|
@@ -17,22 +17,22 @@ class ResearchAgent(BaseAgent):
|
|
| 17 |
|
| 18 |
def __call__(self, question: str, **kwargs) -> str:
|
| 19 |
print(f"Research agent processing question: {question[:100]}...")
|
| 20 |
-
|
| 21 |
-
# First, try structured scraping if the question looks like a list/data question
|
| 22 |
-
# structured_answer = self.try_structured_wikipedia_scrape(question)
|
| 23 |
-
# if structured_answer:
|
| 24 |
-
# return structured_answer
|
| 25 |
|
| 26 |
-
#
|
| 27 |
search_query = self.extract_search_query(question)
|
| 28 |
# print(f"Extracted search query: {search_query}")
|
|
|
|
|
|
|
| 29 |
answer = self.try_structured_wikipedia_scrape(search_query)
|
| 30 |
-
print(f"Structured answer: {answer}")
|
| 31 |
if not answer:
|
| 32 |
# If structured answer is not found, perform a web search
|
| 33 |
search_results = self.search_web(search_query)
|
| 34 |
answer = self.format_search_results(search_results)
|
| 35 |
|
|
|
|
|
|
|
|
|
|
| 36 |
system_prompt = """
|
| 37 |
You are a research expert tasked with answering factual questions based on search results.
|
| 38 |
Analyze the search results carefully and extract the information needed to answer the question accurately.
|
|
@@ -40,8 +40,6 @@ class ResearchAgent(BaseAgent):
|
|
| 40 |
Provide a concise, accurate answer based only on the provided information.
|
| 41 |
You must provide only the exact answer requested by the user, in the correct type and minimal format, based purely on the provided information.
|
| 42 |
|
| 43 |
-
Finish your answer with the following template: FINAL ANSWER: [YOUR FINAL ANSWER].
|
| 44 |
-
|
| 45 |
YOUR FINAL ANSWER should be a number OR as few words as possible OR a comma separated list of numbers and/or strings.
|
| 46 |
If you are asked for a number, don't use comma to write your number neither use units such as $ or percent sign unless specified otherwise.
|
| 47 |
If you are asked for a string, don't use articles, neither abbreviations (e.g. for cities), and write the digits in plain text unless specified otherwise.
|
|
|
|
| 17 |
|
| 18 |
def __call__(self, question: str, **kwargs) -> str:
|
| 19 |
print(f"Research agent processing question: {question[:100]}...")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
+
# First extract the search query using LLM
|
| 22 |
search_query = self.extract_search_query(question)
|
| 23 |
# print(f"Extracted search query: {search_query}")
|
| 24 |
+
|
| 25 |
+
# Then try to search Wikipedia
|
| 26 |
answer = self.try_structured_wikipedia_scrape(search_query)
|
| 27 |
+
# print(f"Structured answer: {answer}")
|
| 28 |
if not answer:
|
| 29 |
# If structured answer is not found, perform a web search
|
| 30 |
search_results = self.search_web(search_query)
|
| 31 |
answer = self.format_search_results(search_results)
|
| 32 |
|
| 33 |
+
|
| 34 |
+
# Now over to LLM again to interpret the result and give final answer
|
| 35 |
+
|
| 36 |
system_prompt = """
|
| 37 |
You are a research expert tasked with answering factual questions based on search results.
|
| 38 |
Analyze the search results carefully and extract the information needed to answer the question accurately.
|
|
|
|
| 40 |
Provide a concise, accurate answer based only on the provided information.
|
| 41 |
You must provide only the exact answer requested by the user, in the correct type and minimal format, based purely on the provided information.
|
| 42 |
|
|
|
|
|
|
|
| 43 |
YOUR FINAL ANSWER should be a number OR as few words as possible OR a comma separated list of numbers and/or strings.
|
| 44 |
If you are asked for a number, don't use comma to write your number neither use units such as $ or percent sign unless specified otherwise.
|
| 45 |
If you are asked for a string, don't use articles, neither abbreviations (e.g. for cities), and write the digits in plain text unless specified otherwise.
|