Skip to content

Conversation

devsyntax123
Copy link

@devsyntax123 devsyntax123 commented May 28, 2025

I have implemented the same project — "MCP-powered Financial Analyst using CrewAI" : but this time using LangGraph instead of CrewAI.

Why LangGraph?
*Granular control over the multi-agent workflow.

*It is a graph-based framework, which offers better modularity and flow customization.

*Allows for more explicit step-by-step agent orchestration, which is ideal for complex agentic tasks like financial analysis.

This implementation mirrors the original use case but showcases the potential of LangGraph for building more controllable and structured multi-agent systems.

Summary by CodeRabbit

  • New Features

    • Introduced a financial analysis workflow that interprets natural language stock queries and generates executable Python code for data analysis and visualization.
    • Added tools to analyze stocks, save generated code, and execute code to display plots.
    • Provided a Jupyter notebook demonstrating the workflow and example usage.
  • Documentation

    • Added setup instructions, usage examples, and project overview in a new README file.
  • Chores

    • Added environment configuration and requirements files for easy setup.

Copy link
Contributor

coderabbitai bot commented May 28, 2025

Walkthrough

A new financial analysis workflow project was introduced, featuring environment setup, documentation, and a modular codebase. The workflow parses user queries about stock analysis, generates corresponding Python code using Azure OpenAI, and enables code execution and visualization. A server interface provides tools for query analysis, code saving, and code execution. Dependency management and setup instructions are included.

Changes

File(s) Change Summary
.env, requirements.txt Added environment configuration file for Azure OpenAI credentials and a requirements file listing dependencies including langgraph, langchain, pydantic, yfinance, matplotlib, python-dotenv, ipython, and mcp.
README.md Added project documentation detailing the workflow purpose, setup instructions, environment configuration, MCP server integration with Cursor IDE, and example usage queries for stock performance and comparison analysis.
building-financial-analyst-langgraph.ipynb, finance_langgraph.py Introduced a Jupyter notebook and a Python module implementing the workflow: parsing queries, generating Python code, and returning results. Defined Pydantic models, a typed state dictionary, node functions for each workflow step, and the workflow graph. Provided sample usage, error handling, and visualization of the workflow graph. Included environment variable loading and Azure OpenAI chat model integration.
server.py Added a FastMCP server module exposing three tools: analyze_stock (generates Python code from natural language queries), save_code (writes code to file), and run_code_and_show_plot (executes saved code to display plots). Integrated with the workflow module and included basic exception handling. Server runs locally with stdio transport.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Server
    participant Workflow
    participant AzureOpenAI

    User->>Server: analyze_stock(query)
    Server->>Workflow: run_financial_analysis(query)
    Workflow->>AzureOpenAI: Parse query (QueryParser node)
    AzureOpenAI-->>Workflow: Parsed fields (symbol, timeframe, action)
    Workflow->>AzureOpenAI: Generate Python code (CodeWriter node)
    AzureOpenAI-->>Workflow: Python code
    Workflow-->>Server: Return generated code
    Server-->>User: Show generated code

    User->>Server: save_code(code)
    Server->>Server: Write code to stock_analysis.py
    Server-->>User: Return success or error message

    User->>Server: run_code_and_show_plot()
    Server->>Server: Execute stock_analysis.py
    Server-->>User: Display plot or result
Loading

Poem

In the warren of code, a new path is unfurled,
For stocks and for charts, a new workflow is twirled.
With queries parsed smartly and code spun with care,
Plots bloom like carrots in digital air.
🐇💹
Hooray for the analysts—let’s analyze and share!

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 10

♻️ Duplicate comments (3)
financial-analyst-deepseek/financial-analyst-langgraph/building-financial-analyst-langgraph.ipynb (3)

9-21: 🛠️ Refactor suggestion

Clean up imports in the notebook.

Similar to the Python module, this notebook has several unused imports that should be removed for clarity.


130-130: ⚠️ Potential issue

Fix typo: "recieved" → "received"


147-147: ⚠️ Potential issue

Fix critical syntax error in code_result function.

Same issue as in the Python module - incorrect dictionary access.

 def code_result(state: StockAnalysisState):
-    ans=StockAnalysisState["generated_code"]
+    ans = state["generated_code"]
     return {"execution_result": ans}
