Skip to content

Building AI agents, atomically

style: run black to auto-format, pass black check + flake8

ueveu2116edf90a7d
diff --git a/atomic-forge/atomic_tools/tavily_search/tests/test_tavily_search.py b/atomic-forge/atomic_tools/tavily_search/tests/test_tavily_search.py
index 311e124..6dddb77 100644
--- a/atomic-forge/atomic_tools/tavily_search/tests/test_tavily_search.py
+++ b/atomic-forge/atomic_tools/tavily_search/tests/test_tavily_search.py
@@ -19,9 +19,7 @@ def tool(mock_config):
class TestTavilySearchTool:
@pytest.mark.asyncio
- async def test_fetch_search_results_respects_max_results_override(
- self, tool
- ):
+ async def test_fetch_search_results_respects_max_results_override(self, tool):
"""Regression test: max_results override must propagate to the API call, not be ignored."""
mock_session = AsyncMock()
mock_response = AsyncMock()
@@ -45,16 +43,12 @@ class TestTavilySearchTool:
mock_session.__aenter__ = AsyncMock(return_value=mock_session)
mock_session.__aexit__ = AsyncMock(return_value=None)
- await tool._fetch_search_results(
- mock_session, "test query", max_results=2
- )
+ await tool._fetch_search_results(mock_session, "test query", max_results=2)
# The key assertion: the API must have been called with max_results=2, not self.max_results=5
call_args = mock_session.post.call_args
json_data = call_args.kwargs["json"]
- assert (
- json_data["max_results"] == 2
- ), "max_results override was ignored in API call"
+ assert json_data["max_results"] == 2, "max_results override was ignored in API call"
@pytest.mark.asyncio
async def test_run_async_respects_max_results_override(self, tool):
@@ -75,9 +69,7 @@ class TestTavilySearchTool:
"content": "...",
"score": 1.0,
}
- for i in range(
- max_override + 3
- ) # Return MORE than requested
+ for i in range(max_override + 3) # Return MORE than requested
],
"answer": "test answer",
}
@@ -129,9 +121,7 @@ class TestTavilySearchTool:
await tool.run_async(params) # No max_results override
for call in mock_session.post.call_args_list:
- assert (
- call.kwargs["json"]["max_results"] == 5
- ) # Should use config default (5)
+ assert call.kwargs["json"]["max_results"] == 5 # Should use config default (5)
def test_init_defaults(self):
"""Default config should set max_results to 5."""
diff --git a/atomic-forge/atomic_tools/tavily_search/tool/tavily_search.py b/atomic-forge/atomic_tools/tavily_search/tool/tavily_search.py
index 199c5e0..ad00fdf 100644
--- a/atomic-forge/atomic_tools/tavily_search/tool/tavily_search.py
+++ b/atomic-forge/atomic_tools/tavily_search/tool/tavily_search.py
@@ -29,27 +29,17 @@ class TavilySearchResultItemSchema(BaseIOSchema):
title: str = Field(..., description="The title of the search result")
url: str = Field(..., description="The URL of the search result")
- content: str = Field(
- None, description="The content snippet of the search result"
- )
+ content: str = Field(None, description="The content snippet of the search result")
score: float = Field(..., description="The score of the search result")
- raw_content: Optional[str] = Field(
- None, description="The raw content of the search result"
- )
- query: Optional[str] = Field(
- ..., description="The query used to obtain this search result"
- )
- answer: Optional[str] = Field(
- ..., description="The answer to the query provided by Tavily"
- )
+ raw_content: Optional[str] = Field(None, description="The raw content of the search result")
+ query: Optional[str] = Field(..., description="The query used to obtain this search result")
+ answer: Optional[str] = Field(..., description="The answer to the query provided by Tavily")
class TavilySearchToolOutputSchema(BaseIOSchema):
"""This schema represents the output of the Tavily search tool."""
- results: List[TavilySearchResultItemSchema] = Field(
- ..., description="List of search result items"
- )
+ results: List[TavilySearchResultItemSchema] = Field(..., description="List of search result items")
##############
@@ -63,9 +53,7 @@ class TavilySearchToolConfig(BaseToolConfig):
exclude_domains: Optional[List[str]] = None
-class TavilySearchTool(
- BaseTool[TavilySearchToolInputSchema, TavilySearchToolOutputSchema]
-):
+class TavilySearchTool(BaseTool[TavilySearchToolInputSchema, TavilySearchToolOutputSchema]):
"""
Tool for performing searches using the Tavily search API.
@@ -76,9 +64,7 @@ class TavilySearchTool(
api_key (str): The API key for the Tavily API.
"""
- def __init__(
- self, config: TavilySearchToolConfig = TavilySearchToolConfig()
- ):
+ def __init__(self, config: TavilySearchToolConfig = TavilySearchToolConfig()):
"""
Initializes the TavilySearchTool.
@@ -94,9 +80,7 @@ class TavilySearchTool(
self.exclude_domains = config.exclude_domains
self.include_answer = False
- async def _fetch_search_results(
- self, session: aiohttp.ClientSession, query: str, max_results: int
- ) -> dict:
+ async def _fetch_search_results(self, session: aiohttp.ClientSession, query: str, max_results: int) -> dict:
headers = {
"accept": "/",
"content-type": "application/json",
@@ -119,9 +103,7 @@ class TavilySearchTool(
"include_answer": self.include_answer,
}
- async with session.post(
- "https://api.tavily.com/search", headers=headers, json=json_data
- ) as response:
+ async with session.post("https://api.tavily.com/search", headers=headers, json=json_data) as response:
if response.status != 200:
error_message = await response.text()
raise Exception(
@@ -144,17 +126,10 @@ class TavilySearchTool(
params: TavilySearchToolInputSchema,
max_results: Optional[int] = None,
) -> TavilySearchToolOutputSchema:
- effective_max_results = (
- self.max_results if max_results is None else max_results
- )
+ effective_max_results = self.max_results if max_results is None else max_results
async with aiohttp.ClientSession() as session:
- tasks = [
- self._fetch_search_results(
- session, query, effective_max_results
- )
- for query in params.queries
- ]
+ tasks = [self._fetch_search_results(session, query, effective_max_results) for query in params.queries]
raw_responses = await asyncio.gather(*tasks)
processed_results = []
@@ -164,10 +139,7 @@ class TavilySearchTool(
query_processed = []
for result in query_results:
- if all(
- key in result
- for key in ["title", "url", "content", "score"]
- ):
+ if all(key in result for key in ["title", "url", "content", "score"]):
query_processed.append(
TavilySearchResultItemSchema(
title=result["title"],