Spaces:
Sleeping
Sleeping
| from crewai import Agent | |
| from crew.tasks.context_tasks import create_context_analysis_task | |
| """ | |
| The Context Analyst | |
| Take in raw user text and classifies it into a structuctred JSON intent. | |
| There are 4 differeant intent (General Questions, Policy Question, Customer Info, Loan Reuqest). | |
| He help loan officer agent (Manager) understand the context of the query | |
| To prevent hallucination, we have set up the prompt in the way that this agent does not have access to DB and Rag vector DB | |
| """ | |
| class ContextAnalystAgent: | |
| def __init__(self, llm): | |
| self.agent = Agent( | |
| role="Senior Context Analyst", | |
| goal="Classify user queries into exactly one of 4 intent categories.", | |
| backstory=( | |
| "You are the **Executive Assitant** for the Chief Loan Officer (Orchestrator).\n" | |
| "**YOUR JOB**: You sit in the front office. You read the incoming message, understand the context, " | |
| "and type up a clean, structured 'One-Page Briefing' (JSON) for the Chief Loan Officer (Orchestrator).\n\n" | |
| "### HARDWARE LIMITATIONS (CRITICAL):\n" | |
| "1. **NO DATABASE ACCESS**: You physically cannot see the customer database.\n" | |
| "2. **NO POLICY ACCESS**: You do not have the policy manual PDF.\n" | |
| "3. **TEXT ONLY**: You operate in a sealed room. You only see the text slip passed under the door.\n\n" | |
| "### YOUR CLASSIFICATION PROTOCOL:\n" | |
| "You must map every query to one of these 4 intents based on the text *alone*:\n" | |
| "1. **General Chat** (No Action)\n" | |
| "2. **Policy Question** (Needs Rules, No Name)\n" | |
| "3. **Customer Info** (Needs Name, No Rules)\n" | |
| "4. **Loan Request** (Needs Name + Rules)\n\n" | |
| "**OUTPUT**: Return strict JSON. Do not write memos." | |
| ), | |
| llm=llm, | |
| verbose=True, | |
| allow_delegation=False, | |
| max_iter=2 | |
| ) | |
| def get_task(self, query): | |
| return create_context_analysis_task(self.agent, query) |