zrb 1.7.1__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.
- zrb/builtin/jwt.py +3 -1
- zrb/builtin/llm/llm_ask.py +2 -23
- zrb/builtin/llm/tool/file.py +47 -0
- zrb/builtin/llm/tool/sub_agent.py +16 -6
- zrb/task/llm/context_enrichment.py +10 -1
- {zrb-1.7.1.dist-info → zrb-1.7.3.dist-info}/METADATA +1 -1
- {zrb-1.7.1.dist-info → zrb-1.7.3.dist-info}/RECORD +9 -9
- {zrb-1.7.1.dist-info → zrb-1.7.3.dist-info}/WHEEL +0 -0
- {zrb-1.7.1.dist-info → zrb-1.7.3.dist-info}/entry_points.txt +0 -0
zrb/builtin/jwt.py
CHANGED
@@ -24,10 +24,12 @@ from zrb.task.make_task import make_task
|
|
24
24
|
],
|
25
25
|
)
|
26
26
|
def encode_jwt(ctx: AnyContext) -> str:
|
27
|
+
import json
|
28
|
+
|
27
29
|
import jwt
|
28
30
|
|
29
31
|
try:
|
30
|
-
payload =
|
32
|
+
payload = json.loads(ctx.input.payload)
|
31
33
|
token = jwt.encode(
|
32
34
|
payload=payload, key=ctx.input.secret, algorithm=ctx.input.algorithm
|
33
35
|
)
|
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,28 +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
|
-
"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
|
-
"Always use this tool to get deep understanding of file content",
|
145
|
-
]
|
146
|
-
),
|
147
|
-
sub_agent_system_prompt="\n".join(
|
148
|
-
[
|
149
|
-
"You are a file analyzer assistant",
|
150
|
-
"Your goal is to help the main asisstant by reading file",
|
151
|
-
"and perform necessary indepth analysis required by the main assistant",
|
152
|
-
]
|
153
|
-
),
|
154
|
-
sub_agent_tools=[read_from_file, search_files],
|
155
|
-
),
|
134
|
+
analyze_file,
|
156
135
|
)
|
157
136
|
|
158
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 = [
|
@@ -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
|
-
|
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(
|
@@ -47,6 +47,7 @@ async def enrich_context(
|
|
47
47
|
|
48
48
|
ctx.log_info("Attempting to enrich conversation context...")
|
49
49
|
# Prepare context and history for the enrichment prompt
|
50
|
+
history_summary = conversation_context.get("history_summary")
|
50
51
|
try:
|
51
52
|
context_json = json.dumps(conversation_context)
|
52
53
|
history_json = json.dumps(history_list)
|
@@ -54,7 +55,13 @@ async def enrich_context(
|
|
54
55
|
user_prompt_data = "\n".join(
|
55
56
|
[
|
56
57
|
"Extract context from the following conversation info.",
|
57
|
-
"
|
58
|
+
"Extract only contexts that will be relevant across multiple conversations, like", # noqa
|
59
|
+
"- user name",
|
60
|
+
"- user hobby",
|
61
|
+
"- user's long life goal",
|
62
|
+
"- standard/SOP",
|
63
|
+
"- etc.",
|
64
|
+
"Always maintain the relevant context and remove the irrelevant ones.",
|
58
65
|
"Restructure the context in a helpful way",
|
59
66
|
"Keep the context small",
|
60
67
|
f"Existing Context: {context_json}",
|
@@ -90,6 +97,8 @@ async def enrich_context(
|
|
90
97
|
ctx.print(stylize_faint(f"[Token Usage] {usage}"), plain=True)
|
91
98
|
if response:
|
92
99
|
conversation_context = response
|
100
|
+
# Re inject history summary
|
101
|
+
conversation_context["history_summary"] = history_summary
|
93
102
|
ctx.log_info("Context enriched based on history.")
|
94
103
|
ctx.log_info(
|
95
104
|
f"Updated conversation context: {json.dumps(conversation_context)}"
|
@@ -8,18 +8,18 @@ zrb/builtin/git.py,sha256=8_qVE_2lVQEVXQ9vhiw8Tn4Prj1VZB78ZjEJJS5Ab3M,5461
|
|
8
8
|
zrb/builtin/git_subtree.py,sha256=7BKwOkVTWDrR0DXXQ4iJyHqeR6sV5VYRt8y_rEB0EHg,3505
|
9
9
|
zrb/builtin/group.py,sha256=t008xLM4_fgbjfZrPoi_fQAnSHIo6MOiQSCHBO4GDYU,2379
|
10
10
|
zrb/builtin/http.py,sha256=sLqEczuSxGYXWzyJR6frGOHkPTviu4BeyroUr3-ZuAI,4322
|
11
|
-
zrb/builtin/jwt.py,sha256=
|
11
|
+
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=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=
|
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
|
@@ -320,7 +320,7 @@ zrb/task/llm/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
320
320
|
zrb/task/llm/agent.py,sha256=6wGSsw03GdY_fj12CsJh7wxB6BnE13N8RYXaWfbiUsk,5451
|
321
321
|
zrb/task/llm/config.py,sha256=oGxHYMdIvhASnKwNuMPwcdeJiFfS0tNskzGHakpfpQU,3458
|
322
322
|
zrb/task/llm/context.py,sha256=U9a8lxa2ikz6my0Sd5vpO763legHrMHyvBjbrqNmv0Y,3838
|
323
|
-
zrb/task/llm/context_enrichment.py,sha256=
|
323
|
+
zrb/task/llm/context_enrichment.py,sha256=jB7lekwo4hTk8HIwhhq7HSMfgAzwaV2U867icBRt6Z0,7088
|
324
324
|
zrb/task/llm/error.py,sha256=27DQXSG8SH1-XuvXFdZQKzP39wZDWmd_YnSTz6DJKKI,3690
|
325
325
|
zrb/task/llm/history.py,sha256=3WMXoi7RquxosXQf3iv2_BCeF8iKtY1f407pR71xERs,7745
|
326
326
|
zrb/task/llm/history_summarization.py,sha256=n3GbgwXlDIkgpJppMGfpqF_8Wpi9yAoZYh46O1pFQeU,6432
|
@@ -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.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
|
File without changes
|