An Agentic AI Framework for Processing Philippine-Hong Kong Migrant Workers Legal Queries
Saint Louis University Baguio | Team 404FoundUs
The Legal Adaptive Routing Framework (LARF) is a specialized Python framework designed to bridge the gap between informal user queries (often in Taglish) and formal legal reasoning. It employs a multi-stage Agentic Pipeline to intelligently process, route, and resolve legal queries with high accuracy.
graph LR
A[User Query<br/>Taglish/Tagalog] --> B(1. Normalize);
B --> C(2. Classify);
C --> D(3. Retrieve);
D --> E(4. Generate);
E --> F(5. Audit);
F --> G[Legally Grounded<br/>Response];
classDef step fill:#f9f9f9,stroke:#333,stroke-width:2px;
class B,C,D,E,F step;
style A fill:#e1f5fe,stroke:#0288d1,stroke-width:2px
style G fill:#e8f5e9,stroke:#388e3c,stroke-width:2px
- Normalize: Translate linguistic variations (Taglish/Tagalog) into standard legal English.
- Classify: Intelligently route queries to the correct domain (e.g., General Information vs. Complex Reasoning).
- Retrieve: Advanced RAG (Retrieval-Augmented Generation) search mechanism focused on semantic querying of specific jurisdictional indices (e.g., Philippine and Hong Kong Legal Statutes).
- Generate: Produce legally grounded responses using specialized LLMs.
- Audit: Validate generated output for safety and minimize hallucinations.
- Multi-lingual Support: Native handling of Tagalog and Taglish inputs.
- Smart Routing: Directs queries to the most appropriate legal index or reasoning engine.
- Modular Architecture: Built for scalability and easy integration into existing systems.
- Robust Fact-Checking: Built-in mechanisms to reduce AI hallucinations in legal contexts.
Click to expand the directory structure
LegalAdaptiveRoutingFramework/
├── src/
│ └── adaptive_routing/
│ ├── config.py # Global Configuration
│ ├── core/ # Low-level Engine
│ │ ├── engine.py # OpenRouter API Handler
│ │ └── exceptions.py # Custom Errors
│ └── modules/
│ ├── multihead_classifier/ # Triage Components
│ │ ├── detector.py
│ │ └── linguistic.py
│ ├── semantic_router/ # Routing Components
│ │ ├── legal_generation.py
│ │ └── logic_classifier.py
│ ├── legal_retrieval/ # RAG Components
│ │ ├── embedding.py
│ │ └── retriever.py
│ ├── safety_audit/ # Safety Components
│ │ ├── response_audit.py
│ │ └── safety_audit.md # Module Documentation
│ ├── retrieval.py # Legal Retrieval Facade
│ ├── router.py # Router Facade
│ └── triage.py # Triage Facade
├── tests/ # Unit Tests
├── docs/ # Documentation
├── main.py # CLI Driver Script
├── requirements.txt # Python Dependencies
└── .env # Secrets (Excluded from Git)
- Python:
3.10or higher - API Key: OpenRouter API Key for LLM access
-
Clone the repository
git clone https://github.com/SLU-404FoundUs/Legal-Adaptive-Routing-Framework.git cd Legal-Adaptive-Routing-Framework -
Setup Virtual Environment
Choose the instructions for your operating system:
Windows (PowerShell)
# 1. Set execution policy (Required to run scripts) Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser # 2. Create virtual environment python -m venv myvenv # 3. Activate virtual environment .\myvenv\Scripts\Activate.ps1 # 4. Install dependencies pip install -r requirements.txt
macOS / Linux (Terminal)
# 1. Create virtual environment python3 -m venv myvenv # 2. Activate virtual environment source myvenv/bin/activate # 3. Install dependencies pip install -r requirements.txt
-
Initialize and Run The
.envconfiguration file is automatically generated when you first run either the CLI or Web interface.[!TIP] To utilize the latest stable configuration for both
WEB.pyandCLI.py, it is highly recommended to import thestable_veritas_v1.configfile (located inlocalfiles/) via the Configuration menu in the Web Interface.Run CLI Version:
python CLI.py
Run Web Version:
python WEB.py
Note: On your first run, you will be prompted to enter your OpenRouter API key and preferred models.
Launch the interactive command-line interface with customizable settings and an isolated terminal popup:
python CLI.pyNote: A discrete popup terminal will launch to run the assistant clearly on both Windows and macOS.
To use the Web-based Graphical User Interface, start the Flask web server:
python WEB.pyThen, open your browser and navigate to the address displayed in the terminal (usually http://localhost:5220).
You can import the modules directly into your Python application:
from src.adaptive_routing import TriageModule, SemanticRouterModule
# 1. Initialize Modules
triage = TriageModule()
router = SemanticRouterModule()
# 2. Process Input (Taglish -> English)
input_text = "Tinanggal ako sa trabaho ng walang notice."
result = triage._process_request_(input_text)
normalized_text = result['normalized_text']
# Output: "I was terminated from my job without notice."
# 3. Route & Generate Legal Response
if normalized_text:
response = router._process_routing_(normalized_text)
print(f"Advice: {response['response_text']}")For detailed API references, configuration options, and architectural diagrams, please refer to the Full Documentation.
Portions of the code in this framework were generated with the assistance of an agentic AI. However, all components have been thoroughly tested, reviewed, and validated by the developers to ensure safety, correctness, and adherence to legal logic standards.
- Deleon, Earl Macy —
2221816@slu.edu.ph - Diola, Josh Mckenzie —
2225962@slu.edu.ph - Lachica, Rafael —
2195465@slu.edu.ph - Lucban, Prince John Louie —
2225254@slu.edu.ph - Navarro, Josiah Ezra —
2233059@slu.edu.ph - Ramos, Albert Jannsen —
2221023@slu.edu.ph - Retuta, Ian Benedick —
2223041@slu.edu.ph - Yuen, Ka Hang Christian —
2214959@slu.edu.ph
Contributions are welcome! Please ensure that you follow the Technical Documentation Standards when adding new modules.
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature) - Commit your Changes (
git commit -m 'Add some AmazingFeature') - Push to the Branch (
git push origin feature/AmazingFeature) - Open a Pull Request
Distributed under the MIT License. See LICENSE for more information.
Thesis Study by Team 404FoundUs