ag2 0.9.7__py3-none-any.whl → 0.9.9__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of ag2 might be problematic. Click here for more details.

Files changed (236) hide show
  1. {ag2-0.9.7.dist-info → ag2-0.9.9.dist-info}/METADATA +102 -75
  2. ag2-0.9.9.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 +292 -290
  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 +60 -63
  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 +38 -27
  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 +2 -1
  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 +113 -139
  186. autogen/oai/client_utils.py +3 -3
  187. autogen/oai/cohere.py +34 -11
  188. autogen/oai/gemini.py +39 -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 +19 -9
  200. autogen/oai/openai_responses.py +40 -17
  201. autogen/oai/openai_utils.py +48 -38
  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 +8 -6
  230. autogen/types.py +2 -2
  231. autogen/version.py +1 -1
  232. ag2-0.9.7.dist-info/RECORD +0 -421
  233. autogen/llm_config.py +0 -385
  234. {ag2-0.9.7.dist-info → ag2-0.9.9.dist-info}/WHEEL +0 -0
  235. {ag2-0.9.7.dist-info → ag2-0.9.9.dist-info}/licenses/LICENSE +0 -0
  236. {ag2-0.9.7.dist-info → ag2-0.9.9.dist-info}/licenses/NOTICE.md +0 -0
@@ -3,8 +3,9 @@
3
3
  # SPDX-License-Identifier: Apache-2.0
4
4
 
5
5
  from abc import ABC
6
+ from collections.abc import Callable
6
7
  from copy import deepcopy
7
- from typing import TYPE_CHECKING, Any, Callable, Literal, Optional, Union
8
+ from typing import TYPE_CHECKING, Any, Literal, Union
8
9
  from uuid import UUID
9
10
 
10
11
  from pydantic import BaseModel, field_validator, model_serializer
@@ -56,22 +57,22 @@ EventRole = Literal["assistant", "function", "tool"]
56
57
 
57
58
 
58
59
  class BasePrintReceivedEvent(BaseEvent, ABC):
59
- content: Union[str, int, float, bool]
60
+ content: str | int | float | bool
60
61
  sender: str
61
62
  recipient: str
62
63
 
63
- def print(self, f: Optional[Callable[..., Any]] = None) -> None:
64
+ def print(self, f: Callable[..., Any] | None = None) -> None:
64
65
  f = f or print
65
66
  f(f"{colored(self.sender, 'yellow')} (to {self.recipient}):\n", flush=True)
66
67
 
67
68
 
68
69
  @wrap_event
69
70
  class FunctionResponseEvent(BasePrintReceivedEvent):
70
- name: Optional[str] = None
71
+ name: str | None = None
71
72
  role: EventRole = "function"
72
- content: Union[str, int, float, bool]
73
+ content: str | int | float | bool
73
74
 
74
- def print(self, f: Optional[Callable[..., Any]] = None) -> None:
75
+ def print(self, f: Callable[..., Any] | None = None) -> None:
75
76
  f = f or print
76
77
  super().print(f)
77
78
 
@@ -85,11 +86,11 @@ class FunctionResponseEvent(BasePrintReceivedEvent):
85
86
 
86
87
 
87
88
  class ToolResponse(BaseModel):
88
- tool_call_id: Optional[str] = None
89
+ tool_call_id: str | None = None
89
90
  role: EventRole = "tool"
90
- content: Union[str, int, float, bool]
91
+ content: str | int | float | bool
91
92
 
92
- def print(self, f: Optional[Callable[..., Any]] = None) -> None:
93
+ def print(self, f: Callable[..., Any] | None = None) -> None:
93
94
  f = f or print
94
95
  id = self.tool_call_id or "No id found"
95
96
  tool_print = f"***** Response from calling {self.role} ({id}) *****"
@@ -102,9 +103,9 @@ class ToolResponse(BaseModel):
102
103
  class ToolResponseEvent(BasePrintReceivedEvent):
103
104
  role: EventRole = "tool"
104
105
  tool_responses: list[ToolResponse]
105
- content: Union[str, int, float, bool]
106
+ content: str | int | float | bool
106
107
 
107
- def print(self, f: Optional[Callable[..., Any]] = None) -> None:
108
+ def print(self, f: Callable[..., Any] | None = None) -> None:
108
109
  f = f or print
