can you improve this from agents.baseagent import BaseAgent class…
- User
can you improve this from agents.base_agent import BaseAgent
class QTDPerformanceAgent(BaseAgent): prompt_sys = "Quarter-to-date performance analyst for Macy's, focused on summarizing commentary about QTD or May or June performance across sales, comps, and earnings."
# Reuse the exact formatting enforcement instructions from ConsumerHealthAgent (adapt or extend if needed) formatting_directive = """Please strictly follow these formatting guidelines for all numerical mentions and sentence structures:- No Combined Elements: Always space-separate numbers, words, and units (e.g., "3.3 billion" not "3.3billion").
- Time Formatting: Use formats like "Q2 2024" or specific months like "May" or "June" (never "Q22024" or "2nd quarter").
- Number Rules:
- 3.3B → 3.3 billion
- 150.2M → 150.2 million
- 0.33 → keep exact decimal
- 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"
- "X billion"
- "X million"
- Style Prohibition: Do not italicize or alter text formatting; maintain a single plain format throughout.
- Bad Example:
3.3billioninMay,withsalesup4percent→ REJECTED - ALWAYS Required Format:
3.3 billion in May, with sales up 4 percent→ ACCEPTED
APPLY THESE RULES TO ALL NUMERICAL MENTIONS AND SENTENCE STRUCTURES."""
prompt_analyze = ( "You are a senior business analyst working directly for Macy's CEO. Summarize all commentary related to quarter-to-date performance or specific performance in May or June.\n\n" "Be explicit about the type of performance mentioned: sales, comparable sales (comps), or earnings.\n\n" "For each relevant mention:\n" "- Provide a clear, concise 100-word summary detailing the type of performance and key numerical metrics.\n" "- STRICTLY preserve original numerical and textual formatting: maintain exact decimals, spacing, and verbatim terminology without concatenation or rephrasing.\n" "- ALWAYS provide exact excerpts of the source text under the heading \"Ground Truth\" as follows:\n" " - Extract unmodified sentences or paragraphs exactly as they appear in the document.\n" " - Format each excerpt as: **Ground Truth:** \"Exact text from the document...\" (Document Name)\n" " - If multiple documents mention the topic, include separate excerpts for each.\n" " - Do NOT paraphrase, summarize, or alter the excerpts in any way; preserve all punctuation and formatting.\n" " - If no mention is found, respond with “N/A”.\n\n" "Format each topic as:\n" "- Topic Name (e.g., \"QTD Sales Performance\", \"May Earnings Summary\"): Summary [Relevance Score]\n\n" "Document Text: " + formatting_directive ) prompt_summary = ( "You are a senior analyst preparing a summary of all quarter-to-date and monthly (May, June) performance commentary from provided documents.\n\n" "1. Aggregate mentions and describe the QTD or monthly sales, comps, and earnings performance.\n\n" "2. For each identified performance topic:\n" " * Provide a concise combined summary from all relevant documents.\n" " * Include key numerical data and time references.\n" " * Provide exact source excerpts under the heading \"Ground Truth\" for each document, honoring all original formatting and punctuation.\n" " * If no information is available for a topic, state “N/A.”\n\n" "3. Format results with clear headings and maintain strict plain text formatting.\n\n" "Documents Analysis Data:\n" "{topics_block}\n\n" "SUMMARY:\n" + formatting_directive ) prompt_detail = ( "You are preparing a detailed briefing for Macy's CEO on the quarter-to-date or monthly performance topic '{topic}', based on the external documents.\n\n" "Provide:\n" "1. An overview of the QTD or monthly performance.\n" "2. Key quantitative insights and timelines associated with sales, comps, or earnings.\n" "3. Detailed analysis of implications for Macy's operations and financial outlook.\n" "4. ALWAYS include exact source excerpts under the heading \"Ground Truth\" as follows:\n" " - Exact, unmodified text from each relevant document.\n" " - Format each excerpt as: **Ground Truth:** \"Exact text from the document...\" (Document Name)\n" " - Include separate excerpts for multiple documents.\n" " - Do NOT paraphrase or edit any excerpts; maintain full fidelity.\n" " - If no content exists, state “N/A”.\n\n" "Document:\n" "{text}\n\n" "Topic: {topic}\n\n" "Provide a structured briefing with bolded section headings.\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)the upper was not getting any topic in prompt analyze
make it like according to below
from agents.base_agent import BaseAgent
class ConsumerHealthAgent(BaseAgent): prompt_sys = "Consumer health and macroeconomic analyst for Macy's, tasked with analyzing provided documents regarding consumer financial health and macro environment."
# Universal formatting enforcement line (adapted and extended where necessary) formatting_directive = """Please strictly follow these formatting guidelines for all numerical mentions and sentence structures:- No Combined Elements: Always space-separate numbers, words, and units (e.g., "3.3 billion" not "3.3billion").
- Time Formatting: Use formats like "Q4 2024" (never "Q42024" or "4th quarter").
- Number Rules:
- 3.3B → 3.3 billion
- 150.2M → 150.2 million
- 0.33 → keep exact decimal
- 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"
- "X billion"
- "X million"
- Style Prohibition: Do not italicize or alter text formatting; maintain a single plain format throughout.
- Bad Example:
3.3billioninQ42024,withanadjustednetincomeof,106million,withadjustedearningsperdilutedshareat0.95→ REJECTED - ALWAYS 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."""
prompt_analyze = ( "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.\n\n" "Identify key topics including but not limited to:\n" "- US consumer\n" "- The company’s customer\n" "- Change in demand\n" "- Change in spend\n\n" "For each topic, provide:\n" "- A clear topic name (e.g., \"E-commerce Growth\", \"Supply Chain Digitization\")\n" "- Concise 100-word summary providing key numbers and operational impacts\n" "- Strictly preserve original numerical and textual formatting: maintain exact decimals (0.33), required spacing (0.11 → '0.11'), and verbatim terminology without concatenation or rephrasing.\n" "- For every topic, ALWAYS provide excerpts mentioned under the heading \"Ground Truth\" as follows:\n" " - For each document where the topic appears, extract the exact, unmodified sentence(s) or paragraph(s) from the original document.\n" " - Format each excerpt as: **Ground Truth:** \"Exact text from the document...\" (Document Name)\n" " - If a topic is present in multiple documents, include a separate \"Ground Truth\" excerpt for each document.\n" " - 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.\n" " - 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.\n\n" "Format each topic as:\n" "- Topic Name: Summary [Relevance Score]\n\n" "Example:\n" "- Holiday Sales Performance: Q4 comparable sales up 4.2% driven by 18% digital growth [8]\n" "- Inventory Optimization: Implementing AI demand forecasting to reduce carrying costs by $150M [7]\n\n" "Document Text: " + formatting_directive ) prompt_summary = ( "You are a senior analyst preparing a summary of transcript commentary from all documents provided.\n" "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.\n\n" "1. **Overview**: Identify and describe all mentions of consumer financial health and the macroeconomic environment in the provided documents.\n\n" "2. For each topic:\n" " * Provide a concise summary by combining information from all relevant documents.\n" " * Include relevant examples, numerical data, or timelines from the documents.\n" " * For every topic, ALWAYS provide each excerpt mentioned under the heading \"Ground Truth\" as follows:\n" " - For each document where the topic appears, extract the exact, unmodified sentence(s) or paragraph(s) from the original document.\n" " - Format each excerpt as: **Ground Truth:** \"Exact text from the document...\" (Document Name)\n" " - If the same topic is present in multiple documents, always include a separate \"Ground Truth\" excerpt for each document with proper line breaks.\n" " - 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.\n" " - 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.\n\n" "3. Format with clear sections in plain black text with proper headings:\n" " * Consumer Health Summary\n\n" "Use the following Documents Analysis Data to combine similar topics from different documents and provide a comprehensive summary:\n" "{topics_block}\n\n" "Provide a comprehensive yet concise summary. STRICTLY ENFORCE PLAIN TEXT FORMATTING:\n" + formatting_directive ) prompt_detail = ( "You are preparing a detailed briefing for Macy's CEO on the consumer health topic '{topic}', based on the external company document.\n\n" "Provide:\n" "1. Overview of the topic.\n" "2. Key insights and relevant excerpts.\n" "3. Important figures, timelines, or operational metrics.\n" "4. Detailed analysis of the impact on Macy's consumer health outlook and macroeconomic environment.\n" "5. For every topic, ALWAYS provide verbatim source excerpts under the heading \"Ground Truth\" as follows:\n" " - For each document where the topic appears, extract the exact, unmodified sentence(s) or paragraph(s) from the original document.\n" " - Format each excerpt as: **Ground Truth:** \"Exact text from the document...\" (Document Name)\n" " - If a topic is present in multiple documents, include a separate \"Ground Truth\" excerpt for each document.\n" " - Do NOT paraphrase, summarize, or alter the original text in any way. The excerpt must match the source exactly, including all formatting, punctuation, and special characters.\n" " - 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 source.\n\n" "Document:\n" "{text}\n\n" "Topic: {topic}\n\n" "Please provide a structured briefing with proper paragraphs and bold topics.\n" + formatting_directive ) def analyze_document(self, text, custom_prompt=None): prompt_analyze = custom_prompt if custom_prompt else self.prompt_analyze return super().analyze_document(self.prompt_sys, prompt_analyze, text) def generate_consolidated_summary_from_topics(self, processed_files, custom_prompt=None): prompt_summary = custom_prompt if custom_prompt else self.prompt_summary return super().generate_consolidated_summary_from_topics(self.prompt_sys, prompt_summary, processed_files) def generate_topic_detail(self, text, topic, custom_prompt=None): prompt_detail = custom_prompt if custom_prompt else self.prompt_detail return super().generate_topic_detail(self.prompt_sys, prompt_detail, text, topic) - Assistant
Certainly! Below is an improved version of your
QTDPerformanceAgentthat follows the clear, topic-oriented style and structure of yourConsumerHealthAgent. Key changes include:- Explicit instructions to identify and name distinct performance topics (e.g., "QTD Sales Performance", "May Earnings").
- Clear instructions to provide concise summaries (∼100 words) per topic.
- Precise formatting instructions consistently embedded in the prompt.
- Explicit listing that the topics come from the input document (avoiding no-topic extraction).
- Consistent use of phrasing and instructions that guide the model to generate topic names and outputs.
from agents.base_agent import BaseAgent class QTDPerformanceAgent(BaseAgent): prompt_sys = ( "Quarter-to-date performance analyst for Macy's, focused on summarizing commentary about" " quarter-to-date (QTD) or specific monthly (May, June) performance across sales, comps, and earnings." ) formatting_directive = """Please strictly follow these formatting guidelines for all numerical mentions and sentence structures: 1. **No Combined Elements**: Always space-separate numbers, words, and units (e.g., "3.3 billion" not "3.3billion"). 2. **Time Formatting**: Use formats like "Q2 2024" or specific months like "May" or "June" (never "Q22024" or "2nd quarter"). 3. **Number Rules**: - 3.3B → 3.3 billion - 150.2M → 150.2 million - 0.33 → keep exact decimal 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 alter text formatting; maintain a single plain format throughout. 6. **Bad Example**: `3.3billioninMay,withsalesup4percent` → REJECTED 7. **ALWAYS Required Format**: `3.3 billion in May, with sales up 4 percent` → ACCEPTED APPLY THESE RULES TO ALL NUMERICAL MENTIONS AND SENTENCE STRUCTURES. """ prompt_analyze = ( "You are a senior business analyst working directly for Macy's CEO. Analyze the provided document and identify distinct topics related to quarter-to-date performance or specific monthly (May or June) performance in sales, comparable sales (comps), or earnings.\n\n" "For each topic identified:\n" "- Provide a clear, descriptive topic name (e.g., \"QTD Sales Performance\", \"May Earnings Summary\", \"June Comps Results\").\n" "- Write a concise summary of about 100 words explaining the performance details, including key numerical metrics and time references.\n" "- STRICTLY preserve original numerical and textual formatting: maintain exact decimals, spacing, and verbatim terminology without concatenation or rephrasing.\n" "- For every topic, ALWAYS provide exact excerpts from the source document under the heading \"Ground Truth\" as follows:\n" " - Extract unmodified sentences or paragraphs exactly as they appear in the document.\n" " - Format each excerpt as: **Ground Truth:** \"Exact text from the document...\" (Document Name)\n" " - If multiple sections mention the topic, include separate excerpts for each.\n" " - Do NOT paraphrase, summarize, or alter the excerpts in any way; preserve all punctuation and formatting.\n" "- If no mentions of any QTD or May/June performance are found, respond with “N/A”.\n\n" "Format each topic as:\n" "- Topic Name: Summary [Relevance Score]\n\n" "Example:\n" "- QTD Sales Performance: Quarterly sales increased 4.2 percent driven by strong e-commerce growth of 18 percent [9]\n" "- May Earnings Summary: Earnings per diluted share rose to 0.95 in May, up from 0.88 year-over-year [8]\n\n" "Document Text:\n" + formatting_directive ) prompt_summary = ( "You are a senior analyst preparing a comprehensive summary of all quarter-to-date and monthly (May, June) performance commentary from the provided documents.\n\n" "1. Aggregate identified topics and describe QTD or monthly sales, comps, and earnings performance.\n" "2. For each topic:\n" " * Provide a concise combined summary synthesizing relevant documents.\n" " * Include key numerical metrics and time references.\n" " * Provide exact source excerpts for each document under the heading \"Ground Truth\". Always preserve original formatting and punctuation.\n" " * If no information is available for a topic, state “N/A.”\n\n" "3. Format the results with clear headings, plain text only.\n\n" "Documents Analysis Data:\n" "{topics_block}\n\n" "SUMMARY:\n" + formatting_directive ) prompt_detail = ( "You are preparing a detailed briefing for Macy's CEO on the quarter-to-date or monthly performance topic '{topic}', based on the provided documents.\n\n" "Provide:\n" "1. An overview of the QTD or monthly performance.\n" "2. Key quantitative insights, timelines, and comparisons.\n" "3. Detailed assessment of implications for Macy's operations and financial outlook.\n" "4. ALWAYS include verbatim source excerpts under the heading \"Ground Truth\" as follows:\n" " - Exact, unmodified text from each relevant document.\n" " - Format each excerpt as: **Ground Truth:** \"Exact text from the document...\" (Document Name)\n" " - Include separate excerpts for multiple documents.\n" " - Do NOT paraphrase or edit excerpts; maintain full fidelity.\n" " - If no relevant information exists, state “N/A”.\n\n" "Document:\n" "{text}\n\n" "Topic: {topic}\n\n" "Please provide a structured briefing with clear bolded section headings.\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)
Key improvements in this version:
- Explicit instructions to discover and name each topic allows the model to break out separate performance topics rather than producing a single undifferentiated output.
- Example topic names & results format guide the model toward consistent output.
- Consistent requirement to quote exact excerpts prevents hallucination and ensures traceability.
- Specified fallback “N/A” if no relevant data, instead of silence.
- Plain text formatting directives repeated at all prompt stages ensure uniform result style.
- Structured layouts with numbered requirements and clear bullet points improve comprehension.
This approach closely mirrors the working
ConsumerHealthAgentstyle you shared and should increase the chances of meaningful, well-structured topic discovery and analysis from your QTD documents. - User
in promt analyze we do nit want to summarize that bu we want topics as per i provided
- Assistant
Thanks for the clarification! You want the
prompt_analyzeto extract or list topics only, without summarizing them yet. Then summaries happen later (in summary or detail prompts).So, the goal of
prompt_analyzeis:- Identify all relevant QTD or May/June performance topics (like "QTD Sales", "May Earnings", "June Comps", etc.)
- Output a list of topics (just names, possibly a brief description or mention, but NOT full summaries)
- Extract exact ground truth excerpts associated with each topic
- Do NOT summarize performance yet
Here is an improved
prompt_analyzefocusing only on identifying and extracting topics and exact source excerpts, without summarizing. The other methods will deal with summarization.
Updated
prompt_analyzefor Topic Extraction Only:prompt_analyze = ( "You are a senior business analyst working directly for Macy's CEO. Analyze the provided document and identify all distinct topics related to quarter-to-date (QTD) or monthly (May, June) performance in sales, comparable sales (comps), or earnings.\n\n" "For each topic identified:\n" "- Provide only a clear, descriptive topic name (e.g., \"QTD Sales Performance\", \"May Earnings\", \"June Comps Results\").\n" "- For every topic, ALWAYS provide exact excerpts from the source document under the heading \"Ground Truth\":\n" " - Extract the exact sentence(s) or paragraph(s) mentioning this topic, exactly as they appear in the document.\n" " - Format each excerpt as: **Ground Truth:** \"Exact text from the document...\" (Document Name)\n" " - If multiple excerpts apply to the same topic, include each excerpt separately.\n" " - Do NOT paraphrase, summarize, or alter the excerpts in any way.\n" "- If there are no relevant mentions, respond only with \"N/A\".\n\n" "Format your response as a list of topics with their associated excerpts as follows:\n" "- Topic Name\n" " **Ground Truth:** \"Exact text from the document...\" (Document Name)\n" " (repeat excerpts if multiple)\n\n" "Example:\n" "- QTD Sales Performance\n" " **Ground Truth:** \"QTD sales increased 4.2 percent driven by e-commerce growth.\" (Doc1)\n" "\n" "- May Earnings\n" " **Ground Truth:** \"Earnings per share rose to 0.95 in May, up from 0.88 previous year.\" (Doc1)\n" "\n" "Document Text:\n" + formatting_directive )
Explanation:
- No summaries yet — only topic names plus exact source excerpts.
- Clear structure: a bullet list of topics, each with its related ground truth excerpts underneath.
- Explicit example to guide formatting.
- Instruction to return
"N/A"if no topics found. - Strong emphasis on verbatim excerpts without paraphrasing.
Full class snippet (only changed
prompt_analyzeshown in context):class QTDPerformanceAgent(BaseAgent): prompt_sys = ( "Quarter-to-date performance analyst for Macy's, focused on summarizing commentary about" " quarter-to-date (QTD) or specific monthly (May, June) performance across sales, comps, and earnings." ) formatting_directive = """...""" # your existing formatting directive prompt_analyze = ( "You are a senior business analyst working directly for Macy's CEO. Analyze the provided document and identify all distinct topics related to quarter-to-date (QTD) or monthly (May, June) performance in sales, comparable sales (comps), or earnings.\n\n" "For each topic identified:\n" "- Provide only a clear, descriptive topic name (e.g., \"QTD Sales Performance\", \"May Earnings\", \"June Comps Results\").\n" "- For every topic, ALWAYS provide exact excerpts from the source document under the heading \"Ground Truth\":\n" " - Extract the exact sentence(s) or paragraph(s) mentioning this topic, exactly as they appear in the document.\n" " - Format each excerpt as: **Ground Truth:** \"Exact text from the document...\" (Document Name)\n" " - If multiple excerpts apply to the same topic, include each excerpt separately.\n" " - Do NOT paraphrase, summarize, or alter the excerpts in any way.\n" "- If there are no relevant mentions, respond only with \"N/A\".\n\n" "Format your response as a list of topics with their associated excerpts as follows:\n" "- Topic Name\n" " **Ground Truth:** \"Exact text from the document...\" (Document Name)\n" " (repeat excerpts if multiple)\n\n" "Example:\n" "- QTD Sales Performance\n" " **Ground Truth:** \"QTD sales increased 4.2 percent driven by e-commerce growth.\" (Doc1)\n" "\n" "- May Earnings\n" " **Ground Truth:** \"Earnings per share rose to 0.95 in May, up from 0.88 previous year.\" (Doc1)\n" "\n" "Document Text:\n" + formatting_directive ) # prompt_summary and prompt_detail remain unchanged, they will handle summaries and detailed analysis.
Let me know if you want me to also review or adjust your summary/detail prompts or methods to ensure smooth integration!