Update app/agents/tools.py
Browse files- app/agents/tools.py +11 -7
app/agents/tools.py
CHANGED
|
@@ -160,7 +160,7 @@ def run_underwriting_func(tool_input: str) -> str:
|
|
| 160 |
def create_loan_application_func(tool_input: str) -> str:
|
| 161 |
"""
|
| 162 |
Create loan application record and generate sanction letter.
|
| 163 |
-
|
| 164 |
|
| 165 |
Args:
|
| 166 |
tool_input: JSON string with user_id, session_id
|
|
@@ -192,11 +192,12 @@ def create_loan_application_func(tool_input: str) -> str:
|
|
| 192 |
|
| 193 |
decision = session["loan_decision"]
|
| 194 |
|
| 195 |
-
#
|
| 196 |
-
|
|
|
|
| 197 |
return json.dumps({
|
| 198 |
"success": False,
|
| 199 |
-
"error": f"Cannot create sanction letter for {decision['decision']} loan"
|
| 200 |
})
|
| 201 |
|
| 202 |
# Get user profile
|
|
@@ -212,7 +213,7 @@ def create_loan_application_func(tool_input: str) -> str:
|
|
| 212 |
"user_id": user_id,
|
| 213 |
"full_name": profile["full_name"],
|
| 214 |
"email": profile["email"],
|
| 215 |
-
"requested_amount": decision["approved_amount"], # Use approved amount
|
| 216 |
"requested_tenure_months": decision["tenure_months"],
|
| 217 |
"approved_amount": decision["approved_amount"],
|
| 218 |
"tenure_months": decision["tenure_months"],
|
|
@@ -220,7 +221,7 @@ def create_loan_application_func(tool_input: str) -> str:
|
|
| 220 |
"interest_rate": decision["interest_rate"],
|
| 221 |
"credit_score": decision["credit_score"],
|
| 222 |
"foir": decision["foir"],
|
| 223 |
-
"decision":
|
| 224 |
"risk_band": decision["risk_band"],
|
| 225 |
"explanation": decision["explanation"],
|
| 226 |
"created_at": datetime.utcnow(),
|
|
@@ -254,7 +255,10 @@ def create_loan_application_func(tool_input: str) -> str:
|
|
| 254 |
"success": True,
|
| 255 |
"loan_id": loan_id,
|
| 256 |
"sanction_pdf_path": pdf_path,
|
| 257 |
-
"
|
|
|
|
|
|
|
|
|
|
| 258 |
})
|
| 259 |
|
| 260 |
except Exception as e:
|
|
|
|
| 160 |
def create_loan_application_func(tool_input: str) -> str:
|
| 161 |
"""
|
| 162 |
Create loan application record and generate sanction letter.
|
| 163 |
+
Works for APPROVED loans and ADJUST loans (after user accepts).
|
| 164 |
|
| 165 |
Args:
|
| 166 |
tool_input: JSON string with user_id, session_id
|
|
|
|
| 192 |
|
| 193 |
decision = session["loan_decision"]
|
| 194 |
|
| 195 |
+
# Accept both APPROVED and ADJUST decisions
|
| 196 |
+
# ADJUST means user accepted the adjusted terms
|
| 197 |
+
if decision["decision"] not in ["APPROVED", "ADJUST"]:
|
| 198 |
return json.dumps({
|
| 199 |
"success": False,
|
| 200 |
+
"error": f"Cannot create sanction letter for {decision['decision']} loan. Only APPROVED or ADJUST loans can generate sanction letters."
|
| 201 |
})
|
| 202 |
|
| 203 |
# Get user profile
|
|
|
|
| 213 |
"user_id": user_id,
|
| 214 |
"full_name": profile["full_name"],
|
| 215 |
"email": profile["email"],
|
| 216 |
+
"requested_amount": decision["approved_amount"], # Use approved/adjusted amount
|
| 217 |
"requested_tenure_months": decision["tenure_months"],
|
| 218 |
"approved_amount": decision["approved_amount"],
|
| 219 |
"tenure_months": decision["tenure_months"],
|
|
|
|
| 221 |
"interest_rate": decision["interest_rate"],
|
| 222 |
"credit_score": decision["credit_score"],
|
| 223 |
"foir": decision["foir"],
|
| 224 |
+
"decision": "APPROVED", # Store as APPROVED in database (both APPROVED and ADJUST are approved)
|
| 225 |
"risk_band": decision["risk_band"],
|
| 226 |
"explanation": decision["explanation"],
|
| 227 |
"created_at": datetime.utcnow(),
|
|
|
|
| 255 |
"success": True,
|
| 256 |
"loan_id": loan_id,
|
| 257 |
"sanction_pdf_path": pdf_path,
|
| 258 |
+
"approved_amount": decision["approved_amount"],
|
| 259 |
+
"emi": decision["emi"],
|
| 260 |
+
"tenure_months": decision["tenure_months"],
|
| 261 |
+
"message": f"Sanction letter generated successfully! Loan ID: {loan_id}"
|
| 262 |
})
|
| 263 |
|
| 264 |
except Exception as e:
|