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,124 +0,0 @@
|
|
|
1
|
-
# SPDX-License-Identifier: Apache-2.0.
|
|
2
|
-
# Copyright (c) 2024 - 2025 Waldiez and contributors.
|
|
3
|
-
# https://docs.ag2.ai/docs/reference/agentchat/contrib/swarm_agent
|
|
4
|
-
"""Swarm agent data."""
|
|
5
|
-
|
|
6
|
-
from typing import List, Union
|
|
7
|
-
|
|
8
|
-
from pydantic import Field, model_validator
|
|
9
|
-
from typing_extensions import Annotated, Self
|
|
10
|
-
|
|
11
|
-
from ..agent import WaldiezAgentData
|
|
12
|
-
from .after_work import WaldiezSwarmAfterWork
|
|
13
|
-
from .on_condition import WaldiezSwarmOnCondition
|
|
14
|
-
from .update_system_message import WaldiezSwarmUpdateSystemMessage
|
|
15
|
-
|
|
16
|
-
WaldiezSwarmHandoff = Union[WaldiezSwarmOnCondition, WaldiezSwarmAfterWork]
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
# flake8: noqa: E501
|
|
20
|
-
# pylint: disable=line-too-long
|
|
21
|
-
class WaldiezSwarmAgentData(WaldiezAgentData):
|
|
22
|
-
"""Swarm agent data.
|
|
23
|
-
|
|
24
|
-
Attributes
|
|
25
|
-
----------
|
|
26
|
-
is_initial: bool
|
|
27
|
-
Whether the agent is the initial agent.
|
|
28
|
-
functions : List[str]
|
|
29
|
-
A list of functions (skill ids) to register with the agent.
|
|
30
|
-
|
|
31
|
-
update_agent_state_before_reply : List[str]
|
|
32
|
-
A list of functions, including `UpdateSystemMessage`,
|
|
33
|
-
called to update the agent's state before it replies. Each function
|
|
34
|
-
is called when the agent is selected and before it speaks.
|
|
35
|
-
|
|
36
|
-
handoffs : List[Union[WaldiezSwarmOnCondition, WaldiezSwarmAfterWork]]
|
|
37
|
-
A list of hand offs to register.
|
|
38
|
-
|
|
39
|
-
Notes
|
|
40
|
-
-----
|
|
41
|
-
Each agent should have at most one `AfterWork` and (if any) it should be
|
|
42
|
-
at the end the list of hand offs.
|
|
43
|
-
"""
|
|
44
|
-
|
|
45
|
-
is_initial: Annotated[
|
|
46
|
-
bool,
|
|
47
|
-
Field(
|
|
48
|
-
False,
|
|
49
|
-
title="Is Initial",
|
|
50
|
-
alias="isInitial",
|
|
51
|
-
description=("Whether the agent is the initial agent."),
|
|
52
|
-
),
|
|
53
|
-
]
|
|
54
|
-
functions: Annotated[
|
|
55
|
-
List[str],
|
|
56
|
-
Field(
|
|
57
|
-
title="Functions",
|
|
58
|
-
description=(
|
|
59
|
-
"A list of functions (skill ids) to register with the agent."
|
|
60
|
-
),
|
|
61
|
-
default_factory=list,
|
|
62
|
-
),
|
|
63
|
-
]
|
|
64
|
-
update_agent_state_before_reply: Annotated[
|
|
65
|
-
List[Union[str, WaldiezSwarmUpdateSystemMessage]],
|
|
66
|
-
Field(
|
|
67
|
-
title="Update Agent State Before Reply",
|
|
68
|
-
alias="updateAgentStateBeforeReply",
|
|
69
|
-
description=(
|
|
70
|
-
"A list of functions, including UpdateSystemMessage,"
|
|
71
|
-
"called to update the agent's state before it replies. "
|
|
72
|
-
" Each function is called when the agent is selected "
|
|
73
|
-
"and before it speaks. If not an UpdateSystemMessage, "
|
|
74
|
-
"it should be a skill id."
|
|
75
|
-
),
|
|
76
|
-
default_factory=list,
|
|
77
|
-
),
|
|
78
|
-
]
|
|
79
|
-
handoffs: Annotated[
|
|
80
|
-
List[Union[WaldiezSwarmOnCondition, WaldiezSwarmAfterWork]],
|
|
81
|
-
Field(
|
|
82
|
-
title="Handoffs",
|
|
83
|
-
description=(
|
|
84
|
-
"A list of hand offs to register. "
|
|
85
|
-
"There should only be at most one `AfterWork` per agent"
|
|
86
|
-
"And (if any) it should be at the end of the list."
|
|
87
|
-
),
|
|
88
|
-
default_factory=list,
|
|
89
|
-
),
|
|
90
|
-
]
|
|
91
|
-
|
|
92
|
-
@model_validator(mode="after")
|
|
93
|
-
def validate_handoffs(self) -> Self:
|
|
94
|
-
"""Validate the hand offs.
|
|
95
|
-
|
|
96
|
-
Returns
|
|
97
|
-
-------
|
|
98
|
-
Self
|
|
99
|
-
The swarm agent data.
|
|
100
|
-
|
|
101
|
-
Raises
|
|
102
|
-
------
|
|
103
|
-
ValueError
|
|
104
|
-
If there are more than one `AfterWork`s.
|
|
105
|
-
"""
|
|
106
|
-
after_works: List[WaldiezSwarmAfterWork] = [
|
|
107
|
-
hand_off
|
|
108
|
-
for hand_off in self.handoffs
|
|
109
|
-
if isinstance(hand_off, WaldiezSwarmAfterWork)
|
|
110
|
-
]
|
|
111
|
-
if len(after_works) > 1:
|
|
112
|
-
raise ValueError(
|
|
113
|
-
"Each agent should have at most one `AfterWork` "
|
|
114
|
-
"and (if any) it should be at the end of the list."
|
|
115
|
-
)
|
|
116
|
-
on_conditions: List[WaldiezSwarmOnCondition] = [
|
|
117
|
-
hand_off
|
|
118
|
-
for hand_off in self.handoffs
|
|
119
|
-
if isinstance(hand_off, WaldiezSwarmOnCondition)
|
|
120
|
-
]
|
|
121
|
-
on_conditions = sorted(on_conditions, key=lambda x: x.target.order)
|
|
122
|
-
handoffs = on_conditions + after_works
|
|
123
|
-
self.handoffs = handoffs
|
|
124
|
-
return self
|
waldiez/models/flow/utils.py
DELETED
|
@@ -1,232 +0,0 @@
|
|
|
1
|
-
# SPDX-License-Identifier: Apache-2.0.
|
|
2
|
-
# Copyright (c) 2024 - 2025 Waldiez and contributors.
|
|
3
|
-
"""Helpers for the flow model."""
|
|
4
|
-
|
|
5
|
-
import uuid
|
|
6
|
-
from datetime import datetime, timezone
|
|
7
|
-
from typing import Any, Dict, List, Optional
|
|
8
|
-
|
|
9
|
-
from ..agents import (
|
|
10
|
-
WaldiezAgent,
|
|
11
|
-
WaldiezAgentNestedChat,
|
|
12
|
-
WaldiezAgentNestedChatMessage,
|
|
13
|
-
WaldiezSwarmAgent,
|
|
14
|
-
WaldiezSwarmOnCondition,
|
|
15
|
-
)
|
|
16
|
-
from ..chat import WaldiezChat
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
def id_factory() -> str:
|
|
20
|
-
"""Generate a unique ID.
|
|
21
|
-
|
|
22
|
-
Returns
|
|
23
|
-
-------
|
|
24
|
-
str
|
|
25
|
-
The unique ID.
|
|
26
|
-
"""
|
|
27
|
-
now_td = datetime.now(timezone.utc)
|
|
28
|
-
now_str = now_td.strftime("%Y%m%d%H%M%S%f")
|
|
29
|
-
return f"{now_str}-{uuid.uuid4().hex}"
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
def check_handoff_to_nested_chat(
|
|
33
|
-
agent: WaldiezSwarmAgent,
|
|
34
|
-
all_agents: List[WaldiezAgent],
|
|
35
|
-
all_chats: List[WaldiezChat],
|
|
36
|
-
) -> None:
|
|
37
|
-
"""Check the handoffs to a nested chat.
|
|
38
|
-
|
|
39
|
-
If we have one and the agent does not have nested_chats,
|
|
40
|
-
we should generate them with the `handoff.target.id`
|
|
41
|
-
as the first (chat's) message.
|
|
42
|
-
|
|
43
|
-
Parameters
|
|
44
|
-
----------
|
|
45
|
-
agent : WaldiezSwarmAgent
|
|
46
|
-
The swarm agent.
|
|
47
|
-
all_agents : List[WaldiezAgent]
|
|
48
|
-
All agents.
|
|
49
|
-
all_chats : List[WaldiezChat]
|
|
50
|
-
All chats.
|
|
51
|
-
|
|
52
|
-
Raises
|
|
53
|
-
------
|
|
54
|
-
ValueError
|
|
55
|
-
If the agent has a handoff to a nested chat,
|
|
56
|
-
but no chat found with it as a source.
|
|
57
|
-
"""
|
|
58
|
-
# pylint: disable=too-complex
|
|
59
|
-
for handoff in agent.handoffs:
|
|
60
|
-
if not isinstance(handoff, WaldiezSwarmOnCondition):
|
|
61
|
-
continue
|
|
62
|
-
is_nested_chat = handoff.target_type == "nested_chat"
|
|
63
|
-
if is_nested_chat:
|
|
64
|
-
# check if the agent already has nested_chats
|
|
65
|
-
# but only to get the order (and the first chat/message)
|
|
66
|
-
# either way, we must include all the connections that
|
|
67
|
-
# are swarm => non-swarm
|
|
68
|
-
# if we have the orders, ok, else we get them from the
|
|
69
|
-
# edges positions
|
|
70
|
-
all_connections = sorted(
|
|
71
|
-
get_nested_chat_swarm_connections(agent, all_agents, all_chats),
|
|
72
|
-
key=lambda x: x.data.order,
|
|
73
|
-
)
|
|
74
|
-
if not all_connections:
|
|
75
|
-
raise ValueError(
|
|
76
|
-
f"Agent {agent.name} has a handoff to a nested chat, "
|
|
77
|
-
"but no chat found with it as a source."
|
|
78
|
-
)
|
|
79
|
-
agent_nested_chats = agent.nested_chats
|
|
80
|
-
if not agent_nested_chats or not agent_nested_chats[0].messages:
|
|
81
|
-
agent.data.nested_chats = [
|
|
82
|
-
WaldiezAgentNestedChat(
|
|
83
|
-
triggered_by=[],
|
|
84
|
-
messages=[
|
|
85
|
-
WaldiezAgentNestedChatMessage(
|
|
86
|
-
id=chat.id,
|
|
87
|
-
is_reply=False,
|
|
88
|
-
)
|
|
89
|
-
for chat in all_connections
|
|
90
|
-
],
|
|
91
|
-
)
|
|
92
|
-
]
|
|
93
|
-
break
|
|
94
|
-
agent.data.nested_chats = merge_nested_chat_messages(
|
|
95
|
-
agent_nested_chats[0].messages, all_connections
|
|
96
|
-
)
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
def get_nested_chat_swarm_connections(
|
|
100
|
-
agent: WaldiezSwarmAgent,
|
|
101
|
-
all_agents: List[WaldiezAgent],
|
|
102
|
-
all_chats: List[WaldiezChat],
|
|
103
|
-
) -> List[WaldiezChat]:
|
|
104
|
-
"""Get the nested chat connections.
|
|
105
|
-
|
|
106
|
-
Parameters
|
|
107
|
-
----------
|
|
108
|
-
agent : WaldiezSwarmAgent
|
|
109
|
-
The swarm agent.
|
|
110
|
-
all_agents : Iterator[WaldiezAgent]
|
|
111
|
-
All agents.
|
|
112
|
-
all_chats : List[WaldiezChat]
|
|
113
|
-
All chats.
|
|
114
|
-
|
|
115
|
-
Returns
|
|
116
|
-
-------
|
|
117
|
-
List[WaldiezAgentNestedChat]
|
|
118
|
-
The nested chat connections.
|
|
119
|
-
"""
|
|
120
|
-
connections_with_non_swarm_targets = []
|
|
121
|
-
for chat in all_chats:
|
|
122
|
-
if chat.source != agent.id:
|
|
123
|
-
continue
|
|
124
|
-
target_agent = next(
|
|
125
|
-
(a for a in all_agents if a.id == chat.target), None
|
|
126
|
-
)
|
|
127
|
-
if not target_agent or target_agent.agent_type != "swarm":
|
|
128
|
-
connections_with_non_swarm_targets.append(chat)
|
|
129
|
-
return connections_with_non_swarm_targets
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
def merge_nested_chat_messages(
|
|
133
|
-
agent_nested_chat_messages: List[WaldiezAgentNestedChatMessage],
|
|
134
|
-
all_connections: List[WaldiezChat],
|
|
135
|
-
) -> List[WaldiezAgentNestedChat]:
|
|
136
|
-
"""Merge the nested chat messages.
|
|
137
|
-
|
|
138
|
-
Parameters
|
|
139
|
-
----------
|
|
140
|
-
all_connections : List[WaldiezChat]
|
|
141
|
-
The connections.
|
|
142
|
-
agent_nested_chat_messages : List[WaldiezAgentNestedChatMessage]
|
|
143
|
-
The agent's nested chat messages.
|
|
144
|
-
|
|
145
|
-
Returns
|
|
146
|
-
-------
|
|
147
|
-
List[WaldiezAgentNestedChat]
|
|
148
|
-
The merged nested chat with all the messages.
|
|
149
|
-
"""
|
|
150
|
-
nested_chat = WaldiezAgentNestedChat(triggered_by=[], messages=[])
|
|
151
|
-
chat_ids_added: List[str] = []
|
|
152
|
-
for message in agent_nested_chat_messages:
|
|
153
|
-
chat = next((c for c in all_connections if c.id == message.id), None)
|
|
154
|
-
if chat and chat.id not in chat_ids_added:
|
|
155
|
-
nested_chat.messages.append(
|
|
156
|
-
WaldiezAgentNestedChatMessage(
|
|
157
|
-
id=chat.id,
|
|
158
|
-
is_reply=False,
|
|
159
|
-
)
|
|
160
|
-
)
|
|
161
|
-
chat_ids_added.append(chat.id)
|
|
162
|
-
for chat in all_connections:
|
|
163
|
-
if chat.id not in chat_ids_added:
|
|
164
|
-
nested_chat.messages.append(
|
|
165
|
-
WaldiezAgentNestedChatMessage(
|
|
166
|
-
id=chat.id,
|
|
167
|
-
is_reply=False,
|
|
168
|
-
)
|
|
169
|
-
)
|
|
170
|
-
chat_ids_added.append(chat.id)
|
|
171
|
-
nested_chat.messages.sort(key=lambda x: chat_ids_added.index(x.id))
|
|
172
|
-
return [nested_chat]
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
def get_flow_data(
|
|
176
|
-
data: Dict[str, Any],
|
|
177
|
-
flow_id: Optional[str] = None,
|
|
178
|
-
name: Optional[str] = None,
|
|
179
|
-
description: Optional[str] = None,
|
|
180
|
-
tags: Optional[List[str]] = None,
|
|
181
|
-
requirements: Optional[List[str]] = None,
|
|
182
|
-
) -> Dict[str, Any]:
|
|
183
|
-
"""Get the flow from the passed data dict.
|
|
184
|
-
|
|
185
|
-
Parameters
|
|
186
|
-
----------
|
|
187
|
-
data : Dict[str, Any]
|
|
188
|
-
The data dict.
|
|
189
|
-
flow_id : Optional[str], optional
|
|
190
|
-
The flow ID, by default None.
|
|
191
|
-
name : Optional[str], optional
|
|
192
|
-
The flow name, by default None.
|
|
193
|
-
description : Optional[str], optional
|
|
194
|
-
The flow description, by default None.
|
|
195
|
-
tags : Optional[List[str]], optional
|
|
196
|
-
The flow tags, by default None.
|
|
197
|
-
requirements : Optional[List[str]], optional
|
|
198
|
-
The flow requirements, by default None.
|
|
199
|
-
|
|
200
|
-
Returns
|
|
201
|
-
-------
|
|
202
|
-
Dict[str, Any]
|
|
203
|
-
The flow data.
|
|
204
|
-
|
|
205
|
-
Raises
|
|
206
|
-
------
|
|
207
|
-
ValueError
|
|
208
|
-
If the flow type is not "flow".
|
|
209
|
-
"""
|
|
210
|
-
item_type = data.get("type", "flow")
|
|
211
|
-
if item_type != "flow":
|
|
212
|
-
# empty flow (from exported model/skill ?)
|
|
213
|
-
raise ValueError(f"Invalid flow type: {item_type}")
|
|
214
|
-
from_args = {
|
|
215
|
-
"id": flow_id,
|
|
216
|
-
"name": name,
|
|
217
|
-
"description": description,
|
|
218
|
-
"tags": tags,
|
|
219
|
-
"requirements": requirements,
|
|
220
|
-
}
|
|
221
|
-
for key, value in from_args.items():
|
|
222
|
-
if value:
|
|
223
|
-
data[key] = value
|
|
224
|
-
if "name" not in data:
|
|
225
|
-
data["name"] = "Waldiez Flow"
|
|
226
|
-
if "description" not in data:
|
|
227
|
-
data["description"] = "Waldiez Flow description"
|
|
228
|
-
if "tags" not in data:
|
|
229
|
-
data["tags"] = []
|
|
230
|
-
if "requirements" not in data:
|
|
231
|
-
data["requirements"] = []
|
|
232
|
-
return data
|
waldiez/models/skill/__init__.py
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
# SPDX-License-Identifier: Apache-2.0.
|
|
2
|
-
# Copyright (c) 2024 - 2025 Waldiez and contributors.
|
|
3
|
-
"""Waldiez Skill related models."""
|
|
4
|
-
|
|
5
|
-
from .extra_requirements import get_skills_extra_requirements
|
|
6
|
-
from .skill import SHARED_SKILL_NAME, WaldiezSkill
|
|
7
|
-
from .skill_data import WaldiezSkillData
|
|
8
|
-
from .skill_type import WaldiezSkillType
|
|
9
|
-
|
|
10
|
-
__all__ = [
|
|
11
|
-
"SHARED_SKILL_NAME",
|
|
12
|
-
"WaldiezSkill",
|
|
13
|
-
"WaldiezSkillData",
|
|
14
|
-
"WaldiezSkillType",
|
|
15
|
-
"get_skills_extra_requirements",
|
|
16
|
-
]
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
# SPDX-License-Identifier: Apache-2.0.
|
|
2
|
-
# Copyright (c) 2024 - 2025 Waldiez and contributors.
|
|
3
|
-
"""Waldiez skill extra requirements."""
|
|
4
|
-
|
|
5
|
-
from typing import Iterator, Set
|
|
6
|
-
|
|
7
|
-
from .skill import WaldiezSkill
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
def get_skills_extra_requirements(
|
|
11
|
-
skills: Iterator[WaldiezSkill],
|
|
12
|
-
autogen_version: str,
|
|
13
|
-
) -> Set[str]:
|
|
14
|
-
"""Get the skills extra requirements.
|
|
15
|
-
|
|
16
|
-
Parameters
|
|
17
|
-
----------
|
|
18
|
-
skills : List[WaldiezSkill]
|
|
19
|
-
The skills.
|
|
20
|
-
autogen_version : str
|
|
21
|
-
The ag2 version.
|
|
22
|
-
|
|
23
|
-
Returns
|
|
24
|
-
-------
|
|
25
|
-
List[str]
|
|
26
|
-
The skills extra requirements.
|
|
27
|
-
"""
|
|
28
|
-
skill_requirements: Set[str] = set()
|
|
29
|
-
for skill in skills:
|
|
30
|
-
if skill.skill_type == "langchain":
|
|
31
|
-
skill_requirements.add(f"ag2[interop-langchain]=={autogen_version}")
|
|
32
|
-
if skill.skill_type == "crewai":
|
|
33
|
-
skill_requirements.add(f"ag2[interop-crewai]=={autogen_version}")
|
|
34
|
-
for requirement in skill.requirements:
|
|
35
|
-
skill_requirements.add(requirement)
|
|
36
|
-
return skill_requirements
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
# SPDX-License-Identifier: Apache-2.0.
|
|
2
|
-
# Copyright (c) 2024 - 2025 Waldiez and contributors.
|
|
3
|
-
"""Waldiez Skill model."""
|
|
4
|
-
|
|
5
|
-
from typing import Dict
|
|
6
|
-
|
|
7
|
-
from pydantic import Field
|
|
8
|
-
from typing_extensions import Annotated
|
|
9
|
-
|
|
10
|
-
from ..common import WaldiezBase
|
|
11
|
-
from .skill_type import WaldiezSkillType
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
class WaldiezSkillData(WaldiezBase):
|
|
15
|
-
"""Waldiez Skill Data.
|
|
16
|
-
|
|
17
|
-
Attributes
|
|
18
|
-
----------
|
|
19
|
-
skill_type : WaldiezSkillType
|
|
20
|
-
The type of the skill: shared, custom, langchain, crewai.
|
|
21
|
-
content : str
|
|
22
|
-
The content (source code) of the skill.
|
|
23
|
-
secrets : Dict[str, str]
|
|
24
|
-
The secrets (environment variables) of the skill.
|
|
25
|
-
"""
|
|
26
|
-
|
|
27
|
-
skill_type: Annotated[
|
|
28
|
-
WaldiezSkillType,
|
|
29
|
-
Field(
|
|
30
|
-
"custom",
|
|
31
|
-
alias="skillType",
|
|
32
|
-
title="Skill Type",
|
|
33
|
-
description=(
|
|
34
|
-
"The type of the skill: shared, custom, langchain, crewai."
|
|
35
|
-
),
|
|
36
|
-
),
|
|
37
|
-
] = "custom"
|
|
38
|
-
content: Annotated[
|
|
39
|
-
str,
|
|
40
|
-
Field(
|
|
41
|
-
...,
|
|
42
|
-
title="Content",
|
|
43
|
-
description="The content (source code) of the skill.",
|
|
44
|
-
),
|
|
45
|
-
]
|
|
46
|
-
secrets: Annotated[
|
|
47
|
-
Dict[str, str],
|
|
48
|
-
Field(
|
|
49
|
-
default_factory=dict,
|
|
50
|
-
title="Secrets",
|
|
51
|
-
description="The secrets (environment variables) of the skill.",
|
|
52
|
-
),
|
|
53
|
-
]
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
# SPDX-License-Identifier: Apache-2.0.
|
|
2
|
-
# Copyright (c) 2024 - 2025 Waldiez and contributors.
|
|
3
|
-
"""Waldiez Skill types."""
|
|
4
|
-
|
|
5
|
-
from typing_extensions import Literal
|
|
6
|
-
|
|
7
|
-
WaldiezSkillType = Literal["shared", "custom", "langchain", "crewai"]
|
|
8
|
-
"""Possible types of a Waldiez Skill."""
|