From ab730642731d9c8a400cad78e76962253ac875f2 Mon Sep 17 00:00:00 2001 From: Zongwei9888 Date: Thu, 11 Sep 2025 18:42:36 +0800 Subject: [PATCH 01/25] update the workflows --- deepcode.py | 2 +- prompts/code_prompts.py | 50 ++++++++++++----------- workflows/agents/memory_agent_concise.py | 4 +- workflows/code_implementation_workflow.py | 6 +-- 4 files changed, 31 insertions(+), 31 deletions(-) diff --git a/deepcode.py b/deepcode.py index 76fdec32..4121f176 100755 --- a/deepcode.py +++ b/deepcode.py @@ -182,7 +182,7 @@ def main(): "run", str(streamlit_app_path), "--server.port", - "8501", + "8502", "--server.address", "localhost", "--browser.gatherUsageStats", diff --git a/prompts/code_prompts.py b/prompts/code_prompts.py index 6356a3e7..c50d8bf2 100644 --- a/prompts/code_prompts.py +++ b/prompts/code_prompts.py @@ -584,7 +584,7 @@ ⚠️ IMPORTANT: Generate a COMPLETE plan that includes ALL 5 sections without being cut off by token limits. ## Content Balance Guidelines: -- **Section 1 (File Structure)**: Brief overview (10% of content) - Focus on CORE implementation files only +- **Section 1 (File Structure)**: Brief overview (10% of content) - Include all files but focus on implementation priority - **Section 2 (Implementation Components)**: Detailed but concise (40% of content) - This is the PRIORITY section - **Section 3 (Validation)**: Moderate detail (25% of content) - Essential experiments and tests - **Section 4 (Environment)**: Brief but complete (10% of content) - All necessary dependencies @@ -598,7 +598,7 @@ 4. **FOURTH**: Configuration and data handling 5. **LAST**: Documentation files (README.md, requirements.txt) - These should be created AFTER core implementation -Note: README and requirements.txt are maintenance files that depend on the final implementation, so plan them last. +Note: README and requirements.txt are maintenance files that depend on the final implementation, so plan them last but INCLUDE them in the file structure. # DETAILED SYNTHESIS PROCESS @@ -652,14 +652,16 @@ # - Organize files and directories in the most logical way for implementation # - Create meaningful names and groupings based on paper content # - Keep it clean, intuitive, and focused on what actually needs to be implemented - # - EXCLUDE documentation files (README.md, requirements.txt) - these come last + # - INCLUDE documentation files (README.md, requirements.txt) but mark them for LAST implementation file_structure: | [Design and specify your own project structure here - KEEP THIS BRIEF] - [Focus ONLY on core implementation files, NOT documentation files] + [Include ALL necessary files including README.md and requirements.txt] [Organize based on what this paper actually contains and needs] [Create directories and files that make sense for this specific implementation] - [EXCLUDE: README.md, requirements.txt - these come last in implementation] + [IMPORTANT: Include executable files (e.g., main.py, run.py, train.py, demo.py) - choose names based on repo content] + [Design executable entry points that match the paper's main functionality and experiments] + [NOTE: README.md and requirements.txt should be implemented LAST after all code files] # SECTION 2: Implementation Components @@ -1102,10 +1104,10 @@ - **Reference only**: Use `search_code_references(indexes_path="indexes", target_file=the_file_you_want_to_implement, keywords=the_keywords_you_want_to_search)` for reference, NOT as implementation standard - **Core principle**: Original paper requirements take absolute priority over any reference code found 3. **TOOL EXECUTION STRATEGY**: - - ⚠️**Development Cycle (for each new file implementation)**: `read_code_mem` (check existing implementations in Working Directory, use `read_file` as fallback if memory unavailable`) → `search_code_references` (OPTIONAL reference check from `/home/agent/indexes`) → `write_file` (implement based on original paper) → `execute_python` (if should test) - - **Environment Setup**: `write_file` (requirements.txt) → `execute_bash` (pip install) → `execute_python` (verify) + - ⚠️**Development Cycle (for each new file implementation)**: `read_code_mem` (check existing implementations in Working Directory, use `read_file` as fallback if memory unavailable`) → `search_code_references` (OPTIONAL reference check from `/home/agent/indexes`) → `write_file` (implement based on original paper) → `execute_python` (if needed to verify implementation) + - **File Verification**: Use `execute_bash` and `execute_python` when needed to check implementation completeness -4. **CRITICAL**: Use bash and python tools to ACTUALLY REPLICATE the paper yourself - do not provide instructions. +4. **CRITICAL**: Use bash and python tools when needed to CHECK and VERIFY implementation completeness - do not provide instructions. These tools help validate that your implementation files are syntactically correct and properly structured. **Execution Guidelines**: - **Plan First**: Before each action, explain your reasoning and which function you'll use @@ -1150,24 +1152,22 @@ 1. **Identify** what needs to be implemented from the requirements 2. **Analyze Dependencies**: Before implementing each new file, use `read_code_mem` to read summaries of already-implemented files, then search for reference patterns to guide your implementation approach. 3. **Implement** one component at a time -4. **Test** immediately using `execute_python` or `execute_bash` to catch issues early - THIS IS MANDATORY, NOT OPTIONAL +4. **Verify** optionally using `execute_python` or `execute_bash` to check implementation completeness if needed 5. **Integrate** with existing components -6. **Verify** against requirement specifications using execution tools to ensure everything works +6. **Validate** against requirement specifications **TOOL CALLING STRATEGY**: 1. ⚠️ **SINGLE FUNCTION CALL PER MESSAGE**: Each message may perform only one function call. You will see the result of the function right after sending the message. If you need to perform multiple actions, you can always send more messages with subsequent function calls. Do some reasoning before your actions, describing what function calls you are going to use and how they fit into your plan. 2. **TOOL EXECUTION STRATEGY**: - - **Development Cycle (for each new file implementation)**: `read_code_mem` (check existing implementations in Working Directory, use `read_file` as fallback if memory unavailable) → `write_file` (implement) → **MANDATORY TESTING**: `execute_python` or `execute_bash` (ALWAYS test after implementation) - - **Environment Setup**: Use `execute_bash` for installing packages, setting up dependencies, downloading files, etc. - - **Testing & Debugging**: Use `execute_python` for Python code testing and `execute_bash` for system commands, package installation, file operations, and bug fixing - - **⚠️ TESTING REMINDER**: After implementing ANY file, you MUST call either `execute_python` or `execute_bash` to test the implementation. Do not skip this step! + - **Development Cycle (for each new file implementation)**: `read_code_mem` (check existing implementations in Working Directory, use `read_file` as fallback if memory unavailable) → `write_file` (implement) → **Optional Verification**: `execute_python` or `execute_bash` (if needed to check implementation) + - **File Verification**: Use `execute_bash` and `execute_python` when needed to verify implementation completeness. -3. **CRITICAL**: Use `execute_bash` and `execute_python` tools to ACTUALLY IMPLEMENT and TEST the requirements yourself - do not provide instructions. These tools are essential for: - - Installing dependencies and setting up environments (`execute_bash`) - - Testing Python implementations (`execute_python`) - - Debugging and fixing issues (`execute_bash` for system-level, `execute_python` for Python-specific) - - Validating that your code actually works before moving to the next component +3. **CRITICAL**: Use `execute_bash` and `execute_python` tools when needed to CHECK and VERIFY file implementation completeness - do not provide instructions. These tools are essential for: + - Checking file syntax and import correctness (`execute_python`) + - Verifying file structure and dependencies (`execute_bash` for listing, `execute_python` for imports) + - Validating that implemented files are syntactically correct and can be imported + - Ensuring code implementation meets basic functionality requirements **Execution Guidelines**: - **Plan First**: Before each action, explain your reasoning and which function you'll use @@ -1633,7 +1633,7 @@ ⚠️ IMPORTANT: Generate a COMPLETE plan that includes ALL 5 sections without being cut off by token limits. ## Content Balance Guidelines: -- **Section 1 (File Structure)**: Brief overview (10% of content) - Focus on CORE implementation files only +- **Section 1 (File Structure)**: Brief overview (10% of content) - Include all files but focus on implementation priority - **Section 2 (Implementation Components)**: Detailed but concise (40% of content) - This is the PRIORITY section - **Section 3 (Validation)**: Moderate detail (25% of content) - Essential experiments and tests - **Section 4 (Environment)**: Brief but complete (10% of content) - All necessary dependencies @@ -1647,7 +1647,7 @@ 4. **FOURTH**: Configuration and data handling 5. **LAST**: Documentation files (README.md, requirements.txt) - These should be created AFTER core implementation -Note: README and requirements.txt are maintenance files that depend on the final implementation, so plan them last. +Note: README and requirements.txt are maintenance files that depend on the final implementation, so plan them last but INCLUDE them in the file structure. # DETAILED SYNTHESIS PROCESS @@ -1701,14 +1701,16 @@ # - Organize files and directories in the most logical way for implementation # - Create meaningful names and groupings based on paper content # - Keep it clean, intuitive, and focused on what actually needs to be implemented - # - EXCLUDE documentation files (README.md, requirements.txt) - these come last + # - INCLUDE documentation files (README.md, requirements.txt) but mark them for LAST implementation file_structure: | [Design and specify your own project structure here - KEEP THIS BRIEF] - [Focus ONLY on core implementation files, NOT documentation files] + [Include ALL necessary files including README.md and requirements.txt] [Organize based on what this paper actually contains and needs] [Create directories and files that make sense for this specific implementation] - [EXCLUDE: README.md, requirements.txt - these come last in implementation] + [IMPORTANT: Include executable files (e.g., main.py, run.py, train.py, demo.py) - choose names based on repo content] + [Design executable entry points that match the paper's main functionality and experiments] + [NOTE: README.md and requirements.txt should be implemented LAST after all code files] # SECTION 2: Implementation Components diff --git a/workflows/agents/memory_agent_concise.py b/workflows/agents/memory_agent_concise.py index b586739e..4b38ea92 100644 --- a/workflows/agents/memory_agent_concise.py +++ b/workflows/agents/memory_agent_concise.py @@ -1072,10 +1072,10 @@ def create_concise_messages( **For NEW file implementation:** 1. **You need to call read_code_mem(already_implemented_file_path)** to understand existing implementations and dependencies - agent should choose relevant ALREADY IMPLEMENTED file paths for reference, NOT the new file you want to create 2. Write_file can be used to implement the new component -3. Finally: Use execute_python or execute_bash for testing (if needed) +3. OPTIONALLY: Use execute_python or execute_bash if meet some specific requirements (if needed) **When all files implemented:** -1. **Use execute_python or execute_bash** to test the complete implementation""" +1. **Use execute_python or execute_bash** to test the complete implementation (if needed)""" # # Append Next Steps information if available (even when no tool results) # if self.current_next_steps.strip(): diff --git a/workflows/code_implementation_workflow.py b/workflows/code_implementation_workflow.py index 4b3e0a29..a38f5c96 100644 --- a/workflows/code_implementation_workflow.py +++ b/workflows/code_implementation_workflow.py @@ -935,11 +935,9 @@ async def main(): # Ask if user wants to continue with actual workflow print("\nContinuing with workflow execution...") - plan_file = "/Users/lizongwei/Reasearch/DeepCode_Base/DeepCode/deepcode_lab/papers/1/initial_plan.txt" + plan_file = "/Users/lizongwei/Reasearch/DeepCode_Base/DeepCode_eval_init/deepcode_lab/papers/1/initial_plan.txt" # plan_file = "/data2/bjdwhzzh/project-hku/Code-Agent2.0/Code-Agent/deepcode-mcp/agent_folders/papers/1/initial_plan.txt" - target_directory = ( - "/Users/lizongwei/Reasearch/DeepCode_Base/DeepCode/deepcode_lab/papers/1/" - ) + target_directory = "/Users/lizongwei/Reasearch/DeepCode_Base/DeepCode_eval_init/deepcode_lab/papers/1/" print("Implementation Mode Selection:") print("1. Pure Code Implementation Mode (Recommended)") print("2. Iterative Implementation Mode") From 064c3b62f835ae5315b5893b3b4bd98b54e34ffa Mon Sep 17 00:00:00 2001 From: Zongwei9888 Date: Wed, 24 Sep 2025 17:40:58 +0800 Subject: [PATCH 02/25] improve the code planning quality --- cli/cli_app.py | 57 +-------- cli/cli_interface.py | 57 ++++++++- cli/main_cli.py | 14 +-- mcp_agent.config.yaml | 157 +++++++++++------------- mcp_agent.secrets.yaml | 1 + workflows/agent_orchestration_engine.py | 149 ++++++++++++++++++++-- 6 files changed, 280 insertions(+), 155 deletions(-) diff --git a/cli/cli_app.py b/cli/cli_app.py index 6504ceda..3aab095f 100644 --- a/cli/cli_app.py +++ b/cli/cli_app.py @@ -37,8 +37,7 @@ def __init__(self): self.app = None # Will be initialized by workflow adapter self.logger = None self.context = None - # Document segmentation configuration - self.segmentation_config = {"enabled": True, "size_threshold_chars": 50000} + # Document segmentation will be managed by CLI interface async def initialize_mcp_app(self): """初始化MCP应用 - 使用工作流适配器""" @@ -49,50 +48,11 @@ async def cleanup_mcp_app(self): """清理MCP应用 - 使用工作流适配器""" await self.workflow_adapter.cleanup_mcp_app() - def update_segmentation_config(self): - """Update document segmentation configuration in mcp_agent.config.yaml""" - import yaml - import os - - config_path = os.path.join( - os.path.dirname(os.path.dirname(os.path.abspath(__file__))), - "mcp_agent.config.yaml", - ) - - try: - # Read current config - with open(config_path, "r", encoding="utf-8") as f: - config = yaml.safe_load(f) - - # Update document segmentation settings - if "document_segmentation" not in config: - config["document_segmentation"] = {} - - config["document_segmentation"]["enabled"] = self.segmentation_config[ - "enabled" - ] - config["document_segmentation"]["size_threshold_chars"] = ( - self.segmentation_config["size_threshold_chars"] - ) - - # Write updated config - with open(config_path, "w", encoding="utf-8") as f: - yaml.dump(config, f, default_flow_style=False, allow_unicode=True) - - self.cli.print_status( - "📄 Document segmentation configuration updated", "success" - ) - - except Exception as e: - self.cli.print_status( - f"⚠️ Failed to update segmentation config: {str(e)}", "warning" - ) async def process_input(self, input_source: str, input_type: str): """处理输入源(URL或文件)- 使用升级版智能体编排引擎""" try: - # Update segmentation configuration before processing - self.update_segmentation_config() + # Document segmentation configuration is managed by CLI interface self.cli.print_separator() self.cli.print_status( @@ -281,20 +241,9 @@ async def run_interactive_session(self): self.cli.show_history() elif choice in ["c", "config", "configure"]: - # Sync current segmentation config from CLI interface - self.segmentation_config["enabled"] = self.cli.segmentation_enabled - self.segmentation_config["size_threshold_chars"] = ( - self.cli.segmentation_threshold - ) - + # Show configuration menu - all settings managed by CLI interface self.cli.show_configuration_menu() - # Sync back from CLI interface after configuration changes - self.segmentation_config["enabled"] = self.cli.segmentation_enabled - self.segmentation_config["size_threshold_chars"] = ( - self.cli.segmentation_threshold - ) - else: self.cli.print_status( "Invalid choice. Please select U, F, T, C, H, or Q.", "warning" diff --git a/cli/cli_interface.py b/cli/cli_interface.py index 770dc1c9..e53773a5 100644 --- a/cli/cli_interface.py +++ b/cli/cli_interface.py @@ -40,9 +40,60 @@ def __init__(self): self.is_running = True self.processing_history = [] self.enable_indexing = True # Default configuration - self.segmentation_enabled = True # Default to smart segmentation - self.segmentation_threshold = 50000 # Default threshold + + # Load segmentation config from the same source as UI + self._load_segmentation_config() + + # Initialize tkinter availability + self._init_tkinter() + + def _load_segmentation_config(self): + """Load segmentation configuration from mcp_agent.config.yaml""" + try: + from utils.llm_utils import get_document_segmentation_config + seg_config = get_document_segmentation_config() + self.segmentation_enabled = seg_config.get("enabled", True) + self.segmentation_threshold = seg_config.get("size_threshold_chars", 50000) + except Exception as e: + print(f"⚠️ Warning: Failed to load segmentation config: {e}") + # Fall back to defaults + self.segmentation_enabled = True + self.segmentation_threshold = 50000 + + def _save_segmentation_config(self): + """Save segmentation configuration to mcp_agent.config.yaml""" + import yaml + import os + + # Get the project root directory (where mcp_agent.config.yaml is located) + current_file = os.path.abspath(__file__) + cli_dir = os.path.dirname(current_file) # cli directory + project_root = os.path.dirname(cli_dir) # project root + config_path = os.path.join(project_root, "mcp_agent.config.yaml") + + try: + # Read current config + with open(config_path, "r", encoding="utf-8") as f: + config = yaml.safe_load(f) + + # Update document segmentation settings + if "document_segmentation" not in config: + config["document_segmentation"] = {} + + config["document_segmentation"]["enabled"] = self.segmentation_enabled + config["document_segmentation"]["size_threshold_chars"] = self.segmentation_threshold + + # Write updated config + with open(config_path, "w", encoding="utf-8") as f: + yaml.dump(config, f, default_flow_style=False, allow_unicode=True) + + print(f"{Colors.OKGREEN}✅ Document segmentation configuration updated{Colors.ENDC}") + + except Exception as e: + print(f"{Colors.WARNING}⚠️ Failed to update segmentation config: {str(e)}{Colors.ENDC}") + def _init_tkinter(self): + """Initialize tkinter availability check""" # Check tkinter availability for file dialogs self.tkinter_available = True try: @@ -765,6 +816,8 @@ def show_configuration_menu(self): elif choice in ["s", "segmentation"]: current_state = getattr(self, "segmentation_enabled", True) self.segmentation_enabled = not current_state + # Save the configuration to file + self._save_segmentation_config() seg_mode = ( "📄 Smart Segmentation" if self.segmentation_enabled diff --git a/cli/main_cli.py b/cli/main_cli.py index 1e70baa0..bee8f748 100644 --- a/cli/main_cli.py +++ b/cli/main_cli.py @@ -230,18 +230,16 @@ async def main(): print( f"\n{Colors.MAGENTA}📄 Document segmentation disabled - using traditional processing{Colors.ENDC}" ) - app.segmentation_config = { - "enabled": False, - "size_threshold_chars": args.segmentation_threshold, - } + app.cli.segmentation_enabled = False + app.cli.segmentation_threshold = args.segmentation_threshold + app.cli._save_segmentation_config() else: print( f"\n{Colors.BLUE}📄 Smart document segmentation enabled (threshold: {args.segmentation_threshold} chars){Colors.ENDC}" ) - app.segmentation_config = { - "enabled": True, - "size_threshold_chars": args.segmentation_threshold, - } + app.cli.segmentation_enabled = True + app.cli.segmentation_threshold = args.segmentation_threshold + app.cli._save_segmentation_config() # 检查是否为直接处理模式 if args.file or args.url or args.chat: diff --git a/mcp_agent.config.yaml b/mcp_agent.config.yaml index 80a50f90..fce8aaf9 100644 --- a/mcp_agent.config.yaml +++ b/mcp_agent.config.yaml @@ -1,102 +1,91 @@ $schema: ./schema/mcp-agent.config.schema.json - -# Default search server configuration -# Options: "brave" or "bocha-mcp" -default_search_server: "brave" - -# Planning mode configuration -# Options: "segmented" or "traditional" -# segmented: Breaks down large tasks to avoid token truncation (recommended) -# traditional: Uses parallel agents but may hit token limits -planning_mode: "traditional" - -# Document segmentation configuration +anthropic: null +default_search_server: brave document_segmentation: - enabled: false # Whether to use intelligent document segmentation - size_threshold_chars: 50000 # Document size threshold (in characters) to trigger segmentation - # If document size > threshold and enabled=true, use segmentation workflow - # If document size <= threshold or enabled=false, use traditional full-document reading - + enabled: true + size_threshold_chars: 50000 execution_engine: asyncio logger: - transports: [console, file] level: info - progress_display: true path_settings: - path_pattern: "logs/mcp-agent-{unique_id}.jsonl" - unique_id: "timestamp" # Options: "timestamp" or "session_id" - timestamp_format: "%Y%m%d_%H%M%S" - - - + path_pattern: logs/mcp-agent-{unique_id}.jsonl + timestamp_format: '%Y%m%d_%H%M%S' + unique_id: timestamp + progress_display: true + transports: + - console + - file mcp: servers: - brave: - # On windows replace the command and args line to use `node` and the absolute path to the server. - # Use `npm i -g @modelcontextprotocol/server-brave-search` to install the server globally. - # Use `npm -g root` to find the global node_modules path.` - # command: "node" - # args: ["c:/Program Files/nodejs/node_modules/@modelcontextprotocol/server-brave-search/dist/index.js"] - command: "npx" - args: ["-y", "@modelcontextprotocol/server-brave-search"] - env: - # You can also place your BRAVE_API_KEY in the fastagent.secrets.yaml file. - BRAVE_API_KEY: "" - filesystem: - # On windows update the command and arguments to use `node` and the absolute path to the server. - # Use `npm i -g @modelcontextprotocol/server-filesystem` to install the server globally. - # Use `npm -g root` to find the global node_modules path.` - # command: "node" - # args: ["c:/Program Files/nodejs/node_modules/@modelcontextprotocol/server-filesystem/dist/index.js","."] - command: "npx" - args: ["-y", "@modelcontextprotocol/server-filesystem"] - fetch: - command: "uvx" - args: ["mcp-server-fetch"] - github-downloader: - command: "python" - args: ["tools/git_command.py"] - env: - PYTHONPATH: "." - file-downloader: - command: "python" - args: ["tools/pdf_downloader.py"] + bocha-mcp: + args: + - tools/bocha_search_server.py + command: python3 env: - PYTHONPATH: "." - command-executor: - command: "python" - args: ["tools/command_executor.py"] + BOCHA_API_KEY: '' + PYTHONPATH: . + brave: + args: + - -y + - '@modelcontextprotocol/server-brave-search' + command: npx env: - PYTHONPATH: "." + BRAVE_API_KEY: '' code-implementation: - command: "python" - args: ["tools/code_implementation_server.py"] + args: + - tools/code_implementation_server.py + command: python + description: Paper code reproduction tool server - provides file operations, + code execution, search and other functions env: - PYTHONPATH: "." - description: "Paper code reproduction tool server - provides file operations, code execution, search and other functions" + PYTHONPATH: . code-reference-indexer: - command: "python" - args: ["tools/code_reference_indexer.py"] + args: + - tools/code_reference_indexer.py + command: python + description: Code reference indexer server - Provides intelligent code reference + search from indexed repositories env: - PYTHONPATH: "." - description: "Code reference indexer server - Provides intelligent code reference search from indexed repositories" - bocha-mcp: - command: "python3" - args: ["tools/bocha_search_server.py"] + PYTHONPATH: . + command-executor: + args: + - tools/command_executor.py + command: python env: - PYTHONPATH: "." - BOCHA_API_KEY: "" + PYTHONPATH: . document-segmentation: - command: "python" - args: ["tools/document_segmentation_server.py"] + args: + - tools/document_segmentation_server.py + command: python + description: Document segmentation server - Provides intelligent document analysis + and segmented reading to optimize token usage + env: + PYTHONPATH: . + fetch: + args: + - mcp-server-fetch + command: uvx + file-downloader: + args: + - tools/pdf_downloader.py + command: python + env: + PYTHONPATH: . + filesystem: + args: + - -y + - '@modelcontextprotocol/server-filesystem' + - . + command: npx + github-downloader: + args: + - tools/git_command.py + command: python env: - PYTHONPATH: "." - description: "Document segmentation server - Provides intelligent document analysis and segmented reading to optimize token usage" - + PYTHONPATH: . openai: - # Secrets (API keys, etc.) are stored in an mcp_agent.secrets.yaml file which can be gitignored - # default_model: "o3-mini" - default_model: "anthropic/claude-3.5-sonnet" - - -anthropic: + base_max_tokens: 16384 + default_model: anthropic/claude-3.5-sonnet + max_tokens_policy: adaptive + retry_max_tokens: 32768 +planning_mode: traditional diff --git a/mcp_agent.secrets.yaml b/mcp_agent.secrets.yaml index 435cf3f7..6e670162 100644 --- a/mcp_agent.secrets.yaml +++ b/mcp_agent.secrets.yaml @@ -3,5 +3,6 @@ openai: base_url: "" + anthropic: api_key: "" diff --git a/workflows/agent_orchestration_engine.py b/workflows/agent_orchestration_engine.py index 3f2d602b..b766b641 100644 --- a/workflows/agent_orchestration_engine.py +++ b/workflows/agent_orchestration_engine.py @@ -62,6 +62,101 @@ os.environ["PYTHONDONTWRITEBYTECODE"] = "1" # Prevent .pyc file generation +def _assess_output_completeness(text: str) -> float: + """ + 智能评估输出完整性的高级算法 + + 使用多种启发式方法来检测输出是否被截断: + 1. 结构化标记完整性检查 + 2. 句子完整性分析 + 3. 代码块完整性验证 + 4. 预期内容元素检查 + + Returns: + float: 完整性分数 (0.0-1.0),越高表示越完整 + """ + if not text or len(text.strip()) < 100: + return 0.0 + + score = 0.0 + factors = 0 + + # 1. 基本长度检查 (权重: 0.2) + if len(text) > 5000: # 期望的最小输出长度 + score += 0.2 + elif len(text) > 2000: + score += 0.1 + factors += 1 + + # 2. 结构完整性检查 (权重: 0.3) + structure_indicators = [ + "## 1.", "## 2.", "## 3.", # 章节标题 + "```", "file_structure", "implementation", + "algorithm", "method", "function" + ] + structure_count = sum(1 for indicator in structure_indicators if indicator.lower() in text.lower()) + if structure_count >= 6: + score += 0.3 + elif structure_count >= 3: + score += 0.15 + factors += 1 + + # 3. 句子完整性检查 (权重: 0.2) + lines = text.strip().split('\n') + if lines: + last_line = lines[-1].strip() + # 检查最后一行是否是完整的句子或结构化内容 + if (last_line.endswith(('.', ':', '```', '!', '?')) or + last_line.startswith(('##', '-', '*', '`')) or + len(last_line) < 10): # 很短的行可能是列表项 + score += 0.2 + elif len(last_line) > 50 and not last_line.endswith(('.', ':', '```', '!', '?')): + # 长行但没有适当结尾,可能被截断 + score += 0.05 + factors += 1 + + # 4. 代码实现计划完整性 (权重: 0.3) + implementation_keywords = [ + "file structure", "architecture", "implementation", + "requirements", "dependencies", "setup", "main", + "class", "function", "method", "algorithm" + ] + impl_count = sum(1 for keyword in implementation_keywords if keyword.lower() in text.lower()) + if impl_count >= 8: + score += 0.3 + elif impl_count >= 4: + score += 0.15 + factors += 1 + + return min(score, 1.0) # 确保不超过1.0 + + +def _adjust_params_for_retry(params: RequestParams, retry_count: int) -> RequestParams: + """ + 动态调整请求参数以提高成功率 + + 基于重试次数智能调整参数: + - 增加token限制 + - 调整temperature + - 优化其他参数 + """ + # 基础token增量:每次重试增加更多tokens + token_increment = 4096 * (retry_count + 1) + new_max_tokens = min(params.max_tokens + token_increment, 32768) # 不超过32K的合理限制 + + # 随着重试次数增加,降低temperature以获得更一致的输出 + new_temperature = max(params.temperature - (retry_count * 0.1), 0.1) + + print(f"🔧 Adjusting parameters for retry {retry_count + 1}:") + print(f" Token limit: {params.max_tokens} → {new_max_tokens}") + print(f" Temperature: {params.temperature} → {new_temperature}") + + return RequestParams( + max_tokens=new_max_tokens, + temperature=new_temperature, + ) + + def get_default_search_server(config_path: str = "mcp_agent.config.yaml"): """ Get the default search server from configuration. @@ -382,10 +477,22 @@ async def run_code_analyzer( llm_factory=get_preferred_llm_class(), ) - # Set appropriate token output limit for Claude models (max 8192) + # Advanced token management system with dynamic scaling + # 检查是否使用分段模式以动态调整token限制 + if use_segmentation: + # 分段模式:可以使用更高的token限制,因为输入已经被优化 + max_tokens_limit = 16384 # 使用更高限制,因为分段减少了输入复杂性 + temperature = 0.2 # 稍微降低temperature以提高一致性 + print("🧠 Using SEGMENTED mode: Higher token limit (16384) with optimized inputs") + else: + # 传统模式:使用保守的token限制并启用增量生成 + max_tokens_limit = 12288 # 中等限制,为聚合输出留出空间 + temperature = 0.3 + print("🧠 Using TRADITIONAL mode: Moderate token limit (12288)") + enhanced_params = RequestParams( - max_tokens=8192, # Adjusted to Claude 3.5 Sonnet's actual limit - temperature=0.3, + max_tokens=max_tokens_limit, + temperature=temperature, ) # Concise message for multi-agent paper analysis and code planning @@ -399,10 +506,38 @@ async def run_code_analyzer( The goal is to create a reproduction plan detailed enough for independent implementation.""" - result = await code_aggregator_agent.generate_str( - message=message, request_params=enhanced_params - ) - print(f"Code analysis result: {result}") + # 智能输出完整性检查和重试机制 + max_retries = 3 + retry_count = 0 + + while retry_count < max_retries: + try: + print(f"🚀 Attempting code analysis (attempt {retry_count + 1}/{max_retries})") + result = await code_aggregator_agent.generate_str( + message=message, request_params=enhanced_params + ) + + # 检查输出完整性的高级指标 + completeness_score = _assess_output_completeness(result) + print(f"📊 Output completeness score: {completeness_score:.2f}/1.0") + + if completeness_score >= 0.8: # 输出被认为是完整的 + print(f"✅ Code analysis completed successfully (length: {len(result)} chars)") + return result + else: + print(f"⚠️ Output appears truncated (score: {completeness_score:.2f}), retrying with enhanced parameters...") + # 动态调整参数进行重试 + enhanced_params = _adjust_params_for_retry(enhanced_params, retry_count) + retry_count += 1 + + except Exception as e: + print(f"❌ Error in code analysis attempt {retry_count + 1}: {e}") + retry_count += 1 + if retry_count >= max_retries: + raise + + # 如果所有重试都失败,返回最后一次的结果 + print(f"⚠️ Returning potentially incomplete result after {max_retries} attempts") return result From fea837312dfa95ae8240a9c2845dc58f4d2691cb Mon Sep 17 00:00:00 2001 From: Zongwei9888 Date: Wed, 24 Sep 2025 17:43:15 +0800 Subject: [PATCH 03/25] improve the code planning quality --- cli/cli_app.py | 1 - cli/cli_interface.py | 19 +++-- workflows/agent_orchestration_engine.py | 106 +++++++++++++++--------- 3 files changed, 82 insertions(+), 44 deletions(-) diff --git a/cli/cli_app.py b/cli/cli_app.py index 3aab095f..0b0627fa 100644 --- a/cli/cli_app.py +++ b/cli/cli_app.py @@ -48,7 +48,6 @@ async def cleanup_mcp_app(self): """清理MCP应用 - 使用工作流适配器""" await self.workflow_adapter.cleanup_mcp_app() - async def process_input(self, input_source: str, input_type: str): """处理输入源(URL或文件)- 使用升级版智能体编排引擎""" try: diff --git a/cli/cli_interface.py b/cli/cli_interface.py index e53773a5..3bf6304a 100644 --- a/cli/cli_interface.py +++ b/cli/cli_interface.py @@ -40,10 +40,10 @@ def __init__(self): self.is_running = True self.processing_history = [] self.enable_indexing = True # Default configuration - + # Load segmentation config from the same source as UI self._load_segmentation_config() - + # Initialize tkinter availability self._init_tkinter() @@ -51,6 +51,7 @@ def _load_segmentation_config(self): """Load segmentation configuration from mcp_agent.config.yaml""" try: from utils.llm_utils import get_document_segmentation_config + seg_config = get_document_segmentation_config() self.segmentation_enabled = seg_config.get("enabled", True) self.segmentation_threshold = seg_config.get("size_threshold_chars", 50000) @@ -64,7 +65,7 @@ def _save_segmentation_config(self): """Save segmentation configuration to mcp_agent.config.yaml""" import yaml import os - + # Get the project root directory (where mcp_agent.config.yaml is located) current_file = os.path.abspath(__file__) cli_dir = os.path.dirname(current_file) # cli directory @@ -81,16 +82,22 @@ def _save_segmentation_config(self): config["document_segmentation"] = {} config["document_segmentation"]["enabled"] = self.segmentation_enabled - config["document_segmentation"]["size_threshold_chars"] = self.segmentation_threshold + config["document_segmentation"]["size_threshold_chars"] = ( + self.segmentation_threshold + ) # Write updated config with open(config_path, "w", encoding="utf-8") as f: yaml.dump(config, f, default_flow_style=False, allow_unicode=True) - print(f"{Colors.OKGREEN}✅ Document segmentation configuration updated{Colors.ENDC}") + print( + f"{Colors.OKGREEN}✅ Document segmentation configuration updated{Colors.ENDC}" + ) except Exception as e: - print(f"{Colors.WARNING}⚠️ Failed to update segmentation config: {str(e)}{Colors.ENDC}") + print( + f"{Colors.WARNING}⚠️ Failed to update segmentation config: {str(e)}{Colors.ENDC}" + ) def _init_tkinter(self): """Initialize tkinter availability check""" diff --git a/workflows/agent_orchestration_engine.py b/workflows/agent_orchestration_engine.py index b766b641..f225a8d8 100644 --- a/workflows/agent_orchestration_engine.py +++ b/workflows/agent_orchestration_engine.py @@ -65,76 +65,98 @@ def _assess_output_completeness(text: str) -> float: """ 智能评估输出完整性的高级算法 - + 使用多种启发式方法来检测输出是否被截断: 1. 结构化标记完整性检查 - 2. 句子完整性分析 + 2. 句子完整性分析 3. 代码块完整性验证 4. 预期内容元素检查 - + Returns: float: 完整性分数 (0.0-1.0),越高表示越完整 """ if not text or len(text.strip()) < 100: return 0.0 - + score = 0.0 factors = 0 - + # 1. 基本长度检查 (权重: 0.2) if len(text) > 5000: # 期望的最小输出长度 score += 0.2 elif len(text) > 2000: score += 0.1 factors += 1 - + # 2. 结构完整性检查 (权重: 0.3) structure_indicators = [ - "## 1.", "## 2.", "## 3.", # 章节标题 - "```", "file_structure", "implementation", - "algorithm", "method", "function" + "## 1.", + "## 2.", + "## 3.", # 章节标题 + "```", + "file_structure", + "implementation", + "algorithm", + "method", + "function", ] - structure_count = sum(1 for indicator in structure_indicators if indicator.lower() in text.lower()) + structure_count = sum( + 1 for indicator in structure_indicators if indicator.lower() in text.lower() + ) if structure_count >= 6: score += 0.3 elif structure_count >= 3: score += 0.15 factors += 1 - + # 3. 句子完整性检查 (权重: 0.2) - lines = text.strip().split('\n') + lines = text.strip().split("\n") if lines: last_line = lines[-1].strip() # 检查最后一行是否是完整的句子或结构化内容 - if (last_line.endswith(('.', ':', '```', '!', '?')) or - last_line.startswith(('##', '-', '*', '`')) or - len(last_line) < 10): # 很短的行可能是列表项 + if ( + last_line.endswith((".", ":", "```", "!", "?")) + or last_line.startswith(("##", "-", "*", "`")) + or len(last_line) < 10 + ): # 很短的行可能是列表项 score += 0.2 - elif len(last_line) > 50 and not last_line.endswith(('.', ':', '```', '!', '?')): + elif len(last_line) > 50 and not last_line.endswith( + (".", ":", "```", "!", "?") + ): # 长行但没有适当结尾,可能被截断 score += 0.05 factors += 1 - + # 4. 代码实现计划完整性 (权重: 0.3) implementation_keywords = [ - "file structure", "architecture", "implementation", - "requirements", "dependencies", "setup", "main", - "class", "function", "method", "algorithm" + "file structure", + "architecture", + "implementation", + "requirements", + "dependencies", + "setup", + "main", + "class", + "function", + "method", + "algorithm", ] - impl_count = sum(1 for keyword in implementation_keywords if keyword.lower() in text.lower()) + impl_count = sum( + 1 for keyword in implementation_keywords if keyword.lower() in text.lower() + ) if impl_count >= 8: score += 0.3 elif impl_count >= 4: score += 0.15 factors += 1 - + return min(score, 1.0) # 确保不超过1.0 def _adjust_params_for_retry(params: RequestParams, retry_count: int) -> RequestParams: """ 动态调整请求参数以提高成功率 - + 基于重试次数智能调整参数: - 增加token限制 - 调整temperature @@ -142,15 +164,17 @@ def _adjust_params_for_retry(params: RequestParams, retry_count: int) -> Request """ # 基础token增量:每次重试增加更多tokens token_increment = 4096 * (retry_count + 1) - new_max_tokens = min(params.max_tokens + token_increment, 32768) # 不超过32K的合理限制 - + new_max_tokens = min( + params.max_tokens + token_increment, 32768 + ) # 不超过32K的合理限制 + # 随着重试次数增加,降低temperature以获得更一致的输出 new_temperature = max(params.temperature - (retry_count * 0.1), 0.1) - + print(f"🔧 Adjusting parameters for retry {retry_count + 1}:") print(f" Token limit: {params.max_tokens} → {new_max_tokens}") print(f" Temperature: {params.temperature} → {new_temperature}") - + return RequestParams( max_tokens=new_max_tokens, temperature=new_temperature, @@ -483,13 +507,15 @@ async def run_code_analyzer( # 分段模式:可以使用更高的token限制,因为输入已经被优化 max_tokens_limit = 16384 # 使用更高限制,因为分段减少了输入复杂性 temperature = 0.2 # 稍微降低temperature以提高一致性 - print("🧠 Using SEGMENTED mode: Higher token limit (16384) with optimized inputs") + print( + "🧠 Using SEGMENTED mode: Higher token limit (16384) with optimized inputs" + ) else: # 传统模式:使用保守的token限制并启用增量生成 max_tokens_limit = 12288 # 中等限制,为聚合输出留出空间 temperature = 0.3 print("🧠 Using TRADITIONAL mode: Moderate token limit (12288)") - + enhanced_params = RequestParams( max_tokens=max_tokens_limit, temperature=temperature, @@ -509,33 +535,39 @@ async def run_code_analyzer( # 智能输出完整性检查和重试机制 max_retries = 3 retry_count = 0 - + while retry_count < max_retries: try: - print(f"🚀 Attempting code analysis (attempt {retry_count + 1}/{max_retries})") + print( + f"🚀 Attempting code analysis (attempt {retry_count + 1}/{max_retries})" + ) result = await code_aggregator_agent.generate_str( message=message, request_params=enhanced_params ) - + # 检查输出完整性的高级指标 completeness_score = _assess_output_completeness(result) print(f"📊 Output completeness score: {completeness_score:.2f}/1.0") - + if completeness_score >= 0.8: # 输出被认为是完整的 - print(f"✅ Code analysis completed successfully (length: {len(result)} chars)") + print( + f"✅ Code analysis completed successfully (length: {len(result)} chars)" + ) return result else: - print(f"⚠️ Output appears truncated (score: {completeness_score:.2f}), retrying with enhanced parameters...") + print( + f"⚠️ Output appears truncated (score: {completeness_score:.2f}), retrying with enhanced parameters..." + ) # 动态调整参数进行重试 enhanced_params = _adjust_params_for_retry(enhanced_params, retry_count) retry_count += 1 - + except Exception as e: print(f"❌ Error in code analysis attempt {retry_count + 1}: {e}") retry_count += 1 if retry_count >= max_retries: raise - + # 如果所有重试都失败,返回最后一次的结果 print(f"⚠️ Returning potentially incomplete result after {max_retries} attempts") return result From 55ae2e23d7d04c9e991588b44f7ae3dc70bee6bb Mon Sep 17 00:00:00 2001 From: Zongwei9888 Date: Thu, 25 Sep 2025 16:19:04 +0800 Subject: [PATCH 04/25] update README_ZH --- README_ZH.md | 793 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 793 insertions(+) create mode 100644 README_ZH.md diff --git a/README_ZH.md b/README_ZH.md new file mode 100644 index 00000000..298f2357 --- /dev/null +++ b/README_ZH.md @@ -0,0 +1,793 @@ +
+ + + + + + +
+ DeepCode Logo + +
    ██████╗ ███████╗███████╗██████╗  ██████╗ ██████╗ ██████╗ ███████╗
