waldiez 0.3.6__py3-none-any.whl → 0.3.7__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 (53) hide show
  1. waldiez/__init__.py +15 -66
  2. waldiez/_version.py +1 -1
  3. waldiez/cli.py +11 -8
  4. waldiez/exporting/__init__.py +2 -0
  5. waldiez/exporting/agent/agent_exporter.py +11 -2
  6. waldiez/exporting/agent/utils/__init__.py +2 -0
  7. waldiez/exporting/agent/utils/agent_class_name.py +2 -0
  8. waldiez/exporting/agent/utils/agent_imports.py +5 -0
  9. waldiez/exporting/agent/utils/reasoning.py +36 -0
  10. waldiez/exporting/flow/flow_exporter.py +21 -8
  11. waldiez/exporting/flow/utils/__init__.py +10 -5
  12. waldiez/exporting/flow/utils/def_main.py +25 -20
  13. waldiez/exporting/flow/utils/flow_content.py +42 -1
  14. waldiez/exporting/flow/utils/importing_utils.py +7 -1
  15. waldiez/exporting/flow/utils/logging_utils.py +176 -42
  16. waldiez/models/__init__.py +8 -0
  17. waldiez/models/agents/__init__.py +10 -0
  18. waldiez/models/agents/agent/agent.py +10 -4
  19. waldiez/models/agents/agent/termination_message.py +2 -0
  20. waldiez/models/agents/agents.py +10 -0
  21. waldiez/models/agents/rag_user/retrieve_config.py +46 -17
  22. waldiez/models/agents/reasoning/__init__.py +13 -0
  23. waldiez/models/agents/reasoning/reasoning_agent.py +43 -0
  24. waldiez/models/agents/reasoning/reasoning_agent_data.py +116 -0
  25. waldiez/models/agents/reasoning/reasoning_agent_reason_config.py +101 -0
  26. waldiez/models/agents/swarm_agent/__init__.py +2 -1
  27. waldiez/models/agents/swarm_agent/swarm_agent_data.py +2 -3
  28. waldiez/models/chat/chat_data.py +30 -63
  29. waldiez/models/chat/chat_message.py +2 -26
  30. waldiez/models/chat/chat_nested.py +7 -8
  31. waldiez/models/common/__init__.py +3 -18
  32. waldiez/models/common/date_utils.py +18 -0
  33. waldiez/models/common/dict_utils.py +37 -0
  34. waldiez/models/common/method_utils.py +2 -5
  35. waldiez/models/flow/flow_data.py +1 -1
  36. waldiez/models/waldiez.py +4 -1
  37. waldiez/runner.py +3 -3
  38. waldiez/running/environment.py +22 -16
  39. waldiez/running/gen_seq_diagram.py +7 -4
  40. waldiez/running/running.py +67 -19
  41. waldiez/utils/__init__.py +15 -0
  42. waldiez/utils/cli_extras/__init__.py +30 -0
  43. waldiez/{cli_extras.py → utils/cli_extras/jupyter.py} +9 -20
  44. waldiez/utils/cli_extras/studio.py +36 -0
  45. waldiez/{conflict_checker.py → utils/conflict_checker.py} +14 -3
  46. waldiez/utils/flaml_warnings.py +17 -0
  47. waldiez/utils/pysqlite3_checker.py +249 -0
  48. {waldiez-0.3.6.dist-info → waldiez-0.3.7.dist-info}/METADATA +27 -19
  49. {waldiez-0.3.6.dist-info → waldiez-0.3.7.dist-info}/RECORD +53 -40
  50. waldiez-0.3.7.dist-info/licenses/NOTICE.md +5 -0
  51. {waldiez-0.3.6.dist-info → waldiez-0.3.7.dist-info}/WHEEL +0 -0
  52. {waldiez-0.3.6.dist-info → waldiez-0.3.7.dist-info}/entry_points.txt +0 -0
  53. {waldiez-0.3.6.dist-info → waldiez-0.3.7.dist-info}/licenses/LICENSE +0 -0
waldiez/__init__.py CHANGED
@@ -2,76 +2,25 @@
2
2
  # Copyright (c) 2024 - 2025 Waldiez and contributors.
3
3
  """Waldiez package."""
4
4
 
5
- import logging
6
- import warnings
7
-
8
5
  from ._version import __version__
9
- from .conflict_checker import check_conflicts
10
6
  from .exporter import WaldiezExporter
11
7
  from .models import Waldiez
