@@ -31,71 +31,29 @@ class ClientSideToolInfo(TypedDict):
3131 output_schema : dict [str , Any ] | None
3232
3333
34- def validate_and_apply_tool_filter (
35- declared_tools : list [dict [str , Any ]],
34+ def apply_tool_filter (
35+ declared_tools : list [str | dict [str , Any ]],
3636 agent_tools : dict [str , ClientSideToolInfo ],
3737) -> None :
38- """Validate client-side tool declarations and set the availability filter .
38+ """Filter available client-side tools to the intersection of declared and agent tools .
3939
40- Compares the client's declared tools against the agent's tool definitions.
41- Raises ValueError if required tools are missing or schemas don't match.
42- Sets the available_client_side_tools context variable for tool functions .
40+ Extracts tool names from the client's declarations, intersects with the agent's
41+ defined client-side tools, and sets the availability filter. Unknown names are
42+ silently ignored .
4343
4444 Args:
45- declared_tools: List of tool declarations from uipath__client_side_tools input.
46- Each item is a dict with 'name' and optional 'inputSchema'/'outputSchema'.
47- agent_tools: The agent's client-side tools.
48- Dict of {tool_name: ClientSideToolInfo}.
45+ declared_tools: List of tool names (strings) or dicts with a 'name' field
46+ from uipath__client_side_tools input.
47+ agent_tools: The agent's client-side tools keyed by name.
4948 """
50- declared : dict [str , dict [str , Any ]] = {}
51- for i , t in enumerate (declared_tools ):
52- if isinstance (t , dict ):
53- if "name" not in t :
54- raise ValueError (
55- f"Client-side tool declaration at index { i } is missing required 'name' field."
56- )
57- name = t ["name" ]
58- elif isinstance (t , str ):
59- name = t
60- t = {"name" : t }
61- else :
62- raise ValueError (
63- f"Client-side tool declaration at index { i } must be a dict or string, got { type (t ).__name__ } ."
64- )
65- if name in declared :
66- raise ValueError (
67- f"Duplicate client-side tool declaration: '{ name } '."
68- )
69- declared [name ] = t
70-
71- required = set (agent_tools .keys ())
72- missing = required - set (declared .keys ())
73- if missing :
74- raise ValueError (
75- f"Missing required client-side tools: { ', ' .join (sorted (missing ))} . "
76- f"The client must register handlers for all client-side tools defined by the agent."
77- )
78-
79- for name , decl in declared .items ():
80- agent_tool = agent_tools .get (name )
81- if agent_tool is None :
82- continue # Unknown tool, runtime will ignore it
83- if decl .get ("inputSchema" ) and agent_tool .get ("input_schema" ):
84- if json .dumps (decl ["inputSchema" ], sort_keys = True ) != json .dumps (
85- agent_tool ["input_schema" ], sort_keys = True
86- ):
87- raise ValueError (
88- f"Client-side tool '{ name } ' inputSchema does not match agent definition."
89- )
90- if decl .get ("outputSchema" ) and agent_tool .get ("output_schema" ):
91- if json .dumps (decl ["outputSchema" ], sort_keys = True ) != json .dumps (
92- agent_tool ["output_schema" ], sort_keys = True
93- ):
94- raise ValueError (
95- f"Client-side tool '{ name } ' outputSchema does not match agent definition."
96- )
97-
98- available_client_side_tools .set (set (declared .keys ()))
49+ declared_names : set [str ] = set ()
50+ for t in declared_tools :
51+ if isinstance (t , str ):
52+ declared_names .add (t )
53+ elif isinstance (t , dict ) and "name" in t :
54+ declared_names .add (t ["name" ])
55+
56+ available_client_side_tools .set (declared_names & set (agent_tools .keys ()))
9957
10058
10159def create_client_side_tool (
0 commit comments