jarvis-ai-assistant 0.1.102__tar.gz → 0.1.103__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 (71) hide show
  1. {jarvis_ai_assistant-0.1.102/src/jarvis_ai_assistant.egg-info → jarvis_ai_assistant-0.1.103}/PKG-INFO +52 -2
  2. {jarvis_ai_assistant-0.1.102 → jarvis_ai_assistant-0.1.103}/README.md +40 -0
  3. {jarvis_ai_assistant-0.1.102 → jarvis_ai_assistant-0.1.103}/pyproject.toml +18 -3
  4. {jarvis_ai_assistant-0.1.102 → jarvis_ai_assistant-0.1.103}/setup.py +18 -3
  5. {jarvis_ai_assistant-0.1.102 → jarvis_ai_assistant-0.1.103}/src/jarvis/__init__.py +1 -1
  6. {jarvis_ai_assistant-0.1.102 → jarvis_ai_assistant-0.1.103}/src/jarvis/agent.py +138 -117
  7. jarvis_ai_assistant-0.1.103/src/jarvis/jarvis_code_agent/code_agent.py +234 -0
  8. {jarvis_ai_assistant-0.1.102/src/jarvis/jarvis_coder → jarvis_ai_assistant-0.1.103/src/jarvis/jarvis_code_agent}/file_select.py +16 -17
  9. jarvis_ai_assistant-0.1.103/src/jarvis/jarvis_code_agent/patch.py +118 -0
  10. jarvis_ai_assistant-0.1.103/src/jarvis/jarvis_code_agent/relevant_files.py +66 -0
  11. jarvis_ai_assistant-0.1.103/src/jarvis/jarvis_codebase/main.py +878 -0
  12. {jarvis_ai_assistant-0.1.102 → jarvis_ai_assistant-0.1.103}/src/jarvis/jarvis_platform/main.py +5 -3
  13. jarvis_ai_assistant-0.1.103/src/jarvis/jarvis_rag/main.py +818 -0
  14. {jarvis_ai_assistant-0.1.102 → jarvis_ai_assistant-0.1.103}/src/jarvis/jarvis_smart_shell/main.py +2 -2
  15. {jarvis_ai_assistant-0.1.102 → jarvis_ai_assistant-0.1.103}/src/jarvis/models/ai8.py +3 -1
  16. {jarvis_ai_assistant-0.1.102 → jarvis_ai_assistant-0.1.103}/src/jarvis/models/kimi.py +36 -30
  17. {jarvis_ai_assistant-0.1.102 → jarvis_ai_assistant-0.1.103}/src/jarvis/models/ollama.py +17 -11
  18. {jarvis_ai_assistant-0.1.102 → jarvis_ai_assistant-0.1.103}/src/jarvis/models/openai.py +15 -12
  19. {jarvis_ai_assistant-0.1.102 → jarvis_ai_assistant-0.1.103}/src/jarvis/models/oyi.py +24 -7
  20. {jarvis_ai_assistant-0.1.102 → jarvis_ai_assistant-0.1.103}/src/jarvis/models/registry.py +1 -25
  21. jarvis_ai_assistant-0.1.103/src/jarvis/tools/__init__.py +0 -0
  22. jarvis_ai_assistant-0.1.103/src/jarvis/tools/ask_codebase.py +99 -0
  23. {jarvis_ai_assistant-0.1.102 → jarvis_ai_assistant-0.1.103}/src/jarvis/tools/ask_user.py +1 -9
  24. {jarvis_ai_assistant-0.1.102 → jarvis_ai_assistant-0.1.103}/src/jarvis/tools/chdir.py +1 -1
  25. jarvis_ai_assistant-0.1.103/src/jarvis/tools/code_review.py +163 -0
  26. jarvis_ai_assistant-0.1.103/src/jarvis/tools/create_code_sub_agent.py +30 -0
  27. jarvis_ai_assistant-0.1.103/src/jarvis/tools/create_code_test_agent.py +115 -0
  28. jarvis_ai_assistant-0.1.103/src/jarvis/tools/create_ctags_agent.py +176 -0
  29. {jarvis_ai_assistant-0.1.102 → jarvis_ai_assistant-0.1.103}/src/jarvis/tools/create_sub_agent.py +2 -2
  30. {jarvis_ai_assistant-0.1.102 → jarvis_ai_assistant-0.1.103}/src/jarvis/tools/execute_shell.py +2 -2
  31. {jarvis_ai_assistant-0.1.102 → jarvis_ai_assistant-0.1.103}/src/jarvis/tools/file_operation.py +2 -2
  32. jarvis_ai_assistant-0.1.103/src/jarvis/tools/find_in_codebase.py +108 -0
  33. jarvis_ai_assistant-0.1.103/src/jarvis/tools/git_commiter.py +68 -0
  34. {jarvis_ai_assistant-0.1.102 → jarvis_ai_assistant-0.1.103}/src/jarvis/tools/methodology.py +3 -3
  35. jarvis_ai_assistant-0.1.103/src/jarvis/tools/rag.py +141 -0
  36. jarvis_ai_assistant-0.1.103/src/jarvis/tools/read_code.py +147 -0
  37. {jarvis_ai_assistant-0.1.102 → jarvis_ai_assistant-0.1.103}/src/jarvis/tools/read_webpage.py +1 -1
  38. {jarvis_ai_assistant-0.1.102 → jarvis_ai_assistant-0.1.103}/src/jarvis/tools/registry.py +47 -31
  39. {jarvis_ai_assistant-0.1.102 → jarvis_ai_assistant-0.1.103}/src/jarvis/tools/search.py +8 -6
  40. {jarvis_ai_assistant-0.1.102 → jarvis_ai_assistant-0.1.103}/src/jarvis/tools/select_code_files.py +4 -4
  41. jarvis_ai_assistant-0.1.103/src/jarvis/utils.py +604 -0
  42. {jarvis_ai_assistant-0.1.102 → jarvis_ai_assistant-0.1.103/src/jarvis_ai_assistant.egg-info}/PKG-INFO +52 -2
  43. {jarvis_ai_assistant-0.1.102 → jarvis_ai_assistant-0.1.103}/src/jarvis_ai_assistant.egg-info/SOURCES.txt +16 -11
  44. jarvis_ai_assistant-0.1.103/src/jarvis_ai_assistant.egg-info/entry_points.txt +11 -0
  45. jarvis_ai_assistant-0.1.103/src/jarvis_ai_assistant.egg-info/requires.txt +26 -0
  46. jarvis_ai_assistant-0.1.102/src/jarvis/jarvis_code_agent/main.py +0 -200
  47. jarvis_ai_assistant-0.1.102/src/jarvis/jarvis_coder/git_utils.py +0 -123
  48. jarvis_ai_assistant-0.1.102/src/jarvis/jarvis_coder/patch_handler.py +0 -340
  49. jarvis_ai_assistant-0.1.102/src/jarvis/jarvis_github/main.py +0 -232
  50. jarvis_ai_assistant-0.1.102/src/jarvis/tools/__init__.py +0 -6
  51. jarvis_ai_assistant-0.1.102/src/jarvis/tools/create_code_sub_agent.py +0 -56
  52. jarvis_ai_assistant-0.1.102/src/jarvis/tools/execute_code_modification.py +0 -70
  53. jarvis_ai_assistant-0.1.102/src/jarvis/tools/find_files.py +0 -119
  54. jarvis_ai_assistant-0.1.102/src/jarvis/tools/generate_tool.py +0 -174
  55. jarvis_ai_assistant-0.1.102/src/jarvis/tools/thinker.py +0 -151
  56. jarvis_ai_assistant-0.1.102/src/jarvis/utils.py +0 -314
  57. jarvis_ai_assistant-0.1.102/src/jarvis_ai_assistant.egg-info/entry_points.txt +0 -6
  58. jarvis_ai_assistant-0.1.102/src/jarvis_ai_assistant.egg-info/requires.txt +0 -16
  59. {jarvis_ai_assistant-0.1.102 → jarvis_ai_assistant-0.1.103}/LICENSE +0 -0
  60. {jarvis_ai_assistant-0.1.102 → jarvis_ai_assistant-0.1.103}/MANIFEST.in +0 -0
  61. {jarvis_ai_assistant-0.1.102 → jarvis_ai_assistant-0.1.103}/setup.cfg +0 -0
  62. {jarvis_ai_assistant-0.1.102 → jarvis_ai_assistant-0.1.103}/src/jarvis/jarvis_code_agent/__init__.py +0 -0
  63. {jarvis_ai_assistant-0.1.102/src/jarvis/jarvis_coder → jarvis_ai_assistant-0.1.103/src/jarvis/jarvis_codebase}/__init__.py +0 -0
  64. {jarvis_ai_assistant-0.1.102/src/jarvis/jarvis_github → jarvis_ai_assistant-0.1.103/src/jarvis/jarvis_platform}/__init__.py +0 -0
  65. {jarvis_ai_assistant-0.1.102/src/jarvis/jarvis_platform → jarvis_ai_assistant-0.1.103/src/jarvis/jarvis_rag}/__init__.py +0 -0
  66. {jarvis_ai_assistant-0.1.102 → jarvis_ai_assistant-0.1.103}/src/jarvis/jarvis_smart_shell/__init__.py +0 -0
  67. {jarvis_ai_assistant-0.1.102 → jarvis_ai_assistant-0.1.103}/src/jarvis/models/__init__.py +0 -0
  68. {jarvis_ai_assistant-0.1.102 → jarvis_ai_assistant-0.1.103}/src/jarvis/models/base.py +0 -0
  69. {jarvis_ai_assistant-0.1.102 → jarvis_ai_assistant-0.1.103}/src/jarvis/tools/base.py +0 -0
  70. {jarvis_ai_assistant-0.1.102 → jarvis_ai_assistant-0.1.103}/src/jarvis_ai_assistant.egg-info/dependency_links.txt +0 -0
  71. {jarvis_ai_assistant-0.1.102 → jarvis_ai_assistant-0.1.103}/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.102
