waldiez 0.2.2__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 +4 -3
  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.2.dist-info → waldiez-0.3.0.dist-info}/METADATA +32 -26
  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.2.dist-info/RECORD +0 -92
  136. waldiez-0.2.2.dist-info/licenses/LICENSE +0 -21
  137. {waldiez-0.2.2.dist-info → waldiez-0.3.0.dist-info}/WHEEL +0 -0
  138. {waldiez-0.2.2.dist-info → waldiez-0.3.0.dist-info}/entry_points.txt +0 -0
@@ -1,6 +1,8 @@
1
+ # SPDX-License-Identifier: Apache-2.0.
2
+ # Copyright (c) 2024 - 2025 Waldiez and contributors.
1
3
  """RAG User related exporting utils."""
2
4
 
3
- from typing import Dict, List, Set, Tuple, Union
5
+ from typing import Callable, Dict, List, Set, Tuple, Union
4
6
 
5
7
  from waldiez.models import (
6
8
  WaldiezAgent,
@@ -9,14 +11,63 @@ from waldiez.models import (
9
11
  WaldiezRagUserRetrieveConfig,
10
12
  )
11
13
 
12
- from ...utils import get_object_string, get_path_string
13
14
  from .vector_db import get_rag_user_vector_db_string
14
15
 
15
16
 
17
+ def get_rag_user_extras(
18
+ agent: WaldiezAgent,
19
+ agent_name: str,
20
+ model_names: Dict[str, str],
21
+ path_resolver: Callable[[str], str],
22
+ serializer: Callable[..., str],
23
+ ) -> Tuple[str, str, Set[str]]:
24
+ """Get the RAG user extra argument, imports and content before the agent.
25
+
26
+ Parameters
27
+ ----------
28
+ agent : WaldiezAgent
29
+ The agent.
30
+ agent_name : str
31
+ The agent's name.
32
+ model_names : Dict[str, str]
33
+ A mapping from model id to model name.
34
+ path_resolver : Callable[[str], str]
35
+ The path resolver function.
36
+ serializer : Callable[..., str]
37
+ The serializer function.
38
+
39
+ Returns
40
+ -------
41
+ Tuple[str, str, Set[str]]
42
+ The content before the agent, the retrieve arg and the db imports.
43
+ """
44
+ before_agent_string = ""
45
+ retrieve_arg = ""
46
+ db_imports: Set[str] = set()
47
+ if agent.agent_type == "rag_user" and isinstance(agent, WaldiezRagUser):
48
+ rag_content_before_agent, retrieve_arg, db_imports = (
49
+ get_rag_user_retrieve_config_str(
50
+ agent=agent,
51
+ agent_name=agent_name,
52
+ model_names=model_names,
53
+ path_resolver=path_resolver,
54
+ serializer=serializer,
55
+ )
56
+ )
57
+ if retrieve_arg:
58
+ retrieve_arg = "\n" + f" retrieve_config={retrieve_arg},"
59
+ if rag_content_before_agent:
60
+ before_agent_string += rag_content_before_agent
61
+ return before_agent_string, retrieve_arg, db_imports
62
+
63
+
64
+ # pylint: disable=too-many-locals
16
65
  def get_rag_user_retrieve_config_str(
17
66
  agent: WaldiezRagUser,
18
67
  agent_name: str,
19
68
  model_names: Dict[str, str],
69
+ path_resolver: Callable[[str], str],
70
+ serializer: Callable[..., str],
20
71
  ) -> Tuple[str, str, Set[str]]:
21
72
  """Get the RAG user retrieve config string.
22
73
 
@@ -28,6 +79,10 @@ def get_rag_user_retrieve_config_str(
28
79
  The agent's name.
29
80
  model_names : Dict[str, str]
30
81
  A mapping from model id to model name.
82
+ path_resolver : Callable[[str], str]
83
+ The path resolver function.
84
+ serializer : Callable[..., str]
85
+ The serializer function.
31
86
  Returns
32
87
  -------
33
88
  Tuple[str, str, Set[str]]
@@ -43,32 +98,34 @@ def get_rag_user_retrieve_config_str(
43
98
  agent_name=agent_name,
44
99
  )
45
100
  imports.update(db_imports)
46
- args_dict = _get_args_dict(agent, retrieve_config, model_names)
101
+ args_dict = _get_args_dict(
102
+ agent, retrieve_config, model_names, path_resolver
103
+ )
47
104
  if retrieve_config.use_custom_token_count:
48
- token_count_arg_name = f"custom_token_count_function_{agent_name}"
49
- before_the_args += (
50
- f"\ndef {token_count_arg_name}():\n"
51
- f"{retrieve_config.token_count_function_string}"
52
- "\n\n"
105
+ function_content, token_count_arg_name = (
106
+ retrieve_config.get_custom_token_count_function(
107
+ name_suffix=agent_name
108
+ )
53
109
  )
110
+ before_the_args += "\n" + function_content + "\n"
54
111
  args_dict["custom_token_count_function"] = token_count_arg_name
55
112
  if retrieve_config.use_custom_text_split:
56
- text_split_arg_name = f"custom_text_split_function_{agent_name}"
57
- before_the_args += (
58
- f"\ndef {text_split_arg_name}():\n"
59
- f"{retrieve_config.text_split_function_string}"
60
- "\n\n"
113
+ function_content, text_split_arg_name = (
114
+ retrieve_config.get_custom_text_split_function(
115
+ name_suffix=agent_name
116
+ )
61
117
  )
118
+ before_the_args += "\n" + function_content + "\n"
62
119
  args_dict["custom_text_split_function"] = text_split_arg_name
63
120
  # docs_path = args_dict.pop("docs_path", [])
64
- args_content = get_object_string(args_dict)
121
+ args_content = serializer(args_dict)
65
122
  # get the last line (where the dict ends)
66
123
  args_parts = args_content.split("\n")
67
124
  before_vector_db = args_parts[:-1]
68
125
  closing_arg = args_parts[-1]
69
126
  args_content = "\n".join(before_vector_db)
70
127
  # add the vector_db arg
71
- args_content += f',\n "vector_db": {vector_db_arg},\n'
128
+ args_content += ",\n" + f' "vector_db": {vector_db_arg},' + "\n"
72
129
  # we should not need to include the client, but let's do it
73
130
  # to avoid later issues (with telemetry or other client settings)
74
131
  # https://github.com/ag2ai/ag2/blob/main/autogen/agentchat/\
@@ -77,48 +134,11 @@ def get_rag_user_retrieve_config_str(
77
134
  f"{agent_name}_client" in before_the_args
78
135
  and agent.retrieve_config.vector_db == "chroma"
79
136
  ):
80
- args_content += f' "client": {agent_name}_client,\n'
137
+ args_content += f' "client": {agent_name}_client,' + "\n"
81
138
  args_content += closing_arg
82
139
  return before_the_args, args_content, imports
83
140
 
84
141
 
85
- def get_rag_user_extras(
86
- agent: WaldiezAgent,
87
- agent_name: str,
88
- model_names: Dict[str, str],
89
- ) -> Tuple[str, str, Set[str]]:
90
- """Get the RAG user extra argument, imports and content before the agent.
91
-
92
- Parameters
93
- ----------
94
- agent : WaldiezAgent
95
- The agent.
96
- agent_name : str
97
- The agent's name.
98
- model_names : Dict[str, str]
99
- A mapping from model id to model name.
100
-
101
- Returns
102
- -------
103
- Tuple[str, str, Set[str]]
104
- The content before the agent, the retrieve arg and the db imports.
105
- """
106
- before_agent_string = ""
107
- retrieve_arg = ""
108
- db_imports: Set[str] = set()
109
- if agent.agent_type == "rag_user" and isinstance(agent, WaldiezRagUser):
110
- rag_content_before_agent, retrieve_arg, db_imports = (
111
- get_rag_user_retrieve_config_str(
112
- agent=agent, agent_name=agent_name, model_names=model_names
113
- )
114
- )
115
- if retrieve_arg:
116
- retrieve_arg = f"\n retrieve_config={retrieve_arg},"
117
- if rag_content_before_agent:
118
- before_agent_string += rag_content_before_agent
119
- return before_agent_string, retrieve_arg, db_imports
120
-
121
-
122
142
  def _get_model_arg(
123
143
  agent: WaldiezRagUser,
124
144
  retrieve_config: WaldiezRagUserRetrieveConfig,
@@ -141,6 +161,7 @@ def _get_args_dict(
141
161
  agent: WaldiezRagUser,
142
162
  retrieve_config: WaldiezRagUserRetrieveConfig,
143
163
  model_names: Dict[str, str],
164
+ path_resolver: Callable[[str], str],
144
165
  ) -> Dict[str, Union[str, List[str]]]:
145
166
  model_arg = _get_model_arg(agent, retrieve_config, model_names)
146
167
  args_dict: Dict[str, Union[str, List[str]]] = {
@@ -160,12 +181,14 @@ def _get_args_dict(
160
181
  args_dict[arg] = getattr(retrieve_config, arg)
161
182
  docs_path: Union[str, List[str]] = []
162
183
  if retrieve_config.docs_path:
163
- docs_path = (
184
+ doc_paths = (
164
185
  retrieve_config.docs_path
165
186
  if isinstance(retrieve_config.docs_path, list)
166
187
  else [retrieve_config.docs_path]
167
188
  )
168
- docs_path = [get_path_string(path) for path in docs_path]
189
+ docs_path = [
190
+ item for item in [path_resolver(path) for path in doc_paths] if item
191
+ ]
169
192
  args_dict["docs_path"] = docs_path
170
193
  if docs_path:
171
194
  args_dict["docs_path"] = docs_path
@@ -1,7 +1,9 @@
1
- """Vector DB exporting utils for RAG user agents."""
2
-
1
+ # SPDX-License-Identifier: Apache-2.0.
2
+ # Copyright (c) 2024 - 2025 Waldiez and contributors.
3
3
  # flake8: noqa E501
4
4
  # pylint: disable=line-too-long
5
+ """Vector DB exporting utils for RAG user agents."""
6
+
5
7
  from typing import Any, Set, Tuple
6
8
 
7
9
  from waldiez.models import WaldiezRagUser
@@ -31,15 +33,15 @@ def _get_metadata_arg(
31
33
  if agent.retrieve_config.db_config.metadata:
32
34
  tab = " "
33
35
  indent = tab * 3
34
- metadata_arg += f"{indent}metadata={{\n"
36
+ metadata_arg += f"{indent}metadata={{" + "\n"
35
37
  for key, value in agent.retrieve_config.db_config.metadata.items():
36
38
  value_string: Any = f'"{value}"'
37
39
  if str(value).isdigit():
38
40
  value_string = int(value)
39
41
  elif str(value).replace(".", "").isdigit():
40
42
  value_string = float(value)
41
- metadata_arg += f'{indent} "{key}": {value_string},\n'
42
- metadata_arg += f"{indent}}},\n"
43
+ metadata_arg += f'{indent} "{key}": {value_string},' + "\n"
44
+ metadata_arg += f"{indent}}}," + "\n"
43
45
  return metadata_arg
44
46
 
45
47
 
@@ -109,12 +111,12 @@ def get_rag_user_vector_db_string(
109
111
  agent, agent_name
110
112
  )
111
113
  if content_before:
112
- before += f"\n{content_before}"
114
+ before += "\n" + f"{content_before}"
113
115
  if ef_body:
114
- before += f"\n{ef_body}\n"
116
+ before += "\n" + f"{ef_body}" + "\n"
115
117
  if db_imports:
116
118
  imports.update(db_imports)
117
119
  kwarg_string += _get_metadata_arg(agent)
118
- vdb_arg = f"{vdb_class}(\n"
120
+ vdb_arg = f"{vdb_class}(" + "\n"
119
121
  vdb_arg += kwarg_string + " )"
120
122
  return before, vdb_arg, imports