jarvis-ai-assistant 0.1.96__tar.gz → 0.1.97__tar.gz

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 jarvis-ai-assistant might be problematic. Click here for more details.

Files changed (56) hide show
  1. {jarvis_ai_assistant-0.1.96/src/jarvis_ai_assistant.egg-info → jarvis_ai_assistant-0.1.97}/PKG-INFO +1 -1
  2. {jarvis_ai_assistant-0.1.96 → jarvis_ai_assistant-0.1.97}/pyproject.toml +1 -1
  3. {jarvis_ai_assistant-0.1.96 → jarvis_ai_assistant-0.1.97}/setup.py +1 -1
  4. {jarvis_ai_assistant-0.1.96 → jarvis_ai_assistant-0.1.97}/src/jarvis/__init__.py +1 -1
  5. {jarvis_ai_assistant-0.1.96 → jarvis_ai_assistant-0.1.97}/src/jarvis/agent.py +138 -144
  6. {jarvis_ai_assistant-0.1.96 → jarvis_ai_assistant-0.1.97}/src/jarvis/jarvis_codebase/main.py +87 -54
  7. {jarvis_ai_assistant-0.1.96 → jarvis_ai_assistant-0.1.97}/src/jarvis/jarvis_coder/git_utils.py +4 -7
  8. {jarvis_ai_assistant-0.1.96 → jarvis_ai_assistant-0.1.97}/src/jarvis/jarvis_coder/main.py +17 -22
  9. jarvis_ai_assistant-0.1.97/src/jarvis/jarvis_coder/patch_handler.py +192 -0
  10. jarvis_ai_assistant-0.1.97/src/jarvis/jarvis_coder/plan_generator.py +103 -0
  11. {jarvis_ai_assistant-0.1.96 → jarvis_ai_assistant-0.1.97}/src/jarvis/jarvis_platform/main.py +1 -1
  12. {jarvis_ai_assistant-0.1.96 → jarvis_ai_assistant-0.1.97}/src/jarvis/jarvis_rag/main.py +1 -1
  13. {jarvis_ai_assistant-0.1.96 → jarvis_ai_assistant-0.1.97}/src/jarvis/jarvis_smart_shell/main.py +15 -15
  14. {jarvis_ai_assistant-0.1.96 → jarvis_ai_assistant-0.1.97}/src/jarvis/main.py +24 -24
  15. {jarvis_ai_assistant-0.1.96 → jarvis_ai_assistant-0.1.97}/src/jarvis/models/ai8.py +22 -22
  16. {jarvis_ai_assistant-0.1.96 → jarvis_ai_assistant-0.1.97}/src/jarvis/models/base.py +17 -13
  17. {jarvis_ai_assistant-0.1.96 → jarvis_ai_assistant-0.1.97}/src/jarvis/models/kimi.py +31 -31
  18. {jarvis_ai_assistant-0.1.96 → jarvis_ai_assistant-0.1.97}/src/jarvis/models/ollama.py +28 -28
  19. {jarvis_ai_assistant-0.1.96 → jarvis_ai_assistant-0.1.97}/src/jarvis/models/openai.py +22 -24
  20. {jarvis_ai_assistant-0.1.96 → jarvis_ai_assistant-0.1.97}/src/jarvis/models/oyi.py +25 -25
  21. {jarvis_ai_assistant-0.1.96 → jarvis_ai_assistant-0.1.97}/src/jarvis/models/registry.py +33 -34
  22. {jarvis_ai_assistant-0.1.96 → jarvis_ai_assistant-0.1.97}/src/jarvis/tools/ask_user.py +5 -5
  23. {jarvis_ai_assistant-0.1.96 → jarvis_ai_assistant-0.1.97}/src/jarvis/tools/base.py +2 -2
  24. {jarvis_ai_assistant-0.1.96 → jarvis_ai_assistant-0.1.97}/src/jarvis/tools/chdir.py +9 -9
  25. {jarvis_ai_assistant-0.1.96 → jarvis_ai_assistant-0.1.97}/src/jarvis/tools/codebase_qa.py +4 -4
  26. {jarvis_ai_assistant-0.1.96 → jarvis_ai_assistant-0.1.97}/src/jarvis/tools/coder.py +4 -4
  27. {jarvis_ai_assistant-0.1.96 → jarvis_ai_assistant-0.1.97}/src/jarvis/tools/file_ops.py +1 -1
  28. {jarvis_ai_assistant-0.1.96 → jarvis_ai_assistant-0.1.97}/src/jarvis/tools/generator.py +23 -23
  29. {jarvis_ai_assistant-0.1.96 → jarvis_ai_assistant-0.1.97}/src/jarvis/tools/methodology.py +4 -4
  30. {jarvis_ai_assistant-0.1.96 → jarvis_ai_assistant-0.1.97}/src/jarvis/tools/rag.py +4 -4
  31. {jarvis_ai_assistant-0.1.96 → jarvis_ai_assistant-0.1.97}/src/jarvis/tools/registry.py +38 -38
  32. {jarvis_ai_assistant-0.1.96 → jarvis_ai_assistant-0.1.97}/src/jarvis/tools/search.py +42 -42
  33. {jarvis_ai_assistant-0.1.96 → jarvis_ai_assistant-0.1.97}/src/jarvis/tools/shell.py +13 -13
  34. {jarvis_ai_assistant-0.1.96 → jarvis_ai_assistant-0.1.97}/src/jarvis/tools/sub_agent.py +16 -16
  35. {jarvis_ai_assistant-0.1.96 → jarvis_ai_assistant-0.1.97}/src/jarvis/tools/thinker.py +41 -41
  36. {jarvis_ai_assistant-0.1.96 → jarvis_ai_assistant-0.1.97}/src/jarvis/tools/webpage.py +17 -17
  37. {jarvis_ai_assistant-0.1.96 → jarvis_ai_assistant-0.1.97}/src/jarvis/utils.py +59 -60
  38. {jarvis_ai_assistant-0.1.96 → jarvis_ai_assistant-0.1.97/src/jarvis_ai_assistant.egg-info}/PKG-INFO +1 -1
  39. jarvis_ai_assistant-0.1.96/src/jarvis/jarvis_coder/patch_handler.py +0 -492
  40. jarvis_ai_assistant-0.1.96/src/jarvis/jarvis_coder/plan_generator.py +0 -75
  41. {jarvis_ai_assistant-0.1.96 → jarvis_ai_assistant-0.1.97}/LICENSE +0 -0
  42. {jarvis_ai_assistant-0.1.96 → jarvis_ai_assistant-0.1.97}/MANIFEST.in +0 -0
  43. {jarvis_ai_assistant-0.1.96 → jarvis_ai_assistant-0.1.97}/README.md +0 -0
  44. {jarvis_ai_assistant-0.1.96 → jarvis_ai_assistant-0.1.97}/setup.cfg +0 -0
  45. {jarvis_ai_assistant-0.1.96 → jarvis_ai_assistant-0.1.97}/src/jarvis/jarvis_codebase/__init__.py +0 -0
  46. {jarvis_ai_assistant-0.1.96 → jarvis_ai_assistant-0.1.97}/src/jarvis/jarvis_coder/__init__.py +0 -0
  47. {jarvis_ai_assistant-0.1.96 → jarvis_ai_assistant-0.1.97}/src/jarvis/jarvis_platform/__init__.py +0 -0
  48. {jarvis_ai_assistant-0.1.96 → jarvis_ai_assistant-0.1.97}/src/jarvis/jarvis_rag/__init__.py +0 -0
  49. {jarvis_ai_assistant-0.1.96 → jarvis_ai_assistant-0.1.97}/src/jarvis/jarvis_smart_shell/__init__.py +0 -0
  50. {jarvis_ai_assistant-0.1.96 → jarvis_ai_assistant-0.1.97}/src/jarvis/models/__init__.py +0 -0
  51. {jarvis_ai_assistant-0.1.96 → jarvis_ai_assistant-0.1.97}/src/jarvis/tools/__init__.py +0 -0
  52. {jarvis_ai_assistant-0.1.96 → jarvis_ai_assistant-0.1.97}/src/jarvis_ai_assistant.egg-info/SOURCES.txt +0 -0
  53. {jarvis_ai_assistant-0.1.96 → jarvis_ai_assistant-0.1.97}/src/jarvis_ai_assistant.egg-info/dependency_links.txt +0 -0
  54. {jarvis_ai_assistant-0.1.96 → jarvis_ai_assistant-0.1.97}/src/jarvis_ai_assistant.egg-info/entry_points.txt +0 -0
  55. {jarvis_ai_assistant-0.1.96 → jarvis_ai_assistant-0.1.97}/src/jarvis_ai_assistant.egg-info/requires.txt +0 -0
  56. {jarvis_ai_assistant-0.1.96 → jarvis_ai_assistant-0.1.97}/src/jarvis_ai_assistant.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: jarvis-ai-assistant
