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
@@ -4,7 +4,7 @@
4
4
 
5
5
  import asyncio
6
6
  import logging
7
- from typing import List, Optional, Union
7
+ from typing import Optional
8
8
 
9
9
  from ....import_utils import optional_import_block, require_optional_import
10
10
  from .document import Document, DocumentType
@@ -39,12 +39,12 @@ class Neo4jNativeGraphQueryEngine:
39
39
  username: str = "neo4j",
40
40
  password: str = "password",
41
41
  embeddings: Optional["Embedder"] = None,
42
- embedding_dimension: Optional[int] = 3072,
42
+ embedding_dimension: int | None = 3072,
43
43
  llm: Optional["LLMInterface"] = None,
44
44
  query_llm: Optional["LLMInterface"] = None,
45
- entities: Optional[List[str]] = None,
46
- relations: Optional[List[str]] = None,
47
- potential_schema: Optional[List[tuple[str, str, str]]] = None,
45
+ entities: list[str] | None = None,
46
+ relations: list[str] | None = None,
47
+ potential_schema: list[tuple[str, str, str]] | None = None,
48
48
  ):
49
49
  """Initialize a Neo4j graph query engine.
50
50
 
@@ -74,7 +74,7 @@ class Neo4jNativeGraphQueryEngine:
74
74
  self.relations = relations
75
75
  self.potential_schema = potential_schema
76
76
 
77
- def init_db(self, input_doc: Optional[Union[list[Document]]] = None) -> None:
77
+ def init_db(self, input_doc: list[Document] | None = None) -> None:
78
78
  """Initialize the Neo4j graph database using the provided input doc.
79
79
  Currently this method only supports single document input (only reads the first doc).
80
80
 
@@ -189,7 +189,7 @@ class Neo4jNativeGraphQueryEngine:
189
189
  from_pdf=True,
190
190
  )
191
191
 
192
- def _build_graph(self, input_doc: List[Document]) -> None:
192
+ def _build_graph(self, input_doc: list[Document]) -> None:
193
193
  """Build the knowledge graph using the provided input documents.
194
194
 
195
195
  Args:
@@ -2,7 +2,7 @@
2
2
  #
3
3
  # SPDX-License-Identifier: Apache-2.0
4
4
 
5
- from typing import Any, Optional, Union
5
+ from typing import Any
6
6
 
7
7
  from .... import Agent, ConversableAgent
8
8
  from .graph_query_engine import GraphStoreQueryResult
@@ -41,10 +41,10 @@ class Neo4jNativeGraphCapability(GraphRagCapability):
41
41
  def _reply_using_native_neo4j_query(
42
42
  self,
43
43
  recipient: ConversableAgent,
44
- messages: Optional[list[dict[str, Any]]] = None,
45
- sender: Optional[Agent] = None,
46
- config: Optional[Any] = None,
47
- ) -> tuple[bool, Optional[Union[str, dict[str, Any]]]]:
44
+ messages: list[dict[str, Any]] | None = None,
45
+ sender: Agent | None = None,
46
+ config: Any | None = None,
47
+ ) -> tuple[bool, str | dict[str, Any] | None]:
48
48
  """Query Neo4j and return the message. Internally, it uses the Neo4jNativeGraphQueryEngine to query the graph.
49
49
 
50
50
  The agent's system message will be incorporated into the query, if it's not blank.
@@ -66,7 +66,7 @@ class Neo4jNativeGraphCapability(GraphRagCapability):
66
66
 
67
67
  return True, result.answer if result.answer else "I'm sorry, I don't have an answer for that."
68
68
 
69
- def _messages_summary(self, messages: Union[dict[str, Any], str], system_message: str) -> str:
69
+ def _messages_summary(self, messages: dict[str, Any] | str, system_message: str) -> str:
70
70
  """Summarize the messages in the conversation history. Excluding any message with 'tool_calls' and 'tool_responses'
71
71
  Includes the 'name' (if it exists) and the 'content', with a new line between each one, like:
72
72
  customer:
@@ -194,7 +194,7 @@ def convert_base64_to_data_uri(base64_image):
194
194
 
195
195
 
196
196
  @require_optional_import("PIL", "unknown")
197
- def gpt4v_formatter(prompt: str, img_format: str = "uri") -> list[Union[str, dict[str, Any]]]:
197
+ def gpt4v_formatter(prompt: str, img_format: str = "uri") -> list[str | dict[str, Any]]:
198
198
  """Formats the input prompt by replacing image tags and returns a list of text and images.