3
+ Version: 0.1.103
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
@@ -45,10 +45,20 @@ Requires-Dist: colorama>=0.4.6
45
45
  Requires-Dist: prompt_toolkit>=3.0.0
46
46
  Requires-Dist: openai>=1.20.0
47
47
  Requires-Dist: playwright>=1.41.1
48
- Requires-Dist: numpy>=1.24.0
48
+ Requires-Dist: numpy>=1.17.4
49
+ Requires-Dist: faiss-cpu>=1.8.0
50
+ Requires-Dist: sentence-transformers>=2.2.2
49
51
  Requires-Dist: bs4>=0.0.1
52
+ Requires-Dist: PyMuPDF>=1.21.0
53
+ Requires-Dist: python-docx>=0.8.11
54
+ Requires-Dist: tiktoken>=0.3.0
50
55
  Requires-Dist: tqdm>=4.65.0
56
+ Requires-Dist: docx>=0.2.4
51
57
  Requires-Dist: yaspin>=2.5.0
58
+ Requires-Dist: rich>=13.3.1
59
+ Requires-Dist: pygments>=2.15.0
60
+ Requires-Dist: fuzzywuzzy>=0.18.0
61
+ Requires-Dist: python-Levenshtein>=0.26.1
52
62
  Provides-Extra: dev