🧹 Nitpick comments (7)
financial-analyst-deepseek/financial-analyst-langgraph/README.md (2)

15-24: Fix markdown formatting issues.

The static analysis tools identified several formatting issues that should be addressed for better readability.

Apply these formatting improvements:

-**Fill Your Environment Variables**
+## Fill Your Environment Variables

 A `.env` file is already included in the project.  
-Open the file and fill in your actual API keys:
+Open the file and fill in your actual API keys.
+
+Copy the example environment file and configure your credentials:
+```bash
+cp .env.example .env
+# Edit .env with your actual Azure OpenAI credentials
+```

-**Install Dependencies**
+## Install Dependencies

    Ensure you have Python 3.12 or later installed.
-```
+```bash
    pip install -r requirements.txt

<details>
<summary>🧰 Tools</summary>

<details>
<summary>🪛 markdownlint-cli2 (0.17.2)</summary>

15-15: Emphasis used instead of a heading
null

(MD036, no-emphasis-as-heading)

---

24-24: Emphasis used instead of a heading
null

(MD036, no-emphasis-as-heading)

</details>

</details>

---

`59-59`: **Add missing comma for better readability.**



```diff
-In Cursor MCP settings make sure to toggle the button to connect the server to the host. Done! Your server is now up and running.
+In Cursor MCP settings, make sure to toggle the button to connect the server to the host. Done! Your server is now up and running.
🧰 Tools
🪛 LanguageTool

[uncategorized] ~59-~59: A comma might be missing here.
Context: ...ted in the MCP settings. In Cursor MCP settings make sure to toggle the button to conne...

(AI_EN_LECTOR_MISSING_PUNCTUATION_COMMA)

financial-analyst-deepseek/financial-analyst-langgraph/server.py (1)

27-31: Enhance error handling in analyze_stock function.

The current error handling is minimal and doesn't provide enough context for debugging issues.

     try:
         result = run_financial_analysis(query)
+        if not result:
+            return "Error: No analysis result generated"
         return result
     except Exception as e:
+        import traceback
+        error_details = traceback.format_exc()
+        print(f"Analysis error: {error_details}")  # Log for debugging
         return f"Error: {e}"
financial-analyst-deepseek/financial-analyst-langgraph/finance_langgraph.py (1)

56-61: Consider extracting the prompt to improve readability.

The prompt string is quite long and contains formatting instructions. Consider moving it to a constant or separate function for better maintainability.

+CODE_WRITER_PROMPT = """You are a Senior Python Developer. Generate code to {action} the stock data.
+Stock: {symbol}
+Timeframe: {timeframe}
+
+Use yfinance, pandas, and matplotlib libraries. Output should be a clean, executable .py Python script for stock visualization without explanations or AI-generated messages—just the direct script content, without ''' or any code blockers."""
+
 def code_writer_node(state: StockAnalysisState):
     parsed = state["parsed_output"]
     if isinstance(parsed, dict):
         raise NodeInterrupt("received wrong type")
-    fprompt = """You are a Senior Python Developer. Generate code to {action} the stock data.
-    Stock: {symbol}
-    Timeframe: {timeframe}
-
-    Use yfinance, pandas, and matplotlib libraries. Output should be a clean, executable .py Python script for stock visualization without explanations or AI-generated messages—just the direct script content. without ''' or any code blockers
-    """
+    
     action=parsed.result.action
     symbol=parsed.result.symbol
     time=parsed.result.timeframe
-    ffprompt=fprompt.format(action=action,symbol=symbol,timeframe=time)
+    ffprompt=CODE_WRITER_PROMPT.format(action=action,symbol=symbol,timeframe=time)
     code = llm.invoke(ffprompt)
     return {"generated_code": code}
financial-analyst-deepseek/financial-analyst-langgraph/building-financial-analyst-langgraph.ipynb (3)

24-30: Remove empty code cell.

This empty cell serves no purpose and should be removed to keep the notebook clean.


135-135: Improve prompt formatting.

The prompt has awkward phrasing "without ''' or any code blockers". Consider rephrasing to be clearer.

-    Use yfinance, pandas, and matplotlib libraries. Output should be a clean, executable .py Python script for stock visualization without explanations or AI-generated messages—just the direct script content.without ''' or any code blockers
+    Use yfinance, pandas, and matplotlib libraries. Output should be a clean, executable Python script for stock visualization without explanations or AI-generated messages—just the direct script content without code block markers.

247-250: Remove empty cells at the end of notebook.

These empty cells at the end serve no purpose and should be removed.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 234a727 and 9a3c7f8.

⛔ Files ignored due to path filters (1)
  • financial-analyst-deepseek/financial-analyst-langgraph/graph.png is excluded by !**/*.png
📒 Files selected for processing (6)
  • financial-analyst-deepseek/financial-analyst-langgraph/.env (1 hunks)
  • financial-analyst-deepseek/financial-analyst-langgraph/README.md (1 hunks)
  • financial-analyst-deepseek/financial-analyst-langgraph/building-financial-analyst-langgraph.ipynb (1 hunks)
  • financial-analyst-deepseek/financial-analyst-langgraph/finance_langgraph.py (1 hunks)
  • financial-analyst-deepseek/financial-analyst-langgraph/requirements.txt (1 hunks)
  • financial-analyst-deepseek/financial-analyst-langgraph/server.py (1 hunks)
🧰 Additional context used
🪛 LanguageTool
financial-analyst-deepseek/financial-analyst-langgraph/README.md

[uncategorized] ~59-~59: A comma might be missing here.
Context: ...ted in the MCP settings. In Cursor MCP settings make sure to toggle the button to conne...

(AI_EN_LECTOR_MISSING_PUNCTUATION_COMMA)

🪛 markdownlint-cli2 (0.17.2)
financial-analyst-deepseek/financial-analyst-langgraph/README.md

15-15: Emphasis used instead of a heading
null

(MD036, no-emphasis-as-heading)


24-24: Emphasis used instead of a heading
null

(MD036, no-emphasis-as-heading)


27-27: Fenced code blocks should have a language specified
null

(MD040, fenced-code-language)

🪛 Ruff (0.11.9)
financial-analyst-deepseek/financial-analyst-langgraph/finance_langgraph.py

3-3: langchain_core.runnables.Runnable imported but unused

Remove unused import: langchain_core.runnables.Runnable

(F401)


4-4: typing.Literal imported but unused

Remove unused import: typing.Literal

(F401)


5-5: langchain_core.messages.AIMessage imported but unused

Remove unused import

(F401)


5-5: langchain_core.messages.HumanMessage imported but unused

Remove unused import

(F401)


6-6: ast imported but unused

Remove unused import: ast

(F401)


7-7: IPython.display.Image imported but unused

Remove unused import

(F401)


7-7: IPython.display.display imported but unused

Remove unused import

(F401)


8-8: typing.Dict imported but unused

Remove unused import: typing.Dict

(F401)


13-13: yfinance imported but unused

Remove unused import: yfinance

(F401)


98-98: Found useless attribute access. Either assign it to a variable or remove it.

(B018)

🔇 Additional comments (3)
financial-analyst-deepseek/financial-analyst-langgraph/server.py (1)

2-2:

✅ Verification successful

Verify the imported module exists.

The import references finance_langgraph module which is not provided in this review. Ensure this module exists and contains the run_financial_analysis function.


🏁 Script executed:

#!/bin/bash
# Description: Check if the finance_langgraph module exists and contains the required function
# Expected: Find the file and the function definition

fd -t f "finance_langgraph.py"
if [ $? -eq 0 ]; then
    echo "=== Checking for run_financial_analysis function ==="
    rg -A 5 "def run_financial_analysis"
else
    echo "finance_langgraph.py not found in repository"
fi

Length of output: 1359


finance_langgraph module found
Confirmed that financial-analyst-langgraph/finance_langgraph.py defines the run_financial_analysis function. No further action required.

financial-analyst-deepseek/financial-analyst-langgraph/finance_langgraph.py (1)

26-37: Well-structured data models!

The Pydantic models and TypedDict are well-designed with clear field descriptions.

financial-analyst-deepseek/financial-analyst-langgraph/building-financial-analyst-langgraph.ipynb (1)

225-242: Good demonstration of workflow execution!

The notebook effectively demonstrates the end-to-end workflow by executing the generated code and displaying the stock chart.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

♻️ Duplicate comments (5)
financial-analyst-deepseek/financial-analyst-langgraph/finance_langgraph.py (5)

1-13: Remove unused imports to improve code clarity.

Multiple imports are not used in the code and should be removed to improve maintainability and reduce confusion.

🧰 Tools
🪛 Ruff (0.11.9)

3-3: langchain_core.runnables.Runnable imported but unused

Remove unused import: langchain_core.runnables.Runnable

(F401)


4-4: typing.Literal imported but unused

Remove unused import: typing.Literal

(F401)


5-5: langchain_core.messages.AIMessage imported but unused

Remove unused import

(F401)


5-5: langchain_core.messages.HumanMessage imported but unused

Remove unused import

(F401)


6-6: ast imported but unused

Remove unused import: ast

(F401)


7-7: IPython.display.Image imported but unused

Remove unused import

(F401)


7-7: IPython.display.display imported but unused

Remove unused import

(F401)


8-8: typing.Dict imported but unused

Remove unused import: typing.Dict

(F401)


13-13: yfinance imported but unused

Remove unused import: yfinance

(F401)


17-22: Add validation for required environment variables.

The code directly accesses Azure OpenAI environment variables without validation, which can cause unclear errors if any are missing.


54-55: Fix typo in error message.

"recieved" should be "received".


70-73: Fix critical syntax error in code_result function.

The function incorrectly accesses the TypedDict class instead of the state parameter.


96-99: Remove dead code and add error handling.

Line 98 accesses result["generated_code"].content without using it, and the function lacks error handling.

🧹 Nitpick comments (2)
financial-analyst-deepseek/financial-analyst-langgraph/finance_langgraph.py (2)

43-45: Clean up prompt formatting.

The prompt has trailing whitespace and could be formatted more cleanly.

-    prompt = """You are a Stock Data Analyst. Extract stock details from this user query: {query}. 
-    
-    """
+    prompt = """You are a Stock Data Analyst. Extract stock details from this user query: {query}."""

62-65: Improve variable naming consistency.

Variable names could be more descriptive and consistent to enhance code readability.

-    action=parsed.result.action
-    symbol=parsed.result.symbol
-    time=parsed.result.timeframe
-    ffprompt=fprompt.format(action=action,symbol=symbol,timeframe=time)
+    action = parsed.result.action
+    symbol = parsed.result.symbol
+    timeframe = parsed.result.timeframe
+    final_prompt = fprompt.format(action=action, symbol=symbol, timeframe=timeframe)
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9a3c7f8 and b65e151.

📒 Files selected for processing (1)
  • financial-analyst-deepseek/financial-analyst-langgraph/finance_langgraph.py (1 hunks)
🧰 Additional context used
🪛 Ruff (0.11.9)
financial-analyst-deepseek/financial-analyst-langgraph/finance_langgraph.py

3-3: langchain_core.runnables.Runnable imported but unused

Remove unused import: langchain_core.runnables.Runnable

(F401)


4-4: typing.Literal imported but unused

Remove unused import: typing.Literal

(F401)


5-5: langchain_core.messages.AIMessage imported but unused

Remove unused import

(F401)


5-5: langchain_core.messages.HumanMessage imported but unused

Remove unused import

(F401)


6-6: ast imported but unused

Remove unused import: ast

(F401)


7-7: IPython.display.Image imported but unused

Remove unused import

(F401)


7-7: IPython.display.display imported but unused

Remove unused import

(F401)


8-8: typing.Dict imported but unused

Remove unused import: typing.Dict

(F401)


13-13: yfinance imported but unused

Remove unused import: yfinance

(F401)

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

♻️ Duplicate comments (3)
financial-analyst-deepseek/financial-analyst-langgraph/finance_langgraph.py (3)

1-13: Remove unused imports to improve code clarity.

Multiple imports are unused and should be removed as identified by static analysis tools.

🧰 Tools
🪛 Ruff (0.11.9)

3-3: langchain_core.runnables.Runnable imported but unused

Remove unused import: langchain_core.runnables.Runnable

(F401)


4-4: typing.Literal imported but unused

Remove unused import: typing.Literal

(F401)


5-5: langchain_core.messages.AIMessage imported but unused

Remove unused import

(F401)


5-5: langchain_core.messages.HumanMessage imported but unused

Remove unused import

(F401)


6-6: ast imported but unused

Remove unused import: ast

(F401)


7-7: IPython.display.Image imported but unused

Remove unused import

(F401)


7-7: IPython.display.display imported but unused

Remove unused import

(F401)


8-8: typing.Dict imported but unused

Remove unused import: typing.Dict

(F401)


13-13: yfinance imported but unused

Remove unused import: yfinance

(F401)


17-22: Add validation for required environment variables.

Environment variables are accessed without validation, which can cause unclear errors if any are missing.


54-55: Fix typo in error message.

The typo "recieved" should be "received".

🧹 Nitpick comments (2)
financial-analyst-deepseek/financial-analyst-langgraph/finance_langgraph.py (2)

41-50: Improve variable naming and prompt formatting.

Consider improving code style for better readability:

 def query_parser_node(state: StockAnalysisState):
     query = state["query"]
-    prompt = """You are a Stock Data Analyst. Extract stock details from this user query: {query}. 
-    
-    """
-    finalprompt=prompt.format(query=query)
-    llm_with_struc=llm.with_structured_output(QueryAnalysisOutput)
-    response = llm_with_struc.invoke(finalprompt)
+    prompt = """You are a Stock Data Analyst. Extract stock details from this user query: {query}."""
+    final_prompt = prompt.format(query=query)
+    llm_with_struct = llm.with_structured_output(QueryAnalysisOutput)
+    response = llm_with_struct.invoke(final_prompt)
     
     return {"parsed_output": response}

56-67: Improve variable naming consistency.

Consider using consistent and descriptive variable names for better code readability:

-    fprompt = """You are a Senior Python Developer. Generate code to {action} the stock data.
+    code_prompt = """You are a Senior Python Developer. Generate code to {action} the stock data.
     Stock: {symbol}
     Timeframe: {timeframe}

     Use yfinance, pandas, and matplotlib libraries. Output should be a clean, executable .py Python script for stock visualization without explanations or AI-generated messages—just the direct script content. without ''' or any code blockers
     """
-    action=parsed.result.action
-    symbol=parsed.result.symbol
-    time=parsed.result.timeframe
-    ffprompt=fprompt.format(action=action,symbol=symbol,timeframe=time)
-    code = llm.invoke(ffprompt)
+    action = parsed.result.action
+    symbol = parsed.result.symbol
+    timeframe = parsed.result.timeframe
+    final_prompt = code_prompt.format(action=action, symbol=symbol, timeframe=timeframe)
+    code = llm.invoke(final_prompt)
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b65e151 and 3861bf2.

📒 Files selected for processing (1)
  • financial-analyst-deepseek/financial-analyst-langgraph/finance_langgraph.py (1 hunks)
🧰 Additional context used
🪛 Ruff (0.11.9)
financial-analyst-deepseek/financial-analyst-langgraph/finance_langgraph.py

3-3: langchain_core.runnables.Runnable imported but unused

Remove unused import: langchain_core.runnables.Runnable

(F401)


4-4: typing.Literal imported but unused

Remove unused import: typing.Literal

(F401)


5-5: langchain_core.messages.AIMessage imported but unused

Remove unused import

(F401)


5-5: langchain_core.messages.HumanMessage imported but unused

Remove unused import

(F401)


6-6: ast imported but unused

Remove unused import: ast

(F401)


7-7: IPython.display.Image imported but unused

Remove unused import

(F401)


7-7: IPython.display.display imported but unused

Remove unused import

(F401)


8-8: typing.Dict imported but unused

Remove unused import: typing.Dict

(F401)


13-13: yfinance imported but unused

Remove unused import: yfinance

(F401)

🔇 Additional comments (2)
financial-analyst-deepseek/financial-analyst-langgraph/finance_langgraph.py (2)

26-37: LGTM! Well-structured Pydantic models.

The model definitions follow proper Pydantic patterns with clear field descriptions and appropriate typing.


76-103: LGTM! Well-structured workflow setup.

The LangGraph workflow is properly configured with appropriate node connections and the helper function provides a clean interface.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

♻️ Duplicate comments (4)
financial-analyst-deepseek/financial-analyst-langgraph/finance_langgraph.py (4)

1-13: Remove unused imports to improve code clarity.

Multiple imports are unused and should be removed as identified by static analysis.

🧰 Tools
🪛 Ruff (0.11.9)

3-3: langchain_core.runnables.Runnable imported but unused

Remove unused import: langchain_core.runnables.Runnable

(F401)


4-4: typing.Literal imported but unused

Remove unused import: typing.Literal

(F401)


5-5: langchain_core.messages.AIMessage imported but unused

Remove unused import

(F401)


5-5: langchain_core.messages.HumanMessage imported but unused

Remove unused import

(F401)


6-6: ast imported but unused

Remove unused import: ast

(F401)


7-7: IPython.display.Image imported but unused

Remove unused import

(F401)


7-7: IPython.display.display imported but unused

Remove unused import

(F401)


8-8: typing.Dict imported but unused

Remove unused import: typing.Dict

(F401)


13-13: yfinance imported but unused

Remove unused import: yfinance

(F401)


17-22: Add validation for required environment variables.

The code directly accesses Azure OpenAI environment variables without validation, which can cause unclear errors if any are missing.


54-55: Fix typo in error message.

"recieved" should be "received".


102-105: 🛠️ Refactor suggestion

Add error handling to prevent runtime failures.

The function should handle cases where the workflow fails or expected keys are missing:

 def run_financial_analysis(query):
-    result = workflow.invoke({"query": query})
-    
-    return result["generated_code"].content
+    try:
+        result = workflow.invoke({"query": query})
+        
+        if "generated_code" not in result:
+            raise ValueError("Workflow did not generate code")
+        
+        generated_code = result["generated_code"]
+        if not hasattr(generated_code, 'content'):
+            raise ValueError("Generated code has no content")
+            
+        return generated_code.content
+    except Exception as e:
+        raise RuntimeError(f"Financial analysis failed: {str(e)}")
🧹 Nitpick comments (2)
financial-analyst-deepseek/financial-analyst-langgraph/finance_langgraph.py (2)

46-47: Improve variable naming for better readability.

Consider using more descriptive variable names:

-    finalprompt=prompt.format(query=query)
-    llm_with_struc=llm.with_structured_output(QueryAnalysisOutput)
+    formatted_prompt = prompt.format(query=query)
+    structured_llm = llm.with_structured_output(QueryAnalysisOutput)

62-65: Improve variable naming and spacing.

Variable names could be more descriptive and consistent:

-    action=parsed.result.action
-    symbol=parsed.result.symbol
-    time=parsed.result.timeframe
-    ffprompt=fprompt.format(action=action,symbol=symbol,timeframe=time)
+    action = parsed.result.action
+    symbol = parsed.result.symbol
+    timeframe = parsed.result.timeframe
+    formatted_prompt = fprompt.format(action=action, symbol=symbol, timeframe=timeframe)
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3861bf2 and 5cf86f5.

📒 Files selected for processing (1)
  • financial-analyst-deepseek/financial-analyst-langgraph/finance_langgraph.py (1 hunks)
🧰 Additional context used
🪛 Ruff (0.11.9)
financial-analyst-deepseek/financial-analyst-langgraph/finance_langgraph.py

3-3: langchain_core.runnables.Runnable imported but unused

Remove unused import: langchain_core.runnables.Runnable

(F401)


4-4: typing.Literal imported but unused

Remove unused import: typing.Literal

(F401)


5-5: langchain_core.messages.AIMessage imported but unused

Remove unused import

(F401)


5-5: langchain_core.messages.HumanMessage imported but unused

Remove unused import

(F401)


6-6: ast imported but unused

Remove unused import: ast

(F401)


7-7: IPython.display.Image imported but unused

Remove unused import

(F401)


7-7: IPython.display.display imported but unused

Remove unused import

(F401)


8-8: typing.Dict imported but unused

Remove unused import: typing.Dict

(F401)


13-13: yfinance imported but unused

Remove unused import: yfinance

(F401)

Copy link
Owner

@patchy631 patchy631 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use uv as package manager.

refer this readme: https://github.com/patchy631/ai-engineering-hub/tree/main/mcp-video-rag

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please use UV as a package manager? rest of the things look good

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes definnetly, i will update

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants