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.

Files changed (236) hide show
  1. {ag2-0.9.6.dist-info → ag2-0.9.8.post1.dist-info}/METADATA +102 -75
  2. ag2-0.9.8.post1.dist-info/RECORD +387 -0
  3. autogen/__init__.py +1 -2
  4. autogen/_website/generate_api_references.py +4 -5
  5. autogen/_website/generate_mkdocs.py +9 -15
  6. autogen/_website/notebook_processor.py +13 -14
  7. autogen/_website/process_notebooks.py +10 -10
  8. autogen/_website/utils.py +5 -4
  9. autogen/agentchat/agent.py +13 -13
  10. autogen/agentchat/assistant_agent.py +7 -6
  11. autogen/agentchat/contrib/agent_eval/agent_eval.py +3 -3
  12. autogen/agentchat/contrib/agent_eval/critic_agent.py +3 -3
  13. autogen/agentchat/contrib/agent_eval/quantifier_agent.py +3 -3
  14. autogen/agentchat/contrib/agent_eval/subcritic_agent.py +3 -3
  15. autogen/agentchat/contrib/agent_optimizer.py +3 -3
  16. autogen/agentchat/contrib/capabilities/generate_images.py +11 -11
  17. autogen/agentchat/contrib/capabilities/teachability.py +15 -15
  18. autogen/agentchat/contrib/capabilities/transforms.py +17 -18
  19. autogen/agentchat/contrib/capabilities/transforms_util.py +5 -5
  20. autogen/agentchat/contrib/capabilities/vision_capability.py +4 -3
  21. autogen/agentchat/contrib/captainagent/agent_builder.py +30 -30
  22. autogen/agentchat/contrib/captainagent/captainagent.py +22 -21
  23. autogen/agentchat/contrib/captainagent/tool_retriever.py +2 -3
  24. autogen/agentchat/contrib/gpt_assistant_agent.py +9 -9
  25. autogen/agentchat/contrib/graph_rag/document.py +3 -3
  26. autogen/agentchat/contrib/graph_rag/falkor_graph_query_engine.py +3 -3
  27. autogen/agentchat/contrib/graph_rag/falkor_graph_rag_capability.py +6 -6
  28. autogen/agentchat/contrib/graph_rag/graph_query_engine.py +3 -3
  29. autogen/agentchat/contrib/graph_rag/neo4j_graph_query_engine.py +5 -11
  30. autogen/agentchat/contrib/graph_rag/neo4j_graph_rag_capability.py +6 -6
  31. autogen/agentchat/contrib/graph_rag/neo4j_native_graph_query_engine.py +7 -7
  32. autogen/agentchat/contrib/graph_rag/neo4j_native_graph_rag_capability.py +6 -6
  33. autogen/agentchat/contrib/img_utils.py +1 -1
  34. autogen/agentchat/contrib/llamaindex_conversable_agent.py +11 -11
  35. autogen/agentchat/contrib/llava_agent.py +18 -4
  36. autogen/agentchat/contrib/math_user_proxy_agent.py +11 -11
  37. autogen/agentchat/contrib/multimodal_conversable_agent.py +8 -8
  38. autogen/agentchat/contrib/qdrant_retrieve_user_proxy_agent.py +6 -5
  39. autogen/agentchat/contrib/rag/chromadb_query_engine.py +22 -26
  40. autogen/agentchat/contrib/rag/llamaindex_query_engine.py +14 -17
  41. autogen/agentchat/contrib/rag/mongodb_query_engine.py +27 -37
  42. autogen/agentchat/contrib/rag/query_engine.py +7 -5
  43. autogen/agentchat/contrib/retrieve_assistant_agent.py +5 -5
  44. autogen/agentchat/contrib/retrieve_user_proxy_agent.py +8 -7
  45. autogen/agentchat/contrib/society_of_mind_agent.py +15 -14
  46. autogen/agentchat/contrib/swarm_agent.py +76 -98
  47. autogen/agentchat/contrib/text_analyzer_agent.py +7 -7
  48. autogen/agentchat/contrib/vectordb/base.py +10 -18
  49. autogen/agentchat/contrib/vectordb/chromadb.py +2 -1
  50. autogen/agentchat/contrib/vectordb/couchbase.py +18 -20
  51. autogen/agentchat/contrib/vectordb/mongodb.py +6 -5
  52. autogen/agentchat/contrib/vectordb/pgvectordb.py +40 -41
  53. autogen/agentchat/contrib/vectordb/qdrant.py +5 -5
  54. autogen/agentchat/contrib/web_surfer.py +20 -19
  55. autogen/agentchat/conversable_agent.py +311 -295
  56. autogen/agentchat/group/context_str.py +1 -3
  57. autogen/agentchat/group/context_variables.py +15 -25
  58. autogen/agentchat/group/group_tool_executor.py +10 -10
  59. autogen/agentchat/group/group_utils.py +15 -15
  60. autogen/agentchat/group/guardrails.py +7 -7
  61. autogen/agentchat/group/handoffs.py +19 -36
  62. autogen/agentchat/group/multi_agent_chat.py +7 -7
  63. autogen/agentchat/group/on_condition.py +4 -7
  64. autogen/agentchat/group/on_context_condition.py +4 -7
  65. autogen/agentchat/group/patterns/auto.py +8 -7
  66. autogen/agentchat/group/patterns/manual.py +7 -6
  67. autogen/agentchat/group/patterns/pattern.py +13 -12
  68. autogen/agentchat/group/patterns/random.py +3 -3
  69. autogen/agentchat/group/patterns/round_robin.py +3 -3
  70. autogen/agentchat/group/reply_result.py +2 -4
  71. autogen/agentchat/group/speaker_selection_result.py +5 -5
  72. autogen/agentchat/group/targets/group_chat_target.py +7 -6
  73. autogen/agentchat/group/targets/group_manager_target.py +4 -4
  74. autogen/agentchat/group/targets/transition_target.py +2 -1
  75. autogen/agentchat/groupchat.py +58 -61
  76. autogen/agentchat/realtime/experimental/audio_adapters/twilio_audio_adapter.py +4 -4
  77. autogen/agentchat/realtime/experimental/audio_adapters/websocket_audio_adapter.py +4 -4
  78. autogen/agentchat/realtime/experimental/clients/gemini/client.py +7 -7
  79. autogen/agentchat/realtime/experimental/clients/oai/base_client.py +8 -8
  80. autogen/agentchat/realtime/experimental/clients/oai/rtc_client.py +6 -6
  81. autogen/agentchat/realtime/experimental/clients/realtime_client.py +10 -9
  82. autogen/agentchat/realtime/experimental/realtime_agent.py +10 -9
  83. autogen/agentchat/realtime/experimental/realtime_observer.py +3 -3
  84. autogen/agentchat/realtime/experimental/realtime_swarm.py +44 -44
  85. autogen/agentchat/user_proxy_agent.py +10 -9
  86. autogen/agentchat/utils.py +3 -3
  87. autogen/agents/contrib/time/time_reply_agent.py +6 -5
  88. autogen/agents/contrib/time/time_tool_agent.py +2 -1
  89. autogen/agents/experimental/deep_research/deep_research.py +3 -3
  90. autogen/agents/experimental/discord/discord.py +2 -2
  91. autogen/agents/experimental/document_agent/chroma_query_engine.py +29 -44
  92. autogen/agents/experimental/document_agent/docling_doc_ingest_agent.py +9 -14
  93. autogen/agents/experimental/document_agent/document_agent.py +15 -16
  94. autogen/agents/experimental/document_agent/document_conditions.py +3 -3
  95. autogen/agents/experimental/document_agent/document_utils.py +5 -9
  96. autogen/agents/experimental/document_agent/inmemory_query_engine.py +14 -20
  97. autogen/agents/experimental/document_agent/parser_utils.py +4 -4
  98. autogen/agents/experimental/document_agent/url_utils.py +14 -23
  99. autogen/agents/experimental/reasoning/reasoning_agent.py +33 -33
  100. autogen/agents/experimental/slack/slack.py +2 -2
  101. autogen/agents/experimental/telegram/telegram.py +2 -3
  102. autogen/agents/experimental/websurfer/websurfer.py +4 -4
  103. autogen/agents/experimental/wikipedia/wikipedia.py +5 -7
  104. autogen/browser_utils.py +8 -8
  105. autogen/cache/abstract_cache_base.py +5 -5
  106. autogen/cache/cache.py +12 -12
  107. autogen/cache/cache_factory.py +4 -4
  108. autogen/cache/cosmos_db_cache.py +9 -9
  109. autogen/cache/disk_cache.py +6 -6
  110. autogen/cache/in_memory_cache.py +4 -4
  111. autogen/cache/redis_cache.py +4 -4
  112. autogen/code_utils.py +18 -18
  113. autogen/coding/base.py +6 -6
  114. autogen/coding/docker_commandline_code_executor.py +9 -9
  115. autogen/coding/func_with_reqs.py +7 -6
  116. autogen/coding/jupyter/base.py +3 -3
  117. autogen/coding/jupyter/docker_jupyter_server.py +3 -4
  118. autogen/coding/jupyter/import_utils.py +3 -3
  119. autogen/coding/jupyter/jupyter_client.py +5 -5
  120. autogen/coding/jupyter/jupyter_code_executor.py +3 -4
  121. autogen/coding/jupyter/local_jupyter_server.py +2 -6
  122. autogen/coding/local_commandline_code_executor.py +8 -7
  123. autogen/coding/markdown_code_extractor.py +1 -2
  124. autogen/coding/utils.py +1 -2
  125. autogen/doc_utils.py +3 -2
  126. autogen/environments/docker_python_environment.py +19 -29
  127. autogen/environments/python_environment.py +8 -17
  128. autogen/environments/system_python_environment.py +3 -4
  129. autogen/environments/venv_python_environment.py +8 -12
  130. autogen/environments/working_directory.py +1 -2
  131. autogen/events/agent_events.py +106 -109
  132. autogen/events/base_event.py +6 -5
  133. autogen/events/client_events.py +15 -14
  134. autogen/events/helpers.py +1 -1
  135. autogen/events/print_event.py +4 -5
  136. autogen/fast_depends/_compat.py +10 -15
  137. autogen/fast_depends/core/build.py +17 -36
  138. autogen/fast_depends/core/model.py +64 -113
  139. autogen/fast_depends/dependencies/model.py +2 -1
  140. autogen/fast_depends/dependencies/provider.py +3 -2
  141. autogen/fast_depends/library/model.py +4 -4
  142. autogen/fast_depends/schema.py +7 -7
  143. autogen/fast_depends/use.py +17 -25
  144. autogen/fast_depends/utils.py +10 -30
  145. autogen/formatting_utils.py +6 -6
  146. autogen/graph_utils.py +1 -4
  147. autogen/import_utils.py +13 -13
  148. autogen/interop/crewai/crewai.py +2 -2
  149. autogen/interop/interoperable.py +2 -2
  150. autogen/interop/langchain/langchain_chat_model_factory.py +3 -2
  151. autogen/interop/langchain/langchain_tool.py +2 -6
  152. autogen/interop/litellm/litellm_config_factory.py +6 -7
  153. autogen/interop/pydantic_ai/pydantic_ai.py +4 -7
  154. autogen/interop/registry.py +2 -1
  155. autogen/io/base.py +5 -5
  156. autogen/io/run_response.py +33 -32
  157. autogen/io/websockets.py +6 -5
  158. autogen/json_utils.py +1 -2
  159. autogen/llm_config/__init__.py +11 -0
  160. autogen/llm_config/client.py +58 -0
  161. autogen/llm_config/config.py +384 -0
  162. autogen/llm_config/entry.py +154 -0
  163. autogen/logger/base_logger.py +4 -3
  164. autogen/logger/file_logger.py +2 -1
  165. autogen/logger/logger_factory.py +2 -2
  166. autogen/logger/logger_utils.py +2 -2
  167. autogen/logger/sqlite_logger.py +3 -2
  168. autogen/math_utils.py +4 -5
  169. autogen/mcp/__main__.py +6 -6
  170. autogen/mcp/helpers.py +4 -4
  171. autogen/mcp/mcp_client.py +170 -29
  172. autogen/mcp/mcp_proxy/fastapi_code_generator_helpers.py +3 -4
  173. autogen/mcp/mcp_proxy/mcp_proxy.py +23 -26
  174. autogen/mcp/mcp_proxy/operation_grouping.py +4 -5
  175. autogen/mcp/mcp_proxy/operation_renaming.py +6 -10
  176. autogen/mcp/mcp_proxy/security.py +2 -3
  177. autogen/messages/agent_messages.py +96 -98
  178. autogen/messages/base_message.py +6 -5
  179. autogen/messages/client_messages.py +15 -14
  180. autogen/messages/print_message.py +4 -5
  181. autogen/oai/__init__.py +1 -2
  182. autogen/oai/anthropic.py +42 -41
  183. autogen/oai/bedrock.py +68 -57
  184. autogen/oai/cerebras.py +26 -25
  185. autogen/oai/client.py +118 -138
  186. autogen/oai/client_utils.py +3 -3
  187. autogen/oai/cohere.py +34 -11
  188. autogen/oai/gemini.py +40 -17
  189. autogen/oai/gemini_types.py +11 -12
  190. autogen/oai/groq.py +22 -10
  191. autogen/oai/mistral.py +17 -11
  192. autogen/oai/oai_models/__init__.py +14 -2
  193. autogen/oai/oai_models/_models.py +2 -2
  194. autogen/oai/oai_models/chat_completion.py +13 -14
  195. autogen/oai/oai_models/chat_completion_message.py +11 -9
  196. autogen/oai/oai_models/chat_completion_message_tool_call.py +26 -3
  197. autogen/oai/oai_models/chat_completion_token_logprob.py +3 -4
  198. autogen/oai/oai_models/completion_usage.py +8 -9
  199. autogen/oai/ollama.py +22 -10
  200. autogen/oai/openai_responses.py +40 -17
  201. autogen/oai/openai_utils.py +159 -85
  202. autogen/oai/together.py +29 -14
  203. autogen/retrieve_utils.py +6 -7
  204. autogen/runtime_logging.py +5 -4
  205. autogen/token_count_utils.py +7 -4
  206. autogen/tools/contrib/time/time.py +0 -1
  207. autogen/tools/dependency_injection.py +5 -6
  208. autogen/tools/experimental/browser_use/browser_use.py +10 -10
  209. autogen/tools/experimental/code_execution/python_code_execution.py +5 -7
  210. autogen/tools/experimental/crawl4ai/crawl4ai.py +12 -15
  211. autogen/tools/experimental/deep_research/deep_research.py +9 -8
  212. autogen/tools/experimental/duckduckgo/duckduckgo_search.py +5 -11
  213. autogen/tools/experimental/firecrawl/firecrawl_tool.py +98 -115
  214. autogen/tools/experimental/google/authentication/credentials_local_provider.py +1 -1
  215. autogen/tools/experimental/google/drive/drive_functions.py +4 -4
  216. autogen/tools/experimental/google/drive/toolkit.py +5 -5
  217. autogen/tools/experimental/google_search/google_search.py +5 -5
  218. autogen/tools/experimental/google_search/youtube_search.py +5 -5
  219. autogen/tools/experimental/messageplatform/discord/discord.py +8 -12
  220. autogen/tools/experimental/messageplatform/slack/slack.py +14 -20
  221. autogen/tools/experimental/messageplatform/telegram/telegram.py +8 -12
  222. autogen/tools/experimental/perplexity/perplexity_search.py +18 -29
  223. autogen/tools/experimental/reliable/reliable.py +68 -74
  224. autogen/tools/experimental/searxng/searxng_search.py +20 -19
  225. autogen/tools/experimental/tavily/tavily_search.py +12 -19
  226. autogen/tools/experimental/web_search_preview/web_search_preview.py +13 -7
  227. autogen/tools/experimental/wikipedia/wikipedia.py +7 -10
  228. autogen/tools/function_utils.py +7 -7
  229. autogen/tools/tool.py +6 -5
  230. autogen/types.py +2 -2
  231. autogen/version.py +1 -1
  232. ag2-0.9.6.dist-info/RECORD +0 -421
  233. autogen/llm_config.py +0 -385
  234. {ag2-0.9.6.dist-info → ag2-0.9.8.post1.dist-info}/WHEEL +0 -0
  235. {ag2-0.9.6.dist-info → ag2-0.9.8.post1.dist-info}/licenses/LICENSE +0 -0
  236. {ag2-0.9.6.dist-info → ag2-0.9.8.post1.dist-info}/licenses/NOTICE.md +0 -0
@@ -15,10 +15,11 @@ import sys
15
15
  import tempfile
16
16
  import threading
17
17
  import time
18
+ from collections.abc import Callable
18
19
  from dataclasses import dataclass
19
20
  from functools import lru_cache
20
21
  from pathlib import Path
21
- from typing import Any, Callable, Optional, TypeVar, Union
22
+ from typing import Any, TypeVar
22
23
 
23
24
  from ..import_utils import optional_import_block, require_optional_import
24
25
 
@@ -37,7 +38,7 @@ with optional_import_block():
37
38
  @dataclass
38
39
  class NotebookError:
39
40
  error_name: str
40
- error_value: Optional[str]
41
+ error_value: str | None
41
42
  traceback: str
42
43
  cell_source: str
43
44
 
@@ -79,7 +80,6 @@ C = TypeVar("C", bound=Callable[..., Any])
79
80
 
80
81
  def require_quarto_bin(f: C) -> C:
81
82
  """Decorator to skip a function if quarto is not installed."""
82
-
83
83
  if check_quarto_bin():
84
84
  return f
85
85
  else:
@@ -91,13 +91,13 @@ def require_quarto_bin(f: C) -> C:
91
91
  return wrapper # type: ignore[return-value]
92
92
 
93
93
 
94
- def load_metadata(notebook: Path) -> dict[str, dict[str, Union[str, list[str], None]]]:
94
+ def load_metadata(notebook: Path) -> dict[str, dict[str, str | list[str] | None]]:
95
95
  content = json.load(notebook.open(encoding="utf-8"))
