waldiez 0.2.1__py3-none-any.whl → 0.3.0__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 (138) hide show
  1. waldiez/__init__.py +2 -0
  2. waldiez/__main__.py +2 -0
  3. waldiez/_version.py +3 -1
  4. waldiez/cli.py +13 -3
  5. waldiez/cli_extras.py +25 -27
  6. waldiez/conflict_checker.py +4 -3
  7. waldiez/exporter.py +28 -105
  8. waldiez/exporting/__init__.py +8 -9
  9. waldiez/exporting/agent/__init__.py +7 -0
  10. waldiez/exporting/agent/agent_exporter.py +279 -0
  11. waldiez/exporting/agent/utils/__init__.py +23 -0
  12. waldiez/exporting/agent/utils/agent_class_name.py +34 -0
  13. waldiez/exporting/agent/utils/agent_imports.py +50 -0
  14. waldiez/exporting/{agents → agent/utils}/code_execution.py +9 -11
  15. waldiez/exporting/{agents → agent/utils}/group_manager.py +47 -35
  16. waldiez/exporting/{agents → agent/utils}/rag_user/__init__.py +2 -0
  17. waldiez/exporting/{agents → agent/utils}/rag_user/chroma_utils.py +22 -17
  18. waldiez/exporting/{agents → agent/utils}/rag_user/mongo_utils.py +14 -10
  19. waldiez/exporting/{agents → agent/utils}/rag_user/pgvector_utils.py +12 -8
  20. waldiez/exporting/{agents → agent/utils}/rag_user/qdrant_utils.py +11 -8
  21. waldiez/exporting/{agents → agent/utils}/rag_user/rag_user.py +78 -55
  22. waldiez/exporting/{agents → agent/utils}/rag_user/vector_db.py +10 -8
  23. waldiez/exporting/agent/utils/swarm_agent.py +463 -0
  24. waldiez/exporting/{agents → agent/utils}/teachability.py +10 -6
  25. waldiez/exporting/{agents → agent/utils}/termination_message.py +7 -8
  26. waldiez/exporting/base/__init__.py +25 -0
  27. waldiez/exporting/base/agent_position.py +75 -0
  28. waldiez/exporting/base/base_exporter.py +118 -0
  29. waldiez/exporting/base/export_position.py +48 -0
  30. waldiez/exporting/base/import_position.py +23 -0
  31. waldiez/exporting/base/mixin.py +134 -0
  32. waldiez/exporting/base/utils/__init__.py +18 -0
  33. waldiez/exporting/{utils → base/utils}/comments.py +12 -55
  34. waldiez/exporting/{utils → base/utils}/naming.py +14 -4
  35. waldiez/exporting/base/utils/path_check.py +68 -0
  36. waldiez/exporting/{utils/object_string.py → base/utils/to_string.py} +21 -20
  37. waldiez/exporting/chats/__init__.py +5 -12
  38. waldiez/exporting/chats/chats_exporter.py +240 -0
  39. waldiez/exporting/chats/utils/__init__.py +15 -0
  40. waldiez/exporting/chats/utils/common.py +81 -0
  41. waldiez/exporting/chats/{nested.py → utils/nested.py} +125 -86
  42. waldiez/exporting/chats/utils/sequential.py +244 -0
  43. waldiez/exporting/chats/utils/single_chat.py +313 -0
  44. waldiez/exporting/chats/utils/swarm.py +207 -0
  45. waldiez/exporting/flow/__init__.py +5 -3
  46. waldiez/exporting/flow/flow_exporter.py +503 -0
  47. waldiez/exporting/flow/utils/__init__.py +47 -0
  48. waldiez/exporting/flow/utils/agent_utils.py +204 -0
  49. waldiez/exporting/flow/utils/chat_utils.py +71 -0
  50. waldiez/exporting/flow/utils/def_main.py +62 -0
  51. waldiez/exporting/flow/utils/flow_content.py +112 -0
  52. waldiez/exporting/flow/utils/flow_names.py +115 -0
  53. waldiez/exporting/flow/utils/importing_utils.py +179 -0
  54. waldiez/exporting/{utils → flow/utils}/logging_utils.py +34 -31
  55. waldiez/exporting/models/__init__.py +7 -242
  56. waldiez/exporting/models/models_exporter.py +192 -0
  57. waldiez/exporting/models/utils.py +166 -0
  58. waldiez/exporting/skills/__init__.py +7 -161
  59. waldiez/exporting/skills/skills_exporter.py +169 -0
  60. waldiez/exporting/skills/utils.py +281 -0
  61. waldiez/models/__init__.py +25 -7
  62. waldiez/models/agents/__init__.py +70 -0
  63. waldiez/models/agents/agent/__init__.py +11 -1
  64. waldiez/models/agents/agent/agent.py +9 -4
  65. waldiez/models/agents/agent/agent_data.py +3 -1
  66. waldiez/models/agents/agent/code_execution.py +2 -0
  67. waldiez/models/agents/agent/linked_skill.py +2 -0
  68. waldiez/models/agents/agent/nested_chat.py +2 -0
  69. waldiez/models/agents/agent/teachability.py +2 -0
  70. waldiez/models/agents/agent/termination_message.py +49 -13
  71. waldiez/models/agents/agents.py +15 -3
  72. waldiez/models/agents/assistant/__init__.py +2 -0
  73. waldiez/models/agents/assistant/assistant.py +2 -0
  74. waldiez/models/agents/assistant/assistant_data.py +2 -0
  75. waldiez/models/agents/group_manager/__init__.py +9 -1
  76. waldiez/models/agents/group_manager/group_manager.py +2 -0
  77. waldiez/models/agents/group_manager/group_manager_data.py +2 -0
  78. waldiez/models/agents/group_manager/speakers.py +49 -13
  79. waldiez/models/agents/rag_user/__init__.py +21 -4
  80. waldiez/models/agents/rag_user/rag_user.py +3 -1
  81. waldiez/models/agents/rag_user/rag_user_data.py +2 -0
  82. waldiez/models/agents/rag_user/retrieve_config.py +268 -17
  83. waldiez/models/agents/rag_user/vector_db_config.py +5 -3
  84. waldiez/models/agents/swarm_agent/__init__.py +49 -0
  85. waldiez/models/agents/swarm_agent/after_work.py +178 -0
  86. waldiez/models/agents/swarm_agent/on_condition.py +103 -0
  87. waldiez/models/agents/swarm_agent/on_condition_available.py +140 -0
  88. waldiez/models/agents/swarm_agent/on_condition_target.py +40 -0
  89. waldiez/models/agents/swarm_agent/swarm_agent.py +107 -0
  90. waldiez/models/agents/swarm_agent/swarm_agent_data.py +125 -0
  91. waldiez/models/agents/swarm_agent/update_system_message.py +144 -0
  92. waldiez/models/agents/user_proxy/__init__.py +2 -0
  93. waldiez/models/agents/user_proxy/user_proxy.py +2 -0
  94. waldiez/models/agents/user_proxy/user_proxy_data.py +2 -0
  95. waldiez/models/chat/__init__.py +21 -3
  96. waldiez/models/chat/chat.py +241 -7
  97. waldiez/models/chat/chat_data.py +192 -48
  98. waldiez/models/chat/chat_message.py +153 -144
  99. waldiez/models/chat/chat_nested.py +33 -53
  100. waldiez/models/chat/chat_summary.py +2 -0
  101. waldiez/models/common/__init__.py +6 -6
  102. waldiez/models/common/base.py +4 -1
  103. waldiez/models/common/method_utils.py +163 -83
  104. waldiez/models/flow/__init__.py +2 -0
  105. waldiez/models/flow/flow.py +176 -40
  106. waldiez/models/flow/flow_data.py +63 -2
  107. waldiez/models/flow/utils.py +172 -0
  108. waldiez/models/model/__init__.py +2 -0
  109. waldiez/models/model/model.py +25 -6
  110. waldiez/models/model/model_data.py +3 -1
  111. waldiez/models/skill/__init__.py +4 -1
  112. waldiez/models/skill/skill.py +30 -2
  113. waldiez/models/skill/skill_data.py +2 -0
  114. waldiez/models/waldiez.py +28 -4
  115. waldiez/runner.py +142 -228
  116. waldiez/running/__init__.py +33 -0
  117. waldiez/running/environment.py +83 -0
  118. waldiez/running/gen_seq_diagram.py +185 -0
  119. waldiez/running/running.py +300 -0
  120. {waldiez-0.2.1.dist-info → waldiez-0.3.0.dist-info}/METADATA +36 -30
  121. waldiez-0.3.0.dist-info/RECORD +125 -0
  122. waldiez-0.3.0.dist-info/licenses/LICENSE +201 -0
  123. waldiez/exporting/agents/__init__.py +0 -5
  124. waldiez/exporting/agents/agent.py +0 -236
  125. waldiez/exporting/agents/agent_skills.py +0 -67
  126. waldiez/exporting/agents/llm_config.py +0 -53
  127. waldiez/exporting/chats/chats.py +0 -46
  128. waldiez/exporting/chats/helpers.py +0 -420
  129. waldiez/exporting/flow/def_main.py +0 -32
  130. waldiez/exporting/flow/flow.py +0 -189
  131. waldiez/exporting/utils/__init__.py +0 -36
  132. waldiez/exporting/utils/importing.py +0 -265
  133. waldiez/exporting/utils/method_utils.py +0 -35
  134. waldiez/exporting/utils/path_check.py +0 -51
  135. waldiez-0.2.1.dist-info/RECORD +0 -92
  136. waldiez-0.2.1.dist-info/licenses/LICENSE +0 -21
  137. {waldiez-0.2.1.dist-info → waldiez-0.3.0.dist-info}/WHEEL +0 -0
  138. {waldiez-0.2.1.dist-info → waldiez-0.3.0.dist-info}/entry_points.txt +0 -0
