jarvis-ai-assistant 0.1.22__tar.gz → 0.1.24__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 (57) hide show
  1. {jarvis_ai_assistant-0.1.22/src/jarvis_ai_assistant.egg-info → jarvis_ai_assistant-0.1.24}/PKG-INFO +1 -1
  2. {jarvis_ai_assistant-0.1.22 → jarvis_ai_assistant-0.1.24}/pyproject.toml +1 -1
  3. {jarvis_ai_assistant-0.1.22 → jarvis_ai_assistant-0.1.24}/setup.py +1 -1
  4. {jarvis_ai_assistant-0.1.22 → jarvis_ai_assistant-0.1.24}/src/jarvis/__init__.py +1 -1
  5. jarvis_ai_assistant-0.1.24/src/jarvis/__pycache__/__init__.cpython-313.pyc +0 -0
  6. {jarvis_ai_assistant-0.1.22 → jarvis_ai_assistant-0.1.24}/src/jarvis/__pycache__/agent.cpython-313.pyc +0 -0
  7. jarvis_ai_assistant-0.1.24/src/jarvis/__pycache__/main.cpython-313.pyc +0 -0
  8. {jarvis_ai_assistant-0.1.22 → jarvis_ai_assistant-0.1.24}/src/jarvis/__pycache__/utils.cpython-313.pyc +0 -0
  9. {jarvis_ai_assistant-0.1.22 → jarvis_ai_assistant-0.1.24}/src/jarvis/agent.py +43 -9
  10. {jarvis_ai_assistant-0.1.22 → jarvis_ai_assistant-0.1.24}/src/jarvis/main.py +4 -17
  11. jarvis_ai_assistant-0.1.24/src/jarvis/models/__pycache__/kimi.cpython-313.pyc +0 -0
  12. {jarvis_ai_assistant-0.1.22 → jarvis_ai_assistant-0.1.24}/src/jarvis/models/kimi.py +82 -2
  13. jarvis_ai_assistant-0.1.24/src/jarvis/tools/__pycache__/base.cpython-313.pyc +0 -0
  14. jarvis_ai_assistant-0.1.24/src/jarvis/tools/__pycache__/sub_agent.cpython-313.pyc +0 -0
  15. {jarvis_ai_assistant-0.1.22 → jarvis_ai_assistant-0.1.24}/src/jarvis/tools/base.py +3 -3
  16. jarvis_ai_assistant-0.1.24/src/jarvis/tools/sub_agent.py +108 -0
  17. {jarvis_ai_assistant-0.1.22 → jarvis_ai_assistant-0.1.24}/src/jarvis/utils.py +1 -1
  18. {jarvis_ai_assistant-0.1.22 → jarvis_ai_assistant-0.1.24/src/jarvis_ai_assistant.egg-info}/PKG-INFO +1 -1
  19. {jarvis_ai_assistant-0.1.22 → jarvis_ai_assistant-0.1.24}/src/jarvis_ai_assistant.egg-info/SOURCES.txt +1 -0
  20. jarvis_ai_assistant-0.1.22/src/jarvis/__pycache__/__init__.cpython-313.pyc +0 -0
  21. jarvis_ai_assistant-0.1.22/src/jarvis/__pycache__/main.cpython-313.pyc +0 -0
  22. jarvis_ai_assistant-0.1.22/src/jarvis/models/__pycache__/kimi.cpython-313.pyc +0 -0
  23. jarvis_ai_assistant-0.1.22/src/jarvis/tools/__pycache__/base.cpython-313.pyc +0 -0
  24. jarvis_ai_assistant-0.1.22/src/jarvis/tools/__pycache__/sub_agent.cpython-313.pyc +0 -0
  25. {jarvis_ai_assistant-0.1.22 → jarvis_ai_assistant-0.1.24}/LICENSE +0 -0
  26. {jarvis_ai_assistant-0.1.22 → jarvis_ai_assistant-0.1.24}/MANIFEST.in +0 -0
  27. {jarvis_ai_assistant-0.1.22 → jarvis_ai_assistant-0.1.24}/README.md +0 -0
  28. {jarvis_ai_assistant-0.1.22 → jarvis_ai_assistant-0.1.24}/setup.cfg +0 -0
  29. {jarvis_ai_assistant-0.1.22 → jarvis_ai_assistant-0.1.24}/src/jarvis/__pycache__/models.cpython-313.pyc +0 -0
  30. {jarvis_ai_assistant-0.1.22 → jarvis_ai_assistant-0.1.24}/src/jarvis/__pycache__/tools.cpython-313.pyc +0 -0
  31. {jarvis_ai_assistant-0.1.22 → jarvis_ai_assistant-0.1.24}/src/jarvis/__pycache__/zte_llm.cpython-313.pyc +0 -0
  32. {jarvis_ai_assistant-0.1.22 → jarvis_ai_assistant-0.1.24}/src/jarvis/models/__init__.py +0 -0
  33. {jarvis_ai_assistant-0.1.22 → jarvis_ai_assistant-0.1.24}/src/jarvis/models/__pycache__/__init__.cpython-313.pyc +0 -0
  34. {jarvis_ai_assistant-0.1.22 → jarvis_ai_assistant-0.1.24}/src/jarvis/models/__pycache__/base.cpython-313.pyc +0 -0
  35. {jarvis_ai_assistant-0.1.22 → jarvis_ai_assistant-0.1.24}/src/jarvis/models/base.py +0 -0
  36. {jarvis_ai_assistant-0.1.22 → jarvis_ai_assistant-0.1.24}/src/jarvis/tools/__init__.py +0 -0
  37. {jarvis_ai_assistant-0.1.22 → jarvis_ai_assistant-0.1.24}/src/jarvis/tools/__pycache__/__init__.cpython-313.pyc +0 -0
  38. {jarvis_ai_assistant-0.1.22 → jarvis_ai_assistant-0.1.24}/src/jarvis/tools/__pycache__/bing_search.cpython-313.pyc +0 -0
  39. {jarvis_ai_assistant-0.1.22 → jarvis_ai_assistant-0.1.24}/src/jarvis/tools/__pycache__/calculator.cpython-313.pyc +0 -0
  40. {jarvis_ai_assistant-0.1.22 → jarvis_ai_assistant-0.1.24}/src/jarvis/tools/__pycache__/calculator_tool.cpython-313.pyc +0 -0
  41. {jarvis_ai_assistant-0.1.22 → jarvis_ai_assistant-0.1.24}/src/jarvis/tools/__pycache__/file_ops.cpython-313.pyc +0 -0
  42. {jarvis_ai_assistant-0.1.22 → jarvis_ai_assistant-0.1.24}/src/jarvis/tools/__pycache__/generator.cpython-313.pyc +0 -0
  43. {jarvis_ai_assistant-0.1.22 → jarvis_ai_assistant-0.1.24}/src/jarvis/tools/__pycache__/python_script.cpython-313.pyc +0 -0
  44. {jarvis_ai_assistant-0.1.22 → jarvis_ai_assistant-0.1.24}/src/jarvis/tools/__pycache__/rag.cpython-313.pyc +0 -0
  45. {jarvis_ai_assistant-0.1.22 → jarvis_ai_assistant-0.1.24}/src/jarvis/tools/__pycache__/search.cpython-313.pyc +0 -0
  46. {jarvis_ai_assistant-0.1.22 → jarvis_ai_assistant-0.1.24}/src/jarvis/tools/__pycache__/shell.cpython-313.pyc +0 -0
  47. {jarvis_ai_assistant-0.1.22 → jarvis_ai_assistant-0.1.24}/src/jarvis/tools/__pycache__/user_confirmation.cpython-313.pyc +0 -0
  48. {jarvis_ai_assistant-0.1.22 → jarvis_ai_assistant-0.1.24}/src/jarvis/tools/__pycache__/user_input.cpython-313.pyc +0 -0
  49. {jarvis_ai_assistant-0.1.22 → jarvis_ai_assistant-0.1.24}/src/jarvis/tools/__pycache__/user_interaction.cpython-313.pyc +0 -0
  50. {jarvis_ai_assistant-0.1.22 → jarvis_ai_assistant-0.1.24}/src/jarvis/tools/__pycache__/webpage.cpython-313.pyc +0 -0
  51. {jarvis_ai_assistant-0.1.22 → jarvis_ai_assistant-0.1.24}/src/jarvis/tools/file_ops.py +0 -0
  52. {jarvis_ai_assistant-0.1.22 → jarvis_ai_assistant-0.1.24}/src/jarvis/tools/generator.py +0 -0
  53. {jarvis_ai_assistant-0.1.22 → jarvis_ai_assistant-0.1.24}/src/jarvis/tools/shell.py +0 -0
  54. {jarvis_ai_assistant-0.1.22 → jarvis_ai_assistant-0.1.24}/src/jarvis_ai_assistant.egg-info/dependency_links.txt +0 -0
  55. {jarvis_ai_assistant-0.1.22 → jarvis_ai_assistant-0.1.24}/src/jarvis_ai_assistant.egg-info/entry_points.txt +0 -0
  56. {jarvis_ai_assistant-0.1.22 → jarvis_ai_assistant-0.1.24}/src/jarvis_ai_assistant.egg-info/requires.txt +0 -0
  57. {jarvis_ai_assistant-0.1.22 → jarvis_ai_assistant-0.1.24}/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.22
