zrb 1.21.28__py3-none-any.whl → 1.21.37__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 zrb might be problematic. Click here for more details.
- zrb/builtin/llm/chat_completion.py +199 -222
- zrb/builtin/llm/chat_session.py +1 -1
- zrb/builtin/llm/chat_session_cmd.py +28 -11
- zrb/builtin/llm/chat_trigger.py +3 -4
- zrb/builtin/llm/tool/cli.py +45 -14
- zrb/builtin/llm/tool/code.py +5 -1
- zrb/builtin/llm/tool/file.py +17 -0
- zrb/builtin/llm/tool/note.py +7 -7
- zrb/builtin/llm/tool/search/__init__.py +1 -0
- zrb/builtin/llm/tool/search/brave.py +66 -0
- zrb/builtin/llm/tool/search/searxng.py +61 -0
- zrb/builtin/llm/tool/search/serpapi.py +61 -0
- zrb/builtin/llm/tool/sub_agent.py +4 -1
- zrb/builtin/llm/tool/web.py +17 -72
- zrb/cmd/cmd_result.py +2 -1
- zrb/config/config.py +5 -1
- zrb/config/default_prompt/interactive_system_prompt.md +15 -12
- zrb/config/default_prompt/system_prompt.md +16 -18
- zrb/config/llm_rate_limitter.py +36 -13
- zrb/input/option_input.py +30 -2
- zrb/task/cmd_task.py +3 -0
- zrb/task/llm/agent_runner.py +6 -2
- zrb/task/llm/history_list.py +13 -0
- zrb/task/llm/history_processor.py +4 -13
- zrb/task/llm/print_node.py +64 -23
- zrb/task/llm/tool_confirmation_completer.py +41 -0
- zrb/task/llm/tool_wrapper.py +6 -4
- zrb/task/llm/workflow.py +41 -14
- zrb/task/llm_task.py +4 -5
- zrb/task/rsync_task.py +2 -0
- zrb/util/cmd/command.py +33 -10
- zrb/util/match.py +71 -0
- {zrb-1.21.28.dist-info → zrb-1.21.37.dist-info}/METADATA +1 -1
- {zrb-1.21.28.dist-info → zrb-1.21.37.dist-info}/RECORD +36 -29
- {zrb-1.21.28.dist-info → zrb-1.21.37.dist-info}/WHEEL +0 -0
- {zrb-1.21.28.dist-info → zrb-1.21.37.dist-info}/entry_points.txt +0 -0
zrb/builtin/llm/tool/code.py
CHANGED
|
@@ -59,8 +59,12 @@ async def analyze_repo(
|
|
|
59
59
|
"""
|
|
60
60
|
Analyzes a code repository or directory to answer a specific query.
|
|
61
61
|
|
|
62
|
-
CRITICAL: The
|
|
62
|
+
CRITICAL: The query must contain ALL necessary context, instructions, and information.
|
|
63
|
+
The sub-agent performing the analysis does NOT share your current conversation
|
|
64
|
+
history, memory, or global context.
|
|
65
|
+
The quality of analysis depends entirely on the query. Vague queries yield poor
|
|
63
66
|
results.
|
|
67
|
+
|
|
64
68
|
IMPORTANT: This tool can be slow and expensive on large repositories. Use judiciously.
|
|
65
69
|
|
|
66
70
|
Example:
|
zrb/builtin/llm/tool/file.py
CHANGED
|
@@ -89,6 +89,10 @@ def list_files(
|
|
|
89
89
|
"""
|
|
90
90
|
Lists files recursively up to a specified depth.
|
|
91
91
|
|
|
92
|
+
**EFFICIENCY TIP:**
|
|
93
|
+
Do NOT use this tool if you already know the file path (e.g., from the user's prompt).
|
|
94
|
+
Use `read_from_file` directly in that case. Only use this to explore directory structures.
|
|
95
|
+
|
|
92
96
|
Example:
|
|
93
97
|
list_files(path='src', include_hidden=False, depth=2)
|
|
94
98
|
|
|
@@ -179,6 +183,12 @@ def read_from_file(
|
|
|
179
183
|
"""
|
|
180
184
|
Reads content from one or more files, optionally specifying line ranges.
|
|
181
185
|
|
|
186
|
+
**EFFICIENCY TIP:**
|
|
187
|
+
For source code or configuration files, prefer reading the **entire file** at once
|
|
188
|
+
to ensure you have full context (imports, class definitions, etc.).
|
|
189
|
+
Only use `start_line` and `end_line` for extremely large files (like logs) or
|
|
190
|
+
when you are certain only a specific section is needed.
|
|
191
|
+
|
|
182
192
|
Examples:
|
|
183
193
|
```
|
|
184
194
|
# Read entire content of a single file
|
|
@@ -516,6 +526,12 @@ async def analyze_file(
|
|
|
516
526
|
"""
|
|
517
527
|
Analyzes a file using a sub-agent for complex questions.
|
|
518
528
|
|
|
529
|
+
CRITICAL: The query must contain ALL necessary context, instructions, and information.
|
|
530
|
+
The sub-agent performing the analysis does NOT share your current conversation
|
|
531
|
+
history, memory, or global context.
|
|
532
|
+
The quality of analysis depends entirely on the query. Vague queries yield poor
|
|
533
|
+
results.
|
|
534
|
+
|
|
519
535
|
Example:
|
|
520
536
|
analyze_file(path='src/main.py', query='Summarize the main function.')
|
|
521
537
|
|
|
@@ -547,6 +563,7 @@ async def analyze_file(
|
|
|
547
563
|
tools=[read_from_file, search_files],
|
|
548
564
|
auto_summarize=False,
|
|
549
565
|
remember_history=False,
|
|
566
|
+
yolo_mode=True,
|
|
550
567
|
)
|
|
551
568
|
payload = json.dumps(
|
|
552
569
|
{
|
zrb/builtin/llm/tool/note.py
CHANGED
|
@@ -5,9 +5,9 @@ from zrb.config.llm_context.config import llm_context_config
|
|
|
5
5
|
|
|
6
6
|
def read_long_term_note() -> str:
|
|
7
7
|
"""
|
|
8
|
-
Retrieves the GLOBAL
|
|
8
|
+
Retrieves the GLOBAL 🧠 Long Term Note shared across ALL sessions and projects.
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
Use this to recall user preferences, facts, and cross-project context.
|
|
11
11
|
|
|
12
12
|
Returns:
|
|
13
13
|
str: The current global note content.
|
|
@@ -18,7 +18,7 @@ def read_long_term_note() -> str:
|
|
|
18
18
|
|
|
19
19
|
def write_long_term_note(content: str) -> str:
|
|
20
20
|
"""
|
|
21
|
-
Persists CRITICAL facts to the GLOBAL
|
|
21
|
+
Persists CRITICAL facts to the GLOBAL 🧠 Long Term Note.
|
|
22
22
|
|
|
23
23
|
USE EAGERLY to save or update:
|
|
24
24
|
- User preferences (e.g., "I prefer Python", "No unit tests").
|
|
@@ -27,7 +27,7 @@ def write_long_term_note(content: str) -> str:
|
|
|
27
27
|
- Cross-project goals.
|
|
28
28
|
- Anything that will be useful for future interaction across projects.
|
|
29
29
|
|
|
30
|
-
WARNING: This OVERWRITES the entire
|
|
30
|
+
WARNING: This OVERWRITES the entire Long Term Note.
|
|
31
31
|
|
|
32
32
|
Args:
|
|
33
33
|
content (str): The text to strictly memorize.
|
|
@@ -41,7 +41,7 @@ def write_long_term_note(content: str) -> str:
|
|
|
41
41
|
|
|
42
42
|
def read_contextual_note(path: str | None = None) -> str:
|
|
43
43
|
"""
|
|
44
|
-
Retrieves LOCAL
|
|
44
|
+
Retrieves LOCAL 📝 Contextual Note specific to a directory path.
|
|
45
45
|
|
|
46
46
|
Use to recall project-specific architecture, code summaries, or past decisions
|
|
47
47
|
relevant to the current working location.
|
|
@@ -61,7 +61,7 @@ def read_contextual_note(path: str | None = None) -> str:
|
|
|
61
61
|
|
|
62
62
|
def write_contextual_note(content: str, path: str | None = None) -> str:
|
|
63
63
|
"""
|
|
64
|
-
Persists LOCAL facts specific to a
|
|
64
|
+
Persists LOCAL facts specific to a directory into 📝 Contextual Note.
|
|
65
65
|
|
|
66
66
|
USE EAGERLY to save or update:
|
|
67
67
|
- Architectural patterns for this project/directory.
|
|
@@ -69,7 +69,7 @@ def write_contextual_note(content: str, path: str | None = None) -> str:
|
|
|
69
69
|
- Specific guidelines for this project.
|
|
70
70
|
- Anything related to this directory that will be useful for future interaction.
|
|
71
71
|
|
|
72
|
-
WARNING: This OVERWRITES the
|
|
72
|
+
WARNING: This OVERWRITES the entire Contextual Note for a directory.
|
|
73
73
|
|
|
74
74
|
Args:
|
|
75
75
|
content (str): The text to memorize for this location.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# This file makes the directory a Python package
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
from typing import Any
|
|
2
|
+
|
|
3
|
+
import requests
|
|
4
|
+
|
|
5
|
+
from zrb.config.config import CFG
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def search_internet(
|
|
9
|
+
query: str,
|
|
10
|
+
page: int = 1,
|
|
11
|
+
safe_search: str | None = None,
|
|
12
|
+
language: str | None = None,
|
|
13
|
+
) -> dict[str, Any]:
|
|
14
|
+
"""
|
|
15
|
+
Performs an internet search using Brave Search.
|
|
16
|
+
|
|
17
|
+
Use this tool to find up-to-date information, answer questions about current events,
|
|
18
|
+
or research topics using a search engine.
|
|
19
|
+
|
|
20
|
+
**EFFICIENCY TIP:**
|
|
21
|
+
Make your `query` specific and keyword-rich to get the best results in a single call.
|
|
22
|
+
Avoid vague queries that require follow-up searches.
|
|
23
|
+
Bad: "new python features"
|
|
24
|
+
Good: "python 3.12 new features list release date"
|
|
25
|
+
|
|
26
|
+
Args:
|
|
27
|
+
query (str): The natural language search query (e.g., 'Soto Madura').
|
|
28
|
+
Do NOT include instructions, meta-talk, or internal reasoning.
|
|
29
|
+
Use concise terms as a human would in a search engine.
|
|
30
|
+
page (int): Search result page number. Defaults to 1.
|
|
31
|
+
safe_search (str | None): Safety setting. 'strict', 'moderate', or 'off'.
|
|
32
|
+
If None, uses the system default configuration.
|
|
33
|
+
language (str | None): Language code (e.g., 'en').
|
|
34
|
+
If None, uses the system default configuration.
|
|
35
|
+
|
|
36
|
+
Returns:
|
|
37
|
+
dict: Summary of search results (titles, links, snippets).
|
|
38
|
+
"""
|
|
39
|
+
if safe_search is None:
|
|
40
|
+
safe_search = CFG.BRAVE_API_SAFE
|
|
41
|
+
if language is None:
|
|
42
|
+
language = CFG.BRAVE_API_LANG
|
|
43
|
+
|
|
44
|
+
user_agent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36" # noqa
|
|
45
|
+
|
|
46
|
+
response = requests.get(
|
|
47
|
+
"https://api.search.brave.com/res/v1/web/search",
|
|
48
|
+
headers={
|
|
49
|
+
"User-Agent": user_agent,
|
|
50
|
+
"Accept": "application/json",
|
|
51
|
+
"x-subscription-token": CFG.BRAVE_API_KEY,
|
|
52
|
+
},
|
|
53
|
+
params={
|
|
54
|
+
"q": query,
|
|
55
|
+
"count": "10",
|
|
56
|
+
"offset": (page - 1) * 10,
|
|
57
|
+
"safesearch": safe_search,
|
|
58
|
+
"search_lang": language,
|
|
59
|
+
"summary": "true",
|
|
60
|
+
},
|
|
61
|
+
)
|
|
62
|
+
if response.status_code != 200:
|
|
63
|
+
raise Exception(
|
|
64
|
+
f"Error: Unable to retrieve search results (status code: {response.status_code})"
|
|
65
|
+
)
|
|
66
|
+
return response.json()
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
from typing import Any
|
|
2
|
+
|
|
3
|
+
import requests
|
|
4
|
+
|
|
5
|
+
from zrb.config.config import CFG
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def search_internet(
|
|
9
|
+
query: str,
|
|
10
|
+
page: int = 1,
|
|
11
|
+
safe_search: int | None = None,
|
|
12
|
+
language: str | None = None,
|
|
13
|
+
) -> dict[str, Any]:
|
|
14
|
+
"""
|
|
15
|
+
Performs an internet search using SearXNG.
|
|
16
|
+
|
|
17
|
+
Use this tool to find up-to-date information, answer questions about current events,
|
|
18
|
+
or research topics using a search engine.
|
|
19
|
+
|
|
20
|
+
**EFFICIENCY TIP:**
|
|
21
|
+
Make your `query` specific and keyword-rich to get the best results in a single call.
|
|
22
|
+
Avoid vague queries that require follow-up searches.
|
|
23
|
+
Bad: "new python features"
|
|
24
|
+
Good: "python 3.12 new features list release date"
|
|
25
|
+
|
|
26
|
+
Args:
|
|
27
|
+
query (str): The natural language search query (e.g., 'Soto Madura').
|
|
28
|
+
Do NOT include instructions, meta-talk, or internal reasoning.
|
|
29
|
+
Use concise terms as a human would in a search engine.
|
|
30
|
+
page (int): Search result page number. Defaults to 1.
|
|
31
|
+
safe_search (int | None): Safety setting. 0 (None), 1 (Moderate), 2 (Strict).
|
|
32
|
+
If None, uses the system default configuration.
|
|
33
|
+
language (str | None): Language code (e.g., 'en').
|
|
34
|
+
If None, uses the system default configuration.
|
|
35
|
+
|
|
36
|
+
Returns:
|
|
37
|
+
dict: Summary of search results (titles, links, snippets).
|
|
38
|
+
"""
|
|
39
|
+
if safe_search is None:
|
|
40
|
+
safe_search = CFG.SEARXNG_SAFE
|
|
41
|
+
if language is None:
|
|
42
|
+
language = CFG.SEARXNG_LANG
|
|
43
|
+
|
|
44
|
+
user_agent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36" # noqa
|
|
45
|
+
|
|
46
|
+
response = requests.get(
|
|
47
|
+
url=f"{CFG.SEARXNG_BASE_URL}/search",
|
|
48
|
+
headers={"User-Agent": user_agent},
|
|
49
|
+
params={
|
|
50
|
+
"q": query,
|
|
51
|
+
"format": "json",
|
|
52
|
+
"pageno": page,
|
|
53
|
+
"safesearch": safe_search,
|
|
54
|
+
"language": language,
|
|
55
|
+
},
|
|
56
|
+
)
|
|
57
|
+
if response.status_code != 200:
|
|
58
|
+
raise Exception(
|
|
59
|
+
f"Error: Unable to retrieve search results (status code: {response.status_code})"
|
|
60
|
+
)
|
|
61
|
+
return response.json()
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
from typing import Any
|
|
2
|
+
|
|
3
|
+
import requests
|
|
4
|
+
|
|
5
|
+
from zrb.config.config import CFG
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def search_internet(
|
|
9
|
+
query: str,
|
|
10
|
+
page: int = 1,
|
|
11
|
+
safe_search: str | None = None,
|
|
12
|
+
language: str | None = None,
|
|
13
|
+
) -> dict[str, Any]:
|
|
14
|
+
"""
|
|
15
|
+
Performs an internet search using SerpApi (Google).
|
|
16
|
+
|
|
17
|
+
Use this tool to find up-to-date information, answer questions about current events,
|
|
18
|
+
or research topics using a search engine.
|
|
19
|
+
|
|
20
|
+
**EFFICIENCY TIP:**
|
|
21
|
+
Make your `query` specific and keyword-rich to get the best results in a single call.
|
|
22
|
+
Avoid vague queries that require follow-up searches.
|
|
23
|
+
Bad: "new python features"
|
|
24
|
+
Good: "python 3.12 new features list release date"
|
|
25
|
+
|
|
26
|
+
Args:
|
|
27
|
+
query (str): The natural language search query (e.g., 'Soto Madura').
|
|
28
|
+
Do NOT include instructions, meta-talk, or internal reasoning.
|
|
29
|
+
Use concise terms as a human would in a search engine.
|
|
30
|
+
page (int): Search result page number. Defaults to 1.
|
|
31
|
+
safe_search (str | None): Safety setting. 'active' or 'off'.
|
|
32
|
+
If None, uses the system default configuration.
|
|
33
|
+
language (str | None): Two-letter language code (e.g., 'en', 'id').
|
|
34
|
+
If None, uses the system default configuration.
|
|
35
|
+
|
|
36
|
+
Returns:
|
|
37
|
+
dict: Summary of search results (titles, links, snippets).
|
|
38
|
+
"""
|
|
39
|
+
if safe_search is None:
|
|
40
|
+
safe_search = CFG.SERPAPI_SAFE
|
|
41
|
+
if language is None:
|
|
42
|
+
language = CFG.SERPAPI_LANG
|
|
43
|
+
|
|
44
|
+
user_agent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36" # noqa
|
|
45
|
+
|
|
46
|
+
response = requests.get(
|
|
47
|
+
"https://serpapi.com/search",
|
|
48
|
+
headers={"User-Agent": user_agent},
|
|
49
|
+
params={
|
|
50
|
+
"q": query,
|
|
51
|
+
"start": (page - 1) * 10,
|
|
52
|
+
"hl": language,
|
|
53
|
+
"safe": safe_search,
|
|
54
|
+
"api_key": CFG.SERPAPI_KEY,
|
|
55
|
+
},
|
|
56
|
+
)
|
|
57
|
+
if response.status_code != 200:
|
|
58
|
+
raise Exception(
|
|
59
|
+
f"Error: Unable to retrieve search results (status code: {response.status_code})"
|
|
60
|
+
)
|
|
61
|
+
return response.json()
|
|
@@ -7,6 +7,7 @@ from zrb.context.any_context import AnyContext
|
|
|
7
7
|
from zrb.task.llm.agent import create_agent_instance
|
|
8
8
|
from zrb.task.llm.agent_runner import run_agent_iteration
|
|
9
9
|
from zrb.task.llm.config import get_model, get_model_settings
|
|
10
|
+
from zrb.task.llm.history_list import remove_system_prompt_and_instruction
|
|
10
11
|
from zrb.task.llm.prompt import get_system_and_user_prompt
|
|
11
12
|
from zrb.task.llm.subagent_conversation_history import (
|
|
12
13
|
get_ctx_subagent_history,
|
|
@@ -127,7 +128,9 @@ def create_sub_agent_tool(
|
|
|
127
128
|
set_ctx_subagent_history(
|
|
128
129
|
ctx,
|
|
129
130
|
agent_name,
|
|
130
|
-
|
|
131
|
+
remove_system_prompt_and_instruction(
|
|
132
|
+
json.loads(sub_agent_run.result.all_messages_json())
|
|
133
|
+
),
|
|
131
134
|
)
|
|
132
135
|
return sub_agent_run.result.output
|
|
133
136
|
ctx.log_warning("Sub-agent run did not produce a result.")
|
zrb/builtin/llm/tool/web.py
CHANGED
|
@@ -2,6 +2,7 @@ from collections.abc import Callable
|
|
|
2
2
|
from typing import Any
|
|
3
3
|
from urllib.parse import urljoin
|
|
4
4
|
|
|
5
|
+
from zrb.builtin.llm.tool.search import brave, searxng, serpapi
|
|
5
6
|
from zrb.config.config import CFG
|
|
6
7
|
from zrb.config.llm_config import llm_config
|
|
7
8
|
|
|
@@ -13,6 +14,11 @@ async def open_web_page(url: str) -> dict[str, Any]:
|
|
|
13
14
|
Fetches, parses, and converts a web page to readable Markdown.
|
|
14
15
|
Preserves semantic structure, removes non-essentials, and extracts all absolute links.
|
|
15
16
|
|
|
17
|
+
**EFFICIENCY TIP:**
|
|
18
|
+
Use this tool to read the full content of a specific search result or article.
|
|
19
|
+
It returns clean Markdown and a list of links, which is perfect for deep-diving
|
|
20
|
+
into a topic without navigating a browser UI.
|
|
21
|
+
|
|
16
22
|
Example:
|
|
17
23
|
open_web_page(url='https://www.example.com/article')
|
|
18
24
|
|
|
@@ -30,78 +36,17 @@ async def open_web_page(url: str) -> dict[str, Any]:
|
|
|
30
36
|
def create_search_internet_tool() -> Callable:
|
|
31
37
|
if llm_config.default_search_internet_tool is not None:
|
|
32
38
|
return llm_config.default_search_internet_tool
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
""
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
page (int, optional): Search result page number. Defaults to 1.
|
|
45
|
-
|
|
46
|
-
Returns:
|
|
47
|
-
dict: Summary of search results (titles, links, snippets).
|
|
48
|
-
"""
|
|
49
|
-
import requests
|
|
50
|
-
|
|
51
|
-
if (
|
|
52
|
-
CFG.SEARCH_INTERNET_METHOD.strip().lower() == "serpapi"
|
|
53
|
-
and CFG.SERPAPI_KEY != ""
|
|
54
|
-
):
|
|
55
|
-
response = requests.get(
|
|
56
|
-
"https://serpapi.com/search",
|
|
57
|
-
headers={"User-Agent": _DEFAULT_USER_AGENT},
|
|
58
|
-
params={
|
|
59
|
-
"q": query,
|
|
60
|
-
"start": (page - 1) * 10,
|
|
61
|
-
"hl": CFG.SERPAPI_LANG,
|
|
62
|
-
"safe": CFG.SERPAPI_SAFE,
|
|
63
|
-
"api_key": CFG.SERPAPI_KEY,
|
|
64
|
-
},
|
|
65
|
-
)
|
|
66
|
-
elif (
|
|
67
|
-
CFG.SEARCH_INTERNET_METHOD.strip().lower() == "brave"
|
|
68
|
-
and CFG.BRAVE_API_KEY != ""
|
|
69
|
-
):
|
|
70
|
-
response = requests.get(
|
|
71
|
-
"https://api.search.brave.com/res/v1/web/search",
|
|
72
|
-
headers={
|
|
73
|
-
"User-Agent": _DEFAULT_USER_AGENT,
|
|
74
|
-
"Accept": "application/json",
|
|
75
|
-
"x-subscription-token": CFG.BRAVE_API_KEY,
|
|
76
|
-
},
|
|
77
|
-
params={
|
|
78
|
-
"q": query,
|
|
79
|
-
"count": "10",
|
|
80
|
-
"offset": (page - 1) * 10,
|
|
81
|
-
"safesearch": CFG.BRAVE_API_SAFE,
|
|
82
|
-
"search_lang": CFG.BRAVE_API_LANG,
|
|
83
|
-
"summary": "true",
|
|
84
|
-
},
|
|
85
|
-
)
|
|
86
|
-
else:
|
|
87
|
-
response = requests.get(
|
|
88
|
-
url=f"{CFG.SEARXNG_BASE_URL}/search",
|
|
89
|
-
headers={"User-Agent": _DEFAULT_USER_AGENT},
|
|
90
|
-
params={
|
|
91
|
-
"q": query,
|
|
92
|
-
"format": "json",
|
|
93
|
-
"pageno": page,
|
|
94
|
-
"safesearch": CFG.SEARXNG_SAFE,
|
|
95
|
-
"language": CFG.SEARXNG_LANG,
|
|
96
|
-
},
|
|
97
|
-
)
|
|
98
|
-
if response.status_code != 200:
|
|
99
|
-
raise Exception(
|
|
100
|
-
f"Error: Unable to retrieve search results (status code: {response.status_code})" # noqa
|
|
101
|
-
)
|
|
102
|
-
return response.json()
|
|
103
|
-
|
|
104
|
-
return search_internet
|
|
39
|
+
if (
|
|
40
|
+
CFG.SEARCH_INTERNET_METHOD.strip().lower() == "serpapi"
|
|
41
|
+
and CFG.SERPAPI_KEY != ""
|
|
42
|
+
):
|
|
43
|
+
return serpapi.search_internet
|
|
44
|
+
if (
|
|
45
|
+
CFG.SEARCH_INTERNET_METHOD.strip().lower() == "brave"
|
|
46
|
+
and CFG.BRAVE_API_KEY != ""
|
|
47
|
+
):
|
|
48
|
+
return brave.search_internet
|
|
49
|
+
return searxng.search_internet
|
|
105
50
|
|
|
106
51
|
|
|
107
52
|
async def _fetch_page_content(url: str) -> tuple[str, list[str]]:
|
zrb/cmd/cmd_result.py
CHANGED
zrb/config/config.py
CHANGED
|
@@ -345,6 +345,10 @@ class Config:
|
|
|
345
345
|
value = self._getenv("LLM_SUMMARIZATION_PROMPT")
|
|
346
346
|
return None if value == "" else value
|
|
347
347
|
|
|
348
|
+
@property
|
|
349
|
+
def LLM_SHOW_TOOL_CALL_PREPARATION(self) -> bool:
|
|
350
|
+
return to_boolean(self._getenv("LLM_SHOW_TOOL_CALL_PREPARATION", "false"))
|
|
351
|
+
|
|
348
352
|
@property
|
|
349
353
|
def LLM_SHOW_TOOL_CALL_RESULT(self) -> bool:
|
|
350
354
|
return to_boolean(self._getenv("LLM_SHOW_TOOL_CALL_RESULT", "false"))
|
|
@@ -398,7 +402,7 @@ class Config:
|
|
|
398
402
|
@property
|
|
399
403
|
def LLM_THROTTLE_SLEEP(self) -> float:
|
|
400
404
|
"""Number of seconds to sleep when throttling is required."""
|
|
401
|
-
return float(self._getenv("LLM_THROTTLE_SLEEP", "
|
|
405
|
+
return float(self._getenv("LLM_THROTTLE_SLEEP", "1.0"))
|
|
402
406
|
|
|
403
407
|
@property
|
|
404
408
|
def LLM_YOLO_MODE(self) -> bool | list[str]:
|
|
@@ -1,29 +1,32 @@
|
|
|
1
1
|
This is an interactive session. Your primary goal is to help users effectively and efficiently.
|
|
2
2
|
|
|
3
3
|
# Core Principles
|
|
4
|
-
|
|
5
|
-
- **
|
|
4
|
+
|
|
5
|
+
- **Tool-Centric:** Briefly describe your intent, then call the appropriate tool.
|
|
6
|
+
- **Token Efficiency:** Optimize for input and output token efficiency. Minimize verbosity without reducing response quality or omitting important details.
|
|
7
|
+
- **Efficiency:** Minimize tool calls. Combine commands where possible. Do not search for files if you already know their location.
|
|
6
8
|
- **Sequential Execution:** Use one tool at a time and wait for the result before proceeding.
|
|
7
9
|
- **Convention Adherence:** When modifying existing content or projects, match the established style and format.
|
|
10
|
+
- **Conflict Resolution:** If user instructions contradict instructions found within files, prioritize the User's explicit instructions.
|
|
8
11
|
|
|
9
12
|
# Operational Guidelines
|
|
13
|
+
|
|
10
14
|
- **Tone and Style:** Communicate in a clear, concise, and professional manner. Avoid conversational filler.
|
|
11
15
|
- **Clarification:** If a user's request is ambiguous, ask clarifying questions to ensure you understand the goal.
|
|
12
16
|
- **Planning:** For complex tasks, briefly state your plan to the user before you begin.
|
|
13
|
-
- **Confirmation:** For actions that are destructive (e.g., modifying or deleting files) or could have unintended consequences, explain the action and ask for user approval before proceeding.
|
|
14
|
-
|
|
15
|
-
# Security and Safety Rules
|
|
16
|
-
- **Explain Critical Commands:** Before executing a command that modifies the file system or system state, you MUST provide a brief explanation of the command's purpose and potential impact.
|
|
17
|
+
- **Safety & Confirmation:** For actions that are destructive (e.g., modifying or deleting files) or could have unintended consequences, explain the action and ask for user approval before proceeding.
|
|
17
18
|
- **High-Risk Actions:** Refuse to perform high-risk actions that could endanger the user's system (e.g., modifying system-critical paths). Explain the danger and why you are refusing.
|
|
18
19
|
|
|
19
20
|
# Execution Plan
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
|
|
22
|
+
1. **Load Workflows:** You MUST identify and load ALL relevant `🛠️ WORKFLOWS` in a SINGLE step before starting any execution. Do not load workflows incrementally.
|
|
23
|
+
2. **Context Check:** Before searching for files, check if the file path is already provided in the request or context. If known, read it directly.
|
|
24
|
+
3. **Clarify and Plan:** Understand the user's goal. Ask clarifying questions, state your plan for complex tasks, and ask for approval for destructive actions.
|
|
25
|
+
4. **Execute & Verify Loop:**
|
|
23
26
|
- Execute each step of your plan.
|
|
24
|
-
- **
|
|
25
|
-
|
|
27
|
+
- **Smart Verification:** Verify outcomes efficiently. Use concise commands (e.g., `python -m py_compile script.py`) instead of heavy operations unless necessary.
|
|
28
|
+
5. **Error Handling:**
|
|
26
29
|
- Do not give up on failures. Analyze error messages and exit codes to understand the root cause.
|
|
27
30
|
- Formulate a specific hypothesis and execute a corrected action.
|
|
28
31
|
- Exhaust all reasonable fixes before asking the user for help.
|
|
29
|
-
|
|
32
|
+
6. **Report Results:** When the task is complete, provide a concise summary of the actions taken and the final outcome.
|
|
@@ -1,38 +1,36 @@
|
|
|
1
|
-
This is a single request session.
|
|
1
|
+
This is a single request session. Your primary goal is to complete the task directly, effectively, and efficiently, with minimal interaction.
|
|
2
2
|
|
|
3
3
|
# Core Principles
|
|
4
4
|
|
|
5
|
-
- **Tool-Centric:** Call tools directly without describing
|
|
6
|
-
- **Efficiency:**
|
|
7
|
-
- **
|
|
5
|
+
- **Tool-Centric:** Call tools directly without describing actions beforehand. Only communicate to report the final result.
|
|
6
|
+
- **Token Efficiency:** Optimize for input and output token efficiency. Minimize verbosity without reducing response quality or omitting important details.
|
|
7
|
+
- **Efficiency:** Minimize tool calls. Combine commands where possible. Do not search for files if you already know their location.
|
|
8
|
+
- **Sequential Execution:** Use one tool at a time and wait for the result before proceeding.
|
|
8
9
|
- **Convention Adherence:** When modifying existing content or projects, match the established style and format.
|
|
9
10
|
- **Proactiveness:** Fulfill the user's request thoroughly and anticipate their needs.
|
|
10
|
-
- **Confirm Ambiguity:** If a request is unclear, do not guess. Ask for clarification.
|
|
11
11
|
|
|
12
12
|
# Operational Guidelines
|
|
13
13
|
|
|
14
|
-
- **
|
|
14
|
+
- **Tone and Style:** Adopt a professional, direct, and concise tone.
|
|
15
15
|
- **Tools vs. Text:** Use tools for actions. Use text output only for reporting final results. Do not add explanatory comments within tool calls.
|
|
16
16
|
- **Handling Inability:** If you are unable to fulfill a request, state so briefly and offer alternatives if appropriate.
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
- **Explain Critical Commands:** Before executing commands that modify the file system or system state, you MUST provide a brief explanation of the command's purpose and potential impact.
|
|
21
|
-
- **Security First:** Always apply security best practices. Never introduce code that exposes secrets or sensitive information.
|
|
17
|
+
- **Safety & Confirmation:** Explain destructive actions (modifying/deleting files) briefly before execution if safety protocols require it.
|
|
18
|
+
- **Confirm Ambiguity:** If a request is unclear, do not guess. Ask for clarification (this is the only exception to "minimal interaction").
|
|
22
19
|
|
|
23
20
|
# Execution Plan
|
|
24
21
|
|
|
25
|
-
1. **Load Workflows:** You MUST identify and load
|
|
26
|
-
2. **
|
|
27
|
-
3. **
|
|
22
|
+
1. **Load Workflows:** You MUST identify and load ALL relevant `🛠️ WORKFLOWS` in a SINGLE step before starting any execution. Do not load workflows incrementally.
|
|
23
|
+
2. **Context Check:** Before searching for files, check if the file path is already provided in the request or context. If known, read it directly.
|
|
24
|
+
3. **Plan:** Devise a clear, step-by-step internal plan.
|
|
25
|
+
4. **Risk Assessment:**
|
|
28
26
|
- **Safe actions (read-only, creating new files):** Proceed directly.
|
|
29
27
|
- **Destructive actions (modifying/deleting files):** For low-risk changes, proceed. For moderate/high-risk, explain the action and ask for confirmation.
|
|
30
28
|
- **High-risk actions (touching system paths):** Refuse and explain the danger.
|
|
31
|
-
|
|
29
|
+
5. **Execute & Verify Loop:**
|
|
32
30
|
- Execute each step of your plan.
|
|
33
|
-
- **
|
|
34
|
-
|
|
31
|
+
- **Smart Verification:** Verify outcomes efficiently. Use concise commands (e.g., `python -m py_compile script.py`) instead of heavy operations unless necessary.
|
|
32
|
+
6. **Error Handling:**
|
|
35
33
|
- Do not give up on failures. Analyze error messages and exit codes to understand the root cause.
|
|
36
34
|
- Formulate a specific hypothesis about the cause and execute a corrected action.
|
|
37
35
|
- Exhaust all reasonable fixes before reporting failure.
|
|
38
|
-
|
|
36
|
+
7. **Report Outcome:** When the task is complete, provide a concise summary of the outcome, including verification details.
|