53
63
  Requires-Dist: pytest; extra == "dev"
54
64
  Requires-Dist: black; extra == "dev"
@@ -148,6 +158,27 @@ Jarvis supports configuration through environment variables that can be set in t
148
158
  jarvis
149
159
  ```
150
160
 
161
+ ### Codebase Search
162
+ ```bash
163
+ # Generate codebase index
164
+ jarvis-codebase generate
165
+
166
+ # Search similar code
167
+ jarvis-codebase search "your search query"
168
+
169
+ # Ask questions about codebase
170
+ jarvis-codebase ask "your question"
171
+ ```
172
+
173
+ ### Document Analysis (RAG)
174
+ ```bash
175
+ # Build document index
176
+ jarvis-rag --dir /path/to/documents --build
177
+
178
+ # Search documents
179
+ jarvis-rag --query "your search query"
180
+ ```
181
+
151
182
  ### Search Tool
152
183
  ```bash
153
184
  # Basic search
@@ -162,6 +193,19 @@ jarvis-search "your query" --max 3
162
193
 
163
194
  ## 🛠️ Tools
164
195
 
196
+
197
+ ### Built-in Tools
198
+
199
+ | Tool | Description |
200
+ |------|-------------|
201
+ | execute_shell | Execute system commands and capture output |
202
+ | file_operation | File operations (read/write/append/delete) |
203
+ | generate_tool | AI-powered tool generation and integration |
204
+ | methodology | Experience accumulation and methodology management |
205
+ | create_sub_agent | Create specialized sub-agents for specific tasks |
206
+ | coder | Automatic code modification and generation tool |
207
+ | codebase | Codebase management and search tool |
208
+
165
209
  ### Tool Locations
166
210
  - Built-in tools: `src/jarvis/tools/`
167
211
  - User tools: `~/.jarvis/tools/`
@@ -174,21 +218,27 @@ jarvis-search "your query" --max 3
174
218
  - Automatic code generation and integration
175
219
  - Dynamic capability expansion through sub-agents
176
220
  - Automatic code modification with version control
221
+ - Codebase indexing and semantic search
177
222
 
178
223
  #### 2. Methodology Learning
179
224
  - Automatic experience accumulation from interactions
180
225
  - Pattern recognition and methodology extraction
181
226
  - Continuous refinement through usage
182
227
  - Code modification history tracking
228
+ - Codebase analysis and documentation generation
183
229
 
184
230
  #### 3. Adaptive Problem Solving
185
231
  - Context-aware sub-agent creation
186
232
  - Dynamic tool composition
187
233
  - Learning from execution feedback
234
+ - Codebase-aware problem solving
188
235
  - Multi-model collaboration for complex tasks
189
236
 
190
237
  #### 4. Code Intelligence
238
+ - Automatic codebase indexing
239
+ - Semantic code search
191
240
  - Code modification with git integration
241
+ - Code analysis and documentation
192
242
  - Multi-model code generation
193
243
 
194
244
  ## 🎯 Extending Jarvis
@@ -88,6 +88,27 @@ Jarvis supports configuration through environment variables that can be set in t
88
88
  jarvis