109
110
  super().print(f)
110
111
 
@@ -114,10 +115,10 @@ class ToolResponseEvent(BasePrintReceivedEvent):
114
115
 
115
116
 
116
117
  class FunctionCall(BaseModel):
117
- name: Optional[str] = None
118
- arguments: Optional[str] = None
118
+ name: str | None = None
119
+ arguments: str | None = None
119
120
 
120
- def print(self, f: Optional[Callable[..., Any]] = None) -> None:
121
+ def print(self, f: Callable[..., Any] | None = None) -> None:
121
122
  f = f or print
122
123
 
123
124
  name = self.name or "(No function name found)"
@@ -136,10 +137,10 @@ class FunctionCall(BaseModel):
136
137
 
137
138
  @wrap_event
138
139
  class FunctionCallEvent(BasePrintReceivedEvent):
139
- content: Optional[Union[str, int, float, bool]] = None # type: ignore [assignment]
140
+ content: str | int | float | bool | None = None # type: ignore [assignment]
140
141
  function_call: FunctionCall
141
142
 
142
- def print(self, f: Optional[Callable[..., Any]] = None) -> None:
143
+ def print(self, f: Callable[..., Any] | None = None) -> None:
143
144
  f = f or print
144
145
  super().print(f)
145
146
 
@@ -152,11 +153,11 @@ class FunctionCallEvent(BasePrintReceivedEvent):
152
153
 
153
154
 
154
155
  class ToolCall(BaseModel):
155
- id: Optional[str] = None
156
+ id: str | None = None
156
157
  function: FunctionCall
157
158
  type: str
158
159
 
159
- def print(self, f: Optional[Callable[..., Any]] = None) -> None:
160
+ def print(self, f: Callable[..., Any] | None = None) -> None:
160
161
  f = f or print
161
162
 
162
163
  id = self.id or "No tool call id found"
@@ -177,14 +178,14 @@ class ToolCall(BaseModel):
177
178
 
178
179
  @wrap_event
179
180
  class ToolCallEvent(BasePrintReceivedEvent):
180
- content: Optional[Union[str, int, float, bool]] = None # type: ignore [assignment]
181
- refusal: Optional[str] = None
182
- role: Optional[EventRole] = None
183
- audio: Optional[str] = None
184
- function_call: Optional[FunctionCall] = None
181
+ content: str | int | float | bool | None = None # type: ignore [assignment]
182
+ refusal: str | None = None
183
+ role: EventRole | None = None
184
+ audio: str | None = None
185
+ function_call: FunctionCall | None = None
185
186
  tool_calls: list[ToolCall]
186
187
 
187
- def print(self, f: Optional[Callable[..., Any]] = None) -> None:
188
+ def print(self, f: Callable[..., Any] | None = None) -> None:
188
189
  f = f or print
189
190
  super().print(f)
190
191
 
@@ -199,7 +200,7 @@ class ToolCallEvent(BasePrintReceivedEvent):
199
200
 
200
201
  @wrap_event
201
202
  class TextEvent(BasePrintReceivedEvent):
202
- content: Optional[Union[str, int, float, bool, list[dict[str, Union[str, dict[str, Any]]]]]] = None # type: ignore [assignment]
203
+ content: str | int | float | bool | list[dict[str, str | dict[str, Any]]] | None = None # type: ignore [assignment]
203
204
 
204
205
  @classmethod
205
206
  @require_optional_import("PIL", "unknown")
@@ -210,8 +211,8 @@ class TextEvent(BasePrintReceivedEvent):
210
211
  @field_validator("content", mode="before")
211
212
  @classmethod
212
213
  def validate_and_encode_content(
213
- cls, content: Optional[Union[str, int, float, bool, list[dict[str, Union[str, dict[str, Any]]]]]]
214
- ) -> Optional[Union[str, int, float, bool, list[dict[str, Union[str, dict[str, Any]]]]]]:
214
+ cls, content: str | int | float | bool | list[dict[str, str | dict[str, Any]]] | None
215
+ ) -> str | int | float | bool | list[dict[str, str | dict[str, Any]]] | None:
215
216
  if not IS_PIL_AVAILABLE:
216
217
  return content
217
218
 
@@ -224,7 +225,7 @@ class TextEvent(BasePrintReceivedEvent):
224
225
 