199
199
 
200
200
  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, Union
7
+ from typing import Any
8
8
 
9
9
  from ... import OpenAIWrapper
10
10
  from ...import_utils import optional_import_block, require_optional_import
@@ -32,7 +32,7 @@ class LLamaIndexConversableAgent(ConversableAgent):
32
32
  self,
33
33
  name: str,
34
34
  llama_index_agent: "AgentRunner",
35
- description: Optional[str] = None,
35
+ description: str | None = None,
36
36
  **kwargs: Any,
37
37
  ):
38
38
  """Args:
@@ -65,10 +65,10 @@ class LLamaIndexConversableAgent(ConversableAgent):
65
65
 
66
66
  def _generate_oai_reply(
67
67
  self,
68
- messages: Optional[list[dict[str, Any]]] = None,
69
- sender: Optional[Agent] = None,
70
- config: Optional[OpenAIWrapper] = None,
71
- ) -> tuple[bool, Optional[Union[str, dict[str, Any]]]]:
68
+ messages: list[dict[str, Any]] | None = None,
69
+ sender: Agent | None = None,
70
+ config: OpenAIWrapper | None = None,
71
+ ) -> tuple[bool, str | dict[str, Any] | None]:
72
72
  """Generate a reply using autogen.oai."""
73
73
  user_message, history = self._extract_message_and_history(messages=messages, sender=sender)
74
74
 
@@ -80,10 +80,10 @@ class LLamaIndexConversableAgent(ConversableAgent):
80
80
 
81
81
  async def _a_generate_oai_reply(
82
82
  self,
83
- messages: Optional[list[dict[str, Any]]] = None,
84
- sender: Optional[Agent] = None,
85
- config: Optional[OpenAIWrapper] = None,
86
- ) -> tuple[bool, Optional[Union[str, dict[str, Any]]]]:
83
+ messages: list[dict[str, Any]] | None = None,
84
+ sender: Agent | None = None,
85
+ config: OpenAIWrapper | None = None,
86
+ ) -> tuple[bool, str | dict[str, Any] | None]:
87
87
  """Generate a reply using autogen.oai."""
88
88
  user_message, history = self._extract_message_and_history(messages=messages, sender=sender)
89
89
 
@@ -96,7 +96,7 @@ class LLamaIndexConversableAgent(ConversableAgent):
96
96
  return (True, extracted_response)
97
97
 
98
98
  def _extract_message_and_history(
99
- self, messages: Optional[list[dict[str, Any]]] = None, sender: Optional[Agent] = None
99
+ self, messages: list[dict[str, Any]] | None = None, sender: Agent | None = None
100
100
  ) -> tuple[str, list["ChatMessage"]]:
101
101
  """Extract the message and history from the messages."""
102
102
  if not messages:
@@ -6,7 +6,8 @@
6
6
  # SPDX-License-Identifier: MIT
7
7
  import json
8
8
  import logging
9
- from typing import Any, Optional, Union
9
+ import warnings
10
+ from typing import Any
10
11
 
11
12
  import requests
12
13
 
@@ -33,7 +34,7 @@ class LLaVAAgent(MultimodalConversableAgent):
33
34
  def __init__(
34
35
  self,
35
36
  name: str,
36
- system_message: Optional[tuple[str, list]] = DEFAULT_LLAVA_SYS_MSG,
37
+ system_message: tuple[str, list] | None = DEFAULT_LLAVA_SYS_MSG,
37
38
  *args,
38
39
  **kwargs: Any,
39
40
  ):
@@ -84,12 +85,25 @@ class LLaVAAgent(MultimodalConversableAgent):
84
85
  retry = 10
85
86
  while len(out) == 0 and retry > 0:
86
87
  # image names will be inferred automatically from llava_call
88
+ if "max_new_tokens" in self.llm_config:
89
+ warnings.warn(
90
+ (
91
+ "`max_new_tokens` is deprecated in `llm_config` for llava agents. "
92
+ "Use `max_tokens` instead. "
93
+ "Scheduled for removal in 0.10.0 version."
94
+ ),
95
+ DeprecationWarning,
96
+ )
97
+ max_tokens = self.llm_config["max_new_tokens"]
98
+ else:
99
+ max_tokens = self.llm_config.get("max_tokens")
100
+
87
101
  out = llava_call_binary(
88
102
  prompt=prompt,
89
103
  images=images,
90
104
  config_list=self.llm_config["config_list"],
91
105
  temperature=self.llm_config.get("temperature", 0.5),
92
- max_new_tokens=self.llm_config.get("max_new_tokens", 2000),
106
+ max_new_tokens=max_tokens or 2000,
93
107
  )
94
108
  retry -= 1
95
109
 
@@ -169,7 +183,7 @@ def llava_call_binary(
169
183
  continue
170
184
 
171
185
 
172
- def llava_call(prompt: str, llm_config: Union[LLMConfig, dict]) -> str:
186
+ def llava_call(prompt: str, llm_config: LLMConfig | dict) -> str:
173
187
  """Makes a call to the LLaVA service to generate text based on a given prompt"""
174
188
  prompt, images = llava_formatter(prompt, order_image_tokens=False)
175
189
 
@@ -6,8 +6,9 @@
6
6
  # SPDX-License-Identifier: MIT
7
7
  import os
8
8
  import re
9
+ from collections.abc import Callable
9
10
  from time import sleep
10
- from typing import Any, Callable, Dict, Literal, Optional, Union
11
+ from typing import Any, Literal
11
12
 
12
13
  from pydantic import BaseModel, root_validator
13
14
 
@@ -141,12 +142,11 @@ class MathUserProxyAgent(UserProxyAgent):
141
142
 
142
143
  def __init__(
143
144
  self,
144
- name: Optional[str] = "MathChatAgent", # default set to MathChatAgent
145
- is_termination_msg: Optional[
146
- Callable[[Dict[str, Any]], bool]
147
- ] = _is_termination_msg_mathchat, # terminate if \boxed{} in message
145
+ name: str | None = "MathChatAgent", # default set to MathChatAgent
146
+ is_termination_msg: Callable[[dict[str, Any]], bool]
147
+ | None = _is_termination_msg_mathchat, # terminate if \boxed{} in message
148
148
  human_input_mode: Literal["ALWAYS", "NEVER", "TERMINATE"] = "NEVER", # Fully automated
149
- default_auto_reply: Optional[Union[str, dict[str, Any]]] = DEFAULT_REPLY,
149
+ default_auto_reply: str | dict[str, Any] | None = DEFAULT_REPLY,
150
150
  max_invalid_q_per_step=3, # a parameter needed in MathChat
151
151
  **kwargs: Any,
152
152
  ):
@@ -294,9 +294,9 @@ class MathUserProxyAgent(UserProxyAgent):
294
294
 
295
295
  def _generate_math_reply(
296
296
  self,
297
- messages: Optional[list[dict]] = None,
298
- sender: Optional[Agent] = None,
299
- config: Optional[Any] = None,
297
+ messages: list[dict] | None = None,
298
+ sender: Agent | None = None,
299
+ config: Any | None = None,
300
300
  ):
301
301
  """Generate an auto reply."""
302
302
  if messages is None:
@@ -366,7 +366,7 @@ class MathUserProxyAgent(UserProxyAgent):
366
366
  # THE SOFTWARE.
367
367
 
368
368
 
369
- def get_from_dict_or_env(data: dict[str, Any], key: str, env_key: str, default: Optional[str] = None) -> str:
369
+ def get_from_dict_or_env(data: dict[str, Any], key: str, env_key: str, default: str | None = None) -> str:
370
370
  """Get a value from a dictionary or an environment variable."""
371
371
  if data.get(key):
372
372
  return data[key]
@@ -395,7 +395,7 @@ class WolframAlphaAPIWrapper(BaseModel):
395
395
  """
