ag2 0.9.1a1__py3-none-any.whl → 0.9.1.post0__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 (357) hide show
  1. {ag2-0.9.1a1.dist-info → ag2-0.9.1.post0.dist-info}/METADATA +264 -73
  2. ag2-0.9.1.post0.dist-info/RECORD +392 -0
  3. {ag2-0.9.1a1.dist-info → ag2-0.9.1.post0.dist-info}/WHEEL +1 -2
  4. autogen/__init__.py +89 -0
  5. autogen/_website/__init__.py +3 -0
  6. autogen/_website/generate_api_references.py +427 -0
  7. autogen/_website/generate_mkdocs.py +1174 -0
  8. autogen/_website/notebook_processor.py +476 -0
  9. autogen/_website/process_notebooks.py +656 -0
  10. autogen/_website/utils.py +412 -0
  11. autogen/agentchat/__init__.py +44 -0
  12. autogen/agentchat/agent.py +182 -0
  13. autogen/agentchat/assistant_agent.py +85 -0
  14. autogen/agentchat/chat.py +309 -0
  15. autogen/agentchat/contrib/__init__.py +5 -0
  16. autogen/agentchat/contrib/agent_eval/README.md +7 -0
  17. autogen/agentchat/contrib/agent_eval/agent_eval.py +108 -0
  18. autogen/agentchat/contrib/agent_eval/criterion.py +43 -0
  19. autogen/agentchat/contrib/agent_eval/critic_agent.py +44 -0
  20. autogen/agentchat/contrib/agent_eval/quantifier_agent.py +39 -0
  21. autogen/agentchat/contrib/agent_eval/subcritic_agent.py +45 -0
  22. autogen/agentchat/contrib/agent_eval/task.py +42 -0
  23. autogen/agentchat/contrib/agent_optimizer.py +429 -0
  24. autogen/agentchat/contrib/capabilities/__init__.py +5 -0
  25. autogen/agentchat/contrib/capabilities/agent_capability.py +20 -0
  26. autogen/agentchat/contrib/capabilities/generate_images.py +301 -0
  27. autogen/agentchat/contrib/capabilities/teachability.py +393 -0
  28. autogen/agentchat/contrib/capabilities/text_compressors.py +66 -0
  29. autogen/agentchat/contrib/capabilities/tools_capability.py +22 -0
  30. autogen/agentchat/contrib/capabilities/transform_messages.py +93 -0
  31. autogen/agentchat/contrib/capabilities/transforms.py +566 -0
  32. autogen/agentchat/contrib/capabilities/transforms_util.py +122 -0
  33. autogen/agentchat/contrib/capabilities/vision_capability.py +214 -0
  34. autogen/agentchat/contrib/captainagent/__init__.py +9 -0
  35. autogen/agentchat/contrib/captainagent/agent_builder.py +790 -0
  36. autogen/agentchat/contrib/captainagent/captainagent.py +512 -0
  37. autogen/agentchat/contrib/captainagent/tool_retriever.py +335 -0
  38. autogen/agentchat/contrib/captainagent/tools/README.md +44 -0
  39. autogen/agentchat/contrib/captainagent/tools/__init__.py +5 -0
  40. autogen/agentchat/contrib/captainagent/tools/data_analysis/calculate_correlation.py +40 -0
  41. autogen/agentchat/contrib/captainagent/tools/data_analysis/calculate_skewness_and_kurtosis.py +28 -0
  42. autogen/agentchat/contrib/captainagent/tools/data_analysis/detect_outlier_iqr.py +28 -0
  43. autogen/agentchat/contrib/captainagent/tools/data_analysis/detect_outlier_zscore.py +28 -0
  44. autogen/agentchat/contrib/captainagent/tools/data_analysis/explore_csv.py +21 -0
  45. autogen/agentchat/contrib/captainagent/tools/data_analysis/shapiro_wilk_test.py +30 -0
  46. autogen/agentchat/contrib/captainagent/tools/information_retrieval/arxiv_download.py +27 -0
  47. autogen/agentchat/contrib/captainagent/tools/information_retrieval/arxiv_search.py +53 -0
  48. autogen/agentchat/contrib/captainagent/tools/information_retrieval/extract_pdf_image.py +53 -0
  49. autogen/agentchat/contrib/captainagent/tools/information_retrieval/extract_pdf_text.py +38 -0
  50. autogen/agentchat/contrib/captainagent/tools/information_retrieval/get_wikipedia_text.py +21 -0
  51. autogen/agentchat/contrib/captainagent/tools/information_retrieval/get_youtube_caption.py +34 -0
  52. autogen/agentchat/contrib/captainagent/tools/information_retrieval/image_qa.py +60 -0
  53. autogen/agentchat/contrib/captainagent/tools/information_retrieval/optical_character_recognition.py +61 -0
  54. autogen/agentchat/contrib/captainagent/tools/information_retrieval/perform_web_search.py +47 -0
  55. autogen/agentchat/contrib/captainagent/tools/information_retrieval/scrape_wikipedia_tables.py +33 -0
  56. autogen/agentchat/contrib/captainagent/tools/information_retrieval/transcribe_audio_file.py +21 -0
  57. autogen/agentchat/contrib/captainagent/tools/information_retrieval/youtube_download.py +35 -0
  58. autogen/agentchat/contrib/captainagent/tools/math/calculate_circle_area_from_diameter.py +21 -0
  59. autogen/agentchat/contrib/captainagent/tools/math/calculate_day_of_the_week.py +18 -0
  60. autogen/agentchat/contrib/captainagent/tools/math/calculate_fraction_sum.py +28 -0
  61. autogen/agentchat/contrib/captainagent/tools/math/calculate_matrix_power.py +31 -0
  62. autogen/agentchat/contrib/captainagent/tools/math/calculate_reflected_point.py +16 -0
  63. autogen/agentchat/contrib/captainagent/tools/math/complex_numbers_product.py +25 -0
  64. autogen/agentchat/contrib/captainagent/tools/math/compute_currency_conversion.py +23 -0
  65. autogen/agentchat/contrib/captainagent/tools/math/count_distinct_permutations.py +27 -0
  66. autogen/agentchat/contrib/captainagent/tools/math/evaluate_expression.py +28 -0
  67. autogen/agentchat/contrib/captainagent/tools/math/find_continuity_point.py +34 -0
  68. autogen/agentchat/contrib/captainagent/tools/math/fraction_to_mixed_numbers.py +39 -0
  69. autogen/agentchat/contrib/captainagent/tools/math/modular_inverse_sum.py +23 -0
  70. autogen/agentchat/contrib/captainagent/tools/math/simplify_mixed_numbers.py +36 -0
  71. autogen/agentchat/contrib/captainagent/tools/math/sum_of_digit_factorials.py +15 -0
  72. autogen/agentchat/contrib/captainagent/tools/math/sum_of_primes_below.py +15 -0
  73. autogen/agentchat/contrib/captainagent/tools/requirements.txt +10 -0
  74. autogen/agentchat/contrib/captainagent/tools/tool_description.tsv +34 -0
  75. autogen/agentchat/contrib/gpt_assistant_agent.py +526 -0
  76. autogen/agentchat/contrib/graph_rag/__init__.py +9 -0
  77. autogen/agentchat/contrib/graph_rag/document.py +29 -0
  78. autogen/agentchat/contrib/graph_rag/falkor_graph_query_engine.py +170 -0
  79. autogen/agentchat/contrib/graph_rag/falkor_graph_rag_capability.py +103 -0
  80. autogen/agentchat/contrib/graph_rag/graph_query_engine.py +53 -0
  81. autogen/agentchat/contrib/graph_rag/graph_rag_capability.py +63 -0
  82. autogen/agentchat/contrib/graph_rag/neo4j_graph_query_engine.py +268 -0
  83. autogen/agentchat/contrib/graph_rag/neo4j_graph_rag_capability.py +83 -0
  84. autogen/agentchat/contrib/graph_rag/neo4j_native_graph_query_engine.py +210 -0
  85. autogen/agentchat/contrib/graph_rag/neo4j_native_graph_rag_capability.py +93 -0
  86. autogen/agentchat/contrib/img_utils.py +397 -0
  87. autogen/agentchat/contrib/llamaindex_conversable_agent.py +117 -0
  88. autogen/agentchat/contrib/llava_agent.py +187 -0
  89. autogen/agentchat/contrib/math_user_proxy_agent.py +464 -0
  90. autogen/agentchat/contrib/multimodal_conversable_agent.py +125 -0
  91. autogen/agentchat/contrib/qdrant_retrieve_user_proxy_agent.py +324 -0
  92. autogen/agentchat/contrib/rag/__init__.py +10 -0
  93. autogen/agentchat/contrib/rag/chromadb_query_engine.py +272 -0
  94. autogen/agentchat/contrib/rag/llamaindex_query_engine.py +198 -0
  95. autogen/agentchat/contrib/rag/mongodb_query_engine.py +329 -0
  96. autogen/agentchat/contrib/rag/query_engine.py +74 -0
  97. autogen/agentchat/contrib/retrieve_assistant_agent.py +56 -0
  98. autogen/agentchat/contrib/retrieve_user_proxy_agent.py +703 -0
  99. autogen/agentchat/contrib/society_of_mind_agent.py +199 -0
  100. autogen/agentchat/contrib/swarm_agent.py +1425 -0
  101. autogen/agentchat/contrib/text_analyzer_agent.py +79 -0
  102. autogen/agentchat/contrib/vectordb/__init__.py +5 -0
  103. autogen/agentchat/contrib/vectordb/base.py +232 -0
  104. autogen/agentchat/contrib/vectordb/chromadb.py +315 -0
  105. autogen/agentchat/contrib/vectordb/couchbase.py +407 -0
  106. autogen/agentchat/contrib/vectordb/mongodb.py +550 -0
  107. autogen/agentchat/contrib/vectordb/pgvectordb.py +928 -0
  108. autogen/agentchat/contrib/vectordb/qdrant.py +320 -0
  109. autogen/agentchat/contrib/vectordb/utils.py +126 -0
  110. autogen/agentchat/contrib/web_surfer.py +303 -0
  111. autogen/agentchat/conversable_agent.py +4020 -0
  112. autogen/agentchat/group/__init__.py +64 -0
  113. autogen/agentchat/group/available_condition.py +91 -0
  114. autogen/agentchat/group/context_condition.py +77 -0
  115. autogen/agentchat/group/context_expression.py +238 -0
  116. autogen/agentchat/group/context_str.py +41 -0
  117. autogen/agentchat/group/context_variables.py +192 -0
  118. autogen/agentchat/group/group_tool_executor.py +202 -0
  119. autogen/agentchat/group/group_utils.py +591 -0
  120. autogen/agentchat/group/handoffs.py +244 -0
  121. autogen/agentchat/group/llm_condition.py +93 -0
  122. autogen/agentchat/group/multi_agent_chat.py +237 -0
  123. autogen/agentchat/group/on_condition.py +58 -0
  124. autogen/agentchat/group/on_context_condition.py +54 -0
  125. autogen/agentchat/group/patterns/__init__.py +18 -0
  126. autogen/agentchat/group/patterns/auto.py +159 -0
  127. autogen/agentchat/group/patterns/manual.py +176 -0
  128. autogen/agentchat/group/patterns/pattern.py +288 -0
  129. autogen/agentchat/group/patterns/random.py +106 -0
  130. autogen/agentchat/group/patterns/round_robin.py +117 -0
  131. autogen/agentchat/group/reply_result.py +26 -0
  132. autogen/agentchat/group/speaker_selection_result.py +41 -0
  133. autogen/agentchat/group/targets/__init__.py +4 -0
  134. autogen/agentchat/group/targets/group_chat_target.py +132 -0
  135. autogen/agentchat/group/targets/group_manager_target.py +151 -0
  136. autogen/agentchat/group/targets/transition_target.py +413 -0
  137. autogen/agentchat/group/targets/transition_utils.py +6 -0
  138. autogen/agentchat/groupchat.py +1694 -0
  139. autogen/agentchat/realtime/__init__.py +3 -0
  140. autogen/agentchat/realtime/experimental/__init__.py +20 -0
  141. autogen/agentchat/realtime/experimental/audio_adapters/__init__.py +8 -0
  142. autogen/agentchat/realtime/experimental/audio_adapters/twilio_audio_adapter.py +148 -0
  143. autogen/agentchat/realtime/experimental/audio_adapters/websocket_audio_adapter.py +139 -0
  144. autogen/agentchat/realtime/experimental/audio_observer.py +42 -0
  145. autogen/agentchat/realtime/experimental/clients/__init__.py +15 -0
  146. autogen/agentchat/realtime/experimental/clients/gemini/__init__.py +7 -0
  147. autogen/agentchat/realtime/experimental/clients/gemini/client.py +274 -0
  148. autogen/agentchat/realtime/experimental/clients/oai/__init__.py +8 -0
  149. autogen/agentchat/realtime/experimental/clients/oai/base_client.py +220 -0
  150. autogen/agentchat/realtime/experimental/clients/oai/rtc_client.py +243 -0
  151. autogen/agentchat/realtime/experimental/clients/oai/utils.py +48 -0
  152. autogen/agentchat/realtime/experimental/clients/realtime_client.py +190 -0
  153. autogen/agentchat/realtime/experimental/function_observer.py +85 -0
  154. autogen/agentchat/realtime/experimental/realtime_agent.py +158 -0
  155. autogen/agentchat/realtime/experimental/realtime_events.py +42 -0
  156. autogen/agentchat/realtime/experimental/realtime_observer.py +100 -0
  157. autogen/agentchat/realtime/experimental/realtime_swarm.py +475 -0
  158. autogen/agentchat/realtime/experimental/websockets.py +21 -0
  159. autogen/agentchat/realtime_agent/__init__.py +21 -0
  160. autogen/agentchat/user_proxy_agent.py +111 -0
  161. autogen/agentchat/utils.py +206 -0
  162. autogen/agents/__init__.py +3 -0
  163. autogen/agents/contrib/__init__.py +10 -0
  164. autogen/agents/contrib/time/__init__.py +8 -0
  165. autogen/agents/contrib/time/time_reply_agent.py +73 -0
  166. autogen/agents/contrib/time/time_tool_agent.py +51 -0
  167. autogen/agents/experimental/__init__.py +27 -0
  168. autogen/agents/experimental/deep_research/__init__.py +7 -0
  169. autogen/agents/experimental/deep_research/deep_research.py +52 -0
  170. autogen/agents/experimental/discord/__init__.py +7 -0
  171. autogen/agents/experimental/discord/discord.py +66 -0
  172. autogen/agents/experimental/document_agent/__init__.py +19 -0
  173. autogen/agents/experimental/document_agent/chroma_query_engine.py +316 -0
  174. autogen/agents/experimental/document_agent/docling_doc_ingest_agent.py +118 -0
  175. autogen/agents/experimental/document_agent/document_agent.py +461 -0
  176. autogen/agents/experimental/document_agent/document_conditions.py +50 -0
  177. autogen/agents/experimental/document_agent/document_utils.py +380 -0
  178. autogen/agents/experimental/document_agent/inmemory_query_engine.py +220 -0
  179. autogen/agents/experimental/document_agent/parser_utils.py +130 -0
  180. autogen/agents/experimental/document_agent/url_utils.py +426 -0
  181. autogen/agents/experimental/reasoning/__init__.py +7 -0
  182. autogen/agents/experimental/reasoning/reasoning_agent.py +1178 -0
  183. autogen/agents/experimental/slack/__init__.py +7 -0
  184. autogen/agents/experimental/slack/slack.py +73 -0
  185. autogen/agents/experimental/telegram/__init__.py +7 -0
  186. autogen/agents/experimental/telegram/telegram.py +77 -0
  187. autogen/agents/experimental/websurfer/__init__.py +7 -0
  188. autogen/agents/experimental/websurfer/websurfer.py +62 -0
  189. autogen/agents/experimental/wikipedia/__init__.py +7 -0
  190. autogen/agents/experimental/wikipedia/wikipedia.py +90 -0
  191. autogen/browser_utils.py +309 -0
  192. autogen/cache/__init__.py +10 -0
  193. autogen/cache/abstract_cache_base.py +75 -0
  194. autogen/cache/cache.py +203 -0
  195. autogen/cache/cache_factory.py +88 -0
  196. autogen/cache/cosmos_db_cache.py +144 -0
  197. autogen/cache/disk_cache.py +102 -0
  198. autogen/cache/in_memory_cache.py +58 -0
  199. autogen/cache/redis_cache.py +123 -0
  200. autogen/code_utils.py +596 -0
  201. autogen/coding/__init__.py +22 -0
  202. autogen/coding/base.py +119 -0
  203. autogen/coding/docker_commandline_code_executor.py +268 -0
  204. autogen/coding/factory.py +47 -0
  205. autogen/coding/func_with_reqs.py +202 -0
  206. autogen/coding/jupyter/__init__.py +23 -0
  207. autogen/coding/jupyter/base.py +36 -0
  208. autogen/coding/jupyter/docker_jupyter_server.py +167 -0
  209. autogen/coding/jupyter/embedded_ipython_code_executor.py +182 -0
  210. autogen/coding/jupyter/import_utils.py +82 -0
  211. autogen/coding/jupyter/jupyter_client.py +231 -0
  212. autogen/coding/jupyter/jupyter_code_executor.py +160 -0
  213. autogen/coding/jupyter/local_jupyter_server.py +172 -0
  214. autogen/coding/local_commandline_code_executor.py +405 -0
  215. autogen/coding/markdown_code_extractor.py +45 -0
  216. autogen/coding/utils.py +56 -0
  217. autogen/doc_utils.py +34 -0
  218. autogen/events/__init__.py +7 -0
  219. autogen/events/agent_events.py +1010 -0
  220. autogen/events/base_event.py +99 -0
  221. autogen/events/client_events.py +167 -0
  222. autogen/events/helpers.py +36 -0
  223. autogen/events/print_event.py +46 -0
  224. autogen/exception_utils.py +73 -0
  225. autogen/extensions/__init__.py +5 -0
  226. autogen/fast_depends/__init__.py +16 -0
  227. autogen/fast_depends/_compat.py +80 -0
  228. autogen/fast_depends/core/__init__.py +14 -0
  229. autogen/fast_depends/core/build.py +225 -0
  230. autogen/fast_depends/core/model.py +576 -0
  231. autogen/fast_depends/dependencies/__init__.py +15 -0
  232. autogen/fast_depends/dependencies/model.py +29 -0
  233. autogen/fast_depends/dependencies/provider.py +39 -0
  234. autogen/fast_depends/library/__init__.py +10 -0
  235. autogen/fast_depends/library/model.py +46 -0
  236. autogen/fast_depends/py.typed +6 -0
  237. autogen/fast_depends/schema.py +66 -0
  238. autogen/fast_depends/use.py +280 -0
  239. autogen/fast_depends/utils.py +187 -0
  240. autogen/formatting_utils.py +83 -0
  241. autogen/function_utils.py +13 -0
  242. autogen/graph_utils.py +178 -0
  243. autogen/import_utils.py +526 -0
  244. autogen/interop/__init__.py +22 -0
  245. autogen/interop/crewai/__init__.py +7 -0
  246. autogen/interop/crewai/crewai.py +88 -0
  247. autogen/interop/interoperability.py +71 -0
  248. autogen/interop/interoperable.py +46 -0
  249. autogen/interop/langchain/__init__.py +8 -0
  250. autogen/interop/langchain/langchain_chat_model_factory.py +155 -0
  251. autogen/interop/langchain/langchain_tool.py +82 -0
  252. autogen/interop/litellm/__init__.py +7 -0
  253. autogen/interop/litellm/litellm_config_factory.py +113 -0
  254. autogen/interop/pydantic_ai/__init__.py +7 -0
  255. autogen/interop/pydantic_ai/pydantic_ai.py +168 -0
  256. autogen/interop/registry.py +69 -0
  257. autogen/io/__init__.py +15 -0
  258. autogen/io/base.py +151 -0
  259. autogen/io/console.py +56 -0
  260. autogen/io/processors/__init__.py +12 -0
  261. autogen/io/processors/base.py +21 -0
  262. autogen/io/processors/console_event_processor.py +56 -0
  263. autogen/io/run_response.py +293 -0
  264. autogen/io/thread_io_stream.py +63 -0
  265. autogen/io/websockets.py +213 -0
  266. autogen/json_utils.py +43 -0
  267. autogen/llm_config.py +379 -0
  268. autogen/logger/__init__.py +11 -0
  269. autogen/logger/base_logger.py +128 -0
  270. autogen/logger/file_logger.py +261 -0
  271. autogen/logger/logger_factory.py +42 -0
  272. autogen/logger/logger_utils.py +57 -0
  273. autogen/logger/sqlite_logger.py +523 -0
  274. autogen/math_utils.py +339 -0
  275. autogen/mcp/__init__.py +7 -0
  276. autogen/mcp/mcp_client.py +208 -0
  277. autogen/messages/__init__.py +7 -0
  278. autogen/messages/agent_messages.py +948 -0
  279. autogen/messages/base_message.py +107 -0
  280. autogen/messages/client_messages.py +171 -0
  281. autogen/messages/print_message.py +49 -0
  282. autogen/oai/__init__.py +53 -0
  283. autogen/oai/anthropic.py +714 -0
  284. autogen/oai/bedrock.py +628 -0
  285. autogen/oai/cerebras.py +299 -0
  286. autogen/oai/client.py +1435 -0
  287. autogen/oai/client_utils.py +169 -0
  288. autogen/oai/cohere.py +479 -0
  289. autogen/oai/gemini.py +990 -0
  290. autogen/oai/gemini_types.py +129 -0
  291. autogen/oai/groq.py +305 -0
  292. autogen/oai/mistral.py +303 -0
  293. autogen/oai/oai_models/__init__.py +11 -0
  294. autogen/oai/oai_models/_models.py +16 -0
  295. autogen/oai/oai_models/chat_completion.py +87 -0
  296. autogen/oai/oai_models/chat_completion_audio.py +32 -0
  297. autogen/oai/oai_models/chat_completion_message.py +86 -0
  298. autogen/oai/oai_models/chat_completion_message_tool_call.py +37 -0
  299. autogen/oai/oai_models/chat_completion_token_logprob.py +63 -0
  300. autogen/oai/oai_models/completion_usage.py +60 -0
  301. autogen/oai/ollama.py +643 -0
  302. autogen/oai/openai_utils.py +881 -0
  303. autogen/oai/together.py +370 -0
  304. autogen/retrieve_utils.py +491 -0
  305. autogen/runtime_logging.py +160 -0
  306. autogen/token_count_utils.py +267 -0
  307. autogen/tools/__init__.py +20 -0
  308. autogen/tools/contrib/__init__.py +9 -0
  309. autogen/tools/contrib/time/__init__.py +7 -0
  310. autogen/tools/contrib/time/time.py +41 -0
  311. autogen/tools/dependency_injection.py +254 -0
  312. autogen/tools/experimental/__init__.py +43 -0
  313. autogen/tools/experimental/browser_use/__init__.py +7 -0
  314. autogen/tools/experimental/browser_use/browser_use.py +161 -0
  315. autogen/tools/experimental/crawl4ai/__init__.py +7 -0
  316. autogen/tools/experimental/crawl4ai/crawl4ai.py +153 -0
  317. autogen/tools/experimental/deep_research/__init__.py +7 -0
  318. autogen/tools/experimental/deep_research/deep_research.py +328 -0
  319. autogen/tools/experimental/duckduckgo/__init__.py +7 -0
  320. autogen/tools/experimental/duckduckgo/duckduckgo_search.py +109 -0
  321. autogen/tools/experimental/google/__init__.py +14 -0
  322. autogen/tools/experimental/google/authentication/__init__.py +11 -0
  323. autogen/tools/experimental/google/authentication/credentials_hosted_provider.py +43 -0
  324. autogen/tools/experimental/google/authentication/credentials_local_provider.py +91 -0
  325. autogen/tools/experimental/google/authentication/credentials_provider.py +35 -0
  326. autogen/tools/experimental/google/drive/__init__.py +9 -0
  327. autogen/tools/experimental/google/drive/drive_functions.py +124 -0
  328. autogen/tools/experimental/google/drive/toolkit.py +88 -0
  329. autogen/tools/experimental/google/model.py +17 -0
  330. autogen/tools/experimental/google/toolkit_protocol.py +19 -0
  331. autogen/tools/experimental/google_search/__init__.py +8 -0
  332. autogen/tools/experimental/google_search/google_search.py +93 -0
  333. autogen/tools/experimental/google_search/youtube_search.py +181 -0
  334. autogen/tools/experimental/messageplatform/__init__.py +17 -0
  335. autogen/tools/experimental/messageplatform/discord/__init__.py +7 -0
  336. autogen/tools/experimental/messageplatform/discord/discord.py +288 -0
  337. autogen/tools/experimental/messageplatform/slack/__init__.py +7 -0
  338. autogen/tools/experimental/messageplatform/slack/slack.py +391 -0
  339. autogen/tools/experimental/messageplatform/telegram/__init__.py +7 -0
  340. autogen/tools/experimental/messageplatform/telegram/telegram.py +275 -0
  341. autogen/tools/experimental/perplexity/__init__.py +7 -0
  342. autogen/tools/experimental/perplexity/perplexity_search.py +260 -0
  343. autogen/tools/experimental/tavily/__init__.py +7 -0
  344. autogen/tools/experimental/tavily/tavily_search.py +183 -0
  345. autogen/tools/experimental/web_search_preview/__init__.py +7 -0
  346. autogen/tools/experimental/web_search_preview/web_search_preview.py +114 -0
  347. autogen/tools/experimental/wikipedia/__init__.py +7 -0
  348. autogen/tools/experimental/wikipedia/wikipedia.py +287 -0
  349. autogen/tools/function_utils.py +411 -0
  350. autogen/tools/tool.py +187 -0
  351. autogen/tools/toolkit.py +86 -0
  352. autogen/types.py +29 -0
  353. autogen/version.py +7 -0
  354. ag2-0.9.1a1.dist-info/RECORD +0 -6
  355. ag2-0.9.1a1.dist-info/top_level.txt +0 -1
  356. {ag2-0.9.1a1.dist-info → ag2-0.9.1.post0.dist-info/licenses}/LICENSE +0 -0
  357. {ag2-0.9.1a1.dist-info → ag2-0.9.1.post0.dist-info/licenses}/NOTICE.md +0 -0
