auto-coder 0.1.392__py3-none-any.whl → 0.1.395__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of auto-coder might be problematic. Click here for more details.

@@ -10,6 +10,10 @@ from rich.panel import Panel
10
10
  from pydantic import SkipValidation
11
11
  from byzerllm.utils.types import SingleOutputMeta
12
12
 
13
+ from byzerllm.utils import (
14
+ format_str_jinja2
15
+ )
16
+
13
17
  from autocoder.common import AutoCoderArgs, git_utils, SourceCodeList, SourceCode
14
18
  from autocoder.common.global_cancel import global_cancel
15
19
  from autocoder.common import detect_env
@@ -56,7 +60,7 @@ from autocoder.common.v2.agent.agentic_edit_tools import ( # Import specific re
56
60
  ReplaceInFileToolResolver, SearchFilesToolResolver, ListFilesToolResolver,
57
61
  ListCodeDefinitionNamesToolResolver, AskFollowupQuestionToolResolver,
58
62
  AttemptCompletionToolResolver, PlanModeRespondToolResolver, UseMcpToolResolver,
59
- ListPackageInfoToolResolver
63
+ UseRAGToolResolver, ListPackageInfoToolResolver
60
64
  )
61
65
  from autocoder.common.llm_friendly_package import LLMFriendlyPackageManager
62
66
  from autocoder.common.rulefiles.autocoderrules_utils import get_rules,auto_select_rules,get_required_and_index_rules
