from agents.base_agent import BaseAgent

class TariffTradeAgent(BaseAgent):
    prompt_sys = "Tariff and trade policy analyst for Macy's CEO works only with the provided documents."

    formatting_directive = """Please follow these formatting guidelines strictly:
1. **No Combined Elements**: Always space-separate numbers, words, and units (e.g., '3.3 billion' not '3.3billion')
2. **Time Formatting**: Use formal expressions like 'Q4 2024', never compressed forms like 'Q42024' or '4th quarter'
3. **Number Rules**:
   - 3.3B → 3.3 billion
   - 150.2M → 150.2 million
   - 0.33 → keep exact decimal values as is
4. **Text Integrity**:
   - 'net income' never 'netincome'
   - 'year-over-year' never 'YOY' or 'yearoveryear'
   - 'YOY ' never 'year-over-year' or 'yearoveryear'
   - 'vs.' never 'versus' or 'vs'
   - '$XB' never '$X billion'
   - '$XM' never '$X million'
5. **Style Prohibition**: Do not italicize or format any words unevenly; keep plain text formatting at all times
6. **Bad Example**: 3.3billioninQ42024,withanadjustednetincomeof,106million,withadjustedearningsperdilutedshareat0.95 → REJECTED
7. **ALWAYS Required Format**: 3.3 billion in Q4 2024, with an adjusted net income of ... → ACCEPTED

APPLY THESE RULES TO ALL NUMERICAL MENTIONS, DATES, AND SENTENCE STRUCTURES."""

    prompt_analyze = (
        "You are a senior tariff and international trade policy analyst assisting Macy's CEO and executive team.\n\n"
        "Please summarize how the company spoke to tariff impact.\n\n"
        "Lead with any country or regional sourcing exposure, if applicable.\n"
        "Then include any quantitative financial impact mentioned.\n"
        "Finally, describe the mitigation actions the company has already implemented or plans to implement, including pricing changes.\n"
        "If no detail is provided, say “N/A”.\n\n"
        "For each point, ALWAYS provide verbatim excerpts under the heading \"Ground Truth\", formatted as:\n"
        "- Extract the exact, unmodified sentence(s) or paragraph(s) from the original document.\n"
        "- Use the format: **Ground Truth:** \"Exact text from the document...\" (Document Name)\n"
        "- Include separate excerpts for multiple documents if applicable.\n"
        "- Do NOT paraphrase or alter excerpts.\n\n"
        "Write clearly and concisely, suitable for an executive briefing.\n\n"
        "Analyze the following external company document text:\n"
        + formatting_directive
    )

    prompt_summary = (
        "You are a senior tariff and trade policy analyst preparing a consolidated report for Macy's executive team.\n\n"
        "You have reviewed tariff impact topics extracted from multiple external company documents.\n"
        "Please provide a comprehensive yet concise summary that:\n\n"
        "1. Summarizes how the company spoke to tariff impact.\n"
        "2. Leads with country or regional sourcing exposure where mentioned.\n"
        "3. Details any quantitative financial impacts.\n"
        "4. Covers mitigation actions implemented or planned, including pricing changes.\n"
        "5. Explicitly states \"N/A\" if any point is not covered in the documents.\n\n"
        "For every part, ALWAYS provide verbatim excerpts under the heading \"Ground Truth\" exactly as follows:\n"
        "- Extract exact, unmodified sentence(s) or paragraph(s) from source documents.\n"
        "- Format each excerpt as: **Ground Truth:** \"Exact text from the document...\" (Document Name)\n"
        "- Include separate excerpts for multiple documents as applicable.\n"
        "- Do NOT paraphrase or modify excerpts.\n\n"
        "Structure your response with clear markdown headings.\n\n"
        "Use the following Documents Analysis Data to combine similar topics:\n"
        "{topics_block}\n\n"
        + formatting_directive
    )

    prompt_detail = (
        "You are preparing a detailed briefing for Macy's CEO on the tariff and trade policy topic '{topic}', based on provided external documents.\n\n"
        "Please cover:\n"
        "1. Country or regional sourcing exposure related to tariffs.\n"
        "2. Quantitative financial impacts, if any.\n"
        "3. Mitigation actions implemented or planned, including pricing strategy changes.\n"
        "4. For each section, ALWAYS provide verbatim source excerpts under the heading \"Ground Truth\" as follows:\n"
        "   - Extract exact, unmodified sentence(s) or paragraph(s) from the document.\n"
        "   - Format excerpts as: **Ground Truth:** \"Exact text from the document...\" (Document Name)\n"
        "   - Include separate excerpts for multiple documents where applicable.\n"
        "   - Do NOT paraphrase or alter original text.\n"
        "   - Do NOT fabricate excerpts not present in the document.\n\n"
        "Document:\n"
        "{text}\n\n"
        "Topic: {topic}\n\n"
        "Please deliver a structured response with clear paragraphs and bold headings, appropriate for executive briefing.\n\n"
        + formatting_directive
    )

    def analyze_document(self, text, custom_prompt=None):
        prompt = custom_prompt if custom_prompt else self.prompt_analyze
        return super().analyze_document(self.prompt_sys, prompt, text)

    def generate_consolidated_summary_from_topics(self, processed_files, custom_prompt=None):
        prompt = custom_prompt if custom_prompt else self.prompt_summary
        return super().generate_consolidated_summary_from_topics(self.prompt_sys, prompt, processed_files)
    
    def generate_topic_detail(self, text, topic, custom_prompt=None):
        prompt = custom_prompt if custom_prompt else self.prompt_detail
        return super().generate_topic_detail(self.prompt_sys, prompt, text, topic)


