zrb 1.7.2__py3-none-any.whl → 1.7.4__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 -24
- zrb/builtin/llm/tool/file.py +57 -18
- zrb/builtin/llm/tool/sub_agent.py +16 -6
- {zrb-1.7.2.dist-info → zrb-1.7.4.dist-info}/METADATA +1 -1
- {zrb-1.7.2.dist-info → zrb-1.7.4.dist-info}/RECORD +7 -7
- {zrb-1.7.2.dist-info → zrb-1.7.4.dist-info}/WHEEL +0 -0
- {zrb-1.7.2.dist-info → zrb-1.7.4.dist-info}/entry_points.txt +0 -0
zrb/builtin/llm/llm_ask.py
CHANGED
@@ -5,13 +5,13 @@ from zrb.builtin.llm.input import PreviousSessionInput
|
|
5
5
|
from zrb.builtin.llm.tool.api import get_current_location, get_current_weather
|
6
6
|
from zrb.builtin.llm.tool.cli import run_shell_command
|
7
7
|
from zrb.builtin.llm.tool.file import (
|
8
|
+
analyze_file,
|
8
9
|
apply_diff,
|
9
10
|
list_files,
|
10
11
|
read_from_file,
|
11
12
|
search_files,
|
12
13
|
write_to_file,
|
13
14
|
)
|
14
|
-
from zrb.builtin.llm.tool.sub_agent import create_sub_agent_tool
|
15
15
|
from zrb.builtin.llm.tool.web import (
|
16
16
|
create_search_internet_tool,
|
17
17
|
open_web_page,
|
@@ -131,29 +131,7 @@ if CFG.LLM_ALLOW_ACCESS_LOCAL_FILE:
|
|
131
131
|
write_to_file,
|
132
132
|
search_files,
|
133
133
|
apply_diff,
|
134
|
-
|
135
|
-
tool_name="analyze_file",
|
136
|
-
tool_description="\n".join(
|
137
|
-
[
|
138
|
-
"Always use this tool to analyze file using LLM capability.",
|
139
|
-
"This tool can do:",
|
140
|
-
"- summarization",
|
141
|
-
"- outline/structure extraction",
|
142
|
-
"- code review",
|
143
|
-
"- other tasks requiring deep understanding.",
|
144
|
-
"This tool ONLY HAVE SINGLE ARGUMENT: query",
|
145
|
-
"Make sure to include the file path you want to analyze in the query",
|
146
|
-
]
|
147
|
-
),
|
148
|
-
sub_agent_system_prompt="\n".join(
|
149
|
-
[
|
150
|
-
"You are a file analyzer assistant",
|
151
|
-
"Your goal is to help the main asisstant by reading file",
|
152
|
-
"and perform necessary indepth analysis required by the main assistant",
|
153
|
-
]
|
154
|
-
),
|
155
|
-
sub_agent_tools=[read_from_file, search_files],
|
156
|
-
),
|
134
|
+
analyze_file,
|
157
135
|
)
|
158
136
|
|
159
137
|
if CFG.LLM_ALLOW_ACCESS_SHELL:
|
zrb/builtin/llm/tool/file.py
CHANGED
@@ -4,6 +4,8 @@ import os
|
|
4
4
|
import re
|
5
5
|
from typing import Any, Optional
|
6
6
|
|
7
|
+
from zrb.builtin.llm.tool.sub_agent import create_sub_agent_tool
|
8
|
+
from zrb.context.any_context import AnyContext
|
7
9
|
from zrb.util.file import read_file, read_file_with_line_numbers, write_file
|
8
10
|
|
9
11
|
DEFAULT_EXCLUDED_PATTERNS = [
|
@@ -199,11 +201,11 @@ def read_from_file(
|
|
199
201
|
Raises:
|
200
202
|
Exception: If an error occurs.
|
201
203
|
"""
|
204
|
+
abs_path = os.path.abspath(os.path.expanduser(path))
|
205
|
+
# Check if file exists
|
206
|
+
if not os.path.exists(abs_path):
|
207
|
+
raise FileNotFoundError(f"File not found: {path}")
|
202
208
|
try:
|
203
|
-
abs_path = os.path.abspath(os.path.expanduser(path))
|
204
|
-
# Check if file exists
|
205
|
-
if not os.path.exists(abs_path):
|
206
|
-
return json.dumps({"error": f"File {path} does not exist"})
|
207
209
|
content = read_file_with_line_numbers(abs_path)
|
208
210
|
lines = content.splitlines()
|
209
211
|
total_lines = len(lines)
|
@@ -400,24 +402,15 @@ def apply_diff(
|
|
400
402
|
Raises:
|
401
403
|
Exception: If an error occurs.
|
402
404
|
"""
|
405
|
+
abs_path = os.path.abspath(os.path.expanduser(path))
|
406
|
+
if not os.path.exists(abs_path):
|
407
|
+
raise FileNotFoundError(f"File not found: {path}")
|
403
408
|
try:
|
404
|
-
abs_path = os.path.abspath(os.path.expanduser(path))
|
405
|
-
if not os.path.exists(abs_path):
|
406
|
-
return json.dumps(
|
407
|
-
{"success": False, "path": path, "error": f"File not found at {path}"}
|
408
|
-
)
|
409
409
|
content = read_file(abs_path)
|
410
410
|
lines = content.splitlines()
|
411
411
|
if start_line < 1 or end_line > len(lines) or start_line > end_line:
|
412
|
-
|
413
|
-
{
|
414
|
-
"success": False,
|
415
|
-
"path": path,
|
416
|
-
"error": (
|
417
|
-
f"Invalid line range {start_line}-{end_line} "
|
418
|
-
f"for file with {len(lines)} lines."
|
419
|
-
),
|
420
|
-
}
|
412
|
+
raise ValueError(
|
413
|
+
f"Invalid line range {start_line}-{end_line} for file with {len(lines)} lines"
|
421
414
|
)
|
422
415
|
original_content = "\n".join(lines[start_line - 1 : end_line])
|
423
416
|
if original_content != search_content:
|
@@ -444,3 +437,49 @@ def apply_diff(
|
|
444
437
|
raise OSError(f"Error applying diff to {path}: {e}")
|
445
438
|
except Exception as e:
|
446
439
|
raise RuntimeError(f"Unexpected error applying diff to {path}: {e}")
|
440
|
+
|
441
|
+
|
442
|
+
async def analyze_file(ctx: AnyContext, path: str, query: str) -> str:
|
443
|
+
"""Analyze file using LLM capability to reduce context usage.
|
444
|
+
Use this tool for:
|
445
|
+
- summarization
|
446
|
+
- outline/structure extraction
|
447
|
+
- code review
|
448
|
+
- other tasks
|
449
|
+
Args:
|
450
|
+
path (str): File path to be analyze. Pass exactly as provided, including '~'.
|
451
|
+
query(str): Instruction to analyze the file
|
452
|
+
Returns:
|
453
|
+
str: The analysis result
|
454
|
+
Raises:
|
455
|
+
Exception: If an error occurs.
|
456
|
+
"""
|
457
|
+
abs_path = os.path.abspath(os.path.expanduser(path))
|
458
|
+
if not os.path.exists(abs_path):
|
459
|
+
raise FileNotFoundError(f"File not found: {path}")
|
460
|
+
file_content = read_file(abs_path)
|
461
|
+
_analyze_file = create_sub_agent_tool(
|
462
|
+
tool_name="analyze_file",
|
463
|
+
tool_description="analyze file with LLM capability",
|
464
|
+
sub_agent_system_prompt="\n".join(
|
465
|
+
[
|
466
|
+
"You are a file analyzer assistant",
|
467
|
+
"Your goal is to help the main asisstant by reading file",
|
468
|
+
"and perform necessary indepth analysis required by the main assistant",
|
469
|
+
]
|
470
|
+
),
|
471
|
+
sub_agent_tools=[read_from_file, search_files],
|
472
|
+
)
|
473
|
+
return await _analyze_file(
|
474
|
+
ctx,
|
475
|
+
"\n".join(
|
476
|
+
[
|
477
|
+
file_content,
|
478
|
+
"# Instruction",
|
479
|
+
query,
|
480
|
+
"# File path",
|
481
|
+
abs_path,
|
482
|
+
"# File content",
|
483
|
+
]
|
484
|
+
),
|
485
|
+
)
|
@@ -1,18 +1,28 @@
|
|
1
1
|
import json
|
2
2
|
from collections.abc import Callable
|
3
3
|
from textwrap import dedent
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
from pydantic_ai
|
8
|
-
from pydantic_ai.
|
4
|
+
from typing import TYPE_CHECKING, Any
|
5
|
+
|
6
|
+
if TYPE_CHECKING:
|
7
|
+
from pydantic_ai import Tool
|
8
|
+
from pydantic_ai.mcp import MCPServer
|
9
|
+
from pydantic_ai.models import Model
|
10
|
+
from pydantic_ai.settings import ModelSettings
|
11
|
+
else:
|
12
|
+
Tool = Any
|
13
|
+
MCPServer = Any
|
14
|
+
Model = Any
|
15
|
+
ModelSettings = Any
|
9
16
|
|
10
17
|
from zrb.context.any_context import AnyContext
|
11
18
|
from zrb.task.llm.agent import create_agent_instance, run_agent_iteration
|
12
19
|
from zrb.task.llm.config import get_model, get_model_settings
|
13
20
|
from zrb.task.llm.prompt import get_combined_system_prompt
|
14
21
|
|
15
|
-
|
22
|
+
if TYPE_CHECKING:
|
23
|
+
ToolOrCallable = Tool | Callable
|
24
|
+
else:
|
25
|
+
ToolOrCallable = Any
|
16
26
|
|
17
27
|
|
18
28
|
def create_sub_agent_tool(
|
@@ -12,14 +12,14 @@ zrb/builtin/jwt.py,sha256=3M5uaQhJZbKQLjTUft1OwPz_JxtmK-xtkjxWjciOQho,2859
|
|
12
12
|
zrb/builtin/llm/chat_session.py,sha256=HqFwrE1DiSlJrR-S3LRYWQBHkVsD-sfAV8_IIbnmtqY,6631
|
13
13
|
zrb/builtin/llm/history.py,sha256=cnkOyO43uiMQ9cEvmqk-pPoCk1zCAH_fwAqSgBtsjzY,3079
|
14
14
|
zrb/builtin/llm/input.py,sha256=Nw-26uTWp2QhUgKJcP_IMHmtk-b542CCSQ_vCOjhvhM,877
|
15
|
-
zrb/builtin/llm/llm_ask.py,sha256=
|
15
|
+
zrb/builtin/llm/llm_ask.py,sha256=TIHpZFofbehJO1LXbsi4O84kHF85Xfqjev6UkI1RiL0,4367
|
16
16
|
zrb/builtin/llm/previous-session.js,sha256=xMKZvJoAbrwiyHS0OoPrWuaKxWYLoyR5sguePIoCjTY,816
|
17
17
|
zrb/builtin/llm/tool/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
18
18
|
zrb/builtin/llm/tool/api.py,sha256=yR9I0ZsI96OeQl9pgwORMASVuXsAL0a89D_iPS4C8Dc,1699
|
19
19
|
zrb/builtin/llm/tool/cli.py,sha256=_CNEmEc6K2Z0i9ppYeM7jGpqaEdT3uxaWQatmxP3jKE,858
|
20
|
-
zrb/builtin/llm/tool/file.py,sha256=
|
20
|
+
zrb/builtin/llm/tool/file.py,sha256=nCY74VtruTr9LgAq5mroSr4zF0g6LA_uXMI5sh9c8OE,17909
|
21
21
|
zrb/builtin/llm/tool/rag.py,sha256=VUyRBvnSeDf8T_lKY--c5HVTfccNgiEJU3QpwssJF8E,8182
|
22
|
-
zrb/builtin/llm/tool/sub_agent.py,sha256=
|
22
|
+
zrb/builtin/llm/tool/sub_agent.py,sha256=7n14KzUSFe5Bjf2lpluKlLyL-b1Mehj2QekkuDzo0ik,5091
|
23
23
|
zrb/builtin/llm/tool/web.py,sha256=pXRLhcB_Y6z-2w4C4WezH8n-pg3PSMgt_bwn3aaqi6g,5479
|
24
24
|
zrb/builtin/md5.py,sha256=690RV2LbW7wQeTFxY-lmmqTSVEEZv3XZbjEUW1Q3XpE,1480
|
25
25
|
zrb/builtin/project/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
@@ -370,7 +370,7 @@ zrb/util/string/name.py,sha256=SXEfxJ1-tDOzHqmSV8kvepRVyMqs2XdV_vyoh_9XUu0,1584
|
|
370
370
|
zrb/util/todo.py,sha256=VGISej2KQZERpornK-8X7bysp4JydMrMUTnG8B0-liI,20708
|
371
371
|
zrb/xcom/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
372
372
|
zrb/xcom/xcom.py,sha256=o79rxR9wphnShrcIushA0Qt71d_p3ZTxjNf7x9hJB78,1571
|
373
|
-
zrb-1.7.
|
374
|
-
zrb-1.7.
|
375
|
-
zrb-1.7.
|
376
|
-
zrb-1.7.
|
373
|
+
zrb-1.7.4.dist-info/METADATA,sha256=-C9uLHUST6zakEUGga9poKISERqL6VWDctrjCU6f8h8,8385
|
374
|
+
zrb-1.7.4.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
|
375
|
+
zrb-1.7.4.dist-info/entry_points.txt,sha256=-Pg3ElWPfnaSM-XvXqCxEAa-wfVI6BEgcs386s8C8v8,46
|
376
|
+
zrb-1.7.4.dist-info/RECORD,,
|
File without changes
|
File without changes
|