396
396
 
397
397
  wolfram_client: Any #: :meta private:
398
- wolfram_alpha_appid: Optional[str] = None
398
+ wolfram_alpha_appid: str | None = None
399
399
 
400
400
  @root_validator(skip_on_failure=True)
401
401
  @classmethod
@@ -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 copy
8
- from typing import Any, Optional, Union
8
+ from typing import Any
9
9
 
10
10
  from ... import OpenAIWrapper
11
11
  from ...code_utils import content_str
@@ -27,7 +27,7 @@ class MultimodalConversableAgent(ConversableAgent):
27
27
  def __init__(
28
28
  self,
29
29
  name: str,
30
- system_message: Optional[Union[str, list]] = DEFAULT_LMM_SYS_MSG,
30
+ system_message: str | list | None = DEFAULT_LMM_SYS_MSG,
31
31
  is_termination_msg: str = None,
32
32
  *args,
33
33
  **kwargs: Any,
@@ -61,7 +61,7 @@ class MultimodalConversableAgent(ConversableAgent):
61
61
  MultimodalConversableAgent.a_generate_oai_reply,
62
62
  )
63
63
 
64
- def update_system_message(self, system_message: Union[dict[str, Any], list[str], str]):
64
+ def update_system_message(self, system_message: dict[str, Any] | list[str] | str):
65
65
  """Update the system message.
66
66
 
67
67
  Args:
@@ -71,7 +71,7 @@ class MultimodalConversableAgent(ConversableAgent):
71
71
  self._oai_system_message[0]["role"] = "system"
72
72
 
73
73
  @staticmethod
74
- def _message_to_dict(message: Union[dict[str, Any], list[str], str]) -> dict:
74
+ def _message_to_dict(message: dict[str, Any] | list[str] | str) -> dict:
75
75
  """Convert a message to a dictionary. This implementation
76
76
  handles the GPT-4V formatting for easier prompts.
77
77
 
@@ -100,10 +100,10 @@ class MultimodalConversableAgent(ConversableAgent):
100
100
 
101
101
  def generate_oai_reply(
102
102
  self,
103
- messages: Optional[list[dict[str, Any]]] = None,
104
- sender: Optional[Agent] = None,
105
- config: Optional[OpenAIWrapper] = None,
106
- ) -> tuple[bool, Optional[Union[str, dict[str, Any]]]]:
103
+ messages: list[dict[str, Any]] | None = None,
104
+ sender: Agent | None = None,
105
+ config: OpenAIWrapper | None = None,
106
+ ) -> tuple[bool, str | dict[str, Any] | None]:
107
107
  """Generate a reply using autogen.oai."""
108
108
  client = self.client if config is None else config
109
109
  if client is None:
@@ -5,7 +5,8 @@
5
5
  # Portions derived from https://github.com/microsoft/autogen are under the MIT License.
6
6
  # SPDX-License-Identifier: MIT
7
7
  import warnings
8
- from typing import Any, Callable, Literal, Optional
8
+ from collections.abc import Callable
9
+ from typing import Any, Literal, Optional
9
10
 
10
11
  from ...import_utils import optional_import_block, require_optional_import
11
12
  from ...retrieve_utils import TEXT_FORMATS, get_files_from_dir, split_files_to_chunks
@@ -30,8 +31,8 @@ class QdrantRetrieveUserProxyAgent(RetrieveUserProxyAgent):
30
31
  self,
31
32
  name="RetrieveChatAgent", # default set to RetrieveChatAgent
32
33
  human_input_mode: Literal["ALWAYS", "NEVER", "TERMINATE"] = "ALWAYS",
33
- is_termination_msg: Optional[Callable[[dict[str, Any]], bool]] = None,
34
- retrieve_config: Optional[dict[str, Any]] = None, # config for the retrieve agent
34
+ is_termination_msg: Callable[[dict[str, Any]], bool] | None = None,
35
+ retrieve_config: dict[str, Any] | None = None, # config for the retrieve agent
35
36
  **kwargs: Any,
36
37
  ):
37
38
  """Args:
@@ -175,7 +176,7 @@ def create_qdrant_from_dir(
175
176
  quantization_config: Optional["models.QuantizationConfig"] = None,
176
177
  hnsw_config: Optional["models.HnswConfigDiff"] = None,
177
178
  payload_indexing: bool = False,
178
- qdrant_client_options: Optional[dict[str, Any]] = {},
179
+ qdrant_client_options: dict[str, Any] | None = {},
179
180
  ):
180
181
  """Create a Qdrant collection from all the files in a given directory, the directory can also be a single file or a
