zrb 1.9.5__py3-none-any.whl → 1.9.6__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.
- zrb/builtin/llm/llm_ask.py +2 -2
- zrb/builtin/llm/tool/api.py +19 -9
- zrb/builtin/llm/tool/cli.py +11 -5
- zrb/builtin/llm/tool/code.py +19 -19
- zrb/builtin/llm/tool/file.py +106 -154
- zrb/builtin/llm/tool/rag.py +27 -4
- zrb/builtin/llm/tool/sub_agent.py +12 -14
- zrb/builtin/llm/tool/web.py +46 -14
- zrb/config/llm_config.py +142 -157
- zrb-1.9.6.dist-info/METADATA +250 -0
- {zrb-1.9.5.dist-info → zrb-1.9.6.dist-info}/RECORD +13 -13
- zrb-1.9.5.dist-info/METADATA +0 -245
- {zrb-1.9.5.dist-info → zrb-1.9.6.dist-info}/WHEEL +0 -0
- {zrb-1.9.5.dist-info → zrb-1.9.6.dist-info}/entry_points.txt +0 -0
zrb/builtin/llm/tool/web.py
CHANGED
@@ -3,11 +3,16 @@ from collections.abc import Callable
|
|
3
3
|
|
4
4
|
|
5
5
|
async def open_web_page(url: str) -> str:
|
6
|
-
"""
|
6
|
+
"""
|
7
|
+
Fetches and parses the textual content of a given web page URL.
|
8
|
+
|
9
|
+
Use this tool to "read" a web page. It strips away HTML tags, scripts, and other non-textual elements to provide the clean text content. It also extracts any hyperlinks found on the page. This is useful when you need to understand the content of a specific URL that you have discovered through a search or from another source.
|
10
|
+
|
7
11
|
Args:
|
8
|
-
url (str): The URL of the web page to open.
|
12
|
+
url (str): The full URL of the web page to open (e.g., "https://example.com/article").
|
13
|
+
|
9
14
|
Returns:
|
10
|
-
str: JSON
|
15
|
+
str: A JSON object containing the cleaned text `content` of the page and a list of `links_on_page`.
|
11
16
|
"""
|
12
17
|
|
13
18
|
async def get_page_content(page_url: str):
|
@@ -57,13 +62,30 @@ async def open_web_page(url: str) -> str:
|
|
57
62
|
|
58
63
|
|
59
64
|
def create_search_internet_tool(serp_api_key: str) -> Callable[[str, int], str]:
|
65
|
+
"""
|
66
|
+
Creates a tool that searches the internet using the SerpAPI Google Search API.
|
67
|
+
|
68
|
+
This factory returns a function that can be used to find information on the web. The generated tool is the primary way to answer general knowledge questions or to find information on topics you are unfamiliar with.
|
69
|
+
|
70
|
+
Args:
|
71
|
+
serp_api_key (str): The API key for SerpAPI.
|
72
|
+
|
73
|
+
Returns:
|
74
|
+
Callable: A function that takes a search query and returns a list of search results.
|
75
|
+
"""
|
76
|
+
|
60
77
|
def search_internet(query: str, num_results: int = 10) -> str:
|
61
|
-
"""
|
78
|
+
"""
|
79
|
+
Performs an internet search using Google and returns a summary of the results.
|
80
|
+
|
81
|
+
Use this tool to find information on the web, answer general knowledge questions, or research topics.
|
82
|
+
|
62
83
|
Args:
|
63
|
-
query (str):
|
64
|
-
num_results (int):
|
84
|
+
query (str): The search query.
|
85
|
+
num_results (int, optional): The desired number of search results. Defaults to 10.
|
86
|
+
|
65
87
|
Returns:
|
66
|
-
str: JSON
|
88
|
+
str: A JSON object containing the parsed text content from the search results page.
|
67
89
|
"""
|
68
90
|
import requests
|
69
91
|
|
@@ -90,11 +112,16 @@ def create_search_internet_tool(serp_api_key: str) -> Callable[[str, int], str]:
|
|
90
112
|
|
91
113
|
|
92
114
|
def search_wikipedia(query: str) -> str:
|
93
|
-
"""
|
115
|
+
"""
|
116
|
+
Searches for articles on Wikipedia.
|
117
|
+
|
118
|
+
This is a specialized search tool for querying Wikipedia. It's best for when the user is asking for definitions, historical information, or biographical details that are likely to be found on an encyclopedia.
|
119
|
+
|
94
120
|
Args:
|
95
|
-
query (str):
|
121
|
+
query (str): The search term or question.
|
122
|
+
|
96
123
|
Returns:
|
97
|
-
str: JSON from Wikipedia API
|
124
|
+
str: The raw JSON response from the Wikipedia API, containing a list of search results.
|
98
125
|
"""
|
99
126
|
import requests
|
100
127
|
|
@@ -104,12 +131,17 @@ def search_wikipedia(query: str) -> str:
|
|
104
131
|
|
105
132
|
|
106
133
|
def search_arxiv(query: str, num_results: int = 10) -> str:
|
107
|
-
"""
|
134
|
+
"""
|
135
|
+
Searches for academic papers and preprints on ArXiv.
|
136
|
+
|
137
|
+
Use this tool when the user's query is scientific or technical in nature and they are likely looking for research papers, articles, or academic publications.
|
138
|
+
|
108
139
|
Args:
|
109
|
-
query (str):
|
110
|
-
num_results (int):
|
140
|
+
query (str): The search query, which can include keywords, author names, or titles.
|
141
|
+
num_results (int, optional): The maximum number of results to return. Defaults to 10.
|
142
|
+
|
111
143
|
Returns:
|
112
|
-
str: XML
|
144
|
+
str: The raw XML response from the ArXiv API, containing a list of matching papers.
|
113
145
|
"""
|
114
146
|
import requests
|
115
147
|
|
zrb/config/llm_config.py
CHANGED
@@ -9,185 +9,170 @@ if TYPE_CHECKING:
|
|
9
9
|
|
10
10
|
|
11
11
|
DEFAULT_PERSONA = (
|
12
|
-
"You are a helpful and
|
13
|
-
|
14
|
-
"information, execute tasks, and solve problems. Always be accurate, "
|
15
|
-
"efficient, and get straight to the point."
|
16
|
-
).strip()
|
12
|
+
"You are a helpful and efficient AI agent specializing in CLI " "interaction."
|
13
|
+
)
|
17
14
|
|
18
15
|
DEFAULT_INTERACTIVE_SYSTEM_PROMPT = (
|
19
|
-
"This is an interactive session.
|
20
|
-
"this
|
21
|
-
"
|
22
|
-
"
|
23
|
-
"
|
24
|
-
"
|
25
|
-
"
|
26
|
-
"
|
27
|
-
"
|
28
|
-
"
|
29
|
-
"
|
30
|
-
"
|
31
|
-
"
|
32
|
-
"
|
33
|
-
"
|
34
|
-
"action
|
35
|
-
"
|
16
|
+
"This is an interactive CLI session. Your standard response format is\n"
|
17
|
+
"GitHub-flavored Markdown. You MUST follow this thinking process:\n\n"
|
18
|
+
"1. **Analyze Request:** Use the `Scratchpad` and `Narrative Summary` to\n"
|
19
|
+
" fully understand the user's request in the context of the\n"
|
20
|
+
" conversation.\n\n"
|
21
|
+
"2. **Plan & Verify Pre-conditions:** Create a step-by-step plan. Before\n"
|
22
|
+
" executing, use read-only tools to check the current state. For\n"
|
23
|
+
" example, if the plan is to create a file, check if it already\n"
|
24
|
+
" exists. If pre-conditions are not as expected, inform the user.\n\n"
|
25
|
+
"3. **Assess Consent & Execute:**\n"
|
26
|
+
" - If the user's last instruction was an explicit command (e.g.,\n"
|
27
|
+
' "create file X", "delete Y"), you have consent. Proceed with the\n'
|
28
|
+
" action.\n"
|
29
|
+
' - If the request was general (e.g., "fix the bug") and your plan\n'
|
30
|
+
" involves a potentially altering action, you MUST explain the\n"
|
31
|
+
" action and ask for user approval before proceeding.\n\n"
|
32
|
+
"4. **Verify Outcome:** After executing the action, use read-only tools to\n"
|
33
|
+
" confirm it was successful. Report the outcome to the user.\n\n"
|
34
|
+
"For software engineering tasks, you MUST follow the guidelines in the\n"
|
35
|
+
"`DEFAULT_SPECIAL_INSTRUCTION_PROMPT`."
|
36
36
|
).strip()
|
37
37
|
|
38
38
|
DEFAULT_SYSTEM_PROMPT = (
|
39
|
-
"
|
40
|
-
"
|
41
|
-
"
|
42
|
-
"
|
43
|
-
"
|
44
|
-
"2. **
|
45
|
-
"
|
46
|
-
"
|
47
|
-
"
|
39
|
+
"This is a one-shot CLI session. Your final answer MUST be in\n"
|
40
|
+
"GitHub-flavored Markdown. You MUST follow this thinking process:\n\n"
|
41
|
+
"1. **Analyze Request:** Use the `Scratchpad` and `Narrative Summary` to\n"
|
42
|
+
" fully understand the user's request in the context of the\n"
|
43
|
+
" conversation.\n\n"
|
44
|
+
"2. **Plan & Verify Pre-conditions:** Create a step-by-step plan. Before\n"
|
45
|
+
" executing, use read-only tools to check the current state. For\n"
|
46
|
+
" example, if the plan is to create a file, check if it already\n"
|
47
|
+
" exists. If pre-conditions are not as expected, state that and stop.\n\n"
|
48
|
+
"3. **Assess Consent & Execute:**\n"
|
49
|
+
" - If the user's last instruction was an explicit command (e.g.,\n"
|
50
|
+
' "create file X", "delete Y"), you have consent. Proceed with the\n'
|
51
|
+
" action.\n"
|
52
|
+
' - If the request was general (e.g., "fix the bug") and your plan\n'
|
53
|
+
" involves a potentially altering action, you MUST explain the\n"
|
54
|
+
" action and ask for user approval before proceeding.\n\n"
|
55
|
+
"4. **Verify Outcome:** After executing the action, use read-only tools to\n"
|
56
|
+
" confirm it was successful. Report the outcome to the user.\n\n"
|
57
|
+
"For software engineering tasks, you MUST follow the guidelines in the\n"
|
58
|
+
"`DEFAULT_SPECIAL_INSTRUCTION_PROMPT`."
|
48
59
|
).strip()
|
49
60
|
|
50
61
|
DEFAULT_SPECIAL_INSTRUCTION_PROMPT = (
|
51
|
-
"
|
52
|
-
"
|
53
|
-
"
|
54
|
-
"
|
55
|
-
"
|
56
|
-
"
|
57
|
-
"
|
58
|
-
"
|
59
|
-
"
|
60
|
-
"
|
61
|
-
"
|
62
|
-
"
|
63
|
-
"
|
64
|
-
"configuration
|
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
|
-
"
|
62
|
+
"## Software Engineering Tasks\n"
|
63
|
+
"When requested to perform tasks like fixing bugs, adding features,\n"
|
64
|
+
"refactoring, or explaining code, follow this sequence:\n"
|
65
|
+
"1. **Understand:** Think about the user's request and the relevant\n"
|
66
|
+
"codebase context. Use your tools to understand file structures,\n"
|
67
|
+
"existing code patterns, and conventions.\n"
|
68
|
+
"2. **Plan:** Build a coherent and grounded plan. Share an extremely\n"
|
69
|
+
"concise yet clear plan with the user.\n"
|
70
|
+
"3. **Implement:** Use the available tools to act on the plan, strictly\n"
|
71
|
+
"adhering to the project's established conventions.\n"
|
72
|
+
"4. **Verify (Tests):** If applicable and feasible, verify the changes\n"
|
73
|
+
"using the project's testing procedures. Identify the correct test\n"
|
74
|
+
"commands and frameworks by examining 'README' files, build/package\n"
|
75
|
+
"configuration, or existing test execution patterns. NEVER assume\n"
|
76
|
+
"standard test commands.\n"
|
77
|
+
"5. **Verify (Standards):** After making code changes, execute the\n"
|
78
|
+
"project-specific build, linting and type-checking commands. This\n"
|
79
|
+
"ensures code quality and adherence to standards.\n\n"
|
80
|
+
"## New Applications\n"
|
81
|
+
"When asked to create a new application, follow this workflow:\n"
|
82
|
+
"1. **Understand Requirements:** Analyze the user's request to identify\n"
|
83
|
+
"core features, application type, and constraints.\n"
|
84
|
+
"2. **Propose Plan:** Formulate a development plan. Present a clear,\n"
|
85
|
+
"concise, high-level summary to the user, including technologies to be\n"
|
86
|
+
"used.\n"
|
87
|
+
"3. **User Approval:** Obtain user approval for the proposed plan.\n"
|
88
|
+
"4. **Implementation:** Autonomously implement each feature and design\n"
|
89
|
+
"element per the approved plan.\n"
|
90
|
+
"5. **Verify:** Review work against the original request and the approved\n"
|
91
|
+
"plan. Ensure the application builds and runs without errors.\n"
|
92
|
+
"6. **Solicit Feedback:** Provide instructions on how to start the\n"
|
93
|
+
"application and request user feedback.\n\n"
|
94
|
+
"## Git Repository\n"
|
95
|
+
"If you are in a git repository, you can be asked to commit changes:\n"
|
96
|
+
"- Use `git status` to ensure all relevant files are tracked and staged.\n"
|
97
|
+
"- Use `git diff HEAD` to review all changes.\n"
|
98
|
+
"- Use `git log -n 3` to review recent commit messages and match their\n"
|
99
|
+
"style.\n"
|
100
|
+
"- Propose a draft commit message. Never just ask the user to give you\n"
|
101
|
+
"the full commit message.\n\n"
|
102
|
+
"## Researching\n"
|
103
|
+
"When asked to research a topic, follow this workflow:\n"
|
104
|
+
"1. **Understand:** Clarify the research question and the desired output\n"
|
105
|
+
"format (e.g., summary, list of key points).\n"
|
106
|
+
"2. **Search:** Use your tools to gather information from multiple reputable \n"
|
107
|
+
"sources.\n"
|
108
|
+
"3. **Synthesize & Cite:** Present the information in the requested\n"
|
109
|
+
"format. For every piece of information, you MUST provide a citation\n"
|
110
|
+
"with the source URL."
|
97
111
|
).strip()
|
98
112
|
|
113
|
+
|
99
114
|
DEFAULT_SUMMARIZATION_PROMPT = (
|
100
|
-
"You are a Conversation Historian
|
101
|
-
"
|
102
|
-
"assistant
|
115
|
+
"You are a Conversation Historian. Your task is to distill the\n"
|
116
|
+
"conversation history into a dense, structured snapshot for the main\n"
|
117
|
+
"assistant. This snapshot is CRITICAL, as it will become the agent's\n"
|
118
|
+
"primary short-term memory.\n\n"
|
103
119
|
"## Historian Protocol\n"
|
104
|
-
"You
|
105
|
-
"
|
106
|
-
"
|
107
|
-
"
|
108
|
-
"
|
109
|
-
"
|
110
|
-
"
|
111
|
-
"
|
112
|
-
"
|
113
|
-
"
|
114
|
-
"
|
115
|
-
"
|
116
|
-
"
|
117
|
-
"
|
118
|
-
"
|
120
|
+
"You will receive a `Previous Summary` and the `Recent Conversation\n"
|
121
|
+
"History`. Your job is to create a new, updated summary.\n\n"
|
122
|
+
"### 1. Update the Narrative Summary\n"
|
123
|
+
"- **Integrate:** Weave the key events from the `Recent Conversation\n"
|
124
|
+
" History` into the `Narrative Summary`.\n"
|
125
|
+
"- **Condense and Prune:** As you add new information, you MUST condense\n"
|
126
|
+
" older parts of the narrative. Be incredibly dense with information.\n"
|
127
|
+
" Omit any irrelevant conversational filler. The summary should be a\n"
|
128
|
+
" rolling, high-level overview, not an ever-expanding log.\n\n"
|
129
|
+
"### 2. Update the Scratchpad\n"
|
130
|
+
"- **Purpose:** The Scratchpad is the assistant's working memory. It must\n"
|
131
|
+
" contain the last few turns of the conversation in full, non-truncated\n"
|
132
|
+
" detail.\n"
|
133
|
+
"- **ABSOLUTE REQUIREMENT: The assistant's response MUST be COPIED\n"
|
134
|
+
" VERBATIM into the Scratchpad. It is CRITICAL that you DO NOT\n"
|
135
|
+
" truncate, summarize, use placeholders, or alter the assistant's\n"
|
136
|
+
" response in any way. The entire, full response must be preserved.**\n"
|
137
|
+
"- **Format:** Present the assistant's turn as: `assistant (thought:\n"
|
138
|
+
" brief summary of action) final response`.\n\n"
|
119
139
|
"### 3. Output Specification\n"
|
120
|
-
"Your entire output MUST be a single block of text
|
121
|
-
"
|
122
|
-
"1. `## Narrative Summary` (The updated narrative)\n"
|
123
|
-
"2. `##
|
124
|
-
"---\n"
|
125
|
-
"## Example\n\n"
|
126
|
-
"### Input to You:\n\n"
|
127
|
-
"--- previous_summary ---\n"
|
128
|
-
"## Narrative Summary\n"
|
129
|
-
"The user, working on the 'Apollo' project, requested to refactor "
|
130
|
-
"`auth.py`.\n"
|
131
|
-
"## Recent History\n"
|
132
|
-
"user: I need to refactor auth.py to use the new 'requests' library.\n"
|
133
|
-
"assistant: Understood. I am starting the refactoring now.\n"
|
134
|
-
"user: Has it been completed?\n"
|
135
|
-
"assistant: Yes. The refactoring of `auth.py` is complete and all tests "
|
136
|
-
"are passing.\n"
|
137
|
-
"--- recent_conversation_history ---\n"
|
138
|
-
"user: Excellent. Now, please update the documentation in README.md.\n"
|
139
|
-
"assistant: I have updated the README.md file with the new documentation.\n"
|
140
|
-
"user: Looks good. Can you commit the changes for me?\n"
|
141
|
-
"assistant: Of course. What should the commit message be?\n\n"
|
142
|
-
"### Your Correct Output:\n"
|
143
|
-
"## Narrative Summary\n"
|
144
|
-
"The user, working on the 'Apollo' project, requested to refactor "
|
145
|
-
"`auth.py`. This was completed successfully. The user then asked to "
|
146
|
-
"update the documentation in `README.md`, which was also completed.\n\n"
|
147
|
-
"## Recent History\n"
|
148
|
-
"user: Excellent. Now, please update the documentation in README.md.\n"
|
149
|
-
"assistant: I have updated the README.md file with the new documentation.\n"
|
150
|
-
"user: Looks good. Can you commit the changes for me?\n"
|
151
|
-
"assistant: Of course. What should the commit message be?\n"
|
140
|
+
"Your entire output MUST be a single block of text with these two\n"
|
141
|
+
"sections:\n"
|
142
|
+
"1. `## Narrative Summary` (The updated and condensed narrative)\n"
|
143
|
+
"2. `## Scratchpad` (The new, non-truncated recent history)"
|
152
144
|
).strip()
|
153
145
|
|
154
146
|
DEFAULT_CONTEXT_ENRICHMENT_PROMPT = (
|
155
|
-
"You are a Memory Curator
|
156
|
-
"conversation and produce a concise, up-to-date Markdown block of
|
147
|
+
"You are a Memory Curator. Your sole purpose is to process a\n"
|
148
|
+
"conversation and produce a concise, up-to-date Markdown block of\n"
|
157
149
|
"long-term context for the main assistant.\n\n"
|
158
|
-
"You will be given the previous 'Long-Term Context' and the 'Recent
|
159
|
-
"Conversation History'. Your job is to return a NEW, UPDATED version of
|
150
|
+
"You will be given the previous 'Long-Term Context' and the 'Recent\n"
|
151
|
+
"Conversation History'. Your job is to return a NEW, UPDATED version of\n"
|
160
152
|
"the 'Long-Term Context'.\n\n"
|
161
153
|
"**Your Curation Process:**\n"
|
162
154
|
"1. **Review:** Analyze the existing 'Long-Term Context'.\n"
|
163
|
-
"2. **Update:** Read the 'Recent Conversation History' to identify
|
164
|
-
"new facts, changed goals, or completed tasks.\n"
|
165
|
-
"3. **Re-write:** Create the new 'Long-Term Context' by applying these
|
166
|
-
"changes.\n\n"
|
155
|
+
"2. **Update:** Read the 'Recent Conversation History' to identify\n"
|
156
|
+
" new facts, changed goals, or completed tasks.\n"
|
157
|
+
"3. **Re-write:** Create the new 'Long-Term Context' by applying these\n"
|
158
|
+
" changes.\n\n"
|
167
159
|
"**CRITICAL CURATION RULES:**\n"
|
168
|
-
"- **
|
160
|
+
"- **The context MUST NOT grow indefinitely.** Your primary goal is to\n"
|
161
|
+
" keep it concise and relevant to the *current* state of the\n"
|
162
|
+
" conversation.\n"
|
163
|
+
"- **ADD** new, stable facts (e.g., long-term user preferences).\n"
|
169
164
|
"- **UPDATE** existing facts if the user provides new information.\n"
|
170
|
-
"- **REMOVE** goals, tasks, or files that are completed or no longer
|
171
|
-
"relevant.
|
172
|
-
"
|
173
|
-
"
|
174
|
-
"
|
175
|
-
"
|
176
|
-
"
|
177
|
-
"
|
178
|
-
"
|
179
|
-
"
|
180
|
-
"
|
181
|
-
"assistant: The refactoring of `auth.py` is complete and all tests are "
|
182
|
-
"passing.\n"
|
183
|
-
"user: Great! Now, can you please write the documentation for the new "
|
184
|
-
"`auth.py` module in the `README.md` file?\n\n"
|
185
|
-
"**YOUR CORRECT OUTPUT (as a single Markdown block):**\n\n"
|
186
|
-
"## Long-Term Context\n"
|
187
|
-
"- **User Profile:** The user's name is Alex.\n"
|
188
|
-
"- **Current Goal:** Write documentation for the `auth.py` module in "
|
189
|
-
"`README.md`.\n"
|
190
|
-
"- **Key Files:** `auth.py`, `README.md`\n"
|
165
|
+
"- **REMOVE** goals, tasks, or files that are completed or no longer\n"
|
166
|
+
" relevant. Be aggressive in pruning irrelevant information.\n"
|
167
|
+
"- **CONDENSE** older entries that are still relevant but not the\n"
|
168
|
+
" immediate focus. For example, a completed high-level goal might be\n"
|
169
|
+
" condensed into a single 'Past Accomplishments' line item.\n\n"
|
170
|
+
"**A Note on Dynamic Information:**\n"
|
171
|
+
"Be mindful that some information is temporary. Details like the current\n"
|
172
|
+
"working directory, project context, or file contents can change\n"
|
173
|
+
"frequently. The main assistant MUST NOT assume this information is\n"
|
174
|
+
"current and should always use its tools to verify the latest state when\n"
|
175
|
+
"needed."
|
191
176
|
).strip()
|
192
177
|
|
193
178
|
|