@@ -146,9 +146,12 @@ def _prepare_selection_request(self, request: ModelRequest) -> _SelectionRequest
146
146
if not request .tools or len (request .tools ) == 0 :
147
147
return None
148
148
149
+ # Filter to only BaseTool instances (exclude provider-specific tool dicts)
150
+ base_tools = [tool for tool in request .tools if not isinstance (tool , dict )]
151
+
149
152
# Validate that always_include tools exist
150
153
if self .always_include :
151
- available_tool_names = {tool .name for tool in request . tools }
154
+ available_tool_names = {tool .name for tool in base_tools }
152
155
missing_tools = [
153
156
name for name in self .always_include if name not in available_tool_names
154
157
]
@@ -160,7 +163,7 @@ def _prepare_selection_request(self, request: ModelRequest) -> _SelectionRequest
160
163
raise ValueError (msg )
161
164
162
165
# Separate tools that are always included from those available for selection
163
- available_tools = [tool for tool in request . tools if tool .name not in self .always_include ]
166
+ available_tools = [tool for tool in base_tools if tool .name not in self .always_include ]
164
167
165
168
# If no tools available for selection, return None
166
169
if not available_tools :
@@ -224,10 +227,20 @@ def _process_selection_response(
224
227
raise ValueError (msg )
225
228
226
229
# Filter tools based on selection and append always-included tools
227
- selected_tools = [tool for tool in available_tools if tool .name in selected_tool_names ]
228
- always_included_tools = [tool for tool in request .tools if tool .name in self .always_include ]
230
+ selected_tools : list [BaseTool ] = [
231
+ tool for tool in available_tools if tool .name in selected_tool_names
232
+ ]
233
+ always_included_tools : list [BaseTool ] = [
234
+ tool
235
+ for tool in request .tools
236
+ if not isinstance (tool , dict ) and tool .name in self .always_include
237
+ ]
229
238
selected_tools .extend (always_included_tools )
230
- request .tools = selected_tools
239
+
240
+ # Also preserve any provider-specific tool dicts from the original request
241
+ provider_tools = [tool for tool in request .tools if isinstance (tool , dict )]
242
+
243
+ request .tools = [* selected_tools , * provider_tools ]
231
244
return request
232
245
233
246
def modify_model_request (
0 commit comments