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,836 @@
|
|
|
1
|
+
# Copyright (c) 2023 - 2025, AG2ai, Inc., AG2ai open-source projects maintainers and core contributors
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
|
|
5
|
+
import logging
|
|
6
|
+
import os
|
|
7
|
+
from typing import Annotated, Any
|
|
8
|
+
|
|
9
|
+
from ....doc_utils import export_module
|
|
10
|
+
from ....import_utils import optional_import_block, require_optional_import
|
|
11
|
+
from ....llm_config import LLMConfig
|
|
12
|
+
from ... import Depends, Tool
|
|
13
|
+
from ...dependency_injection import on
|
|
14
|
+
|
|
15
|
+
logger = logging.getLogger(__name__)
|
|
16
|
+
|
|
17
|
+
with optional_import_block():
|
|
18
|
+
from firecrawl import FirecrawlApp, ScrapeOptions
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
@require_optional_import(
|
|
22
|
+
[
|
|
23
|
+
"firecrawl-py",
|
|
24
|
+
],
|
|
25
|
+
"firecrawl",
|
|
26
|
+
)
|
|
27
|
+
def _execute_firecrawl_scrape(
|
|
28
|
+
url: str,
|
|
29
|
+
firecrawl_api_key: str,
|
|
30
|
+
firecrawl_api_url: str | None = None,
|
|
31
|
+
formats: list[str] | None = None,
|
|
32
|
+
include_tags: list[str] | None = None,
|
|
33
|
+
exclude_tags: list[str] | None = None,
|
|
34
|
+
headers: dict[str, str] | None = None,
|
|
35
|
+
wait_for: int | None = None,
|
|
36
|
+
timeout: int | None = None,
|
|
37
|
+
) -> dict[str, Any]:
|
|
38
|
+
"""Execute a scrape operation using the Firecrawl API.
|
|
39
|
+
|
|
40
|
+
Args:
|
|
41
|
+
url (str): The URL to scrape.
|
|
42
|
+
firecrawl_api_key (str): The API key for Firecrawl.
|
|
43
|
+
firecrawl_api_url (str, optional): The base URL for the Firecrawl API. Defaults to None (uses default or env var).
|
|
44
|
+
formats (list[str], optional): Output formats (e.g., ['markdown', 'html']). Defaults to ['markdown'].
|
|
45
|
+
include_tags (list[str], optional): HTML tags to include. Defaults to None.
|
|
46
|
+
exclude_tags (list[str], optional): HTML tags to exclude. Defaults to None.
|
|
47
|
+
headers (dict[str, str], optional): HTTP headers to use. Defaults to None.
|
|
48
|
+
wait_for (int, optional): Time to wait for page load in milliseconds. Defaults to None.
|
|
49
|
+
timeout (int, optional): Request timeout in milliseconds. Defaults to None.
|
|
50
|
+
|
|
51
|
+
Returns:
|
|
52
|
+
dict[str, Any]: The scrape result from Firecrawl.
|
|
53
|
+
"""
|
|
54
|
+
if formats is None:
|
|
55
|
+
formats = ["markdown"]
|
|
56
|
+
|
|
57
|
+
app = FirecrawlApp(api_key=firecrawl_api_key, api_url=firecrawl_api_url)
|
|
58
|
+
|
|
59
|
+
result = app.scrape_url(
|
|
60
|
+
url=url,
|
|
61
|
+
formats=formats,
|
|
62
|
+
include_tags=include_tags,
|
|
63
|
+
exclude_tags=exclude_tags,
|
|
64
|
+
headers=headers,
|
|
65
|
+
wait_for=wait_for,
|
|
66
|
+
timeout=timeout,
|
|
67
|
+
)
|
|
68
|
+
return dict(result)
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
@require_optional_import(
|
|
72
|
+
[
|
|
73
|
+
"firecrawl-py",
|
|
74
|
+
],
|
|
75
|
+
"firecrawl",
|
|
76
|
+
)
|
|
77
|
+
def _execute_firecrawl_crawl(
|
|
78
|
+
url: str,
|
|
79
|
+
firecrawl_api_key: str,
|
|
80
|
+
firecrawl_api_url: str | None = None,
|
|
81
|
+
limit: int = 5,
|
|
82
|
+
formats: list[str] | None = None,
|
|
83
|
+
include_paths: list[str] | None = None,
|
|
84
|
+
exclude_paths: list[str] | None = None,
|
|
85
|
+
max_depth: int | None = None,
|
|
86
|
+
allow_backward_crawling: bool = False,
|
|
87
|
+
allow_external_content_links: bool = False,
|
|
88
|
+
) -> dict[str, Any]:
|
|
89
|
+
"""Execute a crawl operation using the Firecrawl API.
|
|
90
|
+
|
|
91
|
+
Args:
|
|
92
|
+
url (str): The starting URL to crawl.
|
|
93
|
+
firecrawl_api_key (str): The API key for Firecrawl.
|
|
94
|
+
firecrawl_api_url (str, optional): The base URL for the Firecrawl API. Defaults to None (uses default or env var).
|
|
95
|
+
limit (int, optional): Maximum number of pages to crawl. Defaults to 5.
|
|
96
|
+
formats (list[str], optional): Output formats (e.g., ['markdown', 'html']). Defaults to ['markdown'].
|
|
97
|
+
include_paths (list[str], optional): URL patterns to include. Defaults to None.
|
|
98
|
+
exclude_paths (list[str], optional): URL patterns to exclude. Defaults to None.
|
|
99
|
+
max_depth (int, optional): Maximum crawl depth. Defaults to None.
|
|
100
|
+
allow_backward_crawling (bool, optional): Allow crawling backward links. Defaults to False.
|
|
101
|
+
allow_external_content_links (bool, optional): Allow external links. Defaults to False.
|
|
102
|
+
|
|
103
|
+
Returns:
|
|
104
|
+
dict[str, Any]: The crawl result from Firecrawl.
|
|
105
|
+
"""
|
|
106
|
+
if formats is None:
|
|
107
|
+
formats = ["markdown"]
|
|
108
|
+
|
|
109
|
+
app = FirecrawlApp(api_key=firecrawl_api_key, api_url=firecrawl_api_url)
|
|
110
|
+
|
|
111
|
+
# Build scrape options for crawling
|
|
112
|
+
scrape_options = None
|
|
113
|
+
if formats:
|
|
114
|
+
scrape_options = ScrapeOptions(formats=formats)
|
|
115
|
+
|
|
116
|
+
result = app.crawl_url(
|
|
117
|
+
url=url,
|
|
118
|
+
limit=limit,
|
|
119
|
+
scrape_options=scrape_options,
|
|
120
|
+
include_paths=include_paths,
|
|
121
|
+
exclude_paths=exclude_paths,
|
|
122
|
+
max_depth=max_depth,
|
|
123
|
+
allow_backward_links=allow_backward_crawling,
|
|
124
|
+
allow_external_links=allow_external_content_links,
|
|
125
|
+
)
|
|
126
|
+
return dict(result)
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
@require_optional_import(
|
|
130
|
+
[
|
|
131
|
+
"firecrawl-py",
|
|
132
|
+
],
|
|
133
|
+
"firecrawl",
|
|
134
|
+
)
|
|
135
|
+
def _execute_firecrawl_map(
|
|
136
|
+
url: str,
|
|
137
|
+
firecrawl_api_key: str,
|
|
138
|
+
firecrawl_api_url: str | None = None,
|
|
139
|
+
search: str | None = None,
|
|
140
|
+
ignore_sitemap: bool = False,
|
|
141
|
+
include_subdomains: bool = False,
|
|
142
|
+
limit: int = 5000,
|
|
143
|
+
) -> dict[str, Any]:
|
|
144
|
+
"""Execute a map operation using the Firecrawl API to get URLs from a website.
|
|
145
|
+
|
|
146
|
+
Args:
|
|
147
|
+
url (str): The website URL to map.
|
|
148
|
+
firecrawl_api_key (str): The API key for Firecrawl.
|
|
149
|
+
firecrawl_api_url (str, optional): The base URL for the Firecrawl API. Defaults to None (uses default or env var).
|
|
150
|
+
search (str, optional): Search term to filter URLs. Defaults to None.
|
|
151
|
+
ignore_sitemap (bool, optional): Whether to ignore the sitemap. Defaults to False.
|
|
152
|
+
include_subdomains (bool, optional): Whether to include subdomains. Defaults to False.
|
|
153
|
+
limit (int, optional): Maximum number of URLs to return. Defaults to 5000.
|
|
154
|
+
|
|
155
|
+
Returns:
|
|
156
|
+
dict[str, Any]: The map result from Firecrawl.
|
|
157
|
+
"""
|
|
158
|
+
app = FirecrawlApp(api_key=firecrawl_api_key, api_url=firecrawl_api_url)
|
|
159
|
+
|
|
160
|
+
result = app.map_url(
|
|
161
|
+
url=url,
|
|
162
|
+
search=search,
|
|
163
|
+
ignore_sitemap=ignore_sitemap,
|
|
164
|
+
include_subdomains=include_subdomains,
|
|
165
|
+
limit=limit,
|
|
166
|
+
)
|
|
167
|
+
return dict(result)
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
@require_optional_import(
|
|
171
|
+
[
|
|
172
|
+
"firecrawl-py",
|
|
173
|
+
],
|
|
174
|
+
"firecrawl",
|
|
175
|
+
)
|
|
176
|
+
def _execute_firecrawl_search(
|
|
177
|
+
query: str,
|
|
178
|
+
firecrawl_api_key: str,
|
|
179
|
+
firecrawl_api_url: str | None = None,
|
|
180
|
+
limit: int = 5,
|
|
181
|
+
tbs: str | None = None,
|
|
182
|
+
filter: str | None = None,
|
|
183
|
+
lang: str = "en",
|
|
184
|
+
country: str = "us",
|
|
185
|
+
location: str | None = None,
|
|
186
|
+
timeout: int | None = None,
|
|
187
|
+
) -> dict[str, Any]:
|
|
188
|
+
"""Execute a search operation using the Firecrawl API.
|
|
189
|
+
|
|
190
|
+
Args:
|
|
191
|
+
query (str): The search query string.
|
|
192
|
+
firecrawl_api_key (str): The API key for Firecrawl.
|
|
193
|
+
firecrawl_api_url (str, optional): The base URL for the Firecrawl API. Defaults to None (uses default or env var).
|
|
194
|
+
limit (int, optional): Maximum number of results to return. Defaults to 5.
|
|
195
|
+
tbs (str, optional): Time filter (e.g., "qdr:d" for past day). Defaults to None.
|
|
196
|
+
filter (str, optional): Custom result filter. Defaults to None.
|
|
197
|
+
lang (str, optional): Language code. Defaults to "en".
|
|
198
|
+
country (str, optional): Country code. Defaults to "us".
|
|
199
|
+
location (str, optional): Geo-targeting location. Defaults to None.
|
|
200
|
+
timeout (int, optional): Request timeout in milliseconds. Defaults to None.
|
|
201
|
+
|
|
202
|
+
Returns:
|
|
203
|
+
dict[str, Any]: The search result from Firecrawl.
|
|
204
|
+
"""
|
|
205
|
+
app = FirecrawlApp(api_key=firecrawl_api_key, api_url=firecrawl_api_url)
|
|
206
|
+
|
|
207
|
+
result = app.search(
|
|
208
|
+
query=query,
|
|
209
|
+
limit=limit,
|
|
210
|
+
tbs=tbs,
|
|
211
|
+
filter=filter,
|
|
212
|
+
lang=lang,
|
|
213
|
+
country=country,
|
|
214
|
+
location=location,
|
|
215
|
+
timeout=timeout,
|
|
216
|
+
)
|
|
217
|
+
return dict(result)
|
|
218
|
+
|
|
219
|
+
|
|
220
|
+
@require_optional_import(
|
|
221
|
+
[
|
|
222
|
+
"firecrawl-py",
|
|
223
|
+
],
|
|
224
|
+
"firecrawl",
|
|
225
|
+
)
|
|
226
|
+
def _execute_firecrawl_deep_research(
|
|
227
|
+
query: str,
|
|
228
|
+
firecrawl_api_key: str,
|
|
229
|
+
firecrawl_api_url: str | None = None,
|
|
230
|
+
max_depth: int = 7,
|
|
231
|
+
time_limit: int = 270,
|
|
232
|
+
max_urls: int = 20,
|
|
233
|
+
analysis_prompt: str | None = None,
|
|
234
|
+
system_prompt: str | None = None,
|
|
235
|
+
) -> dict[str, Any]:
|
|
236
|
+
"""Execute a deep research operation using the Firecrawl API.
|
|
237
|
+
|
|
238
|
+
Args:
|
|
239
|
+
query (str): The research query or topic to investigate.
|
|
240
|
+
firecrawl_api_key (str): The API key for Firecrawl.
|
|
241
|
+
firecrawl_api_url (str, optional): The base URL for the Firecrawl API. Defaults to None (uses default or env var).
|
|
242
|
+
max_depth (int, optional): Maximum depth of research exploration. Defaults to 7.
|
|
243
|
+
time_limit (int, optional): Time limit in seconds for research. Defaults to 270.
|
|
244
|
+
max_urls (int, optional): Maximum number of URLs to process. Defaults to 20.
|
|
245
|
+
analysis_prompt (str, optional): Custom prompt for analysis. Defaults to None.
|
|
246
|
+
system_prompt (str, optional): Custom system prompt. Defaults to None.
|
|
247
|
+
|
|
248
|
+
Returns:
|
|
249
|
+
dict[str, Any]: The deep research result from Firecrawl.
|
|
250
|
+
"""
|
|
251
|
+
app = FirecrawlApp(api_key=firecrawl_api_key, api_url=firecrawl_api_url)
|
|
252
|
+
|
|
253
|
+
result = app.deep_research(
|
|
254
|
+
query=query,
|
|
255
|
+
max_depth=max_depth,
|
|
256
|
+
time_limit=time_limit,
|
|
257
|
+
max_urls=max_urls,
|
|
258
|
+
analysis_prompt=analysis_prompt,
|
|
259
|
+
system_prompt=system_prompt,
|
|
260
|
+
)
|
|
261
|
+
return dict(result)
|
|
262
|
+
|
|
263
|
+
|
|
264
|
+
def _firecrawl_scrape(
|
|
265
|
+
url: str,
|
|
266
|
+
firecrawl_api_key: str,
|
|
267
|
+
firecrawl_api_url: str | None = None,
|
|
268
|
+
formats: list[str] | None = None,
|
|
269
|
+
include_tags: list[str] | None = None,
|
|
270
|
+
exclude_tags: list[str] | None = None,
|
|
271
|
+
headers: dict[str, str] | None = None,
|
|
272
|
+
wait_for: int | None = None,
|
|
273
|
+
timeout: int | None = None,
|
|
274
|
+
) -> list[dict[str, Any]]:
|
|
275
|
+
"""Perform a Firecrawl scrape and format the results.
|
|
276
|
+
|
|
277
|
+
Args:
|
|
278
|
+
url (str): The URL to scrape.
|
|
279
|
+
firecrawl_api_key (str): The API key for Firecrawl.
|
|
280
|
+
firecrawl_api_url (str, optional): The base URL for the Firecrawl API. Defaults to None.
|
|
281
|
+
formats (list[str], optional): Output formats. Defaults to ['markdown'].
|
|
282
|
+
include_tags (list[str], optional): HTML tags to include. Defaults to None.
|
|
283
|
+
exclude_tags (list[str], optional): HTML tags to exclude. Defaults to None.
|
|
284
|
+
headers (dict[str, str], optional): HTTP headers to use. Defaults to None.
|
|
285
|
+
wait_for (int, optional): Time to wait for page load in milliseconds. Defaults to None.
|
|
286
|
+
timeout (int, optional): Request timeout in milliseconds. Defaults to None.
|
|
287
|
+
|
|
288
|
+
Returns:
|
|
289
|
+
list[dict[str, Any]]: A list containing the scraped content.
|
|
290
|
+
"""
|
|
291
|
+
try:
|
|
292
|
+
result = _execute_firecrawl_scrape(
|
|
293
|
+
url=url,
|
|
294
|
+
firecrawl_api_key=firecrawl_api_key,
|
|
295
|
+
firecrawl_api_url=firecrawl_api_url,
|
|
296
|
+
formats=formats,
|
|
297
|
+
include_tags=include_tags,
|
|
298
|
+
exclude_tags=exclude_tags,
|
|
299
|
+
headers=headers,
|
|
300
|
+
wait_for=wait_for,
|
|
301
|
+
timeout=timeout,
|
|
302
|
+
)
|
|
303
|
+
|
|
304
|
+
# Format the result to match expected output
|
|
305
|
+
formatted_result = {
|
|
306
|
+
"title": result.get("metadata", {}).get("title", ""),
|
|
307
|
+
"url": url,
|
|
308
|
+
"content": result.get("markdown", result.get("html", "")),
|
|
309
|
+
"metadata": result.get("metadata", {}),
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
return [formatted_result]
|
|
313
|
+
except Exception as e:
|
|
314
|
+
logger.error(f"Firecrawl scrape failed: {e}")
|
|
315
|
+
return []
|
|
316
|
+
|
|
317
|
+
|
|
318
|
+
def _firecrawl_crawl(
|
|
319
|
+
url: str,
|
|
320
|
+
firecrawl_api_key: str,
|
|
321
|
+
firecrawl_api_url: str | None = None,
|
|
322
|
+
limit: int = 5,
|
|
323
|
+
formats: list[str] | None = None,
|
|
324
|
+
include_paths: list[str] | None = None,
|
|
325
|
+
exclude_paths: list[str] | None = None,
|
|
326
|
+
max_depth: int | None = None,
|
|
327
|
+
allow_backward_crawling: bool = False,
|
|
328
|
+
allow_external_content_links: bool = False,
|
|
329
|
+
) -> list[dict[str, Any]]:
|
|
330
|
+
"""Perform a Firecrawl crawl and format the results.
|
|
331
|
+
|
|
332
|
+
Args:
|
|
333
|
+
url (str): The starting URL to crawl.
|
|
334
|
+
firecrawl_api_key (str): The API key for Firecrawl.
|
|
335
|
+
firecrawl_api_url (str, optional): The base URL for the Firecrawl API. Defaults to None.
|
|
336
|
+
limit (int, optional): Maximum number of pages to crawl. Defaults to 5.
|
|
337
|
+
formats (list[str], optional): Output formats. Defaults to ['markdown'].
|
|
338
|
+
include_paths (list[str], optional): URL patterns to include. Defaults to None.
|
|
339
|
+
exclude_paths (list[str], optional): URL patterns to exclude. Defaults to None.
|
|
340
|
+
max_depth (int, optional): Maximum crawl depth. Defaults to None.
|
|
341
|
+
allow_backward_crawling (bool, optional): Allow crawling backward links. Defaults to False.
|
|
342
|
+
allow_external_content_links (bool, optional): Allow external links. Defaults to False.
|
|
343
|
+
|
|
344
|
+
Returns:
|
|
345
|
+
list[dict[str, Any]]: A list of crawled pages with content.
|
|
346
|
+
"""
|
|
347
|
+
try:
|
|
348
|
+
result = _execute_firecrawl_crawl(
|
|
349
|
+
url=url,
|
|
350
|
+
firecrawl_api_key=firecrawl_api_key,
|
|
351
|
+
firecrawl_api_url=firecrawl_api_url,
|
|
352
|
+
limit=limit,
|
|
353
|
+
formats=formats,
|
|
354
|
+
include_paths=include_paths,
|
|
355
|
+
exclude_paths=exclude_paths,
|
|
356
|
+
max_depth=max_depth,
|
|
357
|
+
allow_backward_crawling=allow_backward_crawling,
|
|
358
|
+
allow_external_content_links=allow_external_content_links,
|
|
359
|
+
)
|
|
360
|
+
|
|
361
|
+
# Format the results
|
|
362
|
+
formatted_results = []
|
|
363
|
+
data = result.get("data", [])
|
|
364
|
+
|
|
365
|
+
for item in data:
|
|
366
|
+
formatted_result = {
|
|
367
|
+
"title": item.get("metadata", {}).get("title", ""),
|
|
368
|
+
"url": item.get("metadata", {}).get("sourceURL", ""),
|
|
369
|
+
"content": item.get("markdown", item.get("html", "")),
|
|
370
|
+
"metadata": item.get("metadata", {}),
|
|
371
|
+
}
|
|
372
|
+
formatted_results.append(formatted_result)
|
|
373
|
+
|
|
374
|
+
return formatted_results
|
|
375
|
+
except Exception as e:
|
|
376
|
+
logger.error(f"Firecrawl crawl failed: {e}")
|
|
377
|
+
return []
|
|
378
|
+
|
|
379
|
+
|
|
380
|
+
def _firecrawl_map(
|
|
381
|
+
url: str,
|
|
382
|
+
firecrawl_api_key: str,
|
|
383
|
+
firecrawl_api_url: str | None = None,
|
|
384
|
+
search: str | None = None,
|
|
385
|
+
ignore_sitemap: bool = False,
|
|
386
|
+
include_subdomains: bool = False,
|
|
387
|
+
limit: int = 5000,
|
|
388
|
+
) -> list[dict[str, Any]]:
|
|
389
|
+
"""Perform a Firecrawl map operation and format the results.
|
|
390
|
+
|
|
391
|
+
Args:
|
|
392
|
+
url (str): The website URL to map.
|
|
393
|
+
firecrawl_api_key (str): The API key for Firecrawl.
|
|
394
|
+
firecrawl_api_url (str, optional): The base URL for the Firecrawl API. Defaults to None.
|
|
395
|
+
search (str, optional): Search term to filter URLs. Defaults to None.
|
|
396
|
+
ignore_sitemap (bool, optional): Whether to ignore the sitemap. Defaults to False.
|
|
397
|
+
include_subdomains (bool, optional): Whether to include subdomains. Defaults to False.
|
|
398
|
+
limit (int, optional): Maximum number of URLs to return. Defaults to 5000.
|
|
399
|
+
|
|
400
|
+
Returns:
|
|
401
|
+
list[dict[str, Any]]: A list of URLs found on the website.
|
|
402
|
+
"""
|
|
403
|
+
try:
|
|
404
|
+
result = _execute_firecrawl_map(
|
|
405
|
+
url=url,
|
|
406
|
+
firecrawl_api_key=firecrawl_api_key,
|
|
407
|
+
firecrawl_api_url=firecrawl_api_url,
|
|
408
|
+
search=search,
|
|
409
|
+
ignore_sitemap=ignore_sitemap,
|
|
410
|
+
include_subdomains=include_subdomains,
|
|
411
|
+
limit=limit,
|
|
412
|
+
)
|
|
413
|
+
|
|
414
|
+
# Format the results
|
|
415
|
+
formatted_results = []
|
|
416
|
+
links = result.get("links", [])
|
|
417
|
+
|
|
418
|
+
for link in links:
|
|
419
|
+
formatted_result = {
|
|
420
|
+
"url": link,
|
|
421
|
+
"title": "", # Map operation doesn't provide titles
|
|
422
|
+
"content": "", # Map operation doesn't provide content
|
|
423
|
+
}
|
|
424
|
+
formatted_results.append(formatted_result)
|
|
425
|
+
|
|
426
|
+
return formatted_results
|
|
427
|
+
except Exception as e:
|
|
428
|
+
logger.error(f"Firecrawl map failed: {e}")
|
|
429
|
+
return []
|
|
430
|
+
|
|
431
|
+
|
|
432
|
+
def _firecrawl_search(
|
|
433
|
+
query: str,
|
|
434
|
+
firecrawl_api_key: str,
|
|
435
|
+
firecrawl_api_url: str | None = None,
|
|
436
|
+
limit: int = 5,
|
|
437
|
+
tbs: str | None = None,
|
|
438
|
+
filter: str | None = None,
|
|
439
|
+
lang: str = "en",
|
|
440
|
+
country: str = "us",
|
|
441
|
+
location: str | None = None,
|
|
442
|
+
timeout: int | None = None,
|
|
443
|
+
) -> list[dict[str, Any]]:
|
|
444
|
+
"""Perform a Firecrawl search and format the results.
|
|
445
|
+
|
|
446
|
+
Args:
|
|
447
|
+
query (str): The search query string.
|
|
448
|
+
firecrawl_api_key (str): The API key for Firecrawl.
|
|
449
|
+
firecrawl_api_url (str, optional): The base URL for the Firecrawl API. Defaults to None.
|
|
450
|
+
limit (int, optional): Maximum number of results to return. Defaults to 5.
|
|
451
|
+
tbs (str, optional): Time filter (e.g., "qdr:d" for past day). Defaults to None.
|
|
452
|
+
filter (str, optional): Custom result filter. Defaults to None.
|
|
453
|
+
lang (str, optional): Language code. Defaults to "en".
|
|
454
|
+
country (str, optional): Country code. Defaults to "us".
|
|
455
|
+
location (str, optional): Geo-targeting location. Defaults to None.
|
|
456
|
+
timeout (int, optional): Request timeout in milliseconds. Defaults to None.
|
|
457
|
+
|
|
458
|
+
Returns:
|
|
459
|
+
list[dict[str, Any]]: A list of search results with content.
|
|
460
|
+
"""
|
|
461
|
+
try:
|
|
462
|
+
result = _execute_firecrawl_search(
|
|
463
|
+
query=query,
|
|
464
|
+
firecrawl_api_key=firecrawl_api_key,
|
|
465
|
+
firecrawl_api_url=firecrawl_api_url,
|
|
466
|
+
limit=limit,
|
|
467
|
+
tbs=tbs,
|
|
468
|
+
filter=filter,
|
|
469
|
+
lang=lang,
|
|
470
|
+
country=country,
|
|
471
|
+
location=location,
|
|
472
|
+
timeout=timeout,
|
|
473
|
+
)
|
|
474
|
+
|
|
475
|
+
# Format the results
|
|
476
|
+
formatted_results = []
|
|
477
|
+
data = result.get("data", [])
|
|
478
|
+
|
|
479
|
+
for item in data:
|
|
480
|
+
formatted_result = {
|
|
481
|
+
"title": item.get("title", ""),
|
|
482
|
+
"url": item.get("url", ""),
|
|
483
|
+
"content": item.get("markdown", item.get("html", "")),
|
|
484
|
+
"description": item.get("description", ""),
|
|
485
|
+
"metadata": item.get("metadata", {}),
|
|
486
|
+
}
|
|
487
|
+
formatted_results.append(formatted_result)
|
|
488
|
+
|
|
489
|
+
return formatted_results
|
|
490
|
+
except Exception as e:
|
|
491
|
+
logger.error(f"Firecrawl search failed: {e}")
|
|
492
|
+
return []
|
|
493
|
+
|
|
494
|
+
|
|
495
|
+
def _firecrawl_deep_research(
|
|
496
|
+
query: str,
|
|
497
|
+
firecrawl_api_key: str,
|
|
498
|
+
firecrawl_api_url: str | None = None,
|
|
499
|
+
max_depth: int = 7,
|
|
500
|
+
time_limit: int = 270,
|
|
501
|
+
max_urls: int = 20,
|
|
502
|
+
analysis_prompt: str | None = None,
|
|
503
|
+
system_prompt: str | None = None,
|
|
504
|
+
) -> dict[str, Any]:
|
|
505
|
+
"""Perform a Firecrawl deep research operation and format the results.
|
|
506
|
+
|
|
507
|
+
Args:
|
|
508
|
+
query (str): The research query or topic to investigate.
|
|
509
|
+
firecrawl_api_key (str): The API key for Firecrawl.
|
|
510
|
+
firecrawl_api_url (str, optional): The base URL for the Firecrawl API. Defaults to None.
|
|
511
|
+
max_depth (int, optional): Maximum depth of research exploration. Defaults to 7.
|
|
512
|
+
time_limit (int, optional): Time limit in seconds for research. Defaults to 270.
|
|
513
|
+
max_urls (int, optional): Maximum number of URLs to process. Defaults to 20.
|
|
514
|
+
analysis_prompt (str, optional): Custom prompt for analysis. Defaults to None.
|
|
515
|
+
system_prompt (str, optional): Custom system prompt. Defaults to None.
|
|
516
|
+
|
|
517
|
+
Returns:
|
|
518
|
+
dict[str, Any]: The deep research result with analysis, sources, and summaries.
|
|
519
|
+
"""
|
|
520
|
+
try:
|
|
521
|
+
result = _execute_firecrawl_deep_research(
|
|
522
|
+
query=query,
|
|
523
|
+
firecrawl_api_key=firecrawl_api_key,
|
|
524
|
+
firecrawl_api_url=firecrawl_api_url,
|
|
525
|
+
max_depth=max_depth,
|
|
526
|
+
time_limit=time_limit,
|
|
527
|
+
max_urls=max_urls,
|
|
528
|
+
analysis_prompt=analysis_prompt,
|
|
529
|
+
system_prompt=system_prompt,
|
|
530
|
+
)
|
|
531
|
+
|
|
532
|
+
# Format the result - deep research returns a comprehensive analysis
|
|
533
|
+
formatted_result = {
|
|
534
|
+
"query": query,
|
|
535
|
+
"status": result.get("status", ""),
|
|
536
|
+
"data": result.get("data", {}),
|
|
537
|
+
"sources": result.get("sources", []),
|
|
538
|
+
"summaries": result.get("summaries", []),
|
|
539
|
+
"activities": result.get("activities", []),
|
|
540
|
+
"success": result.get("success", False),
|
|
541
|
+
"error": result.get("error", ""),
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
return formatted_result
|
|
545
|
+
except Exception as e:
|
|
546
|
+
logger.error(f"Firecrawl deep research failed: {e}")
|
|
547
|
+
return {
|
|
548
|
+
"query": query,
|
|
549
|
+
"status": "failed",
|
|
550
|
+
"data": {},
|
|
551
|
+
"sources": [],
|
|
552
|
+
"summaries": [],
|
|
553
|
+
"activities": [],
|
|
554
|
+
"success": False,
|
|
555
|
+
"error": str(e),
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
|
|
559
|
+
@export_module("autogen.tools.experimental")
|
|
560
|
+
class FirecrawlTool(Tool):
|
|
561
|
+
"""FirecrawlTool is a tool that uses the Firecrawl API to scrape, crawl, map, search, and research websites.
|
|
562
|
+
|
|
563
|
+
This tool allows agents to leverage Firecrawl for web content extraction, discovery, and research.
|
|
564
|
+
It requires a Firecrawl API key, which can be provided during initialization or set as
|
|
565
|
+
an environment variable `FIRECRAWL_API_KEY`.
|
|
566
|
+
|
|
567
|
+
The tool provides five main functionalities:
|
|
568
|
+
- Scrape: Extract content from a single URL
|
|
569
|
+
- Crawl: Recursively crawl a website starting from a URL
|
|
570
|
+
- Map: Discover URLs from a website
|
|
571
|
+
- Search: Search the web for content using Firecrawl's search capabilities
|
|
572
|
+
- Deep Research: Perform comprehensive research on a topic with analysis and insights
|
|
573
|
+
|
|
574
|
+
Attributes:
|
|
575
|
+
firecrawl_api_key (str): The API key used for authenticating with the Firecrawl API.
|
|
576
|
+
firecrawl_api_url (str, optional): The base URL for the Firecrawl API. Defaults to None.
|
|
577
|
+
"""
|
|
578
|
+
|
|
579
|
+
def __init__(
|
|
580
|
+
self,
|
|
581
|
+
*,
|
|
582
|
+
llm_config: LLMConfig | dict[str, Any] | None = None,
|
|
583
|
+
firecrawl_api_key: str | None = None,
|
|
584
|
+
firecrawl_api_url: str | None = None,
|
|
585
|
+
):
|
|
586
|
+
"""Initializes the FirecrawlTool.
|
|
587
|
+
|
|
588
|
+
Args:
|
|
589
|
+
llm_config (Optional[Union[LLMConfig, dict[str, Any]]]): LLM configuration. (Currently unused but kept for potential future integration).
|
|
590
|
+
firecrawl_api_key (Optional[str]): The API key for the Firecrawl API. If not provided,
|
|
591
|
+
it attempts to read from the `FIRECRAWL_API_KEY` environment variable.
|
|
592
|
+
firecrawl_api_url (Optional[str]): The base URL for the Firecrawl API. If not provided,
|
|
593
|
+
it attempts to read from the `FIRECRAWL_API_URL` environment variable, or defaults
|
|
594
|
+
to the public Firecrawl API. Use this parameter to connect to self-hosted Firecrawl instances.
|
|
595
|
+
|
|
596
|
+
Raises:
|
|
597
|
+
ValueError: If `firecrawl_api_key` is not provided either directly or via the environment variable.
|
|
598
|
+
"""
|
|
599
|
+
self.firecrawl_api_key = firecrawl_api_key or os.getenv("FIRECRAWL_API_KEY")
|
|
600
|
+
self.firecrawl_api_url = firecrawl_api_url or os.getenv("FIRECRAWL_API_URL")
|
|
601
|
+
|
|
602
|
+
if self.firecrawl_api_key is None:
|
|
603
|
+
raise ValueError(
|
|
604
|
+
"firecrawl_api_key must be provided either as an argument or via FIRECRAWL_API_KEY env var"
|
|
605
|
+
)
|
|
606
|
+
|
|
607
|
+
def firecrawl_scrape(
|
|
608
|
+
url: Annotated[str, "The URL to scrape."],
|
|
609
|
+
firecrawl_api_key: Annotated[str | None, Depends(on(self.firecrawl_api_key))],
|
|
610
|
+
firecrawl_api_url: Annotated[str | None, Depends(on(self.firecrawl_api_url))],
|
|
611
|
+
formats: Annotated[list[str] | None, "Output formats (e.g., ['markdown', 'html'])"] = None,
|
|
612
|
+
include_tags: Annotated[list[str] | None, "HTML tags to include"] = None,
|
|
613
|
+
exclude_tags: Annotated[list[str] | None, "HTML tags to exclude"] = None,
|
|
614
|
+
headers: Annotated[dict[str, str] | None, "HTTP headers to use"] = None,
|
|
615
|
+
wait_for: Annotated[int | None, "Time to wait for page load in milliseconds"] = None,
|
|
616
|
+
timeout: Annotated[int | None, "Request timeout in milliseconds"] = None,
|
|
617
|
+
) -> list[dict[str, Any]]:
|
|
618
|
+
"""Scrapes a single URL and returns the content.
|
|
619
|
+
|
|
620
|
+
Args:
|
|
621
|
+
url: The URL to scrape.
|
|
622
|
+
firecrawl_api_key: The API key for Firecrawl (injected dependency).
|
|
623
|
+
firecrawl_api_url: The base URL for the Firecrawl API (injected dependency).
|
|
624
|
+
formats: Output formats (e.g., ['markdown', 'html']). Defaults to ['markdown'].
|
|
625
|
+
include_tags: HTML tags to include. Defaults to None.
|
|
626
|
+
exclude_tags: HTML tags to exclude. Defaults to None.
|
|
627
|
+
headers: HTTP headers to use. Defaults to None.
|
|
628
|
+
wait_for: Time to wait for page load in milliseconds. Defaults to None.
|
|
629
|
+
timeout: Request timeout in milliseconds. Defaults to None.
|
|
630
|
+
|
|
631
|
+
Returns:
|
|
632
|
+
A list containing the scraped content with title, url, content, and metadata.
|
|
633
|
+
|
|
634
|
+
Raises:
|
|
635
|
+
ValueError: If the Firecrawl API key is not available.
|
|
636
|
+
"""
|
|
637
|
+
if firecrawl_api_key is None:
|
|
638
|
+
raise ValueError("Firecrawl API key is missing.")
|
|
639
|
+
return _firecrawl_scrape(
|
|
640
|
+
url=url,
|
|
641
|
+
firecrawl_api_key=firecrawl_api_key,
|
|
642
|
+
firecrawl_api_url=firecrawl_api_url,
|
|
643
|
+
formats=formats,
|
|
644
|
+
include_tags=include_tags,
|
|
645
|
+
exclude_tags=exclude_tags,
|
|
646
|
+
headers=headers,
|
|
647
|
+
wait_for=wait_for,
|
|
648
|
+
timeout=timeout,
|
|
649
|
+
)
|
|
650
|
+
|
|
651
|
+
def firecrawl_crawl(
|
|
652
|
+
url: Annotated[str, "The starting URL to crawl."],
|
|
653
|
+
firecrawl_api_key: Annotated[str | None, Depends(on(self.firecrawl_api_key))],
|
|
654
|
+
firecrawl_api_url: Annotated[str | None, Depends(on(self.firecrawl_api_url))],
|
|
655
|
+
limit: Annotated[int, "Maximum number of pages to crawl"] = 5,
|
|
656
|
+
formats: Annotated[list[str] | None, "Output formats (e.g., ['markdown', 'html'])"] = None,
|
|
657
|
+
include_paths: Annotated[list[str] | None, "URL patterns to include"] = None,
|
|
658
|
+
exclude_paths: Annotated[list[str] | None, "URL patterns to exclude"] = None,
|
|
659
|
+
max_depth: Annotated[int | None, "Maximum crawl depth"] = None,
|
|
660
|
+
allow_backward_crawling: Annotated[bool | None, "Allow crawling backward links"] = False,
|
|
661
|
+
allow_external_content_links: Annotated[bool | None, "Allow external links"] = False,
|
|
662
|
+
) -> list[dict[str, Any]]:
|
|
663
|
+
"""Crawls a website starting from a URL and returns the content from multiple pages.
|
|
664
|
+
|
|
665
|
+
Args:
|
|
666
|
+
url: The starting URL to crawl.
|
|
667
|
+
firecrawl_api_key: The API key for Firecrawl (injected dependency).
|
|
668
|
+
firecrawl_api_url: The base URL for the Firecrawl API (injected dependency).
|
|
669
|
+
limit: Maximum number of pages to crawl. Defaults to 5.
|
|
670
|
+
formats: Output formats (e.g., ['markdown', 'html']). Defaults to ['markdown'].
|
|
671
|
+
include_paths: URL patterns to include. Defaults to None.
|
|
672
|
+
exclude_paths: URL patterns to exclude. Defaults to None.
|
|
673
|
+
max_depth: Maximum crawl depth. Defaults to None.
|
|
674
|
+
allow_backward_crawling: Allow crawling backward links. Defaults to False.
|
|
675
|
+
allow_external_content_links: Allow external links. Defaults to False.
|
|
676
|
+
|
|
677
|
+
Returns:
|
|
678
|
+
A list of crawled pages with title, url, content, and metadata for each page.
|
|
679
|
+
|
|
680
|
+
Raises:
|
|
681
|
+
ValueError: If the Firecrawl API key is not available.
|
|
682
|
+
"""
|
|
683
|
+
if firecrawl_api_key is None:
|
|
684
|
+
raise ValueError("Firecrawl API key is missing.")
|
|
685
|
+
return _firecrawl_crawl(
|
|
686
|
+
url=url,
|
|
687
|
+
firecrawl_api_key=firecrawl_api_key,
|
|
688
|
+
firecrawl_api_url=firecrawl_api_url,
|
|
689
|
+
limit=limit,
|
|
690
|
+
formats=formats,
|
|
691
|
+
include_paths=include_paths,
|
|
692
|
+
exclude_paths=exclude_paths,
|
|
693
|
+
max_depth=max_depth,
|
|
694
|
+
allow_backward_crawling=allow_backward_crawling or False,
|
|
695
|
+
allow_external_content_links=allow_external_content_links or False,
|
|
696
|
+
)
|
|
697
|
+
|
|
698
|
+
def firecrawl_map(
|
|
699
|
+
url: Annotated[str, "The website URL to map."],
|
|
700
|
+
firecrawl_api_key: Annotated[str | None, Depends(on(self.firecrawl_api_key))],
|
|
701
|
+
firecrawl_api_url: Annotated[str | None, Depends(on(self.firecrawl_api_url))],
|
|
702
|
+
search: Annotated[str | None, "Search term to filter URLs"] = None,
|
|
703
|
+
ignore_sitemap: Annotated[bool | None, "Whether to ignore the sitemap"] = False,
|
|
704
|
+
include_subdomains: Annotated[bool | None, "Whether to include subdomains"] = False,
|
|
705
|
+
limit: Annotated[int, "Maximum number of URLs to return"] = 5000,
|
|
706
|
+
) -> list[dict[str, Any]]:
|
|
707
|
+
"""Maps a website to discover URLs.
|
|
708
|
+
|
|
709
|
+
Args:
|
|
710
|
+
url: The website URL to map.
|
|
711
|
+
firecrawl_api_key: The API key for Firecrawl (injected dependency).
|
|
712
|
+
firecrawl_api_url: The base URL for the Firecrawl API (injected dependency).
|
|
713
|
+
search: Search term to filter URLs. Defaults to None.
|
|
714
|
+
ignore_sitemap: Whether to ignore the sitemap. Defaults to False.
|
|
715
|
+
include_subdomains: Whether to include subdomains. Defaults to False.
|
|
716
|
+
limit: Maximum number of URLs to return. Defaults to 5000.
|
|
717
|
+
|
|
718
|
+
Returns:
|
|
719
|
+
A list of URLs found on the website.
|
|
720
|
+
|
|
721
|
+
Raises:
|
|
722
|
+
ValueError: If the Firecrawl API key is not available.
|
|
723
|
+
"""
|
|
724
|
+
if firecrawl_api_key is None:
|
|
725
|
+
raise ValueError("Firecrawl API key is missing.")
|
|
726
|
+
return _firecrawl_map(
|
|
727
|
+
url=url,
|
|
728
|
+
firecrawl_api_key=firecrawl_api_key,
|
|
729
|
+
firecrawl_api_url=firecrawl_api_url,
|
|
730
|
+
search=search,
|
|
731
|
+
ignore_sitemap=ignore_sitemap or False,
|
|
732
|
+
include_subdomains=include_subdomains or False,
|
|
733
|
+
limit=limit,
|
|
734
|
+
)
|
|
735
|
+
|
|
736
|
+
def firecrawl_search(
|
|
737
|
+
query: Annotated[str, "The search query string."],
|
|
738
|
+
firecrawl_api_key: Annotated[str | None, Depends(on(self.firecrawl_api_key))],
|
|
739
|
+
firecrawl_api_url: Annotated[str | None, Depends(on(self.firecrawl_api_url))],
|
|
740
|
+
limit: Annotated[int, "Maximum number of results to return"] = 5,
|
|
741
|
+
tbs: Annotated[str | None, "Time filter (e.g., 'qdr:d' for past day)"] = None,
|
|
742
|
+
filter: Annotated[str | None, "Custom result filter"] = None,
|
|
743
|
+
lang: Annotated[str | None, "Language code"] = "en",
|
|
744
|
+
country: Annotated[str | None, "Country code"] = "us",
|
|
745
|
+
location: Annotated[str | None, "Geo-targeting location"] = None,
|
|
746
|
+
timeout: Annotated[int | None, "Request timeout in milliseconds"] = None,
|
|
747
|
+
) -> list[dict[str, Any]]:
|
|
748
|
+
"""Executes a search operation using the Firecrawl API.
|
|
749
|
+
|
|
750
|
+
Args:
|
|
751
|
+
query: The search query string.
|
|
752
|
+
firecrawl_api_key: The API key for Firecrawl (injected dependency).
|
|
753
|
+
firecrawl_api_url: The base URL for the Firecrawl API (injected dependency).
|
|
754
|
+
limit: Maximum number of results to return. Defaults to 5.
|
|
755
|
+
tbs: Time filter (e.g., "qdr:d" for past day). Defaults to None.
|
|
756
|
+
filter: Custom result filter. Defaults to None.
|
|
757
|
+
lang: Language code. Defaults to "en".
|
|
758
|
+
country: Country code. Defaults to "us".
|
|
759
|
+
location: Geo-targeting location. Defaults to None.
|
|
760
|
+
timeout: Request timeout in milliseconds. Defaults to None.
|
|
761
|
+
|
|
762
|
+
Returns:
|
|
763
|
+
A list of search results with title, url, content, and metadata.
|
|
764
|
+
|
|
765
|
+
Raises:
|
|
766
|
+
ValueError: If the Firecrawl API key is not available.
|
|
767
|
+
"""
|
|
768
|
+
if firecrawl_api_key is None:
|
|
769
|
+
raise ValueError("Firecrawl API key is missing.")
|
|
770
|
+
return _firecrawl_search(
|
|
771
|
+
query=query,
|
|
772
|
+
firecrawl_api_key=firecrawl_api_key,
|
|
773
|
+
firecrawl_api_url=firecrawl_api_url,
|
|
774
|
+
limit=limit,
|
|
775
|
+
tbs=tbs,
|
|
776
|
+
filter=filter,
|
|
777
|
+
lang=lang or "en",
|
|
778
|
+
country=country or "us",
|
|
779
|
+
location=location,
|
|
780
|
+
timeout=timeout,
|
|
781
|
+
)
|
|
782
|
+
|
|
783
|
+
def firecrawl_deep_research(
|
|
784
|
+
query: Annotated[str, "The research query or topic to investigate."],
|
|
785
|
+
firecrawl_api_key: Annotated[str | None, Depends(on(self.firecrawl_api_key))],
|
|
786
|
+
firecrawl_api_url: Annotated[str | None, Depends(on(self.firecrawl_api_url))],
|
|
787
|
+
max_depth: Annotated[int, "Maximum depth of research exploration"] = 7,
|
|
788
|
+
time_limit: Annotated[int, "Time limit in seconds for research"] = 270,
|
|
789
|
+
max_urls: Annotated[int, "Maximum number of URLs to process"] = 20,
|
|
790
|
+
analysis_prompt: Annotated[str | None, "Custom prompt for analysis"] = None,
|
|
791
|
+
system_prompt: Annotated[str | None, "Custom system prompt"] = None,
|
|
792
|
+
) -> dict[str, Any]:
|
|
793
|
+
"""Executes a deep research operation using the Firecrawl API.
|
|
794
|
+
|
|
795
|
+
Args:
|
|
796
|
+
query: The research query or topic to investigate.
|
|
797
|
+
firecrawl_api_key: The API key for Firecrawl (injected dependency).
|
|
798
|
+
firecrawl_api_url: The base URL for the Firecrawl API (injected dependency).
|
|
799
|
+
max_depth: Maximum depth of research exploration. Defaults to 7.
|
|
800
|
+
time_limit: Time limit in seconds for research. Defaults to 270.
|
|
801
|
+
max_urls: Maximum number of URLs to process. Defaults to 20.
|
|
802
|
+
analysis_prompt: Custom prompt for analysis. Defaults to None.
|
|
803
|
+
system_prompt: Custom system prompt. Defaults to None.
|
|
804
|
+
|
|
805
|
+
Returns:
|
|
806
|
+
The deep research result from Firecrawl.
|
|
807
|
+
|
|
808
|
+
Raises:
|
|
809
|
+
ValueError: If the Firecrawl API key is not available.
|
|
810
|
+
"""
|
|
811
|
+
if firecrawl_api_key is None:
|
|
812
|
+
raise ValueError("Firecrawl API key is missing.")
|
|
813
|
+
return _execute_firecrawl_deep_research(
|
|
814
|
+
query=query,
|
|
815
|
+
firecrawl_api_key=firecrawl_api_key,
|
|
816
|
+
firecrawl_api_url=firecrawl_api_url,
|
|
817
|
+
max_depth=max_depth,
|
|
818
|
+
time_limit=time_limit,
|
|
819
|
+
max_urls=max_urls,
|
|
820
|
+
analysis_prompt=analysis_prompt,
|
|
821
|
+
system_prompt=system_prompt,
|
|
822
|
+
)
|
|
823
|
+
|
|
824
|
+
# Default to scrape functionality for the main tool
|
|
825
|
+
super().__init__(
|
|
826
|
+
name="firecrawl_scrape",
|
|
827
|
+
description="Use the Firecrawl API to scrape content from a single URL.",
|
|
828
|
+
func_or_tool=firecrawl_scrape,
|
|
829
|
+
)
|
|
830
|
+
|
|
831
|
+
# Store additional methods for manual access
|
|
832
|
+
self.scrape = firecrawl_scrape
|
|
833
|
+
self.crawl = firecrawl_crawl
|
|
834
|
+
self.map = firecrawl_map
|
|
835
|
+
self.search = firecrawl_search
|
|
836
|
+
self.deep_research = firecrawl_deep_research
|