89
89
  ```
90
90
 
91
+ ### Codebase Search
92
+ ```bash
93
+ # Generate codebase index
94
+ jarvis-codebase generate
95
+
96
+ # Search similar code
97
+ jarvis-codebase search "your search query"
98
+
99
+ # Ask questions about codebase
100
+ jarvis-codebase ask "your question"
101
+ ```
102
+
103
+ ### Document Analysis (RAG)
104
+ ```bash
105
+ # Build document index
106
+ jarvis-rag --dir /path/to/documents --build
107
+
108
+ # Search documents
109
+ jarvis-rag --query "your search query"
110
+ ```
111
+
91
112
  ### Search Tool
92
113
  ```bash
93
114
  # Basic search
@@ -102,6 +123,19 @@ jarvis-search "your query" --max 3
102
123
 
103
124
  ## 🛠️ Tools
104
125
 
126
+
127
+ ### Built-in Tools
128
+
129
+ | Tool | Description |
130
+ |------|-------------|
131
+ | execute_shell | Execute system commands and capture output |
132
+ | file_operation | File operations (read/write/append/delete) |
133
+ | generate_tool | AI-powered tool generation and integration |
134
+ | methodology | Experience accumulation and methodology management |
135
+ | create_sub_agent | Create specialized sub-agents for specific tasks |
136
+ | coder | Automatic code modification and generation tool |
137
+ | codebase | Codebase management and search tool |
138
+
105
139
  ### Tool Locations
106
140
  - Built-in tools: `src/jarvis/tools/`
107
141
  - User tools: `~/.jarvis/tools/`
@@ -114,21 +148,27 @@ jarvis-search "your query" --max 3
114
148
  - Automatic code generation and integration
115
149
  - Dynamic capability expansion through sub-agents
116
150
  - Automatic code modification with version control
151
+ - Codebase indexing and semantic search
117
152
 
118
153
  #### 2. Methodology Learning
119
154
  - Automatic experience accumulation from interactions
120
155
  - Pattern recognition and methodology extraction
121
156
  - Continuous refinement through usage
122
157
  - Code modification history tracking
158
+ - Codebase analysis and documentation generation
123
159
 
124
160
  #### 3. Adaptive Problem Solving
125
161
  - Context-aware sub-agent creation
126
162
  - Dynamic tool composition
127
163
  - Learning from execution feedback
164
+ - Codebase-aware problem solving
128
165
  - Multi-model collaboration for complex tasks
129
166
 
130
167
  #### 4. Code Intelligence
168
+ - Automatic codebase indexing
169
+ - Semantic code search
131
170
  - Code modification with git integration
171
+ - Code analysis and documentation
132
172
  - Multi-model code generation
133
173
 
134
174
  ## 🎯 Extending Jarvis
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "jarvis-ai-assistant"
7
- version = "0.1.102"
7
+ version = "0.1.103"
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" }]
@@ -27,10 +27,20 @@ dependencies = [
27
27
  "prompt_toolkit>=3.0.0",
28
28
  "openai>=1.20.0",
29
29
  "playwright>=1.41.1",
30
- "numpy>=1.24.0",
30
+ "numpy>=1.17.4",
31
+ "faiss-cpu>=1.8.0",
32
+ "sentence-transformers>=2.2.2",
31
33
  "bs4>=0.0.1",
34
+ "PyMuPDF>=1.21.0",
35
+ "python-docx>=0.8.11",
36
+ "tiktoken>=0.3.0",
32
37
  "tqdm>=4.65.0",
38
+ "docx>=0.2.4",
33
39
  "yaspin>=2.5.0",
40
+ "rich>=13.3.1",
41
+ "pygments>=2.15.0",
42
+ "fuzzywuzzy>=0.18.0",
43
+ "python-Levenshtein>=0.26.1",
34
44
  ]
35
45
  requires-python = ">=3.8"
36
46
 
@@ -42,7 +52,12 @@ Homepage = "https://github.com/skyfireitdiy/Jarvis"
42
52
 
43
53
  [project.scripts]
44
54
  jarvis = "jarvis.agent:main"
45
- jarvis-code-agent = "jarvis.jarvis_code_agent.main:main"
55
+ jarvis-code-agent = "jarvis.jarvis_code_agent.code_agent:main"
56
+ jarvis-codebase = "jarvis.jarvis_codebase.main:main"
57
+ jarvis-rag = "jarvis.jarvis_rag.main:main"
46
58
  jarvis-smart-shell = "jarvis.jarvis_smart_shell.main:main"
47
59
  jss = "jarvis.jarvis_smart_shell.main:main"
48
60
  jarvis-platform = "jarvis.jarvis_platform.main:main"