+    ██╔══██╗██╔════╝██╔════╝██╔══██╗██╔════╝██╔═══██╗██╔══██╗██╔════╝
+    ██║  ██║█████╗  █████╗  ██████╔╝██║     ██║   ██║██║  ██║█████╗
+    ██║  ██║██╔══╝  ██╔══╝  ██╔═══╝ ██║     ██║   ██║██║  ██║██╔══╝
+    ██████╔╝███████╗███████╗██║     ╚██████╗╚██████╔╝██████╔╝███████╗
+    ╚═════╝ ╚══════╝╚══════╝╚═╝      ╚═════╝ ╚═════╝ ╚═════╝ ╚══════╝
+
+ +
+HKUDS%2FDeepCode | Trendshift +
+ + + +# DeepCode Logo DeepCode: 开源智能体编程 + +### *基于多智能体系统推进代码生成技术* + + +

+ + + +

+

+ + +

+
+
+
+ + + +### 🖥️ **界面展示** + + + + + + +
+ +#### 🖥️ **命令行界面** +**基于终端的开发环境** + +
+ + CLI Interface Demo + +
+ 🚀 高级终端体验
+ ⚡ 快速命令行工作流
🔧 开发者友好界面
📊 实时进度跟踪
+
+ + *专业终端界面,适合高级用户和CI/CD集成* +
+ +
+ +#### 🌐 **Web界面** +**可视化交互体验** + +
+ + Web Interface Demo + +
+ 🎨 现代化Web仪表板
+ 🖱️ 直观的拖拽操作
📱 响应式设计
🎯 可视化进度跟踪
+
+ + *美观的Web界面,为所有技能水平用户提供流畅的工作流程* +
+ +
+ +--- + +
+ +### 🎬 **介绍视频** + + + +*🎯 **观看我们的完整介绍** - 了解DeepCode如何将研究论文和自然语言转换为生产就绪的代码* + +

