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
|
@@ -4,51 +4,30 @@
|
|
|
4
4
|
# pylint: disable=line-too-long
|
|
5
5
|
"""Vector DB exporting utils for RAG user agents."""
|
|
6
6
|
|
|
7
|
-
from
|
|
7
|
+
from dataclasses import dataclass, field
|
|
8
|
+
from typing import Any
|
|
8
9
|
|
|
9
|
-
from waldiez.models import
|
|
10
|
+
from waldiez.models import WaldiezRagUserProxy
|
|
10
11
|
|
|
11
|
-
from .
|
|
12
|
-
from .
|
|
13
|
-
from .
|
|
14
|
-
from .
|
|
12
|
+
from .chroma_extras import get_chroma_db_args
|
|
13
|
+
from .mongo_extras import get_mongodb_db_args
|
|
14
|
+
from .pgvector_extras import get_pgvector_db_args
|
|
15
|
+
from .qdrant_extras import get_qdrant_db_args
|
|
15
16
|
|
|
16
17
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
"""Get the metadata arg.
|
|
21
|
-
|
|
22
|
-
Parameters
|
|
23
|
-
----------
|
|
24
|
-
agent : WaldiezRagUser
|
|
25
|
-
The agent.
|
|
18
|
+
@dataclass
|
|
19
|
+
class VectorDBExtras:
|
|
20
|
+
"""Vector DB exporting extras for RAG user agents."""
|
|
26
21
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
str
|
|
30
|
-
The metadata arg.
|
|
31
|
-
"""
|
|
32
|
-
metadata_arg = ""
|
|
33
|
-
if agent.retrieve_config.db_config.metadata:
|
|
34
|
-
tab = " "
|
|
35
|
-
indent = tab * 3
|
|
36
|
-
metadata_arg += f"{indent}metadata={{" + "\n"
|
|
37
|
-
for key, value in agent.retrieve_config.db_config.metadata.items():
|
|
38
|
-
value_string: Any = f'"{value}"'
|
|
39
|
-
if str(value).isdigit():
|
|
40
|
-
value_string = int(value)
|
|
41
|
-
elif str(value).replace(".", "").isdigit():
|
|
42
|
-
value_string = float(value)
|
|
43
|
-
metadata_arg += f'{indent} "{key}": {value_string},' + "\n"
|
|
44
|
-
metadata_arg += f"{indent}}}," + "\n"
|
|
45
|
-
return metadata_arg
|
|
22
|
+
before_arg: str
|
|
23
|
+
vector_db_arg: str
|
|
24
|
+
imports: set[str] = field(default_factory=set[str])
|
|
46
25
|
|
|
47
26
|
|
|
48
|
-
def
|
|
49
|
-
agent:
|
|
27
|
+
def get_vector_db_extras(
|
|
28
|
+
agent: WaldiezRagUserProxy,
|
|
50
29
|
agent_name: str,
|
|
51
|
-
) ->
|
|
30
|
+
) -> VectorDBExtras:
|
|
52
31
|
"""Get the RAG user vector db string.
|
|
53
32
|
|
|
54
33
|
The vector db can be one of the following:
|
|
@@ -62,20 +41,20 @@ def get_rag_user_vector_db_string(
|
|
|
62
41
|
|
|
63
42
|
Parameters
|
|
64
43
|
----------
|
|
65
|
-
agent :
|
|
44
|
+
agent : WaldiezRagUserProxy
|
|
66
45
|
The agent.
|
|
67
46
|
agent_name : str
|
|
68
47
|
The agent's name.
|
|
69
48
|
|
|
70
49
|
Returns
|
|
71
50
|
-------
|
|
72
|
-
|
|
51
|
+
tuple[str, str, Set[str]]
|
|
73
52
|
The content before the arg if any, the arg and the related imports.
|
|
74
53
|
"""
|
|
75
54
|
before = ""
|
|
76
|
-
imports:
|
|
55
|
+
imports: set[str] = set()
|
|
77
56
|
ef_body: str = ""
|
|
78
|
-
db_imports:
|
|
57
|
+
db_imports: set[str] = set()
|
|
79
58
|
kwarg_string = ""
|
|
80
59
|
content_before = ""
|
|
81
60
|
vdb_class = "ChromaVectorDB"
|
|
@@ -97,14 +76,14 @@ def get_rag_user_vector_db_string(
|
|
|
97
76
|
if agent.retrieve_config.vector_db == "mongodb":
|
|
98
77
|
vdb_class = "MongoDBAtlasVectorDB"
|
|
99
78
|
imports.add(
|
|
100
|
-
"from autogen.agentchat.contrib.vectordb.
|
|
79
|
+
"from autogen.agentchat.contrib.vectordb.mongodb import MongoDBAtlasVectorDB"
|
|
101
80
|
)
|
|
102
81
|
kwarg_string, db_imports, ef_body = get_mongodb_db_args(
|
|
103
82
|
agent, agent_name
|
|
104
83
|
)
|
|
105
84
|
if agent.retrieve_config.vector_db == "pgvector":
|
|
106
85
|
imports.add(
|
|
107
|
-
"from autogen.agentchat.contrib.vectordb.
|
|
86
|
+
"from autogen.agentchat.contrib.vectordb.pgvectordb import PGVectorDB"
|
|
108
87
|
)
|
|
109
88
|
vdb_class = "PGVectorDB"
|
|
110
89
|
kwarg_string, db_imports, ef_body = get_pgvector_db_args(
|
|
@@ -114,9 +93,43 @@ def get_rag_user_vector_db_string(
|
|
|
114
93
|
before += "\n" + f"{content_before}"
|
|
115
94
|
if ef_body:
|
|
116
95
|
before += "\n" + f"{ef_body}" + "\n"
|
|
117
|
-
|
|
118
|
-
imports.update(db_imports)
|
|
96
|
+
imports.update(db_imports)
|
|
119
97
|
kwarg_string += _get_metadata_arg(agent)
|
|
120
98
|
vdb_arg = f"{vdb_class}(" + "\n"
|
|
121
99
|
vdb_arg += kwarg_string + " )"
|
|
122
|
-
return
|
|
100
|
+
return VectorDBExtras(
|
|
101
|
+
before_arg=before,
|
|
102
|
+
vector_db_arg=vdb_arg,
|
|
103
|
+
imports=imports,
|
|
104
|
+
)
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
def _get_metadata_arg(
|
|
108
|
+
agent: WaldiezRagUserProxy,
|
|
109
|
+
) -> str:
|
|
110
|
+
"""Get the metadata arg.
|
|
111
|
+
|
|
112
|
+
Parameters
|
|
113
|
+
----------
|
|
114
|
+
agent : WaldiezRagUserProxy
|
|
115
|
+
The agent.
|
|
116
|
+
|
|
117
|
+
Returns
|
|
118
|
+
-------
|
|
119
|
+
str
|
|
120
|
+
The metadata arg.
|
|
121
|
+
"""
|
|
122
|
+
metadata_arg = ""
|
|
123
|
+
if agent.retrieve_config.db_config.metadata:
|
|
124
|
+
tab = " "
|
|
125
|
+
indent = tab * 3
|
|
126
|
+
metadata_arg += f"{indent}metadata={{" + "\n"
|
|
127
|
+
for key, value in agent.retrieve_config.db_config.metadata.items():
|
|
128
|
+
value_string: Any = f'"{value}"'
|
|
129
|
+
if str(value).isdigit():
|
|
130
|
+
value_string = int(value)
|
|
131
|
+
elif str(value).replace(".", "").isdigit():
|
|
132
|
+
value_string = float(value)
|
|
133
|
+
metadata_arg += f'{indent} "{key}": {value_string},' + "\n"
|
|
134
|
+
metadata_arg += f"{indent}}}," + "\n"
|
|
135
|
+
return metadata_arg
|
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
# SPDX-License-Identifier: Apache-2.0.
|
|
2
|
+
# Copyright (c) 2024 - 2025 Waldiez and contributors.
|
|
3
|
+
"""RAG user proxy agent configuration processor."""
|
|
4
|
+
|
|
5
|
+
from typing import Union
|
|
6
|
+
|
|
7
|
+
from waldiez.models import (
|
|
8
|
+
WaldiezAgent,
|
|
9
|
+
WaldiezRagUserProxy,
|
|
10
|
+
WaldiezRagUserProxyModels,
|
|
11
|
+
WaldiezRagUserProxyRetrieveConfig,
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
from ...core import (
|
|
15
|
+
DefaultPathResolver,
|
|
16
|
+
DefaultSerializer,
|
|
17
|
+
ImportPosition,
|
|
18
|
+
ImportStatement,
|
|
19
|
+
InstanceArgument,
|
|
20
|
+
PathResolver,
|
|
21
|
+
Serializer,
|
|
22
|
+
)
|
|
23
|
+
from ...core.extras.agent_extras import RAGUserExtras
|
|
24
|
+
from .rag import VectorDBExtras, get_vector_db_extras
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
# pylint: disable=too-few-public-methods
|
|
28
|
+
class RagUserProxyAgentProcessor:
|
|
29
|
+
"""Processor for RAG user proxy agent configuration."""
|
|
30
|
+
|
|
31
|
+
_before_agent: str = ""
|
|
32
|
+
|
|
33
|
+
def __init__(
|
|
34
|
+
self,
|
|
35
|
+
agent: WaldiezAgent,
|
|
36
|
+
agent_name: str,
|
|
37
|
+
model_names: dict[str, str],
|
|
38
|
+
path_resolver: PathResolver | None = None,
|
|
39
|
+
serializer: Serializer | None = None,
|
|
40
|
+
):
|
|
41
|
+
"""Initialize the processor.
|
|
42
|
+
|
|
43
|
+
Parameters
|
|
44
|
+
----------
|
|
45
|
+
agent : WaldiezAgent
|
|
46
|
+
The Waldiez RAG user proxy agent to process.
|
|
47
|
+
model_names : dict[str, str]
|
|
48
|
+
A mapping from model id to model name.
|
|
49
|
+
path_resolver : PathResolver | None
|
|
50
|
+
Optional path resolver for resolving paths.
|
|
51
|
+
Defaults to DefaultPathResolver if not provided.
|
|
52
|
+
serializer : Serializer | None
|
|
53
|
+
Optional serializer for the RAG configuration.
|
|
54
|
+
Defaults to DefaultSerializer if not provided.
|
|
55
|
+
"""
|
|
56
|
+
self.agent = agent
|
|
57
|
+
self.agent_name = agent_name
|
|
58
|
+
self.model_names = model_names
|
|
59
|
+
self.path_resolver = path_resolver or DefaultPathResolver()
|
|
60
|
+
self.serializer = serializer or DefaultSerializer()
|
|
61
|
+
|
|
62
|
+
def process(self) -> RAGUserExtras:
|
|
63
|
+
"""Process RAG user proxy agent configuration.
|
|
64
|
+
|
|
65
|
+
Returns
|
|
66
|
+
-------
|
|
67
|
+
RAGConfig
|
|
68
|
+
The processed result containing extra arguments, before content,
|
|
69
|
+
imports, and environment variables.
|
|
70
|
+
"""
|
|
71
|
+
result = RAGUserExtras(self.agent.id)
|
|
72
|
+
if not self.agent.is_rag_user or not isinstance(
|
|
73
|
+
self.agent, WaldiezRagUserProxy
|
|
74
|
+
):
|
|
75
|
+
return result
|
|
76
|
+
# Get the extra args
|
|
77
|
+
vector_db_extras = get_vector_db_extras(
|
|
78
|
+
agent=self.agent, agent_name=self.agent_name
|
|
79
|
+
)
|
|
80
|
+
before_agent, arg_value = self._get_retrieve_config(vector_db_extras)
|
|
81
|
+
if before_agent:
|
|
82
|
+
self._before_agent += before_agent
|
|
83
|
+
if arg_value:
|
|
84
|
+
retrieve_arg = InstanceArgument(
|
|
85
|
+
instance_id=self.agent.id,
|
|
86
|
+
name="retrieve_config",
|
|
87
|
+
value=arg_value,
|
|
88
|
+
tabs=1,
|
|
89
|
+
)
|
|
90
|
+
result.add_arg(retrieve_arg)
|
|
91
|
+
for import_statement in vector_db_extras.imports:
|
|
92
|
+
result.add_import(
|
|
93
|
+
ImportStatement(
|
|
94
|
+
statement=import_statement,
|
|
95
|
+
position=ImportPosition.THIRD_PARTY,
|
|
96
|
+
)
|
|
97
|
+
)
|
|
98
|
+
if self._before_agent:
|
|
99
|
+
result.prepend_before_agent(self._before_agent)
|
|
100
|
+
return result
|
|
101
|
+
|
|
102
|
+
def _get_retrieve_config(
|
|
103
|
+
self, vector_db_extras: VectorDBExtras
|
|
104
|
+
) -> tuple[str, str]:
|
|
105
|
+
"""Get the retrieve config argument for the agent.
|
|
106
|
+
|
|
107
|
+
Returns
|
|
108
|
+
-------
|
|
109
|
+
InstanceArgument | None
|
|
110
|
+
The retrieve config argument if applicable, otherwise None.
|
|
111
|
+
"""
|
|
112
|
+
if not isinstance(self.agent, WaldiezRagUserProxy):
|
|
113
|
+
return "", ""
|
|
114
|
+
retrieve_config: WaldiezRagUserProxyRetrieveConfig = (
|
|
115
|
+
self.agent.retrieve_config
|
|
116
|
+
)
|
|
117
|
+
if not retrieve_config:
|
|
118
|
+
return "", ""
|
|
119
|
+
args_dict = self._get_args_dict()
|
|
120
|
+
if not args_dict:
|
|
121
|
+
return "", ""
|
|
122
|
+
before_agent = vector_db_extras.before_arg
|
|
123
|
+
if self.agent.retrieve_config.use_custom_token_count:
|
|
124
|
+
function_content, token_count_arg_name = (
|
|
125
|
+
retrieve_config.get_custom_token_count_function(
|
|
126
|
+
name_suffix=self.agent_name
|
|
127
|
+
)
|
|
128
|
+
)
|
|
129
|
+
args_dict["custom_token_count_function"] = token_count_arg_name
|
|
130
|
+
before_agent += "\n" + function_content + "\n"
|
|
131
|
+
if self.agent.retrieve_config.use_custom_text_split:
|
|
132
|
+
function_content, text_split_arg_name = (
|
|
133
|
+
retrieve_config.get_custom_text_split_function(
|
|
134
|
+
name_suffix=self.agent_name
|
|
135
|
+
)
|
|
136
|
+
)
|
|
137
|
+
args_dict["custom_text_split_function"] = text_split_arg_name
|
|
138
|
+
before_agent += "\n" + function_content + "\n"
|
|
139
|
+
if before_agent.strip() and not before_agent.endswith("\n"):
|
|
140
|
+
before_agent += "\n"
|
|
141
|
+
return before_agent, self._get_args_string(
|
|
142
|
+
args_dict,
|
|
143
|
+
vector_db_extras,
|
|
144
|
+
before_agent,
|
|
145
|
+
)
|
|
146
|
+
|
|
147
|
+
def _get_args_string(
|
|
148
|
+
self,
|
|
149
|
+
args_dict: dict[str, Union[str, list[str]]],
|
|
150
|
+
vector_db_extras: VectorDBExtras,
|
|
151
|
+
before_agent: str,
|
|
152
|
+
) -> str:
|
|
153
|
+
if not isinstance(self.agent, WaldiezRagUserProxy):
|
|
154
|
+
return ""
|
|
155
|
+
args_content = self.serializer.serialize(args_dict)
|
|
156
|
+
# get the last line (where the dict ends)
|
|
157
|
+
args_parts = args_content.split("\n")
|
|
158
|
+
before_vector_db = args_parts[:-1]
|
|
159
|
+
closing_arg = args_parts[-1]
|
|
160
|
+
args_content = "\n".join(before_vector_db)
|
|
161
|
+
# add the vector_db arg
|
|
162
|
+
args_content += (
|
|
163
|
+
",\n"
|
|
164
|
+
+ f' "vector_db": {vector_db_extras.vector_db_arg},'
|
|
165
|
+
+ "\n"
|
|
166
|
+
)
|
|
167
|
+
# we should not need to include the client, but let's do it
|
|
168
|
+
# to avoid later issues (with telemetry or other client settings)
|
|
169
|
+
# https://github.com/ag2ai/ag2/blob/main/autogen/agentchat/\
|
|
170
|
+
# contrib/retrieve_user_proxy_agent.py#L265-L266
|
|
171
|
+
if (
|
|
172
|
+
f"{self.agent_name}_client" in before_agent
|
|
173
|
+
and self.agent.retrieve_config.vector_db == "chroma"
|
|
174
|
+
):
|
|
175
|
+
args_content += (
|
|
176
|
+
f' "client": {self.agent_name}_client,' + "\n"
|
|
177
|
+
)
|
|
178
|
+
args_content += closing_arg
|
|
179
|
+
return args_content
|
|
180
|
+
|
|
181
|
+
def _get_model_arg(
|
|
182
|
+
self,
|
|
183
|
+
) -> str:
|
|
184
|
+
if not isinstance(self.agent, WaldiezRagUserProxy):
|
|
185
|
+
return ""
|
|
186
|
+
if self.agent.data.model_ids:
|
|
187
|
+
model_name = self.model_names[self.agent.data.model_ids[0]]
|
|
188
|
+
new_model_name = f"{model_name}"
|
|
189
|
+
return f"{new_model_name}"
|
|
190
|
+
if self.agent.retrieve_config.model in self.model_names:
|
|
191
|
+
selected_model = self.model_names[self.agent.retrieve_config.model]
|
|
192
|
+
new_model_name = f"{selected_model}"
|
|
193
|
+
return f"{new_model_name}"
|
|
194
|
+
return WaldiezRagUserProxyModels[self.agent.retrieve_config.vector_db]
|
|
195
|
+
|
|
196
|
+
def _get_args_dict(self) -> dict[str, Union[str, list[str]]]:
|
|
197
|
+
if not isinstance(self.agent, WaldiezRagUserProxy):
|
|
198
|
+
return {}
|
|
199
|
+
model_arg = self._get_model_arg()
|
|
200
|
+
args_dict: dict[str, Union[str, list[str]]] = {
|
|
201
|
+
"task": self.agent.retrieve_config.task,
|
|
202
|
+
"model": model_arg,
|
|
203
|
+
}
|
|
204
|
+
optional_args = [
|
|
205
|
+
"chunk_token_size",
|
|
206
|
+
"context_max_tokens",
|
|
207
|
+
"customized_prompt",
|
|
208
|
+
"customized_answer_prefix",
|
|
209
|
+
]
|
|
210
|
+
for arg in optional_args:
|
|
211
|
+
arg_value = getattr(self.agent.retrieve_config, arg)
|
|
212
|
+
if arg_value is not None:
|
|
213
|
+
args_dict[arg] = arg_value
|
|
214
|
+
args_dict[arg] = getattr(self.agent.retrieve_config, arg)
|
|
215
|
+
docs_path: Union[str, list[str]] = []
|
|
216
|
+
if self.agent.retrieve_config.docs_path:
|
|
217
|
+
doc_paths = (
|
|
218
|
+
self.agent.retrieve_config.docs_path
|
|
219
|
+
if isinstance(self.agent.retrieve_config.docs_path, list)
|
|
220
|
+
else [self.agent.retrieve_config.docs_path]
|
|
221
|
+
)
|
|
222
|
+
docs_path = [
|
|
223
|
+
item
|
|
224
|
+
for item in [
|
|
225
|
+
self.path_resolver.resolve(path) for path in doc_paths
|
|
226
|
+
]
|
|
227
|
+
if item
|
|
228
|
+
]
|
|
229
|
+
args_dict["docs_path"] = docs_path
|
|
230
|
+
if docs_path:
|
|
231
|
+
args_dict["docs_path"] = docs_path
|
|
232
|
+
non_optional_args = [
|
|
233
|
+
"new_docs",
|
|
234
|
+
"update_context",
|
|
235
|
+
"get_or_create",
|
|
236
|
+
"overwrite",
|
|
237
|
+
"recursive",
|
|
238
|
+
"chunk_mode",
|
|
239
|
+
"must_break_at_empty_line",
|
|
240
|
+
"collection_name",
|
|
241
|
+
"distance_threshold",
|
|
242
|
+
]
|
|
243
|
+
for arg in non_optional_args:
|
|
244
|
+
args_dict[arg] = getattr(self.agent.retrieve_config, arg)
|
|
245
|
+
return args_dict
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
# SPDX-License-Identifier: Apache-2.0.
|
|
2
|
+
# Copyright (c) 2024 - 2025 Waldiez and contributors.
|
|
3
|
+
# pylint: disable=too-few-public-methods,no-self-use
|
|
4
|
+
"""Reasoning agent configuration processor."""
|
|
5
|
+
|
|
6
|
+
from typing import Optional
|
|
7
|
+
|
|
8
|
+
from waldiez.models import WaldiezAgent, WaldiezReasoningAgent
|
|
9
|
+
|
|
10
|
+
from ...core import (
|
|
11
|
+
CodeExecutionConfig,
|
|
12
|
+
DefaultSerializer,
|
|
13
|
+
InstanceArgument,
|
|
14
|
+
Serializer,
|
|
15
|
+
SystemMessageConfig,
|
|
16
|
+
TerminationConfig,
|
|
17
|
+
)
|
|
18
|
+
from ...core.extras.agent_extras import ReasoningExtras
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class ReasoningAgentProcessor:
|
|
22
|
+
"""Processor for reasoning agent configuration."""
|
|
23
|
+
|
|
24
|
+
def __init__(self, agent: WaldiezAgent, serializer: Serializer | None):
|
|
25
|
+
"""Initialize the processor with the agent and serializer.
|
|
26
|
+
|
|
27
|
+
Parameters
|
|
28
|
+
----------
|
|
29
|
+
agent : WaldiezAgent
|
|
30
|
+
The Waldiez agent to process.
|
|
31
|
+
serializer : Serializer | None
|
|
32
|
+
Optional serializer for the reasoning configuration.
|
|
33
|
+
Defaults to DefaultSerializer if not provided.
|
|
34
|
+
"""
|
|
35
|
+
self.agent = agent
|
|
36
|
+
self.serializer = serializer or DefaultSerializer()
|
|
37
|
+
|
|
38
|
+
def process(
|
|
39
|
+
self,
|
|
40
|
+
code_execution_config: Optional[CodeExecutionConfig] = None,
|
|
41
|
+
termination_config: Optional[TerminationConfig] = None,
|
|
42
|
+
system_message_config: Optional[SystemMessageConfig] = None,
|
|
43
|
+
) -> ReasoningExtras:
|
|
44
|
+
"""Process reasoning agent configuration.
|
|
45
|
+
|
|
46
|
+
Parameters
|
|
47
|
+
----------
|
|
48
|
+
code_execution_config : CodeExecutionConfig, optional
|
|
49
|
+
Configuration for code execution, if applicable.
|
|
50
|
+
termination_config : TerminationConfig, optional
|
|
51
|
+
Configuration for termination, if applicable.
|
|
52
|
+
system_message_config : SystemMessageConfig, optional
|
|
53
|
+
Configuration for system messages, if applicable.
|
|
54
|
+
|
|
55
|
+
Returns
|
|
56
|
+
-------
|
|
57
|
+
ReasoningExtras
|
|
58
|
+
The processed result containing extra arguments, before content,
|
|
59
|
+
imports, and environment variables.
|
|
60
|
+
"""
|
|
61
|
+
result = ReasoningExtras(
|
|
62
|
+
instance_id=self.agent.id,
|
|
63
|
+
code_execution_config=code_execution_config,
|
|
64
|
+
termination_config=termination_config,
|
|
65
|
+
system_message_config=system_message_config,
|
|
66
|
+
)
|
|
67
|
+
if not self.agent.is_reasoning or not isinstance(
|
|
68
|
+
self.agent, WaldiezReasoningAgent
|
|
69
|
+
): # pragma: no cover
|
|
70
|
+
return result
|
|
71
|
+
|
|
72
|
+
reasoning_config = self.agent.get_reasoning_config()
|
|
73
|
+
serialized = self.serializer.serialize(reasoning_config)
|
|
74
|
+
reason_arg = InstanceArgument(
|
|
75
|
+
instance_id=self.agent.id,
|
|
76
|
+
name="reason_config",
|
|
77
|
+
value=serialized,
|
|
78
|
+
tabs=1,
|
|
79
|
+
)
|
|
80
|
+
result.add_arg(reason_arg)
|
|
81
|
+
verbose_arg = InstanceArgument(
|
|
82
|
+
instance_id=self.agent.id,
|
|
83
|
+
name="verbose",
|
|
84
|
+
value=self.agent.data.verbose,
|
|
85
|
+
tabs=1,
|
|
86
|
+
)
|
|
87
|
+
result.add_arg(verbose_arg)
|
|
88
|
+
return result
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
# SPDX-License-Identifier: Apache-2.0.
|
|
2
|
+
# Copyright (c) 2024 - 2025 Waldiez and contributors.
|
|
3
|
+
# pylint: disable=too-few-public-methods,
|
|
4
|
+
# pylint: disable=too-many-arguments,too-many-positional-arguments
|
|
5
|
+
"""Factory for creating agent exporter."""
|
|
6
|
+
|
|
7
|
+
from pathlib import Path
|
|
8
|
+
from typing import Any, Callable, Optional, Union
|
|
9
|
+
|
|
10
|
+
from waldiez.models import (
|
|
11
|
+
WaldiezAgent,
|
|
12
|
+
WaldiezAgentConnection,
|
|
13
|
+
WaldiezChat,
|
|
14
|
+
WaldiezModel,
|
|
15
|
+
)
|
|
16
|
+
|
|
17
|
+
from ..core import (
|
|
18
|
+
ExporterContext,
|
|
19
|
+
get_default_exporter_context,
|
|
20
|
+
)
|
|
21
|
+
from .exporter import AgentExporter
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def create_agent_exporter(
|
|
25
|
+
agent: WaldiezAgent,
|
|
26
|
+
agent_names: dict[str, str],
|
|
27
|
+
models: tuple[list[WaldiezModel], dict[str, str]],
|
|
28
|
+
chats: tuple[list[WaldiezChat], dict[str, str]],
|
|
29
|
+
tool_names: dict[str, str],
|
|
30
|
+
initial_chats: list[WaldiezAgentConnection],
|
|
31
|
+
is_async: bool = False,
|
|
32
|
+
for_notebook: bool = False,
|
|
33
|
+
cache_seed: Optional[int] = None,
|
|
34
|
+
group_chat_members: Optional[list[WaldiezAgent]] = None,
|
|
35
|
+
arguments_resolver: Optional[Callable[[WaldiezAgent], list[str]]] = None,
|
|
36
|
+
output_dir: Optional[Union[str, Path]] = None,
|
|
37
|
+
context: Optional[ExporterContext] = None,
|
|
38
|
+
**kwargs: Any,
|
|
39
|
+
) -> AgentExporter:
|
|
40
|
+
"""Create an agent exporter.
|
|
41
|
+
|
|
42
|
+
Parameters
|
|
43
|
+
----------
|
|
44
|
+
agent : WaldiezAgent
|
|
45
|
+
The agent to export.
|
|
46
|
+
agent_names : dict[str, str]
|
|
47
|
+
Mapping of agent IDs to names.
|
|
48
|
+
models : tuple[list[WaldiezModel], dict[str, str]]
|
|
49
|
+
All models and model names mapping.
|
|
50
|
+
chats : tuple[list[WaldiezChat], dict[str, str]]
|
|
51
|
+
All chats and chat names mapping.
|
|
52
|
+
tool_names : dict[str, str]
|
|
53
|
+
Mapping of tool IDs to names.
|
|
54
|
+
is_async : bool, optional
|
|
55
|
+
Whether the flow is async, by default False
|
|
56
|
+
for_notebook : bool, optional
|
|
57
|
+
Whether exporting for notebook, by default False
|
|
58
|
+
cache_seed : Optional[int], optional
|
|
59
|
+
Cache seed if any, by default None
|
|
60
|
+
initial_chats : Optional[list[WaldiezAgentConnection]], optional
|
|
61
|
+
Initial chats for group managers, by default None
|
|
62
|
+
group_chat_members : Optional[list[WaldiezAgent]], optional
|
|
63
|
+
Group chat members if group manager, by default None
|
|
64
|
+
arguments_resolver : Optional[Callable], optional
|
|
65
|
+
Function to resolve additional arguments, by default None
|
|
66
|
+
output_dir : Optional[Union[str, Path]], optional
|
|
67
|
+
Output directory for generated files, by default None
|
|
68
|
+
context : Optional[ExporterContext], optional
|
|
69
|
+
Exporter context with dependencies, by default None
|
|
70
|
+
**kwargs : Any
|
|
71
|
+
Additional keyword arguments.
|
|
72
|
+
|
|
73
|
+
Returns
|
|
74
|
+
-------
|
|
75
|
+
AgentExporter
|
|
76
|
+
The created agent exporter.
|
|
77
|
+
"""
|
|
78
|
+
if context is None:
|
|
79
|
+
context = get_default_exporter_context()
|
|
80
|
+
return AgentExporter(
|
|
81
|
+
agent=agent,
|
|
82
|
+
agent_names=agent_names,
|
|
83
|
+
models=models,
|
|
84
|
+
chats=chats,
|
|
85
|
+
tool_names=tool_names,
|
|
86
|
+
is_async=is_async,
|
|
87
|
+
for_notebook=for_notebook,
|
|
88
|
+
cache_seed=cache_seed,
|
|
89
|
+
initial_chats=initial_chats,
|
|
90
|
+
group_chat_members=group_chat_members,
|
|
91
|
+
arguments_resolver=arguments_resolver,
|
|
92
|
+
output_dir=output_dir,
|
|
93
|
+
context=context,
|
|
94
|
+
**kwargs,
|
|
95
|
+
)
|