This commit is contained in:
1 parent
df67a298be
commit
bb32884ecb
4 files changed
+69
-11
No files matched your search
@@ -3463,6 +3463,7 @@ async def _send_message_core(
|
||||
|
||||
|
||||
_schema = {"type": "object", "properties": {}}
|
||||
_schema = _normalize_mcp_schema(_schema)
|
||||
|
||||
|
||||
|
||||
@@ -5228,7 +5229,7 @@ async def _send_message_core(
|
||||
|
||||
|
||||
|
||||
tool_result = f"[工具调用已被策略拦截] {_policy_check.get('message', _reason)}"
|
||||
tool_result = f"[策略拦截: {_policy_check.get('message', _reason)}] 建议: 检查权限设置或新开对话"
|
||||
|
||||
|
||||
|
||||
@@ -5404,7 +5405,7 @@ async def _send_message_core(
|
||||
|
||||
|
||||
|
||||
tool_result = "[MCP 工具未找到或映射缺失]"
|
||||
tool_result = "[MCP 工具未找到] 建议: 检查工具名或尝试其他MCP工具。可用: " + str(list(mcp_tool_map.keys())[:5])
|
||||
|
||||
|
||||
|
||||
@@ -8402,6 +8403,35 @@ def _resolve_agent_tool_policy(agents):
|
||||
|
||||
|
||||
|
||||
def _normalize_mcp_schema(schema: dict) -> dict:
|
||||
"""MCP JSON Schema -> OpenAI function calling 兼容。
|
||||
处理: $ref, oneOf/anyOf -> first option, 剥离非标关键字"""
|
||||
if not isinstance(schema, dict):
|
||||
return {"type": "object", "properties": {}}
|
||||
if "$ref" in schema:
|
||||
return {"type": "object", "properties": {}}
|
||||
if "oneOf" in schema or "anyOf" in schema:
|
||||
opts = schema.get("oneOf") or schema.get("anyOf") or []
|
||||
if opts and isinstance(opts[0], dict):
|
||||
return _normalize_mcp_schema(opts[0])
|
||||
return {"type": "object", "properties": {}}
|
||||
if "allOf" in schema:
|
||||
merged = {"type": "object", "properties": {}}
|
||||
for s in schema.get("allOf", []):
|
||||
sub = _normalize_mcp_schema(s)
|
||||
if sub.get("properties"):
|
||||
merged["properties"].update(sub["properties"])
|
||||
return merged
|
||||
result = {}
|
||||
for k in ("type", "properties", "required", "description", "enum", "items"):
|
||||
if k in schema:
|
||||
result[k] = schema[k]
|
||||
if result.get("type") != "object":
|
||||
result["type"] = "object"
|
||||
if "properties" not in result:
|
||||
result["properties"] = {}
|
||||
return result
|
||||
|
||||
|
||||
def _check_tool_policy(func_name, mcp_info, skills, policy, call_count, round_count):
|
||||
|
||||
|
||||
@@ -1272,7 +1272,7 @@ def _execute_skill_tool(
|
||||
|
||||
|
||||
|
||||
return f"工具 '{func_name}' 执行结果: 已处理输入内容, 但未找到对应的技能定义。请基于通用知识回复用户。"
|
||||
return f"工具 '{func_name}' 执行结果: 已处理输入内容, 但未找到对应的技能定义。请基于通用知识回复用户。如有已加载的技能,可使用其名称直接调用。"
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user