贷款审批协调代理系统

一个多代理协调系统,用于自动化贷款审批流程,包括客户验证、谈判、信用评估和制裁函生成。

  • by lavneshrao
  • Python
  • 本地部署
  • 更新于
在 GitHub 查看 lavneshrao/MCP_client_server

使用说明

  1. 结构:一个主代理、协调器、四个工作代理
  2. 保持所有代理的状态结构相同,并将此状态存储在编排器中,以便所有代理都可以对其执行读写操作。此状态必须覆盖所有字段。
  3. 首先,主代理启动对话,并在状态中填写customer_id字段,同时执行常规聊天机器人操作。
  4. 销售代理:此customer_id随后由销售代理获取,并使用mcp服务器中的get_customer_info工具获取并写入编排状态中所需的协商详细信息。
  5. 然后,主代理寻求用户的批准,并在状态字段中更新该批准。如果状态不确定,协调器将返回销售代理以更新谈判条款。
  6. 一旦用户确认编排状态中的状态字段,编排器就会移动到验证代理。
  7. 验证代理:验证代理使用mcp服务器的verify_kyc工具验证用户,并在编排共享状态下更新用户。
  8. 一旦验证,流程将进一步转移到承销代理。
  9. 承销代理:承销代理使用get_credit_score和upload_salary_slip等工具获取详细信息并执行工具功能中提到的操作。
  10. 根据报价的结果和可接受性,主代理在收到制裁函生成器代理开始工作的确认后,寻求客户/用户最终接受贷款。
  11. 制裁函生成器:在获得完全批准后,它使用generate_Sanction_Letter mcp工具生成pdf。
  12. 最终,主代理表示祝贺,并向用户发送了批准函

共享状态:

从键入导入TypedDict、Dict、Any、Optional、List

类编排状态:

# -------------------------------------------------------
# 1. MASTER AGENT / USER INPUT
# -------------------------------------------------------
customer_id: str                       # Filled by master agent when user provides ID
user_query: str                        # Raw user input for conversation continuity
status: str                            # negotiation_status: "pending" | "approved" | "rejected"

# -------------------------------------------------------
# 2. CUSTOMER DATA (from MCP: get_customer_info)
# -------------------------------------------------------
customer_info: Dict[str, Any]          # Full customer dict returned by MCP server

# -------------------------------------------------------
# 3. NEGOTIATION (Sales Agent)
# -------------------------------------------------------
requested_amount: Optional[int]        # Customer-requested amount
preferred_tenure_months: Optional[int] # Customer preferred tenure
max_interest_rate: Optional[float]     # User threshold

negotiated_offer: Dict[str, Any]       # {
                                       #   "customer_id": str,
                                       #   "approved_amount": int,
                                       #   "tenure_months": int,
                                       #   "interest_rate": float,
                                       #   "justification": str
                                       # }


# -------------------------------------------------------
# 4. KYC VERIFICATION (Verification Agent)
# -------------------------------------------------------
kyc_result: Dict[str, Any]             # {
                                       #   "phone_verified": bool,
                                       #   "address_verified": bool
                                       # }
kyc_status: str                        # "pending" | "verified" | "failed"

# -------------------------------------------------------
# 5. UNDERWRITING (Underwriting Agent)
# -------------------------------------------------------
credit_score: Optional[int]            # fetched from get_credit_score
salary_slip_resource: Optional[str]    # resource://<file> link after upload
underwriting_input: Dict[str, Any]     # the exact MCP input payload
underwriting_result: Dict[str, Any]    # MCP underwriting output
underwriting_status: str               # "pending" | "approved" | "rejected" | "need_documents"

# -------------------------------------------------------
# 6. SANCTION LETTER (Sanction Letter Generator Agent)
# -------------------------------------------------------
sanction_letter_resource: Optional[str]  # resource://<pdf>
sanction_letter_path: Optional[str]      # local server path for debugging
sanction_letter_status: str              # "generated" or "failed"

# -------------------------------------------------------
# 7. SYSTEM FLOW CONTROL (used by orchestrator)
# -------------------------------------------------------
flow_stage: str                        # one of:
                                       # "start"
                                       # "collect_customer_id"
                                       # "negotiation"
                                       # "await_user_confirmation"
                                       # "verification"
                                       # "underwriting"
                                       # "sanction_generation"
                                       # "complete"

messages: List[Dict[str, Any]]         # optional conversation history for master agent

# -------------------------------------------------------
# 8. LOGGING / AUDIT
# -------------------------------------------------------
log_events: List[Dict[str, Any]]       # track events locally before sending to MCP log_event