ag2 0.9.7__py3-none-any.whl → 0.9.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 ag2 might be problematic. Click here for more details.
- {ag2-0.9.7.dist-info → ag2-0.9.9.dist-info}/METADATA +102 -75
- ag2-0.9.9.dist-info/RECORD +387 -0
- autogen/__init__.py +1 -2
- autogen/_website/generate_api_references.py +4 -5
- autogen/_website/generate_mkdocs.py +9 -15
- autogen/_website/notebook_processor.py +13 -14
- autogen/_website/process_notebooks.py +10 -10
- autogen/_website/utils.py +5 -4
- autogen/agentchat/agent.py +13 -13
- autogen/agentchat/assistant_agent.py +7 -6
- autogen/agentchat/contrib/agent_eval/agent_eval.py +3 -3
- autogen/agentchat/contrib/agent_eval/critic_agent.py +3 -3
- autogen/agentchat/contrib/agent_eval/quantifier_agent.py +3 -3
- autogen/agentchat/contrib/agent_eval/subcritic_agent.py +3 -3
- autogen/agentchat/contrib/agent_optimizer.py +3 -3
- autogen/agentchat/contrib/capabilities/generate_images.py +11 -11
- autogen/agentchat/contrib/capabilities/teachability.py +15 -15
- autogen/agentchat/contrib/capabilities/transforms.py +17 -18
- autogen/agentchat/contrib/capabilities/transforms_util.py +5 -5
- autogen/agentchat/contrib/capabilities/vision_capability.py +4 -3
- autogen/agentchat/contrib/captainagent/agent_builder.py +30 -30
- autogen/agentchat/contrib/captainagent/captainagent.py +22 -21
- autogen/agentchat/contrib/captainagent/tool_retriever.py +2 -3
- autogen/agentchat/contrib/gpt_assistant_agent.py +9 -9
- autogen/agentchat/contrib/graph_rag/document.py +3 -3
- autogen/agentchat/contrib/graph_rag/falkor_graph_query_engine.py +3 -3
- autogen/agentchat/contrib/graph_rag/falkor_graph_rag_capability.py +6 -6
- autogen/agentchat/contrib/graph_rag/graph_query_engine.py +3 -3
- autogen/agentchat/contrib/graph_rag/neo4j_graph_query_engine.py +5 -11
- autogen/agentchat/contrib/graph_rag/neo4j_graph_rag_capability.py +6 -6
- autogen/agentchat/contrib/graph_rag/neo4j_native_graph_query_engine.py +7 -7
- autogen/agentchat/contrib/graph_rag/neo4j_native_graph_rag_capability.py +6 -6
- autogen/agentchat/contrib/img_utils.py +1 -1
- autogen/agentchat/contrib/llamaindex_conversable_agent.py +11 -11
- autogen/agentchat/contrib/llava_agent.py +18 -4
- autogen/agentchat/contrib/math_user_proxy_agent.py +11 -11
- autogen/agentchat/contrib/multimodal_conversable_agent.py +8 -8
- autogen/agentchat/contrib/qdrant_retrieve_user_proxy_agent.py +6 -5
- autogen/agentchat/contrib/rag/chromadb_query_engine.py +22 -26
- autogen/agentchat/contrib/rag/llamaindex_query_engine.py +14 -17
- autogen/agentchat/contrib/rag/mongodb_query_engine.py +27 -37
- autogen/agentchat/contrib/rag/query_engine.py +7 -5
- autogen/agentchat/contrib/retrieve_assistant_agent.py +5 -5
- autogen/agentchat/contrib/retrieve_user_proxy_agent.py +8 -7
- autogen/agentchat/contrib/society_of_mind_agent.py +15 -14
- autogen/agentchat/contrib/swarm_agent.py +76 -98
- autogen/agentchat/contrib/text_analyzer_agent.py +7 -7
- autogen/agentchat/contrib/vectordb/base.py +10 -18
- autogen/agentchat/contrib/vectordb/chromadb.py +2 -1
- autogen/agentchat/contrib/vectordb/couchbase.py +18 -20
- autogen/agentchat/contrib/vectordb/mongodb.py +6 -5
- autogen/agentchat/contrib/vectordb/pgvectordb.py +40 -41
- autogen/agentchat/contrib/vectordb/qdrant.py +5 -5
- autogen/agentchat/contrib/web_surfer.py +20 -19
- autogen/agentchat/conversable_agent.py +292 -290
- autogen/agentchat/group/context_str.py +1 -3
- autogen/agentchat/group/context_variables.py +15 -25
- autogen/agentchat/group/group_tool_executor.py +10 -10
- autogen/agentchat/group/group_utils.py +15 -15
- autogen/agentchat/group/guardrails.py +7 -7
- autogen/agentchat/group/handoffs.py +19 -36
- autogen/agentchat/group/multi_agent_chat.py +7 -7
- autogen/agentchat/group/on_condition.py +4 -7
- autogen/agentchat/group/on_context_condition.py +4 -7
- autogen/agentchat/group/patterns/auto.py +8 -7
- autogen/agentchat/group/patterns/manual.py +7 -6
- autogen/agentchat/group/patterns/pattern.py +13 -12
- autogen/agentchat/group/patterns/random.py +3 -3
- autogen/agentchat/group/patterns/round_robin.py +3 -3
- autogen/agentchat/group/reply_result.py +2 -4
- autogen/agentchat/group/speaker_selection_result.py +5 -5
- autogen/agentchat/group/targets/group_chat_target.py +7 -6
- autogen/agentchat/group/targets/group_manager_target.py +4 -4
- autogen/agentchat/group/targets/transition_target.py +2 -1
- autogen/agentchat/groupchat.py +60 -63
- autogen/agentchat/realtime/experimental/audio_adapters/twilio_audio_adapter.py +4 -4
- autogen/agentchat/realtime/experimental/audio_adapters/websocket_audio_adapter.py +4 -4
- autogen/agentchat/realtime/experimental/clients/gemini/client.py +7 -7
- autogen/agentchat/realtime/experimental/clients/oai/base_client.py +8 -8
- autogen/agentchat/realtime/experimental/clients/oai/rtc_client.py +6 -6
- autogen/agentchat/realtime/experimental/clients/realtime_client.py +10 -9
- autogen/agentchat/realtime/experimental/realtime_agent.py +10 -9
- autogen/agentchat/realtime/experimental/realtime_observer.py +3 -3
- autogen/agentchat/realtime/experimental/realtime_swarm.py +44 -44
- autogen/agentchat/user_proxy_agent.py +10 -9
- autogen/agentchat/utils.py +3 -3
- autogen/agents/contrib/time/time_reply_agent.py +6 -5
- autogen/agents/contrib/time/time_tool_agent.py +2 -1
- autogen/agents/experimental/deep_research/deep_research.py +3 -3
- autogen/agents/experimental/discord/discord.py +2 -2
- autogen/agents/experimental/document_agent/chroma_query_engine.py +29 -44
- autogen/agents/experimental/document_agent/docling_doc_ingest_agent.py +9 -14
- autogen/agents/experimental/document_agent/document_agent.py +15 -16
- autogen/agents/experimental/document_agent/document_conditions.py +3 -3
- autogen/agents/experimental/document_agent/document_utils.py +5 -9
- autogen/agents/experimental/document_agent/inmemory_query_engine.py +14 -20
- autogen/agents/experimental/document_agent/parser_utils.py +4 -4
- autogen/agents/experimental/document_agent/url_utils.py +14 -23
- autogen/agents/experimental/reasoning/reasoning_agent.py +33 -33
- autogen/agents/experimental/slack/slack.py +2 -2
- autogen/agents/experimental/telegram/telegram.py +2 -3
- autogen/agents/experimental/websurfer/websurfer.py +4 -4
- autogen/agents/experimental/wikipedia/wikipedia.py +5 -7
- autogen/browser_utils.py +8 -8
- autogen/cache/abstract_cache_base.py +5 -5
- autogen/cache/cache.py +12 -12
- autogen/cache/cache_factory.py +4 -4
- autogen/cache/cosmos_db_cache.py +9 -9
- autogen/cache/disk_cache.py +6 -6
- autogen/cache/in_memory_cache.py +4 -4
- autogen/cache/redis_cache.py +4 -4
- autogen/code_utils.py +18 -18
- autogen/coding/base.py +6 -6
- autogen/coding/docker_commandline_code_executor.py +9 -9
- autogen/coding/func_with_reqs.py +7 -6
- autogen/coding/jupyter/base.py +3 -3
- autogen/coding/jupyter/docker_jupyter_server.py +3 -4
- autogen/coding/jupyter/import_utils.py +3 -3
- autogen/coding/jupyter/jupyter_client.py +5 -5
- autogen/coding/jupyter/jupyter_code_executor.py +3 -4
- autogen/coding/jupyter/local_jupyter_server.py +2 -6
- autogen/coding/local_commandline_code_executor.py +8 -7
- autogen/coding/markdown_code_extractor.py +1 -2
- autogen/coding/utils.py +1 -2
- autogen/doc_utils.py +3 -2
- autogen/environments/docker_python_environment.py +19 -29
- autogen/environments/python_environment.py +8 -17
- autogen/environments/system_python_environment.py +3 -4
- autogen/environments/venv_python_environment.py +8 -12
- autogen/environments/working_directory.py +1 -2
- autogen/events/agent_events.py +106 -109
- autogen/events/base_event.py +6 -5
- autogen/events/client_events.py +15 -14
- autogen/events/helpers.py +1 -1
- autogen/events/print_event.py +4 -5
- autogen/fast_depends/_compat.py +10 -15
- autogen/fast_depends/core/build.py +17 -36
- autogen/fast_depends/core/model.py +64 -113
- autogen/fast_depends/dependencies/model.py +2 -1
- autogen/fast_depends/dependencies/provider.py +3 -2
- autogen/fast_depends/library/model.py +4 -4
- autogen/fast_depends/schema.py +7 -7
- autogen/fast_depends/use.py +17 -25
- autogen/fast_depends/utils.py +10 -30
- autogen/formatting_utils.py +6 -6
- autogen/graph_utils.py +1 -4
- autogen/import_utils.py +38 -27
- autogen/interop/crewai/crewai.py +2 -2
- autogen/interop/interoperable.py +2 -2
- autogen/interop/langchain/langchain_chat_model_factory.py +3 -2
- autogen/interop/langchain/langchain_tool.py +2 -6
- autogen/interop/litellm/litellm_config_factory.py +6 -7
- autogen/interop/pydantic_ai/pydantic_ai.py +4 -7
- autogen/interop/registry.py +2 -1
- autogen/io/base.py +5 -5
- autogen/io/run_response.py +33 -32
- autogen/io/websockets.py +6 -5
- autogen/json_utils.py +1 -2
- autogen/llm_config/__init__.py +11 -0
- autogen/llm_config/client.py +58 -0
- autogen/llm_config/config.py +384 -0
- autogen/llm_config/entry.py +154 -0
- autogen/logger/base_logger.py +4 -3
- autogen/logger/file_logger.py +2 -1
- autogen/logger/logger_factory.py +2 -2
- autogen/logger/logger_utils.py +2 -2
- autogen/logger/sqlite_logger.py +2 -1
- autogen/math_utils.py +4 -5
- autogen/mcp/__main__.py +6 -6
- autogen/mcp/helpers.py +4 -4
- autogen/mcp/mcp_client.py +170 -29
- autogen/mcp/mcp_proxy/fastapi_code_generator_helpers.py +3 -4
- autogen/mcp/mcp_proxy/mcp_proxy.py +23 -26
- autogen/mcp/mcp_proxy/operation_grouping.py +4 -5
- autogen/mcp/mcp_proxy/operation_renaming.py +6 -10
- autogen/mcp/mcp_proxy/security.py +2 -3
- autogen/messages/agent_messages.py +96 -98
- autogen/messages/base_message.py +6 -5
- autogen/messages/client_messages.py +15 -14
- autogen/messages/print_message.py +4 -5
- autogen/oai/__init__.py +1 -2
- autogen/oai/anthropic.py +42 -41
- autogen/oai/bedrock.py +68 -57
- autogen/oai/cerebras.py +26 -25
- autogen/oai/client.py +113 -139
- autogen/oai/client_utils.py +3 -3
- autogen/oai/cohere.py +34 -11
- autogen/oai/gemini.py +39 -17
- autogen/oai/gemini_types.py +11 -12
- autogen/oai/groq.py +22 -10
- autogen/oai/mistral.py +17 -11
- autogen/oai/oai_models/__init__.py +14 -2
- autogen/oai/oai_models/_models.py +2 -2
- autogen/oai/oai_models/chat_completion.py +13 -14
- autogen/oai/oai_models/chat_completion_message.py +11 -9
- autogen/oai/oai_models/chat_completion_message_tool_call.py +26 -3
- autogen/oai/oai_models/chat_completion_token_logprob.py +3 -4
- autogen/oai/oai_models/completion_usage.py +8 -9
- autogen/oai/ollama.py +19 -9
- autogen/oai/openai_responses.py +40 -17
- autogen/oai/openai_utils.py +48 -38
- autogen/oai/together.py +29 -14
- autogen/retrieve_utils.py +6 -7
- autogen/runtime_logging.py +5 -4
- autogen/token_count_utils.py +7 -4
- autogen/tools/contrib/time/time.py +0 -1
- autogen/tools/dependency_injection.py +5 -6
- autogen/tools/experimental/browser_use/browser_use.py +10 -10
- autogen/tools/experimental/code_execution/python_code_execution.py +5 -7
- autogen/tools/experimental/crawl4ai/crawl4ai.py +12 -15
- autogen/tools/experimental/deep_research/deep_research.py +9 -8
- autogen/tools/experimental/duckduckgo/duckduckgo_search.py +5 -11
- autogen/tools/experimental/firecrawl/firecrawl_tool.py +98 -115
- autogen/tools/experimental/google/authentication/credentials_local_provider.py +1 -1
- autogen/tools/experimental/google/drive/drive_functions.py +4 -4
- autogen/tools/experimental/google/drive/toolkit.py +5 -5
- autogen/tools/experimental/google_search/google_search.py +5 -5
- autogen/tools/experimental/google_search/youtube_search.py +5 -5
- autogen/tools/experimental/messageplatform/discord/discord.py +8 -12
- autogen/tools/experimental/messageplatform/slack/slack.py +14 -20
- autogen/tools/experimental/messageplatform/telegram/telegram.py +8 -12
- autogen/tools/experimental/perplexity/perplexity_search.py +18 -29
- autogen/tools/experimental/reliable/reliable.py +68 -74
- autogen/tools/experimental/searxng/searxng_search.py +20 -19
- autogen/tools/experimental/tavily/tavily_search.py +12 -19
- autogen/tools/experimental/web_search_preview/web_search_preview.py +13 -7
- autogen/tools/experimental/wikipedia/wikipedia.py +7 -10
- autogen/tools/function_utils.py +7 -7
- autogen/tools/tool.py +8 -6
- autogen/types.py +2 -2
- autogen/version.py +1 -1
- ag2-0.9.7.dist-info/RECORD +0 -421
- autogen/llm_config.py +0 -385
- {ag2-0.9.7.dist-info → ag2-0.9.9.dist-info}/WHEEL +0 -0
- {ag2-0.9.7.dist-info → ag2-0.9.9.dist-info}/licenses/LICENSE +0 -0
- {ag2-0.9.7.dist-info → ag2-0.9.9.dist-info}/licenses/NOTICE.md +0 -0
|
@@ -25,7 +25,7 @@ class GoogleCredentialsLocalProvider(GoogleCredentialsProvider):
|
|
|
25
25
|
self,
|
|
26
26
|
client_secret_file: str,
|
|
27
27
|
scopes: list[str], # e.g. ['https://www.googleapis.com/auth/drive/readonly']
|
|
28
|
-
token_file:
|
|
28
|
+
token_file: str | None = None,
|
|
29
29
|
port: int = 8080,
|
|
30
30
|
) -> None:
|
|
31
31
|
"""A Google credentials provider that gets the credentials locally.
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
import io
|
|
6
6
|
from pathlib import Path
|
|
7
|
-
from typing import Any
|
|
7
|
+
from typing import Any
|
|
8
8
|
|
|
9
9
|
from .....import_utils import optional_import_block, require_optional_import
|
|
10
10
|
from ..model import GoogleFileInfo
|
|
@@ -25,7 +25,7 @@ __all__ = [
|
|
|
25
25
|
],
|
|
26
26
|
"google-api",
|
|
27
27
|
)
|
|
28
|
-
def list_files_and_folders(service: Any, page_size: int, folder_id:
|
|
28
|
+
def list_files_and_folders(service: Any, page_size: int, folder_id: str | None) -> list[GoogleFileInfo]:
|
|
29
29
|
kwargs = {
|
|
30
30
|
"pageSize": page_size,
|
|
31
31
|
"fields": "nextPageToken, files(id, name, mimeType)",
|
|
@@ -40,7 +40,7 @@ def list_files_and_folders(service: Any, page_size: int, folder_id: Optional[str
|
|
|
40
40
|
return result
|
|
41
41
|
|
|
42
42
|
|
|
43
|
-
def _get_file_extension(mime_type: str) ->
|
|
43
|
+
def _get_file_extension(mime_type: str) -> str | None:
|
|
44
44
|
"""Returns the correct file extension for a given MIME type."""
|
|
45
45
|
mime_extensions = {
|
|
46
46
|
"application/vnd.google-apps.document": "docx", # Google Docs → Word
|
|
@@ -70,7 +70,7 @@ def download_file(
|
|
|
70
70
|
file_name: str,
|
|
71
71
|
mime_type: str,
|
|
72
72
|
download_folder: Path,
|
|
73
|
-
subfolder_path:
|
|
73
|
+
subfolder_path: str | None = None,
|
|
74
74
|
) -> str:
|
|
75
75
|
"""Download or export file based on its MIME type, optionally saving to a subfolder."""
|
|
76
76
|
file_extension = _get_file_extension(mime_type)
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
# SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
|
|
5
5
|
from pathlib import Path
|
|
6
|
-
from typing import Annotated, Literal
|
|
6
|
+
from typing import Annotated, Literal
|
|
7
7
|
|
|
8
8
|
from .....doc_utils import export_module
|
|
9
9
|
from .....import_utils import optional_import_block
|
|
@@ -29,8 +29,8 @@ class GoogleDriveToolkit(Toolkit, GoogleToolkitProtocol):
|
|
|
29
29
|
self,
|
|
30
30
|
*,
|
|
31
31
|
credentials: "Credentials",
|
|
32
|
-
download_folder:
|
|
33
|
-
exclude:
|
|
32
|
+
download_folder: Path | str,
|
|
33
|
+
exclude: list[Literal["list_drive_files_and_folders", "download_file_from_drive"]] | None = None,
|
|
34
34
|
api_version: str = "v3",
|
|
35
35
|
) -> None:
|
|
36
36
|
"""Initialize the Google Drive tool map.
|
|
@@ -51,7 +51,7 @@ class GoogleDriveToolkit(Toolkit, GoogleToolkitProtocol):
|
|
|
51
51
|
def list_drive_files_and_folders(
|
|
52
52
|
page_size: Annotated[int, "The number of files to list per page."] = 10,
|
|
53
53
|
folder_id: Annotated[
|
|
54
|
-
|
|
54
|
+
str | None,
|
|
55
55
|
"The ID of the folder to list files from. If not provided, lists all files in the root folder.",
|
|
56
56
|
] = None,
|
|
57
57
|
) -> list[GoogleFileInfo]:
|
|
@@ -61,7 +61,7 @@ class GoogleDriveToolkit(Toolkit, GoogleToolkitProtocol):
|
|
|
61
61
|
def download_file_from_drive(
|
|
62
62
|
file_info: Annotated[GoogleFileInfo, "The file info to download."],
|
|
63
63
|
subfolder_path: Annotated[
|
|
64
|
-
|
|
64
|
+
str | None,
|
|
65
65
|
"The subfolder path to save the file in. If not provided, saves in the main download folder.",
|
|
66
66
|
] = None,
|
|
67
67
|
) -> str:
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
import logging
|
|
7
|
-
from typing import Annotated, Any
|
|
7
|
+
from typing import Annotated, Any
|
|
8
8
|
|
|
9
9
|
from ....doc_utils import export_module
|
|
10
10
|
from ....import_utils import optional_import_block, require_optional_import
|
|
@@ -49,8 +49,8 @@ class GoogleSearchTool(Tool):
|
|
|
49
49
|
def __init__(
|
|
50
50
|
self,
|
|
51
51
|
*,
|
|
52
|
-
search_api_key:
|
|
53
|
-
search_engine_id:
|
|
52
|
+
search_api_key: str | None = None,
|
|
53
|
+
search_engine_id: str | None = None,
|
|
54
54
|
use_internal_llm_tool_if_available: bool = True,
|
|
55
55
|
):
|
|
56
56
|
"""GoogleSearchTool is a tool that uses the Google Search API to perform a search.
|
|
@@ -74,8 +74,8 @@ class GoogleSearchTool(Tool):
|
|
|
74
74
|
|
|
75
75
|
def google_search(
|
|
76
76
|
query: Annotated[str, "The search query."],
|
|
77
|
-
search_api_key: Annotated[
|
|
78
|
-
search_engine_id: Annotated[
|
|
77
|
+
search_api_key: Annotated[str | None, Depends(on(search_api_key))],
|
|
78
|
+
search_engine_id: Annotated[str | None, Depends(on(search_engine_id))],
|
|
79
79
|
num_results: Annotated[int, "The number of results to return."] = 10,
|
|
80
80
|
) -> list[dict[str, Any]]:
|
|
81
81
|
if search_api_key is None or search_engine_id is None:
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
import logging
|
|
7
|
-
from typing import Annotated, Any
|
|
7
|
+
from typing import Annotated, Any
|
|
8
8
|
|
|
9
9
|
from ....doc_utils import export_module
|
|
10
10
|
from ....import_utils import optional_import_block, require_optional_import
|
|
@@ -48,7 +48,7 @@ def _execute_search_query(query: str, youtube_api_key: str, max_results: int) ->
|
|
|
48
48
|
["googleapiclient"],
|
|
49
49
|
"google-search",
|
|
50
50
|
)
|
|
51
|
-
def _get_video_details(video_ids:
|
|
51
|
+
def _get_video_details(video_ids: list[str], youtube_api_key: str) -> Any:
|
|
52
52
|
"""Get detailed information about specific YouTube videos.
|
|
53
53
|
|
|
54
54
|
Args:
|
|
@@ -79,7 +79,7 @@ def _youtube_search(
|
|
|
79
79
|
youtube_api_key: str,
|
|
80
80
|
max_results: int,
|
|
81
81
|
include_video_details: bool = True,
|
|
82
|
-
) ->
|
|
82
|
+
) -> list[dict[str, Any]]:
|
|
83
83
|
"""Search YouTube videos based on a query.
|
|
84
84
|
|
|
85
85
|
Args:
|
|
@@ -140,7 +140,7 @@ class YoutubeSearchTool(Tool):
|
|
|
140
140
|
def __init__(
|
|
141
141
|
self,
|
|
142
142
|
*,
|
|
143
|
-
youtube_api_key:
|
|
143
|
+
youtube_api_key: str | None = None,
|
|
144
144
|
):
|
|
145
145
|
"""Initialize a YouTube search tool.
|
|
146
146
|
|
|
@@ -157,7 +157,7 @@ class YoutubeSearchTool(Tool):
|
|
|
157
157
|
youtube_api_key: Annotated[str, Depends(on(youtube_api_key))],
|
|
158
158
|
max_results: Annotated[int, "The maximum number of results to return."] = 5,
|
|
159
159
|
include_video_details: Annotated[bool, "Whether to include detailed video information."] = True,
|
|
160
|
-
) ->
|
|
160
|
+
) -> list[dict[str, Any]]:
|
|
161
161
|
"""Search for YouTube videos based on a query.
|
|
162
162
|
|
|
163
163
|
Args:
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
import asyncio
|
|
6
6
|
from datetime import datetime, timezone
|
|
7
|
-
from typing import Annotated, Any
|
|
7
|
+
from typing import Annotated, Any
|
|
8
8
|
|
|
9
9
|
from .....doc_utils import export_module
|
|
10
10
|
from .....import_utils import optional_import_block, require_optional_import
|
|
@@ -26,8 +26,7 @@ class DiscordSendTool(Tool):
|
|
|
26
26
|
"""Sends a message to a Discord channel."""
|
|
27
27
|
|
|
28
28
|
def __init__(self, *, bot_token: str, channel_name: str, guild_name: str) -> None:
|
|
29
|
-
"""
|
|
30
|
-
Initialize the DiscordSendTool.
|
|
29
|
+
"""Initialize the DiscordSendTool.
|
|
31
30
|
|
|
32
31
|
Args:
|
|
33
32
|
bot_token: The bot token to use for sending messages.
|
|
@@ -42,8 +41,7 @@ class DiscordSendTool(Tool):
|
|
|
42
41
|
guild_name: Annotated[str, Depends(on(guild_name))],
|
|
43
42
|
channel_name: Annotated[str, Depends(on(channel_name))],
|
|
44
43
|
) -> Any:
|
|
45
|
-
"""
|
|
46
|
-
Sends a message to a Discord channel.
|
|
44
|
+
"""Sends a message to a Discord channel.
|
|
47
45
|
|
|
48
46
|
Args:
|
|
49
47
|
message: The message to send to the channel.
|
|
@@ -123,8 +121,7 @@ class DiscordRetrieveTool(Tool):
|
|
|
123
121
|
"""Retrieves messages from a Discord channel."""
|
|
124
122
|
|
|
125
123
|
def __init__(self, *, bot_token: str, channel_name: str, guild_name: str) -> None:
|
|
126
|
-
"""
|
|
127
|
-
Initialize the DiscordRetrieveTool.
|
|
124
|
+
"""Initialize the DiscordRetrieveTool.
|
|
128
125
|
|
|
129
126
|
Args:
|
|
130
127
|
bot_token: The bot token to use for retrieving messages.
|
|
@@ -137,15 +134,14 @@ class DiscordRetrieveTool(Tool):
|
|
|
137
134
|
guild_name: Annotated[str, Depends(on(guild_name))],
|
|
138
135
|
channel_name: Annotated[str, Depends(on(channel_name))],
|
|
139
136
|
messages_since: Annotated[
|
|
140
|
-
|
|
137
|
+
str | None,
|
|
141
138
|
"Date to retrieve messages from (ISO format) OR Discord snowflake ID. If None, retrieves latest messages.",
|
|
142
139
|
] = None,
|
|
143
140
|
maximum_messages: Annotated[
|
|
144
|
-
|
|
141
|
+
int | None, "Maximum number of messages to retrieve. If None, retrieves all messages since date."
|
|
145
142
|
] = None,
|
|
146
143
|
) -> Any:
|
|
147
|
-
"""
|
|
148
|
-
Retrieves messages from a Discord channel.
|
|
144
|
+
"""Retrieves messages from a Discord channel.
|
|
149
145
|
|
|
150
146
|
Args:
|
|
151
147
|
bot_token: The bot token to use for Discord. (uses dependency injection)
|
|
@@ -162,7 +158,7 @@ class DiscordRetrieveTool(Tool):
|
|
|
162
158
|
client = Client(intents=intents)
|
|
163
159
|
result_future: asyncio.Future[list[dict[str, Any]]] = asyncio.Future()
|
|
164
160
|
|
|
165
|
-
messages_since_date:
|
|
161
|
+
messages_since_date: str | None = None
|
|
166
162
|
if messages_since is not None:
|
|
167
163
|
if DiscordRetrieveTool._is_snowflake(messages_since):
|
|
168
164
|
messages_since_date = DiscordRetrieveTool._snowflake_to_iso(messages_since)
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
import asyncio
|
|
6
6
|
from datetime import datetime, timedelta
|
|
7
|
-
from typing import Annotated, Any
|
|
7
|
+
from typing import Annotated, Any
|
|
8
8
|
|
|
9
9
|
from .....doc_utils import export_module
|
|
10
10
|
from .....import_utils import optional_import_block, require_optional_import
|
|
@@ -26,8 +26,7 @@ class SlackSendTool(Tool):
|
|
|
26
26
|
"""Sends a message to a Slack channel."""
|
|
27
27
|
|
|
28
28
|
def __init__(self, *, bot_token: str, channel_id: str) -> None:
|
|
29
|
-
"""
|
|
30
|
-
Initialize the SlackSendTool.
|
|
29
|
+
"""Initialize the SlackSendTool.
|
|
31
30
|
|
|
32
31
|
Args:
|
|
33
32
|
bot_token: Bot User OAuth Token starting with "xoxb-".
|
|
@@ -40,8 +39,7 @@ class SlackSendTool(Tool):
|
|
|
40
39
|
bot_token: Annotated[str, Depends(on(bot_token))],
|
|
41
40
|
channel_id: Annotated[str, Depends(on(channel_id))],
|
|
42
41
|
) -> Any:
|
|
43
|
-
"""
|
|
44
|
-
Sends a message to a Slack channel.
|
|
42
|
+
"""Sends a message to a Slack channel.
|
|
45
43
|
|
|
46
44
|
Args:
|
|
47
45
|
message: The message to send to the channel.
|
|
@@ -93,8 +91,7 @@ class SlackRetrieveTool(Tool):
|
|
|
93
91
|
"""Retrieves messages from a Slack channel."""
|
|
94
92
|
|
|
95
93
|
def __init__(self, *, bot_token: str, channel_id: str) -> None:
|
|
96
|
-
"""
|
|
97
|
-
Initialize the SlackRetrieveTool.
|
|
94
|
+
"""Initialize the SlackRetrieveTool.
|
|
98
95
|
|
|
99
96
|
Args:
|
|
100
97
|
bot_token: Bot User OAuth Token starting with "xoxb-".
|
|
@@ -105,15 +102,14 @@ class SlackRetrieveTool(Tool):
|
|
|
105
102
|
bot_token: Annotated[str, Depends(on(bot_token))],
|
|
106
103
|
channel_id: Annotated[str, Depends(on(channel_id))],
|
|
107
104
|
messages_since: Annotated[
|
|
108
|
-
|
|
105
|
+
str | None,
|
|
109
106
|
"Date to retrieve messages from (ISO format) OR Slack message ID. If None, retrieves latest messages.",
|
|
110
107
|
] = None,
|
|
111
108
|
maximum_messages: Annotated[
|
|
112
|
-
|
|
109
|
+
int | None, "Maximum number of messages to retrieve. If None, retrieves all messages since date."
|
|
113
110
|
] = None,
|
|
114
111
|
) -> Any:
|
|
115
|
-
"""
|
|
116
|
-
Retrieves messages from a Discord channel.
|
|
112
|
+
"""Retrieves messages from a Discord channel.
|
|
117
113
|
|
|
118
114
|
Args:
|
|
119
115
|
bot_token: The bot token to use for Discord. (uses dependency injection)
|
|
@@ -198,8 +194,7 @@ class SlackRetrieveRepliesTool(Tool):
|
|
|
198
194
|
"""Retrieves replies to a specific Slack message from both threads and the channel."""
|
|
199
195
|
|
|
200
196
|
def __init__(self, *, bot_token: str, channel_id: str) -> None:
|
|
201
|
-
"""
|
|
202
|
-
Initialize the SlackRetrieveRepliesTool.
|
|
197
|
+
"""Initialize the SlackRetrieveRepliesTool.
|
|
203
198
|
|
|
204
199
|
Args:
|
|
205
200
|
bot_token: Bot User OAuth Token starting with "xoxb-".
|
|
@@ -211,7 +206,7 @@ class SlackRetrieveRepliesTool(Tool):
|
|
|
211
206
|
bot_token: Annotated[str, Depends(on(bot_token))],
|
|
212
207
|
channel_id: Annotated[str, Depends(on(channel_id))],
|
|
213
208
|
min_replies: Annotated[
|
|
214
|
-
|
|
209
|
+
int | None,
|
|
215
210
|
"Minimum number of replies to wait for before returning (thread + channel). If None, returns immediately.",
|
|
216
211
|
] = None,
|
|
217
212
|
timeout_seconds: Annotated[
|
|
@@ -222,8 +217,7 @@ class SlackRetrieveRepliesTool(Tool):
|
|
|
222
217
|
bool, "Whether to include messages in the channel after the original message."
|
|
223
218
|
] = True,
|
|
224
219
|
) -> Any:
|
|
225
|
-
"""
|
|
226
|
-
Retrieves replies to a specific Slack message, from both threads and the main channel.
|
|
220
|
+
"""Retrieves replies to a specific Slack message, from both threads and the main channel.
|
|
227
221
|
|
|
228
222
|
Args:
|
|
229
223
|
message_ts: The timestamp (ts) identifier of the parent message.
|
|
@@ -238,7 +232,7 @@ class SlackRetrieveRepliesTool(Tool):
|
|
|
238
232
|
web_client = WebClient(token=bot_token)
|
|
239
233
|
|
|
240
234
|
# Function to get current thread replies
|
|
241
|
-
async def get_thread_replies() -> tuple[
|
|
235
|
+
async def get_thread_replies() -> tuple[list[dict[str, Any]] | None, str | None]:
|
|
242
236
|
try:
|
|
243
237
|
response = web_client.conversations_replies(
|
|
244
238
|
channel=channel_id,
|
|
@@ -258,7 +252,7 @@ class SlackRetrieveRepliesTool(Tool):
|
|
|
258
252
|
return None, f"Thread reply retrieval failed, exception: {e}"
|
|
259
253
|
|
|
260
254
|
# Function to get messages in the channel after the original message
|
|
261
|
-
async def get_channel_messages() ->
|
|
255
|
+
async def get_channel_messages() -> tuple[list[dict[str, Any]] | None, str | None]:
|
|
262
256
|
try:
|
|
263
257
|
response = web_client.conversations_history(
|
|
264
258
|
channel=channel_id,
|
|
@@ -286,8 +280,8 @@ class SlackRetrieveRepliesTool(Tool):
|
|
|
286
280
|
return None, f"Channel message retrieval failed, exception: {e}"
|
|
287
281
|
|
|
288
282
|
# Function to get all replies (both thread and channel)
|
|
289
|
-
async def get_all_replies() ->
|
|
290
|
-
|
|
283
|
+
async def get_all_replies() -> tuple[
|
|
284
|
+
list[dict[str, Any]] | None, list[dict[str, Any]] | None, str | None
|
|
291
285
|
]:
|
|
292
286
|
thread_replies, thread_error = await get_thread_replies()
|
|
293
287
|
if thread_error:
|
|
@@ -92,8 +92,7 @@ class TelegramSendTool(BaseTelegramTool, Tool):
|
|
|
92
92
|
"""Sends a message to a Telegram channel, group, or user."""
|
|
93
93
|
|
|
94
94
|
def __init__(self, *, api_id: str, api_hash: str, chat_id: str) -> None:
|
|
95
|
-
"""
|
|
96
|
-
Initialize the TelegramSendTool.
|
|
95
|
+
"""Initialize the TelegramSendTool.
|
|
97
96
|
|
|
98
97
|
Args:
|
|
99
98
|
api_id: Telegram API ID from https://my.telegram.org/apps.
|
|
@@ -106,8 +105,7 @@ class TelegramSendTool(BaseTelegramTool, Tool):
|
|
|
106
105
|
message: Annotated[str, "Message to send to the chat."],
|
|
107
106
|
chat_id: Annotated[str, Depends(on(chat_id))],
|
|
108
107
|
) -> Any:
|
|
109
|
-
"""
|
|
110
|
-
Sends a message to a Telegram chat.
|
|
108
|
+
"""Sends a message to a Telegram chat.
|
|
111
109
|
|
|
112
110
|
Args:
|
|
113
111
|
message: The message to send.
|
|
@@ -124,7 +122,7 @@ class TelegramSendTool(BaseTelegramTool, Tool):
|
|
|
124
122
|
message[i : i + (MAX_MESSAGE_LENGTH - 1)]
|
|
125
123
|
for i in range(0, len(message), (MAX_MESSAGE_LENGTH - 1))
|
|
126
124
|
]
|
|
127
|
-
first_message:
|
|
125
|
+
first_message: Message | None = None # type: ignore[no-any-unimported]
|
|
128
126
|
|
|
129
127
|
for i, chunk in enumerate(chunks):
|
|
130
128
|
sent = await client.send_message(
|
|
@@ -163,8 +161,7 @@ class TelegramRetrieveTool(BaseTelegramTool, Tool):
|
|
|
163
161
|
"""Retrieves messages from a Telegram channel."""
|
|
164
162
|
|
|
165
163
|
def __init__(self, *, api_id: str, api_hash: str, chat_id: str) -> None:
|
|
166
|
-
"""
|
|
167
|
-
Initialize the TelegramRetrieveTool.
|
|
164
|
+
"""Initialize the TelegramRetrieveTool.
|
|
168
165
|
|
|
169
166
|
Args:
|
|
170
167
|
api_id: Telegram API ID from https://my.telegram.org/apps.
|
|
@@ -177,16 +174,15 @@ class TelegramRetrieveTool(BaseTelegramTool, Tool):
|
|
|
177
174
|
async def telegram_retrieve_messages(
|
|
178
175
|
chat_id: Annotated[str, Depends(on(chat_id))],
|
|
179
176
|
messages_since: Annotated[
|
|
180
|
-
|
|
177
|
+
str | None,
|
|
181
178
|
"Date to retrieve messages from (ISO format) OR message ID. If None, retrieves latest messages.",
|
|
182
179
|
] = None,
|
|
183
180
|
maximum_messages: Annotated[
|
|
184
|
-
|
|
181
|
+
int | None, "Maximum number of messages to retrieve. If None, retrieves all messages since date."
|
|
185
182
|
] = None,
|
|
186
|
-
search: Annotated[
|
|
183
|
+
search: Annotated[str | None, "Optional string to search for in messages."] = None,
|
|
187
184
|
) -> Any:
|
|
188
|
-
"""
|
|
189
|
-
Retrieves messages from a Telegram chat.
|
|
185
|
+
"""Retrieves messages from a Telegram chat.
|
|
190
186
|
|
|
191
187
|
Args:
|
|
192
188
|
chat_id: The ID of the chat. (uses dependency injection)
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
"""
|
|
2
|
-
Module: perplexity_search_tool
|
|
1
|
+
"""Module: perplexity_search_tool
|
|
3
2
|
Copyright (c) 2023 - 2025, AG2ai, Inc., AG2ai open-source projects maintainers and core contributors
|
|
4
3
|
SPDX-License-Identifier: Apache-2.0
|
|
5
4
|
|
|
@@ -9,7 +8,7 @@ It defines data models for responses and a tool for executing web and conversati
|
|
|
9
8
|
|
|
10
9
|
import json
|
|
11
10
|
import os
|
|
12
|
-
from typing import Any
|
|
11
|
+
from typing import Any
|
|
13
12
|
|
|
14
13
|
import requests
|
|
15
14
|
from pydantic import BaseModel, ValidationError
|
|
@@ -18,8 +17,7 @@ from autogen.tools import Tool
|
|
|
18
17
|
|
|
19
18
|
|
|
20
19
|
class Message(BaseModel):
|
|
21
|
-
"""
|
|
22
|
-
Represents a message in the chat conversation.
|
|
20
|
+
"""Represents a message in the chat conversation.
|
|
23
21
|
|
|
24
22
|
Attributes:
|
|
25
23
|
role (str): The role of the message sender (e.g., "system", "user").
|
|
@@ -31,8 +29,7 @@ class Message(BaseModel):
|
|
|
31
29
|
|
|
32
30
|
|
|
33
31
|
class Usage(BaseModel):
|
|
34
|
-
"""
|
|
35
|
-
Model representing token usage details.
|
|
32
|
+
"""Model representing token usage details.
|
|
36
33
|
|
|
37
34
|
Attributes:
|
|
38
35
|
prompt_tokens (int): The number of tokens used for the prompt.
|
|
@@ -48,8 +45,7 @@ class Usage(BaseModel):
|
|
|
48
45
|
|
|
49
46
|
|
|
50
47
|
class Choice(BaseModel):
|
|
51
|
-
"""
|
|
52
|
-
Represents one choice in the response from the Perplexity API.
|
|
48
|
+
"""Represents one choice in the response from the Perplexity API.
|
|
53
49
|
|
|
54
50
|
Attributes:
|
|
55
51
|
index (int): The index of this choice.
|
|
@@ -63,8 +59,7 @@ class Choice(BaseModel):
|
|
|
63
59
|
|
|
64
60
|
|
|
65
61
|
class PerplexityChatCompletionResponse(BaseModel):
|
|
66
|
-
"""
|
|
67
|
-
Represents the full chat completion response from the Perplexity API.
|
|
62
|
+
"""Represents the full chat completion response from the Perplexity API.
|
|
68
63
|
|
|
69
64
|
Attributes:
|
|
70
65
|
id (str): Unique identifier for the response.
|
|
@@ -86,8 +81,7 @@ class PerplexityChatCompletionResponse(BaseModel):
|
|
|
86
81
|
|
|
87
82
|
|
|
88
83
|
class SearchResponse(BaseModel):
|
|
89
|
-
"""
|
|
90
|
-
Represents the response from a search query.
|
|
84
|
+
"""Represents the response from a search query.
|
|
91
85
|
|
|
92
86
|
Attributes:
|
|
93
87
|
content (Optional[str]): The textual content returned from the search.
|
|
@@ -95,14 +89,13 @@ class SearchResponse(BaseModel):
|
|
|
95
89
|
error (Optional[str]): An error message if the search failed.
|
|
96
90
|
"""
|
|
97
91
|
|
|
98
|
-
content:
|
|
99
|
-
citations:
|
|
100
|
-
error:
|
|
92
|
+
content: str | None
|
|
93
|
+
citations: list[str] | None
|
|
94
|
+
error: str | None
|
|
101
95
|
|
|
102
96
|
|
|
103
97
|
class PerplexitySearchTool(Tool):
|
|
104
|
-
"""
|
|
105
|
-
Tool for interacting with the Perplexity AI search API.
|
|
98
|
+
"""Tool for interacting with the Perplexity AI search API.
|
|
106
99
|
|
|
107
100
|
This tool uses the Perplexity API to perform web search, news search,
|
|
108
101
|
and conversational search, returning concise and precise responses.
|
|
@@ -118,12 +111,11 @@ class PerplexitySearchTool(Tool):
|
|
|
118
111
|
def __init__(
|
|
119
112
|
self,
|
|
120
113
|
model: str = "sonar",
|
|
121
|
-
api_key:
|
|
114
|
+
api_key: str | None = None,
|
|
122
115
|
max_tokens: int = 1000,
|
|
123
|
-
search_domain_filter:
|
|
116
|
+
search_domain_filter: list[str] | None = None,
|
|
124
117
|
):
|
|
125
|
-
"""
|
|
126
|
-
Initializes a new instance of the PerplexitySearchTool.
|
|
118
|
+
"""Initializes a new instance of the PerplexitySearchTool.
|
|
127
119
|
|
|
128
120
|
Args:
|
|
129
121
|
model (str, optional): The model to use. Defaults to "sonar".
|
|
@@ -150,10 +142,9 @@ class PerplexitySearchTool(Tool):
|
|
|
150
142
|
|
|
151
143
|
@staticmethod
|
|
152
144
|
def _validate_tool_config(
|
|
153
|
-
model: str, api_key:
|
|
145
|
+
model: str, api_key: str | None, max_tokens: int, search_domain_filter: list[str] | None
|
|
154
146
|
) -> None:
|
|
155
|
-
"""
|
|
156
|
-
Validates the configuration parameters for the search tool.
|
|
147
|
+
"""Validates the configuration parameters for the search tool.
|
|
157
148
|
|
|
158
149
|
Args:
|
|
159
150
|
model (str): The model to use.
|
|
@@ -175,8 +166,7 @@ class PerplexitySearchTool(Tool):
|
|
|
175
166
|
raise ValueError("search_domain_filter must be a list")
|
|
176
167
|
|
|
177
168
|
def _execute_query(self, payload: dict[str, Any]) -> "PerplexityChatCompletionResponse":
|
|
178
|
-
"""
|
|
179
|
-
Executes a query by sending a POST request to the Perplexity API.
|
|
169
|
+
"""Executes a query by sending a POST request to the Perplexity API.
|
|
180
170
|
|
|
181
171
|
Args:
|
|
182
172
|
payload (dict[str, Any]): The payload to send in the API request.
|
|
@@ -223,8 +213,7 @@ class PerplexitySearchTool(Tool):
|
|
|
223
213
|
return perp_resp
|
|
224
214
|
|
|
225
215
|
def search(self, query: str) -> "SearchResponse":
|
|
226
|
-
"""
|
|
227
|
-
Perform a search query using the Perplexity AI API.
|
|
216
|
+
"""Perform a search query using the Perplexity AI API.
|
|
228
217
|
|
|
229
218
|
Constructs the payload, executes the query, and parses the response to return
|
|
230
219
|
a concise search result along with any provided citations.
|