Update langgraph_agent.py
Browse files- langgraph_agent.py +14 -6
langgraph_agent.py
CHANGED
|
@@ -40,12 +40,20 @@ def modulus(a: int, b: int) -> int:
|
|
| 40 |
@tool
|
| 41 |
def wiki_search(query: str) -> dict:
|
| 42 |
"""Search Wikipedia for a query and return up to 2 documents."""
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
|
| 50 |
@tool
|
| 51 |
def web_search(query: str) -> dict:
|
|
|
|
| 40 |
@tool
|
| 41 |
def wiki_search(query: str) -> dict:
|
| 42 |
"""Search Wikipedia for a query and return up to 2 documents."""
|
| 43 |
+
try:
|
| 44 |
+
docs = WikipediaLoader(query=query, load_max_docs=2, lang="en").load() # Added lang="en" for clarity
|
| 45 |
+
if not docs:
|
| 46 |
+
return {"wiki_results": f"No documents found on Wikipedia for '{query}'."}
|
| 47 |
+
formatted = "\n\n---\n\n".join(
|
| 48 |
+
f'<Document source="{d.metadata.get("source", "N/A")}"/>\n{d.page_content}' # Added .get for safety
|
| 49 |
+
for d in docs
|
| 50 |
+
)
|
| 51 |
+
return {"wiki_results": formatted}
|
| 52 |
+
except Exception as e:
|
| 53 |
+
# Log the full error for debugging if possible
|
| 54 |
+
print(f"Error in wiki_search tool: {e}")
|
| 55 |
+
return {"wiki_results": f"Error occurred while searching Wikipedia for '{query}'. Details: {str(e)}"}
|
| 56 |
+
|
| 57 |
|
| 58 |
@tool
|
| 59 |
def web_search(query: str) -> dict:
|