Spaces:
Sleeping
Sleeping
File size: 7,583 Bytes
5774aff | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 | """
Uplan Visa Context Profiles
Jurisdiction-aware threshold lookup. Hardcoded for 4 visa categories in the PoC,
designed to be RAG-fed from immigration policy PDFs in production.
The VisaContext object gets passed into the rule engine and injected into every
agent prompt β same algebra, different Ξ±/Ξ΅/Ξ΄ values per visa+country combination.
"""
from __future__ import annotations
from dataclasses import dataclass, field
from typing import Optional
@dataclass
class VisaContext:
"""Threshold set for a specific visa_type + destination combination."""
visa_type: str
destination: str
applicant_country: Optional[str] = None
# Financial thresholds
min_balance: Optional[float] = None
balance_currency: str = "USD"
spike_ratio_alpha: float = 3.0
income_balance_epsilon: float = 0.20 # Tolerance for salary vs deposit mismatch
# Temporal thresholds
income_months_required: int = 6
gap_warn_days: int = 30
gap_crit_days: int = 90
# Sponsor thresholds
sponsor_coverage_multiplier: float = 1.2
# Required document types for this visa category
required_doc_types: list[str] = field(default_factory=list)
# Context string for agent prompts
jurisdiction_context: str = ""
def to_dict(self) -> dict:
"""Serialize for state storage and agent prompt injection."""
return {
"visa_type": self.visa_type,
"destination": self.destination,
"applicant_country": self.applicant_country,
"min_balance": self.min_balance,
"balance_currency": self.balance_currency,
"spike_ratio_alpha": self.spike_ratio_alpha,
"income_balance_epsilon": self.income_balance_epsilon,
"income_months_required": self.income_months_required,
"gap_warn_days": self.gap_warn_days,
"gap_crit_days": self.gap_crit_days,
"sponsor_coverage_multiplier": self.sponsor_coverage_multiplier,
"required_doc_types": self.required_doc_types,
"jurisdiction_context": self.jurisdiction_context,
}
# ββ Hardcoded profiles for PoC ββββββββββββββββββββββββββββββββββββββ
PROFILES: dict[tuple[str, str], VisaContext] = {
("student", "japan"): VisaContext(
visa_type="student",
destination="japan",
min_balance=2_000_000,
balance_currency="JPY",
spike_ratio_alpha=3.0,
income_balance_epsilon=0.15,
income_months_required=6,
gap_warn_days=30,
gap_crit_days=90,
sponsor_coverage_multiplier=1.2,
required_doc_types=[
"passport",
"bank_statement",
"payslip",
"enrollment_letter",
],
jurisdiction_context=(
"Japanese Student (COE) visa requirements: "
"Minimum bank balance of Β₯2,000,000. "
"6 months of consecutive bank statements required. "
"Certificate of Eligibility (COE) must match visa application dates. "
"All large deposits must have documented sources. "
"Sponsor must demonstrate income β₯1.2Γ total program costs."
),
),
("student", "uk"): VisaContext(
visa_type="student",
destination="uk",
min_balance=12_006, # 9 months Γ Β£1,334
balance_currency="GBP",
spike_ratio_alpha=2.5,
income_balance_epsilon=0.10,
income_months_required=3,
gap_warn_days=14,
gap_crit_days=30,
sponsor_coverage_multiplier=1.0,
required_doc_types=[
"passport",
"bank_statement",
"enrollment_letter",
],
jurisdiction_context=(
"UK Student (Tier 4/Student Route) visa requirements: "
"Minimum funds of Β£1,334/month for up to 9 months (Β£12,006 total) "
"for courses outside London. "
"Funds must be held for 28 consecutive days. "
"CAS letter required from licensed sponsor institution."
),
),
("student", "us"): VisaContext(
visa_type="student",
destination="us",
min_balance=None, # Full tuition + living β varies by institution
balance_currency="USD",
spike_ratio_alpha=3.0,
income_balance_epsilon=0.20,
income_months_required=6,
gap_warn_days=30,
gap_crit_days=90,
sponsor_coverage_multiplier=1.0,
required_doc_types=[
"passport",
"bank_statement",
"enrollment_letter",
"sponsor_letter",
],
jurisdiction_context=(
"US F-1 Student visa requirements: "
"Must demonstrate funding for full tuition + living expenses. "
"I-20 form from SEVP-certified school required. "
"Bank statements must show sufficient funds for first year minimum. "
"Sponsor's I-134 Affidavit of Support needed if not self-funded."
),
),
("work", "japan"): VisaContext(
visa_type="work",
destination="japan",
min_balance=500_000,
balance_currency="JPY",
spike_ratio_alpha=4.0,
income_balance_epsilon=0.20,
income_months_required=3,
gap_warn_days=30,
gap_crit_days=60,
sponsor_coverage_multiplier=1.0,
required_doc_types=[
"passport",
"employment_letter",
"tax_return",
"bank_statement",
],
jurisdiction_context=(
"Japanese Work visa (Engineer/Specialist in Humanities) requirements: "
"Employment contract or offer letter from Japanese company required. "
"Tax returns demonstrating income history. "
"Company must be registered as a visa sponsor."
),
),
}
# ββ Default profile (generic fallback) ββββββββββββββββββββββββββββββ
_DEFAULT = VisaContext(
visa_type="general",
destination="unknown",
min_balance=None,
balance_currency="USD",
spike_ratio_alpha=3.0,
income_balance_epsilon=0.20,
income_months_required=6,
gap_warn_days=30,
gap_crit_days=90,
sponsor_coverage_multiplier=1.2,
required_doc_types=["passport", "bank_statement"],
jurisdiction_context="General visa requirements. No jurisdiction-specific thresholds applied.",
)
def get_context(visa_type: str, destination: str) -> VisaContext:
"""Look up the threshold set for a visa_type + destination pair."""
key = (visa_type.lower().strip(), destination.lower().strip())
return PROFILES.get(key, _DEFAULT)
def list_available_profiles() -> list[dict]:
"""List all available visa profiles for UI dropdowns."""
return [
{
"visa_type": ctx.visa_type,
"destination": ctx.destination,
"label": f"{ctx.visa_type.title()} β {ctx.destination.title()}",
}
for ctx in PROFILES.values()
]
# ββ Destination / visa type options for UI ββββββββββββββββββββββββββ
DESTINATIONS = ["Japan", "UK", "US", "Canada", "Australia", "Germany"]
VISA_TYPES = ["Student", "Work", "Tourist", "Business", "Dependent"]
APPLICANT_COUNTRIES = [
"India", "China", "Philippines", "Vietnam", "Indonesia",
"Bangladesh", "Nepal", "Pakistan", "Sri Lanka", "Nigeria",
"Brazil", "Mexico", "South Korea", "Thailand", "Other",
]
|