Spaces:
Sleeping
Sleeping
| from crewai import Task | |
| """ | |
| Create context analysis task will return output in JSON format | |
| it helps to extract customer name, context, requires database, requires policy and summary briefing note | |
| These data will help the manager decide which co-worker to delegate to | |
| """ | |
| def create_context_analysis_task(agent, query): | |
| return Task( | |
| description=( | |
| f"**INCOMING MEMO**: '{query}'\n\n" | |
| "**ROLE**: You are a JSON Classification Engine. You do not speak English. You output data.\n" | |
| "**OBJECTIVE**: Map the user's request to exactly ONE of the 4 intent categories below.\n\n" | |
| "**CLASSIFICATION TRUTH TABLE (STRICT)**:\n" | |
| "1. **General Chat**: Greetings, jokes, or vague comments (e.g., 'Hello', 'What can you do?').\n" | |
| " -> requires_database: False | requires_policy: False\n" | |
| "2. **Policy Question**: Asking for rules, rates, limits, or eligibility WITHOUT naming a person.\n" | |
| " -> requires_database: False | requires_policy: True\n" | |
| "3. **Customer Info**: Asking for static data about a person (ID, Address, Status) WITHOUT asking for rules/rates.\n" | |
| " -> requires_database: True | requires_policy: False\n" | |
| "4. **Loan Request**: Asking if a specific person qualifies, or checking rates for a specific person.\n" | |
| " -> requires_database: True | requires_policy: True\n\n" | |
| "**EXTRACTION RULES**:\n" | |
| "- **customer_name**: Extract the exact substring (e.g., 'Andy'). If no name, set to null.\n" | |
| "- **Context**: Look ONLY at the provided string. Do not infer previous conversations.\n\n" | |
| "**NEGATIVE CONSTRAINTS**:\n" | |
| "- DO NOT include 'Here is the JSON'.\n" | |
| "- DO NOT output markdown ticks (```json). Just the raw curly braces.\n\n" | |
| "**REQUIRED OUTPUT SCHEMA**:\n" | |
| "{\n" | |
| ' "thought_process": "A clear, 1-sentence summary of the strategy. (e.g. \'User asked for a loan, so I will trigger the Data and Policy agents.\')",\n' | |
| ' "intent": "General Chat" | "Policy Question" | "Customer Info" | "Loan Request",\n' | |
| ' "customer_name": "string or null",\n' | |
| ' "requires_database": boolean,\n' | |
| ' "requires_policy": boolean,\n' | |
| ' "briefing_note": "string"\n' | |
| "}" | |
| ), | |
| expected_output="A single valid JSON object containing the classification flags and intent.", | |
| agent=agent | |
| ) |