ag2 0.9.1a1__py3-none-any.whl → 0.9.2__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.2.dist-info}/METADATA +272 -75
- ag2-0.9.2.dist-info/RECORD +406 -0
- {ag2-0.9.1a1.dist-info → ag2-0.9.2.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 +4023 -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 +1013 -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 +179 -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 +382 -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/__main__.py +78 -0
- autogen/mcp/mcp_client.py +208 -0
- autogen/mcp/mcp_proxy/__init__.py +19 -0
- autogen/mcp/mcp_proxy/fastapi_code_generator_helpers.py +63 -0
- autogen/mcp/mcp_proxy/mcp_proxy.py +581 -0
- autogen/mcp/mcp_proxy/operation_grouping.py +158 -0
- autogen/mcp/mcp_proxy/operation_renaming.py +114 -0
- autogen/mcp/mcp_proxy/patch_fastapi_code_generator.py +98 -0
- autogen/mcp/mcp_proxy/security.py +400 -0
- autogen/mcp/mcp_proxy/security_schema_visitor.py +37 -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 +1444 -0
- autogen/oai/client_utils.py +169 -0
- autogen/oai/cohere.py +479 -0
- autogen/oai/gemini.py +998 -0
- autogen/oai/gemini_types.py +155 -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 +48 -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/reliable/__init__.py +10 -0
- autogen/tools/experimental/reliable/reliable.py +1316 -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
- templates/client_template/main.jinja2 +69 -0
- templates/config_template/config.jinja2 +7 -0
- templates/main.jinja2 +61 -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.2.dist-info/licenses}/LICENSE +0 -0
- {ag2-0.9.1a1.dist-info → ag2-0.9.2.dist-info/licenses}/NOTICE.md +0 -0
|
@@ -0,0 +1,46 @@
|
|
|
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/https://github.com/Lancetnik/FastDepends are under the MIT License.
|
|
6
|
+
# SPDX-License-Identifier: MIT
|
|
7
|
+
|
|
8
|
+
from abc import ABC
|
|
9
|
+
from typing import Any, Dict, Optional, TypeVar
|
|
10
|
+
|
|
11
|
+
Cls = TypeVar("Cls", bound="CustomField")
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class CustomField(ABC):
|
|
15
|
+
param_name: Optional[str]
|
|
16
|
+
cast: bool
|
|
17
|
+
required: bool
|
|
18
|
+
|
|
19
|
+
__slots__ = (
|
|
20
|
+
"cast",
|
|
21
|
+
"param_name",
|
|
22
|
+
"required",
|
|
23
|
+
"field",
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
def __init__(
|
|
27
|
+
self,
|
|
28
|
+
*,
|
|
29
|
+
cast: bool = True,
|
|
30
|
+
required: bool = True,
|
|
31
|
+
) -> None:
|
|
32
|
+
self.cast = cast
|
|
33
|
+
self.param_name = None
|
|
34
|
+
self.required = required
|
|
35
|
+
self.field = False
|
|
36
|
+
|
|
37
|
+
def set_param_name(self: Cls, name: str) -> Cls:
|
|
38
|
+
self.param_name = name
|
|
39
|
+
return self
|
|
40
|
+
|
|
41
|
+
def use(self, /, **kwargs: Any) -> Dict[str, Any]:
|
|
42
|
+
assert self.param_name, "You should specify `param_name` before using"
|
|
43
|
+
return kwargs
|
|
44
|
+
|
|
45
|
+
def use_field(self, kwargs: Dict[str, Any]) -> None:
|
|
46
|
+
raise NotImplementedError("You should implement `use_field` method.")
|
|
@@ -0,0 +1,6 @@
|
|
|
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/https://github.com/Lancetnik/FastDepends are under the MIT License.
|
|
6
|
+
# SPDX-License-Identifier: MIT
|
|
@@ -0,0 +1,66 @@
|
|
|
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/https://github.com/Lancetnik/FastDepends are under the MIT License.
|
|
6
|
+
# SPDX-License-Identifier: MIT
|
|
7
|
+
|
|
8
|
+
from typing import Any, Dict, List, Optional
|
|
9
|
+
|
|
10
|
+
from ._compat import PYDANTIC_V2, create_model, model_schema
|
|
11
|
+
from .core import CallModel
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def get_schema(
|
|
15
|
+
call: CallModel[Any, Any],
|
|
16
|
+
embed: bool = False,
|
|
17
|
+
resolve_refs: bool = False,
|
|
18
|
+
) -> Dict[str, Any]:
|
|
19
|
+
assert call.model, "Call should has a model"
|
|
20
|
+
params_model = create_model( # type: ignore[call-overload]
|
|
21
|
+
call.model.__name__, **call.flat_params
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
body: Dict[str, Any] = model_schema(params_model)
|
|
25
|
+
|
|
26
|
+
if not call.flat_params:
|
|
27
|
+
body = {"title": body["title"], "type": "null"}
|
|
28
|
+
|
|
29
|
+
if resolve_refs:
|
|
30
|
+
pydantic_key = "$defs" if PYDANTIC_V2 else "definitions"
|
|
31
|
+
body = _move_pydantic_refs(body, pydantic_key)
|
|
32
|
+
body.pop(pydantic_key, None)
|
|
33
|
+
|
|
34
|
+
if embed and len(body["properties"]) == 1:
|
|
35
|
+
body = list(body["properties"].values())[0]
|
|
36
|
+
|
|
37
|
+
return body
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def _move_pydantic_refs(original: Any, key: str, refs: Optional[Dict[str, Any]] = None) -> Any:
|
|
41
|
+
if not isinstance(original, Dict):
|
|
42
|
+
return original
|
|
43
|
+
|
|
44
|
+
data = original.copy()
|
|
45
|
+
|
|
46
|
+
if refs is None:
|
|
47
|
+
raw_refs = data.get(key, {})
|
|
48
|
+
refs = _move_pydantic_refs(raw_refs, key, raw_refs)
|
|
49
|
+
|
|
50
|
+
name: Optional[str] = None
|
|
51
|
+
for k in data:
|
|
52
|
+
if k == "$ref":
|
|
53
|
+
name = data[k].replace(f"#/{key}/", "")
|
|
54
|
+
|
|
55
|
+
elif isinstance(data[k], dict):
|
|
56
|
+
data[k] = _move_pydantic_refs(data[k], key, refs)
|
|
57
|
+
|
|
58
|
+
elif isinstance(data[k], List):
|
|
59
|
+
for i in range(len(data[k])):
|
|
60
|
+
data[k][i] = _move_pydantic_refs(data[k][i], key, refs)
|
|
61
|
+
|
|
62
|
+
if name:
|
|
63
|
+
assert refs, "Smth wrong"
|
|
64
|
+
data = refs[name]
|
|
65
|
+
|
|
66
|
+
return data
|
|
@@ -0,0 +1,280 @@
|
|
|
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/https://github.com/Lancetnik/FastDepends are under the MIT License.
|
|
6
|
+
# SPDX-License-Identifier: MIT
|
|
7
|
+
|
|
8
|
+
from contextlib import AsyncExitStack, ExitStack
|
|
9
|
+
from functools import partial, wraps
|
|
10
|
+
from typing import (
|
|
11
|
+
Any,
|
|
12
|
+
AsyncIterator,
|
|
13
|
+
Callable,
|
|
14
|
+
Iterator,
|
|
15
|
+
Optional,
|
|
16
|
+
Protocol,
|
|
17
|
+
Sequence,
|
|
18
|
+
TypeVar,
|
|
19
|
+
Union,
|
|
20
|
+
cast,
|
|
21
|
+
overload,
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
from typing_extensions import ParamSpec
|
|
25
|
+
|
|
26
|
+
from ._compat import ConfigDict
|
|
27
|
+
from .core import CallModel, build_call_model
|
|
28
|
+
from .dependencies import dependency_provider, model
|
|
29
|
+
|
|
30
|
+
P = ParamSpec("P")
|
|
31
|
+
T = TypeVar("T")
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def Depends( # noqa: N802
|
|
35
|
+
dependency: Callable[P, T],
|
|
36
|
+
*,
|
|
37
|
+
use_cache: bool = True,
|
|
38
|
+
cast: bool = True,
|
|
39
|
+
) -> Any:
|
|
40
|
+
return model.Depends(
|
|
41
|
+
dependency=dependency,
|
|
42
|
+
use_cache=use_cache,
|
|
43
|
+
cast=cast,
|
|
44
|
+
)
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
class _InjectWrapper(Protocol[P, T]):
|
|
48
|
+
def __call__(
|
|
49
|
+
self,
|
|
50
|
+
func: Callable[P, T],
|
|
51
|
+
model: Optional[CallModel[P, T]] = None,
|
|
52
|
+
) -> Callable[P, T]: ...
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
@overload
|
|
56
|
+
def inject( # pragma: no cover
|
|
57
|
+
func: None,
|
|
58
|
+
*,
|
|
59
|
+
cast: bool = True,
|
|
60
|
+
extra_dependencies: Sequence[model.Depends] = (),
|
|
61
|
+
pydantic_config: Optional[ConfigDict] = None,
|
|
62
|
+
dependency_overrides_provider: Optional[Any] = dependency_provider,
|
|
63
|
+
wrap_model: Callable[[CallModel[P, T]], CallModel[P, T]] = lambda x: x,
|
|
64
|
+
) -> _InjectWrapper[P, T]: ...
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
@overload
|
|
68
|
+
def inject( # pragma: no cover
|
|
69
|
+
func: Callable[P, T],
|
|
70
|
+
*,
|
|
71
|
+
cast: bool = True,
|
|
72
|
+
extra_dependencies: Sequence[model.Depends] = (),
|
|
73
|
+
pydantic_config: Optional[ConfigDict] = None,
|
|
74
|
+
dependency_overrides_provider: Optional[Any] = dependency_provider,
|
|
75
|
+
wrap_model: Callable[[CallModel[P, T]], CallModel[P, T]] = lambda x: x,
|
|
76
|
+
) -> Callable[P, T]: ...
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def inject(
|
|
80
|
+
func: Optional[Callable[P, T]] = None,
|
|
81
|
+
*,
|
|
82
|
+
cast: bool = True,
|
|
83
|
+
extra_dependencies: Sequence[model.Depends] = (),
|
|
84
|
+
pydantic_config: Optional[ConfigDict] = None,
|
|
85
|
+
dependency_overrides_provider: Optional[Any] = dependency_provider,
|
|
86
|
+
wrap_model: Callable[[CallModel[P, T]], CallModel[P, T]] = lambda x: x,
|
|
87
|
+
) -> Union[
|
|
88
|
+
Callable[P, T],
|
|
89
|
+
_InjectWrapper[P, T],
|
|
90
|
+
]:
|
|
91
|
+
decorator = _wrap_inject(
|
|
92
|
+
dependency_overrides_provider=dependency_overrides_provider,
|
|
93
|
+
wrap_model=wrap_model,
|
|
94
|
+
extra_dependencies=extra_dependencies,
|
|
95
|
+
cast=cast,
|
|
96
|
+
pydantic_config=pydantic_config,
|
|
97
|
+
)
|
|
98
|
+
|
|
99
|
+
if func is None:
|
|
100
|
+
return decorator
|
|
101
|
+
|
|
102
|
+
else:
|
|
103
|
+
return decorator(func)
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
def _wrap_inject(
|
|
107
|
+
dependency_overrides_provider: Optional[Any],
|
|
108
|
+
wrap_model: Callable[
|
|
109
|
+
[CallModel[P, T]],
|
|
110
|
+
CallModel[P, T],
|
|
111
|
+
],
|
|
112
|
+
extra_dependencies: Sequence[model.Depends],
|
|
113
|
+
cast: bool,
|
|
114
|
+
pydantic_config: Optional[ConfigDict],
|
|
115
|
+
) -> _InjectWrapper[P, T]:
|
|
116
|
+
if (
|
|
117
|
+
dependency_overrides_provider
|
|
118
|
+
and getattr(dependency_overrides_provider, "dependency_overrides", None) is not None
|
|
119
|
+
):
|
|
120
|
+
overrides = dependency_overrides_provider.dependency_overrides
|
|
121
|
+
else:
|
|
122
|
+
overrides = None
|
|
123
|
+
|
|
124
|
+
def func_wrapper(
|
|
125
|
+
func: Callable[P, T],
|
|
126
|
+
model: Optional[CallModel[P, T]] = None,
|
|
127
|
+
) -> Callable[P, T]:
|
|
128
|
+
if model is None:
|
|
129
|
+
real_model = wrap_model(
|
|
130
|
+
build_call_model(
|
|
131
|
+
call=func,
|
|
132
|
+
extra_dependencies=extra_dependencies,
|
|
133
|
+
cast=cast,
|
|
134
|
+
pydantic_config=pydantic_config,
|
|
135
|
+
)
|
|
136
|
+
)
|
|
137
|
+
else:
|
|
138
|
+
real_model = model
|
|
139
|
+
|
|
140
|
+
if real_model.is_async:
|
|
141
|
+
injected_wrapper: Callable[P, T]
|
|
142
|
+
|
|
143
|
+
if real_model.is_generator:
|
|
144
|
+
injected_wrapper = partial(solve_async_gen, real_model, overrides) # type: ignore[assignment]
|
|
145
|
+
|
|
146
|
+
else:
|
|
147
|
+
|
|
148
|
+
@wraps(func)
|
|
149
|
+
async def injected_wrapper(*args: P.args, **kwargs: P.kwargs) -> T:
|
|
150
|
+
async with AsyncExitStack() as stack:
|
|
151
|
+
r = await real_model.asolve(
|
|
152
|
+
*args,
|
|
153
|
+
stack=stack,
|
|
154
|
+
dependency_overrides=overrides,
|
|
155
|
+
cache_dependencies={},
|
|
156
|
+
nested=False,
|
|
157
|
+
**kwargs,
|
|
158
|
+
)
|
|
159
|
+
return r
|
|
160
|
+
|
|
161
|
+
raise AssertionError("unreachable")
|
|
162
|
+
|
|
163
|
+
else:
|
|
164
|
+
if real_model.is_generator:
|
|
165
|
+
injected_wrapper = partial(solve_gen, real_model, overrides) # type: ignore[assignment]
|
|
166
|
+
|
|
167
|
+
else:
|
|
168
|
+
|
|
169
|
+
@wraps(func)
|
|
170
|
+
def injected_wrapper(*args: P.args, **kwargs: P.kwargs) -> T:
|
|
171
|
+
with ExitStack() as stack:
|
|
172
|
+
r = real_model.solve(
|
|
173
|
+
*args,
|
|
174
|
+
stack=stack,
|
|
175
|
+
dependency_overrides=overrides,
|
|
176
|
+
cache_dependencies={},
|
|
177
|
+
nested=False,
|
|
178
|
+
**kwargs,
|
|
179
|
+
)
|
|
180
|
+
return r
|
|
181
|
+
|
|
182
|
+
raise AssertionError("unreachable")
|
|
183
|
+
|
|
184
|
+
return injected_wrapper
|
|
185
|
+
|
|
186
|
+
return func_wrapper
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
class solve_async_gen: # noqa: N801
|
|
190
|
+
_iter: Optional[AsyncIterator[Any]] = None
|
|
191
|
+
|
|
192
|
+
def __init__(
|
|
193
|
+
self,
|
|
194
|
+
model: "CallModel[..., Any]",
|
|
195
|
+
overrides: Optional[Any],
|
|
196
|
+
*args: Any,
|
|
197
|
+
**kwargs: Any,
|
|
198
|
+
):
|
|
199
|
+
self.call = model
|
|
200
|
+
self.args = args
|
|
201
|
+
self.kwargs = kwargs
|
|
202
|
+
self.overrides = overrides
|
|
203
|
+
|
|
204
|
+
def __aiter__(self) -> "solve_async_gen":
|
|
205
|
+
self._iter = None
|
|
206
|
+
self.stack = AsyncExitStack()
|
|
207
|
+
return self
|
|
208
|
+
|
|
209
|
+
async def __anext__(self) -> Any:
|
|
210
|
+
if self._iter is None:
|
|
211
|
+
stack = self.stack = AsyncExitStack()
|
|
212
|
+
await self.stack.__aenter__()
|
|
213
|
+
self._iter = cast(
|
|
214
|
+
AsyncIterator[Any],
|
|
215
|
+
(
|
|
216
|
+
await self.call.asolve(
|
|
217
|
+
*self.args,
|
|
218
|
+
stack=stack,
|
|
219
|
+
dependency_overrides=self.overrides,
|
|
220
|
+
cache_dependencies={},
|
|
221
|
+
nested=False,
|
|
222
|
+
**self.kwargs,
|
|
223
|
+
)
|
|
224
|
+
).__aiter__(),
|
|
225
|
+
)
|
|
226
|
+
|
|
227
|
+
try:
|
|
228
|
+
r = await self._iter.__anext__()
|
|
229
|
+
except StopAsyncIteration as e:
|
|
230
|
+
await self.stack.__aexit__(None, None, None)
|
|
231
|
+
raise e
|
|
232
|
+
else:
|
|
233
|
+
return r
|
|
234
|
+
|
|
235
|
+
|
|
236
|
+
class solve_gen: # noqa: N801
|
|
237
|
+
_iter: Optional[Iterator[Any]] = None
|
|
238
|
+
|
|
239
|
+
def __init__(
|
|
240
|
+
self,
|
|
241
|
+
model: "CallModel[..., Any]",
|
|
242
|
+
overrides: Optional[Any],
|
|
243
|
+
*args: Any,
|
|
244
|
+
**kwargs: Any,
|
|
245
|
+
):
|
|
246
|
+
self.call = model
|
|
247
|
+
self.args = args
|
|
248
|
+
self.kwargs = kwargs
|
|
249
|
+
self.overrides = overrides
|
|
250
|
+
|
|
251
|
+
def __iter__(self) -> "solve_gen":
|
|
252
|
+
self._iter = None
|
|
253
|
+
self.stack = ExitStack()
|
|
254
|
+
return self
|
|
255
|
+
|
|
256
|
+
def __next__(self) -> Any:
|
|
257
|
+
if self._iter is None:
|
|
258
|
+
stack = self.stack = ExitStack()
|
|
259
|
+
self.stack.__enter__()
|
|
260
|
+
self._iter = cast(
|
|
261
|
+
Iterator[Any],
|
|
262
|
+
iter(
|
|
263
|
+
self.call.solve(
|
|
264
|
+
*self.args,
|
|
265
|
+
stack=stack,
|
|
266
|
+
dependency_overrides=self.overrides,
|
|
267
|
+
cache_dependencies={},
|
|
268
|
+
nested=False,
|
|
269
|
+
**self.kwargs,
|
|
270
|
+
)
|
|
271
|
+
),
|
|
272
|
+
)
|
|
273
|
+
|
|
274
|
+
try:
|
|
275
|
+
r = next(self._iter)
|
|
276
|
+
except StopIteration as e:
|
|
277
|
+
self.stack.__exit__(None, None, None)
|
|
278
|
+
raise e
|
|
279
|
+
else:
|
|
280
|
+
return r
|
|
@@ -0,0 +1,187 @@
|
|
|
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/https://github.com/Lancetnik/FastDepends are under the MIT License.
|
|
6
|
+
# SPDX-License-Identifier: MIT
|
|
7
|
+
|
|
8
|
+
import asyncio
|
|
9
|
+
import functools
|
|
10
|
+
import inspect
|
|
11
|
+
from contextlib import AsyncExitStack, ExitStack, asynccontextmanager, contextmanager
|
|
12
|
+
from typing import (
|
|
13
|
+
TYPE_CHECKING,
|
|
14
|
+
Any,
|
|
15
|
+
AsyncGenerator,
|
|
16
|
+
AsyncIterable,
|
|
17
|
+
Awaitable,
|
|
18
|
+
Callable,
|
|
19
|
+
ContextManager,
|
|
20
|
+
Dict,
|
|
21
|
+
ForwardRef,
|
|
22
|
+
List,
|
|
23
|
+
Tuple,
|
|
24
|
+
TypeVar,
|
|
25
|
+
Union,
|
|
26
|
+
cast,
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
import anyio
|
|
30
|
+
from typing_extensions import (
|
|
31
|
+
Annotated,
|
|
32
|
+
ParamSpec,
|
|
33
|
+
get_args,
|
|
34
|
+
get_origin,
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
from ._compat import evaluate_forwardref
|
|
38
|
+
|
|
39
|
+
if TYPE_CHECKING:
|
|
40
|
+
from types import FrameType
|
|
41
|
+
|
|
42
|
+
P = ParamSpec("P")
|
|
43
|
+
T = TypeVar("T")
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
async def run_async(
|
|
47
|
+
func: Union[
|
|
48
|
+
Callable[P, T],
|
|
49
|
+
Callable[P, Awaitable[T]],
|
|
50
|
+
],
|
|
51
|
+
*args: P.args,
|
|
52
|
+
**kwargs: P.kwargs,
|
|
53
|
+
) -> T:
|
|
54
|
+
if is_coroutine_callable(func):
|
|
55
|
+
return await cast(Callable[P, Awaitable[T]], func)(*args, **kwargs)
|
|
56
|
+
else:
|
|
57
|
+
return await run_in_threadpool(cast(Callable[P, T], func), *args, **kwargs)
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
async def run_in_threadpool(func: Callable[P, T], *args: P.args, **kwargs: P.kwargs) -> T:
|
|
61
|
+
if kwargs:
|
|
62
|
+
func = functools.partial(func, **kwargs)
|
|
63
|
+
return await anyio.to_thread.run_sync(func, *args)
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
async def solve_generator_async(
|
|
67
|
+
*sub_args: Any, call: Callable[..., Any], stack: AsyncExitStack, **sub_values: Any
|
|
68
|
+
) -> Any:
|
|
69
|
+
if is_gen_callable(call):
|
|
70
|
+
cm = contextmanager_in_threadpool(contextmanager(call)(**sub_values))
|
|
71
|
+
elif is_async_gen_callable(call): # pragma: no branch
|
|
72
|
+
cm = asynccontextmanager(call)(*sub_args, **sub_values)
|
|
73
|
+
return await stack.enter_async_context(cm)
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def solve_generator_sync(*sub_args: Any, call: Callable[..., Any], stack: ExitStack, **sub_values: Any) -> Any:
|
|
77
|
+
cm = contextmanager(call)(*sub_args, **sub_values)
|
|
78
|
+
return stack.enter_context(cm)
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def get_typed_signature(call: Callable[..., Any]) -> Tuple[inspect.Signature, Any]:
|
|
82
|
+
signature = inspect.signature(call)
|
|
83
|
+
|
|
84
|
+
locals = collect_outer_stack_locals()
|
|
85
|
+
|
|
86
|
+
# We unwrap call to get the original unwrapped function
|
|
87
|
+
call = inspect.unwrap(call)
|
|
88
|
+
|
|
89
|
+
globalns = getattr(call, "__globals__", {})
|
|
90
|
+
typed_params = [
|
|
91
|
+
inspect.Parameter(
|
|
92
|
+
name=param.name,
|
|
93
|
+
kind=param.kind,
|
|
94
|
+
default=param.default,
|
|
95
|
+
annotation=get_typed_annotation(
|
|
96
|
+
param.annotation,
|
|
97
|
+
globalns,
|
|
98
|
+
locals,
|
|
99
|
+
),
|
|
100
|
+
)
|
|
101
|
+
for param in signature.parameters.values()
|
|
102
|
+
]
|
|
103
|
+
|
|
104
|
+
return inspect.Signature(typed_params), get_typed_annotation(
|
|
105
|
+
signature.return_annotation,
|
|
106
|
+
globalns,
|
|
107
|
+
locals,
|
|
108
|
+
)
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
def collect_outer_stack_locals() -> Dict[str, Any]:
|
|
112
|
+
frame = inspect.currentframe()
|
|
113
|
+
|
|
114
|
+
frames: List[FrameType] = []
|
|
115
|
+
while frame is not None:
|
|
116
|
+
if "fast_depends" not in frame.f_code.co_filename:
|
|
117
|
+
frames.append(frame)
|
|
118
|
+
frame = frame.f_back
|
|
119
|
+
|
|
120
|
+
locals = {}
|
|
121
|
+
for f in frames[::-1]:
|
|
122
|
+
locals.update(f.f_locals)
|
|
123
|
+
|
|
124
|
+
return locals
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
def get_typed_annotation(
|
|
128
|
+
annotation: Any,
|
|
129
|
+
globalns: Dict[str, Any],
|
|
130
|
+
locals: Dict[str, Any],
|
|
131
|
+
) -> Any:
|
|
132
|
+
if isinstance(annotation, str):
|
|
133
|
+
annotation = ForwardRef(annotation)
|
|
134
|
+
|
|
135
|
+
if isinstance(annotation, ForwardRef):
|
|
136
|
+
annotation = evaluate_forwardref(annotation, globalns, locals)
|
|
137
|
+
|
|
138
|
+
if get_origin(annotation) is Annotated and (args := get_args(annotation)):
|
|
139
|
+
solved_args = [get_typed_annotation(x, globalns, locals) for x in args]
|
|
140
|
+
annotation.__origin__, annotation.__metadata__ = solved_args[0], tuple(solved_args[1:])
|
|
141
|
+
|
|
142
|
+
return annotation
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
@asynccontextmanager
|
|
146
|
+
async def contextmanager_in_threadpool(
|
|
147
|
+
cm: ContextManager[T],
|
|
148
|
+
) -> AsyncGenerator[T, None]:
|
|
149
|
+
exit_limiter = anyio.CapacityLimiter(1)
|
|
150
|
+
try:
|
|
151
|
+
yield await run_in_threadpool(cm.__enter__)
|
|
152
|
+
except Exception as e:
|
|
153
|
+
ok = bool(await anyio.to_thread.run_sync(cm.__exit__, type(e), e, None, limiter=exit_limiter))
|
|
154
|
+
if not ok: # pragma: no branch
|
|
155
|
+
raise e
|
|
156
|
+
else:
|
|
157
|
+
await anyio.to_thread.run_sync(cm.__exit__, None, None, None, limiter=exit_limiter)
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
def is_gen_callable(call: Callable[..., Any]) -> bool:
|
|
161
|
+
if inspect.isgeneratorfunction(call):
|
|
162
|
+
return True
|
|
163
|
+
dunder_call = getattr(call, "__call__", None) # noqa: B004
|
|
164
|
+
return inspect.isgeneratorfunction(dunder_call)
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
def is_async_gen_callable(call: Callable[..., Any]) -> bool:
|
|
168
|
+
if inspect.isasyncgenfunction(call):
|
|
169
|
+
return True
|
|
170
|
+
dunder_call = getattr(call, "__call__", None) # noqa: B004
|
|
171
|
+
return inspect.isasyncgenfunction(dunder_call)
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
def is_coroutine_callable(call: Callable[..., Any]) -> bool:
|
|
175
|
+
if inspect.isclass(call):
|
|
176
|
+
return False
|
|
177
|
+
|
|
178
|
+
if asyncio.iscoroutinefunction(call):
|
|
179
|
+
return True
|
|
180
|
+
|
|
181
|
+
dunder_call = getattr(call, "__call__", None) # noqa: B004
|
|
182
|
+
return asyncio.iscoroutinefunction(dunder_call)
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
async def async_map(func: Callable[..., T], async_iterable: AsyncIterable[Any]) -> AsyncIterable[T]:
|
|
186
|
+
async for i in async_iterable:
|
|
187
|
+
yield func(i)
|
|
@@ -0,0 +1,83 @@
|
|
|
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 __future__ import annotations
|
|
8
|
+
|
|
9
|
+
from collections.abc import Iterable
|
|
10
|
+
from typing import Literal, Optional
|
|
11
|
+
|
|
12
|
+
from .import_utils import optional_import_block
|
|
13
|
+
|
|
14
|
+
with optional_import_block() as result:
|
|
15
|
+
from termcolor import colored
|
|
16
|
+
|
|
17
|
+
if not result.is_successful:
|
|
18
|
+
# termcolor is an optional dependency - if it cannot be imported then no color is used.
|
|
19
|
+
# Alternatively the envvar NO_COLOR can be used to disable color.
|
|
20
|
+
# To allow for proper typing and for termcolor to be optional we need to re-define the types used in the lib here.
|
|
21
|
+
# This is the direct function definition from termcolor.
|
|
22
|
+
Attribute = Literal[
|
|
23
|
+
"bold",
|
|
24
|
+
"dark",
|
|
25
|
+
"underline",
|
|
26
|
+
"blink",
|
|
27
|
+
"reverse",
|
|
28
|
+
"concealed",
|
|
29
|
+
]
|
|
30
|
+
|
|
31
|
+
Highlight = Literal[
|
|
32
|
+
"on_black",
|
|
33
|
+
"on_grey",
|
|
34
|
+
"on_red",
|
|
35
|
+
"on_green",
|
|
36
|
+
"on_yellow",
|
|
37
|
+
"on_blue",
|
|
38
|
+
"on_magenta",
|
|
39
|
+
"on_cyan",
|
|
40
|
+
"on_light_grey",
|
|
41
|
+
"on_dark_grey",
|
|
42
|
+
"on_light_red",
|
|
43
|
+
"on_light_green",
|
|
44
|
+
"on_light_yellow",
|
|
45
|
+
"on_light_blue",
|
|
46
|
+
"on_light_magenta",
|
|
47
|
+
"on_light_cyan",
|
|
48
|
+
"on_white",
|
|
49
|
+
]
|
|
50
|
+
|
|
51
|
+
Color = Literal[
|
|
52
|
+
"black",
|
|
53
|
+
"grey",
|
|
54
|
+
"red",
|
|
55
|
+
"green",
|
|
56
|
+
"yellow",
|
|
57
|
+
"blue",
|
|
58
|
+
"magenta",
|
|
59
|
+
"cyan",
|
|
60
|
+
"light_grey",
|
|
61
|
+
"dark_grey",
|
|
62
|
+
"light_red",
|
|
63
|
+
"light_green",
|
|
64
|
+
"light_yellow",
|
|
65
|
+
"light_blue",
|
|
66
|
+
"light_magenta",
|
|
67
|
+
"light_cyan",
|
|
68
|
+
"white",
|
|
69
|
+
]
|
|
70
|
+
|
|
71
|
+
def colored(
|
|
72
|
+
text: object,
|
|
73
|
+
color: Optional[Color] = None,
|
|
74
|
+
on_color: Optional[Highlight] = None,
|
|
75
|
+
attrs: Optional[Iterable[Attribute]] = None,
|
|
76
|
+
*,
|
|
77
|
+
no_color: Optional[bool] = None,
|
|
78
|
+
force_color: Optional[bool] = None,
|
|
79
|
+
) -> str:
|
|
80
|
+
return str(text)
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
__all__ = ["colored"]
|
|
@@ -0,0 +1,13 @@
|
|
|
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 logging import getLogger
|
|
6
|
+
|
|
7
|
+
from .tools import get_function_schema, load_basemodels_if_needed, serialize_to_str
|
|
8
|
+
|
|
9
|
+
__all__ = ["get_function_schema", "load_basemodels_if_needed", "serialize_to_str"]
|
|
10
|
+
|
|
11
|
+
logger = getLogger(__name__)
|
|
12
|
+
|
|
13
|
+
logger.info("Importing from 'autogen.function_utils' is deprecated, import from 'autogen.tools' instead.")
|