3
+ Version: 0.1.24
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.22"
7
+ version = "0.1.24"
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.22",
5
+ version="0.1.24",
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.22"
3
+ __version__ = "0.1.24"
@@ -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", is_sub_agent: bool = False):
14
+ def __init__(self, model: BaseModel, tool_registry: ToolRegistry, name: str = "Jarvis", is_sub_agent: bool = False, verbose: bool = False):
15
15
  """Initialize Agent with a model, optional tool registry and name
16
16
 
17
17
  Args:
@@ -21,7 +21,7 @@ class Agent:
21
21
  is_sub_agent: 是否为子Agent,默认为False
22
22
  """
23
23
  self.model = model
24
- self.tool_registry = tool_registry or ToolRegistry(model)
24
+ self.tool_registry = tool_registry or ToolRegistry(model, verbose=verbose)
25
25
  self.name = name
26
26
  self.is_sub_agent = is_sub_agent
27
27
  self.prompt = ""
@@ -111,17 +111,23 @@ class Agent:
111
111
  核心能力:
112
112
  1. 使用现有工具完成任务
113
113
  2. 通过 generate_tool 创建新工具扩展功能
114
- 3. 遵循 ReAct (思考-行动-观察) 框架
114
+ 3. 通过 create_sub_agent 创建子代理处理独立任务
115
+ 4. 访问和理解网页内容(无需使用工具)
116
+ 5. 遵循 ReAct (思考-行动-观察) 框架
115
117
 
116
118
  工作流程:
117
119
  1. 思考
118
120
  - 分析需求和可用工具
119
121
  - 评估是否需要新工具
122
+ - 考虑是否需要拆分子任务
120
123
  - 规划解决方案
124
+ - 确定是否需要访问网页
121
125
 
122
126
  2. 行动 (如果需要)
123
127
  - 使用现有工具
124
128
  - 创建新工具
129
+ - 创建子代理
130
+ - 访问网页获取信息
125
131
  - 询问更多信息
126
132
 
127
133
  3. 观察
@@ -129,14 +135,32 @@ class Agent:
129
135
  - 分析反馈
130
136
  - 规划下一步
131
137
 
132
- 工具使用格式:
138
+ 网页访问能力:
139
+ - 可以直接访问和阅读网页内容
140
+ - 无需使用额外工具
141
+ - 可以提取和分析网页信息
142
+ - 支持多种网页格式
143
+ - 注意:仅支持公开访问的网页
144
+
145
+ 任务拆分建议:
146
+ - 当任务包含多个独立步骤时
147
+ - 当子任务需要独立的上下文时
148
+ - 当子任务有明确的完成目标时
149
+ - 当需要并行处理多个任务时
150
+
151
+ 创建子代理时,必须提供尽可能多的上下文信息,以确保其正确工作。
152
+
153
+ 创建子代理示例:
133
154
  <START_TOOL_CALL>
