waldiez 0.5.7__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 +16 -1
- waldiez/exporting/chats/utils/common.py +45 -1
- waldiez/exporting/chats/utils/group.py +1 -1
- waldiez/exporting/flow/execution_generator.py +54 -32
- waldiez/exporting/flow/utils/common.py +4 -11
- waldiez/exporting/flow/utils/importing.py +2 -1
- waldiez/exporting/models/exporter.py +2 -1
- waldiez/exporting/tools/exporter.py +2 -1
- waldiez/exporting/tools/processor.py +6 -1
- waldiez/models/model/model.py +2 -2
- waldiez/models/tool/predefined/_google.py +4 -11
- waldiez/models/tool/predefined/_perplexity.py +9 -8
- waldiez/models/tool/predefined/_tavily.py +0 -6
- waldiez/models/tool/predefined/_youtube.py +0 -4
- waldiez/runner.py +17 -13
- waldiez/running/base_runner.py +89 -38
- waldiez/running/protocol.py +50 -48
- waldiez/running/run_results.py +2 -10
- waldiez/running/standard_runner.py +10 -10
- {waldiez-0.5.7.dist-info → waldiez-0.5.8.dist-info}/METADATA +14 -13
- {waldiez-0.5.7.dist-info → waldiez-0.5.8.dist-info}/RECORD +26 -26
- {waldiez-0.5.7.dist-info → waldiez-0.5.8.dist-info}/WHEEL +0 -0
- {waldiez-0.5.7.dist-info → waldiez-0.5.8.dist-info}/entry_points.txt +0 -0
- {waldiez-0.5.7.dist-info → waldiez-0.5.8.dist-info}/licenses/LICENSE +0 -0
- {waldiez-0.5.7.dist-info → waldiez-0.5.8.dist-info}/licenses/NOTICE.md +0 -0
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(
|
|
@@ -213,7 +230,7 @@ class WaldiezBaseRunner(WaldiezRunnerProtocol):
|
|
|
213
230
|
skip_mmd: bool,
|
|
214
231
|
skip_timeline: bool,
|
|
215
232
|
**kwargs: Any,
|
|
216
|
-
) ->
|
|
233
|
+
) -> list[dict[str, Any]]:
|
|
217
234
|
"""Run the Waldiez flow."""
|
|
218
235
|
raise NotImplementedError(
|
|
219
236
|
"The _run method must be implemented in the subclass."
|
|
@@ -227,7 +244,7 @@ class WaldiezBaseRunner(WaldiezRunnerProtocol):
|
|
|
227
244
|
skip_mmd: bool,
|
|
228
245
|
skip_timeline: bool,
|
|
229
246
|
**kwargs: Any,
|
|
230
|
-
) ->
|
|
247
|
+
) -> list[dict[str, Any]]:
|
|
231
248
|
"""Run the Waldiez flow asynchronously."""
|
|
232
249
|
raise NotImplementedError(
|
|
233
250
|
"The _a_run method must be implemented in the subclass."
|
|
@@ -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,8 +459,9 @@ class WaldiezBaseRunner(WaldiezRunnerProtocol):
|
|
|
444
459
|
structured_io: bool | None = None,
|
|
445
460
|
skip_mmd: bool = False,
|
|
446
461
|
skip_timeline: bool = False,
|
|
462
|
+
dot_env: str | Path | None = None,
|
|
447
463
|
**kwargs: Any,
|
|
448
|
-
) ->
|
|
464
|
+
) -> list[dict[str, Any]]:
|
|
449
465
|
"""Run the Waldiez flow in blocking mode.
|
|
450
466
|
|
|
451
467
|
Parameters
|
|
@@ -461,20 +477,25 @@ class WaldiezBaseRunner(WaldiezRunnerProtocol):
|
|
|
461
477
|
Whether to skip generating the mermaid diagram, by default False.
|
|
462
478
|
skip_timeline : bool
|
|
463
479
|
Whether to skip generating the timeline JSON.
|
|
480
|
+
dot_env : str | Path | None
|
|
481
|
+
The path to the .env file, if any.
|
|
464
482
|
**kwargs : Any
|
|
465
483
|
Additional keyword arguments for the run method.
|
|
466
484
|
|
|
467
485
|
Returns
|
|
468
486
|
-------
|
|
469
|
-
|
|
470
|
-
The result of the run
|
|
471
|
-
or a list of AsyncRunResponseProtocol.
|
|
487
|
+
list[dict[str, Any]]
|
|
488
|
+
The result of the run.
|
|
472
489
|
|
|
473
490
|
Raises
|
|
474
491
|
------
|
|
475
492
|
RuntimeError
|
|
476
493
|
If the runner is already running.
|
|
477
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
|
|
478
499
|
if structured_io is not None:
|
|
479
500
|
WaldiezBaseRunner._structured_io = structured_io
|
|
480
501
|
if self.is_running():
|
|
@@ -499,9 +520,7 @@ class WaldiezBaseRunner(WaldiezRunnerProtocol):
|
|
|
499
520
|
self.install_requirements()
|
|
500
521
|
refresh_environment()
|
|
501
522
|
WaldiezBaseRunner._running = True
|
|
502
|
-
results:
|
|
503
|
-
list["RunResponseProtocol"], list["AsyncRunResponseProtocol"]
|
|
504
|
-
]
|
|
523
|
+
results: list[dict[str, Any]] = []
|
|
505
524
|
old_env_vars = set_env_vars(self.waldiez.get_flow_env_vars())
|
|
506
525
|
try:
|
|
507
526
|
with chdir(to=temp_dir):
|
|
@@ -537,7 +556,9 @@ class WaldiezBaseRunner(WaldiezRunnerProtocol):
|
|
|
537
556
|
structured_io: bool | None = None,
|
|
538
557
|
skip_mmd: bool = False,
|
|
539
558
|
skip_timeline: bool = False,
|
|
540
|
-
|
|
559
|
+
dot_env: str | Path | None = None,
|
|
560
|
+
**kwargs: Any,
|
|
561
|
+
) -> list[dict[str, Any]]:
|
|
541
562
|
"""Run the Waldiez flow asynchronously.
|
|
542
563
|
|
|
543
564
|
Parameters
|
|
@@ -553,18 +574,25 @@ class WaldiezBaseRunner(WaldiezRunnerProtocol):
|
|
|
553
574
|
Whether to skip generating the mermaid diagram, by default False.
|
|
554
575
|
skip_timeline : bool
|
|
555
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.
|
|
556
581
|
|
|
557
582
|
Returns
|
|
558
583
|
-------
|
|
559
|
-
|
|
560
|
-
The result of the run
|
|
561
|
-
or a list of AsyncRunResponseProtocol.
|
|
584
|
+
list[dict[str, Any]]
|
|
585
|
+
The result of the run.
|
|
562
586
|
|
|
563
587
|
Raises
|
|
564
588
|
------
|
|
565
589
|
RuntimeError
|
|
566
590
|
If the runner is already running.
|
|
567
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
|
|
568
596
|
if structured_io is not None:
|
|
569
597
|
WaldiezBaseRunner._structured_io = structured_io
|
|
570
598
|
if self.is_running():
|
|
@@ -580,9 +608,7 @@ class WaldiezBaseRunner(WaldiezRunnerProtocol):
|
|
|
580
608
|
await self.a_install_requirements()
|
|
581
609
|
refresh_environment()
|
|
582
610
|
WaldiezBaseRunner._running = True
|
|
583
|
-
results:
|
|
584
|
-
list["RunResponseProtocol"], list["AsyncRunResponseProtocol"]
|
|
585
|
-
]
|
|
611
|
+
results: list[dict[str, Any]] = []
|
|
586
612
|
old_env_vars = set_env_vars(self.waldiez.get_flow_env_vars())
|
|
587
613
|
try:
|
|
588
614
|
async with a_chdir(to=temp_dir):
|
|
@@ -616,6 +642,8 @@ class WaldiezBaseRunner(WaldiezRunnerProtocol):
|
|
|
616
642
|
structured_io: bool | None = None,
|
|
617
643
|
skip_mmd: bool = False,
|
|
618
644
|
skip_timeline: bool = False,
|
|
645
|
+
dot_env: str | Path | None = None,
|
|
646
|
+
**kwargs: Any,
|
|
619
647
|
) -> None:
|
|
620
648
|
"""Start running the Waldiez flow in a non-blocking way.
|
|
621
649
|
|
|
@@ -631,12 +659,20 @@ class WaldiezBaseRunner(WaldiezRunnerProtocol):
|
|
|
631
659
|
Whether to skip generating the mermaid diagram, by default False.
|
|
632
660
|
skip_timeline : bool
|
|
633
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.
|
|
634
666
|
|
|
635
667
|
Raises
|
|
636
668
|
------
|
|
637
669
|
RuntimeError
|
|
638
670
|
If the runner is already running.
|
|
639
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
|
|
640
676
|
if structured_io is not None:
|
|
641
677
|
WaldiezBaseRunner._structured_io = structured_io
|
|
642
678
|
if self.is_running():
|
|
@@ -668,6 +704,8 @@ class WaldiezBaseRunner(WaldiezRunnerProtocol):
|
|
|
668
704
|
structured_io: bool | None = None,
|
|
669
705
|
skip_mmd: bool = False,
|
|
670
706
|
skip_timeline: bool = False,
|
|
707
|
+
dot_env: str | Path | None = None,
|
|
708
|
+
**kwargs: Any,
|
|
671
709
|
) -> None:
|
|
672
710
|
"""Asynchronously start running the Waldiez flow in a non-blocking way.
|
|
673
711
|
|
|
@@ -683,12 +721,20 @@ class WaldiezBaseRunner(WaldiezRunnerProtocol):
|
|
|
683
721
|
Whether to skip generating the mermaid diagram, by default False.
|
|
684
722
|
skip_timeline : bool = False
|
|
685
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.
|
|
686
728
|
|
|
687
729
|
Raises
|
|
688
730
|
------
|
|
689
731
|
RuntimeError
|
|
690
732
|
If the runner is already running.
|
|
691
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
|
|
692
738
|
if structured_io is not None:
|
|
693
739
|
WaldiezBaseRunner._structured_io = structured_io
|
|
694
740
|
if self.is_running():
|
|
@@ -714,9 +760,7 @@ class WaldiezBaseRunner(WaldiezRunnerProtocol):
|
|
|
714
760
|
|
|
715
761
|
def after_run(
|
|
716
762
|
self,
|
|
717
|
-
results:
|
|
718
|
-
list["RunResponseProtocol"], list["AsyncRunResponseProtocol"]
|
|
719
|
-
],
|
|
763
|
+
results: list[dict[str, Any]],
|
|
720
764
|
output_file: Path,
|
|
721
765
|
uploads_root: Path | None,
|
|
722
766
|
temp_dir: Path,
|
|
@@ -727,7 +771,7 @@ class WaldiezBaseRunner(WaldiezRunnerProtocol):
|
|
|
727
771
|
|
|
728
772
|
Parameters
|
|
729
773
|
----------
|
|
730
|
-
results :
|
|
774
|
+
results : list[dict[str, Any]]
|
|
731
775
|
The results of the flow run.
|
|
732
776
|
output_file : Path
|
|
733
777
|
The path to the output file.
|
|
@@ -751,9 +795,7 @@ class WaldiezBaseRunner(WaldiezRunnerProtocol):
|
|
|
751
795
|
|
|
752
796
|
async def a_after_run(
|
|
753
797
|
self,
|
|
754
|
-
results:
|
|
755
|
-
list["RunResponseProtocol"], list["AsyncRunResponseProtocol"]
|
|
756
|
-
],
|
|
798
|
+
results: list[dict[str, Any]],
|
|
757
799
|
output_file: Path,
|
|
758
800
|
uploads_root: Path | None,
|
|
759
801
|
temp_dir: Path,
|
|
@@ -764,7 +806,7 @@ class WaldiezBaseRunner(WaldiezRunnerProtocol):
|
|
|
764
806
|
|
|
765
807
|
Parameters
|
|
766
808
|
----------
|
|
767
|
-
results :
|
|
809
|
+
results : list[dict[str, Any]]
|
|
768
810
|
The results of the flow run.
|
|
769
811
|
output_file : Path
|
|
770
812
|
The path to the output file.
|
|
@@ -833,6 +875,11 @@ class WaldiezBaseRunner(WaldiezRunnerProtocol):
|
|
|
833
875
|
"""Check if the runner is using structured IO."""
|
|
834
876
|
return WaldiezBaseRunner._structured_io
|
|
835
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
|
+
|
|
836
883
|
@property
|
|
837
884
|
def output_path(self) -> str | Path | None:
|
|
838
885
|
"""Get the output path for the runner."""
|
|
@@ -859,6 +906,7 @@ class WaldiezBaseRunner(WaldiezRunnerProtocol):
|
|
|
859
906
|
output_path: str | Path | None = None,
|
|
860
907
|
uploads_root: str | Path | None = None,
|
|
861
908
|
structured_io: bool = False,
|
|
909
|
+
dot_env: str | Path | None = None,
|
|
862
910
|
) -> "WaldiezBaseRunner":
|
|
863
911
|
"""Load a waldiez flow from a file and create a runner.
|
|
864
912
|
|
|
@@ -881,6 +929,8 @@ class WaldiezBaseRunner(WaldiezRunnerProtocol):
|
|
|
881
929
|
structured_io : bool, optional
|
|
882
930
|
Whether to use structured IO instead of the default 'input/print',
|
|
883
931
|
by default False.
|
|
932
|
+
dot_env : str | Path | None, optional
|
|
933
|
+
The path to the .env file, if any, by default None.
|
|
884
934
|
|
|
885
935
|
Returns
|
|
886
936
|
-------
|
|
@@ -899,6 +949,7 @@ class WaldiezBaseRunner(WaldiezRunnerProtocol):
|
|
|
899
949
|
output_path=output_path,
|
|
900
950
|
uploads_root=uploads_root,
|
|
901
951
|
structured_io=structured_io,
|
|
952
|
+
dot_env=dot_env,
|
|
902
953
|
)
|
|
903
954
|
|
|
904
955
|
def __enter__(self) -> Self:
|
waldiez/running/protocol.py
CHANGED
|
@@ -1,16 +1,10 @@
|
|
|
1
1
|
# SPDX-License-Identifier: Apache-2.0.
|
|
2
2
|
# Copyright (c) 2024 - 2025 Waldiez and contributors.
|
|
3
|
-
|
|
3
|
+
# pyright: reportReturnType=false
|
|
4
4
|
"""Waldiez Runner protocol."""
|
|
5
5
|
|
|
6
6
|
from pathlib import Path
|
|
7
|
-
from typing import
|
|
8
|
-
|
|
9
|
-
if TYPE_CHECKING:
|
|
10
|
-
from autogen.io.run_response import ( # type: ignore[import-untyped]
|
|
11
|
-
AsyncRunResponseProtocol,
|
|
12
|
-
RunResponseProtocol,
|
|
13
|
-
)
|
|
7
|
+
from typing import Any, Protocol, runtime_checkable
|
|
14
8
|
|
|
15
9
|
|
|
16
10
|
@runtime_checkable
|
|
@@ -63,6 +57,9 @@ class WaldiezRunnerProtocol(Protocol):
|
|
|
63
57
|
uploads_root: str | Path | None,
|
|
64
58
|
structured_io: bool | None = None,
|
|
65
59
|
skip_mmd: bool = False,
|
|
60
|
+
skip_timeline: bool = False,
|
|
61
|
+
dot_env: str | Path | None = None,
|
|
62
|
+
**kwargs: Any,
|
|
66
63
|
) -> None:
|
|
67
64
|
"""Start running the Waldiez flow in a non-blocking way.
|
|
68
65
|
|
|
@@ -78,6 +75,12 @@ class WaldiezRunnerProtocol(Protocol):
|
|
|
78
75
|
Whether to use structured IO instead of the default 'input/print'.
|
|
79
76
|
skip_mmd : bool
|
|
80
77
|
Whether to skip generating the mermaid diagram.
|
|
78
|
+
skip_timeline : bool
|
|
79
|
+
Whether to skip generating the timeline JSON.
|
|
80
|
+
dot_env : str | Path | None
|
|
81
|
+
The path to the .env file, if any.
|
|
82
|
+
**kwargs : Any
|
|
83
|
+
Additional keyword arguments for the start method.
|
|
81
84
|
|
|
82
85
|
Raises
|
|
83
86
|
------
|
|
@@ -91,6 +94,9 @@ class WaldiezRunnerProtocol(Protocol):
|
|
|
91
94
|
uploads_root: str | Path | None,
|
|
92
95
|
structured_io: bool | None = None,
|
|
93
96
|
skip_mmd: bool = False,
|
|
97
|
+
skip_timeline: bool = False,
|
|
98
|
+
dot_env: str | Path | None = None,
|
|
99
|
+
**kwargs: Any,
|
|
94
100
|
) -> None:
|
|
95
101
|
"""Asynchronously start running the Waldiez flow in a non-blocking way.
|
|
96
102
|
|
|
@@ -106,6 +112,12 @@ class WaldiezRunnerProtocol(Protocol):
|
|
|
106
112
|
Whether to use structured IO instead of the default 'input/print'.
|
|
107
113
|
skip_mmd : bool
|
|
108
114
|
Whether to skip generating the mermaid diagram.
|
|
115
|
+
skip_timeline : bool
|
|
116
|
+
Whether to skip generating the timeline JSON.
|
|
117
|
+
dot_env : str | Path | None
|
|
118
|
+
The path to the .env file, if any.
|
|
119
|
+
**kwargs : Any
|
|
120
|
+
Additional keyword arguments for the start method.
|
|
109
121
|
|
|
110
122
|
Raises
|
|
111
123
|
------
|
|
@@ -119,10 +131,10 @@ class WaldiezRunnerProtocol(Protocol):
|
|
|
119
131
|
uploads_root: str | Path | None,
|
|
120
132
|
structured_io: bool | None = None,
|
|
121
133
|
skip_mmd: bool = False,
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
]:
|
|
134
|
+
skip_timeline: bool = False,
|
|
135
|
+
dot_env: str | Path | None = None,
|
|
136
|
+
**kwargs: Any,
|
|
137
|
+
) -> list[dict[str, Any]]:
|
|
126
138
|
"""Run the Waldiez flow in a blocking way.
|
|
127
139
|
|
|
128
140
|
Parameters
|
|
@@ -135,15 +147,17 @@ class WaldiezRunnerProtocol(Protocol):
|
|
|
135
147
|
Whether to use structured IO instead of the default 'input/print'.
|
|
136
148
|
skip_mmd : bool
|
|
137
149
|
Whether to skip generating the mermaid diagram.
|
|
150
|
+
skip_timeline : bool
|
|
151
|
+
Whether to skip generating the timeline JSON.
|
|
152
|
+
dot_env : str | Path | None
|
|
153
|
+
The path to the .env file, if any.
|
|
154
|
+
**kwargs : Any
|
|
155
|
+
Additional keyword arguments for the run method.
|
|
138
156
|
|
|
139
157
|
Returns
|
|
140
158
|
-------
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
list["AsyncRunResponseProtocol"],
|
|
144
|
-
]
|
|
145
|
-
The result of the run, which can be a list of RunResponseProtocol
|
|
146
|
-
or a list of AsyncRunResponseProtocol.
|
|
159
|
+
list[dict[str, Any]]
|
|
160
|
+
The result of the run.
|
|
147
161
|
"""
|
|
148
162
|
|
|
149
163
|
async def a_run(
|
|
@@ -152,10 +166,10 @@ class WaldiezRunnerProtocol(Protocol):
|
|
|
152
166
|
uploads_root: str | Path | None,
|
|
153
167
|
structured_io: bool | None = None,
|
|
154
168
|
skip_mmd: bool = False,
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
]:
|
|
169
|
+
skip_timeline: bool = False,
|
|
170
|
+
dot_env: str | Path | None = None,
|
|
171
|
+
**kwargs: Any,
|
|
172
|
+
) -> list[dict[str, Any]]:
|
|
159
173
|
"""Run the Waldiez flow.
|
|
160
174
|
|
|
161
175
|
Parameters
|
|
@@ -168,23 +182,22 @@ class WaldiezRunnerProtocol(Protocol):
|
|
|
168
182
|
Whether to use structured IO instead of the default 'input/print'.
|
|
169
183
|
skip_mmd : bool
|
|
170
184
|
Whether to skip generating the mermaid diagram.
|
|
185
|
+
skip_timeline : bool
|
|
186
|
+
Whether to skip generating the timeline JSON.
|
|
187
|
+
dot_env : str | Path | None
|
|
188
|
+
The path to the .env file, if any.
|
|
189
|
+
**kwargs : Any
|
|
190
|
+
Additional keyword arguments for the a_run method.
|
|
171
191
|
|
|
172
192
|
Returns
|
|
173
193
|
-------
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
list["AsyncRunResponseProtocol"],
|
|
177
|
-
]
|
|
178
|
-
The result of the run, which can be a list of RunResponseProtocol
|
|
179
|
-
or a list of AsyncRunResponseProtocol.
|
|
194
|
+
list[dict[str, Any]]
|
|
195
|
+
The result of the run.
|
|
180
196
|
"""
|
|
181
197
|
|
|
182
198
|
def after_run(
|
|
183
199
|
self,
|
|
184
|
-
results:
|
|
185
|
-
list["RunResponseProtocol"],
|
|
186
|
-
list["AsyncRunResponseProtocol"],
|
|
187
|
-
],
|
|
200
|
+
results: list[dict[str, Any]],
|
|
188
201
|
output_file: Path,
|
|
189
202
|
uploads_root: Path | None,
|
|
190
203
|
temp_dir: Path,
|
|
@@ -195,12 +208,8 @@ class WaldiezRunnerProtocol(Protocol):
|
|
|
195
208
|
|
|
196
209
|
Parameters
|
|
197
210
|
----------
|
|
198
|
-
results :
|
|
199
|
-
|
|
200
|
-
list["AsyncRunResponseProtocol"],
|
|
201
|
-
]
|
|
202
|
-
The results of the run, which can be a list of RunResponseProtocol
|
|
203
|
-
or a list of AsyncRunResponseProtocol.
|
|
211
|
+
results : list[dict[str, Any]]
|
|
212
|
+
The results of the run.
|
|
204
213
|
output_file : Path
|
|
205
214
|
The path to the output file.
|
|
206
215
|
uploads_root : Path | None
|
|
@@ -215,10 +224,7 @@ class WaldiezRunnerProtocol(Protocol):
|
|
|
215
224
|
|
|
216
225
|
async def a_after_run(
|
|
217
226
|
self,
|
|
218
|
-
results:
|
|
219
|
-
list["RunResponseProtocol"],
|
|
220
|
-
list["AsyncRunResponseProtocol"],
|
|
221
|
-
],
|
|
227
|
+
results: list[dict[str, Any]],
|
|
222
228
|
output_file: Path,
|
|
223
229
|
uploads_root: Path | None,
|
|
224
230
|
temp_dir: Path,
|
|
@@ -229,12 +235,8 @@ class WaldiezRunnerProtocol(Protocol):
|
|
|
229
235
|
|
|
230
236
|
Parameters
|
|
231
237
|
----------
|
|
232
|
-
results :
|
|
233
|
-
|
|
234
|
-
list["AsyncRunResponseProtocol"]
|
|
235
|
-
]
|
|
236
|
-
The results of the run, which can be a list of RunResponseProtocol
|
|
237
|
-
or a list of AsyncRunResponseProtocol.
|
|
238
|
+
results : list[dict[str, Any]]
|
|
239
|
+
The results of the run.
|
|
238
240
|
output_file : Path
|
|
239
241
|
The path to the output file.
|
|
240
242
|
uploads_root : Path | None
|
waldiez/running/run_results.py
CHANGED
|
@@ -3,20 +3,12 @@
|
|
|
3
3
|
|
|
4
4
|
"""Waldiez run results module."""
|
|
5
5
|
|
|
6
|
-
from typing import
|
|
7
|
-
|
|
8
|
-
if TYPE_CHECKING:
|
|
9
|
-
from autogen.io.run_response import ( # type: ignore[import-untyped]
|
|
10
|
-
AsyncRunResponseProtocol,
|
|
11
|
-
RunResponseProtocol,
|
|
12
|
-
)
|
|
6
|
+
from typing import Any, TypedDict
|
|
13
7
|
|
|
14
8
|
|
|
15
9
|
class WaldiezRunResults(TypedDict):
|
|
16
10
|
"""Results of the Waldiez run."""
|
|
17
11
|
|
|
18
|
-
results:
|
|
19
|
-
list["RunResponseProtocol"], list["AsyncRunResponseProtocol"]
|
|
20
|
-
]
|
|
12
|
+
results: list[dict[str, Any]]
|
|
21
13
|
exception: Exception | None
|
|
22
14
|
completed: bool
|
|
@@ -32,10 +32,6 @@ from .utils import chdir
|
|
|
32
32
|
|
|
33
33
|
if TYPE_CHECKING:
|
|
34
34
|
from autogen.events import BaseEvent # type: ignore
|
|
35
|
-
from autogen.io.run_response import ( # type: ignore
|
|
36
|
-
AsyncRunResponseProtocol,
|
|
37
|
-
RunResponseProtocol,
|
|
38
|
-
)
|
|
39
35
|
from autogen.messages import BaseMessage # type: ignore
|
|
40
36
|
|
|
41
37
|
|
|
@@ -48,6 +44,8 @@ class WaldiezStandardRunner(WaldiezBaseRunner):
|
|
|
48
44
|
output_path: str | Path | None = None,
|
|
49
45
|
uploads_root: str | Path | None = None,
|
|
50
46
|
structured_io: bool = False,
|
|
47
|
+
dot_env: str | Path | None = None,
|
|
48
|
+
**kwargs: Any,
|
|
51
49
|
) -> None:
|
|
52
50
|
"""Initialize the Waldiez manager."""
|
|
53
51
|
super().__init__(
|
|
@@ -55,6 +53,8 @@ class WaldiezStandardRunner(WaldiezBaseRunner):
|
|
|
55
53
|
output_path=output_path,
|
|
56
54
|
uploads_root=uploads_root,
|
|
57
55
|
structured_io=structured_io,
|
|
56
|
+
dot_env=dot_env,
|
|
57
|
+
**kwargs,
|
|
58
58
|
)
|
|
59
59
|
self._execution_thread: threading.Thread | None = None
|
|
60
60
|
self._loaded_module: ModuleType | None = None
|
|
@@ -107,7 +107,7 @@ class WaldiezStandardRunner(WaldiezBaseRunner):
|
|
|
107
107
|
skip_mmd: bool,
|
|
108
108
|
skip_timeline: bool,
|
|
109
109
|
**kwargs: Any,
|
|
110
|
-
) ->
|
|
110
|
+
) -> list[dict[str, Any]]:
|
|
111
111
|
"""Run the Waldiez workflow."""
|
|
112
112
|
from autogen.io import IOStream # type: ignore
|
|
113
113
|
|
|
@@ -185,7 +185,7 @@ class WaldiezStandardRunner(WaldiezBaseRunner):
|
|
|
185
185
|
)
|
|
186
186
|
event.content.respond(user_input)
|
|
187
187
|
else:
|
|
188
|
-
self._send(event)
|
|
188
|
+
self._send(event) # pyright: ignore
|
|
189
189
|
self._processed_events += 1
|
|
190
190
|
except Exception as e:
|
|
191
191
|
raise RuntimeError(
|
|
@@ -301,7 +301,7 @@ class WaldiezStandardRunner(WaldiezBaseRunner):
|
|
|
301
301
|
user_input = await user_input
|
|
302
302
|
await event.content.respond(user_input)
|
|
303
303
|
else:
|
|
304
|
-
self._send(event)
|
|
304
|
+
self._send(event) # pyright: ignore
|
|
305
305
|
self._processed_events += 1
|
|
306
306
|
except Exception as e:
|
|
307
307
|
raise RuntimeError(
|
|
@@ -317,18 +317,18 @@ class WaldiezStandardRunner(WaldiezBaseRunner):
|
|
|
317
317
|
skip_mmd: bool = False,
|
|
318
318
|
skip_timeline: bool = False,
|
|
319
319
|
**kwargs: Any,
|
|
320
|
-
) ->
|
|
320
|
+
) -> list[dict[str, Any]]:
|
|
321
321
|
"""Run the Waldiez workflow asynchronously."""
|
|
322
322
|
|
|
323
323
|
# fmt: off
|
|
324
|
-
async def _execute_workflow() ->
|
|
324
|
+
async def _execute_workflow() -> list[dict[str, Any]]:
|
|
325
325
|
# fmt: on
|
|
326
326
|
"""Execute the workflow in an async context."""
|
|
327
327
|
from autogen.io import IOStream # pyright: ignore
|
|
328
328
|
|
|
329
329
|
from waldiez.io import StructuredIOStream
|
|
330
330
|
|
|
331
|
-
results:
|
|
331
|
+
results: list[dict[str, Any]] = []
|
|
332
332
|
try:
|
|
333
333
|
self._loaded_module = self._load_module(output_file, temp_dir)
|
|
334
334
|
if self._stop_requested.is_set():
|