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.
- {ag2-0.9.1a1.dist-info → ag2-0.9.1.post0.dist-info}/METADATA +264 -73
- ag2-0.9.1.post0.dist-info/RECORD +392 -0
- {ag2-0.9.1a1.dist-info → ag2-0.9.1.post0.dist-info}/WHEEL +1 -2
- autogen/__init__.py +89 -0
- autogen/_website/__init__.py +3 -0
- autogen/_website/generate_api_references.py +427 -0
- autogen/_website/generate_mkdocs.py +1174 -0
- autogen/_website/notebook_processor.py +476 -0
- autogen/_website/process_notebooks.py +656 -0
- autogen/_website/utils.py +412 -0
- autogen/agentchat/__init__.py +44 -0
- autogen/agentchat/agent.py +182 -0
- autogen/agentchat/assistant_agent.py +85 -0
- autogen/agentchat/chat.py +309 -0
- autogen/agentchat/contrib/__init__.py +5 -0
- autogen/agentchat/contrib/agent_eval/README.md +7 -0
- autogen/agentchat/contrib/agent_eval/agent_eval.py +108 -0
- autogen/agentchat/contrib/agent_eval/criterion.py +43 -0
- autogen/agentchat/contrib/agent_eval/critic_agent.py +44 -0
- autogen/agentchat/contrib/agent_eval/quantifier_agent.py +39 -0
- autogen/agentchat/contrib/agent_eval/subcritic_agent.py +45 -0
- autogen/agentchat/contrib/agent_eval/task.py +42 -0
- autogen/agentchat/contrib/agent_optimizer.py +429 -0
- autogen/agentchat/contrib/capabilities/__init__.py +5 -0
- autogen/agentchat/contrib/capabilities/agent_capability.py +20 -0
- autogen/agentchat/contrib/capabilities/generate_images.py +301 -0
- autogen/agentchat/contrib/capabilities/teachability.py +393 -0
- autogen/agentchat/contrib/capabilities/text_compressors.py +66 -0
- autogen/agentchat/contrib/capabilities/tools_capability.py +22 -0
- autogen/agentchat/contrib/capabilities/transform_messages.py +93 -0
- autogen/agentchat/contrib/capabilities/transforms.py +566 -0
- autogen/agentchat/contrib/capabilities/transforms_util.py +122 -0
- autogen/agentchat/contrib/capabilities/vision_capability.py +214 -0
- autogen/agentchat/contrib/captainagent/__init__.py +9 -0
- autogen/agentchat/contrib/captainagent/agent_builder.py +790 -0
- autogen/agentchat/contrib/captainagent/captainagent.py +512 -0
- autogen/agentchat/contrib/captainagent/tool_retriever.py +335 -0
- autogen/agentchat/contrib/captainagent/tools/README.md +44 -0
- autogen/agentchat/contrib/captainagent/tools/__init__.py +5 -0
- autogen/agentchat/contrib/captainagent/tools/data_analysis/calculate_correlation.py +40 -0
- autogen/agentchat/contrib/captainagent/tools/data_analysis/calculate_skewness_and_kurtosis.py +28 -0
- autogen/agentchat/contrib/captainagent/tools/data_analysis/detect_outlier_iqr.py +28 -0
- autogen/agentchat/contrib/captainagent/tools/data_analysis/detect_outlier_zscore.py +28 -0
- autogen/agentchat/contrib/captainagent/tools/data_analysis/explore_csv.py +21 -0
- autogen/agentchat/contrib/captainagent/tools/data_analysis/shapiro_wilk_test.py +30 -0
- autogen/agentchat/contrib/captainagent/tools/information_retrieval/arxiv_download.py +27 -0
- autogen/agentchat/contrib/captainagent/tools/information_retrieval/arxiv_search.py +53 -0
- autogen/agentchat/contrib/captainagent/tools/information_retrieval/extract_pdf_image.py +53 -0
- autogen/agentchat/contrib/captainagent/tools/information_retrieval/extract_pdf_text.py +38 -0
- autogen/agentchat/contrib/captainagent/tools/information_retrieval/get_wikipedia_text.py +21 -0
- autogen/agentchat/contrib/captainagent/tools/information_retrieval/get_youtube_caption.py +34 -0
- autogen/agentchat/contrib/captainagent/tools/information_retrieval/image_qa.py +60 -0
- autogen/agentchat/contrib/captainagent/tools/information_retrieval/optical_character_recognition.py +61 -0
- autogen/agentchat/contrib/captainagent/tools/information_retrieval/perform_web_search.py +47 -0
- autogen/agentchat/contrib/captainagent/tools/information_retrieval/scrape_wikipedia_tables.py +33 -0
- autogen/agentchat/contrib/captainagent/tools/information_retrieval/transcribe_audio_file.py +21 -0
- autogen/agentchat/contrib/captainagent/tools/information_retrieval/youtube_download.py +35 -0
- autogen/agentchat/contrib/captainagent/tools/math/calculate_circle_area_from_diameter.py +21 -0
- autogen/agentchat/contrib/captainagent/tools/math/calculate_day_of_the_week.py +18 -0
- autogen/agentchat/contrib/captainagent/tools/math/calculate_fraction_sum.py +28 -0
- autogen/agentchat/contrib/captainagent/tools/math/calculate_matrix_power.py +31 -0
- autogen/agentchat/contrib/captainagent/tools/math/calculate_reflected_point.py +16 -0
- autogen/agentchat/contrib/captainagent/tools/math/complex_numbers_product.py +25 -0
- autogen/agentchat/contrib/captainagent/tools/math/compute_currency_conversion.py +23 -0
- autogen/agentchat/contrib/captainagent/tools/math/count_distinct_permutations.py +27 -0
- autogen/agentchat/contrib/captainagent/tools/math/evaluate_expression.py +28 -0
- autogen/agentchat/contrib/captainagent/tools/math/find_continuity_point.py +34 -0
- autogen/agentchat/contrib/captainagent/tools/math/fraction_to_mixed_numbers.py +39 -0
- autogen/agentchat/contrib/captainagent/tools/math/modular_inverse_sum.py +23 -0
- autogen/agentchat/contrib/captainagent/tools/math/simplify_mixed_numbers.py +36 -0
- autogen/agentchat/contrib/captainagent/tools/math/sum_of_digit_factorials.py +15 -0
- autogen/agentchat/contrib/captainagent/tools/math/sum_of_primes_below.py +15 -0
- autogen/agentchat/contrib/captainagent/tools/requirements.txt +10 -0
- autogen/agentchat/contrib/captainagent/tools/tool_description.tsv +34 -0
- autogen/agentchat/contrib/gpt_assistant_agent.py +526 -0
- autogen/agentchat/contrib/graph_rag/__init__.py +9 -0
- autogen/agentchat/contrib/graph_rag/document.py +29 -0
- autogen/agentchat/contrib/graph_rag/falkor_graph_query_engine.py +170 -0
- autogen/agentchat/contrib/graph_rag/falkor_graph_rag_capability.py +103 -0
- autogen/agentchat/contrib/graph_rag/graph_query_engine.py +53 -0
- autogen/agentchat/contrib/graph_rag/graph_rag_capability.py +63 -0
- autogen/agentchat/contrib/graph_rag/neo4j_graph_query_engine.py +268 -0
- autogen/agentchat/contrib/graph_rag/neo4j_graph_rag_capability.py +83 -0
- autogen/agentchat/contrib/graph_rag/neo4j_native_graph_query_engine.py +210 -0
- autogen/agentchat/contrib/graph_rag/neo4j_native_graph_rag_capability.py +93 -0
- autogen/agentchat/contrib/img_utils.py +397 -0
- autogen/agentchat/contrib/llamaindex_conversable_agent.py +117 -0
- autogen/agentchat/contrib/llava_agent.py +187 -0
- autogen/agentchat/contrib/math_user_proxy_agent.py +464 -0
- autogen/agentchat/contrib/multimodal_conversable_agent.py +125 -0
- autogen/agentchat/contrib/qdrant_retrieve_user_proxy_agent.py +324 -0
- autogen/agentchat/contrib/rag/__init__.py +10 -0
- autogen/agentchat/contrib/rag/chromadb_query_engine.py +272 -0
- autogen/agentchat/contrib/rag/llamaindex_query_engine.py +198 -0
- autogen/agentchat/contrib/rag/mongodb_query_engine.py +329 -0
- autogen/agentchat/contrib/rag/query_engine.py +74 -0
- autogen/agentchat/contrib/retrieve_assistant_agent.py +56 -0
- autogen/agentchat/contrib/retrieve_user_proxy_agent.py +703 -0
- autogen/agentchat/contrib/society_of_mind_agent.py +199 -0
- autogen/agentchat/contrib/swarm_agent.py +1425 -0
- autogen/agentchat/contrib/text_analyzer_agent.py +79 -0
- autogen/agentchat/contrib/vectordb/__init__.py +5 -0
- autogen/agentchat/contrib/vectordb/base.py +232 -0
- autogen/agentchat/contrib/vectordb/chromadb.py +315 -0
- autogen/agentchat/contrib/vectordb/couchbase.py +407 -0
- autogen/agentchat/contrib/vectordb/mongodb.py +550 -0
- autogen/agentchat/contrib/vectordb/pgvectordb.py +928 -0
- autogen/agentchat/contrib/vectordb/qdrant.py +320 -0
- autogen/agentchat/contrib/vectordb/utils.py +126 -0
- autogen/agentchat/contrib/web_surfer.py +303 -0
- autogen/agentchat/conversable_agent.py +4020 -0
- autogen/agentchat/group/__init__.py +64 -0
- autogen/agentchat/group/available_condition.py +91 -0
- autogen/agentchat/group/context_condition.py +77 -0
- autogen/agentchat/group/context_expression.py +238 -0
- autogen/agentchat/group/context_str.py +41 -0
- autogen/agentchat/group/context_variables.py +192 -0
- autogen/agentchat/group/group_tool_executor.py +202 -0
- autogen/agentchat/group/group_utils.py +591 -0
- autogen/agentchat/group/handoffs.py +244 -0
- autogen/agentchat/group/llm_condition.py +93 -0
- autogen/agentchat/group/multi_agent_chat.py +237 -0
- autogen/agentchat/group/on_condition.py +58 -0
- autogen/agentchat/group/on_context_condition.py +54 -0
- autogen/agentchat/group/patterns/__init__.py +18 -0
- autogen/agentchat/group/patterns/auto.py +159 -0
- autogen/agentchat/group/patterns/manual.py +176 -0
- autogen/agentchat/group/patterns/pattern.py +288 -0
- autogen/agentchat/group/patterns/random.py +106 -0
- autogen/agentchat/group/patterns/round_robin.py +117 -0
- autogen/agentchat/group/reply_result.py +26 -0
- autogen/agentchat/group/speaker_selection_result.py +41 -0
- autogen/agentchat/group/targets/__init__.py +4 -0
- autogen/agentchat/group/targets/group_chat_target.py +132 -0
- autogen/agentchat/group/targets/group_manager_target.py +151 -0
- autogen/agentchat/group/targets/transition_target.py +413 -0
- autogen/agentchat/group/targets/transition_utils.py +6 -0
- autogen/agentchat/groupchat.py +1694 -0
- autogen/agentchat/realtime/__init__.py +3 -0
- autogen/agentchat/realtime/experimental/__init__.py +20 -0
- autogen/agentchat/realtime/experimental/audio_adapters/__init__.py +8 -0
- autogen/agentchat/realtime/experimental/audio_adapters/twilio_audio_adapter.py +148 -0
- autogen/agentchat/realtime/experimental/audio_adapters/websocket_audio_adapter.py +139 -0
- autogen/agentchat/realtime/experimental/audio_observer.py +42 -0
- autogen/agentchat/realtime/experimental/clients/__init__.py +15 -0
- autogen/agentchat/realtime/experimental/clients/gemini/__init__.py +7 -0
- autogen/agentchat/realtime/experimental/clients/gemini/client.py +274 -0
- autogen/agentchat/realtime/experimental/clients/oai/__init__.py +8 -0
- autogen/agentchat/realtime/experimental/clients/oai/base_client.py +220 -0
- autogen/agentchat/realtime/experimental/clients/oai/rtc_client.py +243 -0
- autogen/agentchat/realtime/experimental/clients/oai/utils.py +48 -0
- autogen/agentchat/realtime/experimental/clients/realtime_client.py +190 -0
- autogen/agentchat/realtime/experimental/function_observer.py +85 -0
- autogen/agentchat/realtime/experimental/realtime_agent.py +158 -0
- autogen/agentchat/realtime/experimental/realtime_events.py +42 -0
- autogen/agentchat/realtime/experimental/realtime_observer.py +100 -0
- autogen/agentchat/realtime/experimental/realtime_swarm.py +475 -0
- autogen/agentchat/realtime/experimental/websockets.py +21 -0
- autogen/agentchat/realtime_agent/__init__.py +21 -0
- autogen/agentchat/user_proxy_agent.py +111 -0
- autogen/agentchat/utils.py +206 -0
- autogen/agents/__init__.py +3 -0
- autogen/agents/contrib/__init__.py +10 -0
- autogen/agents/contrib/time/__init__.py +8 -0
- autogen/agents/contrib/time/time_reply_agent.py +73 -0
- autogen/agents/contrib/time/time_tool_agent.py +51 -0
- autogen/agents/experimental/__init__.py +27 -0
- autogen/agents/experimental/deep_research/__init__.py +7 -0
- autogen/agents/experimental/deep_research/deep_research.py +52 -0
- autogen/agents/experimental/discord/__init__.py +7 -0
- autogen/agents/experimental/discord/discord.py +66 -0
- autogen/agents/experimental/document_agent/__init__.py +19 -0
- autogen/agents/experimental/document_agent/chroma_query_engine.py +316 -0
- autogen/agents/experimental/document_agent/docling_doc_ingest_agent.py +118 -0
- autogen/agents/experimental/document_agent/document_agent.py +461 -0
- autogen/agents/experimental/document_agent/document_conditions.py +50 -0
- autogen/agents/experimental/document_agent/document_utils.py +380 -0
- autogen/agents/experimental/document_agent/inmemory_query_engine.py +220 -0
- autogen/agents/experimental/document_agent/parser_utils.py +130 -0
- autogen/agents/experimental/document_agent/url_utils.py +426 -0
- autogen/agents/experimental/reasoning/__init__.py +7 -0
- autogen/agents/experimental/reasoning/reasoning_agent.py +1178 -0
- autogen/agents/experimental/slack/__init__.py +7 -0
- autogen/agents/experimental/slack/slack.py +73 -0
- autogen/agents/experimental/telegram/__init__.py +7 -0
- autogen/agents/experimental/telegram/telegram.py +77 -0
- autogen/agents/experimental/websurfer/__init__.py +7 -0
- autogen/agents/experimental/websurfer/websurfer.py +62 -0
- autogen/agents/experimental/wikipedia/__init__.py +7 -0
- autogen/agents/experimental/wikipedia/wikipedia.py +90 -0
- autogen/browser_utils.py +309 -0
- autogen/cache/__init__.py +10 -0
- autogen/cache/abstract_cache_base.py +75 -0
- autogen/cache/cache.py +203 -0
- autogen/cache/cache_factory.py +88 -0
- autogen/cache/cosmos_db_cache.py +144 -0
- autogen/cache/disk_cache.py +102 -0
- autogen/cache/in_memory_cache.py +58 -0
- autogen/cache/redis_cache.py +123 -0
- autogen/code_utils.py +596 -0
- autogen/coding/__init__.py +22 -0
- autogen/coding/base.py +119 -0
- autogen/coding/docker_commandline_code_executor.py +268 -0
- autogen/coding/factory.py +47 -0
- autogen/coding/func_with_reqs.py +202 -0
- autogen/coding/jupyter/__init__.py +23 -0
- autogen/coding/jupyter/base.py +36 -0
- autogen/coding/jupyter/docker_jupyter_server.py +167 -0
- autogen/coding/jupyter/embedded_ipython_code_executor.py +182 -0
- autogen/coding/jupyter/import_utils.py +82 -0
- autogen/coding/jupyter/jupyter_client.py +231 -0
- autogen/coding/jupyter/jupyter_code_executor.py +160 -0
- autogen/coding/jupyter/local_jupyter_server.py +172 -0
- autogen/coding/local_commandline_code_executor.py +405 -0
- autogen/coding/markdown_code_extractor.py +45 -0
- autogen/coding/utils.py +56 -0
- autogen/doc_utils.py +34 -0
- autogen/events/__init__.py +7 -0
- autogen/events/agent_events.py +1010 -0
- autogen/events/base_event.py +99 -0
- autogen/events/client_events.py +167 -0
- autogen/events/helpers.py +36 -0
- autogen/events/print_event.py +46 -0
- autogen/exception_utils.py +73 -0
- autogen/extensions/__init__.py +5 -0
- autogen/fast_depends/__init__.py +16 -0
- autogen/fast_depends/_compat.py +80 -0
- autogen/fast_depends/core/__init__.py +14 -0
- autogen/fast_depends/core/build.py +225 -0
- autogen/fast_depends/core/model.py +576 -0
- autogen/fast_depends/dependencies/__init__.py +15 -0
- autogen/fast_depends/dependencies/model.py +29 -0
- autogen/fast_depends/dependencies/provider.py +39 -0
- autogen/fast_depends/library/__init__.py +10 -0
- autogen/fast_depends/library/model.py +46 -0
- autogen/fast_depends/py.typed +6 -0
- autogen/fast_depends/schema.py +66 -0
- autogen/fast_depends/use.py +280 -0
- autogen/fast_depends/utils.py +187 -0
- autogen/formatting_utils.py +83 -0
- autogen/function_utils.py +13 -0
- autogen/graph_utils.py +178 -0
- autogen/import_utils.py +526 -0
- autogen/interop/__init__.py +22 -0
- autogen/interop/crewai/__init__.py +7 -0
- autogen/interop/crewai/crewai.py +88 -0
- autogen/interop/interoperability.py +71 -0
- autogen/interop/interoperable.py +46 -0
- autogen/interop/langchain/__init__.py +8 -0
- autogen/interop/langchain/langchain_chat_model_factory.py +155 -0
- autogen/interop/langchain/langchain_tool.py +82 -0
- autogen/interop/litellm/__init__.py +7 -0
- autogen/interop/litellm/litellm_config_factory.py +113 -0
- autogen/interop/pydantic_ai/__init__.py +7 -0
- autogen/interop/pydantic_ai/pydantic_ai.py +168 -0
- autogen/interop/registry.py +69 -0
- autogen/io/__init__.py +15 -0
- autogen/io/base.py +151 -0
- autogen/io/console.py +56 -0
- autogen/io/processors/__init__.py +12 -0
- autogen/io/processors/base.py +21 -0
- autogen/io/processors/console_event_processor.py +56 -0
- autogen/io/run_response.py +293 -0
- autogen/io/thread_io_stream.py +63 -0
- autogen/io/websockets.py +213 -0
- autogen/json_utils.py +43 -0
- autogen/llm_config.py +379 -0
- autogen/logger/__init__.py +11 -0
- autogen/logger/base_logger.py +128 -0
- autogen/logger/file_logger.py +261 -0
- autogen/logger/logger_factory.py +42 -0
- autogen/logger/logger_utils.py +57 -0
- autogen/logger/sqlite_logger.py +523 -0
- autogen/math_utils.py +339 -0
- autogen/mcp/__init__.py +7 -0
- autogen/mcp/mcp_client.py +208 -0
- autogen/messages/__init__.py +7 -0
- autogen/messages/agent_messages.py +948 -0
- autogen/messages/base_message.py +107 -0
- autogen/messages/client_messages.py +171 -0
- autogen/messages/print_message.py +49 -0
- autogen/oai/__init__.py +53 -0
- autogen/oai/anthropic.py +714 -0
- autogen/oai/bedrock.py +628 -0
- autogen/oai/cerebras.py +299 -0
- autogen/oai/client.py +1435 -0
- autogen/oai/client_utils.py +169 -0
- autogen/oai/cohere.py +479 -0
- autogen/oai/gemini.py +990 -0
- autogen/oai/gemini_types.py +129 -0
- autogen/oai/groq.py +305 -0
- autogen/oai/mistral.py +303 -0
- autogen/oai/oai_models/__init__.py +11 -0
- autogen/oai/oai_models/_models.py +16 -0
- autogen/oai/oai_models/chat_completion.py +87 -0
- autogen/oai/oai_models/chat_completion_audio.py +32 -0
- autogen/oai/oai_models/chat_completion_message.py +86 -0
- autogen/oai/oai_models/chat_completion_message_tool_call.py +37 -0
- autogen/oai/oai_models/chat_completion_token_logprob.py +63 -0
- autogen/oai/oai_models/completion_usage.py +60 -0
- autogen/oai/ollama.py +643 -0
- autogen/oai/openai_utils.py +881 -0
- autogen/oai/together.py +370 -0
- autogen/retrieve_utils.py +491 -0
- autogen/runtime_logging.py +160 -0
- autogen/token_count_utils.py +267 -0
- autogen/tools/__init__.py +20 -0
- autogen/tools/contrib/__init__.py +9 -0
- autogen/tools/contrib/time/__init__.py +7 -0
- autogen/tools/contrib/time/time.py +41 -0
- autogen/tools/dependency_injection.py +254 -0
- autogen/tools/experimental/__init__.py +43 -0
- autogen/tools/experimental/browser_use/__init__.py +7 -0
- autogen/tools/experimental/browser_use/browser_use.py +161 -0
- autogen/tools/experimental/crawl4ai/__init__.py +7 -0
- autogen/tools/experimental/crawl4ai/crawl4ai.py +153 -0
- autogen/tools/experimental/deep_research/__init__.py +7 -0
- autogen/tools/experimental/deep_research/deep_research.py +328 -0
- autogen/tools/experimental/duckduckgo/__init__.py +7 -0
- autogen/tools/experimental/duckduckgo/duckduckgo_search.py +109 -0
- autogen/tools/experimental/google/__init__.py +14 -0
- autogen/tools/experimental/google/authentication/__init__.py +11 -0
- autogen/tools/experimental/google/authentication/credentials_hosted_provider.py +43 -0
- autogen/tools/experimental/google/authentication/credentials_local_provider.py +91 -0
- autogen/tools/experimental/google/authentication/credentials_provider.py +35 -0
- autogen/tools/experimental/google/drive/__init__.py +9 -0
- autogen/tools/experimental/google/drive/drive_functions.py +124 -0
- autogen/tools/experimental/google/drive/toolkit.py +88 -0
- autogen/tools/experimental/google/model.py +17 -0
- autogen/tools/experimental/google/toolkit_protocol.py +19 -0
- autogen/tools/experimental/google_search/__init__.py +8 -0
- autogen/tools/experimental/google_search/google_search.py +93 -0
- autogen/tools/experimental/google_search/youtube_search.py +181 -0
- autogen/tools/experimental/messageplatform/__init__.py +17 -0
- autogen/tools/experimental/messageplatform/discord/__init__.py +7 -0
- autogen/tools/experimental/messageplatform/discord/discord.py +288 -0
- autogen/tools/experimental/messageplatform/slack/__init__.py +7 -0
- autogen/tools/experimental/messageplatform/slack/slack.py +391 -0
- autogen/tools/experimental/messageplatform/telegram/__init__.py +7 -0
- autogen/tools/experimental/messageplatform/telegram/telegram.py +275 -0
- autogen/tools/experimental/perplexity/__init__.py +7 -0
- autogen/tools/experimental/perplexity/perplexity_search.py +260 -0
- autogen/tools/experimental/tavily/__init__.py +7 -0
- autogen/tools/experimental/tavily/tavily_search.py +183 -0
- autogen/tools/experimental/web_search_preview/__init__.py +7 -0
- autogen/tools/experimental/web_search_preview/web_search_preview.py +114 -0
- autogen/tools/experimental/wikipedia/__init__.py +7 -0
- autogen/tools/experimental/wikipedia/wikipedia.py +287 -0
- autogen/tools/function_utils.py +411 -0
- autogen/tools/tool.py +187 -0
- autogen/tools/toolkit.py +86 -0
- autogen/types.py +29 -0
- autogen/version.py +7 -0
- ag2-0.9.1a1.dist-info/RECORD +0 -6
- ag2-0.9.1a1.dist-info/top_level.txt +0 -1
- {ag2-0.9.1a1.dist-info → ag2-0.9.1.post0.dist-info/licenses}/LICENSE +0 -0
- {ag2-0.9.1a1.dist-info → ag2-0.9.1.post0.dist-info/licenses}/NOTICE.md +0 -0
|
@@ -0,0 +1,412 @@
|
|
|
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
|
+
import re
|
|
6
|
+
import shutil
|
|
7
|
+
import subprocess
|
|
8
|
+
import sys
|
|
9
|
+
from datetime import datetime
|
|
10
|
+
from pathlib import Path
|
|
11
|
+
from textwrap import dedent, indent
|
|
12
|
+
from typing import Literal, Optional, TypedDict, Union
|
|
13
|
+
|
|
14
|
+
from ..import_utils import optional_import_block, require_optional_import
|
|
15
|
+
|
|
16
|
+
with optional_import_block():
|
|
17
|
+
import yaml
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
EDIT_URL_HTML = """
|
|
21
|
+
<div className="edit-url-container">
|
|
22
|
+
<a className="edit-url" href="https://github.com/ag2ai/ag2/edit/main/{file_path}" target='_blank'><Icon icon="pen" iconType="solid" size="13px"/> Edit this page</a>
|
|
23
|
+
</div>
|
|
24
|
+
"""
|
|
25
|
+
|
|
26
|
+
build_system = Literal["mkdocs", "mintlify"]
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
class NavigationGroup(TypedDict):
|
|
30
|
+
group: str
|
|
31
|
+
pages: list[Union[str, "NavigationGroup"]]
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def get_git_tracked_and_untracked_files_in_directory(directory: Path) -> list[Path]:
|
|
35
|
+
"""Get all files in the directory that are tracked by git or newly added."""
|
|
36
|
+
proc = subprocess.run(
|
|
37
|
+
["git", "-C", str(directory), "ls-files", "--others", "--exclude-standard", "--cached"],
|
|
38
|
+
capture_output=True,
|
|
39
|
+
text=True,
|
|
40
|
+
check=True,
|
|
41
|
+
)
|
|
42
|
+
return list({directory / p for p in proc.stdout.splitlines()})
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def copy_files(src_dir: Path, dst_dir: Path, files_to_copy: list[Path]) -> None:
|
|
46
|
+
"""Copy files from src_dir to dst_dir."""
|
|
47
|
+
for file in files_to_copy:
|
|
48
|
+
if file.is_file():
|
|
49
|
+
dst = dst_dir / file.relative_to(src_dir)
|
|
50
|
+
dst.parent.mkdir(parents=True, exist_ok=True)
|
|
51
|
+
shutil.copy2(file, dst)
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def copy_only_git_tracked_and_untracked_files(src_dir: Path, dst_dir: Path, ignore_dir: Optional[str] = None) -> None:
|
|
55
|
+
"""Copy only the files that are tracked by git or newly added from src_dir to dst_dir."""
|
|
56
|
+
tracked_and_new_files = get_git_tracked_and_untracked_files_in_directory(src_dir)
|
|
57
|
+
|
|
58
|
+
if ignore_dir:
|
|
59
|
+
ignore_dir_rel_path = src_dir / ignore_dir
|
|
60
|
+
|
|
61
|
+
tracked_and_new_files = list({
|
|
62
|
+
file for file in tracked_and_new_files if not any(parent == ignore_dir_rel_path for parent in file.parents)
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
copy_files(src_dir, dst_dir, tracked_and_new_files)
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def remove_marker_blocks(content: str, marker_prefix: str) -> str:
|
|
69
|
+
"""Remove marker blocks from the content.
|
|
70
|
+
|
|
71
|
+
Args:
|
|
72
|
+
content: The source content to process
|
|
73
|
+
marker_prefix: The marker prefix to identify blocks to remove (without the START/END suffix)
|
|
74
|
+
|
|
75
|
+
Returns:
|
|
76
|
+
Processed content with appropriate blocks handled
|
|
77
|
+
"""
|
|
78
|
+
# First, remove blocks with the specified marker completely
|
|
79
|
+
if f"{{/* {marker_prefix}-START */}}" in content:
|
|
80
|
+
pattern = rf"\{{/\* {re.escape(marker_prefix)}-START \*/\}}.*?\{{/\* {re.escape(marker_prefix)}-END \*/\}}"
|
|
81
|
+
content = re.sub(pattern, "", content, flags=re.DOTALL)
|
|
82
|
+
|
|
83
|
+
# Now, remove markers but keep content for the other marker type
|
|
84
|
+
other_prefix = (
|
|
85
|
+
"DELETE-ME-WHILE-BUILDING-MKDOCS"
|
|
86
|
+
if marker_prefix == "DELETE-ME-WHILE-BUILDING-MINTLIFY"
|
|
87
|
+
else "DELETE-ME-WHILE-BUILDING-MINTLIFY"
|
|
88
|
+
)
|
|
89
|
+
|
|
90
|
+
# Remove start markers
|
|
91
|
+
start_pattern = rf"\{{/\* {re.escape(other_prefix)}-START \*/\}}\s*"
|
|
92
|
+
content = re.sub(start_pattern, "", content)
|
|
93
|
+
|
|
94
|
+
# Remove end markers
|
|
95
|
+
end_pattern = rf"\s*\{{/\* {re.escape(other_prefix)}-END \*/\}}"
|
|
96
|
+
content = re.sub(end_pattern, "", content)
|
|
97
|
+
|
|
98
|
+
# Fix any double newlines that might have been created
|
|
99
|
+
content = re.sub(r"\n\s*\n\s*\n", "\n\n", content)
|
|
100
|
+
|
|
101
|
+
return content
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
# Sort files by parent directory date (if exists) and name
|
|
105
|
+
def sort_files_by_date(file_path: Path) -> tuple[datetime, str]:
|
|
106
|
+
dirname = file_path.parent.name
|
|
107
|
+
try:
|
|
108
|
+
# Extract date from directory name (first 3 parts)
|
|
109
|
+
date_str = "-".join(dirname.split("-")[:3])
|
|
110
|
+
date = datetime.strptime(date_str, "%Y-%m-%d")
|
|
111
|
+
except ValueError:
|
|
112
|
+
date = datetime.min
|
|
113
|
+
return (date, dirname)
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
def construct_authors_html(authors_list: list[str], authors_dict: dict[str, dict[str, str]], build_system: str) -> str:
|
|
117
|
+
"""Constructs HTML for displaying author cards in a blog.
|
|
118
|
+
|
|
119
|
+
Args:
|
|
120
|
+
authors_list: list of author identifiers
|
|
121
|
+
authors_dict: Dictionary containing author information keyed by author identifier
|
|
122
|
+
build_system: The build system being used (mkdocs or mintlify)
|
|
123
|
+
Returns:
|
|
124
|
+
str: Formatted HTML string containing author cards
|
|
125
|
+
"""
|
|
126
|
+
if not authors_list:
|
|
127
|
+
return ""
|
|
128
|
+
|
|
129
|
+
card_template_mintlify = """
|
|
130
|
+
<Card href="{url}">
|
|
131
|
+
<div class="col card">
|
|
132
|
+
<div class="img-placeholder">
|
|
133
|
+
<img noZoom src="{avatar}" />
|
|
134
|
+
</div>
|
|
135
|
+
<div>
|
|
136
|
+
<p class="name">{name}</p>
|
|
137
|
+
<p>{description}</p>
|
|
138
|
+
</div>
|
|
139
|
+
</div>
|
|
140
|
+
</Card>"""
|
|
141
|
+
|
|
142
|
+
card_template_mkdocs = """
|
|
143
|
+
<div class="card">
|
|
144
|
+
<div class="col card">
|
|
145
|
+
<div class="img-placeholder">
|
|
146
|
+
<img noZoom src="{avatar}" />
|
|
147
|
+
</div>
|
|
148
|
+
<div>
|
|
149
|
+
<p class="name">{name}</p>
|
|
150
|
+
<p>{description}</p>
|
|
151
|
+
</div>
|
|
152
|
+
</div>
|
|
153
|
+
</div>
|
|
154
|
+
"""
|
|
155
|
+
|
|
156
|
+
card_template = card_template_mintlify if build_system == "mintlify" else card_template_mkdocs
|
|
157
|
+
|
|
158
|
+
authors_html = [card_template.format(**authors_dict[author]) for author in authors_list]
|
|
159
|
+
|
|
160
|
+
author_label = "Author:" if len(authors_list) == 1 else "Authors:"
|
|
161
|
+
authors_html_str = indent("".join(authors_html), " ")
|
|
162
|
+
|
|
163
|
+
retval = ""
|
|
164
|
+
if build_system == "mintlify":
|
|
165
|
+
retval = dedent(
|
|
166
|
+
f"""
|
|
167
|
+
<div class="blog-authors">
|
|
168
|
+
<p class="authors">{author_label}</p>
|
|
169
|
+
<CardGroup cols={{2}}>{authors_html_str}
|
|
170
|
+
</CardGroup>
|
|
171
|
+
</div>
|
|
172
|
+
"""
|
|
173
|
+
)
|
|
174
|
+
else:
|
|
175
|
+
retval = dedent(
|
|
176
|
+
f"""
|
|
177
|
+
<div class="blog-authors">
|
|
178
|
+
<p class="authors">{author_label}</p>
|
|
179
|
+
<div class="card-group">
|
|
180
|
+
{authors_html_str}
|
|
181
|
+
</div>
|
|
182
|
+
</div>
|
|
183
|
+
"""
|
|
184
|
+
)
|
|
185
|
+
return retval
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
def separate_front_matter_and_content(file_path: Path) -> tuple[str, str]:
|
|
189
|
+
"""Separate front matter and content from a markdown file.
|
|
190
|
+
|
|
191
|
+
Args:
|
|
192
|
+
file_path (Path): Path to the mdx file
|
|
193
|
+
"""
|
|
194
|
+
content = file_path.read_text(encoding="utf-8")
|
|
195
|
+
|
|
196
|
+
if content.startswith("---"):
|
|
197
|
+
front_matter_end = content.find("---", 3)
|
|
198
|
+
front_matter = content[0 : front_matter_end + 3]
|
|
199
|
+
content = content[front_matter_end + 3 :].strip()
|
|
200
|
+
return front_matter, content
|
|
201
|
+
|
|
202
|
+
return "", content
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
def ensure_edit_url(content: str, file_path: Path) -> str:
|
|
206
|
+
"""Ensure editUrl is present in the content.
|
|
207
|
+
Args:
|
|
208
|
+
content (str): Content of the file
|
|
209
|
+
file_path (Path): Path to the file
|
|
210
|
+
"""
|
|
211
|
+
html_placeholder = [line for line in EDIT_URL_HTML.splitlines() if line.strip() != ""][0]
|
|
212
|
+
if html_placeholder in content:
|
|
213
|
+
return content
|
|
214
|
+
|
|
215
|
+
return content + EDIT_URL_HTML.format(file_path=file_path)
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
@require_optional_import("yaml", "docs")
|
|
219
|
+
def add_authors_and_social_preview(
|
|
220
|
+
website_build_dir: Path,
|
|
221
|
+
target_dir: Path,
|
|
222
|
+
all_authors_info: dict[str, dict[str, str]],
|
|
223
|
+
build_system: build_system = "mintlify",
|
|
224
|
+
) -> None:
|
|
225
|
+
"""Add authors info and social share image to mdx files in the target directory."""
|
|
226
|
+
|
|
227
|
+
social_img_html = (
|
|
228
|
+
"""\n<div>
|
|
229
|
+
<img noZoom className="social-share-img"
|
|
230
|
+
src="https://media.githubusercontent.com/media/ag2ai/ag2/refs/heads/main/website/static/img/cover.png"
|
|
231
|
+
alt="social preview"
|
|
232
|
+
style={{ position: 'absolute', left: '-9999px' }}
|
|
233
|
+
/>
|
|
234
|
+
</div>"""
|
|
235
|
+
if build_system == "mintlify"
|
|
236
|
+
else ""
|
|
237
|
+
)
|
|
238
|
+
|
|
239
|
+
target_file_extension = "mdx" if build_system == "mintlify" else "md"
|
|
240
|
+
for file_path in target_dir.glob(f"**/*.{target_file_extension}"):
|
|
241
|
+
try:
|
|
242
|
+
front_matter_string, content = separate_front_matter_and_content(file_path)
|
|
243
|
+
|
|
244
|
+
# Convert single author to list and handle authors
|
|
245
|
+
front_matter = yaml.safe_load(front_matter_string[4:-3])
|
|
246
|
+
authors = front_matter.get("authors", [])
|
|
247
|
+
authors_list = [authors] if isinstance(authors, str) else authors
|
|
248
|
+
|
|
249
|
+
# Generate authors HTML
|
|
250
|
+
authors_html = (
|
|
251
|
+
construct_authors_html(authors_list, all_authors_info, build_system)
|
|
252
|
+
if '<div class="blog-authors">' not in content
|
|
253
|
+
else ""
|
|
254
|
+
)
|
|
255
|
+
|
|
256
|
+
# Combine content
|
|
257
|
+
new_content = f"{front_matter_string}\n{social_img_html}\n{authors_html}\n{content}"
|
|
258
|
+
|
|
259
|
+
# ensure editUrl is present
|
|
260
|
+
|
|
261
|
+
if build_system == "mintlify":
|
|
262
|
+
rel_file_path = (
|
|
263
|
+
str(file_path.relative_to(website_build_dir.parent))
|
|
264
|
+
.replace("build/docs/", "website/docs/")
|
|
265
|
+
.replace("website/docs/blog/", "website/docs/_blogs/")
|
|
266
|
+
)
|
|
267
|
+
content_with_edit_url = ensure_edit_url(new_content, Path(rel_file_path))
|
|
268
|
+
|
|
269
|
+
# replace the mkdocs excerpt marker
|
|
270
|
+
content_with_edit_url = content_with_edit_url.replace(r"\<!-- more -->", "")
|
|
271
|
+
|
|
272
|
+
file_path.write_text(f"{content_with_edit_url}\n", encoding="utf-8")
|
|
273
|
+
|
|
274
|
+
else:
|
|
275
|
+
file_path.write_text(f"{new_content}\n", encoding="utf-8")
|
|
276
|
+
|
|
277
|
+
except Exception as e:
|
|
278
|
+
print(f"Error processing {file_path}: {e}")
|
|
279
|
+
continue
|
|
280
|
+
|
|
281
|
+
|
|
282
|
+
@require_optional_import("yaml", "docs")
|
|
283
|
+
def get_authors_info(authors_yml: Path) -> dict[str, dict[str, str]]:
|
|
284
|
+
try:
|
|
285
|
+
all_authors_info = yaml.safe_load(authors_yml.read_text(encoding="utf-8"))["authors"]
|
|
286
|
+
except (yaml.YAMLError, OSError) as e:
|
|
287
|
+
print(f"Error reading authors file: {e}")
|
|
288
|
+
sys.exit(1)
|
|
289
|
+
|
|
290
|
+
return all_authors_info # type: ignore [no-any-return]
|
|
291
|
+
|
|
292
|
+
|
|
293
|
+
@require_optional_import("yaml", "docs")
|
|
294
|
+
def render_gallery_html(gallery_file_path: Path) -> str:
|
|
295
|
+
"""Renders a gallery of items with tag filtering
|
|
296
|
+
|
|
297
|
+
Args:
|
|
298
|
+
gallery_file_path: Path to the YAML file containing gallery items
|
|
299
|
+
|
|
300
|
+
Returns:
|
|
301
|
+
HTML string for the gallery
|
|
302
|
+
"""
|
|
303
|
+
try:
|
|
304
|
+
# Load gallery items from YAML file
|
|
305
|
+
with open(gallery_file_path, "r") as file:
|
|
306
|
+
gallery_items = yaml.safe_load(file)
|
|
307
|
+
|
|
308
|
+
# Ensure gallery_items is a list
|
|
309
|
+
if not isinstance(gallery_items, list):
|
|
310
|
+
return f"<div class='error'>Error: YAML file did not contain a list, but a {type(gallery_items)}</div>"
|
|
311
|
+
|
|
312
|
+
# Extract all unique tags from gallery items
|
|
313
|
+
all_tags = []
|
|
314
|
+
for item in gallery_items:
|
|
315
|
+
if not isinstance(item, dict):
|
|
316
|
+
continue
|
|
317
|
+
|
|
318
|
+
if "tags" in item and item["tags"]:
|
|
319
|
+
all_tags.extend(item["tags"])
|
|
320
|
+
all_tags = sorted(list(set(all_tags)))
|
|
321
|
+
|
|
322
|
+
# Generate HTML directly
|
|
323
|
+
html = '<div class="examples-gallery-container">'
|
|
324
|
+
|
|
325
|
+
# Generate tag filter select
|
|
326
|
+
html += '<select multiple class="tag-filter" data-placeholder="Filter by tags">'
|
|
327
|
+
for tag in all_tags:
|
|
328
|
+
html += f'<option value="{tag}">{tag}</option>'
|
|
329
|
+
html += "</select>"
|
|
330
|
+
|
|
331
|
+
# Generate gallery cards
|
|
332
|
+
html += '<div class="gallery-cards">'
|
|
333
|
+
|
|
334
|
+
for item in gallery_items:
|
|
335
|
+
# Skip if item is not a dictionary
|
|
336
|
+
if not isinstance(item, dict):
|
|
337
|
+
continue
|
|
338
|
+
|
|
339
|
+
image_url = item.get("image", "default.png")
|
|
340
|
+
if image_url and not isinstance(image_url, str):
|
|
341
|
+
# Handle case where image is not a string
|
|
342
|
+
image_url = "default.png"
|
|
343
|
+
|
|
344
|
+
if image_url and not image_url.startswith("http"):
|
|
345
|
+
image_url = f"../../../../assets/img/gallery/{image_url}"
|
|
346
|
+
|
|
347
|
+
# Handle default image
|
|
348
|
+
if not image_url:
|
|
349
|
+
image_url = "../../../../assets/img/gallery/default.png"
|
|
350
|
+
|
|
351
|
+
# Tags HTML
|
|
352
|
+
tags_html = ""
|
|
353
|
+
if "tags" in item and item["tags"]:
|
|
354
|
+
tags_html = '<div class="tags-container">'
|
|
355
|
+
for tag in item["tags"]:
|
|
356
|
+
tags_html += f'<span class="tag" data-tag="{tag}">{tag}</span>'
|
|
357
|
+
tags_html += "</div>"
|
|
358
|
+
|
|
359
|
+
# Badges HTML
|
|
360
|
+
badges_html = ""
|
|
361
|
+
notebook_src = item.get("source", None)
|
|
362
|
+
|
|
363
|
+
if notebook_src:
|
|
364
|
+
colab_href = f"https://colab.research.google.com/github/ag2ai/ag2/blob/main/{notebook_src}"
|
|
365
|
+
github_href = f"https://github.com/ag2ai/ag2/blob/main/{notebook_src}"
|
|
366
|
+
badges_html = f"""
|
|
367
|
+
<div class="badges">
|
|
368
|
+
<a style="margin-right: 5px" href="{colab_href}" target="_blank">
|
|
369
|
+
<img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab"/>
|
|
370
|
+
</a>
|
|
371
|
+
<p class="hidden">{item.get("title", "")}</p>
|
|
372
|
+
<a href="{github_href}" target="_blank">
|
|
373
|
+
<img alt="GitHub" src="https://img.shields.io/badge/Open%20on%20GitHub-grey?logo=github"/>
|
|
374
|
+
</a>
|
|
375
|
+
</div>
|
|
376
|
+
"""
|
|
377
|
+
|
|
378
|
+
# Generate card HTML with safer access to attributes
|
|
379
|
+
tags_str = ",".join(item.get("tags", [])) if isinstance(item.get("tags"), list) else ""
|
|
380
|
+
|
|
381
|
+
# Generate HTML for image tag
|
|
382
|
+
img_tag = (
|
|
383
|
+
f'<img src="{image_url}" alt="{item.get("title", "")}" class="card-image">' if not notebook_src else ""
|
|
384
|
+
)
|
|
385
|
+
|
|
386
|
+
data_link_target = "_self" if notebook_src else "_blank"
|
|
387
|
+
html += f"""
|
|
388
|
+
<div class="card" data-link="{item.get("link", "#")}" data-rel-link="{item.get("rel_link", "#")}" data-tags="{tags_str}" data-link-target="{data_link_target}">
|
|
389
|
+
<div class="card-container">
|
|
390
|
+
{img_tag}
|
|
391
|
+
<p class="card-title">{item.get("title", "")}</p>
|
|
392
|
+
{badges_html}
|
|
393
|
+
<p class="card-description">{item.get("description", item.get("title", ""))}</p>
|
|
394
|
+
{tags_html}
|
|
395
|
+
</div>
|
|
396
|
+
</div>
|
|
397
|
+
"""
|
|
398
|
+
|
|
399
|
+
# Close containers
|
|
400
|
+
html += """
|
|
401
|
+
</div>
|
|
402
|
+
</div>
|
|
403
|
+
"""
|
|
404
|
+
|
|
405
|
+
return html
|
|
406
|
+
|
|
407
|
+
except FileNotFoundError:
|
|
408
|
+
return f"<div class='error'>Error: YAML file not found at path: {gallery_file_path}</div>"
|
|
409
|
+
except yaml.YAMLError:
|
|
410
|
+
return f"<div class='error'>Error: Invalid YAML format in file: {gallery_file_path}</div>"
|
|
411
|
+
except Exception as e:
|
|
412
|
+
return f"<div class='error'>Error: {str(e)}</div>"
|
|
@@ -0,0 +1,44 @@
|
|
|
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
|
+
# Portions derived from https://github.com/microsoft/autogen are under the MIT License.
|
|
6
|
+
# SPDX-License-Identifier: MIT
|
|
7
|
+
from .agent import Agent, LLMAgent
|
|
8
|
+
from .assistant_agent import AssistantAgent
|
|
9
|
+
from .chat import ChatResult, a_initiate_chats, initiate_chats
|
|
10
|
+
|
|
11
|
+
# Imported last to avoid circular imports
|
|
12
|
+
from .contrib.swarm_agent import (
|
|
13
|
+
a_initiate_swarm_chat,
|
|
14
|
+
a_run_swarm,
|
|
15
|
+
run_swarm,
|
|
16
|
+
)
|
|
17
|
+
from .conversable_agent import ConversableAgent, UpdateSystemMessage, register_function
|
|
18
|
+
from .group.multi_agent_chat import a_initiate_group_chat, a_run_group_chat, initiate_group_chat, run_group_chat
|
|
19
|
+
from .groupchat import GroupChat, GroupChatManager
|
|
20
|
+
from .user_proxy_agent import UserProxyAgent
|
|
21
|
+
from .utils import gather_usage_summary
|
|
22
|
+
|
|
23
|
+
__all__ = [
|
|
24
|
+
"Agent",
|
|
25
|
+
"AssistantAgent",
|
|
26
|
+
"ChatResult",
|
|
27
|
+
"ConversableAgent",
|
|
28
|
+
"GroupChat",
|
|
29
|
+
"GroupChatManager",
|
|
30
|
+
"LLMAgent",
|
|
31
|
+
"UpdateSystemMessage",
|
|
32
|
+
"UserProxyAgent",
|
|
33
|
+
"a_initiate_chats",
|
|
34
|
+
"a_initiate_group_chat",
|
|
35
|
+
"a_initiate_swarm_chat",
|
|
36
|
+
"a_run_group_chat",
|
|
37
|
+
"a_run_swarm",
|
|
38
|
+
"gather_usage_summary",
|
|
39
|
+
"initiate_chats",
|
|
40
|
+
"initiate_group_chat",
|
|
41
|
+
"register_function",
|
|
42
|
+
"run_group_chat",
|
|
43
|
+
"run_swarm",
|
|
44
|
+
]
|
|
@@ -0,0 +1,182 @@
|
|
|
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
|
+
# Portions derived from https://github.com/microsoft/autogen are under the MIT License.
|
|
6
|
+
# SPDX-License-Identifier: MIT
|
|
7
|
+
from typing import TYPE_CHECKING, Any, Optional, Protocol, TypeVar, Union, runtime_checkable
|
|
8
|
+
|
|
9
|
+
from ..doc_utils import export_module
|
|
10
|
+
|
|
11
|
+
__all__ = ["Agent", "LLMAgent", "LLMMessageType"]
|
|
12
|
+
|
|
13
|
+
Tool = TypeVar("Tool")
|
|
14
|
+
|
|
15
|
+
LLMMessageType = dict[str, Any]
|
|
16
|
+
|
|
17
|
+
DEFAULT_SUMMARY_METHOD = "last_msg"
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
@runtime_checkable
|
|
21
|
+
@export_module("autogen")
|
|
22
|
+
class Agent(Protocol):
|
|
23
|
+
"""(In preview) A protocol for Agent.
|
|
24
|
+
|
|
25
|
+
An agent can communicate with other agents and perform actions.
|
|
26
|
+
Different agents can differ in what actions they perform in the `receive` method.
|
|
27
|
+
"""
|
|
28
|
+
|
|
29
|
+
@property
|
|
30
|
+
def name(self) -> str:
|
|
31
|
+
"""The name of the agent."""
|
|
32
|
+
...
|
|
33
|
+
|
|
34
|
+
@property
|
|
35
|
+
def description(self) -> str:
|
|
36
|
+
"""The description of the agent. Used for the agent's introduction in
|
|
37
|
+
a group chat setting.
|
|
38
|
+
"""
|
|
39
|
+
...
|
|
40
|
+
|
|
41
|
+
def send(
|
|
42
|
+
self,
|
|
43
|
+
message: Union[dict[str, Any], str],
|
|
44
|
+
recipient: "Agent",
|
|
45
|
+
request_reply: Optional[bool] = None,
|
|
46
|
+
) -> None:
|
|
47
|
+
"""Send a message to another agent.
|
|
48
|
+
|
|
49
|
+
Args:
|
|
50
|
+
message (dict or str): the message to send. If a dict, it should be
|
|
51
|
+
a JSON-serializable and follows the OpenAI's ChatCompletion schema.
|
|
52
|
+
recipient (Agent): the recipient of the message.
|
|
53
|
+
request_reply (bool): whether to request a reply from the recipient.
|
|
54
|
+
"""
|
|
55
|
+
...
|
|
56
|
+
|
|
57
|
+
async def a_send(
|
|
58
|
+
self,
|
|
59
|
+
message: Union[dict[str, Any], str],
|
|
60
|
+
recipient: "Agent",
|
|
61
|
+
request_reply: Optional[bool] = None,
|
|
62
|
+
) -> None:
|
|
63
|
+
"""(Async) Send a message to another agent.
|
|
64
|
+
|
|
65
|
+
Args:
|
|
66
|
+
message (dict or str): the message to send. If a dict, it should be
|
|
67
|
+
a JSON-serializable and follows the OpenAI's ChatCompletion schema.
|
|
68
|
+
recipient (Agent): the recipient of the message.
|
|
69
|
+
request_reply (bool): whether to request a reply from the recipient.
|
|
70
|
+
"""
|
|
71
|
+
...
|
|
72
|
+
|
|
73
|
+
def receive(
|
|
74
|
+
self,
|
|
75
|
+
message: Union[dict[str, Any], str],
|
|
76
|
+
sender: "Agent",
|
|
77
|
+
request_reply: Optional[bool] = None,
|
|
78
|
+
) -> None:
|
|
79
|
+
"""Receive a message from another agent.
|
|
80
|
+
|
|
81
|
+
Args:
|
|
82
|
+
message (dict or str): the message received. If a dict, it should be
|
|
83
|
+
a JSON-serializable and follows the OpenAI's ChatCompletion schema.
|
|
84
|
+
sender (Agent): the sender of the message.
|
|
85
|
+
request_reply (bool): whether the sender requests a reply.
|
|
86
|
+
"""
|
|
87
|
+
|
|
88
|
+
async def a_receive(
|
|
89
|
+
self,
|
|
90
|
+
message: Union[dict[str, Any], str],
|
|
91
|
+
sender: "Agent",
|
|
92
|
+
request_reply: Optional[bool] = None,
|
|
93
|
+
) -> None:
|
|
94
|
+
"""(Async) Receive a message from another agent.
|
|
95
|
+
|
|
96
|
+
Args:
|
|
97
|
+
message (dict or str): the message received. If a dict, it should be
|
|
98
|
+
a JSON-serializable and follows the OpenAI's ChatCompletion schema.
|
|
99
|
+
sender (Agent): the sender of the message.
|
|
100
|
+
request_reply (bool): whether the sender requests a reply.
|
|
101
|
+
"""
|
|
102
|
+
...
|
|
103
|
+
|
|
104
|
+
def generate_reply(
|
|
105
|
+
self,
|
|
106
|
+
messages: Optional[list[dict[str, Any]]] = None,
|
|
107
|
+
sender: Optional["Agent"] = None,
|
|
108
|
+
**kwargs: Any,
|
|
109
|
+
) -> Union[str, dict[str, Any], None]:
|
|
110
|
+
"""Generate a reply based on the received messages.
|
|
111
|
+
|
|
112
|
+
Args:
|
|
113
|
+
messages (list[dict[str, Any]]): a list of messages received from other agents.
|
|
114
|
+
The messages are dictionaries that are JSON-serializable and
|
|
115
|
+
follows the OpenAI's ChatCompletion schema.
|
|
116
|
+
sender: sender of an Agent instance.
|
|
117
|
+
**kwargs: Additional keyword arguments.
|
|
118
|
+
|
|
119
|
+
Returns:
|
|
120
|
+
str or dict or None: the generated reply. If None, no reply is generated.
|
|
121
|
+
"""
|
|
122
|
+
|
|
123
|
+
async def a_generate_reply(
|
|
124
|
+
self,
|
|
125
|
+
messages: Optional[list[dict[str, Any]]] = None,
|
|
126
|
+
sender: Optional["Agent"] = None,
|
|
127
|
+
**kwargs: Any,
|
|
128
|
+
) -> Union[str, dict[str, Any], None]:
|
|
129
|
+
"""(Async) Generate a reply based on the received messages.
|
|
130
|
+
|
|
131
|
+
Args:
|
|
132
|
+
messages (list[dict[str, Any]]): a list of messages received from other agents.
|
|
133
|
+
The messages are dictionaries that are JSON-serializable and
|
|
134
|
+
follows the OpenAI's ChatCompletion schema.
|
|
135
|
+
sender: sender of an Agent instance.
|
|
136
|
+
**kwargs: Additional keyword arguments.
|
|
137
|
+
|
|
138
|
+
Returns:
|
|
139
|
+
str or dict or None: the generated reply. If None, no reply is generated.
|
|
140
|
+
"""
|
|
141
|
+
...
|
|
142
|
+
|
|
143
|
+
def set_ui_tools(self, tools: list[Tool]) -> None:
|
|
144
|
+
"""Set the UI tools for the agent.
|
|
145
|
+
|
|
146
|
+
Args:
|
|
147
|
+
tools: a list of UI tools to set.
|
|
148
|
+
"""
|
|
149
|
+
...
|
|
150
|
+
|
|
151
|
+
def unset_ui_tools(self, tools: list[Tool]) -> None:
|
|
152
|
+
"""Unset the UI tools for the agent.
|
|
153
|
+
|
|
154
|
+
Args:
|
|
155
|
+
tools: a list of UI tools to set.
|
|
156
|
+
"""
|
|
157
|
+
...
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
@runtime_checkable
|
|
161
|
+
@export_module("autogen")
|
|
162
|
+
class LLMAgent(Agent, Protocol):
|
|
163
|
+
"""(In preview) A protocol for an LLM agent."""
|
|
164
|
+
|
|
165
|
+
@property
|
|
166
|
+
def system_message(self) -> str:
|
|
167
|
+
"""The system message of this agent."""
|
|
168
|
+
|
|
169
|
+
def update_system_message(self, system_message: str) -> None:
|
|
170
|
+
"""Update this agent's system message.
|
|
171
|
+
|
|
172
|
+
Args:
|
|
173
|
+
system_message (str): system message for inference.
|
|
174
|
+
"""
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
if TYPE_CHECKING:
|
|
178
|
+
# mypy will fail if Conversable agent does not implement Agent protocol
|
|
179
|
+
from .conversable_agent import ConversableAgent
|
|
180
|
+
|
|
181
|
+
def _check_protocol_implementation(agent: ConversableAgent) -> Agent:
|
|
182
|
+
return agent
|