waldiez 0.2.2__py3-none-any.whl → 0.3.0__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 +2 -0
- waldiez/__main__.py +2 -0
- waldiez/_version.py +3 -1
- waldiez/cli.py +13 -3
- waldiez/cli_extras.py +4 -3
- waldiez/conflict_checker.py +4 -3
- waldiez/exporter.py +28 -105
- waldiez/exporting/__init__.py +8 -9
- waldiez/exporting/agent/__init__.py +7 -0
- waldiez/exporting/agent/agent_exporter.py +279 -0
- waldiez/exporting/agent/utils/__init__.py +23 -0
- waldiez/exporting/agent/utils/agent_class_name.py +34 -0
- waldiez/exporting/agent/utils/agent_imports.py +50 -0
- waldiez/exporting/{agents → agent/utils}/code_execution.py +9 -11
- waldiez/exporting/{agents → agent/utils}/group_manager.py +47 -35
- waldiez/exporting/{agents → agent/utils}/rag_user/__init__.py +2 -0
- waldiez/exporting/{agents → agent/utils}/rag_user/chroma_utils.py +22 -17
- waldiez/exporting/{agents → agent/utils}/rag_user/mongo_utils.py +14 -10
- waldiez/exporting/{agents → agent/utils}/rag_user/pgvector_utils.py +12 -8
- waldiez/exporting/{agents → agent/utils}/rag_user/qdrant_utils.py +11 -8
- waldiez/exporting/{agents → agent/utils}/rag_user/rag_user.py +78 -55
- waldiez/exporting/{agents → agent/utils}/rag_user/vector_db.py +10 -8
- waldiez/exporting/agent/utils/swarm_agent.py +463 -0
- waldiez/exporting/{agents → agent/utils}/teachability.py +10 -6
- waldiez/exporting/{agents → agent/utils}/termination_message.py +7 -8
- waldiez/exporting/base/__init__.py +25 -0
- waldiez/exporting/base/agent_position.py +75 -0
- waldiez/exporting/base/base_exporter.py +118 -0
- waldiez/exporting/base/export_position.py +48 -0
- waldiez/exporting/base/import_position.py +23 -0
- waldiez/exporting/base/mixin.py +134 -0
- waldiez/exporting/base/utils/__init__.py +18 -0
- waldiez/exporting/{utils → base/utils}/comments.py +12 -55
- waldiez/exporting/{utils → base/utils}/naming.py +14 -4
- waldiez/exporting/base/utils/path_check.py +68 -0
- waldiez/exporting/{utils/object_string.py → base/utils/to_string.py} +21 -20
- waldiez/exporting/chats/__init__.py +5 -12
- waldiez/exporting/chats/chats_exporter.py +240 -0
- waldiez/exporting/chats/utils/__init__.py +15 -0
- waldiez/exporting/chats/utils/common.py +81 -0
- waldiez/exporting/chats/{nested.py → utils/nested.py} +125 -86
- waldiez/exporting/chats/utils/sequential.py +244 -0
- waldiez/exporting/chats/utils/single_chat.py +313 -0
- waldiez/exporting/chats/utils/swarm.py +207 -0
- waldiez/exporting/flow/__init__.py +5 -3
- waldiez/exporting/flow/flow_exporter.py +503 -0
- waldiez/exporting/flow/utils/__init__.py +47 -0
- waldiez/exporting/flow/utils/agent_utils.py +204 -0
- waldiez/exporting/flow/utils/chat_utils.py +71 -0
- waldiez/exporting/flow/utils/def_main.py +62 -0
- waldiez/exporting/flow/utils/flow_content.py +112 -0
- waldiez/exporting/flow/utils/flow_names.py +115 -0
- waldiez/exporting/flow/utils/importing_utils.py +179 -0
- waldiez/exporting/{utils → flow/utils}/logging_utils.py +34 -31
- waldiez/exporting/models/__init__.py +7 -242
- waldiez/exporting/models/models_exporter.py +192 -0
- waldiez/exporting/models/utils.py +166 -0
- waldiez/exporting/skills/__init__.py +7 -161
- waldiez/exporting/skills/skills_exporter.py +169 -0
- waldiez/exporting/skills/utils.py +281 -0
- waldiez/models/__init__.py +25 -7
- waldiez/models/agents/__init__.py +70 -0
- waldiez/models/agents/agent/__init__.py +11 -1
- waldiez/models/agents/agent/agent.py +9 -4
- waldiez/models/agents/agent/agent_data.py +3 -1
- waldiez/models/agents/agent/code_execution.py +2 -0
- waldiez/models/agents/agent/linked_skill.py +2 -0
- waldiez/models/agents/agent/nested_chat.py +2 -0
- waldiez/models/agents/agent/teachability.py +2 -0
- waldiez/models/agents/agent/termination_message.py +49 -13
- waldiez/models/agents/agents.py +15 -3
- waldiez/models/agents/assistant/__init__.py +2 -0
- waldiez/models/agents/assistant/assistant.py +2 -0
- waldiez/models/agents/assistant/assistant_data.py +2 -0
- waldiez/models/agents/group_manager/__init__.py +9 -1
- waldiez/models/agents/group_manager/group_manager.py +2 -0
- waldiez/models/agents/group_manager/group_manager_data.py +2 -0
- waldiez/models/agents/group_manager/speakers.py +49 -13
- waldiez/models/agents/rag_user/__init__.py +21 -4
- waldiez/models/agents/rag_user/rag_user.py +3 -1
- waldiez/models/agents/rag_user/rag_user_data.py +2 -0
- waldiez/models/agents/rag_user/retrieve_config.py +268 -17
- waldiez/models/agents/rag_user/vector_db_config.py +5 -3
- waldiez/models/agents/swarm_agent/__init__.py +49 -0
- waldiez/models/agents/swarm_agent/after_work.py +178 -0
- waldiez/models/agents/swarm_agent/on_condition.py +103 -0
- waldiez/models/agents/swarm_agent/on_condition_available.py +140 -0
- waldiez/models/agents/swarm_agent/on_condition_target.py +40 -0
- waldiez/models/agents/swarm_agent/swarm_agent.py +107 -0
- waldiez/models/agents/swarm_agent/swarm_agent_data.py +125 -0
- waldiez/models/agents/swarm_agent/update_system_message.py +144 -0
- waldiez/models/agents/user_proxy/__init__.py +2 -0
- waldiez/models/agents/user_proxy/user_proxy.py +2 -0
- waldiez/models/agents/user_proxy/user_proxy_data.py +2 -0
- waldiez/models/chat/__init__.py +21 -3
- waldiez/models/chat/chat.py +241 -7
- waldiez/models/chat/chat_data.py +192 -48
- waldiez/models/chat/chat_message.py +153 -144
- waldiez/models/chat/chat_nested.py +33 -53
- waldiez/models/chat/chat_summary.py +2 -0
- waldiez/models/common/__init__.py +6 -6
- waldiez/models/common/base.py +4 -1
- waldiez/models/common/method_utils.py +163 -83
- waldiez/models/flow/__init__.py +2 -0
- waldiez/models/flow/flow.py +176 -40
- waldiez/models/flow/flow_data.py +63 -2
- waldiez/models/flow/utils.py +172 -0
- waldiez/models/model/__init__.py +2 -0
- waldiez/models/model/model.py +25 -6
- waldiez/models/model/model_data.py +3 -1
- waldiez/models/skill/__init__.py +4 -1
- waldiez/models/skill/skill.py +30 -2
- waldiez/models/skill/skill_data.py +2 -0
- waldiez/models/waldiez.py +28 -4
- waldiez/runner.py +142 -228
- waldiez/running/__init__.py +33 -0
- waldiez/running/environment.py +83 -0
- waldiez/running/gen_seq_diagram.py +185 -0
- waldiez/running/running.py +300 -0
- {waldiez-0.2.2.dist-info → waldiez-0.3.0.dist-info}/METADATA +32 -26
- waldiez-0.3.0.dist-info/RECORD +125 -0
- waldiez-0.3.0.dist-info/licenses/LICENSE +201 -0
- waldiez/exporting/agents/__init__.py +0 -5
- waldiez/exporting/agents/agent.py +0 -236
- waldiez/exporting/agents/agent_skills.py +0 -67
- waldiez/exporting/agents/llm_config.py +0 -53
- waldiez/exporting/chats/chats.py +0 -46
- waldiez/exporting/chats/helpers.py +0 -420
- waldiez/exporting/flow/def_main.py +0 -32
- waldiez/exporting/flow/flow.py +0 -189
- waldiez/exporting/utils/__init__.py +0 -36
- waldiez/exporting/utils/importing.py +0 -265
- waldiez/exporting/utils/method_utils.py +0 -35
- waldiez/exporting/utils/path_check.py +0 -51
- waldiez-0.2.2.dist-info/RECORD +0 -92
- waldiez-0.2.2.dist-info/licenses/LICENSE +0 -21
- {waldiez-0.2.2.dist-info → waldiez-0.3.0.dist-info}/WHEEL +0 -0
- {waldiez-0.2.2.dist-info → waldiez-0.3.0.dist-info}/entry_points.txt +0 -0
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
# SPDX-License-Identifier: Apache-2.0.
|
|
2
|
+
# Copyright (c) 2024 - 2025 Waldiez and contributors.
|
|
3
|
+
"""Update the agent's system message before they reply."""
|
|
4
|
+
|
|
5
|
+
from typing import Optional, Tuple
|
|
6
|
+
|
|
7
|
+
from pydantic import Field, model_validator
|
|
8
|
+
from typing_extensions import Annotated, Literal, Self
|
|
9
|
+
|
|
10
|
+
from ...common import WaldiezBase, check_function, generate_function
|
|
11
|
+
|
|
12
|
+
WaldiezSwarmUpdateFunctionType = Literal["string", "callable"]
|
|
13
|
+
|
|
14
|
+
CUSTOM_UPDATE_SYSTEM_MESSAGE = "custom_update_system_message"
|
|
15
|
+
CUSTOM_UPDATE_SYSTEM_MESSAGE_ARGS = ["agent", "messages"]
|
|
16
|
+
CUSTOM_UPDATE_SYSTEM_MESSAGE_TYPES = (
|
|
17
|
+
["ConversableAgent", "List[Dict[str, Any]]"],
|
|
18
|
+
"str",
|
|
19
|
+
)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class WaldiezSwarmUpdateSystemMessage(WaldiezBase):
|
|
23
|
+
"""Update the agent's system message before they reply.
|
|
24
|
+
|
|
25
|
+
Attributes
|
|
26
|
+
----------
|
|
27
|
+
update_function_type : Literal["string", "callable"]
|
|
28
|
+
The type of the update function. Can be either a string or a callable.
|
|
29
|
+
update_function : str
|
|
30
|
+
The string template or function definition to update
|
|
31
|
+
the agent's system message. Can be a string or a Callable.
|
|
32
|
+
If the `function_type` is 'string' it will be used as a
|
|
33
|
+
template and substitute the context variables.
|
|
34
|
+
If the `function_type` is 'callable', it should have the signature:
|
|
35
|
+
```
|
|
36
|
+
def custom_update_system_message(
|
|
37
|
+
agent: ConversableAgent,
|
|
38
|
+
messages: List[Dict[str, Any]]
|
|
39
|
+
) -> str:
|
|
40
|
+
|
|
41
|
+
```
|
|
42
|
+
"""
|
|
43
|
+
|
|
44
|
+
update_function_type: Annotated[
|
|
45
|
+
WaldiezSwarmUpdateFunctionType,
|
|
46
|
+
Field(
|
|
47
|
+
"string",
|
|
48
|
+
title="Function Type",
|
|
49
|
+
alias="updateFunctionType",
|
|
50
|
+
description=(
|
|
51
|
+
"The type of the update function. "
|
|
52
|
+
"Can be either 'string' or 'callable'."
|
|
53
|
+
),
|
|
54
|
+
),
|
|
55
|
+
]
|
|
56
|
+
|
|
57
|
+
update_function: Annotated[
|
|
58
|
+
str,
|
|
59
|
+
Field(
|
|
60
|
+
...,
|
|
61
|
+
title="Update Function",
|
|
62
|
+
alias="updateFunction",
|
|
63
|
+
description=(
|
|
64
|
+
"The string template or function definition to update "
|
|
65
|
+
"the agent's system message. Can be a string or a Callable. "
|
|
66
|
+
"If the `update_function_type` is 'string', "
|
|
67
|
+
" it will be used as a template and substitute "
|
|
68
|
+
"the context variables. If `update_function_type` "
|
|
69
|
+
"is 'callable', it should have signature: "
|
|
70
|
+
"def custom_update_system_message("
|
|
71
|
+
" agent: ConversableAgent, "
|
|
72
|
+
" messages: List[Dict[str, Any]] "
|
|
73
|
+
") -> str"
|
|
74
|
+
),
|
|
75
|
+
),
|
|
76
|
+
]
|
|
77
|
+
|
|
78
|
+
_update_function: str = ""
|
|
79
|
+
|
|
80
|
+
def get_update_function(
|
|
81
|
+
self,
|
|
82
|
+
name_prefix: Optional[str] = None,
|
|
83
|
+
name_suffix: Optional[str] = None,
|
|
84
|
+
) -> Tuple[str, str]:
|
|
85
|
+
"""Get the update function.
|
|
86
|
+
|
|
87
|
+
Parameters
|
|
88
|
+
----------
|
|
89
|
+
name_prefix : str, optional
|
|
90
|
+
The prefix of the name, by default None
|
|
91
|
+
name_suffix : str, optional
|
|
92
|
+
The suffix of the name, by default None
|
|
93
|
+
|
|
94
|
+
Returns
|
|
95
|
+
-------
|
|
96
|
+
Tuple[str, str]
|
|
97
|
+
The update function and the function name.
|
|
98
|
+
|
|
99
|
+
"""
|
|
100
|
+
function_name = CUSTOM_UPDATE_SYSTEM_MESSAGE
|
|
101
|
+
if name_prefix:
|
|
102
|
+
function_name = f"{name_prefix}_{function_name}"
|
|
103
|
+
if name_suffix:
|
|
104
|
+
function_name = f"{function_name}_{name_suffix}"
|
|
105
|
+
return (
|
|
106
|
+
generate_function(
|
|
107
|
+
function_name=function_name,
|
|
108
|
+
function_args=CUSTOM_UPDATE_SYSTEM_MESSAGE_ARGS,
|
|
109
|
+
function_types=CUSTOM_UPDATE_SYSTEM_MESSAGE_TYPES,
|
|
110
|
+
function_body=self._update_function,
|
|
111
|
+
),
|
|
112
|
+
function_name,
|
|
113
|
+
)
|
|
114
|
+
|
|
115
|
+
@model_validator(mode="after")
|
|
116
|
+
def validate_update_system_message(self) -> Self:
|
|
117
|
+
"""Validate the update system message function.
|
|
118
|
+
|
|
119
|
+
Returns
|
|
120
|
+
-------
|
|
121
|
+
UpdateSystemMessage
|
|
122
|
+
The validated update system message.
|
|
123
|
+
|
|
124
|
+
Raises
|
|
125
|
+
------
|
|
126
|
+
ValueError
|
|
127
|
+
If the type is callable and the function is invalid.
|
|
128
|
+
or if the function type is not 'string' or 'callable'.
|
|
129
|
+
|
|
130
|
+
"""
|
|
131
|
+
self._update_function = self.update_function
|
|
132
|
+
if self.update_function_type == "callable":
|
|
133
|
+
valid, error_or_body = check_function(
|
|
134
|
+
code_string=self.update_function,
|
|
135
|
+
function_name=CUSTOM_UPDATE_SYSTEM_MESSAGE,
|
|
136
|
+
function_args=CUSTOM_UPDATE_SYSTEM_MESSAGE_ARGS,
|
|
137
|
+
)
|
|
138
|
+
if not valid or not error_or_body:
|
|
139
|
+
# pylint: disable=inconsistent-quotes
|
|
140
|
+
raise ValueError(
|
|
141
|
+
f"Invalid custom method: {error_or_body or 'no content'}"
|
|
142
|
+
)
|
|
143
|
+
self._update_function = error_or_body
|
|
144
|
+
return self
|
waldiez/models/chat/__init__.py
CHANGED
|
@@ -1,16 +1,35 @@
|
|
|
1
|
+
# SPDX-License-Identifier: Apache-2.0.
|
|
2
|
+
# Copyright (c) 2024 - 2025 Waldiez and contributors.
|
|
1
3
|
"""Waldiez chat related models."""
|
|
2
4
|
|
|
3
5
|
from .chat import WaldiezChat
|
|
4
6
|
from .chat_data import WaldiezChatData
|
|
5
7
|
from .chat_message import (
|
|
8
|
+
CALLABLE_MESSAGE,
|
|
9
|
+
CALLABLE_MESSAGE_ARGS,
|
|
10
|
+
CALLABLE_MESSAGE_RAG_WITH_CARRYOVER_TYPES,
|
|
11
|
+
CALLABLE_MESSAGE_TYPES,
|
|
6
12
|
WaldiezChatMessage,
|
|
7
13
|
WaldiezChatMessageType,
|
|
8
|
-
validate_message_dict,
|
|
9
14
|
)
|
|
10
|
-
from .chat_nested import
|
|
15
|
+
from .chat_nested import (
|
|
16
|
+
NESTED_CHAT_ARGS,
|
|
17
|
+
NESTED_CHAT_MESSAGE,
|
|
18
|
+
NESTED_CHAT_REPLY,
|
|
19
|
+
NESTED_CHAT_TYPES,
|
|
20
|
+
WaldiezChatNested,
|
|
21
|
+
)
|
|
11
22
|
from .chat_summary import WaldiezChatSummary, WaldiezChatSummaryMethod
|
|
12
23
|
|
|
13
24
|
__all__ = [
|
|
25
|
+
"CALLABLE_MESSAGE",
|
|
26
|
+
"CALLABLE_MESSAGE_ARGS",
|
|
27
|
+
"CALLABLE_MESSAGE_TYPES",
|
|
28
|
+
"CALLABLE_MESSAGE_RAG_WITH_CARRYOVER_TYPES",
|
|
29
|
+
"NESTED_CHAT_MESSAGE",
|
|
30
|
+
"NESTED_CHAT_REPLY",
|
|
31
|
+
"NESTED_CHAT_ARGS",
|
|
32
|
+
"NESTED_CHAT_TYPES",
|
|
14
33
|
"WaldiezChat",
|
|
15
34
|
"WaldiezChatData",
|
|
16
35
|
"WaldiezChatMessage",
|
|
@@ -18,5 +37,4 @@ __all__ = [
|
|
|
18
37
|
"WaldiezChatNested",
|
|
19
38
|
"WaldiezChatSummary",
|
|
20
39
|
"WaldiezChatSummaryMethod",
|
|
21
|
-
"validate_message_dict",
|
|
22
40
|
]
|
waldiez/models/chat/chat.py
CHANGED
|
@@ -1,15 +1,30 @@
|
|
|
1
|
+
# SPDX-License-Identifier: Apache-2.0.
|
|
2
|
+
# Copyright (c) 2024 - 2025 Waldiez and contributors.
|
|
1
3
|
"""Waldiez chat model."""
|
|
2
4
|
|
|
3
|
-
from typing import Any, Dict, Optional
|
|
5
|
+
from typing import Any, Dict, List, Optional, Tuple
|
|
4
6
|
|
|
5
7
|
from pydantic import Field
|
|
6
8
|
from typing_extensions import Annotated
|
|
7
9
|
|
|
8
|
-
from ..agents import WaldiezAgent, WaldiezRagUser
|
|
9
|
-
from ..common import WaldiezBase
|
|
10
|
+
from ..agents import WaldiezAgent, WaldiezRagUser, WaldiezSwarmAfterWork
|
|
11
|
+
from ..common import WaldiezBase, generate_function
|
|
10
12
|
from .chat_data import WaldiezChatData
|
|
11
|
-
from .chat_message import
|
|
12
|
-
|
|
13
|
+
from .chat_message import (
|
|
14
|
+
CALLABLE_MESSAGE,
|
|
15
|
+
CALLABLE_MESSAGE_ARGS,
|
|
16
|
+
CALLABLE_MESSAGE_RAG_WITH_CARRYOVER_TYPES,
|
|
17
|
+
CALLABLE_MESSAGE_TYPES,
|
|
18
|
+
RAG_METHOD_WITH_CARRYOVER_BODY,
|
|
19
|
+
WaldiezChatMessage,
|
|
20
|
+
)
|
|
21
|
+
from .chat_nested import (
|
|
22
|
+
NESTED_CHAT_ARGS,
|
|
23
|
+
NESTED_CHAT_MESSAGE,
|
|
24
|
+
NESTED_CHAT_REPLY,
|
|
25
|
+
NESTED_CHAT_TYPES,
|
|
26
|
+
WaldiezChatNested,
|
|
27
|
+
)
|
|
13
28
|
|
|
14
29
|
|
|
15
30
|
class WaldiezChat(WaldiezBase):
|
|
@@ -63,6 +78,11 @@ class WaldiezChat(WaldiezBase):
|
|
|
63
78
|
"""Get the name."""
|
|
64
79
|
return self.data.name
|
|
65
80
|
|
|
81
|
+
@property
|
|
82
|
+
def description(self) -> str:
|
|
83
|
+
"""Get the description."""
|
|
84
|
+
return self.data.description
|
|
85
|
+
|
|
66
86
|
@property
|
|
67
87
|
def source(self) -> str:
|
|
68
88
|
"""Get the source."""
|
|
@@ -77,6 +97,11 @@ class WaldiezChat(WaldiezBase):
|
|
|
77
97
|
return self.data.real_target
|
|
78
98
|
return self.data.target
|
|
79
99
|
|
|
100
|
+
@property
|
|
101
|
+
def order(self) -> int:
|
|
102
|
+
"""Get the order."""
|
|
103
|
+
return self.data.order
|
|
104
|
+
|
|
80
105
|
@property
|
|
81
106
|
def nested_chat(self) -> WaldiezChatNested:
|
|
82
107
|
"""Get the nested chat."""
|
|
@@ -101,22 +126,204 @@ class WaldiezChat(WaldiezBase):
|
|
|
101
126
|
"""Get the message content."""
|
|
102
127
|
return self.data.message_content
|
|
103
128
|
|
|
129
|
+
@property
|
|
130
|
+
def context_variables(self) -> Dict[str, Any]:
|
|
131
|
+
"""Get the context variables."""
|
|
132
|
+
return self.data.context_variables or {}
|
|
133
|
+
|
|
134
|
+
@property
|
|
135
|
+
def max_rounds(self) -> int:
|
|
136
|
+
"""Get the max rounds for swarm chat."""
|
|
137
|
+
return self.data.max_rounds
|
|
138
|
+
|
|
139
|
+
@property
|
|
140
|
+
def after_work(self) -> Optional[WaldiezSwarmAfterWork]:
|
|
141
|
+
"""Get the after work."""
|
|
142
|
+
return self.data.after_work
|
|
143
|
+
|
|
144
|
+
@property
|
|
145
|
+
def chat_id(self) -> int:
|
|
146
|
+
"""Get the chat ID."""
|
|
147
|
+
return self.data.get_chat_id()
|
|
148
|
+
|
|
149
|
+
@property
|
|
150
|
+
def prerequisites(self) -> List[int]:
|
|
151
|
+
"""Get the chat prerequisites."""
|
|
152
|
+
return self.data.get_prerequisites()
|
|
153
|
+
|
|
154
|
+
def set_chat_id(self, value: int) -> None:
|
|
155
|
+
"""Set the chat ID.
|
|
156
|
+
|
|
157
|
+
Parameters
|
|
158
|
+
----------
|
|
159
|
+
value : int
|
|
160
|
+
The chat ID.
|
|
161
|
+
"""
|
|
162
|
+
self.data.set_chat_id(value)
|
|
163
|
+
|
|
164
|
+
def set_prerequisites(self, value: List[int]) -> None:
|
|
165
|
+
"""Set the chat prerequisites.
|
|
166
|
+
|
|
167
|
+
Parameters
|
|
168
|
+
----------
|
|
169
|
+
value : List[int]
|
|
170
|
+
The chat prerequisites.
|
|
171
|
+
"""
|
|
172
|
+
self.data.set_prerequisites(value)
|
|
173
|
+
|
|
174
|
+
def get_message_function(
|
|
175
|
+
self,
|
|
176
|
+
name_prefix: Optional[str] = None,
|
|
177
|
+
name_suffix: Optional[str] = None,
|
|
178
|
+
is_rag: bool = False,
|
|
179
|
+
) -> Tuple[str, str]:
|
|
180
|
+
"""Get the message function.
|
|
181
|
+
|
|
182
|
+
Parameters
|
|
183
|
+
----------
|
|
184
|
+
name_prefix : str
|
|
185
|
+
The function name prefix.
|
|
186
|
+
name_suffix : str
|
|
187
|
+
The function name suffix.
|
|
188
|
+
is_rag : bool
|
|
189
|
+
If the message is from a RAG user.
|
|
190
|
+
|
|
191
|
+
Returns
|
|
192
|
+
-------
|
|
193
|
+
Tuple[str, str]
|
|
194
|
+
The message function and the function name.
|
|
195
|
+
"""
|
|
196
|
+
if self.message.type in ("string", "none") or (
|
|
197
|
+
not self.message_content and is_rag is False
|
|
198
|
+
):
|
|
199
|
+
return "", ""
|
|
200
|
+
function_types = CALLABLE_MESSAGE_TYPES
|
|
201
|
+
function_name = CALLABLE_MESSAGE
|
|
202
|
+
if name_prefix:
|
|
203
|
+
function_name = f"{name_prefix}_{function_name}"
|
|
204
|
+
if name_suffix:
|
|
205
|
+
function_name = f"{function_name}_{name_suffix}"
|
|
206
|
+
if is_rag and self.message.type == "rag_message_generator":
|
|
207
|
+
function_types = CALLABLE_MESSAGE_RAG_WITH_CARRYOVER_TYPES
|
|
208
|
+
return (
|
|
209
|
+
generate_function(
|
|
210
|
+
function_name=function_name,
|
|
211
|
+
function_args=CALLABLE_MESSAGE_ARGS,
|
|
212
|
+
function_types=function_types,
|
|
213
|
+
function_body=self.message.content_body
|
|
214
|
+
or RAG_METHOD_WITH_CARRYOVER_BODY,
|
|
215
|
+
),
|
|
216
|
+
function_name,
|
|
217
|
+
)
|
|
218
|
+
return (
|
|
219
|
+
generate_function(
|
|
220
|
+
function_name=function_name,
|
|
221
|
+
function_args=CALLABLE_MESSAGE_ARGS,
|
|
222
|
+
function_types=function_types,
|
|
223
|
+
function_body=self.message_content or "",
|
|
224
|
+
),
|
|
225
|
+
function_name,
|
|
226
|
+
)
|
|
227
|
+
|
|
228
|
+
def get_nested_chat_message_function(
|
|
229
|
+
self,
|
|
230
|
+
name_prefix: Optional[str] = None,
|
|
231
|
+
name_suffix: Optional[str] = None,
|
|
232
|
+
) -> Tuple[str, str]:
|
|
233
|
+
"""Get the nested chat message function.
|
|
234
|
+
|
|
235
|
+
Parameters
|
|
236
|
+
----------
|
|
237
|
+
name_prefix : str
|
|
238
|
+
The function name prefix.
|
|
239
|
+
name_suffix : str
|
|
240
|
+
The function name suffix.
|
|
241
|
+
|
|
242
|
+
Returns
|
|
243
|
+
-------
|
|
244
|
+
Tuple[str, str]
|
|
245
|
+
The nested chat message function and the function name.
|
|
246
|
+
"""
|
|
247
|
+
if (
|
|
248
|
+
not self.nested_chat.message
|
|
249
|
+
or self.nested_chat.message.type in ("string", "none")
|
|
250
|
+
or not self.nested_chat.message_content
|
|
251
|
+
):
|
|
252
|
+
return "", ""
|
|
253
|
+
function_name = NESTED_CHAT_MESSAGE
|
|
254
|
+
if name_prefix:
|
|
255
|
+
function_name = f"{name_prefix}_{function_name}"
|
|
256
|
+
if name_suffix:
|
|
257
|
+
function_name = f"{function_name}_{name_suffix}"
|
|
258
|
+
return (
|
|
259
|
+
generate_function(
|
|
260
|
+
function_name=function_name,
|
|
261
|
+
function_args=NESTED_CHAT_ARGS,
|
|
262
|
+
function_types=NESTED_CHAT_TYPES,
|
|
263
|
+
function_body=self.nested_chat.message_content,
|
|
264
|
+
),
|
|
265
|
+
function_name,
|
|
266
|
+
)
|
|
267
|
+
|
|
268
|
+
def get_nested_chat_reply_function(
|
|
269
|
+
self,
|
|
270
|
+
name_prefix: Optional[str] = None,
|
|
271
|
+
name_suffix: Optional[str] = None,
|
|
272
|
+
) -> Tuple[str, str]:
|
|
273
|
+
"""Get the nested chat reply function.
|
|
274
|
+
|
|
275
|
+
Parameters
|
|
276
|
+
----------
|
|
277
|
+
name_prefix : str
|
|
278
|
+
The function name prefix.
|
|
279
|
+
name_suffix : str
|
|
280
|
+
The function name suffix.
|
|
281
|
+
|
|
282
|
+
Returns
|
|
283
|
+
-------
|
|
284
|
+
Tuple[str, str]
|
|
285
|
+
The nested chat reply function and the function name.
|
|
286
|
+
"""
|
|
287
|
+
if (
|
|
288
|
+
not self.nested_chat.reply
|
|
289
|
+
or self.nested_chat.reply.type in ("string", "none")
|
|
290
|
+
or not self.nested_chat.reply_content
|
|
291
|
+
):
|
|
292
|
+
return "", ""
|
|
293
|
+
function_name = NESTED_CHAT_REPLY
|
|
294
|
+
if name_prefix:
|
|
295
|
+
function_name = f"{name_prefix}_{function_name}"
|
|
296
|
+
if name_suffix:
|
|
297
|
+
function_name = f"{function_name}_{name_suffix}"
|
|
298
|
+
return (
|
|
299
|
+
generate_function(
|
|
300
|
+
function_name=function_name,
|
|
301
|
+
function_args=NESTED_CHAT_ARGS,
|
|
302
|
+
function_types=NESTED_CHAT_TYPES,
|
|
303
|
+
function_body=self.nested_chat.reply_content,
|
|
304
|
+
),
|
|
305
|
+
function_name,
|
|
306
|
+
)
|
|
307
|
+
|
|
104
308
|
def get_chat_args(
|
|
105
309
|
self,
|
|
310
|
+
for_queue: bool,
|
|
106
311
|
sender: Optional[WaldiezAgent] = None,
|
|
107
312
|
) -> Dict[str, Any]:
|
|
108
313
|
"""Get the chat arguments to use in autogen.
|
|
109
314
|
|
|
110
315
|
Parameters
|
|
111
316
|
----------
|
|
112
|
-
|
|
317
|
+
for_queue : bool
|
|
318
|
+
Whether to get the chat arguments for a chat queue.
|
|
319
|
+
sender : WaldiezAgent, optional
|
|
113
320
|
The sender agent, to check if it's a RAG user.
|
|
114
321
|
Returns
|
|
115
322
|
-------
|
|
116
323
|
dict
|
|
117
324
|
The chat arguments.
|
|
118
325
|
"""
|
|
119
|
-
args_dict = self.data.get_chat_args()
|
|
326
|
+
args_dict = self.data.get_chat_args(for_queue)
|
|
120
327
|
if (
|
|
121
328
|
isinstance(sender, WaldiezRagUser)
|
|
122
329
|
and sender.agent_type == "rag_user"
|
|
@@ -127,3 +334,30 @@ class WaldiezChat(WaldiezBase):
|
|
|
127
334
|
if isinstance(n_results, int) and n_results > 0:
|
|
128
335
|
args_dict["n_results"] = n_results
|
|
129
336
|
return args_dict
|
|
337
|
+
|
|
338
|
+
def model_dump(self, **kwargs: Any) -> Dict[str, Any]:
|
|
339
|
+
"""Dump the model to a dict including the chat attributes.
|
|
340
|
+
|
|
341
|
+
Parameters
|
|
342
|
+
----------
|
|
343
|
+
kwargs : Any
|
|
344
|
+
The keyword arguments.
|
|
345
|
+
Returns
|
|
346
|
+
-------
|
|
347
|
+
Dict[str, Any]
|
|
348
|
+
The model dump with the chat attributes.
|
|
349
|
+
"""
|
|
350
|
+
dump = super().model_dump(**kwargs)
|
|
351
|
+
dump["name"] = self.name
|
|
352
|
+
dump["description"] = self.description
|
|
353
|
+
dump["source"] = self.source
|
|
354
|
+
dump["target"] = self.target
|
|
355
|
+
dump["nested_chat"] = self.nested_chat.model_dump()
|
|
356
|
+
dump["message"] = self.message.model_dump()
|
|
357
|
+
dump["message_content"] = self.message_content
|
|
358
|
+
dump["context_variables"] = self.context_variables
|
|
359
|
+
dump["max_rounds"] = self.max_rounds
|
|
360
|
+
dump["after_work"] = (
|
|
361
|
+
self.after_work.model_dump() if self.after_work else None
|
|
362
|
+
)
|
|
363
|
+
return dump
|