61
+ jarvis-gh = "jarvis.jarvis_github.main:main"
62
+ jarvis-git-commit = "jarvis.tools.git_commiter:main"
63
+ jarvis-ctags = "jarvis.tools.create_ctags_agent:main"
@@ -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.102",
5
+ version="0.1.103",
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",
@@ -19,18 +19,33 @@ setup(
19
19
  "prompt_toolkit>=3.0.0",
20
20
  "openai>=1.20.0",
21
21
  "playwright>=1.41.1",
22
- "numpy>=1.24.0",
22
+ "numpy==1.17.4",
23
+ "faiss-cpu>=1.8.0",
24
+ "sentence-transformers>=2.2.2",
23
25
  "bs4>=0.0.1",
26
+ "PyMuPDF>=1.21.0",
27
+ "python-docx>=0.8.11",
28
+ "tiktoken>=0.3.0",
24
29
  "tqdm>=4.65.0",
30
+ "docx>=0.2.4",
25
31
  "yaspin>=2.5.0",
32
+ "rich>=13.3.1",
33
+ "pygments>=2.15.0",
34
+ "fuzzywuzzy>=0.18.0",
35
+ "python-Levenshtein>=0.26.1",
26
36
  ],
27
37
  entry_points={
28
38
  "console_scripts": [
29
39
  "jarvis=jarvis.agent:main",
30
- "jarvis-code-agent=jarvis.jarvis_code_agent.main:main",
40
+ "jarvis-code-agent=jarvis.jarvis_code_agent.code_agent:main",
41
+ "jarvis-codebase=jarvis.jarvis_codebase.main:main",
42
+ "jarvis-rag=jarvis.jarvis_rag.main:main",
31
43
  "jarvis-smart-shell=jarvis.jarvis_smart_shell.main:main",
32
44
  "jss=jarvis.jarvis_smart_shell.main:main",
33
45
  "jarvis-platform=jarvis.jarvis_platform.main:main",
46
+ "jarvis-gh=jarvis.jarvis_github.main:main",
47
+ "jarvis-git-commit=jarvis.tools.git_commiter:main",
48
+ "jarvis-ctags=jarvis.tools.create_ctags_agent:main",
34
49
  ],
35
50
  },
36
51
  python_requires=">=3.8",
@@ -1,3 +1,3 @@
1
1
  """Jarvis AI Assistant"""
2
2
 
3
- __version__ = "0.1.102"
3
+ __version__ = "0.1.103"
@@ -1,22 +1,38 @@
1
1
  import argparse
2
2
  import time
3
- from typing import Dict, List, Optional
3
+ from typing import Callable, Dict, List, Optional
4
4
 
5
5
  from prompt_toolkit import prompt
6
6
  import yaml
7
7
 
8
+ from jarvis.models.base import BasePlatform
8
9
  from jarvis.models.registry import PlatformRegistry
9
- from jarvis.tools import ToolRegistry
10
- from jarvis.tools.registry import load_tools
11
- from jarvis.utils import PrettyOutput, OutputType, get_single_line_input, load_methodology, add_agent, delete_current_agent, get_max_context_length, get_multiline_input, init_env
10
+ from jarvis.tools.registry import ToolRegistry, tool_call_help
11
+ from jarvis.utils import PrettyOutput, OutputType, is_auto_complete, load_methodology, add_agent, delete_current_agent, get_max_context_length, get_multiline_input, init_env
12
12
  import os
13
13
 
14
14
  class Agent:
15
15
 
16
16
  def __del__(self):
17
17
  delete_current_agent()
18
+
19
+ def set_summary_prompt(self, summary_prompt: str):
20
+ self.summary_prompt = summary_prompt
21
+
22
+ def set_output_filter(self, output_filter: List[Callable]):
23
+ self.output_filter = output_filter
18
24
 
19
- def __init__(self, system_prompt: str, name: str = "Jarvis", is_sub_agent: bool = False, tool_registry: Optional[ToolRegistry] = None):
25
+ def __init__(self,
26
+ system_prompt: str,
27
+ name: str = "Jarvis",
28
+ is_sub_agent: bool = False,
29
+ tool_registry: Optional[ToolRegistry] = None,
30
+ platform: Optional[BasePlatform] = None,
31
+ summary_prompt: Optional[str] = None,
32
+ auto_complete: bool = False,
33
+ record_methodology: bool = True,
34
+ output_filter: Optional[List[Callable]] = None,
35
+ need_summary: bool = True):
20
36
  """Initialize Agent with a model, optional tool registry and name
21
37
 
22
38
  Args:
@@ -24,25 +40,70 @@ class Agent:
24
40
  name: Agent name, default is "Jarvis"
25
41
  is_sub_agent: Whether it is a sub-agent, default is False
26
42
  tool_registry: Tool registry instance
43
+ platform: Optional platform instance, default uses normal platform
27
44
  """
28
45
  add_agent(name)
29
46
  PrettyOutput.print(f"Welcome to Jarvis, your AI assistant, Initiating...", OutputType.SYSTEM)