181
182
  url to a single file.
@@ -271,7 +272,7 @@ def query_qdrant(
271
272
  collection_name: str = "all-my-documents",
272
273
  search_string: str = "",
273
274
  embedding_model: str = "BAAI/bge-small-en-v1.5",
274
- qdrant_client_options: Optional[dict[str, Any]] = {},
275
+ qdrant_client_options: dict[str, Any] | None = {},
275
276
  ) -> list[list["QueryResponse"]]:
276
277
  """Perform a similarity search with filters on a Qdrant collection
277
278
 
@@ -4,8 +4,9 @@
4
4
 
5
5
  import logging
6
6
  import os
7
+ from collections.abc import Sequence
7
8
  from pathlib import Path
8
- from typing import TYPE_CHECKING, Any, Optional, Sequence, Union
9
+ from typing import TYPE_CHECKING, Any, Optional
9
10
 
10
11
  from ....doc_utils import export_module
11
12
  from ....import_utils import optional_import_block, require_optional_import
@@ -37,8 +38,7 @@ logger = logging.getLogger(__name__)
37
38
  @require_optional_import(["chromadb", "llama_index"], "rag")
38
39
  @export_module("autogen.agentchat.contrib.rag")
39
40
  class ChromaDBQueryEngine:
40
- """
41
- This engine leverages Chromadb to persist document embeddings in a named collection
41
+ """This engine leverages Chromadb to persist document embeddings in a named collection
42
42
  and LlamaIndex's VectorStoreIndex to efficiently index and retrieve documents, and generate an answer in response
43
43
  to natural language queries. Collection can be regarded as an abstraction of group of documents in the database.
44
44
 
@@ -51,18 +51,18 @@ class ChromaDBQueryEngine:
51
51
 
52
52
  def __init__( # type: ignore[no-any-unimported]
53
53
  self,
54
- host: Optional[str] = "localhost",
55
- port: Optional[int] = 8000,
54
+ host: str | None = "localhost",
55
+ port: int | None = 8000,
56
56
  settings: Optional["Settings"] = None,
57
- tenant: Optional[str] = None,
58
- database: Optional[str] = None,
59
- embedding_function: "Optional[EmbeddingFunction[Any]]" = None,
60
- metadata: Optional[dict[str, Any]] = None,
57
+ tenant: str | None = None,
58
+ database: str | None = None,
59
+ embedding_function: "EmbeddingFunction[Any] | None" = None,
60
+ metadata: dict[str, Any] | None = None,
61
61
  llm: Optional["LLM"] = None,
62
- collection_name: Optional[str] = None,
62
+ collection_name: str | None = None,
63
63
  ) -> None:
64
- """
65
- Initializes the ChromaDBQueryEngine with db_path, metadata, and embedding function and llm.
64
+ """Initializes the ChromaDBQueryEngine with db_path, metadata, and embedding function and llm.
65
+
66
66
  Args:
67
67
  host: The host address of the ChromaDB server. Default is localhost.
68
68
  port: The port number of the ChromaDB server. Default is 8000.
@@ -101,8 +101,8 @@ class ChromaDBQueryEngine:
101
101
 
102
102
  def init_db(
103
103
  self,
104
- new_doc_dir: Optional[Union[Path, str]] = None,
105
- new_doc_paths_or_urls: Optional[Sequence[Union[Path, str]]] = None,
104
+ new_doc_dir: Path | str | None = None,
105
+ new_doc_paths_or_urls: Sequence[Path | str] | None = None,
106
106
  *args: Any,
107
107
  **kwargs: Any,
108
108
  ) -> bool:
@@ -125,7 +125,6 @@ class ChromaDBQueryEngine:
125
125
  bool: True if initialization is successful
126
126
 
127
127
  """
128
-
129
128
  self._set_up(overwrite=True)
130
129
  documents = self._load_doc(input_dir=new_doc_dir, input_docs=new_doc_paths_or_urls)
131
130
  self.index = VectorStoreIndex.from_documents(documents=documents, storage_context=self.storage_context)
@@ -155,8 +154,8 @@ class ChromaDBQueryEngine:
155
154
 