3
- Version: 0.1.96
3
+ Version: 0.1.97
4
4
  Summary: Jarvis: An AI assistant that uses tools to interact with the system
5
5
  Home-page: https://github.com/skyfireitdiy/Jarvis
6
6
  Author: skyfire
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "jarvis-ai-assistant"
7
- version = "0.1.96"
7
+ version = "0.1.97"
8
8
  description = "Jarvis: An AI assistant that uses tools to interact with the system"
9
9
  readme = "README.md"
10
10
  authors = [{ name = "Your Name", email = "your.email@example.com" }]
@@ -2,7 +2,7 @@ from setuptools import setup, find_packages
2
2
 
3
3
  setup(
4
4
  name="jarvis-ai-assistant",
5
- version="0.1.96",
5
+ version="0.1.97",
6
6
  author="skyfire",
7
7
  author_email="skyfireitdiy@hotmail.com",
8
8
  description="An AI assistant that uses various tools to interact with the system",
@@ -1,3 +1,3 @@
1
1
  """Jarvis AI Assistant"""
2
2
 
3
- __version__ = "0.1.96"
3
+ __version__ = "0.1.97"
@@ -4,73 +4,69 @@ from typing import Dict, List, Optional
4
4
  import yaml
5
5
  import numpy as np
6
6
  import faiss
7
- import json
8
7
 
9
8
  from .models.registry import PlatformRegistry
10
9
  from .tools import ToolRegistry
11
- from .utils import PrettyOutput, OutputType, get_max_context_length, get_multiline_input, load_embedding_model, while_success
10
+ from .utils import PrettyOutput, OutputType, get_max_context_length, get_multiline_input, load_embedding_model
12
11
  import os
13
- from datetime import datetime
14
- from prompt_toolkit import prompt
15
- from sentence_transformers import SentenceTransformer
16
12
 
17
13
  class Agent:
18
14
  def __init__(self, name: str = "Jarvis", is_sub_agent: bool = False):
19
15
  """Initialize Agent with a model, optional tool registry and name
20
16
 
21
17
  Args:
22
- model: 语言模型实例
23
- tool_registry: 工具注册表实例
24
- name: Agent名称,默认为"Jarvis"
25
- is_sub_agent: 是否为子Agent,默认为False
18
+ model: LLM model instance
19
+ tool_registry: Tool registry instance
20
+ name: Agent name, default is "Jarvis"
21
+ is_sub_agent: Whether it is a sub-agent, default is False
26
22
  """
27
23
  self.model = PlatformRegistry.get_global_platform_registry().get_normal_platform()
28
24
  self.tool_registry = ToolRegistry.get_global_tool_registry()
29
25
  self.name = name
30
26
  self.is_sub_agent = is_sub_agent
31
27
  self.prompt = ""
32
- self.conversation_length = 0 # 改用长度计数器
28
+ self.conversation_length = 0 # Use length counter instead
33
29
 
34
- # 从环境变量加载配置
30
+ # Load configuration from environment variables
35
31
  self.embedding_dimension = 1536 # Default for many embedding models
36
32
  self.max_context_length = get_max_context_length()
37
33
 
38
- # 初始化嵌入模型
34
+ # Initialize embedding model
39
35
  try:
40
36
  self.embedding_model = load_embedding_model()
41
37
 
42
- # 预热模型并获取正确的维度
43
- test_text = "这是一段测试文本,用于确保模型完全加载。"
38
+ # Warm up model and get correct dimension
39
+ test_text = "This is a test text to ensure the model is fully loaded."
44
40
  test_embedding = self.embedding_model.encode(
45
41
  test_text,
46
42
  convert_to_tensor=True,
47
43
  normalize_embeddings=True
48
44
  )
49
45
  self.embedding_dimension = len(test_embedding)
50
- PrettyOutput.print("嵌入模型加载完成", OutputType.SUCCESS)
46
+ PrettyOutput.print("Successfully loaded embedding model", OutputType.SUCCESS)
51
47
 
52
- # 初始化HNSW索引(使用正确的维度)
48
+ # Initialize HNSW index (use correct dimension)
53
49
  hnsw_index = faiss.IndexHNSWFlat(self.embedding_dimension, 16)
54
50
  hnsw_index.hnsw.efConstruction = 40
55
51
  hnsw_index.hnsw.efSearch = 16
56
52
  self.methodology_index = faiss.IndexIDMap(hnsw_index)
57
53
 
58
54
  except Exception as e:
59
- PrettyOutput.print(f"加载嵌入模型失败: {str(e)}", OutputType.ERROR)
55
+ PrettyOutput.print(f"Failed to load embedding model: {str(e)}", OutputType.ERROR)
60
56
  raise
61
57
 
62
- # 初始化方法论相关属性
58
+ # Initialize methodology related attributes
63
59
  self.methodology_data = []
64
60
 
65
61
  @staticmethod
66
62
  def extract_tool_calls(content: str) -> List[Dict]:
67
- """从内容中提取工具调用,如果检测到多个工具调用则抛出异常,并返回工具调用之前的内容和工具调用"""
68
- # 分割内容为行
63
+ """Extract tool calls from content, if multiple tool calls are detected, raise an exception, and return the content before the tool call and the tool call"""
64
+ # Split content into lines
69
65
  lines = content.split('\n')
70
66
  tool_call_lines = []
71
67
  in_tool_call = False
72
68
 
73
- # 逐行处理
69
+ # Process line by line
74
70
  for line in lines:
75
71
  if '<TOOL_CALL>' in line:
76
72
  in_tool_call = True
@@ -78,26 +74,26 @@ class Agent:
78
74
  elif '</TOOL_CALL>' in line:
79
75
  if in_tool_call and tool_call_lines:
80
76
  try:
81
- # 直接解析YAML
77
+ # Parse YAML directly
82
78
  tool_call_text = '\n'.join(tool_call_lines)
83
79
  tool_call_data = yaml.safe_load(tool_call_text)
84
80
 
85
- # 验证必要的字段
81
+ # Validate necessary fields
86
82
  if "name" in tool_call_data and "arguments" in tool_call_data:
87
- # 返回工具调用之前的内容和工具调用
83
+ # Return content before tool call and tool call
88
84
  return [{
89
85
  "name": tool_call_data["name"],
90
86
  "arguments": tool_call_data["arguments"]
91
87
  }]
92
88
  else:
93
- PrettyOutput.print("工具调用缺少必要字段", OutputType.ERROR)
94
- raise Exception("工具调用缺少必要字段")
89
+ PrettyOutput.print("Tool call missing necessary fields", OutputType.ERROR)
90
+ raise Exception("Tool call missing necessary fields")
95
91
  except yaml.YAMLError as e:
96
- PrettyOutput.print(f"YAML解析错误: {str(e)}", OutputType.ERROR)
97
- raise Exception(f"YAML解析错误: {str(e)}")
92
+ PrettyOutput.print(f"YAML parsing error: {str(e)}", OutputType.ERROR)
93
+ raise Exception(f"YAML parsing error: {str(e)}")
98
94
  except Exception as e:
99
- PrettyOutput.print(f"处理工具调用时发生错误: {str(e)}", OutputType.ERROR)
100
- raise Exception(f"处理工具调用时发生错误: {str(e)}")
95
+ PrettyOutput.print(f"Error processing tool call: {str(e)}", OutputType.ERROR)
96
+ raise Exception(f"Error processing tool call: {str(e)}")
101
97
  in_tool_call = False
102
98
  continue
103
99
 
@@ -107,14 +103,14 @@ class Agent:
107
103
  return []
108
104
 
109
105
  def _call_model(self, message: str) -> str:
110
- """调用模型获取响应"""
106
+ """Call model to get response"""
111
107
  sleep_time = 5
112
108
  while True:
113
- ret = while_success(lambda: self.model.chat(message), sleep_time=5)
109
+ ret = self.model.chat_until_success(message)
114
110
  if ret:
115
111
  return ret
116
112
  else:
117
- PrettyOutput.print(f"调用模型失败,重试中... 等待 {sleep_time}s", OutputType.INFO)
113
+ PrettyOutput.print(f"Model call failed, retrying... waiting {sleep_time}s", OutputType.INFO)
118
114
  time.sleep(sleep_time)
119
115
  sleep_time *= 2
120
116
  if sleep_time > 30:
@@ -122,9 +118,9 @@ class Agent:
122
118
  continue
123
119
 
124
120
  def _create_methodology_embedding(self, methodology_text: str) -> np.ndarray:
125
- """为方法论文本创建嵌入向量"""
121
+ """Create embedding vector for methodology text"""
126
122
  try:
127
- # 对长文本进行截断
123
+ # Truncate long text
128
124
  max_length = 512
129
125
  text = ' '.join(methodology_text.split()[:max_length])
130
126
 
@@ -133,14 +129,14 @@ class Agent:
133
129
  convert_to_tensor=True,
134
130
  normalize_embeddings=True)
