Skip to content

Commit 28084f7

Browse files
committed
feat: websearch tool added
1 parent 40bb04b commit 28084f7

4 files changed

Lines changed: 64 additions & 4 deletions

File tree

.github/workflows/publish.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ jobs:
3434
TAG_NAME="${{ github.event.release.tag_name }}"
3535
if [ -z "$TAG_NAME" ]; then
3636
echo "No release tag found. Generating dev version."
37-
VERSION="0.1.2.dev${{ github.run_number }}"
37+
VERSION="0.1.3.dev${{ github.run_number }}"
3838
else
3939
echo "GitHub Release Tag: $TAG_NAME"
4040
VERSION=$(echo "$TAG_NAME" | sed 's/^v//')

nexus/tools/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
from nexus.tools.file_ops import file_tools
77
from nexus.tools.mode import mode_tools
88
from nexus.tools.shell import shell_tools
9+
from nexus.tools.web_search import search_tools
910

10-
all_tools: list = file_tools + shell_tools + mode_tools
11+
all_tools: list = file_tools + shell_tools + mode_tools + search_tools
1112

12-
__all__: list[str] = ["all_tools", "file_tools", "mode_tools", "shell_tools"]
13+
__all__: list[str] = ["all_tools", "file_tools", "mode_tools", "search_tools", "shell_tools"]

nexus/tools/web_search.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
"""Web Search Tools.
2+
3+
LangChain tools for web search functionality using DDGS.
4+
"""
5+
6+
from typing import Annotated
7+
8+
from ddgs import DDGS
9+
from langchain_core.tools import tool
10+
11+
12+
@tool
13+
def web_search(
14+
query: Annotated[str, "Search query to execute"],
15+
max_results: Annotated[int, "Maximum number of results to return"] = 5,
16+
) -> str:
17+
"""Web Search.
18+
19+
Execute a web search using DuckDuckGo and return formatted results.
20+
21+
Args:
22+
query: str - The search query string.
23+
max_results: int - Maximum number of results to return (default: 5).
24+
25+
Returns:
26+
str - Formatted search results or error message.
27+
28+
Raises:
29+
None
30+
"""
31+
32+
try:
33+
results: list[str] = []
34+
with DDGS() as ddgs:
35+
search_results = ddgs.text(
36+
keywords=query,
37+
max_results=max_results,
38+
)
39+
40+
for index, result in enumerate(search_results, start=1):
41+
title = result.get("title", "No Title")
42+
href = result.get("href", "No URL")
43+
body = result.get("body", "No Description")
44+
results.append(f"{index}. {title}\n URL: {href}\n {body}\n")
45+
46+
if not results:
47+
return "No results found."
48+
49+
return "\n".join(results)
50+
51+
except Exception as e: # noqa: BLE001
52+
return f"Error performing web search: {e!s}"
53+
54+
55+
search_tools: list = [web_search]
56+
57+
58+
__all__: list[str] = ["search_tools", "web_search"]

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "agent-nexus-cli"
3-
version = "0.1.2"
3+
version = "0.1.3"
44
description = "Nexus is an autonomous CLI coding agent powered by LangGraph and MCP. It plans complex tasks, persists context via SQLite, and securely orchestrates tools. Features specialized Architect/Code modes, real-time metrics, and human-in-the-loop safety for production workflows."
55
readme = "readme.md"
66
requires-python = ">=3.14.2"
@@ -16,6 +16,7 @@ classifiers = [
1616
urls = { Homepage = "https://github.com/datarohit/nexus" }
1717
dependencies = [
1818
"aiosqlite==0.22.1",
19+
"ddgs==9.10.0",
1920
"httpx==0.28.1",
2021
"langchain==1.2.7",
2122
"langchain-community==0.4.1",

0 commit comments

Comments
 (0)