Files
XH-202626/XH-202626_原型系统源码与部署手册/01_原型系统源码/agents/law_agent.py
T

146 lines
5.9 KiB
Python

# -*- coding: utf-8 -*-
"""
法务风控节点
审查维度:算法备案状态、实体清单命中、数据出境风险、知识产权诉讼
"""
import json
from .base_agent import BaseAgent
LAW_SYSTEM_PROMPT = """你是一名资深法务风控专家,精通以下法律法规:
- 《生成式人工智能服务管理暂行办法》
- 《互联网信息服务算法推荐管理规定》
- 《数据安全法》《个人信息保护法》
- 《出口管制法》及美国 BIS 实体清单相关规则
- 《科创板上市规则》中的合规要求
你的任务是基于提供的企业数据,从法律合规角度评估以下风险:
1. 算法备案合规风险:企业是否涉及AI业务但未完成算法备案
2. 地缘政治与出口管制风险:企业或其供应链是否受到制裁
3. 数据合规风险:是否存在数据出境、数据安全方面的隐患
4. 知识产权诉讼风险:是否面临重大IP纠纷
请以严谨的法律视角进行评估,输出JSON格式:
{
"agent": "法务风控节点",
"algo_compliance_risk": {"score": 0-100, "level": "高/中/低", "detail": "..."},
"geopolitical_risk": {"score": 0-100, "level": "高/中/低", "detail": "..."},
"data_compliance_risk": {"score": 0-100, "level": "高/中/低", "detail": "..."},
"ip_litigation_risk": {"score": 0-100, "level": "高/中/低", "detail": "..."},
"overall_law_risk": {"score": 0-100, "level": "高/中/低"},
"key_findings": ["..."],
"recommendations": ["..."]
}"""
class LawAgent(BaseAgent):
"""法务风控节点"""
def __init__(self):
super().__init__(
name="法务风控节点",
system_prompt=LAW_SYSTEM_PROMPT,
role_icon="👩‍⚖️",
)
def evaluate(self, company_data: dict) -> dict:
"""执行法务风险评估"""
prompt = self._build_prompt(company_data)
result = self.infer_json(prompt)
# 如果 JSON 解析失败,使用规则引擎
if result.get("parse_error"):
result = self._rule_based_evaluation(company_data)
result["agent"] = "法务风控节点"
result["icon"] = self.role_icon
return result
def _build_prompt(self, company_data: dict) -> str:
"""构建评估提示词"""
return f"""请对以下科创企业进行法务风险评估:
企业名称:{company_data.get('short_name', company_data.get('company_name', '未知'))}
行业:{company_data.get('industry', '未知')}
领域:{company_data.get('sector', '未知')}
合规状态:
- 算法备案:{json.dumps(company_data.get('compliance', {}), ensure_ascii=False)}
供应链信息:
- 关键供应商:{json.dumps(company_data.get('supply_chain', {}).get('key_suppliers', []), ensure_ascii=False)}
- 供应商集中度风险:{company_data.get('supply_chain', {}).get('supplier_concentration_risk', '未知')}
技术路线:
{json.dumps(company_data.get('tech_route', {}), ensure_ascii=False)}
请输出严格的JSON评估结果。"""
def fallback_inference(self, prompt: str) -> str:
"""规则引擎降级"""
return json.dumps(self._rule_based_evaluation({}), ensure_ascii=False)
def _rule_based_evaluation(self, company_data: dict) -> dict:
"""基于规则的法务风险评估"""
compliance = company_data.get("compliance", {})
supply_chain = company_data.get("supply_chain", {})
sector = company_data.get("sector", "")
# 算法备案风险
algo_status = compliance.get("algo_filing_status", "")
algo_score = 20
algo_detail = "合规状态正常"
if sector in ["AI", "软件", "互联网"] and algo_status == "不适用":
algo_score = 60
algo_detail = "涉及AI业务但标注为不适用,建议核实"
elif "未" in algo_status or not algo_status:
algo_score = 80
algo_detail = "未查到算法备案记录,存在合规风险"
elif "已备案" in algo_status:
algo_score = 10
algo_detail = "已完成算法备案"
# 地缘政治风险
entity_status = compliance.get("entity_list_status", "")
geo_score = 15
geo_detail = "未受出口管制影响"
if "被列入" in entity_status:
geo_score = 95
geo_detail = f"已被列入实体清单: {compliance.get('sanctions_detail', '')}"
elif supply_chain.get("supplier_concentration_risk") == "极高":
geo_score = 70
geo_detail = "核心供应链高度依赖海外,存在间接制裁风险"
# 数据合规风险
data_risk = compliance.get("data_export_risk", "低")
data_score = {"高": 75, "中": 45, "低": 15}.get(data_risk, 20)
data_detail = f"数据出境风险等级: {data_risk}"
# 知识产权风险
ip_score = 25
ip_detail = "未发现重大IP纠纷"
# 综合法务风险
overall_score = int(
algo_score * 0.25 + geo_score * 0.35 +
data_score * 0.25 + ip_score * 0.15
)
return {
"algo_compliance_risk": {"score": algo_score, "level": self._level(algo_score), "detail": algo_detail},
"geopolitical_risk": {"score": geo_score, "level": self._level(geo_score), "detail": geo_detail},
"data_compliance_risk": {"score": data_score, "level": self._level(data_score), "detail": data_detail},
"ip_litigation_risk": {"score": ip_score, "level": self._level(ip_score), "detail": ip_detail},
"overall_law_risk": {"score": overall_score, "level": self._level(overall_score)},
"key_findings": [algo_detail, geo_detail, data_detail],
"recommendations": ["建议定期审查合规状态", "关注实体清单更新动态"],
}
@staticmethod
def _level(score: int) -> str:
if score >= 70:
return "高"
elif score >= 40:
return "中"
return "低"