135
131
  vector = np.array(embedding.cpu().numpy(), dtype=np.float32)
136
- return vector[0] # 返回第一个向量,因为我们只编码了一个文本
132
+ return vector[0] # Return first vector, because we only encoded one text
137
133
  except Exception as e:
138
- PrettyOutput.print(f"创建方法论嵌入向量失败: {str(e)}", OutputType.ERROR)
134
+ PrettyOutput.print(f"Failed to create methodology embedding vector: {str(e)}", OutputType.ERROR)
139
135
  return np.zeros(self.embedding_dimension, dtype=np.float32)
140
136
 
141
137
  def _load_methodology(self, user_input: str) -> Dict[str, str]:
142
- """加载方法论并构建向量索引"""
143
- PrettyOutput.print("加载方法论...", OutputType.PROGRESS)
138
+ """Load methodology and build vector index"""
139
+ PrettyOutput.print("Loading methodology...", OutputType.PROGRESS)
144
140
  user_jarvis_methodology = os.path.expanduser("~/.jarvis_methodology")
145
141
  if not os.path.exists(user_jarvis_methodology):
146
142
  return {}
@@ -149,14 +145,14 @@ class Agent:
149
145
  with open(user_jarvis_methodology, "r", encoding="utf-8") as f:
150
146
  data = yaml.safe_load(f)
