waldiez 0.5.8__py3-none-any.whl → 0.5.10__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.

Files changed (88) hide show
  1. waldiez/_version.py +1 -1
  2. waldiez/cli.py +112 -24
  3. waldiez/exporting/agent/exporter.py +3 -0
  4. waldiez/exporting/agent/extras/captain_agent_extras.py +44 -7
  5. waldiez/exporting/agent/extras/handoffs/condition.py +3 -1
  6. waldiez/exporting/chats/utils/common.py +25 -23
  7. waldiez/exporting/core/__init__.py +0 -2
  8. waldiez/exporting/core/context.py +13 -13
  9. waldiez/exporting/core/protocols.py +0 -141
  10. waldiez/exporting/core/result.py +5 -5
  11. waldiez/exporting/flow/merger.py +2 -2
  12. waldiez/exporting/flow/orchestrator.py +1 -0
  13. waldiez/exporting/flow/utils/common.py +2 -2
  14. waldiez/exporting/flow/utils/importing.py +1 -0
  15. waldiez/exporting/flow/utils/logging.py +6 -7
  16. waldiez/exporting/tools/exporter.py +5 -0
  17. waldiez/exporting/tools/factory.py +4 -0
  18. waldiez/exporting/tools/processor.py +5 -1
  19. waldiez/io/_ws.py +13 -5
  20. waldiez/io/models/content/image.py +1 -0
  21. waldiez/io/models/user_input.py +4 -4
  22. waldiez/io/models/user_response.py +1 -0
  23. waldiez/io/mqtt.py +1 -1
  24. waldiez/io/structured.py +17 -17
  25. waldiez/io/utils.py +1 -1
  26. waldiez/io/ws.py +9 -11
  27. waldiez/logger.py +180 -63
  28. waldiez/models/agents/agent/update_system_message.py +0 -2
  29. waldiez/models/agents/doc_agent/doc_agent.py +8 -1
  30. waldiez/models/common/dict_utils.py +169 -40
  31. waldiez/models/flow/flow.py +6 -6
  32. waldiez/models/flow/info.py +5 -1
  33. waldiez/models/model/_llm.py +28 -14
  34. waldiez/models/model/model.py +4 -1
  35. waldiez/models/model/model_data.py +18 -5
  36. waldiez/models/tool/predefined/_config.py +5 -1
  37. waldiez/models/tool/predefined/_duckduckgo.py +4 -0
  38. waldiez/models/tool/predefined/_email.py +474 -0
  39. waldiez/models/tool/predefined/_google.py +8 -6
  40. waldiez/models/tool/predefined/_perplexity.py +3 -0
  41. waldiez/models/tool/predefined/_searxng.py +3 -0
  42. waldiez/models/tool/predefined/_tavily.py +4 -1
  43. waldiez/models/tool/predefined/_wikipedia.py +4 -1
  44. waldiez/models/tool/predefined/_youtube.py +4 -1
  45. waldiez/models/tool/predefined/protocol.py +3 -0
  46. waldiez/models/tool/tool.py +22 -4
  47. waldiez/models/waldiez.py +12 -0
  48. waldiez/runner.py +37 -54
  49. waldiez/running/__init__.py +6 -0
  50. waldiez/running/base_runner.py +310 -353
  51. waldiez/running/environment.py +1 -0
  52. waldiez/running/exceptions.py +9 -0
  53. waldiez/running/post_run.py +4 -4
  54. waldiez/running/pre_run.py +51 -40
  55. waldiez/running/protocol.py +21 -101
  56. waldiez/running/run_results.py +1 -1
  57. waldiez/running/standard_runner.py +84 -277
  58. waldiez/running/step_by_step/__init__.py +46 -0
  59. waldiez/running/step_by_step/breakpoints_mixin.py +188 -0
  60. waldiez/running/step_by_step/step_by_step_models.py +224 -0
  61. waldiez/running/step_by_step/step_by_step_runner.py +745 -0
  62. waldiez/running/subprocess_runner/__base__.py +282 -0
  63. waldiez/running/subprocess_runner/__init__.py +16 -0
  64. waldiez/running/subprocess_runner/_async_runner.py +362 -0
  65. waldiez/running/subprocess_runner/_sync_runner.py +455 -0
  66. waldiez/running/subprocess_runner/runner.py +561 -0
  67. waldiez/running/timeline_processor.py +1 -1
  68. waldiez/running/utils.py +376 -1
  69. waldiez/utils/version.py +2 -6
  70. waldiez/ws/__init__.py +70 -0
  71. waldiez/ws/__main__.py +15 -0
  72. waldiez/ws/_file_handler.py +201 -0
  73. waldiez/ws/cli.py +211 -0
  74. waldiez/ws/client_manager.py +835 -0
  75. waldiez/ws/errors.py +416 -0
  76. waldiez/ws/models.py +971 -0
  77. waldiez/ws/reloader.py +342 -0
  78. waldiez/ws/server.py +469 -0
  79. waldiez/ws/session_manager.py +393 -0
  80. waldiez/ws/session_stats.py +83 -0
  81. waldiez/ws/utils.py +385 -0
  82. {waldiez-0.5.8.dist-info → waldiez-0.5.10.dist-info}/METADATA +74 -74
  83. {waldiez-0.5.8.dist-info → waldiez-0.5.10.dist-info}/RECORD +87 -65
  84. waldiez/running/patch_io_stream.py +0 -210
  85. {waldiez-0.5.8.dist-info → waldiez-0.5.10.dist-info}/WHEEL +0 -0
  86. {waldiez-0.5.8.dist-info → waldiez-0.5.10.dist-info}/entry_points.txt +0 -0
  87. {waldiez-0.5.8.dist-info → waldiez-0.5.10.dist-info}/licenses/LICENSE +0 -0
  88. {waldiez-0.5.8.dist-info → waldiez-0.5.10.dist-info}/licenses/NOTICE.md +0 -0
