|
""" |
|
QuantitativeAnalystExpert: A specialized expert that blends math, finance, and code domains |
|
for solving complex quantitative analysis tasks. |
|
""" |
|
|
|
from typing import Dict, Any, Optional |
|
from experts.base_expert import BaseExpert |
|
from experts.domain import DomainBase |
|
from experts.tools import ToolBase |
|
from experts.shared import shared |
|
from experts.chain_tracker import ChainTracker |
|
from experts.shared_memory import SharedMemory |
|
|
|
class QuantitativeAnalystExpert(BaseExpert): |
|
"""Expert specialized in quantitative analysis tasks.""" |
|
|
|
def __init__(self): |
|
super().__init__() |
|
self.domains = ["math", "finance", "code"] |
|
self.math_module = shared.math_module |
|
self.finance_module = shared.finance_module |
|
self.codegen_tool = shared.codegen_tool |
|
self.shared_memory = shared.memory |
|
self.chain_tracker = ChainTracker() |
|
|
|
def handle_task(self, task: Dict[str, Any], context: Optional[Dict[str, Any]] = None) -> Dict[str, Any]: |
|
""" |
|
Handle a quantitative analysis task by blending math, finance, and code domains. |
|
|
|
Args: |
|
task: Task description and parameters |
|
context: Optional context information |
|
|
|
Returns: |
|
Dict containing the blended analysis results |
|
""" |
|
|
|
memory_context = self.shared_memory.query(task) |
|
|
|
|
|
math_analysis = self.math_module.analyze(task) |
|
|
|
|
|
finance_evaluation = self.finance_module.evaluate(task) |
|
|
|
|
|
code_generation = self.codegen_tool.generate_code(task) |
|
|
|
|
|
combined_result = self._blend_results( |
|
math_analysis, |
|
finance_evaluation, |
|
code_generation, |
|
memory_context |
|
) |
|
|
|
|
|
self.chain_tracker.log_chain( |
|
task=task, |
|
math_result=math_analysis, |
|
finance_result=finance_evaluation, |
|
code_result=code_generation, |
|
final_result=combined_result |
|
) |
|
|
|
return combined_result |
|
|
|
def _blend_results(self, math: Dict, finance: Dict, code: Dict, memory: Dict) -> Dict: |
|
"""Combine results from different domains.""" |
|
|
|
|
|
|
|
|
|
|
|
|
|
blended_result = { |
|
"math_analysis": math, |
|
"financial_evaluation": finance, |
|
"generated_code": code, |
|
"context": memory, |
|
"final_recommendation": self._generate_recommendation(math, finance) |
|
} |
|
|
|
return blended_result |
|
|
|
def _generate_recommendation(self, math: Dict, finance: Dict) -> str: |
|
"""Generate a final recommendation based on math and finance analysis.""" |
|
|
|
return """Based on the quantitative analysis: |
|
- Mathematical soundness: {} |
|
- Financial implications: {} |
|
- Recommended action: {}""".format( |
|
math.get("confidence", "N/A"), |
|
finance.get("impact", "N/A"), |
|
self._determine_action(math, finance) |
|
) |
|
|
|
def _determine_action(self, math: Dict, finance: Dict) -> str: |
|
"""Determine appropriate action based on analysis.""" |
|
|
|
return "Analyze results and determine appropriate action" |
|
|