Skip to content

Latest commit

Β 

History

86 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ•΅οΈβ€β™‚οΈ assembly-member_LangGraph-tracker

LangGraph-Based Agent Workflow for Tracking the Legislative Activities of South Korean National Assembly Members

A LangGraph-based web application for analyzing the legislative activities of National Assembly members. It primarily uses the Open National Assembly Information API to analyze sponsored bills, voting records, alignment with party majority positions, co-sponsorship networks, and recent issues.

By consolidating and analyzing complex, fragmented legislative activity data, the application helps citizens monitor legislative work and stay informed about recent issues. It also provides journalists with data-driven leads and objective verification tools for effective watchdog journalism.

🌐 URL: https://national-assembly.streamlit.app/

Open National Assembly Information APIs Used

Integrated National Assembly Member Information API Bills Sponsored by National Assembly Members
Voting Status by Bill National Assembly Member Plenary Vote Information

Source:https://open.assembly.go.kr/portal/openapi/openApiNaListPage.do

Google News RSS is used to retrieve recent issues involving National Assembly members.


🌟 Key Features

πŸ“‹ 1. Member Information Lookup

  • Member profiles: Retrieve basic information such as a National Assembly member's name, photo, party, and constituency from the Open National Assembly Information API
  • Member directory: Browse members by National Assembly term in a card-based interface
    • Filter by term (2nd–22nd National Assembly)
    • Apply multiple filters by party, constituency, and committee
    • Search by name, constituency, and committee
    • Sort by name, party, constituency, or committee
  • Term-of-office analysis: Review the terms served by a member and whether the member was reelected
  • Committee information: View current committee memberships and positions

πŸ“‘ 2. Sponsored Bill Analysis

  • Primary and co-sponsored bill lookup: Retrieve an integrated list of bills sponsored by each member through the National Assembly Open Data Portal API
  • Sponsorship role breakdown: Visualize the proportion of primary sponsorships versus co-sponsorships to assess the level of legislative activity
  • Analysis by responsible committee:
    • Visualize the number of sponsored bills by committee in a Treemap chart
    • View statistics for major responsible committees
  • Sponsored bill statistics:
    • View statistics by legislative outcome (discarded, pending, passed, rejected, and others)
    • Analyze trends over time
  • Legislative interest analysis: Use an LLM to automatically classify the topics of sponsored bills and interpret patterns in legislative activity
  • Detailed source data for sponsored bills: Access the complete sponsored bill data table, available for download as CSV

πŸ•ΈοΈ 3. Co-Sponsorship Network Analysis

  • First-degree ego-network visualization: Interactive network graph built with vis.js
    • Connect co-sponsorship partners around the selected member
    • Dynamically adjust node size based on co-sponsorship frequency
    • Adjust edge thickness based on the number of collaborations
  • Collaboration type classification:
    • Within-party collaboration (green): Collaboration with members of the same party
    • Cross-party collaboration (orange): Collaboration with members of other parties
    • Analyze cross-party collaboration patterns using a bipartisanship index
  • Collaboration statistics:
    • Number of collaboration partners and collaborative connections
    • Ratio of within-party to cross-party collaboration
  • Network filtering by responsible committee: Display only collaboration partners associated with a specific committee
  • Repeated collaboration analysis:
    • Bar chart ranking the top 10 collaborating members
    • Track the date of the most recent co-sponsorship
    • Statistics on responsible committees involved in collaboration
  • Collaboration interpretation: Use LLM analysis to interpret the political and policy implications of collaboration patterns

πŸ“Š 4. Voting Activity Analysis

  • Integrated voting record lookup: Collect each member's plenary-session voting records by National Assembly term
  • Vote result classification:
    • Analyze votes in favor
    • Analyze votes against
    • Analyze abstentions
    • Analyze absences
  • Voting summary charts:
    • Voting statistics by term (distribution of votes in favor, votes against, abstentions, and absences)
    • Trend analysis over time
  • Detailed voting record query scope:
    • Retrieve the most recent N records (default: 200)
    • Option to retrieve votes from all terms served
    • Selectively retrieve additional terms
  • Detailed voting source data:
    • Complete information, including bill title, voting date, committee, policy name, and vote value
    • Available for download as CSV
  • Voting statistics interpretation: Automatically generate caveats that account for the query scope and proportion of absences

