|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## Project Overview |
| 6 | + |
| 7 | +This is a LangGraph ReAct (Reasoning and Action) Agent template that implements an iterative reasoning agent using LangGraph framework. The agent processes user queries through a cycle of reasoning, action execution, and observation. |
| 8 | + |
| 9 | +## Architecture |
| 10 | + |
| 11 | +The core architecture follows a modular stateful graph pattern: |
| 12 | + |
| 13 | +- **Common Module**: Shared components in `src/common/` provide reusable functionality across agents |
| 14 | +- **State Management**: Uses `State` and `InputState` dataclasses (defined in `src/react_agent/state.py`) to track conversation messages and execution state |
| 15 | +- **Graph Structure**: The main graph is defined in `src/react_agent/graph.py` with two primary nodes: |
| 16 | + - `call_model`: Handles LLM reasoning and tool selection |
| 17 | + - `tools`: Executes selected tools via ToolNode |
| 18 | +- **Execution Flow**: `call_model` → conditional routing → either `tools` (if tool calls needed) or `__end__` (if ready to respond) → back to `call_model` (creates the ReAct loop) |
| 19 | +- **Context System**: Runtime context defined in `src/common/context.py` provides model configuration, system prompts, and DeepWiki integration control |
| 20 | +- **Dynamic Tools**: Runtime tool loading with MCP integration for external documentation sources (DeepWiki MCP server) |
| 21 | + |
| 22 | +## Development Commands |
| 23 | + |
| 24 | +### Testing |
| 25 | +```bash |
| 26 | +# Run specific test types |
| 27 | +make test # Run unit and integration tests (default) |
| 28 | +make test_unit # Run unit tests only |
| 29 | +make test_integration # Run integration tests only |
| 30 | +make test_e2e # Run e2e tests only (requires running LangGraph server) |
| 31 | +make test_all # Run all tests (unit + integration + e2e) |
| 32 | + |
| 33 | +# Watch mode for continuous testing |
| 34 | +make test_watch # Run unit tests in watch mode |
| 35 | +make test_watch_unit # Run unit tests in watch mode |
| 36 | +make test_watch_integration # Run integration tests in watch mode |
| 37 | +make test_watch_e2e # Run e2e tests in watch mode |
| 38 | + |
| 39 | +# Additional test options |
| 40 | +make extended_tests # Run extended test suite |
| 41 | +``` |
| 42 | + |
| 43 | +### Code Quality |
| 44 | +```bash |
| 45 | +make lint # Run linters (ruff + mypy) |
| 46 | +make format # Auto-format code with ruff |
| 47 | +make lint_package # Lint only src/ directory |
| 48 | +make lint_tests # Lint only tests/ directory |
| 49 | +``` |
| 50 | + |
| 51 | +### Development Server |
| 52 | +```bash |
| 53 | +make dev # Start LangGraph development server |
| 54 | +make dev_ui # Start LangGraph development server with UI |
| 55 | +``` |
| 56 | + |
| 57 | +### Environment Setup |
| 58 | +- Copy `.env.example` to `.env` and configure API keys |
| 59 | +- **Required**: `TAVILY_API_KEY` for web search functionality |
| 60 | +- **Model Providers**: `ANTHROPIC_API_KEY`, `OPENAI_API_KEY`, `DASHSCOPE_API_KEY` (for Qwen models) |
| 61 | +- **Optional**: `REGION` (set to `prc` or `international` for Qwen API endpoints) |
| 62 | +- **Optional**: `ENABLE_DEEPWIKI=true` to enable DeepWiki MCP documentation tools |
| 63 | +- **Default Model**: Uses `qwen:qwen-turbo` as default model (configurable via `MODEL` environment variable) |
| 64 | + |
| 65 | +## Key Files and Their Purposes |
| 66 | + |
| 67 | +### Core Agent Files |
| 68 | +- `src/react_agent/graph.py`: Main graph definition and ReAct loop implementation |
| 69 | +- `src/react_agent/state.py`: State management with message tracking via `add_messages` annotation |
| 70 | + |
| 71 | +### Common Module (Shared Components) |
| 72 | +- `src/common/context.py`: Runtime context and configuration with environment variable support and DeepWiki integration |
| 73 | +- `src/common/tools.py`: Tool definitions including web search and dynamic MCP tool loading |
| 74 | +- `src/common/mcp.py`: MCP client management for external documentation sources (e.g. DeepWiki) |
| 75 | +- `src/common/models.py`: Custom model integrations (Qwen, QwQ, QvQ) with regional API support |
| 76 | +- `src/common/prompts.py`: System prompt templates |
| 77 | +- `src/common/utils.py`: Shared utility functions |
| 78 | + |
| 79 | +### Configuration |
| 80 | +- `langgraph.json`: LangGraph Studio configuration pointing to the main graph |
| 81 | +- `.env`: Environment variables for API keys and configuration |
| 82 | + |
| 83 | +## LangGraph Studio Integration |
| 84 | + |
| 85 | +This project is designed for LangGraph Studio. The `langgraph.json` config file defines: |
| 86 | +- Graph entry point: `./src/react_agent/graph.py:graph` |
| 87 | +- Environment file: `.env` |
| 88 | +- Dependencies: current directory (`.`) |
| 89 | + |
| 90 | +## MCP Integration |
| 91 | + |
| 92 | +This project integrates with Model Context Protocol (MCP) servers for dynamic external tool loading: |
| 93 | + |
| 94 | +- **DeepWiki MCP Server**: Provides documentation tools for GitHub repositories |
| 95 | +- **Dynamic Loading**: Tools are loaded at runtime based on context configuration |
| 96 | +- **Caching**: MCP client and tools are cached for performance |
| 97 | +- **Configuration**: Enable via `ENABLE_DEEPWIKI=true` environment variable or context parameter |
| 98 | +- **Server Configuration**: MCP servers configured in `src/common/mcp.py` |
| 99 | + |
| 100 | +### MCP Usage |
| 101 | +- Set `enable_deepwiki=True` in Context to load DeepWiki tools |
| 102 | +- Tools include repository documentation access and Q&A capabilities |
| 103 | +- Integrated seamlessly with LangGraph ReAct pattern for tool execution |
| 104 | + |
| 105 | +## Python Configuration |
| 106 | + |
| 107 | +- Python requirement: `>=3.11,<4.0` |
| 108 | +- Main dependencies: LangGraph, LangChain, provider-specific packages, langchain-mcp-adapters |
| 109 | +- Development tools: mypy, ruff, pytest |
| 110 | +- Package structure supports both standalone and LangGraph template usage |
| 111 | + |
| 112 | +## Development Guidelines |
| 113 | + |
| 114 | +- **Research Tools**: Use `context7` and/or `deepwiki` to study unfamiliar projects or frameworks |
| 115 | +- **Code Quality**: Always run `make lint` after completing tasks |
| 116 | +- **Testing**: Comprehensive test suite includes unit, integration, and e2e tests with DeepWiki MCP integration coverage |
| 117 | +- **MCP Integration**: DeepWiki tools are dynamically loaded when `enable_deepwiki=True` in context configuration |
0 commit comments