技能架构设计:208个金融AI Skill的分类体系

简介: 银行智能体架构:7个Skill如何协同工作 实战代码:基于 financial-ai-skills 项目 | 架构设计 | Skill协同 | 数据流 单体架构 vs 微服务架构 银行系统常见的两种架构: `` 单体架构: 微服务架构: ┌─────────────┐ ┌─────┐ ┌─────┐ ┌─────┐ │ 核心系统 │ │信贷 │ │风控 │ │营销 │ │ ├─信贷

银行智能体架构:7个Skill如何协同工作

实战代码:基于 financial-ai-skills 项目 | 架构设计 | Skill协同 | 数据流

单体架构 vs 微服务架构

银行系统常见的两种架构:

单体架构:                    微服务架构:
┌─────────────┐            ┌─────┐ ┌─────┐ ┌─────┐
│  核心系统    │            │信贷 │ │风控 │ │营销 │
│  ├─信贷     │            │服务 │ │服务 │ │服务 │
│  ├─风控     │            └─────┘ └─────┘ └─────┘
│  ├─营销     │               ↑       ↑       ↑
│  └─运营     │            ┌─────────────────────┐
└─────────────┘            │      API网关         │
                           └─────────────────────┘

问题:单体太臃肿,微服务太复杂。

方案:Skill化架构

我设计的架构:

┌─────────────────────────────────────────┐
│           应用层 (业务系统)               │
│  ┌─────────┐ ┌─────────┐ ┌─────────┐  │
│  │ 信贷系统 │ │ 风控系统 │ │ 营销系统 │  │
│  └────┬────┘ └────┬────┘ └────┬────┘  │
└───────┼───────────┼───────────┼────────┘
        │           │           │
        └───────────┼───────────┘
                    ↓
┌─────────────────────────────────────────┐
│           Skill层 (7个核心模块)           │
│  ┌─────┐ ┌─────┐ ┌─────┐ ┌─────┐      │
│  │财务 │ │风控 │ │尽调 │ │营销 │      │
│  │智能 │ │合规 │ │    │ │    │      │
│  └─────┘ └─────┘ └─────┘ └─────┘      │
│  ┌─────┐ ┌─────┐ ┌─────┐              │
│  │信贷 │ │运营 │ │财富 │              │
│  │审批 │ │自动化│ │管理 │              │
│  └─────┘ └─────┘ └─────┘              │
└─────────────────────────────────────────┘
                    │
        ┌───────────┼───────────┐
        ↓           ↓           ↓
┌───────────┐ ┌───────────┐ ┌───────────┐
│  数据层    │ │  规则引擎  │ │  LLM层    │
│  CSV/SQL  │ │  评分卡   │ │ (可选)    │
└───────────┘ └───────────┘ └───────────┘

Skill协同示例

from financial_intelligence import CashflowForecaster
from risk_compliance import FraudDetector
from credit_approval import CreditScorer

# 场景:企业申请贷款
# 需要多个Skill协同

class LoanApprovalWorkflow:
    def __init__(self):
        self.cashflow = CashflowForecaster()
        self.fraud = FraudDetector()
        self.credit = CreditScorer()

    def process(self, application: dict) -> dict:
        """处理贷款申请"""
        results = {
   }

        # Step 1: 财务分析
        print("🔍 Step 1: 财务分析")
        cashflow_result = self.cashflow.forecast(
            application["financial_data"]
        )
        results["cashflow"] = cashflow_result

        # Step 2: 反欺诈检测
        print("🔍 Step 2: 反欺诈检测")
        fraud_result = self.fraud.check(
            application["transaction_history"]
        )
        results["fraud"] = fraud_result

        # Step 3: 信用评分
        print("🔍 Step 3: 信用评分")
        credit_result = self.credit.score(
            application["credit_data"]
        )
        results["credit"] = credit_result

        # Step 4: 综合决策
        print("🔍 Step 4: 综合决策")
        decision = self.make_decision(results)

        return {
   
            "application_id": application["id"],
            "results": results,
            "decision": decision,
            "timestamp": datetime.now().isoformat()
        }

    def make_decision(self, results: dict) -> dict:
        """综合决策"""
        score = 0
        reasons = []

        # 现金流评分 (权重30%)
        cf_score = results["cashflow"]["health_score"]
        score += cf_score * 0.3

        # 反欺诈评分 (权重30%)
        fraud_score = 100 - results["fraud"]["risk_score"]
        score += fraud_score * 0.3

        # 信用评分 (权重40%)
        credit_score = results["credit"]["score"]
        score += credit_score * 0.4

        # 决策
        if score >= 80:
            decision = "APPROVE"
            suggestion = "建议审批"
        elif score >= 60:
            decision = "REVIEW"
            suggestion = "建议人工复核"
        else:
            decision = "REJECT"
            suggestion = "建议拒绝"

        return {
   
            "score": score,
            "decision": decision,
            "suggestion": suggestion,
            "reasons": reasons
        }