@@ -215,24 +215,39 @@ class WaldiezTool(WaldiezBase):
215
215
  """Get the secrets (environment variables) of the tool."""
216
216
  return self.data.secrets or {}
217
217
 
218
- def get_content(self) -> str:
218
+ def get_content(self, runtime_kwargs: dict[str, Any] | None = None) -> str:
219
219
  """Get the content of the tool.
220
220
 
221
+ Parameters
222
+ ----------
223
+ runtime_kwargs : dict[str, Any] | None, optional
224
+ Runtime keyword arguments to customize the content generation.
225
+
221
226
  Returns
222
227
  -------
223
228
  str
224
229
  The content of the tool.
225
230
  """
226
231
  if self.is_predefined:
227
- return self._generate_predefined_content()
232
+ return self._generate_predefined_content(
233
+ runtime_kwargs=runtime_kwargs
234
+ )
228
235
  if self.is_shared or self.is_interop:
229
236
  return self.data.content
230
237
  # if custom, only the function content
231
238
  return get_function(self.data.content, self.name)
232
239
 
233
- def _generate_predefined_content(self) -> str:
240
+ def _generate_predefined_content(
241
+ self,
242
+ runtime_kwargs: dict[str, Any] | None = None,
243
+ ) -> str:
234
244
  """Generate the content for a predefined tool.
235
245
 
246
+ Parameters
247
+ ----------
248
+ runtime_kwargs : dict[str, Any] | None, optional
249
+ Runtime keyword arguments to customize the content generation.
250
+
236
251
  Returns
237
252
  -------
238
253
  str
@@ -241,7 +256,10 @@ class WaldiezTool(WaldiezBase):
241
256
  config = get_predefined_tool_config(self.name)
242
257
  if not config:
243
258
  return ""
244
- return config.get_content(self.data.secrets)
259
+ return config.get_content(
260
+ self.data.secrets,
261
+ runtime_kwargs=runtime_kwargs,
262
+ )
245
263
 
246
264
  def _validate_interop_tool(self) -> None:
247
265
  """Validate the interoperability tool.
waldiez/models/waldiez.py CHANGED
@@ -39,6 +39,18 @@ class Waldiez:
39
39
 
40
40
  flow: WaldiezFlow
41
41
 
