janito 3.12.1__py3-none-any.whl → 3.12.3__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/agent/setup_agent.py +378 -377
- janito/cli/chat_mode/session.py +505 -505
- janito/cli/cli_commands/list_profiles.py +104 -107
- janito/cli/cli_commands/show_system_prompt.py +166 -166
- janito/cli/core/runner.py +250 -266
- janito/cli/main_cli.py +520 -519
- janito/cli/single_shot_mode/handler.py +167 -167
- janito/llm/__init__.py +6 -5
- janito/llm/driver.py +290 -254
- janito/llm/response_cache.py +57 -0
- janito/plugins/builtin.py +64 -88
- janito/plugins/tools/local/__init__.py +82 -80
- janito/plugins/tools/local/markdown_view.py +94 -0
- janito/plugins/tools/local/read_files.py +1 -1
- janito/plugins/tools/local/replace_text_in_file.py +1 -1
- janito/plugins/tools/local/search_text/core.py +2 -2
- janito/plugins/tools/local/show_image.py +119 -74
- janito/plugins/tools/local/show_image_grid.py +134 -76
- janito/plugins/tools/local/view_file.py +3 -3
- janito/providers/alibaba/model_info.py +136 -105
- janito/providers/alibaba/provider.py +104 -104
- {janito-3.12.1.dist-info → janito-3.12.3.dist-info}/METADATA +1 -1
- {janito-3.12.1.dist-info → janito-3.12.3.dist-info}/RECORD +27 -25
- {janito-3.12.1.dist-info → janito-3.12.3.dist-info}/WHEEL +0 -0
- {janito-3.12.1.dist-info → janito-3.12.3.dist-info}/entry_points.txt +0 -0
- {janito-3.12.1.dist-info → janito-3.12.3.dist-info}/licenses/LICENSE +0 -0
- {janito-3.12.1.dist-info → janito-3.12.3.dist-info}/top_level.txt +0 -0
janito/agent/setup_agent.py
CHANGED
@@ -1,377 +1,378 @@
|
|
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
|
-
|
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
|
27
|
-
"""
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
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
|
-
context
|
111
|
-
context["
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
if
|
132
|
-
|
133
|
-
|
134
|
-
context["
|
135
|
-
context["
|
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
|
-
import
|
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
|
-
agent.template_vars["
|
213
|
-
agent.
|
214
|
-
agent.
|
215
|
-
agent.
|
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
|
-
tools_provider
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
agent.template_vars["
|
271
|
-
agent.template_vars["
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
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
|
+
|
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" ➜ "Developer" (matches: system_prompt_template_Developer.txt.j2)).
|
27
|
+
"""
|
28
|
+
# Normalize profile name for file matching: convert to lowercase and replace spaces with underscores
|
29
|
+
normalized_profile = profile.strip().lower().replace(" ", "_")
|
30
|
+
template_filename = f"system_prompt_template_{normalized_profile}.txt.j2"
|
31
|
+
|
32
|
+
return _find_template_file(template_filename, templates_dir, profile)
|
33
|
+
|
34
|
+
|
35
|
+
def _find_template_file(template_filename, templates_dir, profile):
|
36
|
+
"""Find and load template file from various locations."""
|
37
|
+
template_path = templates_dir / template_filename
|
38
|
+
|
39
|
+
# 1) Check local templates directory
|
40
|
+
if template_path.exists():
|
41
|
+
with open(template_path, "r", encoding="utf-8") as file:
|
42
|
+
return file.read(), template_path
|
43
|
+
|
44
|
+
# 2) Try package resources fallback
|
45
|
+
try:
|
46
|
+
with importlib.resources.files("janito.agent.templates.profiles").joinpath(
|
47
|
+
template_filename
|
48
|
+
).open("r", encoding="utf-8") as file:
|
49
|
+
return file.read(), template_path
|
50
|
+
except (FileNotFoundError, ModuleNotFoundError, AttributeError):
|
51
|
+
pass
|
52
|
+
|
53
|
+
# 3) Finally, look in the user profiles directory (~/.janito/profiles)
|
54
|
+
user_profiles_dir = Path(os.path.expanduser("~/.janito/profiles"))
|
55
|
+
user_template_path = user_profiles_dir / template_filename
|
56
|
+
if user_template_path.exists():
|
57
|
+
with open(user_template_path, "r", encoding="utf-8") as file:
|
58
|
+
return file.read(), user_template_path
|
59
|
+
|
60
|
+
# If nothing matched, list available profiles and raise an informative error
|
61
|
+
from janito.cli.cli_commands.list_profiles import (
|
62
|
+
_gather_default_profiles,
|
63
|
+
_gather_user_profiles,
|
64
|
+
)
|
65
|
+
|
66
|
+
default_profiles = _gather_default_profiles()
|
67
|
+
user_profiles = _gather_user_profiles()
|
68
|
+
|
69
|
+
available_profiles = []
|
70
|
+
if default_profiles:
|
71
|
+
available_profiles.extend([(p, "default") for p in default_profiles])
|
72
|
+
if user_profiles:
|
73
|
+
available_profiles.extend([(p, "user") for p in user_profiles])
|
74
|
+
|
75
|
+
# Normalize the input profile for better matching suggestions
|
76
|
+
normalized_input = re.sub(r"\s+", " ", profile.strip().lower())
|
77
|
+
|
78
|
+
if available_profiles:
|
79
|
+
profile_list = "\n".join(
|
80
|
+
[f" - {name} ({source})" for name, source in available_profiles]
|
81
|
+
)
|
82
|
+
|
83
|
+
# Find close matches
|
84
|
+
close_matches = []
|
85
|
+
for name, source in available_profiles:
|
86
|
+
normalized_name = name.lower()
|
87
|
+
if (
|
88
|
+
normalized_input in normalized_name
|
89
|
+
or normalized_name in normalized_input
|
90
|
+
):
|
91
|
+
close_matches.append(name)
|
92
|
+
|
93
|
+
suggestion = ""
|
94
|
+
if close_matches:
|
95
|
+
suggestion = f"\nDid you mean: {', '.join(close_matches)}?"
|
96
|
+
|
97
|
+
error_msg = f"[janito] Could not find profile '{profile}'. Available profiles:\n{profile_list}{suggestion}"
|
98
|
+
else:
|
99
|
+
error_msg = (
|
100
|
+
f"[janito] Could not find profile '{profile}'. No profiles available."
|
101
|
+
)
|
102
|
+
|
103
|
+
raise FileNotFoundError(error_msg)
|
104
|
+
|
105
|
+
|
106
|
+
def _prepare_template_context(role, profile, allowed_permissions, args=None):
|
107
|
+
"""
|
108
|
+
Prepares the context dictionary for Jinja2 template rendering.
|
109
|
+
"""
|
110
|
+
context = {}
|
111
|
+
context["role"] = role or "developer"
|
112
|
+
context["profile"] = profile
|
113
|
+
if allowed_permissions is None:
|
114
|
+
allowed_permissions = get_global_allowed_permissions()
|
115
|
+
# Convert ToolPermissions -> string like "rwx"
|
116
|
+
if isinstance(allowed_permissions, ToolPermissions):
|
117
|
+
perm_str = ""
|
118
|
+
if allowed_permissions.read:
|
119
|
+
perm_str += "r"
|
120
|
+
if allowed_permissions.write:
|
121
|
+
perm_str += "w"
|
122
|
+
if allowed_permissions.execute:
|
123
|
+
perm_str += "x"
|
124
|
+
allowed_permissions = perm_str or None
|
125
|
+
context["allowed_permissions"] = allowed_permissions
|
126
|
+
|
127
|
+
# Add emoji flag for system prompt
|
128
|
+
context["emoji_enabled"] = (
|
129
|
+
getattr(args, "emoji", False) if "args" in locals() else False
|
130
|
+
)
|
131
|
+
# Inject platform info if execute permission is present
|
132
|
+
if allowed_permissions and "x" in allowed_permissions:
|
133
|
+
pd = PlatformDiscovery()
|
134
|
+
context["platform"] = pd.get_platform_name()
|
135
|
+
context["python_version"] = pd.get_python_version()
|
136
|
+
context["shell_info"] = pd.detect_shell()
|
137
|
+
|
138
|
+
# Add allowed sites for market analyst profile
|
139
|
+
if profile == "market-analyst":
|
140
|
+
from janito.tools.url_whitelist import get_url_whitelist_manager
|
141
|
+
|
142
|
+
whitelist_manager = get_url_whitelist_manager()
|
143
|
+
allowed_sites = whitelist_manager.get_allowed_sites()
|
144
|
+
context["allowed_sites"] = allowed_sites
|
145
|
+
|
146
|
+
# Add market data sources documentation
|
147
|
+
if not allowed_sites:
|
148
|
+
context["allowed_sites_info"] = (
|
149
|
+
"No whitelist restrictions - all sites allowed"
|
150
|
+
)
|
151
|
+
else:
|
152
|
+
context["allowed_sites_info"] = f"Restricted to: {', '.join(allowed_sites)}"
|
153
|
+
|
154
|
+
# Add emoji flag for system prompt
|
155
|
+
context["emoji_enabled"] = (
|
156
|
+
getattr(args, "emoji", False) if "args" in locals() else False
|
157
|
+
)
|
158
|
+
|
159
|
+
# Add current date/time with timezone using standard library
|
160
|
+
from datetime import datetime, timezone
|
161
|
+
import time
|
162
|
+
|
163
|
+
# Get local time with timezone info
|
164
|
+
local_time = datetime.now()
|
165
|
+
|
166
|
+
# Get timezone offset
|
167
|
+
if time.daylight:
|
168
|
+
offset = time.altzone
|
169
|
+
else:
|
170
|
+
offset = time.timezone
|
171
|
+
|
172
|
+
# Format offset as +HHMM or -HHMM
|
173
|
+
offset_hours = -offset // 3600
|
174
|
+
offset_minutes = abs(offset) % 3600 // 60
|
175
|
+
offset_str = f"{offset_hours:+03d}{offset_minutes:02d}"
|
176
|
+
|
177
|
+
# Get timezone name
|
178
|
+
tz_name = time.tzname[time.daylight and time.daylight or 0]
|
179
|
+
|
180
|
+
context["current_datetime"] = local_time.strftime(
|
181
|
+
f"%Y-%m-%d %H:%M:%S {tz_name}{offset_str}"
|
182
|
+
)
|
183
|
+
context["timezone"] = f"{tz_name} (UTC{offset_str})"
|
184
|
+
|
185
|
+
return context
|
186
|
+
|
187
|
+
|
188
|
+
def _create_agent(
|
189
|
+
provider_instance,
|
190
|
+
tools_provider,
|
191
|
+
role,
|
192
|
+
system_prompt,
|
193
|
+
input_queue,
|
194
|
+
output_queue,
|
195
|
+
verbose_agent,
|
196
|
+
context,
|
197
|
+
template_path,
|
198
|
+
profile,
|
199
|
+
):
|
200
|
+
"""
|
201
|
+
Creates and returns an LLMAgent instance with the provided parameters.
|
202
|
+
"""
|
203
|
+
agent = LLMAgent(
|
204
|
+
provider_instance,
|
205
|
+
tools_provider,
|
206
|
+
agent_name=role or "developer",
|
207
|
+
system_prompt=system_prompt,
|
208
|
+
input_queue=input_queue,
|
209
|
+
output_queue=output_queue,
|
210
|
+
verbose_agent=verbose_agent,
|
211
|
+
)
|
212
|
+
agent.template_vars["role"] = context["role"]
|
213
|
+
agent.template_vars["profile"] = profile
|
214
|
+
agent.system_prompt_template = str(template_path)
|
215
|
+
agent._template_vars = context.copy()
|
216
|
+
agent._original_template_vars = context.copy()
|
217
|
+
return agent
|
218
|
+
|
219
|
+
|
220
|
+
def setup_agent(
|
221
|
+
provider_instance,
|
222
|
+
llm_driver_config,
|
223
|
+
role=None,
|
224
|
+
templates_dir=None,
|
225
|
+
zero_mode=False,
|
226
|
+
input_queue=None,
|
227
|
+
output_queue=None,
|
228
|
+
verbose_tools=False,
|
229
|
+
verbose_agent=False,
|
230
|
+
allowed_permissions=None,
|
231
|
+
profile=None,
|
232
|
+
profile_system_prompt=None,
|
233
|
+
no_tools_mode=False,
|
234
|
+
):
|
235
|
+
"""
|
236
|
+
Creates an agent. A system prompt is rendered from a template only when a profile is specified.
|
237
|
+
"""
|
238
|
+
if no_tools_mode or zero_mode:
|
239
|
+
tools_provider = None
|
240
|
+
else:
|
241
|
+
tools_provider = get_local_tools_adapter()
|
242
|
+
tools_provider.set_verbose_tools(verbose_tools)
|
243
|
+
|
244
|
+
# If zero_mode is enabled or no profile is given we skip the system prompt.
|
245
|
+
if zero_mode or (profile is None and profile_system_prompt is None):
|
246
|
+
agent = LLMAgent(
|
247
|
+
provider_instance,
|
248
|
+
tools_provider,
|
249
|
+
agent_name=role or "developer",
|
250
|
+
system_prompt=None,
|
251
|
+
input_queue=input_queue,
|
252
|
+
output_queue=output_queue,
|
253
|
+
verbose_agent=verbose_agent,
|
254
|
+
)
|
255
|
+
if role:
|
256
|
+
agent.template_vars["role"] = role
|
257
|
+
return agent
|
258
|
+
|
259
|
+
# If profile_system_prompt is set, use it directly
|
260
|
+
if profile_system_prompt is not None:
|
261
|
+
agent = LLMAgent(
|
262
|
+
provider_instance,
|
263
|
+
tools_provider,
|
264
|
+
agent_name=role or "developer",
|
265
|
+
system_prompt=profile_system_prompt,
|
266
|
+
input_queue=input_queue,
|
267
|
+
output_queue=output_queue,
|
268
|
+
verbose_agent=verbose_agent,
|
269
|
+
)
|
270
|
+
agent.template_vars["role"] = role or "developer"
|
271
|
+
agent.template_vars["profile"] = None
|
272
|
+
agent.template_vars["profile_system_prompt"] = profile_system_prompt
|
273
|
+
return agent
|
274
|
+
|
275
|
+
# Normal flow (profile-specific system prompt)
|
276
|
+
if templates_dir is None:
|
277
|
+
templates_dir = Path(__file__).parent / "templates" / "profiles"
|
278
|
+
template_content, template_path = _load_template_content(profile, templates_dir)
|
279
|
+
|
280
|
+
template = Template(template_content)
|
281
|
+
context = _prepare_template_context(
|
282
|
+
role, profile, allowed_permissions, locals().get("args")
|
283
|
+
)
|
284
|
+
|
285
|
+
# Debug output if requested
|
286
|
+
debug_flag = False
|
287
|
+
try:
|
288
|
+
debug_flag = hasattr(sys, "argv") and (
|
289
|
+
"--debug" in sys.argv or "--verbose" in sys.argv or "-v" in sys.argv
|
290
|
+
)
|
291
|
+
except Exception:
|
292
|
+
pass
|
293
|
+
if debug_flag:
|
294
|
+
rich_print(
|
295
|
+
f"[bold magenta][DEBUG][/bold magenta] Rendering system prompt template '[cyan]{template_path.name}[/cyan]' with allowed_permissions: [yellow]{context.get('allowed_permissions')}[/yellow]"
|
296
|
+
)
|
297
|
+
rich_print(
|
298
|
+
f"[bold magenta][DEBUG][/bold magenta] Template context: [green]{context}[/green]"
|
299
|
+
)
|
300
|
+
start_render = time.time()
|
301
|
+
rendered_prompt = template.render(**context)
|
302
|
+
end_render = time.time()
|
303
|
+
# Merge multiple empty lines into a single empty line
|
304
|
+
rendered_prompt = re.sub(r"\n{3,}", "\n\n", rendered_prompt)
|
305
|
+
|
306
|
+
return _create_agent(
|
307
|
+
provider_instance,
|
308
|
+
tools_provider,
|
309
|
+
role,
|
310
|
+
rendered_prompt,
|
311
|
+
input_queue,
|
312
|
+
output_queue,
|
313
|
+
verbose_agent,
|
314
|
+
context,
|
315
|
+
template_path,
|
316
|
+
profile,
|
317
|
+
)
|
318
|
+
|
319
|
+
|
320
|
+
def create_configured_agent(
|
321
|
+
*,
|
322
|
+
provider_instance=None,
|
323
|
+
llm_driver_config=None,
|
324
|
+
role=None,
|
325
|
+
verbose_tools=False,
|
326
|
+
verbose_agent=False,
|
327
|
+
templates_dir=None,
|
328
|
+
zero_mode=False,
|
329
|
+
allowed_permissions=None,
|
330
|
+
profile=None,
|
331
|
+
profile_system_prompt=None,
|
332
|
+
no_tools_mode=False,
|
333
|
+
):
|
334
|
+
"""
|
335
|
+
Normalizes agent setup for all CLI modes.
|
336
|
+
|
337
|
+
Args:
|
338
|
+
provider_instance: Provider instance for the agent
|
339
|
+
llm_driver_config: LLM driver configuration
|
340
|
+
role: Optional role string
|
341
|
+
verbose_tools: Optional, default False
|
342
|
+
verbose_agent: Optional, default False
|
343
|
+
templates_dir: Optional
|
344
|
+
zero_mode: Optional, default False
|
345
|
+
|
346
|
+
Returns:
|
347
|
+
Configured agent instance
|
348
|
+
"""
|
349
|
+
input_queue = None
|
350
|
+
output_queue = None
|
351
|
+
driver = None
|
352
|
+
if hasattr(provider_instance, "create_driver"):
|
353
|
+
driver = provider_instance.create_driver()
|
354
|
+
# Ensure no tools are passed to the driver when --no-tools flag is active
|
355
|
+
if no_tools_mode:
|
356
|
+
driver.tools_adapter = None
|
357
|
+
driver.start() # Ensure the driver background thread is started
|
358
|
+
input_queue = getattr(driver, "input_queue", None)
|
359
|
+
output_queue = getattr(driver, "output_queue", None)
|
360
|
+
|
361
|
+
agent = setup_agent(
|
362
|
+
provider_instance=provider_instance,
|
363
|
+
llm_driver_config=llm_driver_config,
|
364
|
+
role=role,
|
365
|
+
templates_dir=templates_dir,
|
366
|
+
zero_mode=zero_mode,
|
367
|
+
input_queue=input_queue,
|
368
|
+
output_queue=output_queue,
|
369
|
+
verbose_tools=verbose_tools,
|
370
|
+
verbose_agent=verbose_agent,
|
371
|
+
allowed_permissions=allowed_permissions,
|
372
|
+
profile=profile,
|
373
|
+
profile_system_prompt=profile_system_prompt,
|
374
|
+
no_tools_mode=no_tools_mode,
|
375
|
+
)
|
376
|
+
if driver is not None:
|
377
|
+
agent.driver = driver # Attach driver to agent for thread management
|
378
|
+
return agent
|