30
- self.model = PlatformRegistry.get_global_platform_registry().get_normal_platform()
31
- self.tool_registry = tool_registry if tool_registry else ToolRegistry.get_global_tool_registry()
47
+ if platform is not None:
48
+ self.model = platform
49
+ else:
50
+ self.model = PlatformRegistry.get_global_platform_registry().get_normal_platform()
51
+ self.tool_registry = tool_registry if tool_registry else ToolRegistry()
52
+ self.record_methodology = record_methodology
32
53
  self.name = name
33
54
  self.is_sub_agent = is_sub_agent
34
55
  self.prompt = ""
35
56
  self.conversation_length = 0 # Use length counter instead
36
57
  self.system_prompt = system_prompt
58
+ self.need_summary = need_summary
37
59
  # Load configuration from environment variables
60
+ self.output_filter = output_filter if output_filter else []
61
+
62
+ self.summary_prompt = summary_prompt if summary_prompt else f"""Please generate a concise summary report of the task execution, including:
63
+
64
+ 1. Task Objective: Task restatement
65
+ 2. Execution Result: Success/Failure
66
+ 3. Key Information: Important information extracted during execution
67
+ 4. Important Findings: Any noteworthy discoveries
68
+ 5. Follow-up Suggestions: If any
69
+
70
+ Please describe in concise bullet points, highlighting important information.
71
+ """
38
72
 
39
73
  self.max_context_length = get_max_context_length()
74
+
75
+ self.auto_complete = auto_complete
76
+
77
+
40
78
 
41
79
 
42
80
  # Initialize methodology related attributes
43
81
  self.methodology_data = []
44
82
 
45
83
  PrettyOutput.section(f"Jarvis initialized - With {self.model.name()}", OutputType.SYSTEM)
84
+ tools = self.tool_registry.get_all_tools()
85
+ if tools:
86
+ PrettyOutput.section(f"Available tools: {', '.join([tool['name'] for tool in tools])}", OutputType.SYSTEM)
87
+
88
+
89
+ # Load methodology
90
+
91
+ tools_prompt = self.tool_registry.load_tools()
92
+ complete_prompt = """"""
93
+ if self.auto_complete:
94
+ complete_prompt = """
95
+ When the task is completed, you should print the following message:
96
+ <!!!COMPLETE!!!>
97
+ """
98
+
99
+ self.model.set_system_message(f"""
100
+ {self.system_prompt}
101
+
102
+ {tools_prompt}
103
+
104
+ {complete_prompt}
105
+ """)
106
+ self.first = True
46
107
 
47
108
  @staticmethod
48
109
  def extract_tool_calls(content: str) -> List[Dict]:
@@ -52,14 +113,6 @@ class Agent:
52
113
  tool_call_lines = []
53
114
  in_tool_call = False
54
115
 
55
- tool_call_help = """Tool Usage Format:
56
-
57
- <TOOL_CALL>
58
- name: tool_name
59
- arguments:
60
- param1: value1
61
- param2: value2
62
- </TOOL_CALL>"""
63
116
 
64
117
  # Process line by line
65
118
  for line in lines:
@@ -68,27 +121,19 @@ arguments:
68
121
  continue
69
122
  elif '</TOOL_CALL>' in line:
70
123
  if in_tool_call and tool_call_lines:
71
- try:
72
- # Parse YAML directly
73
- tool_call_text = '\n'.join(tool_call_lines)
74
- tool_call_data = yaml.safe_load(tool_call_text)
75
-
76
- # Validate necessary fields
77
- if "name" in tool_call_data and "arguments" in tool_call_data:
78
- # Return content before tool call and tool call
79
- return [{
80
- "name": tool_call_data["name"],
81
- "arguments": tool_call_data["arguments"]
82
- }]
83
- else:
84
- PrettyOutput.print("Tool call missing necessary fields", OutputType.ERROR)
85
- raise Exception("Tool call missing necessary fields, " + tool_call_help)
86
- except yaml.YAMLError as e:
87
- PrettyOutput.print(f"YAML parsing error: {str(e)}", OutputType.ERROR)
88
- raise Exception(f"YAML parsing error: {str(e)}")
89
- except Exception as e:
90
- PrettyOutput.print(f"Error processing tool call: {str(e)}", OutputType.ERROR)
91
- raise Exception(f"Error processing tool call: {str(e)}")
124
+ # Parse YAML directly
125
+ tool_call_text = '\n'.join(tool_call_lines)
126
+ tool_call_data = yaml.safe_load(tool_call_text)
127
+
128
+ # Validate necessary fields
129
+ if "name" in tool_call_data and "arguments" in tool_call_data:
130
+ # Return content before tool call and tool call
131
+ return [{
132
+ "name": tool_call_data["name"],
133
+ "arguments": tool_call_data["arguments"]
134
+ }]
135
+ else:
136
+ raise Exception("Tool call missing necessary fields")
92
137
  in_tool_call = False
93
138
  continue
94
139
 
