nimonkaranurag/langchain-study

🤖 Build a Code Review Assistant

Open

#3 opened on Nov 15, 2025

View on GitHub
 (4 comments) (0 reactions) (1 assignee)Python (1 fork)auto 404
advancedagentic aienhancementgood first issuelangchain

Repository metrics

Stars
 (1 star)
PR merge metrics
 (PR metrics pending)

Description

Description

Create a new assistant that helps users review Python code by following the established architecture patterns in this repository. This will demonstrate understanding of the builder pattern, tool integration, and RAG implementation.

Objective

Build a production-ready assistant that:

  1. Accepts Python code snippets
  2. Performs static analysis
  3. Suggests improvements based on PEP 8 and best practices
  4. Provides examples from a knowledge base

Architecture Requirements

1. Extend Base Classes

Create these files following existing patterns:

assistants/code_review_assistant/code_review_assistant.py

  • Extend assistants.assistant.Assistant
  • Implement query(user_input: str) -> CodeReviewResponse
  • Maintain conversation history
  • Handle tool calls for code analysis

assistants/code_review_assistant/code_review_assistant_builder.py

  • Extend assistants.assistant_builder.AssistantBuilder
  • Configure LLM with code-focused system prompt
  • Register tools: analyze_code, suggest_refactoring, check_pep8

assistants/code_review_assistant/schemas.py

  • Define CodeReviewResponse (Pydantic model)
  • Include fields: review_summary, issues_found, suggestions, severity_score

2. Implement Tools

assistants/code_review_assistant/tools.py

from langchain_core.tools import tool

@tool
def analyze_code(code_snippet: str) -> dict:
    """
    Analyze Python code for common issues.
    Uses ast module for syntax checking.
    """
    # Implementation using Python's ast module
    pass

@tool  
def check_pep8(code_snippet: str) -> dict:
    """
    Check code against PEP 8 style guidelines.
    """
    # Integration with pylint or flake8
    pass

3. Optional: Add RAG (Advanced)

assistants/code_review_assistant/code_patterns_ingestor.py

  • Ingest Python best practices documentation
  • Store code pattern examples in Pinecone
  • Follow the Ingestor and IngestionPipeline pattern from data_ingestor.py

4. CLI Entry Point

assistants/code_review_assistant/main.py

  • Follow the pattern from other assistants' main.py
  • Accept code via stdin or file path
  • Display formatted review results

5. Streamlit Integration

frontend/pages/code_review_assistant.py

  • Code input area (st.text_area with syntax highlighting)
  • Display review results in expandable sections
  • Show severity indicators with color coding

Acceptance Criteria

  • All abstract methods from base classes implemented
  • At least 2 functional tools integrated
  • Pydantic schema for structured responses
  • System prompt guides code review behavior
  • CLI interface works end-to-end
  • Streamlit page functional (optional for backend-focused)
  • Follows existing code style and patterns
  • No breaking changes to existing assistants

Testing Checklist

# Test code snippet
def calculate_sum(numbers):
    total = 0
    for num in numbers:
        total = total + num
    return total

Expected review should catch:

  • Missing type hints
  • Could use sum() builtin
  • Missing docstring
  • Variable naming could be more descriptive

Resources

  • Study existing assistants: hr_assistant/, study_assistant/, search_assistant/
  • Base classes: assistants/assistant.py, assistants/data_ingestor.py
  • LangChain tools: Tool Documentation
  • Python AST: ast module docs

Success Metrics

  • Code runs without errors
  • Provides actionable feedback
  • Demonstrates architectural understanding
  • Could be extended to support other languages

Difficulty: Advanced

Estimated effort: 6-8 hours
Skills demonstrated: Software architecture, LangChain agents, RAG, tool integration, testing


Maintainer notes: This issue demonstrates understanding of:

  • Builder pattern implementation
  • Abstract base class extension
  • Tool decorator usage
  • Pydantic schema design
  • RAG pipeline (optional)

Contributor guide