βš–οΈ 5. Alignment with the Party Majority Position

  • Partisanship analysis: Analyze how closely a member's votes align with the majority position of members from the same party
  • Alignment calculation:
    • Calculate the proportion of votes in favor and against among members of the same party for each vote
    • Determine whether the member's vote aligns with or diverges from the majority position
  • Alignment summary charts:
    • Pie chart showing the overall composition of aligned, divergent, absent, and excluded votes
    • Stacked chart showing party-alignment trends by term
  • Detailed analysis of divergent votes: List votes that opposed the party majority position
    • Compare the party majority position with the member's vote by voting date and bill title
  • Scope reanalysis:
    • Recalculate using the most recent N records within the initially retrieved voting range
    • Dynamically adjust the threshold (50–500 records)
    • Compare reanalysis results in real time
  • Party-alignment status: Track cache hits and additional API calls

πŸ” 6. Recent Issue Tracking

  • Google News RSS-based search: Automatically collect recently published news using the member's name and party name
  • News summaries:
    • Use an LLM to analyze and summarize recent issues
    • Automatically identify context from search results
  • News timeline visualization: Display a news timeline by publication date
  • News table filtering:
    • Filter by title, news outlet, and date
    • Links to original articles (open in a new tab)
  • News source data: Download complete article metadata as CSV

🎯 7. Integrated Analysis and Visualization

  • Key briefing: A 3–5 sentence summary based on sponsored bills, voting records, party alignment, and the number of recent news articles
  • KPI dashboard:
    • Total number of sponsored bills
    • Total number of votes participated in
    • Party-alignment rate
    • Number of recent news articles
  • Member profile summary: Detailed profile information, including party, constituency, committee, and terms of office
  • Query scope details:
    • Term used to retrieve basic member information
    • Terms used to retrieve sponsored bills
    • Terms initially used to retrieve voting information
    • Additional selectable terms for voting information
  • Multi-tab interface:
    • Summary tab: Integrated metrics and analysis results
    • Sponsored Bills tab: Bill analysis and networks
    • Voting tab: Voting records and detailed analysis
    • Party Alignment tab: Partisanship analysis and divergence tracking
    • Recent Issues tab: News search results and analysis
    • Source Data tab: JSON data and error messages

βš™οΈ 8. Custom Analysis Options

  • Query scope controls:
    • Sponsored bills: Most recent term served vs. all terms served
    • Voting records: Most recent N records (50–1,000)
    • Party alignment: Most recent N records (50–500)
  • Analysis module toggles:
    • Enable or disable sponsored bill retrieval
    • Enable or disable the initial detailed voting record retrieval
    • Enable or disable party-alignment analysis
    • Enable or disable recent news search
    • Enable or disable LLM analysis
  • Detailed settings: Fine-tune the query scope using advanced options
  • Personal Gemini API key management: Secure input stored only in the user's browser

πŸ”„ 9. LangGraph-Based AI Agent Workflow

LangGraph Agent Workflow for Tracking National Assembly Member Activities

The workflow first retrieves the member's basic information, then collects sponsored bills, voting records, and recent issues in parallel before merging the results into a final key briefing.

  • Fan-out/Fan-in parallel analysis pipeline:
    1. Prepare inputs (normalize the user request and options)
    2. Retrieve basic member information (terms served, party, and constituency)
    3. After retrieving the member information, run three tasks in parallel
      • Retrieve sponsored bills
      • Retrieve detailed voting records
      • Search for recent issues
    4. After retrieving the sponsored bills, run two analyses in parallel
      • Analyze legislative interests
      • Analyze the co-sponsorship network
    5. After retrieving detailed voting records, analyze alignment with the party majority position and generate voting interpretation notes
    6. Once the legislative interest, co-sponsorship network, voting interpretation, and recent issue analyses are complete, generate the key briefing
    7. Organize the final results (arrange them for display)
  • Parallel state merging: Apply LangGraph state reducers to prevent conflicts when multiple nodes update error messages or LLM quota status simultaneously
  • In-node optimization: Handle repeated API calls for each BILL_ID within get_all_member_votes and analyze_party_alignment as asynchronous I/O using async def/await
  • Progress tracking: Display real-time progress and status messages for each stage
  • Error handling: Record detailed messages when an error occurs at any stage

