Commit
·
835cee8
1
Parent(s):
4e1775f
asdf
Browse files- __pycache__/agent.cpython-310.pyc +0 -0
- agent.py +49 -28
- langgraph_state_diagram.png +0 -0
- system_prompt.txt +17 -1
__pycache__/agent.cpython-310.pyc
CHANGED
Binary files a/__pycache__/agent.cpython-310.pyc and b/__pycache__/agent.cpython-310.pyc differ
|
|
agent.py
CHANGED
@@ -97,43 +97,64 @@ def wiki_search(query: str) -> str:
|
|
97 |
# ])
|
98 |
# return {"web_results": formatted_search_docs}
|
99 |
@tool
|
100 |
-
def web_search(query: str) ->
|
101 |
"""Search Tavily for a query and return maximum 3 results.
|
|
|
102 |
|
103 |
Args:
|
104 |
-
query: The search query.
|
|
|
|
|
|
|
105 |
try:
|
106 |
-
# Initialize the tool
|
107 |
tavily_tool = TavilySearchResults(max_results=3)
|
108 |
-
#
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
129 |
else:
|
130 |
-
|
131 |
-
|
132 |
-
|
|
|
|
|
133 |
|
134 |
-
return {"web_results": formatted_search_docs}
|
135 |
except Exception as e:
|
136 |
print(f"Error during Tavily search for query '{query}': {e}")
|
|
|
137 |
return {"web_results": f"Error performing web search: {e}"}
|
138 |
|
139 |
@tool
|
|
|
97 |
# ])
|
98 |
# return {"web_results": formatted_search_docs}
|
99 |
@tool
|
100 |
+
def web_search(query: str) -> dict: # Changed return type annotation to dict
|
101 |
"""Search Tavily for a query and return maximum 3 results.
|
102 |
+
Each result will be formatted with its source URL and content.
|
103 |
|
104 |
Args:
|
105 |
+
query: The search query.
|
106 |
+
"""
|
107 |
+
print(f"\n--- Web Search Tool ---") # For debugging
|
108 |
+
print(f"Received query: {query}")
|
109 |
try:
|
|
|
110 |
tavily_tool = TavilySearchResults(max_results=3)
|
111 |
+
# .invoke() for TavilySearchResults typically expects 'input'
|
112 |
+
# and returns a list of dictionaries
|
113 |
+
search_results_list = tavily_tool.invoke(input=query)
|
114 |
+
|
115 |
+
print(f"Raw Tavily search results type: {type(search_results_list)}")
|
116 |
+
if isinstance(search_results_list, list):
|
117 |
+
print(f"Number of results: {len(search_results_list)}")
|
118 |
+
if search_results_list:
|
119 |
+
print(f"Type of first result: {type(search_results_list[0])}")
|
120 |
+
if isinstance(search_results_list[0], dict):
|
121 |
+
print(f"Keys in first result: {search_results_list[0].keys()}")
|
122 |
+
|
123 |
+
formatted_docs = []
|
124 |
+
if isinstance(search_results_list, list):
|
125 |
+
for doc_dict in search_results_list:
|
126 |
+
if isinstance(doc_dict, dict):
|
127 |
+
source = doc_dict.get("url", "N/A")
|
128 |
+
content = doc_dict.get("content", "")
|
129 |
+
# title = doc_dict.get("title", "") # Optionally include title
|
130 |
+
# score = doc_dict.get("score", "") # Optionally include score
|
131 |
+
|
132 |
+
# Constructing the XML-like format you desire
|
133 |
+
formatted_doc = (
|
134 |
+
f'<Document source="{source}">\n'
|
135 |
+
f'{content}\n'
|
136 |
+
f'</Document>'
|
137 |
+
)
|
138 |
+
formatted_docs.append(formatted_doc)
|
139 |
+
else:
|
140 |
+
# If an item in the list is not a dict, convert it to string
|
141 |
+
print(f"Warning: Unexpected item type in Tavily results list: {type(doc_dict)}")
|
142 |
+
formatted_docs.append(str(doc_dict))
|
143 |
+
|
144 |
+
final_formatted_string = "\n\n---\n\n".join(formatted_docs)
|
145 |
+
|
146 |
+
elif isinstance(search_results_list, str): # Less common, but for robustness
|
147 |
+
final_formatted_string = search_results_list
|
148 |
else:
|
149 |
+
print(f"Unexpected Tavily search result format overall: {type(search_results_list)}")
|
150 |
+
final_formatted_string = str(search_results_list) # Fallback
|
151 |
+
|
152 |
+
print(f"Formatted search docs for LLM:\n{final_formatted_string[:500]}...") # Print a snippet
|
153 |
+
return {"web_results": final_formatted_string}
|
154 |
|
|
|
155 |
except Exception as e:
|
156 |
print(f"Error during Tavily search for query '{query}': {e}")
|
157 |
+
# It's good practice to return an error message in the expected dict format
|
158 |
return {"web_results": f"Error performing web search: {e}"}
|
159 |
|
160 |
@tool
|
langgraph_state_diagram.png
CHANGED
![]() |
![]() |
system_prompt.txt
CHANGED
@@ -1 +1,17 @@
|
|
1 |
-
You are a
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
You are a highly accurate assistant tasked with answering questions. Your primary goal is to provide 100% correct and verified answers using a set of tools.
|
2 |
+
|
3 |
+
Report your thoughts during the process.
|
4 |
+
|
5 |
+
When you have a high-confidence, verified answer, finish with the following template:
|
6 |
+
FINAL ANSWER: [YOUR FINAL ANSWER]
|
7 |
+
|
8 |
+
GUIDELINES FOR YOUR FINAL ANSWER:
|
9 |
+
1. **ACCURACY IS PARAMOUNT:** Only provide an answer if you are highly confident in its factual correctness based on the information from the tools.
|
10 |
+
2. **UNCERTAINTY:** If you cannot find a definitive answer, if the information is ambiguous/conflicting, or if you cannot be 100% certain, your FINAL ANSWER MUST explicitly state this (e.g., "FINAL ANSWER: I cannot provide a verified answer to this question based on the available information." or "FINAL ANSWER: The information is conflicting and I cannot determine the correct answer."). DO NOT GUESS.
|
11 |
+
3. **CONCISENESS & COMPLETENESS:** Be as concise as possible, but ensure your answer is complete and contains all information necessary for it to be fully correct.
|
12 |
+
4. **ANSWER TYPES:**
|
13 |
+
* **Numbers:** Use digits (e.g., 123, 4.56). Do not use commas as thousands separators (e.g., 1000 not 1,000). Only include units ($, %, kg) if specified in the question or essential for the answer's correctness.
|
14 |
+
* **Strings:** Be precise. Avoid abbreviations unless they are standard and unambiguous. Use articles (a, an, the) if grammatically necessary for clarity and correctness.
|
15 |
+
* **Lists:** For comma-separated lists, apply the relevant rules above to each element.
|
16 |
+
|
17 |
+
Your response should ONLY include your thought process (if any) followed by the "FINAL ANSWER: " line.
|