waldiez 0.5.6__py3-none-any.whl → 0.5.8__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 waldiez might be problematic. Click here for more details.
- waldiez/_version.py +1 -1
- waldiez/cli.py +17 -2
- waldiez/exporter.py +1 -1
- waldiez/exporting/agent/code_execution.py +8 -1
- waldiez/exporting/agent/exporter.py +2 -1
- waldiez/exporting/agent/extras/captain_agent_extras.py +1 -0
- waldiez/exporting/agent/extras/doc_agent_extras.py +2 -3
- waldiez/exporting/agent/extras/group_manager_agent_extas.py +1 -0
- waldiez/exporting/agent/extras/handoffs/after_work.py +4 -4
- waldiez/exporting/agent/extras/handoffs/target.py +3 -0
- waldiez/exporting/agent/extras/rag/chroma_extras.py +0 -4
- waldiez/exporting/agent/extras/rag/mongo_extras.py +0 -1
- waldiez/exporting/agent/extras/rag/pgvector_extras.py +0 -2
- waldiez/exporting/agent/extras/rag/qdrant_extras.py +0 -3
- waldiez/exporting/agent/extras/rag/vector_db_extras.py +3 -2
- waldiez/exporting/agent/factory.py +11 -11
- waldiez/exporting/agent/processor.py +3 -2
- waldiez/exporting/chats/exporter.py +2 -2
- waldiez/exporting/chats/factory.py +5 -5
- waldiez/exporting/chats/processor.py +22 -1
- waldiez/exporting/chats/utils/common.py +45 -1
- waldiez/exporting/chats/utils/group.py +1 -1
- waldiez/exporting/chats/utils/sequential.py +3 -68
- waldiez/exporting/chats/utils/single.py +1 -38
- waldiez/exporting/core/context.py +39 -38
- waldiez/exporting/core/exporter.py +10 -10
- waldiez/exporting/core/exporters.py +36 -0
- waldiez/exporting/core/extras/base.py +2 -2
- waldiez/exporting/core/extras/chat_extras.py +4 -2
- waldiez/exporting/core/extras/path_resolver.py +6 -4
- waldiez/exporting/core/extras/serializer.py +1 -0
- waldiez/exporting/core/protocols.py +6 -0
- waldiez/exporting/core/result.py +8 -7
- waldiez/exporting/core/types.py +2 -2
- waldiez/exporting/core/utils/llm_config.py +2 -0
- waldiez/exporting/flow/execution_generator.py +54 -32
- waldiez/exporting/flow/factory.py +2 -2
- waldiez/exporting/flow/file_generator.py +8 -7
- waldiez/exporting/flow/merger.py +8 -7
- waldiez/exporting/flow/orchestrator.py +22 -8
- waldiez/exporting/flow/utils/__init__.py +2 -0
- waldiez/exporting/flow/utils/common.py +20 -11
- waldiez/exporting/flow/utils/importing.py +2 -1
- waldiez/exporting/flow/utils/logging.py +5 -2
- waldiez/exporting/models/exporter.py +2 -1
- waldiez/exporting/models/factory.py +6 -7
- waldiez/exporting/tools/exporter.py +7 -6
- waldiez/exporting/tools/factory.py +4 -5
- waldiez/exporting/tools/processor.py +9 -4
- waldiez/exporting/tools/registration.py +1 -0
- waldiez/io/_ws.py +2 -0
- waldiez/io/models/content/audio.py +1 -0
- waldiez/io/models/content/file.py +1 -0
- waldiez/io/models/content/image.py +1 -0
- waldiez/io/models/content/text.py +1 -0
- waldiez/io/models/content/video.py +1 -0
- waldiez/io/models/user_input.py +1 -0
- waldiez/io/models/user_response.py +1 -0
- waldiez/io/mqtt.py +6 -3
- waldiez/io/redis.py +7 -9
- waldiez/io/structured.py +8 -6
- waldiez/io/utils.py +11 -4
- waldiez/io/ws.py +4 -3
- waldiez/logger.py +11 -1
- waldiez/models/agents/agent/agent.py +1 -0
- waldiez/models/agents/agent/agent_data.py +2 -2
- waldiez/models/agents/agent/nested_chat.py +1 -4
- waldiez/models/agents/agent/termination_message.py +0 -7
- waldiez/models/agents/agent/update_system_message.py +2 -2
- waldiez/models/agents/doc_agent/doc_agent_data.py +33 -26
- waldiez/models/agents/doc_agent/rag_query_engine.py +1 -1
- waldiez/models/agents/extra_requirements.py +5 -5
- waldiez/models/agents/group_manager/group_manager.py +3 -7
- waldiez/models/agents/group_manager/speakers.py +0 -7
- waldiez/models/agents/rag_user_proxy/rag_user_proxy.py +0 -2
- waldiez/models/agents/rag_user_proxy/rag_user_proxy_data.py +0 -2
- waldiez/models/agents/rag_user_proxy/retrieve_config.py +1 -17
- waldiez/models/agents/rag_user_proxy/vector_db_config.py +0 -5
- waldiez/models/chat/chat_data.py +0 -2
- waldiez/models/chat/chat_summary.py +5 -3
- waldiez/models/common/handoff.py +26 -18
- waldiez/models/common/naming.py +1 -0
- waldiez/models/flow/flow.py +9 -7
- waldiez/models/model/_llm.py +4 -2
- waldiez/models/model/extra_requirements.py +3 -3
- waldiez/models/model/model.py +5 -4
- waldiez/models/tool/extra_requirements.py +2 -2
- waldiez/models/tool/predefined/_google.py +7 -12
- waldiez/models/tool/predefined/_perplexity.py +13 -9
- waldiez/models/tool/predefined/_searxng.py +4 -1
- waldiez/models/tool/predefined/_tavily.py +0 -6
- waldiez/models/tool/predefined/_wikipedia.py +5 -1
- waldiez/models/tool/predefined/_youtube.py +0 -4
- waldiez/models/tool/tool.py +7 -7
- waldiez/models/tool/tool_data.py +39 -2
- waldiez/models/waldiez.py +29 -29
- waldiez/runner.py +18 -13
- waldiez/running/base_runner.py +96 -40
- waldiez/running/environment.py +2 -0
- waldiez/running/patch_io_stream.py +2 -0
- waldiez/running/post_run.py +3 -0
- waldiez/running/pre_run.py +1 -0
- waldiez/running/protocol.py +50 -48
- waldiez/running/run_results.py +2 -10
- waldiez/running/standard_runner.py +37 -13
- waldiez/running/timeline_processor.py +12 -1
- waldiez/running/utils.py +2 -0
- waldiez/utils/conflict_checker.py +1 -1
- waldiez/utils/version.py +1 -0
- {waldiez-0.5.6.dist-info → waldiez-0.5.8.dist-info}/METADATA +68 -65
- {waldiez-0.5.6.dist-info → waldiez-0.5.8.dist-info}/RECORD +115 -116
- waldiez/exporting/agent/extras/group/target.py +0 -178
- {waldiez-0.5.6.dist-info → waldiez-0.5.8.dist-info}/WHEEL +0 -0
- {waldiez-0.5.6.dist-info → waldiez-0.5.8.dist-info}/entry_points.txt +0 -0
- {waldiez-0.5.6.dist-info → waldiez-0.5.8.dist-info}/licenses/LICENSE +0 -0
- {waldiez-0.5.6.dist-info → waldiez-0.5.8.dist-info}/licenses/NOTICE.md +0 -0
waldiez/runner.py
CHANGED
|
@@ -14,7 +14,7 @@ variables specified in the waldiez file are set.
|
|
|
14
14
|
"""
|
|
15
15
|
|
|
16
16
|
from pathlib import Path
|
|
17
|
-
from typing import
|
|
17
|
+
from typing import Any
|
|
18
18
|
|
|
19
19
|
from typing_extensions import Literal
|
|
20
20
|
|
|
@@ -24,12 +24,6 @@ from .running import (
|
|
|
24
24
|
WaldiezStandardRunner,
|
|
25
25
|
)
|
|
26
26
|
|
|
27
|
-
if TYPE_CHECKING:
|
|
28
|
-
from autogen.io.run_response import ( # type: ignore[import-untyped]
|
|
29
|
-
AsyncRunResponseProtocol,
|
|
30
|
-
RunResponseProtocol,
|
|
31
|
-
)
|
|
32
|
-
|
|
33
27
|
|
|
34
28
|
def create_runner(
|
|
35
29
|
waldiez: Waldiez,
|
|
@@ -38,6 +32,7 @@ def create_runner(
|
|
|
38
32
|
output_path: str | Path | None = None,
|
|
39
33
|
uploads_root: str | Path | None = None,
|
|
40
34
|
structured_io: bool = False,
|
|
35
|
+
dot_env: str | Path | None = None,
|
|
41
36
|
**kwargs: Any,
|
|
42
37
|
) -> WaldiezBaseRunner:
|
|
43
38
|
"""Create a Waldiez runner of the specified type.
|
|
@@ -54,6 +49,8 @@ def create_runner(
|
|
|
54
49
|
Uploads root directory, by default None
|
|
55
50
|
structured_io : bool, optional
|
|
56
51
|
Use structured I/O, by default False
|
|
52
|
+
dot_env : str | Path | None, optional
|
|
53
|
+
Path to a .env file for environment variables, by default None
|
|
57
54
|
**kwargs
|
|
58
55
|
Additional arguments for specific runner types
|
|
59
56
|
|
|
@@ -84,6 +81,7 @@ def create_runner(
|
|
|
84
81
|
output_path=output_path,
|
|
85
82
|
uploads_root=uploads_root,
|
|
86
83
|
structured_io=structured_io,
|
|
84
|
+
dot_env=dot_env,
|
|
87
85
|
**kwargs,
|
|
88
86
|
)
|
|
89
87
|
|
|
@@ -92,6 +90,7 @@ class WaldiezRunner(WaldiezBaseRunner):
|
|
|
92
90
|
"""Factory class for creating Waldiez runners."""
|
|
93
91
|
|
|
94
92
|
# pylint: disable=super-init-not-called
|
|
93
|
+
# noinspection PyMissingConstructor
|
|
95
94
|
def __init__(
|
|
96
95
|
self,
|
|
97
96
|
waldiez: Waldiez,
|
|
@@ -100,6 +99,7 @@ class WaldiezRunner(WaldiezBaseRunner):
|
|
|
100
99
|
output_path: str | Path | None = None,
|
|
101
100
|
uploads_root: str | Path | None = None,
|
|
102
101
|
structured_io: bool = False,
|
|
102
|
+
dot_env: str | Path | None = None,
|
|
103
103
|
**kwargs: Any,
|
|
104
104
|
):
|
|
105
105
|
"""Create a runner instance.
|
|
@@ -116,9 +116,10 @@ class WaldiezRunner(WaldiezBaseRunner):
|
|
|
116
116
|
Uploads root directory, by default None
|
|
117
117
|
structured_io : bool, optional
|
|
118
118
|
Use structured I/O, by default False
|
|
119
|
+
dot_env : str | Path | None, optional
|
|
120
|
+
Path to a .env file for environment variables, by default None
|
|
119
121
|
**kwargs
|
|
120
122
|
Additional arguments for specific runner types
|
|
121
|
-
|
|
122
123
|
"""
|
|
123
124
|
self._runner = create_runner(
|
|
124
125
|
waldiez=waldiez,
|
|
@@ -126,6 +127,7 @@ class WaldiezRunner(WaldiezBaseRunner):
|
|
|
126
127
|
output_path=output_path,
|
|
127
128
|
uploads_root=uploads_root,
|
|
128
129
|
structured_io=structured_io,
|
|
130
|
+
dot_env=dot_env,
|
|
129
131
|
**kwargs,
|
|
130
132
|
)
|
|
131
133
|
|
|
@@ -164,10 +166,7 @@ class WaldiezRunner(WaldiezBaseRunner):
|
|
|
164
166
|
skip_mmd: bool,
|
|
165
167
|
skip_timeline: bool,
|
|
166
168
|
**kwargs: Any,
|
|
167
|
-
) ->
|
|
168
|
-
list["RunResponseProtocol"],
|
|
169
|
-
list["AsyncRunResponseProtocol"],
|
|
170
|
-
]:
|
|
169
|
+
) -> list[dict[str, Any]]:
|
|
171
170
|
return self._runner._run(
|
|
172
171
|
temp_dir=temp_dir,
|
|
173
172
|
output_file=output_file,
|
|
@@ -204,14 +203,16 @@ class WaldiezRunner(WaldiezBaseRunner):
|
|
|
204
203
|
uploads_root: Path | None,
|
|
205
204
|
skip_mmd: bool,
|
|
206
205
|
skip_timeline: bool,
|
|
206
|
+
dot_env: str | Path | None = None,
|
|
207
207
|
**kwargs: Any,
|
|
208
|
-
) ->
|
|
208
|
+
) -> list[dict[str, Any]]:
|
|
209
209
|
return await self._runner._a_run(
|
|
210
210
|
temp_dir=temp_dir,
|
|
211
211
|
output_file=output_file,
|
|
212
212
|
uploads_root=uploads_root,
|
|
213
213
|
skip_mmd=skip_mmd,
|
|
214
214
|
skip_timeline=skip_timeline,
|
|
215
|
+
dot_env=dot_env,
|
|
215
216
|
**kwargs,
|
|
216
217
|
)
|
|
217
218
|
|
|
@@ -245,6 +246,7 @@ class WaldiezRunner(WaldiezBaseRunner):
|
|
|
245
246
|
output_path: str | Path | None = None,
|
|
246
247
|
uploads_root: str | Path | None = None,
|
|
247
248
|
structured_io: bool = False,
|
|
249
|
+
dot_env: str | Path | None = None,
|
|
248
250
|
**kwargs: Any,
|
|
249
251
|
) -> "WaldiezRunner":
|
|
250
252
|
"""Load a waldiez flow and create a runner.
|
|
@@ -267,6 +269,8 @@ class WaldiezRunner(WaldiezBaseRunner):
|
|
|
267
269
|
Uploads root directory, by default None
|
|
268
270
|
structured_io : bool, optional
|
|
269
271
|
Use structured I/O, by default False
|
|
272
|
+
dot_env : str | Path | None, optional
|
|
273
|
+
Path to a .env file for environment variables, by default None
|
|
270
274
|
**kwargs
|
|
271
275
|
Additional arguments for specific runner types
|
|
272
276
|
|
|
@@ -294,5 +298,6 @@ class WaldiezRunner(WaldiezBaseRunner):
|
|
|
294
298
|
output_path=output_path,
|
|
295
299
|
uploads_root=uploads_root,
|
|
296
300
|
structured_io=structured_io,
|
|
301
|
+
dot_env=dot_env,
|
|
297
302
|
**kwargs,
|
|
298
303
|
)
|
waldiez/running/base_runner.py
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
|
|
8
8
|
"""Base runner for Waldiez workflows."""
|
|
9
9
|
|
|
10
|
+
import shutil
|
|
10
11
|
import sys
|
|
11
12
|
import tempfile
|
|
12
13
|
import threading
|
|
@@ -19,9 +20,9 @@ from typing import (
|
|
|
19
20
|
Coroutine,
|
|
20
21
|
Optional,
|
|
21
22
|
Type,
|
|
22
|
-
Union,
|
|
23
23
|
)
|
|
24
24
|
|
|
25
|
+
from aiofiles.os import wrap
|
|
25
26
|
from anyio.from_thread import start_blocking_portal
|
|
26
27
|
from typing_extensions import Self
|
|
27
28
|
|
|
@@ -43,15 +44,19 @@ from .utils import (
|
|
|
43
44
|
|
|
44
45
|
if TYPE_CHECKING:
|
|
45
46
|
from autogen.events import BaseEvent # type: ignore[import-untyped]
|
|
46
|
-
from autogen.io.run_response import ( # type: ignore[import-untyped]
|
|
47
|
-
AsyncRunResponseProtocol,
|
|
48
|
-
RunResponseProtocol,
|
|
49
|
-
)
|
|
50
47
|
|
|
51
48
|
|
|
52
49
|
class WaldiezBaseRunner(WaldiezRunnerProtocol):
|
|
53
50
|
"""Base runner for Waldiez.
|
|
54
51
|
|
|
52
|
+
Initialization parameters:
|
|
53
|
+
- waldiez: The Waldiez flow to run.
|
|
54
|
+
- output_path: Path to save the output file.
|
|
55
|
+
- uploads_root: Root directory for uploads.
|
|
56
|
+
- structured_io: Whether to use structured I/O.
|
|
57
|
+
- skip_patch_io: Whether to skip patching I/O functions.
|
|
58
|
+
- dot_env: Path to a .env file for environment variables.
|
|
59
|
+
|
|
55
60
|
Methods to override:
|
|
56
61
|
- _before_run: Actions to perform before running the flow.
|
|
57
62
|
- _a_before_run: Async actions to perform before running the flow.
|
|
@@ -68,6 +73,7 @@ class WaldiezBaseRunner(WaldiezRunnerProtocol):
|
|
|
68
73
|
_structured_io: bool
|
|
69
74
|
_output_path: str | Path | None
|
|
70
75
|
_uploads_root: str | Path | None
|
|
76
|
+
_dot_env_path: str | Path | None
|
|
71
77
|
_skip_patch_io: bool
|
|
72
78
|
_running: bool
|
|
73
79
|
|
|
@@ -78,6 +84,7 @@ class WaldiezBaseRunner(WaldiezRunnerProtocol):
|
|
|
78
84
|
uploads_root: str | Path | None,
|
|
79
85
|
structured_io: bool,
|
|
80
86
|
skip_patch_io: bool = False,
|
|
87
|
+
dot_env: str | Path | None = None,
|
|
81
88
|
) -> None:
|
|
82
89
|
"""Initialize the Waldiez manager."""
|
|
83
90
|
self._waldiez = waldiez
|
|
@@ -86,6 +93,7 @@ class WaldiezBaseRunner(WaldiezRunnerProtocol):
|
|
|
86
93
|
WaldiezBaseRunner._output_path = output_path
|
|
87
94
|
WaldiezBaseRunner._uploads_root = uploads_root
|
|
88
95
|
WaldiezBaseRunner._skip_patch_io = skip_patch_io
|
|
96
|
+
WaldiezBaseRunner._dot_env_path = dot_env
|
|
89
97
|
self._called_install_requirements = False
|
|
90
98
|
self._exporter = WaldiezExporter(waldiez)
|
|
91
99
|
self._stop_requested = threading.Event()
|
|
@@ -95,9 +103,7 @@ class WaldiezBaseRunner(WaldiezRunnerProtocol):
|
|
|
95
103
|
self._input: (
|
|
96
104
|
Callable[..., str] | Callable[..., Coroutine[Any, Any, str]]
|
|
97
105
|
) = input
|
|
98
|
-
self._last_results:
|
|
99
|
-
list["RunResponseProtocol"], list["AsyncRunResponseProtocol"]
|
|
100
|
-
] = []
|
|
106
|
+
self._last_results: list[dict[str, Any]] = []
|
|
101
107
|
self._last_exception: Exception | None = None
|
|
102
108
|
self._execution_complete_event = threading.Event()
|
|
103
109
|
self._execution_thread: Optional[threading.Thread] = None
|
|
@@ -186,6 +192,11 @@ class WaldiezBaseRunner(WaldiezRunnerProtocol):
|
|
|
186
192
|
uploads_root=uploads_root,
|
|
187
193
|
structured_io=WaldiezBaseRunner._structured_io,
|
|
188
194
|
)
|
|
195
|
+
if self._dot_env_path:
|
|
196
|
+
shutil.copyfile(
|
|
197
|
+
str(self._dot_env_path),
|
|
198
|
+
str(temp_dir / ".env"),
|
|
199
|
+
)
|
|
189
200
|
return temp_dir
|
|
190
201
|
|
|
191
202
|
async def _a_before_run(
|
|
@@ -203,6 +214,12 @@ class WaldiezBaseRunner(WaldiezRunnerProtocol):
|
|
|
203
214
|
structured_io=self.structured_io,
|
|
204
215
|
force=True,
|
|
205
216
|
)
|
|
217
|
+
if self._dot_env_path:
|
|
218
|
+
wrapped = wrap(shutil.copyfile)
|
|
219
|
+
await wrapped(
|
|
220
|
+
str(self._dot_env_path),
|
|
221
|
+
str(temp_dir / ".env"),
|
|
222
|
+
)
|
|
206
223
|
return temp_dir
|
|
207
224
|
|
|
208
225
|
def _run(
|
|
@@ -212,7 +229,8 @@ class WaldiezBaseRunner(WaldiezRunnerProtocol):
|
|
|
212
229
|
uploads_root: Path | None,
|
|
213
230
|
skip_mmd: bool,
|
|
214
231
|
skip_timeline: bool,
|
|
215
|
-
|
|
232
|
+
**kwargs: Any,
|
|
233
|
+
) -> list[dict[str, Any]]:
|
|
216
234
|
"""Run the Waldiez flow."""
|
|
217
235
|
raise NotImplementedError(
|
|
218
236
|
"The _run method must be implemented in the subclass."
|
|
@@ -225,7 +243,8 @@ class WaldiezBaseRunner(WaldiezRunnerProtocol):
|
|
|
225
243
|
uploads_root: Path | None,
|
|
226
244
|
skip_mmd: bool,
|
|
227
245
|
skip_timeline: bool,
|
|
228
|
-
|
|
246
|
+
**kwargs: Any,
|
|
247
|
+
) -> list[dict[str, Any]]:
|
|
229
248
|
"""Run the Waldiez flow asynchronously."""
|
|
230
249
|
raise NotImplementedError(
|
|
231
250
|
"The _a_run method must be implemented in the subclass."
|
|
@@ -262,8 +281,6 @@ class WaldiezBaseRunner(WaldiezRunnerProtocol):
|
|
|
262
281
|
The path to the output file.
|
|
263
282
|
uploads_root : Path | None
|
|
264
283
|
The root path for uploads, if any.
|
|
265
|
-
structured_io : bool
|
|
266
|
-
Whether to use structured IO instead of the default 'input/print'.
|
|
267
284
|
skip_mmd : bool
|
|
268
285
|
Whether to skip generating the mermaid diagram.
|
|
269
286
|
"""
|
|
@@ -273,9 +290,7 @@ class WaldiezBaseRunner(WaldiezRunnerProtocol):
|
|
|
273
290
|
|
|
274
291
|
def _after_run(
|
|
275
292
|
self,
|
|
276
|
-
results:
|
|
277
|
-
list["RunResponseProtocol"], list["AsyncRunResponseProtocol"]
|
|
278
|
-
],
|
|
293
|
+
results: list[dict[str, Any]],
|
|
279
294
|
output_file: Path,
|
|
280
295
|
uploads_root: Path | None,
|
|
281
296
|
temp_dir: Path,
|
|
@@ -300,9 +315,7 @@ class WaldiezBaseRunner(WaldiezRunnerProtocol):
|
|
|
300
315
|
|
|
301
316
|
async def _a_after_run(
|
|
302
317
|
self,
|
|
303
|
-
results:
|
|
304
|
-
list["RunResponseProtocol"], list["AsyncRunResponseProtocol"]
|
|
305
|
-
],
|
|
318
|
+
results: list[dict[str, Any]],
|
|
306
319
|
output_file: Path,
|
|
307
320
|
uploads_root: Path | None,
|
|
308
321
|
temp_dir: Path,
|
|
@@ -367,6 +380,8 @@ class WaldiezBaseRunner(WaldiezRunnerProtocol):
|
|
|
367
380
|
for req in self.waldiez.requirements
|
|
368
381
|
if req not in sys.modules and "waldiez" not in req
|
|
369
382
|
}
|
|
383
|
+
if "python-dotenv" not in extra_requirements:
|
|
384
|
+
extra_requirements.add("python-dotenv")
|
|
370
385
|
return extra_requirements
|
|
371
386
|
|
|
372
387
|
def install_requirements(self) -> None:
|
|
@@ -444,7 +459,9 @@ class WaldiezBaseRunner(WaldiezRunnerProtocol):
|
|
|
444
459
|
structured_io: bool | None = None,
|
|
445
460
|
skip_mmd: bool = False,
|
|
446
461
|
skip_timeline: bool = False,
|
|
447
|
-
|
|
462
|
+
dot_env: str | Path | None = None,
|
|
463
|
+
**kwargs: Any,
|
|
464
|
+
) -> list[dict[str, Any]]:
|
|
448
465
|
"""Run the Waldiez flow in blocking mode.
|
|
449
466
|
|
|
450
467
|
Parameters
|
|
@@ -460,18 +477,25 @@ class WaldiezBaseRunner(WaldiezRunnerProtocol):
|
|
|
460
477
|
Whether to skip generating the mermaid diagram, by default False.
|
|
461
478
|
skip_timeline : bool
|
|
462
479
|
Whether to skip generating the timeline JSON.
|
|
480
|
+
dot_env : str | Path | None
|
|
481
|
+
The path to the .env file, if any.
|
|
482
|
+
**kwargs : Any
|
|
483
|
+
Additional keyword arguments for the run method.
|
|
463
484
|
|
|
464
485
|
Returns
|
|
465
486
|
-------
|
|
466
|
-
|
|
467
|
-
The result of the run
|
|
468
|
-
or a list of AsyncRunResponseProtocol.
|
|
487
|
+
list[dict[str, Any]]
|
|
488
|
+
The result of the run.
|
|
469
489
|
|
|
470
490
|
Raises
|
|
471
491
|
------
|
|
472
492
|
RuntimeError
|
|
473
493
|
If the runner is already running.
|
|
474
494
|
"""
|
|
495
|
+
if dot_env is not None:
|
|
496
|
+
resolved = Path(dot_env).resolve()
|
|
497
|
+
if resolved.is_file():
|
|
498
|
+
WaldiezBaseRunner._dot_env_path = resolved
|
|
475
499
|
if structured_io is not None:
|
|
476
500
|
WaldiezBaseRunner._structured_io = structured_io
|
|
477
501
|
if self.is_running():
|
|
@@ -496,9 +520,7 @@ class WaldiezBaseRunner(WaldiezRunnerProtocol):
|
|
|
496
520
|
self.install_requirements()
|
|
497
521
|
refresh_environment()
|
|
498
522
|
WaldiezBaseRunner._running = True
|
|
499
|
-
results:
|
|
500
|
-
list["RunResponseProtocol"], list["AsyncRunResponseProtocol"]
|
|
501
|
-
] = []
|
|
523
|
+
results: list[dict[str, Any]] = []
|
|
502
524
|
old_env_vars = set_env_vars(self.waldiez.get_flow_env_vars())
|
|
503
525
|
try:
|
|
504
526
|
with chdir(to=temp_dir):
|
|
@@ -526,6 +548,7 @@ class WaldiezBaseRunner(WaldiezRunnerProtocol):
|
|
|
526
548
|
sys.path.pop(0)
|
|
527
549
|
return results
|
|
528
550
|
|
|
551
|
+
# noinspection DuplicatedCode
|
|
529
552
|
async def a_run(
|
|
530
553
|
self,
|
|
531
554
|
output_path: str | Path | None = None,
|
|
@@ -533,7 +556,9 @@ class WaldiezBaseRunner(WaldiezRunnerProtocol):
|
|
|
533
556
|
structured_io: bool | None = None,
|
|
534
557
|
skip_mmd: bool = False,
|
|
535
558
|
skip_timeline: bool = False,
|
|
536
|
-
|
|
559
|
+
dot_env: str | Path | None = None,
|
|
560
|
+
**kwargs: Any,
|
|
561
|
+
) -> list[dict[str, Any]]:
|
|
537
562
|
"""Run the Waldiez flow asynchronously.
|
|
538
563
|
|
|
539
564
|
Parameters
|
|
@@ -549,18 +574,25 @@ class WaldiezBaseRunner(WaldiezRunnerProtocol):
|
|
|
549
574
|
Whether to skip generating the mermaid diagram, by default False.
|
|
550
575
|
skip_timeline : bool
|
|
551
576
|
Whether to skip generating the timeline JSON, by default False.
|
|
577
|
+
dot_env : str | Path | None
|
|
578
|
+
The path to the .env file, if any.
|
|
579
|
+
**kwargs : Any
|
|
580
|
+
Additional keyword arguments for the run method.
|
|
552
581
|
|
|
553
582
|
Returns
|
|
554
583
|
-------
|
|
555
|
-
|
|
556
|
-
The result of the run
|
|
557
|
-
or a list of AsyncRunResponseProtocol.
|
|
584
|
+
list[dict[str, Any]]
|
|
585
|
+
The result of the run.
|
|
558
586
|
|
|
559
587
|
Raises
|
|
560
588
|
------
|
|
561
589
|
RuntimeError
|
|
562
590
|
If the runner is already running.
|
|
563
591
|
"""
|
|
592
|
+
if dot_env is not None:
|
|
593
|
+
resolved = Path(dot_env).resolve()
|
|
594
|
+
if resolved.is_file():
|
|
595
|
+
WaldiezBaseRunner._dot_env_path = resolved
|
|
564
596
|
if structured_io is not None:
|
|
565
597
|
WaldiezBaseRunner._structured_io = structured_io
|
|
566
598
|
if self.is_running():
|
|
@@ -576,9 +608,7 @@ class WaldiezBaseRunner(WaldiezRunnerProtocol):
|
|
|
576
608
|
await self.a_install_requirements()
|
|
577
609
|
refresh_environment()
|
|
578
610
|
WaldiezBaseRunner._running = True
|
|
579
|
-
results:
|
|
580
|
-
list["RunResponseProtocol"], list["AsyncRunResponseProtocol"]
|
|
581
|
-
] = []
|
|
611
|
+
results: list[dict[str, Any]] = []
|
|
582
612
|
old_env_vars = set_env_vars(self.waldiez.get_flow_env_vars())
|
|
583
613
|
try:
|
|
584
614
|
async with a_chdir(to=temp_dir):
|
|
@@ -612,6 +642,8 @@ class WaldiezBaseRunner(WaldiezRunnerProtocol):
|
|
|
612
642
|
structured_io: bool | None = None,
|
|
613
643
|
skip_mmd: bool = False,
|
|
614
644
|
skip_timeline: bool = False,
|
|
645
|
+
dot_env: str | Path | None = None,
|
|
646
|
+
**kwargs: Any,
|
|
615
647
|
) -> None:
|
|
616
648
|
"""Start running the Waldiez flow in a non-blocking way.
|
|
617
649
|
|
|
@@ -627,12 +659,20 @@ class WaldiezBaseRunner(WaldiezRunnerProtocol):
|
|
|
627
659
|
Whether to skip generating the mermaid diagram, by default False.
|
|
628
660
|
skip_timeline : bool
|
|
629
661
|
Whether to skip generating the timeline JSON, by default False.
|
|
662
|
+
dot_env : str | Path | None
|
|
663
|
+
The path to the .env file, if any.
|
|
664
|
+
**kwargs : Any
|
|
665
|
+
Additional keyword arguments for the start method.
|
|
630
666
|
|
|
631
667
|
Raises
|
|
632
668
|
------
|
|
633
669
|
RuntimeError
|
|
634
670
|
If the runner is already running.
|
|
635
671
|
"""
|
|
672
|
+
if dot_env is not None:
|
|
673
|
+
resolved = Path(dot_env).resolve()
|
|
674
|
+
if resolved.is_file():
|
|
675
|
+
WaldiezBaseRunner._dot_env_path = resolved
|
|
636
676
|
if structured_io is not None:
|
|
637
677
|
WaldiezBaseRunner._structured_io = structured_io
|
|
638
678
|
if self.is_running():
|
|
@@ -656,6 +696,7 @@ class WaldiezBaseRunner(WaldiezRunnerProtocol):
|
|
|
656
696
|
skip_timeline=skip_timeline,
|
|
657
697
|
)
|
|
658
698
|
|
|
699
|
+
# noinspection DuplicatedCode
|
|
659
700
|
async def a_start(
|
|
660
701
|
self,
|
|
661
702
|
output_path: str | Path | None,
|
|
@@ -663,6 +704,8 @@ class WaldiezBaseRunner(WaldiezRunnerProtocol):
|
|
|
663
704
|
structured_io: bool | None = None,
|
|
664
705
|
skip_mmd: bool = False,
|
|
665
706
|
skip_timeline: bool = False,
|
|
707
|
+
dot_env: str | Path | None = None,
|
|
708
|
+
**kwargs: Any,
|
|
666
709
|
) -> None:
|
|
667
710
|
"""Asynchronously start running the Waldiez flow in a non-blocking way.
|
|
668
711
|
|
|
@@ -678,12 +721,20 @@ class WaldiezBaseRunner(WaldiezRunnerProtocol):
|
|
|
678
721
|
Whether to skip generating the mermaid diagram, by default False.
|
|
679
722
|
skip_timeline : bool = False
|
|
680
723
|
Whether to skip generating the timeline JSON, by default False.
|
|
724
|
+
dot_env : str | Path | None = None
|
|
725
|
+
The path to the .env file, if any.
|
|
726
|
+
**kwargs : Any
|
|
727
|
+
Additional keyword arguments for the start method.
|
|
681
728
|
|
|
682
729
|
Raises
|
|
683
730
|
------
|
|
684
731
|
RuntimeError
|
|
685
732
|
If the runner is already running.
|
|
686
733
|
"""
|
|
734
|
+
if dot_env is not None:
|
|
735
|
+
resolved = Path(dot_env).resolve()
|
|
736
|
+
if resolved.is_file():
|
|
737
|
+
WaldiezBaseRunner._dot_env_path = resolved
|
|
687
738
|
if structured_io is not None:
|
|
688
739
|
WaldiezBaseRunner._structured_io = structured_io
|
|
689
740
|
if self.is_running():
|
|
@@ -709,9 +760,7 @@ class WaldiezBaseRunner(WaldiezRunnerProtocol):
|
|
|
709
760
|
|
|
710
761
|
def after_run(
|
|
711
762
|
self,
|
|
712
|
-
results:
|
|
713
|
-
list["RunResponseProtocol"], list["AsyncRunResponseProtocol"]
|
|
714
|
-
],
|
|
763
|
+
results: list[dict[str, Any]],
|
|
715
764
|
output_file: Path,
|
|
716
765
|
uploads_root: Path | None,
|
|
717
766
|
temp_dir: Path,
|
|
@@ -722,7 +771,7 @@ class WaldiezBaseRunner(WaldiezRunnerProtocol):
|
|
|
722
771
|
|
|
723
772
|
Parameters
|
|
724
773
|
----------
|
|
725
|
-
results :
|
|
774
|
+
results : list[dict[str, Any]]
|
|
726
775
|
The results of the flow run.
|
|
727
776
|
output_file : Path
|
|
728
777
|
The path to the output file.
|
|
@@ -746,9 +795,7 @@ class WaldiezBaseRunner(WaldiezRunnerProtocol):
|
|
|
746
795
|
|
|
747
796
|
async def a_after_run(
|
|
748
797
|
self,
|
|
749
|
-
results:
|
|
750
|
-
list["RunResponseProtocol"], list["AsyncRunResponseProtocol"]
|
|
751
|
-
],
|
|
798
|
+
results: list[dict[str, Any]],
|
|
752
799
|
output_file: Path,
|
|
753
800
|
uploads_root: Path | None,
|
|
754
801
|
temp_dir: Path,
|
|
@@ -759,7 +806,7 @@ class WaldiezBaseRunner(WaldiezRunnerProtocol):
|
|
|
759
806
|
|
|
760
807
|
Parameters
|
|
761
808
|
----------
|
|
762
|
-
results :
|
|
809
|
+
results : list[dict[str, Any]]
|
|
763
810
|
The results of the flow run.
|
|
764
811
|
output_file : Path
|
|
765
812
|
The path to the output file.
|
|
@@ -828,6 +875,11 @@ class WaldiezBaseRunner(WaldiezRunnerProtocol):
|
|
|
828
875
|
"""Check if the runner is using structured IO."""
|
|
829
876
|
return WaldiezBaseRunner._structured_io
|
|
830
877
|
|
|
878
|
+
@property
|
|
879
|
+
def dot_env_path(self) -> str | Path | None:
|
|
880
|
+
"""Get the path to the .env file, if any."""
|
|
881
|
+
return WaldiezBaseRunner._dot_env_path
|
|
882
|
+
|
|
831
883
|
@property
|
|
832
884
|
def output_path(self) -> str | Path | None:
|
|
833
885
|
"""Get the output path for the runner."""
|
|
@@ -854,6 +906,7 @@ class WaldiezBaseRunner(WaldiezRunnerProtocol):
|
|
|
854
906
|
output_path: str | Path | None = None,
|
|
855
907
|
uploads_root: str | Path | None = None,
|
|
856
908
|
structured_io: bool = False,
|
|
909
|
+
dot_env: str | Path | None = None,
|
|
857
910
|
) -> "WaldiezBaseRunner":
|
|
858
911
|
"""Load a waldiez flow from a file and create a runner.
|
|
859
912
|
|
|
@@ -876,6 +929,8 @@ class WaldiezBaseRunner(WaldiezRunnerProtocol):
|
|
|
876
929
|
structured_io : bool, optional
|
|
877
930
|
Whether to use structured IO instead of the default 'input/print',
|
|
878
931
|
by default False.
|
|
932
|
+
dot_env : str | Path | None, optional
|
|
933
|
+
The path to the .env file, if any, by default None.
|
|
879
934
|
|
|
880
935
|
Returns
|
|
881
936
|
-------
|
|
@@ -894,6 +949,7 @@ class WaldiezBaseRunner(WaldiezRunnerProtocol):
|
|
|
894
949
|
output_path=output_path,
|
|
895
950
|
uploads_root=uploads_root,
|
|
896
951
|
structured_io=structured_io,
|
|
952
|
+
dot_env=dot_env,
|
|
897
953
|
)
|
|
898
954
|
|
|
899
955
|
def __enter__(self) -> Self:
|
waldiez/running/environment.py
CHANGED
|
@@ -135,6 +135,7 @@ def reload_autogen() -> None: # noqa: C901 # pragma: no cover
|
|
|
135
135
|
|
|
136
136
|
except Exception as e:
|
|
137
137
|
# If reload fails, at least try to re-import autogen
|
|
138
|
+
# noinspection PyBroadException
|
|
138
139
|
try:
|
|
139
140
|
import autogen # type: ignore # noqa: F401
|
|
140
141
|
|
|
@@ -174,6 +175,7 @@ def reload_chroma_if_needed() -> None: # pragma: no cover
|
|
|
174
175
|
return
|
|
175
176
|
|
|
176
177
|
|
|
178
|
+
# noinspection DuplicatedCode
|
|
177
179
|
def try_handle_the_np_thing() -> None:
|
|
178
180
|
"""Try to handle the numpy deprecation warning."""
|
|
179
181
|
# we might get:
|
|
@@ -95,6 +95,7 @@ def get_printer() -> Callable[..., None]: # noqa: C901
|
|
|
95
95
|
The printer function that handles Unicode encoding errors gracefully.
|
|
96
96
|
"""
|
|
97
97
|
try:
|
|
98
|
+
# noinspection PyUnresolvedReferences
|
|
98
99
|
from autogen.io import IOStream # pyright: ignore
|
|
99
100
|
|
|
100
101
|
printer = IOStream.get_default().print
|
|
@@ -102,6 +103,7 @@ def get_printer() -> Callable[..., None]: # noqa: C901
|
|
|
102
103
|
# Fallback to standard print if autogen is not available
|
|
103
104
|
printer = print
|
|
104
105
|
|
|
106
|
+
# noinspection PyBroadException
|
|
105
107
|
def safe_printer(*args: Any, **kwargs: Any) -> None: # noqa: C901
|
|
106
108
|
"""Safe printer that handles Unicode encoding errors.
|
|
107
109
|
|
waldiez/running/post_run.py
CHANGED
|
@@ -15,6 +15,7 @@ from .patch_io_stream import get_printer
|
|
|
15
15
|
from .timeline_processor import TimelineProcessor
|
|
16
16
|
|
|
17
17
|
|
|
18
|
+
# noinspection PyUnusedLocal
|
|
18
19
|
def after_run(
|
|
19
20
|
temp_dir: Path,
|
|
20
21
|
output_file: Optional[Union[str, Path]],
|
|
@@ -71,6 +72,7 @@ def after_run(
|
|
|
71
72
|
shutil.rmtree(temp_dir)
|
|
72
73
|
|
|
73
74
|
|
|
75
|
+
# noinspection PyBroadException
|
|
74
76
|
def _make_mermaid_diagram(
|
|
75
77
|
temp_dir: Path,
|
|
76
78
|
output_file: Optional[Union[str, Path]],
|
|
@@ -93,6 +95,7 @@ def _make_mermaid_diagram(
|
|
|
93
95
|
pass
|
|
94
96
|
|
|
95
97
|
|
|
98
|
+
# noinspection PyBroadException
|
|
96
99
|
def _make_timeline_json(
|
|
97
100
|
temp_dir: Path,
|
|
98
101
|
) -> None:
|