waldiez 0.5.1__py3-none-any.whl → 0.5.3__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 +2 -0
- waldiez/exporting/agent/extras/group_manager_agent_extas.py +5 -1
- waldiez/exporting/chats/processor.py +4 -4
- waldiez/exporting/chats/utils/group.py +4 -4
- waldiez/exporting/chats/utils/single.py +3 -3
- waldiez/exporting/tools/exporter.py +1 -1
- waldiez/models/chat/chat_message.py +1 -1
- waldiez/models/tool/extra_requirements.py +5 -0
- waldiez/models/tool/predefined/__init__.py +24 -0
- waldiez/models/tool/predefined/_config.py +68 -0
- waldiez/models/tool/predefined/_google.py +166 -0
- waldiez/models/tool/predefined/_tavily.py +124 -0
- waldiez/models/tool/predefined/_wikipedia.py +130 -0
- waldiez/models/tool/predefined/_youtube.py +123 -0
- waldiez/models/tool/predefined/protocol.py +85 -0
- waldiez/models/tool/predefined/registry.py +79 -0
- waldiez/models/tool/tool.py +96 -13
- waldiez/models/tool/tool_data.py +12 -0
- waldiez/models/tool/tool_type.py +3 -1
- waldiez/runner.py +35 -2
- waldiez/running/base_runner.py +38 -8
- waldiez/running/environment.py +32 -12
- waldiez/running/import_runner.py +13 -0
- waldiez/running/post_run.py +71 -14
- waldiez/running/pre_run.py +42 -0
- waldiez/running/protocol.py +6 -0
- waldiez/running/subprocess_runner.py +4 -0
- waldiez/running/timeline_processor.py +1248 -0
- waldiez/utils/version.py +12 -1
- {waldiez-0.5.1.dist-info → waldiez-0.5.3.dist-info}/METADATA +39 -38
- {waldiez-0.5.1.dist-info → waldiez-0.5.3.dist-info}/RECORD +36 -27
- {waldiez-0.5.1.dist-info → waldiez-0.5.3.dist-info}/WHEEL +0 -0
- {waldiez-0.5.1.dist-info → waldiez-0.5.3.dist-info}/entry_points.txt +0 -0
- {waldiez-0.5.1.dist-info → waldiez-0.5.3.dist-info}/licenses/LICENSE +0 -0
- {waldiez-0.5.1.dist-info → waldiez-0.5.3.dist-info}/licenses/NOTICE.md +0 -0
waldiez/_version.py
CHANGED
waldiez/cli.py
CHANGED
|
@@ -139,6 +139,7 @@ def run(
|
|
|
139
139
|
structured,
|
|
140
140
|
not patch_io, # skip_patch_io
|
|
141
141
|
False, # skip_mmd
|
|
142
|
+
False, # skip_timeline
|
|
142
143
|
)
|
|
143
144
|
else:
|
|
144
145
|
runner.run(
|
|
@@ -148,6 +149,7 @@ def run(
|
|
|
148
149
|
threaded=threaded,
|
|
149
150
|
skip_patch_io=not patch_io,
|
|
150
151
|
skip_mmd=False,
|
|
152
|
+
skip_timeline=False,
|
|
151
153
|
)
|
|
152
154
|
|
|
153
155
|
|
|
@@ -353,8 +353,12 @@ class GroupManagerProcessor:
|
|
|
353
353
|
|
|
354
354
|
# Selection method
|
|
355
355
|
if speakers.selection_method != "custom":
|
|
356
|
+
selection_method = speakers.selection_method
|
|
357
|
+
if selection_method == "default":
|
|
358
|
+
# this only on pattern based group chats :(
|
|
359
|
+
selection_method = "auto"
|
|
356
360
|
config_lines.append(
|
|
357
|
-
f' speaker_selection_method="{
|
|
361
|
+
f' speaker_selection_method="{selection_method}",'
|
|
358
362
|
)
|
|
359
363
|
else:
|
|
360
364
|
# Custom selection method
|
|
@@ -103,10 +103,10 @@ class ChatsProcessor:
|
|
|
103
103
|
"""Process the chats export."""
|
|
104
104
|
self._gather_imports()
|
|
105
105
|
self._handle_chat_registrations()
|
|
106
|
-
chat_initiation = self.
|
|
106
|
+
chat_initiation = self._generate_chat_initiation()
|
|
107
107
|
self._extras.set_chat_initiation(chat_initiation)
|
|
108
108
|
|
|
109
|
-
def
|
|
109
|
+
def _generate_chat_initiation(self) -> str:
|
|
110
110
|
"""Generate the chat definition string.
|
|
111
111
|
|
|
112
112
|
Returns
|
|
@@ -120,7 +120,7 @@ class ChatsProcessor:
|
|
|
120
120
|
return export_group_chats(
|
|
121
121
|
agent_names=self._agent_names,
|
|
122
122
|
manager=self._root_group_manager,
|
|
123
|
-
|
|
123
|
+
initial_chat=None,
|
|
124
124
|
tabs=self._chat_tabs,
|
|
125
125
|
is_async=self._is_async,
|
|
126
126
|
)
|
|
@@ -139,7 +139,7 @@ class ChatsProcessor:
|
|
|
139
139
|
return export_group_chats(
|
|
140
140
|
agent_names=self._agent_names,
|
|
141
141
|
manager=recipient,
|
|
142
|
-
|
|
142
|
+
initial_chat=chat_massage_string,
|
|
143
143
|
tabs=self._chat_tabs,
|
|
144
144
|
is_async=self._is_async,
|
|
145
145
|
)
|
|
@@ -14,7 +14,7 @@ from waldiez.models import WaldiezGroupManager
|
|
|
14
14
|
def export_group_chats(
|
|
15
15
|
agent_names: dict[str, str],
|
|
16
16
|
manager: WaldiezGroupManager,
|
|
17
|
-
|
|
17
|
+
initial_chat: str | None,
|
|
18
18
|
tabs: int,
|
|
19
19
|
is_async: bool,
|
|
20
20
|
) -> str:
|
|
@@ -26,7 +26,7 @@ def export_group_chats(
|
|
|
26
26
|
The agent names.
|
|
27
27
|
manager : WaldiezGroupManager
|
|
28
28
|
The group manager agent.
|
|
29
|
-
|
|
29
|
+
initial_chat : str | None
|
|
30
30
|
The initial chat to use if any.
|
|
31
31
|
tabs : int
|
|
32
32
|
The number of tabs for indentation.
|
|
@@ -46,8 +46,8 @@ def export_group_chats(
|
|
|
46
46
|
pattern_name = f"{manager_name}_pattern"
|
|
47
47
|
content = f"{tab}results, _, __ = {initiate_group_chat}(" + "\n"
|
|
48
48
|
content += f"{tab} pattern={pattern_name}," + "\n"
|
|
49
|
-
if
|
|
50
|
-
content += f"{tab} messages={json.dumps(
|
|
49
|
+
if initial_chat:
|
|
50
|
+
content += f"{tab} messages={json.dumps(initial_chat)}," + "\n"
|
|
51
51
|
else:
|
|
52
52
|
content += f'{tab} messages="",\n'
|
|
53
53
|
content += f"{tab} max_rounds={manager.data.max_round},\n"
|
|
@@ -26,7 +26,7 @@ def export_single_chat(
|
|
|
26
26
|
tabs: int,
|
|
27
27
|
is_async: bool,
|
|
28
28
|
skip_cache: bool,
|
|
29
|
-
|
|
29
|
+
tab_length: int = 4,
|
|
30
30
|
) -> tuple[str, str]:
|
|
31
31
|
"""Get the chat string when there is only one chat in the flow.
|
|
32
32
|
|
|
@@ -50,7 +50,7 @@ def export_single_chat(
|
|
|
50
50
|
Whether the chat is asynchronous.
|
|
51
51
|
skip_cache : bool
|
|
52
52
|
Whether to skip the cache argument.
|
|
53
|
-
|
|
53
|
+
tab_length : int, optional
|
|
54
54
|
The length of the tab string, by default 4.
|
|
55
55
|
|
|
56
56
|
Returns
|
|
@@ -94,7 +94,7 @@ def export_single_chat(
|
|
|
94
94
|
)
|
|
95
95
|
```
|
|
96
96
|
"""
|
|
97
|
-
tab = " " *
|
|
97
|
+
tab = " " * tab_length * tabs if tabs > 0 else ""
|
|
98
98
|
chat_args = chat.get_chat_args(for_queue=False, sender=sender)
|
|
99
99
|
# chat_args = update_summary_chat_args(chat_args, skip_summary=True)
|
|
100
100
|
if not chat_args:
|
|
@@ -159,7 +159,7 @@ class WaldiezChatMessage(WaldiezBase):
|
|
|
159
159
|
)
|
|
160
160
|
content = self.content
|
|
161
161
|
if self.type == "rag_message_generator":
|
|
162
|
-
if self.use_carryover:
|
|
162
|
+
if not self.use_carryover:
|
|
163
163
|
content = get_last_carryover_method_content(
|
|
164
164
|
text_content=self.content or "",
|
|
165
165
|
)
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
from typing import Iterator, Set
|
|
6
6
|
|
|
7
|
+
from .predefined import get_predefined_tool_requirements
|
|
7
8
|
from .tool import WaldiezTool
|
|
8
9
|
|
|
9
10
|
|
|
@@ -31,6 +32,10 @@ def get_tools_extra_requirements(
|
|
|
31
32
|
tool_requirements.add(f"ag2[interop-langchain]=={autogen_version}")
|
|
32
33
|
if tool.tool_type == "crewai":
|
|
33
34
|
tool_requirements.add(f"ag2[interop-crewai]=={autogen_version}")
|
|
35
|
+
if tool.is_predefined:
|
|
36
|
+
tool_requirements.update(
|
|
37
|
+
get_predefined_tool_requirements(tool.name)
|
|
38
|
+
)
|
|
34
39
|
for requirement in tool.requirements:
|
|
35
40
|
tool_requirements.add(requirement)
|
|
36
41
|
return tool_requirements
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# SPDX-License-Identifier: Apache-2.0.
|
|
2
|
+
# Copyright (c) 2024 - 2025 Waldiez and contributors.
|
|
3
|
+
|
|
4
|
+
"""Predefined tools for Waldiez."""
|
|
5
|
+
|
|
6
|
+
from ._config import PredefinedToolConfig
|
|
7
|
+
from .protocol import PredefinedTool
|
|
8
|
+
from .registry import (
|
|
9
|
+
PREDEFINED_TOOLS,
|
|
10
|
+
get_predefined_tool_config,
|
|
11
|
+
get_predefined_tool_imports,
|
|
12
|
+
get_predefined_tool_requirements,
|
|
13
|
+
list_predefined_tools,
|
|
14
|
+
)
|
|
15
|
+
|
|
16
|
+
__all__ = [
|
|
17
|
+
"PredefinedTool",
|
|
18
|
+
"PredefinedToolConfig",
|
|
19
|
+
"PREDEFINED_TOOLS",
|
|
20
|
+
"get_predefined_tool_imports",
|
|
21
|
+
"get_predefined_tool_config",
|
|
22
|
+
"get_predefined_tool_requirements",
|
|
23
|
+
"list_predefined_tools",
|
|
24
|
+
]
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
# SPDX-License-Identifier: Apache-2.0.
|
|
2
|
+
# Copyright (c) 2024 - 2025 Waldiez and contributors.
|
|
3
|
+
"""Predefined tool configuration for Waldiez."""
|
|
4
|
+
|
|
5
|
+
from dataclasses import dataclass
|
|
6
|
+
|
|
7
|
+
from .protocol import PredefinedTool
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
@dataclass
|
|
11
|
+
class PredefinedToolConfig:
|
|
12
|
+
"""Configuration for a predefined tool."""
|
|
13
|
+
|
|
14
|
+
name: str
|
|
15
|
+
description: str
|
|
16
|
+
required_secrets: list[str]
|
|
17
|
+
required_kwargs: dict[str, type]
|
|
18
|
+
requirements: list[str]
|
|
19
|
+
tags: list[str]
|
|
20
|
+
implementation: PredefinedTool
|
|
21
|
+
|
|
22
|
+
def validate_secrets(self, secrets: dict[str, str]) -> list[str]:
|
|
23
|
+
"""Validate secrets and return list of missing required ones.
|
|
24
|
+
|
|
25
|
+
Parameters
|
|
26
|
+
----------
|
|
27
|
+
secrets : dict[str, str]
|
|
28
|
+
Dictionary of secrets/environment variables.
|
|
29
|
+
|
|
30
|
+
Returns
|
|
31
|
+
-------
|
|
32
|
+
list[str]
|
|
33
|
+
List of missing required secrets.
|
|
34
|
+
"""
|
|
35
|
+
return self.implementation.validate_secrets(secrets)
|
|
36
|
+
|
|
37
|
+
def validate_kwargs(self, kwargs: dict[str, str]) -> list[str]:
|
|
38
|
+
"""Validate keyword arguments and return list of missing required ones.
|
|
39
|
+
|
|
40
|
+
Parameters
|
|
41
|
+
----------
|
|
42
|
+
kwargs : dict[str, str]
|
|
43
|
+
Dictionary of keyword arguments.
|
|
44
|
+
|
|
45
|
+
Returns
|
|
46
|
+
-------
|
|
47
|
+
list[str]
|
|
48
|
+
List of missing required keyword arguments.
|
|
49
|
+
"""
|
|
50
|
+
return self.implementation.validate_kwargs(kwargs)
|
|
51
|
+
|
|
52
|
+
def get_content(
|
|
53
|
+
self,
|
|
54
|
+
secrets: dict[str, str],
|
|
55
|
+
) -> str:
|
|
56
|
+
"""Get the content of the tool.
|
|
57
|
+
|
|
58
|
+
Parameters
|
|
59
|
+
----------
|
|
60
|
+
secrets : dict[str, str]
|
|
61
|
+
Dictionary of secrets/environment variables.
|
|
62
|
+
|
|
63
|
+
Returns
|
|
64
|
+
-------
|
|
65
|
+
str
|
|
66
|
+
Content of the tool.
|
|
67
|
+
"""
|
|
68
|
+
return self.implementation.get_content(secrets)
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
# SPDX-License-Identifier: Apache-2.0.
|
|
2
|
+
# Copyright (c) 2024 - 2025 Waldiez and contributors.
|
|
3
|
+
# pylint: disable=line-too-long
|
|
4
|
+
# flake8: noqa: E501
|
|
5
|
+
"""Predefined Google search tool for Waldiez."""
|
|
6
|
+
|
|
7
|
+
import os
|
|
8
|
+
from typing import Any
|
|
9
|
+
|
|
10
|
+
from ._config import PredefinedToolConfig
|
|
11
|
+
from .protocol import PredefinedTool
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class GoogleSearchToolImpl(PredefinedTool):
|
|
15
|
+
"""Google search tool for Waldiez."""
|
|
16
|
+
|
|
17
|
+
required_secrets: list[str] = [
|
|
18
|
+
"GOOGLE_SEARCH_API_KEY",
|
|
19
|
+
]
|
|
20
|
+
required_kwargs: dict[str, type] = {
|
|
21
|
+
"google_search_engine_id": str,
|
|
22
|
+
}
|
|
23
|
+
_kwargs: dict[str, Any] = {}
|
|
24
|
+
|
|
25
|
+
@property
|
|
26
|
+
def name(self) -> str:
|
|
27
|
+
"""Tool name."""
|
|
28
|
+
return "google_search"
|
|
29
|
+
|
|
30
|
+
@property
|
|
31
|
+
def description(self) -> str:
|
|
32
|
+
"""Tool description."""
|
|
33
|
+
return "Search Google for a given query."
|
|
34
|
+
|
|
35
|
+
@property
|
|
36
|
+
def kwargs(self) -> dict[str, Any]:
|
|
37
|
+
"""Keyword arguments for the tool, used for initialization."""
|
|
38
|
+
return self._kwargs
|
|
39
|
+
|
|
40
|
+
@property
|
|
41
|
+
def requirements(self) -> list[str]:
|
|
42
|
+
"""Python requirements for the tool."""
|
|
43
|
+
return ["ag2[google-search,gemini,openai]"]
|
|
44
|
+
|
|
45
|
+
@property
|
|
46
|
+
def tags(self) -> list[str]:
|
|
47
|
+
"""Tags for the tool, used for categorization."""
|
|
48
|
+
return ["google", "search", "web"]
|
|
49
|
+
|
|
50
|
+
@property
|
|
51
|
+
def tool_imports(self) -> list[str]:
|
|
52
|
+
"""Imports required for the tool implementation."""
|
|
53
|
+
return [
|
|
54
|
+
"from autogen.tools.experimental import GoogleSearchTool",
|
|
55
|
+
]
|
|
56
|
+
|
|
57
|
+
@property
|
|
58
|
+
def google_search_engine_id(self) -> str:
|
|
59
|
+
"""Google search engine ID."""
|
|
60
|
+
from_env = os.environ.get("GOOGLE_SEARCH_ENGINE_ID", "")
|
|
61
|
+
if from_env:
|
|
62
|
+
return from_env
|
|
63
|
+
return str(self.kwargs.get("google_search_engine_id", ""))
|
|
64
|
+
|
|
65
|
+
def validate_secrets(self, secrets: dict[str, str]) -> list[str]:
|
|
66
|
+
"""Validate secrets and return list of missing required ones.
|
|
67
|
+
|
|
68
|
+
Parameters
|
|
69
|
+
----------
|
|
70
|
+
secrets : dict[str, str]
|
|
71
|
+
Dictionary of secrets/environment variables.
|
|
72
|
+
|
|
73
|
+
Returns
|
|
74
|
+
-------
|
|
75
|
+
list[str]
|
|
76
|
+
List of missing required secrets.
|
|
77
|
+
"""
|
|
78
|
+
missing: list[str] = []
|
|
79
|
+
for secret in self.required_secrets:
|
|
80
|
+
if secret not in secrets:
|
|
81
|
+
missing.append(secret)
|
|
82
|
+
return missing
|
|
83
|
+
|
|
84
|
+
def validate_kwargs(self, kwargs: dict[str, str]) -> list[str]:
|
|
85
|
+
"""Validate keyword arguments and return list of missing required ones.
|
|
86
|
+
|
|
87
|
+
Parameters
|
|
88
|
+
----------
|
|
89
|
+
kwargs : dict[str, str]
|
|
90
|
+
Dictionary of keyword arguments.
|
|
91
|
+
|
|
92
|
+
Returns
|
|
93
|
+
-------
|
|
94
|
+
list[str]
|
|
95
|
+
List of missing required keyword arguments.
|
|
96
|
+
|
|
97
|
+
Raises
|
|
98
|
+
------
|
|
99
|
+
ValueError
|
|
100
|
+
If any keyword argument is invalid
|
|
101
|
+
(cannot be cast to the required type).
|
|
102
|
+
"""
|
|
103
|
+
missing: list[str] = []
|
|
104
|
+
invalid: list[str] = []
|
|
105
|
+
for name, type_of in self.required_kwargs.items():
|
|
106
|
+
if name not in kwargs:
|
|
107
|
+
missing.append(name)
|
|
108
|
+
elif not isinstance(kwargs[name], type_of):
|
|
109
|
+
try:
|
|
110
|
+
kwargs[name] = type_of(kwargs[name])
|
|
111
|
+
self._kwargs[name] = kwargs[name]
|
|
112
|
+
except Exception: # pylint: disable=broad-except
|
|
113
|
+
invalid.append(name)
|
|
114
|
+
else:
|
|
115
|
+
if name in self._kwargs:
|
|
116
|
+
self._kwargs[name] = kwargs[name]
|
|
117
|
+
else:
|
|
118
|
+
self._kwargs[name] = kwargs[name]
|
|
119
|
+
if invalid:
|
|
120
|
+
raise ValueError(f"Invalid keyword arguments: {invalid}")
|
|
121
|
+
return missing
|
|
122
|
+
|
|
123
|
+
def get_content(
|
|
124
|
+
self,
|
|
125
|
+
secrets: dict[str, str],
|
|
126
|
+
) -> str:
|
|
127
|
+
"""Get content for the tool.
|
|
128
|
+
|
|
129
|
+
Parameters
|
|
130
|
+
----------
|
|
131
|
+
secrets : dict[str, str]
|
|
132
|
+
Dictionary of secrets/environment variables.
|
|
133
|
+
|
|
134
|
+
Returns
|
|
135
|
+
-------
|
|
136
|
+
str
|
|
137
|
+
The content for the tool.
|
|
138
|
+
"""
|
|
139
|
+
os.environ["GOOGLE_SEARCH_API_KEY"] = secrets.get(
|
|
140
|
+
"GOOGLE_SEARCH_API_KEY", ""
|
|
141
|
+
)
|
|
142
|
+
google_search_engine_id = self.google_search_engine_id
|
|
143
|
+
if not google_search_engine_id:
|
|
144
|
+
google_search_engine_id = secrets.get("GOOGLE_SEARCH_ENGINE_ID", "")
|
|
145
|
+
content = f"""
|
|
146
|
+
google_search_api_key = os.environ.get("GOOGLE_SEARCH_API_KEY", "")
|
|
147
|
+
if not google_search_api_key:
|
|
148
|
+
raise ValueError("GOOGLE_SEARCH_API_KEY is required for Google search tool.")
|
|
149
|
+
{self.name} = GoogleSearchTool(
|
|
150
|
+
search_api_key=google_search_api_key,
|
|
151
|
+
search_engine_id="{google_search_engine_id}",
|
|
152
|
+
)
|
|
153
|
+
"""
|
|
154
|
+
return content
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
GoogleSearchTool = GoogleSearchToolImpl()
|
|
158
|
+
GoogleSearchConfig = PredefinedToolConfig(
|
|
159
|
+
name=GoogleSearchTool.name,
|
|
160
|
+
description=GoogleSearchTool.description,
|
|
161
|
+
required_secrets=GoogleSearchTool.required_secrets,
|
|
162
|
+
required_kwargs=GoogleSearchTool.required_kwargs,
|
|
163
|
+
requirements=GoogleSearchTool.requirements,
|
|
164
|
+
tags=GoogleSearchTool.tags,
|
|
165
|
+
implementation=GoogleSearchTool,
|
|
166
|
+
)
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
# SPDX-License-Identifier: Apache-2.0.
|
|
2
|
+
# Copyright (c) 2024 - 2025 Waldiez and contributors.
|
|
3
|
+
# pylint: disable=line-too-long
|
|
4
|
+
# flake8: noqa: E501
|
|
5
|
+
"""Predefined Tavily search tool for Waldiez."""
|
|
6
|
+
|
|
7
|
+
import os
|
|
8
|
+
from typing import Any
|
|
9
|
+
|
|
10
|
+
from ._config import PredefinedToolConfig
|
|
11
|
+
from .protocol import PredefinedTool
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class TavilySearchToolImpl(PredefinedTool):
|
|
15
|
+
"""Tavily search tool for Waldiez."""
|
|
16
|
+
|
|
17
|
+
required_secrets: list[str] = ["TAVILY_API_KEY"]
|
|
18
|
+
required_kwargs: dict[str, type] = {}
|
|
19
|
+
|
|
20
|
+
@property
|
|
21
|
+
def name(self) -> str:
|
|
22
|
+
"""Tool name."""
|
|
23
|
+
return "tavily_search"
|
|
24
|
+
|
|
25
|
+
@property
|
|
26
|
+
def description(self) -> str:
|
|
27
|
+
"""Tool description."""
|
|
28
|
+
return "Search Tavily for a given query."
|
|
29
|
+
|
|
30
|
+
@property
|
|
31
|
+
def kwargs(self) -> dict[str, Any]:
|
|
32
|
+
"""Keyword arguments for the tool, used for initialization."""
|
|
33
|
+
return {}
|
|
34
|
+
|
|
35
|
+
@property
|
|
36
|
+
def requirements(self) -> list[str]:
|
|
37
|
+
"""Python requirements for the tool."""
|
|
38
|
+
return ["ag2[tavily, openai]"]
|
|
39
|
+
|
|
40
|
+
@property
|
|
41
|
+
def tags(self) -> list[str]:
|
|
42
|
+
"""Tags for the tool, used for categorization."""
|
|
43
|
+
return ["tavily", "search", "web"]
|
|
44
|
+
|
|
45
|
+
@property
|
|
46
|
+
def tool_imports(self) -> list[str]:
|
|
47
|
+
"""Imports required for the tool implementation."""
|
|
48
|
+
return [
|
|
49
|
+
"from autogen.tools.experimental import TavilySearchTool",
|
|
50
|
+
]
|
|
51
|
+
|
|
52
|
+
def validate_secrets(self, secrets: dict[str, str]) -> list[str]:
|
|
53
|
+
"""Validate secrets and return list of missing required ones.
|
|
54
|
+
|
|
55
|
+
Parameters
|
|
56
|
+
----------
|
|
57
|
+
secrets : dict[str, str]
|
|
58
|
+
Dictionary of secrets/environment variables.
|
|
59
|
+
|
|
60
|
+
Returns
|
|
61
|
+
-------
|
|
62
|
+
list[str]
|
|
63
|
+
List of missing required secrets.
|
|
64
|
+
"""
|
|
65
|
+
missing = []
|
|
66
|
+
if not secrets.get("TAVILY_API_KEY"):
|
|
67
|
+
missing.append("TAVILY_API_KEY")
|
|
68
|
+
return missing
|
|
69
|
+
|
|
70
|
+
def validate_kwargs(self, kwargs: dict[str, str]) -> list[str]:
|
|
71
|
+
"""Validate keyword arguments and return list of missing required ones.
|
|
72
|
+
|
|
73
|
+
Parameters
|
|
74
|
+
----------
|
|
75
|
+
kwargs : dict[str, str]
|
|
76
|
+
Dictionary of keyword arguments.
|
|
77
|
+
|
|
78
|
+
Returns
|
|
79
|
+
-------
|
|
80
|
+
list[str]
|
|
81
|
+
List of missing required keyword arguments.
|
|
82
|
+
"""
|
|
83
|
+
return []
|
|
84
|
+
|
|
85
|
+
def get_content(
|
|
86
|
+
self,
|
|
87
|
+
secrets: dict[str, str],
|
|
88
|
+
) -> str:
|
|
89
|
+
"""Get content for the tool.
|
|
90
|
+
|
|
91
|
+
Parameters
|
|
92
|
+
----------
|
|
93
|
+
secrets : dict[str, str]
|
|
94
|
+
Dictionary of secrets/environment variables.
|
|
95
|
+
|
|
96
|
+
Returns
|
|
97
|
+
-------
|
|
98
|
+
str
|
|
99
|
+
The content for the tool.
|
|
100
|
+
"""
|
|
101
|
+
os.environ["TAVILY_API_KEY"] = secrets.get(
|
|
102
|
+
"TAVILY_API_KEY", os.environ.get("TAVILY_API_KEY", "")
|
|
103
|
+
)
|
|
104
|
+
content = f"""
|
|
105
|
+
tavily_api_key = os.environ.get("TAVILY_API_KEY", "")
|
|
106
|
+
if not tavily_api_key:
|
|
107
|
+
raise ValueError("TAVILY_API_KEY is required for Tavily search tool.")
|
|
108
|
+
{self.name} = TavilySearchTool(
|
|
109
|
+
tavily_api_key=tavily_api_key,
|
|
110
|
+
)
|
|
111
|
+
"""
|
|
112
|
+
return content
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
TavilySearchTool = TavilySearchToolImpl()
|
|
116
|
+
TavilySearchConfig = PredefinedToolConfig(
|
|
117
|
+
name=TavilySearchTool.name,
|
|
118
|
+
description=TavilySearchTool.description,
|
|
119
|
+
required_secrets=TavilySearchTool.required_secrets,
|
|
120
|
+
required_kwargs=TavilySearchTool.required_kwargs,
|
|
121
|
+
requirements=TavilySearchTool.requirements,
|
|
122
|
+
tags=TavilySearchTool.tags,
|
|
123
|
+
implementation=TavilySearchTool,
|
|
124
|
+
)
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
# SPDX-License-Identifier: Apache-2.0.
|
|
2
|
+
# Copyright (c) 2024 - 2025 Waldiez and contributors.
|
|
3
|
+
"""Predefined Wikipedia search tool for Waldiez."""
|
|
4
|
+
|
|
5
|
+
from typing import Any
|
|
6
|
+
|
|
7
|
+
from ._config import PredefinedToolConfig
|
|
8
|
+
from .protocol import PredefinedTool
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class WikipediaSearchToolImpl(PredefinedTool):
|
|
12
|
+
"""Wikipedia search tool for Waldiez."""
|
|
13
|
+
|
|
14
|
+
required_secrets: list[str] = []
|
|
15
|
+
kwargs_types: dict[str, type] = {
|
|
16
|
+
"language": str,
|
|
17
|
+
"top_k": int,
|
|
18
|
+
"verbose": bool,
|
|
19
|
+
}
|
|
20
|
+
required_kwargs: dict[str, type] = {}
|
|
21
|
+
|
|
22
|
+
@property
|
|
23
|
+
def name(self) -> str:
|
|
24
|
+
"""Tool name."""
|
|
25
|
+
return "wikipedia_search"
|
|
26
|
+
|
|
27
|
+
@property
|
|
28
|
+
def description(self) -> str:
|
|
29
|
+
"""Tool description."""
|
|
30
|
+
return "Search Wikipedia for a given query."
|
|
31
|
+
|
|
32
|
+
@property
|
|
33
|
+
def kwargs(self) -> dict[str, Any]:
|
|
34
|
+
"""Keyword arguments for the tool, used for initialization."""
|
|
35
|
+
return {
|
|
36
|
+
"language": "en",
|
|
37
|
+
"top_k": 3,
|
|
38
|
+
"verbose": False,
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
@property
|
|
42
|
+
def requirements(self) -> list[str]:
|
|
43
|
+
"""Python requirements for the tool."""
|
|
44
|
+
return ["ag2[wikipedia, openai]"]
|
|
45
|
+
|
|
46
|
+
@property
|
|
47
|
+
def tags(self) -> list[str]:
|
|
48
|
+
"""Tags for the tool, used for categorization."""
|
|
49
|
+
return ["wikipedia", "search", "knowledge", "reference"]
|
|
50
|
+
|
|
51
|
+
@property
|
|
52
|
+
def tool_imports(self) -> list[str]:
|
|
53
|
+
"""Imports required for the tool implementation."""
|
|
54
|
+
return [
|
|
55
|
+
"from autogen.tools.experimental import WikipediaQueryRunTool",
|
|
56
|
+
"from autogen.tools.experimental import WikipediaPageLoadTool",
|
|
57
|
+
]
|
|
58
|
+
|
|
59
|
+
def validate_secrets(self, secrets: dict[str, str]) -> list[str]:
|
|
60
|
+
"""Validate secrets and return list of missing required ones.
|
|
61
|
+
|
|
62
|
+
Parameters
|
|
63
|
+
----------
|
|
64
|
+
secrets : dict[str, str]
|
|
65
|
+
Dictionary of secrets/environment variables.
|
|
66
|
+
|
|
67
|
+
Returns
|
|
68
|
+
-------
|
|
69
|
+
list[str]
|
|
70
|
+
List of missing required secrets.
|
|
71
|
+
"""
|
|
72
|
+
return []
|
|
73
|
+
|
|
74
|
+
def validate_kwargs(self, kwargs: dict[str, Any]) -> list[str]:
|
|
75
|
+
"""Validate keyword arguments and return list of missing required ones.
|
|
76
|
+
|
|
77
|
+
Parameters
|
|
78
|
+
----------
|
|
79
|
+
kwargs : dict[str, Any]
|
|
80
|
+
Dictionary of keyword arguments.
|
|
81
|
+
|
|
82
|
+
Returns
|
|
83
|
+
-------
|
|
84
|
+
list[str]
|
|
85
|
+
List of missing required keyword arguments.
|
|
86
|
+
"""
|
|
87
|
+
for key, _ in self.kwargs.items():
|
|
88
|
+
if key in kwargs:
|
|
89
|
+
type_of = self.required_kwargs.get(key, str)
|
|
90
|
+
try:
|
|
91
|
+
casted = type_of(kwargs[key])
|
|
92
|
+
if key in self.kwargs:
|
|
93
|
+
self.kwargs[key] = casted
|
|
94
|
+
except Exception: # pylint: disable=broad-except
|
|
95
|
+
pass
|
|
96
|
+
return []
|
|
97
|
+
|
|
98
|
+
def get_content(
|
|
99
|
+
self,
|
|
100
|
+
secrets: dict[str, str],
|
|
101
|
+
) -> str:
|
|
102
|
+
"""Get the content of the tool.
|
|
103
|
+
|
|
104
|
+
Parameters
|
|
105
|
+
----------
|
|
106
|
+
secrets : dict[str, str]
|
|
107
|
+
Dictionary of secrets/environment variables.
|
|
108
|
+
|
|
109
|
+
Returns
|
|
110
|
+
-------
|
|
111
|
+
str
|
|
112
|
+
Content of the tool.
|
|
113
|
+
"""
|
|
114
|
+
content = f"{self.name} = WikipediaQueryRunTool(\n"
|
|
115
|
+
for key, value in self.kwargs.items():
|
|
116
|
+
content += f" {key}={value!r},\n"
|
|
117
|
+
content += ")\n"
|
|
118
|
+
return content
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
WikipediaSearchTool = WikipediaSearchToolImpl()
|
|
122
|
+
WikipediaSearchConfig = PredefinedToolConfig(
|
|
123
|
+
name=WikipediaSearchTool.name,
|
|
124
|
+
description=WikipediaSearchTool.description,
|
|
125
|
+
required_secrets=WikipediaSearchTool.required_secrets,
|
|
126
|
+
required_kwargs=WikipediaSearchTool.required_kwargs,
|
|
127
|
+
requirements=WikipediaSearchTool.requirements,
|
|
128
|
+
tags=WikipediaSearchTool.tags,
|
|
129
|
+
implementation=WikipediaSearchTool,
|
|
130
|
+
)
|