πŸ’Ύ 10. Data Management and Downloads

  • CSV downloads: Download every data table in CSV format
    • Sponsored bill data
    • Voting records (votes in favor, votes against, abstentions, and absences)
    • Co-sponsor information
    • Recent news list
  • Caching system: Cache the member list for 24 hours to enable faster retrieval
  • JSON source data: View and verify the complete analysis results as JSON

πŸ—οΈ System Architecture and Workflow

The system consists of three data collection layers and a LangGraph-based AI inference layer.

πŸ“Š System Data Flow Diagram

+============================================================================================+
|                                   DATA COLLECTION LAYER                                    |
+--------------------------------------------------------------------------------------------+
| +--------------------------+   +--------------------------+   +--------------------------+ |
| | Member Info API          |   | Sponsored Bills API      |   | Voting Info API          | |
| | Open Assembly Data       |   | Open Assembly Data       |   | Open Assembly Data       | |
| | - Member details         |   | - Primary sponsor        |   | - Plenary votes          | |
| | - Party, district        |   | - Co-sponsors            |   | - Vote results           | |
| | - Committees             |   | - Bill outcomes          |   | - Vote details           | |
| +--------------------------+   +--------------------------+   +--------------------------+ |
|                                                                                            |
|                   Data APIs feed the news search and collection pipeline                   |
|                             +--------------------------------+                             |
|                             | News Search API                |                             |
|                             | Google News RSS                |                             |
|                             | - Member name                  |                             |
|                             | - Party name                   |                             |
|                             | - Recent news                  |                             |
|                             +--------------------------------+                             |
+============================================================================================+
                                               |
                                              v
+============================================================================================+
|                             DATA NORMALIZATION & CACHING LAYER                             |
+--------------------------------------------------------------------------------------------+
|                           - Data preprocessing and normalization                           |
|                   - Integration of member, bill, and voting information                    |
|               - 24-hour cache (member list, bills, voting details, and news)               |
|                - async/await-based voting detail retrieval for each BILL_ID                |
+============================================================================================+
                                               |
                                              v
+============================================================================================+
|                          LANGGRAPH AI INFERENCE & ANALYSIS LAYER                           |
+--------------------------------------------------------------------------------------------+
|                        +------------------------------------------+                        |
|                        | Stage 1: Prepare inputs                  |                        |
|                        | normalize_user_request                   |                        |
|                        +------------------------------------------+                        |
|                                             |                                              |
|                                             v                                              |
|                      +----------------------------------------------+                      |
|                      | Stage 2: Retrieve member information         |                      |
|                      | get_member_info                              |                      |
|                      +----------------------------------------------+                      |
|                                             |                                              |
|                                             v                                              |
|                   Fan-out: run independent collection tasks in parallel                    |
| +--------------------------+   +--------------------------+   +--------------------------+ |
| | Parallel A               |   | Parallel B               |   | Parallel C               | |
| | Retrieve bills           |   | Retrieve vote details    |   | Search recent issues     | |
| | search_member_bills      |   | get_all_member_votes     |   | search_recent_news       | |
| +--------------------------+   +--------------------------+   +--------------------------+ |
|                                                                                            |
|                 Bill branch analyses                 Vote branch analysis                  |
| +--------------------------+   +--------------------------+   +--------------------------+ |
| | Legislative interest     |   | Co-sponsorship network   |   | Party alignment          | |
| | analysis                 |   | analysis                 |   | party_alignment          | |
| |                          |   |                          |   | Generate vote notes      | |
| |                          |   |                          |   | interpret_vote_stats     | |
| +--------------------------+   +--------------------------+   +--------------------------+ |
|                                             |                                              |
|                                             v                                              |
|                         Fan-in: merge completed analysis branches                          |
|                      +----------------------------------------------+                      |
|                      | Generate key briefing (LLM)                  |                      |
|                      | generate_activity_briefing                   |                      |
|                      | Optional: Gemini LLM                         |                      |
|                      +----------------------------------------------+                      |
|                                             |                                              |
|                                             v                                              |
|                      +----------------------------------------------+                      |
|                      | Organize final results                       |                      |
|                      | summarize_member_activity                    |                      |
|                      +----------------------------------------------+                      |
+============================================================================================+
                                               |
                                              v
