Created
December 16, 2025 04:29
-
-
Save pranjalAI/936db99c6df5b67de7799734d1b79c22 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # agents/ratios_agent.py | |
| from state import ResearchState | |
| from mcp_client import call_mcp_tool | |
| class RatiosAgent: | |
| def run(self, state: ResearchState) -> ResearchState: | |
| symbol = state.symbol | |
| if not symbol: | |
| raise ValueError("Symbol missing in state.") | |
| ratios_ttm = call_mcp_tool("getFinancialRatiosTTM", {"symbol": symbol}) | |
| metrics_ttm = call_mcp_tool("getKeyMetricsTTM", {"symbol": symbol}) | |
| ratios = ratios_ttm[0] if isinstance(ratios_ttm, list) and ratios_ttm else ratios_ttm | |
| metrics = metrics_ttm[0] if isinstance(metrics_ttm, list) and metrics_ttm else metrics_ttm | |
| state.ratios = { | |
| "ratios_ttm": ratios or {}, | |
| "metrics_ttm": metrics or {}, | |
| } | |
| highlights = [] | |
| if ratios: | |
| pe = ratios.get("priceEarningsRatioTTM") | |
| if pe is not None: | |
| highlights.append(f"P/E (TTM): {pe:.2f}") | |
| net_margin = ratios.get("netProfitMarginTTM") | |
| if net_margin is not None: | |
| highlights.append(f"Net profit margin (TTM): {net_margin:.2%}") | |
| debt_to_equity = ratios.get("debtEquityTTM") | |
| if debt_to_equity is not None: | |
| highlights.append(f"Debt-to-equity: {debt_to_equity:.2f}") | |
| if metrics: | |
| roe = metrics.get("roeTTM") | |
| if roe is not None: | |
| highlights.append(f"Return on equity (TTM): {roe:.2%}") | |
| state.highlights.extend(highlights) | |
| return state | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment