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
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
# SPDX-License-Identifier: Apache-2.0.
|
|
2
|
+
# Copyright (c) 2024 - 2025 Waldiez and contributors.
|
|
3
|
+
# pylint: disable=too-few-public-methods
|
|
4
|
+
"""Transition target processor for Waldiez agents."""
|
|
5
|
+
|
|
6
|
+
from dataclasses import dataclass, field
|
|
7
|
+
from typing import Callable, Set
|
|
8
|
+
|
|
9
|
+
from waldiez.exporting.chats.utils.nested import get_nested_chat_queue
|
|
10
|
+
from waldiez.models import (
|
|
11
|
+
WaldiezAgent,
|
|
12
|
+
WaldiezAgentTarget,
|
|
13
|
+
WaldiezChat,
|
|
14
|
+
WaldiezGroupOrNestedTarget,
|
|
15
|
+
WaldiezRandomAgentTarget,
|
|
16
|
+
WaldiezTransitionTarget,
|
|
17
|
+
)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
@dataclass
|
|
21
|
+
class TargetResult:
|
|
22
|
+
"""Result from processing a transition target.
|
|
23
|
+
|
|
24
|
+
Attributes
|
|
25
|
+
----------
|
|
26
|
+
content : str
|
|
27
|
+
Content to be used for the target processing.
|
|
28
|
+
before_content : str
|
|
29
|
+
Content to be placed before the target processing.
|
|
30
|
+
extra_imports : Set[str]
|
|
31
|
+
Additional imports required for the target processing.
|
|
32
|
+
"""
|
|
33
|
+
|
|
34
|
+
content: str = ""
|
|
35
|
+
before_content: str = ""
|
|
36
|
+
extra_imports: Set[str] = field(default_factory=set) # pyright: ignore
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
class TransitionTargetProcessor:
|
|
40
|
+
"""Processor for transition targets."""
|
|
41
|
+
|
|
42
|
+
def __init__(
|
|
43
|
+
self,
|
|
44
|
+
agent: WaldiezAgent,
|
|
45
|
+
agent_names: dict[str, str],
|
|
46
|
+
chat_names: dict[str, str],
|
|
47
|
+
all_chats: list[WaldiezChat],
|
|
48
|
+
serializer: Callable[..., str],
|
|
49
|
+
) -> None:
|
|
50
|
+
"""Initialize the processor with agent names and context.
|
|
51
|
+
|
|
52
|
+
Parameters
|
|
53
|
+
----------
|
|
54
|
+
agent_names : dict[str, str]
|
|
55
|
+
Mapping of agent IDs to their names.
|
|
56
|
+
"""
|
|
57
|
+
self.agent_names = agent_names
|
|
58
|
+
self.chat_names = chat_names
|
|
59
|
+
self.agent = agent
|
|
60
|
+
self.agent_name = agent_names[agent.id]
|
|
61
|
+
self.all_chats = all_chats
|
|
62
|
+
self.serializer = serializer
|
|
63
|
+
|
|
64
|
+
def process(self, target: WaldiezTransitionTarget) -> TargetResult:
|
|
65
|
+
"""Process transition target based on its type.
|
|
66
|
+
|
|
67
|
+
Parameters
|
|
68
|
+
----------
|
|
69
|
+
target : WaldiezTransitionTarget
|
|
70
|
+
The transition target to process.
|
|
71
|
+
|
|
72
|
+
Returns
|
|
73
|
+
-------
|
|
74
|
+
TargetResult
|
|
75
|
+
The processed result containing the target string,
|
|
76
|
+
before_content code, and extra imports.
|
|
77
|
+
|
|
78
|
+
Raises
|
|
79
|
+
------
|
|
80
|
+
ValueError
|
|
81
|
+
If the target type is unknown.
|
|
82
|
+
"""
|
|
83
|
+
result = TargetResult()
|
|
84
|
+
where = "autogen.agentchat.group"
|
|
85
|
+
if target.target_type == "GroupManagerTarget":
|
|
86
|
+
where += ".targets.group_manager_target"
|
|
87
|
+
what = target.target_type
|
|
88
|
+
result.extra_imports.add(f"from {where} import {what}")
|
|
89
|
+
|
|
90
|
+
processors: dict[str, Callable[[WaldiezTransitionTarget], str]] = {
|
|
91
|
+
"AgentTarget": self._process_agent_target,
|
|
92
|
+
"RandomAgentTarget": self._process_random_agent_target,
|
|
93
|
+
"GroupChatTarget": self._process_group_chat_target,
|
|
94
|
+
"NestedChatTarget": self._process_nested_chat_target,
|
|
95
|
+
"AskUserTarget": self._process_simple_target,
|
|
96
|
+
"GroupManagerTarget": self._process_simple_target,
|
|
97
|
+
"RevertToUserTarget": self._process_simple_target,
|
|
98
|
+
"StayTarget": self._process_simple_target,
|
|
99
|
+
"TerminateTarget": self._process_simple_target,
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
processor = processors.get(target.target_type)
|
|
103
|
+
if not processor:
|
|
104
|
+
raise ValueError(f"Unknown target type: {target.target_type}")
|
|
105
|
+
|
|
106
|
+
result.content = processor(target)
|
|
107
|
+
|
|
108
|
+
# Special handling for nested chat targets
|
|
109
|
+
if target.target_type == "NestedChatTarget":
|
|
110
|
+
nested_result = self._process_nested_chat_target_full(target)
|
|
111
|
+
result.before_content = nested_result.before_content
|
|
112
|
+
|
|
113
|
+
return result
|
|
114
|
+
|
|
115
|
+
def _process_agent_target(self, target: WaldiezTransitionTarget) -> str:
|
|
116
|
+
"""Process agent target."""
|
|
117
|
+
if not isinstance(target, WaldiezAgentTarget):
|
|
118
|
+
raise ValueError(
|
|
119
|
+
"Expected WaldiezAgentTarget for agent target processing."
|
|
120
|
+
)
|
|
121
|
+
agent_name = self.agent_names[target.value[0]]
|
|
122
|
+
return f"AgentTarget({agent_name})"
|
|
123
|
+
|
|
124
|
+
def _process_random_agent_target(
|
|
125
|
+
self, target: WaldiezTransitionTarget
|
|
126
|
+
) -> str:
|
|
127
|
+
"""Process random agent target."""
|
|
128
|
+
if not isinstance(target, WaldiezRandomAgentTarget):
|
|
129
|
+
raise ValueError(
|
|
130
|
+
"Expected WaldiezRandomAgentTarget"
|
|
131
|
+
" for random agent target processing."
|
|
132
|
+
)
|
|
133
|
+
agent_vars = [self.agent_names[agent_id] for agent_id in target.value]
|
|
134
|
+
agents_str = ", ".join(agent_vars)
|
|
135
|
+
return f"RandomAgentTarget([{agents_str}])"
|
|
136
|
+
|
|
137
|
+
def _process_group_chat_target(
|
|
138
|
+
self, target: WaldiezTransitionTarget
|
|
139
|
+
) -> str:
|
|
140
|
+
"""Process group chat target."""
|
|
141
|
+
if not isinstance(target, WaldiezGroupOrNestedTarget):
|
|
142
|
+
raise ValueError(
|
|
143
|
+
"Expected WaldiezGroupOrNestedTarget for group chat target "
|
|
144
|
+
"processing."
|
|
145
|
+
)
|
|
146
|
+
chat_name = self.chat_names[target.value[0]]
|
|
147
|
+
return f"GroupChatTarget({chat_name})"
|
|
148
|
+
|
|
149
|
+
def _process_nested_chat_target(self, _: WaldiezTransitionTarget) -> str:
|
|
150
|
+
"""Process nested chat target (simple string only)."""
|
|
151
|
+
chat_name = f"{self.agent_name}_handoff_nested_chat_queue"
|
|
152
|
+
target_arg = f'nested_chat_config={{"chat_queue": {chat_name}}}'
|
|
153
|
+
return f"NestedChatTarget({target_arg})"
|
|
154
|
+
|
|
155
|
+
def _process_nested_chat_target_full(
|
|
156
|
+
self, _: WaldiezTransitionTarget
|
|
157
|
+
) -> TargetResult:
|
|
158
|
+
"""Process nested chat target with full configuration."""
|
|
159
|
+
result = TargetResult()
|
|
160
|
+
|
|
161
|
+
chat_queue, extra_methods = get_nested_chat_queue(
|
|
162
|
+
nested_chat=self.agent.data.nested_chats[0],
|
|
163
|
+
agent=self.agent,
|
|
164
|
+
agent_names=self.agent_names,
|
|
165
|
+
chat_names=self.chat_names,
|
|
166
|
+
all_chats=self.all_chats,
|
|
167
|
+
serializer=self.serializer,
|
|
168
|
+
)
|
|
169
|
+
|
|
170
|
+
chat_name = f"{self.agent_name}_handoff_nested_chat_queue"
|
|
171
|
+
|
|
172
|
+
if extra_methods:
|
|
173
|
+
result.before_content += "\n".join(extra_methods) + "\n"
|
|
174
|
+
|
|
175
|
+
result.before_content += (
|
|
176
|
+
f"{chat_name}: list[dict[str, Any]] = {chat_queue}\n\n"
|
|
177
|
+
)
|
|
178
|
+
return result
|
|
179
|
+
|
|
180
|
+
# pylint: disable=no-self-use
|
|
181
|
+
def _process_simple_target(self, target: WaldiezTransitionTarget) -> str:
|
|
182
|
+
"""Process simple targets that don't need parameters.
|
|
183
|
+
|
|
184
|
+
Parameters
|
|
185
|
+
----------
|
|
186
|
+
target : WaldiezTransitionTarget
|
|
187
|
+
The target to process.
|
|
188
|
+
"""
|
|
189
|
+
return f"{target.target_type}()"
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# SPDX-License-Identifier: Apache-2.0.
|
|
2
|
+
# Copyright (c) 2024 - 2025 Waldiez and contributors.
|
|
3
|
+
"""Agent exporter rag extras."""
|
|
4
|
+
|
|
5
|
+
from .vector_db_extras import VectorDBExtras, get_vector_db_extras
|
|
6
|
+
|
|
7
|
+
__all__ = [
|
|
8
|
+
"get_vector_db_extras",
|
|
9
|
+
"VectorDBExtras",
|
|
10
|
+
]
|
|
@@ -3,24 +3,24 @@
|
|
|
3
3
|
"""Get chroma db related imports and content."""
|
|
4
4
|
|
|
5
5
|
from pathlib import Path
|
|
6
|
-
from typing import Set
|
|
6
|
+
from typing import Set
|
|
7
7
|
|
|
8
|
-
from waldiez.models import
|
|
8
|
+
from waldiez.models import WaldiezRagUserProxy
|
|
9
9
|
|
|
10
10
|
|
|
11
|
-
def _get_chroma_client_string(agent:
|
|
11
|
+
def _get_chroma_client_string(agent: WaldiezRagUserProxy) -> tuple[str, str]:
|
|
12
12
|
"""Get the ChromaVectorDB client string.
|
|
13
13
|
|
|
14
14
|
Parameters
|
|
15
15
|
----------
|
|
16
|
-
agent :
|
|
16
|
+
agent : WaldiezRagUserProxy
|
|
17
17
|
The agent.
|
|
18
18
|
agent_name : str
|
|
19
19
|
The agent's name.
|
|
20
20
|
|
|
21
21
|
Returns
|
|
22
22
|
-------
|
|
23
|
-
|
|
23
|
+
tuple[str, str]
|
|
24
24
|
The 'client' and what to import.
|
|
25
25
|
"""
|
|
26
26
|
# TODO: also check `connection_url` (chroma in client-server mode)
|
|
@@ -46,33 +46,32 @@ def _get_chroma_client_string(agent: WaldiezRagUser) -> Tuple[str, str]:
|
|
|
46
46
|
|
|
47
47
|
|
|
48
48
|
def _get_chroma_embedding_function_string(
|
|
49
|
-
agent:
|
|
50
|
-
) ->
|
|
49
|
+
agent: WaldiezRagUserProxy, agent_name: str
|
|
50
|
+
) -> tuple[str, str, str]:
|
|
51
51
|
"""Get the ChromaVectorDB embedding function string.
|
|
52
52
|
|
|
53
53
|
Parameters
|
|
54
54
|
----------
|
|
55
|
-
agent :
|
|
55
|
+
agent : WaldiezRagUserProxy
|
|
56
56
|
The agent.
|
|
57
57
|
agent_name : str
|
|
58
58
|
The agent's name.
|
|
59
59
|
|
|
60
60
|
Returns
|
|
61
61
|
-------
|
|
62
|
-
|
|
62
|
+
tuple[str, str, str]
|
|
63
63
|
The 'embedding_function', the import and the custom embedding function.
|
|
64
64
|
"""
|
|
65
65
|
to_import = ""
|
|
66
66
|
embedding_function_arg = ""
|
|
67
67
|
embedding_function_content = ""
|
|
68
|
-
vector_db_model = agent.retrieve_config.db_config.model
|
|
69
68
|
if not agent.retrieve_config.use_custom_embedding:
|
|
70
69
|
to_import = (
|
|
71
|
-
"from chromadb.utils.embedding_functions
|
|
72
|
-
"import
|
|
70
|
+
"from chromadb.utils.embedding_functions."
|
|
71
|
+
"sentence_transformer_embedding_function import "
|
|
72
|
+
"SentenceTransformerEmbeddingFunction"
|
|
73
73
|
)
|
|
74
|
-
embedding_function_arg = "
|
|
75
|
-
embedding_function_arg += f'model_name="{vector_db_model}")'
|
|
74
|
+
embedding_function_arg = f"{agent_name}_embedding_function"
|
|
76
75
|
else:
|
|
77
76
|
embedding_function_content, embedding_function_arg = (
|
|
78
77
|
agent.retrieve_config.get_custom_embedding_function(
|
|
@@ -84,20 +83,20 @@ def _get_chroma_embedding_function_string(
|
|
|
84
83
|
|
|
85
84
|
|
|
86
85
|
def get_chroma_db_args(
|
|
87
|
-
agent:
|
|
88
|
-
) ->
|
|
86
|
+
agent: WaldiezRagUserProxy, agent_name: str
|
|
87
|
+
) -> tuple[str, Set[str], str, str]:
|
|
89
88
|
"""Get the 'kwargs to use for ChromaVectorDB.
|
|
90
89
|
|
|
91
90
|
Parameters
|
|
92
91
|
----------
|
|
93
|
-
agent :
|
|
92
|
+
agent : WaldiezRagUserProxy
|
|
94
93
|
The agent.
|
|
95
94
|
agent_name : str
|
|
96
95
|
The agent's name.
|
|
97
96
|
|
|
98
97
|
Returns
|
|
99
98
|
-------
|
|
100
|
-
|
|
99
|
+
tuple[str, Set[str], str]
|
|
101
100
|
|
|
102
101
|
- The 'kwargs' string.
|
|
103
102
|
- What to import.
|
|
@@ -123,21 +122,35 @@ def get_chroma_db_args(
|
|
|
123
122
|
# manually initializing the collection before running the flow,
|
|
124
123
|
# might be a workaround.
|
|
125
124
|
content_before = f"{agent_name}_client = {client_str}" + "\n"
|
|
125
|
+
vector_db_model = agent.retrieve_config.db_config.model
|
|
126
|
+
if not embedding_function_body:
|
|
127
|
+
content_before += (
|
|
128
|
+
f"{agent_name}_embedding_function = "
|
|
129
|
+
"SentenceTransformerEmbeddingFunction(\n"
|
|
130
|
+
f' model_name="{vector_db_model}",' + "\n"
|
|
131
|
+
")\n"
|
|
132
|
+
)
|
|
126
133
|
collection_name = agent.retrieve_config.collection_name
|
|
127
134
|
get_or_create = agent.retrieve_config.get_or_create
|
|
128
135
|
if collection_name:
|
|
129
136
|
if get_or_create:
|
|
130
137
|
content_before += (
|
|
131
|
-
f"{agent_name}_client.get_or_create_collection("
|
|
132
|
-
f'"{collection_name}"
|
|
138
|
+
f"{agent_name}_client.get_or_create_collection" + "(\n"
|
|
139
|
+
f' "{collection_name}",' + "\n"
|
|
140
|
+
f" embedding_function={embedding_function_arg}," + "\n"
|
|
141
|
+
")" + "\n"
|
|
133
142
|
)
|
|
134
143
|
else:
|
|
135
144
|
content_before += (
|
|
136
145
|
"try:\n"
|
|
137
|
-
f
|
|
138
|
-
+ "\n"
|
|
146
|
+
f" {agent_name}_client.get_collection(" + "\n"
|
|
147
|
+
f' "{collection_name}",' + "\n"
|
|
148
|
+
f" embedding_function={embedding_function_arg}," + "\n"
|
|
149
|
+
" )\n"
|
|
139
150
|
"except ValueError:\n"
|
|
140
|
-
f" {agent_name}_client.create_collection("
|
|
141
|
-
f'"{collection_name}"
|
|
151
|
+
f" {agent_name}_client.create_collection(" + "\n"
|
|
152
|
+
f' "{collection_name}",' + "\n"
|
|
153
|
+
f" embedding_function={embedding_function_arg}," + "\n"
|
|
154
|
+
" )\n"
|
|
142
155
|
)
|
|
143
156
|
return kwarg_string, to_import, embedding_function_body, content_before
|
|
@@ -2,26 +2,26 @@
|
|
|
2
2
|
# Copyright (c) 2024 - 2025 Waldiez and contributors.
|
|
3
3
|
"""Get mongodb related content and imports."""
|
|
4
4
|
|
|
5
|
-
from typing import Set
|
|
5
|
+
from typing import Set
|
|
6
6
|
|
|
7
|
-
from waldiez.models import
|
|
7
|
+
from waldiez.models import WaldiezRagUserProxy
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
def _get_mongodb_embedding_function_string(
|
|
11
|
-
agent:
|
|
12
|
-
) ->
|
|
11
|
+
agent: WaldiezRagUserProxy, agent_name: str
|
|
12
|
+
) -> tuple[str, str, str]:
|
|
13
13
|
"""Get the MongoDBAtlasVectorDB embedding function string.
|
|
14
14
|
|
|
15
15
|
Parameters
|
|
16
16
|
----------
|
|
17
|
-
agent :
|
|
17
|
+
agent : WaldiezRagUserProxy
|
|
18
18
|
The agent.
|
|
19
19
|
agent_name : str
|
|
20
20
|
The agent's name.
|
|
21
21
|
|
|
22
22
|
Returns
|
|
23
23
|
-------
|
|
24
|
-
|
|
24
|
+
tuple[str, str, str]
|
|
25
25
|
The 'embedding_function', the import and the custom_embedding_function.
|
|
26
26
|
"""
|
|
27
27
|
to_import = ""
|
|
@@ -45,20 +45,20 @@ def _get_mongodb_embedding_function_string(
|
|
|
45
45
|
|
|
46
46
|
|
|
47
47
|
def get_mongodb_db_args(
|
|
48
|
-
agent:
|
|
49
|
-
) ->
|
|
48
|
+
agent: WaldiezRagUserProxy, agent_name: str
|
|
49
|
+
) -> tuple[str, Set[str], str]:
|
|
50
50
|
"""Get the kwargs to use for MongoDBAtlasVectorDB.
|
|
51
51
|
|
|
52
52
|
Parameters
|
|
53
53
|
----------
|
|
54
|
-
agent :
|
|
54
|
+
agent : WaldiezRagUserProxy
|
|
55
55
|
The agent.
|
|
56
56
|
agent_name : str
|
|
57
57
|
The agent's name.
|
|
58
58
|
|
|
59
59
|
Returns
|
|
60
60
|
-------
|
|
61
|
-
|
|
61
|
+
tuple[str, Set[str], str]
|
|
62
62
|
The kwargs to use, what to import and the custom_embedding_function.
|
|
63
63
|
"""
|
|
64
64
|
embedding_function_arg, to_import_embedding, embedding_function_body = (
|
|
@@ -2,22 +2,22 @@
|
|
|
2
2
|
# Copyright (c) 2024 - 2025 Waldiez and contributors.
|
|
3
3
|
"""Get pgvector related content and imports."""
|
|
4
4
|
|
|
5
|
-
from typing import Set
|
|
5
|
+
from typing import Set
|
|
6
6
|
|
|
7
|
-
from waldiez.models import
|
|
7
|
+
from waldiez.models import WaldiezRagUserProxy
|
|
8
8
|
|
|
9
9
|
|
|
10
|
-
def _get_pgvector_client_string(agent:
|
|
10
|
+
def _get_pgvector_client_string(agent: WaldiezRagUserProxy) -> tuple[str, str]:
|
|
11
11
|
"""Get the PGVectorDB client string.
|
|
12
12
|
|
|
13
13
|
Parameters
|
|
14
14
|
----------
|
|
15
|
-
agent :
|
|
15
|
+
agent : WaldiezRagUserProxy
|
|
16
16
|
The agent.
|
|
17
17
|
|
|
18
18
|
Returns
|
|
19
19
|
-------
|
|
20
|
-
|
|
20
|
+
tuple[str, str]
|
|
21
21
|
The 'client' and what to import.
|
|
22
22
|
"""
|
|
23
23
|
to_import = "import psycopg"
|
|
@@ -28,20 +28,20 @@ def _get_pgvector_client_string(agent: WaldiezRagUser) -> Tuple[str, str]:
|
|
|
28
28
|
|
|
29
29
|
|
|
30
30
|
def _get_pgvector_embedding_function_string(
|
|
31
|
-
agent:
|
|
32
|
-
) ->
|
|
31
|
+
agent: WaldiezRagUserProxy, agent_name: str
|
|
32
|
+
) -> tuple[str, str, str]:
|
|
33
33
|
"""Get the PGVectorDB embedding function string.
|
|
34
34
|
|
|
35
35
|
Parameters
|
|
36
36
|
----------
|
|
37
|
-
agent :
|
|
37
|
+
agent : WaldiezRagUserProxy
|
|
38
38
|
The agent.
|
|
39
39
|
agent_name : str
|
|
40
40
|
The agent's name.
|
|
41
41
|
|
|
42
42
|
Returns
|
|
43
43
|
-------
|
|
44
|
-
|
|
44
|
+
tuple[str, str, str]
|
|
45
45
|
The 'embedding_function', the import and the custom_embedding_function.
|
|
46
46
|
"""
|
|
47
47
|
to_import = ""
|
|
@@ -65,20 +65,20 @@ def _get_pgvector_embedding_function_string(
|
|
|
65
65
|
|
|
66
66
|
|
|
67
67
|
def get_pgvector_db_args(
|
|
68
|
-
agent:
|
|
69
|
-
) ->
|
|
68
|
+
agent: WaldiezRagUserProxy, agent_name: str
|
|
69
|
+
) -> tuple[str, Set[str], str]:
|
|
70
70
|
"""Get the kwargs to use for PGVectorDB.
|
|
71
71
|
|
|
72
72
|
Parameters
|
|
73
73
|
----------
|
|
74
|
-
agent :
|
|
74
|
+
agent : WaldiezRagUserProxy
|
|
75
75
|
The agent.
|
|
76
76
|
agent_name : str
|
|
77
77
|
The agent's name.
|
|
78
78
|
|
|
79
79
|
Returns
|
|
80
80
|
-------
|
|
81
|
-
|
|
81
|
+
tuple[tuple[str,str], Set[str], str]
|
|
82
82
|
The kwargs to use, what to import and the custom_embedding_function.
|
|
83
83
|
"""
|
|
84
84
|
client_str, to_import_client = _get_pgvector_client_string(agent)
|
|
@@ -3,24 +3,24 @@
|
|
|
3
3
|
"""Get qdrant db related imports and content."""
|
|
4
4
|
|
|
5
5
|
from pathlib import Path
|
|
6
|
-
from typing import Set
|
|
6
|
+
from typing import Set
|
|
7
7
|
|
|
8
|
-
from waldiez.models import
|
|
8
|
+
from waldiez.models import WaldiezRagUserProxy
|
|
9
9
|
|
|
10
10
|
|
|
11
|
-
def _get_qdrant_client_string(agent:
|
|
11
|
+
def _get_qdrant_client_string(agent: WaldiezRagUserProxy) -> tuple[str, str]:
|
|
12
12
|
"""Get the QdrantVectorDB client string.
|
|
13
13
|
|
|
14
14
|
Parameters
|
|
15
15
|
----------
|
|
16
|
-
agent :
|
|
16
|
+
agent : WaldiezRagUserProxy
|
|
17
17
|
The agent.
|
|
18
18
|
agent_name : str
|
|
19
19
|
The agent's name.
|
|
20
20
|
|
|
21
21
|
Returns
|
|
22
22
|
-------
|
|
23
|
-
|
|
23
|
+
tuple[str, str, str]
|
|
24
24
|
The 'client' argument, and the module to import.
|
|
25
25
|
"""
|
|
26
26
|
to_import: str = "from qdrant_client import QdrantClient"
|
|
@@ -44,20 +44,20 @@ def _get_qdrant_client_string(agent: WaldiezRagUser) -> Tuple[str, str]:
|
|
|
44
44
|
|
|
45
45
|
|
|
46
46
|
def _get_qdrant_embedding_function_string(
|
|
47
|
-
agent:
|
|
48
|
-
) ->
|
|
47
|
+
agent: WaldiezRagUserProxy, agent_name: str
|
|
48
|
+
) -> tuple[str, str, str]:
|
|
49
49
|
"""Get the QdrantVectorDB embedding function string.
|
|
50
50
|
|
|
51
51
|
Parameters
|
|
52
52
|
----------
|
|
53
|
-
agent :
|
|
53
|
+
agent : WaldiezRagUserProxy
|
|
54
54
|
The agent.
|
|
55
55
|
agent_name : str
|
|
56
56
|
The agent's name.
|
|
57
57
|
|
|
58
58
|
Returns
|
|
59
59
|
-------
|
|
60
|
-
|
|
60
|
+
tuple[str, str, str]
|
|
61
61
|
The 'embedding_function', the module to import
|
|
62
62
|
and the custom_embedding_function if used.
|
|
63
63
|
"""
|
|
@@ -83,20 +83,20 @@ def _get_qdrant_embedding_function_string(
|
|
|
83
83
|
|
|
84
84
|
|
|
85
85
|
def get_qdrant_db_args(
|
|
86
|
-
agent:
|
|
87
|
-
) ->
|
|
86
|
+
agent: WaldiezRagUserProxy, agent_name: str
|
|
87
|
+
) -> tuple[str, Set[str], str]:
|
|
88
88
|
"""Get the kwargs to use for QdrantVectorDB.
|
|
89
89
|
|
|
90
90
|
Parameters
|
|
91
91
|
----------
|
|
92
|
-
agent :
|
|
92
|
+
agent : WaldiezRagUserProxy
|
|
93
93
|
The agent.
|
|
94
94
|
agent_name : str
|
|
95
95
|
The agent's name.
|
|
96
96
|
|
|
97
97
|
Returns
|
|
98
98
|
-------
|
|
99
|
-
|
|
99
|
+
tuple[str, Set[str], str]
|
|
100
100
|
The kwargs to use, the imports and the embedding function body if used.
|
|
101
101
|
"""
|
|
102
102
|
client_str, to_import_client = _get_qdrant_client_string(agent)
|