151
147
 
152
- # 重置数据结构
148
+ # Reset data structure
153
149
  self.methodology_data = []
154
150
  vectors = []
155
151
  ids = []
156
152
 
157
- # 为每个方法论创建嵌入向量
153
+ # Create embedding vector for each methodology
158
154
  for i, (key, value) in enumerate(data.items()):
159
- PrettyOutput.print(f"向量化方法论: {key} ...", OutputType.INFO)
155
+ PrettyOutput.print(f"Vectorizing methodology: {key} ...", OutputType.INFO)
160
156
  methodology_text = f"{key}\n{value}"
161
157
  embedding = self._create_methodology_embedding(methodology_text)
162
158
  vectors.append(embedding)
@@ -168,7 +164,7 @@ class Agent:
168
164
  self.methodology_index.add_with_ids(vectors_array, np.array(ids)) # type: ignore
169
165
  query_embedding = self._create_methodology_embedding(user_input)
170
166
  k = min(5, len(self.methodology_data))
171
- PrettyOutput.print(f"检索方法论...", OutputType.INFO)
167
+ PrettyOutput.print(f"Retrieving methodology...", OutputType.INFO)
172
168
  distances, indices = self.methodology_index.search(
173
169
  query_embedding.reshape(1, -1), k
174
170
  ) # type: ignore