156
155
  def add_docs(
157
156
  self,
158
- new_doc_dir: Optional[Union[Path, str]] = None,
159
- new_doc_paths_or_urls: Optional[Sequence[Union[Path, str]]] = None,
157
+ new_doc_dir: Path | str | None = None,
158
+ new_doc_paths_or_urls: Sequence[Path | str] | None = None,
160
159
  *args: Any,
161
160
  **kwargs: Any,
162
161
  ) -> None:
@@ -174,8 +173,7 @@ class ChromaDBQueryEngine:
174
173
  self.index.insert(doc)
175
174
 
176
175
  def query(self, question: str) -> str:
177
- """
178
- Retrieve information from indexed documents by processing a query using the engine's LLM.
176
+ """Retrieve information from indexed documents by processing a query using the engine's LLM.
179
177
 
180
178
  Args:
181
179
  question: A natural language query string used to search the indexed documents.
@@ -193,8 +191,7 @@ class ChromaDBQueryEngine:
193
191
  return str(response)
194
192
 
195
193
  def get_collection_name(self) -> str:
196
- """
197
- Get the name of the collection used by the query engine.
194
+ """Get the name of the collection used by the query engine.
198
195
 
199
196
  Returns:
200
197
  The name of the collection.
@@ -210,10 +207,10 @@ class ChromaDBQueryEngine:
210
207
  raise Exception("Query index is not initialized. Please call init_db or connect_db first.")
211
208
 
212
209
  def _set_up(self, overwrite: bool) -> None:
213
- """
214
- Set up ChromaDB and LlamaIndex storage by:
210
+ """Set up ChromaDB and LlamaIndex storage by:
215
211
  1. Initialize the ChromaDB using VectorDBFactory and create a collection with the given name.
216
212
  2. Create the LlamaIndex vector store and storage context for the collection.
213
+
217
214
  Args:
218
215
  overwrite: If True, overwrite the existing collection with the same name.
219
216
  """
@@ -223,10 +220,9 @@ class ChromaDBQueryEngine:
223
220
  self.storage_context = StorageContext.from_defaults(vector_store=self.vector_store)
224
221
 
225
222
  def _load_doc( # type: ignore[no-any-unimported]
226
- self, input_dir: Optional[Union[Path, str]], input_docs: Optional[Sequence[Union[Path, str]]]
223
+ self, input_dir: Path | str | None, input_docs: Sequence[Path | str] | None
227
224
  ) -> Sequence["LlamaDocument"]:
228
- """
229
- Load documents from a directory and/or a sequence of file paths.
225
+ """Load documents from a directory and/or a sequence of file paths.
230
226
 
231
227
  It uses LlamaIndex's SimpleDirectoryReader that supports multiple file[formats]((https://docs.llamaindex.ai/en/stable/module_guides/loading/simpledirectoryreader/#supported-file-types)).
232
228
 
@@ -4,8 +4,9 @@
4
4
 
5
5
  import logging
6
6
  import os
7
+ from collections.abc import Sequence
7
8
  from pathlib import Path
8
- from typing import TYPE_CHECKING, Any, Optional, Sequence, Union
9
+ from typing import TYPE_CHECKING, Any, Optional
9
10
 
10
11
  from ....doc_utils import export_module
11
12
  from ....import_utils import optional_import_block, require_optional_import
@@ -33,8 +34,7 @@ logger = logging.getLogger(__name__)
33
34
  @require_optional_import("llama_index", "rag")
34
35
  @export_module("autogen.agentchat.contrib.rag")
35
36
  class LlamaIndexQueryEngine:
36
- """
37
- This engine leverages LlamaIndex's VectorStoreIndex to efficiently index and retrieve documents, and generate an answer in response
37
+ """This engine leverages LlamaIndex's VectorStoreIndex to efficiently index and retrieve documents, and generate an answer in response
38
38
  to natural language queries. It use any LlamaIndex [vector store](https://docs.llamaindex.ai/en/stable/module_guides/storing/vector_stores/).
39
39
 
40
40
  By default the engine will use OpenAI's GPT-4o model (use the `llm` parameter to change that).
@@ -44,10 +44,10 @@ class LlamaIndexQueryEngine:
44
44
  self,
45
45
  vector_store: "BasePydanticVectorStore",
46
46
  llm: Optional["LLM"] = None,
47
- file_reader_class: Optional[type["SimpleDirectoryReader"]] = None,
47
+ file_reader_class: type["SimpleDirectoryReader"] | None = None,
48
48
  ) -> None:
49
- """
50
- Initializes the LlamaIndexQueryEngine with the given vector store.
49
+ """Initializes the LlamaIndexQueryEngine with the given vector store.
50
+
51
51
  Args:
52
52
  vector_store: The vector store to use for indexing and querying documents.
53
53
  llm: LLM model used by LlamaIndex for query processing. You can find more supported LLMs at [LLM](https://docs.llamaindex.ai/en/stable/module_guides/models/llms/).
@@ -59,8 +59,8 @@ class LlamaIndexQueryEngine:
59
59
 
60
60
  def init_db(
61
61
  self,
62
- new_doc_dir: Optional[Union[Path, str]] = None,
63
- new_doc_paths_or_urls: Optional[Sequence[Union[Path, str]]] = None,
62
+ new_doc_dir: Path | str | None = None,
63
+ new_doc_paths_or_urls: Sequence[Path | str] | None = None,
64
64
  *args: Any,
65
65
  **kwargs: Any,
66
66
  ) -> bool:
@@ -80,7 +80,6 @@ class LlamaIndexQueryEngine:
80
80
  bool: True if initialization is successful
81
81
 
82
82
  """