waldiez/__init__.py CHANGED
@@ -1,3 +1,5 @@
1
+ # SPDX-License-Identifier: Apache-2.0.
2
+ # Copyright (c) 2024 - 2025 Waldiez and contributors.
1
3
  """Waldiez package."""
2
4
 
3
5
  import logging
waldiez/__main__.py CHANGED
@@ -1,3 +1,5 @@
1
+ # SPDX-License-Identifier: Apache-2.0.
2
+ # Copyright (c) 2024 - 2025 Waldiez and contributors.
1
3
  """Waldiez entrypoint when called as a module."""
2
4
 
3
5
  from .cli import app
waldiez/_version.py CHANGED
@@ -1,3 +1,5 @@
1
+ # SPDX-License-Identifier: Apache-2.0.
2
+ # Copyright (c) 2024 - 2025 Waldiez and contributors.
1
3
  """Version information for Waldiez."""
2
4
 
3
- __version__ = "0.2.1"
5
+ __version__ = "0.3.0"
waldiez/cli.py CHANGED
@@ -1,6 +1,8 @@
1
+ # SPDX-License-Identifier: Apache-2.0.
2
+ # Copyright (c) 2024 - 2025 Waldiez and contributors.
3
+ # pylint: disable=missing-function-docstring,missing-param-doc,missing-raises-doc # noqa: E501
1
4
  """Command line interface to convert or run a waldiez file."""
