2026-03-13 01:10:41 +01:00
|
|
|
from modules.web_search import perform_web_search, truncate_content_by_tokens
|
2026-03-12 20:02:57 +01:00
|
|
|
|
|
|
|
|
tool = {
|
|
|
|
|
"type": "function",
|
|
|
|
|
"function": {
|
|
|
|
|
"name": "web_search",
|
|
|
|
|
"description": "Search the web using DuckDuckGo and return page contents.",
|
|
|
|
|
"parameters": {
|
|
|
|
|
"type": "object",
|
|
|
|
|
"properties": {
|
|
|
|
|
"query": {"type": "string", "description": "The search query."},
|
|
|
|
|
},
|
|
|
|
|
"required": ["query"]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def execute(arguments):
|
|
|
|
|
query = arguments.get("query", "")
|
|
|
|
|
results = perform_web_search(query, num_pages=3)
|
|
|
|
|
output = []
|
|
|
|
|
for r in results:
|
|
|
|
|
if r and r["content"].strip():
|
2026-03-13 01:10:41 +01:00
|
|
|
output.append({"title": r["title"], "url": r["url"], "content": truncate_content_by_tokens(r["content"])})
|
2026-03-12 20:02:57 +01:00
|
|
|
|
|
|
|
|
return output if output else [{"error": "No results found."}]
|