1+ import open_taranis as T
2+ from open_taranis .tools import brave_research , fast_scraping
13
4+ client = T .clients .openrouter (api_key = None )
5+ request = T .clients .openrouter_request
6+
7+ messages = [
8+ T .create_system_prompt ("""You are an autonomous AI web search agent.
9+ For example, you can search for URLs in Brave and scrape them to obtain all their content.
10+
11+ Don't hesitate to conduct in-depth searches, such as navigating from site to site using the URLs you find there, and so on.
12+ Make as many function calls as needed for the tasks the user assigns you.
13+ You must execute them flawlessly and never cheat; complete your mission successfully!""" ),
14+ T .create_user_prompt (input ("Request : " ))
15+ ]
16+
17+ run = True
18+
19+ while run :
20+ respond = ""
21+
22+ for token , tool_calls , run in T .handle_streaming (request (
23+ client = client ,messages = messages ,model = "nvidia/nemotron-3-nano-30b-a3b:free" ,
24+ tools = T .functions_to_tools ([brave_research ,fast_scraping ])
25+ )):
26+ if token :
27+ print (token , end = "" )
28+ respond += token
29+
30+ if run :
31+ messages .append (T .create_assistant_response (respond , tool_calls ))
32+
33+ for tool_call in tool_calls :
34+ fid , fname , args , _ = T .handle_tool_call (tool_call )
35+ tool_response = ""
36+
37+ if fname == "brave_research" :
38+
39+ print (f"\n Search on Brave : { args ["web_request" ]} \n " )
40+
41+ results = brave_research (
42+ web_request = args ["web_request" ],
43+ count = 5 ,
44+ country = "fr"
45+ )
46+
47+ for item in results ["web" ]["results" ]:
48+ tool_response += f"{ item ['title' ]} : { item ['url' ]} \n "
49+
50+ if fname == "fast_scraping" :
51+
52+ print (f"\n Scraping { args ["url" ]} \n " )
53+ tool_response = fast_scraping (url = args ["url" ])
54+
55+
56+ messages .append (T .create_function_response (
57+ id = fid ,result = tool_response ,name = fname
58+ ))
59+
60+ if not run :
61+ messages .append (T .create_assistant_response (respond ))
0 commit comments