96
- metadata: dict[str, dict[str, Union[str, list[str], None]]] = content.get("metadata", {})
96
+ metadata: dict[str, dict[str, str | list[str] | None]] = content.get("metadata", {})
97
97
  return metadata
98
98
 
99
99
 
100
- def skip_reason_or_none_if_ok(notebook: Path) -> Union[str, None, dict[str, Any]]:
100
+ def skip_reason_or_none_if_ok(notebook: Path) -> str | None | dict[str, Any]:
101
101
  """Return a reason to skip the notebook, or None if it should not be skipped."""
102
102
  if notebook.suffix != ".ipynb":
103
103
  return "not a notebook"
@@ -149,7 +149,7 @@ def skip_reason_or_none_if_ok(notebook: Path) -> Union[str, None, dict[str, Any]
149
149
  return None
150
150
 
151
151
 
152
- def extract_title(notebook: Path) -> Optional[str]:
152
+ def extract_title(notebook: Path) -> str | None:
153
153
  """Extract the title of the notebook."""
154
154
  with open(notebook, encoding="utf-8") as f:
155
155
  content = f.read()
@@ -196,7 +196,7 @@ def fmt_ok(notebook: Path) -> str:
196
196
 
197
197
 
198
198
  @require_optional_import("termcolor", "docs")
199
- def fmt_error(notebook: Path, error: Union[NotebookError, str]) -> str:
199
+ def fmt_error(notebook: Path, error: NotebookError | str) -> str:
200
200
  if isinstance(error, str):
201
201
  return f"{colored('[Error]', 'red')} {colored(notebook.name, 'blue')}: {error}"
202
202
  elif isinstance(error, NotebookError):
@@ -207,7 +207,7 @@ def fmt_error(notebook: Path, error: Union[NotebookError, str]) -> str:
207
207
 
208
208
  @require_quarto_bin
209
209
  @require_optional_import("nbclient", "docs")
210
- def test_notebook(notebook_path: Path, timeout: int = 300) -> tuple[Path, Optional[Union[NotebookError, NotebookSkip]]]:
210
+ def test_notebook(notebook_path: Path, timeout: int = 300) -> tuple[Path, NotebookError | NotebookSkip | None]:
211
211
  nb = nbformat.read(str(notebook_path), NB_VERSION) # type: ignore[arg-type,no-untyped-call]
212
212
 
213
213
  if "skip_test" in nb.metadata:
@@ -240,7 +240,7 @@ def test_notebook(notebook_path: Path, timeout: int = 300) -> tuple[Path, Option
240
240
  @require_optional_import("nbclient", "docs")
241
241
  def get_timeout_info(
242
242
  nb: NotebookNode,
243
- ) -> Optional[NotebookError]:
243
+ ) -> NotebookError | None:
244
244
  for i, cell in enumerate(nb.cells):
245
245
  if cell.cell_type != "code":
246
246
  continue
@@ -256,7 +256,7 @@ def get_timeout_info(
256
256
 
257
257
 
258
258
  @require_optional_import("nbclient", "docs")
259
- def get_error_info(nb: NotebookNode) -> Optional[NotebookError]:
259
+ def get_error_info(nb: NotebookNode) -> NotebookError | None:
260
260
  for cell in nb["cells"]: # get LAST error
261
261
  if cell["cell_type"] != "code":
262
262
  continue
@@ -288,7 +288,7 @@ def process_notebook(
288
288
  quarto_bin: str,
289
289
  dry_run: bool,
290
290
  target_dir_func: Callable[[Path], Path],
291
- post_processor: Optional[Callable[[Path, Path, dict[str, Any], Path], None]] = None,
291
+ post_processor: Callable[[Path, Path, dict[str, Any], Path], None] | None = None,
292
292
  ) -> str:
293
293
  """Process a single notebook.
294
294
 
@@ -301,7 +301,6 @@ def process_notebook(
301
301
  target_dir_func: Function to determine target directory for notebooks
302
302
  post_processor: Optional callback for post-processing
303
303
  """
304
-
305
304
  in_notebook_dir = "notebook" in src_notebook.parts
306
305
 
307
306
  metadata = load_metadata(src_notebook)
@@ -400,7 +399,7 @@ def create_base_argument_parser() -> argparse.ArgumentParser:
400
399
 
401
400
  def process_notebooks_core(
402
401
  args: argparse.Namespace,
403
- post_process_func: Optional[Callable[[Path, Path, dict[str, Any], Path], None]],
402
+ post_process_func: Callable[[Path, Path, dict[str, Any], Path], None] | None,
404
403
  target_dir_func: Callable[[Path], Path],
405
404
  ) -> list[Path]:
406
405
  """Core logic for processing notebooks shared across build systems.
@@ -12,9 +12,9 @@ import json
12
12
  import re
13
13
  import shutil
14
14
  import sys
15
+ from collections.abc import Sequence
15
16
  from copy import deepcopy
16
17
  from pathlib import Path
17
- from typing import Sequence, Union
18
18
 
19
19
  from ..import_utils import optional_import_block, require_optional_import
20
20
  from .notebook_processor import (
@@ -41,7 +41,7 @@ def notebooks_target_dir(website_build_directory: Path) -> Path:
41
41
 
42
42
 
43
43
  def add_front_matter_to_metadata_mdx(
44
- front_matter: dict[str, Union[str, list[str], None]], website_build_directory: Path, rendered_mdx: Path
44
+ front_matter: dict[str, str | list[str] | None], website_build_directory: Path, rendered_mdx: Path
45
45
  ) -> None:
46
46
  source = front_matter.get("source_notebook")
47
47
  if isinstance(source, str) and source.startswith("/website/docs/"):
@@ -239,7 +239,7 @@ def extract_img_tag_from_figure_tag(content: str, img_rel_path: Path) -> str:
239
239
  def post_process_mdx(
240
240
  rendered_mdx: Path,
241
241
  source_notebooks: Path,
242
- front_matter: dict[str, Union[str, list[str], None]],
242
+ front_matter: dict[str, str | list[str] | None],
243
243
  website_build_directory: Path,
244
244
  ) -> None:
245
245
  with open(rendered_mdx, encoding="utf-8") as f:
@@ -309,7 +309,7 @@ def post_process_mdx(
309
309
  # Convert callout blocks
310
310
  content = convert_callout_blocks(content)
311
311
 
312
- # Convert mdx image syntax to mintly image syntax
312
+ # Convert mdx image syntax to mintlify image syntax
313
313
  content = convert_mdx_image_blocks(content, rendered_mdx, website_build_directory)
314
314
 
315
315
  # ensure editUrl is present
@@ -340,7 +340,7 @@ def get_sorted_files(input_dir: Path, prefix: str) -> list[str]:
340
340
  return [f"{prefix}/{f.parent.relative_to(input_dir)}/index".replace("\\", "/") for f in reversed_files]
341
341
 
342
342
 
343
- def generate_nav_group(input_dir: Path, group_header: str, prefix: str) -> dict[str, Union[str, list[str]]]:
343
+ def generate_nav_group(input_dir: Path, group_header: str, prefix: str) -> dict[str, str | list[str]]:
344
344
  """Generate navigation group for a directory.
345
345
 
346
346
  Args:
@@ -381,15 +381,15 @@ def extract_example_group(metadata_path: Path) -> list[str]:
381
381
 
382
382
 
383
383
  def update_group_pages(
384
- mint_navigation: list[dict[str, Union[str, list[Union[str, dict[str, Union[str, list[str]]]]]]]],
384
+ mint_navigation: list[dict[str, str | list[str | dict[str, str | list[str]]]]],
385
385
  target_group: str,
386
- new_value: Sequence[Union[str, dict[str, Union[str, Sequence[str]]]]],
387
- ) -> list[dict[str, Union[str, list[Union[str, dict[str, Union[str, list[str]]]]]]]]:
386
+ new_value: Sequence[str | dict[str, str | Sequence[str]]],
387
+ ) -> list[dict[str, str | list[str | dict[str, str | list[str]]]]]:
388
388
  """Update mint.json navigation group with new pages."""
389
389
  nav_copy = deepcopy(mint_navigation)
390
390
 
391
391
  def update_recursively(
392
- items: list[dict[str, Union[str, list[Union[str, dict[str, Union[str, list[str]]]]]]]],
392
+ items: list[dict[str, str | list[str | dict[str, str | list[str]]]]],
393
393
  ) -> None:
394
394
  for item in items:
395
395
  if isinstance(item, dict):
@@ -572,7 +572,7 @@ def get_files_path_from_navigation(navigation: list[NavigationGroup]) -> list[Pa
572
572
  """
573
573
  file_paths = []
574
574
 
575
- def extract_paths(items: Union[Sequence[Union[str, NavigationGroup]]]) -> None:
575
+ def extract_paths(items: Sequence[str | NavigationGroup]) -> None:
576
576
  for item in items:
577
577
  if isinstance(item, str):
578
578
  file_paths.append(Path(item))
autogen/_website/utils.py CHANGED
@@ -9,7 +9,7 @@ import sys
9
9
  from datetime import datetime
10
10
  from pathlib import Path
11
11
  from textwrap import dedent, indent
12
- from typing import Literal, Optional, TypedDict, Union
12
+ from typing import Literal, TypedDict, Union
13
13
 
14
14
  from ..import_utils import optional_import_block, require_optional_import
15
15
 
@@ -51,7 +51,7 @@ def copy_files(src_dir: Path, dst_dir: Path, files_to_copy: list[Path]) -> None:
51
51
  shutil.copy2(file, dst)
52
52
 
53
53
 
54
- def copy_only_git_tracked_and_untracked_files(src_dir: Path, dst_dir: Path, ignore_dir: Optional[str] = None) -> None:
54
+ def copy_only_git_tracked_and_untracked_files(src_dir: Path, dst_dir: Path, ignore_dir: str | None = None) -> None:
55
55
  """Copy only the files that are tracked by git or newly added from src_dir to dst_dir."""
56
56
  tracked_and_new_files = get_git_tracked_and_untracked_files_in_directory(src_dir)
57
57
 
@@ -120,6 +120,7 @@ def construct_authors_html(authors_list: list[str], authors_dict: dict[str, dict
120
120
  authors_list: list of author identifiers
121
121
  authors_dict: Dictionary containing author information keyed by author identifier
122
122
  build_system: The build system being used (mkdocs or mintlify)
123
+
123
124
  Returns:
124
125
  str: Formatted HTML string containing author cards
125
126
  """
@@ -204,6 +205,7 @@ def separate_front_matter_and_content(file_path: Path) -> tuple[str, str]:
204
205
 
205
206
  def ensure_edit_url(content: str, file_path: Path) -> str:
206
207
  """Ensure editUrl is present in the content.
208
+
207
209
  Args:
208
210
  content (str): Content of the file
209
211
  file_path (Path): Path to the file
@@ -223,7 +225,6 @@ def add_authors_and_social_preview(
223
225
  build_system: build_system = "mintlify",
224
226
  ) -> None:
225
227
  """Add authors info and social share image to mdx files in the target directory."""
226
-
227
228
  social_img_html = (
228
229
  """\n<div>
229
230
  <img noZoom className="social-share-img"
@@ -302,7 +303,7 @@ def render_gallery_html(gallery_file_path: Path) -> str:
302
303
  """
303
304
  try:
304
305
  # Load gallery items from YAML file
305
- with open(gallery_file_path, "r") as file:
306
+ with open(gallery_file_path) as file:
306
307
  gallery_items = yaml.safe_load(file)
307
308
 
308
309
  # Ensure gallery_items is a list
@@ -4,7 +4,7 @@
4
4
  #
5
5
  # Portions derived from https://github.com/microsoft/autogen are under the MIT License.
6
6
  # SPDX-License-Identifier: MIT
7
- from typing import TYPE_CHECKING, Any, Optional, Protocol, TypeVar, Union, runtime_checkable
7
+ from typing import TYPE_CHECKING, Any, Optional, Protocol, TypeVar, runtime_checkable
8
8
 
9
9
  from ..doc_utils import export_module
10
10
 
@@ -40,9 +40,9 @@ class Agent(Protocol):
40
40
 
41
41
  def send(
42
42
  self,
43
- message: Union[dict[str, Any], str],
43
+ message: dict[str, Any] | str,
44
44
  recipient: "Agent",
45
- request_reply: Optional[bool] = None,
45
+ request_reply: bool | None = None,
46
46
  ) -> None:
47
47
  """Send a message to another agent.
48
48
 
@@ -56,9 +56,9 @@ class Agent(Protocol):
56
56
 
57
57
  async def a_send(
58
58
  self,
59
- message: Union[dict[str, Any], str],
59
+ message: dict[str, Any] | str,
60
60
  recipient: "Agent",
61
- request_reply: Optional[bool] = None,
61
+ request_reply: bool | None = None,
62
62
  ) -> None:
63
63
  """(Async) Send a message to another agent.
64
64
 
@@ -72,9 +72,9 @@ class Agent(Protocol):
72
72
 
73
73
  def receive(
74
74
  self,
75
- message: Union[dict[str, Any], str],
75
+ message: dict[str, Any] | str,
76
76
  sender: "Agent",
77
- request_reply: Optional[bool] = None,
77
+ request_reply: bool | None = None,
78
78
  ) -> None:
79
79
  """Receive a message from another agent.
80
80
 
@@ -87,9 +87,9 @@ class Agent(Protocol):
87
87
 
88
88
  async def a_receive(
89
89
  self,
90
- message: Union[dict[str, Any], str],
90
+ message: dict[str, Any] | str,
91
91
  sender: "Agent",
92
- request_reply: Optional[bool] = None,
92
+ request_reply: bool | None = None,
93
93
  ) -> None:
94
94
  """(Async) Receive a message from another agent.
95
95
 
@@ -103,10 +103,10 @@ class Agent(Protocol):
103
103
 
104
104
  def generate_reply(
105
105
  self,
106
- messages: Optional[list[dict[str, Any]]] = None,
106
+ messages: list[dict[str, Any]] | None = None,
107
107
  sender: Optional["Agent"] = None,
108
108
  **kwargs: Any,
109
- ) -> Union[str, dict[str, Any], None]:
109
+ ) -> str | dict[str, Any] | None:
110
110
  """Generate a reply based on the received messages.
111
111
 
112
112
  Args:
@@ -122,10 +122,10 @@ class Agent(Protocol):
122
122
 
123
123
  async def a_generate_reply(
124
124
  self,
125
- messages: Optional[list[dict[str, Any]]] = None,
125
+ messages: list[dict[str, Any]] | None = None,
126
126
  sender: Optional["Agent"] = None,
127
127
  **kwargs: Any,
128
- ) -> Union[str, dict[str, Any], None]:
128
+ ) -> str | dict[str, Any] | None:
129
129
  """(Async) Generate a reply based on the received messages.
130
130
 
131
131
  Args:
@@ -4,7 +4,8 @@
4
4
  #
5
5
  # Portions derived from https://github.com/microsoft/autogen are under the MIT License.
6
6
  # SPDX-License-Identifier: MIT
7
- from typing import Any, Callable, Literal, Optional, Union
7
+ from collections.abc import Callable
8
+ from typing import Any, Literal
8
9
 
9
10
  from ..doc_utils import export_module
10
11
  from ..llm_config import LLMConfig
@@ -42,12 +43,12 @@ Reply "TERMINATE" in the end when everything is done.
42
43
  def __init__(
43
44
  self,
44
45
  name: str,
45
- system_message: Optional[str] = DEFAULT_SYSTEM_MESSAGE,
46
- llm_config: Optional[Union[LLMConfig, dict[str, Any], Literal[False]]] = None,
47
- is_termination_msg: Optional[Callable[[dict[str, Any]], bool]] = None,
48
- max_consecutive_auto_reply: Optional[int] = None,
46
+ system_message: str | None = DEFAULT_SYSTEM_MESSAGE,
47
+ llm_config: LLMConfig | dict[str, Any] | Literal[False] | None = None,
48
+ is_termination_msg: Callable[[dict[str, Any]], bool] | None = None,
49
+ max_consecutive_auto_reply: int | None = None,
49
50
  human_input_mode: Literal["ALWAYS", "NEVER", "TERMINATE"] = "NEVER",
50
- description: Optional[str] = None,
51
+ description: str | None = None,
51
52
  **kwargs: Any,
52
53
  ):
53
54
  """Args:
@@ -4,7 +4,7 @@
4
4
  #
5
5
  # Portions derived from https://github.com/microsoft/autogen are under the MIT License.
6
6
  # SPDX-License-Identifier: MIT
7
- from typing import Any, Literal, Optional, Union
7
+ from typing import Any, Literal
8
8
 
9
9
  from .... import GroupChat, GroupChatManager, UserProxyAgent
10
10
  from ....llm_config import LLMConfig
@@ -16,7 +16,7 @@ from .task import Task
16
16
 
17
17
 
18
18
  def generate_criteria(
19
- llm_config: Optional[Union[LLMConfig, dict[str, Any], Literal[False]]] = None,
19
+ llm_config: LLMConfig | dict[str, Any] | Literal[False] | None = None,
20
20
  task: Task = None,
21
21
  additional_instructions: str = "",
22
22
  max_round=2,
@@ -67,7 +67,7 @@ def generate_criteria(
67
67
 
68
68
 
69
69
  def quantify_criteria(
70
- llm_config: Optional[Union[LLMConfig, dict[str, Any], Literal[False]]] = None,
70
+ llm_config: LLMConfig | dict[str, Any] | Literal[False] | None = None,
71
71
  criteria: list[Criterion] = None,
72
72
  task: Task = None,
73
73
  test_case: str = "",
@@ -4,7 +4,7 @@
4
4
  #
5
5
  # Portions derived from https://github.com/microsoft/autogen are under the MIT License.
6
6
  # SPDX-License-Identifier: MIT
7
- from typing import Any, Optional
7
+ from typing import Any
8
8
 
9
9
  from ...conversable_agent import ConversableAgent
10
10
 
@@ -24,8 +24,8 @@ class CriticAgent(ConversableAgent):
24
24
  def __init__(
25
25
  self,
26
26
  name="critic",
27
- system_message: Optional[str] = DEFAULT_SYSTEM_MESSAGE,
28
- description: Optional[str] = DEFAULT_DESCRIPTION,
27
+ system_message: str | None = DEFAULT_SYSTEM_MESSAGE,
28
+ description: str | None = DEFAULT_DESCRIPTION,
29
29
  **kwargs: Any,
30
30
  ):
31
31
  """Args:
@@ -4,7 +4,7 @@
4
4
  #
5
5
  # Portions derived from https://github.com/microsoft/autogen are under the MIT License.
6
6
  # SPDX-License-Identifier: MIT
7
- from typing import Any, Optional
7
+ from typing import Any
8
8
 
9
9
  from ...conversable_agent import ConversableAgent
10
10
 
@@ -24,8 +24,8 @@ class QuantifierAgent(ConversableAgent):
24
24
  def __init__(
25
25
  self,
26
26
  name="quantifier",
27
- system_message: Optional[str] = DEFAULT_SYSTEM_MESSAGE,
28
- description: Optional[str] = DEFAULT_DESCRIPTION,
27
+ system_message: str | None = DEFAULT_SYSTEM_MESSAGE,
28
+ description: str | None = DEFAULT_DESCRIPTION,
29
29
  **kwargs: Any,
30
30
  ):
31
31
  """Args:
@@ -4,7 +4,7 @@
4
4
  #
5
5
  # Portions derived from https://github.com/microsoft/autogen are under the MIT License.
6
6
  # SPDX-License-Identifier: MIT
7
- from typing import Any, Optional
7
+ from typing import Any
8
8
 
9
9
  from ...conversable_agent import ConversableAgent
10
10
 
@@ -25,8 +25,8 @@ class SubCriticAgent(ConversableAgent):
25
25
  def __init__(
26
26
  self,
27
27
  name="subcritic",
28
- system_message: Optional[str] = DEFAULT_SYSTEM_MESSAGE,
29
- description: Optional[str] = DEFAULT_DESCRIPTION,
28
+ system_message: str | None = DEFAULT_SYSTEM_MESSAGE,
29
+ description: str | None = DEFAULT_DESCRIPTION,
30
30
  **kwargs: Any,
31
31
  ):
32
32
  """Args:
@@ -6,7 +6,7 @@
6
6
  # SPDX-License-Identifier: MIT
7
7
  import copy
8
8
  import json
9
- from typing import Any, Optional, Union
9
+ from typing import Any
10
10
 
11
11
  from ... import OpenAIWrapper, filter_config
12
12
  from ...code_utils import execute_code
@@ -176,8 +176,8 @@ class AgentOptimizer:
176
176
  def __init__(
177
177
  self,
178
178
  max_actions_per_step: int,
179
- llm_config: Optional[Union[LLMConfig, dict[str, Any]]] = None,
180
- optimizer_model: Optional[str] = "gpt-4-1106-preview",
179
+ llm_config: LLMConfig | dict[str, Any] | None = None,
180
+ optimizer_model: str | None = "gpt-4-1106-preview",
181
181
  ):
182
182
  """(These APIs are experimental and may change in the future.)
183
183
 
@@ -5,7 +5,7 @@
5
5
  # Portions derived from https://github.com/microsoft/autogen are under the MIT License.
6
6
  # SPDX-License-Identifier: MIT
7
7
  import re
8
- from typing import Any, Literal, Optional, Protocol, Union
8
+ from typing import Any, Literal, Optional, Protocol
9
9
 
10
10
  from .... import Agent, ConversableAgent, code_utils
11
11
  from ....cache import AbstractCache
@@ -78,7 +78,7 @@ class DalleImageGenerator:
78
78
 
79
79
  def __init__(
80
80
  self,
81
- llm_config: Union[LLMConfig, dict[str, Any]],
81
+ llm_config: LLMConfig | dict[str, Any],
82
82
  resolution: Literal["256x256", "512x512", "1024x1024", "1792x1024", "1024x1792"] = "1024x1024",
83
83
  quality: Literal["standard", "hd"] = "standard",
84
84
  num_images: int = 1,
@@ -153,8 +153,8 @@ class ImageGeneration(AgentCapability):
153
153
  def __init__(
154
154
  self,
155
155
  image_generator: ImageGenerator,
156
- cache: Optional[AbstractCache] = None,
157
- text_analyzer_llm_config: Optional[Union[LLMConfig, dict[str, Any]]] = None,
156
+ cache: AbstractCache | None = None,
157
+ text_analyzer_llm_config: LLMConfig | dict[str, Any] | None = None,
158
158
  text_analyzer_instructions: str = PROMPT_INSTRUCTIONS,
159
159
  verbosity: int = 0,
160
160
  register_reply_position: int = 2,
@@ -183,8 +183,8 @@ class ImageGeneration(AgentCapability):
183
183
  self._verbosity = verbosity
184
184
  self._register_reply_position = register_reply_position
185
185
 
186
- self._agent: Optional[ConversableAgent] = None
187
- self._text_analyzer: Optional[TextAnalyzerAgent] = None
186
+ self._agent: ConversableAgent | None = None
187
+ self._text_analyzer: TextAnalyzerAgent | None = None
188
188
 
189
189
  def add_to_agent(self, agent: ConversableAgent):
190
190
  """Adds the Image Generation capability to the specified ConversableAgent.
@@ -216,10 +216,10 @@ class ImageGeneration(AgentCapability):
216
216
  def _image_gen_reply(
217
217
  self,
218
218
  recipient: ConversableAgent,
219
- messages: Optional[list[dict[str, Any]]],
220
- sender: Optional[Agent] = None,
221
- config: Optional[Any] = None,
222
- ) -> tuple[bool, Optional[Union[str, dict[str, Any]]]]:
219
+ messages: list[dict[str, Any]] | None,
220
+ sender: Agent | None = None,
221
+ config: Any | None = None,
222
+ ) -> tuple[bool, str | dict[str, Any] | None]:
223
223
  if messages is None:
224
224
  return False, None
225
225
 
@@ -272,7 +272,7 @@ class ImageGeneration(AgentCapability):
272
272
  key = self._image_generator.cache_key(prompt)
273
273
  self._cache.set(key, img_utils.pil_to_data_uri(image))
274
274
 
275
- def _extract_analysis(self, analysis: Optional[Union[str, dict[str, Any]]]) -> str:
275
+ def _extract_analysis(self, analysis: str | dict[str, Any] | None) -> str:
276
276
  if isinstance(analysis, dict):
277
277
  return code_utils.content_str(analysis["content"])
278
278
  else:
@@ -6,7 +6,7 @@
6
6
  # SPDX-License-Identifier: MIT
7
7
  import os
8
8
  import pickle
9
- from typing import Any, Optional, Union
9
+ from typing import Any
10
10
 
11
11
  from ....formatting_utils import colored
12
12
  from ....import_utils import optional_import_block, require_optional_import
@@ -38,12 +38,12 @@ class Teachability(AgentCapability):
38
38
 
39
39
  def __init__(
40
40
  self,
41
- verbosity: Optional[int] = 0,
42
- reset_db: Optional[bool] = False,
43
- path_to_db_dir: Optional[str] = "./tmp/teachable_agent_db",
44
- recall_threshold: Optional[float] = 1.5,
45
- max_num_retrievals: Optional[int] = 10,
46
- llm_config: Optional[Union[LLMConfig, dict[str, Any], bool]] = None,
41
+ verbosity: int | None = 0,
42
+ reset_db: bool | None = False,
43
+ path_to_db_dir: str | None = "./tmp/teachable_agent_db",
44
+ recall_threshold: float | None = 1.5,
45
+ max_num_retrievals: int | None = 10,
46
+ llm_config: LLMConfig | dict[str, Any] | bool | None = None,
47
47
  ):
48
48
  """Args:
49
49
  verbosity (Optional, int): # 0 (default) for basic info, 1 to add memory operations, 2 for analyzer messages, 3 for memo lists.
@@ -92,7 +92,7 @@ class Teachability(AgentCapability):
92
92
  """Adds a few arbitrary memos to the DB."""
93
93
  self.memo_store.prepopulate()
94
94
 
95
- def process_last_received_message(self, text: Union[dict[str, Any], str]):
95
+ def process_last_received_message(self, text: dict[str, Any] | str):
96
96
  """Appends any relevant memos to the message text, and stores any apparent teachings in new memos.
97
97
  Uses TextAnalyzerAgent to make decisions about memo storage and retrieval.
98
98
  """
@@ -107,7 +107,7 @@ class Teachability(AgentCapability):
107
107
  # Return the (possibly) expanded message text.
108
108
  return expanded_text
109
109
 
110
- def _consider_memo_storage(self, comment: Union[dict[str, Any], str]):
110
+ def _consider_memo_storage(self, comment: dict[str, Any] | str):
111
111
  """Decides whether to store something from one user comment in the DB."""
112
112
  memo_added = False
113
113
 
@@ -165,7 +165,7 @@ class Teachability(AgentCapability):
165
165
  # Yes. Save them to disk.
166
166
  self.memo_store._save_memos()
167
167
 
168
- def _consider_memo_retrieval(self, comment: Union[dict[str, Any], str]):
168
+ def _consider_memo_retrieval(self, comment: dict[str, Any] | str):
169
169
  """Decides whether to retrieve memos from the DB, and add them to the chat context."""
170
170
  # First, use the comment directly as the lookup key.
171
171
  if self.verbosity >= 1:
@@ -228,7 +228,7 @@ class Teachability(AgentCapability):
228
228
  memo_texts = memo_texts + "\n" + info
229
229
  return memo_texts
230
230
 
231
- def _analyze(self, text_to_analyze: Union[dict[str, Any], str], analysis_instructions: Union[dict[str, Any], str]):
231
+ def _analyze(self, text_to_analyze: dict[str, Any] | str, analysis_instructions: dict[str, Any] | str):
232
232
  """Asks TextAnalyzerAgent to analyze the given text according to specific instructions."""
233
233
  self.analyzer.reset() # Clear the analyzer's list of messages.
234
234
  self.teachable_agent.send(
@@ -251,9 +251,9 @@ class MemoStore:
251
251
 
252
252
  def __init__(
253
253
  self,
254
- verbosity: Optional[int] = 0,
255
- reset: Optional[bool] = False,
256
- path_to_db_dir: Optional[str] = "./tmp/teachable_agent_db",
254
+ verbosity: int | None = 0,
255
+ reset: bool | None = False,
256
+ path_to_db_dir: str | None = "./tmp/teachable_agent_db",
257
257
  ):
258
258
  """Args:
259
259
  - verbosity (Optional, int): 1 to print memory operations, 0 to omit them. 3+ to print memo lists.
@@ -342,7 +342,7 @@ class MemoStore:
342
342
  )
343
343
  return input_text, output_text, distance
344
344
 
345
- def get_related_memos(self, query_text: str, n_results: int, threshold: Union[int, float]):
345
+ def get_related_memos(self, query_text: str, n_results: int, threshold: int | float):
346
346
  """Retrieves memos that are related to the given query text within the specified distance threshold."""
347
347
  if n_results > len(self.uid_text_dict):
348
348
  n_results = len(self.uid_text_dict)