@@ -69,7 +73,7 @@ from autocoder.common.v2.agent.agentic_edit_types import (AgenticEditRequest, To
69
73
  ListFilesTool,
70
74
  ListCodeDefinitionNamesTool, AskFollowupQuestionTool,
71
75
  AttemptCompletionTool, PlanModeRespondTool, UseMcpTool,
72
- ListPackageInfoTool,
76
+ UseRAGTool, ListPackageInfoTool,
73
77
  TOOL_MODEL_MAP,
74
78
  # Event Types
75
79
  LLMOutputEvent, LLMThinkingEvent, ToolCallEvent,
@@ -80,7 +84,7 @@ from autocoder.common.v2.agent.agentic_edit_types import (AgenticEditRequest, To
80
84
  ListFilesTool, SearchFilesTool, ListCodeDefinitionNamesTool,
81
85
  AskFollowupQuestionTool, UseMcpTool, AttemptCompletionTool
82
86
  )
83
-
87
+ from autocoder.common.rag_manager import RAGManager
84
88
  from autocoder.rag.token_counter import count_tokens
85
89
 
86
90
  # Map Pydantic Tool Models to their Resolver Classes
@@ -96,7 +100,8 @@ TOOL_RESOLVER_MAP: Dict[Type[BaseTool], Type[BaseToolResolver]] = {
96
100
  AskFollowupQuestionTool: AskFollowupQuestionToolResolver,
97
101
  AttemptCompletionTool: AttemptCompletionToolResolver, # Will stop the loop anyway
98
102
  PlanModeRespondTool: PlanModeRespondToolResolver,
99
- UseMcpTool: UseMcpToolResolver
103
+ UseMcpTool: UseMcpToolResolver,
104
+ UseRAGTool: UseRAGToolResolver
100
105
  }
101
106
 
102
107
 
@@ -161,12 +166,25 @@ class AgenticEdit:
161
166
  except Exception as e:
162
167
  logger.error(f"Error getting MCP server info: {str(e)}")
163
168
 
169
+ # 初始化 RAG 管理器并获取服务器信息
170
+ self.rag_server_info = ""
171
+ try:
172
+ self.rag_manager = RAGManager(args)
173
+ if self.rag_manager.has_configs():
174
+ self.rag_server_info = self.rag_manager.get_config_info()
175
+ logger.info(f"RAG manager initialized with {len(self.rag_manager.get_all_configs())} configurations")
176
+ else:
177
+ logger.info("No RAG configurations found")
178
+ except Exception as e:
179
+ logger.error(f"Error initializing RAG manager: {str(e)}")
180
+ self.rag_manager = None
181
+
164
182
  # 变更跟踪信息
165
183
  # 格式: { file_path: FileChangeEntry(...) }
166
184
  self.file_changes: Dict[str, FileChangeEntry] = {}
167
185
 
168
186
  @byzerllm.prompt()
169
- def generate_library_docs_prompt(self, libraries: List[str], docs_content: str) -> Dict[str, Any]:
187
+ def generate_library_docs_prompt(self, libraries_with_paths: List[Dict[str, str]], docs_content: str) -> Dict[str, Any]:
170
188
  """
171
189
  ====
172
190
 
@@ -187,8 +205,15 @@ class AgenticEdit:
187
205
  4. You need to understand the API or usage patterns of these libraries
188
206
  ====
189
207
  """
208
+ # 格式化库列表,包含名称和路径
209
+ libraries_list = []
210
+ for lib_info in libraries_with_paths:
211
+ name = lib_info.get('name', '')
212
+ path = lib_info.get('path', 'Path not found')
213
+ libraries_list.append(f"{name} (路径: {path})")
214
+
190
215
  return {
191
- "libraries_list": ", ".join(libraries),
216
+ "libraries_list": ", ".join(libraries_list),
192
217
  "combined_docs": docs_content
193
218
  }
194
219
 
@@ -442,6 +467,22 @@ class AgenticEdit:
442
467
  {{mcp_server_info}}
443
468
  {%endif%}
444
469
 
470
+ ## rag_tool
471
+ Description: Request to query the RAG server for information. Use this when you need to query the RAG server for information.
472
+ Parameters:
473
+ - server_name: (required) The url of the RAG server to use.
474
+ - query: (required) The query to pass to the tool.
475
+ Usage:
476
+ <use_rag_tool>
477
+ <server_name>xxx</server_name>
478
+ <query>Your query here</query>
479
+ </use_rag_tool>
480
+
481
+ {%if rag_server_info %}
482
+ ### RAG_SERVER_LIST
483
+ {{rag_server_info}}
484
+ {%endif%}
485
+
445
486
  # Tool Use Examples
446
487
 
447
488
  ## Example 1: Requesting to execute a command
@@ -517,7 +558,7 @@ class AgenticEdit:
517
558
  </use_mcp_tool>
518
559
 
519
560
  # Tool Use Guidelines
520
-
561
+ 0. **ALWAYS START WITH THOROUGH SEARCH AND EXPLORATION.** Before making any code changes, use search tools (list_files, grep commands) to fully understand the codebase structure, existing patterns, and dependencies. This prevents errors and ensures your changes align with project conventions.
521
562
  1. In <thinking> tags, assess what information you already have and what information you need to proceed with the task.
522
563
  2. Choose the most appropriate tool based on the task and the tool descriptions provided. Assess if you need additional information to proceed, and which of the available tools would be most effective for gathering this information. For example using the list_files tool is more effective than running a command like \`ls\` in the terminal. It's critical that you think about each available tool and use the one that best fits the current step in the task.
523
564
  3. If multiple actions are needed, use one tool at a time per message to accomplish the task iteratively, with each tool use being informed by the result of the previous tool use. Do not assume the outcome of any tool use. Each step must be informed by the previous step's result.
@@ -538,9 +579,286 @@ class AgenticEdit:
538
579
  By waiting for and carefully considering the user's response after each tool use, you can react accordingly and make informed decisions about how to proceed with the task. This iterative process helps ensure the overall success and accuracy of your work.
539
580
 
540
581
  ====
582
+ SEARCHING FILES
583
+
584
+ **THIS IS YOUR CORE METHODOLOGY** - The following search-first approach is not optional but mandatory for reliable code work. Every code task should follow this systematic exploration pattern.
585
+ This guide provides a systematic approach for AI agents and developers to effectively search, understand, and modify codebases. It emphasizes thorough pre-code investigation and post-code verification to ensure reliable and maintainable changes.
541
586
 
542
- EDITING FILES
587
+ The methodology combines multiple search tools (grep, list_files, read_file) with structured workflows to minimize code errors, ensure comprehensive understanding, validate changes systematically, and follow established project patterns.
588
+
589
+ # list_files
590
+
591
+ ## Purpose
592
+
593
+ - Discover project structure and understand directory organization
594
+ - Get an overview of available files and folders before diving deeper
595
+
596
+ ## When to Use
597
+
598
+ - Initial project exploration to understand the codebase layout
599
+ - Identifying key directories like `src/`, `lib/`, `components/`, `utils/`
600
+ - Locating configuration files like `package.json`, `tsconfig.json`, `Makefile`
601
+ - Before using more targeted search tools
602
+
603
+ ## Advantages
604
+
605
+ - Provides quick project overview without overwhelming detail
606
+ - Helps plan targeted searches in specific directories
607
+ - Essential first step in understanding unfamiliar codebases
608
+
609
+ # grep (Shell Commands)
610
+
611
+ ## Purpose
612
+
613
+ - Find exact text matches and patterns across multiple files
614
+ - Perform precise searches with minimal output overhead
615
+ - Verify code changes and validate implementations
616
+
617
+ ## When to Use
618
+
619
+ - **Pre-code Context Gathering**: Locate symbols, functions, imports, and usage patterns
620
+ - **Post-code Verification**: Confirm changes were applied correctly and no stale references remain
621
+ - **Pattern Analysis**: Understand coding conventions and existing implementations
622
+
623
+ ## Key Command Patterns
624
+
625
+ **Pre-code Context Examples:**
626
+
627
+ <execute_command>
628
+ <command>grep -l "className" src/ | head -5</command>
629
+ <requires_approval>false</requires_approval>
630
+ </execute_command>
631
+
632
+ <execute_command>
633
+ <command>grep -rc "import.*React" src/ | grep -v ":0"</command>
634
+ <requires_approval>false</requires_approval>
635
+ </execute_command>
636
+
637
+ <execute_command>
638
+ <command>grep -Rn "function.*MyFunction\|const.*MyFunction" . | head -10</command>
639
+ <requires_approval>false</requires_approval>
640
+ </execute_command>
641
+
642
+ <execute_command>
643
+ <command>grep -R --exclude-dir={node_modules,dist,build,.git} "TODO" .</command>
644
+ <requires_approval>false</requires_approval>
645
+ </execute_command>
646
+
647
+ **Post-code Verification Examples:**
648
+
649
+ <execute_command>
650
+ <command>ls -la newfile.js 2>/dev/null && echo "File created" || echo "File not found"</command>
651
+ <requires_approval>false</requires_approval>
652
+ </execute_command>
653
+
654
+ <execute_command>
655
+ <command>grep -Rn "oldName" . || echo "✓ No stale references found"</command>
656
+ <requires_approval>false</requires_approval>
657
+ </execute_command>
658
+
659
+ <execute_command>
660
+ <command>grep -c "newName" src/*.js | grep -v ":0" || echo "⚠ New references not found"</command>
661
+ <requires_approval>false</requires_approval>
662
+ </execute_command>
663
+
664
+ <execute_command>
665
+ <command>grep -Rn "import.*newModule\|export.*newFunction" . | wc -l</command>
666
+ <requires_approval>false</requires_approval>
667
+ </execute_command>
668
+
669
+ ## Output Optimization Tips
670
+
671
+ - Use `-l` for filenames only
672
+ - Use `-c` for count only
673
+ - Use `| head -N` to limit lines
674
+ - Use `| wc -l` for total count
675
+ - Use `2>/dev/null` to suppress errors
676
+ - Combine with `|| echo` for clear status messages
677
+
678
+ # search_files (Fallback)
679
+
680
+ ## Purpose
681
+
682
+ - Alternative search method when grep commands aren't available
683
+ - Semantic search capabilities for finding related code
684
+
685
+ ## When to Use
686
+
687
+ - When shell access is limited or grep is unavailable
688
+ - For broader, less precise searches across the codebase
689
+ - As a complement to grep for comprehensive code discovery
690
+
691
+ # read_file
692
+
693
+ ## Purpose
694
+
695
+ - Examine complete file contents in detail
696
+ - Understand context, patterns, and implementation details
697
+
698
+ ## When to Use
543
699
 
700
+ - After identifying target files through list_files or grep
701
+ - To understand function signatures, interfaces, and contracts
702
+ - For analyzing usage patterns and project conventions
703
+ - When detailed code examination is needed before making changes
704
+
705
+ ## Important Considerations
706
+
707
+ - Use strategically after narrowing down target files
708
+ - Essential for understanding context before code modification
709
+ - Helps identify dependencies and potential side effects
710
+
711
+ # Choosing the Right Search Strategy
712
+
713
+ - **Start with list_files** to understand project structure
714
+ - **Use grep for targeted searches** when you know what to look for
715
+ - **Apply read_file for detailed examination** of specific files
716
+ - **Combine multiple approaches** for comprehensive understanding
717
+
718
+ **Default workflow:**
719
+ 1. `list_files` → understand structure
720
+ 2. `grep` → find specific patterns/symbols
721
+ 3. `read_file` → examine details
722
+ 4. Implement changes
723
+ 5. `grep` → verify changes
724
+
725
+ # Comprehensive Workflow
726
+
727
+ ## Phase 1: Project Discovery & Analysis
728
+
729
+ **Project Structure Overview**
730
+ <execute_command>
731
+ <command>ls -la</command>
732
+ <requires_approval>false</requires_approval>
733
+ </execute_command>
734
+
735
+ - Use `list_files` tool to understand directory structure
736
+ - Identify key directories: `src/`, `lib/`, `components/`, `utils/`
737
+ - Look for config files: `package.json`, `tsconfig.json`, `Makefile`
738
+
739
+ **Technology Stack Identification**
740
+ <execute_command>
741
+ <command>grep -E "(import|require|from).*['\"]" src/ | head -20</command>
742
+ <requires_approval>false</requires_approval>
743
+ </execute_command>
744
+
745
+ - Check package dependencies and imports
746
+ - Identify frameworks, libraries, and coding patterns
747
+ - Understand project conventions (naming, file organization)
748
+
749
+ ## Phase 2: Contextual Code Investigation
750
+
751
+ **Symbol and Pattern Search**
752
+ <execute_command>
753
+ <command>grep -Rn "targetFunction\|targetClass" . --exclude-dir={node_modules,dist}</command>
754
+ <requires_approval>false</requires_approval>
755
+ </execute_command>
756
+
757
+ **Usage Pattern Analysis**
758
+ - Use `read_file` to examine key files in detail
759
+ - Understand function signatures, interfaces, and contracts
760
+ - Check error handling patterns and edge cases
761
+
762
+ **Dependency Mapping**
763
+ <execute_command>
764
+ <command>grep -Rn "import.*targetModule" . | grep -v test</command>
765
+ <requires_approval>false</requires_approval>
766
+ </execute_command>
767
+
768
+ ## Phase 3: Implementation Planning
769
+
770
+ **Impact Assessment**
771
+ - Identify all files that need modification
772
+ - Plan backwards compatibility considerations
773
+ - Consider potential side effects
774
+
775
+ **Test Strategy**
776
+ <execute_command>
777
+ <command>find . -name "*test*" -o -name "*spec*" | head -10</command>
778
+ <requires_approval>false</requires_approval>
779
+ </execute_command>
780
+
781
+ - Locate existing tests for reference
782
+ - Plan new test cases if needed
783
+
784
+ ## Phase 4: Code Implementation
785
+
786
+ More detail is on the EDITING FILES PART.
787
+
788
+ ## Phase 5: Comprehensive Verification
789
+
790
+ **File System Verification**
791
+ <execute_command>
792
+ <command>ls -la newfile.* 2>/dev/null || echo "Expected new files not found"</command>
793
+ <requires_approval>false</requires_approval>
794
+ </execute_command>
795
+
796
+ **Code Integration Verification**
797
+ <execute_command>
798
+ <command>grep -Rn "oldSymbol" . --exclude-dir={node_modules,dist} || echo "✓ No stale references"</command>
799
+ <requires_approval>false</requires_approval>
800
+ </execute_command>
801
+
802
+ <execute_command>
803
+ <command>grep -c "newSymbol" src/ --include="*.js" --include="*.ts" | grep -v ":0"</command>
804
+ <requires_approval>false</requires_approval>
805
+ </execute_command>
806
+
807
+ **Functional Verification**
808
+ <execute_command>
809
+ <command>npm run lint 2>/dev/null || echo "Linting not configured"</command>
810
+ <requires_approval>false</requires_approval>
811
+ </execute_command>
812
+
813
+ <execute_command>
814
+ <command>npm test 2>/dev/null || echo "Testing not configured"</command>
815
+ <requires_approval>false</requires_approval>
816
+ </execute_command>
817
+
818
+ <execute_command>
819
+ <command>npm run build 2>/dev/null || echo "Build not configured"</command>
820
+ <requires_approval>false</requires_approval>
821
+ </execute_command>
822
+
823
+ **Documentation & Comments**
824
+ - Verify that new functions/classes have appropriate documentation
825
+ - Check that complex logic has explanatory comments
826
+ - Ensure README or other docs are updated if needed
827
+
828
+ ## Phase 6: Quality Assurance
829
+
830
+ **Performance Considerations**
831
+ - Check for potential performance impacts
832
+ - Verify memory usage patterns
833
+ - Consider scalability implications
834
+
835
+ **Security Review**
836
+ - Look for potential security vulnerabilities
837
+ - Verify input validation and sanitization
838
+ - Check for proper error handling
839
+
840
+ **Final Integration Check**
841
+ <execute_command>
842
+ <command>grep -Rn "TODO\|FIXME\|XXX" . --exclude-dir={node_modules,dist} | wc -l</command>
843
+ <requires_approval>false</requires_approval>
844
+ </execute_command>
845
+
846
+ # Best Practices
847
+
848
+ - **Iterative Approach**: Don't try to understand everything at once; build knowledge progressively
849
+ - **Documentation First**: Read existing docs, comments, and README files before diving into code
850
+ - **Small Steps**: Make incremental changes and verify each step
851
+ - **Rollback Ready**: Always know how to undo changes if something goes wrong
852
+ - **Test Early**: Run tests frequently during development, not just at the end
853
+ - **Pattern Consistency**: Follow established project patterns rather than introducing new ones
854
+
855
+ By following this comprehensive approach, you ensure thorough understanding, reliable implementation, and robust verification of all code changes.
856
+
857
+ ====
858
+
859
+ EDITING FILES
860
+
861
+ Before applying the editing techniques below, ensure you have followed the SEARCHING FILES methodology to fully understand the codebase context.
544
862
  You have access to two tools for working with files: **write_to_file** and **replace_in_file**. Understanding their roles and selecting the right one for the job will help ensure efficient and accurate modifications.
545
863
 
546
864
  # write_to_file
@@ -647,28 +965,31 @@ class AgenticEdit:
647
965
 
648
966
  - Quickly identifies recently modified files that may be relevant to your task
649
967
  - Provides high-level understanding of directory contents and purpose
650
- - Helps prioritize which files to examine in detail with tools like read_file, search_files, or list_code_definition_names
968
+ - Helps prioritize which files to examine in detail with tools like read_file, shell commands, or list_code_definition_names
651
969
 
652
970
  ====
653
971
 
654
972
  CAPABILITIES
655
-
973
+
974
+ - **SEARCH AND UNDERSTAND FIRST**: Your primary strength lies in systematically exploring and understanding codebases before making changes. Use list_files, execute_command (grep) to map project structure, identify patterns, and understand dependencies. This exploration-first approach is crucial for reliable code modifications.
656
975
  - You have access to tools that let you execute CLI commands on the user's computer, list files, view source code definitions, regex search, read and edit files, and ask follow-up questions. These tools help you effectively accomplish a wide range of tasks, such as writing code, making edits or improvements to existing files, understanding the current state of a project, performing system operations, and much more.
657
976
  - When the user initially gives you a task, a recursive list of all filepaths in the current working directory ('{{ current_project }}') will be included in environment_details. This provides an overview of the project's file structure, offering key insights into the project from directory/file names (how developers conceptualize and organize their code) and file extensions (the language used). This can also guide decision-making on which files to explore further. If you need to further explore directories such as outside the current working directory, you can use the list_files tool. If you pass 'true' for the recursive parameter, it will list files recursively. Otherwise, it will list files at the top level, which is better suited for generic directories where you don't necessarily need the nested structure, like the Desktop.
658
- - You can use search_files to perform regex searches across files in a specified directory, outputting context-rich results that include surrounding lines. This is particularly useful for understanding code patterns, finding specific implementations, or identifying areas that need refactoring.
977
+ - You can use shell_command(grep) to perform regex searches across files in a specified directory, outputting context-rich results that include surrounding lines. This is particularly useful for understanding code patterns, finding specific implementations, or identifying areas that need refactoring.
659
978
  - You can use the list_code_definition_names tool to get an overview of source code definitions for all files at the top level of a specified directory. This can be particularly useful when you need to understand the broader context and relationships between certain parts of the code. You may need to call this tool multiple times to understand various parts of the codebase related to the task.
660
- - For example, when asked to make edits or improvements you might analyze the file structure in the initial environment_details to get an overview of the project, then use list_code_definition_names to get further insight using source code definitions for files located in relevant directories, then read_file to examine the contents of relevant files, analyze the code and suggest improvements or make necessary edits, then use the replace_in_file tool to implement changes. If you refactored code that could affect other parts of the codebase, you could use search_files to ensure you update other files as needed.
979
+ - For example, when asked to make edits or improvements you might analyze the file structure in the initial environment_details to get an overview of the project, then use list_code_definition_names to get further insight using source code definitions for files located in relevant directories, then read_file to examine the contents of relevant files, analyze the code and suggest improvements or make necessary edits, then use the replace_in_file tool to implement changes. If you refactored code that could affect other parts of the codebase, you could use shell commands(grep) to ensure you update other files as needed.
661
980
  - You can use the execute_command tool to run commands on the user's computer whenever you feel it can help accomplish the user's task. When you need to execute a CLI command, you must provide a clear explanation of what the command does. Prefer to execute complex CLI commands over creating executable scripts, since they are more flexible and easier to run. Interactive and long-running commands are allowed, since the commands are run in the user's VSCode terminal. The user may keep commands running in the background and you will be kept updated on their status along the way. Each command you execute is run in a new terminal instance.
662
981
 
663
982
  ====
664
983
 
665
984
  RULES
666
-
985
+
667
986
  - Your current working directory is: {{current_project}}
987
+ - **MANDATORY SEARCH BEFORE EDIT**: Before editing any file, you MUST first search to understand its context, dependencies, and usage patterns. Use list_files or grep commands to find related code, imports, and references.
988
+ - **VERIFY THROUGH SEARCH**: After making changes, use list_files or grep commands to verify no stale references remain and that new code integrates properly with existing patterns.
668
989
  - You cannot \`cd\` into a different directory to complete a task. You are stuck operating from '{{ current_project }}', so be sure to pass in the correct 'path' parameter when using tools that require a path.
669
990
  - Do not use the ~ character or $HOME to refer to the home directory.
670
991
  - Before using the execute_command tool, you must first think about the SYSTEM INFORMATION context provided to understand the user's environment and tailor your commands to ensure they are compatible with their system. You must also consider if the command you need to run should be executed in a specific directory outside of the current working directory '{{ current_project }}', and if so prepend with \`cd\`'ing into that directory && then executing the command (as one command since you are stuck operating from '{{ current_project }}'). For example, if you needed to run \`npm install\` in a project outside of '{{ current_project }}', you would need to prepend with a \`cd\` i.e. pseudocode for this would be \`cd (path to project) && (command, in this case npm install)\`.
671
- - When using the search_files tool, craft your regex patterns carefully to balance specificity and flexibility. Based on the user's task you may use it to find code patterns, TODO comments, function definitions, or any text-based information across the project. The results include context, so analyze the surrounding code to better understand the matches. Leverage the search_files tool in combination with other tools for more comprehensive analysis. For example, use it to find specific code patterns, then use read_file to examine the full context of interesting matches before using replace_in_file to make informed changes.
992
+ - When using the shell command tool (grep), craft your regex patterns carefully to balance specificity and flexibility. Based on the user's task you may use it to find code patterns, TODO comments, function definitions, or any text-based information across the project. The results include context, so analyze the surrounding code to better understand the matches. Leverage the shell command tool(grep) in combination with other tools for more comprehensive analysis. For example, use it to find specific code patterns, then use read_file to examine the full context of interesting matches before using replace_in_file to make informed changes.
672
993
  - When creating a new project (such as an app, website, or any software project), organize all new files within a dedicated project directory unless the user specifies otherwise. Use appropriate file paths when creating files, as the write_to_file tool will automatically create any necessary directories. Structure the project logically, adhering to best practices for the specific type of project being created. Unless otherwise specified, new projects should be easily run without additional setup, for example most projects can be built in HTML, CSS, and JavaScript - which you can open in a browser.
673
994
  - Be sure to consider the type of project (e.g. Python, JavaScript, web application) when determining the appropriate structure and files to include. Also consider what files may be most relevant to accomplishing the task, for example looking at a project's manifest file would help you understand the project's dependencies, which you could incorporate into any code you write.
674
995
  - When making changes to code, always consider the context in which the code is being used. Ensure that your changes are compatible with the existing codebase and that they follow the project's coding standards and best practices.
@@ -688,6 +1009,7 @@ class AgenticEdit:
688
1009
  - It is critical you wait for the user's response after each tool use, in order to confirm the success of the tool use. For example, if asked to make a todo app, you would create a file, wait for the user's response it was created successfully, then create another file if needed, wait for the user's response it was created successfully, etc.
689
1010
  - To display LaTeX formulas, use a single dollar sign to wrap inline formulas, like `$E=mc^2$`, and double dollar signs to wrap block-level formulas, like `$$\frac{d}{dx}e^x = e^x$$`.
690
1011
  - To include flowcharts or diagrams, you can use Mermaid syntax.
1012
+ - If you come across some unknown or unfamiliar concepts or terms, or if the user is asking a question, you can try using appropriate MCP or RAG services to obtain the information.
691
1013
 
692
1014
 
693
1015
  {% if extra_docs %}
@@ -743,6 +1065,7 @@ class AgenticEdit:
743
1065
  3. Remember, you have extensive capabilities with access to a wide range of tools that can be used in powerful and clever ways as necessary to accomplish each goal. Before calling a tool, do some analysis within <thinking></thinking> tags. First, analyze the file structure provided in environment_details to gain context and insights for proceeding effectively. Then, think about which of the provided tools is the most relevant tool to accomplish the user's task. Next, go through each of the required parameters of the relevant tool and determine if the user has directly provided or given enough information to infer a value. When deciding if the parameter can be inferred, carefully consider all the context to see if it supports a specific value. If all of the required parameters are present or can be reasonably inferred, close the thinking tag and proceed with the tool use. BUT, if one of the values for a required parameter is missing, DO NOT invoke the tool (not even with fillers for the missing params) and instead, ask the user to provide the missing parameters using the ask_followup_question tool. DO NOT ask for more information on optional parameters if it is not provided.
744
1066
  4. Once you've completed the user's task, you must use the attempt_completion tool to present the result of the task to the user. You may also provide a CLI command to showcase the result of your task; this can be particularly useful for web development tasks, where you can run e.g. \`open index.html\` to show the website you've built.
745
1067
  5. The user may provide feedback, which you can use to make improvements and try again. But DO NOT continue in pointless back and forth conversations, i.e. don't end your responses with questions or offers for further assistance.
1068
+ 6. Work through these goals sequentially, **ALWAYS STARTING WITH COMPREHENSIVE SEARCH AND EXPLORATION** using available tools. For any code-related task, begin with list_files to understand structure, then use commands(grep) to find relevant patterns, and read_file to examine context before making changes.
746
1069
 
747
1070
  """
748
1071
  ## auto_select_rules(context=request.user_input, llm=self.llm,args=self.args) rules =
@@ -769,6 +1092,7 @@ class AgenticEdit:
769
1092
  "home_dir": os.path.expanduser("~"),
770
1093
  "files": self.files.to_str(),
771
1094
  "mcp_server_info": self.mcp_server_info,
1095
+ "rag_server_info": self.rag_server_info,
772
1096
  "enable_active_context_in_generate": self.args.enable_active_context_in_generate,
773
1097
  "extra_docs": extra_docs,
774
1098
  "file_paths_str": file_paths_str,
@@ -842,6 +1166,15 @@ class AgenticEdit:
842
1166
  added_libraries = package_manager.list_added_libraries()
843
1167
 
844
1168
  if added_libraries:
1169
+ # Build libraries with paths information
1170
+ libraries_with_paths = []
1171
+ for lib_name in added_libraries:
1172
+ lib_path = package_manager.get_package_path(lib_name)
1173
+ libraries_with_paths.append({
1174
+ 'name': lib_name,
1175
+ 'path': lib_path if lib_path else 'Path not found'
1176
+ })
1177
+
845
1178
  # Get documentation content for all added libraries
846
1179
  docs_content = package_manager.get_docs(return_paths=False)
847
1180
 
@@ -851,9 +1184,9 @@ class AgenticEdit:
851
1184
 
852
1185
  # Generate library documentation prompt using decorator
853
1186
  library_docs_prompt = self.generate_library_docs_prompt.prompt(
854
- libraries=added_libraries,
1187
+ libraries_with_paths=libraries_with_paths,
855
1188
  docs_content=combined_docs
856
- )
1189
+ )
857
1190
 
858
1191
  conversations.append({
859
1192
  "role": "user",
@@ -11,6 +11,7 @@ from .ask_followup_question_tool_resolver import AskFollowupQuestionToolResolver
11
11
  from .attempt_completion_tool_resolver import AttemptCompletionToolResolver
12
12
  from .plan_mode_respond_tool_resolver import PlanModeRespondToolResolver
13
13
  from .use_mcp_tool_resolver import UseMcpToolResolver
14
+ from .use_rag_tool_resolver import UseRAGToolResolver
14
15
  from .list_package_info_tool_resolver import ListPackageInfoToolResolver
15
16
 
16
17
  __all__ = [
@@ -26,5 +27,6 @@ __all__ = [
26
27
  "AttemptCompletionToolResolver",
27
28
  "PlanModeRespondToolResolver",
28
29
  "UseMcpToolResolver",
30
+ "UseRAGToolResolver",
29
31
  "ListPackageInfoToolResolver",
30
32
  ]
@@ -0,0 +1,91 @@
1
+ from typing import Dict, Any, Optional
2
+ import typing
3
+ import openai
4
+ from autocoder.common import AutoCoderArgs
5
+ from autocoder.common.v2.agent.agentic_edit_tools.base_tool_resolver import BaseToolResolver
6
+ from autocoder.common.v2.agent.agentic_edit_types import UseRAGTool, ToolResult
7
+ from autocoder.common.rag_manager import RAGManager
8
+ from loguru import logger
9
+
10
+ if typing.TYPE_CHECKING:
11
+ from autocoder.common.v2.agent.agentic_edit import AgenticEdit
12
+
13
+
14
+ class UseRAGToolResolver(BaseToolResolver):
15
+ def __init__(self, agent: Optional['AgenticEdit'], tool: UseRAGTool, args: AutoCoderArgs):
16
+ super().__init__(agent, tool, args)
17
+ self.tool: UseRAGTool = tool # For type hinting
18
+ self.rag_manager = RAGManager(args)
19
+
20
+ def resolve(self) -> ToolResult:
21
+ """
22
+ 通过 OpenAI SDK 访问 RAG server 来执行查询。
23
+ """
24
+ server_name = self.tool.server_name
25
+ query = self.tool.query
26
+
27
+ logger.info(f"正在解析 UseRAGTool: Server='{server_name}', Query='{query}'")
28
+
29
+ # 检查是否有可用的 RAG 配置
30
+ if not self.rag_manager.has_configs():
31
+ error_msg = "未找到可用的 RAG 服务器配置,请确保配置文件存在并格式正确"
32
+ logger.error(error_msg)
33
+ return ToolResult(success=False, message=error_msg)
34
+
35
+ try:
36
+ # 查找指定的 RAG 配置
37
+ rag_config = None
38
+ if server_name:
39
+ # 尝试通过名称查找
40
+ rag_config = self.rag_manager.get_config_by_name(server_name)
41
+ # 如果按名称找不到,尝试直接使用 server_name 作为 URL
42
+ if not rag_config:
43
+ # 检查是否是直接的 URL
44
+ if server_name.startswith('http'):
45
+ # 使用提供的 server_name 作为 base_url
46
+ base_url = server_name
47
+ api_key = "dummy-key"
48
+ else:
49
+ error_msg = f"未找到名为 '{server_name}' 的 RAG 服务器配置\n\n{self.rag_manager.get_config_info()}"
50
+ logger.error(error_msg)
51
+ return ToolResult(success=False, message=error_msg)
52
+ else:
53
+ base_url = rag_config.server_name
54
+ api_key = rag_config.api_key or "dummy-key"
55
+ else:
56
+ # 如果没有指定 server_name,使用第一个可用的配置
57
+ rag_config = self.rag_manager.get_all_configs()[0]
58
+ base_url = rag_config.server_name
59
+ api_key = rag_config.api_key or "dummy-key"
60
+ logger.info(f"未指定服务器名称,使用默认配置: {rag_config.name}")
61
+
62
+ logger.info(f"使用 RAG 服务器: {base_url}")
63
+
64
+ # 使用 OpenAI SDK 访问 RAG server
65
+ client = openai.OpenAI(
66
+ base_url=base_url,
67
+ api_key=api_key
68
+ )
69
+
70
+ response = client.chat.completions.create(
71
+ model="default",
72
+ messages=[
73
+ {
74
+ "role": "user",
75
+ "content": query
76
+ }
77
+ ],
78
+ max_tokens=8024
79
+ )
80
+
81
+ result_content = response.choices[0].message.content
82
+ logger.info(f"RAG server 响应成功,内容长度: {len(result_content)}")
83
+
84
+ return ToolResult(success=True, message=result_content)
85
+
86
+ except Exception as e:
87
+ error_msg = f"访问 RAG server 时出错: {str(e)}"
88
+ if not self.rag_manager.has_configs():
89
+ error_msg += f"\n\n{self.rag_manager.get_config_info()}"
90
+ logger.error(error_msg)
91
+ return ToolResult(success=False, message=error_msg)
@@ -56,6 +56,10 @@ class UseMcpTool(BaseTool):
56
56
  tool_name: str
57
57
  query:str
58
58
 
59
+ class UseRAGTool(BaseTool):
60
+ server_name: str
61
+ query: str
62
+
59
63
  class ListPackageInfoTool(BaseTool):
60
64
  path: str # 源码包目录,相对路径或绝对路径
61
65
 
@@ -118,6 +122,7 @@ TOOL_MODEL_MAP: Dict[str, Type[BaseTool]] = {
118
122
  "attempt_completion": AttemptCompletionTool,
119
123
  "plan_mode_respond": PlanModeRespondTool,
120
124
  "use_mcp_tool": UseMcpTool,
125
+ "use_rag_tool": UseRAGTool,
121
126
  "list_package_info": ListPackageInfoTool,
122
127
  }
123
128