55# the root directory of this source tree.
66import os
77
8- import inspect
9-
108import fire
119from llama_stack_client import LlamaStackClient , Agent , AgentEventLogger
1210from termcolor import colored
1311
14- from .utils import check_model_is_available , get_any_available_model
12+ from .utils import check_model_is_available , get_any_available_chat_model
1513
1614
1715def main (host : str , port : int , model_id : str | None = None ):
@@ -29,14 +27,8 @@ def main(host: str, port: int, model_id: str | None = None):
2927 provider_data = {"tavily_search_api_key" : os .getenv ("TAVILY_SEARCH_API_KEY" )},
3028 )
3129
32- available_shields = [shield .identifier for shield in client .shields .list ()]
33- if not available_shields :
34- print (colored ("No available shields. Disabling safety." , "yellow" ))
35- else :
36- print (f"Available shields found: { available_shields } " )
37-
3830 if model_id is None :
39- model_id = get_any_available_model (client )
31+ model_id = get_any_available_chat_model (client )
4032 if model_id is None :
4133 return
4234 else :
@@ -45,25 +37,13 @@ def main(host: str, port: int, model_id: str | None = None):
4537
4638 print (f"Using model: { model_id } " )
4739
48- agent_kwargs = {
49- "model" : model_id ,
50- "instructions" : "" ,
40+ agent = Agent (
41+ client ,
42+ model = model_id ,
43+ instructions = "" ,
5144 # OpenAI Responses tool schema requires a type discriminator.
52- "tools" : [{"type" : "web_search" }],
53- "input_shields" : available_shields ,
54- "output_shields" : available_shields ,
55- "enable_session_persistence" : False ,
56- }
57- allowed_params = set (inspect .signature (Agent .__init__ ).parameters )
58- filtered_kwargs = {k : v for k , v in agent_kwargs .items () if k in allowed_params }
59- try :
60- agent = Agent (client , ** filtered_kwargs )
61- except TypeError as exc :
62- # Fallback for older clients that only accept string tool names.
63- if "Unsupported tool type" not in str (exc ):
64- raise
65- filtered_kwargs ["tools" ] = ["builtin::websearch" ]
66- agent = Agent (client , ** filtered_kwargs )
45+ tools = [{"type" : "web_search" }],
46+ )
6747 user_prompts = [
6848 "Hello" ,
6949 "Search web for which players played in the winning team of the NBA western conference semifinals of 2024" ,
0 commit comments