2026-03-13 20:09:08 +01:00
from modules . web_search import perform_web_search
2026-03-12 20:02:57 +01:00
tool = {
" type " : " function " ,
" function " : {
" name " : " web_search " ,
2026-03-13 20:09:08 +01:00
" description " : " Search the web using DuckDuckGo and return a list of result titles and URLs. Use fetch_webpage to read the contents of a specific result. " ,
2026-03-12 20:02:57 +01:00
" parameters " : {
" type " : " object " ,
" properties " : {
" query " : { " type " : " string " , " description " : " The search query. " } ,
2026-03-13 20:09:08 +01:00
" num_pages " : { " type " : " integer " , " description " : " Number of search results to return (default: 3). " } ,
2026-03-12 20:02:57 +01:00
} ,
" required " : [ " query " ]
}
}
}
def execute ( arguments ) :
query = arguments . get ( " query " , " " )
2026-03-13 02:17:23 +01:00
num_pages = arguments . get ( " num_pages " , 3 )
2026-03-13 20:09:08 +01:00
results = perform_web_search ( query , num_pages = num_pages , fetch_content = False )
2026-03-12 20:02:57 +01:00
output = [ ]
for r in results :
2026-03-13 20:09:08 +01:00
if r :
output . append ( { " title " : r [ " title " ] , " url " : r [ " url " ] } )
2026-03-12 20:02:57 +01:00
return output if output else [ { " error " : " No results found. " } ]