Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🏦 Bank Responsibility Mapping AI Platform (LangGraph-FastAPI)

License: MIT Python 3.12+ FastAPI LangGraph

A dual-pipeline bank responsibility platform utilizing a LangGraph multi-agent network. Features background automation cron loops and real-time interactive SSE chat streaming with state retention.


🎯 Project Overview

This repository houses an enterprise-grade compliance intelligence backend built to map shifting financial regulations, banking laws, and corporate governance guidelines directly to corporate roles and institutional targets [finance].

The platform departs from rigid, unmanaged linear LLM wrappers by deploying a State-Managed Multi-Agent Network built on top of LangGraph. The system splits workloads into two distinct operational execution layers:

  1. Background Automation Pipeline (run_cron.py): A non-interactive batch process triggered by external OS daemons (e.g., Linux crontab) to scrape legislative updates, evaluate role impacts, and flag compliance vulnerabilities.
  2. Interactive Auditing Cockpit (api.py): An asynchronous FastAPI engine providing real-time communication via Server-Sent Events (SSE). It retains conversation states across graph execution nodes, streaming deterministic, RAG-enriched reasoning paths directly to compliance officers under high concurrency.

🏗️ System Architecture & Asynchronous Data Flow

The backend establishes an event-driven network pipeline to process incoming multi-variable request states and push dynamic token streams back to the client interface.


⚡ Core Technical Features & Systems Design

1. Asynchronous Graph State Streaming (.astream())

  • The Engineering Problem: Complex regulatory matching across massive legal frameworks takes considerable time. Standard synchronous REST APIs keep client sockets hanging, leading to high timeouts, poor UI performance, and severe thread blocking on the corporate server.
  • The Solution: Leveraged LangGraph's asynchronous graph engine combined with FastAPI's StreamingResponse to create an explicit Server-Sent Events (SSE) pipe. By using .astream(..., stream_mode="values"), the system tracks variable mutations across node execution boundaries in real time, converting final analytical tokens into structured JSON payloads (text/event-stream) and pushing them down the port pipe instantly to eliminate latency.

2. Multi-Variable State Machine Management

  • The Architectural Advantage: Instead of running unmanaged linear structures, the graph acts as an isolated state machine tracking multi-variable contexts concurrently:
    • Global Structural Triggers: updated_law_ids, updated_laws_target_users, updated_law_changes.
    • Target Verification Trackers: target_id, target_name, target_classification, target_law_changes, target_knowledge.
    • History Retention: target_last_response maps conversation state chains directly into the graph context to preserve structural continuity and state retention.

3. Integrated Production-Grade System Cron

  • The Execution Advantage: Incorporates a modular background syncing process (run_cron.py). It utilizes native OS return parameters (sys.exit(1)) to plug seamlessly into Linux crontab, Kubernetes CronJobs, or Apache Airflow schedulers, enabling headless batch synchronization without manual microservice interference.

⚙️ Core Pipeline Sub-Routine Mapping

The backend translates internal utility helpers directly into deterministic state execution blocks as outlined in schema.txt:

Pipeline 1: Background Automation (Cron)

  • preprocessing_law_changes + fetch_law_change_http ➔ Feeds fetch_law_changes_node
  • get_db_connection ➔ Feeds fetch_target_users_node (Identifies target compliance roles)
  • notification ➔ Feeds send_notifications_node (Dispatches alerts)

Pipeline 2: Interactive Chatflow (FastAPI SSE)

  • IntentSchema + get_local_llm ➔ Feeds classify_intent_node (Routes execution)
  • Classification 1 ➔ Routes to fetch_law_list_node
  • Classification 2 ➔ Routes to fetch_specific_law_nodeanalyze_law_changes_node (LLM Analysis)
  • Classification 3 ➔ Routes to fetch_all_laws_nodeanalyze_law_changes_node (LLM Analysis)
  • Classification 4 ➔ Routes to generate_optimized_search_query_noderetrieve_rag_context_nodeanalyze_todo_list_node
  • Classification 5 ➔ Routes to fallback_router_node

🛠️ Repository Folder Structure

BankResponsibilityMapping/
│
├── api.py                           # Master FastAPI application & SSE Streaming Endpoint
├── agent_graph.py                   # Compiled LangGraph Multi-Agent State Machine workflow
├── state.py                         # Pydantic data schema defining the unified AgentState
├── nodes.py                         # Independent functional multi-agent logical execution nodes
├── run_cron.py                      # Production batch synchronization engine (Background automation)
├── schema.txt                       # Structural blueprint mapping helper functions to core execution nodes
├── static/                          # Local directory housing native UI front-end assets
│   └── index.html                   # Core dashboard interface index entry point
├── .gitignore                       # Explicitly masks virtual environments, cache files, and logs
├── requirements.txt                 # Verified production-grade package dependency stack
└── LICENSE                          # MIT open-source certification

🚀 Local Linux Installation & Deployment

1. Setup the Asynchronous Virtual Environment

Ensure your local Linux or WSL2 terminal environment is active, then initialize your runtime dependencies:

# Clone the repository
git clone https://github.com/kb0422bk/PythonAgentAI_ResponsibilityMapping
cd BankResponsibilityMapping

# Initialize and launch the virtual environment
python3 -m venv .venv
source .venv/bin/activate

# Install the verified performance packages
pip install fastapi uvicorn langgraph langchain pydantic python-dotenv

2. Running the Production Server

Deploy the asynchronous server daemon via Uvicorn. Bind it natively to your private local network host IP to open up internal compliance access ports:

# Fire up the Uvicorn live-reloading daemon
uvicorn api:api_app --host 0.0.0.0 --port 0000 --reload

The server will initialize your LangGraph state models, mount the static visual directories, and listen for inbound network streaming blocks at http://0.0.0.0:0000.

3. Executing Background Cron Sync

# Trigger the batch automation flow manually
python run_cron.py

⚖️ License

Distributed under the MIT License. See LICENSE for more information.

About

A dual-pipeline bank responsibility platform utilizing a LangGraph multi-agent network. Features background automation cron loops and real-time interactive SSE chat streaming with state retention.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages