fix(toolset): 工具传递改为展开的 tools 列表,不再用 FunctionToolset 包装
前端/DB 仍用 toolset 做逻辑分组管理,但传给 pydantic-ai Agent 时 把 toolset 内的 callable 展开为 tools=[] 扁平列表,MCP server 等 需要 toolset 语义的单独走 toolsets=[] 参数。解决工具"存在但调不了"的问题。 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -100,34 +100,42 @@ async def get_mcp_toolsets_from_gsm() -> List[Any]:
|
||||
return []
|
||||
|
||||
|
||||
async def get_all_toolsets_for_scope(
|
||||
async def get_all_tools_and_toolsets_for_scope(
|
||||
scope: str, toolset_ids: Optional[List[str]] = None
|
||||
) -> List[Any]:
|
||||
"""汇总某个 scope 下的全部 toolset:system + personal + mcp。
|
||||
) -> tuple:
|
||||
"""汇总某个 scope 下的工具:展开的 tool callable 列表 + MCP toolsets。
|
||||
|
||||
Args:
|
||||
scope: 调用方所属 scope。
|
||||
toolset_ids: agent 配置的 toolset 列表;为 None 或空列表表示返回全部。
|
||||
|
||||
返回顺序保持稳定:先本地 toolset(按 toolset_ids),再 MCP toolset。
|
||||
任意一类拉取失败仅记录日志,不影响其他类。
|
||||
Returns:
|
||||
(tools, toolsets) — tools 是展开的 callable 列表(传给 Agent(tools=...)),
|
||||
toolsets 是 MCP server 等需要 toolset 语义的对象(传给 Agent(toolsets=...))。
|
||||
"""
|
||||
tools: List[Any] = []
|
||||
toolsets: List[Any] = []
|
||||
try:
|
||||
from kilostar.core.global_state_machine.gsm_snapshot import (
|
||||
build_toolsets_for_scope,
|
||||
build_tools_for_scope,
|
||||
fetch_snapshot,
|
||||
)
|
||||
|
||||
snapshot = await fetch_snapshot()
|
||||
effective_ids = toolset_ids if toolset_ids else None
|
||||
local = build_toolsets_for_scope(snapshot, scope, toolset_ids=effective_ids)
|
||||
if local:
|
||||
toolsets.extend(local)
|
||||
tools = build_tools_for_scope(snapshot, scope, toolset_ids=effective_ids)
|
||||
except Exception as e:
|
||||
logger.error(f"Failed to load local toolsets from GSM ({scope}): {e}")
|
||||
logger.error(f"Failed to load tools from GSM ({scope}): {e}")
|
||||
|
||||
toolsets.extend(await get_mcp_toolsets_from_gsm())
|
||||
toolsets = await get_mcp_toolsets_from_gsm()
|
||||
return tools, toolsets
|
||||
|
||||
|
||||
async def get_all_toolsets_for_scope(
|
||||
scope: str, toolset_ids: Optional[List[str]] = None
|
||||
) -> List[Any]:
|
||||
"""兼容旧调用:返回 MCP toolsets 列表(不再包含 FunctionToolset)。"""
|
||||
_, toolsets = await get_all_tools_and_toolsets_for_scope(scope, toolset_ids)
|
||||
return toolsets
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user