1919)
2020from src .agents .skill_registry import get_skills_section
2121from src .agents .subagent_tool import SubAgentTool
22- from src .schemas .chat import ChatCompletionRequest , FileAttachment , UserProfile
22+ from src .schemas .chat import ChatCompletionRequest , FileAttachment , SelectionItem , UserProfile
2323from src .services .tools import create_registry
2424from src .travel_plan import plan_store , set_bus , set_token
2525
@@ -251,6 +251,26 @@ async def _post_profile_callback(
251251 logger .exception ("profile callback failed to %s" , url )
252252
253253
254+ def _parse_disabled_selections (
255+ selections : Optional [List [SelectionItem ]],
256+ ) -> tuple [Optional [List [str ]], Optional [List [str ]], Optional [List [str ]]]:
257+ """从 disabled_selections 中按 type 拆分出三个独立黑名单。
258+
259+ 返回 (tool_ids, skill_ids, subagent_ids),均表示需要禁用的 id 列表。
260+ 某 type 在 selections 中无条目时对应值为 None(表示该类型全部开放)。
261+ selections 为 None 或空列表时三个值均为 None(全部开放)。
262+ """
263+ if not selections :
264+ return None , None , None
265+ tool_ids = [s .id for s in selections if s .type == "tool" ] or None
266+ skill_ids = [s .id for s in selections if s .type == "skill" ] or None
267+ subagent_ids = [s .id for s in selections if s .type == "subagent" ] or None
268+ return tool_ids , skill_ids , subagent_ids
269+
270+
271+ _parse_selections = _parse_disabled_selections # backwards compat alias
272+
273+
254274def _load_subagent_keys () -> List [str ]:
255275 path = os .path .join (
256276 os .path .dirname (__file__ ), ".." , "agents" , "tool_allocation.yaml"
@@ -308,9 +328,14 @@ async def run_agent_workflow(
308328 trace = TraceCollector (query = user_request )
309329 set_trace (trace )
310330
311- # ---- SubAgent tools ----
331+ # ---- 解析 disabled_selections,拆分出三类黑名单 ----
332+ tool_ids , skill_ids , subagent_ids = _parse_disabled_selections (request .disabled_selections )
333+
334+ # ---- SubAgent tools(subagent_ids 为 None 时全部创建,否则排除被禁用的) ----
312335 subagent_tools : list = []
313336 for key in _SUBAGENT_KEYS :
337+ if subagent_ids is not None and key in subagent_ids :
338+ continue
314339 worker_cls = WORKER_CLASSES .get (key )
315340 if not worker_cls :
316341 continue
@@ -321,15 +346,15 @@ async def run_agent_workflow(
321346 prompt_provider = prompt_provider ,
322347 session_context = session_ctx ,
323348 bus = bus ,
324- user_allowed_tools = request . tool_ids ,
349+ user_disabled_tools = tool_ids ,
325350 )
326351 subagent_tools .append (tool )
327352 tool_registry ._tool_map [tool .name ] = tool # type: ignore[attr-defined]
328353
329354 # ---- Supervisor tools ----
330355 supervisor = SupervisorAgent (
331356 "supervisor" , tool_registry , prompt_provider , metadata ,
332- user_allowed_tools = request . tool_ids ,
357+ user_disabled_tools = tool_ids ,
333358 )
334359 supervisor_tools = await supervisor .get_tools ()
335360
@@ -340,7 +365,7 @@ async def run_agent_workflow(
340365 "user_request" : user_request ,
341366 "metadata" : metadata ,
342367 "user_profile_section" : _format_user_profile (request .user_profile ),
343- "skills_section" : get_skills_section (),
368+ "skills_section" : get_skills_section (skill_ids ),
344369 }
345370 supervisor_messages = supervisor .build_plan_messages (supervisor_context )
346371 if request .files :
0 commit comments