12
8
  from .runner import WaldiezRunner
13
-
14
- warnings.filterwarnings(
15
- "ignore", module="flaml", message="^.*flaml.automl is not available.*$"
16
- )
17
-
18
-
19
- # pylint: disable=too-few-public-methods
20
- class FlamlFilter(logging.Filter):
21
- """Filter out flaml.automl is not available message."""
22
-
23
- def filter(self, record: logging.LogRecord) -> bool:
24
- """Filter out flaml.automl is not available message.
25
-
26
- this is just annoying:
27
-
28
- ```
29
- flaml.automl is not available.
30
- Please install flaml[automl] to enable AutoML functionalities.
31
- ```
32
-
33
- Parameters
34
- ----------
35
- record : logging.LogRecord
36
- Log record to filter.
37
-
38
- Returns
39
- -------
40
- bool
41
- Whether to filter out the log record.
42
- """
43
- return "flaml.automl is not available" not in record.getMessage()
44
-
45
-
46
- # flag to check if ag2 and autogen-agentchat
47
- # are installed at the same time
48
- __WALDIEZ_CHECKED_FOR_CONFLICTS = False
49
- # flag to handle flaml logging
50
- # suppress the annoying message about flaml.automl
51
- __WALDIEZ_HANDLED_FLAML_LOGGING = False
52
-
53
-
54
- def _check_conflicts() -> None:
55
- """Check for conflicts once."""
56
- # pylint: disable=global-statement
57
- global __WALDIEZ_CHECKED_FOR_CONFLICTS
58
- if __WALDIEZ_CHECKED_FOR_CONFLICTS is False:
59
- check_conflicts()
60
- __WALDIEZ_CHECKED_FOR_CONFLICTS = True
61
-
62
-
63
- def _handle_flaml_logging() -> None:
64
- """Handle flaml logging once."""
65
- # pylint: disable=global-statement
66
- global __WALDIEZ_HANDLED_FLAML_LOGGING
67
- if __WALDIEZ_HANDLED_FLAML_LOGGING is False:
68
- __WALDIEZ_HANDLED_FLAML_LOGGING = True
69
- flam_logger = logging.getLogger("flaml")
70
- flam_logger.addFilter(FlamlFilter())
71
-
72
-
73
- _check_conflicts()
74
- _handle_flaml_logging()
9
+ from .utils import check_conflicts, check_flaml_warnings
10
+
11
+ __WALDIEZ_INITIALIZED = False
12
+
13
+ if not __WALDIEZ_INITIALIZED:
14
+ check_conflicts()
15
+ check_flaml_warnings()
16
+ # let's skip the one below
17
+ # check_pysqlite3()
18
+ # and use it only if needed:
19
+ # captain_agent dependency:
20
+ # before calling pip install pyautogen[captainagent]
21
+ # we should have pysqlite3 installed (at least on windows)
22
+ # before running a flow
23
+ __WALDIEZ_INITIALIZED = True
75
24
 
76
25
  __all__ = [
77
26
  "Waldiez",
waldiez/_version.py CHANGED
@@ -2,4 +2,4 @@
2
2
  # Copyright (c) 2024 - 2025 Waldiez and contributors.
3
3
  """Version information for Waldiez."""
4
4
 
5
- __version__ = "0.3.6"
5
+ __version__ = "0.3.7"
waldiez/cli.py CHANGED
@@ -7,7 +7,6 @@ import json
7
7
  import logging
8
8
  import os
9
9
  import sys
10
- import warnings
11
10
  from pathlib import Path
12
11
  from typing import TYPE_CHECKING, Optional
13
12
 
@@ -15,14 +14,11 @@ import anyio
15
14
  import typer
16
15
  from typing_extensions import Annotated
17
16
 
18
- from . import Waldiez, __version__
19
- from .cli_extras import add_cli_extras # type: ignore
17
+ from ._version import __version__
20
18
  from .exporter import WaldiezExporter
19
+ from .models import Waldiez
21
20
  from .runner import WaldiezRunner
22
-
23
- warnings.filterwarnings(
24
- "ignore", module="flaml", message="^.*flaml.automl is not available.*$"
25
- )
21
+ from .utils import add_cli_extras
26
22
 
27
23
  if TYPE_CHECKING:
28
24
  from autogen import ChatResult # type: ignore[import-untyped]
@@ -90,7 +86,7 @@ def run(
90
86
  ),
91
87
  ) -> None:
92
88
  """Run a Waldiez flow."""