+ + Watch Video + +

+ +
+ +--- + + + + +> *"AI智能体将创意转化为生产就绪代码的地方"* + +
+ +--- + +## 📑 目录 + +- [🚀 核心特性](#-核心特性) +- [🏗️ 架构](#️-架构) +- [🚀 快速开始](#-快速开始) +- [💡 示例](#-示例) + - [🎬 实时演示](#-实时演示) +- [⭐ 星标历史](#-星标历史) +- [📄 许可证](#-许可证) + +--- + +## 🚀 核心特性 + +
+ + + + + + + +
+ +
+

🚀 论文转代码

+
+ +
+ Algorithm Badge +
+ +
+

复杂算法的自动化实现

+
+ +
+

轻松将研究论文中的复杂算法转换为高质量生产就绪的代码,加速算法复现。

+
+ + + +
+ +
+

🎨 文本转Web

+
+ +
+ Frontend Badge +
+ +
+

自动化前端Web开发

+
+ +
+

将纯文本描述转换为功能完整视觉美观的前端Web代码,快速创建界面。

+
+ + + +
+ +
+

⚙️ 文本转后端

+
+ +
+ Backend Badge +
+ +
+

自动化后端开发

+
+ +
+

从简单的文本输入生成高效可扩展功能丰富的后端代码,简化服务器端开发。

