jarvis-ai-assistant 0.1.19__py3-none-any.whl → 0.1.23__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 jarvis-ai-assistant might be problematic. Click here for more details.
- jarvis/__init__.py +1 -1
- jarvis/__pycache__/__init__.cpython-313.pyc +0 -0
- jarvis/__pycache__/agent.cpython-313.pyc +0 -0
- jarvis/agent.py +51 -10
- jarvis/tools/__pycache__/base.cpython-313.pyc +0 -0
- jarvis/tools/__pycache__/generator.cpython-313.pyc +0 -0
- jarvis/tools/__pycache__/sub_agent.cpython-313.pyc +0 -0
- jarvis/tools/base.py +1 -1
- jarvis/tools/generator.py +1 -1
- jarvis/tools/sub_agent.py +108 -0
- {jarvis_ai_assistant-0.1.19.dist-info → jarvis_ai_assistant-0.1.23.dist-info}/METADATA +1 -1
- {jarvis_ai_assistant-0.1.19.dist-info → jarvis_ai_assistant-0.1.23.dist-info}/RECORD +16 -15
- {jarvis_ai_assistant-0.1.19.dist-info → jarvis_ai_assistant-0.1.23.dist-info}/LICENSE +0 -0
- {jarvis_ai_assistant-0.1.19.dist-info → jarvis_ai_assistant-0.1.23.dist-info}/WHEEL +0 -0
- {jarvis_ai_assistant-0.1.19.dist-info → jarvis_ai_assistant-0.1.23.dist-info}/entry_points.txt +0 -0
- {jarvis_ai_assistant-0.1.19.dist-info → jarvis_ai_assistant-0.1.23.dist-info}/top_level.txt +0 -0
jarvis/__init__.py
CHANGED
|
Binary file
|
|
Binary file
|
jarvis/agent.py
CHANGED
|
@@ -11,7 +11,7 @@ import os
|
|
|
11
11
|
from datetime import datetime
|
|
12
12
|
|
|
13
13
|
class Agent:
|
|
14
|
-
def __init__(self, model: BaseModel, tool_registry: ToolRegistry, name: str = "Jarvis"):
|
|
14
|
+
def __init__(self, model: BaseModel, tool_registry: ToolRegistry, name: str = "Jarvis", is_sub_agent: bool = False):
|
|
15
15
|
"""Initialize Agent with a model, optional tool registry and name
|
|
16
16
|
|
|
17
17
|
Args:
|
|
@@ -23,6 +23,7 @@ class Agent:
|
|
|
23
23
|
self.model = model
|
|
24
24
|
self.tool_registry = tool_registry or ToolRegistry(model)
|
|
25
25
|
self.name = name
|
|
26
|
+
self.is_sub_agent = is_sub_agent
|
|
26
27
|
self.prompt = ""
|
|
27
28
|
|
|
28
29
|
|
|
@@ -77,7 +78,7 @@ class Agent:
|
|
|
77
78
|
except Exception as e:
|
|
78
79
|
raise Exception(f"{self.name}: 模型调用失败: {str(e)}")
|
|
79
80
|
|
|
80
|
-
def run(self, user_input: str, file_list: Optional[List[str]] = None, keep_history: bool = False):
|
|
81
|
+
def run(self, user_input: str, file_list: Optional[List[str]] = None, keep_history: bool = False) -> str:
|
|
81
82
|
"""处理用户输入并返回响应,返回任务总结报告
|
|
82
83
|
|
|
83
84
|
Args:
|
|
@@ -110,17 +111,20 @@ class Agent:
|
|
|
110
111
|
核心能力:
|
|
111
112
|
1. 使用现有工具完成任务
|
|
112
113
|
2. 通过 generate_tool 创建新工具扩展功能
|
|
113
|
-
3.
|
|
114
|
+
3. 通过 create_sub_agent 创建子代理处理独立任务
|
|
115
|
+
4. 遵循 ReAct (思考-行动-观察) 框架
|
|
114
116
|
|
|
115
117
|
工作流程:
|
|
116
118
|
1. 思考
|
|
117
119
|
- 分析需求和可用工具
|
|
118
120
|
- 评估是否需要新工具
|
|
121
|
+
- 考虑是否需要拆分子任务
|
|
119
122
|
- 规划解决方案
|
|
120
123
|
|
|
121
124
|
2. 行动 (如果需要)
|
|
122
125
|
- 使用现有工具
|
|
123
126
|
- 创建新工具
|
|
127
|
+
- 创建子代理
|
|
124
128
|
- 询问更多信息
|
|
125
129
|
|
|
126
130
|
3. 观察
|
|
@@ -128,14 +132,25 @@ class Agent:
|
|
|
128
132
|
- 分析反馈
|
|
129
133
|
- 规划下一步
|
|
130
134
|
|
|
131
|
-
|
|
135
|
+
任务拆分建议:
|
|
136
|
+
- 当任务包含多个独立步骤时
|
|
137
|
+
- 当子任务需要独立的上下文时
|
|
138
|
+
- 当子任务有明确的完成目标时
|
|
139
|
+
- 当需要并行处理多个任务时
|
|
140
|
+
|
|
141
|
+
创建子代理时,必须提供尽可能多的上下文信息,以确保其正确工作。
|
|
142
|
+
|
|
143
|
+
创建子代理示例:
|
|
132
144
|
<START_TOOL_CALL>
|
|
133
|
-
name:
|
|
145
|
+
name: create_sub_agent
|
|
134
146
|
arguments:
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
147
|
+
agent_name: CodeAnalyzer
|
|
148
|
+
task: 分析项目代码质量
|
|
149
|
+
context: |
|
|
150
|
+
这是一个Python项目
|
|
151
|
+
使用了Flask框架
|
|
152
|
+
需要关注性能和安全性
|
|
153
|
+
goal: 生成代码质量分析报告
|
|
139
154
|
<END_TOOL_CALL>
|
|
140
155
|
|
|
141
156
|
创建新工具示例:
|
|
@@ -154,6 +169,16 @@ arguments:
|
|
|
154
169
|
required: [param1]
|
|
155
170
|
<END_TOOL_CALL>
|
|
156
171
|
|
|
172
|
+
工具使用格式:
|
|
173
|
+
<START_TOOL_CALL>
|
|
174
|
+
name: tool_name
|
|
175
|
+
arguments:
|
|
176
|
+
param1: value1
|
|
177
|
+
param2: |
|
|
178
|
+
multiline
|
|
179
|
+
value
|
|
180
|
+
<END_TOOL_CALL>
|
|
181
|
+
|
|
157
182
|
严格规则:
|
|
158
183
|
1. 每次只能执行一个工具
|
|
159
184
|
2. 等待用户提供执行结果
|
|
@@ -203,7 +228,23 @@ arguments:
|
|
|
203
228
|
|
|
204
229
|
if not user_input:
|
|
205
230
|
PrettyOutput.section("任务完成", OutputType.SUCCESS)
|
|
206
|
-
|
|
231
|
+
if self.is_sub_agent:
|
|
232
|
+
# 生成任务总结
|
|
233
|
+
summary_prompt = f"""请对以上任务执行情况生成一个简洁的总结报告,包括:
|
|
234
|
+
|
|
235
|
+
1. 任务目标: xxxx
|
|
236
|
+
2. 执行结果: 成功/失败
|
|
237
|
+
3. 关键信息: 提取执行过程中的重要信息
|
|
238
|
+
4. 重要发现: 任何值得注意的发现
|
|
239
|
+
5. 后续建议: 如果有的话
|
|
240
|
+
|
|
241
|
+
请用简洁的要点形式描述,突出重要信息。
|
|
242
|
+
"""
|
|
243
|
+
self.prompt = summary_prompt
|
|
244
|
+
summary = self.model.chat(self.prompt)
|
|
245
|
+
return summary
|
|
246
|
+
else:
|
|
247
|
+
return "Task completed"
|
|
207
248
|
|
|
208
249
|
except Exception as e:
|
|
209
250
|
PrettyOutput.print(str(e), OutputType.ERROR)
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
jarvis/tools/base.py
CHANGED
|
@@ -115,7 +115,7 @@ class ToolRegistry:
|
|
|
115
115
|
parameters=tool_instance.parameters,
|
|
116
116
|
func=tool_instance.execute
|
|
117
117
|
)
|
|
118
|
-
self.output_handler.print(f"已加载工具: {tool_instance.name}", OutputType.INFO)
|
|
118
|
+
self.output_handler.print(f"已加载工具: {tool_instance.name}: {tool_instance.description}", OutputType.INFO)
|
|
119
119
|
tool_found = True
|
|
120
120
|
|
|
121
121
|
if not tool_found:
|
jarvis/tools/generator.py
CHANGED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
from typing import Dict, Any, Protocol, Optional
|
|
2
|
+
from enum import Enum
|
|
3
|
+
import os
|
|
4
|
+
import sys
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
|
|
7
|
+
# 添加项目根目录到 Python 路径
|
|
8
|
+
project_root = Path(__file__).parent.parent.parent
|
|
9
|
+
if str(project_root) not in sys.path:
|
|
10
|
+
sys.path.append(str(project_root))
|
|
11
|
+
|
|
12
|
+
from jarvis.agent import Agent
|
|
13
|
+
from jarvis.utils import OutputType
|
|
14
|
+
|
|
15
|
+
class OutputHandler(Protocol):
|
|
16
|
+
def print(self, text: str, output_type: OutputType) -> None: ...
|
|
17
|
+
|
|
18
|
+
class ModelHandler(Protocol):
|
|
19
|
+
def chat(self, message: str) -> str: ...
|
|
20
|
+
|
|
21
|
+
class SubAgentTool:
|
|
22
|
+
name = "create_sub_agent"
|
|
23
|
+
description = "创建一个子代理来处理特定任务,子代理会生成任务总结报告"
|
|
24
|
+
parameters = {
|
|
25
|
+
"type": "object",
|
|
26
|
+
"properties": {
|
|
27
|
+
"agent_name": {
|
|
28
|
+
"type": "string",
|
|
29
|
+
"description": "子代理的名称"
|
|
30
|
+
},
|
|
31
|
+
"task": {
|
|
32
|
+
"type": "string",
|
|
33
|
+
"description": "需要完成的具体任务"
|
|
34
|
+
},
|
|
35
|
+
"context": {
|
|
36
|
+
"type": "string",
|
|
37
|
+
"description": "任务相关的上下文信息",
|
|
38
|
+
"default": ""
|
|
39
|
+
},
|
|
40
|
+
"goal": {
|
|
41
|
+
"type": "string",
|
|
42
|
+
"description": "任务的完成目标",
|
|
43
|
+
"default": ""
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
"required": ["agent_name", "task", "context", "goal"]
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
def __init__(self, **kwargs):
|
|
50
|
+
"""初始化子代理工具
|
|
51
|
+
|
|
52
|
+
Args:
|
|
53
|
+
model: 模型处理器
|
|
54
|
+
output_handler: 输出处理器
|
|
55
|
+
register: 工具注册器
|
|
56
|
+
"""
|
|
57
|
+
self.model = kwargs.get('model')
|
|
58
|
+
if not self.model:
|
|
59
|
+
raise Exception("Model is required for SubAgentTool")
|
|
60
|
+
self.output = kwargs.get('output_handler')
|
|
61
|
+
self.register = kwargs.get('register')
|
|
62
|
+
|
|
63
|
+
def _print(self, text: str, output_type: OutputType = OutputType.INFO):
|
|
64
|
+
"""输出信息"""
|
|
65
|
+
if self.output:
|
|
66
|
+
self.output.print(text, output_type)
|
|
67
|
+
|
|
68
|
+
def execute(self, args: Dict) -> Dict[str, Any]:
|
|
69
|
+
"""创建并运行子代理"""
|
|
70
|
+
try:
|
|
71
|
+
agent_name = args["agent_name"]
|
|
72
|
+
task = args["task"]
|
|
73
|
+
context = args.get("context", "")
|
|
74
|
+
goal = args.get("goal", "")
|
|
75
|
+
|
|
76
|
+
self._print(f"创建子代理: {agent_name}")
|
|
77
|
+
|
|
78
|
+
# 构建任务描述
|
|
79
|
+
task_description = task
|
|
80
|
+
if context:
|
|
81
|
+
task_description = f"上下文信息:\n{context}\n\n任务:\n{task}"
|
|
82
|
+
if goal:
|
|
83
|
+
task_description += f"\n\n完成目标:\n{goal}"
|
|
84
|
+
|
|
85
|
+
# 创建子代理
|
|
86
|
+
sub_agent = Agent(
|
|
87
|
+
name=agent_name,
|
|
88
|
+
model=self.model,
|
|
89
|
+
tool_registry=self.register,
|
|
90
|
+
is_sub_agent=True
|
|
91
|
+
)
|
|
92
|
+
|
|
93
|
+
# 运行子代理
|
|
94
|
+
self._print(f"子代理开始执行任务...")
|
|
95
|
+
result = sub_agent.run(task_description)
|
|
96
|
+
|
|
97
|
+
return {
|
|
98
|
+
"success": True,
|
|
99
|
+
"stdout": f"子代理任务完成\n\n{result}",
|
|
100
|
+
"stderr": ""
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
except Exception as e:
|
|
104
|
+
self._print(str(e), OutputType.ERROR)
|
|
105
|
+
return {
|
|
106
|
+
"success": False,
|
|
107
|
+
"error": f"子代理执行失败: {str(e)}"
|
|
108
|
+
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
jarvis/__init__.py,sha256=
|
|
2
|
-
jarvis/agent.py,sha256=
|
|
1
|
+
jarvis/__init__.py,sha256=WSKGFVi_j1dkarXDlgPoryqQHFsuvbJuPKwZDbqctjA,50
|
|
2
|
+
jarvis/agent.py,sha256=ojs1f3Gjy049zKh7foAKkablPjsPhJI9DGB12b4l9rY,9592
|
|
3
3
|
jarvis/main.py,sha256=tptQp6rjhHOSsPphmrtoxf7l78btnP_hJmr3hVMO4zg,8103
|
|
4
4
|
jarvis/utils.py,sha256=YipQpEuIRwFE3y3YrgGlSVLEPDrlbBNY1gRiOJix9DU,6602
|
|
5
|
-
jarvis/__pycache__/__init__.cpython-313.pyc,sha256=
|
|
6
|
-
jarvis/__pycache__/agent.cpython-313.pyc,sha256=
|
|
5
|
+
jarvis/__pycache__/__init__.cpython-313.pyc,sha256=rT2SAKbzBYAMp9vZpjydqHwIBuZLRzzOXq6n3F-H5pE,209
|
|
6
|
+
jarvis/__pycache__/agent.cpython-313.pyc,sha256=LYq1CMB8lQpBLrk54MBWsFpEsNf6-FvNvN-GYTxM8vA,12532
|
|
7
7
|
jarvis/__pycache__/main.cpython-313.pyc,sha256=uQ1QHMHR6EukOb7z-YOz8CicXRPEfiHyS7KRq15xxVw,10943
|
|
8
8
|
jarvis/__pycache__/models.cpython-313.pyc,sha256=uWuRIjGrY4YDB3dGW5PGDLWaS03et8g11O725TjY_eU,5960
|
|
9
9
|
jarvis/__pycache__/tools.cpython-313.pyc,sha256=lAD4LrnnWzNZQmHXGfZ_2l7oskOpr2_2OC-gdFhxQY8,33933
|
|
@@ -16,29 +16,30 @@ jarvis/models/__pycache__/__init__.cpython-313.pyc,sha256=jAwySX4diR7EWM_alK75ti
|
|
|
16
16
|
jarvis/models/__pycache__/base.cpython-313.pyc,sha256=4I9KZlXHvTB7vENA9YWK4Fx0sns_KvIOtWqzE9y_-Co,1094
|
|
17
17
|
jarvis/models/__pycache__/kimi.cpython-313.pyc,sha256=-hOwhZrfvqfd5K_c34Tm-uR3gaZ9r6EV1NtwV0-FDmg,13647
|
|
18
18
|
jarvis/tools/__init__.py,sha256=AjmFYLXt-_ulZXdYiXya2fD7QCJ-RaK91PEZCNj-UbA,262
|
|
19
|
-
jarvis/tools/base.py,sha256=
|
|
19
|
+
jarvis/tools/base.py,sha256=4LvbpUXDnLNu2r6S2G-luAPKRk_-6I6lfQQbxxiyIUw,7347
|
|
20
20
|
jarvis/tools/file_ops.py,sha256=KbQLVCCXw-MtJg-12iyMeVGu8BTtLq7Mk7fpVKau40U,4296
|
|
21
|
-
jarvis/tools/generator.py,sha256=
|
|
21
|
+
jarvis/tools/generator.py,sha256=qURQ2ct61tRaN-CNhnbpjoj7recGGjFWnQUteKvej_g,7430
|
|
22
22
|
jarvis/tools/shell.py,sha256=MWe9-BAGApbGJfR60XG4nElGYHNBnbdF9vsOQTnEZ4g,2989
|
|
23
|
+
jarvis/tools/sub_agent.py,sha256=jU0j__Y5ufBktxIF5qdT3NyLHnybE23c39QRj3oz5CI,3381
|
|
23
24
|
jarvis/tools/__pycache__/__init__.cpython-313.pyc,sha256=KC48FS57427navbkxZ0eDKLePMCH2BKc5vAIu0b8lFc,404
|
|
24
|
-
jarvis/tools/__pycache__/base.cpython-313.pyc,sha256=
|
|
25
|
+
jarvis/tools/__pycache__/base.cpython-313.pyc,sha256=Pw89qn1ZMSNdU03CoM4ezkAHEiP_iTZEWceGg1TE_mk,9913
|
|
25
26
|
jarvis/tools/__pycache__/bing_search.cpython-313.pyc,sha256=1G_wPbk5wcQYh7H0drLIS2Aw0XOG2ZM8ztgfQaqu3P8,2031
|
|
26
27
|
jarvis/tools/__pycache__/calculator.cpython-313.pyc,sha256=C_qwTDGm6gc7QNxtPzPZXyStdKEintJVQIt5NMHQ8oY,4205
|
|
27
28
|
jarvis/tools/__pycache__/calculator_tool.cpython-313.pyc,sha256=PI4LZNDTPdSe3ffWDRovLZ-r-vF8Kl-n6xdGdFWiBpY,4296
|
|
28
29
|
jarvis/tools/__pycache__/file_ops.cpython-313.pyc,sha256=OBR2EDQ2Ana7CTtLOoM5AYJzyVwP683LS7QrOR8_I3g,5208
|
|
29
|
-
jarvis/tools/__pycache__/generator.cpython-313.pyc,sha256=
|
|
30
|
+
jarvis/tools/__pycache__/generator.cpython-313.pyc,sha256=EXK5lveBUQqOnpHRsAvYHZFCso350-OchiHJc62wEVQ,8770
|
|
30
31
|
jarvis/tools/__pycache__/python_script.cpython-313.pyc,sha256=8JpryqTovEiTvBlWAK1KjZmPvHUuPc9GT9rTXBEQoJc,6693
|
|
31
32
|
jarvis/tools/__pycache__/rag.cpython-313.pyc,sha256=JH6-PSZRMKAvTZqCwlRXJGClxYXNMs-vetU0q7hBLz0,6064
|
|
32
33
|
jarvis/tools/__pycache__/search.cpython-313.pyc,sha256=wLMIkFwT-h4NGHgssytT4xme7sGO6ZhEnex7kjcy0-k,5990
|
|
33
34
|
jarvis/tools/__pycache__/shell.cpython-313.pyc,sha256=6HWtxO-OWIxSraGkLs4K8hJrJ-UBVdi5KVuQUhyEUMA,4784
|
|
34
|
-
jarvis/tools/__pycache__/sub_agent.cpython-313.pyc,sha256=
|
|
35
|
+
jarvis/tools/__pycache__/sub_agent.cpython-313.pyc,sha256=RqIUPCSentRuZAARTX3wLTSy3HjzwEe1MFJ-fRx_U0Y,4645
|
|
35
36
|
jarvis/tools/__pycache__/user_confirmation.cpython-313.pyc,sha256=wK3Ev10lHSUSRvoYmi7A0GzxYkzU-C4Wfhs5qW_HBqs,2271
|
|
36
37
|
jarvis/tools/__pycache__/user_input.cpython-313.pyc,sha256=JjTFOhObKsKF4Pn8KBRuKfV1_Ssj083fjU7Mfc_5z7c,2531
|
|
37
38
|
jarvis/tools/__pycache__/user_interaction.cpython-313.pyc,sha256=RuVZ-pmiPBDywY3efgXSfohMAciC1avMGPmBK5qlnew,3305
|
|
38
39
|
jarvis/tools/__pycache__/webpage.cpython-313.pyc,sha256=BjzSfnNzsKCrLETCcWjt32lNDLzwnjqcVGg4JfWd9OM,3008
|
|
39
|
-
jarvis_ai_assistant-0.1.
|
|
40
|
-
jarvis_ai_assistant-0.1.
|
|
41
|
-
jarvis_ai_assistant-0.1.
|
|
42
|
-
jarvis_ai_assistant-0.1.
|
|
43
|
-
jarvis_ai_assistant-0.1.
|
|
44
|
-
jarvis_ai_assistant-0.1.
|
|
40
|
+
jarvis_ai_assistant-0.1.23.dist-info/LICENSE,sha256=AGgVgQmTqFvaztRtCAXsAMryUymB18gZif7_l2e1XOg,1063
|
|
41
|
+
jarvis_ai_assistant-0.1.23.dist-info/METADATA,sha256=n_8hfZ0nFZc44KvlVnmlX46zsqJOY9QxpsZ6zXkvl1Y,10193
|
|
42
|
+
jarvis_ai_assistant-0.1.23.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
|
|
43
|
+
jarvis_ai_assistant-0.1.23.dist-info/entry_points.txt,sha256=iKu7OMfew9dtfGhW71gIMTg4wvafuPqKb4wyQOnMAGU,44
|
|
44
|
+
jarvis_ai_assistant-0.1.23.dist-info/top_level.txt,sha256=1BOxyWfzOP_ZXj8rVTDnNCJ92bBGB0rwq8N1PCpoMIs,7
|
|
45
|
+
jarvis_ai_assistant-0.1.23.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
{jarvis_ai_assistant-0.1.19.dist-info → jarvis_ai_assistant-0.1.23.dist-info}/entry_points.txt
RENAMED
|
File without changes
|
|
File without changes
|