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,576 @@
|
|
|
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 collections import namedtuple
|
|
9
|
+
from contextlib import AsyncExitStack, ExitStack
|
|
10
|
+
from functools import partial
|
|
11
|
+
from inspect import Parameter, unwrap
|
|
12
|
+
from itertools import chain
|
|
13
|
+
from typing import (
|
|
14
|
+
Any,
|
|
15
|
+
Awaitable,
|
|
16
|
+
Callable,
|
|
17
|
+
Dict,
|
|
18
|
+
Generator,
|
|
19
|
+
Generic,
|
|
20
|
+
Iterable,
|
|
21
|
+
List,
|
|
22
|
+
Optional,
|
|
23
|
+
Sequence,
|
|
24
|
+
Tuple,
|
|
25
|
+
Type,
|
|
26
|
+
TypeVar,
|
|
27
|
+
Union,
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
import anyio
|
|
31
|
+
from typing_extensions import ParamSpec
|
|
32
|
+
|
|
33
|
+
from .._compat import BaseModel, ExceptionGroup, get_aliases
|
|
34
|
+
from ..library import CustomField
|
|
35
|
+
from ..utils import (
|
|
36
|
+
async_map,
|
|
37
|
+
is_async_gen_callable,
|
|
38
|
+
is_coroutine_callable,
|
|
39
|
+
is_gen_callable,
|
|
40
|
+
run_async,
|
|
41
|
+
solve_generator_async,
|
|
42
|
+
solve_generator_sync,
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
P = ParamSpec("P")
|
|
46
|
+
T = TypeVar("T")
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
PriorityPair = namedtuple("PriorityPair", ("call", "dependencies_number", "dependencies_names"))
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
class ResponseModel(BaseModel, Generic[T]):
|
|
53
|
+
response: T
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
class CallModel(Generic[P, T]):
|
|
57
|
+
call: Union[
|
|
58
|
+
Callable[P, T],
|
|
59
|
+
Callable[P, Awaitable[T]],
|
|
60
|
+
]
|
|
61
|
+
is_async: bool
|
|
62
|
+
is_generator: bool
|
|
63
|
+
model: Optional[Type[BaseModel]]
|
|
64
|
+
response_model: Optional[Type[ResponseModel[T]]]
|
|
65
|
+
|
|
66
|
+
params: Dict[str, Tuple[Any, Any]]
|
|
67
|
+
alias_arguments: Tuple[str, ...]
|
|
68
|
+
|
|
69
|
+
dependencies: Dict[str, "CallModel[..., Any]"]
|
|
70
|
+
extra_dependencies: Iterable["CallModel[..., Any]"]
|
|
71
|
+
sorted_dependencies: Tuple[Tuple["CallModel[..., Any]", int], ...]
|
|
72
|
+
custom_fields: Dict[str, CustomField]
|
|
73
|
+
keyword_args: Tuple[str, ...]
|
|
74
|
+
positional_args: Tuple[str, ...]
|
|
75
|
+
var_positional_arg: Optional[str]
|
|
76
|
+
var_keyword_arg: Optional[str]
|
|
77
|
+
|
|
78
|
+
# Dependencies and custom fields
|
|
79
|
+
use_cache: bool
|
|
80
|
+
cast: bool
|
|
81
|
+
|
|
82
|
+
__slots__ = (
|
|
83
|
+
"call",
|
|
84
|
+
"is_async",
|
|
85
|
+
"is_generator",
|
|
86
|
+
"model",
|
|
87
|
+
"response_model",
|
|
88
|
+
"params",
|
|
89
|
+
"alias_arguments",
|
|
90
|
+
"keyword_args",
|
|
91
|
+
"positional_args",
|
|
92
|
+
"var_positional_arg",
|
|
93
|
+
"var_keyword_arg",
|
|
94
|
+
"dependencies",
|
|
95
|
+
"extra_dependencies",
|
|
96
|
+
"sorted_dependencies",
|
|
97
|
+
"custom_fields",
|
|
98
|
+
"use_cache",
|
|
99
|
+
"cast",
|
|
100
|
+
)
|
|
101
|
+
|
|
102
|
+
@property
|
|
103
|
+
def call_name(self) -> str:
|
|
104
|
+
call = unwrap(self.call)
|
|
105
|
+
return getattr(call, "__name__", type(call).__name__)
|
|
106
|
+
|
|
107
|
+
@property
|
|
108
|
+
def flat_params(self) -> Dict[str, Tuple[Any, Any]]:
|
|
109
|
+
params = self.params
|
|
110
|
+
for d in (*self.dependencies.values(), *self.extra_dependencies):
|
|
111
|
+
params.update(d.flat_params)
|
|
112
|
+
return params
|
|
113
|
+
|
|
114
|
+
@property
|
|
115
|
+
def flat_dependencies(
|
|
116
|
+
self,
|
|
117
|
+
) -> Dict[
|
|
118
|
+
Callable[..., Any],
|
|
119
|
+
Tuple[
|
|
120
|
+
"CallModel[..., Any]",
|
|
121
|
+
Tuple[Callable[..., Any], ...],
|
|
122
|
+
],
|
|
123
|
+
]:
|
|
124
|
+
flat: Dict[
|
|
125
|
+
Callable[..., Any],
|
|
126
|
+
Tuple[
|
|
127
|
+
CallModel[..., Any],
|
|
128
|
+
Tuple[Callable[..., Any], ...],
|
|
129
|
+
],
|
|
130
|
+
] = {}
|
|
131
|
+
|
|
132
|
+
for i in (*self.dependencies.values(), *self.extra_dependencies):
|
|
133
|
+
flat.update({
|
|
134
|
+
i.call: (
|
|
135
|
+
i,
|
|
136
|
+
tuple(j.call for j in i.dependencies.values()),
|
|
137
|
+
)
|
|
138
|
+
})
|
|
139
|
+
|
|
140
|
+
flat.update(i.flat_dependencies)
|
|
141
|
+
|
|
142
|
+
return flat
|
|
143
|
+
|
|
144
|
+
def __init__(
|
|
145
|
+
self,
|
|
146
|
+
/,
|
|
147
|
+
call: Union[
|
|
148
|
+
Callable[P, T],
|
|
149
|
+
Callable[P, Awaitable[T]],
|
|
150
|
+
],
|
|
151
|
+
model: Optional[Type[BaseModel]],
|
|
152
|
+
params: Dict[str, Tuple[Any, Any]],
|
|
153
|
+
response_model: Optional[Type[ResponseModel[T]]] = None,
|
|
154
|
+
use_cache: bool = True,
|
|
155
|
+
cast: bool = True,
|
|
156
|
+
is_async: bool = False,
|
|
157
|
+
is_generator: bool = False,
|
|
158
|
+
dependencies: Optional[Dict[str, "CallModel[..., Any]"]] = None,
|
|
159
|
+
extra_dependencies: Optional[Iterable["CallModel[..., Any]"]] = None,
|
|
160
|
+
keyword_args: Optional[List[str]] = None,
|
|
161
|
+
positional_args: Optional[List[str]] = None,
|
|
162
|
+
var_positional_arg: Optional[str] = None,
|
|
163
|
+
var_keyword_arg: Optional[str] = None,
|
|
164
|
+
custom_fields: Optional[Dict[str, CustomField]] = None,
|
|
165
|
+
):
|
|
166
|
+
self.call = call
|
|
167
|
+
self.model = model
|
|
168
|
+
|
|
169
|
+
if model:
|
|
170
|
+
self.alias_arguments = get_aliases(model)
|
|
171
|
+
else: # pragma: no cover
|
|
172
|
+
self.alias_arguments = ()
|
|
173
|
+
|
|
174
|
+
self.keyword_args = tuple(keyword_args or ())
|
|
175
|
+
self.positional_args = tuple(positional_args or ())
|
|
176
|
+
self.var_positional_arg = var_positional_arg
|
|
177
|
+
self.var_keyword_arg = var_keyword_arg
|
|
178
|
+
self.response_model = response_model
|
|
179
|
+
self.use_cache = use_cache
|
|
180
|
+
self.cast = cast
|
|
181
|
+
self.is_async = is_async or is_coroutine_callable(call) or is_async_gen_callable(call)
|
|
182
|
+
self.is_generator = is_generator or is_gen_callable(call) or is_async_gen_callable(call)
|
|
183
|
+
|
|
184
|
+
self.dependencies = dependencies or {}
|
|
185
|
+
self.extra_dependencies = extra_dependencies or ()
|
|
186
|
+
self.custom_fields = custom_fields or {}
|
|
187
|
+
|
|
188
|
+
sorted_dep: List[CallModel[..., Any]] = []
|
|
189
|
+
flat = self.flat_dependencies
|
|
190
|
+
for calls in flat.values():
|
|
191
|
+
_sort_dep(sorted_dep, calls, flat)
|
|
192
|
+
|
|
193
|
+
self.sorted_dependencies = tuple((i, len(i.sorted_dependencies)) for i in sorted_dep if i.use_cache)
|
|
194
|
+
for name in chain(self.dependencies.keys(), self.custom_fields.keys()):
|
|
195
|
+
params.pop(name, None)
|
|
196
|
+
self.params = params
|
|
197
|
+
|
|
198
|
+
def _solve(
|
|
199
|
+
self,
|
|
200
|
+
/,
|
|
201
|
+
*args: Tuple[Any, ...],
|
|
202
|
+
cache_dependencies: Dict[
|
|
203
|
+
Union[
|
|
204
|
+
Callable[P, T],
|
|
205
|
+
Callable[P, Awaitable[T]],
|
|
206
|
+
],
|
|
207
|
+
T,
|
|
208
|
+
],
|
|
209
|
+
dependency_overrides: Optional[
|
|
210
|
+
Dict[
|
|
211
|
+
Union[
|
|
212
|
+
Callable[P, T],
|
|
213
|
+
Callable[P, Awaitable[T]],
|
|
214
|
+
],
|
|
215
|
+
Union[
|
|
216
|
+
Callable[P, T],
|
|
217
|
+
Callable[P, Awaitable[T]],
|
|
218
|
+
],
|
|
219
|
+
]
|
|
220
|
+
] = None,
|
|
221
|
+
**kwargs: Dict[str, Any],
|
|
222
|
+
) -> Generator[
|
|
223
|
+
Tuple[
|
|
224
|
+
Sequence[Any],
|
|
225
|
+
Dict[str, Any],
|
|
226
|
+
Callable[..., Any],
|
|
227
|
+
],
|
|
228
|
+
Any,
|
|
229
|
+
T,
|
|
230
|
+
]:
|
|
231
|
+
if dependency_overrides:
|
|
232
|
+
call = dependency_overrides.get(self.call, self.call)
|
|
233
|
+
assert self.is_async or not is_coroutine_callable(call), (
|
|
234
|
+
f"You cannot use async dependency `{self.call_name}` at sync main"
|
|
235
|
+
)
|
|
236
|
+
|
|
237
|
+
else:
|
|
238
|
+
call = self.call
|
|
239
|
+
|
|
240
|
+
if self.use_cache and call in cache_dependencies:
|
|
241
|
+
return cache_dependencies[call]
|
|
242
|
+
|
|
243
|
+
kw: Dict[str, Any] = {}
|
|
244
|
+
|
|
245
|
+
for arg in self.keyword_args:
|
|
246
|
+
if (v := kwargs.pop(arg, Parameter.empty)) is not Parameter.empty:
|
|
247
|
+
kw[arg] = v
|
|
248
|
+
|
|
249
|
+
if self.var_keyword_arg is not None:
|
|
250
|
+
kw[self.var_keyword_arg] = kwargs
|
|
251
|
+
else:
|
|
252
|
+
kw.update(kwargs)
|
|
253
|
+
|
|
254
|
+
for arg in self.positional_args:
|
|
255
|
+
if args:
|
|
256
|
+
kw[arg], args = args[0], args[1:]
|
|
257
|
+
else:
|
|
258
|
+
break
|
|
259
|
+
|
|
260
|
+
keyword_args: Iterable[str]
|
|
261
|
+
if self.var_positional_arg is not None:
|
|
262
|
+
kw[self.var_positional_arg] = args
|
|
263
|
+
keyword_args = self.keyword_args
|
|
264
|
+
|
|
265
|
+
else:
|
|
266
|
+
keyword_args = self.keyword_args + self.positional_args
|
|
267
|
+
for arg in keyword_args:
|
|
268
|
+
if not self.cast and arg in self.params:
|
|
269
|
+
kw[arg] = self.params[arg][1]
|
|
270
|
+
|
|
271
|
+
if not args:
|
|
272
|
+
break
|
|
273
|
+
|
|
274
|
+
if arg not in self.dependencies:
|
|
275
|
+
kw[arg], args = args[0], args[1:]
|
|
276
|
+
|
|
277
|
+
solved_kw: Dict[str, Any]
|
|
278
|
+
solved_kw = yield args, kw, call
|
|
279
|
+
|
|
280
|
+
args_: Sequence[Any]
|
|
281
|
+
if self.cast:
|
|
282
|
+
assert self.model, "Cast should be used only with model"
|
|
283
|
+
casted_model = self.model(**solved_kw)
|
|
284
|
+
|
|
285
|
+
kwargs_ = {arg: getattr(casted_model, arg, solved_kw.get(arg)) for arg in keyword_args}
|
|
286
|
+
if self.var_keyword_arg:
|
|
287
|
+
kwargs_.update(getattr(casted_model, self.var_keyword_arg, {}))
|
|
288
|
+
|
|
289
|
+
if self.var_positional_arg is not None:
|
|
290
|
+
args_ = [getattr(casted_model, arg, solved_kw.get(arg)) for arg in self.positional_args]
|
|
291
|
+
args_.extend(getattr(casted_model, self.var_positional_arg, ()))
|
|
292
|
+
else:
|
|
293
|
+
args_ = ()
|
|
294
|
+
|
|
295
|
+
else:
|
|
296
|
+
kwargs_ = {arg: solved_kw.get(arg) for arg in keyword_args}
|
|
297
|
+
|
|
298
|
+
args_ = tuple(map(solved_kw.get, self.positional_args)) if self.var_positional_arg is None else ()
|
|
299
|
+
|
|
300
|
+
response: T
|
|
301
|
+
response = yield args_, kwargs_, call
|
|
302
|
+
|
|
303
|
+
if self.cast and not self.is_generator:
|
|
304
|
+
response = self._cast_response(response)
|
|
305
|
+
|
|
306
|
+
if self.use_cache: # pragma: no branch
|
|
307
|
+
cache_dependencies[call] = response
|
|
308
|
+
|
|
309
|
+
return response
|
|
310
|
+
|
|
311
|
+
def _cast_response(self, /, value: Any) -> Any:
|
|
312
|
+
if self.response_model is not None:
|
|
313
|
+
return self.response_model(response=value).response
|
|
314
|
+
else:
|
|
315
|
+
return value
|
|
316
|
+
|
|
317
|
+
def solve(
|
|
318
|
+
self,
|
|
319
|
+
/,
|
|
320
|
+
*args: Any,
|
|
321
|
+
stack: ExitStack,
|
|
322
|
+
cache_dependencies: Dict[
|
|
323
|
+
Union[
|
|
324
|
+
Callable[P, T],
|
|
325
|
+
Callable[P, Awaitable[T]],
|
|
326
|
+
],
|
|
327
|
+
T,
|
|
328
|
+
],
|
|
329
|
+
dependency_overrides: Optional[
|
|
330
|
+
Dict[
|
|
331
|
+
Union[
|
|
332
|
+
Callable[P, T],
|
|
333
|
+
Callable[P, Awaitable[T]],
|
|
334
|
+
],
|
|
335
|
+
Union[
|
|
336
|
+
Callable[P, T],
|
|
337
|
+
Callable[P, Awaitable[T]],
|
|
338
|
+
],
|
|
339
|
+
]
|
|
340
|
+
] = None,
|
|
341
|
+
nested: bool = False,
|
|
342
|
+
**kwargs: Any,
|
|
343
|
+
) -> T:
|
|
344
|
+
cast_gen = self._solve(
|
|
345
|
+
*args,
|
|
346
|
+
cache_dependencies=cache_dependencies,
|
|
347
|
+
dependency_overrides=dependency_overrides,
|
|
348
|
+
**kwargs,
|
|
349
|
+
)
|
|
350
|
+
try:
|
|
351
|
+
args, kwargs, _ = next(cast_gen) # type: ignore[assignment]
|
|
352
|
+
except StopIteration as e:
|
|
353
|
+
cached_value: T = e.value
|
|
354
|
+
return cached_value
|
|
355
|
+
|
|
356
|
+
# Heat cache and solve extra dependencies
|
|
357
|
+
for dep, _ in self.sorted_dependencies:
|
|
358
|
+
dep.solve(
|
|
359
|
+
*args,
|
|
360
|
+
stack=stack,
|
|
361
|
+
cache_dependencies=cache_dependencies,
|
|
362
|
+
dependency_overrides=dependency_overrides,
|
|
363
|
+
nested=True,
|
|
364
|
+
**kwargs,
|
|
365
|
+
)
|
|
366
|
+
|
|
367
|
+
# Always get from cache
|
|
368
|
+
for dep in self.extra_dependencies:
|
|
369
|
+
dep.solve(
|
|
370
|
+
*args,
|
|
371
|
+
stack=stack,
|
|
372
|
+
cache_dependencies=cache_dependencies,
|
|
373
|
+
dependency_overrides=dependency_overrides,
|
|
374
|
+
nested=True,
|
|
375
|
+
**kwargs,
|
|
376
|
+
)
|
|
377
|
+
|
|
378
|
+
for dep_arg, dep in self.dependencies.items():
|
|
379
|
+
kwargs[dep_arg] = dep.solve(
|
|
380
|
+
stack=stack,
|
|
381
|
+
cache_dependencies=cache_dependencies,
|
|
382
|
+
dependency_overrides=dependency_overrides,
|
|
383
|
+
nested=True,
|
|
384
|
+
**kwargs,
|
|
385
|
+
)
|
|
386
|
+
|
|
387
|
+
for custom in self.custom_fields.values():
|
|
388
|
+
if custom.field:
|
|
389
|
+
custom.use_field(kwargs)
|
|
390
|
+
else:
|
|
391
|
+
kwargs = custom.use(**kwargs)
|
|
392
|
+
|
|
393
|
+
final_args, final_kwargs, call = cast_gen.send(kwargs)
|
|
394
|
+
|
|
395
|
+
if self.is_generator and nested:
|
|
396
|
+
response = solve_generator_sync(
|
|
397
|
+
*final_args,
|
|
398
|
+
call=call,
|
|
399
|
+
stack=stack,
|
|
400
|
+
**final_kwargs,
|
|
401
|
+
)
|
|
402
|
+
|
|
403
|
+
else:
|
|
404
|
+
response = call(*final_args, **final_kwargs)
|
|
405
|
+
|
|
406
|
+
try:
|
|
407
|
+
cast_gen.send(response)
|
|
408
|
+
except StopIteration as e:
|
|
409
|
+
value: T = e.value
|
|
410
|
+
|
|
411
|
+
if not self.cast or nested or not self.is_generator:
|
|
412
|
+
return value
|
|
413
|
+
|
|
414
|
+
else:
|
|
415
|
+
return map(self._cast_response, value) # type: ignore[no-any-return, call-overload]
|
|
416
|
+
|
|
417
|
+
raise AssertionError("unreachable")
|
|
418
|
+
|
|
419
|
+
async def asolve(
|
|
420
|
+
self,
|
|
421
|
+
/,
|
|
422
|
+
*args: Any,
|
|
423
|
+
stack: AsyncExitStack,
|
|
424
|
+
cache_dependencies: Dict[
|
|
425
|
+
Union[
|
|
426
|
+
Callable[P, T],
|
|
427
|
+
Callable[P, Awaitable[T]],
|
|
428
|
+
],
|
|
429
|
+
T,
|
|
430
|
+
],
|
|
431
|
+
dependency_overrides: Optional[
|
|
432
|
+
Dict[
|
|
433
|
+
Union[
|
|
434
|
+
Callable[P, T],
|
|
435
|
+
Callable[P, Awaitable[T]],
|
|
436
|
+
],
|
|
437
|
+
Union[
|
|
438
|
+
Callable[P, T],
|
|
439
|
+
Callable[P, Awaitable[T]],
|
|
440
|
+
],
|
|
441
|
+
]
|
|
442
|
+
] = None,
|
|
443
|
+
nested: bool = False,
|
|
444
|
+
**kwargs: Any,
|
|
445
|
+
) -> T:
|
|
446
|
+
cast_gen = self._solve(
|
|
447
|
+
*args,
|
|
448
|
+
cache_dependencies=cache_dependencies,
|
|
449
|
+
dependency_overrides=dependency_overrides,
|
|
450
|
+
**kwargs,
|
|
451
|
+
)
|
|
452
|
+
try:
|
|
453
|
+
args, kwargs, _ = next(cast_gen) # type: ignore[assignment]
|
|
454
|
+
except StopIteration as e:
|
|
455
|
+
cached_value: T = e.value
|
|
456
|
+
return cached_value
|
|
457
|
+
|
|
458
|
+
# Heat cache and solve extra dependencies
|
|
459
|
+
dep_to_solve: List[Callable[..., Awaitable[Any]]] = []
|
|
460
|
+
try:
|
|
461
|
+
async with anyio.create_task_group() as tg:
|
|
462
|
+
for dep, subdep in self.sorted_dependencies:
|
|
463
|
+
solve = partial(
|
|
464
|
+
dep.asolve,
|
|
465
|
+
*args,
|
|
466
|
+
stack=stack,
|
|
467
|
+
cache_dependencies=cache_dependencies,
|
|
468
|
+
dependency_overrides=dependency_overrides,
|
|
469
|
+
nested=True,
|
|
470
|
+
**kwargs,
|
|
471
|
+
)
|
|
472
|
+
if not subdep:
|
|
473
|
+
tg.start_soon(solve)
|
|
474
|
+
else:
|
|
475
|
+
dep_to_solve.append(solve)
|
|
476
|
+
except ExceptionGroup as exgr:
|
|
477
|
+
for ex in exgr.exceptions:
|
|
478
|
+
raise ex from None
|
|
479
|
+
|
|
480
|
+
for i in dep_to_solve:
|
|
481
|
+
await i()
|
|
482
|
+
|
|
483
|
+
# Always get from cache
|
|
484
|
+
for dep in self.extra_dependencies:
|
|
485
|
+
await dep.asolve(
|
|
486
|
+
*args,
|
|
487
|
+
stack=stack,
|
|
488
|
+
cache_dependencies=cache_dependencies,
|
|
489
|
+
dependency_overrides=dependency_overrides,
|
|
490
|
+
nested=True,
|
|
491
|
+
**kwargs,
|
|
492
|
+
)
|
|
493
|
+
|
|
494
|
+
for dep_arg, dep in self.dependencies.items():
|
|
495
|
+
kwargs[dep_arg] = await dep.asolve(
|
|
496
|
+
stack=stack,
|
|
497
|
+
cache_dependencies=cache_dependencies,
|
|
498
|
+
dependency_overrides=dependency_overrides,
|
|
499
|
+
nested=True,
|
|
500
|
+
**kwargs,
|
|
501
|
+
)
|
|
502
|
+
|
|
503
|
+
custom_to_solve: List[CustomField] = []
|
|
504
|
+
|
|
505
|
+
try:
|
|
506
|
+
async with anyio.create_task_group() as tg:
|
|
507
|
+
for custom in self.custom_fields.values():
|
|
508
|
+
if custom.field:
|
|
509
|
+
tg.start_soon(run_async, custom.use_field, kwargs)
|
|
510
|
+
else:
|
|
511
|
+
custom_to_solve.append(custom)
|
|
512
|
+
|
|
513
|
+
except ExceptionGroup as exgr:
|
|
514
|
+
for ex in exgr.exceptions:
|
|
515
|
+
raise ex from None
|
|
516
|
+
|
|
517
|
+
for j in custom_to_solve:
|
|
518
|
+
kwargs = await run_async(j.use, **kwargs)
|
|
519
|
+
|
|
520
|
+
final_args, final_kwargs, call = cast_gen.send(kwargs)
|
|
521
|
+
|
|
522
|
+
if self.is_generator and nested:
|
|
523
|
+
response = await solve_generator_async(
|
|
524
|
+
*final_args,
|
|
525
|
+
call=call,
|
|
526
|
+
stack=stack,
|
|
527
|
+
**final_kwargs,
|
|
528
|
+
)
|
|
529
|
+
else:
|
|
530
|
+
response = await run_async(call, *final_args, **final_kwargs)
|
|
531
|
+
|
|
532
|
+
try:
|
|
533
|
+
cast_gen.send(response)
|
|
534
|
+
except StopIteration as e:
|
|
535
|
+
value: T = e.value
|
|
536
|
+
|
|
537
|
+
if not self.cast or nested or not self.is_generator:
|
|
538
|
+
return value
|
|
539
|
+
|
|
540
|
+
else:
|
|
541
|
+
return async_map(self._cast_response, value) # type: ignore[return-value, arg-type]
|
|
542
|
+
|
|
543
|
+
raise AssertionError("unreachable")
|
|
544
|
+
|
|
545
|
+
|
|
546
|
+
def _sort_dep(
|
|
547
|
+
collector: List["CallModel[..., Any]"],
|
|
548
|
+
items: Tuple[
|
|
549
|
+
"CallModel[..., Any]",
|
|
550
|
+
Tuple[Callable[..., Any], ...],
|
|
551
|
+
],
|
|
552
|
+
flat: Dict[
|
|
553
|
+
Callable[..., Any],
|
|
554
|
+
Tuple[
|
|
555
|
+
"CallModel[..., Any]",
|
|
556
|
+
Tuple[Callable[..., Any], ...],
|
|
557
|
+
],
|
|
558
|
+
],
|
|
559
|
+
) -> None:
|
|
560
|
+
model, calls = items
|
|
561
|
+
|
|
562
|
+
if model in collector:
|
|
563
|
+
return
|
|
564
|
+
|
|
565
|
+
if not calls:
|
|
566
|
+
position = -1
|
|
567
|
+
|
|
568
|
+
else:
|
|
569
|
+
for i in calls:
|
|
570
|
+
sub_model, _ = flat[i]
|
|
571
|
+
if sub_model not in collector: # pragma: no branch
|
|
572
|
+
_sort_dep(collector, flat[i], flat)
|
|
573
|
+
|
|
574
|
+
position = max(collector.index(flat[i][0]) for i in calls)
|
|
575
|
+
|
|
576
|
+
collector.insert(position + 1, model)
|
|
@@ -0,0 +1,15 @@
|
|
|
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 .model import Depends
|
|
9
|
+
from .provider import Provider, dependency_provider
|
|
10
|
+
|
|
11
|
+
__all__ = (
|
|
12
|
+
"Depends",
|
|
13
|
+
"Provider",
|
|
14
|
+
"dependency_provider",
|
|
15
|
+
)
|
|
@@ -0,0 +1,29 @@
|
|
|
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, Callable
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class Depends:
|
|
12
|
+
use_cache: bool
|
|
13
|
+
cast: bool
|
|
14
|
+
|
|
15
|
+
def __init__(
|
|
16
|
+
self,
|
|
17
|
+
dependency: Callable[..., Any],
|
|
18
|
+
*,
|
|
19
|
+
use_cache: bool = True,
|
|
20
|
+
cast: bool = True,
|
|
21
|
+
) -> None:
|
|
22
|
+
self.dependency = dependency
|
|
23
|
+
self.use_cache = use_cache
|
|
24
|
+
self.cast = cast
|
|
25
|
+
|
|
26
|
+
def __repr__(self) -> str:
|
|
27
|
+
attr = getattr(self.dependency, "__name__", type(self.dependency).__name__)
|
|
28
|
+
cache = "" if self.use_cache else ", use_cache=False"
|
|
29
|
+
return f"{self.__class__.__name__}({attr}{cache})"
|
|
@@ -0,0 +1,39 @@
|
|
|
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 contextmanager
|
|
9
|
+
from typing import Any, Callable, Dict, Iterator
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class Provider:
|
|
13
|
+
dependency_overrides: Dict[Callable[..., Any], Callable[..., Any]]
|
|
14
|
+
|
|
15
|
+
def __init__(self) -> None:
|
|
16
|
+
self.dependency_overrides = {}
|
|
17
|
+
|
|
18
|
+
def clear(self) -> None:
|
|
19
|
+
self.dependency_overrides = {}
|
|
20
|
+
|
|
21
|
+
def override(
|
|
22
|
+
self,
|
|
23
|
+
original: Callable[..., Any],
|
|
24
|
+
override: Callable[..., Any],
|
|
25
|
+
) -> None:
|
|
26
|
+
self.dependency_overrides[original] = override
|
|
27
|
+
|
|
28
|
+
@contextmanager
|
|
29
|
+
def scope(
|
|
30
|
+
self,
|
|
31
|
+
original: Callable[..., Any],
|
|
32
|
+
override: Callable[..., Any],
|
|
33
|
+
) -> Iterator[None]:
|
|
34
|
+
self.dependency_overrides[original] = override
|
|
35
|
+
yield
|
|
36
|
+
self.dependency_overrides.pop(original, None)
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
dependency_provider = Provider()
|
|
@@ -0,0 +1,10 @@
|
|
|
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 .model import CustomField
|
|
9
|
+
|
|
10
|
+
__all__ = ("CustomField",)
|