用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/aiskillstore/marketplace --skill risk-control-engineer命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
基于 SOC 职业分类
正在显示 SKILL.md
| name | risk-control-engineer |
| description | 风控工程师(反欺诈/反作弊)Agent — 覆盖风险策略制定、特征工程、模型开发、实时风控系统建设、黑产对抗、数据监控全流程。支持规则引擎设计、异常检测、团伙欺诈挖掘、策略回测与迭代。 |
本 Agent 模拟风控工程师的工作流,覆盖从风险识别、策略设计、模型开发、实时决策到事后复盘的全链路。适用于电商、金融、内容平台、游戏等需要反欺诈/反作弊的场景。
用户描述业务场景
↓
Agent 分析该场景的欺诈风险点
↓
输出风险场景文档(含攻击路径、影响面)
↓
设计风控规则/策略
↓
输出规则文档(含回测建议)
触发条件:用户描述一个业务场景(如"电商大促活动"、"新用户注册"、"提现环节"、"内容发布")
步骤:
用户提供历史数据(CSV/JSON/数据库)
↓
Agent 加载数据并解析
↓
模拟策略执行(规则命中 + 模型评分)
↓
输出回测报告(指标 + 可视化建议)
触发条件:用户提供历史交易/行为数据,要求验证策略效果
步骤:
用户提供行为数据
↓
Agent 进行特征提取
↓
异常检测(统计方法 + 模型方法)
↓
团伙挖掘(图分析 + 社区发现)
↓
输出异常报告(含可疑群体、证据链)
触发条件:用户怀疑存在团伙欺诈或异常行为模式
步骤:
用户提出风控系统建设需求
↓
Agent 分析业务规模和场景
↓
设计系统架构(实时引擎 + 特征平台 + 决策流)
↓
输出架构文档(含技术选型建议)
触发条件:用户需要从零搭建或升级风控系统
步骤:
# 典型特征提取模板
import pandas as pd
import numpy as np
def extract_device_features(logs_df):
"""提取设备维度特征"""
features = logs_df.groupby('device_id').agg({
'user_id': 'nunique',
'ip': 'nunique',
'event_time': ['count', lambda x: (x.max() - x.min()).total_seconds()],
'amount': ['sum', 'mean', 'std']
})
features.columns = ['user_cnt', 'ip_cnt', 'event_cnt', 'active_seconds', 'amount_sum', 'amount_mean', 'amount_std']
return features
def extract_ip_features(logs_df):
"""提取IP维度特征"""
features = logs_df.groupby('ip').agg({
'user_id': 'nunique',
'device_id': 'nunique',
'event_time': 'count'
})
features.columns = ['user_cnt', 'device_cnt', 'event_cnt']
return features
def extract_behavior_sequence_features(logs_df):
logs_df = logs_df.sort_values([, ])
logs_df[] = logs_df.groupby()[].diff().dt.total_seconds()
speed = logs_df.groupby()[].apply(
x: (x) / ((x.() - x.()).total_seconds() / ) (x.() - x.()).total_seconds() >
)
speed
# 规则定义模板
RULES = [
{
'id': 'R001',
'name': '同一设备关联多账号',
'type': 'single',
'condition': 'device_user_cnt > 3',
'decision': 'REVIEW',
'priority': 1,
'description': '同一设备在24小时内关联超过3个不同账号'
},
{
'id': 'R002',
'name': '代理IP注册',
'condition': 'is_proxy_ip == True AND event_type == \"register\"',
'decision': 'REJECT',
'priority': 2,
'description': '使用代理IP进行注册'
},
{
'id': 'R003',
'name': '高频交易异常',
'type': 'sequence',
'condition': 'txn_count_1min > 10 AND amount_mean > 5000',
'decision': 'REVIEW',
'priority': 3,
'description': '1分钟内交易超过10笔且平均金额>5000'
}
]
# 风控模型训练模板
import xgboost as xgb
from sklearn.model_selection import train_test_split
from sklearn.metrics import roc_auc_score, precision_recall_curve, confusion_matrix
def train_risk_model(X, y, params=None):
"""训练风控XGBoost模型"""
if params is None:
params = {
'objective': 'binary:logistic',
'eval_metric': 'auc',
'max_depth': 6,
'learning_rate': 0.05,
'subsample': 0.8,
'colsample_bytree': 0.8,
'scale_pos_weight': sum(y==0)/sum(y==1), # 处理样本不平衡
'random_state': 42
}
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=42)
dtrain = xgb.DMatrix(X_train, label=y_train)
dtest = xgb.DMatrix(X_test, label=y_test)
model = xgb.train(params, dtrain, num_boost_round=100, evals=[(dtest, 'test')], early_stopping_rounds=10, verbose_eval=False)
return model
def evaluate_risk_model(model, X_test, y_test):
"""风控模型评估"""
y_pred = model.predict(xgb.DMatrix(X_test))
auc = roc_auc_score(y_test, y_pred)
thresholds = [, , , ]
results = []
t thresholds:
y_pred_bin = (y_pred >= t).astype()
cm = confusion_matrix(y_test, y_pred_bin)
tn, fp, fn, tp = cm.ravel()
results.append({
: t,
: tp / (tp + fn),
: fp / (fp + tn),
: tp / (tp + fp) (tp+fp) > ,
: *tp/(*tp+fp+fn) (*tp+fp+fn) >
})
results
# 规则引擎核心逻辑模板
class RuleEngine:
def __init__(self, rules):
self.rules = sorted(rules, key=lambda r: r['priority'])
def evaluate(self, features: dict) -> dict:
"""逐条执行规则,返回决策结果"""
hit_rules = []
for rule in self.rules:
if self._match_rule(rule['condition'], features):
hit_rules.append(rule)
if rule.get('decision') == 'REJECT':
break # 拒绝类规则短路
return {
'decision': self._decide(hit_rules),
'hit_rules': [r['id'] for r in hit_rules],
'risk_level': self._calc_risk_level(hit_rules)
}
def _match_rule(self, condition: str, features: dict) -> bool:
"""安全执行规则条件表达式"""
# 使用受限的eval或预编译表达式
allowed_vars = features
try:
return bool((condition, {\
import numpy as np
from sklearn.ensemble import IsolationForest
from scipy import stats
def statistical_anomaly_detection(df, feature_cols, method='iqr'):
"""统计异常检测"""
anomalies = pd.DataFrame()
for col in feature_cols:
if method == 'iqr':
Q1 = df[col].quantile(0.25)
Q3 = df[col].quantile(0.75)
IQR = Q3 - Q1
lower = Q1 - 3 * IQR
upper = Q3 + 3 * IQR
mask = (df[col] < lower) | (df[col] > upper)
elif method == 'zscore':
z = np.abs(stats.zscore(df[col].fillna(0)))
mask = z > 3
anomalies = df[mask]
anomalies['anomaly_feature'] = col
anomalies['anomaly_score'] = mask.astype(int)
return anomalies
def community_fraud_detection(edges_df):
"""团伙欺诈检测 - 基于图社区发现"""
import networkx as nx
from community import community_louvain
G = nx.Graph()
for _, row in edges_df.iterrows():
G.add_edge(row['node_a'], row['node_b'], weight=row.get('weight', 1))
# 社区发现
partition = community_louvain.best_partition(G, weight=)
communities = {}
node, comm_id partition.items():
comm_id communities:
communities[comm_id] = {: [], : }
communities[comm_id][].append(node)
communities[comm_id][] +=
high_risk = {cid: info cid, info communities.items()
info[] > }
high_risk
def backtest_strategy(data, rules, model=None):
"""策略回测"""
results = []
for _, row in data.iterrows():
features = extract_features(row)
# 规则评估
rule_engine = RuleEngine(rules)
rule_result = rule_engine.evaluate(features)
# 模型评分(如果有)
model_score = model.predict_proba([features])[0][1] if model else None
results.append({
'user_id': row['user_id'],
'rule_decision': rule_result['decision'],
'model_score': model_score,
'hit_rules': rule_result['hit_rules'],
'true_label': row.get('label', None)
})
# 计算回测指标
df_result = pd.DataFrame(results)
metrics = {
'total': len(df_result),
'pass_rate': (df_result['rule_decision'] == 'PASS').mean(),
'reject_rate': (df_result['rule_decision'] == 'REJECT').mean(),
'review_rate': (df_result['rule_decision'] == 'REVIEW').mean(),
}
if 'true_label' in df_result.columns:
labeled = df_result[df_result['true_label'].notna()]
metrics['capture_rate'] = (labeled['true_label'] == 1).mean()
metrics[] = (
(labeled[] == ) & (labeled[] == )
).mean()
metrics
# 生成风控系统架构描述
def generate_risk_control_architecture(business_type='ecommerce', qps=1000):
"""根据业务场景生成风控系统架构建议"""
arch = {
'data_pipeline': {
'source': '业务日志 → Kafka',
'real_time_features': 'Flink SQL + Redis 实时特征',
'batch_features': 'Spark/Hive 离线特征 → ClickHouse',
'feature_store': 'Redis(实时) + HBase(离线)'
},
'decision_engine': {
'rule_engine': 'Drools/自研规则引擎(Groovy动态规则)',
'model_inference': 'XGBoost/ONNX 模型推理服务',
'decision_flow': '规则引擎 → 模型评分 → 名单匹配 → 决策输出'
},
'data_storage': {
'real_time': 'Redis + ClickHouse',
'offline': 'Hive/Spark + HBase',
'log_search': 'Elasticsearch'
},
'monitoring': {
'metrics': 'Prometheus + Grafana',
'alert': '自研告警/ELK',
'dashboard': '通过率/拒绝率/人工审核率/欺诈率趋势'
}
}
return arch