83
-
84
83
  self.storage_context = StorageContext.from_defaults(vector_store=self.vector_store)
85
84
  documents = self._load_doc(input_dir=new_doc_dir, input_docs=new_doc_paths_or_urls)
86
85
  self.index = VectorStoreIndex.from_documents(documents=documents, storage_context=self.storage_context)
@@ -106,8 +105,8 @@ class LlamaIndexQueryEngine:
106
105
 
107
106
  def add_docs(
108
107
  self,
109
- new_doc_dir: Optional[Union[Path, str]] = None,
110
- new_doc_paths_or_urls: Optional[Sequence[Union[Path, str]]] = None,
108
+ new_doc_dir: Path | str | None = None,
109
+ new_doc_paths_or_urls: Sequence[Path | str] | None = None,
111
110
  *args: Any,
112
111
  **kwargs: Any,
113
112
  ) -> None:
@@ -125,8 +124,7 @@ class LlamaIndexQueryEngine:
125
124
  self.index.insert(doc)
126
125
 
127
126
  def query(self, question: str) -> str:
128
- """
129
- Retrieve information from indexed documents by processing a query using the engine's LLM.
127
+ """Retrieve information from indexed documents by processing a query using the engine's LLM.
130
128
 
131
129
  Args:
132
130
  question: A natural language query string used to search the indexed documents.
@@ -149,10 +147,9 @@ class LlamaIndexQueryEngine:
149
147
  raise Exception("Query index is not initialized. Please call init_db or connect_db first.")
150
148
 
151
149
  def _load_doc( # type: ignore[no-any-unimported]
152
- self, input_dir: Optional[Union[Path, str]], input_docs: Optional[Sequence[Union[Path, str]]]
150
+ self, input_dir: Path | str | None, input_docs: Sequence[Path | str] | None
153
151
  ) -> Sequence["LlamaDocument"]:
154
- """
155
- Load documents from a directory and/or a sequence of file paths.
152
+ """Load documents from a directory and/or a sequence of file paths.
156
153
 
157
154
  Default to uses LlamaIndex's SimpleDirectoryReader that supports multiple file[formats](https://docs.llamaindex.ai/en/stable/module_guides/loading/simpledirectoryreader/#supported-file-types).
158
155
 
@@ -170,7 +167,7 @@ class LlamaIndexQueryEngine:
170
167
  ValueError: If any provided file path does not exist.
171
168
  ValueError: If neither input_dir nor input_docs is provided.
172
169
  """
173
- loaded_documents: list["LlamaDocument"] = [] # type: ignore[no-any-unimported]
170
+ loaded_documents: list[LlamaDocument] = [] # type: ignore[no-any-unimported]
174
171
  if input_dir:
175
172
  logger.info(f"Loading docs from directory: {input_dir}")
176
173
  if not os.path.exists(input_dir):