@@ -179,7 +175,7 @@ class Agent:
179
175
  similarity = 1.0 / (1.0 + float(dist))
180
176
  methodology = self.methodology_data[idx]
181
177
  PrettyOutput.print(
182
- f"方法论 '{methodology['key']}' 相似度: {similarity:.3f}",
178
+ f"Methodology '{methodology['key']}' similarity: {similarity:.3f}",
183
179
  OutputType.INFO
184
180
  )
185
181
  if similarity >= 0.5:
@@ -191,77 +187,77 @@ class Agent:
191
187
  return {}
192
188
 
193
189
  except Exception as e:
194
- PrettyOutput.print(f"加载方法论时发生错误: {str(e)}", OutputType.ERROR)
190
+ PrettyOutput.print(f"Error loading methodology: {str(e)}", OutputType.ERROR)
195
191
  return {}
196
192
 
197
193
  def _summarize_and_clear_history(self) -> None:
198
194
  """
199
- [系统消息]
200
- 总结当前对话历史并清空历史记录,只保留系统消息和总结
195
+ [System message]
196
+ Summarize current conversation history and clear history, only keep system message and summary
201
197
 
202
- 这个方法会:
203
- 1. 请求模型总结当前对话的关键信息
204
- 2. 清空对话历史
205
- 3. 保留系统消息
206
- 4. 添加总结作为新的上下文
207
- 5. 重置对话轮数
198
+ This method will:
199
+ 1. Request the model to summarize the key information from the current conversation
200
+ 2. Clear the conversation history
201
+ 3. Keep the system message
202
+ 4. Add the summary as new context
203
+ 5. Reset the conversation round
208
204
  """
209
- # 创建一个新的模型实例来做总结,避免影响主对话
205
+ # Create a new model instance to summarize, avoid affecting the main conversation
210
206
 
211
- PrettyOutput.print("总结对话历史,准备生成总结,开始新的对话...", OutputType.PROGRESS)
207
+ PrettyOutput.print("Summarizing conversation history, preparing to generate summary, starting new conversation...", OutputType.PROGRESS)
212
208
 
213
- prompt = """请总结之前对话中的关键信息,包括:
214
- 1. 当前任务目标
215
- 2. 已经确认的关键信息
216
- 3. 已经尝试过的方案
217
- 4. 当前进展
218
- 5. 待解决的问题
219
-
220
- 请用简洁的要点形式描述,突出重要信息。不要包含对话细节。
209
+ prompt = """Please summarize the key information from the previous conversation, including:
210
+ 1. Current task objective
211
+ 2. Confirmed key information
212
+ 3. Solutions that have been tried
213
+ 4. Current progress
214
+ 5. Pending issues
215
+
216
+ Please describe in concise bullet points, highlighting important information. Do not include conversation details.
221
217
  """
222
218
 
223
219
  try:
224
- summary = self.model.chat(self.prompt + "\n" + prompt)
220
+ summary = self.model.chat_until_success(self.prompt + "\n" + prompt)
225
221
 
226
222
  # 清空当前对话历史,但保留系统消息
227
- self.conversation_length = 0 # 重置对话长度
223
+ self.conversation_length = 0 # Reset conversation length
228
224
 
229
225
  # 添加总结作为新的上下文
230
- self.prompt = f"""以下是之前对话的关键信息总结:
226
+ self.prompt = f"""Here is a summary of key information from previous conversations:
231
227
 
232
228
  {summary}
233
229
 
234
- 请基于以上信息继续完成任务。
230
+ Please continue the task based on the above information.
235
231
  """
236
232
  self.conversation_length = len(self.prompt) # 设置新的起始长度
