waldiez 0.4.7__py3-none-any.whl → 0.4.9__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/__init__.py +5 -5
- waldiez/_version.py +1 -1
- waldiez/cli.py +97 -102
- waldiez/exporter.py +61 -19
- waldiez/exporting/__init__.py +25 -6
- waldiez/exporting/agent/__init__.py +7 -3
- waldiez/exporting/agent/code_execution.py +114 -0
- waldiez/exporting/agent/exporter.py +354 -0
- waldiez/exporting/agent/extras/__init__.py +15 -0
- waldiez/exporting/agent/extras/captain_agent_extras.py +315 -0
- waldiez/exporting/agent/extras/group/target.py +178 -0
- waldiez/exporting/agent/extras/group_manager_agent_extas.py +500 -0
- waldiez/exporting/agent/extras/group_member_extras.py +181 -0
- waldiez/exporting/agent/extras/handoffs/__init__.py +19 -0
- waldiez/exporting/agent/extras/handoffs/after_work.py +78 -0
- waldiez/exporting/agent/extras/handoffs/available.py +74 -0
- waldiez/exporting/agent/extras/handoffs/condition.py +158 -0
- waldiez/exporting/agent/extras/handoffs/handoff.py +171 -0
- waldiez/exporting/agent/extras/handoffs/target.py +189 -0
- waldiez/exporting/agent/extras/rag/__init__.py +10 -0
- waldiez/exporting/agent/{utils/rag_user/chroma_utils.py → extras/rag/chroma_extras.py} +37 -24
- waldiez/exporting/agent/{utils/rag_user/mongo_utils.py → extras/rag/mongo_extras.py} +10 -10
- waldiez/exporting/agent/{utils/rag_user/pgvector_utils.py → extras/rag/pgvector_extras.py} +13 -13
- waldiez/exporting/agent/{utils/rag_user/qdrant_utils.py → extras/rag/qdrant_extras.py} +13 -13
- waldiez/exporting/agent/{utils/rag_user/vector_db.py → extras/rag/vector_db_extras.py} +59 -46
- waldiez/exporting/agent/extras/rag_user_proxy_agent_extras.py +245 -0
- waldiez/exporting/agent/extras/reasoning_agent_extras.py +88 -0
- waldiez/exporting/agent/factory.py +95 -0
- waldiez/exporting/agent/processor.py +150 -0
- waldiez/exporting/agent/system_message.py +36 -0
- waldiez/exporting/agent/termination.py +50 -0
- waldiez/exporting/chats/__init__.py +7 -3
- waldiez/exporting/chats/exporter.py +97 -0
- waldiez/exporting/chats/factory.py +65 -0
- waldiez/exporting/chats/processor.py +226 -0
- waldiez/exporting/chats/utils/__init__.py +6 -5
- waldiez/exporting/chats/utils/common.py +11 -45
- waldiez/exporting/chats/utils/group.py +55 -0
- waldiez/exporting/chats/utils/nested.py +37 -52
- waldiez/exporting/chats/utils/sequential.py +72 -61
- waldiez/exporting/chats/utils/{single_chat.py → single.py} +48 -50
- waldiez/exporting/core/__init__.py +196 -0
- waldiez/exporting/core/constants.py +17 -0
- waldiez/exporting/core/content.py +69 -0
- waldiez/exporting/core/context.py +244 -0
- waldiez/exporting/core/enums.py +89 -0
- waldiez/exporting/core/errors.py +19 -0
- waldiez/exporting/core/exporter.py +390 -0
- waldiez/exporting/core/exporters.py +67 -0
- waldiez/exporting/core/extras/__init__.py +39 -0
- waldiez/exporting/core/extras/agent_extras/__init__.py +27 -0
- waldiez/exporting/core/extras/agent_extras/captain_extras.py +57 -0
- waldiez/exporting/core/extras/agent_extras/group_manager_extras.py +102 -0
- waldiez/exporting/core/extras/agent_extras/rag_user_extras.py +53 -0
- waldiez/exporting/core/extras/agent_extras/reasoning_extras.py +68 -0
- waldiez/exporting/core/extras/agent_extras/standard_extras.py +263 -0
- waldiez/exporting/core/extras/base.py +241 -0
- waldiez/exporting/core/extras/chat_extras.py +118 -0
- waldiez/exporting/core/extras/flow_extras.py +70 -0
- waldiez/exporting/core/extras/model_extras.py +73 -0
- waldiez/exporting/core/extras/path_resolver.py +93 -0
- waldiez/exporting/core/extras/serializer.py +138 -0
- waldiez/exporting/core/extras/tool_extras.py +82 -0
- waldiez/exporting/core/protocols.py +259 -0
- waldiez/exporting/core/result.py +705 -0
- waldiez/exporting/core/types.py +329 -0
- waldiez/exporting/core/utils/__init__.py +11 -0
- waldiez/exporting/core/utils/comment.py +33 -0
- waldiez/exporting/core/utils/llm_config.py +117 -0
- waldiez/exporting/core/validation.py +96 -0
- waldiez/exporting/flow/__init__.py +6 -2
- waldiez/exporting/flow/execution_generator.py +193 -0
- waldiez/exporting/flow/exporter.py +107 -0
- waldiez/exporting/flow/factory.py +94 -0
- waldiez/exporting/flow/file_generator.py +214 -0
- waldiez/exporting/flow/merger.py +387 -0
- waldiez/exporting/flow/orchestrator.py +411 -0
- waldiez/exporting/flow/utils/__init__.py +9 -36
- waldiez/exporting/flow/utils/common.py +206 -0
- waldiez/exporting/flow/utils/importing.py +373 -0
- waldiez/exporting/flow/utils/linting.py +200 -0
- waldiez/exporting/flow/utils/{logging_utils.py → logging.py} +23 -9
- waldiez/exporting/models/__init__.py +3 -1
- waldiez/exporting/models/exporter.py +233 -0
- waldiez/exporting/models/factory.py +66 -0
- waldiez/exporting/models/processor.py +139 -0
- waldiez/exporting/tools/__init__.py +11 -0
- waldiez/exporting/tools/exporter.py +207 -0
- waldiez/exporting/tools/factory.py +57 -0
- waldiez/exporting/tools/processor.py +248 -0
- waldiez/exporting/tools/registration.py +133 -0
- waldiez/io/__init__.py +128 -0
- waldiez/io/_ws.py +199 -0
- waldiez/io/models/__init__.py +60 -0
- waldiez/io/models/base.py +66 -0
- waldiez/io/models/constants.py +78 -0
- waldiez/io/models/content/__init__.py +23 -0
- waldiez/io/models/content/audio.py +43 -0
- waldiez/io/models/content/base.py +45 -0
- waldiez/io/models/content/file.py +43 -0
- waldiez/io/models/content/image.py +96 -0
- waldiez/io/models/content/text.py +37 -0
- waldiez/io/models/content/video.py +43 -0
- waldiez/io/models/user_input.py +269 -0
- waldiez/io/models/user_response.py +215 -0
- waldiez/io/mqtt.py +681 -0
- waldiez/io/redis.py +782 -0
- waldiez/io/structured.py +439 -0
- waldiez/io/utils.py +184 -0
- waldiez/io/ws.py +298 -0
- waldiez/logger.py +481 -0
- waldiez/models/__init__.py +108 -51
- waldiez/models/agents/__init__.py +34 -70
- waldiez/models/agents/agent/__init__.py +10 -4
- waldiez/models/agents/agent/agent.py +466 -65
- waldiez/models/agents/agent/agent_data.py +119 -47
- waldiez/models/agents/agent/agent_type.py +13 -2
- waldiez/models/agents/agent/code_execution.py +12 -12
- waldiez/models/agents/agent/human_input_mode.py +8 -0
- waldiez/models/agents/agent/{linked_skill.py → linked_tool.py} +7 -7
- waldiez/models/agents/agent/nested_chat.py +35 -7
- waldiez/models/agents/agent/termination_message.py +30 -22
- waldiez/models/agents/{swarm_agent → agent}/update_system_message.py +22 -22
- waldiez/models/agents/agents.py +58 -63
- waldiez/models/agents/assistant/assistant.py +4 -4
- waldiez/models/agents/assistant/assistant_data.py +13 -1
- waldiez/models/agents/{captain_agent → captain}/captain_agent.py +5 -5
- waldiez/models/agents/{captain_agent → captain}/captain_agent_data.py +5 -5
- waldiez/models/agents/extra_requirements.py +11 -16
- waldiez/models/agents/group_manager/group_manager.py +103 -13
- waldiez/models/agents/group_manager/group_manager_data.py +36 -14
- waldiez/models/agents/group_manager/speakers.py +77 -24
- waldiez/models/agents/{rag_user → rag_user_proxy}/__init__.py +16 -16
- waldiez/models/agents/rag_user_proxy/rag_user_proxy.py +64 -0
- waldiez/models/agents/{rag_user/rag_user_data.py → rag_user_proxy/rag_user_proxy_data.py} +6 -5
- waldiez/models/agents/{rag_user → rag_user_proxy}/retrieve_config.py +182 -114
- waldiez/models/agents/{rag_user → rag_user_proxy}/vector_db_config.py +13 -13
- waldiez/models/agents/reasoning/reasoning_agent.py +6 -6
- waldiez/models/agents/reasoning/reasoning_agent_data.py +110 -63
- waldiez/models/agents/reasoning/reasoning_agent_reason_config.py +38 -10
- waldiez/models/agents/user_proxy/user_proxy.py +11 -7
- waldiez/models/agents/user_proxy/user_proxy_data.py +2 -2
- waldiez/models/chat/__init__.py +2 -1
- waldiez/models/chat/chat.py +166 -87
- waldiez/models/chat/chat_data.py +99 -136
- waldiez/models/chat/chat_message.py +33 -23
- waldiez/models/chat/chat_nested.py +31 -30
- waldiez/models/chat/chat_summary.py +10 -8
- waldiez/models/common/__init__.py +52 -2
- waldiez/models/common/ag2_version.py +1 -1
- waldiez/models/common/base.py +38 -7
- waldiez/models/common/dict_utils.py +42 -17
- waldiez/models/common/handoff.py +459 -0
- waldiez/models/common/id_generator.py +19 -0
- waldiez/models/common/method_utils.py +130 -68
- waldiez/{exporting/base/utils → models/common}/naming.py +38 -61
- waldiez/models/common/waldiez_version.py +37 -0
- waldiez/models/flow/__init__.py +9 -2
- waldiez/models/flow/connection.py +18 -0
- waldiez/models/flow/flow.py +311 -215
- waldiez/models/flow/flow_data.py +207 -40
- waldiez/models/flow/info.py +85 -0
- waldiez/models/flow/naming.py +131 -0
- waldiez/models/model/__init__.py +7 -1
- waldiez/models/model/extra_requirements.py +3 -12
- waldiez/models/model/model.py +76 -21
- waldiez/models/model/model_data.py +108 -20
- waldiez/models/tool/__init__.py +16 -0
- waldiez/models/tool/extra_requirements.py +36 -0
- waldiez/models/{skill/skill.py → tool/tool.py} +88 -88
- waldiez/models/tool/tool_data.py +51 -0
- waldiez/models/tool/tool_type.py +8 -0
- waldiez/models/waldiez.py +97 -80
- waldiez/runner.py +115 -61
- waldiez/running/__init__.py +13 -7
- waldiez/running/environment.py +49 -68
- waldiez/running/gen_seq_diagram.py +16 -14
- waldiez/running/post_run.py +119 -0
- waldiez/running/pre_run.py +149 -0
- waldiez/running/util.py +134 -0
- waldiez/utils/__init__.py +2 -4
- waldiez/utils/cli_extras/jupyter.py +5 -3
- waldiez/utils/cli_extras/runner.py +6 -4
- waldiez/utils/cli_extras/studio.py +6 -4
- waldiez/utils/conflict_checker.py +15 -9
- waldiez/utils/flaml_warnings.py +5 -5
- waldiez/utils/version.py +47 -0
- {waldiez-0.4.7.dist-info → waldiez-0.4.9.dist-info}/METADATA +235 -91
- waldiez-0.4.9.dist-info/RECORD +203 -0
- waldiez/exporting/agent/agent_exporter.py +0 -297
- waldiez/exporting/agent/utils/__init__.py +0 -23
- waldiez/exporting/agent/utils/captain_agent.py +0 -263
- waldiez/exporting/agent/utils/code_execution.py +0 -65
- waldiez/exporting/agent/utils/group_manager.py +0 -220
- waldiez/exporting/agent/utils/rag_user/__init__.py +0 -7
- waldiez/exporting/agent/utils/rag_user/rag_user.py +0 -209
- waldiez/exporting/agent/utils/reasoning.py +0 -36
- waldiez/exporting/agent/utils/swarm_agent.py +0 -469
- waldiez/exporting/agent/utils/teachability.py +0 -41
- waldiez/exporting/agent/utils/termination_message.py +0 -44
- waldiez/exporting/base/__init__.py +0 -25
- waldiez/exporting/base/agent_position.py +0 -75
- waldiez/exporting/base/base_exporter.py +0 -118
- waldiez/exporting/base/export_position.py +0 -48
- waldiez/exporting/base/import_position.py +0 -23
- waldiez/exporting/base/mixin.py +0 -137
- waldiez/exporting/base/utils/__init__.py +0 -18
- waldiez/exporting/base/utils/comments.py +0 -96
- waldiez/exporting/base/utils/path_check.py +0 -68
- waldiez/exporting/base/utils/to_string.py +0 -84
- waldiez/exporting/chats/chats_exporter.py +0 -240
- waldiez/exporting/chats/utils/swarm.py +0 -210
- waldiez/exporting/flow/flow_exporter.py +0 -528
- waldiez/exporting/flow/utils/agent_utils.py +0 -204
- waldiez/exporting/flow/utils/chat_utils.py +0 -71
- waldiez/exporting/flow/utils/def_main.py +0 -77
- waldiez/exporting/flow/utils/flow_content.py +0 -202
- waldiez/exporting/flow/utils/flow_names.py +0 -116
- waldiez/exporting/flow/utils/importing_utils.py +0 -227
- waldiez/exporting/models/models_exporter.py +0 -199
- waldiez/exporting/models/utils.py +0 -174
- waldiez/exporting/skills/__init__.py +0 -9
- waldiez/exporting/skills/skills_exporter.py +0 -176
- waldiez/exporting/skills/utils.py +0 -369
- waldiez/models/agents/agent/teachability.py +0 -70
- waldiez/models/agents/rag_user/rag_user.py +0 -60
- waldiez/models/agents/swarm_agent/__init__.py +0 -50
- waldiez/models/agents/swarm_agent/after_work.py +0 -179
- waldiez/models/agents/swarm_agent/on_condition.py +0 -105
- waldiez/models/agents/swarm_agent/on_condition_available.py +0 -142
- waldiez/models/agents/swarm_agent/on_condition_target.py +0 -40
- waldiez/models/agents/swarm_agent/swarm_agent.py +0 -107
- waldiez/models/agents/swarm_agent/swarm_agent_data.py +0 -124
- waldiez/models/flow/utils.py +0 -232
- waldiez/models/skill/__init__.py +0 -16
- waldiez/models/skill/extra_requirements.py +0 -36
- waldiez/models/skill/skill_data.py +0 -53
- waldiez/models/skill/skill_type.py +0 -8
- waldiez/running/running.py +0 -369
- waldiez/utils/pysqlite3_checker.py +0 -308
- waldiez/utils/rdps_checker.py +0 -122
- waldiez-0.4.7.dist-info/RECORD +0 -149
- /waldiez/models/agents/{captain_agent → captain}/__init__.py +0 -0
- /waldiez/models/agents/{captain_agent → captain}/captain_agent_lib_entry.py +0 -0
- {waldiez-0.4.7.dist-info → waldiez-0.4.9.dist-info}/WHEEL +0 -0
- {waldiez-0.4.7.dist-info → waldiez-0.4.9.dist-info}/entry_points.txt +0 -0
- {waldiez-0.4.7.dist-info → waldiez-0.4.9.dist-info}/licenses/LICENSE +0 -0
- {waldiez-0.4.7.dist-info → waldiez-0.4.9.dist-info}/licenses/NOTICE.md +0 -0
|
@@ -1,528 +0,0 @@
|
|
|
1
|
-
# SPDX-License-Identifier: Apache-2.0.
|
|
2
|
-
# Copyright (c) 2024 - 2025 Waldiez and contributors.
|
|
3
|
-
"""Flow Exporter class.
|
|
4
|
-
|
|
5
|
-
- We gather all the exports (models, skills, agents, chats).
|
|
6
|
-
|
|
7
|
-
- We first add all the imports from the above exports.
|
|
8
|
-
- If we have skills, we include their imports.
|
|
9
|
-
(their files were generated when exporting the skills).
|
|
10
|
-
- Then, we write the all model configs.
|
|
11
|
-
- Next, we write the agent definitions
|
|
12
|
-
(using the `llm_config=...` argument from the model exports).
|
|
13
|
-
- If additional (nested_chats) are defined,
|
|
14
|
-
we write their registrations after all agents are defined.
|
|
15
|
-
- Next, we write the chat definitions
|
|
16
|
-
(using the agent names from the agent exports).
|
|
17
|
-
- If exporting to py,
|
|
18
|
-
we add the `run` function and the `def main()` to call the run function.
|
|
19
|
-
- If the flow is async, the `run` function is async.
|
|
20
|
-
"""
|
|
21
|
-
|
|
22
|
-
# flake8: noqa: E501
|
|
23
|
-
# pylint: disable=line-too-long
|
|
24
|
-
|
|
25
|
-
from functools import partial
|
|
26
|
-
from pathlib import Path
|
|
27
|
-
from typing import List, Optional, Tuple, Union
|
|
28
|
-
|
|
29
|
-
from waldiez.models import Waldiez, WaldiezAgent
|
|
30
|
-
|
|
31
|
-
from ..agent import AgentExporter
|
|
32
|
-
from ..base import (
|
|
33
|
-
AgentPosition,
|
|
34
|
-
AgentPositions,
|
|
35
|
-
BaseExporter,
|
|
36
|
-
ExporterMixin,
|
|
37
|
-
ExporterReturnType,
|
|
38
|
-
ExportPosition,
|
|
39
|
-
ExportPositions,
|
|
40
|
-
ImportPosition,
|
|
41
|
-
)
|
|
42
|
-
from ..chats import ChatsExporter
|
|
43
|
-
from ..models import ModelsExporter
|
|
44
|
-
from ..skills import SkillsExporter
|
|
45
|
-
from .utils import (
|
|
46
|
-
add_after_agent_content,
|
|
47
|
-
add_after_chat_content,
|
|
48
|
-
add_before_agent_content,
|
|
49
|
-
ensure_unique_names,
|
|
50
|
-
gather_agent_outputs,
|
|
51
|
-
gather_imports,
|
|
52
|
-
get_after_run_content,
|
|
53
|
-
get_def_main,
|
|
54
|
-
get_ipynb_content_start,
|
|
55
|
-
get_np_no_nep50_handle,
|
|
56
|
-
get_py_content_start,
|
|
57
|
-
get_sqlite_out,
|
|
58
|
-
get_start_logging,
|
|
59
|
-
get_stop_logging,
|
|
60
|
-
get_the_imports_string,
|
|
61
|
-
)
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
# pylint: disable=too-many-instance-attributes
|
|
65
|
-
class FlowExporter(BaseExporter, ExporterMixin):
|
|
66
|
-
"""Flow exporter."""
|
|
67
|
-
|
|
68
|
-
def __init__(
|
|
69
|
-
self,
|
|
70
|
-
waldiez: Waldiez,
|
|
71
|
-
for_notebook: bool,
|
|
72
|
-
output_dir: Optional[Union[str, Path]] = None,
|
|
73
|
-
) -> None:
|
|
74
|
-
"""Initialize the flow exporter."""
|
|
75
|
-
self.waldiez = waldiez
|
|
76
|
-
self.for_notebook = for_notebook
|
|
77
|
-
if output_dir is not None and not isinstance(output_dir, Path):
|
|
78
|
-
output_dir = Path(output_dir).resolve()
|
|
79
|
-
self.output_dir = output_dir
|
|
80
|
-
self.initialize()
|
|
81
|
-
|
|
82
|
-
def initialize(
|
|
83
|
-
self,
|
|
84
|
-
) -> None:
|
|
85
|
-
"""Get all the names in the flow.
|
|
86
|
-
|
|
87
|
-
We need to make sure that no duplicate names are used,
|
|
88
|
-
and that the names can be used as python variables.
|
|
89
|
-
"""
|
|
90
|
-
unique_names = ensure_unique_names(
|
|
91
|
-
self.waldiez,
|
|
92
|
-
self.get_valid_instance_name,
|
|
93
|
-
)
|
|
94
|
-
self.flow_name = unique_names["flow_name"]
|
|
95
|
-
self.agents = unique_names["agents"]
|
|
96
|
-
self.models = unique_names["models"]
|
|
97
|
-
self.skills = unique_names["skills"]
|
|
98
|
-
self.chats = unique_names["chats"]
|
|
99
|
-
self.agent_names = unique_names["agent_names"]
|
|
100
|
-
self.model_names = unique_names["model_names"]
|
|
101
|
-
self.skill_names = unique_names["skill_names"]
|
|
102
|
-
self.chat_names = unique_names["chat_names"]
|
|
103
|
-
|
|
104
|
-
def export_flow(self) -> ExporterReturnType:
|
|
105
|
-
"""Export the flow.
|
|
106
|
-
|
|
107
|
-
Returns
|
|
108
|
-
-------
|
|
109
|
-
ExporterReturnType
|
|
110
|
-
The exported flow.
|
|
111
|
-
"""
|
|
112
|
-
models_output = self.export_models()
|
|
113
|
-
skills_output = self.export_skills()
|
|
114
|
-
chats_output = self.export_chats()
|
|
115
|
-
env_vars = self.gather_environment_variables(
|
|
116
|
-
model_env_vars=models_output["environment_variables"],
|
|
117
|
-
skill_env_vars=skills_output["environment_variables"],
|
|
118
|
-
chat_env_vars=chats_output["environment_variables"],
|
|
119
|
-
)
|
|
120
|
-
before_export = self.gather_exports(
|
|
121
|
-
model_export=models_output["before_export"],
|
|
122
|
-
skill_export=skills_output["before_export"],
|
|
123
|
-
chat_export=chats_output["before_export"],
|
|
124
|
-
)
|
|
125
|
-
after_export = self.gather_exports(
|
|
126
|
-
model_export=models_output["after_export"],
|
|
127
|
-
skill_export=skills_output["after_export"],
|
|
128
|
-
chat_export=chats_output["after_export"],
|
|
129
|
-
)
|
|
130
|
-
# agents last (to make sure we have any needed arguments)
|
|
131
|
-
# like `llm_config=...` from the models
|
|
132
|
-
agents_output = self.export_agents(
|
|
133
|
-
before_export=before_export,
|
|
134
|
-
after_export=after_export,
|
|
135
|
-
)
|
|
136
|
-
imports = gather_imports(
|
|
137
|
-
model_imports=models_output["imports"],
|
|
138
|
-
skill_imports=skills_output["imports"],
|
|
139
|
-
chat_imports=chats_output["imports"],
|
|
140
|
-
agent_imports=agents_output["imports"],
|
|
141
|
-
)
|
|
142
|
-
if agents_output["environment_variables"]:
|
|
143
|
-
env_vars.extend(agents_output["environment_variables"])
|
|
144
|
-
if agents_output["before_export"]:
|
|
145
|
-
before_export.extend(agents_output["before_export"])
|
|
146
|
-
if agents_output["after_export"]:
|
|
147
|
-
after_export.extend(agents_output["after_export"])
|
|
148
|
-
all_imports = (
|
|
149
|
-
get_the_imports_string(imports, is_async=self.waldiez.is_async),
|
|
150
|
-
ImportPosition.LOCAL,
|
|
151
|
-
)
|
|
152
|
-
before_chats_export = chats_output["before_export"] or []
|
|
153
|
-
content_before_chats = [
|
|
154
|
-
x[0]
|
|
155
|
-
for x in before_chats_export
|
|
156
|
-
if isinstance(x[1], ExportPosition)
|
|
157
|
-
and x[1].position == ExportPositions.CHATS
|
|
158
|
-
]
|
|
159
|
-
before_chats = "\n".join(content_before_chats)
|
|
160
|
-
content = self.merge_exports(
|
|
161
|
-
imports=all_imports,
|
|
162
|
-
models_output=models_output["content"] or "",
|
|
163
|
-
skills_output=skills_output["content"] or "",
|
|
164
|
-
agents_content=agents_output["content"] or "",
|
|
165
|
-
chats_content=chats_output["content"] or "",
|
|
166
|
-
before_chats=before_chats,
|
|
167
|
-
)
|
|
168
|
-
return {
|
|
169
|
-
"content": content,
|
|
170
|
-
"imports": [all_imports],
|
|
171
|
-
"after_export": after_export,
|
|
172
|
-
"before_export": before_export,
|
|
173
|
-
"environment_variables": env_vars,
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
def merge_exports(
|
|
177
|
-
self,
|
|
178
|
-
imports: Tuple[str, ImportPosition],
|
|
179
|
-
models_output: str,
|
|
180
|
-
skills_output: str,
|
|
181
|
-
agents_content: str,
|
|
182
|
-
chats_content: str,
|
|
183
|
-
before_chats: str,
|
|
184
|
-
) -> str:
|
|
185
|
-
"""Merge all the export contents.
|
|
186
|
-
|
|
187
|
-
Parameters
|
|
188
|
-
----------
|
|
189
|
-
imports : Tuple[str, ImportPosition]
|
|
190
|
-
The imports.
|
|
191
|
-
models_output : str
|
|
192
|
-
The models output.
|
|
193
|
-
skills_output : str
|
|
194
|
-
The skills output.
|
|
195
|
-
agents_content : str
|
|
196
|
-
The agents content.
|
|
197
|
-
chats_content : str
|
|
198
|
-
The chats content.
|
|
199
|
-
before_chats : str
|
|
200
|
-
|
|
201
|
-
Returns
|
|
202
|
-
-------
|
|
203
|
-
str
|
|
204
|
-
The merged export contents.
|
|
205
|
-
"""
|
|
206
|
-
is_async = self.waldiez.is_async
|
|
207
|
-
cache_seed = self.waldiez.cache_seed
|
|
208
|
-
content = (
|
|
209
|
-
get_py_content_start(self.waldiez)
|
|
210
|
-
if not self.for_notebook
|
|
211
|
-
else get_ipynb_content_start(self.waldiez, comment=self.comment)
|
|
212
|
-
)
|
|
213
|
-
content += self.get_comment("imports", self.for_notebook) + "\n"
|
|
214
|
-
content += imports[0] + "\n"
|
|
215
|
-
content += get_np_no_nep50_handle() + "\n"
|
|
216
|
-
content += self.get_comment("logging", self.for_notebook) + "\n"
|
|
217
|
-
content += get_start_logging(is_async=is_async, tabs=0) + "\n"
|
|
218
|
-
content += "start_logging()\n\n"
|
|
219
|
-
if models_output:
|
|
220
|
-
content += self.get_comment("models", self.for_notebook) + "\n"
|
|
221
|
-
content += models_output + "\n"
|
|
222
|
-
if skills_output:
|
|
223
|
-
content += self.get_comment("skills", self.for_notebook) + "\n"
|
|
224
|
-
content += skills_output + "\n"
|
|
225
|
-
if agents_content:
|
|
226
|
-
content += self.get_comment("agents", self.for_notebook) + "\n"
|
|
227
|
-
content += agents_content + "\n"
|
|
228
|
-
if before_chats:
|
|
229
|
-
content += before_chats + "\n"
|
|
230
|
-
content += get_sqlite_out(is_async=is_async) + "\n"
|
|
231
|
-
content += get_stop_logging(tabs=0, is_async=is_async) + "\n"
|
|
232
|
-
content += self.get_comment("run", self.for_notebook) + "\n"
|
|
233
|
-
after_run = get_after_run_content(
|
|
234
|
-
waldiez=self.waldiez,
|
|
235
|
-
agent_names=self.agent_names,
|
|
236
|
-
tabs=0 if self.for_notebook else 1,
|
|
237
|
-
)
|
|
238
|
-
if self.for_notebook is False:
|
|
239
|
-
content += get_def_main(
|
|
240
|
-
chats_content,
|
|
241
|
-
after_run=after_run,
|
|
242
|
-
is_async=self.waldiez.is_async,
|
|
243
|
-
cache_seed=cache_seed,
|
|
244
|
-
)
|
|
245
|
-
else:
|
|
246
|
-
if chats_content.startswith("\n"):
|
|
247
|
-
chats_content = chats_content[1:]
|
|
248
|
-
content += (
|
|
249
|
-
"\n" + f"with Cache.disk(cache_seed={cache_seed}) as cache:"
|
|
250
|
-
"\n" + chats_content + "\n"
|
|
251
|
-
)
|
|
252
|
-
if is_async:
|
|
253
|
-
content += "await stop_logging()"
|
|
254
|
-
else:
|
|
255
|
-
content += "stop_logging()"
|
|
256
|
-
content += after_run
|
|
257
|
-
content = content.replace("\n\n\n\n", "\n\n\n")
|
|
258
|
-
return content
|
|
259
|
-
|
|
260
|
-
@staticmethod
|
|
261
|
-
def gather_environment_variables(
|
|
262
|
-
model_env_vars: Optional[List[Tuple[str, str]]],
|
|
263
|
-
skill_env_vars: Optional[List[Tuple[str, str]]],
|
|
264
|
-
chat_env_vars: Optional[List[Tuple[str, str]]],
|
|
265
|
-
) -> List[Tuple[str, str]]:
|
|
266
|
-
"""
|
|
267
|
-
Gather all the environment variables.
|
|
268
|
-
|
|
269
|
-
Parameters
|
|
270
|
-
----------
|
|
271
|
-
model_env_vars : Optional[List[Tuple[str, str]]]
|
|
272
|
-
The model environment variables.
|
|
273
|
-
skill_env_vars : Optional[List[Tuple[str, str]]]
|
|
274
|
-
The skill environment variables.
|
|
275
|
-
chat_env_vars : Optional[List[Tuple[str, str]]]
|
|
276
|
-
The chat environment variables.
|
|
277
|
-
|
|
278
|
-
Returns
|
|
279
|
-
-------
|
|
280
|
-
List[Tuple[str, str]]
|
|
281
|
-
The gathered environment variables.
|
|
282
|
-
"""
|
|
283
|
-
all_env_vars: List[Tuple[str, str]] = []
|
|
284
|
-
if model_env_vars:
|
|
285
|
-
all_env_vars.extend(model_env_vars)
|
|
286
|
-
if skill_env_vars:
|
|
287
|
-
all_env_vars.extend(skill_env_vars)
|
|
288
|
-
if chat_env_vars:
|
|
289
|
-
all_env_vars.extend(chat_env_vars)
|
|
290
|
-
return all_env_vars
|
|
291
|
-
|
|
292
|
-
@staticmethod
|
|
293
|
-
def gather_exports(
|
|
294
|
-
model_export: Optional[
|
|
295
|
-
List[Tuple[str, Union[ExportPosition, AgentPosition]]]
|
|
296
|
-
],
|
|
297
|
-
skill_export: Optional[
|
|
298
|
-
List[Tuple[str, Union[ExportPosition, AgentPosition]]]
|
|
299
|
-
],
|
|
300
|
-
chat_export: Optional[
|
|
301
|
-
List[Tuple[str, Union[ExportPosition, AgentPosition]]]
|
|
302
|
-
],
|
|
303
|
-
) -> List[Tuple[str, Union[ExportPosition, AgentPosition]]]:
|
|
304
|
-
"""Gather all (but agents) the before or after exports.
|
|
305
|
-
|
|
306
|
-
Parameters
|
|
307
|
-
----------
|
|
308
|
-
model_export : Optional[List[Tuple[str, Union[ExportPosition, AgentPosition]]]]
|
|
309
|
-
The model exports.
|
|
310
|
-
skill_export : Optional[List[Tuple[str, Union[ExportPosition, AgentPosition]]]]
|
|
311
|
-
The skill exports.
|
|
312
|
-
chat_export : Optional[List[Tuple[str, Union[ExportPosition, AgentPosition]]]]
|
|
313
|
-
The chat exports.
|
|
314
|
-
|
|
315
|
-
Returns
|
|
316
|
-
-------
|
|
317
|
-
List[Tuple[str, Union[ExportPosition, AgentPosition]]]
|
|
318
|
-
The gathered exports.
|
|
319
|
-
"""
|
|
320
|
-
all_exports: List[Tuple[str, Union[ExportPosition, AgentPosition]]] = []
|
|
321
|
-
if model_export:
|
|
322
|
-
all_exports.extend(model_export)
|
|
323
|
-
if skill_export:
|
|
324
|
-
all_exports.extend(skill_export)
|
|
325
|
-
if chat_export:
|
|
326
|
-
all_exports.extend(chat_export)
|
|
327
|
-
return all_exports
|
|
328
|
-
|
|
329
|
-
def export_models(self) -> ExporterReturnType:
|
|
330
|
-
"""Export the models.
|
|
331
|
-
|
|
332
|
-
Returns
|
|
333
|
-
-------
|
|
334
|
-
str
|
|
335
|
-
The exported models.
|
|
336
|
-
"""
|
|
337
|
-
exporter = ModelsExporter(
|
|
338
|
-
flow_name=self.flow_name,
|
|
339
|
-
agents=self.agents,
|
|
340
|
-
agent_names=self.agent_names,
|
|
341
|
-
models=self.models,
|
|
342
|
-
model_names=self.model_names,
|
|
343
|
-
for_notebook=self.for_notebook,
|
|
344
|
-
output_dir=self.output_dir,
|
|
345
|
-
cache_seed=self.waldiez.cache_seed,
|
|
346
|
-
)
|
|
347
|
-
return exporter.export()
|
|
348
|
-
|
|
349
|
-
def export_skills(self) -> ExporterReturnType:
|
|
350
|
-
"""Export the skills.
|
|
351
|
-
|
|
352
|
-
Returns
|
|
353
|
-
-------
|
|
354
|
-
str
|
|
355
|
-
The exported skills.
|
|
356
|
-
"""
|
|
357
|
-
exporter = SkillsExporter(
|
|
358
|
-
flow_name=self.flow_name,
|
|
359
|
-
agents=self.agents,
|
|
360
|
-
agent_names=self.agent_names,
|
|
361
|
-
skills=self.skills,
|
|
362
|
-
skill_names=self.skill_names,
|
|
363
|
-
output_dir=self.output_dir,
|
|
364
|
-
)
|
|
365
|
-
return exporter.export()
|
|
366
|
-
|
|
367
|
-
@staticmethod
|
|
368
|
-
def gather_agent_arguments(
|
|
369
|
-
before_export: List[Tuple[str, Union[ExportPosition, AgentPosition]]],
|
|
370
|
-
after_export: List[Tuple[str, Union[ExportPosition, AgentPosition]]],
|
|
371
|
-
) -> List[Tuple[str, AgentPosition]]:
|
|
372
|
-
"""Gather the agent arguments.
|
|
373
|
-
|
|
374
|
-
Parameters
|
|
375
|
-
----------
|
|
376
|
-
before_export : List[Tuple[str, Union[ExportPosition, AgentPosition]]]
|
|
377
|
-
The before export.
|
|
378
|
-
after_export : List[Tuple[str, Union[ExportPosition, AgentPosition]]]
|
|
379
|
-
The after export.
|
|
380
|
-
|
|
381
|
-
Returns
|
|
382
|
-
-------
|
|
383
|
-
List[Tuple[str, AgentPosition]]
|
|
384
|
-
The gathered agent arguments.
|
|
385
|
-
"""
|
|
386
|
-
exported_with_agent_arg: List[Tuple[str, AgentPosition]] = []
|
|
387
|
-
for before in before_export:
|
|
388
|
-
position = before[1]
|
|
389
|
-
if (
|
|
390
|
-
isinstance(position, AgentPosition)
|
|
391
|
-
and position.position == AgentPositions.AS_ARGUMENT
|
|
392
|
-
):
|
|
393
|
-
exported_with_agent_arg.append((before[0], position))
|
|
394
|
-
for after in after_export:
|
|
395
|
-
position = after[1]
|
|
396
|
-
if (
|
|
397
|
-
isinstance(position, AgentPosition)
|
|
398
|
-
and position.position == AgentPositions.AS_ARGUMENT
|
|
399
|
-
):
|
|
400
|
-
exported_with_agent_arg.append((after[0], position))
|
|
401
|
-
return exported_with_agent_arg
|
|
402
|
-
|
|
403
|
-
def export_agents(
|
|
404
|
-
self,
|
|
405
|
-
before_export: List[Tuple[str, Union[ExportPosition, AgentPosition]]],
|
|
406
|
-
after_export: List[Tuple[str, Union[ExportPosition, AgentPosition]]],
|
|
407
|
-
) -> ExporterReturnType:
|
|
408
|
-
"""Export the agents.
|
|
409
|
-
|
|
410
|
-
Parameters
|
|
411
|
-
----------
|
|
412
|
-
before_export : List[Tuple[str, Union[ExportPosition, AgentPosition]]]
|
|
413
|
-
The before export.
|
|
414
|
-
after_export : List[Tuple[str, Union[ExportPosition, AgentPosition]]]
|
|
415
|
-
The after export.
|
|
416
|
-
|
|
417
|
-
Returns
|
|
418
|
-
-------
|
|
419
|
-
str
|
|
420
|
-
The exported agents.
|
|
421
|
-
"""
|
|
422
|
-
agent_outputs = []
|
|
423
|
-
for agent in self.agents:
|
|
424
|
-
exported_with_agent_arg = self.gather_agent_arguments(
|
|
425
|
-
before_export, after_export
|
|
426
|
-
)
|
|
427
|
-
arguments_resolver = partial(
|
|
428
|
-
self.agent_arguments_resolver,
|
|
429
|
-
exported_with_agent_arg,
|
|
430
|
-
)
|
|
431
|
-
group_chat_members = self.waldiez.get_group_chat_members(agent)
|
|
432
|
-
exporter = AgentExporter(
|
|
433
|
-
agent=agent,
|
|
434
|
-
agent_names=self.agent_names,
|
|
435
|
-
models=(self.models, self.model_names),
|
|
436
|
-
chats=(self.chats, self.chat_names),
|
|
437
|
-
skill_names=self.skill_names,
|
|
438
|
-
is_async=self.waldiez.is_async,
|
|
439
|
-
for_notebook=self.for_notebook,
|
|
440
|
-
output_dir=self.output_dir,
|
|
441
|
-
group_chat_members=group_chat_members,
|
|
442
|
-
arguments_resolver=arguments_resolver,
|
|
443
|
-
)
|
|
444
|
-
agent_output = exporter.export()
|
|
445
|
-
agent_content = agent_output["content"] or ""
|
|
446
|
-
after_agent_export = agent_output["after_export"]
|
|
447
|
-
if after_agent_export:
|
|
448
|
-
after_export.extend(after_agent_export)
|
|
449
|
-
before_agent_export = agent_output["before_export"]
|
|
450
|
-
if before_agent_export:
|
|
451
|
-
before_export.extend(before_agent_export)
|
|
452
|
-
if agent_content:
|
|
453
|
-
agent_content = add_before_agent_content(
|
|
454
|
-
agent_content,
|
|
455
|
-
before_export,
|
|
456
|
-
agent,
|
|
457
|
-
)
|
|
458
|
-
agent_content = add_after_agent_content(
|
|
459
|
-
agent_content,
|
|
460
|
-
after_export,
|
|
461
|
-
agent,
|
|
462
|
-
)
|
|
463
|
-
agent_output["content"] = agent_content
|
|
464
|
-
agent_outputs.append(agent_output)
|
|
465
|
-
return gather_agent_outputs(
|
|
466
|
-
before_export=before_export,
|
|
467
|
-
after_export=after_export,
|
|
468
|
-
agent_outputs=agent_outputs,
|
|
469
|
-
)
|
|
470
|
-
|
|
471
|
-
@staticmethod
|
|
472
|
-
def agent_arguments_resolver(
|
|
473
|
-
additional_exports: List[Tuple[str, AgentPosition]], agent: WaldiezAgent
|
|
474
|
-
) -> List[str]:
|
|
475
|
-
"""Resolve the arguments for the agent.
|
|
476
|
-
|
|
477
|
-
Parameters
|
|
478
|
-
----------
|
|
479
|
-
additional_exports : List[Tuple[str, AgentPosition]]
|
|
480
|
-
The additional exports.
|
|
481
|
-
agent : WaldiezAgent
|
|
482
|
-
The agent.
|
|
483
|
-
|
|
484
|
-
Returns
|
|
485
|
-
-------
|
|
486
|
-
List[str]
|
|
487
|
-
The arguments for the agent.
|
|
488
|
-
"""
|
|
489
|
-
return [x[0] for x in additional_exports if x[1].agent == agent]
|
|
490
|
-
|
|
491
|
-
def export_chats(self) -> ExporterReturnType:
|
|
492
|
-
"""Export the chats.
|
|
493
|
-
|
|
494
|
-
Returns
|
|
495
|
-
-------
|
|
496
|
-
str
|
|
497
|
-
The exported chats.
|
|
498
|
-
"""
|
|
499
|
-
exporter = ChatsExporter(
|
|
500
|
-
get_swarm_members=self.waldiez.get_swarm_members,
|
|
501
|
-
all_agents=self.agents,
|
|
502
|
-
agent_names=self.agent_names,
|
|
503
|
-
all_chats=self.chats,
|
|
504
|
-
chat_names=self.chat_names,
|
|
505
|
-
main_chats=self.waldiez.chats,
|
|
506
|
-
for_notebook=self.for_notebook,
|
|
507
|
-
is_async=self.waldiez.is_async,
|
|
508
|
-
)
|
|
509
|
-
output = exporter.export()
|
|
510
|
-
chat_contents = output["content"] or ""
|
|
511
|
-
after_chats = output["after_export"]
|
|
512
|
-
if chat_contents and after_chats:
|
|
513
|
-
chat_contents = add_after_chat_content(
|
|
514
|
-
chat_contents,
|
|
515
|
-
after_chats,
|
|
516
|
-
)
|
|
517
|
-
output["content"] = chat_contents
|
|
518
|
-
return output
|
|
519
|
-
|
|
520
|
-
def export(self) -> ExporterReturnType:
|
|
521
|
-
"""Export the flow.
|
|
522
|
-
|
|
523
|
-
Returns
|
|
524
|
-
-------
|
|
525
|
-
SubExporterReturnType
|
|
526
|
-
The exported flow.
|
|
527
|
-
"""
|
|
528
|
-
return self.export_flow()
|