+============================================================================================+
|                                      RENDERING LAYER                                       |
+--------------------------------------------------------------------------------------------+
| +--------------------------+   +--------------------------+   +--------------------------+ |
| | Streamlit                |   | ECharts                  |   | vis.js Network           | |
| | Web Interface            |   | Visualization            |   | Visualization            | |
| | - Dashboard              |   | - Bar/Pie charts         |   | - Ego-Network            | |
| | - Tab interface          |   | - Time series            |   | - Collaboration          | |
| | - Filtering UI           |   | - Treemap                |   | - Dynamic layout         | |
| +--------------------------+   +--------------------------+   +--------------------------+ |
|                                             |                                              |
|                                             v                                              |
|                                  +----------------------+                                  |
|                                  | User                 |                                  |
|                                  +----------------------+                                  |
+============================================================================================+

πŸ”„ Workflow Details

Stage Node Execution Mode Role Primary Dependency
1 normalize_user_request Preprocessing Normalize the user request and analysis options User input
2 get_member_info Preprocessing Retrieve basic member information and determine terms served and terms available for analysis Normalized member name
3-A search_member_bills Parallel Collect primary and co-sponsored bills and calculate statistics by legislative outcome and responsible committee Basic member information
3-B get_all_member_votes Parallel Retrieve detailed plenary-session votes and classify votes in favor, votes against, abstentions, and absences Basic member information
3-C search_recent_member_news Parallel Collect and summarize recent issues through Google News RSS Basic member information
4-A-1 analyze_legislative_interests Parallel Analyze legislative interests based on sponsored bills Sponsored bill retrieval results
4-A-2 analyze_cosponsor_network Parallel Analyze co-sponsorship partners and collaboration patterns Sponsored bill retrieval results
4-B-1 analyze_party_alignment Sequential Analyze alignment with and divergence from the majority position among members of the same party Detailed voting record results
4-B-2 interpret_vote_statistics Sequential Generate voting interpretation notes that account for the query scope and proportion of absences Party-alignment analysis results
5 generate_activity_briefing After Fan-in Generate a key briefing integrating legislative activity, co-sponsorships, voting records, and recent issues Completion of all four analysis branches
6 summarize_member_activity Final Organize summary results for display Key briefing and complete analysis results

The parallelization rule is to run tasks concurrently only when they do not need to wait for one another's output. For example, detailed voting record retrieval does not depend on sponsored bill results, so it runs concurrently with search_member_bills. Party-alignment analysis, however, requires the detailed voting records and therefore runs only after get_all_member_votes.


πŸ“‚ Project Structure

πŸ“‚
β”œβ”€β”€ μ˜μ›_ν™œλ™_좔적_λž­κ·Έλž˜ν”„_μ›Œν¬ν”Œλ‘œμš°.ipynb
β”œβ”€β”€ app.py (Streamlit main application)
β”œβ”€β”€ src/
β”‚ β”œβ”€β”€ member_activity_workflow.py
β”‚ β”œβ”€β”€ member_directory.py
β”‚ └── streamlit_runtime.py
β”œβ”€β”€ requirements.txt
└── README.md


πŸ› οΈ Tech Stack

  • Language: Python 3.10+
  • Frameworks: LangGraph, LangChain
  • Data Source: National Assembly Open Data Portal (Open API) and real-time Google News collection
  • Streamlit: Visualizes collected legislative activity data and LLM inference results through an intuitive web interface

About

A LangGraph-based web app for analyzing the legislative activities of South Korean National Assembly members

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages