jarvis-ai-assistant 0.1.16__py3-none-any.whl → 0.1.18__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.16"
3
+ __version__ = "0.1.18"
Binary file
Binary file
Binary file
jarvis/agent.py CHANGED
@@ -77,12 +77,13 @@ class Agent:
77
77
  except Exception as e:
78
78
  raise Exception(f"{self.name}: 模型调用失败: {str(e)}")
79
79
 
80
- def run(self, user_input: str, file_list: Optional[List[str]] = None):
80
+ def run(self, user_input: str, file_list: Optional[List[str]] = None, keep_history: bool = False):
81
81
  """处理用户输入并返回响应,返回任务总结报告
82
82
 
83
83
  Args:
84
84
  user_input: 用户输入的任务描述
85
85
  file_list: 可选的文件列表,默认为None
86
+ keep_history: 是否保留对话历史,默认为False
86
87
 
87
88
  Returns:
88
89
  str: 任务总结报告
@@ -245,11 +246,12 @@ arguments:
245
246
  return f"Task failed: {str(e)}"
246
247
 
247
248
  finally:
248
- # 确保在所有情况下都删除会话
249
- try:
250
- self.model.delete_chat()
251
- except Exception as e:
252
- PrettyOutput.print(f"清理会话时发生错误: {str(e)}", OutputType.ERROR)
249
+ # 只在不保留历史时删除会话
250
+ if not keep_history:
251
+ try:
252
+ self.model.delete_chat()
253
+ except Exception as e:
254
+ PrettyOutput.print(f"清理会话时发生错误: {str(e)}", OutputType.ERROR)
253
255
 
254
256
  def clear_history(self):
255
257
  """清除对话历史,只保留系统提示"""
jarvis/main.py CHANGED
@@ -90,6 +90,7 @@ def main():
90
90
  # Add argument parser
91
91
  parser = argparse.ArgumentParser(description='Jarvis AI Assistant')
92
92
  parser.add_argument('-f', '--files', nargs='*', help='List of files to process')
93
+ parser.add_argument('--keep-history', action='store_true', help='Keep chat history (do not delete chat session)')
93
94
  args = parser.parse_args()
94
95
 
95
96
  load_env_from_file()
@@ -120,11 +121,13 @@ def main():
120
121
 
121
122
  model = KimiModel(kimi_api_key)
122
123
 
123
- tool_registry = ToolRegistry(model)
124
+ tool_registry = ToolRegistry()
124
125
  agent = Agent(model, tool_registry)
125
126
 
126
127
  # 欢迎信息
127
128
  PrettyOutput.print(f"Jarvis 已初始化 - With Kimi", OutputType.SYSTEM)
129
+ if args.keep_history:
130
+ PrettyOutput.print("已启用历史保留模式", OutputType.INFO)
128
131
 
129
132
  # 加载预定义任务
130
133
  tasks = load_tasks()
@@ -132,7 +135,7 @@ def main():
132
135
  selected_task = select_task(tasks)
133
136
  if selected_task:
134
137
  PrettyOutput.print(f"\n执行任务: {selected_task}", OutputType.INFO)
135
- agent.run(selected_task, args.files)
138
+ agent.run(selected_task, args.files, keep_history=args.keep_history)
136
139
  return 0
137
140
 
138
141
  # 如果没有选择预定义任务,进入交互模式
@@ -141,7 +144,7 @@ def main():
141
144
  user_input = get_multiline_input("请输入您的任务(输入空行退出):")
142
145
  if not user_input or user_input == "__interrupt__":
143
146
  break
144
- agent.run(user_input, args.files)
147
+ agent.run(user_input, args.files, keep_history=args.keep_history)
145
148
  except Exception as e:
146
149
  PrettyOutput.print(f"错误: {str(e)}", OutputType.ERROR)
147
150
 
jarvis/models/kimi.py CHANGED
@@ -261,7 +261,7 @@ class KimiModel(BaseModel):
261
261
  response = requests.delete(url, headers=headers)
262
262
  if response.status_code == 200:
263
263
  PrettyOutput.print("会话已删除", OutputType.SUCCESS)
264
- self.chat_id = "" # 清除会话ID
264
+ self.reset()
265
265
  return True
266
266
  else:
267
267
  PrettyOutput.print(f"删除会话失败: HTTP {response.status_code}", OutputType.ERROR)
@@ -272,8 +272,6 @@ class KimiModel(BaseModel):
272
272
 
273
273
  def reset(self):
274
274
  """重置对话"""
275
- if self.chat_id:
276
- self.delete_chat() # 删除现有会话
277
275
  self.chat_id = ""
278
276
  self.uploaded_files = []
279
277
  self.first_chat = True # 重置first_chat标记
jarvis/tools/__init__.py CHANGED
@@ -1,10 +1,12 @@
1
1
  from .base import Tool, ToolRegistry
2
2
  from .file_ops import FileOperationTool
3
3
  from .shell import ShellTool
4
+ from .generator import ToolGeneratorTool
4
5
 
5
6
  __all__ = [
6
7
  'Tool',
7
8
  'ToolRegistry',
8
9
  'FileOperationTool',
9
10
  'ShellTool',
11
+ 'ToolGeneratorTool',
10
12
  ]
jarvis/tools/base.py CHANGED
@@ -1,5 +1,12 @@
1
- from typing import Dict, Any, List, Optional, Callable
1
+ from typing import Dict, Any, List, Optional, Callable, Type
2
2
  import json
3
+ import os
4
+ import importlib.util
5
+ from pathlib import Path
6
+ import sys
7
+
8
+ from jarvis.models.kimi import KimiModel
9
+
3
10
  from ..utils import PrettyOutput, OutputType
4
11
  from ..models import BaseModel
5
12
 
@@ -11,7 +18,7 @@ class Tool:
11
18
  self.func = func
12
19
 
13
20
  def to_dict(self) -> Dict:
14
- """转换为Ollama工具格式"""
21
+ """转换为工具格式"""
15
22
  return {
16
23
  "name": self.name,
17
24
  "description": self.description,
@@ -23,28 +30,103 @@ class Tool:
23
30
  return self.func(arguments)
24
31
 
25
32
  class ToolRegistry:
26
- def __init__(self, model: BaseModel):
33
+ def __init__(self, output_handler=None):
34
+ """初始化工具注册器
35
+
36
+ Args:
37
+ output_handler: 输出处理器 (可选)
38
+ """
27
39
  self.tools: Dict[str, Tool] = {}
28
- self.model = model
29
- self._register_default_tools()
40
+ self.output_handler = output_handler or PrettyOutput
41
+
42
+ # 加载内置工具和外部工具
43
+ self._load_builtin_tools()
44
+ self._load_external_tools()
30
45
 
31
- def _register_default_tools(self):
32
- """注册所有默认工具"""
33
- from .shell import ShellTool
34
- from .file_ops import FileOperationTool
46
+ def _load_builtin_tools(self):
47
+ """从内置tools目录加载工具"""
48
+ tools_dir = Path(__file__).parent
49
+
50
+ # 遍历目录下的所有.py文件
51
+ for file_path in tools_dir.glob("*.py"):
52
+ # 跳过基础文件和__init__.py
53
+ if file_path.name in ["base.py", "__init__.py"]:
54
+ continue
55
+
56
+ self.register_tool_by_file(file_path)
35
57
 
36
- tools = [
37
- ShellTool(),
38
- FileOperationTool(),
39
- ]
58
+ def _load_external_tools(self):
59
+ """从~/.jarvis_tools加载外部工具"""
60
+ external_tools_dir = Path.home() / '.jarvis_tools'
61
+ if not external_tools_dir.exists():
62
+ return
63
+
64
+ # 遍历目录下的所有.py文件
65
+ for file_path in external_tools_dir.glob("*.py"):
66
+ # 跳过__init__.py
67
+ if file_path.name == "__init__.py":
68
+ continue
69
+
70
+ self.register_tool_by_file(file_path)
40
71
 
41
- for tool in tools:
42
- self.register_tool(
43
- name=tool.name,
44
- description=tool.description,
45
- parameters=tool.parameters,
46
- func=tool.execute
47
- )
72
+ def register_tool_by_file(self, file_path: str):
73
+ """从指定文件加载并注册工具
74
+
75
+ Args:
76
+ file_path: 工具文件的路径
77
+
78
+ Returns:
79
+ bool: 是否成功加载工具
80
+ """
81
+ try:
82
+ file_path = Path(file_path).resolve() # 获取绝对路径
83
+ if not file_path.exists() or not file_path.is_file():
84
+ self.output_handler.print(f"文件不存在: {file_path}", OutputType.ERROR)
85
+ return False
86
+
87
+ # 动态导入模块
88
+ module_name = file_path.stem
89
+ spec = importlib.util.spec_from_file_location(module_name, file_path)
90
+ if not spec or not spec.loader:
91
+ self.output_handler.print(f"无法加载模块: {file_path}", OutputType.ERROR)
92
+ return False
93
+
94
+ module = importlib.util.module_from_spec(spec)
95
+ sys.modules[module_name] = module # 添加到 sys.modules 以支持相对导入
96
+ spec.loader.exec_module(module)
97
+
98
+ # 查找模块中的工具类
99
+ tool_found = False
100
+ for item_name in dir(module):
101
+ item = getattr(module, item_name)
102
+ # 检查是否是类,并且有必要的属性
103
+ if (isinstance(item, type) and
104
+ hasattr(item, 'name') and
105
+ hasattr(item, 'description') and
106
+ hasattr(item, 'parameters')):
107
+
108
+ # 实例化工具类,传入模型和输出处理器
109
+ tool_instance = item(model=KimiModel(), register=self, output_handler=self.output_handler)
110
+
111
+ # 注册工具
112
+ self.register_tool(
113
+ name=tool_instance.name,
114
+ description=tool_instance.description,
115
+ parameters=tool_instance.parameters,
116
+ func=tool_instance.execute
117
+ )
118
+ self.output_handler.print(f"已加载工具: {tool_instance.name}", OutputType.INFO)
119
+ tool_found = True
120
+
121
+ if not tool_found:
122
+ self.output_handler.print(f"文件中未找到有效的工具类: {file_path}", OutputType.WARNING)
123
+ return False
124
+
125
+ return True
126
+
127
+ except Exception as e:
128
+ self.output_handler.print(f"加载工具失败 {file_path.name}: {str(e)}", OutputType.ERROR)
129
+ return False
48
130
 
49
131
  def register_tool(self, name: str, description: str, parameters: Dict, func: Callable):
50
132
  """注册新工具"""
jarvis/tools/file_ops.py CHANGED
@@ -1,7 +1,17 @@
1
- from typing import Dict, Any
1
+ from typing import Dict, Any, Protocol, Optional
2
2
  import os
3
3
  from pathlib import Path
4
- from ..utils import PrettyOutput, OutputType
4
+ from enum import Enum
5
+
6
+ class OutputType(Enum):
7
+ INFO = "info"
8
+ ERROR = "error"
9
+
10
+ class OutputHandler(Protocol):
11
+ def print(self, text: str, output_type: OutputType) -> None: ...
12
+
13
+ class ModelHandler(Protocol):
14
+ def chat(self, message: str) -> str: ...
5
15
 
6
16
  class FileOperationTool:
7
17
  name = "file_operation"
@@ -32,6 +42,14 @@ class FileOperationTool:
32
42
  "required": ["operation", "filepath"]
33
43
  }
34
44
 
45
+ def __init__(self, **kwargs):
46
+ self.output = kwargs.get('output_handler')
47
+
48
+ def _print(self, text: str, output_type: OutputType = OutputType.INFO):
49
+ """输出信息"""
50
+ if self.output:
51
+ self.output.print(text, output_type)
52
+
35
53
  def execute(self, args: Dict) -> Dict[str, Any]:
36
54
  """执行文件操作"""
37
55
  try:
@@ -41,7 +59,7 @@ class FileOperationTool:
41
59
 
42
60
  # 记录操作和完整路径
43
61
  abs_path = os.path.abspath(filepath)
44
- PrettyOutput.print(f"文件操作: {operation} - {abs_path}", OutputType.INFO)
62
+ self._print(f"文件操作: {operation} - {abs_path}")
45
63
 
46
64
  if operation == "exists":
47
65
  exists = os.path.exists(filepath)
@@ -100,6 +118,7 @@ class FileOperationTool:
100
118
  }
101
119
 
102
120
  except Exception as e:
121
+ self._print(str(e), OutputType.ERROR)
103
122
  return {
104
123
  "success": False,
105
124
  "error": f"文件操作失败: {str(e)}"
@@ -0,0 +1,223 @@
1
+ from typing import Dict, Any, Protocol, Optional
2
+ import os
3
+ from pathlib import Path
4
+ from enum import Enum
5
+
6
+ class OutputType(Enum):
7
+ INFO = "info"
8
+ ERROR = "error"
9
+
10
+ class OutputHandler(Protocol):
11
+ def print(self, text: str, output_type: OutputType) -> None: ...
12
+
13
+ class ModelHandler(Protocol):
14
+ def chat(self, message: str) -> str: ...
15
+
16
+ class ToolGeneratorTool:
17
+ name = "generate_tool"
18
+ description = "生成新的工具代码并自动注册到ToolRegistry"
19
+ parameters = {
20
+ "type": "object",
21
+ "properties": {
22
+ "tool_name": {
23
+ "type": "string",
24
+ "description": "工具的名称(snake_case格式)"
25
+ },
26
+ "class_name": {
27
+ "type": "string",
28
+ "description": "工具类的名称(PascalCase格式)"
29
+ },
30
+ "description": {
31
+ "type": "string",
32
+ "description": "工具的功能描述"
33
+ },
34
+ "parameters": {
35
+ "type": "object",
36
+ "description": "工具参数的JSON Schema定义"
37
+ }
38
+ },
39
+ "required": ["tool_name", "class_name", "description", "parameters"]
40
+ }
41
+
42
+ def __init__(self, **kwargs):
43
+ """初始化工具生成器
44
+
45
+ Args:
46
+ model: 模型处理器 (必需)
47
+ output_handler: 输出处理器 (可选)
48
+ register: 注册器 (必需)
49
+ tools_dir: 工具目录 (可选,默认为 ~/.jarvis_tools)
50
+ """
51
+ self.register = kwargs.get('register')
52
+ if not self.register:
53
+ raise Exception("Register is required for ToolGeneratorTool")
54
+ self.model = kwargs.get('model')
55
+ if not self.model:
56
+ raise Exception("Model is required for ToolGeneratorTool")
57
+ self.output = kwargs.get('output_handler')
58
+
59
+ # 设置工具目录
60
+ tools_dir = kwargs.get('tools_dir')
61
+ if tools_dir:
62
+ self.tools_dir = Path(tools_dir)
63
+ else:
64
+ self.tools_dir = Path.home() / '.jarvis_tools'
65
+
66
+ # 确保工具目录存在
67
+ self.tools_dir.mkdir(parents=True, exist_ok=True)
68
+
69
+ def _print(self, text: str, output_type: OutputType = OutputType.INFO):
70
+ """输出信息"""
71
+ if self.output:
72
+ self.output.print(text, output_type)
73
+
74
+ def _generate_tool_code(self, tool_name: str, class_name: str, description: str, parameters: Dict) -> str:
75
+ """使用大模型生成工具代码"""
76
+ if not self.model:
77
+ raise Exception("Model not initialized")
78
+
79
+ prompt = f"""请生成一个Python工具类的代码,要求如下:
80
+
81
+ 1. 类名: {class_name}
82
+ 2. 工具名称: {tool_name}
83
+ 3. 功能描述: {description}
84
+ 4. 参数定义: {parameters}
85
+
86
+ 严格按照以下格式生成代码(各函数的参数和返回值一定要与示例一致):
87
+
88
+ ```python
89
+ from typing import Dict, Any, Protocol, Optional
90
+ from enum import Enum
91
+
92
+ class OutputType(Enum):
93
+ INFO = "info"
94
+ ERROR = "error"
95
+
96
+ class OutputHandler(Protocol):
97
+ def print(self, text: str, output_type: OutputType) -> None: ...
98
+
99
+ class ModelHandler(Protocol):
100
+ def chat(self, message: str) -> str: ...
101
+
102
+ class ExampleTool:
103
+ name = "example_tool"
104
+ description = "示例工具"
105
+ parameters = {{
106
+ "type": "object",
107
+ "properties": {{
108
+ "param1": {{"type": "string"}}
109
+ }},
110
+ "required": ["param1"]
111
+ }}
112
+
113
+ def __init__(self, **kwargs):
114
+ '''初始化工具
115
+ Args:
116
+ model: 模型处理器
117
+ output_handler: 输出处理器
118
+ register: 注册器
119
+ '''
120
+ self.model = kwargs.get('model')
121
+ self.output = kwargs.get('output_handler')
122
+ self.register = kwargs.get('register')
123
+
124
+ def _print(self, text: str, output_type: OutputType = OutputType.INFO):
125
+ if self.output:
126
+ self.output.print(text, output_type)
127
+
128
+ def execute(self, args: Dict) -> Dict[str, Any]:
129
+ try:
130
+ # 验证参数
131
+ if "param1" not in args:
132
+ return {{"success": False, "error": "缺少必需参数: param1"}}
133
+
134
+ # 记录操作
135
+ self._print(f"处理参数: {{args['param1']}}")
136
+
137
+ # 实现具体功能
138
+ result = "处理结果"
139
+
140
+ return {{
141
+ "success": True,
142
+ "stdout": result,
143
+ "stderr": ""
144
+ }}
145
+ except Exception as e:
146
+ self._print(str(e), OutputType.ERROR)
147
+ return {{
148
+ "success": False,
149
+ "error": str(e)
150
+ }}
151
+ ```"""
152
+
153
+ # 调用模型生成代码
154
+ response = self.model.chat(prompt)
155
+ self.model.delete_chat()
156
+
157
+ # 提取代码块
158
+ code_start = response.find("```python")
159
+ code_end = response.rfind("```")
160
+
161
+ if code_start == -1 or code_end == -1:
162
+ # 如果没有找到代码块标记,假设整个响应都是代码
163
+ return response
164
+
165
+ # 提取代码块内容(去掉```python和```标记)
166
+ code = response[code_start + 9:code_end].strip()
167
+ return code
168
+
169
+ def execute(self, args: Dict) -> Dict[str, Any]:
170
+ """生成工具代码"""
171
+ try:
172
+ tool_name = args["tool_name"]
173
+ class_name = args["class_name"]
174
+ description = args["description"]
175
+ parameters = args["parameters"]
176
+
177
+ self._print(f"开始生成工具: {tool_name}")
178
+
179
+ # 生成工具代码
180
+ tool_code = self._generate_tool_code(
181
+ tool_name,
182
+ class_name,
183
+ description,
184
+ parameters
185
+ )
186
+
187
+ # 获取工具文件路径
188
+ tool_file = self.tools_dir / f"{tool_name}.py"
189
+
190
+ # 写入工具文件
191
+ with open(tool_file, "w", encoding="utf-8") as f:
192
+ f.write(tool_code)
193
+
194
+ # 创建或更新 __init__.py
195
+ init_file = self.tools_dir / "__init__.py"
196
+ if not init_file.exists():
197
+ with open(init_file, "w", encoding="utf-8") as f:
198
+ f.write("# Jarvis Tools\n")
199
+
200
+ # 注册工具
201
+ success = self.register.register_tool_by_file(tool_file)
202
+ if not success:
203
+ return {
204
+ "success": False,
205
+ "error": "工具生成成功但注册失败"
206
+ }
207
+
208
+ return {
209
+ "success": True,
210
+ "stdout": f"工具已生成并注册到Jarvis\n"
211
+ f"工具目录: {self.tools_dir}\n"
212
+ f"工具名称: {tool_name}\n"
213
+ f"工具描述: {description}\n"
214
+ f"工具参数: {parameters}",
215
+ "stderr": ""
216
+ }
217
+
218
+ except Exception as e:
219
+ self._print(str(e), OutputType.ERROR)
220
+ return {
221
+ "success": False,
222
+ "error": f"生成工具失败: {str(e)}"
223
+ }
jarvis/tools/shell.py CHANGED
@@ -1,9 +1,18 @@
1
- from typing import Dict, Any
1
+ from typing import Dict, Any, Protocol, Optional
2
2
  import os
3
3
  import tempfile
4
- import shlex
5
4
  from pathlib import Path
6
- from ..utils import PrettyOutput, OutputType
5
+ from enum import Enum
6
+
7
+ class OutputType(Enum):
8
+ INFO = "info"
9
+ ERROR = "error"
10
+
11
+ class OutputHandler(Protocol):
12
+ def print(self, text: str, output_type: OutputType) -> None: ...
13
+
14
+ class ModelHandler(Protocol):
15
+ def chat(self, message: str) -> str: ...
7
16
 
8
17
  class ShellTool:
9
18
  name = "execute_shell"
@@ -14,15 +23,22 @@ class ShellTool:
14
23
  "properties": {
15
24
  "command": {
16
25
  "type": "string",
17
- "description": "Shell command to execute (filter output when possible)"
26
+ "description": "Shell command to execute"
18
27
  }
19
28
  },
20
29
  "required": ["command"]
21
30
  }
22
31
 
32
+ def __init__(self, **kwargs):
33
+ self.output = kwargs.get('output_handler')
34
+
35
+ def _print(self, text: str, output_type: OutputType = OutputType.INFO):
36
+ """输出信息"""
37
+ if self.output:
38
+ self.output.print(text, output_type)
39
+
23
40
  def _escape_command(self, cmd: str) -> str:
24
41
  """转义命令中的特殊字符"""
25
- # 将命令中的单引号替换为'"'"'
26
42
  return cmd.replace("'", "'\"'\"'")
27
43
 
28
44
  def execute(self, args: Dict) -> Dict[str, Any]:
@@ -39,7 +55,7 @@ class ShellTool:
39
55
  # 修改命令以使用script
40
56
  tee_command = f"script -q -c '{escaped_command}' {output_file}"
41
57
 
42
- PrettyOutput.print(f"执行命令: {command}", OutputType.INFO)
58
+ self._print(f"执行命令: {command}")
43
59
 
44
60
  # 执行命令
45
61
  return_code = os.system(tee_command)
@@ -70,6 +86,7 @@ class ShellTool:
70
86
  # 确保清理临时文件
71
87
  if 'output_file' in locals():
72
88
  Path(output_file).unlink(missing_ok=True)
89
+ self._print(str(e), OutputType.ERROR)
73
90
  return {
74
91
  "success": False,
75
92
  "error": str(e)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: jarvis-ai-assistant
3
- Version: 0.1.16
3
+ Version: 0.1.18
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
@@ -87,6 +87,9 @@ Dynamic: requires-python
87
87
  - File operations (read/write/append)
88
88
  - Task automation
89
89
  - Predefined task support
90
+ - Dynamic tool system with auto-loading
91
+ - AI-powered tool generation
92
+ - Custom tool development
90
93
 
91
94
  🔄 **Interactive Experience**
92
95
  - Natural language understanding
@@ -95,6 +98,139 @@ Dynamic: requires-python
95
98
  - Multi-line input support
96
99
  - Colored output with progress indicators
97
100
 
101
+ ## 🛠️ Custom Tools
102
+
103
+ ### Tool Locations
104
+ - Built-in tools: `src/jarvis/tools/`
105
+ - User tools: `~/.jarvis_tools/` (automatically created)
106
+
107
+ ### Creating Tools
108
+
109
+ #### 1. Using AI Generator (Recommended)
110
+ ```yaml
111
+ <START_TOOL_CALL>
112
+ name: generate_tool
113
+ arguments:
114
+ tool_name: calculator
115
+ class_name: CalculatorTool
116
+ description: Basic math calculations
117
+ parameters:
118
+ type: object
119
+ properties:
120
+ operation:
121
+ type: string
122
+ enum: ["add", "subtract", "multiply", "divide"]
123
+ numbers:
124
+ type: array
125
+ items:
126
+ type: number
127
+ required: ["operation", "numbers"]
128
+ <END_TOOL_CALL>
129
+ ```
130
+
131
+ #### 2. Manual Creation
132
+ Create a new Python file in `~/.jarvis_tools/`:
133
+
134
+ ```python
135
+ from typing import Dict, Any, Protocol, Optional
136
+ from enum import Enum
137
+
138
+ class OutputType(Enum):
139
+ INFO = "info"
140
+ ERROR = "error"
141
+
142
+ class OutputHandler(Protocol):
143
+ def print(self, text: str, output_type: OutputType) -> None: ...
144
+
145
+ class ModelHandler(Protocol):
146
+ def chat(self, message: str) -> str: ...
147
+
148
+ class CustomTool:
149
+ name = "tool_name" # Tool name for invocation
150
+ description = "Tool description" # Tool purpose
151
+ parameters = { # JSON Schema for parameters
152
+ "type": "object",
153
+ "properties": {
154
+ "param1": {"type": "string"}
155
+ },
156
+ "required": ["param1"]
157
+ }
158
+
159
+ def __init__(self, **kwargs):
160
+ """Initialize tool with optional dependencies
161
+
162
+ Args:
163
+ model: AI model for advanced features
164
+ output_handler: For consistent output formatting
165
+ register: Access to tool registry
166
+ """
167
+ self.model = kwargs.get('model')
168
+ self.output = kwargs.get('output_handler')
169
+ self.register = kwargs.get('register')
170
+
171
+ def _print(self, text: str, output_type: OutputType = OutputType.INFO):
172
+ """Print formatted output"""
173
+ if self.output:
174
+ self.output.print(text, output_type)
175
+
176
+ def execute(self, args: Dict) -> Dict[str, Any]:
177
+ """Execute tool functionality
178
+
179
+ Args:
180
+ args: Parameters passed to the tool
181
+
182
+ Returns:
183
+ Dict with execution results:
184
+ {
185
+ "success": bool,
186
+ "stdout": str, # On success
187
+ "stderr": str, # Optional error details
188
+ "error": str # On failure
189
+ }
190
+ """
191
+ try:
192
+ # Implement tool logic here
193
+ result = "Tool execution result"
194
+
195
+ return {
196
+ "success": True,
197
+ "stdout": result,
198
+ "stderr": ""
199
+ }
200
+ except Exception as e:
201
+ self._print(str(e), OutputType.ERROR)
202
+ return {
203
+ "success": False,
204
+ "error": str(e)
205
+ }
206
+ ```
207
+
208
+ ### Development Guidelines
209
+
210
+ 1. **Tool Structure**
211
+ - Clear name and description
212
+ - Well-defined parameters schema
213
+ - Proper error handling
214
+ - Consistent output format
215
+
216
+ 2. **Best Practices**
217
+ - Use `_print` for output
218
+ - Handle all required parameters
219
+ - Document functionality
220
+ - Return standardized results
221
+ - Keep tools focused and simple
222
+
223
+ 3. **Testing**
224
+ - Verify parameter validation
225
+ - Test error handling
226
+ - Check output format
227
+ - Ensure proper cleanup
228
+
229
+ 4. **Integration**
230
+ - Tools are auto-loaded on startup
231
+ - No manual registration needed
232
+ - Hot-reload supported
233
+ - Dependencies injected automatically
98
234
 
99
235
  ## ⚙️ Environment Setup
100
236
 
@@ -0,0 +1,44 @@
1
+ jarvis/__init__.py,sha256=_f28_I38xy1i_kwbYg6iIU59t_tF8apmhCpqrc4yWvQ,50
2
+ jarvis/agent.py,sha256=f8RIOFIiwRAuql4O32P_nDXByzBKbrNM-ergf_F8FfU,9409
3
+ jarvis/main.py,sha256=CwqsXKTxeZ3rWwdHfhMyzX1DFJC3NA7D-Sbla0YkdSE,7046
4
+ jarvis/utils.py,sha256=YipQpEuIRwFE3y3YrgGlSVLEPDrlbBNY1gRiOJix9DU,6602
5
+ jarvis/__pycache__/__init__.cpython-313.pyc,sha256=PGPqHZavqZ2fSStY_yJGNQjMt49Af70vSbxInRVxFwM,209
6
+ jarvis/__pycache__/agent.cpython-313.pyc,sha256=anFGVa4pfpsOCDbstPAPSsUmglCZUrRkuDN-jnvhSyI,12152
7
+ jarvis/__pycache__/main.cpython-313.pyc,sha256=fvBChS8JvPs2jNR4cYyRJi10n7TVph1RAZtp-AkESuo,9669
8
+ jarvis/__pycache__/models.cpython-313.pyc,sha256=uWuRIjGrY4YDB3dGW5PGDLWaS03et8g11O725TjY_eU,5960
9
+ jarvis/__pycache__/tools.cpython-313.pyc,sha256=lAD4LrnnWzNZQmHXGfZ_2l7oskOpr2_2OC-gdFhxQY8,33933
10
+ jarvis/__pycache__/utils.cpython-313.pyc,sha256=Jpkf2GOA1d_fgrRftqZch1yiO0mB75LWHzQk8IfhHRU,8977
11
+ jarvis/__pycache__/zte_llm.cpython-313.pyc,sha256=kMm9IGundGmOPqjsgrm9oIaWLDagYGCPRAaE3ipkc-0,5662
12
+ jarvis/models/__init__.py,sha256=B_IJFvKTaxdg19FAD1ea288tYp3-bRYRpkeGI0_OcBI,262
13
+ jarvis/models/base.py,sha256=GgVl5N0qDqn-yqRcX_PX3wHjogouE6GPFAWktG40cXg,403
14
+ jarvis/models/kimi.py,sha256=CR3rU4wPSUQjmYOP516NXLU6h3YtcF6taB-4da3-rA4,10690
15
+ jarvis/models/__pycache__/__init__.cpython-313.pyc,sha256=jAwySX4diR7EWM_alK75tiIb_J8bVfs4Bh_U3bdjDLo,534
16
+ jarvis/models/__pycache__/base.cpython-313.pyc,sha256=4I9KZlXHvTB7vENA9YWK4Fx0sns_KvIOtWqzE9y_-Co,1094
17
+ jarvis/models/__pycache__/kimi.cpython-313.pyc,sha256=-hOwhZrfvqfd5K_c34Tm-uR3gaZ9r6EV1NtwV0-FDmg,13647
18
+ jarvis/tools/__init__.py,sha256=AjmFYLXt-_ulZXdYiXya2fD7QCJ-RaK91PEZCNj-UbA,262
19
+ jarvis/tools/base.py,sha256=ZHmRczYks7CuaYHU9uB5QnsD40G_jeqE6ubuhlaSFR8,7318
20
+ jarvis/tools/file_ops.py,sha256=KbQLVCCXw-MtJg-12iyMeVGu8BTtLq7Mk7fpVKau40U,4296
21
+ jarvis/tools/generator.py,sha256=A_J7U9_Vjh37zotGkt5VDM8As1BfNawM-6vbclJ4PR4,7142
22
+ jarvis/tools/shell.py,sha256=MWe9-BAGApbGJfR60XG4nElGYHNBnbdF9vsOQTnEZ4g,2989
23
+ jarvis/tools/__pycache__/__init__.cpython-313.pyc,sha256=KC48FS57427navbkxZ0eDKLePMCH2BKc5vAIu0b8lFc,404
24
+ jarvis/tools/__pycache__/base.cpython-313.pyc,sha256=r-jPPg5L_Rok2c_VsMEAXkhuiiUjHv6bLCwVjnONDRo,9861
25
+ jarvis/tools/__pycache__/bing_search.cpython-313.pyc,sha256=1G_wPbk5wcQYh7H0drLIS2Aw0XOG2ZM8ztgfQaqu3P8,2031
26
+ jarvis/tools/__pycache__/calculator.cpython-313.pyc,sha256=C_qwTDGm6gc7QNxtPzPZXyStdKEintJVQIt5NMHQ8oY,4205
27
+ jarvis/tools/__pycache__/calculator_tool.cpython-313.pyc,sha256=PI4LZNDTPdSe3ffWDRovLZ-r-vF8Kl-n6xdGdFWiBpY,4296
28
+ jarvis/tools/__pycache__/file_ops.cpython-313.pyc,sha256=OBR2EDQ2Ana7CTtLOoM5AYJzyVwP683LS7QrOR8_I3g,5208
29
+ jarvis/tools/__pycache__/generator.cpython-313.pyc,sha256=sOpj8PBTUwYSVrWhBr-ESK43lSP0HOkRUJdEpLD6PPY,8482
30
+ jarvis/tools/__pycache__/python_script.cpython-313.pyc,sha256=8JpryqTovEiTvBlWAK1KjZmPvHUuPc9GT9rTXBEQoJc,6693
31
+ jarvis/tools/__pycache__/rag.cpython-313.pyc,sha256=JH6-PSZRMKAvTZqCwlRXJGClxYXNMs-vetU0q7hBLz0,6064
32
+ jarvis/tools/__pycache__/search.cpython-313.pyc,sha256=wLMIkFwT-h4NGHgssytT4xme7sGO6ZhEnex7kjcy0-k,5990
33
+ 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__/user_confirmation.cpython-313.pyc,sha256=wK3Ev10lHSUSRvoYmi7A0GzxYkzU-C4Wfhs5qW_HBqs,2271
36
+ jarvis/tools/__pycache__/user_input.cpython-313.pyc,sha256=JjTFOhObKsKF4Pn8KBRuKfV1_Ssj083fjU7Mfc_5z7c,2531
37
+ jarvis/tools/__pycache__/user_interaction.cpython-313.pyc,sha256=RuVZ-pmiPBDywY3efgXSfohMAciC1avMGPmBK5qlnew,3305
38
+ jarvis/tools/__pycache__/webpage.cpython-313.pyc,sha256=BjzSfnNzsKCrLETCcWjt32lNDLzwnjqcVGg4JfWd9OM,3008
39
+ jarvis_ai_assistant-0.1.18.dist-info/LICENSE,sha256=AGgVgQmTqFvaztRtCAXsAMryUymB18gZif7_l2e1XOg,1063
40
+ jarvis_ai_assistant-0.1.18.dist-info/METADATA,sha256=3n1MHwr3pmlVGHHwG-CX3tLdb-SI7lqLA7UJlFhM528,10193
41
+ jarvis_ai_assistant-0.1.18.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
42
+ jarvis_ai_assistant-0.1.18.dist-info/entry_points.txt,sha256=iKu7OMfew9dtfGhW71gIMTg4wvafuPqKb4wyQOnMAGU,44
43
+ jarvis_ai_assistant-0.1.18.dist-info/top_level.txt,sha256=1BOxyWfzOP_ZXj8rVTDnNCJ92bBGB0rwq8N1PCpoMIs,7
44
+ jarvis_ai_assistant-0.1.18.dist-info/RECORD,,
@@ -1,40 +0,0 @@
1
- jarvis/__init__.py,sha256=IrFrXtY58xy8OQAUNGadwY5YeK6GgT8xcnXUEb2EWb8,50
2
- jarvis/agent.py,sha256=sa8un7OmbGRlSAD4V-Be0Y9-TCT-S_0OFFthEBXWdVs,9267
3
- jarvis/main.py,sha256=QD8FlhpJ-PFUEOjt77gllpHEgqtfNKV_S8NQZSWRTbE,6760
4
- jarvis/utils.py,sha256=YipQpEuIRwFE3y3YrgGlSVLEPDrlbBNY1gRiOJix9DU,6602
5
- jarvis/__pycache__/__init__.cpython-313.pyc,sha256=P5b0eXfExQu7lDPOOOphvz7WiD2NJHJfsRVoYfDdTbw,209
6
- jarvis/__pycache__/agent.cpython-313.pyc,sha256=rrAZtJSYuJZcTL8gdF0S7XdaNQxpMA8BnNrSoLAny_Q,11913
7
- jarvis/__pycache__/main.cpython-313.pyc,sha256=vsL4l0JZFp805S22a0uZR_9k6NhpHrb-YHFY61JXF4M,9279
8
- jarvis/__pycache__/models.cpython-313.pyc,sha256=uWuRIjGrY4YDB3dGW5PGDLWaS03et8g11O725TjY_eU,5960
9
- jarvis/__pycache__/tools.cpython-313.pyc,sha256=lAD4LrnnWzNZQmHXGfZ_2l7oskOpr2_2OC-gdFhxQY8,33933
10
- jarvis/__pycache__/utils.cpython-313.pyc,sha256=Jpkf2GOA1d_fgrRftqZch1yiO0mB75LWHzQk8IfhHRU,8977
11
- jarvis/__pycache__/zte_llm.cpython-313.pyc,sha256=kMm9IGundGmOPqjsgrm9oIaWLDagYGCPRAaE3ipkc-0,5662
12
- jarvis/models/__init__.py,sha256=B_IJFvKTaxdg19FAD1ea288tYp3-bRYRpkeGI0_OcBI,262
13
- jarvis/models/base.py,sha256=GgVl5N0qDqn-yqRcX_PX3wHjogouE6GPFAWktG40cXg,403
14
- jarvis/models/kimi.py,sha256=YzMLC6_grynNVdPzBBmluFHvcDGdikwxMq7Tl7c6JLA,10791
15
- jarvis/models/__pycache__/__init__.cpython-313.pyc,sha256=jAwySX4diR7EWM_alK75tiIb_J8bVfs4Bh_U3bdjDLo,534
16
- jarvis/models/__pycache__/base.cpython-313.pyc,sha256=4I9KZlXHvTB7vENA9YWK4Fx0sns_KvIOtWqzE9y_-Co,1094
17
- jarvis/models/__pycache__/kimi.cpython-313.pyc,sha256=RZIfeTDZgvJX7GyEZJ1NT_22WQJ2CyK5xR8RZ-L6WBQ,13717
18
- jarvis/tools/__init__.py,sha256=000SvX1Z0yzKtuVR9NS45r41DHUVpE6EiSEzzE99uR0,196
19
- jarvis/tools/base.py,sha256=qm73kMOkqAWHjUisUWFye-x69LJuZdwm0U3Tct-mmMc,3890
20
- jarvis/tools/file_ops.py,sha256=zTksx45NZm3iz9itN5iQGZ8DoxnSeTHdrnF08_ix7PU,3770
21
- jarvis/tools/shell.py,sha256=7q52lA3slf0TdjBjP1bkwugoO5pB0eqh6cYjAzAXNtI,2547
22
- jarvis/tools/__pycache__/__init__.cpython-313.pyc,sha256=6BQJ333a0Oh9uEDLlgh0HHeXS34I7NaPs9KFQI-sil8,347
23
- jarvis/tools/__pycache__/base.cpython-313.pyc,sha256=ZfkdDuQDiCuA7V3qx69coGwrkchLPqNDF6tCGPXKflU,6197
24
- jarvis/tools/__pycache__/bing_search.cpython-313.pyc,sha256=1G_wPbk5wcQYh7H0drLIS2Aw0XOG2ZM8ztgfQaqu3P8,2031
25
- jarvis/tools/__pycache__/file_ops.cpython-313.pyc,sha256=LbOp31JUzoRp5XVazy1VBqCQhpFg0qQYmVftFVY90V4,3628
26
- jarvis/tools/__pycache__/python_script.cpython-313.pyc,sha256=8JpryqTovEiTvBlWAK1KjZmPvHUuPc9GT9rTXBEQoJc,6693
27
- jarvis/tools/__pycache__/rag.cpython-313.pyc,sha256=JH6-PSZRMKAvTZqCwlRXJGClxYXNMs-vetU0q7hBLz0,6064
28
- jarvis/tools/__pycache__/search.cpython-313.pyc,sha256=wLMIkFwT-h4NGHgssytT4xme7sGO6ZhEnex7kjcy0-k,5990
29
- jarvis/tools/__pycache__/shell.cpython-313.pyc,sha256=QMaLUc1MtZXWod3msv_x7iMq2IybwMwz1OoaKsbm6U4,3271
30
- jarvis/tools/__pycache__/sub_agent.cpython-313.pyc,sha256=9spmVX8KSQ4qIH7FbXo5tmmZfNx8KfIGtjy2lxTSp4Y,3144
31
- jarvis/tools/__pycache__/user_confirmation.cpython-313.pyc,sha256=wK3Ev10lHSUSRvoYmi7A0GzxYkzU-C4Wfhs5qW_HBqs,2271
32
- jarvis/tools/__pycache__/user_input.cpython-313.pyc,sha256=JjTFOhObKsKF4Pn8KBRuKfV1_Ssj083fjU7Mfc_5z7c,2531
33
- jarvis/tools/__pycache__/user_interaction.cpython-313.pyc,sha256=RuVZ-pmiPBDywY3efgXSfohMAciC1avMGPmBK5qlnew,3305
34
- jarvis/tools/__pycache__/webpage.cpython-313.pyc,sha256=BjzSfnNzsKCrLETCcWjt32lNDLzwnjqcVGg4JfWd9OM,3008
35
- jarvis_ai_assistant-0.1.16.dist-info/LICENSE,sha256=AGgVgQmTqFvaztRtCAXsAMryUymB18gZif7_l2e1XOg,1063
36
- jarvis_ai_assistant-0.1.16.dist-info/METADATA,sha256=MM6V4lp04d0vFDoNIhU6NqFpi8zgXBsMXlX5wAHrJII,6525
37
- jarvis_ai_assistant-0.1.16.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
38
- jarvis_ai_assistant-0.1.16.dist-info/entry_points.txt,sha256=iKu7OMfew9dtfGhW71gIMTg4wvafuPqKb4wyQOnMAGU,44
39
- jarvis_ai_assistant-0.1.16.dist-info/top_level.txt,sha256=1BOxyWfzOP_ZXj8rVTDnNCJ92bBGB0rwq8N1PCpoMIs,7
40
- jarvis_ai_assistant-0.1.16.dist-info/RECORD,,