237
233
 
238
234
  except Exception as e:
239
- PrettyOutput.print(f"总结对话历史失败: {str(e)}", OutputType.ERROR)
235
+ PrettyOutput.print(f"Failed to summarize conversation history: {str(e)}", OutputType.ERROR)
240
236
 
241
237
  def _complete_task(self) -> str:
242
- """完成任务并生成总结
238
+ """Complete task and generate summary
243
239
 
244
240
  Returns:
245
- str: 任务总结或完成状态
241
+ str: Task summary or completion status
246
242
  """
247
- PrettyOutput.section("任务完成", OutputType.SUCCESS)
243
+ PrettyOutput.section("Task completed", OutputType.SUCCESS)
248
244
 
249
245
  # 询问是否生成方法论,带输入验证
250
246
  while True:
251
- user_input = input("是否要为此任务生成方法论?(y/n): ").strip().lower()
247
+ user_input = input("Generate methodology for this task? (y/n): ").strip().lower()
252
248
  if user_input in ['y', 'n', '']:
253
249
  break
254
- PrettyOutput.print("无效输入,请输入 y n", OutputType.WARNING)
250
+ PrettyOutput.print("Invalid input, please enter y or n", OutputType.WARNING)
255
251
 
256
252
  if user_input == 'y':
257
253
  try:
258
254
  # 让模型判断是否需要生成方法论
259
- analysis_prompt = """本次任务已结束,请分析是否需要生成方法论。
260
- 如果认为需要生成方法论,请先判断是创建新的方法论还是更新已有方法论。如果是更新已有方法论,使用update,否则使用add
261
- 如果认为不需要生成方法论,请说明原因。
262
- 方法论应该适应普遍场景,不要出现本次任务特定的信息,如代码的commit信息等。
263
- 方法论中应该包含:问题重述、最优解决方案、注意事项(按需),除此外不要出现任何其他的信息。
264
- 仅输出方法论工具的调用指令,或者是不需要生成方法论的说明,除此之外不要输出任何内容。
255
+ analysis_prompt = """The current task has ended, please analyze whether a methodology needs to be generated.
256
+ If you think a methodology should be generated, first determine whether to create a new methodology or update an existing one. If updating an existing methodology, use 'update', otherwise use 'add'.
257
+ If you think a methodology is not needed, please explain why.
258
+ The methodology should be applicable to general scenarios, do not include task-specific information such as code commit messages.
259
+ The methodology should include: problem restatement, optimal solution, notes (as needed), and nothing else.
260
+ Only output the methodology tool call instruction, or the explanation for not generating a methodology. Do not output anything else.
265
261
  """
266
262
  self.prompt = analysis_prompt
267
263
  response = self._call_model(self.prompt)
@@ -270,91 +266,90 @@ class Agent:
270
266
  try:
271
267
  tool_calls = Agent.extract_tool_calls(response)
272
268
  if tool_calls:
273
- result = self.tool_registry.handle_tool_calls(tool_calls)
274
- PrettyOutput.print(result, OutputType.RESULT)
269
+ self.tool_registry.handle_tool_calls(tool_calls)
275
270
  except Exception as e:
276
- PrettyOutput.print(f"处理方法论生成失败: {str(e)}", OutputType.ERROR)
271
+ PrettyOutput.print(f"Failed to handle methodology generation: {str(e)}", OutputType.ERROR)
277
272
 
278
273
  except Exception as e:
279
- PrettyOutput.print(f"生成方法论时发生错误: {str(e)}", OutputType.ERROR)
274
+ PrettyOutput.print(f"Error generating methodology: {str(e)}", OutputType.ERROR)
280
275
 
281
276
  if not self.is_sub_agent:
282
277
  return "Task completed"
283
278
 
284
279
  # 生成任务总结
285
- summary_prompt = f"""请对以上任务执行情况生成一个简洁的总结报告,包括:
280
+ summary_prompt = f"""Please generate a concise summary report of the task execution, including:
286
281
 
287
- 1. 任务目标: 任务重述
288
- 2. 执行结果: 成功/失败
289
- 3. 关键信息: 提取执行过程中的重要信息
290
- 4. 重要发现: 任何值得注意的发现
291
- 5. 后续建议: 如果有的话
282
+ 1. Task Objective: Task restatement
283
+ 2. Execution Result: Success/Failure
284
+ 3. Key Information: Important information extracted during execution
285
+ 4. Important Findings: Any noteworthy discoveries
286
+ 5. Follow-up Suggestions: If any
292
287
 
