waldiez 0.3.11__py3-none-any.whl → 0.3.12__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/_version.py +1 -1
- waldiez/exporting/agent/agent_exporter.py +22 -15
- waldiez/exporting/agent/utils/__init__.py +2 -4
- waldiez/exporting/agent/utils/captain_agent.py +254 -0
- waldiez/exporting/flow/flow_exporter.py +3 -6
- waldiez/exporting/flow/utils/def_main.py +5 -4
- waldiez/models/__init__.py +6 -0
- waldiez/models/agents/__init__.py +14 -0
- waldiez/models/agents/agent/agent.py +71 -8
- waldiez/models/agents/agents.py +11 -1
- waldiez/models/agents/captain_agent/__init__.py +15 -0
- waldiez/models/agents/captain_agent/captain_agent.py +45 -0
- waldiez/models/agents/captain_agent/captain_agent_data.py +62 -0
- waldiez/models/agents/captain_agent/captain_agent_lib_entry.py +38 -0
- waldiez/models/agents/extra_requirements.py +88 -0
- waldiez/models/common/__init__.py +2 -0
- waldiez/models/common/ag2_version.py +30 -0
- waldiez/models/common/base.py +1 -1
- waldiez/models/common/date_utils.py +2 -0
- waldiez/models/common/dict_utils.py +2 -0
- waldiez/models/flow/__init__.py +2 -0
- waldiez/models/flow/utils.py +61 -1
- waldiez/models/model/__init__.py +2 -0
- waldiez/models/model/extra_requirements.py +55 -0
- waldiez/models/model/model.py +5 -2
- waldiez/models/model/model_data.py +2 -1
- waldiez/models/waldiez.py +16 -75
- {waldiez-0.3.11.dist-info → waldiez-0.3.12.dist-info}/METADATA +27 -18
- {waldiez-0.3.11.dist-info → waldiez-0.3.12.dist-info}/RECORD +33 -27
- waldiez/exporting/agent/utils/agent_class_name.py +0 -36
- waldiez/exporting/agent/utils/agent_imports.py +0 -55
- {waldiez-0.3.11.dist-info → waldiez-0.3.12.dist-info}/WHEEL +0 -0
- {waldiez-0.3.11.dist-info → waldiez-0.3.12.dist-info}/entry_points.txt +0 -0
- {waldiez-0.3.11.dist-info → waldiez-0.3.12.dist-info}/licenses/LICENSE +0 -0
- {waldiez-0.3.11.dist-info → waldiez-0.3.12.dist-info}/licenses/NOTICE.md +0 -0
waldiez/_version.py
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
from pathlib import Path
|
|
7
7
|
from typing import Callable, Dict, List, Optional, Tuple, Union
|
|
8
8
|
|
|
9
|
-
from waldiez.models import WaldiezAgent, WaldiezChat
|
|
9
|
+
from waldiez.models import WaldiezAgent, WaldiezChat, WaldiezModel
|
|
10
10
|
|
|
11
11
|
from ..base import (
|
|
12
12
|
AgentPosition,
|
|
@@ -18,9 +18,8 @@ from ..base import (
|
|
|
18
18
|
ImportPosition,
|
|
19
19
|
)
|
|
20
20
|
from .utils import (
|
|
21
|
-
get_agent_class_name,
|
|
22
21
|
get_agent_code_execution_config,
|
|
23
|
-
|
|
22
|
+
get_captain_agent_extras,
|
|
24
23
|
get_group_manager_extras,
|
|
25
24
|
get_is_termination_message,
|
|
26
25
|
get_rag_user_extras,
|
|
@@ -36,9 +35,9 @@ class AgentExporter(BaseExporter, ExporterMixin):
|
|
|
36
35
|
self,
|
|
37
36
|
agent: WaldiezAgent,
|
|
38
37
|
agent_names: Dict[str, str],
|
|
39
|
-
|
|
40
|
-
skill_names: Dict[str, str],
|
|
38
|
+
models: Tuple[List[WaldiezModel], Dict[str, str]],
|
|
41
39
|
chats: Tuple[List[WaldiezChat], Dict[str, str]],
|
|
40
|
+
skill_names: Dict[str, str],
|
|
42
41
|
is_async: bool,
|
|
43
42
|
group_chat_members: List[WaldiezAgent],
|
|
44
43
|
for_notebook: bool,
|
|
@@ -53,12 +52,12 @@ class AgentExporter(BaseExporter, ExporterMixin):
|
|
|
53
52
|
The agent to export.
|
|
54
53
|
agent_names : Dict[str, str]
|
|
55
54
|
The agent ids to names mapping.
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
skill_names : Dict[str, str]
|
|
59
|
-
The skill ids to names mapping.
|
|
55
|
+
models : Tuple[List[WaldiezModel], Dict[str, str]]
|
|
56
|
+
All the models and the model ids to names mapping.
|
|
60
57
|
chats : Tuple[List[WaldiezChat], Dict[str, str]]
|
|
61
58
|
All the chats and the chat ids to names mapping.
|
|
59
|
+
skill_names : Dict[str, str]
|
|
60
|
+
The skill ids to names mapping.
|
|
62
61
|
is_async : bool
|
|
63
62
|
Whether the whole flow is async.
|
|
64
63
|
for_notebook : bool
|
|
@@ -72,14 +71,14 @@ class AgentExporter(BaseExporter, ExporterMixin):
|
|
|
72
71
|
if output_dir is not None and not isinstance(output_dir, Path):
|
|
73
72
|
output_dir = Path(output_dir)
|
|
74
73
|
self.output_dir = output_dir
|
|
75
|
-
self.
|
|
74
|
+
self.models = models[0]
|
|
75
|
+
self.model_names = models[1]
|
|
76
76
|
self.skill_names = skill_names
|
|
77
77
|
self.arguments_resolver = arguments_resolver
|
|
78
78
|
self.group_chat_members = group_chat_members
|
|
79
79
|
self.chats = chats
|
|
80
80
|
self.is_async = is_async
|
|
81
81
|
self._agent_name = agent_names[agent.id]
|
|
82
|
-
self._agent_class = get_agent_class_name(self.agent)
|
|
83
82
|
# content, argument, import
|
|
84
83
|
self._code_execution = get_agent_code_execution_config(
|
|
85
84
|
agent=self.agent,
|
|
@@ -119,6 +118,13 @@ class AgentExporter(BaseExporter, ExporterMixin):
|
|
|
119
118
|
agent=self.agent,
|
|
120
119
|
serializer=self.serializer,
|
|
121
120
|
)
|
|
121
|
+
self._captain = get_captain_agent_extras(
|
|
122
|
+
agent=self.agent,
|
|
123
|
+
agent_names=self.agent_names,
|
|
124
|
+
all_models=self.models,
|
|
125
|
+
serializer=self.serializer,
|
|
126
|
+
output_dir=self.output_dir,
|
|
127
|
+
)
|
|
122
128
|
|
|
123
129
|
def get_imports(self) -> Optional[List[Tuple[str, ImportPosition]]]:
|
|
124
130
|
"""Get the imports.
|
|
@@ -130,7 +136,7 @@ class AgentExporter(BaseExporter, ExporterMixin):
|
|
|
130
136
|
"""
|
|
131
137
|
position = ImportPosition.THIRD_PARTY
|
|
132
138
|
# default imports based on the agent class.
|
|
133
|
-
agent_imports =
|
|
139
|
+
agent_imports = self.agent.ag2_imports
|
|
134
140
|
# if code execution is enabled, update the imports.
|
|
135
141
|
if self._code_execution[2]:
|
|
136
142
|
agent_imports.add(self._code_execution[2])
|
|
@@ -220,7 +226,6 @@ class AgentExporter(BaseExporter, ExporterMixin):
|
|
|
220
226
|
"""
|
|
221
227
|
agent = self.agent
|
|
222
228
|
agent_name = self._agent_name
|
|
223
|
-
agent_class = self._agent_class
|
|
224
229
|
retrieve_arg = self._rag[1]
|
|
225
230
|
group_chat_arg = self._group_chat[1]
|
|
226
231
|
is_termination = self._termination[0]
|
|
@@ -231,8 +236,10 @@ class AgentExporter(BaseExporter, ExporterMixin):
|
|
|
231
236
|
default_auto_reply = (
|
|
232
237
|
f'"{self.string_escape(agent.data.agent_default_auto_reply)}"'
|
|
233
238
|
)
|
|
234
|
-
extras =
|
|
235
|
-
|
|
239
|
+
extras = (
|
|
240
|
+
f"{group_chat_arg}{retrieve_arg}{self._reasoning}{self._captain}"
|
|
241
|
+
)
|
|
242
|
+
agent_str = f"""{agent_name} = {self.agent.ag2_class}(
|
|
236
243
|
name="{agent_name}",
|
|
237
244
|
description="{agent.description}"{system_message_arg},
|
|
238
245
|
human_input_mode="{agent.data.human_input_mode}",
|
|
@@ -2,8 +2,7 @@
|
|
|
2
2
|
# Copyright (c) 2024 - 2025 Waldiez and contributors.
|
|
3
3
|
"""Utility functions for generating agent related strings."""
|
|
4
4
|
|
|
5
|
-
from .
|
|
6
|
-
from .agent_imports import get_agent_imports
|
|
5
|
+
from .captain_agent import get_captain_agent_extras
|
|
7
6
|
from .code_execution import get_agent_code_execution_config
|
|
8
7
|
from .group_manager import get_group_manager_extras
|
|
9
8
|
from .rag_user import get_rag_user_extras
|
|
@@ -13,10 +12,9 @@ from .teachability import get_agent_teachability_string
|
|
|
13
12
|
from .termination_message import get_is_termination_message
|
|
14
13
|
|
|
15
14
|
__all__ = [
|
|
16
|
-
"get_agent_class_name",
|
|
17
|
-
"get_agent_imports",
|
|
18
15
|
"get_agent_code_execution_config",
|
|
19
16
|
"get_agent_teachability_string",
|
|
17
|
+
"get_captain_agent_extras",
|
|
20
18
|
"get_group_manager_extras",
|
|
21
19
|
"get_is_termination_message",
|
|
22
20
|
"get_rag_user_extras",
|
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
# SPDX-License-Identifier: Apache-2.0.
|
|
2
|
+
# Copyright (c) 2024 - 2025 Waldiez and contributors.
|
|
3
|
+
""" "Extras for exporting a captain agent."""
|
|
4
|
+
|
|
5
|
+
import json
|
|
6
|
+
import os
|
|
7
|
+
from datetime import datetime, timezone
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
from typing import Any, Callable, Dict, List, Optional, Union
|
|
10
|
+
|
|
11
|
+
from waldiez.models import (
|
|
12
|
+
WaldiezAgent,
|
|
13
|
+
WaldiezCaptainAgent,
|
|
14
|
+
WaldiezModel,
|
|
15
|
+
WaldiezModelData,
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def get_captain_agent_extras(
|
|
20
|
+
agent: WaldiezAgent,
|
|
21
|
+
agent_names: Dict[str, str],
|
|
22
|
+
all_models: List[WaldiezModel],
|
|
23
|
+
serializer: Callable[..., str],
|
|
24
|
+
output_dir: Optional[Union[str, Path]],
|
|
25
|
+
) -> str:
|
|
26
|
+
"""Get the extra args for the captain agent.
|
|
27
|
+
|
|
28
|
+
Parameters
|
|
29
|
+
----------
|
|
30
|
+
agent : WaldiezAgent
|
|
31
|
+
The agent.
|
|
32
|
+
agent_names : Dict[str, str]
|
|
33
|
+
A mapping of agent ids to agent names.
|
|
34
|
+
all_models : List[WaldiezModel]
|
|
35
|
+
All the models in the flow.
|
|
36
|
+
serializer : Callable[..., str]
|
|
37
|
+
The serializer to use.
|
|
38
|
+
output_dir : Optional[Union[str, Path]]
|
|
39
|
+
The output directory to save the agent lib and nested config.
|
|
40
|
+
Returns
|
|
41
|
+
-------
|
|
42
|
+
str
|
|
43
|
+
The extra args to use in the captain agent.
|
|
44
|
+
"""
|
|
45
|
+
# extra args: nested_config, agent_lib, tool_lib
|
|
46
|
+
if not isinstance(agent, WaldiezCaptainAgent):
|
|
47
|
+
return ""
|
|
48
|
+
agent_name = agent_names[agent.id]
|
|
49
|
+
save_path = str(output_dir) if output_dir else "."
|
|
50
|
+
extra_args_content = "\n" + f' agent_config_save_path=r"{save_path}",'
|
|
51
|
+
if agent.data.agent_lib:
|
|
52
|
+
lib_dict = [
|
|
53
|
+
lib.model_dump(by_alias=False) for lib in agent.data.agent_lib
|
|
54
|
+
]
|
|
55
|
+
lib_json_name = f"{agent_name}_agent_lib.json"
|
|
56
|
+
agent_lib_path = os.path.join(save_path, lib_json_name)
|
|
57
|
+
with open(agent_lib_path, "w", encoding="utf-8", newline="\n") as f:
|
|
58
|
+
json.dump(lib_dict, f, ensure_ascii=False, indent=4)
|
|
59
|
+
extra_args_content += "\n" + f' agent_lib=r"{agent_lib_path}",'
|
|
60
|
+
if agent.data.tool_lib:
|
|
61
|
+
extra_args_content += "\n" + f' tool_lib="{agent.data.tool_lib}",'
|
|
62
|
+
nested_config = generate_nested_config(
|
|
63
|
+
agent,
|
|
64
|
+
agent_name,
|
|
65
|
+
all_models,
|
|
66
|
+
save_path,
|
|
67
|
+
)
|
|
68
|
+
serialized_nested_config = serializer(nested_config)
|
|
69
|
+
extra_args_content += (
|
|
70
|
+
"\n" + f" nested_config={serialized_nested_config},"
|
|
71
|
+
)
|
|
72
|
+
return extra_args_content
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def generate_nested_config(
|
|
76
|
+
agent: WaldiezCaptainAgent,
|
|
77
|
+
agent_name: str,
|
|
78
|
+
all_models: List[WaldiezModel],
|
|
79
|
+
save_path: str,
|
|
80
|
+
) -> Dict[str, Any]:
|
|
81
|
+
"""Generate the nested config for the captain agent.
|
|
82
|
+
|
|
83
|
+
Parameters
|
|
84
|
+
----------
|
|
85
|
+
agent : WaldiezCaptainAgent
|
|
86
|
+
The captain agent.
|
|
87
|
+
agent_name : str
|
|
88
|
+
The agent name.
|
|
89
|
+
all_models : List[WaldiezModel]
|
|
90
|
+
All the models in the flow.
|
|
91
|
+
save_path : str
|
|
92
|
+
The path to save the nested config.
|
|
93
|
+
Returns
|
|
94
|
+
-------
|
|
95
|
+
Dict[str, Any]
|
|
96
|
+
The nested config.
|
|
97
|
+
"""
|
|
98
|
+
config_file_or_env_name = f"{agent_name}_llm_config.json"
|
|
99
|
+
llm_config = get_llm_config(agent, all_models)
|
|
100
|
+
to_serialize = {
|
|
101
|
+
"config_list": [llm_config],
|
|
102
|
+
}
|
|
103
|
+
os.makedirs(save_path, exist_ok=True)
|
|
104
|
+
config_file_or_env_path = os.path.join(save_path, config_file_or_env_name)
|
|
105
|
+
with open(
|
|
106
|
+
config_file_or_env_path, "w", encoding="utf-8", newline="\n"
|
|
107
|
+
) as f:
|
|
108
|
+
json.dump(to_serialize, f, ensure_ascii=False, indent=4)
|
|
109
|
+
config_file_or_env = f'r"{config_file_or_env_path}"'
|
|
110
|
+
nested_config = {
|
|
111
|
+
"autobuild_init_config": {
|
|
112
|
+
"config_file_or_env": config_file_or_env,
|
|
113
|
+
"builder_model": llm_config["model"],
|
|
114
|
+
"agent_model": llm_config["model"],
|
|
115
|
+
},
|
|
116
|
+
"autobuild_build_config": get_auto_build_build_config(
|
|
117
|
+
agent, llm_config
|
|
118
|
+
),
|
|
119
|
+
"group_chat_config": {"max_round": agent.data.max_round},
|
|
120
|
+
"group_chat_llm_config": None,
|
|
121
|
+
"max_turns": agent.data.max_turns,
|
|
122
|
+
}
|
|
123
|
+
return nested_config
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
def get_llm_config(
|
|
127
|
+
agent: WaldiezAgent,
|
|
128
|
+
all_models: List[WaldiezModel],
|
|
129
|
+
) -> Dict[str, Any]:
|
|
130
|
+
"""Get the config list environment variable name and its dict value.
|
|
131
|
+
|
|
132
|
+
Parameters
|
|
133
|
+
----------
|
|
134
|
+
agent : WaldiezAgent
|
|
135
|
+
The agent.
|
|
136
|
+
all_models : List[WaldiezModel]
|
|
137
|
+
All the models in the flow.
|
|
138
|
+
Returns
|
|
139
|
+
-------
|
|
140
|
+
Dict[str, str]
|
|
141
|
+
The llm config dict.
|
|
142
|
+
"""
|
|
143
|
+
model_name = "gpt-4o"
|
|
144
|
+
temperature: Optional[float] = 1
|
|
145
|
+
top_p: Optional[float] = 0.95
|
|
146
|
+
max_tokens: Optional[int] = 2048
|
|
147
|
+
if agent.data.model_ids:
|
|
148
|
+
waldiez_model = get_waldiez_model(agent.data.model_ids[0], all_models)
|
|
149
|
+
model_name = waldiez_model.name
|
|
150
|
+
temperature = waldiez_model.data.temperature
|
|
151
|
+
top_p = waldiez_model.data.top_p
|
|
152
|
+
max_tokens = waldiez_model.data.max_tokens
|
|
153
|
+
config_dict = {
|
|
154
|
+
"model": model_name,
|
|
155
|
+
"temperature": temperature,
|
|
156
|
+
"top_p": top_p,
|
|
157
|
+
"max_tokens": max_tokens,
|
|
158
|
+
}
|
|
159
|
+
return config_dict
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
def get_auto_build_build_config(
|
|
163
|
+
agent: WaldiezAgent,
|
|
164
|
+
llm_config: Dict[str, Any],
|
|
165
|
+
) -> Dict[str, Any]:
|
|
166
|
+
"""Get the auto build build config.
|
|
167
|
+
|
|
168
|
+
Parameters
|
|
169
|
+
----------
|
|
170
|
+
agent : WaldiezAgent
|
|
171
|
+
The agent.
|
|
172
|
+
llm_config : Dict[str, Any]
|
|
173
|
+
The llm config.
|
|
174
|
+
|
|
175
|
+
Returns
|
|
176
|
+
-------
|
|
177
|
+
Dict[str, Any]
|
|
178
|
+
The auto build build config.
|
|
179
|
+
"""
|
|
180
|
+
coding = False
|
|
181
|
+
code_execution_config = {
|
|
182
|
+
"timeout": 300,
|
|
183
|
+
"work_dir": "groupchat",
|
|
184
|
+
"last_n_messages": 1,
|
|
185
|
+
"use_docker": False,
|
|
186
|
+
}
|
|
187
|
+
if agent.data.code_execution_config is not False:
|
|
188
|
+
coding = True
|
|
189
|
+
code_execution_config["work_dir"] = (
|
|
190
|
+
agent.data.code_execution_config.work_dir or "groupchat"
|
|
191
|
+
)
|
|
192
|
+
code_execution_config["last_n_messages"] = (
|
|
193
|
+
agent.data.code_execution_config.last_n_messages or 1
|
|
194
|
+
)
|
|
195
|
+
code_execution_config["timeout"] = (
|
|
196
|
+
agent.data.code_execution_config.timeout or 300
|
|
197
|
+
)
|
|
198
|
+
return {
|
|
199
|
+
"default_llm_config": {
|
|
200
|
+
"temperature": llm_config["temperature"],
|
|
201
|
+
"top_p": llm_config["top_p"],
|
|
202
|
+
"max_tokens": llm_config["max_tokens"],
|
|
203
|
+
},
|
|
204
|
+
"code_execution_config": code_execution_config,
|
|
205
|
+
"coding": coding,
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
|
|
209
|
+
def get_waldiez_model(
|
|
210
|
+
model_id: str, all_models: List[WaldiezModel]
|
|
211
|
+
) -> WaldiezModel:
|
|
212
|
+
"""Get the model name from the model id.
|
|
213
|
+
|
|
214
|
+
Parameters
|
|
215
|
+
----------
|
|
216
|
+
model_id : str
|
|
217
|
+
The model id.
|
|
218
|
+
all_models : List[WaldiezModel]
|
|
219
|
+
All the models in the flow.
|
|
220
|
+
|
|
221
|
+
Returns
|
|
222
|
+
-------
|
|
223
|
+
str
|
|
224
|
+
The model name.
|
|
225
|
+
"""
|
|
226
|
+
for model in all_models:
|
|
227
|
+
if model.id == model_id:
|
|
228
|
+
return model
|
|
229
|
+
now = (
|
|
230
|
+
datetime.now(tz=timezone.utc)
|
|
231
|
+
.isoformat(timespec="milliseconds")
|
|
232
|
+
.replace("+00:00", "Z")
|
|
233
|
+
)
|
|
234
|
+
return WaldiezModel(
|
|
235
|
+
id=model_id,
|
|
236
|
+
type="model",
|
|
237
|
+
name="gpt-4o",
|
|
238
|
+
description="The GPT-4o model.",
|
|
239
|
+
tags=["gpt-4o"],
|
|
240
|
+
requirements=[],
|
|
241
|
+
created_at=now,
|
|
242
|
+
updated_at=now,
|
|
243
|
+
data=WaldiezModelData(
|
|
244
|
+
api_type="openai",
|
|
245
|
+
temperature=1,
|
|
246
|
+
top_p=0.95,
|
|
247
|
+
max_tokens=2048,
|
|
248
|
+
base_url=None,
|
|
249
|
+
api_key=os.environ.get("OPENAI_API_KEY", "REPLACE_ME"),
|
|
250
|
+
api_version=None,
|
|
251
|
+
default_headers={},
|
|
252
|
+
price=None,
|
|
253
|
+
),
|
|
254
|
+
)
|
|
@@ -240,13 +240,10 @@ class FlowExporter(BaseExporter, ExporterMixin):
|
|
|
240
240
|
cache_seed=cache_seed,
|
|
241
241
|
)
|
|
242
242
|
else:
|
|
243
|
-
# content += f" with Cache.disk(cache_seed={cache_seed}" + "):\n"
|
|
244
|
-
# content += f"{flow_chats}" + "\n"
|
|
245
|
-
# content += "\n" + chats_content + "\n"
|
|
246
243
|
if chats_content.startswith("\n"):
|
|
247
244
|
chats_content = chats_content[1:]
|
|
248
245
|
content += (
|
|
249
|
-
"\n" + f"with Cache.disk(cache_seed={cache_seed}):"
|
|
246
|
+
"\n" + f"with Cache.disk(cache_seed={cache_seed}) as cache:"
|
|
250
247
|
"\n" + chats_content + "\n"
|
|
251
248
|
)
|
|
252
249
|
if is_async:
|
|
@@ -431,9 +428,9 @@ class FlowExporter(BaseExporter, ExporterMixin):
|
|
|
431
428
|
exporter = AgentExporter(
|
|
432
429
|
agent=agent,
|
|
433
430
|
agent_names=self.agent_names,
|
|
434
|
-
|
|
435
|
-
skill_names=self.skill_names,
|
|
431
|
+
models=(self.models, self.model_names),
|
|
436
432
|
chats=(self.chats, self.chat_names),
|
|
433
|
+
skill_names=self.skill_names,
|
|
437
434
|
is_async=self.waldiez.is_async,
|
|
438
435
|
for_notebook=self.for_notebook,
|
|
439
436
|
output_dir=self.output_dir,
|
|
@@ -53,7 +53,7 @@ def get_def_main(
|
|
|
53
53
|
else:
|
|
54
54
|
content += "def call_main() -> None:\n"
|
|
55
55
|
content += ' """Run the main function and print the results."""\n'
|
|
56
|
-
content += " results = "
|
|
56
|
+
content += " results: Union[ChatResult, List[ChatResult], Dict[int, ChatResult]] = "
|
|
57
57
|
if is_async:
|
|
58
58
|
content += "await "
|
|
59
59
|
content += "main()\n"
|
|
@@ -62,11 +62,12 @@ def get_def_main(
|
|
|
62
62
|
content += " ordered_results = dict(sorted(results.items()))\n"
|
|
63
63
|
content += " for _, result in ordered_results.items():\n"
|
|
64
64
|
content += " pprint(asdict(result))\n"
|
|
65
|
-
content += "
|
|
65
|
+
content += " else:\n"
|
|
66
|
+
content += " if not isinstance(results, list):\n"
|
|
67
|
+
content += " results = [results]\n"
|
|
66
68
|
content += " for result in results:\n"
|
|
67
69
|
content += " pprint(asdict(result))\n"
|
|
68
|
-
content += "
|
|
69
|
-
content += " pprint(asdict(results))\n\n\n"
|
|
70
|
+
content += "\n\n"
|
|
70
71
|
content += 'if __name__ == "__main__":\n'
|
|
71
72
|
if is_async:
|
|
72
73
|
content += " anyio.run(call_main)\n"
|
waldiez/models/__init__.py
CHANGED
|
@@ -23,6 +23,9 @@ from .agents import (
|
|
|
23
23
|
WaldiezAgentType,
|
|
24
24
|
WaldiezAssistant,
|
|
25
25
|
WaldiezAssistantData,
|
|
26
|
+
WaldiezCaptainAgent,
|
|
27
|
+
WaldiezCaptainAgentData,
|
|
28
|
+
WaldiezCaptainAgentLibEntry,
|
|
26
29
|
WaldiezGroupManager,
|
|
27
30
|
WaldiezGroupManagerData,
|
|
28
31
|
WaldiezGroupManagerSpeakers,
|
|
@@ -87,6 +90,9 @@ __all__ = [
|
|
|
87
90
|
"WaldiezAgentType",
|
|
88
91
|
"WaldiezAssistant",
|
|
89
92
|
"WaldiezAssistantData",
|
|
93
|
+
"WaldiezCaptainAgent",
|
|
94
|
+
"WaldiezCaptainAgentData",
|
|
95
|
+
"WaldiezCaptainAgentLibEntry",
|
|
90
96
|
"WaldiezChat",
|
|
91
97
|
"WaldiezChatData",
|
|
92
98
|
"WaldiezChatSummary",
|
|
@@ -18,6 +18,15 @@ from .agent import (
|
|
|
18
18
|
)
|
|
19
19
|
from .agents import WaldiezAgents
|
|
20
20
|
from .assistant import WaldiezAssistant, WaldiezAssistantData
|
|
21
|
+
from .captain_agent import (
|
|
22
|
+
WaldiezCaptainAgent,
|
|
23
|
+
WaldiezCaptainAgentData,
|
|
24
|
+
WaldiezCaptainAgentLibEntry,
|
|
25
|
+
)
|
|
26
|
+
from .extra_requirements import (
|
|
27
|
+
get_captain_agent_extra_requirements,
|
|
28
|
+
get_retrievechat_extra_requirements,
|
|
29
|
+
)
|
|
21
30
|
from .group_manager import (
|
|
22
31
|
CUSTOM_SPEAKER_SELECTION,
|
|
23
32
|
CUSTOM_SPEAKER_SELECTION_ARGS,
|
|
@@ -77,6 +86,8 @@ from .swarm_agent import (
|
|
|
77
86
|
from .user_proxy import WaldiezUserProxy, WaldiezUserProxyData
|
|
78
87
|
|
|
79
88
|
__all__ = [
|
|
89
|
+
"get_retrievechat_extra_requirements",
|
|
90
|
+
"get_captain_agent_extra_requirements",
|
|
80
91
|
"IS_TERMINATION_MESSAGE",
|
|
81
92
|
"IS_TERMINATION_MESSAGE_ARGS",
|
|
82
93
|
"IS_TERMINATION_MESSAGE_TYPES",
|
|
@@ -113,6 +124,9 @@ __all__ = [
|
|
|
113
124
|
"WaldiezAgentNestedChatMessage",
|
|
114
125
|
"WaldiezAgentTeachability",
|
|
115
126
|
"WaldiezAgentTerminationMessage",
|
|
127
|
+
"WaldiezCaptainAgent",
|
|
128
|
+
"WaldiezCaptainAgentData",
|
|
129
|
+
"WaldiezCaptainAgentLibEntry",
|
|
116
130
|
"WaldiezGroupManager",
|
|
117
131
|
"WaldiezGroupManagerData",
|
|
118
132
|
"WaldiezGroupManagerSpeakers",
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
# Copyright (c) 2024 - 2025 Waldiez and contributors.
|
|
3
3
|
"""Base agent class to be inherited by all agents."""
|
|
4
4
|
|
|
5
|
-
from typing import List
|
|
5
|
+
from typing import List, Set
|
|
6
6
|
|
|
7
7
|
from pydantic import Field
|
|
8
8
|
from typing_extensions import Annotated, Literal
|
|
@@ -12,7 +12,7 @@ from .agent_data import WaldiezAgentData
|
|
|
12
12
|
from .code_execution import WaldiezAgentCodeExecutionConfig
|
|
13
13
|
|
|
14
14
|
WaldiezAgentType = Literal[
|
|
15
|
-
"user", "assistant", "manager", "rag_user", "swarm", "reasoning"
|
|
15
|
+
"user", "assistant", "manager", "rag_user", "swarm", "reasoning", "captain"
|
|
16
16
|
]
|
|
17
17
|
|
|
18
18
|
|
|
@@ -25,9 +25,7 @@ class WaldiezAgent(WaldiezBase):
|
|
|
25
25
|
The ID of the agent.
|
|
26
26
|
type : Literal["agent"]
|
|
27
27
|
The type of the "node" in a graph: "agent"
|
|
28
|
-
agent_type :
|
|
29
|
-
"user", "assistant", "manager", "rag_user", "swarm", "reasoning"
|
|
30
|
-
]
|
|
28
|
+
agent_type : WaldiezAgentType
|
|
31
29
|
The type of the agent
|
|
32
30
|
name: str
|
|
33
31
|
The name of the agent.
|
|
@@ -65,9 +63,7 @@ class WaldiezAgent(WaldiezBase):
|
|
|
65
63
|
),
|
|
66
64
|
]
|
|
67
65
|
agent_type: Annotated[
|
|
68
|
-
|
|
69
|
-
"user", "assistant", "manager", "rag_user", "swarm", "reasoning"
|
|
70
|
-
],
|
|
66
|
+
WaldiezAgentType,
|
|
71
67
|
Field(
|
|
72
68
|
...,
|
|
73
69
|
title="Agent type",
|
|
@@ -129,6 +125,73 @@ class WaldiezAgent(WaldiezBase):
|
|
|
129
125
|
),
|
|
130
126
|
]
|
|
131
127
|
|
|
128
|
+
@property
|
|
129
|
+
def ag2_class(self) -> str:
|
|
130
|
+
"""Return the AG2 class of the agent."""
|
|
131
|
+
class_name = "ConversableAgent"
|
|
132
|
+
if self.data.is_multimodal:
|
|
133
|
+
return "MultimodalConversableAgent"
|
|
134
|
+
if self.agent_type == "assistant":
|
|
135
|
+
class_name = "AssistantAgent"
|
|
136
|
+
if self.agent_type == "user":
|
|
137
|
+
class_name = "UserProxyAgent"
|
|
138
|
+
if self.agent_type == "manager":
|
|
139
|
+
class_name = "GroupChatManager"
|
|
140
|
+
if self.agent_type == "rag_user":
|
|
141
|
+
class_name = "RetrieveUserProxyAgent"
|
|
142
|
+
if self.agent_type == "swarm":
|
|
143
|
+
class_name = "SwarmAgent"
|
|
144
|
+
if self.agent_type == "reasoning":
|
|
145
|
+
class_name = "ReasoningAgent"
|
|
146
|
+
if self.agent_type == "captain":
|
|
147
|
+
class_name = "CaptainAgent"
|
|
148
|
+
return class_name
|
|
149
|
+
|
|
150
|
+
@property
|
|
151
|
+
def ag2_imports(self) -> Set[str]:
|
|
152
|
+
"""Return the AG2 imports of the agent."""
|
|
153
|
+
agent_class = self.ag2_class
|
|
154
|
+
imports = set(["import autogen"])
|
|
155
|
+
if agent_class == "AssistantAgent":
|
|
156
|
+
imports.add("from autogen import AssistantAgent")
|
|
157
|
+
elif agent_class == "UserProxyAgent":
|
|
158
|
+
imports.add("from autogen import UserProxyAgent")
|
|
159
|
+
elif agent_class == "GroupChatManager":
|
|
160
|
+
imports.add("from autogen import GroupChatManager")
|
|
161
|
+
elif agent_class == "RetrieveUserProxyAgent":
|
|
162
|
+
imports.add(
|
|
163
|
+
"from autogen.agentchat.contrib.retrieve_user_proxy_agent "
|
|
164
|
+
"import RetrieveUserProxyAgent"
|
|
165
|
+
)
|
|
166
|
+
elif agent_class == "MultimodalConversableAgent":
|
|
167
|
+
imports.add(
|
|
168
|
+
"from autogen.agentchat.contrib.multimodal_conversable_agent "
|
|
169
|
+
"import MultimodalConversableAgent"
|
|
170
|
+
)
|
|
171
|
+
elif agent_class == "SwarmAgent":
|
|
172
|
+
imports.add(
|
|
173
|
+
"from autogen import "
|
|
174
|
+
"AFTER_WORK, "
|
|
175
|
+
"ON_CONDITION, "
|
|
176
|
+
"UPDATE_SYSTEM_MESSAGE, "
|
|
177
|
+
"AfterWorkOption, "
|
|
178
|
+
"SwarmAgent, "
|
|
179
|
+
"SwarmResult"
|
|
180
|
+
)
|
|
181
|
+
elif agent_class == "ReasoningAgent":
|
|
182
|
+
imports.add(
|
|
183
|
+
"from autogen.agentchat.contrib.reasoning_agent "
|
|
184
|
+
"import ReasoningAgent, visualize_tree"
|
|
185
|
+
)
|
|
186
|
+
elif agent_class == "CaptainAgent":
|
|
187
|
+
imports.add(
|
|
188
|
+
"from autogen.agentchat.contrib.captainagent "
|
|
189
|
+
"import CaptainAgent"
|
|
190
|
+
)
|
|
191
|
+
else: # pragma: no cover
|
|
192
|
+
imports.add("import ConversableAgent")
|
|
193
|
+
return imports
|
|
194
|
+
|
|
132
195
|
def validate_linked_skills(
|
|
133
196
|
self, skill_ids: List[str], agent_ids: List[str]
|
|
134
197
|
) -> None:
|
waldiez/models/agents/agents.py
CHANGED
|
@@ -10,7 +10,8 @@ from typing_extensions import Annotated, Self
|
|
|
10
10
|
from ..common import WaldiezBase
|
|
11
11
|
from .agent import WaldiezAgent
|
|
12
12
|
from .assistant import WaldiezAssistant
|
|
13
|
-
from .
|
|
13
|
+
from .captain_agent import WaldiezCaptainAgent
|
|
14
|
+
from .group_manager import WaldiezGroupManager
|
|
14
15
|
from .rag_user import WaldiezRagUser
|
|
15
16
|
from .reasoning import WaldiezReasoningAgent
|
|
16
17
|
from .swarm_agent import WaldiezSwarmAgent
|
|
@@ -80,6 +81,14 @@ class WaldiezAgents(WaldiezBase):
|
|
|
80
81
|
default_factory=list,
|
|
81
82
|
),
|
|
82
83
|
]
|
|
84
|
+
captain_agents: Annotated[
|
|
85
|
+
List[WaldiezCaptainAgent],
|
|
86
|
+
Field(
|
|
87
|
+
title="Captain Agents.",
|
|
88
|
+
description="Captain agents",
|
|
89
|
+
default_factory=list,
|
|
90
|
+
),
|
|
91
|
+
]
|
|
83
92
|
|
|
84
93
|
@property
|
|
85
94
|
def members(self) -> Iterator[WaldiezAgent]:
|
|
@@ -96,6 +105,7 @@ class WaldiezAgents(WaldiezBase):
|
|
|
96
105
|
yield from self.reasoning_agents
|
|
97
106
|
yield from self.swarm_agents
|
|
98
107
|
yield from self.managers
|
|
108
|
+
yield from self.captain_agents
|
|
99
109
|
|
|
100
110
|
@model_validator(mode="after")
|
|
101
111
|
def validate_agents(self) -> Self:
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# SPDX-License-Identifier: Apache-2.0.
|
|
2
|
+
# Copyright (c) 2024 - 2025 Waldiez and contributors.
|
|
3
|
+
"""Captain agent model."""
|
|
4
|
+
|
|
5
|
+
from .captain_agent import WaldiezCaptainAgent
|
|
6
|
+
from .captain_agent_data import (
|
|
7
|
+
WaldiezCaptainAgentData,
|
|
8
|
+
)
|
|
9
|
+
from .captain_agent_lib_entry import WaldiezCaptainAgentLibEntry
|
|
10
|
+
|
|
11
|
+
__all__ = [
|
|
12
|
+
"WaldiezCaptainAgentData",
|
|
13
|
+
"WaldiezCaptainAgent",
|
|
14
|
+
"WaldiezCaptainAgentLibEntry",
|
|
15
|
+
]
|