fix: update stock analyst agent logic to handle financial queries properly

- Refined `mock_multi_agent.py` to parse and route stock-specific inputs correctly
- Addressed issue where StockAnalyst returned fallback prompts instead of actionable responses
- Improved overall agent logic for financial data interpretation and reply generation
pull/819/head
Pavan Kumar 2 days ago committed by ascender1729
parent b9ddc14941
commit 610064b717

@ -40,7 +40,37 @@ class MathAgent:
"response": "I can analyze stock data using moving averages and calculate percentage changes. For example: 'calculate moving average of [10,20,30,40,50] over 3 periods'" "response": "I can analyze stock data using moving averages and calculate percentage changes. For example: 'calculate moving average of [10,20,30,40,50] over 3 periods'"
} }
# Check if input is math-related # Check if input is stock-related (for StockAnalyst)
if self.agent.agent_name == "StockAnalyst" and "moving average" in task.lower():
try:
import re
# Extract list of numbers and period
numbers = re.findall(r'\[([\d,\s]+)\]', task)
period = re.findall(r'over\s+(\d+)\s+periods', task)
if numbers and period:
numbers = [float(n) for n in numbers[0].split(',')]
period = int(period[0])
if len(numbers) >= period:
# Calculate moving average
averages = []
for i in range(len(numbers) - period + 1):
avg = sum(numbers[i:i+period]) / period
averages.append(round(avg, 2))
return {
"agent": self.agent.agent_name,
"task": task,
"response": f"Moving averages: {averages}"
}
except Exception as e:
return {
"agent": self.agent.agent_name,
"task": task,
"error": f"Error calculating moving average: {str(e)}"
}
# Check if input is math-related (for Calculator)
if self.agent.agent_name == "Calculator":
math_keywords = ['add', 'plus', '+', 'multiply', 'times', '*', 'x', 'divide', '/', 'by'] math_keywords = ['add', 'plus', '+', 'multiply', 'times', '*', 'x', 'divide', '/', 'by']
if not any(keyword in task.lower() for keyword in math_keywords): if not any(keyword in task.lower() for keyword in math_keywords):
return { return {

Loading…
Cancel
Save