@@ -0,0 +1,948 @@
1
+ # Copyright (c) 2023 - 2025, AG2ai, Inc., AG2ai open-source projects maintainers and core contributors
2
+ #
3
+ # SPDX-License-Identifier: Apache-2.0
4
+
5
+ from abc import ABC
6
+ from copy import deepcopy
7
+ from typing import TYPE_CHECKING, Any, Callable, Literal, Optional, Union
8
+ from uuid import UUID
9
+
10
+ from pydantic import BaseModel, field_validator
11
+ from termcolor import colored
12
+
13
+ from ..agentchat.agent import LLMMessageType
14
+ from ..code_utils import content_str
15
+ from ..events import deprecated_by
16
+ from ..events.agent_events import (
17
+ ClearAgentsHistoryEvent,
18
+ ClearConversableAgentHistoryEvent,
19
+ ClearConversableAgentHistoryWarningEvent,
20
+ ConversableAgentUsageSummaryEvent,
21
+ ConversableAgentUsageSummaryNoCostIncurredEvent,
22
+ ExecuteCodeBlockEvent,
23
+ ExecuteFunctionEvent,
24
+ ExecutedFunctionEvent,
25
+ FunctionCallEvent,
26
+ FunctionResponseEvent,
27
+ GenerateCodeExecutionReplyEvent,
28
+ GroupChatResumeEvent,
29
+ GroupChatRunChatEvent,
30
+ PostCarryoverProcessingEvent,
31
+ SelectSpeakerEvent,
32
+ SelectSpeakerInvalidInputEvent,
33
+ SelectSpeakerTryCountExceededEvent,
34
+ SpeakerAttemptFailedMultipleAgentsEvent,
35
+ SpeakerAttemptFailedNoAgentsEvent,
36
+ SpeakerAttemptSuccessfulEvent,
37
+ TerminationAndHumanReplyNoInputEvent,
38
+ TerminationEvent,
39
+ TextEvent,
40
+ ToolCallEvent,
41
+ ToolResponseEvent,
42
+ UsingAutoReplyEvent,
43
+ )
44
+ from ..import_utils import optional_import_block, require_optional_import
45
+ from ..oai.client import OpenAIWrapper
46
+ from .base_message import BaseMessage, wrap_message
47
+
48
+ with optional_import_block() as result:
49
+ from PIL.Image import Image
50
+
51
+ IS_PIL_AVAILABLE = result.is_successful
52
+
53
+ if TYPE_CHECKING:
54
+ from ..agentchat.agent import Agent
55
+ from ..coding.base import CodeBlock
56
+
57
+
58
+ __all__ = [
59
+ "ClearAgentsHistoryMessage",
60
+ "ClearConversableAgentHistoryMessage",
61
+ "ConversableAgentUsageSummaryMessage",
62
+ "ConversableAgentUsageSummaryNoCostIncurredMessage",
63
+ "ExecuteCodeBlockMessage",
64
+ "ExecuteFunctionMessage",
65
+ "FunctionCallMessage",
66
+ "FunctionResponseMessage",
67
+ "GenerateCodeExecutionReplyMessage",
68
+ "GroupChatResumeMessage",
69
+ "GroupChatRunChatMessage",
70
+ "PostCarryoverProcessingMessage",
71
+ "SelectSpeakerMessage",
72
+ "SpeakerAttemptFailedMultipleAgentsMessage",
73
+ "SpeakerAttemptFailedNoAgentsMessage",
74
+ "SpeakerAttemptSuccessfulMessage",
75
+ "TerminationAndHumanReplyNoInputMessage",
76
+ "TerminationMessage",
77
+ "TextMessage",
78
+ "ToolCallMessage",
79
+ "ToolResponseMessage",
80
+ ]
81
+
82
+ MessageRole = Literal["assistant", "function", "tool"]
83
+
84
+
85
+ class BasePrintReceivedMessage(BaseMessage, ABC):
86
+ content: Union[str, int, float, bool]
87
+ sender_name: str
88
+ recipient_name: str
89
+
90
+ def print(self, f: Optional[Callable[..., Any]] = None) -> None:
91
+ f = f or print
92
+ f(f"{colored(self.sender_name, 'yellow')} (to {self.recipient_name}):\n", flush=True)
93
+
94
+
95
+ @deprecated_by(FunctionResponseEvent, param_mapping={"sender_name": "sender", "recipient_name": "recipient"})
96
+ @wrap_message
97
+ class FunctionResponseMessage(BasePrintReceivedMessage):
98
+ name: Optional[str] = None
99
+ role: MessageRole = "function"
100
+ content: Union[str, int, float, bool]
101
+
102
+ def print(self, f: Optional[Callable[..., Any]] = None) -> None:
103
+ f = f or print
104
+ super().print(f)
105
+
106
+ id = self.name or "No id found"
107
+ func_print = f"***** Response from calling {self.role} ({id}) *****"
108
+ f(colored(func_print, "green"), flush=True)
109
+ f(self.content, flush=True)
110
+ f(colored("*" * len(func_print), "green"), flush=True)
111
+
112
+ f("\n", "-" * 80, flush=True, sep="")
113
+
114
+
115
+ class ToolResponse(BaseModel):
116
+ tool_call_id: Optional[str] = None
117
+ role: MessageRole = "tool"
118
+ content: Union[str, int, float, bool]
119
+
120
+ def print(self, f: Optional[Callable[..., Any]] = None) -> None:
121
+ f = f or print
122
+ id = self.tool_call_id or "No id found"
123
+ tool_print = f"***** Response from calling {self.role} ({id}) *****"
124
+ f(colored(tool_print, "green"), flush=True)
125
+ f(self.content, flush=True)
126
+ f(colored("*" * len(tool_print), "green"), flush=True)
127
+
128
+
129
+ @deprecated_by(ToolResponseEvent, param_mapping={"sender_name": "sender", "recipient_name": "recipient"})
130
+ @wrap_message
131
+ class ToolResponseMessage(BasePrintReceivedMessage):
132
+ role: MessageRole = "tool"
133
+ tool_responses: list[ToolResponse]
134
+ content: Union[str, int, float, bool]
135
+
136
+ def print(self, f: Optional[Callable[..., Any]] = None) -> None:
137
+ f = f or print
138
+ super().print(f)
139
+
140
+ for tool_response in self.tool_responses:
141
+ tool_response.print(f)
142
+ f("\n", "-" * 80, flush=True, sep="")
143
+
144
+
145
+ class FunctionCall(BaseModel):
146
+ name: Optional[str] = None
147
+ arguments: Optional[str] = None
148
+
149
+ def print(self, f: Optional[Callable[..., Any]] = None) -> None:
150
+ f = f or print
151
+
152
+ name = self.name or "(No function name found)"
153
+ arguments = self.arguments or "(No arguments found)"
154
+
155
+ func_print = f"***** Suggested function call: {name} *****"
156
+ f(colored(func_print, "green"), flush=True)
157
+ f(
158
+ "Arguments: \n",
159
+ arguments,
160
+ flush=True,
161
+ sep="",
162
+ )
163
+ f(colored("*" * len(func_print), "green"), flush=True)
164
+
165
+
166
+ @deprecated_by(FunctionCallEvent, param_mapping={"sender_name": "sender", "recipient_name": "recipient"})
167
+ @wrap_message
168
+ class FunctionCallMessage(BasePrintReceivedMessage):
169
+ content: Optional[Union[str, int, float, bool]] = None # type: ignore [assignment]
170
+ function_call: FunctionCall
171
+
172
+ def print(self, f: Optional[Callable[..., Any]] = None) -> None:
173
+ f = f or print
174
+ super().print(f)
175
+
176
+ if self.content is not None:
177
+ f(self.content, flush=True)
178
+
179
+ self.function_call.print(f)
180
+
181
+ f("\n", "-" * 80, flush=True, sep="")
182
+
183
+
184
+ class ToolCall(BaseModel):
185
+ id: Optional[str] = None
186
+ function: FunctionCall
187
+ type: str
188
+
189
+ def print(self, f: Optional[Callable[..., Any]] = None) -> None:
190
+ f = f or print
191
+
192
+ id = self.id or "No tool call id found"
193
+
194
+ name = self.function.name or "(No function name found)"
195
+ arguments = self.function.arguments or "(No arguments found)"
196
+
197
+ func_print = f"***** Suggested tool call ({id}): {name} *****"
198
+ f(colored(func_print, "green"), flush=True)
199
+ f(
200
+ "Arguments: \n",
201
+ arguments,
202
+ flush=True,
203
+ sep="",
204
+ )
205
+ f(colored("*" * len(func_print), "green"), flush=True)
206
+
207
+
208
+ @deprecated_by(ToolCallEvent, param_mapping={"sender_name": "sender", "recipient_name": "recipient"})
209
+ @wrap_message
210
+ class ToolCallMessage(BasePrintReceivedMessage):
211
+ content: Optional[Union[str, int, float, bool]] = None # type: ignore [assignment]
212
+ refusal: Optional[str] = None
213
+ role: Optional[MessageRole] = None
214
+ audio: Optional[str] = None
215
+ function_call: Optional[FunctionCall] = None
216
+ tool_calls: list[ToolCall]
217
+
218
+ def print(self, f: Optional[Callable[..., Any]] = None) -> None:
219
+ f = f or print
220
+ super().print(f)
221
+
222
+ if self.content is not None:
223
+ f(self.content, flush=True)
224
+
225
+ for tool_call in self.tool_calls:
226
+ tool_call.print(f)
227
+
228
+ f("\n", "-" * 80, flush=True, sep="")
229
+
230
+
231
+ @deprecated_by(TextEvent, param_mapping={"sender_name": "sender", "recipient_name": "recipient"})
232
+ @wrap_message
233
+ class TextMessage(BasePrintReceivedMessage):
234
+ content: Optional[Union[str, int, float, bool, list[dict[str, Union[str, dict[str, Any]]]]]] = None # type: ignore [assignment]
235
+
236
+ @classmethod
237
+ @require_optional_import("PIL", "unknown")
238
+ def _replace_pil_image_with_placeholder(cls, image_url: dict[str, Any]) -> None:
239
+ if "url" in image_url and isinstance(image_url["url"], Image):
240
+ image_url["url"] = "<image>"
241
+
242
+ @field_validator("content", mode="before")
243
+ @classmethod
244
+ def validate_and_encode_content(
245
+ cls, content: Optional[Union[str, int, float, bool, list[dict[str, Union[str, dict[str, Any]]]]]]
246
+ ) -> Optional[Union[str, int, float, bool, list[dict[str, Union[str, dict[str, Any]]]]]]:
247
+ if not IS_PIL_AVAILABLE:
248
+ return content
249
+
250
+ if not isinstance(content, list):
251
+ return content
252
+
253
+ for item in content:
254
+ if isinstance(item, dict) and "image_url" in item and isinstance(item["image_url"], dict):
255
+ cls._replace_pil_image_with_placeholder(item["image_url"])
256
+
257
+ return content
258
+
259
+ def print(self, f: Optional[Callable[..., Any]] = None) -> None:
260
+ f = f or print
261
+ super().print(f)
262
+
263
+ if self.content is not None:
264
+ f(content_str(self.content), flush=True) # type: ignore [arg-type]
265
+
266
+ f("\n", "-" * 80, flush=True, sep="")
267
+
268
+
269
+ def create_received_message_model(
270
+ *, uuid: Optional[UUID] = None, message: dict[str, Any], sender: "Agent", recipient: "Agent"
271
+ ) -> Union[FunctionResponseMessage, ToolResponseMessage, FunctionCallMessage, ToolCallMessage, TextMessage]:
272
+ # print(f"{message=}")
273
+ # print(f"{sender=}")
274
+
275
+ role = message.get("role")
276
+ if role == "function":
277
+ return FunctionResponseMessage(**message, sender_name=sender.name, recipient_name=recipient.name, uuid=uuid)
278
+ if role == "tool":
279
+ return ToolResponseMessage(**message, sender_name=sender.name, recipient_name=recipient.name, uuid=uuid)
280
+
281
+ # Role is neither function nor tool
282
+
283
+ if message.get("function_call"):
284
+ return FunctionCallMessage(
285
+ **message,
286
+ sender_name=sender.name,
287
+ recipient_name=recipient.name,
288
+ uuid=uuid,
289
+ )
290
+
291
+ if message.get("tool_calls"):
292
+ return ToolCallMessage(
293
+ **message,
294
+ sender_name=sender.name,
295
+ recipient_name=recipient.name,
296
+ uuid=uuid,
297
+ )
298
+
299
+ # Now message is a simple content message
300
+ content = message.get("content")
301
+ allow_format_str_template = (
302
+ recipient.llm_config.get("allow_format_str_template", False) if recipient.llm_config else False # type: ignore [attr-defined]
303
+ )
304
+ if content is not None and "context" in message:
305
+ content = OpenAIWrapper.instantiate(
306
+ content, # type: ignore [arg-type]
307
+ message["context"],
308
+ allow_format_str_template,
309
+ )
310
+
311
+ return TextMessage(
312
+ content=content,
313
+ sender_name=sender.name,
314
+ recipient_name=recipient.name,
315
+ uuid=uuid,
316
+ )
317
+
318
+
319
+ @deprecated_by(PostCarryoverProcessingEvent, param_mapping={"sender_name": "sender", "recipient_name": "recipient"})
320
+ @wrap_message
321
+ class PostCarryoverProcessingMessage(BaseMessage):
322
+ carryover: Union[str, list[Union[str, dict[str, Any], Any]]]
323
+ message: str
324
+ verbose: bool = False
325
+
326
+ sender_name: str
327
+ recipient_name: str
328
+ summary_method: str
329
+ summary_args: Optional[dict[str, Any]] = None
330
+ max_turns: Optional[int] = None
331
+
332
+ def __init__(self, *, uuid: Optional[UUID] = None, chat_info: dict[str, Any]):
333
+ carryover = chat_info.get("carryover", "")
334
+ message = chat_info.get("message")
335
+ verbose = chat_info.get("verbose", False)
336
+
337
+ sender_name = chat_info["sender"].name
338
+ recipient_name = chat_info["recipient"].name
339
+ summary_args = chat_info.get("summary_args")
340
+ max_turns = chat_info.get("max_turns")
341
+
342
+ # Fix Callable in chat_info
343
+ summary_method = chat_info.get("summary_method", "")
344
+ if callable(summary_method):
345
+ summary_method = summary_method.__name__
346
+
347
+ print_message = ""
348
+ if isinstance(message, str):
349
+ print_message = message
350
+ elif callable(message):
351
+ print_message = "Callable: " + message.__name__
352
+ elif isinstance(message, dict):
353
+ print_message = "Dict: " + str(message)
354
+ elif message is None:
355
+ print_message = "None"
356
+
357
+ super().__init__(
358
+ uuid=uuid,
359
+ carryover=carryover,
360
+ message=print_message,
361
+ verbose=verbose,
362
+ summary_method=summary_method,
363
+ summary_args=summary_args,
364
+ max_turns=max_turns,
365
+ sender_name=sender_name,
366
+ recipient_name=recipient_name,
367
+ )
368
+
369
+ def _process_carryover(self) -> str:
370
+ if not isinstance(self.carryover, list):
371
+ return self.carryover
372
+
373
+ print_carryover = []
374
+ for carryover_item in self.carryover:
375
+ if isinstance(carryover_item, str):
376
+ print_carryover.append(carryover_item)
377
+ elif isinstance(carryover_item, dict) and "content" in carryover_item:
378
+ print_carryover.append(str(carryover_item["content"]))
379
+ else:
380
+ print_carryover.append(str(carryover_item))
381
+
382
+ return ("\n").join(print_carryover)
383
+
384
+ def print(self, f: Optional[Callable[..., Any]] = None) -> None:
385
+ f = f or print
386
+
387
+ print_carryover = self._process_carryover()
388
+
389
+ f(colored("\n" + "*" * 80, "blue"), flush=True, sep="")
390
+ f(
391
+ colored(
392
+ "Starting a new chat....",
393
+ "blue",
394
+ ),
395
+ flush=True,
396
+ )
397
+ if self.verbose:
398
+ f(colored("Message:\n" + self.message, "blue"), flush=True)
399
+ f(colored("Carryover:\n" + print_carryover, "blue"), flush=True)
400
+ f(colored("\n" + "*" * 80, "blue"), flush=True, sep="")
401
+
402
+
403
+ @deprecated_by(ClearAgentsHistoryEvent, param_mapping={"nr_messages_to_preserve": "nr_events_to_preserve"})
404
+ @wrap_message
405
+ class ClearAgentsHistoryMessage(BaseMessage):
406
+ agent_name: Optional[str] = None
407
+ nr_messages_to_preserve: Optional[int] = None
408
+
409
+ def __init__(
410
+ self,
411
+ *,
412
+ uuid: Optional[UUID] = None,
413
+ agent: Optional["Agent"] = None,
414
+ nr_messages_to_preserve: Optional[int] = None,
415
+ ):
416
+ return super().__init__(
417
+ uuid=uuid, agent_name=agent.name if agent else None, nr_messages_to_preserve=nr_messages_to_preserve
418
+ )
419
+
420
+ def print(self, f: Optional[Callable[..., Any]] = None) -> None:
421
+ f = f or print
422
+
423
+ if self.agent_name:
424
+ if self.nr_messages_to_preserve:
425
+ f(f"Clearing history for {self.agent_name} except last {self.nr_messages_to_preserve} messages.")
426
+ else:
427
+ f(f"Clearing history for {self.agent_name}.")
428
+ else:
429
+ if self.nr_messages_to_preserve:
430
+ f(f"Clearing history for all agents except last {self.nr_messages_to_preserve} messages.")
431
+ else:
432
+ f("Clearing history for all agents.")
433
+
434
+
435
+ # todo: break into multiple messages
436
+ @deprecated_by(SpeakerAttemptSuccessfulEvent)
437
+ @wrap_message
438
+ class SpeakerAttemptSuccessfulMessage(BaseMessage):
439
+ mentions: dict[str, int]
440
+ attempt: int
441
+ attempts_left: int
442
+ verbose: Optional[bool] = False
443
+
444
+ def __init__(
445
+ self,
446
+ *,
447
+ uuid: Optional[UUID] = None,
448
+ mentions: dict[str, int],
449
+ attempt: int,
450
+ attempts_left: int,
451
+ select_speaker_auto_verbose: Optional[bool] = False,
452
+ ):
453
+ super().__init__(
454
+ uuid=uuid,
455
+ mentions=deepcopy(mentions),
456
+ attempt=attempt,
457
+ attempts_left=attempts_left,
458
+ verbose=select_speaker_auto_verbose,
459
+ )
460
+
461
+ def print(self, f: Optional[Callable[..., Any]] = None) -> None:
462
+ f = f or print
463
+
464
+ selected_agent_name = next(iter(self.mentions))
465
+ f(
466
+ colored(
467
+ f">>>>>>>> Select speaker attempt {self.attempt} of {self.attempt + self.attempts_left} successfully selected: {selected_agent_name}",
468
+ "green",
469
+ ),
470
+ flush=True,
471
+ )
472
+
473
+
474
+ @deprecated_by(SpeakerAttemptFailedMultipleAgentsEvent)
475
+ @wrap_message
476
+ class SpeakerAttemptFailedMultipleAgentsMessage(BaseMessage):
477
+ mentions: dict[str, int]
478
+ attempt: int
479
+ attempts_left: int
480
+ verbose: Optional[bool] = False
481
+
482
+ def __init__(
483
+ self,
484
+ *,
485
+ uuid: Optional[UUID] = None,
486
+ mentions: dict[str, int],
487
+ attempt: int,
488
+ attempts_left: int,
489
+ select_speaker_auto_verbose: Optional[bool] = False,
490
+ ):
491
+ super().__init__(
492
+ uuid=uuid,
493
+ mentions=deepcopy(mentions),
494
+ attempt=attempt,
495
+ attempts_left=attempts_left,
496
+ verbose=select_speaker_auto_verbose,
497
+ )
498
+
499
+ def print(self, f: Optional[Callable[..., Any]] = None) -> None:
500
+ f = f or print
501
+
502
+ f(
503
+ colored(
504
+ f">>>>>>>> Select speaker attempt {self.attempt} of {self.attempt + self.attempts_left} failed as it included multiple agent names.",
505
+ "red",
506
+ ),
507
+ flush=True,
508
+ )
509
+
510
+
511
+ @deprecated_by(SpeakerAttemptFailedNoAgentsEvent)
512
+ @wrap_message
513
+ class SpeakerAttemptFailedNoAgentsMessage(BaseMessage):
514
+ mentions: dict[str, int]
515
+ attempt: int
516
+ attempts_left: int
517
+ verbose: Optional[bool] = False
518
+
519
+ def __init__(
520
+ self,
521
+ *,
522
+ uuid: Optional[UUID] = None,
523
+ mentions: dict[str, int],
524
+ attempt: int,
525
+ attempts_left: int,
526
+ select_speaker_auto_verbose: Optional[bool] = False,
527
+ ):
528
+ super().__init__(
529
+ uuid=uuid,
530
+ mentions=deepcopy(mentions),
531
+ attempt=attempt,
532
+ attempts_left=attempts_left,
533
+ verbose=select_speaker_auto_verbose,
534
+ )
535
+
536
+ def print(self, f: Optional[Callable[..., Any]] = None) -> None:
537
+ f = f or print
538
+
539
+ f(
540
+ colored(
541
+ f">>>>>>>> Select speaker attempt #{self.attempt} failed as it did not include any agent names.",
542
+ "red",
543
+ ),
544
+ flush=True,
545
+ )
546
+
547
+
548
+ @deprecated_by(GroupChatResumeEvent, param_mapping={"messages": "events"})
549
+ @wrap_message
550
+ class GroupChatResumeMessage(BaseMessage):
551
+ last_speaker_name: str
552
+ messages: list[LLMMessageType]
553
+ verbose: Optional[bool] = False
554
+
555
+ def __init__(
556
+ self,
557
+ *,
558
+ uuid: Optional[UUID] = None,
559
+ last_speaker_name: str,
560
+ messages: list["LLMMessageType"],
561
+ silent: Optional[bool] = False,
562
+ ):
563
+ super().__init__(uuid=uuid, last_speaker_name=last_speaker_name, messages=messages, verbose=not silent)
564
+
565
+ def print(self, f: Optional[Callable[..., Any]] = None) -> None:
566
+ f = f or print
567
+
568
+ f(
569
+ f"Prepared group chat with {len(self.messages)} messages, the last speaker is",
570
+ colored(self.last_speaker_name, "yellow"),
571
+ flush=True,
572
+ )
573
+
574
+
575
+ @deprecated_by(GroupChatRunChatEvent)
576
+ @wrap_message
577
+ class GroupChatRunChatMessage(BaseMessage):
578
+ speaker_name: str
579
+ verbose: Optional[bool] = False
580
+
581
+ def __init__(self, *, uuid: Optional[UUID] = None, speaker: "Agent", silent: Optional[bool] = False):
582
+ super().__init__(uuid=uuid, speaker_name=speaker.name, verbose=not silent)
583
+
584
+ def print(self, f: Optional[Callable[..., Any]] = None) -> None:
585
+ f = f or print
586
+
587
+ f(colored(f"\nNext speaker: {self.speaker_name}\n", "green"), flush=True)
588
+
589
+
590
+ @deprecated_by(
591
+ TerminationAndHumanReplyNoInputEvent, param_mapping={"sender_name": "sender", "recipient_name": "recipient"}
592
+ )
593
+ @wrap_message
594
+ class TerminationAndHumanReplyNoInputMessage(BaseMessage):
595
+ """When the human-in-the-loop is prompted but provides no input."""
596
+
597
+ no_human_input_msg: str
598
+ sender_name: str
599
+ recipient_name: str
600
+
601
+ def __init__(
602
+ self,
603
+ *,
604
+ uuid: Optional[UUID] = None,
605
+ no_human_input_msg: str,
606
+ sender: Optional["Agent"] = None,
607
+ recipient: "Agent",
608
+ ):
609
+ super().__init__(
610
+ uuid=uuid,
611
+ no_human_input_msg=no_human_input_msg,
612
+ sender_name=sender.name if sender else "No sender",
613
+ recipient_name=recipient.name,
614
+ )
615
+
616
+ def print(self, f: Optional[Callable[..., Any]] = None) -> None:
617
+ f = f or print
618
+
619
+ f(colored(f"\n>>>>>>>> {self.no_human_input_msg}", "red"), flush=True)
620
+
621
+
622
+ @deprecated_by(UsingAutoReplyEvent, param_mapping={"sender_name": "sender", "recipient_name": "recipient"})
623
+ @wrap_message
624
+ class UsingAutoReplyMessage(BaseMessage):
625
+ human_input_mode: str
626
+ sender_name: str
627
+ recipient_name: str
628
+
629
+ def __init__(
630
+ self,
631
+ *,
632
+ uuid: Optional[UUID] = None,
633
+ human_input_mode: str,
634
+ sender: Optional["Agent"] = None,
635
+ recipient: "Agent",
636
+ ):
637
+ super().__init__(
638
+ uuid=uuid,
639
+ human_input_mode=human_input_mode,
640
+ sender_name=sender.name if sender else "No sender",
641
+ recipient_name=recipient.name,
642
+ )
643
+
644
+ def print(self, f: Optional[Callable[..., Any]] = None) -> None:
645
+ f = f or print
646
+
647
+ f(colored("\n>>>>>>>> USING AUTO REPLY...", "red"), flush=True)
648
+
649
+
650
+ @deprecated_by(TerminationEvent)
651
+ @wrap_message
652
+ class TerminationMessage(BaseMessage):
653
+ """When a workflow termination condition is met"""
654
+
655
+ termination_reason: str
656
+
657
+ def __init__(
658
+ self,
659
+ *,
660
+ uuid: Optional[UUID] = None,
661
+ termination_reason: str,
662
+ ):
663
+ super().__init__(
664
+ uuid=uuid,
665
+ termination_reason=termination_reason,
666
+ )
667
+
668
+ def print(self, f: Optional[Callable[..., Any]] = None) -> None:
669
+ f = f or print
670
+
671
+ f(colored(f"\n>>>>>>>> TERMINATING RUN ({str(self.uuid)}): {self.termination_reason}", "red"), flush=True)
672
+
673
+
674
+ @deprecated_by(ExecuteCodeBlockEvent, param_mapping={"recipient_name": "recipient"})
675
+ @wrap_message
676
+ class ExecuteCodeBlockMessage(BaseMessage):
677
+ code: str
678
+ language: str
679
+ code_block_count: int
680
+ recipient_name: str
681
+
682
+ def __init__(
683
+ self, *, uuid: Optional[UUID] = None, code: str, language: str, code_block_count: int, recipient: "Agent"
684
+ ):
685
+ super().__init__(
686
+ uuid=uuid, code=code, language=language, code_block_count=code_block_count, recipient_name=recipient.name
687
+ )
688
+
689
+ def print(self, f: Optional[Callable[..., Any]] = None) -> None:
690
+ f = f or print
691
+
692
+ f(
693
+ colored(
694
+ f"\n>>>>>>>> EXECUTING CODE BLOCK {self.code_block_count} (inferred language is {self.language})...",
695
+ "red",
696
+ ),
697
+ flush=True,
698
+ )
699
+
700
+
701
+ @deprecated_by(ExecuteFunctionEvent, param_mapping={"recipient_name": "recipient"})
702
+ @wrap_message
703
+ class ExecuteFunctionMessage(BaseMessage):
704
+ func_name: str
705
+ call_id: Optional[str] = None
706
+ arguments: dict[str, Any]
707
+ recipient_name: str
708
+
709
+ def __init__(
710
+ self,
711
+ *,
712
+ uuid: Optional[UUID] = None,
713
+ func_name: str,
714
+ call_id: Optional[str] = None,
715
+ arguments: dict[str, Any],
716
+ recipient: "Agent",
717
+ ):
718
+ super().__init__(
719
+ uuid=uuid, func_name=func_name, call_id=call_id, arguments=arguments, recipient_name=recipient.name
720
+ )
721
+
722
+ def print(self, f: Optional[Callable[..., Any]] = None) -> None:
723
+ f = f or print
724
+
725
+ f(
726
+ colored(
727
+ f"\n>>>>>>>> EXECUTING FUNCTION {self.func_name}...\nCall ID: {self.call_id}\nInput arguments: {self.arguments}",
728
+ "magenta",
729
+ ),
730
+ flush=True,
731
+ )
732
+
733
+
734
+ @deprecated_by(ExecutedFunctionEvent, param_mapping={"recipient_name": "recipient"})
735
+ @wrap_message
736
+ class ExecutedFunctionMessage(BaseMessage):
737
+ func_name: str
738
+ call_id: Optional[str] = None
739
+ arguments: dict[str, Any]
740
+ content: str
741
+ recipient_name: str
742
+
743
+ def __init__(
744
+ self,
745
+ *,
746
+ uuid: Optional[UUID] = None,
747
+ func_name: str,
748
+ call_id: Optional[str] = None,
749
+ arguments: dict[str, Any],
750
+ content: str,
751
+ recipient: "Agent",
752
+ ):
753
+ super().__init__(
754
+ uuid=uuid,
755
+ func_name=func_name,
756
+ call_id=call_id,
757
+ arguments=arguments,
758
+ content=content,
759
+ recipient_name=recipient.name,
760
+ )
761
+
762
+ def print(self, f: Optional[Callable[..., Any]] = None) -> None:
763
+ f = f or print
764
+
765
+ f(
766
+ colored(
767
+ f"\n>>>>>>>> EXECUTED FUNCTION {self.func_name}...\nCall ID: {self.call_id}\nInput arguments: {self.arguments}\nOutput:\n{self.content}",
768
+ "magenta",
769
+ ),
770
+ flush=True,
771
+ )
772
+
773
+
774
+ @deprecated_by(SelectSpeakerEvent)
775
+ @wrap_message
776
+ class SelectSpeakerMessage(BaseMessage):
777
+ agent_names: Optional[list[str]] = None
778
+
779
+ def __init__(self, *, uuid: Optional[UUID] = None, agents: Optional[list["Agent"]] = None):
780
+ agent_names = [agent.name for agent in agents] if agents else None
781
+ super().__init__(uuid=uuid, agent_names=agent_names)
782
+
783
+ def print(self, f: Optional[Callable[..., Any]] = None) -> None:
784
+ f = f or print
785
+
786
+ f("Please select the next speaker from the following list:")
787
+ agent_names = self.agent_names or []
788
+ for i, agent_name in enumerate(agent_names):
789
+ f(f"{i + 1}: {agent_name}")
790
+
791
+
792
+ @deprecated_by(SelectSpeakerTryCountExceededEvent)
793
+ @wrap_message
794
+ class SelectSpeakerTryCountExceededMessage(BaseMessage):
795
+ try_count: int
796
+ agent_names: Optional[list[str]] = None
797
+
798
+ def __init__(self, *, uuid: Optional[UUID] = None, try_count: int, agents: Optional[list["Agent"]] = None):
799
+ agent_names = [agent.name for agent in agents] if agents else None
800
+ super().__init__(uuid=uuid, try_count=try_count, agent_names=agent_names)
801
+
802
+ def print(self, f: Optional[Callable[..., Any]] = None) -> None:
803
+ f = f or print
804
+
805
+ f(f"You have tried {self.try_count} times. The next speaker will be selected automatically.")
806
+
807
+
808
+ @deprecated_by(SelectSpeakerInvalidInputEvent)
809
+ @wrap_message
810
+ class SelectSpeakerInvalidInputMessage(BaseMessage):
811
+ agent_names: Optional[list[str]] = None
812
+
813
+ def __init__(self, *, uuid: Optional[UUID] = None, agents: Optional[list["Agent"]] = None):
814
+ agent_names = [agent.name for agent in agents] if agents else None
815
+ super().__init__(uuid=uuid, agent_names=agent_names)
816
+
817
+ def print(self, f: Optional[Callable[..., Any]] = None) -> None:
818
+ f = f or print
819
+
820
+ f(f"Invalid input. Please enter a number between 1 and {len(self.agent_names or [])}.")
821
+
822
+
823
+ @deprecated_by(
824
+ ClearConversableAgentHistoryEvent,
825
+ param_mapping={"no_messages_preserved": "no_events_preserved", "recipient_name": "recipient"},
826
+ )
827
+ @wrap_message
828
+ class ClearConversableAgentHistoryMessage(BaseMessage):
829
+ agent_name: str
830
+ recipient_name: str
831
+ no_messages_preserved: int
832
+
833
+ def __init__(self, *, uuid: Optional[UUID] = None, agent: "Agent", no_messages_preserved: Optional[int] = None):
834
+ super().__init__(
835
+ uuid=uuid,
836
+ agent_name=agent.name,
837
+ recipient_name=agent.name,
838
+ no_messages_preserved=no_messages_preserved,
839
+ )
840
+
841
+ def print(self, f: Optional[Callable[..., Any]] = None) -> None:
842
+ f = f or print
843
+
844
+ for _ in range(self.no_messages_preserved):
845
+ f(
846
+ f"Preserving one more message for {self.agent_name} to not divide history between tool call and "
847
+ f"tool response."
848
+ )
849
+
850
+
851
+ @deprecated_by(ClearConversableAgentHistoryWarningEvent, param_mapping={"recipient_name": "recipient"})
852
+ @wrap_message
853
+ class ClearConversableAgentHistoryWarningMessage(BaseMessage):
854
+ recipient_name: str
855
+
856
+ def __init__(self, *, uuid: Optional[UUID] = None, recipient: "Agent"):
857
+ super().__init__(
858
+ uuid=uuid,
859
+ recipient_name=recipient.name,
860
+ )
861
+
862
+ def print(self, f: Optional[Callable[..., Any]] = None) -> None:
863
+ f = f or print
864
+
865
+ f(
866
+ colored(
867
+ "WARNING: `nr_preserved_messages` is ignored when clearing chat history with a specific agent.",
868
+ "yellow",
869
+ ),
870
+ flush=True,
871
+ )
872
+
873
+
874
+ @deprecated_by(
875
+ GenerateCodeExecutionReplyEvent,
876
+ param_mapping={"sender_name": "sender", "recipient_name": "recipient", "code_block_languages": "code_blocks"},
877
+ )
878
+ @wrap_message
879
+ class GenerateCodeExecutionReplyMessage(BaseMessage):
880
+ code_block_languages: list[str]
881
+ sender_name: Optional[str] = None
882
+ recipient_name: str
883
+
884
+ def __init__(
885
+ self,
886
+ *,
887
+ uuid: Optional[UUID] = None,
888
+ code_blocks: list["CodeBlock"],
889
+ sender: Optional["Agent"] = None,
890
+ recipient: "Agent",
891
+ ):
892
+ code_block_languages = [code_block.language for code_block in code_blocks]
893
+
894
+ super().__init__(
895
+ uuid=uuid,
896
+ code_block_languages=code_block_languages,
897
+ sender_name=sender.name if sender else None,
898
+ recipient_name=recipient.name,
899
+ )
900
+
901
+ def print(self, f: Optional[Callable[..., Any]] = None) -> None:
902
+ f = f or print
903
+
904
+ num_code_blocks = len(self.code_block_languages)
905
+ if num_code_blocks == 1:
906
+ f(
907
+ colored(
908
+ f"\n>>>>>>>> EXECUTING CODE BLOCK (inferred language is {self.code_block_languages[0]})...",
909
+ "red",
910
+ ),
911
+ flush=True,
912
+ )
913
+ else:
914
+ f(
915
+ colored(
916
+ f"\n>>>>>>>> EXECUTING {num_code_blocks} CODE BLOCKS (inferred languages are [{', '.join([x for x in self.code_block_languages])}])...",
917
+ "red",
918
+ ),
919
+ flush=True,
920
+ )
921
+
922
+
923
+ @deprecated_by(ConversableAgentUsageSummaryNoCostIncurredEvent, param_mapping={"recipient_name": "recipient"})
924
+ @wrap_message
925
+ class ConversableAgentUsageSummaryNoCostIncurredMessage(BaseMessage):
926
+ recipient_name: str
927
+
928
+ def __init__(self, *, uuid: Optional[UUID] = None, recipient: "Agent"):
929
+ super().__init__(uuid=uuid, recipient_name=recipient.name)
930
+
931
+ def print(self, f: Optional[Callable[..., Any]] = None) -> None:
932
+ f = f or print
933
+
934
+ f(f"No cost incurred from agent '{self.recipient_name}'.")
935
+
936
+
937
+ @deprecated_by(ConversableAgentUsageSummaryEvent, param_mapping={"recipient_name": "recipient"})
938
+ @wrap_message
939
+ class ConversableAgentUsageSummaryMessage(BaseMessage):
940
+ recipient_name: str
941
+
942
+ def __init__(self, *, uuid: Optional[UUID] = None, recipient: "Agent"):
943
+ super().__init__(uuid=uuid, recipient_name=recipient.name)
944
+
945
+ def print(self, f: Optional[Callable[..., Any]] = None) -> None:
946
+ f = f or print
947
+
948
+ f(f"Agent '{self.recipient_name}':")