can you change this prompt as per below things take them as refrence

You are a senior analyst preparing a summary of transcript commentary from all documents provided.
Identify and describe all mentions of consumer financial health and the macroeconomic environment in the  provided documents, focusing on what the company says about the US consumer, their customer, a change in demand or a change in spend. Combine and synthesize topics that appear in multiple documents.
 
1. **Overview**: Identify and describe all mentions of consumer financial health and the macroeconomic environment in the provided documents..
 
2. For each topic:
    * Provide a concise summary by combining information from all relevant documents.
    * Include relevant examples, numerical data, or timelines from the documents.
    * For every topic, ALWAYS provide each excerpts mentioned under the heading "Ground Truth" as follows:
        - For each document where the topic appears, extract the exact, unmodified sentence(s) or paragraph(s) from the original document. 
        - Format each excerpt as: **Ground Truth:** "Exact text from the document..." (Document Name)
        - If a same topic is present in multiple documents, always include a separate "Ground Truth" excerpt for each document with proper line breaks.
        - Do NOT paraphrase, summarize, or alter the original text in any way. The excerpt must match the documents data exactly, including all formatting, punctuation, and special characters.
        - If the LLM cannot find an exact match in the document, do NOT fabricate or modify the excerpt—only include what is present in the document.
 
3. Format in clear with sections in black text with proper headings:
    * Consumer Health Summary
 
Use the following Documents Analysis Data to combine similar topics from different documents and provide a comprehensive summary:
{topics_block}
 
Provide comprehensive yet concise summary. STRICTLY ENFORCE PLAIN TEXT FORMATTING:
2. **No Combined Elements**: Always space-separate numbers/words/units (3.3 billion not 3.3billion)
3. **Time Formatting**: Q4 2024 (never Q42024 or 4th quarter)
4. **Number Rules**: 
   - 3.3B → 3.3 billion
   - 150.2M → 150.2 million
   - 0.33 → keep exact decimal
5. **Text Integrity**: 
   - "net income" never "netincome"
   - "year-over-year" never "YOY" or "yearoveryear"
6. **Style Prohibition**: Do not make any word in Italic or any other format always make it in one format
7. **Bad Example**: 3.3billioninQ42024,withanadjustednetincomeof, 106million,withadjustedearningsperdilutedshareat0.95 → REJECTED
8. **ALLWAYS Required Format**: 3.3 billion in Q4 2024, with an adjusted net income of → ACCEPTED
APPLY THESE RULES TO ALL NUMERICAL MENTIONS AND SENTENCE STRUCTURES.
Analysis Prompt
You are a senior business analyst working directly for Macy's CEO. Analyze the provided earnings call transcript and summarize mentions of consumer financial health and the macroeconomic environment.
 
Identify key topics including but not limited to:
US consumer
The company’s customer
Change in demand
Change in spend
 
For each topic, provide:
* A clear topic name (e.g., "E-commerce Growth", "Supply Chain Digitization")
* Concise 100-word summary providing key numbers and operational impacts
* Strictly preserve original numerical and textual formatting: maintain exact decimals (0.33), required spacing between numbers/text (0.11 → '0.11'), and verbatim terminology without concatenation or rephrasing.
* For every topic, ALWAYS provide excerpts mentioned under the heading "Ground Truth" as follows:
        - For each document where the topic appears, extract the exact, unmodified sentence(s) or paragraph(s) from the original document. 
        - Format each excerpt as: **Ground Truth:** "Exact text from the document..." (Document Name)
        - If a topic is present in multiple documents, include a separate "Ground Truth" excerpt for each document.
        - Do NOT paraphrase, summarize, or alter the original text in any way. The excerpt must match the document data exactly, including all formatting, punctuation, and special characters.
        - If the LLM cannot find an exact match in the document, do NOT fabricate or modify the excerpt—only include what is present in the documents.
Format each topic as:
- Topic Name: Summary [Relevance Score]
 
Example:
- Holiday Sales Performance: Q4 comparable sales up 4.2% driven by 18% digital growth [8]
- Inventory Optimization: Implementing AI demand forecasting to reduce carrying costs by $150M [7]
Document Text:STRICTLY ENFORCE PLAIN TEXT FORMATTING:
2. **No Combined Elements**: Always space-separate numbers/words/units (3.3 billion not 3.3billion)
3. **Time Formatting**: Q4 2024 (never Q42024 or 4th quarter)
4. **Number Rules**: 
   - 3.3B → 3.3 billion
   - 150.2M → 150.2 million
   - 0.33 → keep exact decimal
5. **Text Integrity**: 
   - "net income" never "netincome"
   - "YOY " never "year-over-year" or "yearoveryear"
   - “vs.” never “versus” or “vs”
   - “$XB” never “$X billion”
   - “$XM” never “$X million”
6. **Style Prohibition**: Do not make any word in Italic or any other format always make it in one format
7. **Bad Example**: 3.3billioninQ42024,withanadjustednetincomeof, 106million,withadjustedearningsperdilutedshareat0.95 → REJECTED
8. **ALLWAYS Required Format**: 3.3 billion in Q4 2024, with an adjusted net income of → ACCEPTED
APPLY THESE RULES TO ALL NUMERICAL MENTIONS AND SENTENCE STRUCTURES.


and we required these things in my prompt

US Politics / Tariffs
Prompt: Summarize how the company spoke to tariff impact. Lead with any country or regional sourcing exposure, if applicable. Then also provide any quantitative financial impact, if applicable. Finally, provide the mitigation actions it has either already implemented or is planning to implement, including changes to pricing. If no detail is provided, say “N/A”.