auto-coder 0.1.373__py3-none-any.whl → 0.1.375__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.

Files changed (27) hide show
  1. {auto_coder-0.1.373.dist-info → auto_coder-0.1.375.dist-info}/METADATA +2 -2
  2. {auto_coder-0.1.373.dist-info → auto_coder-0.1.375.dist-info}/RECORD +27 -23
  3. autocoder/agent/base_agentic/base_agent.py +193 -44
  4. autocoder/agent/base_agentic/default_tools.py +38 -6
  5. autocoder/agent/base_agentic/tools/list_files_tool_resolver.py +83 -43
  6. autocoder/agent/base_agentic/tools/read_file_tool_resolver.py +88 -25
  7. autocoder/agent/base_agentic/tools/replace_in_file_tool_resolver.py +171 -62
  8. autocoder/agent/base_agentic/tools/search_files_tool_resolver.py +101 -56
  9. autocoder/agent/base_agentic/tools/talk_to_group_tool_resolver.py +5 -0
  10. autocoder/agent/base_agentic/tools/talk_to_tool_resolver.py +5 -0
  11. autocoder/agent/base_agentic/tools/write_to_file_tool_resolver.py +145 -32
  12. autocoder/auto_coder_rag.py +68 -11
  13. autocoder/common/v2/agent/agentic_edit_tools/replace_in_file_tool_resolver.py +47 -141
  14. autocoder/common/v2/agent/agentic_edit_tools/write_to_file_tool_resolver.py +47 -102
  15. autocoder/index/index.py +1 -1
  16. autocoder/linters/linter_factory.py +4 -1
  17. autocoder/linters/normal_linter.py +2 -4
  18. autocoder/linters/python_linter.py +18 -115
  19. autocoder/rag/agentic_rag.py +217 -0
  20. autocoder/rag/tools/__init__.py +10 -0
  21. autocoder/rag/tools/recall_tool.py +162 -0
  22. autocoder/rag/tools/search_tool.py +125 -0
  23. autocoder/version.py +1 -1
  24. {auto_coder-0.1.373.dist-info → auto_coder-0.1.375.dist-info}/LICENSE +0 -0
  25. {auto_coder-0.1.373.dist-info → auto_coder-0.1.375.dist-info}/WHEEL +0 -0
  26. {auto_coder-0.1.373.dist-info → auto_coder-0.1.375.dist-info}/entry_points.txt +0 -0
  27. {auto_coder-0.1.373.dist-info → auto_coder-0.1.375.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,125 @@
1
+ """
2
+ SearchTool 模块
3
+
4
+ 该模块实现了 SearchTool 和 SearchToolResolver 类,用于在 BaseAgent 框架中
5
+ 提供基于 LongContextRAG 的文档搜索功能。
6
+ """
7
+
8
+ import os
9
+ from typing import Dict, Any, List, Optional
10
+
11
+ from loguru import logger
12
+
13
+ from autocoder.agent.base_agentic.types import BaseTool, ToolResult
14
+ from autocoder.agent.base_agentic.tool_registry import ToolRegistry
15
+ from autocoder.agent.base_agentic.tools.base_tool_resolver import BaseToolResolver
16
+ from autocoder.agent.base_agentic.types import ToolDescription, ToolExample
17
+ from autocoder.common import AutoCoderArgs
18
+ from autocoder.rag.long_context_rag import LongContextRAG, RecallStat, ChunkStat, AnswerStat, RAGStat
19
+ from autocoder.rag.relevant_utils import FilterDoc, DocRelevance, DocFilterResult
20
+
21
+
22
+ class SearchTool(BaseTool):
23
+ """搜索工具,用于获取与查询相关的文件列表"""
24
+ query: str # 用户查询
25
+ max_files: Optional[int] = 10 # 最大返回文件数量
26
+
27
+
28
+ class SearchToolResolver(BaseToolResolver):
29
+ """搜索工具解析器,实现搜索逻辑"""
30
+ def __init__(self, agent, tool, args):
31
+ super().__init__(agent, tool, args)
32
+ self.tool: SearchTool = tool
33
+
34
+ def resolve(self) -> ToolResult:
35
+ """实现搜索工具的解析逻辑"""
36
+ try:
37
+ # 获取参数
38
+ query = self.tool.query
39
+ max_files = self.tool.max_files
40
+ rag = self.agent.rag
41
+ # 构建对话历史
42
+ conversations = [
43
+ {"role": "user", "content": query}
44
+ ]
45
+
46
+ # 创建 RAGStat 对象
47
+ rag_stat = RAGStat(
48
+ recall_stat=RecallStat(total_input_tokens=0, total_generated_tokens=0),
49
+ chunk_stat=ChunkStat(total_input_tokens=0, total_generated_tokens=0),
50
+ answer_stat=AnswerStat(total_input_tokens=0, total_generated_tokens=0)
51
+ )
52
+
53
+ # 调用文档检索处理
54
+ generator = rag._process_document_retrieval(conversations, query, rag_stat)
55
+
56
+ # 获取最终结果
57
+ result = None
58
+ for item in generator:
59
+ if isinstance(item, dict) and "result" in item:
60
+ result = item["result"]
61
+
62
+ if not result:
63
+ return ToolResult(
64
+ success=False,
65
+ message="未找到相关文档",
66
+ content=[]
67
+ )
68
+
69
+ # 格式化结果
70
+ file_list = []
71
+ for doc in result:
72
+ file_list.append({
73
+ "path": doc.source_code.module_name,
74
+ "relevance": doc.relevance.relevant_score if doc.relevance else 0,
75
+ "is_relevant": doc.relevance.is_relevant if doc.relevance else False
76
+ })
77
+
78
+ # 按相关性排序
79
+ file_list.sort(key=lambda x: x["relevance"], reverse=True)
80
+
81
+ # 限制返回数量
82
+ file_list = file_list[:max_files]
83
+
84
+ return ToolResult(
85
+ success=True,
86
+ message=f"成功检索到 {len(file_list)} 个相关文件",
87
+ content=file_list
88
+ )
89
+
90
+ except Exception as e:
91
+ import traceback
92
+ return ToolResult(
93
+ success=False,
94
+ message=f"搜索工具执行失败: {str(e)}",
95
+ content=traceback.format_exc()
96
+ )
97
+
98
+
99
+ def register_search_tool():
100
+ """注册搜索工具"""
101
+ # 准备工具描述
102
+ description = ToolDescription(
103
+ description="搜索与查询相关的文件",
104
+ parameters="query: 搜索查询\nmax_files: 最大返回文件数量(可选,默认为10)",
105
+ usage="用于根据查询找到相关的代码文件"
106
+ )
107
+
108
+ # 准备工具示例
109
+ example = ToolExample(
110
+ title="搜索工具使用示例",
111
+ body="""<search>
112
+ <query>如何实现文件监控功能</query>
113
+ <max_files>5</max_files>
114
+ </search>"""
115
+ )
116
+
117
+ # 注册工具
118
+ ToolRegistry.register_tool(
119
+ tool_tag="search", # XML标签名
120
+ tool_cls=SearchTool, # 工具类
121
+ resolver_cls=SearchToolResolver, # 解析器类
122
+ description=description, # 工具描述
123
+ example=example, # 工具示例
124
+ use_guideline="此工具用于根据用户查询搜索相关代码文件,返回文件路径及其相关性分数。适用于需要快速找到与特定功能或概念相关的代码文件的场景。" # 使用指南
125
+ )
autocoder/version.py CHANGED
@@ -1,2 +1,2 @@
1
1
 
2
- __version__ = "0.1.373"
2
+ __version__ = "0.1.375"