+
+ + + +
+ +
+ +### 🎯 **自主多智能体工作流** + +**面临的挑战**: + +- 📄 **实现复杂性**: 将学术论文和复杂算法转换为可运行代码需要大量技术投入和领域专业知识 + +- 🔬 **研究瓶颈**: 研究人员将宝贵时间花在算法实现上,而不是专注于核心研究和发现工作 + +- ⏱️ **开发延迟**: 产品团队在概念和可测试原型之间经历长时间等待,减慢创新周期 + +- 🔄 **重复编码**: 开发者重复实现相似的模式和功能,而不是基于现有解决方案构建 + +**DeepCode** 通过为常见开发任务提供可靠的自动化来解决这些工作流程低效问题,简化从概念到代码的开发工作流程。 + +
+ +```mermaid +flowchart LR + A["📄 研究论文
💬 文本提示
🌐 URL和文档
📎 文件: PDF, DOC, PPTX, TXT, HTML"] --> B["🧠 DeepCode
多智能体引擎"] + B --> C["🚀 算法实现
🎨 前端开发
⚙️ 后端开发"] + + style A fill:#ff6b6b,stroke:#c0392b,stroke-width:2px,color:#000 + style B fill:#00d4ff,stroke:#0984e3,stroke-width:3px,color:#000 + style C fill:#00b894,stroke:#00a085,stroke-width:2px,color:#000 +``` + +
+ +--- + +## 🏗️ 架构 + +### 📊 **系统概述** + +**DeepCode** 是一个AI驱动的开发平台,自动化代码生成和实现任务。我们的多智能体系统处理将需求转换为功能性、结构良好代码的复杂性,让您专注于创新而非实现细节。 + +🎯 **技术能力**: + +🧬 **研究到生产流水线**
+多模态文档分析引擎,从学术论文中提取算法逻辑和数学模型。生成优化的实现,使用适当的数据结构,同时保持计算复杂度特征。 + +🪄 **自然语言代码合成**
+使用在精选代码库上训练的微调语言模型进行上下文感知代码生成。在支持多种编程语言和框架的同时保持模块间架构一致性。 + +⚡ **自动化原型引擎**
+智能脚手架系统,生成包括数据库模式、API端点和前端组件的完整应用程序结构。使用依赖分析确保从初始生成开始的可扩展架构。 + +💎 **质量保证自动化**
+集成静态分析与自动化单元测试生成和文档合成。采用AST分析进行代码正确性检查和基于属性的测试进行全面覆盖。 + +🔮 **CodeRAG集成系统**
+高级检索增强生成,结合语义向量嵌入和基于图的依赖分析。从大规模代码语料库中自动发现最优库和实现模式。 + +--- + +### 🔧 **核心技术** + +- 🧠 **智能编排智能体**: 协调工作流阶段和分析需求的中央决策系统。采用动态规划算法,根据不断发展的项目复杂性实时调整执行策略。为每个实现步骤动态选择最优处理策略。
+ +- 💾 **高效内存机制**: 高效管理大规模代码上下文的高级上下文工程系统。实现分层内存结构,具有智能压缩功能,用于处理复杂代码库。该组件实现实现模式的即时检索,并在扩展开发会话中保持语义一致性。
+ +- 🔍 **高级CodeRAG系统**: 分析跨存储库复杂相互依赖关系的全局代码理解引擎。执行跨代码库关系映射,从整体角度理解架构模式。该模块利用依赖图和语义分析在实现过程中提供全局感知的代码建议。 + +--- + +### 🤖 **DeepCode的多智能体架构**: + +- **🎯 中央编排智能体**: 编排整个工作流程执行并做出战略决策。基于输入复杂性分析协调专门智能体。实现动态任务规划和资源分配算法。
+ +- **📝 意图理解智能体**: 对用户需求进行深度语义分析以解码复杂意图。通过高级NLP处理提取功能规范和技术约束。通过结构化任务分解将模糊的人类描述转换为精确、可操作的开发规范。
+ +- **📄 文档解析智能体**: 使用高级解析能力处理复杂的技术文档和研究论文。使用文档理解模型提取算法和方法。通过智能内容分析将学术概念转换为实用的实现规范。
+ +- **🏗️ 代码规划智能体**: 执行架构设计和技术栈优化。动态规划适应性开发路线图。通过自动化设计模式选择执行编码标准并生成模块化结构。
+ +- **🔍 代码参考挖掘智能体**: 通过智能搜索算法发现相关存储库和框架。分析代码库的兼容性和集成潜力。基于相似性度量和自动化依赖分析提供建议。
+ +- **📚 代码索引智能体**: 构建发现代码库的综合知识图谱。维护代码组件之间的语义关系。实现智能检索和交叉引用能力。
+ +- **🧬 代码生成智能体**: 将收集的信息合成为可执行的代码实现。创建功能接口并集成发现的组件。生成全面的测试套件和文档以确保可重现性。 + +--- + +#### 🛠️ **实现工具矩阵** + +**🔧 基于MCP (模型上下文协议) 驱动** + +DeepCode利用**模型上下文协议 (MCP)** 标准与各种工具和服务无缝集成。这种标准化方法确保AI智能体和外部系统之间的可靠通信,实现强大的自动化能力。 + +##### 📡 **MCP服务器和工具** + +| 🛠️ **MCP服务器** | 🔧 **主要功能** | 💡 **目的和能力** | +|-------------------|-------------------------|-------------------------------| +| **🔍 brave** | Web搜索引擎 | 通过Brave搜索API进行实时信息检索 | +| **🌐 bocha-mcp** | 替代搜索 | 具有独立API访问的辅助搜索选项 | +| **📂 filesystem** | 文件系统操作 | 本地文件和目录管理,读/写操作 | +| **🌐 fetch** | Web内容检索 | 从URL和Web资源获取和提取内容 | +| **📥 github-downloader** | 存储库管理 | 克隆和下载GitHub存储库进行分析 | +| **📋 file-downloader** | 文档处理 | 下载文件(PDF、DOCX等)并转换为Markdown | +| **⚡ command-executor** | 系统命令 | 执行bash/shell命令进行环境管理 | +| **🧬 code-implementation** | 代码生成中心 | 具有执行和测试的综合代码复现 | +| **📚 code-reference-indexer** | 智能代码搜索 | 代码存储库的智能索引和搜索 | +| **📄 document-segmentation** | 智能文档分析 | 大型论文和技术文档的智能文档分割 | + +##### 🔧 **传统工具功能** *(供参考)* + +| 🛠️ **功能** | 🎯 **使用上下文** | +|-----------------|---------------------| +| **📄 read_code_mem** | 从内存高效检索代码上下文 | +| **✍️ write_file** | 直接文件内容生成和修改 | +| **🐍 execute_python** | Python代码测试和验证 | +| **📁 get_file_structure** | 项目结构分析和组织 | +| **⚙️ set_workspace** | 动态工作空间和环境配置 | +| **📊 get_operation_history** | 过程监控和操作跟踪 | + + +--- + +🎛️ **多界面框架**
+具有CLI和Web前端的RESTful API,具有实时代码流、交互式调试和可扩展插件架构,用于CI/CD集成。 + +**🚀 多智能体智能流水线:** + +
+ +### 🌟 **智能处理流程** + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+💡 输入层
+📄 研究论文 • 💬 自然语言 • 🌐 URL • 📋 需求 +
+🎯 中央编排
+战略决策制定 • 工作流程协调 • 智能体管理 +
+📝 文本分析
+需求处理 +
+📄 文档分析
+论文和规范处理 +
+📋 复现规划
+深度论文分析 • 代码需求解析 • 复现策略开发 +
+🔍 参考分析
+存储库发现 +
+📚 代码索引
+知识图谱构建 +
+🧬 代码实现
+实现生成 • 测试 • 文档 +
+⚡ 输出交付
+📦 完整代码库 • 🧪 测试套件 • 📚 文档 • 🚀 部署就绪 +
+ +
+ +
+
+ +### 🔄 **流程智能特性** + + + + + + + + +
+
+

