File size: 2,268 Bytes
a9ec4f6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7e453aa
a9ec4f6
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
"""
Simplified financial agent focused only on generating financial statements
"""
from typing import Dict, Any, Optional
import logging
from .base_config import FinRyverAgentConfig, create_agent_executor
from .simple_tools import FINANCIAL_TOOLS

logger = logging.getLogger(__name__)

class FinancialStatementAgent:
    """
    Simple agent that generates: Notes, Balance Sheet, P&L, Cash Flow
    """
    
    def __init__(self, config: Optional[FinRyverAgentConfig] = None):
        self.config = config or FinRyverAgentConfig()
        self.llm = self.config.get_llm()
        
        # Create agent with financial statement tools
        self.agent_executor = create_agent_executor(
            role="Financial Statement Generator",
            goal="Generate financial statements (notes, balance sheet, P&L, cash flow) from trial balance data",
            tools=FINANCIAL_TOOLS,
            context="You generate financial statements from trial balance files. Available outputs: Notes, Balance Sheet, P&L Statement, Cash Flow Statement.",
            llm=self.llm
        )
    
    
    async def generate_specific_statement(self, file_path: str, statement_type: str, note_numbers: str) -> Dict[str, Any]:
        """Generate a specific financial statement"""
        try:
            prompts = {
                "notes": f"Generate financial notes for note numbers {note_numbers} from {file_path}",
                "notes-llm": f"Generate financial notes using LLM for note numbers {note_numbers} from {file_path}",
                "balance_sheet": f"Generate balance sheet from {file_path} using note numbers {note_numbers}",
                "pnl": f"Generate P&L statement from {file_path} using note numbers {note_numbers}",
                "cash_flow": f"Generate cash flow statement from {file_path} using note numbers {note_numbers}"
            }
            
            prompt = prompts.get(statement_type, prompts["notes"])
            
            result = await self.agent_executor.ainvoke({"input": prompt})
            return {"status": "success", "result": result["output"]}
            
        except Exception as e:
            logger.error(f"Error generating {statement_type}: {e}")
            return {"status": "error", "error": str(e)}