jarvis-ai-assistant 0.3.11__py3-none-any.whl → 0.3.13__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.
- jarvis/__init__.py +1 -1
- jarvis/jarvis_agent/__init__.py +31 -27
- jarvis/jarvis_agent/builtin_input_handler.py +11 -3
- jarvis/jarvis_agent/file_methodology_manager.py +3 -7
- jarvis/jarvis_agent/jarvis.py +10 -17
- jarvis/jarvis_agent/session_manager.py +0 -8
- jarvis/jarvis_agent/share_manager.py +10 -10
- {jarvis_ai_assistant-0.3.11.dist-info → jarvis_ai_assistant-0.3.13.dist-info}/METADATA +1 -1
- {jarvis_ai_assistant-0.3.11.dist-info → jarvis_ai_assistant-0.3.13.dist-info}/RECORD +13 -13
- {jarvis_ai_assistant-0.3.11.dist-info → jarvis_ai_assistant-0.3.13.dist-info}/WHEEL +0 -0
- {jarvis_ai_assistant-0.3.11.dist-info → jarvis_ai_assistant-0.3.13.dist-info}/entry_points.txt +0 -0
- {jarvis_ai_assistant-0.3.11.dist-info → jarvis_ai_assistant-0.3.13.dist-info}/licenses/LICENSE +0 -0
- {jarvis_ai_assistant-0.3.11.dist-info → jarvis_ai_assistant-0.3.13.dist-info}/top_level.txt +0 -0
jarvis/__init__.py
CHANGED
jarvis/jarvis_agent/__init__.py
CHANGED
@@ -180,11 +180,11 @@ origin_agent_system_prompt = f"""
|
|
180
180
|
|
181
181
|
|
182
182
|
class Agent:
|
183
|
-
def
|
183
|
+
def clear_history(self):
|
184
184
|
"""
|
185
185
|
Clears the current conversation history by delegating to the session manager.
|
186
186
|
"""
|
187
|
-
self.session.
|
187
|
+
self.session.clear_history()
|
188
188
|
|
189
189
|
def __del__(self):
|
190
190
|
# 只有在记录启动时才停止记录
|
@@ -444,9 +444,10 @@ class Agent:
|
|
444
444
|
4. 会检查并处理上下文长度限制
|
445
445
|
"""
|
446
446
|
# 处理输入
|
447
|
-
|
448
|
-
|
449
|
-
|
447
|
+
if run_input_handlers:
|
448
|
+
message = self._process_input(message)
|
449
|
+
if not message:
|
450
|
+
return ""
|
450
451
|
|
451
452
|
# 添加附加提示
|
452
453
|
message = self._add_addon_prompt(message, need_complete)
|
@@ -459,21 +460,16 @@ class Agent:
|
|
459
460
|
|
460
461
|
return response
|
461
462
|
|
462
|
-
def _process_input(self, message: str
|
463
|
+
def _process_input(self, message: str) -> str:
|
463
464
|
"""处理输入消息"""
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
return message
|
465
|
+
for handler in self.input_handler:
|
466
|
+
message, need_return = handler(message, self)
|
467
|
+
if need_return:
|
468
|
+
self._last_handler_returned = True
|
469
|
+
return message
|
470
470
|
self._last_handler_returned = False
|
471
471
|
return message
|
472
472
|
|
473
|
-
def _should_return_early(self, message: str) -> bool:
|
474
|
-
"""检查是否需要提前返回"""
|
475
|
-
return hasattr(self, "_last_handler_returned") and self._last_handler_returned
|
476
|
-
|
477
473
|
def _add_addon_prompt(self, message: str, need_complete: bool) -> str:
|
478
474
|
"""添加附加提示到消息"""
|
479
475
|
if self.session.addon_prompt:
|
@@ -561,12 +557,19 @@ class Agent:
|
|
561
557
|
def _handle_history_with_summary(self) -> str:
|
562
558
|
"""使用摘要方式处理历史"""
|
563
559
|
summary = self.generate_summary()
|
564
|
-
self.clear_history()
|
565
560
|
|
566
|
-
|
567
|
-
|
561
|
+
# 先获取格式化的摘要消息
|
562
|
+
formatted_summary = ""
|
563
|
+
if summary:
|
564
|
+
formatted_summary = self._format_summary_message(summary)
|
565
|
+
|
566
|
+
# 清理历史(但不清理prompt,因为prompt会在builtin_input_handler中设置)
|
567
|
+
if self.model:
|
568
|
+
self.model.reset()
|
569
|
+
# 重置会话
|
570
|
+
self.session.clear_history()
|
568
571
|
|
569
|
-
return
|
572
|
+
return formatted_summary
|
570
573
|
|
571
574
|
def _handle_history_with_file_upload(self) -> str:
|
572
575
|
"""使用文件上传方式处理历史"""
|
@@ -704,6 +707,7 @@ class Agent:
|
|
704
707
|
current_response = self._call_model(
|
705
708
|
self.session.prompt, True, run_input_handlers
|
706
709
|
)
|
710
|
+
|
707
711
|
self.session.prompt = ""
|
708
712
|
run_input_handlers = False
|
709
713
|
|
@@ -713,12 +717,18 @@ class Agent:
|
|
713
717
|
if isinstance(interrupt_result, tuple):
|
714
718
|
run_input_handlers, should_continue = interrupt_result
|
715
719
|
if should_continue:
|
720
|
+
self.run_input_handlers_next_turn = True
|
716
721
|
continue
|
717
722
|
else:
|
718
723
|
return interrupt_result
|
719
724
|
|
720
725
|
# 处理工具调用
|
721
|
-
need_return,
|
726
|
+
need_return, prompt = self._call_tools(current_response)
|
727
|
+
if self.session.prompt and prompt:
|
728
|
+
self.session.prompt += "\n\n" + prompt
|
729
|
+
else:
|
730
|
+
self.session.prompt = prompt
|
731
|
+
|
722
732
|
if need_return:
|
723
733
|
return self.session.prompt
|
724
734
|
|
@@ -871,9 +881,3 @@ class Agent:
|
|
871
881
|
organizer.organize_memories(memory_type, min_overlap=3)
|
872
882
|
else:
|
873
883
|
PrettyOutput.print(f"已取消 '{scope_name}' 记忆库整理。", OutputType.INFO)
|
874
|
-
|
875
|
-
def clear_history(self):
|
876
|
-
"""
|
877
|
-
Clears conversation history by delegating to the session manager.
|
878
|
-
"""
|
879
|
-
self.session.clear_history()
|
@@ -32,10 +32,18 @@ def builtin_input_handler(user_input: str, agent_: Any) -> Tuple[str, bool]:
|
|
32
32
|
for tag in special_tags:
|
33
33
|
# 优先处理特殊标记
|
34
34
|
if tag == "Summary":
|
35
|
-
agent._summarize_and_clear_history()
|
36
|
-
|
35
|
+
summary = agent._summarize_and_clear_history()
|
36
|
+
memory_tags_prompt = agent.memory_manager.prepare_memory_tags_prompt()
|
37
|
+
prompt = ""
|
38
|
+
if summary:
|
39
|
+
# 将摘要和记忆标签设置为新会话的初始提示
|
40
|
+
prompt = summary + "\n" + memory_tags_prompt
|
41
|
+
else:
|
42
|
+
# 即使没有摘要,也确保设置记忆标签作为新会话的初始提示
|
43
|
+
prompt = memory_tags_prompt
|
44
|
+
return prompt, True
|
37
45
|
elif tag == "Clear":
|
38
|
-
agent.
|
46
|
+
agent.clear_history()
|
39
47
|
return "", True
|
40
48
|
elif tag == "ToolUsage":
|
41
49
|
agent.set_addon_prompt(agent.get_tool_usage_prompt())
|
@@ -48,13 +48,10 @@ class FileMethodologyManager:
|
|
48
48
|
# 上传成功
|
49
49
|
from jarvis.jarvis_agent.memory_manager import MemoryManager
|
50
50
|
|
51
|
-
memory_manager = MemoryManager(self.agent)
|
52
|
-
memory_tags_prompt = memory_manager.prepare_memory_tags_prompt()
|
53
|
-
|
54
51
|
if self.agent.files:
|
55
|
-
self.agent.session.prompt = f"{self.agent.session.prompt}\n\n上传的文件包含历史对话信息和方法论文件,可以从中获取一些经验信息。
|
52
|
+
self.agent.session.prompt = f"{self.agent.session.prompt}\n\n上传的文件包含历史对话信息和方法论文件,可以从中获取一些经验信息。"
|
56
53
|
else:
|
57
|
-
self.agent.session.prompt = f"{self.agent.session.prompt}\n\n上传的文件包含历史对话信息,可以从中获取一些经验信息。
|
54
|
+
self.agent.session.prompt = f"{self.agent.session.prompt}\n\n上传的文件包含历史对话信息,可以从中获取一些经验信息。"
|
58
55
|
|
59
56
|
def _handle_files_upload(self):
|
60
57
|
"""处理普通文件上传"""
|
@@ -79,14 +76,13 @@ class FileMethodologyManager:
|
|
79
76
|
from jarvis.jarvis_agent.memory_manager import MemoryManager
|
80
77
|
|
81
78
|
memory_manager = MemoryManager(self.agent)
|
82
|
-
memory_tags_prompt = memory_manager.prepare_memory_tags_prompt()
|
83
79
|
methodology = load_methodology(
|
84
80
|
msg,
|
85
81
|
self.agent.get_tool_registry(),
|
86
82
|
platform_name=self.agent.model.platform_name(),
|
87
83
|
model_name=self.agent.model.name(),
|
88
84
|
)
|
89
|
-
self.agent.session.prompt = f"{self.agent.session.prompt}\n\n以下是历史类似问题的执行经验,可参考:\n{methodology}
|
85
|
+
self.agent.session.prompt = f"{self.agent.session.prompt}\n\n以下是历史类似问题的执行经验,可参考:\n{methodology}"
|
90
86
|
|
91
87
|
def handle_history_with_file_upload(self) -> str:
|
92
88
|
"""使用文件上传方式处理历史"""
|
jarvis/jarvis_agent/jarvis.py
CHANGED
@@ -19,21 +19,18 @@ def run_cli(
|
|
19
19
|
ctx: typer.Context,
|
20
20
|
llm_type: str = typer.Option(
|
21
21
|
"normal",
|
22
|
-
"-t",
|
22
|
+
"-t",
|
23
|
+
"--llm-type",
|
23
24
|
help="使用的LLM类型,可选值:'normal'(普通)或 'thinking'(思考模式)",
|
24
25
|
),
|
25
|
-
task: Optional[str] = typer.Option(
|
26
|
-
None, "-T", "--task", help="从命令行直接输入任务内容"
|
27
|
-
),
|
26
|
+
task: Optional[str] = typer.Option(None, "-T", "--task", help="从命令行直接输入任务内容"),
|
28
27
|
model_group: Optional[str] = typer.Option(
|
29
28
|
None, "-g", "--llm-group", help="使用的模型组,覆盖配置文件中的设置"
|
30
29
|
),
|
31
30
|
tool_group: Optional[str] = typer.Option(
|
32
31
|
None, "-G", "--tool-group", help="使用的工具组,覆盖配置文件中的设置"
|
33
32
|
),
|
34
|
-
config_file: Optional[str] = typer.Option(
|
35
|
-
None, "-f", "--config", help="自定义配置文件路径"
|
36
|
-
),
|
33
|
+
config_file: Optional[str] = typer.Option(None, "-f", "--config", help="自定义配置文件路径"),
|
37
34
|
restore_session: bool = typer.Option(
|
38
35
|
False,
|
39
36
|
"--restore-session",
|
@@ -43,9 +40,7 @@ def run_cli(
|
|
43
40
|
share_methodology: bool = typer.Option(
|
44
41
|
False, "--share-methodology", help="分享本地方法论到中心方法论仓库"
|
45
42
|
),
|
46
|
-
share_tool: bool = typer.Option(
|
47
|
-
False, "--share-tool", help="分享本地工具到中心工具仓库"
|
48
|
-
),
|
43
|
+
share_tool: bool = typer.Option(False, "--share-tool", help="分享本地工具到中心工具仓库"),
|
49
44
|
) -> None:
|
50
45
|
"""Jarvis AI assistant command-line interface."""
|
51
46
|
if ctx.invoked_subcommand is not None:
|
@@ -59,21 +54,19 @@ def run_cli(
|
|
59
54
|
# 处理方法论分享
|
60
55
|
if share_methodology:
|
61
56
|
init_env("", config_file=config_file) # 初始化配置但不显示欢迎信息
|
62
|
-
|
63
|
-
|
57
|
+
methodology_manager = MethodologyShareManager()
|
58
|
+
methodology_manager.run()
|
64
59
|
return
|
65
60
|
|
66
61
|
# 处理工具分享
|
67
62
|
if share_tool:
|
68
63
|
init_env("", config_file=config_file) # 初始化配置但不显示欢迎信息
|
69
|
-
|
70
|
-
|
64
|
+
tool_manager = ToolShareManager()
|
65
|
+
tool_manager.run()
|
71
66
|
return
|
72
67
|
|
73
68
|
# 初始化环境
|
74
|
-
init_env(
|
75
|
-
"欢迎使用 Jarvis AI 助手,您的智能助理已准备就绪!", config_file=config_file
|
76
|
-
)
|
69
|
+
init_env("欢迎使用 Jarvis AI 助手,您的智能助理已准备就绪!", config_file=config_file)
|
77
70
|
|
78
71
|
# 运行主流程
|
79
72
|
try:
|
@@ -34,14 +34,6 @@ class SessionManager:
|
|
34
34
|
"""Sets the addon prompt for the next model call."""
|
35
35
|
self.addon_prompt = addon_prompt
|
36
36
|
|
37
|
-
def clear(self):
|
38
|
-
"""
|
39
|
-
Clears the current conversation history, prompt, and length counter.
|
40
|
-
"""
|
41
|
-
self.model.reset()
|
42
|
-
self.conversation_length = 0
|
43
|
-
self.prompt = ""
|
44
|
-
|
45
37
|
def save_session(self) -> bool:
|
46
38
|
"""Saves the current session state to a file."""
|
47
39
|
session_dir = os.path.join(os.getcwd(), ".jarvis")
|
@@ -2,7 +2,7 @@
|
|
2
2
|
"""分享管理模块,负责工具和方法论的分享功能"""
|
3
3
|
import os
|
4
4
|
import subprocess
|
5
|
-
from typing import List, Dict, Any
|
5
|
+
from typing import List, Dict, Any, Set
|
6
6
|
from abc import ABC, abstractmethod
|
7
7
|
|
8
8
|
from prompt_toolkit import prompt
|
@@ -16,7 +16,7 @@ def parse_selection(selection_str: str, max_value: int) -> List[int]:
|
|
16
16
|
|
17
17
|
例如: "1,2,3,4-9,20" -> [1, 2, 3, 4, 5, 6, 7, 8, 9, 20]
|
18
18
|
"""
|
19
|
-
selected:
|
19
|
+
selected: Set[int] = set()
|
20
20
|
parts = selection_str.split(",")
|
21
21
|
|
22
22
|
for part in parts:
|
@@ -73,13 +73,15 @@ class ShareManager(ABC):
|
|
73
73
|
if "__pycache__" not in content:
|
74
74
|
f.write("\n__pycache__/\n")
|
75
75
|
modified = True
|
76
|
-
|
76
|
+
|
77
77
|
if modified:
|
78
|
-
subprocess.run(["git", "add", ".gitignore"], cwd=self.repo_path, check=True)
|
79
78
|
subprocess.run(
|
80
|
-
["git", "
|
81
|
-
|
82
|
-
|
79
|
+
["git", "add", ".gitignore"], cwd=self.repo_path, check=True
|
80
|
+
)
|
81
|
+
subprocess.run(
|
82
|
+
["git", "commit", "-m", "chore: add __pycache__ to .gitignore"],
|
83
|
+
cwd=self.repo_path,
|
84
|
+
check=True,
|
83
85
|
)
|
84
86
|
subprocess.run(["git", "push"], cwd=self.repo_path, check=True)
|
85
87
|
else:
|
@@ -163,9 +165,7 @@ class ShareManager(ABC):
|
|
163
165
|
def select_resources(self, resources: List[Dict[str, Any]]) -> List[Dict[str, Any]]:
|
164
166
|
"""让用户选择要分享的资源"""
|
165
167
|
# 显示可选的资源
|
166
|
-
resource_list = [
|
167
|
-
f"\n可分享的{self.get_resource_type()}(已排除中心仓库中已有的):"
|
168
|
-
]
|
168
|
+
resource_list = [f"\n可分享的{self.get_resource_type()}(已排除中心仓库中已有的):"]
|
169
169
|
for i, resource in enumerate(resources, 1):
|
170
170
|
resource_list.append(f"[{i}] {self.format_resource_display(resource)}")
|
171
171
|
|
@@ -1,11 +1,11 @@
|
|
1
|
-
jarvis/__init__.py,sha256=
|
2
|
-
jarvis/jarvis_agent/__init__.py,sha256=
|
1
|
+
jarvis/__init__.py,sha256=sNG-zIDnzHZonw0jMokUfOeIX1O9_pvk1H7gGrXcEUI,74
|
2
|
+
jarvis/jarvis_agent/__init__.py,sha256=vpioyz2E-F4hTK0A2isCbdeH6_90kfZ3FM-I5_mOnaM,31879
|
3
3
|
jarvis/jarvis_agent/agent_manager.py,sha256=YzpMiF0H2-eyk2kn2o24Bkj3bXsQx7Pv2vfD4gWepo0,2893
|
4
|
-
jarvis/jarvis_agent/builtin_input_handler.py,sha256=
|
4
|
+
jarvis/jarvis_agent/builtin_input_handler.py,sha256=wS-FqpT3pIXwHn1dfL3SpXonUKWgVThbQueUIeyRc2U,2917
|
5
5
|
jarvis/jarvis_agent/config_editor.py,sha256=Ctk82sO6w2cNW0-_5L7Bomj-hgM4U7WwMc52fwhAJyg,1809
|
6
6
|
jarvis/jarvis_agent/edit_file_handler.py,sha256=w-byNJ4TN_SlV3djjfFC7OksySOFGrM8ku49w662dzc,11854
|
7
|
-
jarvis/jarvis_agent/file_methodology_manager.py,sha256=
|
8
|
-
jarvis/jarvis_agent/jarvis.py,sha256=
|
7
|
+
jarvis/jarvis_agent/file_methodology_manager.py,sha256=PwDUQwq7HVIyPInsN8fgWyMXLwi8heIXPrqfBZJhVHs,4260
|
8
|
+
jarvis/jarvis_agent/jarvis.py,sha256=mE7sPQzuHtL9j8e_yDO91KfpbEqxrBrBG3px_WyWz50,3238
|
9
9
|
jarvis/jarvis_agent/main.py,sha256=0xq-rjadcTedcB2HJSk2v0ihcm2-r2NXLj_Nq9xS9LY,3345
|
10
10
|
jarvis/jarvis_agent/memory_manager.py,sha256=F7HTNzdN1_-cSygnz7zKSJRJvPLUOosqcXQeiW8zG4U,5266
|
11
11
|
jarvis/jarvis_agent/methodology_share_manager.py,sha256=vwWNexluTXSI3qeNP3zJAemOjWW37o_1AlqDR1C8wCI,6910
|
@@ -13,8 +13,8 @@ jarvis/jarvis_agent/output_handler.py,sha256=P7oWpXBGFfOsWq7cIhS_z9crkQ19ES7qU5p
|
|
13
13
|
jarvis/jarvis_agent/prompt_builder.py,sha256=PH1fPDVa8z_RXkoXHJFNDf8PQjUoLNLYwkh2lC__p40,1705
|
14
14
|
jarvis/jarvis_agent/prompts.py,sha256=X6cXa-n0xqBQ8LDTgLsD0kqziAh1s0cNp89i4mxcvHg,9444
|
15
15
|
jarvis/jarvis_agent/protocols.py,sha256=JWnJDikFEuwvFUv7uzXu0ggJ4O9K2FkMnfVCwIJ5REw,873
|
16
|
-
jarvis/jarvis_agent/session_manager.py,sha256=
|
17
|
-
jarvis/jarvis_agent/share_manager.py,sha256=
|
16
|
+
jarvis/jarvis_agent/session_manager.py,sha256=xPeQcQRBmAlc-CGAzVz4MTOKhZKb27rTS-5De3Oauwg,2713
|
17
|
+
jarvis/jarvis_agent/share_manager.py,sha256=wFcdULSog1mMxDyB94ofbqitFL8DCX8i1u6qVzSEuAk,8704
|
18
18
|
jarvis/jarvis_agent/shell_input_handler.py,sha256=1IboqdxcJuoIqRpmDU10GugR9fWXUHyCEbVF4nIWbyo,1328
|
19
19
|
jarvis/jarvis_agent/task_analyzer.py,sha256=-fQ9YBYFcc-Z1FSoDIPzRfAgkREFoIOXtU2TdBkB-e0,4656
|
20
20
|
jarvis/jarvis_agent/task_manager.py,sha256=HJm4_SMpsFbQMUUsAZeHm7cZuhNbz28YW-DRLYgoarc,4422
|
@@ -119,9 +119,9 @@ jarvis/jarvis_utils/methodology.py,sha256=IIMU17WVSunsWXsnXROd4G77LxgYs4xEC_xm_0
|
|
119
119
|
jarvis/jarvis_utils/output.py,sha256=QRLlKObQKT0KuRSeZRqYb7NlTQvsd1oZXZ41WxeWEuU,10894
|
120
120
|
jarvis/jarvis_utils/tag.py,sha256=f211opbbbTcSyzCDwuIK_oCnKhXPNK-RknYyGzY1yD0,431
|
121
121
|
jarvis/jarvis_utils/utils.py,sha256=LiVui9RMsbfUdzbvBBwbGNC4uniGnLp3LFsk7LXGrQE,47370
|
122
|
-
jarvis_ai_assistant-0.3.
|
123
|
-
jarvis_ai_assistant-0.3.
|
124
|
-
jarvis_ai_assistant-0.3.
|
125
|
-
jarvis_ai_assistant-0.3.
|
126
|
-
jarvis_ai_assistant-0.3.
|
127
|
-
jarvis_ai_assistant-0.3.
|
122
|
+
jarvis_ai_assistant-0.3.13.dist-info/licenses/LICENSE,sha256=AGgVgQmTqFvaztRtCAXsAMryUymB18gZif7_l2e1XOg,1063
|
123
|
+
jarvis_ai_assistant-0.3.13.dist-info/METADATA,sha256=YJ01G5YB7gEX59rrdrPw6xb-0p_pdg-KT5318_yl3t4,18216
|
124
|
+
jarvis_ai_assistant-0.3.13.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
125
|
+
jarvis_ai_assistant-0.3.13.dist-info/entry_points.txt,sha256=4GcWKFxRJD-QU14gw_3ZaW4KuEVxOcZK9i270rwPdjA,1395
|
126
|
+
jarvis_ai_assistant-0.3.13.dist-info/top_level.txt,sha256=1BOxyWfzOP_ZXj8rVTDnNCJ92bBGB0rwq8N1PCpoMIs,7
|
127
|
+
jarvis_ai_assistant-0.3.13.dist-info/RECORD,,
|
File without changes
|
{jarvis_ai_assistant-0.3.11.dist-info → jarvis_ai_assistant-0.3.13.dist-info}/entry_points.txt
RENAMED
File without changes
|
{jarvis_ai_assistant-0.3.11.dist-info → jarvis_ai_assistant-0.3.13.dist-info}/licenses/LICENSE
RENAMED
File without changes
|
File without changes
|