🎯 自适应流程

+

基于输入复杂性的动态智能体选择

+
+
+
+

🧠 智能协调

+

智能任务分配和并行处理

+
+
+
+

🔍 上下文感知

+

通过CodeRAG集成的深度理解

+
+
+
+

⚡ 质量保证

+

全程自动化测试和验证

+
+
+ +
+ +--- + +## 🚀 快速开始 + + + +### 📦 **步骤1: 安装** + +#### ⚡ **直接安装 (推荐)** + +```bash +# 🚀 直接安装DeepCode包 +pip install deepcode-hku + +# 🔑 下载配置文件 +curl -O https://raw.githubusercontent.com/HKUDS/DeepCode/main/mcp_agent.config.yaml +curl -O https://raw.githubusercontent.com/HKUDS/DeepCode/main/mcp_agent.secrets.yaml + +# 🔑 配置API密钥 (必需) +# 使用您的API密钥和base_url编辑mcp_agent.secrets.yaml: +# - openai: api_key, base_url (用于OpenAI/自定义端点) +# - anthropic: api_key (用于Claude模型) + +# 🔑 配置搜索API密钥用于Web搜索 (可选) +# 编辑mcp_agent.config.yaml设置您的API密钥: +# - 对于Brave搜索: 在brave.env部分设置BRAVE_API_KEY: "your_key_here" (第~28行) +# - 对于Bocha-MCP: 在bocha-mcp.env部分设置BOCHA_API_KEY: "your_key_here" (第~74行) + +# 📄 配置文档分割 (可选) +# 编辑mcp_agent.config.yaml控制文档处理: +# - enabled: true/false (是否使用智能文档分割) +# - size_threshold_chars: 50000 (触发分割的文档大小阈值) +``` + +#### 🔧 **开发安装 (从源码)** + +
+📂 点击展开开发安装选项 + +##### 🔥 **使用UV (开发推荐)** + +```bash +# 🔽 克隆存储库 +git clone https://github.com/HKUDS/DeepCode.git +cd DeepCode/ + +# 📦 安装UV包管理器 +curl -LsSf https://astral.sh/uv/install.sh | sh + +# 🔧 使用UV安装依赖 +uv venv --python=3.13 +source .venv/bin/activate # Windows下: .venv\Scripts\activate +uv pip install -r requirements.txt + +# 🔑 配置API密钥 (必需) +# 使用您的API密钥和base_url编辑mcp_agent.secrets.yaml: +# - openai: api_key, base_url (用于OpenAI/自定义端点) +# - anthropic: api_key (用于Claude模型) + +# 🔑 配置搜索API密钥用于Web搜索 (可选) +# 编辑mcp_agent.config.yaml设置您的API密钥: +# - 对于Brave搜索: 在brave.env部分设置BRAVE_API_KEY: "your_key_here" (第~28行) +# - 对于Bocha-MCP: 在bocha-mcp.env部分设置BOCHA_API_KEY: "your_key_here" (第~74行) + +# 📄 配置文档分割 (可选) +# 编辑mcp_agent.config.yaml控制文档处理: +# - enabled: true/false (是否使用智能文档分割) +# - size_threshold_chars: 50000 (触发分割的文档大小阈值) +``` + +##### 🐍 **使用传统pip** + +```bash +# 🔽 克隆存储库 +git clone https://github.com/HKUDS/DeepCode.git +cd DeepCode/ + +# 📦 安装依赖 +pip install -r requirements.txt + +# 🔑 配置API密钥 (必需) +# 使用您的API密钥和base_url编辑mcp_agent.secrets.yaml: +# - openai: api_key, base_url (用于OpenAI/自定义端点) +# - anthropic: api_key (用于Claude模型) + +# 🔑 配置搜索API密钥用于Web搜索 (可选) +# 编辑mcp_agent.config.yaml设置您的API密钥: +# - 对于Brave搜索: 在brave.env部分设置BRAVE_API_KEY: "your_key_here" (第~28行) +# - 对于Bocha-MCP: 在bocha-mcp.env部分设置BOCHA_API_KEY: "your_key_here" (第~74行) + +# 📄 配置文档分割 (可选) +# 编辑mcp_agent.config.yaml控制文档处理: +# - enabled: true/false (是否使用智能文档分割) +# - size_threshold_chars: 50000 (触发分割的文档大小阈值) +``` + +
+ +#### 🪟 **Windows用户: 额外的MCP服务器配置** + +如果您使用Windows,可能需要在`mcp_agent.config.yaml`中手动配置MCP服务器: + +```bash +# 1. 全局安装MCP服务器 +npm i -g @modelcontextprotocol/server-brave-search +npm i -g @modelcontextprotocol/server-filesystem + +# 2. 找到您的全局node_modules路径 +npm -g root +``` + +然后更新您的`mcp_agent.config.yaml`使用绝对路径: + +```yaml +mcp: + servers: + brave: + command: "node" + args: ["C:/Program Files/nodejs/node_modules/@modelcontextprotocol/server-brave-search/dist/index.js"] + filesystem: + command: "node" + args: ["C:/Program Files/nodejs/node_modules/@modelcontextprotocol/server-filesystem/dist/index.js", "."] +``` + +> **注意**: 将路径替换为步骤2中您实际的全局node_modules路径。 + +#### 🔍 **搜索服务器配置 (可选)** + +DeepCode支持多个搜索服务器进行Web搜索功能。您可以在`mcp_agent.config.yaml`中配置您的首选选项: + +```yaml +# 默认搜索服务器配置 +# 选项: "brave" 或 "bocha-mcp" +default_search_server: "brave" +``` + +**可用选项:** +- **🔍 Brave搜索** (`"brave"`): + - 具有高质量搜索结果的默认选项 + - 需要BRAVE_API_KEY配置 + - 推荐给大多数用户 + +- **🌐 Bocha-MCP** (`"bocha-mcp"`): + - 替代搜索服务器选项 + - 需要BOCHA_API_KEY配置 + - 使用本地Python服务器实现 + +**在mcp_agent.config.yaml中的API密钥配置:** +```yaml +# 对于Brave搜索 (默认) - 第28行左右 +brave: + command: "npx" + args: ["-y", "@modelcontextprotocol/server-brave-search"] + env: + BRAVE_API_KEY: "your_brave_api_key_here" + +# 对于Bocha-MCP (替代) - 第74行左右 +bocha-mcp: + command: "python" + args: ["tools/bocha_search_server.py"] + env: + PYTHONPATH: "." + BOCHA_API_KEY: "your_bocha_api_key_here" +``` + +> **💡 提示**: 两个搜索服务器都需要API密钥配置。选择最适合您的API访问和需求的选项。 + +### ⚡ **步骤2: 启动应用程序** + +#### 🚀 **使用已安装的包 (推荐)** + +```bash +# 🌐 直接启动Web界面 +deepcode + +# 应用程序将自动在 http://localhost:8501 启动 +``` + +#### 🛠️ **使用源码** + +选择您首选的界面: + +##### 🌐 **Web界面** (推荐) +```bash +# 使用UV +uv run streamlit run ui/streamlit_app.py +# 或使用传统Python +streamlit run ui/streamlit_app.py +``` +
+ Web Access +
+ +##### 🖥️ **CLI界面** (高级用户) +```bash +# 使用UV +uv run python cli/main_cli.py +# 或使用传统Python +python cli/main_cli.py +``` +
+ CLI Mode +
+ +### 🎯 **步骤3: 生成代码** + +1. **📄 输入**: 上传您的研究论文,提供需求,或粘贴URL +2. **🤖 处理**: 观看多智能体系统分析和规划 +3. **⚡ 输出**: 接收带有测试和文档的生产就绪代码 + + + --- + +## 💡 示例 + + + +### 🎬 **实时演示** + + + + + + + + + +
+ +#### 📄 **论文转代码演示** +**研究到实现** + +
+ + Paper2Code Demo + + + **[▶️ 观看演示](https://www.youtube.com/watch?v=MQZYpLkzsbw)** + + *自动将学术论文转换为生产就绪代码* +
+ +
+ +#### 🖼️ **图像处理演示** +**AI驱动的图像工具** + +
+ + Image Processing Demo + + + **[▶️ 观看演示](https://www.youtube.com/watch?v=nFt5mLaMEac)** + + *智能图像处理,具有背景移除和增强功能* +
+ +
+ +#### 🌐 **前端实现** +**完整Web应用程序** + +
+ + Frontend Demo + + + **[▶️ 观看演示](https://www.youtube.com/watch?v=78wx3dkTaAU)** + + *从概念到部署的全栈Web开发* +
+ +
+ + + +### 🆕 **最新更新** + +#### 📄 **智能文档分割 (v1.2.0)** +- **智能处理**: 自动处理超出LLM令牌限制的大型研究论文和技术文档 +- **可配置控制**: 通过配置切换分割功能,具有基于大小的阈值 +- **语义分析**: 高级内容理解,保留算法、概念和公式 +- **向后兼容**: 对较小文档无缝回退到传统处理 + +### 🚀 **即将推出** + +我们正在不断增强DeepCode的令人兴奋的新功能: + +#### 🔧 **增强的代码可靠性和验证** +- **自动化测试**: 具有执行验证和错误检测的全面功能测试。 +- **代码质量保证**: 通过静态分析、动态测试和性能基准测试进行多级验证。 +- **智能调试**: AI驱动的错误检测,具有自动纠正建议 + +#### 📊 **PaperBench性能展示** +- **基准仪表板**: PaperBench评估套件的综合性能指标。 +- **准确性指标**: 与最先进的论文复现系统的详细比较。 +- **成功分析**: 跨论文类别和复杂度水平的统计分析。 + +#### ⚡ **系统级优化** +- **性能提升**: 多线程处理和优化智能体协调,实现更快的生成。 +- **增强推理**: 具有改进上下文理解的高级推理能力。 +- **扩展支持**: 扩展与其他编程语言和框架的兼容性。 + +--- + +## ⭐ 星标历史 + +
+ +*社区增长轨迹* + + + + + + Star History Chart + + + +
+ +--- + +### 🚀 **准备好变革开发方式了吗?** + +
+ +

+ Get Started + View on GitHub + Star Project +

+ +--- + +### 📄 **许可证** + +MIT License + +**MIT许可证** - 版权所有 (c) 2025 香港大学数据智能实验室 + +--- + + + +Visitors + +
From 420d07580e83885cdf784115131aea884e704a8f Mon Sep 17 00:00:00 2001 From: Zongwei9888 Date: Mon, 29 Sep 2025 15:27:17 +0800 Subject: [PATCH 05/25] Update user demand personalization customization features --- mcp_agent.secrets.yaml | 4 +- ui/components.py | 477 +++++++++++++++++- ui/handlers.py | 221 ++++++++ ui/layout.py | 49 +- workflows/agent_orchestration_engine.py | 127 +++++ .../agents/requirement_analysis_agent.py | 408 +++++++++++++++ 6 files changed, 1272 insertions(+), 14 deletions(-) create mode 100644 workflows/agents/requirement_analysis_agent.py diff --git a/mcp_agent.secrets.yaml b/mcp_agent.secrets.yaml index 6e670162..23c4e1fd 100644 --- a/mcp_agent.secrets.yaml +++ b/mcp_agent.secrets.yaml @@ -1,6 +1,6 @@ openai: - api_key: "" - base_url: "" + api_key: "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" + base_url: "https://openrouter.ai/api/v1" diff --git a/ui/components.py b/ui/components.py index 2fa57050..8427fec8 100644 --- a/ui/components.py +++ b/ui/components.py @@ -6,7 +6,7 @@ import streamlit as st import sys -from typing import Dict, Any, Optional +from typing import Dict, Any, Optional, List from datetime import datetime import json @@ -791,9 +791,283 @@ def url_input_component(task_counter: int) -> Optional[str]: return None +def requirement_analysis_mode_selector(task_counter: int) -> str: + """ + Requirement analysis mode selector + + Args: + task_counter: Task counter + + Returns: + Selected mode ("direct" or "guided") + """ + st.markdown( + """ +
+

+ 🎯 Choose Your Input Mode +

+

+ Select how you'd like to provide your requirements +

+
+ """, + unsafe_allow_html=True, + ) + + mode = st.radio( + "Input mode:", + ["🚀 Direct Input", "🧠 Guided Analysis"], + index=0 + if st.session_state.get("requirement_analysis_mode", "direct") == "direct" + else 1, + horizontal=True, + help="Direct: Enter requirements directly. Guided: AI asks questions to help you clarify needs.", + key=f"req_mode_{task_counter}", + ) + + return "direct" if mode.startswith("🚀") else "guided" + + +def requirement_questions_component( + questions: List[Dict], task_counter: int +) -> Dict[str, str]: + """ + Requirement questions display and answer collection component + + Args: + questions: Question list + task_counter: Task counter + + Returns: + User answer dictionary + """ + st.markdown( + """ +
+

+ 📝 Help Us Understand Your Needs Better +

+

+ Please answer the following questions to help us generate better code. You can skip any question. +

+
+ """, + unsafe_allow_html=True, + ) + + answers = {} + + for i, question in enumerate(questions): + with st.expander( + f"📋 {question.get('category', 'Question')} - {question.get('importance', 'Medium')} Priority", + expanded=i < 3, + ): + st.markdown(f"**{question['question']}**") + + if question.get("hint"): + st.info(f"💡 {question['hint']}") + + answer = st.text_area( + "Your answer:", + placeholder="Enter your answer here, or leave blank to skip...", + height=80, + key=f"answer_{i}_{task_counter}", + ) + + if answer and answer.strip(): + answers[str(i)] = answer.strip() + + st.markdown("---") + st.info(f"📊 You've answered {len(answers)} out of {len(questions)} questions.") + + return answers + + +def requirement_summary_component(summary: str, task_counter: int) -> bool: + """ + Requirement summary display and confirmation component + + Args: + summary: Requirement summary document + task_counter: Task counter + + Returns: + Whether user confirms requirements + """ + st.markdown( + """ +
+

+ 📋 Detailed Requirements Summary +

+

+ Based on your input, here's the detailed requirements document we've generated. +

+
+ """, + unsafe_allow_html=True, + ) + + # Display requirement summary + with st.expander("📖 View Detailed Requirements", expanded=True): + st.markdown(summary) + + # Confirmation options + st.markdown("### 🎯 Next Steps") + + col1, col2, col3 = st.columns(3) + + with col1: + if st.button( + "✅ Looks Good, Proceed", + type="primary", + use_container_width=True, + key=f"confirm_{task_counter}", + ): + # Mark requirements as confirmed, prepare to enter code generation + st.session_state.requirements_confirmed = True + return True + + with col2: + if st.button( + "✏️ Edit Requirements", + type="secondary", + use_container_width=True, + key=f"edit_{task_counter}", + ): + # Enter editing mode + st.session_state.requirement_analysis_step = "editing" + st.session_state.edit_feedback = "" + st.rerun() + + with col3: + if st.button( + "🔄 Start Over", use_container_width=True, key=f"restart_{task_counter}" + ): + # Complete reset + st.session_state.requirement_analysis_mode = "direct" + st.session_state.requirement_analysis_step = "input" + st.session_state.generated_questions = [] + st.session_state.user_answers = {} + st.session_state.detailed_requirements = "" + st.rerun() + + return False + + +def requirement_editing_component(current_requirements: str, task_counter: int) -> bool: + """ + Interactive requirement editing component + + Args: + current_requirements: Current requirement document content + task_counter: Task counter + + Returns: + Whether editing is completed + """ + st.markdown( + """ +
+

+ ✏️ Edit Requirements Document +

+

+ Review the current requirements and tell us how you'd like to modify them. +

+
+ """, + unsafe_allow_html=True, + ) + + # Display current requirements + st.markdown("### 📋 Current Requirements") + with st.expander("📖 View Current Requirements Document", expanded=True): + st.markdown(current_requirements) + + # Ask for modification feedback + st.markdown("### 💭 How would you like to modify the requirements?") + st.markdown("Please describe your changes, additions, or corrections:") + + edit_feedback = st.text_area( + "Your modification request:", + value=st.session_state.edit_feedback, + placeholder="For example:\n- Add user authentication feature\n- Change database from MySQL to PostgreSQL", + height=120, + key=f"edit_feedback_{task_counter}", + ) + + # Update session state + st.session_state.edit_feedback = edit_feedback + + # Action buttons + col1, col2, col3 = st.columns(3) + + with col1: + if st.button( + "🔄 Apply Changes", + type="primary", + use_container_width=True, + key=f"apply_edit_{task_counter}", + ): + if edit_feedback.strip(): + # Start requirement modification process + st.session_state.requirements_editing = True + st.info("🔄 Processing your modification request...") + return True + else: + st.warning("Please provide your modification request first.") + + with col2: + if st.button( + "↩️ Back to Summary", + type="secondary", + use_container_width=True, + key=f"back_summary_{task_counter}", + ): + # Go back to summary view + st.session_state.requirement_analysis_step = "summary" + st.session_state.edit_feedback = "" + st.rerun() + + with col3: + if st.button( + "🔄 Start Over", + use_container_width=True, + key=f"restart_edit_{task_counter}", + ): + # Complete reset + st.session_state.requirement_analysis_mode = "direct" + st.session_state.requirement_analysis_step = "input" + st.session_state.generated_questions = [] + st.session_state.user_answers = {} + st.session_state.detailed_requirements = "" + st.session_state.edit_feedback = "" + st.rerun() + + return False + + def chat_input_component(task_counter: int) -> Optional[str]: """ - Chat input component for coding requirements + Enhanced chat input component with requirement analysis support Args: task_counter: Task counter @@ -801,6 +1075,20 @@ def chat_input_component(task_counter: int) -> Optional[str]: Returns: User coding requirements or None """ + # Select input mode + selected_mode = requirement_analysis_mode_selector(task_counter) + + # Update requirement analysis mode + st.session_state.requirement_analysis_mode = selected_mode + + if selected_mode == "direct": + return _direct_input_component(task_counter) + else: + return _guided_analysis_component(task_counter) + + +def _direct_input_component(task_counter: int) -> Optional[str]: + """Direct input mode component""" st.markdown( """

- 💬 Describe Your Coding Requirements + 🚀 Direct Input Mode

- Tell us what you want to build. Our AI will analyze your requirements and generate a comprehensive implementation plan. + Describe your coding requirements directly. Our AI will analyze and generate a comprehensive implementation plan.

""", @@ -852,7 +1140,7 @@ def chat_input_component(task_counter: int) -> Optional[str]: The system should be scalable and production-ready, with proper error handling and documentation.""", height=200, help="Describe what you want to build, including functionality, technologies, and any specific requirements", - key=f"chat_input_{task_counter}", + key=f"direct_input_{task_counter}", ) if user_input and len(user_input.strip()) > 20: # Minimum length check @@ -871,7 +1159,7 @@ def chat_input_component(task_counter: int) -> Optional[str]: user_input, height=100, disabled=True, - key=f"preview_{task_counter}", + key=f"direct_preview_{task_counter}", ) return user_input.strip() @@ -885,6 +1173,183 @@ def chat_input_component(task_counter: int) -> Optional[str]: return None +def _guided_analysis_component(task_counter: int) -> Optional[str]: + """Guided analysis mode component""" + + # Check if requirements are confirmed, if confirmed return detailed requirements directly + if st.session_state.get("requirements_confirmed", False): + detailed_requirements = st.session_state.get("detailed_requirements", "") + if detailed_requirements: + # Show confirmation message and return requirements for processing + st.success("🎉 Requirement analysis completed! Starting code generation...") + st.info( + "🔄 Automatically proceeding to code generation based on your confirmed requirements." + ) + return detailed_requirements + + st.markdown( + """ +
+

+ 🧠 Guided Analysis Mode +

+

+ Let our AI guide you through a series of questions to better understand your requirements. +

+
+ """, + unsafe_allow_html=True, + ) + + # Check current step + current_step = st.session_state.get("requirement_analysis_step", "input") + + if current_step == "input": + return _guided_input_step(task_counter) + elif current_step == "questions": + return _guided_questions_step(task_counter) + elif current_step == "summary": + return _guided_summary_step(task_counter) + elif current_step == "editing": + return _guided_editing_step(task_counter) + else: + # Reset to initial state + st.session_state.requirement_analysis_step = "input" + st.rerun() + + +def _guided_input_step(task_counter: int) -> Optional[str]: + """Initial input step for guided mode""" + st.markdown("### 📝 Step 1: Tell us your basic idea") + + user_input = st.text_area( + "What would you like to build? (Brief description is fine)", + placeholder="Example: A web app for sentiment analysis of social media posts", + height=120, + help="Don't worry about details - we'll ask specific questions next!", + key=f"guided_input_{task_counter}", + ) + + if user_input and len(user_input.strip()) > 10: + col1, col2 = st.columns([3, 1]) + + with col1: + st.info(f"📝 Initial idea captured: {len(user_input.split())} words") + + with col2: + if st.button( + "🚀 Generate Questions", type="primary", use_container_width=True + ): + # Save initial input and enter question generation step + st.session_state.initial_requirement = user_input.strip() + st.session_state.requirement_analysis_step = "questions" + st.rerun() + + elif user_input and len(user_input.strip()) <= 10: + st.warning( + "⚠️ Please provide at least a brief description (more than 10 characters)" + ) + + return None + + +def _guided_questions_step(task_counter: int) -> Optional[str]: + """Question answering step for guided mode""" + st.markdown("### 🤔 Step 2: Answer questions to refine your requirements") + + # Display initial requirements + with st.expander("📋 Your Initial Idea", expanded=False): + st.write(st.session_state.get("initial_requirement", "")) + + # Check if questions have been generated + if not st.session_state.get("generated_questions"): + st.info("🔄 Generating personalized questions for your project...") + + # Async call needed here, but we show placeholder in UI first + if st.button("🎯 Generate Questions Now", type="primary"): + st.session_state.questions_generating = True + st.rerun() + return None + + # Display questions and collect answers + questions = st.session_state.generated_questions + answers = requirement_questions_component(questions, task_counter) + st.session_state.user_answers = answers + + # Continue button + col1, col2, col3 = st.columns([1, 2, 1]) + + with col2: + if st.button( + "📋 Generate Detailed Requirements", + type="primary", + use_container_width=True, + ): + st.session_state.requirement_analysis_step = "summary" + st.rerun() + + with col1: + if st.button("⬅️ Back", use_container_width=True): + st.session_state.requirement_analysis_step = "input" + st.rerun() + + return None + + +def _guided_summary_step(task_counter: int) -> Optional[str]: + """Requirement summary step for guided mode""" + st.markdown("### 📋 Step 3: Review and confirm your detailed requirements") + + # Check if detailed requirements have been generated + if not st.session_state.get("detailed_requirements"): + st.info("🔄 Generating detailed requirements based on your answers...") + + if st.button("📋 Generate Requirements Now", type="primary"): + st.session_state.requirements_generating = True + st.rerun() + return None + + # Display requirement summary and get confirmation + summary = st.session_state.detailed_requirements + confirmed = requirement_summary_component(summary, task_counter) + + if confirmed: + # Return detailed requirements as final input + return summary + + return None + + +def _guided_editing_step(task_counter: int) -> Optional[str]: + """Requirement editing step for guided mode""" + st.markdown("### ✏️ Step 4: Edit your requirements") + + # Get current requirements + current_requirements = st.session_state.get("detailed_requirements", "") + if not current_requirements: + st.error("No requirements found to edit. Please start over.") + st.session_state.requirement_analysis_step = "input" + st.rerun() + return None + + # Show editing component + editing_requested = requirement_editing_component( + current_requirements, task_counter + ) + + if editing_requested: + # User has provided editing feedback, trigger requirement modification + st.session_state.requirements_editing = True + st.rerun() + return None + + return None + + def input_method_selector(task_counter: int) -> tuple[Optional[str], Optional[str]]: """ Input method selector diff --git a/ui/handlers.py b/ui/handlers.py index f3a03bc3..b109003a 100644 --- a/ui/handlers.py +++ b/ui/handlers.py @@ -587,6 +587,203 @@ def cleanup_temp_file(input_source: str, input_type: str): pass +async def handle_requirement_analysis_workflow( + user_input: str, analysis_mode: str, user_answers: Dict[str, str] = None +) -> Dict[str, Any]: + """ + Handle requirement analysis workflow + + Args: + user_input: User initial requirements + analysis_mode: Analysis mode ("generate_questions" or "summarize_requirements") + user_answers: User answer dictionary + + Returns: + Processing result dictionary + """ + try: + # Import required modules + from workflows.agent_orchestration_engine import ( + execute_requirement_analysis_workflow, + ) + + # Create progress callback function + def update_progress(progress: int, message: str): + # Display progress in Streamlit + st.session_state.current_progress = progress + st.session_state.current_message = message + + # Execute requirement analysis workflow + result = await execute_requirement_analysis_workflow( + user_input=user_input, + analysis_mode=analysis_mode, + user_answers=user_answers, + logger=None, # Can pass in logger + progress_callback=update_progress, + ) + + return result + + except Exception as e: + return { + "status": "error", + "error": str(e), + "message": f"Requirement analysis workflow execution failed: {str(e)}", + } + + +async def handle_requirement_modification_workflow( + current_requirements: str, modification_feedback: str +) -> Dict[str, Any]: + """ + Handle requirement modification workflow + + Args: + current_requirements: Current requirement document content + modification_feedback: User's modification requests and feedback + + Returns: + Processing result dictionary + """ + try: + # Import required modules + from workflows.agents.requirement_analysis_agent import RequirementAnalysisAgent + + # Create progress callback function + def update_progress(progress: int, message: str): + # Display progress in Streamlit + st.session_state.current_progress = progress + st.session_state.current_message = message + + update_progress(10, "🔧 Initializing requirement modification agent...") + + # Initialize RequirementAnalysisAgent + agent = RequirementAnalysisAgent() + + # Initialize agent (LLM is initialized internally) + await agent.initialize() + + update_progress(50, "✏️ Modifying requirements based on your feedback...") + + # Modify requirements + result = await agent.modify_requirements( + current_requirements=current_requirements, + modification_feedback=modification_feedback, + ) + + # Cleanup + await agent.cleanup() + + update_progress(100, "✅ Requirements modification completed!") + + return { + "status": "success", + "result": result, + "message": "Requirements modification completed successfully", + } + + except Exception as e: + return { + "status": "error", + "error": str(e), + "message": f"Requirements modification workflow execution failed: {str(e)}", + } + + +def handle_guided_mode_processing(): + """Handle asynchronous processing for guided mode""" + # Check if questions need to be generated + if st.session_state.get("questions_generating", False): + st.session_state.questions_generating = False + + # Asynchronously generate questions + initial_req = st.session_state.get("initial_requirement", "") + if initial_req: + try: + # Use asynchronous processing to generate questions + result = run_async_task_simple( + handle_requirement_analysis_workflow( + user_input=initial_req, analysis_mode="generate_questions" + ) + ) + + if result["status"] == "success": + # Parse JSON result + import json + + questions = json.loads(result["result"]) + st.session_state.generated_questions = questions + else: + st.error( + f"Question generation failed: {result.get('error', 'Unknown error')}" + ) + + except Exception as e: + st.error(f"Question generation exception: {str(e)}") + + # Check if detailed requirements need to be generated + if st.session_state.get("requirements_generating", False): + st.session_state.requirements_generating = False + + # Asynchronously generate detailed requirements + initial_req = st.session_state.get("initial_requirement", "") + user_answers = st.session_state.get("user_answers", {}) + + if initial_req: + try: + # Use asynchronous processing to generate requirement summary + result = run_async_task_simple( + handle_requirement_analysis_workflow( + user_input=initial_req, + analysis_mode="summarize_requirements", + user_answers=user_answers, + ) + ) + + if result["status"] == "success": + st.session_state.detailed_requirements = result["result"] + else: + st.error( + f"Requirement summary generation failed: {result.get('error', 'Unknown error')}" + ) + + except Exception as e: + st.error(f"Requirement summary generation exception: {str(e)}") + + # Check if requirements need to be edited + if st.session_state.get("requirements_editing", False): + st.session_state.requirements_editing = False + st.info("🔧 Starting requirement modification process...") + + # Asynchronously modify requirements based on user feedback + current_requirements = st.session_state.get("detailed_requirements", "") + edit_feedback = st.session_state.get("edit_feedback", "") + + if current_requirements and edit_feedback: + try: + # Use asynchronous processing to modify requirements + result = run_async_task_simple( + handle_requirement_modification_workflow( + current_requirements=current_requirements, + modification_feedback=edit_feedback, + ) + ) + + if result["status"] == "success": + st.session_state.detailed_requirements = result["result"] + st.session_state.requirement_analysis_step = "summary" + st.session_state.edit_feedback = "" + st.success("✅ Requirements updated successfully!") + st.rerun() + else: + st.error( + f"Requirements modification failed: {result.get('error', 'Unknown error')}" + ) + + except Exception as e: + st.error(f"Requirements modification exception: {str(e)}") + + def handle_start_processing_button(input_source: str, input_type: str): """ Handle start processing button click @@ -666,6 +863,30 @@ def initialize_session_state(): False # Default enable indexing functionality ) + # Requirement analysis related states + if "requirement_analysis_mode" not in st.session_state: + st.session_state.requirement_analysis_mode = "direct" # direct/guided + if "requirement_analysis_step" not in st.session_state: + st.session_state.requirement_analysis_step = "input" # input/questions/summary + if "generated_questions" not in st.session_state: + st.session_state.generated_questions = [] + if "user_answers" not in st.session_state: + st.session_state.user_answers = {} + if "detailed_requirements" not in st.session_state: + st.session_state.detailed_requirements = "" + if "initial_requirement" not in st.session_state: + st.session_state.initial_requirement = "" + if "questions_generating" not in st.session_state: + st.session_state.questions_generating = False + if "requirements_generating" not in st.session_state: + st.session_state.requirements_generating = False + if "requirements_confirmed" not in st.session_state: + st.session_state.requirements_confirmed = False + if "edit_feedback" not in st.session_state: + st.session_state.edit_feedback = "" + if "requirements_editing" not in st.session_state: + st.session_state.requirements_editing = False + def cleanup_resources(): """ diff --git a/ui/layout.py b/ui/layout.py index 54185f55..dec3c9b9 100644 --- a/ui/layout.py +++ b/ui/layout.py @@ -18,6 +18,7 @@ initialize_session_state, handle_start_processing_button, handle_error_display, + handle_guided_mode_processing, ) from .styles import get_main_styles @@ -62,11 +63,45 @@ def render_main_content(): def render_input_interface(): """Render input interface""" - # Get input source and type - input_source, input_type = input_method_selector(st.session_state.task_counter) - - # Processing button - if input_source and not st.session_state.processing: + # 处理引导模式的异步操作 + handle_guided_mode_processing() + + # Check if user is in guided analysis workflow + if st.session_state.get( + "requirement_analysis_mode" + ) == "guided" and st.session_state.get("requirement_analysis_step") in [ + "questions", + "summary", + "editing", + ]: + # User is in guided analysis workflow, show chat input directly + from .components import chat_input_component + + input_source = chat_input_component(st.session_state.task_counter) + input_type = "chat" if input_source else None + else: + # Normal flow: show input method selector + input_source, input_type = input_method_selector(st.session_state.task_counter) + + # Processing button - Check if requirements are confirmed for guided mode + requirements_confirmed = st.session_state.get("requirements_confirmed", False) + + # For guided mode, if requirements are confirmed, automatically start processing + if ( + st.session_state.get("requirement_analysis_mode") == "guided" + and requirements_confirmed + and input_source + and not st.session_state.processing + ): + # Automatically start processing for confirmed requirements + st.session_state.requirements_confirmed = ( + False # Clear flag to prevent re-processing + ) + handle_start_processing_button(input_source, input_type) + elif ( + input_source and not st.session_state.processing and not requirements_confirmed + ): + # Only show Start Processing button if requirements are not already confirmed if st.button("🚀 Start Processing", type="primary", use_container_width=True): handle_start_processing_button(input_source, input_type) @@ -75,7 +110,9 @@ def render_input_interface(): st.warning("⚠️ Do not refresh the page or close the browser during processing.") elif not input_source: - st.info("👆 Please upload a file or enter a URL to start processing.") + st.info( + "👆 Please upload a file, enter a URL, or describe your coding requirements to start processing." + ) def render_sidebar(): diff --git a/workflows/agent_orchestration_engine.py b/workflows/agent_orchestration_engine.py index f225a8d8..f8cf57c1 100644 --- a/workflows/agent_orchestration_engine.py +++ b/workflows/agent_orchestration_engine.py @@ -1737,3 +1737,130 @@ async def execute_chat_based_planning_pipeline( except Exception as e: print(f"Error in execute_chat_based_planning_pipeline: {e}") raise e + + +async def run_requirement_analysis_agent( + user_input: str, + analysis_mode: str, + user_answers: Dict[str, str] = None, + logger=None, +) -> str: + """ + Run requirement analysis Agent for question generation or requirement summarization + + Args: + user_input: User's initial requirement description + analysis_mode: Analysis mode ("generate_questions" or "summarize_requirements") + user_answers: User's answer dictionary for questions (only used in summarize_requirements mode) + logger: Logger instance + + Returns: + str: Generated question JSON string or detailed requirement document + """ + try: + print(f"🧠 Starting requirement analysis Agent, mode: {analysis_mode}") + print(f"Input length: {len(user_input) if user_input else 0}") + + if not user_input or user_input.strip() == "": + raise ValueError("User input cannot be empty") + + # Import requirement analysis Agent + from workflows.agents.requirement_analysis_agent import RequirementAnalysisAgent + + # Create requirement analysis Agent instance + async with RequirementAnalysisAgent(logger=logger) as req_agent: + if analysis_mode == "generate_questions": + # Generate guiding questions + print("📝 Generating guiding questions...") + questions = await req_agent.generate_guiding_questions(user_input) + return json.dumps(questions, ensure_ascii=False, indent=2) + + elif analysis_mode == "summarize_requirements": + # Summarize detailed requirements + print("📋 Summarizing detailed requirements...") + if user_answers is None: + user_answers = {} + summary = await req_agent.summarize_detailed_requirements( + user_input, user_answers + ) + return summary + + else: + raise ValueError(f"Unsupported analysis mode: {analysis_mode}") + + except Exception as e: + print(f"❌ Requirement analysis Agent execution failed: {e}") + print(f"Exception details: {type(e).__name__}: {str(e)}") + raise + + +async def execute_requirement_analysis_workflow( + user_input: str, + analysis_mode: str, + user_answers: Dict[str, str] = None, + logger=None, + progress_callback: Optional[Callable] = None, +) -> Dict[str, Any]: + """ + Execute user requirement analysis workflow + + This function supports two modes: + 1. generate_questions: Generate guiding questions based on user initial requirements + 2. summarize_requirements: Generate detailed requirement document based on user answers + + Args: + user_input: User's initial requirement description + analysis_mode: Analysis mode ("generate_questions" or "summarize_requirements") + user_answers: User's answer dictionary for questions + logger: Logger instance + progress_callback: Progress callback function + + Returns: + Dict[str, Any]: Dictionary containing analysis results + """ + try: + print(f"🧠 Starting requirement analysis workflow, mode: {analysis_mode}") + + if progress_callback: + if analysis_mode == "generate_questions": + progress_callback( + 10, + "🤔 Analyzing user requirements, generating guiding questions...", + ) + else: + progress_callback( + 10, + "📝 Integrating user answers, generating detailed requirement document...", + ) + + # Call requirement analysis Agent + result = await run_requirement_analysis_agent( + user_input=user_input, + analysis_mode=analysis_mode, + user_answers=user_answers, + logger=logger, + ) + + if progress_callback: + progress_callback(100, "✅ Requirement analysis completed!") + + return { + "status": "success", + "mode": analysis_mode, + "result": result, + "message": f"Requirement analysis ({analysis_mode}) executed successfully", + } + + except Exception as e: + error_msg = f"Requirement analysis workflow execution failed: {str(e)}" + print(f"❌ {error_msg}") + + if progress_callback: + progress_callback(0, f"❌ {error_msg}") + + return { + "status": "error", + "mode": analysis_mode, + "error": error_msg, + "message": "Requirement analysis workflow execution failed", + } diff --git a/workflows/agents/requirement_analysis_agent.py b/workflows/agents/requirement_analysis_agent.py new file mode 100644 index 00000000..1bc5b0a7 --- /dev/null +++ b/workflows/agents/requirement_analysis_agent.py @@ -0,0 +1,408 @@ +""" +User Requirement Analysis Agent + +Responsible for analyzing user initial requirements, generating guiding questions, +and summarizing detailed requirement documents based on user responses. +This Agent seamlessly integrates with existing chat workflows to provide more precise requirement understanding. +""" + +import json +import logging +from typing import Dict, Any, List, Optional + +from mcp_agent.agents.agent import Agent +from utils.llm_utils import get_preferred_llm_class + + +class RequirementAnalysisAgent: + """ + User Requirement Analysis Agent + + Core Functions: + 1. Generate 5-8 guiding questions based on user initial requirements + 2. Collect user responses and analyze requirement completeness + 3. Generate detailed requirement documents for subsequent workflows + 4. Support skipping questions to directly enter implementation process + + Design Philosophy:ß + - Intelligent question generation covering functionality, technology, performance, UI, deployment dimensions + - Flexible user interaction supporting partial answers or complete skipping + - Structured requirement output for easy understanding by code generation agents + """ + + def __init__(self, logger: Optional[logging.Logger] = None): + """ + Initialize requirement analysis agent + Args: + logger: Logger instance + """ + self.logger = logger or self._create_default_logger() + self.mcp_agent = None + self.llm = None + + def _create_default_logger(self) -> logging.Logger: + """Create default logger""" + logger = logging.getLogger(f"{__name__}.RequirementAnalysisAgent") + logger.setLevel(logging.INFO) + return logger + + async def __aenter__(self): + """Async context manager entry""" + await self.initialize() + return self + + async def __aexit__(self, exc_type, exc_val, exc_tb): + """Async context manager exit""" + await self.cleanup() + + async def initialize(self): + """Initialize MCP Agent connection and LLM""" + try: + self.mcp_agent = Agent( + name="RequirementAnalysisAgent", + instruction="""You are a professional requirement analysis expert, skilled at guiding users to provide more detailed project requirements through precise questions. + +Your core capabilities: +1. **Intelligent Question Generation**: Based on user initial descriptions, generate 5-8 key questions covering functional requirements, technology selection, performance requirements, user interface, deployment environment, etc. +2. **Requirement Understanding Analysis**: Deep analysis of user's real intentions and implicit requirements +3. **Structured Requirement Output**: Integrate scattered requirement information into clear technical specification documents + +Question Generation Principles: +- Questions should be specific and clear, avoiding overly broad scope +- Cover key decision points for technical implementation +- Consider project feasibility and complexity +- Help users think about important details they might have missed + +Requirement Summary Principles: +- Maintain user's original intent unchanged +- Supplement key information for technical implementation +- Provide clear functional module division +- Give reasonable technical architecture suggestions""", + server_names=[], # No MCP servers needed, only use LLM + ) + + # Initialize agent context + await self.mcp_agent.__aenter__() + + # Attach LLM + self.llm = await self.mcp_agent.attach_llm(get_preferred_llm_class()) + + self.logger.info("RequirementAnalysisAgent initialized successfully") + + except Exception as e: + self.logger.error(f"RequirementAnalysisAgent initialization failed: {e}") + raise + + async def cleanup(self): + """Clean up resources""" + if self.mcp_agent: + try: + await self.mcp_agent.__aexit__(None, None, None) + except Exception as e: + self.logger.warning(f"Error during resource cleanup: {e}") + + async def generate_guiding_questions(self, user_input: str) -> List[Dict[str, str]]: + """ + Generate guiding questions based on user initial requirements + + Args: + user_input: User's initial requirement description + + Returns: + List[Dict]: Question list, each question contains category, question, importance and other fields + """ + try: + self.logger.info("Starting to generate AI precise guiding questions") + + # Build more precise prompt + prompt = f"""Based on user's project requirements, generate precise guiding questions to help refine requirements. + +User Requirements: {user_input} + +Please analyze user requirements and generate 1-3 most critical targeted questions focusing on the most important aspects for this specific project + +Return format (pure JSON array, no other text): +[ + {{ + "category": "Functional Requirements", + "question": "Specific question content", + "importance": "High", + "hint": "Question hint" + }} +] + +Requirements: Questions should be specific and practical, avoiding general discussions.""" + + from mcp_agent.workflows.llm.augmented_llm import RequestParams + + params = RequestParams( + max_tokens=3000, + temperature=0.5 # Lower temperature for more stable JSON output + ) + + self.logger.info(f"Calling LLM to generate precise questions, input length: {len(user_input)}") + + result = await self.llm.generate_str( + message=prompt, + request_params=params + ) + + self.logger.info(f"LLM returned result length: {len(result) if result else 0}") + + if not result or not result.strip(): + self.logger.error("LLM returned empty result") + raise ValueError("LLM returned empty result") + + self.logger.info(f"LLM returned result: {result[:500]}...") + + # Clean result and extract JSON part + result_cleaned = result.strip() + + # Try to find JSON array + import re + json_pattern = r'\[\s*\{.*?\}\s*\]' + json_match = re.search(json_pattern, result_cleaned, re.DOTALL) + + if json_match: + json_str = json_match.group() + self.logger.info(f"Extracted JSON: {json_str[:200]}...") + else: + # If complete JSON not found, try direct parsing + json_str = result_cleaned + + # Parse JSON result + try: + questions = json.loads(json_str) + if isinstance(questions, list) and len(questions) > 0: + self.logger.info(f"✅ Successfully generated {len(questions)} AI precise guiding questions") + return questions + else: + raise ValueError("Returned result is not a valid question list") + + except json.JSONDecodeError as e: + self.logger.error(f"JSON parsing failed: {e}") + self.logger.error(f"Original result: {result}") + + # Try more lenient JSON extraction + lines = result.split('\n') + json_lines = [] + in_json = False + + for line in lines: + if '[' in line: + in_json = True + if in_json: + json_lines.append(line) + if ']' in line and in_json: + break + + if json_lines: + try: + json_attempt = '\n'.join(json_lines) + questions = json.loads(json_attempt) + if isinstance(questions, list) and len(questions) > 0: + self.logger.info(f"✅ Generated {len(questions)} questions through lenient parsing") + return questions + except Exception: + pass + + # If JSON parsing fails, raise an error + self.logger.error("JSON parsing completely failed") + raise ValueError("Failed to parse AI generated questions") + + except Exception as e: + self.logger.error(f"Failed to generate guiding questions: {e}") + # Re-raise the exception instead of falling back to default questions + raise + + async def summarize_detailed_requirements(self, + initial_input: str, + answers: Dict[str, str]) -> str: + """ + Generate detailed requirement document based on initial input and user answers + + Args: + initial_input: User's initial requirement description + answers: User's answer dictionary {question_id: answer} + + Returns: + str: Detailed requirement document + """ + try: + self.logger.info("Starting to generate AI detailed requirement summary") + + # Build answer content + answers_text = "" + if answers: + for question_id, answer in answers.items(): + if answer and answer.strip(): + answers_text += f"• {answer}\n" + + if not answers_text: + answers_text = "User chose to skip questions, generating based on initial requirements" + + prompt = f"""Based on user requirements and responses, generate a concise project requirement document. + +Initial Requirements: {initial_input} + +Additional Information: +{answers_text} + +Please generate a focused requirement document including: + +## Project Overview +Brief description of project's core goals and value proposition + +## Functional Requirements +Detailed list of required features and functional modules: +- Core functionalities +- User interactions and workflows +- Data processing requirements +- Integration needs + +## Technical Architecture +Recommended technical design including: +- Technology stack and frameworks +- System architecture design +- Database and data storage solutions +- API design considerations +- Security requirements + +## Performance & Scalability +- Expected user scale and performance requirements +- Scalability considerations and constraints + +Requirements: Focus on what needs to be built and how to build it technically. Be concise but comprehensive - avoid unnecessary implementation details.""" + + from mcp_agent.workflows.llm.augmented_llm import RequestParams + + params = RequestParams( + max_tokens=4000, + temperature=0.3 + ) + + self.logger.info(f"Calling LLM to generate requirement summary, initial requirement length: {len(initial_input)}") + + result = await self.llm.generate_str( + message=prompt, + request_params=params + ) + + if not result or not result.strip(): + self.logger.error("LLM returned empty requirement summary") + raise ValueError("LLM returned empty requirement summary") + + self.logger.info(f"✅ Requirement summary generation completed, length: {len(result)}") + return result.strip() + + except Exception as e: + self.logger.error(f"Requirement summary failed: {e}") + # Return basic requirement document + return f"""## Project Overview +Based on user requirements: {initial_input} + +## Functional Requirements +Core functionality needed: {initial_input} + +## Technical Architecture +- Select appropriate technology stack based on project requirements +- Adopt modular architecture design +- Consider database and data storage solutions +- Implement necessary security measures + +## Performance & Scalability +- Design for expected user scale +- Consider scalability and performance requirements + +Note: Due to technical issues, this is a simplified requirement document. Manual supplementation of detailed information is recommended.""" + + async def modify_requirements(self, + current_requirements: str, + modification_feedback: str) -> str: + """ + Modify existing requirement document based on user feedback + + Args: + current_requirements: Current requirement document content + modification_feedback: User's modification requests and feedback + + Returns: + str: Modified requirement document + """ + try: + self.logger.info("Starting to modify requirements based on user feedback") + + # Build modification prompt + prompt = f"""Based on the current requirement document and user's modification requests, generate an updated requirement document. + +Current Requirements Document: +{current_requirements} + +User's Modification Requests: +{modification_feedback} + +CRITICAL REQUIREMENT: You MUST generate a complete, well-structured requirement document regardless of how complete or incomplete the user's modification requests are. Even if the user only provides minimal or unclear feedback, you must still produce a comprehensive requirement document following the exact format below. + +Generate an updated requirement document that incorporates any reasonable interpretation of the user's requested changes while maintaining the EXACT structure and format: + +## Project Overview +Brief description of project's core goals and value proposition + +## Functional Requirements +Detailed list of required features and functional modules: +- Core functionalities +- User interactions and workflows +- Data processing requirements +- Integration needs + +## Technical Architecture +Recommended technical design including: +- Technology stack and frameworks +- System architecture design +- Database and data storage solutions +- API design considerations +- Security requirements + +## Performance & Scalability +- Expected user scale and performance requirements +- Scalability considerations and constraints + +MANDATORY REQUIREMENTS: +1. ALWAYS return a complete document with ALL sections above, regardless of user input completeness +2. If user feedback is unclear or incomplete, make reasonable assumptions based on the current requirements +3. Incorporate any clear user requests while filling in missing details intelligently +4. Maintain consistency and coherence throughout the document +5. Ensure all technical suggestions are feasible and practical +6. NEVER return an incomplete or partial document - always provide full sections +7. Keep the same professional structure and format in all cases""" + + from mcp_agent.workflows.llm.augmented_llm import RequestParams + + params = RequestParams( + max_tokens=4000, + temperature=0.3 + ) + + self.logger.info(f"Calling LLM to modify requirements, feedback length: {len(modification_feedback)}") + + result = await self.llm.generate_str( + message=prompt, + request_params=params + ) + + if not result or not result.strip(): + self.logger.error("LLM returned empty modified requirements") + raise ValueError("LLM returned empty modified requirements") + + self.logger.info(f"✅ Requirements modification completed, length: {len(result)}") + return result.strip() + + except Exception as e: + self.logger.error(f"Requirements modification failed: {e}") + # Return current requirements with a note about the modification attempt + return f"""{current_requirements} + +--- +**Note:** Automatic modification failed due to technical issues. The original requirements are shown above. Please manually incorporate the following requested changes: + +{modification_feedback}""" From 80940700ba31b2c1c439cfe45a529f3f4915e334 Mon Sep 17 00:00:00 2001 From: Zongwei9888 Date: Mon, 29 Sep 2025 15:28:05 +0800 Subject: [PATCH 06/25] Update user demand personalization customization features --- mcp_agent.secrets.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mcp_agent.secrets.yaml b/mcp_agent.secrets.yaml index 23c4e1fd..6e670162 100644 --- a/mcp_agent.secrets.yaml +++ b/mcp_agent.secrets.yaml @@ -1,6 +1,6 @@ openai: - api_key: "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" - base_url: "https://openrouter.ai/api/v1" + api_key: "" + base_url: "" From 9d964ecae91eb00ac0e2d982b47d7918e4da55b5 Mon Sep 17 00:00:00 2001 From: Zongwei9888 Date: Tue, 30 Sep 2025 00:36:33 +0800 Subject: [PATCH 07/25] New UI and Update User Demand Personalization Features --- deepcode.py | 2 +- ui/components.py | 398 +---- ui/layout.py | 26 +- ui/styles.py | 1461 ++++++++++++++++- .../agents/requirement_analysis_agent.py | 138 +- 5 files changed, 1538 insertions(+), 487 deletions(-) diff --git a/deepcode.py b/deepcode.py index 4121f176..01e6afc7 100755 --- a/deepcode.py +++ b/deepcode.py @@ -182,7 +182,7 @@ def main(): "run", str(streamlit_app_path), "--server.port", - "8502", + "8503", "--server.address", "localhost", "--browser.gatherUsageStats", diff --git a/ui/components.py b/ui/components.py index 8427fec8..933f419b 100644 --- a/ui/components.py +++ b/ui/components.py @@ -1,3 +1,4 @@ +# -*- coding: utf-8 -*- """ Streamlit UI Components Module @@ -12,382 +13,93 @@ def display_header(): - """Display application header""" + """Display modern, compact application header""" st.markdown( """ -
-

🧬 DeepCode

-

OPEN-SOURCE CODE AGENT

-

⚡ DATA INTELLIGENCE LAB @ HKU • REVOLUTIONIZING RESEARCH REPRODUCIBILITY ⚡

-
- """, - unsafe_allow_html=True, - ) - - -def display_features(): - """Display DeepCode AI Agent capabilities""" - # AI Agent core capabilities display area - updated to match README content - st.markdown( - """ -
-
-
-
-
-
-

🧠 Open Agentic Coding Platform

-

Advancing Code Generation with Multi-Agent Systems

-
- """, - unsafe_allow_html=True, - ) - - # Core functionality modules - Vertical Layout - st.markdown( - """ -
-
-
-
- -
🚀
-
-
-

Paper2Code: Research-to-Production Pipeline

-

Automated Implementation of Complex Algorithms

-
-
-
- Multi-Modal - Analysis -
-
- Production - Ready -
-
-
-
-
-

Multi-modal document analysis engine that extracts algorithmic logic and mathematical models from academic papers, generating optimized implementations with proper data structures while preserving computational complexity characteristics.

-
-
-
📄
- Document Parsing -
-
-
-
🧠
- Algorithm Extraction -
-
-
-
- Code Synthesis -
-
-
-
- Quality Assurance +
+
+
+
+
+
+
+ ◊ DeepCode
-
-
-
-
- Python -
Generating...
-
-
-
import torch
-
import torch.nn as nn
-
class ResearchAlgorithm(nn.Module):
-
def __init__(self, config):
-
super().__init__()
-
+
+ AI Research Engine + + Data Intelligence Lab @ HKU
+
+ + ONLINE +
""", unsafe_allow_html=True, ) + +def display_features(): + """Display DeepCode AI capabilities with world-class, futuristic design""" + + # Capability Matrix st.markdown( """ -
-
-
-
-