zrb 1.7.2__py3-none-any.whl → 1.7.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.
@@ -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
- create_sub_agent_tool(
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:
@@ -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 = [
@@ -444,3 +446,48 @@ def apply_diff(
444
446
  raise OSError(f"Error applying diff to {path}: {e}")
445
447
  except Exception as e:
446
448
  raise RuntimeError(f"Unexpected error applying diff to {path}: {e}")
449
+
450
+
451
+ async def analyze_file(ctx: AnyContext, path: str, query: str) -> str:
452
+ """Analyze file using LLM capability to reduce context usage.
453
+ Use this tool for:
454
+ - summarization
455
+ - outline/structure extraction
456
+ - code review
457
+ - other tasks
458
+ Args:
459
+ path (str): File path to be analyze. Pass exactly as provided, including '~'.
460
+ query(str): Instruction to analyze the file
461
+ Returns:
462
+ str: The analysis result
463
+ Raises:
464
+ Exception: If an error occurs.
465
+ """
466
+ abs_path = os.path.abspath(os.path.expanduser(path))
467
+ if not os.path.exists(abs_path):
468
+ return json.dumps(
469
+ {"success": False, "path": path, "error": f"File not found at {path}"}
470
+ )
471
+ _analyze_file = create_sub_agent_tool(
472
+ tool_name="analyze_file",
473
+ tool_description="analyze file with LLM capability",
474
+ sub_agent_system_prompt="\n".join(
475
+ [
476
+ "You are a file analyzer assistant",
477
+ "Your goal is to help the main asisstant by reading file",
478
+ "and perform necessary indepth analysis required by the main assistant",
479
+ ]
480
+ ),
481
+ sub_agent_tools=[read_from_file, search_files],
482
+ )
483
+ return await _analyze_file(
484
+ ctx,
485
+ "\n".join(
486
+ [
487
+ "# File path",
488
+ abs_path,
489
+ "# Instruction",
490
+ query,
491
+ ]
492
+ ),
493
+ )
@@ -1,18 +1,28 @@
1
1
  import json
2
2
  from collections.abc import Callable
3
3
  from textwrap import dedent
4
-
5
- from pydantic_ai import Tool
6
- from pydantic_ai.mcp import MCPServer
7
- from pydantic_ai.models import Model
8
- from pydantic_ai.settings import ModelSettings
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
- ToolOrCallable = Tool | Callable
22
+ if TYPE_CHECKING:
23
+ ToolOrCallable = Tool | Callable
24
+ else:
25
+ ToolOrCallable = Any
16
26
 
17
27
 
18
28
  def create_sub_agent_tool(
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: zrb
3
- Version: 1.7.2
3
+ Version: 1.7.3
4
4
  Summary: Your Automation Powerhouse
5
5
  Home-page: https://github.com/state-alchemists/zrb
6
6
  License: AGPL-3.0-or-later
@@ -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=GKjJZEVPgW0IbcRDNF9W7deHcLDPUyq3C0Vl-DqiJLc,5427
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=ig4tZGYnGjE96U9KgOpbANmyAgFmTcQzym1wVAsZYRM,16620
20
+ zrb/builtin/llm/tool/file.py,sha256=4bbgsE2aCDR6Y4HbkMM--Q_ohmJW3KPqLbhuoJrrd8M,18173
21
21
  zrb/builtin/llm/tool/rag.py,sha256=VUyRBvnSeDf8T_lKY--c5HVTfccNgiEJU3QpwssJF8E,8182
22
- zrb/builtin/llm/tool/sub_agent.py,sha256=7KaxWfFcT-3_fyqQyd4qA2ipzmVFG71iPzRl7wISM5M,4885
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.2.dist-info/METADATA,sha256=JA6bk-DSmoriPSaNGzS8nmmka4IaNC7SLJQjNaCR_RE,8385
374
- zrb-1.7.2.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
375
- zrb-1.7.2.dist-info/entry_points.txt,sha256=-Pg3ElWPfnaSM-XvXqCxEAa-wfVI6BEgcs386s8C8v8,46
376
- zrb-1.7.2.dist-info/RECORD,,
373
+ zrb-1.7.3.dist-info/METADATA,sha256=XgHOTXqZlnfTnKGLWhWJvkl4K5cz5_-5OPz0GS2zrSM,8385
374
+ zrb-1.7.3.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
375
+ zrb-1.7.3.dist-info/entry_points.txt,sha256=-Pg3ElWPfnaSM-XvXqCxEAa-wfVI6BEgcs386s8C8v8,46
376
+ zrb-1.7.3.dist-info/RECORD,,
File without changes