225
226
  return content
226
227
 
227
- def print(self, f: Optional[Callable[..., Any]] = None) -> None:
228
+ def print(self, f: Callable[..., Any] | None = None) -> None:
228
229
  f = f or print
229
230
  super().print(f)
230
231
 
@@ -235,8 +236,8 @@ class TextEvent(BasePrintReceivedEvent):
235
236
 
236
237
 
237
238
  def create_received_event_model(
238
- *, uuid: Optional[UUID] = None, event: dict[str, Any], sender: "Agent", recipient: "Agent"
239
- ) -> Union[FunctionResponseEvent, ToolResponseEvent, FunctionCallEvent, ToolCallEvent, TextEvent]:
239
+ *, uuid: UUID | None = None, event: dict[str, Any], sender: "Agent", recipient: "Agent"
240
+ ) -> FunctionResponseEvent | ToolResponseEvent | FunctionCallEvent | ToolCallEvent | TextEvent:
240
241
  role = event.get("role")
241
242
  if role == "function":
242
243
  return FunctionResponseEvent(**event, sender=sender.name, recipient=recipient.name, uuid=uuid)
@@ -283,17 +284,17 @@ def create_received_event_model(
283
284
 
284
285
  @wrap_event
285
286
  class PostCarryoverProcessingEvent(BaseEvent):
286
- carryover: Union[str, list[Union[str, dict[str, Any], Any]]]
287
+ carryover: str | list[str | dict[str, Any] | Any]
287
288
  message: str
288
289
  verbose: bool = False
289
290
 
290
291
  sender: str
291
292
  recipient: str
292
293
  summary_method: str
293
- summary_args: Optional[dict[str, Any]] = None
294
- max_turns: Optional[int] = None
294
+ summary_args: dict[str, Any] | None = None
295
+ max_turns: int | None = None
295
296
 
296
- def __init__(self, *, uuid: Optional[UUID] = None, chat_info: dict[str, Any]):
297
+ def __init__(self, *, uuid: UUID | None = None, chat_info: dict[str, Any]):
297
298
  carryover = chat_info.get("carryover", "")
298
299
  message = chat_info.get("message")
299
300
  verbose = chat_info.get("verbose", False)
@@ -361,7 +362,7 @@ class PostCarryoverProcessingEvent(BaseEvent):
361
362
 
362
363
  return ("\n").join(print_carryover)
363
364
 
364
- def print(self, f: Optional[Callable[..., Any]] = None) -> None:
365
+ def print(self, f: Callable[..., Any] | None = None) -> None:
365
366
  f = f or print
366
367
 
367
368
  print_carryover = self._process_carryover()
@@ -382,15 +383,15 @@ class PostCarryoverProcessingEvent(BaseEvent):
382
383
 
383
384
  @wrap_event
384
385
  class ClearAgentsHistoryEvent(BaseEvent):
385
- agent: Optional[str] = None
386
- nr_events_to_preserve: Optional[int] = None
386
+ agent: str | None = None
387
+ nr_events_to_preserve: int | None = None
387
388
 
388
389
  def __init__(
389
390
  self,
390
391
  *,
391
- uuid: Optional[UUID] = None,
392
- agent: Optional[Union["Agent", str]] = None,
393
- nr_events_to_preserve: Optional[int] = None,
392
+ uuid: UUID | None = None,
393
+ agent: Union["Agent", str] | None = None,
394
+ nr_events_to_preserve: int | None = None,
394
395
  ):
395
396
  return super().__init__(
396
397
  uuid=uuid,
@@ -398,7 +399,7 @@ class ClearAgentsHistoryEvent(BaseEvent):
398
399
  nr_events_to_preserve=nr_events_to_preserve,
399
400
  )
400
401
 
401
- def print(self, f: Optional[Callable[..., Any]] = None) -> None:
402
+ def print(self, f: Callable[..., Any] | None = None) -> None:
402
403
  f = f or print
403
404
 
404
405
  if self.agent:
@@ -419,16 +420,16 @@ class SpeakerAttemptSuccessfulEvent(BaseEvent):
419
420
  mentions: dict[str, int]
420
421
  attempt: int
421
422
  attempts_left: int
422
- verbose: Optional[bool] = False
423
+ verbose: bool | None = False
423
424
 
424
425
  def __init__(
425
426
  self,
426
427
  *,
427
- uuid: Optional[UUID] = None,
428
+ uuid: UUID | None = None,
428
429
  mentions: dict[str, int],
429
430
  attempt: int,
430
431
  attempts_left: int,
431
- select_speaker_auto_verbose: Optional[bool] = False,
432
+ select_speaker_auto_verbose: bool | None = False,
432
433
  ):
433
434
  super().__init__(
434
435
  uuid=uuid,
@@ -448,7 +449,7 @@ class SpeakerAttemptSuccessfulEvent(BaseEvent):
448
449
  "select_speaker_auto_verbose": self.verbose,
449
450
  }
450
451
 
451
- def print(self, f: Optional[Callable[..., Any]] = None) -> None:
452
+ def print(self, f: Callable[..., Any] | None = None) -> None:
452
453
  f = f or print
453
454
 
454
455
  selected_agent_name = next(iter(self.mentions))
@@ -466,16 +467,16 @@ class SpeakerAttemptFailedMultipleAgentsEvent(BaseEvent):
466
467
  mentions: dict[str, int]
467
468
  attempt: int
468
469
  attempts_left: int
469
- verbose: Optional[bool] = False
470
+ verbose: bool | None = False
470
471
 
471
472
  def __init__(
472
473
  self,
473
474
  *,
474
- uuid: Optional[UUID] = None,
475
+ uuid: UUID | None = None,
475
476
  mentions: dict[str, int],
476
477
  attempt: int,
477
478
  attempts_left: int,
478
- select_speaker_auto_verbose: Optional[bool] = False,
479
+ select_speaker_auto_verbose: bool | None = False,
479
480
  ):
480
481
  super().__init__(
481
482
  uuid=uuid,
@@ -495,7 +496,7 @@ class SpeakerAttemptFailedMultipleAgentsEvent(BaseEvent):
495
496
  "select_speaker_auto_verbose": self.verbose,
496
497
  }
497
498
 
498
- def print(self, f: Optional[Callable[..., Any]] = None) -> None:
499
+ def print(self, f: Callable[..., Any] | None = None) -> None:
499
500
  f = f or print
500
501
 
501
502
  f(
@@ -512,16 +513,16 @@ class SpeakerAttemptFailedNoAgentsEvent(BaseEvent):
512
513
  mentions: dict[str, int]
513
514
  attempt: int
514
515
  attempts_left: int
515
- verbose: Optional[bool] = False
516
+ verbose: bool | None = False
516
517
 
517
518
  def __init__(
518
519
  self,
519
520
  *,
520
- uuid: Optional[UUID] = None,
521
+ uuid: UUID | None = None,
521
522
  mentions: dict[str, int],
522
523
  attempt: int,
523
524
  attempts_left: int,
524
- select_speaker_auto_verbose: Optional[bool] = False,
525
+ select_speaker_auto_verbose: bool | None = False,
525
526
  ):
526
527
  super().__init__(
527
528
  uuid=uuid,
@@ -541,7 +542,7 @@ class SpeakerAttemptFailedNoAgentsEvent(BaseEvent):
541
542
  "select_speaker_auto_verbose": self.verbose,
542
543
  }
543
544
 
544
- def print(self, f: Optional[Callable[..., Any]] = None) -> None:
545
+ def print(self, f: Callable[..., Any] | None = None) -> None:
545
546
  f = f or print
546
547
 
547
548
  f(
@@ -557,15 +558,15 @@ class SpeakerAttemptFailedNoAgentsEvent(BaseEvent):
557
558
  class GroupChatResumeEvent(BaseEvent):
558
559
  last_speaker_name: str
559
560
  events: list[LLMMessageType]
560
- verbose: Optional[bool] = False
561
+ verbose: bool | None = False
561
562
 
562
563
  def __init__(
563
564
  self,
564
565
  *,
565
- uuid: Optional[UUID] = None,
566
+ uuid: UUID | None = None,
566
567
  last_speaker_name: str,
567
568
  events: list["LLMMessageType"],
568
- silent: Optional[bool] = False,
569
+ silent: bool | None = False,
569
570
  ):
570
571
  super().__init__(uuid=uuid, last_speaker_name=last_speaker_name, events=events, verbose=not silent)
571
572
 
@@ -578,7 +579,7 @@ class GroupChatResumeEvent(BaseEvent):
578
579
  "silent": not self.verbose,
579
580
  }
580
581
 
581
- def print(self, f: Optional[Callable[..., Any]] = None) -> None:
582
+ def print(self, f: Callable[..., Any] | None = None) -> None:
582
583
  f = f or print
583
584
 
584
585
  f(
@@ -591,16 +592,16 @@ class GroupChatResumeEvent(BaseEvent):
591
592
  @wrap_event
592
593
  class GroupChatRunChatEvent(BaseEvent):
593
594
  speaker: str
594
- verbose: Optional[bool] = False
595
+ verbose: bool | None = False
595
596
 
596
- def __init__(self, *, uuid: Optional[UUID] = None, speaker: Union["Agent", str], silent: Optional[bool] = False):
597
+ def __init__(self, *, uuid: UUID | None = None, speaker: Union["Agent", str], silent: bool | None = False):
597
598
  super().__init__(uuid=uuid, speaker=speaker.name if hasattr(speaker, "name") else speaker, verbose=not silent)
598
599
 
599
600
  @model_serializer
600
601
  def serialize_model(self) -> dict[str, Any]:
601
602
  return {"uuid": self.uuid, "speaker": self.speaker, "silent": not self.verbose}
602
603
 
603
- def print(self, f: Optional[Callable[..., Any]] = None) -> None:
604
+ def print(self, f: Callable[..., Any] | None = None) -> None:
604
605
  f = f or print
605
606
 
606
607
  f(colored(f"\nNext speaker: {self.speaker}\n", "green"), flush=True)
@@ -617,9 +618,9 @@ class TerminationAndHumanReplyNoInputEvent(BaseEvent):
617
618
  def __init__(
618
619
  self,
619
620
  *,
620
- uuid: Optional[UUID] = None,
621
+ uuid: UUID | None = None,
621
622
  no_human_input_msg: str,
622
- sender: Optional[Union["Agent", str]] = None,
623
+ sender: Union["Agent", str] | None = None,
623
624
  recipient: Union["Agent", str],
624
625
  ):
625
626
  sender = sender or "No sender"
@@ -630,7 +631,7 @@ class TerminationAndHumanReplyNoInputEvent(BaseEvent):
630
631
  recipient=recipient.name if hasattr(recipient, "name") else recipient,
631
632
  )
632
633
 
633
- def print(self, f: Optional[Callable[..., Any]] = None) -> None:
634
+ def print(self, f: Callable[..., Any] | None = None) -> None:
634
635
  f = f or print
635
636
 
636
637
  f(colored(f"\n>>>>>>>> {self.no_human_input_msg}", "red"), flush=True)
@@ -645,9 +646,9 @@ class UsingAutoReplyEvent(BaseEvent):
645
646
  def __init__(
646
647
  self,
647
648
  *,
648
- uuid: Optional[UUID] = None,
649
+ uuid: UUID | None = None,
649
650
  human_input_mode: str,
650
- sender: Optional[Union["Agent", str]] = None,
651
+ sender: Union["Agent", str] | None = None,
651
652
  recipient: Union["Agent", str],
652
653
  ):
653
654
  sender = sender or "No sender"
@@ -658,7 +659,7 @@ class UsingAutoReplyEvent(BaseEvent):
658
659
  recipient=recipient.name if hasattr(recipient, "name") else recipient,
659
660
  )
660
661
 
661
- def print(self, f: Optional[Callable[..., Any]] = None) -> None:
662
+ def print(self, f: Callable[..., Any] | None = None) -> None:
662
663
  f = f or print
663
664
 
664
665
  f(colored("\n>>>>>>>> USING AUTO REPLY...", "red"), flush=True)
@@ -670,14 +671,14 @@ class TerminationEvent(BaseEvent):
670
671
 
671
672
  termination_reason: str
672
673
  sender: str
673
- recipient: Optional[str] = None
674
+ recipient: str | None = None
674
675
 
675
676
  def __init__(
676
677
  self,
677
678
  *,
678
- uuid: Optional[UUID] = None,
679
+ uuid: UUID | None = None,
679
680
  sender: Union["Agent", str],
680
- recipient: Optional[Union["Agent", str]] = None,
681
+ recipient: Union["Agent", str] | None = None,
681
682
  termination_reason: str,
682
683
  ):
683
684
  super().__init__(
@@ -687,7 +688,7 @@ class TerminationEvent(BaseEvent):
687
688
  recipient=recipient.name if hasattr(recipient, "name") else recipient if recipient else None,
688
689
  )
689
690
 
690
- def print(self, f: Optional[Callable[..., Any]] = None) -> None:
691
+ def print(self, f: Callable[..., Any] | None = None) -> None:
691
692
  f = f or print
692
693
 
693
694
  f(colored(f"\n>>>>>>>> TERMINATING RUN ({str(self.uuid)}): {self.termination_reason}", "red"), flush=True)
@@ -703,7 +704,7 @@ class ExecuteCodeBlockEvent(BaseEvent):
703
704
  def __init__(
704
705
  self,
705
706
  *,
706
- uuid: Optional[UUID] = None,
707
+ uuid: UUID | None = None,
707
708
  code: str,
708
709
  language: str,
709
710
  code_block_count: int,
@@ -717,7 +718,7 @@ class ExecuteCodeBlockEvent(BaseEvent):
717
718
  recipient=recipient.name if hasattr(recipient, "name") else recipient,
718
719
  )
719
720
 
720
- def print(self, f: Optional[Callable[..., Any]] = None) -> None:
721
+ def print(self, f: Callable[..., Any] | None = None) -> None:
721
722
  f = f or print
722
723
 
723
724
  f(
@@ -732,16 +733,16 @@ class ExecuteCodeBlockEvent(BaseEvent):
732
733
  @wrap_event
733
734
  class ExecuteFunctionEvent(BaseEvent):
734
735
  func_name: str
735
- call_id: Optional[str] = None
736
+ call_id: str | None = None
736
737
  arguments: dict[str, Any]
737
738
  recipient: str
738
739
 
739
740
  def __init__(
740
741
  self,
741
742
  *,
742
- uuid: Optional[UUID] = None,
743
+ uuid: UUID | None = None,
743
744
  func_name: str,
744
- call_id: Optional[str] = None,
745
+ call_id: str | None = None,
745
746
  arguments: dict[str, Any],
746
747
  recipient: Union["Agent", str],
747
748
  ):
@@ -753,7 +754,7 @@ class ExecuteFunctionEvent(BaseEvent):
753
754
  recipient=recipient.name if hasattr(recipient, "name") else recipient,
754
755
  )
755
756
 
756
- def print(self, f: Optional[Callable[..., Any]] = None) -> None:
757
+ def print(self, f: Callable[..., Any] | None = None) -> None:
757
758
  f = f or print
758
759
 
759
760
  f(
@@ -768,8 +769,8 @@ class ExecuteFunctionEvent(BaseEvent):
768
769
  @wrap_event
769
770
  class ExecutedFunctionEvent(BaseEvent):
770
771
  func_name: str
771
- call_id: Optional[str] = None
772
- arguments: Optional[dict[str, Any]]
772
+ call_id: str | None = None
773
+ arguments: dict[str, Any] | None
773
774
  content: Any
774
775
  recipient: str
775
776
  is_exec_success: bool = True
@@ -777,10 +778,10 @@ class ExecutedFunctionEvent(BaseEvent):
777
778
  def __init__(
778
779
  self,
779
780
  *,
780
- uuid: Optional[UUID] = None,
781
+ uuid: UUID | None = None,
781
782
  func_name: str,
782
- call_id: Optional[str] = None,
783
- arguments: Optional[dict[str, Any]],
783
+ call_id: str | None = None,
784
+ arguments: dict[str, Any] | None,
784
785
  content: Any,
785
786
  recipient: Union["Agent", str],
786
787
  is_exec_success: bool = True,
@@ -795,7 +796,7 @@ class ExecutedFunctionEvent(BaseEvent):
795
796
  )
796
797
  self.is_exec_success = is_exec_success
797
798
 
798
- def print(self, f: Optional[Callable[..., Any]] = None) -> None:
799
+ def print(self, f: Callable[..., Any] | None = None) -> None:
799
800
  f = f or print
800
801
 
801
802
  f(
@@ -809,13 +810,13 @@ class ExecutedFunctionEvent(BaseEvent):
809
810
 
810
811
  @wrap_event
811
812
  class SelectSpeakerEvent(BaseEvent):
812
- agents: Optional[list[str]] = None
813
+ agents: list[str] | None = None
813
814
 
814
- def __init__(self, *, uuid: Optional[UUID] = None, agents: Optional[list[Union["Agent", str]]] = None):
815
+ def __init__(self, *, uuid: UUID | None = None, agents: list[Union["Agent", str]] | None = None):
815
816
  agents = [agent.name if hasattr(agent, "name") else agent for agent in agents] if agents else None
816
817
  super().__init__(uuid=uuid, agents=agents)
817
818
 
818
- def print(self, f: Optional[Callable[..., Any]] = None) -> None:
819
+ def print(self, f: Callable[..., Any] | None = None) -> None:
819
820
  f = f or print
820
821
 
821
822
  f("Please select the next speaker from the following list:")
@@ -827,15 +828,13 @@ class SelectSpeakerEvent(BaseEvent):
827
828
  @wrap_event
828
829
  class SelectSpeakerTryCountExceededEvent(BaseEvent):
829
830
  try_count: int
830
- agents: Optional[list[str]] = None
831
+ agents: list[str] | None = None
831
832
 
832
- def __init__(
833
- self, *, uuid: Optional[UUID] = None, try_count: int, agents: Optional[list[Union["Agent", str]]] = None
834
- ):
833
+ def __init__(self, *, uuid: UUID | None = None, try_count: int, agents: list[Union["Agent", str]] | None = None):
835
834
  agents = [agent.name if hasattr(agent, "name") else agent for agent in agents] if agents else None
836
835
  super().__init__(uuid=uuid, try_count=try_count, agents=agents)
837
836
 
838
- def print(self, f: Optional[Callable[..., Any]] = None) -> None:
837
+ def print(self, f: Callable[..., Any] | None = None) -> None:
839
838
  f = f or print
840
839
 
841
840
  f(f"You have tried {self.try_count} times. The next speaker will be selected automatically.")
@@ -843,13 +842,13 @@ class SelectSpeakerTryCountExceededEvent(BaseEvent):
843
842
 
844
843
  @wrap_event
845
844
  class SelectSpeakerInvalidInputEvent(BaseEvent):
846
- agents: Optional[list[str]] = None
845
+ agents: list[str] | None = None
847
846
 
848
- def __init__(self, *, uuid: Optional[UUID] = None, agents: Optional[list[Union["Agent", str]]] = None):
847
+ def __init__(self, *, uuid: UUID | None = None, agents: list[Union["Agent", str]] | None = None):
849
848
  agents = [agent.name if hasattr(agent, "name") else agent for agent in agents] if agents else None
850
849
  super().__init__(uuid=uuid, agents=agents)
851
850
 
852
- def print(self, f: Optional[Callable[..., Any]] = None) -> None:
851
+ def print(self, f: Callable[..., Any] | None = None) -> None:
853
852
  f = f or print
854
853
 
855
854
  f(f"Invalid input. Please enter a number between 1 and {len(self.agents or [])}.")
@@ -861,9 +860,7 @@ class ClearConversableAgentHistoryEvent(BaseEvent):
861
860
  recipient: str
862
861
  no_events_preserved: int
863
862
 
864
- def __init__(
865
- self, *, uuid: Optional[UUID] = None, agent: Union["Agent", str], no_events_preserved: Optional[int] = None
866
- ):
863
+ def __init__(self, *, uuid: UUID | None = None, agent: Union["Agent", str], no_events_preserved: int | None = None):
867
864
  super().__init__(
868
865
  uuid=uuid,
869
866
  agent=agent.name if hasattr(agent, "name") else agent,
@@ -879,7 +876,7 @@ class ClearConversableAgentHistoryEvent(BaseEvent):
879
876
  "no_events_preserved": self.no_events_preserved,
880
877
  }
881
878
 
882
- def print(self, f: Optional[Callable[..., Any]] = None) -> None:
879
+ def print(self, f: Callable[..., Any] | None = None) -> None:
883
880
  f = f or print
884
881
 
885
882
  for _ in range(self.no_events_preserved):
@@ -890,13 +887,13 @@ class ClearConversableAgentHistoryEvent(BaseEvent):
890
887
  class ClearConversableAgentHistoryWarningEvent(BaseEvent):
891
888
  recipient: str
892
889
 
893
- def __init__(self, *, uuid: Optional[UUID] = None, recipient: Union["Agent", str]):
890
+ def __init__(self, *, uuid: UUID | None = None, recipient: Union["Agent", str]):
894
891
  super().__init__(
895
892
  uuid=uuid,
896
893
  recipient=recipient.name if hasattr(recipient, "name") else recipient,
897
894
  )
898
895
 
899
- def print(self, f: Optional[Callable[..., Any]] = None) -> None:
896
+ def print(self, f: Callable[..., Any] | None = None) -> None:
900
897
  f = f or print
901
898
 
902
899
  f(
@@ -917,9 +914,9 @@ class GenerateCodeExecutionReplyEvent(BaseEvent):
917
914
  def __init__(
918
915
  self,
919
916
  *,
920
- uuid: Optional[UUID] = None,
917
+ uuid: UUID | None = None,
921
918
  code_blocks: list[Union["CodeBlock", str]],
922
- sender: Optional[Union["Agent", str]] = None,
919
+ sender: Union["Agent", str] | None = None,
923
920
  recipient: Union["Agent", str],
924
921
  ):
925
922
  code_blocks = [
@@ -934,7 +931,7 @@ class GenerateCodeExecutionReplyEvent(BaseEvent):
934
931
  recipient=recipient.name if hasattr(recipient, "name") else recipient,
935
932
  )
936
933
 
937
- def print(self, f: Optional[Callable[..., Any]] = None) -> None:
934
+ def print(self, f: Callable[..., Any] | None = None) -> None:
938
935
  f = f or print
939
936
 
940
937
  num_code_blocks = len(self.code_blocks)
@@ -960,10 +957,10 @@ class GenerateCodeExecutionReplyEvent(BaseEvent):
960
957
  class ConversableAgentUsageSummaryNoCostIncurredEvent(BaseEvent):
961
958
  recipient: str
962
959
 
963
- def __init__(self, *, uuid: Optional[UUID] = None, recipient: Union["Agent", str]):
960
+ def __init__(self, *, uuid: UUID | None = None, recipient: Union["Agent", str]):
964
961
  super().__init__(uuid=uuid, recipient=recipient.name if hasattr(recipient, "name") else recipient)
965
962
 
966
- def print(self, f: Optional[Callable[..., Any]] = None) -> None:
963
+ def print(self, f: Callable[..., Any] | None = None) -> None:
967
964
  f = f or print
968
965
 
969
966
  f(f"No cost incurred from agent '{self.recipient}'.")
@@ -973,10 +970,10 @@ class ConversableAgentUsageSummaryNoCostIncurredEvent(BaseEvent):
973
970
  class ConversableAgentUsageSummaryEvent(BaseEvent):
974
971
  recipient: str
975
972
 
976
- def __init__(self, *, uuid: Optional[UUID] = None, recipient: Union["Agent", str]):
973
+ def __init__(self, *, uuid: UUID | None = None, recipient: Union["Agent", str]):
977
974
  super().__init__(uuid=uuid, recipient=recipient.name if hasattr(recipient, "name") else recipient)
978
975
 
979
- def print(self, f: Optional[Callable[..., Any]] = None) -> None:
976
+ def print(self, f: Callable[..., Any] | None = None) -> None:
980
977
  f = f or print
981
978
 
982
979
  f(f"Agent '{self.recipient}':")
@@ -986,7 +983,7 @@ class ConversableAgentUsageSummaryEvent(BaseEvent):
986
983
  class InputRequestEvent(BaseEvent):
987
984
  prompt: str
988
985
  password: bool = False
989
- respond: Optional[Callable[[str], None]] = None
986
+ respond: Callable[[str], None] | None = None
990
987
 
991
988
  type: str = "input_request"
992
989
 
@@ -1015,5 +1012,5 @@ class RunCompletionEvent(BaseEvent):
1015
1012
  summary: str
1016
1013
  history: list[LLMMessageType]
1017
1014
  cost: dict[str, Any]
1018
- last_speaker: Optional[str]
1019
- context_variables: Optional[ContextVariables] = None
1015
+ last_speaker: str | None
1016
+ context_variables: ContextVariables | None = None