sycommon-python-lib 0.2.7a14__py3-none-any.whl → 0.2.7a16__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- sycommon/agent/deep_agent.py +17 -13
- sycommon/agent/middleware/sensitive_guard.py +16 -14
- sycommon/agent/multi_agent_team.py +1 -1
- {sycommon_python_lib-0.2.7a14.dist-info → sycommon_python_lib-0.2.7a16.dist-info}/METADATA +1 -1
- {sycommon_python_lib-0.2.7a14.dist-info → sycommon_python_lib-0.2.7a16.dist-info}/RECORD +8 -8
- {sycommon_python_lib-0.2.7a14.dist-info → sycommon_python_lib-0.2.7a16.dist-info}/WHEEL +0 -0
- {sycommon_python_lib-0.2.7a14.dist-info → sycommon_python_lib-0.2.7a16.dist-info}/entry_points.txt +0 -0
- {sycommon_python_lib-0.2.7a14.dist-info → sycommon_python_lib-0.2.7a16.dist-info}/top_level.txt +0 -0
sycommon/agent/deep_agent.py
CHANGED
|
@@ -374,8 +374,8 @@ class AgentConfig(BaseModel):
|
|
|
374
374
|
internal_model_name: Optional[str] = None
|
|
375
375
|
# 敏感检测提示词(应用层可覆盖);未传(None)用基础库 DEFAULT_DETECT_PROMPT
|
|
376
376
|
sensitive_detect_prompt: Optional[str] = None
|
|
377
|
-
# 命中敏感后的动作:"downgrade"=降级内部模型继续;"block"=直接阻断不执行
|
|
378
|
-
sensitive_action: str = "
|
|
377
|
+
# 命中敏感后的动作:"allow"=不检测放行;"downgrade"=降级内部模型继续;"block"=直接阻断不执行
|
|
378
|
+
sensitive_action: str = "allow"
|
|
379
379
|
|
|
380
380
|
# 系统提示词
|
|
381
381
|
system_prompt: str = DEFAULT_SYSTEM_PROMPT
|
|
@@ -1421,17 +1421,21 @@ async def _sync_skills_to_sandbox(
|
|
|
1421
1421
|
if remote_content and remote_content.file_data:
|
|
1422
1422
|
# FileData 是 TypedDict(dict), 用键访问而非属性
|
|
1423
1423
|
content = remote_content.file_data.get("content", "") or ""
|
|
1424
|
-
#
|
|
1425
|
-
#
|
|
1426
|
-
#
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1424
|
+
# 优先直接解 version(明文小文件最快);
|
|
1425
|
+
# 解不出再兜底解码 base64——沙箱 /read 对大文件(如 skill-creator 的
|
|
1426
|
+
# 34KB SKILL.md)返回 base64, 但 encoding 标志位可能漏标/误标,
|
|
1427
|
+
# 若依赖该标志位,漏标时会因找不到 "version:" 行误判为"无版本"
|
|
1428
|
+
# → 每次新建 Agent 都全量重传。改为「先解 → 解不出再 b64 兜底」,
|
|
1429
|
+
# 不依赖 encoding 字段, 对明文/base64 两种返回都正确。
|
|
1430
|
+
version = _parse_skill_version(content)
|
|
1431
|
+
if version:
|
|
1432
|
+
return version
|
|
1433
|
+
try:
|
|
1434
|
+
import base64 as _b64
|
|
1435
|
+
decoded = _b64.b64decode(content).decode("utf-8", errors="replace")
|
|
1436
|
+
return _parse_skill_version(decoded)
|
|
1437
|
+
except Exception:
|
|
1438
|
+
return ""
|
|
1435
1439
|
except Exception:
|
|
1436
1440
|
pass
|
|
1437
1441
|
return ""
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
共享同一实例,避免敏感数据通过委派链继续流向外部模型。
|
|
11
11
|
|
|
12
12
|
agent 本就是内部模型(model_tier="internal")时短路放行,不检测。
|
|
13
|
-
检测失败 fail-
|
|
13
|
+
检测失败 fail-open(视为不敏感,放行)。
|
|
14
14
|
"""
|
|
15
15
|
import asyncio
|
|
16
16
|
from typing import Any, Awaitable, Callable, List, Optional
|
|
@@ -228,8 +228,8 @@ class SensitiveGuardMiddleware(AgentMiddleware):
|
|
|
228
228
|
state: Optional[DowngradeState] = None,
|
|
229
229
|
# 应用层可覆盖检测提示词;未传(None)用 DEFAULT_DETECT_PROMPT
|
|
230
230
|
detect_prompt: Optional[str] = None,
|
|
231
|
-
# 命中敏感后的动作:"downgrade"=降级内部模型继续;"block"=直接阻断(不调任何模型)
|
|
232
|
-
action: str = "
|
|
231
|
+
# 命中敏感后的动作:"allow"=不检测放行;"downgrade"=降级内部模型继续;"block"=直接阻断(不调任何模型)
|
|
232
|
+
action: str = "allow",
|
|
233
233
|
# 阻断模式下的异步提示回调(与 on_downgrade 区分文案);downgrade 模式不用
|
|
234
234
|
on_block: Optional[Callable[[], Awaitable[None]]] = None,
|
|
235
235
|
# 测试注入:绕过懒加载的真实 get_llm
|
|
@@ -241,7 +241,8 @@ class SensitiveGuardMiddleware(AgentMiddleware):
|
|
|
241
241
|
self._internal_name = internal_model_name
|
|
242
242
|
self._on_downgrade = on_downgrade
|
|
243
243
|
self._on_block = on_block
|
|
244
|
-
|
|
244
|
+
# 默认 allow(不检测):应用层未显式指定时按"放行"处理,避免误伤。
|
|
245
|
+
self._action = action if action in ("downgrade", "block", "allow") else "allow"
|
|
245
246
|
self._enabled = enabled
|
|
246
247
|
self._state = state or DowngradeState()
|
|
247
248
|
self._detect_prompt = detect_prompt or DEFAULT_DETECT_PROMPT
|
|
@@ -301,16 +302,14 @@ class SensitiveGuardMiddleware(AgentMiddleware):
|
|
|
301
302
|
return self._internal_raw
|
|
302
303
|
|
|
303
304
|
async def _detect(self, messages: List[BaseMessage]) -> SensitiveCheck:
|
|
304
|
-
"""一次检测:命中即返回 SensitiveCheck。fail-
|
|
305
|
+
"""一次检测:命中即返回 SensitiveCheck。fail-open(识别不出来→视为不敏感放行)。
|
|
305
306
|
|
|
306
307
|
稳定性策略:
|
|
307
308
|
- 检测提示词只描述「判什么敏感」,不要求模型自己格式化输出;
|
|
308
309
|
- 直接用 detector.ainvoke 拿原始文本,本方法用正则提 {…} 再 Pydantic 解析;
|
|
309
310
|
- 单轮、零修正重试,避免 with_structured_output 的解析重试烧 token。
|
|
310
|
-
|
|
311
|
+
识别失败时 fail-open 视为不敏感(默认放行),避免误伤正常请求。
|
|
311
312
|
"""
|
|
312
|
-
import json
|
|
313
|
-
import re
|
|
314
313
|
content = _messages_to_text(messages)
|
|
315
314
|
try:
|
|
316
315
|
detector = await self._get_detector()
|
|
@@ -336,21 +335,24 @@ class SensitiveGuardMiddleware(AgentMiddleware):
|
|
|
336
335
|
text = raw.content if isinstance(raw, BaseMessage) else str(raw)
|
|
337
336
|
check = _parse_detect_json(text)
|
|
338
337
|
if check is None:
|
|
338
|
+
# fail-open:识别不出来默认放行(不阻断/不降级),仅告警便于排查。
|
|
339
339
|
SYLogger.warning(
|
|
340
|
-
f"[SensitiveGuard] 检测无有效JSON(fail-
|
|
341
|
-
return SensitiveCheck(is_sensitive=
|
|
340
|
+
f"[SensitiveGuard] 检测无有效JSON(fail-open→放行): {text[:300]!r}")
|
|
341
|
+
return SensitiveCheck(is_sensitive=False, reason="no_json_in_detect_output")
|
|
342
342
|
return check
|
|
343
343
|
except Exception as e:
|
|
344
|
-
|
|
345
|
-
|
|
344
|
+
# fail-open:检测异常默认放行,避免检测器自身故障拖垮正常对话。
|
|
345
|
+
SYLogger.warning(f"[SensitiveGuard] 检测异常(fail-open→放行): {e}")
|
|
346
|
+
return SensitiveCheck(is_sensitive=False, reason=f"detect_error:{e}")
|
|
346
347
|
|
|
347
348
|
async def awrap_model_call(
|
|
348
349
|
self,
|
|
349
350
|
request: ModelRequest[ContextT],
|
|
350
351
|
handler: Callable[[ModelRequest[ContextT]], Awaitable[ModelResponse[ResponseT]]],
|
|
351
352
|
) -> ModelResponse[ResponseT]:
|
|
352
|
-
# (a) 关闭 / 内部 tier
|
|
353
|
-
|
|
353
|
+
# (a) 关闭 / 内部 tier / allow 模式:纯放行,不检测。
|
|
354
|
+
# allow = 应用层完全关闭敏感检测(不调用 detector、不阻断、不降级),零开销。
|
|
355
|
+
if not self._enabled or self._model_tier == "internal" or self._action == "allow":
|
|
354
356
|
return await handler(request)
|
|
355
357
|
|
|
356
358
|
# (b) 本会话已命中敏感
|
|
@@ -133,7 +133,7 @@ class TeamConfig(BaseModel):
|
|
|
133
133
|
sensitive_guard: bool = True # 是否启用敏感信息检测守卫
|
|
134
134
|
internal_model_name: Optional[str] = None # 敏感降级目标内部模型名(应用层透传)
|
|
135
135
|
sensitive_detect_prompt: Optional[str] = None # 敏感检测提示词(应用层覆盖)
|
|
136
|
-
sensitive_action: str = "
|
|
136
|
+
sensitive_action: str = "allow" # "allow"=不检测放行;"downgrade"=降级继续;"block"=阻断
|
|
137
137
|
|
|
138
138
|
coordinator_prompt: str = ""
|
|
139
139
|
coordinator_name: str = "项目经理"
|
|
@@ -136,8 +136,8 @@ sycommon/services.py,sha256=CwC_gESafo05Qn41KLQgtulx6PfX7s2FkxlBI-hXve4,24861
|
|
|
136
136
|
sycommon/agent/__init__.py,sha256=mxceAeUifQ-DKvWp7ZEJIFlmOCb5wpYHPGQw3rwEN8I,4378
|
|
137
137
|
sycommon/agent/agent_manager.py,sha256=UhhaekEumT7g4v_Z1UB4jTp13X0n8M8erYaQdkGGWkA,13620
|
|
138
138
|
sycommon/agent/chat_events.py,sha256=t7qWa6OrIWLfqtd1AnqaVP67QWkn1JxpCBTZYQpoLuM,14226
|
|
139
|
-
sycommon/agent/deep_agent.py,sha256=
|
|
140
|
-
sycommon/agent/multi_agent_team.py,sha256=
|
|
139
|
+
sycommon/agent/deep_agent.py,sha256=UT4noiAqRRUv7aFeobsFo3ad-gUA1L6xw0SV06nxTtY,74542
|
|
140
|
+
sycommon/agent/multi_agent_team.py,sha256=l1hIK6ihsyIp6QCH5st74h0d0cVmZaALQAPPqbZWarc,30282
|
|
141
141
|
sycommon/agent/summarization_utils.py,sha256=bqZRFqSekNGlv2mYQPaT_s2QNA5VDTKddi2Va_SkHWc,18376
|
|
142
142
|
sycommon/agent/acp/__init__.py,sha256=vQGMQYAA5-ZaejYmDZ4r4Fklqs17qH3cDXQ5pZlwj-0,1844
|
|
143
143
|
sycommon/agent/acp/client.py,sha256=s-K626b9ierwyEq61gejrW0xOysvrY2PIpYFsFqSHjc,27108
|
|
@@ -147,7 +147,7 @@ sycommon/agent/acp/tool.py,sha256=yt6ohKL2y7wIZMNiLv-m5oCg5u1p5GAbqgjzQVt285Y,10
|
|
|
147
147
|
sycommon/agent/mcp/__init__.py,sha256=iKrdDhIrFsNIkqG_kgcwNe-nOiM6uVfolKv44LfQ-FQ,636
|
|
148
148
|
sycommon/agent/mcp/models.py,sha256=zda4ho-UTYOJ5oPAZPZ-vxhfDRLghUCsMroHnA2A2QQ,1490
|
|
149
149
|
sycommon/agent/mcp/tool_loader.py,sha256=OQa-lE7RL2s3Lqh-kNOKaUrb130hvorB_HjyFBqZBZs,10960
|
|
150
|
-
sycommon/agent/middleware/sensitive_guard.py,sha256=
|
|
150
|
+
sycommon/agent/middleware/sensitive_guard.py,sha256=ApmC094ogG4jIwEWRaUawTpQSDs722k0OTjdeAEQ7Qc,22159
|
|
151
151
|
sycommon/agent/middleware/sitecustomize.py,sha256=Bt7XFnWV_LJo89l858AGp5VUkXwefpLGmjkCtLe-CMw,4800
|
|
152
152
|
sycommon/agent/middleware/skill_api_whitelist.py,sha256=e15aJekXegPp64owSCEdUE5y0SmwCQVQCF4jnhReZNU,10958
|
|
153
153
|
sycommon/agent/middleware/skill_wl_check.py,sha256=rCJ9F6aWPh8tVQBIPmcq2lKDsfwiJQduwSUku_8kXfs,3952
|
|
@@ -307,8 +307,8 @@ sycommon/tools/syemail.py,sha256=BDFhgf7WDOQeTcjxJEQdu0dQhnHFPO_p3eI0-Ni3LhQ,561
|
|
|
307
307
|
sycommon/tools/timing.py,sha256=OiiE7P07lRoMzX9kzb8sZU9cDb0zNnqIlY5pWqHcnkY,2064
|
|
308
308
|
sycommon/xxljob/__init__.py,sha256=7eoBlQxv-B39IfRSCY2bkqdGYs1QRe1umAWd88VMEEM,86
|
|
309
309
|
sycommon/xxljob/xxljob_service.py,sha256=1yifwIBNGsCIxLnQjHKiBlbsigc_zvPH-dMTZcNxe-Q,7649
|
|
310
|
-
sycommon_python_lib-0.2.
|
|
311
|
-
sycommon_python_lib-0.2.
|
|
312
|
-
sycommon_python_lib-0.2.
|
|
313
|
-
sycommon_python_lib-0.2.
|
|
314
|
-
sycommon_python_lib-0.2.
|
|
310
|
+
sycommon_python_lib-0.2.7a16.dist-info/METADATA,sha256=p2HPgbumt2j54mpC9qt_alpijwUrntvRvpNQJYBwCnI,7962
|
|
311
|
+
sycommon_python_lib-0.2.7a16.dist-info/WHEEL,sha256=K260EYznzXsJYBQGqmI8VTxEdiZYNvDZwW9cBh9-_MA,91
|
|
312
|
+
sycommon_python_lib-0.2.7a16.dist-info/entry_points.txt,sha256=gsR4SssKxDWjRU8ggidzNcdMXDPRSKRS7UaGyNP84Qg,92
|
|
313
|
+
sycommon_python_lib-0.2.7a16.dist-info/top_level.txt,sha256=RgphKrg7nJyZ7irJqbxFr-5H2LUYTvI7ivoWZH2hcD0,29
|
|
314
|
+
sycommon_python_lib-0.2.7a16.dist-info/RECORD,,
|
|
File without changes
|
{sycommon_python_lib-0.2.7a14.dist-info → sycommon_python_lib-0.2.7a16.dist-info}/entry_points.txt
RENAMED
|
File without changes
|
{sycommon_python_lib-0.2.7a14.dist-info → sycommon_python_lib-0.2.7a16.dist-info}/top_level.txt
RENAMED
|
File without changes
|