134
- name: tool_name
155
+ name: create_sub_agent
135
156
  arguments:
136
- param1: value1
137
- param2: |
138
- multiline
139
- value
157
+ agent_name: CodeAnalyzer
158
+ task: 分析项目代码质量
159
+ context: |
160
+ 这是一个Python项目
161
+ 使用了Flask框架
162
+ 需要关注性能和安全性
163
+ goal: 生成代码质量分析报告
140
164
  <END_TOOL_CALL>
141
165
 
142
166
  创建新工具示例:
@@ -155,6 +179,16 @@ arguments:
155
179
  required: [param1]
156
180
  <END_TOOL_CALL>
157
181
 
182
+ 工具使用格式:
183
+ <START_TOOL_CALL>
184
+ name: tool_name
185
+ arguments:
186
+ param1: value1
187
+ param2: |
188
+ multiline
189
+ value
190
+ <END_TOOL_CALL>
191
+
158
192
  严格规则:
159
193
  1. 每次只能执行一个工具
160
194
  2. 等待用户提供执行结果
@@ -58,19 +58,6 @@ def load_tasks() -> dict:
58
58
 
59
59
  return tasks
60
60
 
61
- class NumberValidator(Validator):
62
- def validate(self, document):
63
- text = document.text.strip()
64
- if not text: # Allow empty input
65
- return
66
-
67
- try:
68
- number = int(text)
69
- if number < 0:
70
- raise ValidationError(message='Please enter a non-negative number')
71
- except ValueError:
72
- raise ValidationError(message='Please enter a valid number')
73
-
74
61
  def select_task(tasks: dict) -> str:
75
62
  """Let user select a task from the list or skip. Returns task description if selected."""
76
63
  if not tasks:
@@ -93,7 +80,6 @@ def select_task(tasks: dict) -> str:
93
80
  choice = prompt(
94
81
  "\nSelect a task number (0 to skip): ",
95
82
  completer=number_completer,
96
- validator=NumberValidator(),
97
83
  validate_while_typing=False,
98
84
  enable_history_search=True,
99
85
  ).strip()
@@ -121,6 +107,7 @@ def main():
121
107
  parser = argparse.ArgumentParser(description='Jarvis AI Assistant')
122
108
  parser.add_argument('-f', '--files', nargs='*', help='List of files to process')
123
109
  parser.add_argument('--keep-history', action='store_true', help='Keep chat history (do not delete chat session)')
110
+ parser.add_argument('-v', '--verbose', action='store_true', help='Show detailed search and reference information')
124
111
  args = parser.parse_args()
125
112
 
126
113
  load_env_from_file()
@@ -149,10 +136,10 @@ def main():
149
136
  PrettyOutput.print("\n设置完成后重新运行 Jarvis。", OutputType.INFO, timestamp=False)
150
137
  return 1
151
138
 
152
- model = KimiModel(kimi_api_key)
139
+ model = KimiModel(kimi_api_key, verbose=args.verbose)
153
140
 
154
- tool_registry = ToolRegistry()
155
- agent = Agent(model, tool_registry)
141
+ tool_registry = ToolRegistry(verbose=args.verbose)
142
+ agent = Agent(model, tool_registry, verbose=args.verbose)
156
143
 