2
5
 
3
- # pylint: disable=missing-function-docstring,missing-param-doc,missing-raises-doc # noqa: E501
4
6
  import json
5
7
  import logging
6
8
  import os
@@ -9,6 +11,7 @@ import warnings
9
11
  from pathlib import Path
10
12
  from typing import TYPE_CHECKING, Optional
11
13
 
14
+ import anyio
12
15
  import typer
13
16
  from typing_extensions import Annotated
14
17
 
@@ -87,6 +90,10 @@ def run(
87
90
  ),
88
91
  ) -> None:
89
92
  """Run a Waldiez flow."""
93
+ # swarm without a user,
94
+ # creates a new user (this has a default code execution with docker)
95
+ # temp (until we handle/detect docker setup)
96
+ os.environ["AUTOGEN_USE_DOCKER"] = "0"
90
97
  output_path = _get_output_path(output, force)
91
98
  with file.open("r", encoding="utf-8") as _file:
92
99
  try:
@@ -96,14 +103,17 @@ def run(
96
103
  raise typer.Exit(code=1) from error
97
104
  waldiez = Waldiez.from_dict(data)
98
105
  runner = WaldiezRunner(waldiez)
99
- results = runner.run(output_path=output_path)
106
+ if waldiez.is_async:
107
+ results = anyio.run(runner.a_run, output_path)
108
+ else:
109
+ results = runner.run(output_path=output_path)
100
110
  logger = _get_logger()
101
111
  if isinstance(results, list):
102
112
  logger.info("Results:")
103
113
  for result in results:
104
114
  _log_result(result, logger)
105
115
  sep = "-" * 80
106
- print(f"\n{sep}\n")
116
+ print("\n" + f"{sep}" + "\n")
107
117
  else:
108
118
  _log_result(results, logger)
109
119
 
waldiez/cli_extras.py CHANGED
@@ -1,23 +1,27 @@
1
- # type: ignore
2
- # flake8: noqa
1
+ # SPDX-License-Identifier: Apache-2.0.
2
+ # Copyright (c) 2024 - 2025 Waldiez and contributors.
3
3
  # pylint: skip-file
4
+ # type: ignore
4
5
  # isort: skip_file
5
6
  """Extra typer commands for CLI."""
6
7
 
8
+ from typing import Callable
9
+
7
10
  import typer
11
+ from typer.models import CommandInfo
8
12
  import subprocess # nosemgrep # nosec
9
13
 
10
14
  HAVE_STUDIO = False
11
15
  HAVE_JUPYTER = False
12
16
  try:
13
- from waldiez_studio.cli import app as studio_app
17
+ from waldiez_studio.cli import run as studio_app
14
18
 
15
19
  HAVE_STUDIO = True
16
20
  except BaseException:
17
21
  pass
18
22
 
19
23
  try:
20
- import waldiez_jupyter
24
+ import waldiez_jupyter # noqa: F401
21
25
 
22
26
  HAVE_JUPYTER = True
23
27
  except BaseException:
@@ -38,18 +42,17 @@ def add_cli_extras(app: typer.Typer) -> None:
38
42
  The app with the extra commands added
39
43
  """
40
44
  if HAVE_STUDIO:
41
- app.add_typer(
42
- studio_app,
43
- name="studio",
44
- help="Start Waldiez Studio.",
45
- no_args_is_help=False,
45
+ app.registered_commands.append(
46
+ CommandInfo(name="studio", callback=studio_app)
46
47
  )
47
48
  if HAVE_JUPYTER:
48
49
  jupyter_app = get_jupyter_app()
49
- app.add_typer(jupyter_app, name="lab")
50
+ app.registered_commands.append(
51
+ CommandInfo(name="lab", callback=jupyter_app)
52
+ )
50
53
 
51
54
 
52
- def get_jupyter_app() -> typer.Typer:
55
+ def get_jupyter_app() -> Callable[..., None]:
53
56
  """Get the Jupyter Typer app.
54
57
 
55
58
  Returns
@@ -58,26 +61,22 @@ def get_jupyter_app() -> typer.Typer:
58
61
  The Jupyter Typer app
59
62
  """
60
63
  jupyter_app = typer.Typer(
61
- name="lab",
62
- help="Start jupyter lab with the waldiez extension.",
64
+ add_completion=False,
65
+ no_args_is_help=False,
66
+ pretty_exceptions_enable=False,
67
+ )
68
+
69
+ @jupyter_app.callback(
70
+ name="start",
71
+ help="Start JupyterLab.",
63
72
  context_settings={
64
73
  "help_option_names": ["-h", "--help"],
65
74
  "allow_extra_args": True,
66
75
  "ignore_unknown_options": True,
67
76
  },
68
- add_completion=False,
69
77
  no_args_is_help=False,
70
78
  invoke_without_command=True,
71
79
  add_help_option=True,
72
- pretty_exceptions_enable=False,
73
- epilog=(
74
- "Use `waldiez lab [COMMAND] --help` for command-specific help. "
75
- ),
76
- )
77
-
78
- @jupyter_app.command(
79
- name="start",
80
- help="Start JupyterLab.",
81
80
  )
82
81
  def start(
83
82
  port: int = typer.Option(
@@ -92,8 +91,7 @@ def get_jupyter_app() -> typer.Typer:
92
91
  ),
93
92
  browser: bool = typer.Option(
94
93
  False,
95
- "--no-browser",
96
- help="Don't open the browser.",
94
+ help="Open the browser after starting JupyterLab.",
97
95
  ),
98
96
  password: str = typer.Option(
99
97
  None,
@@ -111,7 +109,7 @@ def get_jupyter_app() -> typer.Typer:
111
109
  "--ServerApp.allow_origin='*'",
112
110
  "--ServerApp.disable_check_xsrf=True",
113
111
  ]
114
- if browser:
112
+ if not browser:
115
113
  command.append("--no-browser")
116
114
  if password:
117
115
  from jupyter_server.auth import passwd
@@ -120,4 +118,4 @@ def get_jupyter_app() -> typer.Typer:
120
118
  command.append(f"--ServerApp.password={hashed_password}")
121
119
  subprocess.run(command)
122
120
 
123
- return jupyter_app
121
+ return start
@@ -1,6 +1,7 @@
1
- """Check for conflicts with 'autogen-agentchat' package."""
2
-
1
+ # SPDX-License-Identifier: Apache-2.0.
2
+ # Copyright (c) 2024 - 2025 Waldiez and contributors.
3
3
  # pylint: disable=line-too-long
4
+ """Check for conflicts with 'autogen-agentchat' package."""
4
5
 
5
6
  import sys
6
7
  from importlib.metadata import PackageNotFoundError, version
@@ -16,7 +17,7 @@ def check_conflicts() -> None: # pragma: no cover
16
17
  "in the current environment, \n"
17
18
  "which conflicts with 'ag2' / 'pyautogen'.\n"
18
19
  "Please uninstall 'autogen-agentchat': \n"
19
- f"{sys.executable} -m pip uninstall -y autogen-agentchat \n"
20
+ f"{sys.executable} -m pip uninstall -y autogen-agentchat" + "\n"
20
21
  "And install 'pyautogen' (and/or 'waldiez') again: \n"
21
22
  f"{sys.executable} -m pip install --force pyautogen waldiez"
22
23
  )
waldiez/exporter.py CHANGED
@@ -1,5 +1,6 @@
1
- """Waldiez exporter.
2
-
1
+ # SPDX-License-Identifier: Apache-2.0.
2
+ # Copyright (c) 2024 - 2025 Waldiez and contributors.
3
+ """
3
4
  The role of the exporter is to export the model's data
4
5
  to an autogen's flow with one or more chats.
5
6
 
@@ -8,8 +9,8 @@ to trigger the chat(s).
8
9
  If additional tools/skills are used,
9
10
  they are exported as their `skill_name` in the same directory with
10
11
  the `flow.py` file. So the `flow.py` could have entries like:
11
- `form {skill1_name} import {skill1_name}`
12
- `form {skill2_name} import {skill2_name}`
12
+ `form {flow_name}_{skill1_name} import {skill1_name}`
13
+ `form {flow_name}_{skill2_name} import {skill2_name}`
13
14
  """
14
15
 
15
16
  # pylint: disable=inconsistent-quotes
@@ -19,16 +20,10 @@ import shutil
19
20
  import subprocess
20
21
  import sys
21
22
  from pathlib import Path
22
- from typing import Dict, List, Optional, Union
23
+ from typing import List, Optional, Union
23
24
 
24
- from .exporting import comment, export_flow, get_valid_instance_name
25
- from .models import (
26
- Waldiez,
27
- WaldiezAgent,
28
- WaldiezChat,
29
- WaldiezModel,
30
- WaldiezSkill,
31
- )
25
+ from .exporting import FlowExporter
26
+ from .models import Waldiez
32
27
 
33
28
 
34
29
  class WaldiezExporter:
@@ -38,15 +33,6 @@ class WaldiezExporter:
38
33
  waldiez (Waldiez): The Waldiez instance.
39
34
  """
40
35
 
41
- _agent_names: Dict[str, str]
42
- _model_names: Dict[str, str]
43
- _skill_names: Dict[str, str]
44
- _chat_names: Dict[str, str]
45
- _chats: List[WaldiezChat]
46
- _skills: List[WaldiezSkill]
47
- _models: List[WaldiezModel]
48
- _agents: List[WaldiezAgent]
49
-
50
36
  def __init__(self, waldiez: Waldiez) -> None:
51
37
  """Initialize the Waldiez exporter.
52
38
 
@@ -54,7 +40,7 @@ class WaldiezExporter:
54
40
  waldiez (Waldiez): The Waldiez instance.
55
41
  """
56
42
  self.waldiez = waldiez
57
- self._initialize()
43
+ # self._initialize()
58
44
 
59
45
  @classmethod
60
46
  def load(cls, file_path: Path) -> "WaldiezExporter":
@@ -73,56 +59,6 @@ class WaldiezExporter:
73
59
  waldiez = Waldiez.load(file_path)
74
60
  return cls(waldiez)
75
61
 
76
- def _initialize(
77
- self,
78
- ) -> None:
79
- """Get all the names in the flow.
80
-
81
- We need to make sure that no duplicate names are used,
82
- and that the names can be used as python variables.
83
- """
84
- all_names: Dict[str, str] = {}
85
- agent_names: Dict[str, str] = {}
86
- model_names: Dict[str, str] = {}
87
- skill_names: Dict[str, str] = {}
88
- chat_names: Dict[str, str] = {}
89
- chats: List[WaldiezChat] = []
90
- skills: List[WaldiezSkill] = []
91
- models: List[WaldiezModel] = []
92
- agents: List[WaldiezAgent] = []
93
- for agent in self.waldiez.agents:
94
- all_names = get_valid_instance_name(
95
- (agent.id, agent.name), all_names, prefix="wa"
96
- )
97
- agent_names[agent.id] = all_names[agent.id]
98
- agents.append(agent)
99
- for model in self.waldiez.models:
100
- all_names = get_valid_instance_name(
101
- (model.id, model.name), all_names, prefix="wm"
102
- )
103
- model_names[model.id] = all_names[model.id]
104
- models.append(model)
105
- for skill in self.waldiez.skills:
106
- all_names = get_valid_instance_name(
107
- (skill.id, skill.name), all_names, prefix="ws"
108
- )
109
- skill_names[skill.id] = all_names[skill.id]
110
- skills.append(skill)
111
- for chat in self.waldiez.flow.data.chats:
112
- all_names = get_valid_instance_name(
113
- (chat.id, chat.name), all_names, prefix="wc"
114
- )
115
- chat_names[chat.id] = all_names[chat.id]
116
- chats.append(chat)
117
- self._agent_names = agent_names
118
- self._model_names = model_names
119
- self._skill_names = skill_names
120
- self._chat_names = chat_names
121
- self._chats = chats
122
- self._skills = skills
123
- self._models = models
124
- self._agents = agents
125
-
126
62
  def export(self, path: Union[str, Path], force: bool = False) -> None:
127
63
  """Export the Waldiez instance.
128
64
 
@@ -175,25 +111,17 @@ class WaldiezExporter:
175
111
  RuntimeError
176
112
  If the notebook could not be generated.
177
113
  """
178
- content = f"{comment(True)}{self.waldiez.name}" + "\n\n"
179
- content += f"{comment(True, 2)}Dependencies" + "\n\n"
180
- content += "import sys\n"
181
- requirements = " ".join(self.waldiez.requirements)
182
- if requirements:
183
- content += (
184
- f"# !{{sys.executable}} -m pip install -q {requirements}" + "\n"
185
- )
186
- content += export_flow(
114
+ # we first create a .py file with the content
115
+ # and then convert it to a notebook using jupytext
116
+ exporter = FlowExporter(
187
117
  waldiez=self.waldiez,
188
- agents=(self._agents, self._agent_names),
189
- chats=(self._chats, self._chat_names),
190
- models=(self._models, self._model_names),
191
- skills=(self._skills, self._skill_names),
192
118
  output_dir=path.parent,
193
- notebook=True,
119
+ for_notebook=True,
194
120
  )
195
- # we first create a .py file with the content
196
- # and then convert it to a notebook using jupytext
121
+ output = exporter.export()
122
+ content = output["content"]
123
+ if not content:
124
+ raise RuntimeError("Could not generate notebook")
197
125
  py_path = path.with_suffix(".tmp.py")
198
126
  with open(py_path, "w", encoding="utf-8", newline="\n") as f:
199
127
  f.write(content)
@@ -226,26 +154,21 @@ class WaldiezExporter:
226
154
  ----------
227
155
  path : Path
228
156
  The path to export to.
157
+
158
+ Raises
159
+ ------
160
+ RuntimeError
161
+ If the python script could not be generated.
229
162
  """
230
- content = "#!/usr/bin/env python\n"
231
- content += f'"""{self.waldiez.name}\n\n'
232
- content += f"{self.waldiez.description}\n\n"
233
- content += f"Tags: {', '.join(self.waldiez.tags)}\n\n"
234
- content += f"Requirements: {', '.join(self.waldiez.requirements)}\n\n"
235
- content += '"""\n\n'
236
- content += "# cspell: disable\n"
237
- content += "# flake8: noqa\n\n"
238
- content += export_flow(
163
+ exporter = FlowExporter(
239
164
  waldiez=self.waldiez,
240
- agents=(self._agents, self._agent_names),
241
- chats=(self._chats, self._chat_names),
242
- models=(self._models, self._model_names),
243
- skills=(self._skills, self._skill_names),
244
165
  output_dir=path.parent,
245
- notebook=False,
166
+ for_notebook=False,
246
167
  )
247
- content += '\n\nif __name__ == "__main__":\n'
248
- content += " print(main())\n"
168
+ output = exporter.export()
169
+ content = output["content"]
170
+ if not content:
171
+ raise RuntimeError("Could not generate python script")
249
172
  with open(path, "w", encoding="utf-8", newline="\n") as file:
250
173
  file.write(content)
251
174
 
@@ -1,14 +1,13 @@
1
+ # SPDX-License-Identifier: Apache-2.0.
2
+ # Copyright (c) 2024 - 2025 Waldiez and contributors.
1
3
  """Tools for exporting agents, models, skills and chats to strings."""
2
4
 
3
- from .flow import export_flow
4
- from .models import export_models
5
- from .skills import export_skills
6
- from .utils import comment, get_valid_instance_name
5
+ from .flow import FlowExporter
6
+ from .models import ModelsExporter
7
+ from .skills import SkillsExporter
7
8
 
8
9
  __all__ = [
9
- "export_flow",
10
- "comment",
11
- "get_valid_instance_name",
12
- "export_models",
13
- "export_skills",
10
+ "FlowExporter",
11
+ "ModelsExporter",
12
+ "SkillsExporter",
14
13
  ]
@@ -0,0 +1,7 @@
1
+ # SPDX-License-Identifier: Apache-2.0.
2
+ # Copyright (c) 2024 - 2025 Waldiez and contributors.
3
+ """Agents exporter."""
4
+
5
+ from .agent_exporter import AgentExporter
6
+
7
+ __all__ = ["AgentExporter"]