293
- 请用简洁的要点形式描述,突出重要信息。
288
+ Please describe in concise bullet points, highlighting important information.
294
289
  """
295
290
  self.prompt = summary_prompt
296
291
  return self._call_model(self.prompt)
297
292
 
298
293
 
299
294
  def run(self, user_input: str, file_list: Optional[List[str]] = None) -> str:
300
- """处理用户输入并返回响应,返回任务总结报告
295
+ """Process user input and return response, return task summary report
301
296
 
302
297
  Args:
303
- user_input: 用户输入的任务描述
304
- file_list: 可选的文件列表,默认为None
298
+ user_input: User input task description
299
+ file_list: Optional file list, default is None
305
300
 
306
301
  Returns:
307
- str: 任务总结报告
302
+ str: Task summary report
308
303
  """
309
304
  try:
310
- PrettyOutput.section("准备环境", OutputType.PLANNING)
305
+ PrettyOutput.section("Preparing environment", OutputType.PLANNING)
311
306
  if file_list:
312
307
  self.model.upload_files(file_list)
313
308
 
314
- # 加载方法论
309
+ # Load methodology
315
310
  methodology = self._load_methodology(user_input)
316
311
  methodology_prompt = ""
317
312
  if methodology:
318
- methodology_prompt = f"""这是以往处理问题的标准方法论,如果当前任务与此类似,可参考:
313
+ methodology_prompt = f"""This is the standard methodology for handling previous problems, if the current task is similar, you can refer to it:
319
314
  {methodology}
320
315
 