@@ -165,53 +210,39 @@ Please continue the task based on the above information.
165
210
  """
166
211
  PrettyOutput.section("Task completed", OutputType.SUCCESS)
167
212
 
168
- # 询问是否生成方法论,带输入验证
169
- while True:
170
- user_input = get_single_line_input("Generate methodology for this task? (y/n)").strip().lower()
171
- if user_input in ['y', 'n', '']:
172
- break
173
- PrettyOutput.print("Invalid input, please enter y or n", OutputType.WARNING)
174
-
175
- if user_input == 'y':
176
- try:
177
- # 让模型判断是否需要生成方法论
178
- analysis_prompt = """The current task has ended, please analyze whether a methodology needs to be generated.
179
- If you think a methodology should be generated, first determine whether to create a new methodology or update an existing one. If updating an existing methodology, use 'update', otherwise use 'add'.
180
- If you think a methodology is not needed, please explain why.
181
- The methodology should be applicable to general scenarios, do not include task-specific information such as code commit messages.
182
- The methodology should include: problem restatement, optimal solution, notes (as needed), and nothing else.
183
- Only output the methodology tool call instruction, or the explanation for not generating a methodology. Do not output anything else.
184
- """
185
- self.prompt = analysis_prompt
186
- response = self._call_model(self.prompt)
187
-
188
- # 检查是否包含工具调用
213
+ if not self.is_sub_agent:
214
+ if self.record_methodology:
215
+
189
216
  try:
190
- tool_calls = Agent.extract_tool_calls(response)
191
- if tool_calls:
192
- self.tool_registry.handle_tool_calls(tool_calls)
217
+ # 让模型判断是否需要生成方法论
218
+ analysis_prompt = """The current task has ended, please analyze whether a methodology needs to be generated.
219
+ If you think a methodology should be generated, first determine whether to create a new methodology or update an existing one. If updating an existing methodology, use 'update', otherwise use 'add'.
220
+ If you think a methodology is not needed, please explain why.
221
+ The methodology should be applicable to general scenarios, do not include task-specific information such as code commit messages.
222
+ The methodology should include: problem restatement, optimal solution, notes (as needed), and nothing else.
223
+ Only output the methodology tool call instruction, or the explanation for not generating a methodology. Do not output anything else.
224
+ """
225
+ self.prompt = analysis_prompt
226
+ response = self._call_model(self.prompt)
227
+
228
+ # 检查是否包含工具调用
229
+ try:
230
+ tool_calls = Agent.extract_tool_calls(response)
231
+ if tool_calls:
232
+ self.tool_registry.handle_tool_calls(tool_calls)
233
+ except Exception as e:
234
+ PrettyOutput.print(f"Failed to handle methodology generation: {str(e)}", OutputType.ERROR)
235
+
193
236
  except Exception as e:
194
- PrettyOutput.print(f"Failed to handle methodology generation: {str(e)}", OutputType.ERROR)
195
-
196
- except Exception as e:
197
- PrettyOutput.print(f"Error generating methodology: {str(e)}", OutputType.ERROR)
198
-
199
- if not self.is_sub_agent:
237
+ PrettyOutput.print(f"Error generating methodology: {str(e)}", OutputType.ERROR)
238
+
200
239
  return "Task completed"
201
240
 
202
- # 生成任务总结
203
- summary_prompt = f"""Please generate a concise summary report of the task execution, including:
204
-
205
- 1. Task Objective: Task restatement
206
- 2. Execution Result: Success/Failure
207
- 3. Key Information: Important information extracted during execution
208
- 4. Important Findings: Any noteworthy discoveries
209
- 5. Follow-up Suggestions: If any
210
-
211
- Please describe in concise bullet points, highlighting important information.
212
- """
213
- self.prompt = summary_prompt
214
- return self._call_model(self.prompt)
241
+ if self.need_summary:
242
+ self.prompt = self.summary_prompt
243
+ return self._call_model(self.prompt)
244
+
245
+ return "Task completed"
215
246
 
216
247
 
217
248
  def run(self, user_input: str, file_list: Optional[List[str]] = None) -> str:
@@ -224,28 +255,22 @@ Please describe in concise bullet points, highlighting important information.
224
255
  Returns:
225
256
  str: Task summary report
226
257
  """
258
+
259
+
260
+
227
261
  try:
228
262
  PrettyOutput.section("Preparing environment", OutputType.PLANNING)
229
263
  if file_list:
230
264
  self.model.upload_files(file_list)
231
265
 
232
- # Load methodology
233
- methodology_prompt = load_methodology(user_input)
234
- tools_prompt = load_tools()
235
-
236
266
  # 显示任务开始
237
267
  PrettyOutput.section(f"Starting new task: {self.name}", OutputType.PLANNING)
238
268
 