157
144
  # 欢迎信息
158
145
  PrettyOutput.print(f"Jarvis 已初始化 - With Kimi", OutputType.SYSTEM)
@@ -10,7 +10,7 @@ import time
10
10
  class KimiModel(BaseModel):
11
11
  """Kimi模型实现"""
12
12
 
13
- def __init__(self, api_key: str = None):
13
+ def __init__(self, api_key: str, verbose: bool = False):
14
14
  """
15
15
  初始化Kimi模型
16
16
  Args:
@@ -23,6 +23,7 @@ class KimiModel(BaseModel):
23
23
  self.chat_id = ""
24
24
  self.uploaded_files = [] # 存储已上传文件的信息
25
25
  self.first_chat = True # 添加标记,用于判断是否是第一次对话
26
+ self.verbose = verbose # 添加verbose属性
26
27
 
27
28
  def _create_chat(self) -> bool:
28
29
  """创建新的对话会话"""
@@ -221,6 +222,10 @@ class KimiModel(BaseModel):
221
222
  response = requests.post(url, headers=headers, json=payload, stream=True)
222
223
  full_response = ""
223
224
 
225
+ # 收集搜索和引用结果
226
+ search_results = []
227
+ ref_sources = []
228
+
224
229
  PrettyOutput.print("接收响应...", OutputType.PROGRESS)
225
230
  for line in response.iter_lines():
226
231
  if not line:
@@ -232,15 +237,90 @@ class KimiModel(BaseModel):
232
237
 
233
238
  try:
234
239
  data = json.loads(line[6:])
235
- if data.get("event") == "cmpl":
240
+ event = data.get("event")
241
+
242
+ if event == "cmpl":
243
+ # 处理补全文本
236
244
  text = data.get("text", "")
237
245
  if text:
238
246
  PrettyOutput.print_stream(text, OutputType.SYSTEM)
239
247
  full_response += text
248
+
249
+ elif event == "search_plus":
250
+ # 收集搜索结果
251
+ msg = data.get("msg", {})
252
+ if msg.get("type") == "get_res":
253
+ search_results.append({
254
+ "date": msg.get("date", ""),
255
+ "site_name": msg.get("site_name", ""),
256
+ "snippet": msg.get("snippet", ""),
257
+ "title": msg.get("title", ""),
258
+ "type": msg.get("type", ""),
259
+ "url": msg.get("url", "")
260
+ })
261
+
262
+ elif event == "ref_docs":
263
+ # 收集引用来源
264
+ ref_cards = data.get("ref_cards", [])
265
+ for card in ref_cards:
266
+ ref_sources.append({
267
+ "idx_s": card.get("idx_s", ""),
268
+ "idx_z": card.get("idx_z", ""),
269
+ "ref_id": card.get("ref_id", ""),
270
+ "url": card.get("url", ""),
271
+ "title": card.get("title", ""),
272
+ "abstract": card.get("abstract", ""),
273
+ "source": card.get("source_label", ""),
274
+ "rag_segments": card.get("rag_segments", []),
275
+ "origin": card.get("origin", {})
276
+ })
277
+
240
278
  except json.JSONDecodeError:
241
279
  continue
242
280
 
243
281
  PrettyOutput.print_stream_end()
282
+
283
+ # 只在verbose模式下显示搜索和引用信息
284
+ if self.verbose:
285
+ # 显示搜索结果摘要
286
+ if search_results:
287
+ PrettyOutput.print("\n搜索结果:", OutputType.INFO)
288
+ for result in search_results:
289
+ PrettyOutput.print(f"- {result['title']}", OutputType.INFO)
290
+ if result['date']:
291
+ PrettyOutput.print(f" 日期: {result['date']}", OutputType.INFO)
292
+ PrettyOutput.print(f" 来源: {result['site_name']}", OutputType.INFO)
293
+ if result['snippet']:
294
+ PrettyOutput.print(f" 摘要: {result['snippet']}", OutputType.INFO)
295
+ PrettyOutput.print(f" 链接: {result['url']}", OutputType.INFO)
296
+ PrettyOutput.print("", OutputType.INFO)
297
+
298
+ # 显示引用来源
299
+ if ref_sources:
300
+ PrettyOutput.print("\n引用来源:", OutputType.INFO)
301
+ for source in ref_sources:
302
+ PrettyOutput.print(f"- [{source['ref_id']}] {source['title']} ({source['source']})", OutputType.INFO)
303
+ PrettyOutput.print(f" 链接: {source['url']}", OutputType.INFO)
304
+ if source['abstract']:
305
+ PrettyOutput.print(f" 摘要: {source['abstract']}", OutputType.INFO)
306
+
307
+ # 显示相关段落
308
+ if source['rag_segments']:
309
+ PrettyOutput.print(" 相关段落:", OutputType.INFO)
310
+ for segment in source['rag_segments']:
311
+ text = segment.get('text', '').replace('\n', ' ').strip()
312
+ if text:
313
+ PrettyOutput.print(f" - {text}", OutputType.INFO)
314
+
315
+ # 显示原文引用
316
+ origin = source['origin']
317
+ if origin:
318
+ text = origin.get('text', '')
319
+ if text:
320
+ PrettyOutput.print(f" 原文: {text}", OutputType.INFO)
321
+
322
+ PrettyOutput.print("", OutputType.INFO)
323
+
244
324
  return full_response
245
325
 
246
326
  except Exception as e:
@@ -30,7 +30,7 @@ class Tool:
30
30
  return self.func(arguments)
31
31
 
32
32
  class ToolRegistry:
33
- def __init__(self, output_handler=None):
33
+ def __init__(self, output_handler=None, verbose=False):
34
34
  """初始化工具注册器
