waldiez 0.4.7__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.7.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.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.8.dist-info}/WHEEL +0 -0
- {waldiez-0.4.7.dist-info → waldiez-0.4.8.dist-info}/entry_points.txt +0 -0
- {waldiez-0.4.7.dist-info → waldiez-0.4.8.dist-info}/licenses/LICENSE +0 -0
- {waldiez-0.4.7.dist-info → waldiez-0.4.8.dist-info}/licenses/NOTICE.md +0 -0
waldiez/models/chat/chat_data.py
CHANGED
|
@@ -2,16 +2,21 @@
|
|
|
2
2
|
# Copyright (c) 2024 - 2025 Waldiez and contributors.
|
|
3
3
|
"""Chat data model."""
|
|
4
4
|
|
|
5
|
-
from typing import Any,
|
|
5
|
+
from typing import Any, Optional, Union
|
|
6
6
|
|
|
7
7
|
from pydantic import Field, field_validator, model_validator
|
|
8
8
|
from typing_extensions import Annotated, Self
|
|
9
9
|
|
|
10
|
-
from ..agents
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
from ..agents import WaldiezAgentType
|
|
11
|
+
from ..common import (
|
|
12
|
+
WaldiezBase,
|
|
13
|
+
WaldiezDefaultCondition,
|
|
14
|
+
WaldiezHandoffCondition,
|
|
15
|
+
WaldiezHandoffTransition,
|
|
16
|
+
WaldiezTransitionAvailability,
|
|
17
|
+
check_function,
|
|
18
|
+
update_dict,
|
|
13
19
|
)
|
|
14
|
-
from ..common import WaldiezBase, check_function, update_dict
|
|
15
20
|
from .chat_message import (
|
|
16
21
|
CALLABLE_MESSAGE,
|
|
17
22
|
CALLABLE_MESSAGE_ARGS,
|
|
@@ -28,10 +33,10 @@ class WaldiezChatData(WaldiezBase):
|
|
|
28
33
|
----------
|
|
29
34
|
name : str
|
|
30
35
|
The name of the chat.
|
|
31
|
-
|
|
32
|
-
The
|
|
33
|
-
|
|
34
|
-
The
|
|
36
|
+
source_type : WaldiezAgentType
|
|
37
|
+
The agent type of the chat source.
|
|
38
|
+
target_type : WaldiezAgentType
|
|
39
|
+
The agent type of the chat target.
|
|
35
40
|
description : str
|
|
36
41
|
The description of the chat.
|
|
37
42
|
position : int
|
|
@@ -48,83 +53,54 @@ class WaldiezChatData(WaldiezBase):
|
|
|
48
53
|
The summary method and options for the chat.
|
|
49
54
|
max_turns : Optional[int]
|
|
50
55
|
The maximum number of turns for the chat, by default None (no limit).
|
|
51
|
-
silent :
|
|
52
|
-
Whether to run the chat silently, by default
|
|
53
|
-
summary_args : Optional[
|
|
56
|
+
silent : bool, optional
|
|
57
|
+
Whether to run the chat silently, by default False (not silent).
|
|
58
|
+
summary_args : Optional[dict[str, Any]]
|
|
54
59
|
The summary args to use in autogen.
|
|
60
|
+
handoff_condition : Optional[WaldiezHandoffCondition], optional
|
|
61
|
+
The handoff condition to use, by default None (for group chat).
|
|
55
62
|
real_source : Optional[str]
|
|
56
63
|
The real source of the chat (overrides the source).
|
|
57
64
|
real_target : Optional[str]
|
|
58
65
|
The real target of the chat (overrides the target).
|
|
59
|
-
max_rounds : int
|
|
60
|
-
Maximum number of conversation rounds (swarm).
|
|
61
|
-
after_work : Optional[WaldiezSwarmAfterWork]
|
|
62
|
-
The work to do after the chat (swarm).
|
|
63
|
-
|
|
64
|
-
Functions
|
|
65
|
-
---------
|
|
66
|
-
validate_message(value: Any)
|
|
67
|
-
Validate the message.
|
|
68
|
-
validate_summary_method(value: Optional[WaldiezChatSummaryMethod])
|
|
69
|
-
Validate the summary method.
|
|
70
|
-
serialize_summary_method(value: Any, info: FieldSerializationInfo)
|
|
71
|
-
Serialize summary method.
|
|
72
|
-
get_chat_args()
|
|
73
|
-
Get the chat arguments to use in autogen.
|
|
74
66
|
"""
|
|
75
67
|
|
|
76
68
|
name: Annotated[
|
|
77
69
|
str, Field(..., title="Name", description="The name of the chat.")
|
|
78
70
|
]
|
|
79
|
-
source: Annotated[
|
|
80
|
-
str,
|
|
81
|
-
Field(
|
|
82
|
-
...,
|
|
83
|
-
title="Source",
|
|
84
|
-
description="The source of the chat (sender).",
|
|
85
|
-
),
|
|
86
|
-
]
|
|
87
|
-
target: Annotated[
|
|
88
|
-
str,
|
|
89
|
-
Field(
|
|
90
|
-
...,
|
|
91
|
-
title="Target",
|
|
92
|
-
description="The target of the chat (recipient).",
|
|
93
|
-
),
|
|
94
|
-
]
|
|
95
71
|
description: Annotated[
|
|
96
72
|
str,
|
|
97
73
|
Field(
|
|
98
|
-
|
|
74
|
+
default="A new chat",
|
|
99
75
|
title="Description",
|
|
100
76
|
description="The description of the chat.",
|
|
101
77
|
),
|
|
102
|
-
]
|
|
78
|
+
] = "A new chat"
|
|
103
79
|
position: Annotated[
|
|
104
80
|
int,
|
|
105
81
|
Field(
|
|
106
|
-
|
|
82
|
+
default=-1,
|
|
107
83
|
title="Position",
|
|
108
84
|
description="The position of the chat in the flow (Ignored).",
|
|
109
85
|
),
|
|
110
|
-
]
|
|
86
|
+
] = -1
|
|
111
87
|
order: Annotated[
|
|
112
88
|
int,
|
|
113
89
|
Field(
|
|
114
|
-
|
|
90
|
+
default=-1,
|
|
115
91
|
title="Order",
|
|
116
92
|
description="The order of the chat in the flow.",
|
|
117
93
|
),
|
|
118
|
-
]
|
|
94
|
+
] = -1
|
|
119
95
|
clear_history: Annotated[
|
|
120
|
-
|
|
96
|
+
bool,
|
|
121
97
|
Field(
|
|
122
|
-
|
|
98
|
+
default=True,
|
|
123
99
|
alias="clearHistory",
|
|
124
100
|
title="Clear History",
|
|
125
101
|
description="Whether to clear the chat history.",
|
|
126
102
|
),
|
|
127
|
-
]
|
|
103
|
+
] = True
|
|
128
104
|
message: Annotated[
|
|
129
105
|
Union[str, WaldiezChatMessage],
|
|
130
106
|
Field(
|
|
@@ -153,84 +129,96 @@ class WaldiezChatData(WaldiezBase):
|
|
|
153
129
|
max_turns: Annotated[
|
|
154
130
|
Optional[int],
|
|
155
131
|
Field(
|
|
156
|
-
None,
|
|
132
|
+
default=None,
|
|
157
133
|
alias="maxTurns",
|
|
158
134
|
title="Max Turns",
|
|
159
135
|
description="The maximum number of turns for the chat.",
|
|
160
136
|
),
|
|
161
|
-
]
|
|
137
|
+
] = None
|
|
162
138
|
prerequisites: Annotated[
|
|
163
|
-
|
|
139
|
+
list[str],
|
|
164
140
|
Field(
|
|
165
141
|
title="Prerequisites",
|
|
166
142
|
description="The prerequisites (chat ids) for the chat (if async).",
|
|
167
143
|
default_factory=list,
|
|
168
144
|
),
|
|
169
|
-
]
|
|
145
|
+
] = []
|
|
170
146
|
silent: Annotated[
|
|
171
|
-
|
|
147
|
+
bool,
|
|
172
148
|
Field(
|
|
173
|
-
|
|
149
|
+
default=False,
|
|
174
150
|
title="Silent",
|
|
175
151
|
description="Whether to run the chat silently.",
|
|
176
152
|
),
|
|
177
|
-
]
|
|
153
|
+
] = False
|
|
178
154
|
real_source: Annotated[
|
|
179
155
|
Optional[str],
|
|
180
156
|
Field(
|
|
181
|
-
None,
|
|
157
|
+
default=None,
|
|
182
158
|
alias="realSource",
|
|
183
159
|
title="Real Source",
|
|
184
160
|
description="The real source of the chat (overrides the source).",
|
|
185
161
|
),
|
|
186
|
-
]
|
|
162
|
+
] = None
|
|
187
163
|
real_target: Annotated[
|
|
188
164
|
Optional[str],
|
|
189
165
|
Field(
|
|
190
|
-
None,
|
|
166
|
+
default=None,
|
|
191
167
|
alias="realTarget",
|
|
192
168
|
title="Real Target",
|
|
193
169
|
description="The real target of the chat (overrides the target).",
|
|
194
170
|
),
|
|
195
|
-
]
|
|
196
|
-
|
|
197
|
-
|
|
171
|
+
] = None
|
|
172
|
+
source_type: Annotated[
|
|
173
|
+
WaldiezAgentType,
|
|
198
174
|
Field(
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
175
|
+
...,
|
|
176
|
+
alias="sourceType",
|
|
177
|
+
title="Source Type",
|
|
178
|
+
description="The agent type of the source.",
|
|
202
179
|
),
|
|
203
|
-
]
|
|
204
|
-
|
|
205
|
-
|
|
180
|
+
]
|
|
181
|
+
target_type: Annotated[
|
|
182
|
+
WaldiezAgentType,
|
|
206
183
|
Field(
|
|
207
|
-
|
|
208
|
-
alias="
|
|
209
|
-
title="
|
|
210
|
-
description="The
|
|
184
|
+
...,
|
|
185
|
+
alias="targetType",
|
|
186
|
+
title="Target Type",
|
|
187
|
+
description="The agent type of the target.",
|
|
211
188
|
),
|
|
212
|
-
]
|
|
213
|
-
|
|
214
|
-
|
|
189
|
+
]
|
|
190
|
+
condition: Annotated[
|
|
191
|
+
WaldiezHandoffCondition,
|
|
215
192
|
Field(
|
|
216
|
-
|
|
217
|
-
alias="
|
|
218
|
-
title="
|
|
219
|
-
description="The
|
|
193
|
+
default_factory=WaldiezDefaultCondition.create,
|
|
194
|
+
alias="condition",
|
|
195
|
+
title="Handoff Condition",
|
|
196
|
+
description="The handoff condition to use.",
|
|
220
197
|
),
|
|
221
|
-
]
|
|
198
|
+
]
|
|
222
199
|
available: Annotated[
|
|
223
|
-
|
|
200
|
+
WaldiezTransitionAvailability,
|
|
224
201
|
Field(
|
|
225
|
-
default_factory=
|
|
226
|
-
title="
|
|
227
|
-
description="The
|
|
202
|
+
default_factory=WaldiezTransitionAvailability,
|
|
203
|
+
title="Availability",
|
|
204
|
+
description="The availability condition for the chat.",
|
|
228
205
|
),
|
|
229
206
|
]
|
|
230
|
-
|
|
207
|
+
after_work: Annotated[
|
|
208
|
+
Optional[WaldiezHandoffTransition],
|
|
209
|
+
Field(
|
|
210
|
+
None,
|
|
211
|
+
title="After Work",
|
|
212
|
+
description=(
|
|
213
|
+
"The target to transfer control to after the chat has "
|
|
214
|
+
"finished its work. (used if in a group chat)"
|
|
215
|
+
),
|
|
216
|
+
alias="afterWork",
|
|
217
|
+
),
|
|
218
|
+
] = None
|
|
231
219
|
_message_content: Optional[str] = None
|
|
232
220
|
_chat_id: int = 0
|
|
233
|
-
_prerequisites:
|
|
221
|
+
_prerequisites: list[int] = []
|
|
234
222
|
|
|
235
223
|
@property
|
|
236
224
|
def message_content(self) -> Optional[str]:
|
|
@@ -257,22 +245,22 @@ class WaldiezChatData(WaldiezBase):
|
|
|
257
245
|
"""
|
|
258
246
|
self._chat_id = value
|
|
259
247
|
|
|
260
|
-
def get_prerequisites(self) ->
|
|
248
|
+
def get_prerequisites(self) -> list[int]:
|
|
261
249
|
"""Get the chat prerequisites.
|
|
262
250
|
|
|
263
251
|
Returns
|
|
264
252
|
-------
|
|
265
|
-
|
|
253
|
+
list[int]
|
|
266
254
|
The chat prerequisites (if async).
|
|
267
255
|
"""
|
|
268
256
|
return self._prerequisites
|
|
269
257
|
|
|
270
|
-
def set_prerequisites(self, value:
|
|
258
|
+
def set_prerequisites(self, value: list[int]) -> None:
|
|
271
259
|
"""Set the chat prerequisites.
|
|
272
260
|
|
|
273
261
|
Parameters
|
|
274
262
|
----------
|
|
275
|
-
value :
|
|
263
|
+
value : list[int]
|
|
276
264
|
The chat prerequisites to set.
|
|
277
265
|
"""
|
|
278
266
|
self._prerequisites = value
|
|
@@ -309,6 +297,7 @@ class WaldiezChatData(WaldiezBase):
|
|
|
309
297
|
self._message_content = error_or_body
|
|
310
298
|
return self
|
|
311
299
|
|
|
300
|
+
# noinspection PyNestedDecorators
|
|
312
301
|
@field_validator("message", mode="before")
|
|
313
302
|
@classmethod
|
|
314
303
|
def validate_message(cls, value: Any) -> WaldiezChatMessage:
|
|
@@ -348,62 +337,36 @@ class WaldiezChatData(WaldiezBase):
|
|
|
348
337
|
)
|
|
349
338
|
return value
|
|
350
339
|
|
|
351
|
-
@field_validator("context_variables", mode="after")
|
|
352
|
-
@classmethod
|
|
353
|
-
def validate_context_variables(
|
|
354
|
-
cls, value: Optional[Dict[str, Any]]
|
|
355
|
-
) -> Optional[Dict[str, Any]]:
|
|
356
|
-
"""Validate the context variables.
|
|
357
|
-
|
|
358
|
-
Parameters
|
|
359
|
-
----------
|
|
360
|
-
value : Optional[Dict[str, Any]]
|
|
361
|
-
The context variables value.
|
|
362
|
-
|
|
363
|
-
Returns
|
|
364
|
-
-------
|
|
365
|
-
Optional[Dict[str, Any]]
|
|
366
|
-
The validated context variables value.
|
|
367
|
-
|
|
368
|
-
Raises
|
|
369
|
-
------
|
|
370
|
-
ValueError
|
|
371
|
-
If the validation fails.
|
|
372
|
-
"""
|
|
373
|
-
if value is None:
|
|
374
|
-
return None
|
|
375
|
-
return update_dict(value)
|
|
376
|
-
|
|
377
340
|
@property
|
|
378
|
-
def summary_args(self) -> Optional[
|
|
341
|
+
def summary_args(self) -> Optional[dict[str, Any]]:
|
|
379
342
|
"""Get the summary args."""
|
|
380
343
|
if self.summary.method not in (
|
|
381
344
|
"reflection_with_llm",
|
|
382
345
|
"reflectionWithLlm",
|
|
383
346
|
):
|
|
384
347
|
return None
|
|
385
|
-
args:
|
|
386
|
-
if self.summary.prompt:
|
|
348
|
+
args: dict[str, Any] = {}
|
|
349
|
+
if self.summary.prompt: # pragma: no branch
|
|
387
350
|
args["summary_prompt"] = self.summary.prompt
|
|
388
|
-
if self.summary.args:
|
|
351
|
+
if self.summary.args: # pragma: no branch
|
|
389
352
|
args.update(self.summary.args)
|
|
390
353
|
return args
|
|
391
354
|
|
|
392
|
-
def _get_context_args(self) ->
|
|
355
|
+
def _get_context_args(self) -> dict[str, Any]:
|
|
393
356
|
"""Get the context arguments to use in autogen.
|
|
394
357
|
|
|
395
358
|
Returns
|
|
396
359
|
-------
|
|
397
|
-
|
|
360
|
+
dict[str, Any]
|
|
398
361
|
The dictionary to use for generating the kwargs.
|
|
399
362
|
"""
|
|
400
|
-
extra_args:
|
|
363
|
+
extra_args: dict[str, Any] = {}
|
|
401
364
|
if not isinstance(self.message, WaldiezChatMessage): # pragma: no cover
|
|
402
365
|
return extra_args
|
|
403
366
|
extra_args.update(update_dict(self.message.context))
|
|
404
367
|
return extra_args
|
|
405
368
|
|
|
406
|
-
def get_chat_args(self, for_queue: bool) ->
|
|
369
|
+
def get_chat_args(self, for_queue: bool) -> dict[str, Any]:
|
|
407
370
|
"""Get the chat arguments to use in autogen.
|
|
408
371
|
|
|
409
372
|
Without the 'message' key.
|
|
@@ -415,20 +378,20 @@ class WaldiezChatData(WaldiezBase):
|
|
|
415
378
|
|
|
416
379
|
Returns
|
|
417
380
|
-------
|
|
418
|
-
|
|
381
|
+
dict[str, Any]
|
|
419
382
|
The dictionary to pass as kwargs.
|
|
420
383
|
"""
|
|
421
|
-
args:
|
|
422
|
-
if self.summary.method:
|
|
423
|
-
args["summary_method"] = self.summary.method
|
|
384
|
+
args: dict[str, Any] = {}
|
|
385
|
+
if self.summary.method: # pragma: no branch
|
|
386
|
+
args["summary_method"] = str(self.summary.method)
|
|
424
387
|
if self.summary_args:
|
|
425
388
|
args["summary_args"] = self.summary_args
|
|
426
|
-
if
|
|
389
|
+
if (
|
|
390
|
+
isinstance(self.max_turns, int) and self.max_turns > 0
|
|
391
|
+
): # pragma: no branch
|
|
427
392
|
args["max_turns"] = self.max_turns
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
if isinstance(self.silent, bool):
|
|
431
|
-
args["silent"] = self.silent
|
|
393
|
+
args["clear_history"] = self.clear_history
|
|
394
|
+
# args["silent"] = self.silent
|
|
432
395
|
args.update(self._get_context_args())
|
|
433
396
|
if for_queue:
|
|
434
397
|
args["chat_id"] = self._chat_id
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
# Copyright (c) 2024 - 2025 Waldiez and contributors.
|
|
3
3
|
"""Waldiez Message Model."""
|
|
4
4
|
|
|
5
|
-
from typing import Any,
|
|
5
|
+
from typing import Any, Optional
|
|
6
6
|
|
|
7
7
|
from pydantic import Field, model_validator
|
|
8
8
|
from typing_extensions import Annotated, Literal, Self
|
|
@@ -17,12 +17,12 @@ WaldiezChatMessageType = Literal[
|
|
|
17
17
|
CALLABLE_MESSAGE = "callable_message"
|
|
18
18
|
CALLABLE_MESSAGE_ARGS = ["sender", "recipient", "context"]
|
|
19
19
|
CALLABLE_MESSAGE_TYPES = (
|
|
20
|
-
["ConversableAgent", "ConversableAgent", "
|
|
21
|
-
"Union[
|
|
20
|
+
["ConversableAgent", "ConversableAgent", "dict[str, Any]"],
|
|
21
|
+
"Union[dict[str, Any], str]",
|
|
22
22
|
)
|
|
23
23
|
CALLABLE_MESSAGE_RAG_WITH_CARRYOVER_TYPES = (
|
|
24
|
-
["RetrieveUserProxyAgent", "ConversableAgent", "
|
|
25
|
-
"Union[
|
|
24
|
+
["RetrieveUserProxyAgent", "ConversableAgent", "dict[str, Any]"],
|
|
25
|
+
"Union[dict[str, Any], str]",
|
|
26
26
|
)
|
|
27
27
|
|
|
28
28
|
|
|
@@ -52,14 +52,14 @@ class WaldiezChatMessage(WaldiezBase):
|
|
|
52
52
|
the `{sender}.message_generator` method will be used.
|
|
53
53
|
content : Optional[str]
|
|
54
54
|
The content of the message (string or method).
|
|
55
|
-
context :
|
|
55
|
+
context : dict[str, Any]
|
|
56
56
|
Extra context of the message.
|
|
57
57
|
"""
|
|
58
58
|
|
|
59
59
|
type: Annotated[
|
|
60
60
|
WaldiezChatMessageType,
|
|
61
61
|
Field(
|
|
62
|
-
"none",
|
|
62
|
+
default="none",
|
|
63
63
|
title="Type",
|
|
64
64
|
description=(
|
|
65
65
|
"The type of the message: "
|
|
@@ -72,34 +72,44 @@ class WaldiezChatMessage(WaldiezBase):
|
|
|
72
72
|
"the `sender.message_generator` method will be used."
|
|
73
73
|
),
|
|
74
74
|
),
|
|
75
|
-
]
|
|
75
|
+
] = "none"
|
|
76
76
|
use_carryover: Annotated[
|
|
77
77
|
bool,
|
|
78
78
|
Field(
|
|
79
|
-
False,
|
|
79
|
+
default=False,
|
|
80
80
|
title="Use Carryover",
|
|
81
81
|
description="Use the carryover from the context.",
|
|
82
82
|
),
|
|
83
|
-
]
|
|
83
|
+
] = False
|
|
84
84
|
content: Annotated[
|
|
85
85
|
Optional[str],
|
|
86
86
|
Field(
|
|
87
|
-
None,
|
|
87
|
+
default=None,
|
|
88
88
|
title="Content",
|
|
89
89
|
description="The content of the message (string or method).",
|
|
90
90
|
),
|
|
91
|
-
]
|
|
91
|
+
] = None
|
|
92
92
|
context: Annotated[
|
|
93
|
-
|
|
93
|
+
dict[str, Any],
|
|
94
94
|
Field(
|
|
95
95
|
default_factory=dict,
|
|
96
96
|
title="Context",
|
|
97
97
|
description="Extra context of the message.",
|
|
98
98
|
),
|
|
99
|
-
]
|
|
99
|
+
] = {}
|
|
100
100
|
|
|
101
101
|
_content_body: Optional[str] = None
|
|
102
102
|
|
|
103
|
+
def is_method(self) -> bool:
|
|
104
|
+
"""Check if the message is a method.
|
|
105
|
+
|
|
106
|
+
Returns
|
|
107
|
+
-------
|
|
108
|
+
bool
|
|
109
|
+
True if the message is a method, False otherwise.
|
|
110
|
+
"""
|
|
111
|
+
return self.type in ("method", "rag_message_generator")
|
|
112
|
+
|
|
103
113
|
@property
|
|
104
114
|
def content_body(self) -> Optional[str]:
|
|
105
115
|
"""Get the content body."""
|
|
@@ -144,7 +154,7 @@ class WaldiezChatMessage(WaldiezBase):
|
|
|
144
154
|
if not self.content:
|
|
145
155
|
self.content = ""
|
|
146
156
|
if self.use_carryover:
|
|
147
|
-
content = get_last_carryover_method_content(
|
|
157
|
+
self.content = get_last_carryover_method_content(
|
|
148
158
|
text_content=self.content,
|
|
149
159
|
)
|
|
150
160
|
content = self.content
|
|
@@ -162,7 +172,7 @@ class WaldiezChatMessage(WaldiezBase):
|
|
|
162
172
|
def validate_method(
|
|
163
173
|
self,
|
|
164
174
|
function_name: str,
|
|
165
|
-
function_args:
|
|
175
|
+
function_args: list[str],
|
|
166
176
|
) -> str:
|
|
167
177
|
"""Validate a method.
|
|
168
178
|
|
|
@@ -170,7 +180,7 @@ class WaldiezChatMessage(WaldiezBase):
|
|
|
170
180
|
----------
|
|
171
181
|
function_name : str
|
|
172
182
|
The method name.
|
|
173
|
-
function_args :
|
|
183
|
+
function_args : list[str]
|
|
174
184
|
The expected method arguments.
|
|
175
185
|
|
|
176
186
|
Returns
|
|
@@ -219,12 +229,12 @@ def get_last_carryover_method_content(text_content: str) -> str:
|
|
|
219
229
|
The source agent.
|
|
220
230
|
recipient : ConversableAgent
|
|
221
231
|
The target agent.
|
|
222
|
-
context :
|
|
232
|
+
context : dict[str, Any]
|
|
223
233
|
The context.
|
|
224
234
|
|
|
225
235
|
Returns
|
|
226
236
|
-------
|
|
227
|
-
Union[
|
|
237
|
+
Union[dict[str, Any], str]
|
|
228
238
|
The message to send using the last carryover.
|
|
229
239
|
"""
|
|
230
240
|
carryover = context.get("carryover", "")
|
|
@@ -258,12 +268,12 @@ RAG_METHOD_WITH_CARRYOVER_BODY = '''
|
|
|
258
268
|
The source agent.
|
|
259
269
|
recipient : ConversableAgent
|
|
260
270
|
The target agent.
|
|
261
|
-
context :
|
|
271
|
+
context : dict[str, Any]
|
|
262
272
|
The context.
|
|
263
273
|
|
|
264
274
|
Returns
|
|
265
275
|
-------
|
|
266
|
-
Union[
|
|
276
|
+
Union[dict[str, Any], str]
|
|
267
277
|
The message to send using the last carryover.
|
|
268
278
|
"""
|
|
269
279
|
carryover = context.get("carryover", "")
|
|
@@ -285,7 +295,7 @@ RAG_METHOD_WITH_CARRYOVER = (
|
|
|
285
295
|
"def callable_message(\n"
|
|
286
296
|
" sender: RetrieveUserProxyAgent,\n"
|
|
287
297
|
" recipient: ConversableAgent,\n"
|
|
288
|
-
" context:
|
|
289
|
-
") -> Union[
|
|
298
|
+
" context: dict[str, Any],\n"
|
|
299
|
+
") -> Union[dict[str, Any], str]:"
|
|
290
300
|
f"{RAG_METHOD_WITH_CARRYOVER_BODY}"
|
|
291
301
|
)
|
|
@@ -16,11 +16,11 @@ NESTED_CHAT_ARGS = ["recipient", "messages", "sender", "config"]
|
|
|
16
16
|
NESTED_CHAT_TYPES = (
|
|
17
17
|
[
|
|
18
18
|
"ConversableAgent",
|
|
19
|
-
"
|
|
19
|
+
"list[dict[str, Any]]",
|
|
20
20
|
"ConversableAgent",
|
|
21
|
-
"
|
|
21
|
+
"dict[str, Any]",
|
|
22
22
|
],
|
|
23
|
-
"Union[
|
|
23
|
+
"Union[dict[str, Any], str]",
|
|
24
24
|
)
|
|
25
25
|
|
|
26
26
|
|
|
@@ -38,19 +38,19 @@ class WaldiezChatNested(WaldiezBase):
|
|
|
38
38
|
message: Annotated[
|
|
39
39
|
Optional[WaldiezChatMessage],
|
|
40
40
|
Field(
|
|
41
|
-
None,
|
|
41
|
+
default=None,
|
|
42
42
|
title="Message",
|
|
43
43
|
description="The message in a nested chat (sender -> recipient).",
|
|
44
44
|
),
|
|
45
|
-
]
|
|
45
|
+
] = None
|
|
46
46
|
reply: Annotated[
|
|
47
47
|
Optional[WaldiezChatMessage],
|
|
48
48
|
Field(
|
|
49
|
-
None,
|
|
49
|
+
default=None,
|
|
50
50
|
title="Reply",
|
|
51
51
|
description="The reply in a nested chat (recipient -> sender).",
|
|
52
52
|
),
|
|
53
|
-
]
|
|
53
|
+
] = None
|
|
54
54
|
|
|
55
55
|
_message_content: Optional[str] = None
|
|
56
56
|
_reply_content: Optional[str] = None
|
|
@@ -65,6 +65,7 @@ class WaldiezChatNested(WaldiezBase):
|
|
|
65
65
|
"""Get the reply content."""
|
|
66
66
|
return self._reply_content
|
|
67
67
|
|
|
68
|
+
# noinspection PyNestedDecorators
|
|
68
69
|
@field_validator("message", "reply", mode="before")
|
|
69
70
|
@classmethod
|
|
70
71
|
def validate_message(cls, value: Any) -> WaldiezChatMessage:
|
|
@@ -113,27 +114,27 @@ class WaldiezChatNested(WaldiezBase):
|
|
|
113
114
|
ValueError
|
|
114
115
|
If the validation fails.
|
|
115
116
|
"""
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
117
|
+
for attr, content_attr, function_name in [
|
|
118
|
+
("message", "_message_content", NESTED_CHAT_MESSAGE),
|
|
119
|
+
("reply", "_reply_content", NESTED_CHAT_REPLY),
|
|
120
|
+
]: # pragma: no branch
|
|
121
|
+
attr_value = getattr(self, attr)
|
|
122
|
+
if attr_value is not None:
|
|
123
|
+
if isinstance(
|
|
124
|
+
attr_value, WaldiezChatMessage
|
|
125
|
+
): # pragma: no branch
|
|
126
|
+
setattr(self, content_attr, attr_value.content_body)
|
|
127
|
+
if attr_value.type == "none":
|
|
128
|
+
setattr(self, content_attr, "")
|
|
129
|
+
elif attr_value.type == "string":
|
|
130
|
+
setattr(self, content_attr, attr_value.content)
|
|
131
|
+
elif attr_value.type == "method": # pragma: no branch
|
|
132
|
+
setattr(
|
|
133
|
+
self,
|
|
134
|
+
content_attr,
|
|
135
|
+
attr_value.validate_method(
|
|
136
|
+
function_name=function_name,
|
|
137
|
+
function_args=NESTED_CHAT_ARGS,
|
|
138
|
+
),
|
|
139
|
+
)
|
|
139
140
|
return self
|