321
316
  """
322
317
  tools_prompt = ""
323
318
 
324
319
  # 选择工具
325
- PrettyOutput.section("可用工具", OutputType.PLANNING)
320
+ PrettyOutput.section("Available tools", OutputType.PLANNING)
326
321
  tools = self.tool_registry.get_all_tools()
327
322
  if tools:
328
- tools_prompt += "可用工具:\n"
323
+ tools_prompt += "Available tools:\n"
329
324
  for tool in tools:
330
325
  PrettyOutput.print(f"{tool['name']}: {tool['description']}", OutputType.INFO)
331
- tools_prompt += f"- 名称: {tool['name']}\n"
332
- tools_prompt += f" 描述: {tool['description']}\n"
333
- tools_prompt += f" 参数: {tool['parameters']}\n"
326
+ tools_prompt += f"- Name: {tool['name']}\n"
327
+ tools_prompt += f" Description: {tool['description']}\n"
328
+ tools_prompt += f" Parameters: {tool['parameters']}\n"
334
329
 
335
330
  # 显示任务开始
336
- PrettyOutput.section(f"开始新任务: {self.name}", OutputType.PLANNING)
331
+ PrettyOutput.section(f"Starting new task: {self.name}", OutputType.PLANNING)
337
332
 
338
333
  self.clear_history()
339
334
 
340
- self.model.set_system_message(f"""你是 {self.name},一个问题处理能力强大的 AI 助手。
341
-
342
- 如果用户需要执行任务,你会严格按照以下步骤处理问题:
343
- 1. 问题重述:确认理解问题
344
- 2. 根因分析(如果是问题分析类需要,其他不需要)
345
- 3. 设定目标:需要可达成,可检验的一个或多个目标
346
- 4. 生成解决方案:生成一个或者多个具备可操作性的解决方案
347
- 5. 评估解决方案:从众多解决方案中选择一种最优的方案
348
- 6. 制定行动计划:根据目前可以使用的工具制定行动计划,使用 PlantUML 格式输出明确的执行流程
349
- 7. 执行行动计划:每步执行一个步骤,**最多使用一个工具**(工具执行完成后,等待工具结果再执行下一步)
350
- 8. 监控与调整:如果执行结果与预期不符,则反思并调整行动计划,迭代之前的步骤
351
- 9. 方法论:如果当前任务具有通用性且执行过程中遇到了值得记录的经验,使用方法论工具记录方法论,以提升后期处理类似问题的能力
352
- 10. 任务结束:如果任务已经完成,使用任务结束指令结束任务
353
-
354
- 方法论模板:
355
- 1. 问题重述
356
- 2. 最优解决方案
357
- 3. 最优方案执行步骤(失败的行动不需要体现)
335
+ self.model.set_system_message(f"""You are {self.name}, an AI assistant with powerful problem-solving capabilities.
336
+
337
+ When users need to execute tasks, you will strictly follow these steps to handle problems:
338
+ 1. Problem Restatement: Confirm understanding of the problem
339
+ 2. Root Cause Analysis (only if needed for problem analysis tasks)
340
+ 3. Set Objectives: Define achievable and verifiable goals
341
+ 4. Generate Solutions: Create one or more actionable solutions
342
+ 5. Evaluate Solutions: Select the optimal solution from multiple options
343
+ 6. Create Action Plan: Based on available tools, create an action plan using PlantUML format for clear execution flow
344
+ 7. Execute Action Plan: Execute one step at a time, **use at most one tool** (wait for tool execution results before proceeding)
345
+ 8. Monitor and Adjust: If execution results don't match expectations, reflect and adjust the action plan, iterate previous steps
346
+ 9. Methodology: If the current task has general applicability and valuable experience is gained, use methodology tools to record it for future similar problems
347
+ 10. Task Completion: End the task using task completion command when finished
348
+
349
+ Methodology Template:
350
+ 1. Problem Restatement
351
+ 2. Optimal Solution
352
+ 3. Optimal Solution Steps (exclude failed actions)
358
353
 
359
354
  -------------------------------------------------------------
360
355
 
@@ -362,7 +357,7 @@ class Agent:
362
357
 
363
358
  -------------------------------------------------------------
364
359
 
365
- 工具使用格式:
360
+ Tool Usage Format:
366
361
 
367
362
  <TOOL_CALL>
368
363
  name: tool_name
@@ -373,17 +368,18 @@ arguments:
373
368
 
374
369
  -------------------------------------------------------------
375
370
 
376
- 严格规则:
377
- 1. 每次只能执行一个工具
378
- 2. 等待用户提供执行结果
379
- 3. 不要假设或想象结果
380
- 4. 不要创建虚假对话
381
- 5. 如果现有信息不足以解决问题,则可以询问用户
382
- 6. 处理问题的每个步骤不是必须有的,可按情况省略
383
- 7. 在执行一些可能对系统或者用户代码库造成破坏的工具时,请先询问用户
384
- 8. 在多次迭代却没有任何进展时,可请求用户指导
385
- 9. 如果返回的yaml字符串中包含冒号,请将整个字符串用引号包裹,避免yaml解析错误
386
- 10. yaml中包含多行字符串时,请使用 | 语法
371
+ Strict Rules:
372
+ - Execute only one tool at a time
373
+ - Tool execution must strictly follow the tool usage format
374
+ - Wait for user to provide execution results
375
+ - Don't assume or imagine results
376
+ - Don't create fake dialogues
377
+ - If current information is insufficient, you may ask the user
378
+ - Not all problem-solving steps are mandatory, skip as appropriate
379
+ - Ask user before executing tools that might damage system or user's codebase
380
+ - Request user guidance when multiple iterations show no progress
381
+ - If yaml string contains colons, wrap the entire string in quotes to avoid yaml parsing errors
382
+ - Use | syntax for multi-line strings in yaml
387
383
 
388
384
  {methodology_prompt}
389
385
 
@@ -395,7 +391,7 @@ arguments:
395
391
  while True:
396
392
  try:
397
393
  # 显示思考状态
398
- PrettyOutput.print("分析任务...", OutputType.PROGRESS)
394
+ PrettyOutput.print("Analyzing task...", OutputType.PROGRESS)
399
395
 
400
396
  # 累加对话长度
401
397
  self.conversation_length += len(self.prompt)
@@ -406,26 +402,24 @@ arguments:
406
402
  continue
407
403
  else:
408
404
  current_response = self._call_model(self.prompt)
409
- self.conversation_length += len(current_response) # 添加响应长度
405
+ self.conversation_length += len(current_response) # Add response length
410
406
  try:
411
407
  result = Agent.extract_tool_calls(current_response)
412
408
  except Exception as e:
413
- PrettyOutput.print(f"工具调用错误: {str(e)}", OutputType.ERROR)
414
- self.prompt = f"工具调用错误: {str(e)}"
409
+ PrettyOutput.print(f"Tool call error: {str(e)}", OutputType.ERROR)
410
+ self.prompt = f"Tool call error: {str(e)}"
415
411
  continue
416
412
 
417
413
  if len(result) > 0:
418
- PrettyOutput.print("执行工具调用...", OutputType.PROGRESS)
414
+ PrettyOutput.print("Executing tool call...", OutputType.PROGRESS)
419
415
  tool_result = self.tool_registry.handle_tool_calls(result)
420
- PrettyOutput.print(tool_result, OutputType.RESULT)
421
-
422
416
  self.prompt = tool_result
423
417
  continue
424
418
 
425
419
  # 获取用户输入
426
- user_input = get_multiline_input(f"{self.name}: 您可以继续输入,或输入空行结束当前任务")
420
+ user_input = get_multiline_input(f"{self.name}: You can continue to input, or enter an empty line to end the current task")
427
421
  if user_input == "__interrupt__":
428
- PrettyOutput.print("任务已取消", OutputType.WARNING)
422
+ PrettyOutput.print("Task cancelled by user", OutputType.WARNING)
429
423
  return "Task cancelled by user"
430
424
 
431
425
  if user_input:
@@ -445,10 +439,10 @@ arguments:
445
439
 
446
440
 
447
441
  def clear_history(self):
448
- """清除对话历史,只保留系统提示"""
442
+ """Clear conversation history, only keep system prompt"""
449
443
  self.prompt = ""
450
444
  self.model.reset()
451
- self.conversation_length = 0 # 重置对话长度
445
+ self.conversation_length = 0 # Reset conversation length
452
446
 
453
447
 
454
448