Skip to content

Building AI agents, atomically

fix(forge): keep ArxivSearchTool results inside the requested category (#316)

Darsh Joshieb257d2d13cd
diff --git a/atomic-forge/tools/arxiv_search/tests/test_arxiv_search.py b/atomic-forge/tools/arxiv_search/tests/test_arxiv_search.py
index 2f27794..7e3e46f 100644
--- a/atomic-forge/tools/arxiv_search/tests/test_arxiv_search.py
+++ b/atomic-forge/tools/arxiv_search/tests/test_arxiv_search.py
@@ -61,11 +61,16 @@ def test_build_search_query_with_field_prefix(tool):
def test_build_search_query_with_category(tool):
- assert tool._build_search_query("RAG", "cs.AI") == "all:RAG AND cat:cs.AI"
+ assert tool._build_search_query("RAG", "cs.AI") == "(all:RAG) AND cat:cs.AI"
+
+
+def test_build_search_query_groups_a_multi_word_query_before_the_category(tool):
+ assert tool._build_search_query("diffusion model", "cs.CV") == "(all:diffusion model) AND cat:cs.CV"
+ assert tool._build_search_query("ti:RAG OR abs:agents", "cs.AI") == "(ti:RAG OR abs:agents) AND cat:cs.AI"
def test_build_search_query_field_prefix_and_category(tool):
- assert tool._build_search_query("ti:RAG", "cs.AI") == "ti:RAG AND cat:cs.AI"
+ assert tool._build_search_query("ti:RAG", "cs.AI") == "(ti:RAG) AND cat:cs.AI"
def test_extract_id_strips_version_and_url(tool):
diff --git a/atomic-forge/tools/arxiv_search/tool/arxiv_search.py b/atomic-forge/tools/arxiv_search/tool/arxiv_search.py
index 54b6db6..15792e7 100644
--- a/atomic-forge/tools/arxiv_search/tool/arxiv_search.py
+++ b/atomic-forge/tools/arxiv_search/tool/arxiv_search.py
@@ -110,7 +110,10 @@ class ArxivSearchTool(BaseTool[ArxivSearchToolInputSchema, ArxivSearchToolOutput
else:
base = f"all:{query}"
if category:
- base = f"{base} AND cat:{category}"
+ # Group the query: arXiv binds `all:` to the first word only and gives AND
+ # precedence, so "all:diffusion model AND cat:cs.CV" also matches any paper
+ # mentioning "diffusion" in another category.
+ base = f"({base}) AND cat:{category}"
return base
@staticmethod