ag2 0.9.6__py3-none-any.whl → 0.9.8.post1__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.6.dist-info → ag2-0.9.8.post1.dist-info}/METADATA +102 -75
- ag2-0.9.8.post1.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 +311 -295
- 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 +58 -61
- 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 +13 -13
- 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 +3 -2
- 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 +118 -138
- autogen/oai/client_utils.py +3 -3
- autogen/oai/cohere.py +34 -11
- autogen/oai/gemini.py +40 -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 +22 -10
- autogen/oai/openai_responses.py +40 -17
- autogen/oai/openai_utils.py +159 -85
- 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 +6 -5
- autogen/types.py +2 -2
- autogen/version.py +1 -1
- ag2-0.9.6.dist-info/RECORD +0 -421
- autogen/llm_config.py +0 -385
- {ag2-0.9.6.dist-info → ag2-0.9.8.post1.dist-info}/WHEEL +0 -0
- {ag2-0.9.6.dist-info → ag2-0.9.8.post1.dist-info}/licenses/LICENSE +0 -0
- {ag2-0.9.6.dist-info → ag2-0.9.8.post1.dist-info}/licenses/NOTICE.md +0 -0
autogen/retrieve_utils.py
CHANGED
|
@@ -9,7 +9,8 @@ import hashlib
|
|
|
9
9
|
import logging
|
|
10
10
|
import os
|
|
11
11
|
import re
|
|
12
|
-
from
|
|
12
|
+
from collections.abc import Callable
|
|
13
|
+
from typing import Any
|
|
13
14
|
from urllib.parse import urlparse
|
|
14
15
|
|
|
15
16
|
import requests
|
|
@@ -158,11 +159,11 @@ def extract_text_from_pdf(file: str) -> str:
|
|
|
158
159
|
|
|
159
160
|
|
|
160
161
|
def split_files_to_chunks(
|
|
161
|
-
files: list[
|
|
162
|
+
files: list[tuple[str, str] | str],
|
|
162
163
|
max_tokens: int = 4000,
|
|
163
164
|
chunk_mode: str = "multi_lines",
|
|
164
165
|
must_break_at_empty_line: bool = True,
|
|
165
|
-
custom_text_split_function:
|
|
166
|
+
custom_text_split_function: Callable[[str], list[str]] | None = None,
|
|
166
167
|
) -> tuple[list[str], list[dict[str, Any]]]:
|
|
167
168
|
"""Split a list of files into chunks of max_tokens."""
|
|
168
169
|
chunks = []
|
|
@@ -200,9 +201,7 @@ def split_files_to_chunks(
|
|
|
200
201
|
return chunks, sources
|
|
201
202
|
|
|
202
203
|
|
|
203
|
-
def get_files_from_dir(
|
|
204
|
-
dir_path: Union[str, list[str]], types: list[str] = TEXT_FORMATS, recursive: bool = True
|
|
205
|
-
) -> list[Any]:
|
|
204
|
+
def get_files_from_dir(dir_path: str | list[str], types: list[str] = TEXT_FORMATS, recursive: bool = True) -> list[Any]:
|
|
206
205
|
"""Return a list of all the files in a given directory, a url, a file path or a list of them."""
|
|
207
206
|
if len(types) == 0:
|
|
208
207
|
raise ValueError("types cannot be empty.")
|
|
@@ -343,7 +342,7 @@ def is_url(string: str):
|
|
|
343
342
|
|
|
344
343
|
@require_optional_import("chromadb", "retrievechat")
|
|
345
344
|
def create_vector_db_from_dir(
|
|
346
|
-
dir_path:
|
|
345
|
+
dir_path: str | list[str],
|
|
347
346
|
max_tokens: int = 4000,
|
|
348
347
|
client: "API" = None,
|
|
349
348
|
db_path: str = "tmp/chromadb.db",
|
autogen/runtime_logging.py
CHANGED
|
@@ -9,7 +9,8 @@ from __future__ import annotations
|
|
|
9
9
|
import logging
|
|
10
10
|
import sqlite3
|
|
11
11
|
import uuid
|
|
12
|
-
from
|
|
12
|
+
from collections.abc import Callable
|
|
13
|
+
from typing import TYPE_CHECKING, Any, Literal, TypeVar
|
|
13
14
|
|
|
14
15
|
from .logger.base_logger import BaseLogger, LLMConfig
|
|
15
16
|
from .logger.logger_factory import LoggerFactory
|
|
@@ -38,9 +39,9 @@ F = TypeVar("F", bound=Callable[..., Any])
|
|
|
38
39
|
|
|
39
40
|
|
|
40
41
|
def start(
|
|
41
|
-
logger:
|
|
42
|
+
logger: BaseLogger | None = None,
|
|
42
43
|
logger_type: Literal["sqlite", "file"] = "sqlite",
|
|
43
|
-
config:
|
|
44
|
+
config: dict[str, Any] | None = None,
|
|
44
45
|
) -> str:
|
|
45
46
|
"""Start logging for the runtime.
|
|
46
47
|
|
|
@@ -71,7 +72,7 @@ def log_chat_completion(
|
|
|
71
72
|
wrapper_id: int,
|
|
72
73
|
agent: str | Agent,
|
|
73
74
|
request: dict[str, float | str | list[dict[str, str]]],
|
|
74
|
-
response: str |
|
|
75
|
+
response: str | ChatCompletion,
|
|
75
76
|
is_cached: int,
|
|
76
77
|
cost: float,
|
|
77
78
|
start_time: str,
|
autogen/token_count_utils.py
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
import json
|
|
9
9
|
import logging
|
|
10
10
|
import re
|
|
11
|
-
from typing import Any
|
|
11
|
+
from typing import Any
|
|
12
12
|
|
|
13
13
|
import tiktoken
|
|
14
14
|
|
|
@@ -63,6 +63,9 @@ def get_max_token_limit(model: str = "gpt-3.5-turbo-0613") -> int:
|
|
|
63
63
|
"gpt-4o-2024-11-20": 128000,
|
|
64
64
|
"gpt-4o-mini": 128000,
|
|
65
65
|
"gpt-4o-mini-2024-07-18": 128000,
|
|
66
|
+
"gpt-5": 128000,
|
|
67
|
+
"gpt-5-mini": 128000,
|
|
68
|
+
"gpt-5-nano": 128000,
|
|
66
69
|
}
|
|
67
70
|
return max_token_limit[model]
|
|
68
71
|
|
|
@@ -71,7 +74,7 @@ def percentile_used(input, model="gpt-3.5-turbo-0613"):
|
|
|
71
74
|
return count_token(input) / get_max_token_limit(model)
|
|
72
75
|
|
|
73
76
|
|
|
74
|
-
def token_left(input:
|
|
77
|
+
def token_left(input: str | list[str] | dict[str, Any], model="gpt-3.5-turbo-0613") -> int:
|
|
75
78
|
"""Count number of tokens left for an OpenAI model.
|
|
76
79
|
|
|
77
80
|
Args:
|
|
@@ -84,7 +87,7 @@ def token_left(input: Union[str, list[str], dict[str, Any]], model="gpt-3.5-turb
|
|
|
84
87
|
return get_max_token_limit(model) - count_token(input, model=model)
|
|
85
88
|
|
|
86
89
|
|
|
87
|
-
def count_token(input:
|
|
90
|
+
def count_token(input: str | list[str] | dict[str, Any], model: str = "gpt-3.5-turbo-0613") -> int:
|
|
88
91
|
"""Count number of tokens used by an OpenAI model.
|
|
89
92
|
|
|
90
93
|
Args:
|
|
@@ -112,7 +115,7 @@ def _num_token_from_text(text: str, model: str = "gpt-3.5-turbo-0613"):
|
|
|
112
115
|
return len(encoding.encode(text))
|
|
113
116
|
|
|
114
117
|
|
|
115
|
-
def _num_token_from_messages(messages:
|
|
118
|
+
def _num_token_from_messages(messages: list[str] | dict[str, Any], model="gpt-3.5-turbo-0613"):
|
|
116
119
|
"""Return the number of tokens used by a list of messages.
|
|
117
120
|
|
|
118
121
|
retrieved from https://github.com/openai/openai-cookbook/blob/main/examples/How_to_count_tokens_with_tiktoken.ipynb/
|
|
@@ -6,8 +6,9 @@ import functools
|
|
|
6
6
|
import inspect
|
|
7
7
|
import sys
|
|
8
8
|
from abc import ABC
|
|
9
|
+
from collections.abc import Callable, Iterable
|
|
9
10
|
from functools import wraps
|
|
10
|
-
from typing import TYPE_CHECKING, Any,
|
|
11
|
+
from typing import TYPE_CHECKING, Any, TypeVar, get_type_hints
|
|
11
12
|
|
|
12
13
|
from ..agentchat import Agent
|
|
13
14
|
from ..doc_utils import export_module
|
|
@@ -67,7 +68,7 @@ class ChatContext(BaseContext):
|
|
|
67
68
|
return self._agent.chat_messages
|
|
68
69
|
|
|
69
70
|
@property
|
|
70
|
-
def last_message(self) ->
|
|
71
|
+
def last_message(self) -> dict[str, Any] | None:
|
|
71
72
|
"""The last message in the chat.
|
|
72
73
|
|
|
73
74
|
Returns:
|
|
@@ -102,7 +103,7 @@ def Depends(x: Any) -> Any: # noqa: N802
|
|
|
102
103
|
return FastDepends(x)
|
|
103
104
|
|
|
104
105
|
|
|
105
|
-
def get_context_params(func: Callable[..., Any], subclass:
|
|
106
|
+
def get_context_params(func: Callable[..., Any], subclass: type[BaseContext] | type[ChatContext]) -> list[str]:
|
|
106
107
|
"""Gets the names of the context parameters in a function signature.
|
|
107
108
|
|
|
108
109
|
Args:
|
|
@@ -116,9 +117,7 @@ def get_context_params(func: Callable[..., Any], subclass: Union[type[BaseContex
|
|
|
116
117
|
return [p.name for p in sig.parameters.values() if _is_context_param(p, subclass=subclass)]
|
|
117
118
|
|
|
118
119
|
|
|
119
|
-
def _is_context_param(
|
|
120
|
-
param: inspect.Parameter, subclass: Union[type[BaseContext], type[ChatContext]] = BaseContext
|
|
121
|
-
) -> bool:
|
|
120
|
+
def _is_context_param(param: inspect.Parameter, subclass: type[BaseContext] | type[ChatContext] = BaseContext) -> bool:
|
|
122
121
|
# param.annotation.__args__[0] is used to handle Annotated[MyContext, Depends(MyContext(b=2))]
|
|
123
122
|
param_annotation = param.annotation.__args__[0] if hasattr(param.annotation, "__args__") else param.annotation
|
|
124
123
|
try:
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
#
|
|
3
3
|
# SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
|
|
5
|
-
from typing import Annotated, Any, Optional
|
|
5
|
+
from typing import Annotated, Any, Optional
|
|
6
6
|
|
|
7
7
|
from pydantic import BaseModel, field_validator
|
|
8
8
|
|
|
@@ -32,11 +32,11 @@ class ExtractedContent(BaseModel):
|
|
|
32
32
|
"""
|
|
33
33
|
|
|
34
34
|
content: str
|
|
35
|
-
url:
|
|
35
|
+
url: str | None
|
|
36
36
|
|
|
37
37
|
@field_validator("url")
|
|
38
38
|
@classmethod
|
|
39
|
-
def check_url(cls, v: str) ->
|
|
39
|
+
def check_url(cls, v: str) -> str | None:
|
|
40
40
|
"""Check if the URL is about:blank and return None if it is.
|
|
41
41
|
|
|
42
42
|
Args:
|
|
@@ -57,7 +57,7 @@ class BrowserUseResult(BaseModel):
|
|
|
57
57
|
"""
|
|
58
58
|
|
|
59
59
|
extracted_content: list[ExtractedContent]
|
|
60
|
-
final_result:
|
|
60
|
+
final_result: str | None
|
|
61
61
|
|
|
62
62
|
|
|
63
63
|
@require_optional_import(
|
|
@@ -78,10 +78,10 @@ class BrowserUseTool(Tool):
|
|
|
78
78
|
def __init__( # type: ignore[no-any-unimported]
|
|
79
79
|
self,
|
|
80
80
|
*,
|
|
81
|
-
llm_config:
|
|
81
|
+
llm_config: LLMConfig | dict[str, Any] | None = None,
|
|
82
82
|
browser: Optional["Browser"] = None,
|
|
83
|
-
agent_kwargs:
|
|
84
|
-
browser_config:
|
|
83
|
+
agent_kwargs: dict[str, Any] | None = None,
|
|
84
|
+
browser_config: dict[str, Any] | None = None,
|
|
85
85
|
):
|
|
86
86
|
"""Use the browser to perform a task.
|
|
87
87
|
|
|
@@ -104,8 +104,8 @@ class BrowserUseTool(Tool):
|
|
|
104
104
|
|
|
105
105
|
async def browser_use( # type: ignore[no-any-unimported]
|
|
106
106
|
task: Annotated[str, "The task to perform."],
|
|
107
|
-
llm_config: Annotated[
|
|
108
|
-
browser: Annotated[
|
|
107
|
+
llm_config: Annotated[LLMConfig | dict[str, Any], Depends(on(llm_config))],
|
|
108
|
+
browser: Annotated[Browser | None, Depends(on(browser))],
|
|
109
109
|
agent_kwargs: Annotated[dict[str, Any], Depends(on(agent_kwargs))],
|
|
110
110
|
browser_config: Annotated[dict[str, Any], Depends(on(browser_config))],
|
|
111
111
|
) -> BrowserUseResult:
|
|
@@ -145,7 +145,7 @@ class BrowserUseTool(Tool):
|
|
|
145
145
|
)
|
|
146
146
|
|
|
147
147
|
@staticmethod
|
|
148
|
-
def _get_controller(llm_config:
|
|
148
|
+
def _get_controller(llm_config: LLMConfig | dict[str, Any]) -> Any:
|
|
149
149
|
response_format = (
|
|
150
150
|
llm_config["config_list"][0].get("response_format", None)
|
|
151
151
|
if "config_list" in llm_config
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
import os
|
|
6
6
|
import tempfile
|
|
7
|
-
from typing import Annotated, Any
|
|
7
|
+
from typing import Annotated, Any
|
|
8
8
|
|
|
9
9
|
from pydantic import BaseModel, Field
|
|
10
10
|
|
|
@@ -24,11 +24,10 @@ class PythonCodeExecutionTool(Tool):
|
|
|
24
24
|
self,
|
|
25
25
|
*,
|
|
26
26
|
timeout: int = 30,
|
|
27
|
-
working_directory:
|
|
28
|
-
python_environment:
|
|
27
|
+
working_directory: WorkingDirectory | None = None,
|
|
28
|
+
python_environment: PythonEnvironment | None = None,
|
|
29
29
|
) -> None:
|
|
30
|
-
"""
|
|
31
|
-
Initialize the PythonCodeExecutionTool.
|
|
30
|
+
"""Initialize the PythonCodeExecutionTool.
|
|
32
31
|
|
|
33
32
|
**CAUTION**: If provided a local environment, this tool will execute code in your local environment, which can be dangerous if the code is untrusted.
|
|
34
33
|
|
|
@@ -56,8 +55,7 @@ class PythonCodeExecutionTool(Tool):
|
|
|
56
55
|
async def execute_python_code(
|
|
57
56
|
code_execution_request: Annotated[CodeExecutionRequest, "Python code and the libraries required"],
|
|
58
57
|
) -> dict[str, Any]:
|
|
59
|
-
"""
|
|
60
|
-
Executes Python code in the attached environment and returns the result.
|
|
58
|
+
"""Executes Python code in the attached environment and returns the result.
|
|
61
59
|
|
|
62
60
|
Args:
|
|
63
61
|
code_execution_request (CodeExecutionRequest): The Python code and libraries to execute
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
#
|
|
3
3
|
# SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
|
|
5
|
-
from typing import Annotated, Any, Optional
|
|
5
|
+
from typing import Annotated, Any, Optional
|
|
6
6
|
|
|
7
7
|
from pydantic import BaseModel
|
|
8
8
|
|
|
@@ -23,18 +23,15 @@ __all__ = ["Crawl4AITool"]
|
|
|
23
23
|
@require_optional_import(["crawl4ai"], "crawl4ai")
|
|
24
24
|
@export_module("autogen.tools.experimental")
|
|
25
25
|
class Crawl4AITool(Tool):
|
|
26
|
-
"""
|
|
27
|
-
Crawl a website and extract information using the crawl4ai library.
|
|
28
|
-
"""
|
|
26
|
+
"""Crawl a website and extract information using the crawl4ai library."""
|
|
29
27
|
|
|
30
28
|
def __init__(
|
|
31
29
|
self,
|
|
32
|
-
llm_config:
|
|
33
|
-
extraction_model:
|
|
34
|
-
llm_strategy_kwargs:
|
|
30
|
+
llm_config: LLMConfig | dict[str, Any] | None = None,
|
|
31
|
+
extraction_model: type[BaseModel] | None = None,
|
|
32
|
+
llm_strategy_kwargs: dict[str, Any] | None = None,
|
|
35
33
|
) -> None:
|
|
36
|
-
"""
|
|
37
|
-
Initialize the Crawl4AITool.
|
|
34
|
+
"""Initialize the Crawl4AITool.
|
|
38
35
|
|
|
39
36
|
Args:
|
|
40
37
|
llm_config: The config dictionary for the LLM model. If None, the tool will run without LLM.
|
|
@@ -70,8 +67,8 @@ class Crawl4AITool(Tool):
|
|
|
70
67
|
url: Annotated[str, "The url to crawl and extract information from."],
|
|
71
68
|
instruction: Annotated[str, "The instruction to provide on how and what to extract."],
|
|
72
69
|
llm_config: Annotated[Any, Depends(on(llm_config))],
|
|
73
|
-
llm_strategy_kwargs: Annotated[
|
|
74
|
-
extraction_model: Annotated[
|
|
70
|
+
llm_strategy_kwargs: Annotated[dict[str, Any] | None, Depends(on(llm_strategy_kwargs))],
|
|
71
|
+
extraction_model: Annotated[type[BaseModel] | None, Depends(on(extraction_model))],
|
|
75
72
|
) -> Any:
|
|
76
73
|
browser_cfg = BrowserConfig(headless=True)
|
|
77
74
|
crawl_config = Crawl4AITool._get_crawl_config(
|
|
@@ -90,7 +87,7 @@ class Crawl4AITool(Tool):
|
|
|
90
87
|
)
|
|
91
88
|
|
|
92
89
|
@staticmethod
|
|
93
|
-
def _validate_llm_strategy_kwargs(llm_strategy_kwargs:
|
|
90
|
+
def _validate_llm_strategy_kwargs(llm_strategy_kwargs: dict[str, Any] | None, llm_config_provided: bool) -> None:
|
|
94
91
|
if not llm_strategy_kwargs:
|
|
95
92
|
return
|
|
96
93
|
|
|
@@ -120,10 +117,10 @@ class Crawl4AITool(Tool):
|
|
|
120
117
|
|
|
121
118
|
@staticmethod
|
|
122
119
|
def _get_crawl_config( # type: ignore[no-any-unimported]
|
|
123
|
-
llm_config:
|
|
120
|
+
llm_config: LLMConfig | dict[str, Any],
|
|
124
121
|
instruction: str,
|
|
125
|
-
llm_strategy_kwargs:
|
|
126
|
-
extraction_model:
|
|
122
|
+
llm_strategy_kwargs: dict[str, Any] | None = None,
|
|
123
|
+
extraction_model: type[BaseModel] | None = None,
|
|
127
124
|
) -> "CrawlerRunConfig":
|
|
128
125
|
lite_llm_config = LiteLLmConfigFactory.create_lite_llm_config(llm_config)
|
|
129
126
|
|
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
# SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
|
|
5
5
|
import copy
|
|
6
|
-
from
|
|
6
|
+
from collections.abc import Callable
|
|
7
|
+
from typing import Annotated, Any
|
|
7
8
|
|
|
8
9
|
from pydantic import BaseModel, Field
|
|
9
10
|
|
|
@@ -77,7 +78,7 @@ class DeepResearchTool(Tool):
|
|
|
77
78
|
|
|
78
79
|
def __init__(
|
|
79
80
|
self,
|
|
80
|
-
llm_config:
|
|
81
|
+
llm_config: LLMConfig | dict[str, Any],
|
|
81
82
|
max_web_steps: int = 30,
|
|
82
83
|
):
|
|
83
84
|
"""Initialize the DeepResearchTool.
|
|
@@ -117,7 +118,7 @@ class DeepResearchTool(Tool):
|
|
|
117
118
|
|
|
118
119
|
def delegate_research_task(
|
|
119
120
|
task: Annotated[str, "The task to perform a research on."],
|
|
120
|
-
llm_config: Annotated[
|
|
121
|
+
llm_config: Annotated[LLMConfig | dict[str, Any], Depends(on(llm_config))],
|
|
121
122
|
max_web_steps: Annotated[int, Depends(on(max_web_steps))],
|
|
122
123
|
) -> str:
|
|
123
124
|
"""Delegate a research task to the agent.
|
|
@@ -165,11 +166,11 @@ class DeepResearchTool(Tool):
|
|
|
165
166
|
|
|
166
167
|
@staticmethod
|
|
167
168
|
def _get_split_question_and_answer_subquestions(
|
|
168
|
-
llm_config:
|
|
169
|
+
llm_config: LLMConfig | dict[str, Any], max_web_steps: int
|
|
169
170
|
) -> Callable[..., Any]:
|
|
170
171
|
def split_question_and_answer_subquestions(
|
|
171
172
|
question: Annotated[str, "The question to split and answer."],
|
|
172
|
-
llm_config: Annotated[
|
|
173
|
+
llm_config: Annotated[LLMConfig | dict[str, Any], Depends(on(llm_config))],
|
|
173
174
|
max_web_steps: Annotated[int, Depends(on(max_web_steps))],
|
|
174
175
|
) -> str:
|
|
175
176
|
decomposition_agent = ConversableAgent(
|
|
@@ -233,7 +234,7 @@ class DeepResearchTool(Tool):
|
|
|
233
234
|
|
|
234
235
|
@staticmethod
|
|
235
236
|
def _get_generate_subquestions(
|
|
236
|
-
llm_config:
|
|
237
|
+
llm_config: LLMConfig | dict[str, Any],
|
|
237
238
|
max_web_steps: int,
|
|
238
239
|
) -> Callable[..., str]:
|
|
239
240
|
"""Get the generate_subquestions method.
|
|
@@ -248,7 +249,7 @@ class DeepResearchTool(Tool):
|
|
|
248
249
|
|
|
249
250
|
def generate_subquestions(
|
|
250
251
|
task: Task,
|
|
251
|
-
llm_config: Annotated[
|
|
252
|
+
llm_config: Annotated[LLMConfig | dict[str, Any], Depends(on(llm_config))],
|
|
252
253
|
max_web_steps: Annotated[int, Depends(on(max_web_steps))],
|
|
253
254
|
) -> str:
|
|
254
255
|
if not task.subquestions:
|
|
@@ -270,7 +271,7 @@ class DeepResearchTool(Tool):
|
|
|
270
271
|
@staticmethod
|
|
271
272
|
def _answer_question(
|
|
272
273
|
question: str,
|
|
273
|
-
llm_config:
|
|
274
|
+
llm_config: LLMConfig | dict[str, Any],
|
|
274
275
|
max_web_steps: int,
|
|
275
276
|
) -> str:
|
|
276
277
|
from ....agents.experimental.websurfer import WebSurferAgent
|
|
@@ -21,8 +21,7 @@ def _execute_duckduckgo_query(
|
|
|
21
21
|
query: str,
|
|
22
22
|
num_results: int = 5,
|
|
23
23
|
) -> list[dict[str, Any]]:
|
|
24
|
-
"""
|
|
25
|
-
Execute a search query using the DuckDuckGo Search API.
|
|
24
|
+
"""Execute a search query using the DuckDuckGo Search API.
|
|
26
25
|
|
|
27
26
|
Args:
|
|
28
27
|
query (str): The search query string.
|
|
@@ -45,8 +44,7 @@ def _duckduckgo_search(
|
|
|
45
44
|
query: str,
|
|
46
45
|
num_results: int = 5,
|
|
47
46
|
) -> list[dict[str, Any]]:
|
|
48
|
-
"""
|
|
49
|
-
Perform a DuckDuckGo search and format the results.
|
|
47
|
+
"""Perform a DuckDuckGo search and format the results.
|
|
50
48
|
|
|
51
49
|
This function takes search parameters, executes the query using `_execute_duckduckgo_query`,
|
|
52
50
|
and formats the results into a list of dictionaries containing title, link, and snippet.
|
|
@@ -71,24 +69,20 @@ def _duckduckgo_search(
|
|
|
71
69
|
|
|
72
70
|
@export_module("autogen.tools.experimental")
|
|
73
71
|
class DuckDuckGoSearchTool(Tool):
|
|
74
|
-
"""
|
|
75
|
-
DuckDuckGoSearchTool is a tool that uses DuckDuckGo to perform a search.
|
|
72
|
+
"""DuckDuckGoSearchTool is a tool that uses DuckDuckGo to perform a search.
|
|
76
73
|
|
|
77
74
|
This tool allows agents to leverage the DuckDuckGo search engine for information retrieval.
|
|
78
75
|
DuckDuckGo does not require an API key, making it easy to use.
|
|
79
76
|
"""
|
|
80
77
|
|
|
81
78
|
def __init__(self) -> None:
|
|
82
|
-
"""
|
|
83
|
-
Initializes the DuckDuckGoSearchTool.
|
|
84
|
-
"""
|
|
79
|
+
"""Initializes the DuckDuckGoSearchTool."""
|
|
85
80
|
|
|
86
81
|
def duckduckgo_search(
|
|
87
82
|
query: Annotated[str, "The search query."],
|
|
88
83
|
num_results: Annotated[int, "The number of results to return."] = 5,
|
|
89
84
|
) -> list[dict[str, Any]]:
|
|
90
|
-
"""
|
|
91
|
-
Performs a search using the DuckDuckGo Search API and returns formatted results.
|
|
85
|
+
"""Performs a search using the DuckDuckGo Search API and returns formatted results.
|
|
92
86
|
|
|
93
87
|
Args:
|
|
94
88
|
query: The search query string.
|