Spaces:
Sleeping
Sleeping
File size: 6,180 Bytes
388aa42 | 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 213 214 | """
Missed Benefits Calculator Agent
Estimates potential benefits user might have missed
"""
import json
from langchain_groq import ChatGroq
from langchain_core.messages import HumanMessage, SystemMessage
from config import GROQ_API_KEY
def get_llm():
"""Initialize Groq LLM"""
if not GROQ_API_KEY:
raise ValueError("GROQ_API_KEY not found in environment variables")
return ChatGroq(
api_key=GROQ_API_KEY,
model="llama-3.3-70b-versatile",
temperature=0.2
)
def calculate_missed_benefits(profile_data: dict, scheme_recommendations: str) -> dict:
"""
Calculates potential benefits the user might have missed in the past
Args:
profile_data: User profile dictionary
scheme_recommendations: Recommended schemes text
Returns:
Dictionary with missed benefits calculation
"""
try:
llm = get_llm()
profile_str = json.dumps(profile_data, indent=2)
prompt = f"""
You are a financial analyst specializing in Indian government welfare schemes.
Based on the user's profile and recommended schemes, calculate how much money/benefits
they might have missed in the past 5 years by not applying to eligible schemes.
**USER PROFILE:**
{profile_str}
**RECOMMENDED SCHEMES:**
{scheme_recommendations}
**ANALYSIS REQUIREMENTS:**
1. **Identify Eligible Schemes:**
- List schemes user was eligible for in past 5 years
- Consider age, income, education criteria over time
2. **Calculate Monetary Benefits:**
- One-time payments missed
- Annual recurring benefits missed
- Subsidies or discounts not availed
- Total missed amount (conservative estimate)
3. **Non-Monetary Benefits:**
- Training opportunities missed
- Healthcare benefits not utilized
- Educational scholarships lost
- Employment opportunities missed
4. **Year-wise Breakdown:**
- Provide year-wise missed benefit estimate
- Account for scheme start dates
- Consider eligibility changes over time
5. **Actionable Insights:**
- Can any benefits be claimed retroactively?
- Which schemes should be applied immediately?
- Priority ranking for current applications
**OUTPUT FORMAT:**
### Total Missed Benefits (Past 5 Years)
- **Monetary Loss:** ₹[Amount]
- **Non-Monetary Loss:** [Description]
### Year-wise Breakdown
**2022:**
- Scheme Name: ₹[Amount] | [Benefit Description]
**2023:**
- Scheme Name: ₹[Amount] | [Benefit Description]
[Continue for all years]
### Retroactive Claims Possible
- List schemes that allow backdated applications
- Required documentation for backdated claims
### Immediate Action Items
1. [Highest priority scheme to apply now]
2. [Second priority scheme]
3. [Third priority scheme]
### Future Projections
If user applies now, estimated benefits over next 5 years: ₹[Amount]
---
**IMPORTANT NOTES:**
- Provide conservative estimates (lower bound)
- Mark assumptions clearly
- Only include verified government schemes
- Consider state-specific schemes based on user's state
- Factor in income bracket changes over time
Proceed with calculation:
"""
messages = [
SystemMessage(content="You are a financial analyst for government welfare schemes. Provide realistic, conservative estimates."),
HumanMessage(content=prompt)
]
response = llm.invoke(messages)
return {
"calculation": response.content,
"profile_considered": profile_data.get('age', 'N/A'),
"schemes_analyzed": "Available in recommendations"
}
except Exception as e:
return {
"error": str(e),
"calculation": "Unable to calculate missed benefits"
}
def estimate_future_benefits(profile_data: dict, scheme_recommendations: str, years: int = 5) -> dict:
"""
Estimates potential benefits over the next N years if user applies now
Args:
profile_data: User profile dictionary
scheme_recommendations: Recommended schemes text
years: Number of years to project (default: 5)
Returns:
Dictionary with future benefits projection
"""
try:
llm = get_llm()
profile_str = json.dumps(profile_data, indent=2)
prompt = f"""
Based on the user's current profile and eligible schemes, estimate the total benefits
they can receive over the next {years} years if they apply immediately.
**USER PROFILE:**
{profile_str}
**ELIGIBLE SCHEMES:**
{scheme_recommendations}
Provide:
1. Year-wise projected benefits
2. Total estimated benefits over {years} years
3. Required actions to maximize benefits
4. Key deadlines to watch
Return structured calculation with conservative estimates.
"""
messages = [
SystemMessage(content="You are a financial projection analyst for government schemes."),
HumanMessage(content=prompt)
]
response = llm.invoke(messages)
return {
"projection": response.content,
"years_projected": years,
"profile_age": profile_data.get('age', 'N/A')
}
except Exception as e:
return {
"error": str(e),
"projection": "Unable to estimate future benefits"
}
if __name__ == "__main__":
# Test the agent
test_profile = {
"age": 25,
"income": "300000",
"caste": "OBC",
"state": "Maharashtra",
"education": "Bachelor's in Engineering",
"employment_status": "Unemployed"
}
test_schemes = """
1. PM Kisan Samman Nidhi: ₹6000 per year
2. Post Matric Scholarship (OBC): ₹5000-10000 per year
3. Skill Development Scheme: Free training worth ₹20000
"""
result = calculate_missed_benefits(test_profile, test_schemes)
print(json.dumps(result, indent=2))
|