zrb 1.21.29__py3-none-any.whl → 2.0.0a4__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/__init__.py +118 -129
- zrb/builtin/__init__.py +54 -2
- zrb/builtin/llm/chat.py +147 -0
- zrb/callback/callback.py +8 -1
- zrb/cmd/cmd_result.py +2 -1
- zrb/config/config.py +491 -280
- zrb/config/helper.py +84 -0
- zrb/config/web_auth_config.py +50 -35
- zrb/context/any_shared_context.py +13 -2
- zrb/context/context.py +31 -3
- zrb/context/print_fn.py +13 -0
- zrb/context/shared_context.py +14 -1
- zrb/input/option_input.py +30 -2
- zrb/llm/agent/__init__.py +9 -0
- zrb/llm/agent/agent.py +215 -0
- zrb/llm/agent/summarizer.py +20 -0
- zrb/llm/app/__init__.py +10 -0
- zrb/llm/app/completion.py +281 -0
- zrb/llm/app/confirmation/allow_tool.py +66 -0
- zrb/llm/app/confirmation/handler.py +178 -0
- zrb/llm/app/confirmation/replace_confirmation.py +77 -0
- zrb/llm/app/keybinding.py +34 -0
- zrb/llm/app/layout.py +117 -0
- zrb/llm/app/lexer.py +155 -0
- zrb/llm/app/redirection.py +28 -0
- zrb/llm/app/style.py +16 -0
- zrb/llm/app/ui.py +733 -0
- zrb/llm/config/__init__.py +4 -0
- zrb/llm/config/config.py +122 -0
- zrb/llm/config/limiter.py +247 -0
- zrb/llm/history_manager/__init__.py +4 -0
- zrb/llm/history_manager/any_history_manager.py +23 -0
- zrb/llm/history_manager/file_history_manager.py +91 -0
- zrb/llm/history_processor/summarizer.py +108 -0
- zrb/llm/note/__init__.py +3 -0
- zrb/llm/note/manager.py +122 -0
- zrb/llm/prompt/__init__.py +29 -0
- zrb/llm/prompt/claude_compatibility.py +92 -0
- zrb/llm/prompt/compose.py +55 -0
- zrb/llm/prompt/default.py +51 -0
- zrb/llm/prompt/markdown/mandate.md +23 -0
- zrb/llm/prompt/markdown/persona.md +3 -0
- zrb/llm/prompt/markdown/summarizer.md +21 -0
- zrb/llm/prompt/note.py +41 -0
- zrb/llm/prompt/system_context.py +46 -0
- zrb/llm/prompt/zrb.py +41 -0
- zrb/llm/skill/__init__.py +3 -0
- zrb/llm/skill/manager.py +86 -0
- zrb/llm/task/__init__.py +4 -0
- zrb/llm/task/llm_chat_task.py +316 -0
- zrb/llm/task/llm_task.py +245 -0
- zrb/llm/tool/__init__.py +39 -0
- zrb/llm/tool/bash.py +75 -0
- zrb/llm/tool/code.py +266 -0
- zrb/llm/tool/file.py +419 -0
- zrb/llm/tool/note.py +70 -0
- zrb/{builtin/llm → llm}/tool/rag.py +8 -5
- zrb/llm/tool/search/brave.py +53 -0
- zrb/llm/tool/search/searxng.py +47 -0
- zrb/llm/tool/search/serpapi.py +47 -0
- zrb/llm/tool/skill.py +19 -0
- zrb/llm/tool/sub_agent.py +70 -0
- zrb/llm/tool/web.py +97 -0
- zrb/llm/tool/zrb_task.py +66 -0
- zrb/llm/util/attachment.py +101 -0
- zrb/llm/util/prompt.py +104 -0
- zrb/llm/util/stream_response.py +178 -0
- zrb/session/any_session.py +0 -3
- zrb/session/session.py +1 -1
- zrb/task/base/context.py +25 -13
- zrb/task/base/execution.py +52 -47
- zrb/task/base/lifecycle.py +7 -4
- zrb/task/base_task.py +48 -49
- zrb/task/base_trigger.py +4 -1
- zrb/task/cmd_task.py +6 -0
- zrb/task/http_check.py +11 -5
- zrb/task/make_task.py +3 -0
- zrb/task/rsync_task.py +5 -0
- zrb/task/scaffolder.py +7 -4
- zrb/task/scheduler.py +3 -0
- zrb/task/tcp_check.py +6 -4
- zrb/util/ascii_art/art/bee.txt +17 -0
- zrb/util/ascii_art/art/cat.txt +9 -0
- zrb/util/ascii_art/art/ghost.txt +16 -0
- zrb/util/ascii_art/art/panda.txt +17 -0
- zrb/util/ascii_art/art/rose.txt +14 -0
- zrb/util/ascii_art/art/unicorn.txt +15 -0
- zrb/util/ascii_art/banner.py +92 -0
- zrb/util/cli/markdown.py +22 -2
- zrb/util/cmd/command.py +33 -10
- zrb/util/file.py +51 -32
- zrb/util/match.py +78 -0
- zrb/util/run.py +3 -3
- {zrb-1.21.29.dist-info → zrb-2.0.0a4.dist-info}/METADATA +9 -15
- {zrb-1.21.29.dist-info → zrb-2.0.0a4.dist-info}/RECORD +100 -128
- zrb/attr/__init__.py +0 -0
- zrb/builtin/llm/attachment.py +0 -40
- zrb/builtin/llm/chat_completion.py +0 -274
- zrb/builtin/llm/chat_session.py +0 -270
- zrb/builtin/llm/chat_session_cmd.py +0 -288
- zrb/builtin/llm/chat_trigger.py +0 -79
- zrb/builtin/llm/history.py +0 -71
- zrb/builtin/llm/input.py +0 -27
- zrb/builtin/llm/llm_ask.py +0 -269
- zrb/builtin/llm/previous-session.js +0 -21
- zrb/builtin/llm/tool/__init__.py +0 -0
- zrb/builtin/llm/tool/api.py +0 -75
- zrb/builtin/llm/tool/cli.py +0 -52
- zrb/builtin/llm/tool/code.py +0 -236
- zrb/builtin/llm/tool/file.py +0 -560
- zrb/builtin/llm/tool/note.py +0 -84
- zrb/builtin/llm/tool/sub_agent.py +0 -150
- zrb/builtin/llm/tool/web.py +0 -171
- zrb/builtin/project/__init__.py +0 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/__init__.py +0 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/module/template/app_template/module/my_module/service/__init__.py +0 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/common/__init__.py +0 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/__init__.py +0 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/auth/service/__init__.py +0 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/auth/service/permission/__init__.py +0 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/auth/service/role/__init__.py +0 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/auth/service/user/__init__.py +0 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/schema/__init__.py +0 -0
- zrb/builtin/project/create/__init__.py +0 -0
- zrb/builtin/shell/__init__.py +0 -0
- zrb/builtin/shell/autocomplete/__init__.py +0 -0
- zrb/callback/__init__.py +0 -0
- zrb/cmd/__init__.py +0 -0
- zrb/config/default_prompt/interactive_system_prompt.md +0 -29
- zrb/config/default_prompt/persona.md +0 -1
- zrb/config/default_prompt/summarization_prompt.md +0 -57
- zrb/config/default_prompt/system_prompt.md +0 -38
- zrb/config/llm_config.py +0 -339
- zrb/config/llm_context/config.py +0 -166
- zrb/config/llm_context/config_parser.py +0 -40
- zrb/config/llm_context/workflow.py +0 -81
- zrb/config/llm_rate_limitter.py +0 -190
- zrb/content_transformer/__init__.py +0 -0
- zrb/context/__init__.py +0 -0
- zrb/dot_dict/__init__.py +0 -0
- zrb/env/__init__.py +0 -0
- zrb/group/__init__.py +0 -0
- zrb/input/__init__.py +0 -0
- zrb/runner/__init__.py +0 -0
- zrb/runner/web_route/__init__.py +0 -0
- zrb/runner/web_route/home_page/__init__.py +0 -0
- zrb/session/__init__.py +0 -0
- zrb/session_state_log/__init__.py +0 -0
- zrb/session_state_logger/__init__.py +0 -0
- zrb/task/__init__.py +0 -0
- zrb/task/base/__init__.py +0 -0
- zrb/task/llm/__init__.py +0 -0
- zrb/task/llm/agent.py +0 -204
- zrb/task/llm/agent_runner.py +0 -152
- zrb/task/llm/config.py +0 -122
- zrb/task/llm/conversation_history.py +0 -209
- zrb/task/llm/conversation_history_model.py +0 -67
- zrb/task/llm/default_workflow/coding/workflow.md +0 -41
- zrb/task/llm/default_workflow/copywriting/workflow.md +0 -68
- zrb/task/llm/default_workflow/git/workflow.md +0 -118
- zrb/task/llm/default_workflow/golang/workflow.md +0 -128
- zrb/task/llm/default_workflow/html-css/workflow.md +0 -135
- zrb/task/llm/default_workflow/java/workflow.md +0 -146
- zrb/task/llm/default_workflow/javascript/workflow.md +0 -158
- zrb/task/llm/default_workflow/python/workflow.md +0 -160
- zrb/task/llm/default_workflow/researching/workflow.md +0 -153
- zrb/task/llm/default_workflow/rust/workflow.md +0 -162
- zrb/task/llm/default_workflow/shell/workflow.md +0 -299
- zrb/task/llm/error.py +0 -95
- zrb/task/llm/file_replacement.py +0 -206
- zrb/task/llm/file_tool_model.py +0 -57
- zrb/task/llm/history_processor.py +0 -206
- zrb/task/llm/history_summarization.py +0 -25
- zrb/task/llm/print_node.py +0 -221
- zrb/task/llm/prompt.py +0 -321
- zrb/task/llm/subagent_conversation_history.py +0 -41
- zrb/task/llm/tool_wrapper.py +0 -361
- zrb/task/llm/typing.py +0 -3
- zrb/task/llm/workflow.py +0 -76
- zrb/task/llm_task.py +0 -379
- zrb/task_status/__init__.py +0 -0
- zrb/util/__init__.py +0 -0
- zrb/util/cli/__init__.py +0 -0
- zrb/util/cmd/__init__.py +0 -0
- zrb/util/codemod/__init__.py +0 -0
- zrb/util/string/__init__.py +0 -0
- zrb/xcom/__init__.py +0 -0
- /zrb/{config/default_prompt/file_extractor_system_prompt.md → llm/prompt/markdown/file_extractor.md} +0 -0
- /zrb/{config/default_prompt/repo_extractor_system_prompt.md → llm/prompt/markdown/repo_extractor.md} +0 -0
- /zrb/{config/default_prompt/repo_summarizer_system_prompt.md → llm/prompt/markdown/repo_summarizer.md} +0 -0
- {zrb-1.21.29.dist-info → zrb-2.0.0a4.dist-info}/WHEEL +0 -0
- {zrb-1.21.29.dist-info → zrb-2.0.0a4.dist-info}/entry_points.txt +0 -0
zrb/task/llm_task.py
DELETED
|
@@ -1,379 +0,0 @@
|
|
|
1
|
-
import json
|
|
2
|
-
from collections.abc import Callable
|
|
3
|
-
from typing import TYPE_CHECKING, Any
|
|
4
|
-
|
|
5
|
-
from zrb.attr.type import BoolAttr, IntAttr, StrAttr, StrListAttr, fstring
|
|
6
|
-
from zrb.config.llm_rate_limitter import LLMRateLimitter
|
|
7
|
-
from zrb.context.any_context import AnyContext
|
|
8
|
-
from zrb.env.any_env import AnyEnv
|
|
9
|
-
from zrb.input.any_input import AnyInput
|
|
10
|
-
from zrb.task.any_task import AnyTask
|
|
11
|
-
from zrb.task.base_task import BaseTask
|
|
12
|
-
from zrb.task.llm.agent import get_agent
|
|
13
|
-
from zrb.task.llm.agent_runner import run_agent_iteration
|
|
14
|
-
from zrb.task.llm.config import (
|
|
15
|
-
get_model,
|
|
16
|
-
get_model_settings,
|
|
17
|
-
get_yolo_mode,
|
|
18
|
-
)
|
|
19
|
-
from zrb.task.llm.conversation_history import (
|
|
20
|
-
inject_conversation_history_notes,
|
|
21
|
-
read_conversation_history,
|
|
22
|
-
write_conversation_history,
|
|
23
|
-
)
|
|
24
|
-
from zrb.task.llm.conversation_history_model import ConversationHistory
|
|
25
|
-
from zrb.task.llm.history_summarization import get_history_summarization_token_threshold
|
|
26
|
-
from zrb.task.llm.prompt import (
|
|
27
|
-
get_attachments,
|
|
28
|
-
get_summarization_system_prompt,
|
|
29
|
-
get_system_and_user_prompt,
|
|
30
|
-
get_user_message,
|
|
31
|
-
)
|
|
32
|
-
from zrb.task.llm.subagent_conversation_history import (
|
|
33
|
-
extract_subagent_conversation_history_from_ctx,
|
|
34
|
-
inject_subagent_conversation_history_into_ctx,
|
|
35
|
-
)
|
|
36
|
-
from zrb.task.llm.workflow import load_workflow
|
|
37
|
-
from zrb.util.cli.style import stylize_faint
|
|
38
|
-
from zrb.xcom.xcom import Xcom
|
|
39
|
-
|
|
40
|
-
if TYPE_CHECKING:
|
|
41
|
-
from pydantic_ai import AbstractToolset, Agent, Tool, UserContent
|
|
42
|
-
from pydantic_ai.models import Model
|
|
43
|
-
from pydantic_ai.settings import ModelSettings
|
|
44
|
-
|
|
45
|
-
ToolOrCallable = Tool | Callable
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
class LLMTask(BaseTask):
|
|
49
|
-
def __init__(
|
|
50
|
-
self,
|
|
51
|
-
name: str,
|
|
52
|
-
color: int | None = None,
|
|
53
|
-
icon: str | None = None,
|
|
54
|
-
description: str | None = None,
|
|
55
|
-
cli_only: bool = False,
|
|
56
|
-
input: list[AnyInput | None] | AnyInput | None = None,
|
|
57
|
-
env: list[AnyEnv | None] | AnyEnv | None = None,
|
|
58
|
-
model: "Callable[[AnyContext], Model | str | fstring | None] | Model | None" = None,
|
|
59
|
-
render_model: bool = True,
|
|
60
|
-
model_base_url: "Callable[[AnyContext], str | None] | str | None" = None,
|
|
61
|
-
render_model_base_url: bool = True,
|
|
62
|
-
model_api_key: "Callable[[AnyContext], str | None] | str | None" = None,
|
|
63
|
-
render_model_api_key: bool = True,
|
|
64
|
-
model_settings: (
|
|
65
|
-
"ModelSettings | Callable[[AnyContext], ModelSettings] | None"
|
|
66
|
-
) = None,
|
|
67
|
-
small_model: (
|
|
68
|
-
"Callable[[AnyContext], Model | str | fstring] | Model | None"
|
|
69
|
-
) = None,
|
|
70
|
-
render_small_model: bool = True,
|
|
71
|
-
small_model_base_url: StrAttr | None = None,
|
|
72
|
-
render_small_model_base_url: bool = True,
|
|
73
|
-
small_model_api_key: StrAttr | None = None,
|
|
74
|
-
render_small_model_api_key: bool = True,
|
|
75
|
-
small_model_settings: (
|
|
76
|
-
"ModelSettings | Callable[[AnyContext], ModelSettings] | None"
|
|
77
|
-
) = None,
|
|
78
|
-
persona: "Callable[[AnyContext], str | None] | str | None" = None,
|
|
79
|
-
render_persona: bool = False,
|
|
80
|
-
system_prompt: "Callable[[AnyContext], str | None] | str | None" = None,
|
|
81
|
-
render_system_prompt: bool = False,
|
|
82
|
-
special_instruction_prompt: "Callable[[AnyContext], str | None] | str | None" = None,
|
|
83
|
-
render_special_instruction_prompt: bool = False,
|
|
84
|
-
workflows: StrListAttr | None = None,
|
|
85
|
-
render_workflows: bool = True,
|
|
86
|
-
message: StrAttr | None = None,
|
|
87
|
-
attachment: "UserContent | list[UserContent] | Callable[[AnyContext], UserContent | list[UserContent]] | None" = None, # noqa
|
|
88
|
-
render_message: bool = True,
|
|
89
|
-
tools: (
|
|
90
|
-
list["ToolOrCallable"] | Callable[[AnyContext], list["ToolOrCallable"]]
|
|
91
|
-
) = [],
|
|
92
|
-
toolsets: (
|
|
93
|
-
list["AbstractToolset[None] | str"]
|
|
94
|
-
| Callable[[AnyContext], list["AbstractToolset[None] | str"]]
|
|
95
|
-
) = [],
|
|
96
|
-
conversation_history: (
|
|
97
|
-
ConversationHistory
|
|
98
|
-
| Callable[[AnyContext], ConversationHistory | dict | list]
|
|
99
|
-
| dict
|
|
100
|
-
| list
|
|
101
|
-
) = ConversationHistory(),
|
|
102
|
-
conversation_history_reader: (
|
|
103
|
-
Callable[[AnyContext], ConversationHistory | dict | list | None] | None
|
|
104
|
-
) = None,
|
|
105
|
-
conversation_history_writer: (
|
|
106
|
-
Callable[[AnyContext, ConversationHistory], None] | None
|
|
107
|
-
) = None,
|
|
108
|
-
conversation_history_file: StrAttr | None = None,
|
|
109
|
-
render_history_file: bool = True,
|
|
110
|
-
summarize_history: BoolAttr | None = None,
|
|
111
|
-
render_summarize_history: bool = True,
|
|
112
|
-
summarization_prompt: "Callable[[AnyContext], str | None] | str | None" = None,
|
|
113
|
-
render_summarization_prompt: bool = False,
|
|
114
|
-
history_summarization_token_threshold: IntAttr | None = None,
|
|
115
|
-
render_history_summarization_token_threshold: bool = True,
|
|
116
|
-
rate_limitter: LLMRateLimitter | None = None,
|
|
117
|
-
execute_condition: bool | str | Callable[[AnyContext], bool] = True,
|
|
118
|
-
retries: int = 2,
|
|
119
|
-
retry_period: float = 0,
|
|
120
|
-
yolo_mode: (
|
|
121
|
-
Callable[[AnyContext], list[str] | bool | None]
|
|
122
|
-
| StrListAttr
|
|
123
|
-
| BoolAttr
|
|
124
|
-
| None
|
|
125
|
-
) = None,
|
|
126
|
-
render_yolo_mode: bool = True,
|
|
127
|
-
readiness_check: list[AnyTask] | AnyTask | None = None,
|
|
128
|
-
readiness_check_delay: float = 0.5,
|
|
129
|
-
readiness_check_period: float = 5,
|
|
130
|
-
readiness_failure_threshold: int = 1,
|
|
131
|
-
readiness_timeout: int = 60,
|
|
132
|
-
monitor_readiness: bool = False,
|
|
133
|
-
max_call_iteration: int = 20,
|
|
134
|
-
upstream: list[AnyTask] | AnyTask | None = None,
|
|
135
|
-
fallback: list[AnyTask] | AnyTask | None = None,
|
|
136
|
-
successor: list[AnyTask] | AnyTask | None = None,
|
|
137
|
-
conversation_context: (
|
|
138
|
-
dict[str, Any] | Callable[[AnyContext], dict[str, Any]] | None
|
|
139
|
-
) = None,
|
|
140
|
-
):
|
|
141
|
-
super().__init__(
|
|
142
|
-
name=name,
|
|
143
|
-
color=color,
|
|
144
|
-
icon=icon,
|
|
145
|
-
description=description,
|
|
146
|
-
cli_only=cli_only,
|
|
147
|
-
input=input,
|
|
148
|
-
env=env,
|
|
149
|
-
execute_condition=execute_condition,
|
|
150
|
-
retries=retries,
|
|
151
|
-
retry_period=retry_period,
|
|
152
|
-
readiness_check=readiness_check,
|
|
153
|
-
readiness_check_delay=readiness_check_delay,
|
|
154
|
-
readiness_check_period=readiness_check_period,
|
|
155
|
-
readiness_failure_threshold=readiness_failure_threshold,
|
|
156
|
-
readiness_timeout=readiness_timeout,
|
|
157
|
-
monitor_readiness=monitor_readiness,
|
|
158
|
-
upstream=upstream,
|
|
159
|
-
fallback=fallback,
|
|
160
|
-
successor=successor,
|
|
161
|
-
)
|
|
162
|
-
self._model = model
|
|
163
|
-
self._render_model = render_model
|
|
164
|
-
self._model_base_url = model_base_url
|
|
165
|
-
self._render_model_base_url = render_model_base_url
|
|
166
|
-
self._model_api_key = model_api_key
|
|
167
|
-
self._render_model_api_key = render_model_api_key
|
|
168
|
-
self._model_settings = model_settings
|
|
169
|
-
self._small_model = small_model
|
|
170
|
-
self._render_small_model = render_small_model
|
|
171
|
-
self._small_model_base_url = small_model_base_url
|
|
172
|
-
self._render_small_model_base_url = render_small_model_base_url
|
|
173
|
-
self._small_model_api_key = small_model_api_key
|
|
174
|
-
self._render_small_model_api_key = render_small_model_api_key
|
|
175
|
-
self._small_model_settings = small_model_settings
|
|
176
|
-
self._persona = persona
|
|
177
|
-
self._render_persona = render_persona
|
|
178
|
-
self._system_prompt = system_prompt
|
|
179
|
-
self._render_system_prompt = render_system_prompt
|
|
180
|
-
self._special_instruction_prompt = special_instruction_prompt
|
|
181
|
-
self._render_special_instruction_prompt = render_special_instruction_prompt
|
|
182
|
-
self._workflows = workflows
|
|
183
|
-
self._render_workflows = render_workflows
|
|
184
|
-
self._message = message
|
|
185
|
-
self._render_message = render_message
|
|
186
|
-
self._summarization_prompt = summarization_prompt
|
|
187
|
-
self._render_summarization_prompt = render_summarization_prompt
|
|
188
|
-
self._tools = tools
|
|
189
|
-
self._rate_limitter = rate_limitter
|
|
190
|
-
self._additional_tools: list["ToolOrCallable"] = [load_workflow]
|
|
191
|
-
self._toolsets = toolsets
|
|
192
|
-
self._additional_toolsets: list["AbstractToolset[None] | str"] = []
|
|
193
|
-
self._conversation_history = conversation_history
|
|
194
|
-
self._conversation_history_reader = conversation_history_reader
|
|
195
|
-
self._conversation_history_writer = conversation_history_writer
|
|
196
|
-
self._conversation_history_file = conversation_history_file
|
|
197
|
-
self._render_history_file = render_history_file
|
|
198
|
-
self._should_summarize_history = summarize_history
|
|
199
|
-
self._render_summarize_history = render_summarize_history
|
|
200
|
-
self._history_summarization_token_threshold = (
|
|
201
|
-
history_summarization_token_threshold
|
|
202
|
-
)
|
|
203
|
-
self._render_history_summarization_token_threshold = (
|
|
204
|
-
render_history_summarization_token_threshold
|
|
205
|
-
)
|
|
206
|
-
self._max_call_iteration = max_call_iteration
|
|
207
|
-
self._conversation_context = conversation_context
|
|
208
|
-
self._yolo_mode = yolo_mode
|
|
209
|
-
self._render_yolo_mode = render_yolo_mode
|
|
210
|
-
self._attachment = attachment
|
|
211
|
-
|
|
212
|
-
def add_tool(self, *tool: "ToolOrCallable"):
|
|
213
|
-
self.append_tool(*tool)
|
|
214
|
-
|
|
215
|
-
def append_tool(self, *tool: "ToolOrCallable"):
|
|
216
|
-
for single_tool in tool:
|
|
217
|
-
self._additional_tools.append(single_tool)
|
|
218
|
-
|
|
219
|
-
def add_toolset(self, *toolset: "AbstractToolset[None] | str"):
|
|
220
|
-
self.append_toolset(*toolset)
|
|
221
|
-
|
|
222
|
-
def append_toolset(self, *toolset: "AbstractToolset[None] | str"):
|
|
223
|
-
for single_toolset in toolset:
|
|
224
|
-
self._additional_toolsets.append(single_toolset)
|
|
225
|
-
|
|
226
|
-
def set_should_summarize_history(self, summarize_history: bool):
|
|
227
|
-
self._should_summarize_history = summarize_history
|
|
228
|
-
|
|
229
|
-
def set_history_summarization_token_threshold(
|
|
230
|
-
self, summarization_token_threshold: int
|
|
231
|
-
):
|
|
232
|
-
self._history_summarization_token_threshold = summarization_token_threshold
|
|
233
|
-
|
|
234
|
-
def set_workflows(self, workflows: StrListAttr):
|
|
235
|
-
self._workflows = workflows
|
|
236
|
-
|
|
237
|
-
def set_yolo_mode(self, yolo_mode: StrListAttr | BoolAttr):
|
|
238
|
-
self._yolo_mode = yolo_mode
|
|
239
|
-
|
|
240
|
-
async def _exec_action(self, ctx: AnyContext) -> Any:
|
|
241
|
-
# Get dependent configurations first
|
|
242
|
-
model_settings = get_model_settings(ctx, self._model_settings)
|
|
243
|
-
model = get_model(
|
|
244
|
-
ctx=ctx,
|
|
245
|
-
model_attr=self._model,
|
|
246
|
-
render_model=self._render_model,
|
|
247
|
-
model_base_url_attr=self._model_base_url,
|
|
248
|
-
render_model_base_url=self._render_model_base_url,
|
|
249
|
-
model_api_key_attr=self._model_api_key,
|
|
250
|
-
render_model_api_key=self._render_model_api_key,
|
|
251
|
-
)
|
|
252
|
-
yolo_mode = get_yolo_mode(
|
|
253
|
-
ctx=ctx,
|
|
254
|
-
yolo_mode_attr=self._yolo_mode,
|
|
255
|
-
render_yolo_mode=self._render_yolo_mode,
|
|
256
|
-
)
|
|
257
|
-
summarization_prompt = get_summarization_system_prompt(
|
|
258
|
-
ctx=ctx,
|
|
259
|
-
summarization_prompt_attr=self._summarization_prompt,
|
|
260
|
-
render_summarization_prompt=self._render_summarization_prompt,
|
|
261
|
-
)
|
|
262
|
-
user_message = get_user_message(ctx, self._message, self._render_message)
|
|
263
|
-
attachments = get_attachments(ctx, self._attachment)
|
|
264
|
-
# 1. Prepare initial state (read history from previous session)
|
|
265
|
-
conversation_history = await read_conversation_history(
|
|
266
|
-
ctx=ctx,
|
|
267
|
-
conversation_history_reader=self._conversation_history_reader,
|
|
268
|
-
conversation_history_file_attr=self._conversation_history_file,
|
|
269
|
-
render_history_file=self._render_history_file,
|
|
270
|
-
conversation_history_attr=self._conversation_history,
|
|
271
|
-
)
|
|
272
|
-
inject_conversation_history_notes(conversation_history)
|
|
273
|
-
inject_subagent_conversation_history_into_ctx(ctx, conversation_history)
|
|
274
|
-
# 2. Get system prompt and user prompt
|
|
275
|
-
system_prompt, user_prompt = get_system_and_user_prompt(
|
|
276
|
-
ctx=ctx,
|
|
277
|
-
user_message=user_message,
|
|
278
|
-
persona_attr=self._persona,
|
|
279
|
-
render_persona=self._render_persona,
|
|
280
|
-
system_prompt_attr=self._system_prompt,
|
|
281
|
-
render_system_prompt=self._render_system_prompt,
|
|
282
|
-
special_instruction_prompt_attr=self._special_instruction_prompt,
|
|
283
|
-
render_special_instruction_prompt=self._render_special_instruction_prompt,
|
|
284
|
-
workflows_attr=self._workflows,
|
|
285
|
-
render_workflows=self._render_workflows,
|
|
286
|
-
conversation_history=conversation_history,
|
|
287
|
-
)
|
|
288
|
-
# 3. Summarization
|
|
289
|
-
small_model = get_model(
|
|
290
|
-
ctx=ctx,
|
|
291
|
-
model_attr=self._small_model,
|
|
292
|
-
render_model=self._render_small_model,
|
|
293
|
-
model_base_url_attr=self._small_model_base_url,
|
|
294
|
-
render_model_base_url=self._render_small_model_base_url,
|
|
295
|
-
model_api_key_attr=self._small_model_api_key,
|
|
296
|
-
render_model_api_key=self._render_small_model_api_key,
|
|
297
|
-
)
|
|
298
|
-
small_model_settings = get_model_settings(ctx, self._small_model_settings)
|
|
299
|
-
summarization_token_threshold = get_history_summarization_token_threshold(
|
|
300
|
-
ctx,
|
|
301
|
-
self._history_summarization_token_threshold,
|
|
302
|
-
self._render_history_summarization_token_threshold,
|
|
303
|
-
)
|
|
304
|
-
# 4. Get the agent instance
|
|
305
|
-
ctx.log_info(f"SYSTEM PROMPT:\n{system_prompt}")
|
|
306
|
-
ctx.log_info(f"USER PROMPT:\n{user_prompt}")
|
|
307
|
-
agent = get_agent(
|
|
308
|
-
ctx=ctx,
|
|
309
|
-
model=model,
|
|
310
|
-
rate_limitter=self._rate_limitter,
|
|
311
|
-
system_prompt=system_prompt,
|
|
312
|
-
model_settings=model_settings,
|
|
313
|
-
tools_attr=self._tools,
|
|
314
|
-
additional_tools=self._additional_tools,
|
|
315
|
-
toolsets_attr=self._toolsets,
|
|
316
|
-
additional_toolsets=self._additional_toolsets,
|
|
317
|
-
yolo_mode=yolo_mode,
|
|
318
|
-
summarization_model=small_model,
|
|
319
|
-
summarization_model_settings=small_model_settings,
|
|
320
|
-
summarization_system_prompt=summarization_prompt,
|
|
321
|
-
summarization_retries=2, # TODO: make this a property
|
|
322
|
-
summarization_token_threshold=summarization_token_threshold,
|
|
323
|
-
history_processors=[], # TODO: make this a property
|
|
324
|
-
)
|
|
325
|
-
# 5. Run the agent iteration and save the results/history
|
|
326
|
-
result = await self._execute_agent(
|
|
327
|
-
ctx=ctx,
|
|
328
|
-
agent=agent,
|
|
329
|
-
user_prompt=user_prompt,
|
|
330
|
-
attachments=attachments,
|
|
331
|
-
conversation_history=conversation_history,
|
|
332
|
-
)
|
|
333
|
-
# 6. Write conversation history
|
|
334
|
-
conversation_history.subagent_history = (
|
|
335
|
-
extract_subagent_conversation_history_from_ctx(ctx)
|
|
336
|
-
)
|
|
337
|
-
await write_conversation_history(
|
|
338
|
-
ctx=ctx,
|
|
339
|
-
history_data=conversation_history,
|
|
340
|
-
conversation_history_writer=self._conversation_history_writer,
|
|
341
|
-
conversation_history_file_attr=self._conversation_history_file,
|
|
342
|
-
render_history_file=self._render_history_file,
|
|
343
|
-
)
|
|
344
|
-
return result
|
|
345
|
-
|
|
346
|
-
async def _execute_agent(
|
|
347
|
-
self,
|
|
348
|
-
ctx: AnyContext,
|
|
349
|
-
agent: "Agent",
|
|
350
|
-
user_prompt: str,
|
|
351
|
-
attachments: "list[UserContent]",
|
|
352
|
-
conversation_history: ConversationHistory,
|
|
353
|
-
) -> Any:
|
|
354
|
-
"""Executes the agent, processes results, and saves history."""
|
|
355
|
-
try:
|
|
356
|
-
agent_run = await run_agent_iteration(
|
|
357
|
-
ctx=ctx,
|
|
358
|
-
agent=agent,
|
|
359
|
-
user_prompt=user_prompt,
|
|
360
|
-
attachments=attachments,
|
|
361
|
-
history_list=conversation_history.history,
|
|
362
|
-
rate_limitter=self._rate_limitter,
|
|
363
|
-
)
|
|
364
|
-
if agent_run and agent_run.result:
|
|
365
|
-
new_history_list = json.loads(agent_run.result.all_messages_json())
|
|
366
|
-
conversation_history.history = new_history_list
|
|
367
|
-
xcom_usage_key = f"{self.name}-usage"
|
|
368
|
-
if xcom_usage_key not in ctx.xcom:
|
|
369
|
-
ctx.xcom[xcom_usage_key] = Xcom([])
|
|
370
|
-
usage = agent_run.result.usage()
|
|
371
|
-
ctx.xcom[xcom_usage_key].push(usage)
|
|
372
|
-
ctx.print(stylize_faint(f" 💸 Token: {usage}"), plain=True)
|
|
373
|
-
return agent_run.result.output
|
|
374
|
-
else:
|
|
375
|
-
ctx.log_warning("Agent run did not produce a result.")
|
|
376
|
-
return None # Or handle as appropriate
|
|
377
|
-
except Exception as e:
|
|
378
|
-
ctx.log_error(f"Error during agent execution or history saving: {str(e)}")
|
|
379
|
-
raise # Re-raise the exception after logging
|
zrb/task_status/__init__.py
DELETED
|
File without changes
|
zrb/util/__init__.py
DELETED
|
File without changes
|
zrb/util/cli/__init__.py
DELETED
|
File without changes
|
zrb/util/cmd/__init__.py
DELETED
|
File without changes
|
zrb/util/codemod/__init__.py
DELETED
|
File without changes
|
zrb/util/string/__init__.py
DELETED
|
File without changes
|
zrb/xcom/__init__.py
DELETED
|
File without changes
|
/zrb/{config/default_prompt/file_extractor_system_prompt.md → llm/prompt/markdown/file_extractor.md}
RENAMED
|
File without changes
|
/zrb/{config/default_prompt/repo_extractor_system_prompt.md → llm/prompt/markdown/repo_extractor.md}
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|