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,325 @@
|
|
|
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 asyncio
|
|
8
|
+
import datetime
|
|
9
|
+
import logging
|
|
10
|
+
import uuid
|
|
11
|
+
import warnings
|
|
12
|
+
from collections import defaultdict
|
|
13
|
+
from dataclasses import dataclass, field
|
|
14
|
+
from functools import partial
|
|
15
|
+
from typing import Any, TypedDict
|
|
16
|
+
|
|
17
|
+
from ..code_utils import content_str
|
|
18
|
+
from ..doc_utils import export_module
|
|
19
|
+
from ..events.agent_events import PostCarryoverProcessingEvent
|
|
20
|
+
from ..io.base import IOStream
|
|
21
|
+
from .utils import consolidate_chat_info
|
|
22
|
+
|
|
23
|
+
logger = logging.getLogger(__name__)
|
|
24
|
+
Prerequisite = tuple[int, int]
|
|
25
|
+
|
|
26
|
+
__all__ = ["ChatResult", "a_initiate_chats", "initiate_chats"]
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
class CostDict(TypedDict):
|
|
30
|
+
usage_including_cached_inference: dict[str, Any]
|
|
31
|
+
usage_excluding_cached_inference: dict[str, Any]
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
@dataclass
|
|
35
|
+
@export_module("autogen")
|
|
36
|
+
class ChatResult:
|
|
37
|
+
"""(Experimental) The result of a chat. Almost certain to be changed."""
|
|
38
|
+
|
|
39
|
+
chat_id: int = field(default_factory=lambda: uuid.uuid4().int)
|
|
40
|
+
"""chat id"""
|
|
41
|
+
|
|
42
|
+
chat_history: list[dict[str, Any]] = field(default_factory=list)
|
|
43
|
+
"""The chat history."""
|
|
44
|
+
|
|
45
|
+
summary: str = ""
|
|
46
|
+
"""A summary obtained from the chat."""
|
|
47
|
+
|
|
48
|
+
cost: CostDict = field(
|
|
49
|
+
default_factory=lambda: {
|
|
50
|
+
"usage_including_cached_inference": {},
|
|
51
|
+
"usage_excluding_cached_inference": {},
|
|
52
|
+
}
|
|
53
|
+
)
|
|
54
|
+
"""The cost of the chat.
|
|
55
|
+
The value for each usage type is a dictionary containing cost information for that specific type.
|
|
56
|
+
- "usage_including_cached_inference": Cost information on the total usage, including the tokens in cached inference.
|
|
57
|
+
- "usage_excluding_cached_inference": Cost information on the usage of tokens, excluding the tokens in cache. No larger than "usage_including_cached_inference".
|
|
58
|
+
"""
|
|
59
|
+
|
|
60
|
+
human_input: list[str] = field(default_factory=list)
|
|
61
|
+
"""A list of human input solicited during the chat."""
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def _validate_recipients(chat_queue: list[dict[str, Any]]) -> None:
|
|
65
|
+
"""Validate recipients exits and warn repetitive recipients."""
|
|
66
|
+
receipts_set = set()
|
|
67
|
+
for chat_info in chat_queue:
|
|
68
|
+
assert "recipient" in chat_info, "recipient must be provided."
|
|
69
|
+
receipts_set.add(chat_info["recipient"])
|
|
70
|
+
if len(receipts_set) < len(chat_queue):
|
|
71
|
+
warnings.warn(
|
|
72
|
+
"Repetitive recipients detected: The chat history will be cleared by default if a recipient appears more than once. To retain the chat history, please set 'clear_history=False' in the configuration of the repeating agent.",
|
|
73
|
+
UserWarning,
|
|
74
|
+
)
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def __create_async_prerequisites(chat_queue: list[dict[str, Any]]) -> list[Prerequisite]:
|
|
78
|
+
"""Create list of Prerequisite (prerequisite_chat_id, chat_id)"""
|
|
79
|
+
prerequisites = []
|
|
80
|
+
for chat_info in chat_queue:
|
|
81
|
+
if "chat_id" not in chat_info:
|
|
82
|
+
raise ValueError("Each chat must have a unique id for async multi-chat execution.")
|
|
83
|
+
chat_id = chat_info["chat_id"]
|
|
84
|
+
pre_chats = chat_info.get("prerequisites", [])
|
|
85
|
+
for pre_chat_id in pre_chats:
|
|
86
|
+
if not isinstance(pre_chat_id, int):
|
|
87
|
+
raise ValueError("Prerequisite chat id is not int.")
|
|
88
|
+
prerequisites.append((chat_id, pre_chat_id))
|
|
89
|
+
return prerequisites
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
def __find_async_chat_order(chat_ids: set[int], prerequisites: list[Prerequisite]) -> list[int]:
|
|
93
|
+
"""Find chat order for async execution based on the prerequisite chats
|
|
94
|
+
|
|
95
|
+
Args:
|
|
96
|
+
chat_ids: A set of all chat IDs that need to be scheduled
|
|
97
|
+
prerequisites: A list of tuples (chat_id, prerequisite_chat_id) where each tuple indicates that chat_id depends on prerequisite_chat_id
|
|
98
|
+
|
|
99
|
+
Returns:
|
|
100
|
+
list: a list of chat_id in order.
|
|
101
|
+
"""
|
|
102
|
+
edges = defaultdict(set)
|
|
103
|
+
indegree = defaultdict(int)
|
|
104
|
+
for pair in prerequisites:
|
|
105
|
+
chat, pre = pair[0], pair[1]
|
|
106
|
+
if chat not in edges[pre]:
|
|
107
|
+
indegree[chat] += 1
|
|
108
|
+
edges[pre].add(chat)
|
|
109
|
+
bfs = [i for i in chat_ids if i not in indegree]
|
|
110
|
+
chat_order = []
|
|
111
|
+
steps = len(indegree)
|
|
112
|
+
for _ in range(steps + 1):
|
|
113
|
+
if not bfs:
|
|
114
|
+
break
|
|
115
|
+
chat_order.extend(bfs)
|
|
116
|
+
nxt = []
|
|
117
|
+
for node in bfs:
|
|
118
|
+
if node in edges:
|
|
119
|
+
for course in edges[node]:
|
|
120
|
+
indegree[course] -= 1
|
|
121
|
+
if indegree[course] == 0:
|
|
122
|
+
nxt.append(course)
|
|
123
|
+
indegree.pop(course)
|
|
124
|
+
edges.pop(node)
|
|
125
|
+
bfs = nxt
|
|
126
|
+
|
|
127
|
+
if indegree:
|
|
128
|
+
return []
|
|
129
|
+
return chat_order
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
def _post_process_carryover_item(carryover_item):
|
|
133
|
+
if isinstance(carryover_item, str):
|
|
134
|
+
return carryover_item
|
|
135
|
+
elif isinstance(carryover_item, dict) and "content" in carryover_item:
|
|
136
|
+
content_value = carryover_item.get("content")
|
|
137
|
+
if isinstance(content_value, (str, list)) or content_value is None:
|
|
138
|
+
return content_str(content_value)
|
|
139
|
+
return str(content_value)
|
|
140
|
+
else:
|
|
141
|
+
return str(carryover_item)
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
def __post_carryover_processing(chat_info: dict[str, Any]) -> None:
|
|
145
|
+
iostream = IOStream.get_default()
|
|
146
|
+
|
|
147
|
+
if "message" not in chat_info:
|
|
148
|
+
warnings.warn(
|
|
149
|
+
"message is not provided in a chat_queue entry. input() will be called to get the initial message.",
|
|
150
|
+
UserWarning,
|
|
151
|
+
)
|
|
152
|
+
|
|
153
|
+
iostream.send(PostCarryoverProcessingEvent(chat_info=chat_info))
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
@export_module("autogen")
|
|
157
|
+
def initiate_chats(chat_queue: list[dict[str, Any]]) -> list[ChatResult]:
|
|
158
|
+
"""Initiate a list of chats.
|
|
159
|
+
|
|
160
|
+
Args:
|
|
161
|
+
chat_queue (List[Dict]): A list of dictionaries containing the information about the chats.\n
|
|
162
|
+
Each dictionary should contain the input arguments for
|
|
163
|
+
[`ConversableAgent.initiate_chat`](../ConversableAgent#initiate-chat).\n
|
|
164
|
+
For example:\n
|
|
165
|
+
- `"sender"` - the sender agent.\n
|
|
166
|
+
- `"recipient"` - the recipient agent.\n
|
|
167
|
+
- `"clear_history"` (bool) - whether to clear the chat history with the agent.\n
|
|
168
|
+
Default is True.\n
|
|
169
|
+
- `"silent"` (bool or None) - (Experimental) whether to print the messages in this\n
|
|
170
|
+
conversation. Default is False.\n
|
|
171
|
+
- `"cache"` (Cache or None) - the cache client to use for this conversation.\n
|
|
172
|
+
Default is None.\n
|
|
173
|
+
- `"max_turns"` (int or None) - maximum number of turns for the chat. If None, the chat\n
|
|
174
|
+
will continue until a termination condition is met. Default is None.\n
|
|
175
|
+
- `"summary_method"` (str or callable) - a string or callable specifying the method to get\n
|
|
176
|
+
a summary from the chat. Default is DEFAULT_summary_method, i.e., "last_msg".\n
|
|
177
|
+
- `"summary_args"` (dict) - a dictionary of arguments to be passed to the summary_method.\n
|
|
178
|
+
Default is {}.\n
|
|
179
|
+
- `"message"` (str, callable or None) - if None, input() will be called to get the\n
|
|
180
|
+
initial message.\n
|
|
181
|
+
- `**context` - additional context information to be passed to the chat.\n
|
|
182
|
+
- `"carryover"` - It can be used to specify the carryover information to be passed\n
|
|
183
|
+
to this chat. If provided, we will combine this carryover with the "message" content when\n
|
|
184
|
+
generating the initial chat message in `generate_init_message`.\n
|
|
185
|
+
- `"finished_chat_indexes_to_exclude_from_carryover"` - It can be used by specifying a list of indexes of the finished_chats list,\n
|
|
186
|
+
from which to exclude the summaries for carryover. If 'finished_chat_indexes_to_exclude_from_carryover' is not provided or an empty list,\n
|
|
187
|
+
then summary from all the finished chats will be taken.\n
|
|
188
|
+
|
|
189
|
+
Returns:
|
|
190
|
+
(list): a list of ChatResult objects corresponding to the finished chats in the chat_queue.\n
|
|
191
|
+
"""
|
|
192
|
+
consolidate_chat_info(chat_queue)
|
|
193
|
+
_validate_recipients(chat_queue)
|
|
194
|
+
current_chat_queue = chat_queue.copy()
|
|
195
|
+
finished_chats = []
|
|
196
|
+
while current_chat_queue:
|
|
197
|
+
chat_info = current_chat_queue.pop(0)
|
|
198
|
+
_chat_carryover = chat_info.get("carryover", [])
|
|
199
|
+
finished_chat_indexes_to_exclude_from_carryover = chat_info.get(
|
|
200
|
+
"finished_chat_indexes_to_exclude_from_carryover", []
|
|
201
|
+
)
|
|
202
|
+
|
|
203
|
+
if isinstance(_chat_carryover, str):
|
|
204
|
+
_chat_carryover = [_chat_carryover]
|
|
205
|
+
chat_info["carryover"] = _chat_carryover + [
|
|
206
|
+
r.summary for i, r in enumerate(finished_chats) if i not in finished_chat_indexes_to_exclude_from_carryover
|
|
207
|
+
]
|
|
208
|
+
|
|
209
|
+
if not chat_info.get("silent", False):
|
|
210
|
+
__post_carryover_processing(chat_info)
|
|
211
|
+
|
|
212
|
+
sender = chat_info["sender"]
|
|
213
|
+
chat_res = sender.initiate_chat(**chat_info)
|
|
214
|
+
finished_chats.append(chat_res)
|
|
215
|
+
return finished_chats
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
def __system_now_str():
|
|
219
|
+
ct = datetime.datetime.now()
|
|
220
|
+
return f" System time at {ct}. "
|
|
221
|
+
|
|
222
|
+
|
|
223
|
+
def _on_chat_future_done(chat_future: asyncio.Future, chat_id: int):
|
|
224
|
+
"""Update ChatResult when async Task for Chat is completed."""
|
|
225
|
+
logger.debug(f"Update chat {chat_id} result on task completion." + __system_now_str())
|
|
226
|
+
chat_result = chat_future.result()
|
|
227
|
+
chat_result.chat_id = chat_id
|
|
228
|
+
|
|
229
|
+
|
|
230
|
+
async def _dependent_chat_future(
|
|
231
|
+
chat_id: int, chat_info: dict[str, Any], prerequisite_chat_futures: dict[int, asyncio.Future]
|
|
232
|
+
) -> asyncio.Task:
|
|
233
|
+
"""Create an async Task for each chat."""
|
|
234
|
+
logger.debug(f"Create Task for chat {chat_id}." + __system_now_str())
|
|
235
|
+
_chat_carryover = chat_info.get("carryover", [])
|
|
236
|
+
finished_chat_indexes_to_exclude_from_carryover = chat_info.get(
|
|
237
|
+
"finished_chat_indexes_to_exclude_from_carryover", []
|
|
238
|
+
)
|
|
239
|
+
finished_chats = {}
|
|
240
|
+
for chat in prerequisite_chat_futures:
|
|
241
|
+
chat_future = prerequisite_chat_futures[chat]
|
|
242
|
+
if chat_future.cancelled():
|
|
243
|
+
raise RuntimeError(f"Chat {chat} is cancelled.")
|
|
244
|
+
|
|
245
|
+
# wait for prerequisite chat results for the new chat carryover
|
|
246
|
+
finished_chats[chat] = await chat_future
|
|
247
|
+
|
|
248
|
+
if isinstance(_chat_carryover, str):
|
|
249
|
+
_chat_carryover = [_chat_carryover]
|
|
250
|
+
data = [
|
|
251
|
+
chat_result.summary
|
|
252
|
+
for chat_id, chat_result in finished_chats.items()
|
|
253
|
+
if chat_id not in finished_chat_indexes_to_exclude_from_carryover
|
|
254
|
+
]
|
|
255
|
+
chat_info["carryover"] = _chat_carryover + data
|
|
256
|
+
if not chat_info.get("silent", False):
|
|
257
|
+
__post_carryover_processing(chat_info)
|
|
258
|
+
|
|
259
|
+
sender = chat_info["sender"]
|
|
260
|
+
chat_res_future = asyncio.create_task(sender.a_initiate_chat(**chat_info))
|
|
261
|
+
call_back_with_args = partial(_on_chat_future_done, chat_id=chat_id)
|
|
262
|
+
chat_res_future.add_done_callback(call_back_with_args)
|
|
263
|
+
logger.debug(f"Task for chat {chat_id} created." + __system_now_str())
|
|
264
|
+
return chat_res_future
|
|
265
|
+
|
|
266
|
+
|
|
267
|
+
async def a_initiate_chats(chat_queue: list[dict[str, Any]]) -> dict[int, ChatResult]:
|
|
268
|
+
"""(async) Initiate a list of chats.
|
|
269
|
+
|
|
270
|
+
Args:
|
|
271
|
+
chat_queue (List[Dict]): A list of dictionaries containing the information about the chats.
|
|
272
|
+
|
|
273
|
+
Each dictionary should contain the input arguments for
|
|
274
|
+
[`ConversableAgent.initiate_chat`](../../../ConversableAgent#initiate-chat).
|
|
275
|
+
For example:
|
|
276
|
+
- `"sender"` - the sender agent.
|
|
277
|
+
- `"recipient"` - the recipient agent.
|
|
278
|
+
- `"clear_history"` (bool) - whether to clear the chat history with the agent.
|
|
279
|
+
Default is True.
|
|
280
|
+
- `"silent"` (bool or None) - (Experimental) whether to print the messages in this
|
|
281
|
+
conversation. Default is False.
|
|
282
|
+
- `"cache"` (Cache or None) - the cache client to use for this conversation.
|
|
283
|
+
Default is None.
|
|
284
|
+
- `"max_turns"` (int or None) - maximum number of turns for the chat. If None, the chat
|
|
285
|
+
will continue until a termination condition is met. Default is None.
|
|
286
|
+
- `"summary_method"` (str or callable) - a string or callable specifying the method to get
|
|
287
|
+
a summary from the chat. Default is DEFAULT_summary_method, i.e., "last_msg".
|
|
288
|
+
- `"summary_args"` (dict) - a dictionary of arguments to be passed to the summary_method.
|
|
289
|
+
Default is {}.
|
|
290
|
+
- `"message"` (str, callable or None) - if None, input() will be called to get the
|
|
291
|
+
initial message.
|
|
292
|
+
- `**context` - additional context information to be passed to the chat.
|
|
293
|
+
- `"carryover"` - It can be used to specify the carryover information to be passed
|
|
294
|
+
to this chat. If provided, we will combine this carryover with the "message" content when
|
|
295
|
+
generating the initial chat message in `generate_init_message`.
|
|
296
|
+
- `"finished_chat_indexes_to_exclude_from_carryover"` - It can be used by specifying a list of indexes of the finished_chats list,
|
|
297
|
+
from which to exclude the summaries for carryover. If 'finished_chat_indexes_to_exclude_from_carryover' is not provided or an empty list,
|
|
298
|
+
then summary from all the finished chats will be taken.
|
|
299
|
+
|
|
300
|
+
|
|
301
|
+
Returns:
|
|
302
|
+
- (Dict): a dict of ChatId: ChatResult corresponding to the finished chats in the chat_queue.
|
|
303
|
+
"""
|
|
304
|
+
consolidate_chat_info(chat_queue)
|
|
305
|
+
_validate_recipients(chat_queue)
|
|
306
|
+
chat_book = {chat_info["chat_id"]: chat_info for chat_info in chat_queue}
|
|
307
|
+
num_chats = chat_book.keys()
|
|
308
|
+
prerequisites = __create_async_prerequisites(chat_queue)
|
|
309
|
+
chat_order_by_id = __find_async_chat_order(num_chats, prerequisites)
|
|
310
|
+
finished_chat_futures = {}
|
|
311
|
+
for chat_id in chat_order_by_id:
|
|
312
|
+
chat_info = chat_book[chat_id]
|
|
313
|
+
prerequisite_chat_ids = chat_info.get("prerequisites", [])
|
|
314
|
+
pre_chat_futures = {}
|
|
315
|
+
for pre_chat_id in prerequisite_chat_ids:
|
|
316
|
+
pre_chat_future = finished_chat_futures[pre_chat_id]
|
|
317
|
+
pre_chat_futures[pre_chat_id] = pre_chat_future
|
|
318
|
+
current_chat_future = await _dependent_chat_future(chat_id, chat_info, pre_chat_futures)
|
|
319
|
+
finished_chat_futures[chat_id] = current_chat_future
|
|
320
|
+
await asyncio.gather(*list(finished_chat_futures.values()))
|
|
321
|
+
finished_chats = {}
|
|
322
|
+
for chat in finished_chat_futures:
|
|
323
|
+
chat_result = finished_chat_futures[chat].result()
|
|
324
|
+
finished_chats[chat] = chat_result
|
|
325
|
+
return finished_chats
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
Agents for running the [AgentEval](https://docs.ag2.ai/latest/docs/blog/2023/11/20/AgentEval/) pipeline.
|
|
2
|
+
|
|
3
|
+
AgentEval is a process for evaluating a LLM-based system's performance on a given task.
|
|
4
|
+
|
|
5
|
+
When given a task to evaluate and a few example runs, the critic and subcritic agents create evaluation criteria for evaluating a system's solution. Once the criteria have been created, the quantifier agent can evaluate subsequent task solutions based on the generated criteria.
|
|
6
|
+
|
|
7
|
+
See our [blog post](https://docs.ag2.ai/blog/2024-06-21-AgentEval) for usage examples and general explanations.
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
# Copyright (c) 2023 - 2025, AG2ai, Inc., AG2ai open-source projects maintainers and core contributors
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
#
|
|
5
|
+
# Portions derived from https://github.com/microsoft/autogen are under the MIT License.
|
|
6
|
+
# SPDX-License-Identifier: MIT
|
|
7
|
+
from typing import Any, Literal
|
|
8
|
+
|
|
9
|
+
from .... import GroupChat, GroupChatManager, UserProxyAgent
|
|
10
|
+
from ....llm_config import LLMConfig
|
|
11
|
+
from .criterion import Criterion
|
|
12
|
+
from .critic_agent import CriticAgent
|
|
13
|
+
from .quantifier_agent import QuantifierAgent
|
|
14
|
+
from .subcritic_agent import SubCriticAgent
|
|
15
|
+
from .task import Task
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def generate_criteria(
|
|
19
|
+
llm_config: LLMConfig | dict[str, Any] | Literal[False] | None = None,
|
|
20
|
+
task: Task = None,
|
|
21
|
+
additional_instructions: str = "",
|
|
22
|
+
max_round=2,
|
|
23
|
+
use_subcritic: bool = False,
|
|
24
|
+
):
|
|
25
|
+
"""Creates a list of criteria for evaluating the utility of a given task.
|
|
26
|
+
|
|
27
|
+
Args:
|
|
28
|
+
llm_config (LLMConfig or dict or bool): llm inference configuration.
|
|
29
|
+
task (Task): The task to evaluate.
|
|
30
|
+
additional_instructions (str): Additional instructions for the criteria agent.
|
|
31
|
+
max_round (int): The maximum number of rounds to run the conversation.
|
|
32
|
+
use_subcritic (bool): Whether to use the subcritic agent to generate subcriteria.
|
|
33
|
+
|
|
34
|
+
Returns:
|
|
35
|
+
list: A list of Criterion objects for evaluating the utility of the given task.
|
|
36
|
+
"""
|
|
37
|
+
critic = CriticAgent(
|
|
38
|
+
system_message=CriticAgent.DEFAULT_SYSTEM_MESSAGE + "\n" + additional_instructions,
|
|
39
|
+
llm_config=llm_config,
|
|
40
|
+
)
|
|
41
|
+
|
|
42
|
+
critic_user = UserProxyAgent(
|
|
43
|
+
name="critic_user",
|
|
44
|
+
max_consecutive_auto_reply=0, # terminate without auto-reply
|
|
45
|
+
human_input_mode="NEVER",
|
|
46
|
+
code_execution_config={"use_docker": False},
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
agents = [critic_user, critic]
|
|
50
|
+
|
|
51
|
+
if use_subcritic:
|
|
52
|
+
subcritic = SubCriticAgent(
|
|
53
|
+
llm_config=llm_config,
|
|
54
|
+
)
|
|
55
|
+
agents.append(subcritic)
|
|
56
|
+
|
|
57
|
+
groupchat = GroupChat(agents=agents, messages=[], max_round=max_round, speaker_selection_method="round_robin")
|
|
58
|
+
critic_manager = GroupChatManager(groupchat=groupchat, llm_config=llm_config)
|
|
59
|
+
|
|
60
|
+
critic_user.initiate_chat(critic_manager, message=task.get_sys_message())
|
|
61
|
+
criteria = critic_user.last_message()
|
|
62
|
+
content = criteria["content"]
|
|
63
|
+
# need to strip out any extra code around the returned json
|
|
64
|
+
content = content[content.find("[") : content.rfind("]") + 1]
|
|
65
|
+
criteria = Criterion.parse_json_str(content)
|
|
66
|
+
return criteria
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def quantify_criteria(
|
|
70
|
+
llm_config: LLMConfig | dict[str, Any] | Literal[False] | None = None,
|
|
71
|
+
criteria: list[Criterion] = None,
|
|
72
|
+
task: Task = None,
|
|
73
|
+
test_case: str = "",
|
|
74
|
+
ground_truth: str = "",
|
|
75
|
+
):
|
|
76
|
+
"""Quantifies the performance of a system using the provided criteria.
|
|
77
|
+
|
|
78
|
+
Args:
|
|
79
|
+
llm_config (LLMConfig or dict or bool): llm inference configuration.
|
|
80
|
+
criteria ([Criterion]): A list of criteria for evaluating the utility of a given task.
|
|
81
|
+
task (Task): The task to evaluate.
|
|
82
|
+
test_case (str): The test case to evaluate.
|
|
83
|
+
ground_truth (str): The ground truth for the test case.
|
|
84
|
+
|
|
85
|
+
Returns:
|
|
86
|
+
dict: A dictionary where the keys are the criteria and the values are the assessed performance based on accepted values for each criteria.
|
|
87
|
+
"""
|
|
88
|
+
quantifier = QuantifierAgent(
|
|
89
|
+
llm_config=llm_config,
|
|
90
|
+
)
|
|
91
|
+
|
|
92
|
+
quantifier_user = UserProxyAgent(
|
|
93
|
+
name="quantifier_user",
|
|
94
|
+
max_consecutive_auto_reply=0, # terminate without auto-reply
|
|
95
|
+
human_input_mode="NEVER",
|
|
96
|
+
code_execution_config={"use_docker": False},
|
|
97
|
+
)
|
|
98
|
+
|
|
99
|
+
quantifier_user.initiate_chat(
|
|
100
|
+
quantifier,
|
|
101
|
+
message=task.get_sys_message()
|
|
102
|
+
+ "Evaluation dictionary: "
|
|
103
|
+
+ Criterion.write_json(criteria)
|
|
104
|
+
+ "actual test case to evaluate: "
|
|
105
|
+
+ test_case,
|
|
106
|
+
)
|
|
107
|
+
quantified_results = quantifier_user.last_message()
|
|
108
|
+
return {"actual_success": ground_truth, "estimated_performance": quantified_results["content"]}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# Copyright (c) 2023 - 2025, AG2ai, Inc., AG2ai open-source projects maintainers and core contributors
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
#
|
|
5
|
+
# Portions derived from https://github.com/microsoft/autogen are under the MIT License.
|
|
6
|
+
# SPDX-License-Identifier: MIT
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
import json
|
|
10
|
+
|
|
11
|
+
from pydantic import BaseModel
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class Criterion(BaseModel):
|
|
15
|
+
"""A class that represents a criterion for agent evaluation."""
|
|
16
|
+
|
|
17
|
+
name: str
|
|
18
|
+
description: str
|
|
19
|
+
accepted_values: list[str]
|
|
20
|
+
sub_criteria: list[Criterion] = []
|
|
21
|
+
|
|
22
|
+
@staticmethod
|
|
23
|
+
def parse_json_str(criteria: str):
|
|
24
|
+
"""Create a list of Criterion objects from a json string.
|
|
25
|
+
|
|
26
|
+
Args:
|
|
27
|
+
criteria (str): Json string that represents the criteria
|
|
28
|
+
returns:
|
|
29
|
+
[Criterion]: A list of Criterion objects that represents the json criteria information.
|
|
30
|
+
"""
|
|
31
|
+
return [Criterion(**crit) for crit in json.loads(criteria)]
|
|
32
|
+
|
|
33
|
+
@staticmethod
|
|
34
|
+
def write_json(criteria):
|
|
35
|
+
"""Create a json string from a list of Criterion objects.
|
|
36
|
+
|
|
37
|
+
Args:
|
|
38
|
+
criteria ([Criterion]): A list of Criterion objects.
|
|
39
|
+
|
|
40
|
+
Returns:
|
|
41
|
+
str: A json string that represents the list of Criterion objects.
|
|
42
|
+
"""
|
|
43
|
+
return json.dumps([crit.model_dump() for crit in criteria], indent=2)
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# Copyright (c) 2023 - 2025, AG2ai, Inc., AG2ai open-source projects maintainers and core contributors
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
#
|
|
5
|
+
# Portions derived from https://github.com/microsoft/autogen are under the MIT License.
|
|
6
|
+
# SPDX-License-Identifier: MIT
|
|
7
|
+
from typing import Any
|
|
8
|
+
|
|
9
|
+
from ...conversable_agent import ConversableAgent
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class CriticAgent(ConversableAgent):
|
|
13
|
+
"""An agent for creating list of criteria for evaluating the utility of a given task."""
|
|
14
|
+
|
|
15
|
+
DEFAULT_SYSTEM_MESSAGE = """You are a helpful assistant. You suggest criteria for evaluating different tasks. They should be distinguishable, quantifiable and not redundant.
|
|
16
|
+
Convert the evaluation criteria into a list where each item is a criteria which consists of the following dictionary as follows
|
|
17
|
+
{"name": name of the criterion, "description": criteria description , "accepted_values": possible accepted inputs for this key}
|
|
18
|
+
Make sure "accepted_values" include the acceptable inputs for each key that are fine-grained and preferably multi-graded levels and "description" includes the criterion description.
|
|
19
|
+
Output just the criteria string you have created, no code.
|
|
20
|
+
"""
|
|
21
|
+
|
|
22
|
+
DEFAULT_DESCRIPTION = "An AI agent for creating list criteria for evaluating the utility of a given task."
|
|
23
|
+
|
|
24
|
+
def __init__(
|
|
25
|
+
self,
|
|
26
|
+
name="critic",
|
|
27
|
+
system_message: str | None = DEFAULT_SYSTEM_MESSAGE,
|
|
28
|
+
description: str | None = DEFAULT_DESCRIPTION,
|
|
29
|
+
**kwargs: Any,
|
|
30
|
+
):
|
|
31
|
+
"""Args:
|
|
32
|
+
name (str): agent name.
|
|
33
|
+
system_message (str): system message for the ChatCompletion inference.
|
|
34
|
+
Please override this attribute if you want to reprogram the agent.
|
|
35
|
+
description (str): The description of the agent.
|
|
36
|
+
**kwargs (dict): Please refer to other kwargs in
|
|
37
|
+
[ConversableAgent](/docs/api-reference/autogen/ConversableAgent#conversableagent).
|
|
38
|
+
"""
|
|
39
|
+
super().__init__(
|
|
40
|
+
name=name,
|
|
41
|
+
system_message=system_message,
|
|
42
|
+
description=description,
|
|
43
|
+
**kwargs,
|
|
44
|
+
)
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# Copyright (c) 2023 - 2025, AG2ai, Inc., AG2ai open-source projects maintainers and core contributors
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
#
|
|
5
|
+
# Portions derived from https://github.com/microsoft/autogen are under the MIT License.
|
|
6
|
+
# SPDX-License-Identifier: MIT
|
|
7
|
+
from typing import Any
|
|
8
|
+
|
|
9
|
+
from ...conversable_agent import ConversableAgent
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class QuantifierAgent(ConversableAgent):
|
|
13
|
+
"""An agent for quantifying the performance of a system using the provided criteria."""
|
|
14
|
+
|
|
15
|
+
DEFAULT_SYSTEM_MESSAGE = """"You are a helpful assistant. You quantify the output of different tasks based on the given criteria.
|
|
16
|
+
The criterion is given in a json list format where each element is a distinct criteria.
|
|
17
|
+
The each element is a dictionary as follows {"name": name of the criterion, "description": criteria description , "accepted_values": possible accepted inputs for this key}
|
|
18
|
+
You are going to quantify each of the crieria for a given task based on the task description.
|
|
19
|
+
Return a dictionary where the keys are the criteria and the values are the assessed performance based on accepted values for each criteria.
|
|
20
|
+
Return only the dictionary, no code."""
|
|
21
|
+
|
|
22
|
+
DEFAULT_DESCRIPTION = "An AI agent for quantifing the performance of a system using the provided criteria."
|
|
23
|
+
|
|
24
|
+
def __init__(
|
|
25
|
+
self,
|
|
26
|
+
name="quantifier",
|
|
27
|
+
system_message: str | None = DEFAULT_SYSTEM_MESSAGE,
|
|
28
|
+
description: str | None = DEFAULT_DESCRIPTION,
|
|
29
|
+
**kwargs: Any,
|
|
30
|
+
):
|
|
31
|
+
"""Args:
|
|
32
|
+
name (str): agent name.
|
|
33
|
+
system_message (str): system message for the ChatCompletion inference.
|
|
34
|
+
Please override this attribute if you want to reprogram the agent.
|
|
35
|
+
description (str): The description of the agent.
|
|
36
|
+
**kwargs (dict): Please refer to other kwargs in
|
|
37
|
+
[ConversableAgent](/docs/api-reference/autogen/ConversableAgent#conversableagent).
|
|
38
|
+
"""
|
|
39
|
+
super().__init__(name=name, system_message=system_message, description=description, **kwargs)
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# Copyright (c) 2023 - 2025, AG2ai, Inc., AG2ai open-source projects maintainers and core contributors
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
#
|
|
5
|
+
# Portions derived from https://github.com/microsoft/autogen are under the MIT License.
|
|
6
|
+
# SPDX-License-Identifier: MIT
|
|
7
|
+
from typing import Any
|
|
8
|
+
|
|
9
|
+
from ...conversable_agent import ConversableAgent
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class SubCriticAgent(ConversableAgent):
|
|
13
|
+
"""An agent for creating subcriteria from a given list of criteria for evaluating the utility of a given task."""
|
|
14
|
+
|
|
15
|
+
DEFAULT_SYSTEM_MESSAGE = """You are a helpful assistant to the critic agent. You suggest sub criteria for evaluating different tasks based on the criteria provided by the critic agent (if you feel it is needed).
|
|
16
|
+
They should be distinguishable, quantifiable, and related to the overall theme of the critic's provided criteria.
|
|
17
|
+
You operate by taking in the description of the criteria. You then create a new key called sub criteria where you provide the sub criteria for the given criteria.
|
|
18
|
+
The value of the sub_criteria is a dictionary where the keys are the subcriteria and each value is as follows {"description": sub criteria description , "accepted_values": possible accepted inputs for this key}
|
|
19
|
+
Do this for each criteria provided by the critic (removing the criteria's accepted values). "accepted_values" include the acceptable inputs for each key that are fine-grained and preferably multi-graded levels. "description" includes the criterion description.
|
|
20
|
+
Once you have created the sub criteria for the given criteria, you return the json (make sure to include the contents of the critic's dictionary in the final dictionary as well).
|
|
21
|
+
Make sure to return a valid json and no code"""
|
|
22
|
+
|
|
23
|
+
DEFAULT_DESCRIPTION = "An AI agent for creating subcriteria from a given list of criteria."
|
|
24
|
+
|
|
25
|
+
def __init__(
|
|
26
|
+
self,
|
|
27
|
+
name="subcritic",
|
|
28
|
+
system_message: str | None = DEFAULT_SYSTEM_MESSAGE,
|
|
29
|
+
description: str | None = DEFAULT_DESCRIPTION,
|
|
30
|
+
**kwargs: Any,
|
|
31
|
+
):
|
|
32
|
+
"""Args:
|
|
33
|
+
name (str): agent name.
|
|
34
|
+
system_message (str): system message for the ChatCompletion inference.
|
|
35
|
+
Please override this attribute if you want to reprogram the agent.
|
|
36
|
+
description (str): The description of the agent.
|
|
37
|
+
**kwargs (dict): Please refer to other kwargs in
|
|
38
|
+
[ConversableAgent](/docs/api-reference/autogen/ConversableAgent#conversableagent).
|
|
39
|
+
"""
|
|
40
|
+
super().__init__(
|
|
41
|
+
name=name,
|
|
42
|
+
system_message=system_message,
|
|
43
|
+
description=description,
|
|
44
|
+
**kwargs,
|
|
45
|
+
)
|
|
@@ -0,0 +1,42 @@
|
|
|
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 json
|
|
8
|
+
|
|
9
|
+
from pydantic import BaseModel
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class Task(BaseModel):
|
|
13
|
+
"""Class representing a task for agent completion, includes example agent execution for criteria generation."""
|
|
14
|
+
|
|
15
|
+
name: str
|
|
16
|
+
description: str
|
|
17
|
+
successful_response: str
|
|
18
|
+
failed_response: str
|
|
19
|
+
|
|
20
|
+
def get_sys_message(self):
|
|
21
|
+
return f"""Task: {self.name}.
|
|
22
|
+
Task description: {self.description}
|
|
23
|
+
Task successful example: {self.successful_response}
|
|
24
|
+
Task failed example: {self.failed_response}
|
|
25
|
+
"""
|
|
26
|
+
|
|
27
|
+
@staticmethod
|
|
28
|
+
def parse_json_str(task: str) -> "Task":
|
|
29
|
+
"""Create a Task object from a json object.
|
|
30
|
+
|
|
31
|
+
Args:
|
|
32
|
+
task (str): A json string that represents the task information.
|
|
33
|
+
|
|
34
|
+
Returns:
|
|
35
|
+
Task: A Task object that represents the json task information.
|
|
36
|
+
"""
|
|
37
|
+
json_data = json.loads(task)
|
|
38
|
+
name = json_data.get("name")
|
|
39
|
+
description = json_data.get("description")
|
|
40
|
+
successful_response = json_data.get("successful_response")
|
|
41
|
+
failed_response = json_data.get("failed_response")
|
|
42
|
+
return Task(name, description, successful_response, failed_response)
|