zrb 1.15.3__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.

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