# 使用
workflow = LoanApprovalWorkflow()
result = workflow.process({
   
    "id": "APP001",
    "financial_data": {
   ...},
    "transaction_history": {
   ...},
    "credit_data": {
   ...}
})

print(f"决策: {result['decision']['decision']}")
print(f"评分: {result['decision']['score']}")
print(f"建议: {result['decision']['suggestion']}")

数据流设计

# Skill间的数据流
class DataFlow:
    """数据流管理器"""

    def __init__(self):
        self.pipeline = []

    def add_step(self, skill, input_mapping, output_mapping):
        """添加处理步骤"""
        self.pipeline.append({
   
            "skill": skill,
            "input_mapping": input_mapping,
            "output_mapping": output_mapping
        })

    def execute(self, initial_data: dict) -> dict:
        """执行数据流"""
        data = initial_data.copy()

        for step in self.pipeline:
            skill = step["skill"]

            # 映射输入
            inputs = {
   }
            for key, path in step["input_mapping"].items():
                inputs[key] = self._get_value(data, path)

            # 执行Skill
            result = skill.process(**inputs)

            # 映射输出
            for key, path in step["output_mapping"].items():
                self._set_value(data, path, result[key])

        return data

    def _get_value(self, data: dict, path: str):
        """获取嵌套值"""
        keys = path.split(".")
        value = data
        for key in keys:
            value = value.get(key, {
   })
        return value

    def _set_value(self, data: dict, path: str, value):
        """设置嵌套值"""
        keys = path.split(".")
        target = data
        for key in keys[:-1]:
            if key not in target:
                target[key] = {
   }
            target = target[key]
        target[keys[-1]] = value

# 定义贷款审批数据流
flow = DataFlow()

# Step 1: 财务分析
flow.add_step(
    skill=CashflowForecaster(),
    input_mapping={
   "data": "application.financial_data"},
    output_mapping={
   "health_score": "results.cashflow.health_score"}
)

# Step 2: 反欺诈
flow.add_step(
    skill=FraudDetector(),
    input_mapping={
   "transactions": "application.transaction_history"},
    output_mapping={
   "risk_score": "results.fraud.risk_score"}
)

# Step 3: 信用评分
flow.add_step(
    skill=CreditScorer(),
    input_mapping={
   "credit_data": "application.credit_data"},
    output_mapping={
   "score": "results.credit.score"}
)

# 执行
result = flow.execute({
   
    "application": {
   ...}
})

配置化Skill加载

# skill_config.yaml
skills:
  financial-intelligence:
    enabled: true
    version: "1.0"
    config:
      forecast_horizon: 30

  risk-compliance:
    enabled: true
    version: "1.1"
    config:
      min_transaction_amount: 100000

  credit-approval:
    enabled: true
    version: "1.0"
    config:
      min_score: 75
      max_auto_amount: 500000

# 加载配置
import yaml

class SkillManager:
    def __init__(self, config_path: str):
        with open(config_path) as f:
            self.config = yaml.safe_load(f)
        self.skills = {
   }

    def load_skills(self):
        """加载所有Skill"""
        for name, cfg in self.config["skills"].items():
            if cfg["enabled"]:
                self.skills[name] = self._load_skill(name, cfg)

    def _load_skill(self, name: str, cfg: dict):
        """加载单个Skill"""
        module = __import__(f"skills.{name.replace('-', '_')}")
        skill_class = getattr(module, name.replace("-", " ").title().replace(" ", ""))
        return skill_class(**cfg.get("config", {
   }))

    def get_skill(self, name: str):
        """获取Skill"""
        return self.skills.get(name)

