Skip to content

Commit b8678aa

Browse files
committed
u
1 parent c5cd150 commit b8678aa

4 files changed

Lines changed: 59 additions & 18 deletions

File tree

praisonai_tools/tools/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ def __getattr__(name):
9797
# Tavily
9898
"TavilyTool": "tavily_tool",
9999
"tavily_search": "tavily_tool",
100+
"tavily_extract": "tavily_tool",
100101
# Wikipedia
101102
"WikipediaTool": "wikipedia_tool",
102103
"wikipedia_search": "wikipedia_tool",
@@ -494,6 +495,7 @@ def __getattr__(name):
494495
# Tavily Tool
495496
"TavilyTool",
496497
"tavily_search",
498+
"tavily_extract",
497499
# Wikipedia Tool
498500
"WikipediaTool",
499501
"wikipedia_search",

praisonai_tools/tools/duckduckgo_tool.py

Lines changed: 44 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,16 @@ def run(
5151
else:
5252
return {"error": f"Unknown action: {action}"}
5353

54-
def search(self, query: str, max_results: int = 5) -> List[Dict[str, Any]]:
55-
"""Search the web."""
54+
def search(self, query: str, max_results: int = 5, retries: int = 3) -> List[Dict[str, Any]]:
55+
"""Search the web with retry logic.
56+
57+
Args:
58+
query: Search query
59+
max_results: Maximum results to return
60+
retries: Number of retry attempts on failure
61+
"""
62+
import time
63+
5664
if not query:
5765
return [{"error": "query is required"}]
5866

@@ -61,21 +69,40 @@ def search(self, query: str, max_results: int = 5) -> List[Dict[str, Any]]:
6169
except ImportError:
6270
return [{"error": "duckduckgo-search not installed. Install with: pip install duckduckgo-search"}]
6371

64-
try:
65-
with DDGS(proxy=self.proxy, timeout=self.timeout) as ddgs:
66-
results = list(ddgs.text(query, max_results=max_results))
67-
68-
return [
69-
{
70-
"title": r.get("title"),
71-
"url": r.get("href"),
72-
"snippet": r.get("body"),
73-
}
74-
for r in results
75-
]
76-
except Exception as e:
77-
logger.error(f"DuckDuckGo search error: {e}")
78-
return [{"error": str(e)}]
72+
last_error = None
73+
retry_delay = 1.0
74+
75+
for attempt in range(retries):
76+
try:
77+
with DDGS(proxy=self.proxy, timeout=self.timeout) as ddgs:
78+
results = list(ddgs.text(query, max_results=max_results))
79+
80+
if results:
81+
return [
82+
{
83+
"title": r.get("title"),
84+
"url": r.get("href"),
85+
"snippet": r.get("body"),
86+
}
87+
for r in results
88+
]
89+
90+
# Empty results - retry
91+
if attempt < retries - 1:
92+
logger.debug(f"DuckDuckGo returned empty, retrying ({attempt + 1}/{retries})...")
93+
time.sleep(retry_delay * (attempt + 1))
94+
95+
except Exception as e:
96+
last_error = e
97+
logger.debug(f"DuckDuckGo attempt {attempt + 1} failed: {e}")
98+
if attempt < retries - 1:
99+
time.sleep(retry_delay * (attempt + 1))
100+
101+
# All retries exhausted
102+
if last_error:
103+
logger.error(f"DuckDuckGo search error after {retries} attempts: {last_error}")
104+
return [{"error": str(last_error)}]
105+
return [{"error": f"No results after {retries} attempts"}]
79106

80107
def news(self, query: str, max_results: int = 5) -> List[Dict[str, Any]]:
81108
"""Get news articles."""

praisonai_tools/tools/tavily_tool.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,3 +158,15 @@ def extract(self, urls: str) -> List[Dict[str, Any]]:
158158
def tavily_search(query: str, max_results: int = 5) -> Dict[str, Any]:
159159
"""Search with Tavily."""
160160
return TavilyTool().search(query=query, max_results=max_results)
161+
162+
163+
def tavily_extract(urls: str) -> List[Dict[str, Any]]:
164+
"""Extract content from URLs using Tavily.
165+
166+
Args:
167+
urls: Comma-separated list of URLs to extract content from
168+
169+
Returns:
170+
List of dicts with url and content keys
171+
"""
172+
return TavilyTool().extract(urls=urls)

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "praisonai-tools"
3-
version = "0.2.12"
3+
version = "0.2.13"
44
description = "Extended tools for PraisonAI Agents"
55
authors = [
66
{name = "Mervin Praison"}

0 commit comments

Comments
 (0)