42
+ @classmethod
43
+ def default(cls) -> "Waldiez":
44
+ """Create a default Waldiez instance.
45
+
46
+ Returns
47
+ -------
48
+ Waldiez
49
+ The default Waldiez instance.
50
+ """
51
+ flow = WaldiezFlow.default()
52
+ return cls(flow=flow)
53
+
42
54
  @classmethod
43
55
  def from_dict(
44
56
  cls,
waldiez/runner.py CHANGED
@@ -5,12 +5,16 @@
5
5
  # pylint: disable=too-many-positional-arguments
6
6
  """Run a waldiez flow.
7
7
 
8
- The flow is first converted to an autogen flow with agents, chats, and tools.
9
- We then chown to temporary directory and:
10
- either import and call the flow's `main()` (if not isolated),
11
- or run the flow in a subprocess (if isolated).
12
- Before running the flow, any additional environment
13
- variables specified in the waldiez file are set.
8
+ The flow is first converted to an ag2 flow with agents, chats, and tools.
9
+ We then chown to temporary directory,
10
+ import and call the flow's `main(on_event)` method.
11
+ The `on_event` method is called with the event emitter,
12
+ which emits events during the flow execution.
13
+ The flow is run in a temporary directory,
14
+ and the results are saved to the output file's directory.
15
+ The uploads root directory is used to store any uploaded files
16
+ during the flow execution.
17
+
14
18
  """
15
19
 
16
20
  from pathlib import Path
@@ -22,13 +26,14 @@ from .models.waldiez import Waldiez
22
26
  from .running import (
23
27
  WaldiezBaseRunner,
24
28
  WaldiezStandardRunner,
29
+ WaldiezStepByStepRunner,
30
+ WaldiezSubprocessRunner,
25
31
  )
26
32
 
27
33
 
28
34
  def create_runner(
29
35
  waldiez: Waldiez,
30
- # mode: Literal["standard", "debug"] = "standard",
31
- mode: Literal["standard"] = "standard",
36
+ mode: Literal["standard", "debug", "subprocess"] = "standard",
32
37
  output_path: str | Path | None = None,
33
38
  uploads_root: str | Path | None = None,
34
39
  structured_io: bool = False,
@@ -41,7 +46,7 @@ def create_runner(
41
46
  ----------
42
47
  waldiez : Waldiez
43
48
  The waldiez flow to run.
44
- mode : str, optional
49
+ mode : Literal["standard", "debug"], optional
45
50
  Runner mode: "standard", "debug", by default "standard"
46
51
  output_path : str | Path | None, optional
47
52
  Output path for results, by default None
@@ -66,22 +71,37 @@ def create_runner(
66
71
  """
67
72
  runners: dict[str, type[WaldiezBaseRunner]] = {
68
73
  "standard": WaldiezStandardRunner,
69
- # "debug": WaldiezDebugRunner,
74
+ "debug": WaldiezStepByStepRunner,
75
+ "subprocess": WaldiezSubprocessRunner,
70
76
  }
71
77
 
72
- if mode not in runners:
78
+ if mode not in runners: # pragma: no cover
73
79
  available = ", ".join(runners.keys())
74
80
  raise ValueError(
75
81
  f"Unknown runner mode '{mode}'. Available: {available}"
76
82
  )
77
83
 
78
84
  runner_class = runners[mode]
85
+ if mode == "subprocess":
86
+ subprocess_mode = kwargs.pop("subprocess_mode", "run")
87
+ if subprocess_mode not in ["run", "debug"]:
88
+ subprocess_mode = "run"
89
+ return runner_class(
90
+ waldiez=waldiez,
91
+ output_path=output_path,
92
+ uploads_root=uploads_root,
93
+ structured_io=structured_io,
94
+ dot_env=dot_env,
95
+ mode=subprocess_mode,
96
+ **kwargs,
97
+ )
79
98
  return runner_class(
80
99
  waldiez=waldiez,
81
100
  output_path=output_path,
82
101
  uploads_root=uploads_root,
83
102
  structured_io=structured_io,
84
103
  dot_env=dot_env,
104
+ mode=mode,
85
105
  **kwargs,
86
106
  )
87
107
 
@@ -94,8 +114,7 @@ class WaldiezRunner(WaldiezBaseRunner):
94
114
  def __init__(
95
115
  self,
96
116
  waldiez: Waldiez,
97
- # mode: Literal["standard", "debug"] = "standard",
98
- mode: Literal["standard"] = "standard",
117
+ mode: Literal["standard", "debug"] = "standard",
99
118
  output_path: str | Path | None = None,
100
119
  uploads_root: str | Path | None = None,
101
120
  structured_io: bool = False,
@@ -131,7 +150,7 @@ class WaldiezRunner(WaldiezBaseRunner):
131
150
  **kwargs,
132
151
  )
133
152
 
134
- def __repr__(self) -> str:
153
+ def __repr__(self) -> str: # pragma: no cover
135
154
  """Get the string representation of the runner.
136
155
 
137
156
  Returns
@@ -156,7 +175,9 @@ class WaldiezRunner(WaldiezBaseRunner):
156
175
  """
157
176
  if hasattr(self._runner, name):
158
177
  return getattr(self._runner, name)
159
- raise AttributeError(f"{type(self).__name__} has no attribute '{name}'")
178
+ raise AttributeError(
179
+ f"{type(self).__name__} has no attribute '{name}'"
180
+ ) # pragma: no cover
160
181
 
161
182
  def _run(
162
183
  self,
@@ -176,26 +197,6 @@ class WaldiezRunner(WaldiezBaseRunner):
176
197
  **kwargs,
177
198
  )
178
199
 
179
- def _start(
180
- self,
181
- temp_dir: Path,
182
- output_file: Path,
183
- uploads_root: Path | None,
184
- skip_mmd: bool,
185
- skip_timeline: bool,
186
- ) -> None:
187
- """Start the workflow in a non-blocking way."""
188
- self._runner._start(
189
- temp_dir=temp_dir,
190
- output_file=output_file,
191
- uploads_root=uploads_root,
192
- skip_mmd=skip_mmd,
193
- skip_timeline=skip_timeline,
194
- )
195
-
196
- def _stop(self) -> None:
197
- self._runner._stop()
198
-
199
200
  async def _a_run(
200
201
  self,
201
202
  temp_dir: Path,
@@ -216,25 +217,6 @@ class WaldiezRunner(WaldiezBaseRunner):
216
217
  **kwargs,
217
218
  )
218
219
 
219
- async def _a_start(
220
- self,
221
- temp_dir: Path,
222
- output_file: Path,
223
- uploads_root: Path | None,
224
- skip_mmd: bool,
225
- skip_timeline: bool,
226
- ) -> None:
227
- return await self._runner._a_start(
228
- temp_dir=temp_dir,
229
- output_file=output_file,
230
- uploads_root=uploads_root,
231
- skip_mmd=skip_mmd,
232
- skip_timeline=skip_timeline,
233
- )
234
-
235
- async def _a_stop(self) -> None:
236
- return await self._runner._a_stop()
237
-
238
220
  @classmethod
239
221
  def load(
240
222
  cls,
@@ -299,5 +281,6 @@ class WaldiezRunner(WaldiezBaseRunner):
299
281
  uploads_root=uploads_root,
300
282
  structured_io=structured_io,
301
283
  dot_env=dot_env,
284
+ waldiez_file=waldiez_file,
302
285
  **kwargs,
303
286
  )
@@ -3,9 +3,15 @@
3
3
  """Running related functions."""
4
4
 
5
5
  from .base_runner import WaldiezBaseRunner
6
+ from .exceptions import StopRunningException
6
7
  from .standard_runner import WaldiezStandardRunner
8
+ from .step_by_step import WaldiezStepByStepRunner
9
+ from .subprocess_runner import WaldiezSubprocessRunner
7
10
 
8
11
  __all__ = [
12
+ "StopRunningException",
9
13
  "WaldiezBaseRunner",
10
14
  "WaldiezStandardRunner",
15
+ "WaldiezStepByStepRunner",
16
+ "WaldiezSubprocessRunner",
11
17
  ]