35
35
 
36
36
  Args:
@@ -38,7 +38,7 @@ class ToolRegistry:
38
38
  """
39
39
  self.tools: Dict[str, Tool] = {}
40
40
  self.output_handler = output_handler or PrettyOutput
41
-
41
+ self.verbose = verbose
42
42
  # 加载内置工具和外部工具
43
43
  self._load_builtin_tools()
44
44
  self._load_external_tools()
@@ -106,7 +106,7 @@ class ToolRegistry:
106
106
  hasattr(item, 'parameters')):
107
107
 
108
108
  # 实例化工具类,传入模型和输出处理器
109
- tool_instance = item(model=KimiModel(), register=self, output_handler=self.output_handler)
109
+ tool_instance = item(model=KimiModel(self.verbose), register=self, output_handler=self.output_handler)
110
110
 
111
111
  # 注册工具
112
112
  self.register_tool(
@@ -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
+ }
@@ -95,7 +95,7 @@ class PrettyOutput:
95
95
  return formatted_text
96
96
 
97
97
  @staticmethod
98
- def print(text: str, output_type: OutputType, timestamp: bool = True):
98
+ def print(text: str, output_type: OutputType, timestamp: bool = False):
99
99
  """打印格式化的输出"""
100
100
  print(PrettyOutput.format(text, output_type, timestamp))
101
101
 
@@ -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.24
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
@@ -25,6 +25,7 @@ src/jarvis/tools/base.py
25
25
  src/jarvis/tools/file_ops.py
26
26
  src/jarvis/tools/generator.py
27
27
  src/jarvis/tools/shell.py
28
+ src/jarvis/tools/sub_agent.py
28
29
  src/jarvis/tools/__pycache__/__init__.cpython-313.pyc
29
30
  src/jarvis/tools/__pycache__/base.cpython-313.pyc
30
31
  src/jarvis/tools/__pycache__/bing_search.cpython-313.pyc