File size: 3,011 Bytes
cffeaa1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
720964a
 
cffeaa1
 
 
 
 
 
 
 
720964a
cffeaa1
 
 
 
 
 
 
 
 
720964a
cffeaa1
 
 
 
 
 
 
 
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
from crewai import Task


"""

This task instructs the agent to act as the final decision maker.

KEY MECHANISM:
1. CONTEXT CONSUMPTION: It takes the inputs from the Data Agent (Facts) and Policy Agent (Rules).
2. LOGIC GATING: It applies a strict "If X then Y" logic chain.
3. ZERO-TRUST: It enforces a "Silent Policy = Reject" rule. If the policy manual doesn't explicitly allow it, the agent must reject it.
"""

def create_underwriting_task(agent, context_tasks):
    return Task(
        description=(
            "**INTERNAL RISK REVIEW**\n\n"
            "**INPUTS**: Review findings from Data Investigator and Policy Researcher.\n\n"
            
            "**STRICT EXECUTION RULES**:\n"
            "1. **Evidence Only**: Every decision must point to a specific data point or policy line provided in the context.\n"
            "2. **Silent Policy = Reject**: If the policy does not explicitly say 'Approve' for a scenario, the default answer is REJECT.\n"
            "3. **Missing Data**: If you do not see a credit score, do not estimate one. Fail the application as 'Incomplete Data'.\n\n"
            
            "**LOGICAL REASONING STEPS**:\n"
            "1. **Residency & Eligibility Check**: \n"
            "   - Check `nationality` and `is_pr` (Permanent Resident status).\n"
            "   - **DEFINITION**: A 'Foreigner' is anyone whose nationality is NOT 'Singaporean'.\n"
            "   - **THE STRICT RULE**: \n"
            "       - If Customer is Singaporean -> **PASS** (Eligible).\n"
            "       - If Customer is Non-Singaporean AND is PR (Permanent Resident) -> **PASS** (Eligible).\n"
            "       - **If Customer is Non-Singaporean AND is NOT Permanent Resident -> REJECT IMMEDIATELY**.\n"
            "   - (Reasoning: We do not lend to non-residents. Foreigners must hold PR status).\n\n"

            "2. **Risk Mapping**: \n"
            "   - Locate `credit_score` and `account_status` in the input.\n"
            "   - Map EXACTLY to the Risk Matrix provided.\n"
            "   - DETERMINE: Is the Overall Risk 'Low', 'Medium', or 'High'?\n\n"

            "3. **Final Verdict**: \n"
            "   - If its High Risk OR Non-Singaporean+PR, please REJECT.\n"
            "   - Low/Medium Risk is APPROVE.\n\n"
            
            "**REQUIRED OUTPUT**:\n"
            "Return a Markdown Memo. You MUST NOT add 'Notes', 'Suggestions', or 'Flexible terms'.\n"
            "End with this strict JSON block:\n"
            "```json\n"
            "{\n"
            '  "decision": "APPROVED" | "REJECTED",\n'
            '  "risk_level": "Low" | "Medium" | "High",\n'
            '  "interest_rate": "The numerical rate (e.g. 4.85%) or N/A",\n'
            '  "reason_code": "The specific rule from policy that triggered this decision"\n'
            "}\n"
            "```"
        ),
        expected_output="A Decision Memo derived 100% from provided text with no outside hallucination.",
        agent=agent,
        context=context_tasks
    )