239
- self.clear_history()
240
-
241
- self.model.set_system_message(f"""
242
- {self.system_prompt}
243
-
244
- {tools_prompt}
245
-
246
- {methodology_prompt}
247
- """)
248
- self.prompt = f"{user_input}"
269
+ if self.first:
270
+ self.prompt = f"{user_input}\n\n{load_methodology(user_input)}"
271
+ self.first = False
272
+ else:
273
+ self.prompt = f"{user_input}"
249
274
 
250
275
  while True:
251
276
  try:
@@ -261,25 +286,32 @@ Please describe in concise bullet points, highlighting important information.
261
286
  continue
262
287
  else:
263
288
  current_response = self._call_model(self.prompt)
264
- self.conversation_length += len(current_response) # Add response length
289
+ self.prompt = ""
290
+ self.conversation_length += len(current_response)
291
+
292
+ for filter in self.output_filter:
293
+ self.prompt += filter(current_response)
294
+
265
295
  try:
266
296
  result = Agent.extract_tool_calls(current_response)
267
297
  except Exception as e:
268
298
  PrettyOutput.print(f"Tool call error: {str(e)}", OutputType.ERROR)
269
- self.prompt = f"Tool call error: {str(e)}"
299
+ self.prompt += f"Tool call error: {str(e)}"
270
300
  continue
271
301
 
272
302
  if len(result) > 0:
273
303
  PrettyOutput.print("Executing tool call...", OutputType.PROGRESS)
274
304
  tool_result = self.tool_registry.handle_tool_calls(result)
275
- self.prompt = tool_result
305
+ self.prompt += tool_result
306
+
307
+ if self.prompt:
276
308
  continue
309
+
310
+ if self.auto_complete and "<!!!COMPLETE!!!>" in current_response:
311
+ return self._complete_task()
277
312
 
278
313
  # 获取用户输入
279
314
  user_input = get_multiline_input(f"{self.name}: You can continue to input, or enter an empty line to end the current task")
280
- if user_input == "__interrupt__":
281
- PrettyOutput.print("Task cancelled by user", OutputType.WARNING)
282
- return "Task cancelled by user"
283
315
 
284
316
  if user_input:
285
317
  self.prompt = user_input
@@ -362,10 +394,11 @@ def select_task(tasks: dict) -> str:
362
394
  # Convert tasks to list for ordered display
363
395
  task_names = list(tasks.keys())
364
396
 
365
- PrettyOutput.print("\nAvailable tasks:", OutputType.INFO)
397
+ task_list = ["Available tasks:"]
366
398
  for i, name in enumerate(task_names, 1):
367
- PrettyOutput.print(f"[{i}] {name}", OutputType.INFO)
368
- PrettyOutput.print("[0] Skip predefined tasks", OutputType.INFO)
399
+ task_list.append(f"[{i}] {name}")
400
+ task_list.append("[0] Skip predefined tasks")
401
+ PrettyOutput.print("\n".join(task_list), OutputType.INFO)
369
402
 
370
403
 
371
404
  while True:
@@ -406,25 +439,13 @@ When users need to execute tasks, you will strictly follow these steps to handle
406
439
  7. Execute Action Plan: Execute one step at a time, **use at most one tool** (wait for tool execution results before proceeding)
407
440
  8. Monitor and Adjust: If execution results don't match expectations, reflect and adjust the action plan, iterate previous steps
408
441
  9. Methodology: If the current task has general applicability and valuable experience is gained, use methodology tools to record it for future similar problems
409
- 10. Task Completion: End the task using task completion command when finished
442
+ 10. Auto check the task goal completion status: If the task goal is completed, use the task completion command to end the task
443
+ 11. Task Completion: End the task using task completion command when finished
410
444
 
411
445
  Methodology Template:
412
446
  1. Problem Restatement
413
447
  2. Optimal Solution
414
448
  3. Optimal Solution Steps (exclude failed actions)
415
-
416
- Strict Rules:
417
- - Execute only one tool at a time
418
- - Tool execution must strictly follow the tool usage format
419
- - Wait for user to provide execution results
420
- - Don't assume or imagine results
421
- - Don't create fake dialogues
422
- - If current information is insufficient, you may ask the user
423
- - Not all problem-solving steps are mandatory, skip as appropriate
424
- - Request user guidance when multiple iterations show no progress
425
- - If yaml string contains colons, wrap the entire string in quotes to avoid yaml parsing errors
426
- - Use | syntax for multi-line strings in yaml
427
- - If you can start executing the task, please start directly without asking the user if you can begin.
428
449
 
429
450
  -------------------------------------------------------------"""
430
451
 
@@ -453,7 +474,7 @@ def main():
453
474
  while True:
454
475
  try:
455
476
  user_input = get_multiline_input("Please enter your task (input empty line to exit):")
456
- if not user_input or user_input == "__interrupt__":
477
+ if not user_input:
457
478
  break
458
479
  agent.run(user_input, args.files)
459
480
  except Exception as e: