waldiez 0.5.3__py3-none-any.whl → 0.5.5__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/cli.py +3 -27
- waldiez/exporter.py +0 -13
- waldiez/exporting/agent/exporter.py +38 -0
- waldiez/exporting/agent/extras/__init__.py +2 -0
- waldiez/exporting/agent/extras/doc_agent_extras.py +366 -0
- waldiez/exporting/agent/extras/group_member_extras.py +3 -2
- waldiez/exporting/agent/processor.py +113 -15
- waldiez/exporting/chats/processor.py +2 -21
- waldiez/exporting/chats/utils/common.py +66 -1
- waldiez/exporting/chats/utils/group.py +6 -3
- waldiez/exporting/chats/utils/nested.py +1 -1
- waldiez/exporting/chats/utils/sequential.py +25 -9
- waldiez/exporting/chats/utils/single.py +8 -6
- waldiez/exporting/core/context.py +0 -12
- waldiez/exporting/core/extras/agent_extras/standard_extras.py +3 -1
- waldiez/exporting/core/extras/base.py +20 -17
- waldiez/exporting/core/extras/path_resolver.py +39 -41
- waldiez/exporting/core/extras/serializer.py +16 -1
- waldiez/exporting/core/protocols.py +17 -0
- waldiez/exporting/core/types.py +6 -9
- waldiez/exporting/flow/execution_generator.py +56 -21
- waldiez/exporting/flow/exporter.py +1 -4
- waldiez/exporting/flow/factory.py +0 -9
- waldiez/exporting/flow/file_generator.py +6 -0
- waldiez/exporting/flow/orchestrator.py +27 -21
- waldiez/exporting/flow/utils/__init__.py +0 -2
- waldiez/exporting/flow/utils/common.py +15 -96
- waldiez/exporting/flow/utils/importing.py +4 -0
- waldiez/io/mqtt.py +33 -14
- waldiez/io/redis.py +18 -13
- waldiez/io/structured.py +9 -4
- waldiez/io/utils.py +32 -0
- waldiez/io/ws.py +8 -2
- waldiez/models/__init__.py +6 -0
- waldiez/models/agents/__init__.py +8 -0
- waldiez/models/agents/agent/agent.py +136 -38
- waldiez/models/agents/agent/agent_type.py +3 -2
- waldiez/models/agents/agents.py +10 -0
- waldiez/models/agents/doc_agent/__init__.py +13 -0
- waldiez/models/agents/doc_agent/doc_agent.py +126 -0
- waldiez/models/agents/doc_agent/doc_agent_data.py +149 -0
- waldiez/models/agents/doc_agent/rag_query_engine.py +127 -0
- waldiez/models/flow/flow.py +13 -2
- waldiez/models/model/__init__.py +2 -2
- waldiez/models/model/_aws.py +75 -0
- waldiez/models/model/_llm.py +516 -0
- waldiez/models/model/_price.py +30 -0
- waldiez/models/model/model.py +45 -2
- waldiez/models/model/model_data.py +2 -83
- waldiez/models/tool/predefined/_duckduckgo.py +123 -0
- waldiez/models/tool/predefined/_google.py +31 -9
- waldiez/models/tool/predefined/_perplexity.py +161 -0
- waldiez/models/tool/predefined/_searxng.py +152 -0
- waldiez/models/tool/predefined/_tavily.py +46 -9
- waldiez/models/tool/predefined/_wikipedia.py +26 -6
- waldiez/models/tool/predefined/_youtube.py +36 -8
- waldiez/models/tool/predefined/registry.py +6 -0
- waldiez/models/waldiez.py +12 -0
- waldiez/runner.py +177 -408
- waldiez/running/__init__.py +2 -4
- waldiez/running/base_runner.py +100 -112
- waldiez/running/environment.py +29 -4
- waldiez/running/post_run.py +0 -1
- waldiez/running/protocol.py +36 -48
- waldiez/running/run_results.py +5 -5
- waldiez/running/standard_runner.py +429 -0
- waldiez/running/timeline_processor.py +0 -82
- {waldiez-0.5.3.dist-info → waldiez-0.5.5.dist-info}/METADATA +59 -62
- {waldiez-0.5.3.dist-info → waldiez-0.5.5.dist-info}/RECORD +74 -64
- waldiez/running/import_runner.py +0 -437
- waldiez/running/subprocess_runner.py +0 -104
- {waldiez-0.5.3.dist-info → waldiez-0.5.5.dist-info}/WHEEL +0 -0
- {waldiez-0.5.3.dist-info → waldiez-0.5.5.dist-info}/entry_points.txt +0 -0
- {waldiez-0.5.3.dist-info → waldiez-0.5.5.dist-info}/licenses/LICENSE +0 -0
- {waldiez-0.5.3.dist-info → waldiez-0.5.5.dist-info}/licenses/NOTICE.md +0 -0
waldiez/_version.py
CHANGED
waldiez/cli.py
CHANGED
|
@@ -92,21 +92,8 @@ def run(
|
|
|
92
92
|
structured: bool = typer.Option( # noqa: B008
|
|
93
93
|
False,
|
|
94
94
|
help=(
|
|
95
|
-
"If set,
|
|
96
|
-
|
|
97
|
-
),
|
|
98
|
-
threaded: bool = typer.Option( # noqa: B008
|
|
99
|
-
False,
|
|
100
|
-
help=(
|
|
101
|
-
"If set, the flow will be run in a separate thread. "
|
|
102
|
-
"This is useful for running flows that require user input or print output."
|
|
103
|
-
),
|
|
104
|
-
),
|
|
105
|
-
patch_io: bool = typer.Option( # noqa: B008
|
|
106
|
-
False,
|
|
107
|
-
help=(
|
|
108
|
-
"If set, the flow will patch ag2's IOStream to safe print and input methods. "
|
|
109
|
-
"This is useful for running flows that require user input or print output."
|
|
95
|
+
"If set, the output will be structured as a directory with "
|
|
96
|
+
"the flow file and any additional generated files in it."
|
|
110
97
|
),
|
|
111
98
|
),
|
|
112
99
|
force: bool = typer.Option( # noqa: B008
|
|
@@ -136,8 +123,7 @@ def run(
|
|
|
136
123
|
runner.a_run,
|
|
137
124
|
output_path,
|
|
138
125
|
uploads_root,
|
|
139
|
-
structured,
|
|
140
|
-
not patch_io, # skip_patch_io
|
|
126
|
+
structured, # structured_io
|
|
141
127
|
False, # skip_mmd
|
|
142
128
|
False, # skip_timeline
|
|
143
129
|
)
|
|
@@ -146,8 +132,6 @@ def run(
|
|
|
146
132
|
output_path=output_path,
|
|
147
133
|
uploads_root=uploads_root,
|
|
148
134
|
structured_io=structured,
|
|
149
|
-
threaded=threaded,
|
|
150
|
-
skip_patch_io=not patch_io,
|
|
151
135
|
skip_mmd=False,
|
|
152
136
|
skip_timeline=False,
|
|
153
137
|
)
|
|
@@ -184,13 +168,6 @@ def convert(
|
|
|
184
168
|
False,
|
|
185
169
|
help="Override the output file if it already exists.",
|
|
186
170
|
),
|
|
187
|
-
patch_io: bool = typer.Option( # noqa: B008
|
|
188
|
-
False,
|
|
189
|
-
help=(
|
|
190
|
-
"If set, the exported script will inlclude a snippet to patch ag2's IOStream "
|
|
191
|
-
"to safe print and input methods. "
|
|
192
|
-
),
|
|
193
|
-
),
|
|
194
171
|
debug: bool = typer.Option(
|
|
195
172
|
False,
|
|
196
173
|
"--debug",
|
|
@@ -219,7 +196,6 @@ def convert(
|
|
|
219
196
|
exporter.export(
|
|
220
197
|
output,
|
|
221
198
|
force=force,
|
|
222
|
-
skip_patch_io=not patch_io,
|
|
223
199
|
debug=debug,
|
|
224
200
|
)
|
|
225
201
|
generated = str(output).replace(os.getcwd(), ".")
|
waldiez/exporter.py
CHANGED
|
@@ -63,7 +63,6 @@ class WaldiezExporter:
|
|
|
63
63
|
path: str | Path,
|
|
64
64
|
structured_io: bool = False,
|
|
65
65
|
uploads_root: Path | None = None,
|
|
66
|
-
skip_patch_io: bool = True,
|
|
67
66
|
force: bool = False,
|
|
68
67
|
debug: bool = False,
|
|
69
68
|
) -> None:
|
|
@@ -78,8 +77,6 @@ class WaldiezExporter:
|
|
|
78
77
|
by default False.
|
|
79
78
|
uploads_root : str | Path | None, (optional)
|
|
80
79
|
The uploads root, to get user-uploaded files, by default None.
|
|
81
|
-
skip_patch_io : bool, (optional)
|
|
82
|
-
Whether to skip patching I/O, by default True.
|
|
83
80
|
force : bool, (optional)
|
|
84
81
|
Override the output file if it already exists, by default False.
|
|
85
82
|
debug : bool, (optional)
|
|
@@ -112,7 +109,6 @@ class WaldiezExporter:
|
|
|
112
109
|
path,
|
|
113
110
|
structured_io=structured_io,
|
|
114
111
|
uploads_root=uploads_root,
|
|
115
|
-
skip_patch_io=skip_patch_io,
|
|
116
112
|
debug=debug,
|
|
117
113
|
)
|
|
118
114
|
elif extension == ".ipynb":
|
|
@@ -120,7 +116,6 @@ class WaldiezExporter:
|
|
|
120
116
|
path,
|
|
121
117
|
structured_io=structured_io,
|
|
122
118
|
uploads_root=uploads_root,
|
|
123
|
-
skip_patch_io=skip_patch_io,
|
|
124
119
|
debug=debug,
|
|
125
120
|
)
|
|
126
121
|
else:
|
|
@@ -131,7 +126,6 @@ class WaldiezExporter:
|
|
|
131
126
|
path: str | Path,
|
|
132
127
|
structured_io: bool = False,
|
|
133
128
|
uploads_root: Path | None = None,
|
|
134
|
-
skip_patch_io: bool = True,
|
|
135
129
|
debug: bool = False,
|
|
136
130
|
) -> None:
|
|
137
131
|
"""Export flow to jupyter notebook.
|
|
@@ -145,8 +139,6 @@ class WaldiezExporter:
|
|
|
145
139
|
by default False.
|
|
146
140
|
uploads_root : Path | None, optional
|
|
147
141
|
The uploads root, to get user-uploaded files, by default None.
|
|
148
|
-
skip_patch_io : bool, optional
|
|
149
|
-
Whether to skip patching I/O, by default True.
|
|
150
142
|
debug : bool, optional
|
|
151
143
|
Whether to enable debug mode, by default False.
|
|
152
144
|
|
|
@@ -165,7 +157,6 @@ class WaldiezExporter:
|
|
|
165
157
|
uploads_root=uploads_root,
|
|
166
158
|
structured_io=structured_io,
|
|
167
159
|
for_notebook=True,
|
|
168
|
-
skip_patch_io=skip_patch_io,
|
|
169
160
|
debug=debug,
|
|
170
161
|
)
|
|
171
162
|
self.flow_extras = exporter.extras
|
|
@@ -202,7 +193,6 @@ class WaldiezExporter:
|
|
|
202
193
|
path: str | Path,
|
|
203
194
|
structured_io: bool = False,
|
|
204
195
|
uploads_root: Path | None = None,
|
|
205
|
-
skip_patch_io: bool = True,
|
|
206
196
|
debug: bool = False,
|
|
207
197
|
) -> None:
|
|
208
198
|
"""Export waldiez flow to a python script.
|
|
@@ -216,8 +206,6 @@ class WaldiezExporter:
|
|
|
216
206
|
by default False.
|
|
217
207
|
uploads_root : Path | None, optional
|
|
218
208
|
The uploads root, to get user-uploaded files, by default None.
|
|
219
|
-
skip_patch_io : bool, optional
|
|
220
|
-
Whether to skip patching I/O, by default True.
|
|
221
209
|
debug : bool, optional
|
|
222
210
|
Whether to enable debug mode, by default False.
|
|
223
211
|
|
|
@@ -234,7 +222,6 @@ class WaldiezExporter:
|
|
|
234
222
|
for_notebook=False,
|
|
235
223
|
uploads_root=uploads_root,
|
|
236
224
|
structured_io=structured_io,
|
|
237
|
-
skip_patch_io=skip_patch_io,
|
|
238
225
|
debug=debug,
|
|
239
226
|
)
|
|
240
227
|
self.flow_extras = exporter.extras
|
|
@@ -23,6 +23,7 @@ from ..core import (
|
|
|
23
23
|
)
|
|
24
24
|
from .code_execution import CodeExecutionProcessor
|
|
25
25
|
from .extras.captain_agent_extras import CaptainAgentProcessor
|
|
26
|
+
from .extras.doc_agent_extras import DocAgentProcessor
|
|
26
27
|
from .extras.group_manager_agent_extas import GroupManagerProcessor
|
|
27
28
|
from .extras.group_member_extras import GroupMemberAgentProcessor
|
|
28
29
|
from .extras.rag_user_proxy_agent_extras import RagUserProxyAgentProcessor
|
|
@@ -125,6 +126,8 @@ class AgentExporter(Exporter[StandardExtras]):
|
|
|
125
126
|
return self.create_reasoning_extras()
|
|
126
127
|
if self.agent.is_rag_user:
|
|
127
128
|
return self._create_rag_user_extras()
|
|
129
|
+
if self.agent.is_doc_agent:
|
|
130
|
+
return self._create_doc_agent_extras()
|
|
128
131
|
return self._create_standard_extras()
|
|
129
132
|
|
|
130
133
|
def _create_standard_extras(self) -> StandardExtras:
|
|
@@ -227,6 +230,41 @@ class AgentExporter(Exporter[StandardExtras]):
|
|
|
227
230
|
extras.prepend_before_agent(rag_result.before_agent)
|
|
228
231
|
return extras
|
|
229
232
|
|
|
233
|
+
def _create_doc_agent_extras(self) -> StandardExtras:
|
|
234
|
+
"""Create doc agent extras."""
|
|
235
|
+
# Start with standard extras
|
|
236
|
+
extras = self._create_standard_extras()
|
|
237
|
+
|
|
238
|
+
doc_processor = DocAgentProcessor(
|
|
239
|
+
agent=self.agent,
|
|
240
|
+
agent_names=self.agent_names,
|
|
241
|
+
model_names=self.model_names,
|
|
242
|
+
all_models=self.models,
|
|
243
|
+
output_dir=self.output_dir,
|
|
244
|
+
cache_seed=self.cache_seed,
|
|
245
|
+
serializer=(
|
|
246
|
+
self.context.get_serializer()
|
|
247
|
+
if self.context.serializer
|
|
248
|
+
else None
|
|
249
|
+
),
|
|
250
|
+
)
|
|
251
|
+
doc_extras = doc_processor.process(
|
|
252
|
+
system_message_config=extras.system_message_config,
|
|
253
|
+
termination_config=extras.termination_config,
|
|
254
|
+
code_execution_config=extras.code_execution_config,
|
|
255
|
+
)
|
|
256
|
+
# Add doc agent specific arguments
|
|
257
|
+
for arg in doc_extras.extra_args:
|
|
258
|
+
extras.add_arg(arg)
|
|
259
|
+
# Add doc agent specific imports
|
|
260
|
+
extras.add_imports(doc_extras.extra_imports)
|
|
261
|
+
if doc_extras.before_agent:
|
|
262
|
+
extras.prepend_before_agent(doc_extras.before_agent)
|
|
263
|
+
if doc_extras.after_agent:
|
|
264
|
+
extras.append_after_agent(doc_extras.after_agent)
|
|
265
|
+
|
|
266
|
+
return extras
|
|
267
|
+
|
|
230
268
|
def _create_captain_extras(self) -> StandardExtras:
|
|
231
269
|
"""Create captain agent extras."""
|
|
232
270
|
# Start with standard extras
|
|
@@ -3,12 +3,14 @@
|
|
|
3
3
|
"""Agents exporter extras."""
|
|
4
4
|
|
|
5
5
|
from .captain_agent_extras import CaptainAgentProcessor
|
|
6
|
+
from .doc_agent_extras import DocAgentProcessor
|
|
6
7
|
from .group_manager_agent_extas import GroupManagerProcessor
|
|
7
8
|
from .group_member_extras import GroupMemberAgentProcessor
|
|
8
9
|
from .reasoning_agent_extras import ReasoningAgentProcessor
|
|
9
10
|
|
|
10
11
|
__all__ = [
|
|
11
12
|
"CaptainAgentProcessor",
|
|
13
|
+
"DocAgentProcessor",
|
|
12
14
|
"GroupManagerProcessor",
|
|
13
15
|
"GroupMemberAgentProcessor",
|
|
14
16
|
"ReasoningAgentProcessor",
|
|
@@ -0,0 +1,366 @@
|
|
|
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
|
+
|
|
5
|
+
# before agent: query engine initialization
|
|
6
|
+
# agent extra args:
|
|
7
|
+
# parsed_docs_path: Optional[Union[str, Path]] = None, # (we use str)
|
|
8
|
+
# collection_name: Optional[str] = None, # (we use str)
|
|
9
|
+
# query_engine: Optional[RAGQueryEngine] = None, # (we use RAGQueryEngine)
|
|
10
|
+
|
|
11
|
+
"""Document Agent Extras."""
|
|
12
|
+
|
|
13
|
+
# import shutil
|
|
14
|
+
import shutil
|
|
15
|
+
from pathlib import Path
|
|
16
|
+
from typing import Optional
|
|
17
|
+
|
|
18
|
+
from waldiez.exporting.core.extras.path_resolver import DefaultPathResolver
|
|
19
|
+
from waldiez.exporting.core.protocols import PathResolver
|
|
20
|
+
from waldiez.exporting.core.utils.llm_config import get_agent_llm_config_arg
|
|
21
|
+
from waldiez.models import (
|
|
22
|
+
WaldiezAgent,
|
|
23
|
+
WaldiezDocAgent,
|
|
24
|
+
WaldiezDocAgentQueryEngine,
|
|
25
|
+
WaldiezModel,
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
from ...core import (
|
|
29
|
+
CodeExecutionConfig,
|
|
30
|
+
DefaultSerializer,
|
|
31
|
+
ImportPosition,
|
|
32
|
+
ImportStatement,
|
|
33
|
+
InstanceArgument,
|
|
34
|
+
Serializer,
|
|
35
|
+
SystemMessageConfig,
|
|
36
|
+
TerminationConfig,
|
|
37
|
+
)
|
|
38
|
+
from ...core.extras.agent_extras import StandardExtras
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
class DocAgentProcessor:
|
|
42
|
+
"""Process document agent requests."""
|
|
43
|
+
|
|
44
|
+
extras: StandardExtras
|
|
45
|
+
|
|
46
|
+
def __init__(
|
|
47
|
+
self,
|
|
48
|
+
agent: WaldiezAgent,
|
|
49
|
+
agent_names: dict[str, str],
|
|
50
|
+
model_names: dict[str, str],
|
|
51
|
+
all_models: list[WaldiezModel],
|
|
52
|
+
cache_seed: Optional[int] = None,
|
|
53
|
+
serializer: Serializer | None = None,
|
|
54
|
+
path_resolver: PathResolver | None = None,
|
|
55
|
+
output_dir: Optional[Path] = None,
|
|
56
|
+
):
|
|
57
|
+
self.agent = agent
|
|
58
|
+
self.agent_name = agent_names.get(agent.id, agent.name)
|
|
59
|
+
self.output_dir = output_dir
|
|
60
|
+
self.model_names = model_names
|
|
61
|
+
self.all_models = all_models
|
|
62
|
+
self.cache_seed = cache_seed
|
|
63
|
+
self.path_resolver = path_resolver or DefaultPathResolver()
|
|
64
|
+
self.serializer = serializer or DefaultSerializer()
|
|
65
|
+
|
|
66
|
+
def process(
|
|
67
|
+
self,
|
|
68
|
+
code_execution_config: Optional[CodeExecutionConfig] = None,
|
|
69
|
+
termination_config: Optional[TerminationConfig] = None,
|
|
70
|
+
system_message_config: Optional[SystemMessageConfig] = None,
|
|
71
|
+
) -> StandardExtras:
|
|
72
|
+
"""Process the document agent configuration.
|
|
73
|
+
|
|
74
|
+
Parameters
|
|
75
|
+
----------
|
|
76
|
+
code_execution_config : CodeExecutionConfig, optional
|
|
77
|
+
Configuration for code execution, if applicable.
|
|
78
|
+
termination_config : TerminationConfig, optional
|
|
79
|
+
Configuration for termination, if applicable.
|
|
80
|
+
system_message_config : SystemMessageConfig, optional
|
|
81
|
+
Configuration for system messages, if applicable.
|
|
82
|
+
|
|
83
|
+
Returns
|
|
84
|
+
-------
|
|
85
|
+
DocExtras
|
|
86
|
+
The document agent extras.
|
|
87
|
+
"""
|
|
88
|
+
self.extras = StandardExtras(
|
|
89
|
+
instance_id=self.agent.id,
|
|
90
|
+
code_execution_config=code_execution_config,
|
|
91
|
+
termination_config=termination_config,
|
|
92
|
+
system_message_config=system_message_config,
|
|
93
|
+
)
|
|
94
|
+
if not self.agent.is_doc_agent or not isinstance(
|
|
95
|
+
self.agent, WaldiezDocAgent
|
|
96
|
+
):
|
|
97
|
+
return self.extras
|
|
98
|
+
parsed_docs_path = self.get_parsed_docs_path()
|
|
99
|
+
self.extras.add_arg(
|
|
100
|
+
InstanceArgument(
|
|
101
|
+
instance_id=self.agent.id,
|
|
102
|
+
name="parsed_docs_path",
|
|
103
|
+
value=parsed_docs_path,
|
|
104
|
+
tabs=1,
|
|
105
|
+
)
|
|
106
|
+
)
|
|
107
|
+
self._get_query_engine_extras()
|
|
108
|
+
if self.extras.before_agent:
|
|
109
|
+
self.extras.add_arg(
|
|
110
|
+
InstanceArgument(
|
|
111
|
+
instance_id=self.agent.id,
|
|
112
|
+
name="query_engine",
|
|
113
|
+
value=f"{self.agent_name}_query_engine",
|
|
114
|
+
tabs=1,
|
|
115
|
+
)
|
|
116
|
+
)
|
|
117
|
+
self.extras.prepend_before_agent(self.extras.before_agent)
|
|
118
|
+
return self.extras
|
|
119
|
+
|
|
120
|
+
def _get_query_engine_extras(self) -> None:
|
|
121
|
+
if not isinstance(self.agent, WaldiezDocAgent):
|
|
122
|
+
return
|
|
123
|
+
query_engine = self.agent.get_query_engine()
|
|
124
|
+
if query_engine.type == "InMemoryQueryEngine":
|
|
125
|
+
self.get_in_memory_query_engine_extras()
|
|
126
|
+
elif query_engine.type == "VectorChromaQueryEngine":
|
|
127
|
+
self.get_vector_chroma_query_engine_extras(
|
|
128
|
+
self.agent.data.get_collection_name(),
|
|
129
|
+
)
|
|
130
|
+
elif (
|
|
131
|
+
query_engine.type == "VectorChromaCitationQueryEngine"
|
|
132
|
+
): # pragma: no branch
|
|
133
|
+
self.get_vector_chroma_citation_query_engine_extras(
|
|
134
|
+
query_engine,
|
|
135
|
+
self.agent.data.get_collection_name(),
|
|
136
|
+
)
|
|
137
|
+
|
|
138
|
+
def get_in_memory_query_engine_extras(self) -> None:
|
|
139
|
+
"""Get the in-memory query engine extras."""
|
|
140
|
+
# InMemoryQueryEngine(llm_config=llm_config)
|
|
141
|
+
self.extras.add_import(
|
|
142
|
+
ImportStatement(
|
|
143
|
+
statement=(
|
|
144
|
+
"from autogen.agents.experimental.document_agent."
|
|
145
|
+
"inmemory_query_engine import InMemoryQueryEngine"
|
|
146
|
+
)
|
|
147
|
+
)
|
|
148
|
+
)
|
|
149
|
+
llm_config_arg = get_agent_llm_config_arg(
|
|
150
|
+
agent=self.agent,
|
|
151
|
+
tabs=1,
|
|
152
|
+
model_names=self.model_names,
|
|
153
|
+
all_models=self.all_models,
|
|
154
|
+
cache_seed=self.cache_seed,
|
|
155
|
+
)
|
|
156
|
+
self.extras.before_agent = (
|
|
157
|
+
f"{self.agent_name}_query_engine = "
|
|
158
|
+
f"InMemoryQueryEngine(\n{llm_config_arg}\n)"
|
|
159
|
+
)
|
|
160
|
+
|
|
161
|
+
def get_vector_chroma_query_engine_extras(
|
|
162
|
+
self,
|
|
163
|
+
collection_name: str,
|
|
164
|
+
) -> None:
|
|
165
|
+
"""Get the vector Chroma query engine extras.
|
|
166
|
+
|
|
167
|
+
Parameters
|
|
168
|
+
----------
|
|
169
|
+
collection_name : str
|
|
170
|
+
The name of the collection to use.
|
|
171
|
+
"""
|
|
172
|
+
# VectorChromaQueryEngine(
|
|
173
|
+
# db_path: Optional[str] = None,
|
|
174
|
+
# embedding_function: "Optional[EmbeddingFunction[Any]]" = None,
|
|
175
|
+
# metadata: Optional[dict[str, Any]] = None,
|
|
176
|
+
# llm: Optional["LLM"] = None,
|
|
177
|
+
# collection_name: Optional[str] = None,
|
|
178
|
+
# )
|
|
179
|
+
self.extras.add_import(
|
|
180
|
+
ImportStatement(
|
|
181
|
+
statement=(
|
|
182
|
+
"from autogen.agents.experimental.document_agent."
|
|
183
|
+
"chroma_query_engine import VectorChromaQueryEngine"
|
|
184
|
+
)
|
|
185
|
+
)
|
|
186
|
+
)
|
|
187
|
+
llm_arg, before = self.get_llm_arg()
|
|
188
|
+
db_path = self.get_db_path()
|
|
189
|
+
self.extras.before_agent = before + "\n"
|
|
190
|
+
q_engine_init = (
|
|
191
|
+
f"{self.agent_name}_query_engine = "
|
|
192
|
+
f"VectorChromaQueryEngine(\n {llm_arg}"
|
|
193
|
+
)
|
|
194
|
+
if db_path: # pragma: no branch
|
|
195
|
+
q_engine_init += f",\n db_path={db_path}"
|
|
196
|
+
if collection_name: # pragma: no branch
|
|
197
|
+
q_engine_init += f',\n collection_name="{collection_name}"'
|
|
198
|
+
q_engine_init += ",\n)"
|
|
199
|
+
self.extras.before_agent += q_engine_init
|
|
200
|
+
|
|
201
|
+
def get_vector_chroma_citation_query_engine_extras(
|
|
202
|
+
self,
|
|
203
|
+
query_engine: WaldiezDocAgentQueryEngine,
|
|
204
|
+
collection_name: str,
|
|
205
|
+
) -> None:
|
|
206
|
+
"""Get the vector Chroma citation query engine extras.
|
|
207
|
+
|
|
208
|
+
Parameters
|
|
209
|
+
----------
|
|
210
|
+
query_engine : WaldiezDocAgentQueryEngine
|
|
211
|
+
The vector Chroma citation query engine to process.
|
|
212
|
+
collection_name : str
|
|
213
|
+
The name of the collection to use.
|
|
214
|
+
"""
|
|
215
|
+
# VectorChromaCitationQueryEngine(
|
|
216
|
+
# llm: Optional["LLM"] = None,
|
|
217
|
+
# collection_name: Optional[str] = None,
|
|
218
|
+
# enable_query_citations: bool = False,
|
|
219
|
+
# citation_chunk_size: int = 512,
|
|
220
|
+
# )
|
|
221
|
+
self.extras.add_import(
|
|
222
|
+
ImportStatement(
|
|
223
|
+
statement=(
|
|
224
|
+
"from autogen.agents.experimental.document_agent."
|
|
225
|
+
"chroma_query_engine import VectorChromaCitationQueryEngine"
|
|
226
|
+
)
|
|
227
|
+
)
|
|
228
|
+
)
|
|
229
|
+
db_path = self.get_db_path()
|
|
230
|
+
llm_arg, before = self.get_llm_arg()
|
|
231
|
+
self.extras.before_agent = before + "\n"
|
|
232
|
+
q_engine_init = (
|
|
233
|
+
f"{self.agent_name}_query_engine = "
|
|
234
|
+
f"VectorChromaCitationQueryEngine({llm_arg}"
|
|
235
|
+
)
|
|
236
|
+
if db_path: # pragma: no branch
|
|
237
|
+
q_engine_init += f",\n db_path={db_path}"
|
|
238
|
+
if collection_name: # pragma: no branch
|
|
239
|
+
q_engine_init += f',\n collection_name="{collection_name}"'
|
|
240
|
+
enable_query_citations = query_engine.enable_query_citations
|
|
241
|
+
chunk_size = query_engine.citation_chunk_size or 512
|
|
242
|
+
q_engine_init += (
|
|
243
|
+
f",\n enable_query_citations={enable_query_citations}"
|
|
244
|
+
f",\n citation_chunk_size={chunk_size}"
|
|
245
|
+
)
|
|
246
|
+
q_engine_init += ",\n)"
|
|
247
|
+
self.extras.before_agent += q_engine_init
|
|
248
|
+
|
|
249
|
+
def get_llm_arg(self) -> tuple[str, str]:
|
|
250
|
+
"""Get the LLM argument for the agent and any content before it.
|
|
251
|
+
|
|
252
|
+
Returns
|
|
253
|
+
-------
|
|
254
|
+
str
|
|
255
|
+
The LLM argument for the agent and any content before it.
|
|
256
|
+
"""
|
|
257
|
+
agent_model = get_agent_model(
|
|
258
|
+
agent=self.agent,
|
|
259
|
+
all_models=self.all_models,
|
|
260
|
+
)
|
|
261
|
+
if not agent_model:
|
|
262
|
+
# ag2's default
|
|
263
|
+
self.extras.add_import(
|
|
264
|
+
ImportStatement(
|
|
265
|
+
statement="from llama_index.llms.openai import OpenAI",
|
|
266
|
+
)
|
|
267
|
+
)
|
|
268
|
+
return 'llm=OpenAI(model="gpt-4o", temperature=0.0)', ""
|
|
269
|
+
arg, before = agent_model.get_llm_arg()
|
|
270
|
+
for import_stmt in agent_model.get_llm_imports():
|
|
271
|
+
self.extras.add_import(
|
|
272
|
+
ImportStatement(
|
|
273
|
+
statement=import_stmt,
|
|
274
|
+
position=ImportPosition.THIRD_PARTY,
|
|
275
|
+
)
|
|
276
|
+
)
|
|
277
|
+
return f"llm={arg}", before
|
|
278
|
+
|
|
279
|
+
def get_db_path(self) -> str:
|
|
280
|
+
"""Get the database path for the document agent.
|
|
281
|
+
|
|
282
|
+
Returns
|
|
283
|
+
-------
|
|
284
|
+
str
|
|
285
|
+
The database path for the document agent.
|
|
286
|
+
|
|
287
|
+
Raises
|
|
288
|
+
------
|
|
289
|
+
TypeError
|
|
290
|
+
If the agent is not a WaldiezDocAgent instance.
|
|
291
|
+
"""
|
|
292
|
+
if not isinstance(self.agent, WaldiezDocAgent): # pragma: no cover
|
|
293
|
+
raise TypeError("Agent must be a WaldiezDocAgent instance.")
|
|
294
|
+
query_engine = self.agent.get_query_engine()
|
|
295
|
+
db_path_str = ""
|
|
296
|
+
if query_engine.get_db_path():
|
|
297
|
+
db_path_str = query_engine.get_db_path()
|
|
298
|
+
else:
|
|
299
|
+
if self.output_dir:
|
|
300
|
+
chroma_dir = self.output_dir / "chroma"
|
|
301
|
+
chroma_dir.mkdir(parents=True, exist_ok=True)
|
|
302
|
+
db_path_str = str(chroma_dir)
|
|
303
|
+
else:
|
|
304
|
+
db_path_str = query_engine.get_db_path()
|
|
305
|
+
if self.agent.data.reset_collection is True:
|
|
306
|
+
shutil.rmtree(db_path_str, ignore_errors=True)
|
|
307
|
+
Path(db_path_str).mkdir(parents=True, exist_ok=True)
|
|
308
|
+
return self.path_resolver.resolve(db_path_str)
|
|
309
|
+
|
|
310
|
+
def get_parsed_docs_path(self) -> str:
|
|
311
|
+
"""Get the parsed documents path for the document agent.
|
|
312
|
+
|
|
313
|
+
Returns
|
|
314
|
+
-------
|
|
315
|
+
str
|
|
316
|
+
The parsed documents path for the document agent.
|
|
317
|
+
|
|
318
|
+
Raises
|
|
319
|
+
------
|
|
320
|
+
TypeError
|
|
321
|
+
If the agent is not a WaldiezDocAgent instance.
|
|
322
|
+
"""
|
|
323
|
+
if not isinstance(self.agent, WaldiezDocAgent):
|
|
324
|
+
raise TypeError("Agent must be a WaldiezDocAgent instance.")
|
|
325
|
+
parsed_docs_path = self.agent.data.parsed_docs_path or ""
|
|
326
|
+
if not parsed_docs_path:
|
|
327
|
+
if self.output_dir:
|
|
328
|
+
parsed_docs_path = str(self.output_dir / "parsed_docs")
|
|
329
|
+
else:
|
|
330
|
+
parsed_docs_path = self.agent.get_parsed_docs_path()
|
|
331
|
+
resolved = Path(parsed_docs_path).resolve()
|
|
332
|
+
if not resolved.is_absolute():
|
|
333
|
+
parsed_docs_path = str(Path.cwd() / parsed_docs_path)
|
|
334
|
+
if not Path(parsed_docs_path).is_dir():
|
|
335
|
+
Path(parsed_docs_path).mkdir(parents=True, exist_ok=True)
|
|
336
|
+
if self.agent.data.reset_collection is True:
|
|
337
|
+
shutil.rmtree(parsed_docs_path, ignore_errors=True)
|
|
338
|
+
Path(parsed_docs_path).mkdir(parents=True, exist_ok=True)
|
|
339
|
+
return self.path_resolver.resolve(str(parsed_docs_path))
|
|
340
|
+
|
|
341
|
+
|
|
342
|
+
def get_agent_model(
|
|
343
|
+
agent: WaldiezAgent,
|
|
344
|
+
all_models: list[WaldiezModel],
|
|
345
|
+
) -> WaldiezModel | None:
|
|
346
|
+
"""Get the first model of the agent.
|
|
347
|
+
|
|
348
|
+
Parameters
|
|
349
|
+
----------
|
|
350
|
+
agent : WaldiezAgent
|
|
351
|
+
The agent.
|
|
352
|
+
all_models : list[WaldiezModel]
|
|
353
|
+
All the models in the flow.
|
|
354
|
+
|
|
355
|
+
Returns
|
|
356
|
+
-------
|
|
357
|
+
WaldiezModel | None
|
|
358
|
+
The first model of the agent, or None if not found.
|
|
359
|
+
"""
|
|
360
|
+
if not agent.data.model_ids:
|
|
361
|
+
return None
|
|
362
|
+
for model_id in agent.data.model_ids:
|
|
363
|
+
model = next((m for m in all_models if m.id == model_id), None)
|
|
364
|
+
if model is not None:
|
|
365
|
+
return model
|
|
366
|
+
return None
|
|
@@ -68,8 +68,9 @@ class GroupMemberAgentProcessor:
|
|
|
68
68
|
self.result = GroupMemberProcessorResult()
|
|
69
69
|
if not self.agent.is_group_member:
|
|
70
70
|
return self.result
|
|
71
|
-
self.
|
|
72
|
-
|
|
71
|
+
if not self.agent.is_doc_agent:
|
|
72
|
+
self._process_agent_functions()
|
|
73
|
+
self._process_agent_update_state_before_reply()
|
|
73
74
|
self._process_handoff_registrations()
|
|
74
75
|
return self.result
|
|
75
76
|
|