jarvis-ai-assistant 0.1.22__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 CHANGED
@@ -1,3 +1,3 @@
1
1
  """Jarvis AI Assistant"""
2
2
 
3
- __version__ = "0.1.22"
3
+ __version__ = "0.1.23"
Binary file
Binary file
jarvis/agent.py CHANGED
@@ -111,17 +111,20 @@ class Agent:
111
111
  核心能力:
112
112
  1. 使用现有工具完成任务
113
113
  2. 通过 generate_tool 创建新工具扩展功能
114
- 3. 遵循 ReAct (思考-行动-观察) 框架
114
+ 3. 通过 create_sub_agent 创建子代理处理独立任务
115
+ 4. 遵循 ReAct (思考-行动-观察) 框架
115
116
 
116
117
  工作流程:
117
118
  1. 思考
118
119
  - 分析需求和可用工具
119
120
  - 评估是否需要新工具
121
+ - 考虑是否需要拆分子任务
120
122
  - 规划解决方案
121
123
 
122
124
  2. 行动 (如果需要)
123
125
  - 使用现有工具
124
126
  - 创建新工具
127
+ - 创建子代理
125
128
  - 询问更多信息
126
129
 
127
130
  3. 观察
@@ -129,14 +132,25 @@ class Agent:
129
132
  - 分析反馈
130
133
  - 规划下一步
131
134
 
132
- 工具使用格式:
135
+ 任务拆分建议:
136
+ - 当任务包含多个独立步骤时
137
+ - 当子任务需要独立的上下文时
138
+ - 当子任务有明确的完成目标时
139
+ - 当需要并行处理多个任务时
140
+
141
+ 创建子代理时,必须提供尽可能多的上下文信息,以确保其正确工作。
142
+
143
+ 创建子代理示例:
133
144
  <START_TOOL_CALL>
134
- name: tool_name
145
+ name: create_sub_agent
135
146
  arguments:
136
- param1: value1
137
- param2: |
138
- multiline
139
- value
147
+ agent_name: CodeAnalyzer
148
+ task: 分析项目代码质量
149
+ context: |
150
+ 这是一个Python项目
151
+ 使用了Flask框架
152
+ 需要关注性能和安全性
153
+ goal: 生成代码质量分析报告
140
154
  <END_TOOL_CALL>
141
155
 
142
156
  创建新工具示例:
@@ -155,6 +169,16 @@ arguments:
155
169
  required: [param1]
156
170
  <END_TOOL_CALL>
157
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
+
158
182
  严格规则:
159
183
  1. 每次只能执行一个工具
160
184
  2. 等待用户提供执行结果
@@ -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,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: jarvis-ai-assistant
3
- Version: 0.1.22
3
+ Version: 0.1.23
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
@@ -1,9 +1,9 @@
1
- jarvis/__init__.py,sha256=Ltq0PxhuQ9N0aWtdEVB8sZZp_5T574JJR69CubPKJW8,50
2
- jarvis/agent.py,sha256=Srcz3RxRGItJG--etdt_juF4FN6-XnbsNx7fXPrTlhw,8876
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=rR_OlOkGGLilqfXDD4v_hwWoZS5HYDeXP0BqMSXb8yQ,209
6
- jarvis/__pycache__/agent.cpython-313.pyc,sha256=JAemMJtOmhmSzSYZeDC9Opi4jgtHKMbXbtFIpdiy2Fo,11814
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
@@ -20,6 +20,7 @@ jarvis/tools/base.py,sha256=4LvbpUXDnLNu2r6S2G-luAPKRk_-6I6lfQQbxxiyIUw,7347
20
20
  jarvis/tools/file_ops.py,sha256=KbQLVCCXw-MtJg-12iyMeVGu8BTtLq7Mk7fpVKau40U,4296
21
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
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
@@ -31,14 +32,14 @@ jarvis/tools/__pycache__/python_script.cpython-313.pyc,sha256=8JpryqTovEiTvBlWAK
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=9spmVX8KSQ4qIH7FbXo5tmmZfNx8KfIGtjy2lxTSp4Y,3144
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.22.dist-info/LICENSE,sha256=AGgVgQmTqFvaztRtCAXsAMryUymB18gZif7_l2e1XOg,1063
40
- jarvis_ai_assistant-0.1.22.dist-info/METADATA,sha256=OzkgBU0mQbrNVdQ5qsdCBsqhXI0mXk-QwNC9A_WMpBc,10193
41
- jarvis_ai_assistant-0.1.22.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
42
- jarvis_ai_assistant-0.1.22.dist-info/entry_points.txt,sha256=iKu7OMfew9dtfGhW71gIMTg4wvafuPqKb4wyQOnMAGU,44
43
- jarvis_ai_assistant-0.1.22.dist-info/top_level.txt,sha256=1BOxyWfzOP_ZXj8rVTDnNCJ92bBGB0rwq8N1PCpoMIs,7
44
- jarvis_ai_assistant-0.1.22.dist-info/RECORD,,
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,,