waldiez 0.4.6__py3-none-any.whl → 0.4.8__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 +112 -73
- 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} +16 -15
- 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 +419 -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 +114 -49
- waldiez/running/__init__.py +1 -1
- waldiez/running/environment.py +49 -68
- waldiez/running/gen_seq_diagram.py +16 -14
- waldiez/running/running.py +53 -34
- waldiez/utils/__init__.py +0 -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-0.4.6.dist-info → waldiez-0.4.8.dist-info}/METADATA +235 -91
- waldiez-0.4.8.dist-info/RECORD +200 -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/utils/pysqlite3_checker.py +0 -308
- waldiez/utils/rdps_checker.py +0 -122
- waldiez-0.4.6.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.6.dist-info → waldiez-0.4.8.dist-info}/WHEEL +0 -0
- {waldiez-0.4.6.dist-info → waldiez-0.4.8.dist-info}/entry_points.txt +0 -0
- {waldiez-0.4.6.dist-info → waldiez-0.4.8.dist-info}/licenses/LICENSE +0 -0
- {waldiez-0.4.6.dist-info → waldiez-0.4.8.dist-info}/licenses/NOTICE.md +0 -0
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
# SPDX-License-Identifier: Apache-2.0.
|
|
2
|
+
# Copyright (c) 2024 - 2025 Waldiez and contributors.
|
|
3
|
+
"""Chats exporter."""
|
|
4
|
+
|
|
5
|
+
from typing import Any, Optional
|
|
6
|
+
|
|
7
|
+
from waldiez.models import (
|
|
8
|
+
WaldiezAgent,
|
|
9
|
+
WaldiezAgentConnection,
|
|
10
|
+
WaldiezChat,
|
|
11
|
+
WaldiezGroupManager,
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
from ..core import ChatExtras, Exporter, ExporterContext
|
|
15
|
+
from .processor import ChatsProcessor
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class ChatsExporter(Exporter[ChatExtras]):
|
|
19
|
+
"""Chats exporter with structured extras."""
|
|
20
|
+
|
|
21
|
+
def __init__(
|
|
22
|
+
self,
|
|
23
|
+
all_agents: list[WaldiezAgent],
|
|
24
|
+
agent_names: dict[str, str],
|
|
25
|
+
all_chats: list[WaldiezChat],
|
|
26
|
+
chat_names: dict[str, str],
|
|
27
|
+
main_chats: list[WaldiezAgentConnection],
|
|
28
|
+
root_group_manager: Optional[WaldiezGroupManager],
|
|
29
|
+
context: Optional[ExporterContext] = None,
|
|
30
|
+
**kwargs: Any,
|
|
31
|
+
) -> None:
|
|
32
|
+
"""Initialize the chats exporter.
|
|
33
|
+
|
|
34
|
+
Parameters
|
|
35
|
+
----------
|
|
36
|
+
all_agents : list[WaldiezAgent]
|
|
37
|
+
All agents involved in the chats.
|
|
38
|
+
agent_names : dict[str, str]
|
|
39
|
+
Mapping of agent IDs to their names.
|
|
40
|
+
all_chats : list[WaldiezChat]
|
|
41
|
+
All chats to be exported.
|
|
42
|
+
chat_names : dict[str, str]
|
|
43
|
+
Mapping of chat IDs to their names.
|
|
44
|
+
main_chats : list[WaldiezAgentConnection]
|
|
45
|
+
Main chats that are connections between agents.
|
|
46
|
+
root_group_manager : Optional[WaldiezGroupManager]
|
|
47
|
+
The root group manager for managing chat groups, if any.
|
|
48
|
+
context : Optional[ExporterContext], optional
|
|
49
|
+
Exporter context with dependencies, by default None
|
|
50
|
+
**kwargs : Any
|
|
51
|
+
Additional keyword arguments for the exporter.
|
|
52
|
+
"""
|
|
53
|
+
super().__init__(context, **kwargs)
|
|
54
|
+
|
|
55
|
+
self.all_agents = all_agents
|
|
56
|
+
self.agent_names = agent_names
|
|
57
|
+
self.all_chats = all_chats
|
|
58
|
+
self.chat_names = chat_names
|
|
59
|
+
self.main_chats = main_chats
|
|
60
|
+
self.root_group_manager = root_group_manager
|
|
61
|
+
config = self.context.get_config()
|
|
62
|
+
self.for_notebook = config.for_notebook
|
|
63
|
+
self.is_async = config.is_async
|
|
64
|
+
self.cache_seed = config.cache_seed
|
|
65
|
+
# Initialize extras with processed chat content
|
|
66
|
+
self._extras = self._create_chat_extras()
|
|
67
|
+
|
|
68
|
+
@property
|
|
69
|
+
def extras(self) -> ChatExtras:
|
|
70
|
+
"""Get the chat extras."""
|
|
71
|
+
return self._extras
|
|
72
|
+
|
|
73
|
+
# pylint: disable=no-self-use
|
|
74
|
+
def _create_chat_extras(self) -> ChatExtras:
|
|
75
|
+
"""Create and populate chat extras."""
|
|
76
|
+
extras = ChatExtras("chats")
|
|
77
|
+
processor = ChatsProcessor(
|
|
78
|
+
all_agents=self.all_agents,
|
|
79
|
+
agent_names=self.agent_names,
|
|
80
|
+
all_chats=self.all_chats,
|
|
81
|
+
chat_names=self.chat_names,
|
|
82
|
+
main_chats=self.main_chats,
|
|
83
|
+
root_group_manager=self.root_group_manager,
|
|
84
|
+
for_notebook=self.for_notebook,
|
|
85
|
+
is_async=self.is_async,
|
|
86
|
+
cache_seed=self.cache_seed,
|
|
87
|
+
serializer=self.context.get_serializer(),
|
|
88
|
+
extras=extras,
|
|
89
|
+
)
|
|
90
|
+
processor.process()
|
|
91
|
+
if extras.chat_registration:
|
|
92
|
+
extras.append_after_all_agents(extras.chat_registration)
|
|
93
|
+
return extras
|
|
94
|
+
|
|
95
|
+
def generate_main_content(self) -> Optional[str]:
|
|
96
|
+
"""Generate the main content of the export."""
|
|
97
|
+
return None
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
# SPDX-License-Identifier: Apache-2.0.
|
|
2
|
+
# Copyright (c) 2024 - 2025 Waldiez and contributors.
|
|
3
|
+
"""Factory function for creating a ChatsExporter instance."""
|
|
4
|
+
|
|
5
|
+
from typing import Any, Optional
|
|
6
|
+
|
|
7
|
+
from waldiez.models import (
|
|
8
|
+
WaldiezAgent,
|
|
9
|
+
WaldiezAgentConnection,
|
|
10
|
+
WaldiezChat,
|
|
11
|
+
WaldiezGroupManager,
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
from ..core import ExporterContext, get_default_exporter_context
|
|
15
|
+
from .exporter import ChatsExporter
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def create_chats_exporter(
|
|
19
|
+
all_agents: list[WaldiezAgent],
|
|
20
|
+
agent_names: dict[str, str],
|
|
21
|
+
all_chats: list[WaldiezChat],
|
|
22
|
+
chat_names: dict[str, str],
|
|
23
|
+
main_chats: list[WaldiezAgentConnection],
|
|
24
|
+
root_group_manager: Optional[WaldiezGroupManager] = None,
|
|
25
|
+
context: Optional[ExporterContext] = None,
|
|
26
|
+
**kwargs: Any,
|
|
27
|
+
) -> ChatsExporter:
|
|
28
|
+
"""Create a chats exporter.
|
|
29
|
+
|
|
30
|
+
Parameters
|
|
31
|
+
----------
|
|
32
|
+
all_agents : list[WaldiezAgent]
|
|
33
|
+
All agents involved in the chats.
|
|
34
|
+
agent_names : dict[str, str]
|
|
35
|
+
Mapping of agent IDs to their names.
|
|
36
|
+
all_chats : list[WaldiezChat]
|
|
37
|
+
All chats to be exported.
|
|
38
|
+
chat_names : dict[str, str]
|
|
39
|
+
Mapping of chat IDs to their names.
|
|
40
|
+
main_chats : list[WaldiezAgentConnection]
|
|
41
|
+
Main chats that are connections between agents.
|
|
42
|
+
root_group_manager : Optional[WaldiezGroupManager], optional
|
|
43
|
+
The root group manager for managing chat groups, if any.
|
|
44
|
+
context : Optional[ExporterContext], optional
|
|
45
|
+
Exporter context with dependencies, by default None
|
|
46
|
+
**kwargs : Any
|
|
47
|
+
Additional keyword arguments for the exporter.
|
|
48
|
+
|
|
49
|
+
Returns
|
|
50
|
+
-------
|
|
51
|
+
ChatsExporter
|
|
52
|
+
The created chats exporter.
|
|
53
|
+
"""
|
|
54
|
+
if context is None:
|
|
55
|
+
context = get_default_exporter_context()
|
|
56
|
+
return ChatsExporter(
|
|
57
|
+
all_agents=all_agents,
|
|
58
|
+
agent_names=agent_names,
|
|
59
|
+
all_chats=all_chats,
|
|
60
|
+
chat_names=chat_names,
|
|
61
|
+
main_chats=main_chats,
|
|
62
|
+
root_group_manager=root_group_manager,
|
|
63
|
+
context=context,
|
|
64
|
+
**kwargs,
|
|
65
|
+
)
|
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
# SPDX-License-Identifier: Apache-2.0.
|
|
2
|
+
# Copyright (c) 2024 - 2025 Waldiez and contributors.
|
|
3
|
+
"""Chats processor."""
|
|
4
|
+
|
|
5
|
+
from dataclasses import dataclass
|
|
6
|
+
from typing import Optional
|
|
7
|
+
|
|
8
|
+
from waldiez.models import (
|
|
9
|
+
WaldiezAgent,
|
|
10
|
+
WaldiezAgentConnection,
|
|
11
|
+
WaldiezChat,
|
|
12
|
+
WaldiezGroupManager,
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
from ..core import (
|
|
16
|
+
ChatExtras,
|
|
17
|
+
ImportPosition,
|
|
18
|
+
ImportStatement,
|
|
19
|
+
Serializer,
|
|
20
|
+
)
|
|
21
|
+
from .utils import (
|
|
22
|
+
export_group_chats,
|
|
23
|
+
export_nested_chat_registration,
|
|
24
|
+
export_sequential_chat,
|
|
25
|
+
export_single_chat,
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
@dataclass
|
|
30
|
+
class ChatParams:
|
|
31
|
+
"""Parameters for the chat export processor."""
|
|
32
|
+
|
|
33
|
+
main: list[WaldiezAgentConnection]
|
|
34
|
+
"""Main chats that are connections between agents."""
|
|
35
|
+
all: list[WaldiezChat]
|
|
36
|
+
"""All the chats in the flow."""
|
|
37
|
+
names: dict[str, str]
|
|
38
|
+
"""Mapping of chat IDs to their names."""
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
# pylint: disable=too-many-arguments,too-many-positional-arguments
|
|
42
|
+
class ChatsProcessor:
|
|
43
|
+
"""Processor for chats export."""
|
|
44
|
+
|
|
45
|
+
def __init__(
|
|
46
|
+
self,
|
|
47
|
+
all_agents: list[WaldiezAgent],
|
|
48
|
+
agent_names: dict[str, str],
|
|
49
|
+
all_chats: list[WaldiezChat],
|
|
50
|
+
chat_names: dict[str, str],
|
|
51
|
+
main_chats: list[WaldiezAgentConnection],
|
|
52
|
+
root_group_manager: Optional[WaldiezGroupManager],
|
|
53
|
+
for_notebook: bool,
|
|
54
|
+
is_async: bool,
|
|
55
|
+
cache_seed: Optional[int],
|
|
56
|
+
serializer: Serializer,
|
|
57
|
+
extras: ChatExtras,
|
|
58
|
+
) -> None:
|
|
59
|
+
"""Initialize the chats processor.
|
|
60
|
+
|
|
61
|
+
Parameters
|
|
62
|
+
----------
|
|
63
|
+
extras : ChatExtras
|
|
64
|
+
The structured extras for the chats export.
|
|
65
|
+
"""
|
|
66
|
+
self._all_agents = all_agents
|
|
67
|
+
self._agent_names = agent_names
|
|
68
|
+
self._chats = ChatParams(
|
|
69
|
+
main=main_chats,
|
|
70
|
+
all=all_chats,
|
|
71
|
+
names=chat_names,
|
|
72
|
+
)
|
|
73
|
+
self._root_group_manager = root_group_manager
|
|
74
|
+
self._is_async = is_async
|
|
75
|
+
self._for_notebook = for_notebook
|
|
76
|
+
self._cache_seed = cache_seed
|
|
77
|
+
self._serializer = serializer
|
|
78
|
+
self._extras = extras
|
|
79
|
+
chat_tabs = 1
|
|
80
|
+
if cache_seed is not None:
|
|
81
|
+
chat_tabs += 1
|
|
82
|
+
self._chat_tabs = chat_tabs
|
|
83
|
+
|
|
84
|
+
def is_group_patterned(self) -> bool:
|
|
85
|
+
"""Check if the chats are group patterned.
|
|
86
|
+
|
|
87
|
+
Returns
|
|
88
|
+
-------
|
|
89
|
+
bool
|
|
90
|
+
True if the chats are group patterned, False otherwise.
|
|
91
|
+
"""
|
|
92
|
+
if len(self._chats.main) == 0 and self._root_group_manager is not None:
|
|
93
|
+
return True
|
|
94
|
+
if len(self._chats.main) == 1:
|
|
95
|
+
main_chat = self._chats.main[0]
|
|
96
|
+
sender = main_chat["source"]
|
|
97
|
+
recipient = main_chat["target"]
|
|
98
|
+
if recipient.is_group_manager or sender.is_group_member:
|
|
99
|
+
return True
|
|
100
|
+
return False
|
|
101
|
+
|
|
102
|
+
def process(self) -> None:
|
|
103
|
+
"""Process the chats export."""
|
|
104
|
+
self._gather_imports()
|
|
105
|
+
self._handle_chat_registrations()
|
|
106
|
+
chat_initiation = self._generate_chat_initation()
|
|
107
|
+
self._extras.set_chat_initiation(chat_initiation)
|
|
108
|
+
|
|
109
|
+
def _generate_chat_initation(self) -> str:
|
|
110
|
+
"""Generate the chat definition string.
|
|
111
|
+
|
|
112
|
+
Returns
|
|
113
|
+
-------
|
|
114
|
+
str
|
|
115
|
+
The chat definition string.
|
|
116
|
+
"""
|
|
117
|
+
if len(self._chats.main) == 0:
|
|
118
|
+
if not self._root_group_manager:
|
|
119
|
+
return ""
|
|
120
|
+
return export_group_chats(
|
|
121
|
+
agent_names=self._agent_names,
|
|
122
|
+
manager=self._root_group_manager,
|
|
123
|
+
intial_chat=None,
|
|
124
|
+
tabs=self._chat_tabs,
|
|
125
|
+
is_async=self._is_async,
|
|
126
|
+
)
|
|
127
|
+
if len(self._chats.main) == 1:
|
|
128
|
+
main_chat = self._chats.main[0]
|
|
129
|
+
chat = main_chat["chat"]
|
|
130
|
+
sender = main_chat["source"]
|
|
131
|
+
recipient = main_chat["target"]
|
|
132
|
+
if (
|
|
133
|
+
isinstance(recipient, WaldiezGroupManager)
|
|
134
|
+
and not chat.message.is_method()
|
|
135
|
+
):
|
|
136
|
+
chat_massage_string: str | None = None
|
|
137
|
+
if chat.message.type == "string":
|
|
138
|
+
chat_massage_string = chat.message.content
|
|
139
|
+
return export_group_chats(
|
|
140
|
+
agent_names=self._agent_names,
|
|
141
|
+
manager=recipient,
|
|
142
|
+
intial_chat=chat_massage_string,
|
|
143
|
+
tabs=self._chat_tabs,
|
|
144
|
+
is_async=self._is_async,
|
|
145
|
+
)
|
|
146
|
+
chat_string, before_chat = export_single_chat(
|
|
147
|
+
sender=sender,
|
|
148
|
+
recipient=recipient,
|
|
149
|
+
chat=chat,
|
|
150
|
+
agent_names=self._agent_names,
|
|
151
|
+
chat_names=self._chats.names,
|
|
152
|
+
serializer=self._serializer.serialize,
|
|
153
|
+
tabs=self._chat_tabs,
|
|
154
|
+
is_async=self._is_async,
|
|
155
|
+
skip_cache=self._cache_seed is None,
|
|
156
|
+
)
|
|
157
|
+
if before_chat:
|
|
158
|
+
self._extras.set_chat_prerequisites(before_chat)
|
|
159
|
+
return chat_string
|
|
160
|
+
chat_string, before_chat = export_sequential_chat(
|
|
161
|
+
main_chats=self._chats.main,
|
|
162
|
+
agent_names=self._agent_names,
|
|
163
|
+
chat_names=self._chats.names,
|
|
164
|
+
serializer=self._serializer.serialize,
|
|
165
|
+
tabs=self._chat_tabs,
|
|
166
|
+
is_async=self._is_async,
|
|
167
|
+
skip_cache=self._cache_seed is None,
|
|
168
|
+
)
|
|
169
|
+
if before_chat:
|
|
170
|
+
self._extras.set_chat_prerequisites(before_chat)
|
|
171
|
+
return chat_string
|
|
172
|
+
|
|
173
|
+
def _handle_chat_registrations(self) -> None:
|
|
174
|
+
"""Handle chat registrations."""
|
|
175
|
+
for agent in self._all_agents:
|
|
176
|
+
if (
|
|
177
|
+
agent.agent_type != "group_manager"
|
|
178
|
+
and not agent.is_group_member
|
|
179
|
+
):
|
|
180
|
+
registration_string = export_nested_chat_registration(
|
|
181
|
+
agent=agent,
|
|
182
|
+
all_chats=self._chats.all,
|
|
183
|
+
chat_names=self._chats.names,
|
|
184
|
+
agent_names=self._agent_names,
|
|
185
|
+
serializer=self._serializer.serialize,
|
|
186
|
+
is_async=self._is_async,
|
|
187
|
+
)
|
|
188
|
+
self._extras.add_registration(registration_string)
|
|
189
|
+
|
|
190
|
+
def _gather_imports(self) -> None:
|
|
191
|
+
"""Get the imports string.
|
|
192
|
+
|
|
193
|
+
Returns
|
|
194
|
+
-------
|
|
195
|
+
list[tuple[str, ImportPosition]]
|
|
196
|
+
List of import strings and their positions.
|
|
197
|
+
"""
|
|
198
|
+
if self.is_group_patterned():
|
|
199
|
+
if self._is_async:
|
|
200
|
+
import_string = (
|
|
201
|
+
"from autogen.agentchat import a_initiate_group_chat"
|
|
202
|
+
)
|
|
203
|
+
else:
|
|
204
|
+
import_string = (
|
|
205
|
+
"from autogen.agentchat import initiate_group_chat"
|
|
206
|
+
)
|
|
207
|
+
self._extras.add_import(
|
|
208
|
+
ImportStatement(
|
|
209
|
+
statement=import_string, position=ImportPosition.THIRD_PARTY
|
|
210
|
+
)
|
|
211
|
+
)
|
|
212
|
+
return
|
|
213
|
+
if len(self._chats.main) == 1:
|
|
214
|
+
# no additional imports, it is `sender.initiate_chat(....)`
|
|
215
|
+
return
|
|
216
|
+
if self._is_async:
|
|
217
|
+
import_string = (
|
|
218
|
+
"from autogen.agentchat.chat import a_initiate_chats"
|
|
219
|
+
)
|
|
220
|
+
else:
|
|
221
|
+
import_string = "from autogen.agentchat.chat import initiate_chats"
|
|
222
|
+
self._extras.add_import(
|
|
223
|
+
ImportStatement(
|
|
224
|
+
statement=import_string, position=ImportPosition.THIRD_PARTY
|
|
225
|
+
)
|
|
226
|
+
)
|
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
# SPDX-License-Identifier: Apache-2.0.
|
|
2
2
|
# Copyright (c) 2024 - 2025 Waldiez and contributors.
|
|
3
|
-
"""
|
|
3
|
+
"""Chat utils for exporting chatsper chat type."""
|
|
4
4
|
|
|
5
|
-
from .
|
|
5
|
+
from .group import export_group_chats
|
|
6
|
+
from .nested import export_nested_chat_registration, get_nested_chat_queue
|
|
6
7
|
from .sequential import export_sequential_chat
|
|
7
|
-
from .
|
|
8
|
-
from .swarm import export_swarm_chat
|
|
8
|
+
from .single import export_single_chat
|
|
9
9
|
|
|
10
10
|
__all__ = [
|
|
11
|
+
"export_group_chats",
|
|
11
12
|
"export_nested_chat_registration",
|
|
13
|
+
"get_nested_chat_queue",
|
|
12
14
|
"export_sequential_chat",
|
|
13
15
|
"export_single_chat",
|
|
14
|
-
"export_swarm_chat",
|
|
15
16
|
]
|
|
@@ -2,44 +2,16 @@
|
|
|
2
2
|
# Copyright (c) 2024 - 2025 Waldiez and contributors.
|
|
3
3
|
"""Common utilities for exporting chats."""
|
|
4
4
|
|
|
5
|
-
from typing import
|
|
5
|
+
from typing import Optional
|
|
6
6
|
|
|
7
7
|
from waldiez.models import WaldiezAgent, WaldiezChat
|
|
8
8
|
|
|
9
9
|
|
|
10
|
-
def update_summary_chat_args(
|
|
11
|
-
chat_args: Dict[str, Any],
|
|
12
|
-
string_escape: Callable[[str], str],
|
|
13
|
-
) -> Dict[str, Any]:
|
|
14
|
-
"""Escape quotes in the summary args if they are strings.
|
|
15
|
-
|
|
16
|
-
Parameters
|
|
17
|
-
----------
|
|
18
|
-
chat_args : Dict[str, Any]
|
|
19
|
-
The chat arguments.
|
|
20
|
-
string_escape : Callable[[str], str]
|
|
21
|
-
The function to escape the string
|
|
22
|
-
|
|
23
|
-
Returns
|
|
24
|
-
-------
|
|
25
|
-
Dict[str, Any]
|
|
26
|
-
The chat arguments with the summary prompt escaped.
|
|
27
|
-
"""
|
|
28
|
-
if "summary_args" in chat_args and isinstance(
|
|
29
|
-
chat_args["summary_args"], dict
|
|
30
|
-
):
|
|
31
|
-
for key, value in chat_args["summary_args"].items():
|
|
32
|
-
if isinstance(value, str):
|
|
33
|
-
chat_args["summary_args"][key] = string_escape(value)
|
|
34
|
-
return chat_args
|
|
35
|
-
|
|
36
|
-
|
|
37
10
|
def get_chat_message_string(
|
|
38
11
|
sender: WaldiezAgent,
|
|
39
12
|
chat: WaldiezChat,
|
|
40
|
-
chat_names:
|
|
41
|
-
|
|
42
|
-
) -> Tuple[str, Optional[str]]:
|
|
13
|
+
chat_names: dict[str, str],
|
|
14
|
+
) -> tuple[str, Optional[str]]:
|
|
43
15
|
"""Get the agent's message as a string.
|
|
44
16
|
|
|
45
17
|
Parameters
|
|
@@ -48,31 +20,25 @@ def get_chat_message_string(
|
|
|
48
20
|
The sender.
|
|
49
21
|
chat : WaldiezChat
|
|
50
22
|
The chat.
|
|
51
|
-
chat_names :
|
|
23
|
+
chat_names : dict[str, str]
|
|
52
24
|
A mapping of chat id to chat name with all the chats in the flow.
|
|
53
|
-
string_escape : Callable[[str], str]
|
|
54
|
-
The function to escape the string.
|
|
55
25
|
|
|
56
26
|
Returns
|
|
57
27
|
-------
|
|
58
|
-
|
|
28
|
+
tuple[str, Optional[str]]
|
|
59
29
|
If the message is a string, the message content and None.
|
|
60
30
|
If the message is a method, the method name and the method content.
|
|
61
31
|
If the message is None, 'None' and None.
|
|
62
32
|
"""
|
|
63
|
-
if
|
|
64
|
-
not chat.message
|
|
65
|
-
or chat.message.type == "none"
|
|
66
|
-
or chat.message.content is None
|
|
67
|
-
or chat.message_content is None
|
|
68
|
-
):
|
|
33
|
+
if not chat.message or chat.message.type == "none":
|
|
69
34
|
return "None", None
|
|
70
35
|
if chat.message.type == "string":
|
|
71
|
-
|
|
36
|
+
if chat.message.content is None: # pragma: no cover
|
|
37
|
+
# should be coverred previousliy on pydantic validation
|
|
38
|
+
return "None", None
|
|
39
|
+
return chat.message.content, None
|
|
72
40
|
|
|
73
|
-
is_rag_with_carryover =
|
|
74
|
-
sender.agent_type == "rag_user" and chat.message.use_carryover
|
|
75
|
-
)
|
|
41
|
+
is_rag_with_carryover = sender.is_rag_user and chat.message.use_carryover
|
|
76
42
|
chat_name = chat_names[chat.id]
|
|
77
43
|
function_content, function_name = chat.get_message_function(
|
|
78
44
|
name_suffix=chat_name,
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# SPDX-License-Identifier: Apache-2.0.
|
|
2
|
+
# Copyright (c) 2024 - 2025 Waldiez and contributors.
|
|
3
|
+
|
|
4
|
+
"""Exporting group chat utils.
|
|
5
|
+
|
|
6
|
+
Using the group patterns (no group manager agent)
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
import json
|
|
10
|
+
|
|
11
|
+
from waldiez.models import WaldiezGroupManager
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def export_group_chats(
|
|
15
|
+
agent_names: dict[str, str],
|
|
16
|
+
manager: WaldiezGroupManager,
|
|
17
|
+
intial_chat: str | None,
|
|
18
|
+
tabs: int,
|
|
19
|
+
is_async: bool,
|
|
20
|
+
) -> str:
|
|
21
|
+
"""Get the group chat string.
|
|
22
|
+
|
|
23
|
+
Parameters
|
|
24
|
+
----------
|
|
25
|
+
agent_names : dict[str, str]
|
|
26
|
+
The agent names.
|
|
27
|
+
manager : WaldiezGroupManager
|
|
28
|
+
The group manager agent.
|
|
29
|
+
intial_chat : str | None
|
|
30
|
+
The initial chat to use if any.
|
|
31
|
+
tabs : int
|
|
32
|
+
The number of tabs for indentation.
|
|
33
|
+
is_async : bool
|
|
34
|
+
Whether the chat is asynchronous.
|
|
35
|
+
|
|
36
|
+
Returns
|
|
37
|
+
-------
|
|
38
|
+
tuple[str, str]
|
|
39
|
+
The group chat string and the import string.
|
|
40
|
+
"""
|
|
41
|
+
tab = " " * tabs
|
|
42
|
+
initiate_group_chat = "initiate_group_chat"
|
|
43
|
+
if is_async:
|
|
44
|
+
initiate_group_chat = "a_initiate_group_chat"
|
|
45
|
+
manager_name = agent_names[manager.id]
|
|
46
|
+
pattern_name = f"{manager_name}_pattern"
|
|
47
|
+
content = f"{tab}results, _, __ = {initiate_group_chat}(" + "\n"
|
|
48
|
+
content += f"{tab} pattern={pattern_name}," + "\n"
|
|
49
|
+
if intial_chat:
|
|
50
|
+
content += f"{tab} messages={json.dumps(intial_chat)}," + "\n"
|
|
51
|
+
else:
|
|
52
|
+
content += f'{tab} messages="",\n'
|
|
53
|
+
content += f"{tab} max_rounds={manager.data.max_round},\n"
|
|
54
|
+
content += f"{tab})\n"
|
|
55
|
+
return content
|