ag2 0.10.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.
- ag2-0.10.2.dist-info/METADATA +819 -0
- ag2-0.10.2.dist-info/RECORD +423 -0
- ag2-0.10.2.dist-info/WHEEL +4 -0
- ag2-0.10.2.dist-info/licenses/LICENSE +201 -0
- ag2-0.10.2.dist-info/licenses/NOTICE.md +19 -0
- autogen/__init__.py +88 -0
- autogen/_website/__init__.py +3 -0
- autogen/_website/generate_api_references.py +426 -0
- autogen/_website/generate_mkdocs.py +1216 -0
- autogen/_website/notebook_processor.py +475 -0
- autogen/_website/process_notebooks.py +656 -0
- autogen/_website/utils.py +413 -0
- autogen/a2a/__init__.py +36 -0
- autogen/a2a/agent_executor.py +86 -0
- autogen/a2a/client.py +357 -0
- autogen/a2a/errors.py +18 -0
- autogen/a2a/httpx_client_factory.py +79 -0
- autogen/a2a/server.py +221 -0
- autogen/a2a/utils.py +207 -0
- autogen/agentchat/__init__.py +47 -0
- autogen/agentchat/agent.py +180 -0
- autogen/agentchat/assistant_agent.py +86 -0
- autogen/agentchat/chat.py +325 -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 +432 -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 +578 -0
- autogen/agentchat/contrib/capabilities/transforms_util.py +122 -0
- autogen/agentchat/contrib/capabilities/vision_capability.py +215 -0
- autogen/agentchat/contrib/captainagent/__init__.py +9 -0
- autogen/agentchat/contrib/captainagent/agent_builder.py +790 -0
- autogen/agentchat/contrib/captainagent/captainagent.py +514 -0
- autogen/agentchat/contrib/captainagent/tool_retriever.py +334 -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 +167 -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 +263 -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 +189 -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 +325 -0
- autogen/agentchat/contrib/rag/__init__.py +10 -0
- autogen/agentchat/contrib/rag/chromadb_query_engine.py +268 -0
- autogen/agentchat/contrib/rag/llamaindex_query_engine.py +195 -0
- autogen/agentchat/contrib/rag/mongodb_query_engine.py +319 -0
- autogen/agentchat/contrib/rag/query_engine.py +76 -0
- autogen/agentchat/contrib/retrieve_assistant_agent.py +59 -0
- autogen/agentchat/contrib/retrieve_user_proxy_agent.py +704 -0
- autogen/agentchat/contrib/society_of_mind_agent.py +200 -0
- autogen/agentchat/contrib/swarm_agent.py +1404 -0
- autogen/agentchat/contrib/text_analyzer_agent.py +79 -0
- autogen/agentchat/contrib/vectordb/__init__.py +5 -0
- autogen/agentchat/contrib/vectordb/base.py +224 -0
- autogen/agentchat/contrib/vectordb/chromadb.py +316 -0
- autogen/agentchat/contrib/vectordb/couchbase.py +405 -0
- autogen/agentchat/contrib/vectordb/mongodb.py +551 -0
- autogen/agentchat/contrib/vectordb/pgvectordb.py +927 -0
- autogen/agentchat/contrib/vectordb/qdrant.py +320 -0
- autogen/agentchat/contrib/vectordb/utils.py +126 -0
- autogen/agentchat/contrib/web_surfer.py +304 -0
- autogen/agentchat/conversable_agent.py +4307 -0
- autogen/agentchat/group/__init__.py +67 -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 +39 -0
- autogen/agentchat/group/context_variables.py +182 -0
- autogen/agentchat/group/events/transition_events.py +111 -0
- autogen/agentchat/group/group_tool_executor.py +324 -0
- autogen/agentchat/group/group_utils.py +659 -0
- autogen/agentchat/group/guardrails.py +179 -0
- autogen/agentchat/group/handoffs.py +303 -0
- autogen/agentchat/group/llm_condition.py +93 -0
- autogen/agentchat/group/multi_agent_chat.py +291 -0
- autogen/agentchat/group/on_condition.py +55 -0
- autogen/agentchat/group/on_context_condition.py +51 -0
- autogen/agentchat/group/patterns/__init__.py +18 -0
- autogen/agentchat/group/patterns/auto.py +160 -0
- autogen/agentchat/group/patterns/manual.py +177 -0
- autogen/agentchat/group/patterns/pattern.py +295 -0
- autogen/agentchat/group/patterns/random.py +106 -0
- autogen/agentchat/group/patterns/round_robin.py +117 -0
- autogen/agentchat/group/reply_result.py +24 -0
- autogen/agentchat/group/safeguards/__init__.py +21 -0
- autogen/agentchat/group/safeguards/api.py +241 -0
- autogen/agentchat/group/safeguards/enforcer.py +1158 -0
- autogen/agentchat/group/safeguards/events.py +140 -0
- autogen/agentchat/group/safeguards/validator.py +435 -0
- autogen/agentchat/group/speaker_selection_result.py +41 -0
- autogen/agentchat/group/targets/__init__.py +4 -0
- autogen/agentchat/group/targets/function_target.py +245 -0
- autogen/agentchat/group/targets/group_chat_target.py +133 -0
- autogen/agentchat/group/targets/group_manager_target.py +151 -0
- autogen/agentchat/group/targets/transition_target.py +424 -0
- autogen/agentchat/group/targets/transition_utils.py +6 -0
- autogen/agentchat/groupchat.py +1832 -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 +191 -0
- autogen/agentchat/realtime/experimental/function_observer.py +84 -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 +533 -0
- autogen/agentchat/realtime/experimental/websockets.py +21 -0
- autogen/agentchat/realtime_agent/__init__.py +21 -0
- autogen/agentchat/user_proxy_agent.py +114 -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 +74 -0
- autogen/agents/contrib/time/time_tool_agent.py +52 -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 +301 -0
- autogen/agents/experimental/document_agent/docling_doc_ingest_agent.py +113 -0
- autogen/agents/experimental/document_agent/document_agent.py +643 -0
- autogen/agents/experimental/document_agent/document_conditions.py +50 -0
- autogen/agents/experimental/document_agent/document_utils.py +376 -0
- autogen/agents/experimental/document_agent/inmemory_query_engine.py +214 -0
- autogen/agents/experimental/document_agent/parser_utils.py +134 -0
- autogen/agents/experimental/document_agent/url_utils.py +417 -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 +76 -0
- autogen/agents/experimental/websurfer/__init__.py +7 -0
- autogen/agents/experimental/websurfer/websurfer.py +70 -0
- autogen/agents/experimental/wikipedia/__init__.py +7 -0
- autogen/agents/experimental/wikipedia/wikipedia.py +88 -0
- autogen/browser_utils.py +309 -0
- autogen/cache/__init__.py +10 -0
- autogen/cache/abstract_cache_base.py +71 -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 +97 -0
- autogen/cache/in_memory_cache.py +54 -0
- autogen/cache/redis_cache.py +119 -0
- autogen/code_utils.py +598 -0
- autogen/coding/__init__.py +30 -0
- autogen/coding/base.py +120 -0
- autogen/coding/docker_commandline_code_executor.py +283 -0
- autogen/coding/factory.py +56 -0
- autogen/coding/func_with_reqs.py +203 -0
- autogen/coding/jupyter/__init__.py +23 -0
- autogen/coding/jupyter/base.py +36 -0
- autogen/coding/jupyter/docker_jupyter_server.py +160 -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 +224 -0
- autogen/coding/jupyter/jupyter_code_executor.py +154 -0
- autogen/coding/jupyter/local_jupyter_server.py +164 -0
- autogen/coding/local_commandline_code_executor.py +341 -0
- autogen/coding/markdown_code_extractor.py +44 -0
- autogen/coding/utils.py +55 -0
- autogen/coding/yepcode_code_executor.py +197 -0
- autogen/doc_utils.py +35 -0
- autogen/environments/__init__.py +10 -0
- autogen/environments/docker_python_environment.py +365 -0
- autogen/environments/python_environment.py +125 -0
- autogen/environments/system_python_environment.py +85 -0
- autogen/environments/venv_python_environment.py +220 -0
- autogen/environments/working_directory.py +74 -0
- autogen/events/__init__.py +7 -0
- autogen/events/agent_events.py +1016 -0
- autogen/events/base_event.py +100 -0
- autogen/events/client_events.py +168 -0
- autogen/events/helpers.py +44 -0
- autogen/events/print_event.py +45 -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 +75 -0
- autogen/fast_depends/core/__init__.py +14 -0
- autogen/fast_depends/core/build.py +206 -0
- autogen/fast_depends/core/model.py +527 -0
- autogen/fast_depends/dependencies/__init__.py +15 -0
- autogen/fast_depends/dependencies/model.py +30 -0
- autogen/fast_depends/dependencies/provider.py +40 -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 +272 -0
- autogen/fast_depends/utils.py +177 -0
- autogen/formatting_utils.py +83 -0
- autogen/function_utils.py +13 -0
- autogen/graph_utils.py +173 -0
- autogen/import_utils.py +539 -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 +156 -0
- autogen/interop/langchain/langchain_tool.py +78 -0
- autogen/interop/litellm/__init__.py +7 -0
- autogen/interop/litellm/litellm_config_factory.py +178 -0
- autogen/interop/pydantic_ai/__init__.py +7 -0
- autogen/interop/pydantic_ai/pydantic_ai.py +172 -0
- autogen/interop/registry.py +70 -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 +61 -0
- autogen/io/run_response.py +294 -0
- autogen/io/thread_io_stream.py +63 -0
- autogen/io/websockets.py +214 -0
- autogen/json_utils.py +42 -0
- autogen/llm_clients/MIGRATION_TO_V2.md +782 -0
- autogen/llm_clients/__init__.py +77 -0
- autogen/llm_clients/client_v2.py +122 -0
- autogen/llm_clients/models/__init__.py +55 -0
- autogen/llm_clients/models/content_blocks.py +389 -0
- autogen/llm_clients/models/unified_message.py +145 -0
- autogen/llm_clients/models/unified_response.py +83 -0
- autogen/llm_clients/openai_completions_client.py +444 -0
- autogen/llm_config/__init__.py +11 -0
- autogen/llm_config/client.py +59 -0
- autogen/llm_config/config.py +461 -0
- autogen/llm_config/entry.py +169 -0
- autogen/llm_config/types.py +37 -0
- autogen/llm_config/utils.py +223 -0
- autogen/logger/__init__.py +11 -0
- autogen/logger/base_logger.py +129 -0
- autogen/logger/file_logger.py +262 -0
- autogen/logger/logger_factory.py +42 -0
- autogen/logger/logger_utils.py +57 -0
- autogen/logger/sqlite_logger.py +524 -0
- autogen/math_utils.py +338 -0
- autogen/mcp/__init__.py +7 -0
- autogen/mcp/__main__.py +78 -0
- autogen/mcp/helpers.py +45 -0
- autogen/mcp/mcp_client.py +349 -0
- autogen/mcp/mcp_proxy/__init__.py +19 -0
- autogen/mcp/mcp_proxy/fastapi_code_generator_helpers.py +62 -0
- autogen/mcp/mcp_proxy/mcp_proxy.py +577 -0
- autogen/mcp/mcp_proxy/operation_grouping.py +166 -0
- autogen/mcp/mcp_proxy/operation_renaming.py +110 -0
- autogen/mcp/mcp_proxy/patch_fastapi_code_generator.py +98 -0
- autogen/mcp/mcp_proxy/security.py +399 -0
- autogen/mcp/mcp_proxy/security_schema_visitor.py +37 -0
- autogen/messages/__init__.py +7 -0
- autogen/messages/agent_messages.py +946 -0
- autogen/messages/base_message.py +108 -0
- autogen/messages/client_messages.py +172 -0
- autogen/messages/print_message.py +48 -0
- autogen/oai/__init__.py +61 -0
- autogen/oai/anthropic.py +1516 -0
- autogen/oai/bedrock.py +800 -0
- autogen/oai/cerebras.py +302 -0
- autogen/oai/client.py +1658 -0
- autogen/oai/client_utils.py +196 -0
- autogen/oai/cohere.py +494 -0
- autogen/oai/gemini.py +1045 -0
- autogen/oai/gemini_types.py +156 -0
- autogen/oai/groq.py +319 -0
- autogen/oai/mistral.py +311 -0
- autogen/oai/oai_models/__init__.py +23 -0
- autogen/oai/oai_models/_models.py +16 -0
- autogen/oai/oai_models/chat_completion.py +86 -0
- autogen/oai/oai_models/chat_completion_audio.py +32 -0
- autogen/oai/oai_models/chat_completion_message.py +97 -0
- autogen/oai/oai_models/chat_completion_message_tool_call.py +60 -0
- autogen/oai/oai_models/chat_completion_token_logprob.py +62 -0
- autogen/oai/oai_models/completion_usage.py +59 -0
- autogen/oai/ollama.py +657 -0
- autogen/oai/openai_responses.py +451 -0
- autogen/oai/openai_utils.py +897 -0
- autogen/oai/together.py +387 -0
- autogen/remote/__init__.py +18 -0
- autogen/remote/agent.py +199 -0
- autogen/remote/agent_service.py +197 -0
- autogen/remote/errors.py +17 -0
- autogen/remote/httpx_client_factory.py +131 -0
- autogen/remote/protocol.py +37 -0
- autogen/remote/retry.py +102 -0
- autogen/remote/runtime.py +96 -0
- autogen/retrieve_utils.py +490 -0
- autogen/runtime_logging.py +161 -0
- autogen/testing/__init__.py +12 -0
- autogen/testing/messages.py +45 -0
- autogen/testing/test_agent.py +111 -0
- autogen/token_count_utils.py +280 -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 +40 -0
- autogen/tools/dependency_injection.py +249 -0
- autogen/tools/experimental/__init__.py +54 -0
- autogen/tools/experimental/browser_use/__init__.py +7 -0
- autogen/tools/experimental/browser_use/browser_use.py +154 -0
- autogen/tools/experimental/code_execution/__init__.py +7 -0
- autogen/tools/experimental/code_execution/python_code_execution.py +86 -0
- autogen/tools/experimental/crawl4ai/__init__.py +7 -0
- autogen/tools/experimental/crawl4ai/crawl4ai.py +150 -0
- autogen/tools/experimental/deep_research/__init__.py +7 -0
- autogen/tools/experimental/deep_research/deep_research.py +329 -0
- autogen/tools/experimental/duckduckgo/__init__.py +7 -0
- autogen/tools/experimental/duckduckgo/duckduckgo_search.py +103 -0
- autogen/tools/experimental/firecrawl/__init__.py +7 -0
- autogen/tools/experimental/firecrawl/firecrawl_tool.py +836 -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 +284 -0
- autogen/tools/experimental/messageplatform/slack/__init__.py +7 -0
- autogen/tools/experimental/messageplatform/slack/slack.py +385 -0
- autogen/tools/experimental/messageplatform/telegram/__init__.py +7 -0
- autogen/tools/experimental/messageplatform/telegram/telegram.py +271 -0
- autogen/tools/experimental/perplexity/__init__.py +7 -0
- autogen/tools/experimental/perplexity/perplexity_search.py +249 -0
- autogen/tools/experimental/reliable/__init__.py +10 -0
- autogen/tools/experimental/reliable/reliable.py +1311 -0
- autogen/tools/experimental/searxng/__init__.py +7 -0
- autogen/tools/experimental/searxng/searxng_search.py +142 -0
- autogen/tools/experimental/tavily/__init__.py +7 -0
- autogen/tools/experimental/tavily/tavily_search.py +176 -0
- autogen/tools/experimental/web_search_preview/__init__.py +7 -0
- autogen/tools/experimental/web_search_preview/web_search_preview.py +120 -0
- autogen/tools/experimental/wikipedia/__init__.py +7 -0
- autogen/tools/experimental/wikipedia/wikipedia.py +284 -0
- autogen/tools/function_utils.py +412 -0
- autogen/tools/tool.py +188 -0
- autogen/tools/toolkit.py +86 -0
- autogen/types.py +29 -0
- autogen/version.py +7 -0
- templates/client_template/main.jinja2 +72 -0
- templates/config_template/config.jinja2 +7 -0
- templates/main.jinja2 +61 -0
|
@@ -0,0 +1,334 @@
|
|
|
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
|
+
import contextlib
|
|
8
|
+
import functools
|
|
9
|
+
import importlib.util
|
|
10
|
+
import inspect
|
|
11
|
+
import io
|
|
12
|
+
import os
|
|
13
|
+
import traceback
|
|
14
|
+
from hashlib import md5
|
|
15
|
+
from pathlib import Path
|
|
16
|
+
from textwrap import dedent, indent
|
|
17
|
+
|
|
18
|
+
from .... import AssistantAgent, UserProxyAgent
|
|
19
|
+
from ....coding import CodeExecutor, CodeExtractor, LocalCommandLineCodeExecutor, MarkdownCodeExtractor
|
|
20
|
+
from ....coding.base import CodeBlock, CodeResult
|
|
21
|
+
from ....doc_utils import export_module
|
|
22
|
+
from ....import_utils import optional_import_block, require_optional_import
|
|
23
|
+
from ....tools import Tool, get_function_schema, load_basemodels_if_needed
|
|
24
|
+
|
|
25
|
+
with optional_import_block():
|
|
26
|
+
import pandas as pd
|
|
27
|
+
from sentence_transformers import SentenceTransformer, util
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
@require_optional_import(["pandas", "sentence_transformers"], "retrievechat")
|
|
31
|
+
@export_module("autogen.agentchat.contrib.captainagent")
|
|
32
|
+
class ToolBuilder:
|
|
33
|
+
TOOL_PROMPT_DEFAULT = """\n## Functions
|
|
34
|
+
You have access to the following functions. They can be accessed from the module called 'functions' by their function names.
|
|
35
|
+
For example, if there is a function called `foo` you could import it by writing `from functions import foo`
|
|
36
|
+
{functions}
|
|
37
|
+
"""
|
|
38
|
+
TOOL_PROMPT_USER_DEFINED = """\n## Functions
|
|
39
|
+
You have access to the following functions. You can write python code to call these functions directly without importing them.
|
|
40
|
+
{functions}
|
|
41
|
+
"""
|
|
42
|
+
|
|
43
|
+
def __init__(self, corpus_root, retriever="all-mpnet-base-v2", type="default"):
|
|
44
|
+
if type == "default":
|
|
45
|
+
corpus_path = os.path.join(corpus_root, "tool_description.tsv")
|
|
46
|
+
self.df = pd.read_csv(corpus_path, sep="\t")
|
|
47
|
+
document_list = self.df["document_content"].tolist()
|
|
48
|
+
self.TOOL_PROMPT = self.TOOL_PROMPT_DEFAULT
|
|
49
|
+
else:
|
|
50
|
+
self.TOOL_PROMPT = self.TOOL_PROMPT_USER_DEFINED
|
|
51
|
+
# user defined tools, retrieve is actually not needed, just for consistency
|
|
52
|
+
document_list = []
|
|
53
|
+
for tool in corpus_root:
|
|
54
|
+
document_list.append(tool.description)
|
|
55
|
+
|
|
56
|
+
self.model = SentenceTransformer(retriever)
|
|
57
|
+
self.embeddings = self.model.encode(document_list)
|
|
58
|
+
self.type = type
|
|
59
|
+
|
|
60
|
+
def retrieve(self, query, top_k=3):
|
|
61
|
+
# Encode the query using the Sentence Transformer model
|
|
62
|
+
query_embedding = self.model.encode([query])
|
|
63
|
+
|
|
64
|
+
hits = util.semantic_search(query_embedding, self.embeddings, top_k=top_k)
|
|
65
|
+
|
|
66
|
+
results = []
|
|
67
|
+
for hit in hits[0]:
|
|
68
|
+
results.append(self.df.iloc[hit["corpus_id"], 1])
|
|
69
|
+
return results
|
|
70
|
+
|
|
71
|
+
def bind(self, agent: AssistantAgent, functions: str):
|
|
72
|
+
"""Binds the function to the agent so that agent is aware of it."""
|
|
73
|
+
sys_message = agent.system_message
|
|
74
|
+
sys_message += self.TOOL_PROMPT.format(functions=functions)
|
|
75
|
+
agent.update_system_message(sys_message)
|
|
76
|
+
return
|
|
77
|
+
|
|
78
|
+
def bind_user_proxy(self, agent: UserProxyAgent, tool_root: str | list):
|
|
79
|
+
"""Updates user proxy agent with a executor so that code executor can successfully execute function-related code.
|
|
80
|
+
Returns an updated user proxy.
|
|
81
|
+
"""
|
|
82
|
+
if isinstance(tool_root, str):
|
|
83
|
+
# Find all the functions in the tool root
|
|
84
|
+
functions = find_callables(tool_root)
|
|
85
|
+
|
|
86
|
+
code_execution_config = agent._code_execution_config
|
|
87
|
+
executor = LocalCommandLineCodeExecutor(
|
|
88
|
+
timeout=code_execution_config.get("timeout", 180),
|
|
89
|
+
work_dir=code_execution_config.get("work_dir", "coding"),
|
|
90
|
+
functions=functions,
|
|
91
|
+
)
|
|
92
|
+
code_execution_config = {
|
|
93
|
+
"executor": executor,
|
|
94
|
+
"last_n_messages": code_execution_config.get("last_n_messages", 1),
|
|
95
|
+
}
|
|
96
|
+
updated_user_proxy = UserProxyAgent(
|
|
97
|
+
name=agent.name,
|
|
98
|
+
is_termination_msg=agent._is_termination_msg,
|
|
99
|
+
code_execution_config=code_execution_config,
|
|
100
|
+
human_input_mode="NEVER",
|
|
101
|
+
default_auto_reply=agent._default_auto_reply,
|
|
102
|
+
)
|
|
103
|
+
return updated_user_proxy
|
|
104
|
+
else:
|
|
105
|
+
# second case: user defined tools
|
|
106
|
+
code_execution_config = agent._code_execution_config
|
|
107
|
+
executor = LocalExecutorWithTools(
|
|
108
|
+
tools=tool_root,
|
|
109
|
+
work_dir=code_execution_config.get("work_dir", "coding"),
|
|
110
|
+
)
|
|
111
|
+
code_execution_config = {
|
|
112
|
+
"executor": executor,
|
|
113
|
+
"last_n_messages": code_execution_config.get("last_n_messages", 1),
|
|
114
|
+
}
|
|
115
|
+
updated_user_proxy = UserProxyAgent(
|
|
116
|
+
name=agent.name,
|
|
117
|
+
is_termination_msg=agent._is_termination_msg,
|
|
118
|
+
code_execution_config=code_execution_config,
|
|
119
|
+
human_input_mode="NEVER",
|
|
120
|
+
default_auto_reply=agent._default_auto_reply,
|
|
121
|
+
)
|
|
122
|
+
return updated_user_proxy
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
class LocalExecutorWithTools(CodeExecutor):
|
|
126
|
+
"""An executor that executes code blocks with injected tools. In this executor, the func within the tools can be called directly without declaring in the code block.
|
|
127
|
+
|
|
128
|
+
For example, for a tool converted from langchain, the relevant functions can be called directly.
|
|
129
|
+
```python
|
|
130
|
+
from langchain_community.tools import WikipediaQueryRun
|
|
131
|
+
from langchain_community.utilities import WikipediaAPIWrapper
|
|
132
|
+
from autogen.interop import Interoperability
|
|
133
|
+
|
|
134
|
+
api_wrapper = WikipediaAPIWrapper(top_k_results=1, doc_content_chars_max=3000)
|
|
135
|
+
langchain_tool = WikipediaQueryRun(api_wrapper=api_wrapper)
|
|
136
|
+
interop = Interoperability()
|
|
137
|
+
ag2_tool = interop.convert_tool(tool=langchain_tool, type="langchain")
|
|
138
|
+
|
|
139
|
+
# `ag2_tool.name` is wikipedia
|
|
140
|
+
local_executor = LocalExecutorWithTools(tools=[ag2_tool], work_dir="./")
|
|
141
|
+
|
|
142
|
+
code = '''
|
|
143
|
+
result = wikipedia(tool_input={"query":"Christmas"})
|
|
144
|
+
print(result)
|
|
145
|
+
'''
|
|
146
|
+
print(
|
|
147
|
+
local_executor.execute_code_blocks(
|
|
148
|
+
code_blocks=[
|
|
149
|
+
CodeBlock(language="python", code=code),
|
|
150
|
+
]
|
|
151
|
+
)
|
|
152
|
+
)
|
|
153
|
+
```
|
|
154
|
+
In this case, the `wikipedia` function can be called directly in the code block. This hides the complexity of the tool.
|
|
155
|
+
|
|
156
|
+
Args:
|
|
157
|
+
tools: The tools to inject into the code execution environment. Default is an empty list.
|
|
158
|
+
work_dir: The working directory for the code execution. Default is the current directory.
|
|
159
|
+
"""
|
|
160
|
+
|
|
161
|
+
@property
|
|
162
|
+
def code_extractor(self) -> CodeExtractor:
|
|
163
|
+
"""(Experimental) Export a code extractor that can be used by an agent."""
|
|
164
|
+
return MarkdownCodeExtractor()
|
|
165
|
+
|
|
166
|
+
def __init__(self, tools: list[Tool] | None = None, work_dir: Path | str = Path()):
|
|
167
|
+
self.tools = tools if tools is not None else []
|
|
168
|
+
self.work_dir = work_dir
|
|
169
|
+
if not os.path.exists(work_dir):
|
|
170
|
+
os.makedirs(work_dir, exist_ok=True)
|
|
171
|
+
|
|
172
|
+
def execute_code_blocks(self, code_blocks: list[CodeBlock]) -> CodeResult:
|
|
173
|
+
"""Execute code blocks and return the result.
|
|
174
|
+
|
|
175
|
+
Args:
|
|
176
|
+
code_blocks (List[CodeBlock]): The code blocks to execute.
|
|
177
|
+
|
|
178
|
+
Returns:
|
|
179
|
+
CodeResult: The result of the code execution.
|
|
180
|
+
"""
|
|
181
|
+
logs_all = ""
|
|
182
|
+
exit_code = 0 # Success code
|
|
183
|
+
code_file = None # Path to the first saved codeblock content
|
|
184
|
+
|
|
185
|
+
for idx, code_block in enumerate(code_blocks):
|
|
186
|
+
code = code_block.code
|
|
187
|
+
code_hash = md5(code.encode()).hexdigest()
|
|
188
|
+
filename = f"tmp_code_{code_hash}.py"
|
|
189
|
+
filepath = os.path.join(self.work_dir, filename)
|
|
190
|
+
# Save code content to file
|
|
191
|
+
with open(filepath, "w", encoding="utf-8") as f:
|
|
192
|
+
f.write(code)
|
|
193
|
+
|
|
194
|
+
if idx == 0:
|
|
195
|
+
code_file = filepath
|
|
196
|
+
|
|
197
|
+
# Create a new execution environment
|
|
198
|
+
execution_env = {}
|
|
199
|
+
# Inject the tools
|
|
200
|
+
for tool in self.tools:
|
|
201
|
+
execution_env[tool.name] = _wrap_function(tool.func)
|
|
202
|
+
|
|
203
|
+
# Prepare to capture stdout and stderr
|
|
204
|
+
stdout = io.StringIO()
|
|
205
|
+
stderr = io.StringIO()
|
|
206
|
+
|
|
207
|
+
# Execute the code block
|
|
208
|
+
try:
|
|
209
|
+
# Redirect stdout and stderr
|
|
210
|
+
with contextlib.redirect_stdout(stdout), contextlib.redirect_stderr(stderr):
|
|
211
|
+
# Exec the code in the execution environment
|
|
212
|
+
exec(code, execution_env)
|
|
213
|
+
except Exception:
|
|
214
|
+
# Capture exception traceback
|
|
215
|
+
tb = traceback.format_exc()
|
|
216
|
+
stderr.write(tb)
|
|
217
|
+
exit_code = 1 # Non-zero exit code indicates failure
|
|
218
|
+
|
|
219
|
+
# Collect outputs
|
|
220
|
+
stdout_content = stdout.getvalue()
|
|
221
|
+
stderr_content = stderr.getvalue()
|
|
222
|
+
logs_all += stdout_content + stderr_content
|
|
223
|
+
|
|
224
|
+
return CodeResult(exit_code=exit_code, output=logs_all, code_file=code_file)
|
|
225
|
+
|
|
226
|
+
def restart(self):
|
|
227
|
+
"""Restart the code executor. Since this executor is stateless, no action is needed."""
|
|
228
|
+
pass
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
@export_module("autogen.agentchat.contrib.captainagent")
|
|
232
|
+
def format_ag2_tool(tool: Tool):
|
|
233
|
+
# get the args first
|
|
234
|
+
schema = get_function_schema(tool.func, description=tool.description)
|
|
235
|
+
|
|
236
|
+
arg_name = list(inspect.signature(tool.func).parameters.keys())[0]
|
|
237
|
+
arg_info = schema["function"]["parameters"]["properties"][arg_name]["properties"]
|
|
238
|
+
|
|
239
|
+
content = f'def {tool.name}({arg_name}):\n """\n'
|
|
240
|
+
content += indent(tool.description, " ") + "\n"
|
|
241
|
+
content += (
|
|
242
|
+
indent(
|
|
243
|
+
f"You must format all the arguments into a dictionary and pass them as **kwargs to {arg_name}. You should use print function to get the results.",
|
|
244
|
+
" ",
|
|
245
|
+
)
|
|
246
|
+
+ "\n"
|
|
247
|
+
+ indent(f"For example:\n\tresult = {tool.name}({arg_name}={{'arg1': 'value1' }})", " ")
|
|
248
|
+
+ "\n"
|
|
249
|
+
)
|
|
250
|
+
content += indent(f"Arguments passed in {arg_name}:\n", " ")
|
|
251
|
+
for arg, info in arg_info.items():
|
|
252
|
+
content += indent(f"{arg} ({info['type']}): {info['description']}\n", " " * 2)
|
|
253
|
+
content += ' """\n'
|
|
254
|
+
return content
|
|
255
|
+
|
|
256
|
+
|
|
257
|
+
def _wrap_function(func):
|
|
258
|
+
"""Wrap the function to dump the return value to json.
|
|
259
|
+
|
|
260
|
+
Handles both sync and async functions.
|
|
261
|
+
|
|
262
|
+
Args:
|
|
263
|
+
func: the function to be wrapped.
|
|
264
|
+
|
|
265
|
+
Returns:
|
|
266
|
+
The wrapped function.
|
|
267
|
+
"""
|
|
268
|
+
|
|
269
|
+
@load_basemodels_if_needed
|
|
270
|
+
@functools.wraps(func)
|
|
271
|
+
def _wrapped_func(*args, **kwargs):
|
|
272
|
+
return func(*args, **kwargs)
|
|
273
|
+
|
|
274
|
+
return _wrapped_func
|
|
275
|
+
|
|
276
|
+
|
|
277
|
+
@export_module("autogen.agentchat.contrib.captainagent")
|
|
278
|
+
def get_full_tool_description(py_file):
|
|
279
|
+
"""Retrieves the function signature for a given Python file."""
|
|
280
|
+
with open(py_file) as f:
|
|
281
|
+
code = f.read()
|
|
282
|
+
exec(code)
|
|
283
|
+
function_name = os.path.splitext(os.path.basename(py_file))[0]
|
|
284
|
+
if function_name in locals():
|
|
285
|
+
func = locals()[function_name]
|
|
286
|
+
content = f"def {func.__name__}{inspect.signature(func)}:\n"
|
|
287
|
+
docstring = func.__doc__
|
|
288
|
+
|
|
289
|
+
if docstring:
|
|
290
|
+
docstring = dedent(docstring)
|
|
291
|
+
docstring = '"""' + docstring + '"""'
|
|
292
|
+
docstring = indent(docstring, " ")
|
|
293
|
+
content += docstring + "\n"
|
|
294
|
+
return content
|
|
295
|
+
else:
|
|
296
|
+
raise ValueError(f"Function {function_name} not found in {py_file}")
|
|
297
|
+
|
|
298
|
+
|
|
299
|
+
def _wrap_function(func):
|
|
300
|
+
"""Wrap the function to dump the return value to json.
|
|
301
|
+
|
|
302
|
+
Handles both sync and async functions.
|
|
303
|
+
|
|
304
|
+
Args:
|
|
305
|
+
func: the function to be wrapped.
|
|
306
|
+
|
|
307
|
+
Returns:
|
|
308
|
+
The wrapped function.
|
|
309
|
+
"""
|
|
310
|
+
|
|
311
|
+
@load_basemodels_if_needed
|
|
312
|
+
@functools.wraps(func)
|
|
313
|
+
def _wrapped_func(*args, **kwargs):
|
|
314
|
+
return func(*args, **kwargs)
|
|
315
|
+
|
|
316
|
+
return _wrapped_func
|
|
317
|
+
|
|
318
|
+
|
|
319
|
+
def find_callables(directory):
|
|
320
|
+
"""Find all callable objects defined in Python files within the specified directory."""
|
|
321
|
+
callables = []
|
|
322
|
+
for root, dirs, files in os.walk(directory):
|
|
323
|
+
for file in files:
|
|
324
|
+
if file.endswith(".py"):
|
|
325
|
+
module_name = os.path.splitext(file)[0]
|
|
326
|
+
module_path = os.path.join(root, file)
|
|
327
|
+
spec = importlib.util.spec_from_file_location(module_name, module_path)
|
|
328
|
+
module = importlib.util.module_from_spec(spec)
|
|
329
|
+
spec.loader.exec_module(module)
|
|
330
|
+
for name, value in module.__dict__.items():
|
|
331
|
+
if callable(value) and name == module_name:
|
|
332
|
+
callables.append(value)
|
|
333
|
+
break
|
|
334
|
+
return callables
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# Introduction
|
|
2
|
+
|
|
3
|
+
This directory contains a library of manually created python tools. These tools have three categories: math, data_analysis and information_retrieval.
|
|
4
|
+
|
|
5
|
+
# Directory Layout
|
|
6
|
+
```
|
|
7
|
+
tools
|
|
8
|
+
├── README.md
|
|
9
|
+
├── data_analysis
|
|
10
|
+
│ ├── calculate_correlation.py
|
|
11
|
+
│ └── ...
|
|
12
|
+
├── information_retrieval
|
|
13
|
+
│ ├── arxiv_download.py
|
|
14
|
+
│ ├── arxiv_search.py
|
|
15
|
+
│ └── ...
|
|
16
|
+
├── math
|
|
17
|
+
│ ├── calculate_circle_area_from_diameter.py
|
|
18
|
+
│ └── ...
|
|
19
|
+
└── tool_description.tsv
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
Tools can be imported from `tools/{category}/{tool_name}.py` with exactly the same function name.
|
|
23
|
+
|
|
24
|
+
`tool_description.tsv` contains descriptions of tools for retrieval.
|
|
25
|
+
|
|
26
|
+
# How to use
|
|
27
|
+
Some tools require Bing Search API key and RapidAPI key. For Bing API, you can read more about how to get an API on the [Bing Web Search API](https://www.microsoft.com/en-us/bing/apis/bing-web-search-api) page. For RapidAPI, you can [sign up](https://rapidapi.com/auth/sign-up) and subscribe to these two links([link1](https://rapidapi.com/solid-api-solid-api-default/api/youtube-transcript3), [link2](https://rapidapi.com/420vijay47/api/youtube-mp3-downloader2)). These apis have free billing options and there is no need to worry about extra costs.
|
|
28
|
+
|
|
29
|
+
To install the requirements for running tools, use pip install.
|
|
30
|
+
```bash
|
|
31
|
+
pip install -r autogen/agentchat/contrib/captainagent/tools/requirements.txt
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
Whenever you run the tool-related code, remember to export the api keys to system variables.
|
|
35
|
+
```bash
|
|
36
|
+
export BING_API_KEY=""
|
|
37
|
+
export RAPID_API_KEY=""
|
|
38
|
+
```
|
|
39
|
+
or
|
|
40
|
+
```python
|
|
41
|
+
import os
|
|
42
|
+
os.environ["BING_API_KEY"] = ""
|
|
43
|
+
os.environ["RAPID_API_KEY"] = ""
|
|
44
|
+
```
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# Copyright (c) 2023 - 2025, AG2ai, Inc., AG2ai open-source projects maintainers and core contributors
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
def calculate_correlation(csv_path: str, column1: str, column2: str, method: str = "pearson") -> float:
|
|
5
|
+
"""Calculate the correlation between two columns in a CSV file.
|
|
6
|
+
|
|
7
|
+
Args:
|
|
8
|
+
csv_path (str): The path to the CSV file.
|
|
9
|
+
column1 (str): The name of the first column.
|
|
10
|
+
column2 (str): The name of the second column.
|
|
11
|
+
method (str or callable, optional): The method used to calculate the correlation.
|
|
12
|
+
- 'pearson' (default): Pearson correlation coefficient.
|
|
13
|
+
- 'kendall': Kendall Tau correlation coefficient.
|
|
14
|
+
- 'spearman': Spearman rank correlation coefficient.
|
|
15
|
+
- callable: A custom correlation function that takes two arrays and returns a scalar.
|
|
16
|
+
|
|
17
|
+
Returns:
|
|
18
|
+
float: The correlation coefficient between the two columns.
|
|
19
|
+
"""
|
|
20
|
+
import pandas as pd
|
|
21
|
+
|
|
22
|
+
# Read the CSV file into a pandas DataFrame
|
|
23
|
+
df = pd.read_csv(csv_path)
|
|
24
|
+
|
|
25
|
+
# Select the specified columns
|
|
26
|
+
selected_columns = df[[column1, column2]]
|
|
27
|
+
|
|
28
|
+
# Calculate the correlation based on the specified method
|
|
29
|
+
if method == "pearson":
|
|
30
|
+
correlation = selected_columns.corr().iloc[0, 1]
|
|
31
|
+
elif method == "kendall":
|
|
32
|
+
correlation = selected_columns.corr(method="kendall").iloc[0, 1]
|
|
33
|
+
elif method == "spearman":
|
|
34
|
+
correlation = selected_columns.corr(method="spearman").iloc[0, 1]
|
|
35
|
+
elif callable(method):
|
|
36
|
+
correlation = selected_columns.corr(method=method).iloc[0, 1]
|
|
37
|
+
else:
|
|
38
|
+
raise ValueError("Invalid correlation method. Please choose 'pearson', 'kendall', 'spearman', or a callable.")
|
|
39
|
+
|
|
40
|
+
return correlation
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# Copyright (c) 2023 - 2025, AG2ai, Inc., AG2ai open-source projects maintainers and core contributors
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
def calculate_skewness_and_kurtosis(csv_file: str, column_name: str) -> tuple:
|
|
5
|
+
"""Calculate the skewness and kurtosis of a specified column in a CSV file. The kurtosis is calculated using the Fisher definition.
|
|
6
|
+
The two metrics are computed using scipy.stats functions.
|
|
7
|
+
|
|
8
|
+
Args:
|
|
9
|
+
csv_file (str): The path to the CSV file.
|
|
10
|
+
column_name (str): The name of the column to calculate skewness and kurtosis for.
|
|
11
|
+
|
|
12
|
+
Returns:
|
|
13
|
+
tuple: (skewness, kurtosis)
|
|
14
|
+
"""
|
|
15
|
+
import pandas as pd
|
|
16
|
+
from scipy.stats import kurtosis, skew
|
|
17
|
+
|
|
18
|
+
# Read the CSV file into a pandas DataFrame
|
|
19
|
+
df = pd.read_csv(csv_file)
|
|
20
|
+
|
|
21
|
+
# Extract the specified column
|
|
22
|
+
column = df[column_name]
|
|
23
|
+
|
|
24
|
+
# Calculate the skewness and kurtosis
|
|
25
|
+
skewness = skew(column)
|
|
26
|
+
kurt = kurtosis(column)
|
|
27
|
+
|
|
28
|
+
return skewness, kurt
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# Copyright (c) 2023 - 2025, AG2ai, Inc., AG2ai open-source projects maintainers and core contributors
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
def detect_outlier_iqr(csv_file: str, column_name: str):
|
|
5
|
+
"""Detect outliers in a specified column of a CSV file using the IQR method.
|
|
6
|
+
|
|
7
|
+
Args:
|
|
8
|
+
csv_file (str): The path to the CSV file.
|
|
9
|
+
column_name (str): The name of the column to detect outliers in.
|
|
10
|
+
|
|
11
|
+
Returns:
|
|
12
|
+
list: A list of row indices that correspond to the outliers.
|
|
13
|
+
"""
|
|
14
|
+
import pandas as pd
|
|
15
|
+
|
|
16
|
+
# Read the CSV file into a pandas DataFrame
|
|
17
|
+
df = pd.read_csv(csv_file)
|
|
18
|
+
|
|
19
|
+
# Calculate the quartiles and IQR for the specified column
|
|
20
|
+
q1 = df[column_name].quantile(0.25)
|
|
21
|
+
q3 = df[column_name].quantile(0.75)
|
|
22
|
+
iqr = q3 - q1
|
|
23
|
+
|
|
24
|
+
# Find the outliers based on the defined criteria
|
|
25
|
+
outliers = df[(df[column_name] < q1 - 1.5 * iqr) | (df[column_name] > q3 + 1.5 * iqr)]
|
|
26
|
+
|
|
27
|
+
# Return the row indices of the outliers
|
|
28
|
+
return outliers.index.tolist()
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# Copyright (c) 2023 - 2025, AG2ai, Inc., AG2ai open-source projects maintainers and core contributors
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
def detect_outlier_zscore(csv_file, column_name, threshold=3):
|
|
5
|
+
"""Detect outliers in a CSV file based on a specified column. The outliers are determined by calculating the z-score of the data points in the column.
|
|
6
|
+
|
|
7
|
+
Args:
|
|
8
|
+
csv_file (str): The path to the CSV file.
|
|
9
|
+
column_name (str): The name of the column to calculate z-scores for.
|
|
10
|
+
threshold (float, optional): The threshold value for determining outliers. By default set to 3.
|
|
11
|
+
|
|
12
|
+
Returns:
|
|
13
|
+
list: A list of row indices where the z-score is above the threshold.
|
|
14
|
+
"""
|
|
15
|
+
import numpy as np
|
|
16
|
+
import pandas as pd
|
|
17
|
+
|
|
18
|
+
# Read the CSV file into a pandas DataFrame
|
|
19
|
+
df = pd.read_csv(csv_file)
|
|
20
|
+
|
|
21
|
+
# Calculate the z-score for the specified column
|
|
22
|
+
z_scores = np.abs((df[column_name] - df[column_name].mean()) / df[column_name].std())
|
|
23
|
+
|
|
24
|
+
# Find the row indices where the z-score is above the threshold
|
|
25
|
+
outlier_indices = np.where(z_scores > threshold)[0]
|
|
26
|
+
|
|
27
|
+
# Return the row indices of the outliers
|
|
28
|
+
return outlier_indices
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# Copyright (c) 2023 - 2025, AG2ai, Inc., AG2ai open-source projects maintainers and core contributors
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
def explore_csv(file_path, num_lines=5):
|
|
5
|
+
"""Reads a CSV file and prints the column names, shape, data types, and the first few lines of data.
|
|
6
|
+
|
|
7
|
+
Args:
|
|
8
|
+
file_path (str): The path to the CSV file.
|
|
9
|
+
num_lines (int, optional): The number of lines to print. Defaults to 5.
|
|
10
|
+
"""
|
|
11
|
+
import pandas as pd
|
|
12
|
+
|
|
13
|
+
df = pd.read_csv(file_path)
|
|
14
|
+
header = df.columns
|
|
15
|
+
print("Columns:")
|
|
16
|
+
print(", ".join(header))
|
|
17
|
+
print("Shape:", df.shape)
|
|
18
|
+
print("Data Types:")
|
|
19
|
+
print(df.dtypes)
|
|
20
|
+
print("First", num_lines, "lines:")
|
|
21
|
+
print(df.head(num_lines))
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# Copyright (c) 2023 - 2025, AG2ai, Inc., AG2ai open-source projects maintainers and core contributors
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
from autogen.coding.func_with_reqs import with_requirements
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
@with_requirements(["pandas", "scipy"])
|
|
8
|
+
def shapiro_wilk_test(csv_file, column_name):
|
|
9
|
+
"""Perform the Shapiro-Wilk test on a specified column of a CSV file.
|
|
10
|
+
|
|
11
|
+
Args:
|
|
12
|
+
csv_file (str): The path to the CSV file.
|
|
13
|
+
column_name (str): The name of the column to perform the test on.
|
|
14
|
+
|
|
15
|
+
Returns:
|
|
16
|
+
float: The p-value resulting from the Shapiro-Wilk test.
|
|
17
|
+
"""
|
|
18
|
+
import pandas as pd
|
|
19
|
+
from scipy.stats import shapiro
|
|
20
|
+
|
|
21
|
+
# Read the CSV file into a pandas DataFrame
|
|
22
|
+
df = pd.read_csv(csv_file)
|
|
23
|
+
|
|
24
|
+
# Extract the specified column as a numpy array
|
|
25
|
+
column_data = df[column_name].values
|
|
26
|
+
|
|
27
|
+
# Perform the Shapiro-Wilk test
|
|
28
|
+
_, p_value = shapiro(column_data)
|
|
29
|
+
|
|
30
|
+
return p_value
|
|
@@ -0,0 +1,27 @@
|
|
|
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
|
+
|
|
6
|
+
from autogen.coding.func_with_reqs import with_requirements
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
@with_requirements(["arxiv"])
|
|
10
|
+
def arxiv_download(id_list: list[str], download_dir="./") -> list[str]:
|
|
11
|
+
"""Downloads PDF files from ArXiv based on a list of arxiv paper IDs.
|
|
12
|
+
|
|
13
|
+
Args:
|
|
14
|
+
id_list (list): A list of paper IDs to download. e.g. [2302.00006v1]
|
|
15
|
+
download_dir (str, optional): The directory to save the downloaded PDF files. Defaults to './'.
|
|
16
|
+
|
|
17
|
+
Returns:
|
|
18
|
+
list: A list of paths to the downloaded PDF files.
|
|
19
|
+
"""
|
|
20
|
+
import arxiv
|
|
21
|
+
|
|
22
|
+
paths = []
|
|
23
|
+
for paper in arxiv.Client().results(arxiv.Search(id_list=id_list)):
|
|
24
|
+
path = paper.download_pdf(download_dir, filename=paper.get_short_id() + ".pdf")
|
|
25
|
+
paths.append(path)
|
|
26
|
+
print("Paper id:", paper.get_short_id(), "Downloaded to:", path)
|
|
27
|
+
return paths
|
|
@@ -0,0 +1,53 @@
|
|
|
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
|
+
|
|
6
|
+
from autogen.coding.func_with_reqs import with_requirements
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
@with_requirements(["arxiv"])
|
|
10
|
+
def arxiv_search(query, max_results=10, sortby="relevance"):
|
|
11
|
+
"""Search for articles on arXiv based on the given query.
|
|
12
|
+
|
|
13
|
+
Args:
|
|
14
|
+
query (str): The search query.
|
|
15
|
+
max_results (int, optional): The maximum number of results to retrieve. Defaults to 10.
|
|
16
|
+
sortby (str, optional): The sorting criterion for the search results. Can be 'relevance' or 'submittedDate'. Defaults to 'relevance'.
|
|
17
|
+
|
|
18
|
+
Returns:
|
|
19
|
+
list: A list of dictionaries containing information about the search results. Each dictionary contains the following keys:
|
|
20
|
+
- 'title': The title of the article.
|
|
21
|
+
- 'authors': The authors of the article.
|
|
22
|
+
- 'summary': The summary of the article.
|
|
23
|
+
- 'entry_id': The entry ID of the article.
|
|
24
|
+
- 'doi': The DOI of the article (If applicable).
|
|
25
|
+
- 'published': The publication date of the article in the format 'Y-M'.
|
|
26
|
+
"""
|
|
27
|
+
import arxiv
|
|
28
|
+
|
|
29
|
+
def get_author(r):
|
|
30
|
+
return ", ".join(a.name for a in r.authors)
|
|
31
|
+
|
|
32
|
+
criterion = {"relevance": arxiv.SortCriterion.Relevance, "submittedDate": arxiv.SortCriterion.SubmittedDate}[sortby]
|
|
33
|
+
|
|
34
|
+
client = arxiv.Client()
|
|
35
|
+
search = arxiv.Search(query=query, max_results=max_results, sort_by=criterion)
|
|
36
|
+
res = []
|
|
37
|
+
results = client.results(search)
|
|
38
|
+
for r in results:
|
|
39
|
+
print("Entry id:", r.entry_id)
|
|
40
|
+
print("Title:", r.title)
|
|
41
|
+
print("Authors:", get_author(r))
|
|
42
|
+
print("DOI:", r.doi)
|
|
43
|
+
print("Published:", r.published.strftime("%Y-%m"))
|
|
44
|
+
# print("Summary:", r.summary)
|
|
45
|
+
res.append({
|
|
46
|
+
"title": r.title,
|
|
47
|
+
"authors": get_author(r),
|
|
48
|
+
"summary": r.summary,
|
|
49
|
+
"entry_id": r.entry_id,
|
|
50
|
+
"doi": r.doi,
|
|
51
|
+
"published": r.published.strftime("%Y-%m"),
|
|
52
|
+
})
|
|
53
|
+
return res
|