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
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
# SPDX-License-Identifier: Apache-2.0.
|
|
2
|
+
# Copyright (c) 2024 - 2025 Waldiez and contributors.
|
|
3
|
+
# pylint: disable=too-few-public-methods
|
|
4
|
+
"""Chat specific extras module."""
|
|
5
|
+
|
|
6
|
+
from dataclasses import dataclass
|
|
7
|
+
|
|
8
|
+
from ..enums import AgentPosition, ContentOrder, ExportPosition
|
|
9
|
+
from ..result import ExportResult
|
|
10
|
+
from .base import BaseExtras
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
@dataclass
|
|
14
|
+
class ChatExtras(BaseExtras):
|
|
15
|
+
"""Extras for chat exporters.
|
|
16
|
+
|
|
17
|
+
Attributes
|
|
18
|
+
----------
|
|
19
|
+
chat_definition : str
|
|
20
|
+
The chat definition content.
|
|
21
|
+
chat_initiation : str
|
|
22
|
+
The chat initiation content.
|
|
23
|
+
"""
|
|
24
|
+
|
|
25
|
+
chat_prerequisites: str = ""
|
|
26
|
+
chat_initiation: str = ""
|
|
27
|
+
chat_registration: str = ""
|
|
28
|
+
|
|
29
|
+
def set_chat_prerequisites(self, prerequisites: str) -> None:
|
|
30
|
+
"""Set the chat prerequisites.
|
|
31
|
+
|
|
32
|
+
Parameters
|
|
33
|
+
----------
|
|
34
|
+
prerequisites : str
|
|
35
|
+
The chat prerequisites content.
|
|
36
|
+
"""
|
|
37
|
+
self.chat_prerequisites = prerequisites
|
|
38
|
+
|
|
39
|
+
def set_chat_initiation(self, initiation: str) -> None:
|
|
40
|
+
"""Set the chat initiation.
|
|
41
|
+
|
|
42
|
+
Parameters
|
|
43
|
+
----------
|
|
44
|
+
initiation : str
|
|
45
|
+
The chat initiation content.
|
|
46
|
+
"""
|
|
47
|
+
self.chat_initiation = initiation
|
|
48
|
+
|
|
49
|
+
def set_chat_registration(self, registration: str) -> None:
|
|
50
|
+
"""Set the chat registration.
|
|
51
|
+
|
|
52
|
+
Parameters
|
|
53
|
+
----------
|
|
54
|
+
registration : str
|
|
55
|
+
The chat registration content.
|
|
56
|
+
"""
|
|
57
|
+
self.chat_registration = registration
|
|
58
|
+
|
|
59
|
+
def add_registration(self, registration: str) -> None:
|
|
60
|
+
"""Add chat registration content.
|
|
61
|
+
|
|
62
|
+
Parameters
|
|
63
|
+
----------
|
|
64
|
+
registration : str
|
|
65
|
+
The chat registration content.
|
|
66
|
+
"""
|
|
67
|
+
if registration and registration.strip():
|
|
68
|
+
self.chat_registration += "\n" + registration.strip() + "\n"
|
|
69
|
+
|
|
70
|
+
def has_specific_content(self) -> bool:
|
|
71
|
+
"""Check for chat specific content.
|
|
72
|
+
|
|
73
|
+
Returns
|
|
74
|
+
-------
|
|
75
|
+
bool
|
|
76
|
+
True if there's chat specific content.
|
|
77
|
+
"""
|
|
78
|
+
return bool(
|
|
79
|
+
self.chat_initiation.strip()
|
|
80
|
+
or self.chat_prerequisites.strip()
|
|
81
|
+
or self.chat_registration.strip()
|
|
82
|
+
)
|
|
83
|
+
|
|
84
|
+
def _contribute_specific_content(self, result: ExportResult) -> None:
|
|
85
|
+
"""Contribute chat specific content.
|
|
86
|
+
|
|
87
|
+
Parameters
|
|
88
|
+
----------
|
|
89
|
+
result : ExportResult
|
|
90
|
+
The export result to contribute to.
|
|
91
|
+
"""
|
|
92
|
+
# Chat prerequisites go before the chat definition
|
|
93
|
+
if self.chat_prerequisites:
|
|
94
|
+
result.add_content(
|
|
95
|
+
self.chat_prerequisites,
|
|
96
|
+
ExportPosition.AGENTS,
|
|
97
|
+
order=ContentOrder.LATE_CLEANUP,
|
|
98
|
+
skip_strip=True,
|
|
99
|
+
)
|
|
100
|
+
|
|
101
|
+
# Chat initiation goes inside "def main()"
|
|
102
|
+
if self.chat_initiation: # pragma: no branch
|
|
103
|
+
result.add_content(
|
|
104
|
+
self.chat_initiation,
|
|
105
|
+
ExportPosition.CHATS,
|
|
106
|
+
order=ContentOrder.MAIN_CONTENT,
|
|
107
|
+
skip_strip=True,
|
|
108
|
+
)
|
|
109
|
+
|
|
110
|
+
# Chat registration goes after all agents are defined
|
|
111
|
+
# (agent.register_nested_chat..))
|
|
112
|
+
if self.chat_registration: # pragma: no branch
|
|
113
|
+
result.add_content(
|
|
114
|
+
self.chat_registration,
|
|
115
|
+
ExportPosition.AGENTS,
|
|
116
|
+
agent_position=AgentPosition.AFTER_ALL,
|
|
117
|
+
order=ContentOrder.POST_CONTENT,
|
|
118
|
+
)
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
# SPDX-License-Identifier: Apache-2.0.
|
|
2
|
+
# Copyright (c) 2024 - 2025 Waldiez and contributors.
|
|
3
|
+
# pylint: disable=too-few-public-methods,too-many-instance-attributes
|
|
4
|
+
# flake8: noqa: E501
|
|
5
|
+
"""Flow specific extras module."""
|
|
6
|
+
|
|
7
|
+
from dataclasses import dataclass, field
|
|
8
|
+
from typing import Optional
|
|
9
|
+
|
|
10
|
+
# pylint: disable=import-error,line-too-long
|
|
11
|
+
# pyright: reportMissingImports=false
|
|
12
|
+
try:
|
|
13
|
+
from waldiez._version import __version__ as waldiez_version # type: ignore[unused-ignore, import-not-found, import-untyped] # noqa
|
|
14
|
+
except ImportError: # pragma: no cover
|
|
15
|
+
import warnings
|
|
16
|
+
|
|
17
|
+
# .gitingored (generated by hatch)
|
|
18
|
+
warnings.warn(
|
|
19
|
+
"Importing __version__ failed. Using 'dev' as version.",
|
|
20
|
+
stacklevel=2,
|
|
21
|
+
)
|
|
22
|
+
waldiez_version = "dev"
|
|
23
|
+
|
|
24
|
+
from ..result import ExportResult
|
|
25
|
+
from ..types import ExportConfig
|
|
26
|
+
from .base import BaseExtras
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
@dataclass
|
|
30
|
+
class FlowExtras(BaseExtras):
|
|
31
|
+
"""Extras for flow exporter."""
|
|
32
|
+
|
|
33
|
+
# Flow metadata
|
|
34
|
+
flow_name: str = ""
|
|
35
|
+
description: str = ""
|
|
36
|
+
config: ExportConfig = field(default_factory=ExportConfig)
|
|
37
|
+
version: str = waldiez_version # pyright: ignore
|
|
38
|
+
|
|
39
|
+
# Sub-exporter results
|
|
40
|
+
tools_result: Optional[ExportResult] = None
|
|
41
|
+
models_result: Optional[ExportResult] = None
|
|
42
|
+
agents_result: Optional[ExportResult] = None
|
|
43
|
+
chats_result: Optional[ExportResult] = None
|
|
44
|
+
|
|
45
|
+
# Generated script parts
|
|
46
|
+
header_content: str = ""
|
|
47
|
+
main_function: str = ""
|
|
48
|
+
after_run: str = ""
|
|
49
|
+
execution_code: str = ""
|
|
50
|
+
|
|
51
|
+
def has_specific_content(self) -> bool:
|
|
52
|
+
"""Check if the flow extras contain specific content.
|
|
53
|
+
|
|
54
|
+
Returns
|
|
55
|
+
-------
|
|
56
|
+
bool
|
|
57
|
+
True if any specific content is present, False otherwise.
|
|
58
|
+
"""
|
|
59
|
+
return bool(
|
|
60
|
+
self.flow_name
|
|
61
|
+
or self.description
|
|
62
|
+
or self.version
|
|
63
|
+
or self.tools_result
|
|
64
|
+
or self.models_result
|
|
65
|
+
or self.agents_result
|
|
66
|
+
or self.chats_result
|
|
67
|
+
or self.header_content
|
|
68
|
+
or self.main_function
|
|
69
|
+
or self.execution_code
|
|
70
|
+
)
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
# SPDX-License-Identifier: Apache-2.0.
|
|
2
|
+
# Copyright (c) 2024 - 2025 Waldiez and contributors.
|
|
3
|
+
# pylint: disable=too-few-public-methods
|
|
4
|
+
"""Agent specific extras module."""
|
|
5
|
+
|
|
6
|
+
from dataclasses import dataclass
|
|
7
|
+
from typing import Any, Optional
|
|
8
|
+
|
|
9
|
+
from waldiez.exporting.core.result import ExportResult
|
|
10
|
+
|
|
11
|
+
from ..enums import ContentOrder, ExportPosition
|
|
12
|
+
from .base import BaseExtras
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
@dataclass
|
|
16
|
+
class ModelExtras(BaseExtras):
|
|
17
|
+
"""Extras for model exporters."""
|
|
18
|
+
|
|
19
|
+
llm_config: Optional[dict[str, Any]] = None
|
|
20
|
+
config_file_path: str = ""
|
|
21
|
+
|
|
22
|
+
def set_llm_config(self, config: dict[str, Any]) -> None:
|
|
23
|
+
"""Set the LLM configuration.
|
|
24
|
+
|
|
25
|
+
Parameters
|
|
26
|
+
----------
|
|
27
|
+
config : dict[str, Any]
|
|
28
|
+
The LLM configuration.
|
|
29
|
+
"""
|
|
30
|
+
self.llm_config = config
|
|
31
|
+
|
|
32
|
+
def set_config_file_path(self, path: str) -> None:
|
|
33
|
+
"""Set the configuration file path.
|
|
34
|
+
|
|
35
|
+
Parameters
|
|
36
|
+
----------
|
|
37
|
+
path : str
|
|
38
|
+
The configuration file path.
|
|
39
|
+
"""
|
|
40
|
+
self.config_file_path = path
|
|
41
|
+
|
|
42
|
+
def get_content(self) -> str:
|
|
43
|
+
"""Get the content of the LLM configuration.
|
|
44
|
+
|
|
45
|
+
Returns
|
|
46
|
+
-------
|
|
47
|
+
str
|
|
48
|
+
The serialized LLM configuration.
|
|
49
|
+
"""
|
|
50
|
+
if self.llm_config and "content" in self.llm_config:
|
|
51
|
+
return self.llm_config["content"]
|
|
52
|
+
return ""
|
|
53
|
+
|
|
54
|
+
def has_specific_content(self) -> bool:
|
|
55
|
+
"""Check for model specific content.
|
|
56
|
+
|
|
57
|
+
Returns
|
|
58
|
+
-------
|
|
59
|
+
bool
|
|
60
|
+
True if there's model specific content.
|
|
61
|
+
"""
|
|
62
|
+
if self.llm_config and "content" in self.llm_config:
|
|
63
|
+
return bool(self.llm_config["content"])
|
|
64
|
+
return False
|
|
65
|
+
|
|
66
|
+
def _contribute_specific_content(self, result: ExportResult) -> None:
|
|
67
|
+
"""Contribute model-specific content to the export result."""
|
|
68
|
+
if self.llm_config and "content" in self.llm_config:
|
|
69
|
+
result.add_content(
|
|
70
|
+
self.llm_config["content"],
|
|
71
|
+
ExportPosition.MODELS,
|
|
72
|
+
order=ContentOrder.MAIN_CONTENT,
|
|
73
|
+
)
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
# SPDX-License-Identifier: Apache-2.0.
|
|
2
|
+
# Copyright (c) 2024 - 2025 Waldiez and contributors.
|
|
3
|
+
"""Default path resolver for Waldiez items."""
|
|
4
|
+
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
from typing import Optional, Union
|
|
7
|
+
|
|
8
|
+
from ..protocols import PathResolver
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
# pylint: disable=too-few-public-methods
|
|
12
|
+
class DefaultPathResolver(PathResolver):
|
|
13
|
+
"""Default path resolver for Waldiez items."""
|
|
14
|
+
|
|
15
|
+
def resolve(self, path: str) -> str:
|
|
16
|
+
"""Resolve a path to a local file system path.
|
|
17
|
+
|
|
18
|
+
Parameters
|
|
19
|
+
----------
|
|
20
|
+
path : Union[str, Path]
|
|
21
|
+
The path to resolve.
|
|
22
|
+
|
|
23
|
+
Returns
|
|
24
|
+
-------
|
|
25
|
+
Optional[Path]
|
|
26
|
+
The resolved local path or None if not found.
|
|
27
|
+
"""
|
|
28
|
+
resolved = _check_local_path(path)
|
|
29
|
+
if not resolved:
|
|
30
|
+
return _get_raw_path_string(path)
|
|
31
|
+
return _get_raw_path_string(resolved)
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def _check_local_path(string: str) -> Optional[Path]:
|
|
35
|
+
"""Check if a string is a local path.
|
|
36
|
+
|
|
37
|
+
Parameters
|
|
38
|
+
----------
|
|
39
|
+
string : str
|
|
40
|
+
The string to check.
|
|
41
|
+
|
|
42
|
+
Returns
|
|
43
|
+
-------
|
|
44
|
+
bool
|
|
45
|
+
True if the path is a local path.
|
|
46
|
+
"""
|
|
47
|
+
# pylint: disable=broad-exception-caught
|
|
48
|
+
try:
|
|
49
|
+
path = Path(string).resolve()
|
|
50
|
+
except BaseException: # pragma: no cover
|
|
51
|
+
return None
|
|
52
|
+
if path.exists():
|
|
53
|
+
return path
|
|
54
|
+
return None
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def _get_raw_path_string(path: Union[str, Path]) -> str:
|
|
58
|
+
"""Get the raw path string.
|
|
59
|
+
|
|
60
|
+
Parameters
|
|
61
|
+
----------
|
|
62
|
+
path : Union[str, Path]
|
|
63
|
+
The string to check.
|
|
64
|
+
|
|
65
|
+
Returns
|
|
66
|
+
-------
|
|
67
|
+
str
|
|
68
|
+
The raw path string.
|
|
69
|
+
"""
|
|
70
|
+
if not isinstance(path, str):
|
|
71
|
+
path = str(path)
|
|
72
|
+
while path.startswith('r"') and path.endswith('"'):
|
|
73
|
+
path = path[2:-1]
|
|
74
|
+
return f'r"{path}"'
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
# def get_path_string(path: str) -> str:
|
|
78
|
+
# """Get the path string.
|
|
79
|
+
|
|
80
|
+
# Parameters
|
|
81
|
+
# ----------
|
|
82
|
+
# path : str
|
|
83
|
+
# The string to check.
|
|
84
|
+
|
|
85
|
+
# Returns
|
|
86
|
+
# -------
|
|
87
|
+
# str
|
|
88
|
+
# The local path string.
|
|
89
|
+
# """
|
|
90
|
+
# resolved = _check_local_path(path)
|
|
91
|
+
# if not resolved:
|
|
92
|
+
# return _get_raw_path_string(path)
|
|
93
|
+
# return _get_raw_path_string(resolved)
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
# SPDX-License-Identifier: Apache-2.0.
|
|
2
|
+
# Copyright (c) 2024 - 2025 Waldiez and contributors.
|
|
3
|
+
# pyright: reportUnknownArgumentType=false,reportUnknownVariableType=false
|
|
4
|
+
"""serializer for converting items to formatted strings."""
|
|
5
|
+
|
|
6
|
+
import json
|
|
7
|
+
from typing import Any, Optional
|
|
8
|
+
|
|
9
|
+
from ..protocols import Serializer
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
# pylint: disable=too-few-public-methods
|
|
13
|
+
class DefaultSerializer(Serializer):
|
|
14
|
+
"""Default serializer for Waldiez items."""
|
|
15
|
+
|
|
16
|
+
def serialize(self, obj: Any, **kwargs: Any) -> str:
|
|
17
|
+
"""Serialize an item to a formatted string.
|
|
18
|
+
|
|
19
|
+
Parameters
|
|
20
|
+
----------
|
|
21
|
+
obj : Any
|
|
22
|
+
The item to serialize.
|
|
23
|
+
**kwargs : Any
|
|
24
|
+
Additional keyword arguments, such as `tabs` for indentation level.
|
|
25
|
+
|
|
26
|
+
Returns
|
|
27
|
+
-------
|
|
28
|
+
str
|
|
29
|
+
The serialized string representation of the item.
|
|
30
|
+
"""
|
|
31
|
+
tabs = kwargs.get("tabs", 1)
|
|
32
|
+
return serialize_item(obj, tabs)
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def serialize_item(
|
|
36
|
+
item: Any,
|
|
37
|
+
tabs: int = 1,
|
|
38
|
+
_visited: Optional[set[int]] = None,
|
|
39
|
+
) -> str:
|
|
40
|
+
"""Convert an item to a formatted string with given indentation.
|
|
41
|
+
|
|
42
|
+
Parameters
|
|
43
|
+
----------
|
|
44
|
+
item : Any
|
|
45
|
+
The item to convert.
|
|
46
|
+
tabs : int, optional
|
|
47
|
+
The number of tabs, by default 1.
|
|
48
|
+
|
|
49
|
+
Returns
|
|
50
|
+
-------
|
|
51
|
+
str
|
|
52
|
+
The formatted string.
|
|
53
|
+
|
|
54
|
+
Example
|
|
55
|
+
-------
|
|
56
|
+
```python
|
|
57
|
+
>>> obj = {"a": 1, "b": [1, 2, 3]}
|
|
58
|
+
>>> serialize_item(obj)
|
|
59
|
+
{
|
|
60
|
+
"a": 1,
|
|
61
|
+
"b": [
|
|
62
|
+
1,
|
|
63
|
+
2,
|
|
64
|
+
3
|
|
65
|
+
]
|
|
66
|
+
}
|
|
67
|
+
>>> obj = {"a": 1, "b": [1, 2, 3], "c": {"d": 4}}
|
|
68
|
+
>>> serialize_item(obj, 2)
|
|
69
|
+
{
|
|
70
|
+
"a": 1,
|
|
71
|
+
"b": [
|
|
72
|
+
1,
|
|
73
|
+
2,
|
|
74
|
+
3
|
|
75
|
+
],
|
|
76
|
+
"c": {
|
|
77
|
+
"d": 4
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
```
|
|
81
|
+
"""
|
|
82
|
+
if _visited is None:
|
|
83
|
+
_visited = set()
|
|
84
|
+
|
|
85
|
+
if callable(item):
|
|
86
|
+
return item.__name__
|
|
87
|
+
|
|
88
|
+
# Handle primitives and preformatted literals
|
|
89
|
+
if isinstance(item, (str, int, float, bool)) or item is None:
|
|
90
|
+
return _format_primitive(item)
|
|
91
|
+
|
|
92
|
+
# Handle circular references in containers
|
|
93
|
+
if isinstance(item, (dict, list)) and id(item) in _visited:
|
|
94
|
+
return '"<circular reference>"'
|
|
95
|
+
|
|
96
|
+
next_indent = " " * 4 * (tabs + 1)
|
|
97
|
+
_visited.add(id(item))
|
|
98
|
+
|
|
99
|
+
if isinstance(item, dict):
|
|
100
|
+
items: list[str] = []
|
|
101
|
+
for key, value in item.items():
|
|
102
|
+
key_str = f'{next_indent}"{key}"'
|
|
103
|
+
value_str = serialize_item(value, tabs + 1, _visited)
|
|
104
|
+
items.append(f"{key_str}: {value_str}")
|
|
105
|
+
return _format_container(items, "{", "}", tabs)
|
|
106
|
+
|
|
107
|
+
if isinstance(item, list):
|
|
108
|
+
items = [
|
|
109
|
+
f"{next_indent}{serialize_item(sub_item, tabs + 1, _visited)}"
|
|
110
|
+
for sub_item in item
|
|
111
|
+
]
|
|
112
|
+
return _format_container(items, "[", "]", tabs)
|
|
113
|
+
|
|
114
|
+
# Fallback for unknown object types
|
|
115
|
+
return repr(item)
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
def _format_primitive(item: Any) -> str:
|
|
119
|
+
"""Format a primitive or formatted literal for code-safe output."""
|
|
120
|
+
if isinstance(item, str):
|
|
121
|
+
if item.startswith("r'") or item.startswith('r"'):
|
|
122
|
+
return item
|
|
123
|
+
return json.dumps(item, ensure_ascii=False)
|
|
124
|
+
return str(item)
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
def _format_container(
|
|
128
|
+
items_list: list[str],
|
|
129
|
+
open_char: str,
|
|
130
|
+
close_char: str,
|
|
131
|
+
tabs: int,
|
|
132
|
+
) -> str:
|
|
133
|
+
"""Format containers consistently with indentation."""
|
|
134
|
+
indent = " " * 4 * tabs
|
|
135
|
+
if not items_list:
|
|
136
|
+
return f"{open_char}{close_char}"
|
|
137
|
+
items_string = ",\n".join(items_list)
|
|
138
|
+
return f"{open_char}\n{items_string}\n{indent}{close_char}"
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
# SPDX-License-Identifier: Apache-2.0.
|
|
2
|
+
# Copyright (c) 2024 - 2025 Waldiez and contributors.
|
|
3
|
+
"""Agent specific extras module."""
|
|
4
|
+
# pylint: disable=too-few-public-methods
|
|
5
|
+
|
|
6
|
+
from dataclasses import dataclass
|
|
7
|
+
|
|
8
|
+
from ..enums import ContentOrder, ExportPosition
|
|
9
|
+
from ..result import ExportResult
|
|
10
|
+
from .base import BaseExtras
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
@dataclass
|
|
14
|
+
class ToolExtras(BaseExtras):
|
|
15
|
+
"""Extras for tool exporters."""
|
|
16
|
+
|
|
17
|
+
function_content: str = ""
|
|
18
|
+
registration_content: str = ""
|
|
19
|
+
|
|
20
|
+
def add_function_content(self, content: str) -> None:
|
|
21
|
+
"""Add function definition content.
|
|
22
|
+
|
|
23
|
+
Parameters
|
|
24
|
+
----------
|
|
25
|
+
content : str
|
|
26
|
+
The function content to add.
|
|
27
|
+
"""
|
|
28
|
+
if content and content.strip(): # pragma: no branch
|
|
29
|
+
if self.function_content:
|
|
30
|
+
self.function_content += "\n\n" + content.rstrip()
|
|
31
|
+
else:
|
|
32
|
+
self.function_content = content.rstrip()
|
|
33
|
+
while not self.function_content.endswith("\n\n"):
|
|
34
|
+
self.function_content += "\n\n"
|
|
35
|
+
|
|
36
|
+
def add_registration_content(self, content: str) -> None:
|
|
37
|
+
"""Add function registration content.
|
|
38
|
+
|
|
39
|
+
Parameters
|
|
40
|
+
----------
|
|
41
|
+
content : str
|
|
42
|
+
The registration content to add.
|
|
43
|
+
"""
|
|
44
|
+
if content and content.strip(): # pragma: no branch
|
|
45
|
+
self.registration_content += "\n" + content.rstrip() + "\n"
|
|
46
|
+
|
|
47
|
+
def has_specific_content(self) -> bool:
|
|
48
|
+
"""Check for tool specific content.
|
|
49
|
+
|
|
50
|
+
Returns
|
|
51
|
+
-------
|
|
52
|
+
bool
|
|
53
|
+
True if there's tool specific content.
|
|
54
|
+
"""
|
|
55
|
+
return bool(
|
|
56
|
+
self.function_content.strip() or self.registration_content.strip()
|
|
57
|
+
)
|
|
58
|
+
|
|
59
|
+
def _contribute_specific_content(self, result: ExportResult) -> None:
|
|
60
|
+
"""Contribute tool specific content.
|
|
61
|
+
|
|
62
|
+
Parameters
|
|
63
|
+
----------
|
|
64
|
+
result : ExportResult
|
|
65
|
+
The export result to contribute to.
|
|
66
|
+
"""
|
|
67
|
+
# Function definitions go in TOOLS section
|
|
68
|
+
if self.function_content:
|
|
69
|
+
result.add_content(
|
|
70
|
+
self.function_content,
|
|
71
|
+
ExportPosition.TOOLS,
|
|
72
|
+
order=ContentOrder.PRE_CONTENT,
|
|
73
|
+
)
|
|
74
|
+
|
|
75
|
+
# Registration content goes after agents
|
|
76
|
+
if self.registration_content:
|
|
77
|
+
result.add_content(
|
|
78
|
+
self.registration_content,
|
|
79
|
+
ExportPosition.AGENTS,
|
|
80
|
+
# After agents but before handoffs
|
|
81
|
+
order=ContentOrder.CLEANUP,
|
|
82
|
+
)
|