# 使用
manager = SkillManager("skill_config.yaml")
manager.load_skills()

credit_skill = manager.get_skill("credit-approval")
result = credit_skill.score(application_data)

监控与日志

class SkillMonitor:
    """Skill监控器"""

    def __init__(self):
        self.metrics = {
   }

    def record(self, skill_name: str, operation: str, duration: float, success: bool):
        """记录指标"""
        key = f"{skill_name}.{operation}"

        if key not in self.metrics:
            self.metrics[key] = {
   
                "count": 0,
                "total_duration": 0,
                "success_count": 0,
                "fail_count": 0
            }

        self.metrics[key]["count"] += 1
        self.metrics[key]["total_duration"] += duration

        if success:
            self.metrics[key]["success_count"] += 1
        else:
            self.metrics[key]["fail_count"] += 1

    def get_report(self) -> dict:
        """生成监控报告"""
        report = {
   }

        for key, metrics in self.metrics.items():
            report[key] = {
   
                "total_calls": metrics["count"],
                "avg_duration": metrics["total_duration"] / metrics["count"],
                "success_rate": metrics["success_count"] / metrics["count"] * 100,
                "error_rate": metrics["fail_count"] / metrics["count"] * 100
            }

        return report

# 装饰器自动记录
import time
import functools

def monitored(skill_name: str, operation: str):
    def decorator(func):
        @functools.wraps(func)
        def wrapper(*args, **kwargs):
            start = time.time()
            try:
                result = func(*args, **kwargs)
                monitor.record(skill_name, operation, time.time() - start, True)
                return result
            except Exception as e:
                monitor.record(skill_name, operation, time.time() - start, False)
                raise
        return wrapper
    return decorator

# 使用
class CreditScorer:
    @monitored("credit-approval", "score")
    def score(self, data: dict) -> dict:
        # 评分逻辑
        pass

完整代码https://github.com/yuzhaopeng-up/financial-ai-skills

#架构设计 #Skill协同 #数据流 #银行系统 #微服务

相关文章
|
2天前
|
人工智能 安全 测试技术
|
4天前
|
云安全 人工智能 安全
阿里云 Agentic SOC 位居 IDC MarketScape安全运营智能体2026领导者类别
以 Agentic AI 重构安全运营闭环,阿里云云安全在产品能力与市场份额
1174 3
|
4天前
|
数据采集 机器学习/深度学习 人工智能
田间杂草定位与检测4200张YOLO智慧农业数据集分享
本数据集含4200张真实农田图像,YOLO格式,单类别(杂草)高质量标注,覆盖多作物、多光照、多生长阶段等复杂场景,专为智慧农业杂草检测与智能除草设备研发设计,支持YOLOv5/v8/v10等主流模型训练。
359 94
|
5天前
|
缓存 UED 开发者
Codex109天重置23次,明天还要再送一次
Codex近109天完成23次额度重置,7月14日将迎来第24次。Tibo高频响应用户反馈:优化GPT-5.6高消耗问题、补发失效福利、调整重置时间——形成“反馈→回应→修复→补偿”正向闭环,彰显以用户为中心的产品哲学。(239字)
612 11
|
8天前
|
存储 人工智能 JSON
Qwen 本地部署搭配 ComfyUI 生成 AI 漫剧完整实操指南(小白零基础可落地,零成本无限生成+角色一致性天花板)
2026全网最优本地漫剧流水线:零成本、离线运行、角色统一、低配(8G显卡)可跑。融合Qwen本地大模型+ComfyUI双引擎,实现剧本生成→分镜绘图→动态成片全自动,隐私安全、无审核限流,新手30分钟上手,日更无忧。(239字)
|
8天前
|
人工智能 缓存 JSON
刚刚 GPT-5.6 发布,吊打 Claude 5 和 Grok 4.5?一手实测来啦!
GPT-5.6 刚发布,跑分号称超越 Fable 5,真的假的?附一手实测,让 3 个最强 AI 编程模型 GPT-5.6 Sol、Claude Fable 5、Grok 4.5 在 Cursor 里同时一把梭开发网页游戏,看看最新模型到底谁更能打。
370 0