93
- # swarm without a user,
89
+ # a swarm chat without a user agent
94
90
  # creates a new user (this has a default code execution with docker)
95
91
  # temp (until we handle/detect docker setup)
96
92
  os.environ["AUTOGEN_USE_DOCKER"] = "0"
@@ -114,6 +110,13 @@ def run(
114
110
  _log_result(result, logger)
115
111
  sep = "-" * 80
116
112
  print("\n" + f"{sep}" + "\n")
113
+ elif isinstance(results, dict):
114
+ logger.info("Results:")
115
+ for key, result in results.items():
116
+ logger.info("Order: %s", key)
117
+ _log_result(result, logger)
118
+ sep = "-" * 80
119
+ print("\n" + f"{sep}" + "\n")
117
120
  else:
118
121
  _log_result(results, logger)
119
122
 
@@ -2,11 +2,13 @@
2
2
  # Copyright (c) 2024 - 2025 Waldiez and contributors.
3
3
  """Tools for exporting agents, models, skills and chats to strings."""
4
4
 
5
+ from .agent import AgentExporter
5
6
  from .flow import FlowExporter
6
7
  from .models import ModelsExporter
7
8
  from .skills import SkillsExporter
8
9
 
9
10
  __all__ = [
11
+ "AgentExporter",
10
12
  "FlowExporter",
11
13
  "ModelsExporter",
12
14
  "SkillsExporter",
@@ -24,6 +24,7 @@ from .utils import (
24
24
  get_group_manager_extras,
25
25
  get_is_termination_message,
26
26
  get_rag_user_extras,
27
+ get_reasoning_agent_extras,
27
28
  get_swarm_extras,
28
29
  )
29
30
 
@@ -114,6 +115,10 @@ class AgentExporter(BaseExporter, ExporterMixin):
114
115
  self._termination = get_is_termination_message(
115
116
  agent=self.agent, agent_name=self._agent_name
116
117
  )
118
+ self._reasoning = get_reasoning_agent_extras(
119
+ agent=self.agent,
120
+ serializer=self.serializer,
121
+ )
117
122
 
118
123
  def get_imports(self) -> Optional[List[Tuple[str, ImportPosition]]]:
119
124
  """Get the imports.
@@ -135,7 +140,10 @@ class AgentExporter(BaseExporter, ExporterMixin):
135
140
  # if the agent has skills, add the register_function import.
136
141
  if self.agent.data.skills:
137
142
  agent_imports.add("from autogen import register_function")
138
- return [(import_string, position) for import_string in agent_imports]
143
+ return sorted(
144
+ [(import_string, position) for import_string in agent_imports],
145
+ key=lambda x: x[0],
146
+ )
139
147
 
140
148
  def get_system_message_arg(self) -> str:
141
149
  """Get the system message argument.
@@ -223,6 +231,7 @@ class AgentExporter(BaseExporter, ExporterMixin):
223
231
  default_auto_reply = (
224
232
  f'"{self.string_escape(agent.data.agent_default_auto_reply)}"'
225
233
  )
234
+ extras = f"{group_chat_arg}{retrieve_arg}{self._reasoning}"
226
235
  agent_str = f"""{agent_name} = {agent_class}(
227
236
  name="{agent_name}",
228
237
  description="{agent.description}"{system_message_arg},
@@ -230,7 +239,7 @@ class AgentExporter(BaseExporter, ExporterMixin):
230
239
  max_consecutive_auto_reply={agent.data.max_consecutive_auto_reply},
231
240
  default_auto_reply={default_auto_reply},
232
241
  code_execution_config={code_execution_arg},
233
- is_termination_msg={is_termination},{group_chat_arg}{retrieve_arg}
242
+ is_termination_msg={is_termination},{extras}
234
243
  """
235
244
  if self._swarm[1]:
236
245
  agent_str += self._swarm[1]
@@ -7,6 +7,7 @@ from .agent_imports import get_agent_imports
7
7
  from .code_execution import get_agent_code_execution_config
8
8
  from .group_manager import get_group_manager_extras
9
9
  from .rag_user import get_rag_user_extras
10
+ from .reasoning import get_reasoning_agent_extras
10
11
  from .swarm_agent import get_swarm_extras
11
12
  from .teachability import get_agent_teachability_string
12
13
  from .termination_message import get_is_termination_message
@@ -19,5 +20,6 @@ __all__ = [
19
20
  "get_group_manager_extras",
20
21
  "get_is_termination_message",
21
22
  "get_rag_user_extras",
23
+ "get_reasoning_agent_extras",
22
24
  "get_swarm_extras",
23
25
  ]
@@ -31,4 +31,6 @@ def get_agent_class_name(agent: WaldiezAgent) -> str:
31
31
  return "RetrieveUserProxyAgent"
32
32
  if agent.agent_type == "swarm":
33
33
  return "SwarmAgent"
34
+ if agent.agent_type == "reasoning":
35
+ return "ReasoningAgent"
34
36
  return "ConversableAgent" # pragma: no cover
@@ -45,6 +45,11 @@ def get_agent_imports(agent_class: str) -> Set[str]:
45
45
  "SwarmAgent, "
46
46
  "SwarmResult"
47
47
  )
48
+ elif agent_class == "ReasoningAgent":
49
+ # pylint: disable=line-too-long
50
+ imports.add(
51
+ "from autogen.agentchat.contrib.reasoning_agent import ReasoningAgent, visualize_tree" # noqa: E501
52
+ )
48
53
  else:
49
54
  imports.add("from autogen import ConversableAgent")
50
55
  return imports
@@ -0,0 +1,36 @@
1
+ # SPDX-License-Identifier: Apache-2.0.
2
+ # Copyright (c) 2024 - 2025 Waldiez and contributors.
3
+ """Export reasoning agent to string."""
4
+
5
+ from typing import Callable
6
+
7
+ from waldiez.models import WaldiezAgent, WaldiezReasoningAgent
8
+
9
+
10
+ def get_reasoning_agent_extras(
11
+ agent: WaldiezAgent,
12
+ serializer: Callable[..., str],
13
+ ) -> str:
14
+ """Get the reasoning agent extras.
15
+
16
+ Parameters
17
+ ----------
18
+ agent : WaldiezReasoningAgent
19
+ The reasoning agent.
20
+ serializer : Callable[..., str]
21
+ The serializer to get the string representation of an object.
22
+
23
+ Returns
24
+ -------
25
+ str
26
+ The reasoning agent extras.
27
+ """
28
+ if agent.agent_type != "reasoning" or not isinstance(
29
+ agent, WaldiezReasoningAgent
30
+ ):
31
+ return ""
32
+ reasoning_config = agent.get_reasoning_config()
33
+ serialized = serializer(reasoning_config)
34
+ content = "\n verbose=" + f"{agent.data.verbose},"
35
+ content += "\n reason_config=" + f"{serialized},"
36
+ return content
@@ -49,13 +49,13 @@ from .utils import (
49
49
  ensure_unique_names,
50
50
  gather_agent_outputs,
51
51
  gather_imports,
52
+ get_after_run_content,
52
53
  get_def_main,
53
54
  get_ipynb_content_start,
54
- get_logging_start_string,
55
- get_logging_stop_string,
56
55
  get_py_content_start,
57
56
  get_sqlite_out,
58
- get_sqlite_out_call,
57
+ get_start_logging,
58
+ get_stop_logging,
59
59
  get_the_imports_string,
60
60
  )
61
61
 
@@ -201,6 +201,7 @@ class FlowExporter(BaseExporter, ExporterMixin):
201
201
  str
202
202
  The merged export contents.
203
203
  """
204
+ is_async = self.waldiez.is_async
204
205
  content = (
205
206
  get_py_content_start(self.waldiez)
206
207
  if not self.for_notebook
@@ -209,7 +210,8 @@ class FlowExporter(BaseExporter, ExporterMixin):
209
210
  content += self.get_comment("imports", self.for_notebook) + "\n"
210
211
  content += imports[0] + "\n"
211
212
  content += self.get_comment("logging", self.for_notebook) + "\n"
212
- content += get_logging_start_string(tabs=0) + "\n\n"
213
+ content += get_start_logging(tabs=0) + "\n"
214
+ content += "start_logging()\n\n"
213
215
  if models_output:
214
216
  content += self.get_comment("models", self.for_notebook) + "\n"
215
217
  content += models_output + "\n"
@@ -221,16 +223,27 @@ class FlowExporter(BaseExporter, ExporterMixin):
221
223
  content += agents_content + "\n"
222
224
  if before_chats:
223
225
  content += before_chats + "\n"
224
- content += get_sqlite_out() + "\n"
226
+ content += get_sqlite_out(is_async=is_async) + "\n"
227
+ content += get_stop_logging(tabs=0, is_async=is_async) + "\n"
225
228
  content += self.get_comment("run", self.for_notebook) + "\n"
229
+ after_run = get_after_run_content(
230
+ waldiez=self.waldiez,
231
+ agent_names=self.agent_names,
232
+ tabs=0 if self.for_notebook else 1,
233
+ )
226
234
  if self.for_notebook is False:
227
235
  content += get_def_main(
228
- chats_content, is_async=self.waldiez.is_async
236
+ chats_content,
237
+ after_run=after_run,
238
+ is_async=self.waldiez.is_async,
229
239
  )
230
240
  else:
231
241
  content += "\n" + chats_content + "\n"
232
- content += get_logging_stop_string(tabs=0) + "\n"
233
- content += get_sqlite_out_call(tabs=0) + "\n"
242
+ if is_async:
243
+ content += "await stop_logging()"
244
+ else:
245
+ content += "stop_logging()"
246
+ content += after_run
234
247
  content = content.replace("\n\n\n\n", "\n\n\n")
235
248
  return content
236
249
 
@@ -11,7 +11,11 @@ from .agent_utils import (
11
11
  )
12
12
  from .chat_utils import add_after_chat_content, add_before_chat_content
13
13
  from .def_main import get_def_main
14
- from .flow_content import get_ipynb_content_start, get_py_content_start
14
+ from .flow_content import (
15
+ get_after_run_content,
16
+ get_ipynb_content_start,
17
+ get_py_content_start,
18
+ )
15
19
  from .flow_names import ensure_unique_names
16
20
  from .importing_utils import (
17
21
  gather_imports,
@@ -19,10 +23,10 @@ from .importing_utils import (
19
23
  get_the_imports_string,
20
24
  )
21
25
  from .logging_utils import (
22
- get_logging_start_string,
23
- get_logging_stop_string,
24
26
  get_sqlite_out,
25
27
  get_sqlite_out_call,
28
+ get_start_logging,
29
+ get_stop_logging,
26
30
  )
27
31
 
28
32
  __all__ = [
@@ -35,11 +39,12 @@ __all__ = [
35
39
  "ensure_unique_names",
36
40
  "gather_agent_outputs",
37
41
  "gather_imports",
42
+ "get_after_run_content",
38
43
  "get_def_main",
39
44
  "get_py_content_start",
40
45
  "get_ipynb_content_start",
41
- "get_logging_start_string",
42
- "get_logging_stop_string",
46
+ "get_start_logging",
47
+ "get_stop_logging",
43
48
  "get_sqlite_out",
44
49
  "get_sqlite_out_call",
45
50
  "get_standard_imports",
@@ -1,11 +1,11 @@
1
1
  # SPDX-License-Identifier: Apache-2.0.
2
2
  # Copyright (c) 2024 - 2025 Waldiez and contributors.
3
+ # flake8: noqa: E501
4
+ # pylint: disable=inconsistent-quotes, line-too-long
3
5
  """Get the main function."""
4
6
 
5
- from .logging_utils import get_logging_stop_string, get_sqlite_out_call
6
7
 
7
-
8
- def get_def_main(flow_chats: str, is_async: bool) -> str:
8
+ def get_def_main(flow_chats: str, after_run: str, is_async: bool) -> str:
9
9
  """Get the main function.
10
10
 
11
11
  When exporting to python, waldiez_chats string will be the
@@ -18,6 +18,8 @@ def get_def_main(flow_chats: str, is_async: bool) -> str:
18
18
  ----------
19
19
  flow_chats : str
20
20
  The content of the main function.
21
+ after_run : str
22
+ The content after the run of the flow.
21
23
  is_async : bool
22
24
  Whether the main function is asynchronous.
23
25
  Returns
@@ -29,31 +31,34 @@ def get_def_main(flow_chats: str, is_async: bool) -> str:
29
31
  if is_async:
30
32
  content += "async "
31
33
  content += "def main():\n"
32
- content += " # type: () -> Union[ChatResult, List[ChatResult]]\n"
34
+ content += " # type: () -> Union[ChatResult, List[ChatResult], Dict[int, ChatResult]]\n"
33
35
  content += ' """Start chatting."""\n'
34
36
  content += f"{flow_chats}" + "\n"
35
- content += get_logging_stop_string(1) + "\n"
36
- content += get_sqlite_out_call(1) + "\n"
37
- content += " return results\n\n\n"
37
+ if is_async:
38
+ content += " await stop_logging()"
39
+ else:
40
+ content += " stop_logging()"
41
+ content += after_run
42
+ content += "\n return results\n\n\n"
38
43
  if is_async:
39
44
  content += "async def call_main():\n"
40
45
  else:
41
46
  content += "def call_main() -> None:\n"
42
47
  content += ' """Run the main function and print the results."""\n'
43
- # fmt: off
48
+ content += " results: Union[ChatResult, List[ChatResult], Dict[int, ChatResult]] = "
44
49
  if is_async:
45
- content += (
46
- " results: Union[ChatResult, List[ChatResult]] = await main()\n"
47
- )
48
- else:
49
- content += (
50
- " results: Union[ChatResult, List[ChatResult]] = main()\n"
51
- )
52
- # fmt: on
53
- content += " if not isinstance(results, list):\n"
54
- content += " results = [results]\n"
55
- content += " for result in results:\n"
56
- content += " pprint(asdict(result))\n\n\n"
50
+ content += "await "
51
+ content += "main()\n"
52
+ content += " if isinstance(results, dict):\n"
53
+ content += " # order by key\n"
54
+ content += " ordered_results = dict(sorted(results.items()))\n"
55
+ content += " for _, result in ordered_results.items():\n"
56
+ content += " pprint(asdict(result))\n"
57
+ content += " elif isinstance(results, list):\n"
58
+ content += " for result in results:\n"
59
+ content += " pprint(asdict(result))\n"
60
+ content += " else:\n"
61
+ content += " pprint(asdict(results))\n"
57
62
  content += 'if __name__ == "__main__":\n'
58
63
  if is_async:
59
64
  content += " anyio.run(call_main)\n"
@@ -1,8 +1,9 @@
1
1
  # SPDX-License-Identifier: Apache-2.0.
2
2
  # Copyright (c) 2024 - 2025 Waldiez and contributors.
3
+ # flake8: noqa E501
3
4
  """Utils to generate the content of a flow."""
4
5
 
5
- from typing import Callable, List, Optional
6
+ from typing import Callable, Dict, List, Optional
6
7
 
7
8
  from waldiez.models import Waldiez
8
9
 
@@ -110,3 +111,43 @@ def get_pylint_ignore_comment(
110
111
  if notebook is True:
111
112
  line = "\n" + line
112
113
  return line + "\n"
114
+
115
+
116
+ def get_after_run_content(
117
+ waldiez: Waldiez,
118
+ agent_names: Dict[str, str],
119
+ tabs: int,
120
+ ) -> str:
121
+ """Get content to add after the flow is run.
122
+
123
+ Parameters
124
+ ----------
125
+ waldiez : Waldiez
126
+ The waldiez object.
127
+ agent_names : Dict[str, str]
128
+ The dictionary of agent names and their corresponding ids
129
+ tabs : int
130
+ The number of tabs to add before the content.
131
+ Returns
132
+ -------
133
+ str
134
+ The content to add after the flow is run.
135
+ """
136
+ # if th eflow has reasoning agents, we add
137
+ # visualize_tree(agent._root) for each agent
138
+ content = ""
139
+ space = " " * tabs
140
+ for agent in waldiez.agents:
141
+ if agent.agent_type == "reasoning":
142
+ agent_name = agent_names[agent.id]
143
+ content += f"""
144
+ {space}# pylint: disable=broad-except,too-many-try-statements
145
+ {space}try:
146
+ {space}{space}visualize_tree({agent_name}._root) # pylint: disable=protected-access
147
+ {space}{space}if os.path.exists("tree_of_thoughts.png"):
148
+ {space}{space}{space}new_name = "{agent_name}_tree_of_thoughts.png"
149
+ {space}{space}{space}os.rename("tree_of_thoughts.png", new_name)
150
+ {space}except BaseException:
151
+ {space}{space}pass
152
+ """
153
+ return content
@@ -124,7 +124,13 @@ def get_the_imports_string(
124
124
  while not final_string.endswith("\n\n"):
125
125
  final_string += "\n"
126
126
  if is_async:
127
- final_string += "\nimport anyio"
127
+ final_string += (
128
+ "\nimport aiofiles"
129
+ "\nimport aiosqlite"
130
+ "\nimport anyio"
131
+ "\nfrom aiocsv import AsyncDictWriter"
132
+ "\nfrom asyncer import asyncify"
133
+ )
128
134
  if got_import_autogen:
129
135
  final_string += "\nimport autogen # type: ignore\n"
130
136
  if autogen_imports: