janito 2.6.1__py3-none-any.whl → 2.8.0__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.
- janito/__init__.py +6 -7
- janito/__main__.py +4 -5
- janito/_version.py +55 -58
- janito/agent/setup_agent.py +308 -241
- janito/agent/templates/profiles/{system_prompt_template_software developer.txt.j2 → system_prompt_template_Developer_with_Python_Tools.txt.j2} +43 -39
- janito/agent/templates/profiles/system_prompt_template_developer.txt.j2 +3 -12
- janito/cli/__init__.py +9 -10
- janito/cli/chat_mode/bindings.py +38 -38
- janito/cli/chat_mode/chat_entry.py +21 -23
- janito/cli/chat_mode/prompt_style.py +22 -25
- janito/cli/chat_mode/script_runner.py +158 -154
- janito/cli/chat_mode/session.py +80 -35
- janito/cli/chat_mode/session_profile_select.py +61 -52
- janito/cli/chat_mode/shell/commands/__init__.py +1 -5
- janito/cli/chat_mode/shell/commands/_priv_check.py +1 -0
- janito/cli/chat_mode/shell/commands/bang.py +10 -3
- janito/cli/chat_mode/shell/commands/conversation_restart.py +24 -7
- janito/cli/chat_mode/shell/commands/execute.py +22 -7
- janito/cli/chat_mode/shell/commands/help.py +4 -1
- janito/cli/chat_mode/shell/commands/model.py +13 -5
- janito/cli/chat_mode/shell/commands/privileges.py +21 -0
- janito/cli/chat_mode/shell/commands/prompt.py +0 -2
- janito/cli/chat_mode/shell/commands/read.py +22 -5
- janito/cli/chat_mode/shell/commands/tools.py +15 -4
- janito/cli/chat_mode/shell/commands/write.py +22 -5
- janito/cli/chat_mode/shell/input_history.py +3 -1
- janito/cli/chat_mode/shell/session/manager.py +0 -2
- janito/cli/chat_mode/toolbar.py +25 -19
- janito/cli/cli_commands/list_models.py +1 -1
- janito/cli/cli_commands/list_providers.py +1 -0
- janito/cli/cli_commands/list_tools.py +35 -7
- janito/cli/cli_commands/model_utils.py +5 -3
- janito/cli/cli_commands/show_config.py +12 -0
- janito/cli/cli_commands/show_system_prompt.py +23 -9
- janito/cli/config.py +0 -13
- janito/cli/core/getters.py +2 -0
- janito/cli/core/runner.py +25 -8
- janito/cli/core/setters.py +13 -76
- janito/cli/main_cli.py +9 -25
- janito/cli/prompt_core.py +19 -18
- janito/cli/prompt_setup.py +6 -3
- janito/cli/rich_terminal_reporter.py +19 -5
- janito/cli/single_shot_mode/handler.py +104 -95
- janito/cli/verbose_output.py +5 -1
- janito/config_manager.py +4 -0
- janito/drivers/azure_openai/driver.py +27 -30
- janito/drivers/driver_registry.py +27 -27
- janito/drivers/openai/driver.py +452 -436
- janito/formatting_token.py +12 -4
- janito/llm/agent.py +15 -6
- janito/llm/driver.py +1 -0
- janito/provider_registry.py +139 -178
- janito/providers/__init__.py +2 -0
- janito/providers/anthropic/model_info.py +40 -41
- janito/providers/anthropic/provider.py +75 -80
- janito/providers/azure_openai/provider.py +9 -4
- janito/providers/deepseek/provider.py +5 -4
- janito/providers/google/model_info.py +4 -2
- janito/providers/google/provider.py +11 -5
- janito/providers/groq/__init__.py +1 -0
- janito/providers/groq/model_info.py +46 -0
- janito/providers/groq/provider.py +76 -0
- janito/providers/moonshotai/__init__.py +1 -0
- janito/providers/moonshotai/model_info.py +15 -0
- janito/providers/moonshotai/provider.py +89 -0
- janito/providers/openai/provider.py +6 -7
- janito/tools/__init__.py +2 -0
- janito/tools/adapters/local/__init__.py +67 -66
- janito/tools/adapters/local/adapter.py +21 -4
- janito/tools/adapters/local/ask_user.py +1 -0
- janito/tools/adapters/local/copy_file.py +1 -0
- janito/tools/adapters/local/create_directory.py +1 -0
- janito/tools/adapters/local/create_file.py +1 -0
- janito/tools/adapters/local/delete_text_in_file.py +2 -1
- janito/tools/adapters/local/fetch_url.py +1 -0
- janito/tools/adapters/local/find_files.py +7 -6
- janito/tools/adapters/local/get_file_outline/core.py +1 -0
- janito/tools/adapters/local/get_file_outline/java_outline.py +22 -15
- janito/tools/adapters/local/get_file_outline/search_outline.py +1 -0
- janito/tools/adapters/local/move_file.py +4 -3
- janito/tools/adapters/local/open_html_in_browser.py +15 -5
- janito/tools/adapters/local/open_url.py +1 -0
- janito/tools/adapters/local/python_code_run.py +1 -0
- janito/tools/adapters/local/python_command_run.py +1 -0
- janito/tools/adapters/local/python_file_run.py +1 -0
- janito/tools/adapters/local/read_files.py +55 -40
- janito/tools/adapters/local/remove_directory.py +1 -0
- janito/tools/adapters/local/remove_file.py +1 -0
- janito/tools/adapters/local/replace_text_in_file.py +4 -3
- janito/tools/adapters/local/run_bash_command.py +1 -0
- janito/tools/adapters/local/run_powershell_command.py +1 -0
- janito/tools/adapters/local/search_text/core.py +18 -17
- janito/tools/adapters/local/search_text/match_lines.py +5 -5
- janito/tools/adapters/local/search_text/pattern_utils.py +1 -1
- janito/tools/adapters/local/search_text/traverse_directory.py +7 -7
- janito/tools/adapters/local/validate_file_syntax/core.py +1 -1
- janito/tools/adapters/local/validate_file_syntax/html_validator.py +8 -1
- janito/tools/disabled_tools.py +68 -0
- janito/tools/path_security.py +18 -11
- janito/tools/permissions.py +6 -0
- janito/tools/permissions_parse.py +4 -3
- janito/tools/tool_base.py +11 -5
- janito/tools/tool_use_tracker.py +1 -4
- janito/tools/tool_utils.py +1 -1
- janito/tools/tools_adapter.py +57 -25
- {janito-2.6.1.dist-info → janito-2.8.0.dist-info}/METADATA +411 -417
- janito-2.8.0.dist-info/RECORD +202 -0
- janito/cli/chat_mode/shell/commands/livelogs.py +0 -49
- janito/drivers/mistralai/driver.py +0 -41
- janito/providers/mistralai/model_info.py +0 -37
- janito/providers/mistralai/provider.py +0 -72
- janito/providers/provider_static_info.py +0 -18
- janito-2.6.1.dist-info/RECORD +0 -199
- /janito/agent/templates/profiles/{system_prompt_template_assistant.txt.j2 → system_prompt_template_model_conversation_without_tools_or_context.txt.j2} +0 -0
- {janito-2.6.1.dist-info → janito-2.8.0.dist-info}/WHEEL +0 -0
- {janito-2.6.1.dist-info → janito-2.8.0.dist-info}/entry_points.txt +0 -0
- {janito-2.6.1.dist-info → janito-2.8.0.dist-info}/licenses/LICENSE +0 -0
- {janito-2.6.1.dist-info → janito-2.8.0.dist-info}/top_level.txt +0 -0
janito/agent/setup_agent.py
CHANGED
@@ -1,241 +1,308 @@
|
|
1
|
-
import importlib.resources
|
2
|
-
import re
|
3
|
-
import os
|
4
|
-
import sys
|
5
|
-
import time
|
6
|
-
import warnings
|
7
|
-
import threading
|
8
|
-
from pathlib import Path
|
9
|
-
from jinja2 import Template
|
10
|
-
from pathlib import Path
|
11
|
-
from queue import Queue
|
12
|
-
from rich import print as rich_print
|
13
|
-
from janito.tools import get_local_tools_adapter
|
14
|
-
from janito.llm.agent import LLMAgent
|
15
|
-
from janito.drivers.driver_registry import get_driver_class
|
16
|
-
from janito.platform_discovery import PlatformDiscovery
|
17
|
-
from janito.tools.tool_base import ToolPermissions
|
18
|
-
from janito.tools.permissions import get_global_allowed_permissions
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
return file.read(), template_path
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
#
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
allowed_permissions=
|
111
|
-
|
112
|
-
|
113
|
-
)
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
1
|
+
import importlib.resources
|
2
|
+
import re
|
3
|
+
import os
|
4
|
+
import sys
|
5
|
+
import time
|
6
|
+
import warnings
|
7
|
+
import threading
|
8
|
+
from pathlib import Path
|
9
|
+
from jinja2 import Template
|
10
|
+
from pathlib import Path
|
11
|
+
from queue import Queue
|
12
|
+
from rich import print as rich_print
|
13
|
+
from janito.tools import get_local_tools_adapter
|
14
|
+
from janito.llm.agent import LLMAgent
|
15
|
+
from janito.drivers.driver_registry import get_driver_class
|
16
|
+
from janito.platform_discovery import PlatformDiscovery
|
17
|
+
from janito.tools.tool_base import ToolPermissions
|
18
|
+
from janito.tools.permissions import get_global_allowed_permissions
|
19
|
+
|
20
|
+
|
21
|
+
def _load_template_content(profile, templates_dir):
|
22
|
+
"""
|
23
|
+
Loads the template content for the given profile from the specified directory or package resources.
|
24
|
+
If the profile template is not found in the default locations, tries to load from the user profiles directory ~/.janito/profiles.
|
25
|
+
|
26
|
+
Spaces in the profile name are converted to underscores to align with the file-naming convention (e.g. "Developer with Python Tools" ➜ "Developer_with_Python_Tools" (matches: system_prompt_template_Developer_with_Python_Tools.txt.j2)).
|
27
|
+
"""
|
28
|
+
# Sanitize profile for filename resolution (convert whitespace to underscores)
|
29
|
+
sanitized_profile = re.sub(r"\s+", "_", profile.strip()) if profile else profile
|
30
|
+
|
31
|
+
template_filename = f"system_prompt_template_{sanitized_profile}.txt.j2"
|
32
|
+
template_path = templates_dir / template_filename
|
33
|
+
|
34
|
+
# 1) Check local templates directory
|
35
|
+
if template_path.exists():
|
36
|
+
with open(template_path, "r", encoding="utf-8") as file:
|
37
|
+
return file.read(), template_path
|
38
|
+
|
39
|
+
# 2) Try package resources fallback
|
40
|
+
try:
|
41
|
+
with importlib.resources.files("janito.agent.templates.profiles").joinpath(
|
42
|
+
template_filename
|
43
|
+
).open("r", encoding="utf-8") as file:
|
44
|
+
return file.read(), template_path
|
45
|
+
except (FileNotFoundError, ModuleNotFoundError, AttributeError):
|
46
|
+
pass
|
47
|
+
|
48
|
+
# 3) Finally, look in the user profiles directory (~/.janito/profiles)
|
49
|
+
user_profiles_dir = Path(os.path.expanduser("~/.janito/profiles"))
|
50
|
+
user_template_path = user_profiles_dir / template_filename
|
51
|
+
if user_template_path.exists():
|
52
|
+
with open(user_template_path, "r", encoding="utf-8") as file:
|
53
|
+
return file.read(), user_template_path
|
54
|
+
|
55
|
+
# If nothing matched, raise an informative error
|
56
|
+
raise FileNotFoundError(
|
57
|
+
f"[janito] Could not find profile-specific template '{template_filename}' in {template_path} nor in janito.agent.templates.profiles package nor in user profiles directory {user_template_path}."
|
58
|
+
)
|
59
|
+
# Replace spaces in profile name with underscores for filename resolution
|
60
|
+
sanitized_profile = re.sub(r"\\s+", "_", profile.strip()) if profile else profile
|
61
|
+
"""
|
62
|
+
Loads the template content for the given profile from the specified directory or package resources.
|
63
|
+
If the profile template is not found in the default locations, tries to load from the user profiles directory ~/.janito/profiles.
|
64
|
+
"""
|
65
|
+
|
66
|
+
# Sanitize profile name by replacing spaces with underscores to match filename conventions
|
67
|
+
sanitized_profile = re.sub(r"\\s+", "_", profile.strip())
|
68
|
+
template_filename = f"system_prompt_template_{sanitized_profile}.txt.j2"
|
69
|
+
template_path = templates_dir / template_filename
|
70
|
+
if template_path.exists():
|
71
|
+
with open(template_path, "r", encoding="utf-8") as file:
|
72
|
+
return file.read(), template_path
|
73
|
+
# Try package import fallback
|
74
|
+
try:
|
75
|
+
with importlib.resources.files("janito.agent.templates.profiles").joinpath(
|
76
|
+
template_filename
|
77
|
+
).open("r", encoding="utf-8") as file:
|
78
|
+
return file.read(), template_path
|
79
|
+
except (FileNotFoundError, ModuleNotFoundError, AttributeError):
|
80
|
+
# Try user profiles directory
|
81
|
+
user_profiles_dir = Path(os.path.expanduser("~/.janito/profiles"))
|
82
|
+
user_template_path = user_profiles_dir / profile
|
83
|
+
if user_template_path.exists():
|
84
|
+
with open(user_template_path, "r", encoding="utf-8") as file:
|
85
|
+
return file.read(), user_template_path
|
86
|
+
raise FileNotFoundError(
|
87
|
+
f"[janito] Could not find profile-specific template '{template_filename}' in {template_path} nor in janito.agent.templates.profiles package nor in user profiles directory {user_template_path}."
|
88
|
+
)
|
89
|
+
|
90
|
+
|
91
|
+
def _prepare_template_context(role, profile, allowed_permissions):
|
92
|
+
"""
|
93
|
+
Prepares the context dictionary for Jinja2 template rendering.
|
94
|
+
"""
|
95
|
+
context = {}
|
96
|
+
context["role"] = role or "developer"
|
97
|
+
context["profile"] = profile
|
98
|
+
if allowed_permissions is None:
|
99
|
+
allowed_permissions = get_global_allowed_permissions()
|
100
|
+
# Convert ToolPermissions -> string like "rwx"
|
101
|
+
if isinstance(allowed_permissions, ToolPermissions):
|
102
|
+
perm_str = ""
|
103
|
+
if allowed_permissions.read:
|
104
|
+
perm_str += "r"
|
105
|
+
if allowed_permissions.write:
|
106
|
+
perm_str += "w"
|
107
|
+
if allowed_permissions.execute:
|
108
|
+
perm_str += "x"
|
109
|
+
allowed_permissions = perm_str or None
|
110
|
+
context["allowed_permissions"] = allowed_permissions
|
111
|
+
# Inject platform info if execute permission is present
|
112
|
+
if allowed_permissions and "x" in allowed_permissions:
|
113
|
+
pd = PlatformDiscovery()
|
114
|
+
context["platform"] = pd.get_platform_name()
|
115
|
+
context["python_version"] = pd.get_python_version()
|
116
|
+
context["shell_info"] = pd.detect_shell()
|
117
|
+
return context
|
118
|
+
|
119
|
+
|
120
|
+
def _create_agent(
|
121
|
+
provider_instance,
|
122
|
+
tools_provider,
|
123
|
+
role,
|
124
|
+
system_prompt,
|
125
|
+
input_queue,
|
126
|
+
output_queue,
|
127
|
+
verbose_agent,
|
128
|
+
context,
|
129
|
+
template_path,
|
130
|
+
profile,
|
131
|
+
):
|
132
|
+
"""
|
133
|
+
Creates and returns an LLMAgent instance with the provided parameters.
|
134
|
+
"""
|
135
|
+
agent = LLMAgent(
|
136
|
+
provider_instance,
|
137
|
+
tools_provider,
|
138
|
+
agent_name=role or "developer",
|
139
|
+
system_prompt=system_prompt,
|
140
|
+
input_queue=input_queue,
|
141
|
+
output_queue=output_queue,
|
142
|
+
verbose_agent=verbose_agent,
|
143
|
+
)
|
144
|
+
agent.template_vars["role"] = context["role"]
|
145
|
+
agent.template_vars["profile"] = profile
|
146
|
+
agent.system_prompt_template = str(template_path)
|
147
|
+
agent._template_vars = context.copy()
|
148
|
+
agent._original_template_vars = context.copy()
|
149
|
+
return agent
|
150
|
+
|
151
|
+
|
152
|
+
def setup_agent(
|
153
|
+
provider_instance,
|
154
|
+
llm_driver_config,
|
155
|
+
role=None,
|
156
|
+
templates_dir=None,
|
157
|
+
zero_mode=False,
|
158
|
+
input_queue=None,
|
159
|
+
output_queue=None,
|
160
|
+
verbose_tools=False,
|
161
|
+
verbose_agent=False,
|
162
|
+
allowed_permissions=None,
|
163
|
+
profile=None,
|
164
|
+
profile_system_prompt=None,
|
165
|
+
no_tools_mode=False,
|
166
|
+
):
|
167
|
+
"""
|
168
|
+
Creates an agent. A system prompt is rendered from a template only when a profile is specified.
|
169
|
+
"""
|
170
|
+
if no_tools_mode:
|
171
|
+
tools_provider = None
|
172
|
+
else:
|
173
|
+
tools_provider = get_local_tools_adapter()
|
174
|
+
tools_provider.set_verbose_tools(verbose_tools)
|
175
|
+
|
176
|
+
# If zero_mode is enabled or no profile is given we skip the system prompt.
|
177
|
+
if zero_mode or (profile is None and profile_system_prompt is None):
|
178
|
+
agent = LLMAgent(
|
179
|
+
provider_instance,
|
180
|
+
tools_provider,
|
181
|
+
agent_name=role or "developer",
|
182
|
+
system_prompt=None,
|
183
|
+
input_queue=input_queue,
|
184
|
+
output_queue=output_queue,
|
185
|
+
verbose_agent=verbose_agent,
|
186
|
+
)
|
187
|
+
if role:
|
188
|
+
agent.template_vars["role"] = role
|
189
|
+
return agent
|
190
|
+
|
191
|
+
# If profile_system_prompt is set, use it directly
|
192
|
+
if profile_system_prompt is not None:
|
193
|
+
agent = LLMAgent(
|
194
|
+
provider_instance,
|
195
|
+
tools_provider,
|
196
|
+
agent_name=role or "developer",
|
197
|
+
system_prompt=profile_system_prompt,
|
198
|
+
input_queue=input_queue,
|
199
|
+
output_queue=output_queue,
|
200
|
+
verbose_agent=verbose_agent,
|
201
|
+
)
|
202
|
+
agent.template_vars["role"] = role or "developer"
|
203
|
+
agent.template_vars["profile"] = None
|
204
|
+
agent.template_vars["profile_system_prompt"] = profile_system_prompt
|
205
|
+
return agent
|
206
|
+
|
207
|
+
# Normal flow (profile-specific system prompt)
|
208
|
+
if templates_dir is None:
|
209
|
+
templates_dir = Path(__file__).parent / "templates" / "profiles"
|
210
|
+
template_content, template_path = _load_template_content(profile, templates_dir)
|
211
|
+
|
212
|
+
template = Template(template_content)
|
213
|
+
context = _prepare_template_context(role, profile, allowed_permissions)
|
214
|
+
|
215
|
+
# Debug output if requested
|
216
|
+
debug_flag = False
|
217
|
+
try:
|
218
|
+
debug_flag = hasattr(sys, "argv") and (
|
219
|
+
"--debug" in sys.argv or "--verbose" in sys.argv or "-v" in sys.argv
|
220
|
+
)
|
221
|
+
except Exception:
|
222
|
+
pass
|
223
|
+
if debug_flag:
|
224
|
+
rich_print(
|
225
|
+
f"[bold magenta][DEBUG][/bold magenta] Rendering system prompt template '[cyan]{template_path.name}[/cyan]' with allowed_permissions: [yellow]{context.get('allowed_permissions')}[/yellow]"
|
226
|
+
)
|
227
|
+
rich_print(
|
228
|
+
f"[bold magenta][DEBUG][/bold magenta] Template context: [green]{context}[/green]"
|
229
|
+
)
|
230
|
+
start_render = time.time()
|
231
|
+
rendered_prompt = template.render(**context)
|
232
|
+
end_render = time.time()
|
233
|
+
# Merge multiple empty lines into a single empty line
|
234
|
+
rendered_prompt = re.sub(r"\n{3,}", "\n\n", rendered_prompt)
|
235
|
+
|
236
|
+
return _create_agent(
|
237
|
+
provider_instance,
|
238
|
+
tools_provider,
|
239
|
+
role,
|
240
|
+
rendered_prompt,
|
241
|
+
input_queue,
|
242
|
+
output_queue,
|
243
|
+
verbose_agent,
|
244
|
+
context,
|
245
|
+
template_path,
|
246
|
+
profile,
|
247
|
+
)
|
248
|
+
|
249
|
+
|
250
|
+
def create_configured_agent(
|
251
|
+
*,
|
252
|
+
provider_instance=None,
|
253
|
+
llm_driver_config=None,
|
254
|
+
role=None,
|
255
|
+
verbose_tools=False,
|
256
|
+
verbose_agent=False,
|
257
|
+
templates_dir=None,
|
258
|
+
zero_mode=False,
|
259
|
+
allowed_permissions=None,
|
260
|
+
profile=None,
|
261
|
+
profile_system_prompt=None,
|
262
|
+
no_tools_mode=False,
|
263
|
+
):
|
264
|
+
"""
|
265
|
+
Normalizes agent setup for all CLI modes.
|
266
|
+
|
267
|
+
Args:
|
268
|
+
provider_instance: Provider instance for the agent
|
269
|
+
llm_driver_config: LLM driver configuration
|
270
|
+
role: Optional role string
|
271
|
+
verbose_tools: Optional, default False
|
272
|
+
verbose_agent: Optional, default False
|
273
|
+
templates_dir: Optional
|
274
|
+
zero_mode: Optional, default False
|
275
|
+
|
276
|
+
Returns:
|
277
|
+
Configured agent instance
|
278
|
+
"""
|
279
|
+
input_queue = None
|
280
|
+
output_queue = None
|
281
|
+
driver = None
|
282
|
+
if hasattr(provider_instance, "create_driver"):
|
283
|
+
driver = provider_instance.create_driver()
|
284
|
+
# Ensure no tools are passed to the driver when --no-tools flag is active
|
285
|
+
if no_tools_mode:
|
286
|
+
driver.tools_adapter = None
|
287
|
+
driver.start() # Ensure the driver background thread is started
|
288
|
+
input_queue = getattr(driver, "input_queue", None)
|
289
|
+
output_queue = getattr(driver, "output_queue", None)
|
290
|
+
|
291
|
+
agent = setup_agent(
|
292
|
+
provider_instance=provider_instance,
|
293
|
+
llm_driver_config=llm_driver_config,
|
294
|
+
role=role,
|
295
|
+
templates_dir=templates_dir,
|
296
|
+
zero_mode=zero_mode,
|
297
|
+
input_queue=input_queue,
|
298
|
+
output_queue=output_queue,
|
299
|
+
verbose_tools=verbose_tools,
|
300
|
+
verbose_agent=verbose_agent,
|
301
|
+
allowed_permissions=allowed_permissions,
|
302
|
+
profile=profile,
|
303
|
+
profile_system_prompt=profile_system_prompt,
|
304
|
+
no_tools_mode=no_tools_mode,
|
305
|
+
)
|
306
|
+
if driver is not None:
|
307
|
+
agent.driver = driver # Attach driver to agent for thread management
|
308
|
+
return agent
|
@@ -1,39 +1,43 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
{
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
{
|
21
|
-
- Before
|
22
|
-
{
|
23
|
-
|
24
|
-
{
|
25
|
-
|
26
|
-
{#
|
27
|
-
-
|
28
|
-
{
|
29
|
-
|
30
|
-
{#
|
31
|
-
-
|
32
|
-
{#
|
33
|
-
-
|
34
|
-
{#
|
35
|
-
-
|
36
|
-
{#
|
37
|
-
-
|
38
|
-
{
|
39
|
-
|
1
|
+
{# General role setup
|
2
|
+
ex. "Search in code" -> Python Developer -> find(*.py) | Java Developer -> find(*.java)
|
3
|
+
#}
|
4
|
+
You are: {{ role }}
|
5
|
+
|
6
|
+
{# Improves tool selection and platform specific constrains, eg, path format, C:\ vs /path #}
|
7
|
+
{% if allowed_permissions and 'x' in allowed_permissions %}
|
8
|
+
You will be using the following environment:
|
9
|
+
Platform: {{ platform }}
|
10
|
+
Python version: {{ python_version }}
|
11
|
+
Shell/Environment: {{ shell_info }}
|
12
|
+
{% endif %}
|
13
|
+
|
14
|
+
|
15
|
+
{% if allowed_permissions and 'r' in allowed_permissions %}
|
16
|
+
Before answering map the questions to artifacts found in the current directory - the current project.
|
17
|
+
{% endif %}
|
18
|
+
|
19
|
+
Respond according to the following guidelines:
|
20
|
+
{% if allowed_permissions %}
|
21
|
+
- Before using the namespace tools provide a short reason
|
22
|
+
{% endif %}
|
23
|
+
{% if allowed_permissions and 'r' in allowed_permissions %}
|
24
|
+
{# Exploratory hint #}
|
25
|
+
- Before answering to the user, explore the content related to the question
|
26
|
+
{# Reduces chunking roundtip #}
|
27
|
+
- When exploring full files content, provide empty range to read the entire files instead of chunked reads
|
28
|
+
{% endif %}
|
29
|
+
{% if allowed_permissions and 'w' in allowed_permissions %}
|
30
|
+
{# Reduce unrequest code verbosity overhead #}
|
31
|
+
- Use the namespace functions to deliver the code changes instead of showing the code.
|
32
|
+
{# Drive edit mode, place holders critical as shown to be crucial to avoid corruption with code placeholders #}
|
33
|
+
- Prefer making localized edits using string replacements. If the required change is extensive, replace the entire file instead, provide full content without placeholders.
|
34
|
+
{# Without this, the LLM choses to create files from a literal interpretation of the purpose and intention #}
|
35
|
+
- Before creating files search the code for the location related to the file purpose
|
36
|
+
{# This will trigger a search for the old names/locations to be updates #}
|
37
|
+
- After moving, removing or renaming functions or classes to different modules, update all imports, references, tests, and documentation to reflect the new locations, then verify functionality.
|
38
|
+
{# Keeping docstrings update is key to have semanatic match between prompts and code #}
|
39
|
+
- Once development or updates are finished, ensure that new or updated packages, modules, functions are properly documented.
|
40
|
+
{# Trying to prevent surrogates generation, found this frequently in gpt4.1/windows #}
|
41
|
+
- While writing code, if you need an emoji or special Unicode character in a string, then insert the actual character (e.g., 📖) directly instead of using surrogate pairs or escape sequences.
|
42
|
+
{% endif %}
|
43
|
+
|