├── .coveragerc ├── .devcontainer ├── README.md ├── devcontainer.json ├── docker-compose.yaml └── postCreateCommand.sh ├── .dockerignore ├── .gitattributes ├── .github ├── ISSUE_TEMPLATE │ ├── config.yaml │ ├── request_new_features.md │ └── show_me_the_bug.md ├── PULL_REQUEST_TEMPLATE.md └── workflows │ ├── build-package.yaml │ ├── fulltest.yaml │ ├── pre-commit.yaml │ ├── stale.yaml │ └── unittest.yaml ├── .gitignore ├── .pre-commit-config.yaml ├── Dockerfile ├── LICENSE ├── MANIFEST.in ├── README.md ├── SECURITY.md ├── config ├── config2.example.yaml ├── config2.yaml ├── examples │ ├── anthropic-claude-3-5-sonnet.yaml │ ├── aws-bedrock.yaml │ ├── google-gemini.yaml │ ├── groq-llama3-70b.yaml │ ├── huoshan_ark.yaml │ ├── openai-gpt-3.5-turbo.yaml │ ├── openai-gpt-4-turbo.yaml │ ├── openrouter-llama3-70b-instruct.yaml │ └── spark_lite.yaml ├── puppeteer-config.json └── vault.example.yaml ├── docs ├── .agent-store-config.yaml.example ├── .pylintrc ├── .well-known │ ├── ai-plugin.json │ ├── metagpt_oas3_api.yaml │ ├── openapi.yaml │ └── skills.yaml ├── ACADEMIC_WORK.md ├── FAQ-EN.md ├── NEWS.md ├── README_CN.md ├── README_FR.md ├── README_JA.md ├── ROADMAP.md ├── install │ ├── cli_install.md │ ├── cli_install_cn.md │ ├── docker_install.md │ └── docker_install_cn.md ├── resources │ ├── MetaGPT-new-log-v2.png │ ├── MetaGPT-new-log.png │ ├── aflow │ │ ├── AFLOW-experiment.jpg │ │ ├── AFLOW-method.jpg │ │ └── AFLOW-performance.jpg │ ├── software_company_cd.jpeg │ ├── software_company_sd.jpeg │ ├── spo │ │ ├── SPO-closed_task_figure.png │ │ ├── SPO-closed_task_table.png │ │ ├── SPO-logo.png │ │ ├── SPO-method.png │ │ └── SPO-open_ended_task_figure.png │ └── workspace │ │ ├── content_rec_sys │ │ └── resources │ │ │ ├── competitive_analysis.pdf │ │ │ ├── competitive_analysis.png │ │ │ ├── competitive_analysis.svg │ │ │ ├── data_api_design.pdf │ │ │ ├── data_api_design.png │ │ │ ├── data_api_design.svg │ │ │ ├── seq_flow.pdf │ │ │ ├── seq_flow.png │ │ │ └── seq_flow.svg │ │ ├── llmops_framework │ │ └── resources │ │ │ ├── competitive_analysis.pdf │ │ │ ├── competitive_analysis.png │ │ │ ├── competitive_analysis.svg │ │ │ ├── data_api_design.pdf │ │ │ ├── data_api_design.png │ │ │ ├── data_api_design.svg │ │ │ ├── seq_flow.pdf │ │ │ ├── seq_flow.png │ │ │ └── seq_flow.svg │ │ ├── match3_puzzle_game │ │ └── resources │ │ │ ├── competitive_analysis.pdf │ │ │ ├── competitive_analysis.png │ │ │ ├── competitive_analysis.svg │ │ │ ├── data_api_design.pdf │ │ │ ├── data_api_design.png │ │ │ ├── data_api_design.svg │ │ │ ├── seq_flow.pdf │ │ │ ├── seq_flow.png │ │ │ └── seq_flow.svg │ │ ├── minimalist_pomodoro_timer │ │ └── resources │ │ │ ├── competitive_analysis.pdf │ │ │ ├── competitive_analysis.png │ │ │ ├── competitive_analysis.svg │ │ │ ├── data_api_design.pdf │ │ │ ├── data_api_design.png │ │ │ ├── data_api_design.svg │ │ │ ├── seq_flow.pdf │ │ │ ├── seq_flow.png │ │ │ └── seq_flow.svg │ │ ├── pyrogue │ │ └── resources │ │ │ ├── competitive_analysis.pdf │ │ │ ├── competitive_analysis.png │ │ │ ├── competitive_analysis.svg │ │ │ ├── data_api_design.pdf │ │ │ ├── data_api_design.png │ │ │ ├── data_api_design.svg │ │ │ ├── seq_flow.pdf │ │ │ ├── seq_flow.png │ │ │ └── seq_flow.svg │ │ └── search_algorithm_framework │ │ └── resources │ │ ├── competitive_analysis.pdf │ │ ├── competitive_analysis.png │ │ ├── competitive_analysis.svg │ │ ├── data_api_design.pdf │ │ ├── data_api_design.png │ │ ├── data_api_design.svg │ │ ├── seq_flow.pdf │ │ ├── seq_flow.png │ │ └── seq_flow.svg ├── scripts │ ├── coverage.sh │ └── get_all_classes_and_funcs.sh └── tutorial │ ├── usage.md │ └── usage_cn.md ├── examples ├── aflow │ ├── README.md │ ├── config2.example.yaml │ └── optimize.py ├── agent_creator.py ├── android_assistant │ ├── requirements.txt │ └── run_assistant.py ├── build_customized_agent.py ├── build_customized_multi_agents.py ├── cr.py ├── dalle_gpt4v_agent.py ├── data │ ├── di │ │ ├── dog.jpg │ │ └── receipt_shopping.jpg │ ├── exp_pool │ │ ├── engineer_exps.json │ │ └── team_leader_exps.json │ ├── omniparse │ │ ├── test01.docx │ │ ├── test02.pdf │ │ ├── test03.mp4 │ │ └── test04.mp3 │ ├── rag │ │ ├── travel.txt │ │ └── writer.txt │ ├── rag_bm │ │ ├── RGB_En │ │ │ ├── answer.json │ │ │ └── documents.txt │ │ ├── dataset_info.json │ │ ├── simplified_CRUD │ │ │ ├── answer.json │ │ │ └── documents.txt │ │ └── simplified_RGB │ │ │ ├── answer.json │ │ │ └── documents.txt │ └── search_kb │ │ ├── example.json │ │ └── example.xlsx ├── debate.py ├── debate_simple.py ├── di │ ├── InfiAgent-DABench │ │ ├── DABench.py │ │ ├── README.md │ │ ├── run_InfiAgent-DABench.py │ │ ├── run_InfiAgent-DABench_all.py │ │ └── run_InfiAgent-DABench_single.py │ ├── README.md │ ├── arxiv_reader.py │ ├── atomization_capacity_plan.py │ ├── automated_planning_of_tasks.py │ ├── crawl_webpage.py │ ├── custom_tool.py │ ├── data_analyst_write_code.py │ ├── data_visualization.py │ ├── email_summary.py │ ├── fix_github_issue.py │ ├── imitate_webpage.py │ ├── interacting_with_human.py │ ├── machine_learning.py │ ├── machine_learning_with_tools.py │ ├── ocr_receipt.py │ ├── requirements_prompt.py │ ├── rm_image_background.py │ ├── run_flask.py │ ├── run_ml_benchmark.py │ ├── run_open_ended_tasks.py │ ├── sd_tool_usage.py │ ├── software_company.py │ ├── solve_math_problems.py │ ├── use_browser.py │ └── use_github_repo.py ├── exp_pool │ ├── README.md │ ├── decorator.py │ ├── init_exp_pool.py │ ├── load_exps_from_log.py │ ├── manager.py │ └── scorer.py ├── hello_world.py ├── invoice_ocr.py ├── llm_vision.py ├── mgx_write_project_framework.py ├── ping.py ├── rag │ ├── omniparse.py │ ├── rag_bm.py │ ├── rag_pipeline.py │ └── rag_search.py ├── research.py ├── search_enhanced_qa.py ├── search_google.py ├── search_with_specific_engine.py ├── sela │ └── README.md ├── serialize_model.py ├── spo │ ├── README.md │ ├── config2.example.yaml │ └── optimize.py ├── stanford_town │ ├── __init__.py │ ├── requirements.txt │ ├── run_st_game.py │ └── storage │ │ ├── .gitignore │ │ └── base_the_ville_isabella_maria_klaus │ │ ├── environment │ │ └── 0.json │ │ ├── personas │ │ ├── Isabella Rodriguez │ │ │ └── bootstrap_memory │ │ │ │ ├── associative_memory │ │ │ │ ├── embeddings.json │ │ │ │ ├── kw_strength.json │ │ │ │ └── nodes.json │ │ │ │ ├── scratch.json │ │ │ │ └── spatial_memory.json │ │ ├── Klaus Mueller │ │ │ └── bootstrap_memory │ │ │ │ ├── associative_memory │ │ │ │ ├── embeddings.json │ │ │ │ ├── kw_strength.json │ │ │ │ └── nodes.json │ │ │ │ ├── scratch.json │ │ │ │ └── spatial_memory.json │ │ └── Maria Lopez │ │ │ └── bootstrap_memory │ │ │ ├── associative_memory │ │ │ ├── embeddings.json │ │ │ ├── kw_strength.json │ │ │ └── nodes.json │ │ │ ├── scratch.json │ │ │ └── spatial_memory.json │ │ └── reverie │ │ └── meta.json ├── stream_output_via_api.py ├── ui_with_chainlit │ ├── .gitignore │ ├── README.md │ ├── __init__.py │ ├── app.py │ ├── init_setup.py │ └── public │ │ ├── 2048.jpg │ │ ├── MetaGPT-new-log.jpg │ │ └── blackjack.jpg ├── use_off_the_shelf_agent.py ├── werewolf_game │ ├── evals │ │ ├── eval.py │ │ └── utils.py │ └── start_game.py ├── write_design.py ├── write_game_code.py ├── write_novel.py └── write_tutorial.py ├── metagpt ├── __init__.py ├── _compat.py ├── actions │ ├── __init__.py │ ├── action.py │ ├── action_graph.py │ ├── action_node.py │ ├── action_outcls_registry.py │ ├── action_output.py │ ├── add_requirement.py │ ├── analyze_requirements.py │ ├── debug_error.py │ ├── design_api.py │ ├── design_api_an.py │ ├── design_api_review.py │ ├── di │ │ ├── __init__.py │ │ ├── ask_review.py │ │ ├── execute_nb_code.py │ │ ├── run_command.py │ │ ├── write_analysis_code.py │ │ └── write_plan.py │ ├── execute_task.py │ ├── extract_readme.py │ ├── fix_bug.py │ ├── generate_questions.py │ ├── import_repo.py │ ├── invoice_ocr.py │ ├── prepare_documents.py │ ├── prepare_interview.py │ ├── project_management.py │ ├── project_management_an.py │ ├── rebuild_class_view.py │ ├── rebuild_sequence_view.py │ ├── requirement_analysis │ │ ├── __init__.py │ │ ├── evaluate_action.py │ │ ├── framework │ │ │ ├── __init__.py │ │ │ ├── evaluate_framework.py │ │ │ └── write_framework.py │ │ ├── requirement │ │ │ ├── __init__.py │ │ │ └── pic2txt.py │ │ └── trd │ │ │ ├── __init__.py │ │ │ ├── compress_external_interfaces.py │ │ │ ├── detect_interaction.py │ │ │ ├── evaluate_trd.py │ │ │ └── write_trd.py │ ├── research.py │ ├── run_code.py │ ├── search_and_summarize.py │ ├── search_enhanced_qa.py │ ├── skill_action.py │ ├── summarize_code.py │ ├── talk_action.py │ ├── write_code.py │ ├── write_code_an_draft.py │ ├── write_code_plan_and_change_an.py │ ├── write_code_review.py │ ├── write_docstring.py │ ├── write_prd.py │ ├── write_prd_an.py │ ├── write_prd_review.py │ ├── write_review.py │ ├── write_teaching_plan.py │ ├── write_test.py │ └── write_tutorial.py ├── base │ ├── __init__.py │ ├── base_env.py │ ├── base_env_space.py │ ├── base_role.py │ └── base_serialization.py ├── config2.py ├── configs │ ├── __init__.py │ ├── browser_config.py │ ├── compress_msg_config.py │ ├── embedding_config.py │ ├── exp_pool_config.py │ ├── llm_config.py │ ├── mermaid_config.py │ ├── models_config.py │ ├── omniparse_config.py │ ├── redis_config.py │ ├── role_custom_config.py │ ├── role_zero_config.py │ ├── s3_config.py │ ├── search_config.py │ └── workspace_config.py ├── const.py ├── context.py ├── context_mixin.py ├── document.py ├── document_store │ ├── __init__.py │ ├── base_store.py │ ├── chromadb_store.py │ ├── faiss_store.py │ ├── lancedb_store.py │ ├── milvus_store.py │ └── qdrant_store.py ├── environment │ ├── README.md │ ├── __init__.py │ ├── android │ │ ├── __init__.py │ │ ├── android_env.py │ │ ├── android_ext_env.py │ │ ├── const.py │ │ ├── env_space.py │ │ ├── grounding_dino_config.py │ │ └── text_icon_localization.py │ ├── api │ │ ├── __init__.py │ │ └── env_api.py │ ├── base_env.py │ ├── mgx │ │ ├── __init__.py │ │ └── mgx_env.py │ ├── minecraft │ │ ├── __init__.py │ │ ├── const.py │ │ ├── minecraft_env.py │ │ ├── minecraft_ext_env.py │ │ ├── mineflayer │ │ │ ├── .gitignore │ │ │ ├── .prettierignore │ │ │ ├── .prettierrc.json │ │ │ ├── index.js │ │ │ ├── lib │ │ │ │ ├── observation │ │ │ │ │ ├── base.js │ │ │ │ │ ├── chests.js │ │ │ │ │ ├── inventory.js │ │ │ │ │ ├── onChat.js │ │ │ │ │ ├── onError.js │ │ │ │ │ ├── onSave.js │ │ │ │ │ ├── status.js │ │ │ │ │ └── voxels.js │ │ │ │ ├── skillLoader.js │ │ │ │ └── utils.js │ │ │ ├── mineflayer-collectblock │ │ │ │ ├── .gitignore │ │ │ │ ├── LICENSE │ │ │ │ ├── README.md │ │ │ │ ├── _config.yml │ │ │ │ ├── docs │ │ │ │ │ └── api.md │ │ │ │ ├── examples │ │ │ │ │ ├── collector.js │ │ │ │ │ ├── oreMiner.js │ │ │ │ │ └── storageBot.js │ │ │ │ ├── package.json │ │ │ │ ├── src │ │ │ │ │ ├── BlockVeins.ts │ │ │ │ │ ├── CollectBlock.ts │ │ │ │ │ ├── Inventory.ts │ │ │ │ │ ├── Targets.ts │ │ │ │ │ ├── TaskQueue.ts │ │ │ │ │ ├── TemporarySubscriber.ts │ │ │ │ │ ├── Util.ts │ │ │ │ │ └── index.ts │ │ │ │ └── tsconfig.json │ │ │ └── package.json │ │ └── process_monitor.py │ ├── software │ │ ├── __init__.py │ │ └── software_env.py │ ├── stanford_town │ │ ├── __init__.py │ │ ├── env_space.py │ │ ├── stanford_town_env.py │ │ └── stanford_town_ext_env.py │ └── werewolf │ │ ├── __init__.py │ │ ├── const.py │ │ ├── env_space.py │ │ ├── werewolf_env.py │ │ └── werewolf_ext_env.py ├── exp_pool │ ├── __init__.py │ ├── context_builders │ │ ├── __init__.py │ │ ├── action_node.py │ │ ├── base.py │ │ ├── role_zero.py │ │ └── simple.py │ ├── decorator.py │ ├── manager.py │ ├── perfect_judges │ │ ├── __init__.py │ │ ├── base.py │ │ └── simple.py │ ├── schema.py │ ├── scorers │ │ ├── __init__.py │ │ ├── base.py │ │ └── simple.py │ └── serializers │ │ ├── __init__.py │ │ ├── action_node.py │ │ ├── base.py │ │ ├── role_zero.py │ │ └── simple.py ├── ext │ ├── __init__.py │ ├── aflow │ │ ├── benchmark │ │ │ ├── README.md │ │ │ ├── benchmark.py │ │ │ ├── drop.py │ │ │ ├── gsm8k.py │ │ │ ├── hotpotqa.py │ │ │ ├── humaneval.py │ │ │ ├── math.py │ │ │ ├── mbpp.py │ │ │ └── utils.py │ │ ├── data │ │ │ └── download_data.py │ │ └── scripts │ │ │ ├── evaluator.py │ │ │ ├── interface.py │ │ │ ├── operator.py │ │ │ ├── operator_an.py │ │ │ ├── optimized │ │ │ └── __init__.py │ │ │ ├── optimizer.py │ │ │ ├── optimizer_utils │ │ │ ├── convergence_utils.py │ │ │ ├── data_utils.py │ │ │ ├── evaluation_utils.py │ │ │ ├── experience_utils.py │ │ │ └── graph_utils.py │ │ │ ├── prompts │ │ │ ├── optimize_prompt.py │ │ │ └── prompt.py │ │ │ ├── utils.py │ │ │ └── workflow.py │ ├── android_assistant │ │ ├── README.md │ │ ├── README_CN.md │ │ ├── __init__.py │ │ ├── actions │ │ │ ├── __init__.py │ │ │ ├── manual_record.py │ │ │ ├── parse_record.py │ │ │ ├── parse_record_an.py │ │ │ ├── screenshot_parse.py │ │ │ ├── screenshot_parse_an.py │ │ │ ├── self_learn_and_reflect.py │ │ │ └── self_learn_reflect_an.py │ │ ├── prompts │ │ │ ├── __init__.py │ │ │ ├── assistant_prompt.py │ │ │ └── operation_prompt.py │ │ ├── roles │ │ │ ├── __init__.py │ │ │ └── android_assistant.py │ │ └── utils │ │ │ ├── __init__.py │ │ │ ├── schema.py │ │ │ └── utils.py │ ├── cr │ │ ├── __init__.py │ │ ├── actions │ │ │ ├── __init__.py │ │ │ ├── code_review.py │ │ │ └── modify_code.py │ │ ├── points.json │ │ ├── points_cn.json │ │ └── utils │ │ │ ├── __init__.py │ │ │ ├── cleaner.py │ │ │ └── schema.py │ ├── sela │ │ ├── README.md │ │ ├── data.yaml │ │ ├── data │ │ │ ├── custom_task.py │ │ │ ├── dataset.py │ │ │ └── hf_data.py │ │ ├── datasets.yaml │ │ ├── evaluation │ │ │ ├── evaluation.py │ │ │ └── visualize_mcts.py │ │ ├── experimenter.py │ │ ├── insights │ │ │ ├── fixed_insights.json │ │ │ ├── instruction_generator.py │ │ │ └── solution_designer.py │ │ ├── requirements.txt │ │ ├── run_experiment.py │ │ ├── runner │ │ │ ├── README.md │ │ │ ├── __init__.py │ │ │ ├── aide.py │ │ │ ├── autogluon.py │ │ │ ├── autosklearn.py │ │ │ ├── custom.py │ │ │ ├── mcts.py │ │ │ ├── mle_bench │ │ │ │ └── instructions.py │ │ │ ├── random_search.py │ │ │ └── runner.py │ │ ├── scripts │ │ │ ├── run_cls.sh │ │ │ ├── run_cls_mod.sh │ │ │ ├── run_reg.sh │ │ │ └── visualize_experiment.py │ │ ├── search │ │ │ ├── search_algorithm.py │ │ │ └── tree_search.py │ │ └── utils.py │ ├── spo │ │ ├── __init__.py │ │ ├── app.py │ │ ├── components │ │ │ ├── __init__.py │ │ │ ├── evaluator.py │ │ │ └── optimizer.py │ │ ├── prompts │ │ │ ├── evaluate_prompt.py │ │ │ └── optimize_prompt.py │ │ ├── settings │ │ │ ├── Navigate.yaml │ │ │ └── Poem.yaml │ │ └── utils │ │ │ ├── __init__.py │ │ │ ├── data_utils.py │ │ │ ├── evaluation_utils.py │ │ │ ├── llm_client.py │ │ │ ├── load.py │ │ │ └── prompt_utils.py │ ├── stanford_town │ │ ├── README.md │ │ ├── README_CN.md │ │ ├── __init__.py │ │ ├── actions │ │ │ ├── __init__.py │ │ │ ├── agent_chat_sum_rel.py │ │ │ ├── decide_to_talk.py │ │ │ ├── dummy_action.py │ │ │ ├── gen_action_details.py │ │ │ ├── gen_daily_schedule.py │ │ │ ├── gen_hourly_schedule.py │ │ │ ├── gen_iter_chat_utt.py │ │ │ ├── inner_voice_action.py │ │ │ ├── new_decomp_schedule.py │ │ │ ├── run_reflect_action.py │ │ │ ├── st_action.py │ │ │ ├── summarize_conv.py │ │ │ ├── task_decomp.py │ │ │ └── wake_up.py │ │ ├── memory │ │ │ ├── __init__.py │ │ │ ├── agent_memory.py │ │ │ ├── retrieve.py │ │ │ ├── scratch.py │ │ │ └── spatial_memory.py │ │ ├── plan │ │ │ ├── __init__.py │ │ │ ├── converse.py │ │ │ └── st_plan.py │ │ ├── prompts │ │ │ ├── __init__.py │ │ │ ├── action_location_object_vMar11.txt │ │ │ ├── action_location_sector_v1.txt │ │ │ ├── action_object_v2.txt │ │ │ ├── daily_planning_v6.txt │ │ │ ├── decide_to_talk_v2.txt │ │ │ ├── generate_event_triple_v1.txt │ │ │ ├── generate_focal_pt_v1.txt │ │ │ ├── generate_hourly_schedule_v2.txt │ │ │ ├── generate_obj_event_v1.txt │ │ │ ├── generate_pronunciatio_v1.txt │ │ │ ├── insight_and_evidence_v1.txt │ │ │ ├── iterative_convo_v1.txt │ │ │ ├── memo_on_convo_v1.txt │ │ │ ├── new_decomp_schedule_v1.txt │ │ │ ├── planning_thought_on_convo_v1.txt │ │ │ ├── poignancy_action_v1.txt │ │ │ ├── poignancy_chat_v1.txt │ │ │ ├── poignancy_event_v1.txt │ │ │ ├── poignancy_thought_v1.txt │ │ │ ├── summarize_chat_relationship_v2.txt │ │ │ ├── summarize_conversation_v1.txt │ │ │ ├── task_decomp_v3.txt │ │ │ ├── wake_up_hour_v1.txt │ │ │ └── whisper_inner_thought_v1.txt │ │ ├── reflect │ │ │ ├── __init__.py │ │ │ └── reflect.py │ │ ├── roles │ │ │ ├── __init__.py │ │ │ └── st_role.py │ │ ├── stanford_town.py │ │ ├── static_dirs │ │ │ └── assets │ │ │ │ └── the_ville │ │ │ │ ├── agent_history_init_n25.csv │ │ │ │ ├── agent_history_init_n3.csv │ │ │ │ └── matrix │ │ │ │ ├── maze │ │ │ │ ├── arena_maze.csv │ │ │ │ ├── collision_maze.csv │ │ │ │ ├── game_object_maze.csv │ │ │ │ ├── sector_maze.csv │ │ │ │ └── spawning_location_maze.csv │ │ │ │ ├── maze_meta_info.json │ │ │ │ └── special_blocks │ │ │ │ ├── arena_blocks.csv │ │ │ │ ├── game_object_blocks.csv │ │ │ │ ├── sector_blocks.csv │ │ │ │ ├── spawning_location_blocks.csv │ │ │ │ └── world_blocks.csv │ │ └── utils │ │ │ ├── __init__.py │ │ │ ├── const.py │ │ │ ├── mg_ga_transform.py │ │ │ └── utils.py │ └── werewolf │ │ ├── __init__.py │ │ ├── actions │ │ ├── __init__.py │ │ ├── common_actions.py │ │ ├── experience_operation.py │ │ ├── guard_actions.py │ │ ├── moderator_actions.py │ │ ├── seer_actions.py │ │ ├── werewolf_actions.py │ │ └── witch_actions.py │ │ ├── roles │ │ ├── __init__.py │ │ ├── base_player.py │ │ ├── guard.py │ │ ├── human_player.py │ │ ├── moderator.py │ │ ├── seer.py │ │ ├── villager.py │ │ ├── werewolf.py │ │ └── witch.py │ │ ├── schema.py │ │ └── werewolf_game.py ├── learn │ ├── __init__.py │ ├── google_search.py │ ├── skill_loader.py │ ├── text_to_embedding.py │ ├── text_to_image.py │ └── text_to_speech.py ├── llm.py ├── logs.py ├── management │ ├── __init__.py │ └── skill_manager.py ├── memory │ ├── __init__.py │ ├── brain_memory.py │ ├── longterm_memory.py │ ├── memory.py │ ├── memory_storage.py │ └── role_zero_memory.py ├── prompts │ ├── __init__.py │ ├── di │ │ ├── __init__.py │ │ ├── architect.py │ │ ├── data_analyst.py │ │ ├── engineer2.py │ │ ├── role_zero.py │ │ ├── swe_agent.py │ │ ├── team_leader.py │ │ └── write_analysis_code.py │ ├── generate_skill.md │ ├── invoice_ocr.py │ ├── metagpt_sample.py │ ├── product_manager.py │ ├── sales.py │ ├── summarize.py │ ├── task_type.py │ └── tutorial_assistant.py ├── provider │ ├── __init__.py │ ├── anthropic_api.py │ ├── ark_api.py │ ├── azure_openai_api.py │ ├── base_llm.py │ ├── bedrock │ │ ├── __init__.py │ │ ├── base_provider.py │ │ ├── bedrock_provider.py │ │ └── utils.py │ ├── bedrock_api.py │ ├── constant.py │ ├── dashscope_api.py │ ├── general_api_base.py │ ├── general_api_requestor.py │ ├── google_gemini_api.py │ ├── human_provider.py │ ├── llm_provider_registry.py │ ├── metagpt_api.py │ ├── ollama_api.py │ ├── openai_api.py │ ├── openrouter_reasoning.py │ ├── postprocess │ │ ├── __init__.py │ │ ├── base_postprocess_plugin.py │ │ └── llm_output_postprocess.py │ ├── qianfan_api.py │ ├── spark_api.py │ ├── zhipuai │ │ ├── __init__.py │ │ ├── async_sse_client.py │ │ └── zhipu_model_api.py │ └── zhipuai_api.py ├── rag │ ├── __init__.py │ ├── benchmark │ │ ├── __init__.py │ │ └── base.py │ ├── engines │ │ ├── __init__.py │ │ ├── flare.py │ │ └── simple.py │ ├── factories │ │ ├── __init__.py │ │ ├── base.py │ │ ├── embedding.py │ │ ├── index.py │ │ ├── llm.py │ │ ├── ranker.py │ │ └── retriever.py │ ├── interface.py │ ├── parsers │ │ ├── __init__.py │ │ └── omniparse.py │ ├── prompts │ │ ├── __init__.py │ │ └── default_prompts.py │ ├── rankers │ │ ├── __init__.py │ │ ├── base.py │ │ └── object_ranker.py │ ├── retrievers │ │ ├── __init__.py │ │ ├── base.py │ │ ├── bm25_retriever.py │ │ ├── chroma_retriever.py │ │ ├── es_retriever.py │ │ ├── faiss_retriever.py │ │ └── hybrid_retriever.py │ └── schema.py ├── repo_parser.py ├── roles │ ├── __init__.py │ ├── architect.py │ ├── assistant.py │ ├── customer_service.py │ ├── di │ │ ├── __init__.py │ │ ├── data_analyst.py │ │ ├── data_interpreter.py │ │ ├── engineer2.py │ │ ├── role_zero.py │ │ ├── swe_agent.py │ │ └── team_leader.py │ ├── engineer.py │ ├── invoice_ocr_assistant.py │ ├── product_manager.py │ ├── project_manager.py │ ├── prompt.py │ ├── qa_engineer.py │ ├── researcher.py │ ├── role.py │ ├── sales.py │ ├── searcher.py │ ├── teacher.py │ └── tutorial_assistant.py ├── schema.py ├── skills │ ├── SummarizeSkill │ │ ├── MakeAbstractReadable │ │ │ ├── config.json │ │ │ └── skprompt.txt │ │ ├── Notegen │ │ │ ├── config.json │ │ │ └── skprompt.txt │ │ ├── Summarize │ │ │ ├── config.json │ │ │ └── skprompt.txt │ │ └── Topics │ │ │ ├── config.json │ │ │ └── skprompt.txt │ └── WriterSkill │ │ ├── Acronym │ │ ├── config.json │ │ └── skprompt.txt │ │ ├── AcronymGenerator │ │ ├── config.json │ │ └── skprompt.txt │ │ ├── AcronymReverse │ │ ├── config.json │ │ └── skprompt.txt │ │ ├── Brainstorm │ │ ├── config.json │ │ └── skprompt.txt │ │ ├── EmailGen │ │ ├── config.json │ │ └── skprompt.txt │ │ ├── EmailTo │ │ ├── config.json │ │ └── skprompt.txt │ │ ├── EnglishImprover │ │ ├── config.json │ │ └── skprompt.txt │ │ ├── NovelChapter │ │ ├── config.json │ │ └── skprompt.txt │ │ ├── NovelChapterWithNotes │ │ ├── config.json │ │ └── skprompt.txt │ │ ├── NovelOutline │ │ ├── config.json │ │ └── skprompt.txt │ │ ├── Rewrite │ │ ├── config.json │ │ └── skprompt.txt │ │ ├── ShortPoem │ │ ├── config.json │ │ └── skprompt.txt │ │ ├── StoryGen │ │ ├── config.json │ │ └── skprompt.txt │ │ ├── TellMeMore │ │ ├── config.json │ │ └── skprompt.txt │ │ ├── Translate │ │ ├── config.json │ │ └── skprompt.txt │ │ └── TwoSentenceSummary │ │ ├── config.json │ │ └── skprompt.txt ├── software_company.py ├── startup.py ├── strategy │ ├── __init__.py │ ├── base.py │ ├── experience_retriever.py │ ├── planner.py │ ├── search_space.py │ ├── solver.py │ ├── task_type.py │ ├── thinking_command.py │ ├── tot.py │ └── tot_schema.py ├── subscription.py ├── team.py ├── tools │ ├── __init__.py │ ├── azure_tts.py │ ├── iflytek_tts.py │ ├── libs │ │ ├── __init__.py │ │ ├── browser.py │ │ ├── cr.py │ │ ├── data_preprocess.py │ │ ├── deployer.py │ │ ├── editor.py │ │ ├── email_login.py │ │ ├── env.py │ │ ├── feature_engineering.py │ │ ├── git.py │ │ ├── gpt_v_generator.py │ │ ├── image_getter.py │ │ ├── index_repo.py │ │ ├── linter.py │ │ ├── sd_engine.py │ │ ├── shell.py │ │ ├── software_development.py │ │ ├── terminal.py │ │ └── web_scraping.py │ ├── metagpt_oas3_api_svc.py │ ├── metagpt_text_to_image.py │ ├── moderation.py │ ├── openai_text_to_embedding.py │ ├── openai_text_to_image.py │ ├── openapi_v3_hello.py │ ├── prompt_writer.py │ ├── search_engine.py │ ├── search_engine_bing.py │ ├── search_engine_ddg.py │ ├── search_engine_googleapi.py │ ├── search_engine_meilisearch.py │ ├── search_engine_serpapi.py │ ├── search_engine_serper.py │ ├── swe_agent_commands │ │ ├── __init__.py │ │ ├── _setup_default_env.sh │ │ ├── _split_string │ │ ├── _split_string.py │ │ ├── defaults.sh │ │ ├── edit_linting.sh │ │ ├── search.sh │ │ ├── setup_default.sh │ │ └── swe_agent_utils.py │ ├── tool_convert.py │ ├── tool_data_type.py │ ├── tool_recommend.py │ ├── tool_registry.py │ ├── translator.py │ ├── ut_writer.py │ ├── web_browser_engine.py │ ├── web_browser_engine_playwright.py │ └── web_browser_engine_selenium.py └── utils │ ├── __init__.py │ ├── a11y_tree.py │ ├── ahttp_client.py │ ├── async_helper.py │ ├── common.py │ ├── cost_manager.py │ ├── custom_decoder.py │ ├── dependency_file.py │ ├── di_graph_repository.py │ ├── embedding.py │ ├── exceptions.py │ ├── file.py │ ├── file_repository.py │ ├── git_repository.py │ ├── graph_repository.py │ ├── highlight.py │ ├── human_interaction.py │ ├── index.html │ ├── json_to_markdown.py │ ├── make_sk_kernel.py │ ├── mermaid.py │ ├── mmdc_ink.py │ ├── mmdc_playwright.py │ ├── mmdc_pyppeteer.py │ ├── omniparse_client.py │ ├── parse_docstring.py │ ├── parse_html.py │ ├── project_repo.py │ ├── proxy_env.py │ ├── pycst.py │ ├── read_document.py │ ├── recovery_util.py │ ├── redis.py │ ├── reflection.py │ ├── repair_llm_raw_output.py │ ├── repo_to_markdown.py │ ├── report.py │ ├── s3.py │ ├── sanitize.py │ ├── save_code.py │ ├── serialize.py │ ├── singleton.py │ ├── special_tokens.py │ ├── stream_pipe.py │ ├── text.py │ ├── token_counter.py │ ├── tree.py │ ├── visual_graph_repo.py │ └── yaml_model.py ├── pytest.ini ├── requirements.txt ├── ruff.toml ├── setup.py └── tests ├── __init__.py ├── config2.yaml ├── conftest.py ├── data ├── andriod_assistant │ ├── .gitignore │ └── demo_Contacts │ │ ├── labeled_screenshots │ │ ├── 0_labeled.png │ │ └── 1_labeled.png │ │ ├── record.txt │ │ └── task_desc.txt ├── audio │ └── hello.mp3 ├── code │ ├── js │ │ └── 1.js │ └── python │ │ └── 1.py ├── config │ ├── config2.yaml │ └── config2_multi_llm.yaml ├── demo_project │ ├── code_summaries.json │ ├── dependencies.json │ ├── game.py │ ├── prd.json │ ├── system_design.json │ ├── tasks.json │ └── test_game.py.json ├── docx_for_test.docx ├── graph_db │ ├── networkx.class_view.json │ └── networkx.sequence_view.json ├── incremental_dev_project │ ├── Gomoku.zip │ ├── dice_simulator_new.zip │ ├── mock.py │ ├── number_guessing_game.zip │ ├── pygame_2048.zip │ ├── readme.md │ ├── simple_add_calculator.zip │ ├── snake_game.zip │ └── word_cloud.zip ├── invoices │ ├── invoice-1.pdf │ ├── invoice-2.png │ ├── invoice-3.jpg │ └── invoice-4.zip ├── mermaid_rsp_cache.json ├── movie │ └── trailer.mp4 ├── openai │ └── embedding.json ├── output_parser │ ├── 1.md │ ├── 2.md │ └── 3.md ├── rsp_cache.json ├── search │ ├── serpapi-metagpt-4.json │ ├── serpapi-metagpt-8.json │ ├── serper-metagpt-6.json │ └── serper-metagpt-8.json ├── search_rsp_cache.json ├── tools │ └── test_script_for_file_manager.py ├── ui │ └── 1b.png.html └── ut_writer │ └── yft_swaggerApi.json ├── metagpt ├── __init__.py ├── actions │ ├── __init__.py │ ├── di │ │ ├── test_ask_review.py │ │ ├── test_execute_nb_code.py │ │ ├── test_write_analysis_code.py │ │ └── test_write_plan.py │ ├── mock_json.py │ ├── mock_markdown.py │ ├── requirement_analysis │ │ ├── __init__.py │ │ └── requirement │ │ │ ├── __init__.py │ │ │ └── test_pic2txt.py │ ├── test_action.py │ ├── test_action_multi_llm.py │ ├── test_action_node.py │ ├── test_action_outcls_registry.py │ ├── test_debug_error.py │ ├── test_design_api.py │ ├── test_design_api_an.py │ ├── test_design_api_review.py │ ├── test_extract_readme.py │ ├── test_fix_bug.py │ ├── test_generate_questions.py │ ├── test_import_repo.py │ ├── test_invoice_ocr.py │ ├── test_prepare_documents.py │ ├── test_prepare_interview.py │ ├── test_project_management.py │ ├── test_project_management_an.py │ ├── test_rebuild_class_view.py │ ├── test_rebuild_sequence_view.py │ ├── test_research.py │ ├── test_run_code.py │ ├── test_skill_action.py │ ├── test_summarize_code.py │ ├── test_talk_action.py │ ├── test_write_code.py │ ├── test_write_code_plan_and_change_an.py │ ├── test_write_code_review.py │ ├── test_write_docstring.py │ ├── test_write_prd.py │ ├── test_write_prd_an.py │ ├── test_write_prd_review.py │ ├── test_write_review.py │ ├── test_write_teaching_plan.py │ ├── test_write_test.py │ └── test_write_tutorial.py ├── configs │ ├── __init__.py │ └── test_models_config.py ├── document_store │ ├── __init__.py │ ├── test_chromadb_store.py │ ├── test_document.py │ ├── test_faiss_store.py │ ├── test_lancedb_store.py │ ├── test_milvus_store.py │ └── test_qdrant_store.py ├── environment │ ├── android_env │ │ ├── __init__.py │ │ └── test_android_ext_env.py │ ├── api │ │ ├── __init__.py │ │ └── test_env_api.py │ ├── mgx_env │ │ └── run_mgx_env.py │ ├── minecraft_env │ │ ├── __init__.py │ │ └── test_minecraft_ext_env.py │ ├── stanford_town_env │ │ ├── __init__.py │ │ └── test_stanford_town_ext_env.py │ ├── test_base_env.py │ └── werewolf_env │ │ ├── __init__.py │ │ └── test_werewolf_ext_env.py ├── exp_pool │ ├── test_context_builders │ │ ├── test_base_context_builder.py │ │ ├── test_rolezero_context_builder.py │ │ └── test_simple_context_builder.py │ ├── test_decorator.py │ ├── test_manager.py │ ├── test_perfect_judges │ │ └── test_simple_perfect_judge.py │ ├── test_scorers │ │ └── test_simple_scorer.py │ └── test_serializers │ │ ├── test_action_node.py │ │ ├── test_role_zero.py │ │ └── test_simple.py ├── ext │ ├── __init__.py │ ├── android_assistant │ │ ├── __init__.py │ │ ├── test_an.py │ │ └── test_parse_record.py │ ├── stanford_town │ │ ├── __init__.py │ │ ├── actions │ │ │ ├── __init__.py │ │ │ ├── test_gen_action_details.py │ │ │ └── test_summarize_conv.py │ │ ├── memory │ │ │ ├── __init__.py │ │ │ ├── test_agent_memory.py │ │ │ ├── test_basic_memory.py │ │ │ └── test_spatial_memory.py │ │ ├── plan │ │ │ ├── __init__.py │ │ │ ├── test_conversation.py │ │ │ └── test_st_plan.py │ │ ├── roles │ │ │ ├── __init__.py │ │ │ └── test_st_role.py │ │ └── test_reflect.py │ └── werewolf │ │ ├── __init__.py │ │ └── actions │ │ ├── __init__.py │ │ └── test_experience_operation.py ├── learn │ ├── __init__.py │ ├── test_google_search.py │ ├── test_skill_loader.py │ ├── test_text_to_embedding.py │ ├── test_text_to_image.py │ └── test_text_to_speech.py ├── management │ ├── __init__.py │ └── test_skill_manager.py ├── memory │ ├── __init__.py │ ├── mock_text_embed.py │ ├── test_brain_memory.py │ ├── test_longterm_memory.py │ ├── test_memory.py │ ├── test_memory_storage.py │ └── test_role_zero_memory.py ├── provider │ ├── __init__.py │ ├── conftest.py │ ├── mock_llm_config.py │ ├── postprocess │ │ ├── __init__.py │ │ ├── test_base_postprocess_plugin.py │ │ └── test_llm_output_postprocess.py │ ├── req_resp_const.py │ ├── test_anthropic_api.py │ ├── test_ark.py │ ├── test_azure_llm.py │ ├── test_base_llm.py │ ├── test_bedrock_api.py │ ├── test_dashscope_api.py │ ├── test_general_api_base.py │ ├── test_general_api_requestor.py │ ├── test_google_gemini_api.py │ ├── test_human_provider.py │ ├── test_metagpt_llm.py │ ├── test_ollama_api.py │ ├── test_openai.py │ ├── test_qianfan_api.py │ ├── test_spark_api.py │ ├── test_zhipuai_api.py │ └── zhipuai │ │ ├── __init__.py │ │ ├── test_async_sse_client.py │ │ └── test_zhipu_model_api.py ├── rag │ ├── __init__.py │ ├── engines │ │ └── test_simple.py │ ├── factories │ │ ├── test_base.py │ │ ├── test_embedding.py │ │ ├── test_index.py │ │ ├── test_llm.py │ │ ├── test_ranker.py │ │ └── test_retriever.py │ ├── parser │ │ └── test_omniparse.py │ ├── rankers │ │ ├── test_base_ranker.py │ │ └── test_object_ranker.py │ ├── retrievers │ │ ├── test_base_retriever.py │ │ ├── test_bm25_retriever.py │ │ ├── test_chroma_retriever.py │ │ ├── test_es_retriever.py │ │ ├── test_faiss_retriever.py │ │ └── test_hybrid_retriever.py │ └── test_large_pdf.py ├── roles │ ├── __init__.py │ ├── di │ │ ├── run_architect.py │ │ ├── run_data_analyst.py │ │ ├── run_engineer2.py │ │ ├── run_product_manager.py │ │ ├── run_project_manager.py │ │ ├── run_swe_agent_for_benchmark.py │ │ ├── run_swe_agent_open_source_issue.py │ │ ├── test_data_analyst.py │ │ ├── test_data_interpreter.py │ │ ├── test_role_zero.py │ │ ├── test_routing.py │ │ ├── test_swe_agent.py │ │ └── test_team_leader.py │ ├── mock.py │ ├── test_architect.py │ ├── test_assistant.py │ ├── test_engineer.py │ ├── test_invoice_ocr_assistant.py │ ├── test_product_manager.py │ ├── test_project_manager.py │ ├── test_qa_engineer.py │ ├── test_researcher.py │ ├── test_role.py │ ├── test_teacher.py │ └── test_tutorial_assistant.py ├── serialize_deserialize │ ├── __init__.py │ ├── test_action.py │ ├── test_architect.py │ ├── test_environment.py │ ├── test_memory.py │ ├── test_polymorphic.py │ ├── test_prepare_interview.py │ ├── test_product_manager.py │ ├── test_project_manager.py │ ├── test_reasearcher.py │ ├── test_role.py │ ├── test_schema.py │ ├── test_serdeser_base.py │ ├── test_team.py │ ├── test_tutorial_assistant.py │ ├── test_write_code.py │ ├── test_write_code_review.py │ ├── test_write_design.py │ ├── test_write_docstring.py │ ├── test_write_prd.py │ ├── test_write_review.py │ └── test_write_tutorial.py ├── strategy │ ├── __init__.py │ ├── examples │ │ ├── __init__.py │ │ ├── test_creative_writing.py │ │ └── test_game24.py │ ├── prompt_templates │ │ ├── __init__.py │ │ ├── creative_writing.py │ │ └── game24.py │ ├── test_planner.py │ └── test_solver.py ├── test_config.py ├── test_context.py ├── test_context_mixin.py ├── test_document.py ├── test_environment.py ├── test_incremental_dev.py ├── test_llm.py ├── test_message.py ├── test_prompt.py ├── test_repo_parser.py ├── test_reporter.py ├── test_role.py ├── test_schema.py ├── test_software_company.py ├── test_subscription.py ├── test_team.py ├── tools │ ├── __init__.py │ ├── libs │ │ ├── __init__.py │ │ ├── test_browser.py │ │ ├── test_cr.py │ │ ├── test_data_preprocess.py │ │ ├── test_editor.py │ │ ├── test_email_login.py │ │ ├── test_env.py │ │ ├── test_feature_engineering.py │ │ ├── test_git.py │ │ ├── test_gpt_v_generator.py │ │ ├── test_image_getter.py │ │ ├── test_index_repo.py │ │ ├── test_linter.py │ │ ├── test_sd_engine.py │ │ ├── test_shell.py │ │ ├── test_software_development.py │ │ ├── test_terminal.py │ │ └── test_web_scraping.py │ ├── test_azure_tts.py │ ├── test_iflytek_tts.py │ ├── test_metagpt_oas3_api_svc.py │ ├── test_metagpt_text_to_image.py │ ├── test_moderation.py │ ├── test_openai_text_to_embedding.py │ ├── test_openai_text_to_image.py │ ├── test_openapi_v3_hello.py │ ├── test_prompt_writer.py │ ├── test_search_engine.py │ ├── test_search_engine_meilisearch.py │ ├── test_summarize.py │ ├── test_tool_convert.py │ ├── test_tool_recommend.py │ ├── test_tool_registry.py │ ├── test_translate.py │ ├── test_ut_writer.py │ ├── test_web_browser_engine.py │ ├── test_web_browser_engine_playwright.py │ └── test_web_browser_engine_selenium.py └── utils │ ├── __init__.py │ ├── test_ahttp_client.py │ ├── test_code_parser.py │ ├── test_common.py │ ├── test_cost_manager.py │ ├── test_custom_decoder.py │ ├── test_dependency_file.py │ ├── test_di_graph_repository.py │ ├── test_file.py │ ├── test_file_repository.py │ ├── test_git_repository.py │ ├── test_human_interaction.py │ ├── test_json_to_markdown.py │ ├── test_mermaid.py │ ├── test_output_parser.py │ ├── test_parse_html.py │ ├── test_project_repo.py │ ├── test_pycst.py │ ├── test_read_docx.py │ ├── test_redis.py │ ├── test_repair_llm_raw_output.py │ ├── test_repo_to_markdown.py │ ├── test_s3.py │ ├── test_save_code.py │ ├── test_serialize.py │ ├── test_session.py │ ├── test_text.py │ ├── test_token_counter.py │ ├── test_tree.py │ └── test_visual_graph_repo.py ├── mock ├── mock_aiohttp.py ├── mock_curl_cffi.py ├── mock_httplib2.py └── mock_llm.py └── scripts └── run_install_deps.sh /.coveragerc: -------------------------------------------------------------------------------- 1 | [run] 2 | source = 3 | ./metagpt/ 4 | omit = 5 | */metagpt/ext/* 6 | */metagpt/environment/android_env/* 7 | */metagpt/environment/werewolf_env/* 8 | -------------------------------------------------------------------------------- /.devcontainer/docker-compose.yaml: -------------------------------------------------------------------------------- 1 | version: '3' 2 | services: 3 | metagpt: 4 | build: 5 | dockerfile: Dockerfile 6 | context: .. 7 | volumes: 8 | # Update this to wherever you want VS Code to mount the folder of your project 9 | - ..:/workspaces:cached 10 | networks: 11 | - metagpt-network 12 | # environment: 13 | # MONGO_ROOT_USERNAME: root 14 | # MONGO_ROOT_PASSWORD: example123 15 | # depends_on: 16 | # - mongo 17 | # mongo: 18 | # image: mongo 19 | # restart: unless-stopped 20 | # environment: 21 | # MONGO_INITDB_ROOT_USERNAME: root 22 | # MONGO_INITDB_ROOT_PASSWORD: example123 23 | # ports: 24 | # - "27017:27017" 25 | # networks: 26 | # - metagpt-network 27 | 28 | networks: 29 | metagpt-network: 30 | driver: bridge 31 | 32 | -------------------------------------------------------------------------------- /.devcontainer/postCreateCommand.sh: -------------------------------------------------------------------------------- 1 | # Step 1: Ensure that NPM is installed on your system. Then install mermaid-js. 2 | npm --version 3 | sudo npm install -g @mermaid-js/mermaid-cli 4 | 5 | # Step 2: Ensure that Python 3.9+ is installed on your system. You can check this by using: 6 | python --version 7 | pip install -e . -------------------------------------------------------------------------------- /.dockerignore: -------------------------------------------------------------------------------- 1 | workspace 2 | tmp 3 | build 4 | dist 5 | data 6 | geckodriver.log 7 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/config.yaml: -------------------------------------------------------------------------------- 1 | blank_issues_enabled: false 2 | contact_links: 3 | - name: "📑 Read online docs" 4 | url: https://docs.deepwisdom.ai/ 5 | about: Find the tutorials, use cases and blogs from the doc site. -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/request_new_features.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: "🤔 Request new features" 3 | about: There are some ideas or demands want to discuss with the official and hope to be implemented in the future. 4 | title: '' 5 | labels: kind/features 6 | assignees: '' 7 | --- 8 | 9 | **Feature description** 10 | 11 | 12 | **Your Feature** 13 | 14 | 15 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | 2 | **Features** 3 | 4 | 5 | 6 | - xx 7 | - yy 8 | 9 | **Feature Docs** 10 | 11 | 12 | **Influence** 13 | 14 | 15 | **Result** 16 | 17 | 18 | **Other** 19 | -------------------------------------------------------------------------------- /.github/workflows/pre-commit.yaml: -------------------------------------------------------------------------------- 1 | name: Pre-commit checks 2 | 3 | on: 4 | pull_request: 5 | branches: 6 | - '**' 7 | push: 8 | branches: 9 | - '**' 10 | 11 | jobs: 12 | pre-commit-check: 13 | runs-on: ubuntu-latest 14 | environment: pre-commit 15 | steps: 16 | - name: Checkout Source Code 17 | uses: actions/checkout@v2 18 | 19 | - name: Setup Python 20 | uses: actions/setup-python@v2 21 | with: 22 | python-version: '3.9.17' 23 | 24 | - name: Install pre-commit 25 | run: pip install pre-commit 26 | 27 | - name: Initialize pre-commit 28 | run: pre-commit install 29 | 30 | - name: Run pre-commit hooks 31 | run: pre-commit run --all-files -------------------------------------------------------------------------------- /.github/workflows/stale.yaml: -------------------------------------------------------------------------------- 1 | name: Close inactive issues 2 | on: 3 | schedule: 4 | - cron: "5 0 * * *" 5 | 6 | jobs: 7 | close-issues: 8 | runs-on: ubuntu-latest 9 | permissions: 10 | issues: write 11 | pull-requests: write 12 | steps: 13 | - uses: actions/stale@v5 14 | with: 15 | days-before-issue-stale: 30 16 | days-before-issue-close: 14 17 | stale-issue-label: "inactive" 18 | stale-issue-message: "This issue has no activity in the past 30 days. Please comment on the issue if you have anything to add." 19 | close-issue-message: "This issue was closed due to 45 days of inactivity. If you feel this issue is still relevant, please reopen the issue to continue the discussion." 20 | days-before-pr-stale: -1 21 | days-before-pr-close: -1 22 | repo-token: ${{ secrets.GITHUB_TOKEN }} 23 | -------------------------------------------------------------------------------- /.pre-commit-config.yaml: -------------------------------------------------------------------------------- 1 | default_stages: [ commit ] 2 | 3 | # Install 4 | # 1. pip install metagpt[dev] 5 | # 2. pre-commit install 6 | # 3. pre-commit run --all-files # make sure all files are clean 7 | repos: 8 | - repo: https://github.com/pycqa/isort 9 | rev: 5.11.5 10 | hooks: 11 | - id: isort 12 | args: ['--profile', 'black'] 13 | exclude: >- 14 | (?x)^( 15 | .*__init__\.py$ 16 | ) 17 | 18 | - repo: https://github.com/astral-sh/ruff-pre-commit 19 | # Ruff version. 20 | rev: v0.0.284 21 | hooks: 22 | - id: ruff 23 | args: [ --fix ] 24 | 25 | - repo: https://github.com/psf/black 26 | rev: 23.3.0 27 | hooks: 28 | - id: black 29 | args: ['--line-length', '120'] 30 | -------------------------------------------------------------------------------- /MANIFEST.in: -------------------------------------------------------------------------------- 1 | recursive-include metagpt/ext/stanford_town/prompts *.txt 2 | recursive-include metagpt/ext/stanford_town/static_dirs *.csv 3 | recursive-include metagpt/ext/stanford_town/static_dirs *.json -------------------------------------------------------------------------------- /SECURITY.md: -------------------------------------------------------------------------------- 1 | # Security Policy 2 | 3 | ## Supported Versions 4 | 5 | | Version | Supported | 6 | |---------|--------------------| 7 | | 0.7.x | :x: | 8 | | 0.6.x | :x: | 9 | | < 0.6.x | :x: | 10 | 11 | 12 | ## Reporting a Vulnerability 13 | 14 | If you have any vulnerability reports, please contact alexanderwu@deepwisdom.ai . -------------------------------------------------------------------------------- /config/config2.yaml: -------------------------------------------------------------------------------- 1 | # Full Example: https://github.com/geekan/MetaGPT/blob/main/config/config2.example.yaml 2 | # Reflected Code: https://github.com/geekan/MetaGPT/blob/main/metagpt/config2.py 3 | # Config Docs: https://docs.deepwisdom.ai/main/en/guide/get_started/configuration.html 4 | llm: 5 | api_type: "openai" # or azure / ollama / groq etc. 6 | model: "gpt-4-turbo" # or gpt-3.5-turbo 7 | base_url: "https://api.openai.com/v1" # or forward url / other llm url 8 | api_key: "YOUR_API_KEY" -------------------------------------------------------------------------------- /config/examples/anthropic-claude-3-5-sonnet.yaml: -------------------------------------------------------------------------------- 1 | llm: 2 | api_type: 'claude' # or anthropic 3 | base_url: 'https://api.anthropic.com' 4 | api_key: 'YOUR_API_KEY' 5 | model: 'claude-3-5-sonnet-20240620' # or 'claude-3-opus-20240229' -------------------------------------------------------------------------------- /config/examples/aws-bedrock.yaml: -------------------------------------------------------------------------------- 1 | llm: 2 | api_type: 'bedrock' 3 | access_key: 'YOUR_API_KEY' 4 | secret_key: 'YOUR_API_SECRET' 5 | 6 | region_name: "us-east-1" 7 | model: "meta.llama2-70b-chat-v1" 8 | # model: "anthropic.claude-3-sonnet-20240229-v1:0" 9 | # model: "mistral.mixtral-8x7b-instruct-v0:1" 10 | # model: "meta.llama2-13b-chat-v1" -------------------------------------------------------------------------------- /config/examples/google-gemini.yaml: -------------------------------------------------------------------------------- 1 | llm: 2 | api_type: 'gemini' 3 | api_key: 'YOUR_API_KEY' 4 | model: 'gemini-pro' -------------------------------------------------------------------------------- /config/examples/groq-llama3-70b.yaml: -------------------------------------------------------------------------------- 1 | llm: 2 | # Visit https://console.groq.com/keys to create api key 3 | base_url: "https://api.groq.com/openai/v1" 4 | api_key: "YOUR_API_KEY" 5 | model: "llama3-70b-8192" # llama3-8b-8192,llama3-70b-8192,llama2-70b-4096 ,mixtral-8x7b-32768,gemma-7b-it 6 | -------------------------------------------------------------------------------- /config/examples/huoshan_ark.yaml: -------------------------------------------------------------------------------- 1 | llm: 2 | api_type: "ark" 3 | model: "" # your model endpoint like ep-xxx 4 | base_url: "https://ark.cn-beijing.volces.com/api/v3" 5 | api_key: "" # your api-key like ey…… -------------------------------------------------------------------------------- /config/examples/openai-gpt-3.5-turbo.yaml: -------------------------------------------------------------------------------- 1 | llm: 2 | api_key: "YOUR_API_KEY" 3 | model: "gpt-3.5-turbo" 4 | #proxy: "http://:" 5 | #base_url: "https:///v1" 6 | -------------------------------------------------------------------------------- /config/examples/openai-gpt-4-turbo.yaml: -------------------------------------------------------------------------------- 1 | llm: 2 | api_key: "YOUR_API_KEY" 3 | model: "gpt-4-turbo" 4 | #proxy: "http://:" 5 | #base_url: "https:///v1" 6 | 7 | -------------------------------------------------------------------------------- /config/examples/openrouter-llama3-70b-instruct.yaml: -------------------------------------------------------------------------------- 1 | llm: 2 | api_type: openrouter 3 | base_url: "https://openrouter.ai/api/v1" 4 | api_key: "YOUR_API_KEY" 5 | model: meta-llama/llama-3-70b-instruct -------------------------------------------------------------------------------- /config/examples/spark_lite.yaml: -------------------------------------------------------------------------------- 1 | # 适用于讯飞星火的spark-lite 参考 https://www.xfyun.cn/doc/spark/Web.html#_2-function-call%E8%AF%B4%E6%98%8E 2 | 3 | llm: 4 | api_type: "spark" 5 | # 对应模型的url 参考 https://www.xfyun.cn/doc/spark/Web.html#_1-%E6%8E%A5%E5%8F%A3%E8%AF%B4%E6%98%8E 6 | base_url: "ws(s)://spark-api.xf-yun.com/v1.1/chat" 7 | app_id: "" 8 | api_key: "" 9 | api_secret: "" 10 | domain: "general" # 取值为 [general,generalv2,generalv3,generalv3.5] 和url一一对应 11 | -------------------------------------------------------------------------------- /config/puppeteer-config.json: -------------------------------------------------------------------------------- 1 | { 2 | "executablePath": "/usr/bin/chromium", 3 | "args": ["--no-sandbox"] 4 | } 5 | -------------------------------------------------------------------------------- /docs/.agent-store-config.yaml.example: -------------------------------------------------------------------------------- 1 | role: 2 | name: Teacher # Referenced the `Teacher` in `metagpt/roles/teacher.py`. 3 | module: metagpt.roles.teacher # Referenced `metagpt/roles/teacher.py`. 4 | skills: # Refer to the skill `name` of the published skill in `docs/.well-known/skills.yaml`. 5 | - name: text_to_speech 6 | description: Text-to-speech 7 | - name: text_to_image 8 | description: Create a drawing based on the text. 9 | 10 | -------------------------------------------------------------------------------- /docs/resources/MetaGPT-new-log-v2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FoundationAgents/MetaGPT/ba2868974b2ecc3fe4218ad29dd334867c07f678/docs/resources/MetaGPT-new-log-v2.png -------------------------------------------------------------------------------- /docs/resources/MetaGPT-new-log.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FoundationAgents/MetaGPT/ba2868974b2ecc3fe4218ad29dd334867c07f678/docs/resources/MetaGPT-new-log.png -------------------------------------------------------------------------------- /docs/resources/aflow/AFLOW-experiment.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FoundationAgents/MetaGPT/ba2868974b2ecc3fe4218ad29dd334867c07f678/docs/resources/aflow/AFLOW-experiment.jpg -------------------------------------------------------------------------------- /docs/resources/aflow/AFLOW-method.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FoundationAgents/MetaGPT/ba2868974b2ecc3fe4218ad29dd334867c07f678/docs/resources/aflow/AFLOW-method.jpg -------------------------------------------------------------------------------- /docs/resources/aflow/AFLOW-performance.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FoundationAgents/MetaGPT/ba2868974b2ecc3fe4218ad29dd334867c07f678/docs/resources/aflow/AFLOW-performance.jpg -------------------------------------------------------------------------------- /docs/resources/software_company_cd.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FoundationAgents/MetaGPT/ba2868974b2ecc3fe4218ad29dd334867c07f678/docs/resources/software_company_cd.jpeg -------------------------------------------------------------------------------- /docs/resources/software_company_sd.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FoundationAgents/MetaGPT/ba2868974b2ecc3fe4218ad29dd334867c07f678/docs/resources/software_company_sd.jpeg -------------------------------------------------------------------------------- /docs/resources/spo/SPO-closed_task_figure.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FoundationAgents/MetaGPT/ba2868974b2ecc3fe4218ad29dd334867c07f678/docs/resources/spo/SPO-closed_task_figure.png -------------------------------------------------------------------------------- /docs/resources/spo/SPO-closed_task_table.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FoundationAgents/MetaGPT/ba2868974b2ecc3fe4218ad29dd334867c07f678/docs/resources/spo/SPO-closed_task_table.png -------------------------------------------------------------------------------- /docs/resources/spo/SPO-logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FoundationAgents/MetaGPT/ba2868974b2ecc3fe4218ad29dd334867c07f678/docs/resources/spo/SPO-logo.png -------------------------------------------------------------------------------- /docs/resources/spo/SPO-method.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FoundationAgents/MetaGPT/ba2868974b2ecc3fe4218ad29dd334867c07f678/docs/resources/spo/SPO-method.png -------------------------------------------------------------------------------- /docs/resources/spo/SPO-open_ended_task_figure.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FoundationAgents/MetaGPT/ba2868974b2ecc3fe4218ad29dd334867c07f678/docs/resources/spo/SPO-open_ended_task_figure.png -------------------------------------------------------------------------------- /docs/resources/workspace/content_rec_sys/resources/competitive_analysis.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FoundationAgents/MetaGPT/ba2868974b2ecc3fe4218ad29dd334867c07f678/docs/resources/workspace/content_rec_sys/resources/competitive_analysis.pdf -------------------------------------------------------------------------------- /docs/resources/workspace/content_rec_sys/resources/competitive_analysis.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FoundationAgents/MetaGPT/ba2868974b2ecc3fe4218ad29dd334867c07f678/docs/resources/workspace/content_rec_sys/resources/competitive_analysis.png -------------------------------------------------------------------------------- /docs/resources/workspace/content_rec_sys/resources/data_api_design.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FoundationAgents/MetaGPT/ba2868974b2ecc3fe4218ad29dd334867c07f678/docs/resources/workspace/content_rec_sys/resources/data_api_design.pdf -------------------------------------------------------------------------------- /docs/resources/workspace/content_rec_sys/resources/data_api_design.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FoundationAgents/MetaGPT/ba2868974b2ecc3fe4218ad29dd334867c07f678/docs/resources/workspace/content_rec_sys/resources/data_api_design.png -------------------------------------------------------------------------------- /docs/resources/workspace/content_rec_sys/resources/seq_flow.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FoundationAgents/MetaGPT/ba2868974b2ecc3fe4218ad29dd334867c07f678/docs/resources/workspace/content_rec_sys/resources/seq_flow.pdf -------------------------------------------------------------------------------- /docs/resources/workspace/content_rec_sys/resources/seq_flow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FoundationAgents/MetaGPT/ba2868974b2ecc3fe4218ad29dd334867c07f678/docs/resources/workspace/content_rec_sys/resources/seq_flow.png -------------------------------------------------------------------------------- /docs/resources/workspace/llmops_framework/resources/competitive_analysis.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FoundationAgents/MetaGPT/ba2868974b2ecc3fe4218ad29dd334867c07f678/docs/resources/workspace/llmops_framework/resources/competitive_analysis.pdf -------------------------------------------------------------------------------- /docs/resources/workspace/llmops_framework/resources/competitive_analysis.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FoundationAgents/MetaGPT/ba2868974b2ecc3fe4218ad29dd334867c07f678/docs/resources/workspace/llmops_framework/resources/competitive_analysis.png -------------------------------------------------------------------------------- /docs/resources/workspace/llmops_framework/resources/data_api_design.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FoundationAgents/MetaGPT/ba2868974b2ecc3fe4218ad29dd334867c07f678/docs/resources/workspace/llmops_framework/resources/data_api_design.pdf -------------------------------------------------------------------------------- /docs/resources/workspace/llmops_framework/resources/data_api_design.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FoundationAgents/MetaGPT/ba2868974b2ecc3fe4218ad29dd334867c07f678/docs/resources/workspace/llmops_framework/resources/data_api_design.png -------------------------------------------------------------------------------- /docs/resources/workspace/llmops_framework/resources/seq_flow.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FoundationAgents/MetaGPT/ba2868974b2ecc3fe4218ad29dd334867c07f678/docs/resources/workspace/llmops_framework/resources/seq_flow.pdf -------------------------------------------------------------------------------- /docs/resources/workspace/llmops_framework/resources/seq_flow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FoundationAgents/MetaGPT/ba2868974b2ecc3fe4218ad29dd334867c07f678/docs/resources/workspace/llmops_framework/resources/seq_flow.png -------------------------------------------------------------------------------- /docs/resources/workspace/match3_puzzle_game/resources/competitive_analysis.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FoundationAgents/MetaGPT/ba2868974b2ecc3fe4218ad29dd334867c07f678/docs/resources/workspace/match3_puzzle_game/resources/competitive_analysis.pdf -------------------------------------------------------------------------------- /docs/resources/workspace/match3_puzzle_game/resources/competitive_analysis.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FoundationAgents/MetaGPT/ba2868974b2ecc3fe4218ad29dd334867c07f678/docs/resources/workspace/match3_puzzle_game/resources/competitive_analysis.png -------------------------------------------------------------------------------- /docs/resources/workspace/match3_puzzle_game/resources/data_api_design.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FoundationAgents/MetaGPT/ba2868974b2ecc3fe4218ad29dd334867c07f678/docs/resources/workspace/match3_puzzle_game/resources/data_api_design.pdf -------------------------------------------------------------------------------- /docs/resources/workspace/match3_puzzle_game/resources/data_api_design.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FoundationAgents/MetaGPT/ba2868974b2ecc3fe4218ad29dd334867c07f678/docs/resources/workspace/match3_puzzle_game/resources/data_api_design.png -------------------------------------------------------------------------------- /docs/resources/workspace/match3_puzzle_game/resources/seq_flow.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FoundationAgents/MetaGPT/ba2868974b2ecc3fe4218ad29dd334867c07f678/docs/resources/workspace/match3_puzzle_game/resources/seq_flow.pdf -------------------------------------------------------------------------------- /docs/resources/workspace/match3_puzzle_game/resources/seq_flow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FoundationAgents/MetaGPT/ba2868974b2ecc3fe4218ad29dd334867c07f678/docs/resources/workspace/match3_puzzle_game/resources/seq_flow.png -------------------------------------------------------------------------------- /docs/resources/workspace/minimalist_pomodoro_timer/resources/competitive_analysis.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FoundationAgents/MetaGPT/ba2868974b2ecc3fe4218ad29dd334867c07f678/docs/resources/workspace/minimalist_pomodoro_timer/resources/competitive_analysis.pdf -------------------------------------------------------------------------------- /docs/resources/workspace/minimalist_pomodoro_timer/resources/competitive_analysis.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FoundationAgents/MetaGPT/ba2868974b2ecc3fe4218ad29dd334867c07f678/docs/resources/workspace/minimalist_pomodoro_timer/resources/competitive_analysis.png -------------------------------------------------------------------------------- /docs/resources/workspace/minimalist_pomodoro_timer/resources/data_api_design.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FoundationAgents/MetaGPT/ba2868974b2ecc3fe4218ad29dd334867c07f678/docs/resources/workspace/minimalist_pomodoro_timer/resources/data_api_design.pdf -------------------------------------------------------------------------------- /docs/resources/workspace/minimalist_pomodoro_timer/resources/data_api_design.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FoundationAgents/MetaGPT/ba2868974b2ecc3fe4218ad29dd334867c07f678/docs/resources/workspace/minimalist_pomodoro_timer/resources/data_api_design.png -------------------------------------------------------------------------------- /docs/resources/workspace/minimalist_pomodoro_timer/resources/seq_flow.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FoundationAgents/MetaGPT/ba2868974b2ecc3fe4218ad29dd334867c07f678/docs/resources/workspace/minimalist_pomodoro_timer/resources/seq_flow.pdf -------------------------------------------------------------------------------- /docs/resources/workspace/minimalist_pomodoro_timer/resources/seq_flow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FoundationAgents/MetaGPT/ba2868974b2ecc3fe4218ad29dd334867c07f678/docs/resources/workspace/minimalist_pomodoro_timer/resources/seq_flow.png -------------------------------------------------------------------------------- /docs/resources/workspace/pyrogue/resources/competitive_analysis.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FoundationAgents/MetaGPT/ba2868974b2ecc3fe4218ad29dd334867c07f678/docs/resources/workspace/pyrogue/resources/competitive_analysis.pdf -------------------------------------------------------------------------------- /docs/resources/workspace/pyrogue/resources/competitive_analysis.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FoundationAgents/MetaGPT/ba2868974b2ecc3fe4218ad29dd334867c07f678/docs/resources/workspace/pyrogue/resources/competitive_analysis.png -------------------------------------------------------------------------------- /docs/resources/workspace/pyrogue/resources/data_api_design.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FoundationAgents/MetaGPT/ba2868974b2ecc3fe4218ad29dd334867c07f678/docs/resources/workspace/pyrogue/resources/data_api_design.pdf -------------------------------------------------------------------------------- /docs/resources/workspace/pyrogue/resources/data_api_design.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FoundationAgents/MetaGPT/ba2868974b2ecc3fe4218ad29dd334867c07f678/docs/resources/workspace/pyrogue/resources/data_api_design.png -------------------------------------------------------------------------------- /docs/resources/workspace/pyrogue/resources/seq_flow.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FoundationAgents/MetaGPT/ba2868974b2ecc3fe4218ad29dd334867c07f678/docs/resources/workspace/pyrogue/resources/seq_flow.pdf -------------------------------------------------------------------------------- /docs/resources/workspace/pyrogue/resources/seq_flow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FoundationAgents/MetaGPT/ba2868974b2ecc3fe4218ad29dd334867c07f678/docs/resources/workspace/pyrogue/resources/seq_flow.png -------------------------------------------------------------------------------- /docs/resources/workspace/search_algorithm_framework/resources/competitive_analysis.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FoundationAgents/MetaGPT/ba2868974b2ecc3fe4218ad29dd334867c07f678/docs/resources/workspace/search_algorithm_framework/resources/competitive_analysis.pdf -------------------------------------------------------------------------------- /docs/resources/workspace/search_algorithm_framework/resources/competitive_analysis.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FoundationAgents/MetaGPT/ba2868974b2ecc3fe4218ad29dd334867c07f678/docs/resources/workspace/search_algorithm_framework/resources/competitive_analysis.png -------------------------------------------------------------------------------- /docs/resources/workspace/search_algorithm_framework/resources/data_api_design.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FoundationAgents/MetaGPT/ba2868974b2ecc3fe4218ad29dd334867c07f678/docs/resources/workspace/search_algorithm_framework/resources/data_api_design.pdf -------------------------------------------------------------------------------- /docs/resources/workspace/search_algorithm_framework/resources/data_api_design.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FoundationAgents/MetaGPT/ba2868974b2ecc3fe4218ad29dd334867c07f678/docs/resources/workspace/search_algorithm_framework/resources/data_api_design.png -------------------------------------------------------------------------------- /docs/resources/workspace/search_algorithm_framework/resources/seq_flow.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FoundationAgents/MetaGPT/ba2868974b2ecc3fe4218ad29dd334867c07f678/docs/resources/workspace/search_algorithm_framework/resources/seq_flow.pdf -------------------------------------------------------------------------------- /docs/resources/workspace/search_algorithm_framework/resources/seq_flow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FoundationAgents/MetaGPT/ba2868974b2ecc3fe4218ad29dd334867c07f678/docs/resources/workspace/search_algorithm_framework/resources/seq_flow.png -------------------------------------------------------------------------------- /docs/scripts/coverage.sh: -------------------------------------------------------------------------------- 1 | coverage run --source ./metagpt -m pytest -n 8 --durations=0 --timeout=100 && coverage report -m && coverage html && open htmlcov/index.html 2 | -------------------------------------------------------------------------------- /docs/scripts/get_all_classes_and_funcs.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | find metagpt | grep "\.py" | grep -Ev "(__init__|pyc)" | xargs grep -E "(^class| def )" 2>/dev/null | grep -v -E "(grep|tests|examples)" -------------------------------------------------------------------------------- /examples/aflow/config2.example.yaml: -------------------------------------------------------------------------------- 1 | models: 2 | "": # model: "gpt-4-turbo" # or gpt-3.5-turbo 3 | api_type: "openai" # or azure / ollama / groq etc. 4 | base_url: "" 5 | api_key: "" 6 | temperature: 0 7 | "": 8 | api_type: "openai" 9 | base_url: "" 10 | api_key: "" 11 | temperature: 0 12 | CALC_USAGE: True 13 | -------------------------------------------------------------------------------- /examples/android_assistant/requirements.txt: -------------------------------------------------------------------------------- 1 | pyshine==0.0.9 2 | opencv-python==4.6.0.66 -------------------------------------------------------------------------------- /examples/cr.py: -------------------------------------------------------------------------------- 1 | import fire 2 | 3 | from metagpt.roles.di.engineer2 import Engineer2 4 | from metagpt.tools.libs.cr import CodeReview 5 | 6 | 7 | async def main(msg): 8 | role = Engineer2(tools=["Plan", "Editor:write,read", "RoleZero", "ValidateAndRewriteCode", "CodeReview"]) 9 | cr = CodeReview() 10 | role.tool_execution_map.update({"CodeReview.review": cr.review, "CodeReview.fix": cr.fix}) 11 | await role.run(msg) 12 | 13 | 14 | if __name__ == "__main__": 15 | fire.Fire(main) 16 | -------------------------------------------------------------------------------- /examples/data/di/dog.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FoundationAgents/MetaGPT/ba2868974b2ecc3fe4218ad29dd334867c07f678/examples/data/di/dog.jpg -------------------------------------------------------------------------------- /examples/data/di/receipt_shopping.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FoundationAgents/MetaGPT/ba2868974b2ecc3fe4218ad29dd334867c07f678/examples/data/di/receipt_shopping.jpg -------------------------------------------------------------------------------- /examples/data/omniparse/test01.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FoundationAgents/MetaGPT/ba2868974b2ecc3fe4218ad29dd334867c07f678/examples/data/omniparse/test01.docx -------------------------------------------------------------------------------- /examples/data/omniparse/test02.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FoundationAgents/MetaGPT/ba2868974b2ecc3fe4218ad29dd334867c07f678/examples/data/omniparse/test02.pdf -------------------------------------------------------------------------------- /examples/data/omniparse/test03.mp4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FoundationAgents/MetaGPT/ba2868974b2ecc3fe4218ad29dd334867c07f678/examples/data/omniparse/test03.mp4 -------------------------------------------------------------------------------- /examples/data/omniparse/test04.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FoundationAgents/MetaGPT/ba2868974b2ecc3fe4218ad29dd334867c07f678/examples/data/omniparse/test04.mp3 -------------------------------------------------------------------------------- /examples/data/rag/travel.txt: -------------------------------------------------------------------------------- 1 | Bob likes traveling. -------------------------------------------------------------------------------- /examples/data/rag_bm/dataset_info.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "simplified_CRUD":{ 4 | "document_file":["documents.txt"], 5 | "gt_file":"answer.json" 6 | } 7 | }, 8 | { 9 | "simplified_RGB":{ 10 | "document_file":["documents.txt"], 11 | "gt_file":"answer.json" 12 | } 13 | }, 14 | { 15 | "RGB_EN":{ 16 | "document_file":["documents.txt"], 17 | "gt_file":"answer.json" 18 | } 19 | } 20 | ] 21 | -------------------------------------------------------------------------------- /examples/data/search_kb/example.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "source": "Which facial cleanser is good for oily skin?", 4 | "output": "ABC cleanser is preferred by many with oily skin." 5 | }, 6 | { 7 | "source": "Is L'Oreal good to use?", 8 | "output": "L'Oreal is a popular brand with many positive reviews." 9 | } 10 | ] -------------------------------------------------------------------------------- /examples/data/search_kb/example.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FoundationAgents/MetaGPT/ba2868974b2ecc3fe4218ad29dd334867c07f678/examples/data/search_kb/example.xlsx -------------------------------------------------------------------------------- /examples/di/InfiAgent-DABench/run_InfiAgent-DABench_single.py: -------------------------------------------------------------------------------- 1 | import fire 2 | from DABench import DABench 3 | 4 | from metagpt.logs import logger 5 | from metagpt.roles.di.data_interpreter import DataInterpreter 6 | from metagpt.utils.recovery_util import save_history 7 | 8 | 9 | async def main(id=0): 10 | """Evaluate one task""" 11 | bench = DABench() 12 | requirement = bench.generate_formatted_prompt(id) 13 | di = DataInterpreter() 14 | result = await di.run(requirement) 15 | logger.info(result) 16 | save_history(role=di) 17 | _, is_correct = bench.eval(id, str(result)) 18 | logger.info(f"Prediction is {'correct' if is_correct else 'incorrect'}.") 19 | 20 | 21 | if __name__ == "__main__": 22 | fire.Fire(main) 23 | -------------------------------------------------------------------------------- /examples/di/arxiv_reader.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | from metagpt.roles.di.data_interpreter import DataInterpreter 4 | from metagpt.tools.libs.web_scraping import view_page_element_to_scrape 5 | 6 | 7 | async def main(): 8 | template = "https://arxiv.org/list/{tag}/pastweek?skip=0&show=300" 9 | tags = ["cs.ai", "cs.cl", "cs.lg", "cs.se"] 10 | urls = [template.format(tag=tag) for tag in tags] 11 | prompt = f"""This is a collection of arxiv urls: '{urls}' . 12 | Record each article, remove duplicates by title (they may have multiple tags), filter out papers related to 13 | large language model / agent / llm, print top 100 and visualize the word count of the titles""" 14 | di = DataInterpreter(react_mode="react", tools=[view_page_element_to_scrape.__name__]) 15 | 16 | await di.run(prompt) 17 | 18 | 19 | if __name__ == "__main__": 20 | import asyncio 21 | 22 | asyncio.run(main()) 23 | -------------------------------------------------------------------------------- /examples/di/automated_planning_of_tasks.py: -------------------------------------------------------------------------------- 1 | import fire 2 | 3 | from metagpt.logs import logger 4 | from metagpt.roles.di.team_leader import TeamLeader 5 | 6 | 7 | async def main(): 8 | # Create an instance of TeamLeader 9 | tl = TeamLeader() 10 | 11 | # Update the plan with the goal to create a 2048 game 12 | # This will auto generate tasks needed to accomplish the goal 13 | await tl.planner.update_plan(goal="create a 2048 game.") 14 | 15 | # Iterate through all tasks in the plan 16 | # Log each task's ID, instruction and completion status 17 | for task in tl.planner.plan.tasks: 18 | logger.info(f"- {task.task_id}: {task.instruction} (Completed: {task.is_finished})") 19 | 20 | 21 | if __name__ == "__main__": 22 | fire.Fire(main) 23 | -------------------------------------------------------------------------------- /examples/di/custom_tool.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | """ 4 | @Time : 2024/3/22 10:54 5 | @Author : alexanderwu 6 | @File : custom_tool.py 7 | """ 8 | 9 | from metagpt.roles.di.data_interpreter import DataInterpreter 10 | from metagpt.tools.tool_registry import register_tool 11 | 12 | 13 | @register_tool() 14 | def magic_function(arg1: str, arg2: int) -> dict: 15 | """ 16 | The magic function that does something. 17 | 18 | Args: 19 | arg1 (str): ... 20 | arg2 (int): ... 21 | 22 | Returns: 23 | dict: ... 24 | """ 25 | return {"arg1": arg1 * 3, "arg2": arg2 * 5} 26 | 27 | 28 | async def main(): 29 | di = DataInterpreter(tools=["magic_function"]) 30 | await di.run("Just call the magic function with arg1 'A' and arg2 2. Tell me the result.") 31 | 32 | 33 | if __name__ == "__main__": 34 | import asyncio 35 | 36 | asyncio.run(main()) 37 | -------------------------------------------------------------------------------- /examples/di/data_visualization.py: -------------------------------------------------------------------------------- 1 | import asyncio 2 | 3 | from metagpt.logs import logger 4 | from metagpt.roles.di.data_interpreter import DataInterpreter 5 | from metagpt.utils.recovery_util import save_history 6 | 7 | 8 | async def main(requirement: str = ""): 9 | di = DataInterpreter() 10 | rsp = await di.run(requirement) 11 | logger.info(rsp) 12 | save_history(role=di) 13 | 14 | 15 | if __name__ == "__main__": 16 | requirement = "Run data analysis on sklearn Iris dataset, include a plot" 17 | asyncio.run(main(requirement)) 18 | -------------------------------------------------------------------------------- /examples/di/imitate_webpage.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | """ 4 | @Time : 2024/01/15 5 | @Author : mannaandpoem 6 | @File : imitate_webpage.py 7 | """ 8 | from metagpt.roles.di.data_interpreter import DataInterpreter 9 | 10 | 11 | async def main(): 12 | web_url = "https://pytorch.org/" 13 | prompt = f"""This is a URL of webpage: '{web_url}' . 14 | Firstly, open the page and take a screenshot of the page. 15 | Secondly, convert the image to a webpage including HTML, CSS and JS in one go. 16 | Note: All required dependencies and environments have been fully installed and configured.""" 17 | di = DataInterpreter(tools=["GPTvGenerator", "Browser"]) 18 | 19 | await di.run(prompt) 20 | 21 | 22 | if __name__ == "__main__": 23 | import asyncio 24 | 25 | asyncio.run(main()) 26 | -------------------------------------------------------------------------------- /examples/di/machine_learning_with_tools.py: -------------------------------------------------------------------------------- 1 | import asyncio 2 | 3 | from metagpt.roles.di.data_interpreter import DataInterpreter 4 | 5 | 6 | async def main(requirement: str): 7 | role = DataInterpreter(use_reflection=True, tools=[""]) 8 | await role.run(requirement) 9 | 10 | 11 | if __name__ == "__main__": 12 | data_path = "your/path/to/titanic" 13 | train_path = f"{data_path}/split_train.csv" 14 | eval_path = f"{data_path}/split_eval.csv" 15 | requirement = f"This is a titanic passenger survival dataset, your goal is to predict passenger survival outcome. The target column is Survived. Perform data analysis, data preprocessing, feature engineering, and modeling to predict the target. Report accuracy on the eval data. Train data path: '{train_path}', eval data path: '{eval_path}'." 16 | asyncio.run(main(requirement)) 17 | -------------------------------------------------------------------------------- /examples/di/rm_image_background.py: -------------------------------------------------------------------------------- 1 | import asyncio 2 | 3 | from metagpt.const import DEFAULT_WORKSPACE_ROOT, EXAMPLE_DATA_PATH 4 | from metagpt.roles.di.data_interpreter import DataInterpreter 5 | 6 | 7 | async def main(requirement: str = ""): 8 | di = DataInterpreter() 9 | await di.run(requirement) 10 | 11 | 12 | if __name__ == "__main__": 13 | image_path = EXAMPLE_DATA_PATH / "di/dog.jpg" 14 | save_path = DEFAULT_WORKSPACE_ROOT / "image_rm_bg.png" 15 | requirement = f"This is a image, you need to use python toolkit rembg to remove the background of the image and save the result. image path:{image_path}; save path:{save_path}." 16 | asyncio.run(main(requirement)) 17 | -------------------------------------------------------------------------------- /examples/di/run_flask.py: -------------------------------------------------------------------------------- 1 | import asyncio 2 | 3 | from metagpt.roles.di.data_interpreter import DataInterpreter 4 | 5 | USE_GOT_REPO_REQ = """ 6 | Write a service using Flask, create a conda environment and run it, and call the service's interface for validation. 7 | Notice: Don't write all codes in one response, each time, just write code for one step. 8 | """ 9 | # If you have created a conda environment, you can say: 10 | # I have created the conda environment '{env_name}', please use this environment to execute. 11 | 12 | 13 | async def main(): 14 | di = DataInterpreter(tools=["Terminal", "Editor"]) 15 | await di.run(USE_GOT_REPO_REQ) 16 | 17 | 18 | if __name__ == "__main__": 19 | asyncio.run(main()) 20 | -------------------------------------------------------------------------------- /examples/di/sd_tool_usage.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # @Date : 1/11/2024 7:06 PM 3 | # @Author : stellahong (stellahong@fuzhi.ai) 4 | # @Desc : 5 | import asyncio 6 | 7 | from metagpt.roles.di.data_interpreter import DataInterpreter 8 | 9 | 10 | async def main(requirement: str = ""): 11 | di = DataInterpreter(tools=["SDEngine"]) 12 | await di.run(requirement) 13 | 14 | 15 | if __name__ == "__main__": 16 | sd_url = "http://your.sd.service.ip:port" 17 | requirement = ( 18 | f"I want to generate an image of a beautiful girl using the stable diffusion text2image tool, sd_url={sd_url}" 19 | ) 20 | 21 | asyncio.run(main(requirement)) 22 | -------------------------------------------------------------------------------- /examples/di/solve_math_problems.py: -------------------------------------------------------------------------------- 1 | import asyncio 2 | 3 | from metagpt.roles.di.data_interpreter import DataInterpreter 4 | 5 | 6 | async def main(requirement: str = ""): 7 | di = DataInterpreter() 8 | await di.run(requirement) 9 | 10 | 11 | if __name__ == "__main__": 12 | requirement = "Solve this math problem: The greatest common divisor of positive integers m and n is 6. The least common multiple of m and n is 126. What is the least possible value of m + n?" 13 | # answer: 60 (m = 18, n = 42) 14 | asyncio.run(main(requirement)) 15 | -------------------------------------------------------------------------------- /examples/di/use_github_repo.py: -------------------------------------------------------------------------------- 1 | import asyncio 2 | 3 | from metagpt.roles.di.data_interpreter import DataInterpreter 4 | 5 | USE_GOT_REPO_REQ = """ 6 | This is a link to the GOT github repo: https://github.com/spcl/graph-of-thoughts.git. 7 | Clone it, read the README to understand the usage, install it, and finally run the quick start example. 8 | **Note the config for LLM is at `config/config_got.json`, it's outside the repo path, before using it, you need to copy it into graph-of-thoughts. 9 | ** Don't write all codes in one response, each time, just write code for one step. 10 | """ 11 | 12 | 13 | async def main(): 14 | di = DataInterpreter(tools=["Terminal"]) 15 | await di.run(USE_GOT_REPO_REQ) 16 | 17 | 18 | if __name__ == "__main__": 19 | asyncio.run(main()) 20 | -------------------------------------------------------------------------------- /examples/exp_pool/README.md: -------------------------------------------------------------------------------- 1 | # Experience Pool 2 | 3 | ## Prerequisites 4 | - Ensure the RAG module is installed: https://docs.deepwisdom.ai/main/en/guide/in_depth_guides/rag_module.html 5 | - Set embedding: https://docs.deepwisdom.ai/main/en/guide/in_depth_guides/rag_module.html 6 | - Set `enabled`、`enable_read` and `enable_write` to `true` in the `exp_pool` section of `config2.yaml` 7 | 8 | ## Example Files 9 | 10 | ### 1. decorator.py 11 | Showcases the implementation of the `@exp_cache` decorator. 12 | 13 | ### 2. init_exp_pool.py 14 | Demonstrates the process of initializing the experience pool. 15 | 16 | ### 3. manager.py 17 | Illustrates CRUD (Create, Read, Update, Delete) operations for managing experiences in the pool. 18 | 19 | ### 4. scorer.py 20 | Outlines methods for evaluating and scoring experiences within the pool. 21 | -------------------------------------------------------------------------------- /examples/exp_pool/decorator.py: -------------------------------------------------------------------------------- 1 | """ 2 | This script demonstrates how to automatically store experiences using @exp_cache and query the stored experiences. 3 | """ 4 | 5 | import asyncio 6 | import uuid 7 | 8 | from metagpt.exp_pool import exp_cache, get_exp_manager 9 | from metagpt.logs import logger 10 | 11 | 12 | @exp_cache() 13 | async def produce(req=""): 14 | return f"{req} {uuid.uuid4().hex}" 15 | 16 | 17 | async def main(): 18 | req = "Water" 19 | 20 | resp = await produce(req=req) 21 | logger.info(f"The response of `produce({req})` is: {resp}") 22 | 23 | exps = await get_exp_manager().query_exps(req) 24 | logger.info(f"Find experiences: {exps}") 25 | 26 | 27 | if __name__ == "__main__": 28 | asyncio.run(main()) 29 | -------------------------------------------------------------------------------- /examples/llm_vision.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | # @Desc : example to run the ability of LLM vision 4 | 5 | import asyncio 6 | from pathlib import Path 7 | 8 | from metagpt.llm import LLM 9 | from metagpt.utils.common import encode_image 10 | 11 | 12 | async def main(): 13 | llm = LLM() 14 | 15 | # check if the configured llm supports llm-vision capacity. If not, it will throw a error 16 | invoice_path = Path(__file__).parent.joinpath("..", "tests", "data", "invoices", "invoice-2.png") 17 | img_base64 = encode_image(invoice_path) 18 | res = await llm.aask(msg="return `True` if this image might be a invoice, or return `False`", images=[img_base64]) 19 | assert ("true" in res.lower()) or ("invoice" in res.lower()) 20 | 21 | 22 | if __name__ == "__main__": 23 | asyncio.run(main()) 24 | -------------------------------------------------------------------------------- /examples/ping.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | """ 4 | @Time : 2024/4/22 14:28 5 | @Author : alexanderwu 6 | @File : ping.py 7 | """ 8 | 9 | import asyncio 10 | 11 | from metagpt.llm import LLM 12 | from metagpt.logs import logger 13 | 14 | 15 | async def ask_and_print(question: str, llm: LLM, system_prompt) -> str: 16 | logger.info(f"Q: {question}") 17 | rsp = await llm.aask(question, system_msgs=[system_prompt]) 18 | logger.info(f"A: {rsp}") 19 | logger.info("\n") 20 | return rsp 21 | 22 | 23 | async def main(): 24 | llm = LLM() 25 | await ask_and_print("ping?", llm, "Just answer pong when ping.") 26 | 27 | 28 | if __name__ == "__main__": 29 | asyncio.run(main()) 30 | -------------------------------------------------------------------------------- /examples/rag/rag_search.py: -------------------------------------------------------------------------------- 1 | """Agent with RAG search.""" 2 | 3 | import asyncio 4 | 5 | from examples.rag.rag_pipeline import DOC_PATH, QUESTION 6 | from metagpt.logs import logger 7 | from metagpt.rag.engines import SimpleEngine 8 | from metagpt.roles import Sales 9 | 10 | 11 | async def search(): 12 | """Agent with RAG search.""" 13 | 14 | store = SimpleEngine.from_docs(input_files=[DOC_PATH]) 15 | role = Sales(profile="Sales", store=store) 16 | result = await role.run(QUESTION) 17 | logger.info(result) 18 | 19 | 20 | if __name__ == "__main__": 21 | asyncio.run(search()) 22 | -------------------------------------------------------------------------------- /examples/research.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import asyncio 4 | 5 | from metagpt.roles.researcher import RESEARCH_PATH, Researcher 6 | 7 | 8 | async def main(): 9 | topic = "dataiku vs. datarobot" 10 | role = Researcher(language="en-us") 11 | await role.run(topic) 12 | print(f"save report to {RESEARCH_PATH / f'{topic}.md'}.") 13 | 14 | 15 | if __name__ == "__main__": 16 | asyncio.run(main()) 17 | -------------------------------------------------------------------------------- /examples/search_enhanced_qa.py: -------------------------------------------------------------------------------- 1 | """ 2 | This script demonstrates how to use the SearchEnhancedQA action to answer questions 3 | by leveraging web search results. It showcases a simple example of querying about 4 | the current weather in Beijing. 5 | 6 | The SearchEnhancedQA action combines web search capabilities with natural language 7 | processing to provide informative answers to user queries. 8 | """ 9 | 10 | import asyncio 11 | 12 | from metagpt.actions.search_enhanced_qa import SearchEnhancedQA 13 | 14 | 15 | async def main(): 16 | """Runs a sample query through SearchEnhancedQA and prints the result.""" 17 | 18 | action = SearchEnhancedQA() 19 | 20 | query = "What is the weather like in Beijing today?" 21 | answer = await action.run(query) 22 | 23 | print(f"The answer to '{query}' is:\n\n{answer}") 24 | 25 | 26 | if __name__ == "__main__": 27 | asyncio.run(main()) 28 | -------------------------------------------------------------------------------- /examples/search_google.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | """ 4 | @Time : 2023/5/7 18:32 5 | @Author : alexanderwu 6 | @File : search_google.py 7 | """ 8 | 9 | import asyncio 10 | 11 | from metagpt.roles import Searcher 12 | 13 | 14 | async def main(): 15 | await Searcher().run("What are some good sun protection products?") 16 | 17 | 18 | if __name__ == "__main__": 19 | asyncio.run(main()) 20 | -------------------------------------------------------------------------------- /examples/search_with_specific_engine.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | """ 4 | """ 5 | import asyncio 6 | 7 | from metagpt.config2 import Config 8 | from metagpt.roles import Searcher 9 | from metagpt.tools.search_engine import SearchEngine 10 | 11 | 12 | async def main(): 13 | question = "What are the most interesting human facts?" 14 | 15 | search = Config.default().search 16 | kwargs = search.model_dump() 17 | await Searcher(search_engine=SearchEngine(engine=search.api_type, **kwargs)).run(question) 18 | 19 | 20 | if __name__ == "__main__": 21 | asyncio.run(main()) 22 | -------------------------------------------------------------------------------- /examples/sela/README.md: -------------------------------------------------------------------------------- 1 | # SELA: Tree-Search Enhanced LLM Agents for Automated Machine Learning 2 | 3 | 4 | Official implementation for paper [SELA: Tree-Search Enhanced LLM Agents for Automated Machine Learning](https://arxiv.org/abs/2410.17238). 5 | 6 | 7 | SELA is an innovative system that enhances Automated Machine Learning (AutoML) by integrating Monte Carlo Tree Search (MCTS) with LLM-based agents. Traditional AutoML methods often generate low-diversity and suboptimal code, limiting their effectiveness in model selection and ensembling. SELA addresses these challenges by representing pipeline configurations as trees, enabling agents to intelligently explore the solution space and iteratively refine their strategies based on experimental feedback. 8 | 9 | For more details, please visit the [SELA path](../../metagpt/ext/sela/README.md). 10 | -------------------------------------------------------------------------------- /examples/serialize_model.py: -------------------------------------------------------------------------------- 1 | from metagpt.environment.mgx.mgx_env import MGXEnv 2 | from metagpt.logs import logger 3 | 4 | 5 | def main(): 6 | """Demonstrates serialization and deserialization using SerializationMixin. 7 | 8 | This example creates an instance of MGXEnv, serializes it to a file, 9 | and then deserializes it back to an instance. 10 | 11 | If executed correctly, the following log messages will be output: 12 | MGXEnv serialization successful. File saved at: /.../workspace/storage/MGXEnv.json 13 | MGXEnv deserialization successful. Instance created from file: /.../workspace/storage/MGXEnv.json 14 | The instance is MGXEnv() 15 | """ 16 | 17 | env = MGXEnv() 18 | env.serialize() 19 | 20 | env: MGXEnv = MGXEnv.deserialize() 21 | logger.info(f"The instance is {repr(env)}") 22 | 23 | 24 | if __name__ == "__main__": 25 | main() 26 | -------------------------------------------------------------------------------- /examples/spo/config2.example.yaml: -------------------------------------------------------------------------------- 1 | llm: 2 | api_type: "openai" 3 | model: "gpt-4o-mini" 4 | base_url: "" 5 | api_key: "" 6 | temperature: 0 7 | models: 8 | "gpt-4o": # model: "gpt-4-turbo" # or gpt-3.5-turbo 9 | api_type: "openai" # or azure / ollama / groq etc. 10 | base_url: "" 11 | api_key: "" 12 | temperature: 0 13 | "deepseek-chat": # api_type: "openai" # or azure / ollama / groq etc. 14 | api_type: "openai" # or azure / ollama / groq etc. 15 | base_url: "" 16 | api_key: "" 17 | temperature: 0 18 | "gpt-4o-mini": # api_type: "openai" # or azure / ollama / groq etc. 19 | api_type: "openai" # or azure / ollama / groq etc. 20 | base_url: "" 21 | api_key: "" 22 | temperature: 0 23 | 24 | # Other models 25 | 26 | -------------------------------------------------------------------------------- /examples/stanford_town/__init__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | # @Desc : 4 | -------------------------------------------------------------------------------- /examples/stanford_town/requirements.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FoundationAgents/MetaGPT/ba2868974b2ecc3fe4218ad29dd334867c07f678/examples/stanford_town/requirements.txt -------------------------------------------------------------------------------- /examples/stanford_town/storage/.gitignore: -------------------------------------------------------------------------------- 1 | # path to store simulation data 2 | test_* 3 | unittest* 4 | July* -------------------------------------------------------------------------------- /examples/stanford_town/storage/base_the_ville_isabella_maria_klaus/environment/0.json: -------------------------------------------------------------------------------- 1 | { 2 | "Isabella Rodriguez": { 3 | "maze": "the_ville", 4 | "x": 72, 5 | "y": 14 6 | }, 7 | "Klaus Mueller": { 8 | "maze": "the_ville", 9 | "x": 126, 10 | "y": 46 11 | }, 12 | "Maria Lopez": { 13 | "maze": "the_ville", 14 | "x": 123, 15 | "y": 57 16 | } 17 | } 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /examples/stanford_town/storage/base_the_ville_isabella_maria_klaus/personas/Isabella Rodriguez/bootstrap_memory/associative_memory/embeddings.json: -------------------------------------------------------------------------------- 1 | {} -------------------------------------------------------------------------------- /examples/stanford_town/storage/base_the_ville_isabella_maria_klaus/personas/Isabella Rodriguez/bootstrap_memory/associative_memory/kw_strength.json: -------------------------------------------------------------------------------- 1 | {"kw_strength_event": {}, 2 | "kw_strength_thought": {}} -------------------------------------------------------------------------------- /examples/stanford_town/storage/base_the_ville_isabella_maria_klaus/personas/Isabella Rodriguez/bootstrap_memory/associative_memory/nodes.json: -------------------------------------------------------------------------------- 1 | {} -------------------------------------------------------------------------------- /examples/stanford_town/storage/base_the_ville_isabella_maria_klaus/personas/Klaus Mueller/bootstrap_memory/associative_memory/embeddings.json: -------------------------------------------------------------------------------- 1 | {} -------------------------------------------------------------------------------- /examples/stanford_town/storage/base_the_ville_isabella_maria_klaus/personas/Klaus Mueller/bootstrap_memory/associative_memory/kw_strength.json: -------------------------------------------------------------------------------- 1 | {"kw_strength_event": {}, 2 | "kw_strength_thought": {}} -------------------------------------------------------------------------------- /examples/stanford_town/storage/base_the_ville_isabella_maria_klaus/personas/Klaus Mueller/bootstrap_memory/associative_memory/nodes.json: -------------------------------------------------------------------------------- 1 | {} -------------------------------------------------------------------------------- /examples/stanford_town/storage/base_the_ville_isabella_maria_klaus/personas/Maria Lopez/bootstrap_memory/associative_memory/embeddings.json: -------------------------------------------------------------------------------- 1 | {} -------------------------------------------------------------------------------- /examples/stanford_town/storage/base_the_ville_isabella_maria_klaus/personas/Maria Lopez/bootstrap_memory/associative_memory/kw_strength.json: -------------------------------------------------------------------------------- 1 | {"kw_strength_event": {}, 2 | "kw_strength_thought": {}} -------------------------------------------------------------------------------- /examples/stanford_town/storage/base_the_ville_isabella_maria_klaus/personas/Maria Lopez/bootstrap_memory/associative_memory/nodes.json: -------------------------------------------------------------------------------- 1 | {} -------------------------------------------------------------------------------- /examples/stanford_town/storage/base_the_ville_isabella_maria_klaus/reverie/meta.json: -------------------------------------------------------------------------------- 1 | { 2 | "fork_sim_code": "base_the_ville_isabella_maria_klaus", 3 | "start_date": "February 13, 2023", 4 | "curr_time": "February 13, 2023, 00:00:00", 5 | "sec_per_step": 10, 6 | "maze_name": "the_ville", 7 | "persona_names": [ 8 | "Isabella Rodriguez", 9 | "Maria Lopez", 10 | "Klaus Mueller" 11 | ], 12 | "step": 0 13 | } -------------------------------------------------------------------------------- /examples/ui_with_chainlit/.gitignore: -------------------------------------------------------------------------------- 1 | *.chainlit 2 | chainlit.md 3 | .files -------------------------------------------------------------------------------- /examples/ui_with_chainlit/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FoundationAgents/MetaGPT/ba2868974b2ecc3fe4218ad29dd334867c07f678/examples/ui_with_chainlit/__init__.py -------------------------------------------------------------------------------- /examples/ui_with_chainlit/public/2048.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FoundationAgents/MetaGPT/ba2868974b2ecc3fe4218ad29dd334867c07f678/examples/ui_with_chainlit/public/2048.jpg -------------------------------------------------------------------------------- /examples/ui_with_chainlit/public/MetaGPT-new-log.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FoundationAgents/MetaGPT/ba2868974b2ecc3fe4218ad29dd334867c07f678/examples/ui_with_chainlit/public/MetaGPT-new-log.jpg -------------------------------------------------------------------------------- /examples/ui_with_chainlit/public/blackjack.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FoundationAgents/MetaGPT/ba2868974b2ecc3fe4218ad29dd334867c07f678/examples/ui_with_chainlit/public/blackjack.jpg -------------------------------------------------------------------------------- /examples/use_off_the_shelf_agent.py: -------------------------------------------------------------------------------- 1 | """ 2 | Filename: MetaGPT/examples/use_off_the_shelf_agent.py 3 | Created Date: Tuesday, September 19th 2023, 6:52:25 pm 4 | Author: garylin2099 5 | """ 6 | import asyncio 7 | 8 | from metagpt.environment.mgx.mgx_env import MGXEnv 9 | from metagpt.logs import logger 10 | from metagpt.roles.di.team_leader import TeamLeader 11 | from metagpt.roles.product_manager import ProductManager 12 | from metagpt.schema import Message 13 | 14 | 15 | async def main(): 16 | msg = "Write a PRD for a snake game" 17 | env = MGXEnv() 18 | env.add_roles([TeamLeader(), ProductManager()]) 19 | env.publish_message(Message(content=msg, role="user")) 20 | tl = env.get_role("Mike") 21 | await tl.run() 22 | 23 | role = env.get_role("Alice") 24 | result = await role.run(msg) 25 | logger.info(result.content[:100]) 26 | 27 | 28 | if __name__ == "__main__": 29 | asyncio.run(main()) 30 | -------------------------------------------------------------------------------- /examples/write_design.py: -------------------------------------------------------------------------------- 1 | import asyncio 2 | 3 | from metagpt.environment.mgx.mgx_env import MGXEnv 4 | from metagpt.logs import logger 5 | from metagpt.roles.architect import Architect 6 | from metagpt.roles.di.team_leader import TeamLeader 7 | from metagpt.schema import Message 8 | 9 | 10 | async def main(): 11 | msg = "Write a TRD for a snake game" 12 | env = MGXEnv() 13 | env.add_roles([TeamLeader(), Architect()]) 14 | env.publish_message(Message(content=msg, role="user")) 15 | tl = env.get_role("Mike") 16 | await tl.run() 17 | 18 | role = env.get_role("Bob") 19 | result = await role.run(msg) 20 | logger.info(result) 21 | 22 | 23 | if __name__ == "__main__": 24 | asyncio.run(main()) 25 | -------------------------------------------------------------------------------- /examples/write_tutorial.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # _*_ coding: utf-8 _*_ 3 | 4 | """ 5 | @Time : 2023/9/4 21:40:57 6 | @Author : Stitch-z 7 | @File : tutorial_assistant.py 8 | """ 9 | 10 | import asyncio 11 | 12 | from metagpt.roles.tutorial_assistant import TutorialAssistant 13 | 14 | 15 | async def main(): 16 | topic = "Write a tutorial about MySQL" 17 | role = TutorialAssistant(language="Chinese") 18 | await role.run(topic) 19 | 20 | 21 | if __name__ == "__main__": 22 | asyncio.run(main()) 23 | -------------------------------------------------------------------------------- /metagpt/__init__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | # @Time : 2023/4/24 22:26 4 | # @Author : alexanderwu 5 | # @File : __init__.py 6 | 7 | from metagpt import _compat as _ # noqa: F401 8 | -------------------------------------------------------------------------------- /metagpt/actions/action_output.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # coding: utf-8 3 | """ 4 | @Time : 2023/7/11 10:03 5 | @Author : chengmaoyu 6 | @File : action_output 7 | """ 8 | 9 | from pydantic import BaseModel 10 | 11 | 12 | class ActionOutput: 13 | content: str 14 | instruct_content: BaseModel 15 | 16 | def __init__(self, content: str, instruct_content: BaseModel): 17 | self.content = content 18 | self.instruct_content = instruct_content 19 | -------------------------------------------------------------------------------- /metagpt/actions/add_requirement.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | """ 4 | @Time : 2023/5/20 17:46 5 | @Author : alexanderwu 6 | @File : add_requirement.py 7 | """ 8 | from metagpt.actions import Action 9 | 10 | 11 | class UserRequirement(Action): 12 | """User Requirement without any implementation details""" 13 | -------------------------------------------------------------------------------- /metagpt/actions/design_api_review.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | """ 4 | @Time : 2023/5/11 19:31 5 | @Author : alexanderwu 6 | @File : design_api_review.py 7 | """ 8 | 9 | from typing import Optional 10 | 11 | from metagpt.actions.action import Action 12 | 13 | 14 | class DesignReview(Action): 15 | name: str = "DesignReview" 16 | i_context: Optional[str] = None 17 | 18 | async def run(self, prd, api_design): 19 | prompt = ( 20 | f"Here is the Product Requirement Document (PRD):\n\n{prd}\n\nHere is the list of APIs designed " 21 | f"based on this PRD:\n\n{api_design}\n\nPlease review whether this API design meets the requirements" 22 | f" of the PRD, and whether it complies with good design practices." 23 | ) 24 | 25 | api_review = await self._aask(prompt) 26 | return api_review 27 | -------------------------------------------------------------------------------- /metagpt/actions/di/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FoundationAgents/MetaGPT/ba2868974b2ecc3fe4218ad29dd334867c07f678/metagpt/actions/di/__init__.py -------------------------------------------------------------------------------- /metagpt/actions/di/run_command.py: -------------------------------------------------------------------------------- 1 | from metagpt.actions import Action 2 | 3 | 4 | class RunCommand(Action): 5 | """A dummy RunCommand action used as a symbol only""" 6 | -------------------------------------------------------------------------------- /metagpt/actions/execute_task.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | """ 4 | @Time : 2023/9/13 12:26 5 | @Author : femto Zheng 6 | @File : execute_task.py 7 | """ 8 | 9 | 10 | from metagpt.actions import Action 11 | from metagpt.schema import Message 12 | 13 | 14 | class ExecuteTask(Action): 15 | name: str = "ExecuteTask" 16 | i_context: list[Message] = [] 17 | 18 | async def run(self, *args, **kwargs): 19 | pass 20 | -------------------------------------------------------------------------------- /metagpt/actions/fix_bug.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | @Time : 2023-12-12 4 | @Author : mashenquan 5 | @File : fix_bug.py 6 | """ 7 | from metagpt.actions import Action 8 | 9 | 10 | class FixBug(Action): 11 | """Fix bug action without any implementation details""" 12 | 13 | name: str = "FixBug" 14 | -------------------------------------------------------------------------------- /metagpt/actions/requirement_analysis/__init__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | """ 4 | @Time : 2024/6/13 5 | @Author : mashenquan 6 | @File : __init__.py 7 | @Desc : The implementation of RFC243. https://deepwisdom.feishu.cn/wiki/QobGwPkImijoyukBUKHcrYetnBb 8 | """ 9 | from metagpt.actions.requirement_analysis.evaluate_action import EvaluationData, EvaluateAction 10 | 11 | __all__ = [EvaluationData, EvaluateAction] 12 | -------------------------------------------------------------------------------- /metagpt/actions/requirement_analysis/requirement/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FoundationAgents/MetaGPT/ba2868974b2ecc3fe4218ad29dd334867c07f678/metagpt/actions/requirement_analysis/requirement/__init__.py -------------------------------------------------------------------------------- /metagpt/actions/requirement_analysis/trd/__init__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | """ 4 | @Time : 2024/6/13 5 | @Author : mashenquan 6 | @File : __init__.py 7 | @Desc : The implementation of RFC243. https://deepwisdom.feishu.cn/wiki/QobGwPkImijoyukBUKHcrYetnBb 8 | """ 9 | 10 | 11 | from metagpt.actions.requirement_analysis.trd.detect_interaction import DetectInteraction 12 | from metagpt.actions.requirement_analysis.trd.evaluate_trd import EvaluateTRD 13 | from metagpt.actions.requirement_analysis.trd.write_trd import WriteTRD 14 | from metagpt.actions.requirement_analysis.trd.compress_external_interfaces import CompressExternalInterfaces 15 | 16 | __all__ = [CompressExternalInterfaces, DetectInteraction, WriteTRD, EvaluateTRD] 17 | -------------------------------------------------------------------------------- /metagpt/base/__init__.py: -------------------------------------------------------------------------------- 1 | from metagpt.base.base_env import BaseEnvironment 2 | from metagpt.base.base_role import BaseRole 3 | 4 | 5 | __all__ = [ 6 | "BaseEnvironment", 7 | "BaseRole", 8 | ] 9 | -------------------------------------------------------------------------------- /metagpt/configs/__init__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | """ 4 | @Time : 2024/1/4 16:33 5 | @Author : alexanderwu 6 | @File : __init__.py 7 | """ 8 | -------------------------------------------------------------------------------- /metagpt/configs/mermaid_config.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | """ 4 | @Time : 2024/1/4 19:07 5 | @Author : alexanderwu 6 | @File : mermaid_config.py 7 | """ 8 | from typing import Literal 9 | 10 | from metagpt.utils.yaml_model import YamlModel 11 | 12 | 13 | class MermaidConfig(YamlModel): 14 | """Config for Mermaid""" 15 | 16 | engine: Literal["nodejs", "ink", "playwright", "pyppeteer", "none"] = "nodejs" 17 | path: str = "mmdc" # mmdc 18 | puppeteer_config: str = "" 19 | pyppeteer_path: str = "/usr/bin/google-chrome-stable" 20 | -------------------------------------------------------------------------------- /metagpt/configs/omniparse_config.py: -------------------------------------------------------------------------------- 1 | from metagpt.utils.yaml_model import YamlModel 2 | 3 | 4 | class OmniParseConfig(YamlModel): 5 | api_key: str = "" 6 | base_url: str = "" 7 | timeout: int = 600 8 | -------------------------------------------------------------------------------- /metagpt/configs/redis_config.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | """ 4 | @Time : 2024/1/4 19:06 5 | @Author : alexanderwu 6 | @File : redis_config.py 7 | """ 8 | from metagpt.utils.yaml_model import YamlModelWithoutDefault 9 | 10 | 11 | class RedisConfig(YamlModelWithoutDefault): 12 | host: str 13 | port: int 14 | username: str = "" 15 | password: str 16 | db: str 17 | 18 | def to_url(self): 19 | return f"redis://{self.host}:{self.port}" 20 | 21 | def to_kwargs(self): 22 | return { 23 | "username": self.username, 24 | "password": self.password, 25 | "db": self.db, 26 | } 27 | -------------------------------------------------------------------------------- /metagpt/configs/role_custom_config.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | """ 4 | @Time : 2024/4/22 16:33 5 | @Author : Justin 6 | @File : role_custom_config.py 7 | """ 8 | from metagpt.configs.llm_config import LLMConfig 9 | from metagpt.utils.yaml_model import YamlModel 10 | 11 | 12 | class RoleCustomConfig(YamlModel): 13 | """custom config for roles 14 | role: role's className or role's role_id 15 | To be expanded 16 | """ 17 | 18 | role: str = "" 19 | llm: LLMConfig 20 | -------------------------------------------------------------------------------- /metagpt/configs/role_zero_config.py: -------------------------------------------------------------------------------- 1 | from pydantic import Field 2 | 3 | from metagpt.utils.yaml_model import YamlModel 4 | 5 | 6 | class RoleZeroConfig(YamlModel): 7 | enable_longterm_memory: bool = Field(default=False, description="Whether to use long-term memory.") 8 | longterm_memory_persist_path: str = Field(default=".role_memory_data", description="The directory to save data.") 9 | memory_k: int = Field(default=200, description="The capacity of short-term memory.") 10 | similarity_top_k: int = Field(default=5, description="The number of long-term memories to retrieve.") 11 | use_llm_ranker: bool = Field(default=False, description="Whether to use LLM Reranker to get better result.") 12 | -------------------------------------------------------------------------------- /metagpt/configs/s3_config.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | """ 4 | @Time : 2024/1/4 19:07 5 | @Author : alexanderwu 6 | @File : s3_config.py 7 | """ 8 | from metagpt.utils.yaml_model import YamlModelWithoutDefault 9 | 10 | 11 | class S3Config(YamlModelWithoutDefault): 12 | access_key: str 13 | secret_key: str 14 | endpoint: str 15 | bucket: str 16 | -------------------------------------------------------------------------------- /metagpt/document_store/__init__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | """ 4 | @Time : 2023/5/25 10:20 5 | @Author : alexanderwu 6 | @File : __init__.py 7 | """ 8 | 9 | from metagpt.document_store.faiss_store import FaissStore 10 | 11 | __all__ = ["FaissStore"] 12 | -------------------------------------------------------------------------------- /metagpt/environment/__init__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | # @Desc : 4 | 5 | from metagpt.environment.base_env import Environment 6 | 7 | # from metagpt.environment.android.android_env import AndroidEnv 8 | from metagpt.environment.werewolf.werewolf_env import WerewolfEnv 9 | from metagpt.environment.stanford_town.stanford_town_env import StanfordTownEnv 10 | from metagpt.environment.software.software_env import SoftwareEnv 11 | 12 | 13 | __all__ = ["AndroidEnv", "WerewolfEnv", "StanfordTownEnv", "SoftwareEnv", "Environment"] 14 | -------------------------------------------------------------------------------- /metagpt/environment/android/__init__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | # @Desc : 4 | -------------------------------------------------------------------------------- /metagpt/environment/android/android_env.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | # @Desc : MG Android Env 4 | 5 | from pydantic import Field 6 | 7 | from metagpt.environment.android.android_ext_env import AndroidExtEnv 8 | from metagpt.environment.base_env import Environment 9 | 10 | 11 | class AndroidEnv(AndroidExtEnv, Environment): 12 | """in order to use actual `reset`&`observe`, inherited order: AndroidExtEnv, Environment""" 13 | 14 | rows: int = Field(default=0, description="rows of a grid on the screenshot") 15 | cols: int = Field(default=0, description="cols of a grid on the screenshot") 16 | -------------------------------------------------------------------------------- /metagpt/environment/android/const.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | # @Desc : 4 | 5 | # For Android Assistant Agent 6 | ADB_EXEC_FAIL = "FAILED" 7 | -------------------------------------------------------------------------------- /metagpt/environment/api/__init__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | # @Desc : 4 | -------------------------------------------------------------------------------- /metagpt/environment/mgx/__init__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | # @Desc : 4 | -------------------------------------------------------------------------------- /metagpt/environment/minecraft/__init__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | # @Desc : 4 | -------------------------------------------------------------------------------- /metagpt/environment/minecraft/mineflayer/.gitignore: -------------------------------------------------------------------------------- 1 | !/lib -------------------------------------------------------------------------------- /metagpt/environment/minecraft/mineflayer/.prettierignore: -------------------------------------------------------------------------------- 1 | # Ignore artifacts: 2 | build 3 | coverage -------------------------------------------------------------------------------- /metagpt/environment/minecraft/mineflayer/.prettierrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "tabWidth": 4 3 | } 4 | -------------------------------------------------------------------------------- /metagpt/environment/minecraft/mineflayer/lib/observation/onChat.js: -------------------------------------------------------------------------------- 1 | const Observation = require("./base.js").Observation; 2 | 3 | class onChat extends Observation { 4 | constructor(bot) { 5 | super(bot); 6 | this.name = "onChat"; 7 | this.obs = ""; 8 | bot.on("chatEvent", (username, message) => { 9 | // Save entity status to local variable 10 | if (message.startsWith("/")) { 11 | return; 12 | } 13 | 14 | this.obs += message; 15 | this.bot.event(this.name); 16 | }); 17 | } 18 | 19 | observe() { 20 | const result = this.obs; 21 | this.obs = ""; 22 | return result; 23 | } 24 | } 25 | 26 | module.exports = onChat; 27 | -------------------------------------------------------------------------------- /metagpt/environment/minecraft/mineflayer/lib/observation/onError.js: -------------------------------------------------------------------------------- 1 | const Observation = require("./base.js").Observation; 2 | 3 | class onError extends Observation { 4 | constructor(bot) { 5 | super(bot); 6 | this.name = "onError"; 7 | this.obs = null; 8 | bot.on("error", (err) => { 9 | // Save entity status to local variable 10 | this.obs = err; 11 | this.bot.event(this.name); 12 | }); 13 | } 14 | 15 | observe() { 16 | const result = this.obs; 17 | this.obs = null; 18 | return result; 19 | } 20 | } 21 | 22 | module.exports = onError; 23 | -------------------------------------------------------------------------------- /metagpt/environment/minecraft/mineflayer/lib/observation/onSave.js: -------------------------------------------------------------------------------- 1 | const Observation = require("./base.js").Observation; 2 | 3 | class onSave extends Observation { 4 | constructor(bot) { 5 | super(bot); 6 | this.name = "onSave"; 7 | this.obs = null; 8 | bot.on("save", (eventName) => { 9 | // Save entity status to local variable 10 | this.obs = eventName; 11 | this.bot.event(this.name); 12 | }); 13 | } 14 | 15 | observe() { 16 | const result = this.obs; 17 | this.obs = null; 18 | return result; 19 | } 20 | } 21 | 22 | module.exports = onSave; 23 | -------------------------------------------------------------------------------- /metagpt/environment/minecraft/mineflayer/lib/utils.js: -------------------------------------------------------------------------------- 1 | let gameTimeCounter = 0; 2 | let gameTimeList = []; 3 | const initCounter = (bot) => { 4 | gameTimeList = []; 5 | for (let i = 0; i < 13000; i += 1000) { 6 | gameTimeList.push(i); 7 | } 8 | for (let i = 13000; i < 24000; i += 2000) { 9 | gameTimeList.push(i); 10 | } 11 | const timeOfDay = bot.time.timeOfDay; 12 | for (let i = 0; i < gameTimeList.length; i++) { 13 | if (gameTimeList[i] > timeOfDay) { 14 | gameTimeCounter = i - 1; 15 | break; 16 | } 17 | } 18 | }; 19 | 20 | const getNextTime = () => { 21 | gameTimeCounter++; 22 | if (gameTimeCounter >= gameTimeList.length) { 23 | gameTimeCounter = 0; 24 | } 25 | return gameTimeList[gameTimeCounter]; 26 | }; 27 | 28 | module.exports = { 29 | initCounter, 30 | getNextTime, 31 | }; 32 | -------------------------------------------------------------------------------- /metagpt/environment/minecraft/mineflayer/mineflayer-collectblock/_config.yml: -------------------------------------------------------------------------------- 1 | theme: jekyll-theme-cayman -------------------------------------------------------------------------------- /metagpt/environment/minecraft/mineflayer/mineflayer-collectblock/src/Util.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Creates a new error object with the given type and message. 3 | * 4 | * @param type - The error type. 5 | * @param message - The error message. 6 | * 7 | * @returns The error object. 8 | */ 9 | export function error (type: string, message: string): Error { 10 | const e = new Error(message) 11 | e.name = type 12 | return e 13 | } 14 | -------------------------------------------------------------------------------- /metagpt/environment/minecraft/mineflayer/mineflayer-collectblock/src/index.ts: -------------------------------------------------------------------------------- 1 | import { Bot } from 'mineflayer' 2 | import { CollectBlock } from './CollectBlock' 3 | import { pathfinder as pathfinderPlugin } from 'mineflayer-pathfinder' 4 | import { plugin as toolPlugin } from 'mineflayer-tool' 5 | 6 | export function plugin (bot: Bot): void { 7 | // @ts-expect-error 8 | bot.collectBlock = new CollectBlock(bot) 9 | 10 | // Load plugins if not loaded manually. 11 | setTimeout(() => loadPathfinderPlugin(bot), 0) 12 | setTimeout(() => loadToolPlugin(bot), 0) 13 | } 14 | 15 | function loadPathfinderPlugin (bot: Bot): void { 16 | if (bot.pathfinder != null) return 17 | bot.loadPlugin(pathfinderPlugin) 18 | } 19 | 20 | function loadToolPlugin (bot: Bot): void { 21 | if (bot.tool != null) return 22 | bot.loadPlugin(toolPlugin) 23 | } 24 | 25 | export { CollectBlock, Callback, CollectOptions } from './CollectBlock' 26 | -------------------------------------------------------------------------------- /metagpt/environment/software/__init__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | # @Desc : 4 | -------------------------------------------------------------------------------- /metagpt/environment/software/software_env.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | # @Desc : MG Software Env 4 | 5 | 6 | from metagpt.environment.base_env import Environment 7 | 8 | 9 | class SoftwareEnv(Environment): 10 | """a specific alias name""" 11 | 12 | pass 13 | -------------------------------------------------------------------------------- /metagpt/environment/stanford_town/__init__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | # @Desc : 4 | -------------------------------------------------------------------------------- /metagpt/environment/stanford_town/stanford_town_env.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | # @Desc : MG StanfordTown Env 4 | 5 | from metagpt.environment.base_env import Environment 6 | from metagpt.environment.stanford_town.stanford_town_ext_env import StanfordTownExtEnv 7 | 8 | 9 | class StanfordTownEnv(StanfordTownExtEnv, Environment): 10 | pass 11 | -------------------------------------------------------------------------------- /metagpt/environment/werewolf/__init__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | # @Desc : 4 | -------------------------------------------------------------------------------- /metagpt/exp_pool/__init__.py: -------------------------------------------------------------------------------- 1 | """Experience pool init.""" 2 | 3 | from metagpt.exp_pool.manager import get_exp_manager 4 | from metagpt.exp_pool.decorator import exp_cache 5 | 6 | __all__ = ["get_exp_manager", "exp_cache"] 7 | -------------------------------------------------------------------------------- /metagpt/exp_pool/context_builders/__init__.py: -------------------------------------------------------------------------------- 1 | """Context builders init.""" 2 | 3 | from metagpt.exp_pool.context_builders.base import BaseContextBuilder 4 | from metagpt.exp_pool.context_builders.simple import SimpleContextBuilder 5 | from metagpt.exp_pool.context_builders.role_zero import RoleZeroContextBuilder 6 | 7 | __all__ = ["BaseContextBuilder", "SimpleContextBuilder", "RoleZeroContextBuilder"] 8 | -------------------------------------------------------------------------------- /metagpt/exp_pool/context_builders/action_node.py: -------------------------------------------------------------------------------- 1 | """Action Node context builder.""" 2 | 3 | from typing import Any 4 | 5 | from metagpt.exp_pool.context_builders.base import BaseContextBuilder 6 | 7 | ACTION_NODE_CONTEXT_TEMPLATE = """ 8 | {req} 9 | 10 | ### Experiences 11 | ----- 12 | {exps} 13 | ----- 14 | 15 | ## Instruction 16 | Consider **Experiences** to generate a better answer. 17 | """ 18 | 19 | 20 | class ActionNodeContextBuilder(BaseContextBuilder): 21 | async def build(self, req: Any) -> str: 22 | """Builds the action node context string. 23 | 24 | If there are no experiences, returns the original `req`; 25 | otherwise returns context with `req` and formatted experiences. 26 | """ 27 | 28 | exps = self.format_exps() 29 | 30 | return ACTION_NODE_CONTEXT_TEMPLATE.format(req=req, exps=exps) if exps else req 31 | -------------------------------------------------------------------------------- /metagpt/exp_pool/context_builders/simple.py: -------------------------------------------------------------------------------- 1 | """Simple context builder.""" 2 | 3 | 4 | from typing import Any 5 | 6 | from metagpt.exp_pool.context_builders.base import BaseContextBuilder 7 | 8 | SIMPLE_CONTEXT_TEMPLATE = """ 9 | ## Context 10 | 11 | ### Experiences 12 | ----- 13 | {exps} 14 | ----- 15 | 16 | ## User Requirement 17 | {req} 18 | 19 | ## Instruction 20 | Consider **Experiences** to generate a better answer. 21 | """ 22 | 23 | 24 | class SimpleContextBuilder(BaseContextBuilder): 25 | async def build(self, req: Any) -> str: 26 | return SIMPLE_CONTEXT_TEMPLATE.format(req=req, exps=self.format_exps()) 27 | -------------------------------------------------------------------------------- /metagpt/exp_pool/perfect_judges/__init__.py: -------------------------------------------------------------------------------- 1 | """Perfect judges init.""" 2 | 3 | from metagpt.exp_pool.perfect_judges.base import BasePerfectJudge 4 | from metagpt.exp_pool.perfect_judges.simple import SimplePerfectJudge 5 | 6 | __all__ = ["BasePerfectJudge", "SimplePerfectJudge"] 7 | -------------------------------------------------------------------------------- /metagpt/exp_pool/perfect_judges/base.py: -------------------------------------------------------------------------------- 1 | """Base perfect judge.""" 2 | 3 | from abc import ABC, abstractmethod 4 | 5 | from pydantic import BaseModel, ConfigDict 6 | 7 | from metagpt.exp_pool.schema import Experience 8 | 9 | 10 | class BasePerfectJudge(BaseModel, ABC): 11 | model_config = ConfigDict(arbitrary_types_allowed=True) 12 | 13 | @abstractmethod 14 | async def is_perfect_exp(self, exp: Experience, serialized_req: str, *args, **kwargs) -> bool: 15 | """Determine whether the experience is perfect. 16 | 17 | Args: 18 | exp (Experience): The experience to evaluate. 19 | serialized_req (str): The serialized request to compare against the experience's request. 20 | """ 21 | -------------------------------------------------------------------------------- /metagpt/exp_pool/scorers/__init__.py: -------------------------------------------------------------------------------- 1 | """Scorers init.""" 2 | 3 | from metagpt.exp_pool.scorers.base import BaseScorer 4 | from metagpt.exp_pool.scorers.simple import SimpleScorer 5 | 6 | __all__ = ["BaseScorer", "SimpleScorer"] 7 | -------------------------------------------------------------------------------- /metagpt/exp_pool/scorers/base.py: -------------------------------------------------------------------------------- 1 | """Base scorer.""" 2 | 3 | from abc import ABC, abstractmethod 4 | 5 | from pydantic import BaseModel, ConfigDict 6 | 7 | from metagpt.exp_pool.schema import Score 8 | 9 | 10 | class BaseScorer(BaseModel, ABC): 11 | model_config = ConfigDict(arbitrary_types_allowed=True) 12 | 13 | @abstractmethod 14 | async def evaluate(self, req: str, resp: str) -> Score: 15 | """Evaluates the quality of a response relative to a given request.""" 16 | -------------------------------------------------------------------------------- /metagpt/exp_pool/serializers/__init__.py: -------------------------------------------------------------------------------- 1 | """Serializers init.""" 2 | 3 | from metagpt.exp_pool.serializers.base import BaseSerializer 4 | from metagpt.exp_pool.serializers.simple import SimpleSerializer 5 | from metagpt.exp_pool.serializers.action_node import ActionNodeSerializer 6 | from metagpt.exp_pool.serializers.role_zero import RoleZeroSerializer 7 | 8 | 9 | __all__ = ["BaseSerializer", "SimpleSerializer", "ActionNodeSerializer", "RoleZeroSerializer"] 10 | -------------------------------------------------------------------------------- /metagpt/exp_pool/serializers/simple.py: -------------------------------------------------------------------------------- 1 | """Simple Serializer.""" 2 | 3 | from typing import Any 4 | 5 | from metagpt.exp_pool.serializers.base import BaseSerializer 6 | 7 | 8 | class SimpleSerializer(BaseSerializer): 9 | def serialize_req(self, **kwargs) -> str: 10 | """Just use `str` to convert the request object into a string.""" 11 | 12 | return str(kwargs.get("req", "")) 13 | 14 | def serialize_resp(self, resp: Any) -> str: 15 | """Just use `str` to convert the response object into a string.""" 16 | 17 | return str(resp) 18 | 19 | def deserialize_resp(self, resp: str) -> Any: 20 | """Just return the string response as it is.""" 21 | 22 | return resp 23 | -------------------------------------------------------------------------------- /metagpt/ext/__init__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | # @Desc : 4 | -------------------------------------------------------------------------------- /metagpt/ext/aflow/scripts/optimized/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FoundationAgents/MetaGPT/ba2868974b2ecc3fe4218ad29dd334867c07f678/metagpt/ext/aflow/scripts/optimized/__init__.py -------------------------------------------------------------------------------- /metagpt/ext/aflow/scripts/workflow.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # @Date : 6/27/2024 22:07 PM 3 | # @Author : didi 4 | # @Desc : Basic Graph Class 5 | 6 | 7 | from metagpt.ext.aflow.scripts.evaluator import DatasetType 8 | from metagpt.provider.llm_provider_registry import create_llm_instance 9 | from metagpt.utils.cost_manager import CostManager 10 | 11 | 12 | class Workflow: 13 | def __init__( 14 | self, 15 | name: str, 16 | llm_config, 17 | dataset: DatasetType, 18 | ) -> None: 19 | self.name = name 20 | self.dataset = dataset 21 | self.llm = create_llm_instance(llm_config) 22 | self.llm.cost_manager = CostManager() 23 | 24 | async def __call__(self, problem: str): 25 | """ 26 | Implementation of the workflow 27 | """ 28 | raise NotImplementedError("This method should be implemented by the subclass") 29 | -------------------------------------------------------------------------------- /metagpt/ext/android_assistant/__init__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | # @Desc : 4 | -------------------------------------------------------------------------------- /metagpt/ext/android_assistant/actions/__init__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | # @Desc : 4 | -------------------------------------------------------------------------------- /metagpt/ext/android_assistant/actions/self_learn_reflect_an.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | # @Desc : the ActionNode to parse Reflection 4 | 5 | from metagpt.actions.action_node import ActionNode 6 | 7 | DECISION = ActionNode( 8 | key="Decision", expected_type=str, instruction="explain why you made this decision", example="BACK" 9 | ) 10 | 11 | 12 | THOUGHT = ActionNode(key="Thought", expected_type=str, instruction="explain why you made this decision", example="") 13 | 14 | 15 | DOCUMENTATION = ActionNode( 16 | key="Documentation", expected_type=str, instruction="describe the function of the UI element", example="" 17 | ) 18 | 19 | 20 | NODES = [DECISION, THOUGHT, DOCUMENTATION] 21 | SELF_LEARN_REFLECT_NODE = ActionNode.from_children("SelfLearnReflect", NODES) 22 | -------------------------------------------------------------------------------- /metagpt/ext/android_assistant/prompts/__init__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | # @Desc : 4 | -------------------------------------------------------------------------------- /metagpt/ext/android_assistant/roles/__init__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | # @Desc : 4 | -------------------------------------------------------------------------------- /metagpt/ext/android_assistant/utils/__init__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | # @Desc : 4 | -------------------------------------------------------------------------------- /metagpt/ext/cr/__init__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | # @Desc : 4 | -------------------------------------------------------------------------------- /metagpt/ext/cr/actions/__init__.py: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /metagpt/ext/cr/utils/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FoundationAgents/MetaGPT/ba2868974b2ecc3fe4218ad29dd334867c07f678/metagpt/ext/cr/utils/__init__.py -------------------------------------------------------------------------------- /metagpt/ext/sela/data.yaml: -------------------------------------------------------------------------------- 1 | datasets_dir: "path/to/datasets" # path to the datasets directory 2 | work_dir: ../../../workspace # path to the workspace directory 3 | role_dir: storage/SELA # path to the role directory -------------------------------------------------------------------------------- /metagpt/ext/sela/insights/fixed_insights.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "Analysis": "Use early stopping, hyperparameter tuning, and cross-validation to avoid overfitting and improve robustness of the model.", 4 | "Category": "Model Training", 5 | "task_id": 4 6 | }, 7 | { 8 | "Analysis": "use k-fold bagging and early stopping", 9 | "Category": "Model Training", 10 | "task_id": 4 11 | }, 12 | { 13 | "Analysis": "To avoid overfitting, train a weighted ensemble model such as StackingClassifier or StackingRegressor; You could do some quick model prototyping to see which models work best and then use them in the ensemble.", 14 | "Category": "Model Training", 15 | "task_id": 4 16 | }, 17 | { 18 | "Analysis": "Please use autogluon for model training with presets='medium_quality', time_limit=None, give dev dataset to tuning_data, and use right eval_metric.", 19 | "Category": "Model Training", 20 | "task_id": 4 21 | } 22 | ] -------------------------------------------------------------------------------- /metagpt/ext/sela/requirements.txt: -------------------------------------------------------------------------------- 1 | # expo 2 | openml==0.14.2 3 | # ml module to run in DI 4 | xgboost 5 | catboost 6 | lightgbm 7 | -------------------------------------------------------------------------------- /metagpt/ext/sela/runner/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FoundationAgents/MetaGPT/ba2868974b2ecc3fe4218ad29dd334867c07f678/metagpt/ext/sela/runner/__init__.py -------------------------------------------------------------------------------- /metagpt/ext/sela/scripts/run_cls.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | tasks=("smoker-status" "software-defects" "jasmine" "credit-g" "Click_prediction_small" "kick" "kc1" "titanic" "icr" "wine-quality-white" "mfeat-factors" "segment" "GesturePhaseSegmentationProcessed") 4 | 5 | 6 | for i in {1..3} 7 | do 8 | for task in "${tasks[@]}"; do 9 | echo "Running experiment for task: $task" 10 | python run_experiment.py --exp_mode mcts --task "$task" --rollouts 10 --special_instruction stacking 11 | echo "Experiment for task $task completed." 12 | done 13 | done 14 | 15 | echo "All experiments completed." 16 | -------------------------------------------------------------------------------- /metagpt/ext/sela/scripts/run_cls_mod.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | tasks=("banking77" "gnad10" "sms_spam" "oxford-iiit-pet" "stanford_cars" "fashion_mnist" ) 4 | 5 | for i in {1..3} 6 | do 7 | for task in "${tasks[@]}"; do 8 | echo "Running experiment for task: $task" 9 | python run_experiment.py --exp_mode mcts --task "$task" --rollouts 10 10 | echo "Experiment for task $task completed." 11 | done 12 | done 13 | echo "All experiments completed." 14 | -------------------------------------------------------------------------------- /metagpt/ext/sela/scripts/run_reg.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | tasks=("concrete-strength" "Moneyball" "colleges" "SAT11-HAND-runtime-regression" "diamonds" "boston" "house-prices") 4 | 5 | for i in {1..3} 6 | do 7 | for task in "${tasks[@]}"; do 8 | echo "Running experiment for task: $task" 9 | python run_experiment.py --exp_mode mcts --task "$task" --rollouts 10 --low_is_better --special_instruction stacking 10 | echo "Experiment for task $task completed." 11 | done 12 | done 13 | 14 | echo "All experiments completed." 15 | -------------------------------------------------------------------------------- /metagpt/ext/spo/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FoundationAgents/MetaGPT/ba2868974b2ecc3fe4218ad29dd334867c07f678/metagpt/ext/spo/__init__.py -------------------------------------------------------------------------------- /metagpt/ext/spo/components/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FoundationAgents/MetaGPT/ba2868974b2ecc3fe4218ad29dd334867c07f678/metagpt/ext/spo/components/__init__.py -------------------------------------------------------------------------------- /metagpt/ext/spo/prompts/evaluate_prompt.py: -------------------------------------------------------------------------------- 1 | EVALUATE_PROMPT = """ 2 | Based on the original requirements, evaluate the two responses, A and B, and determine which one better meets the requirements. If a reference answer is provided, strictly follow the format/content of the reference answer. 3 | 4 | # Requirement 5 | {requirement} 6 | 7 | # A 8 | {sample} 9 | 10 | # B 11 | {new_sample} 12 | 13 | # Golden answer 14 | {answers} 15 | 16 | Provide your analysis and the choice you believe is better, using XML tags to encapsulate your response. 17 | 18 | Some analysis 19 | A/B (the better answer in your opinion) 20 | """ 21 | -------------------------------------------------------------------------------- /metagpt/ext/spo/settings/Poem.yaml: -------------------------------------------------------------------------------- 1 | prompt: | 2 | Create poetry in the requested style and format. 3 | 4 | requirements: | 5 | None 6 | 7 | count: None 8 | 9 | qa: 10 | - question: | 11 | Write a modern sonnet about climate change 12 | answer: | 13 | None 14 | 15 | - question: | 16 | Create a haiku series about New York City 17 | answer: | 18 | None 19 | 20 | - question: | 21 | Write a free verse poem about social media 22 | answer: | 23 | None 24 | -------------------------------------------------------------------------------- /metagpt/ext/spo/utils/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FoundationAgents/MetaGPT/ba2868974b2ecc3fe4218ad29dd334867c07f678/metagpt/ext/spo/utils/__init__.py -------------------------------------------------------------------------------- /metagpt/ext/stanford_town/__init__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | # @Desc : stanford town implement 4 | -------------------------------------------------------------------------------- /metagpt/ext/stanford_town/actions/__init__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | # @Desc : 4 | -------------------------------------------------------------------------------- /metagpt/ext/stanford_town/actions/dummy_action.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | # @Desc : dummy action to make every STRole can deal DummyMessage which is caused by DummyAction 4 | 5 | from metagpt.actions import Action 6 | from metagpt.schema import Message 7 | 8 | 9 | class DummyAction(Action): 10 | async def run(self, *args, **kwargs): 11 | raise NotImplementedError 12 | 13 | 14 | class DummyMessage(Message): 15 | """ 16 | dummy message to pass to role and make them to have a execution every round 17 | """ 18 | 19 | content: str = "dummy" 20 | cause_by: str = "DummyAction" 21 | -------------------------------------------------------------------------------- /metagpt/ext/stanford_town/memory/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FoundationAgents/MetaGPT/ba2868974b2ecc3fe4218ad29dd334867c07f678/metagpt/ext/stanford_town/memory/__init__.py -------------------------------------------------------------------------------- /metagpt/ext/stanford_town/plan/__init__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | # @Desc : 4 | -------------------------------------------------------------------------------- /metagpt/ext/stanford_town/prompts/__init__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | # @Desc : stanford town prompt templates 4 | -------------------------------------------------------------------------------- /metagpt/ext/stanford_town/prompts/daily_planning_v6.txt: -------------------------------------------------------------------------------- 1 | daily_planning_v6.txt 2 | 3 | Variables: 4 | !! -- Commonset 5 | !! -- Lifestyle 6 | !! -- Reverie date time now 7 | !! -- Persona first names 8 | !! -- wake_up_hour 9 | 10 | ### 11 | !! 12 | 13 | In general, !! 14 | Today is !!. Here is !!'s plan today in broad-strokes (with the time of the day. e.g., have a lunch at 12:00 pm, watch TV from 7 to 8 pm): 1) wake up and complete the morning routine at !!, 2) -------------------------------------------------------------------------------- /metagpt/ext/stanford_town/prompts/decide_to_talk_v2.txt: -------------------------------------------------------------------------------- 1 | decide_to_talk_v1.txt 2 | 3 | ### 4 | Task -- given context, determine whether the subject will initiate a conversation with another. 5 | Format: 6 | Context: [] 7 | Question: [] 8 | Reasoning: [] 9 | Answer in "yes" or "no": [] 10 | --- 11 | Context: !! 12 | Right now, it is !!. !! and !! last chatted at !! about !!. 13 | !! 14 | !! 15 | 16 | Question: Would !! initiate a conversation with !!? 17 | 18 | Reasoning: Let's think step by step. -------------------------------------------------------------------------------- /metagpt/ext/stanford_town/prompts/generate_focal_pt_v1.txt: -------------------------------------------------------------------------------- 1 | generate_focal_pt_v1.txt 2 | 3 | Variables: 4 | !! -- Event/thought statements 5 | !! -- Count 6 | 7 | ### 8 | !! 9 | 10 | Given only the information above, what are !! most salient high-level questions we can answer about the subjects grounded in the statements? 11 | 1) -------------------------------------------------------------------------------- /metagpt/ext/stanford_town/prompts/generate_hourly_schedule_v2.txt: -------------------------------------------------------------------------------- 1 | generate_hourly_schedule_v2.txt 2 | 3 | Variables: 4 | !! -- Schedule format 5 | !! -- Commonset 6 | !! -- prior_schedule 7 | !! -- intermission_str 8 | !! -- intermission 2 9 | !! -- prompt_ending 10 | 11 | ### 12 | Hourly schedule format: 13 | !! 14 | === 15 | !! 16 | !! 17 | !!!! 18 | !! -------------------------------------------------------------------------------- /metagpt/ext/stanford_town/prompts/generate_obj_event_v1.txt: -------------------------------------------------------------------------------- 1 | generate_obj_event_v1.txt 2 | 3 | Variables: 4 | !! -- Object name 5 | !! -- Persona name 6 | !! -- Persona action event description 7 | !! -- Object name 8 | !! -- Object name 9 | 10 | ### 11 | Task: We want to understand the state of an object that is being used by someone. 12 | 13 | Let's think step by step. 14 | We want to know about !!'s state. 15 | Step 1. !! is at/using the !!. 16 | Step 2. Describe the !!'s state: !! is -------------------------------------------------------------------------------- /metagpt/ext/stanford_town/prompts/generate_pronunciatio_v1.txt: -------------------------------------------------------------------------------- 1 | generate_pronunciatio_v1.txt 2 | 3 | Variables: 4 | !! -- Action description 5 | 6 | ### 7 | Convert an action description to an emoji (important: use two or less emojis). 8 | 9 | Action description: !! 10 | Emoji: -------------------------------------------------------------------------------- /metagpt/ext/stanford_town/prompts/insight_and_evidence_v1.txt: -------------------------------------------------------------------------------- 1 | insight_and_evidence_v1.txt 2 | 3 | Variables: 4 | !! -- Numbered list of event/thought statements 5 | !! -- target persona name or "the conversation" 6 | 7 | ### 8 | Input: 9 | !! 10 | 11 | What !! high-level insights can you infer from the above statements? Please ensure it includes 'because of' and generates according to the example format.(example format: insight (because of 1, 5, 3)) . 12 | 1. -------------------------------------------------------------------------------- /metagpt/ext/stanford_town/prompts/memo_on_convo_v1.txt: -------------------------------------------------------------------------------- 1 | memo_on_convo_v1.txt 2 | 3 | Variables: 4 | !! -- All convo utterances 5 | !! -- persona name 6 | !! -- persona name 7 | !! -- persona name 8 | 9 | ### 10 | [Conversation] 11 | !! 12 | 13 | Write down if there is anything from the conversation that !! might have found interesting from !!'s perspective, in a full sentence. 14 | 15 | "!! -------------------------------------------------------------------------------- /metagpt/ext/stanford_town/prompts/new_decomp_schedule_v1.txt: -------------------------------------------------------------------------------- 1 | new_decomp_schedule_v1.txt 2 | 3 | Variables: 4 | !! -- persona name 5 | !! -- start hour 6 | !! -- end hour 7 | !! -- original plan 8 | !! -- persona name 9 | !! -- new event 10 | !! -- new event duration 11 | !! -- persona name 12 | !! -- start hour 13 | !! -- end hour 14 | !! -- end hour 15 | !! -- new schedule init 16 | 17 | 18 | ### 19 | Here was !!'s originally planned schedule from !! to !!. 20 | !! 21 | 22 | But !! unexpectedly ended up !! for !! minutes. Revise !!'s schedule from !! to !! accordingly (it has to end by !!). 23 | The revised schedule: 24 | !! -------------------------------------------------------------------------------- /metagpt/ext/stanford_town/prompts/planning_thought_on_convo_v1.txt: -------------------------------------------------------------------------------- 1 | planning_thought_on_convo_v1.txt 2 | 3 | Variables: 4 | !! -- All convo utterances 5 | !! -- persona name 6 | !! -- persona name 7 | !! -- persona name 8 | 9 | ### 10 | [Conversation] 11 | !! 12 | 13 | Write down if there is anything from the conversation that !! need to remember for her planning, from !!'s perspective, in a full sentence. 14 | 15 | "!! -------------------------------------------------------------------------------- /metagpt/ext/stanford_town/prompts/poignancy_action_v1.txt: -------------------------------------------------------------------------------- 1 | poignancy_event_v1.txt 2 | 3 | !!: agent name 4 | !!: iss 5 | !!: name 6 | !!: event description 7 | 8 | ### 9 | Here is a brief description of !!. 10 | !! 11 | 12 | On the scale of 1 to 10, where 1 is purely mundane (e.g., brushing teeth, making bed) and 10 is extremely poignant (e.g., a break up, college acceptance), rate the likely poignancy of the following event for !!. 13 | 14 | Event: !! 15 | Rate (return a number between 1 to 10): -------------------------------------------------------------------------------- /metagpt/ext/stanford_town/prompts/poignancy_chat_v1.txt: -------------------------------------------------------------------------------- 1 | poignancy_chat_v1.txt 2 | 3 | !!: agent name 4 | !!: iss 5 | !!: name 6 | !!: event description 7 | 8 | ### 9 | Here is a brief description of !!. 10 | !! 11 | 12 | On the scale of 1 to 10, where 1 is purely mundane (e.g., routine morning greetings) and 10 is extremely poignant (e.g., a conversation about breaking up, a fight), rate the likely poignancy of the following conversation for !!. 13 | 14 | Conversation: 15 | !! 16 | 17 | Rate (return a number between 1 to 10): -------------------------------------------------------------------------------- /metagpt/ext/stanford_town/prompts/poignancy_event_v1.txt: -------------------------------------------------------------------------------- 1 | poignancy_event_v1.txt 2 | 3 | !!: agent name 4 | !!: iss 5 | !!: name 6 | !!: event description 7 | 8 | ### 9 | Here is a brief description of !!. 10 | !! 11 | 12 | On the scale of 1 to 10, where 1 is purely mundane (e.g., brushing teeth, making bed) and 10 is extremely poignant (e.g., a break up, college acceptance), rate the likely poignancy of the following event for !!. 13 | 14 | Event: !! 15 | Rate (return a number between 1 to 10): -------------------------------------------------------------------------------- /metagpt/ext/stanford_town/prompts/poignancy_thought_v1.txt: -------------------------------------------------------------------------------- 1 | poignancy_thought_v1.txt 2 | 3 | !!: agent name 4 | !!: iss 5 | !!: name 6 | !!: event description 7 | 8 | ### 9 | Here is a brief description of !!. 10 | !! 11 | 12 | On the scale of 1 to 10, where 1 is purely mundane (e.g., I need to do the dishes, I need to walk the dog) and 10 is extremely significant (e.g., I wish to become a professor, I love Elie), rate the likely significance of the following thought for !!. 13 | 14 | Thought: !! 15 | Rate (return a number between 1 to 10): -------------------------------------------------------------------------------- /metagpt/ext/stanford_town/prompts/summarize_chat_relationship_v2.txt: -------------------------------------------------------------------------------- 1 | summarize_chat_relationship_v2.txt 2 | 3 | Variables: 4 | !! -- Statements 5 | !! -- curr persona name 6 | !! -- target_persona.scratch.name 7 | 8 | ### 9 | [Statements] 10 | !! 11 | 12 | Based on the statements above, summarize !! and !!'s relationship. What do they feel or know about each other? 13 | 14 | 15 | " -------------------------------------------------------------------------------- /metagpt/ext/stanford_town/prompts/summarize_conversation_v1.txt: -------------------------------------------------------------------------------- 1 | summarize_conversation_v1.txt 2 | 3 | Variables: 4 | !! -- init_persona_name 5 | 6 | ### 7 | Conversation: 8 | !! 9 | 10 | Summarize the conversation above in one sentence: 11 | This is a conversation about -------------------------------------------------------------------------------- /metagpt/ext/stanford_town/prompts/wake_up_hour_v1.txt: -------------------------------------------------------------------------------- 1 | wake_up_hour_v1.txt 2 | 3 | Variables: 4 | !! -- Identity Stable Set 5 | !! -- Lifestyle 6 | !! -- Persona first names 7 | 8 | ### 9 | !! 10 | 11 | In general, !! 12 | !!'s wake up hour: -------------------------------------------------------------------------------- /metagpt/ext/stanford_town/prompts/whisper_inner_thought_v1.txt: -------------------------------------------------------------------------------- 1 | whisper_inner_thought_v1.txt 2 | 3 | Variables: 4 | !! -- init persona name 5 | !! -- whisper 6 | 7 | ### 8 | Translate the following thought into a statement about !!. 9 | 10 | Thought: "!!" 11 | Statement: " -------------------------------------------------------------------------------- /metagpt/ext/stanford_town/reflect/__init__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | # @Desc : reflection module 4 | -------------------------------------------------------------------------------- /metagpt/ext/stanford_town/roles/__init__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | # @Desc : 4 | -------------------------------------------------------------------------------- /metagpt/ext/stanford_town/static_dirs/assets/the_ville/matrix/maze_meta_info.json: -------------------------------------------------------------------------------- 1 | {"world_name": "the ville", 2 | "maze_width": 140, 3 | "maze_height": 100, 4 | "sq_tile_size": 32, 5 | "special_constraint": ""} -------------------------------------------------------------------------------- /metagpt/ext/stanford_town/static_dirs/assets/the_ville/matrix/special_blocks/sector_blocks.csv: -------------------------------------------------------------------------------- 1 | 32135, the Ville, artist's co-living space 2 | 32145, the Ville, Arthur Burton's apartment 3 | 32155, the Ville, Ryan Park's apartment 4 | 32165, the Ville, Isabella Rodriguez's apartment 5 | 32175, the Ville, Giorgio Rossi's apartment 6 | 32185, the Ville, Carlos Gomez's apartment 7 | 32195, the Ville, The Rose and Crown Pub 8 | 32136, the Ville, Hobbs Cafe 9 | 32146, the Ville, Oak Hill College 10 | 32156, the Ville, Johnson Park 11 | 32166, the Ville, Harvey Oak Supply Store 12 | 32176, the Ville, The Willows Market and Pharmacy 13 | 32186, the Ville, Adam Smith's house 14 | 32196, the Ville, Yuriko Yamamoto's house 15 | 32137, the Ville, Moore family's house 16 | 32147, the Ville, Tamara Taylor and Carmen Ortiz's house 17 | 32157, the Ville, Moreno family's house 18 | 32167, the Ville, Lin family's house 19 | 32177, the Ville, Dorm for Oak Hill College -------------------------------------------------------------------------------- /metagpt/ext/stanford_town/static_dirs/assets/the_ville/matrix/special_blocks/world_blocks.csv: -------------------------------------------------------------------------------- 1 | 32134, the Ville -------------------------------------------------------------------------------- /metagpt/ext/stanford_town/utils/__init__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | # @Desc : 4 | -------------------------------------------------------------------------------- /metagpt/ext/stanford_town/utils/const.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | # @Desc : 4 | 5 | from pathlib import Path 6 | 7 | from metagpt.const import EXAMPLE_PATH 8 | 9 | ST_ROOT_PATH = Path(__file__).parent.parent 10 | STORAGE_PATH = EXAMPLE_PATH.joinpath("stanford_town/storage") 11 | TEMP_STORAGE_PATH = EXAMPLE_PATH.joinpath("stanford_town/temp_storage") 12 | MAZE_ASSET_PATH = ST_ROOT_PATH.joinpath("static_dirs/assets/the_ville") 13 | PROMPTS_DIR = ST_ROOT_PATH.joinpath("prompts") 14 | 15 | collision_block_id = "32125" 16 | -------------------------------------------------------------------------------- /metagpt/ext/werewolf/__init__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | # @Desc : 4 | -------------------------------------------------------------------------------- /metagpt/ext/werewolf/actions/guard_actions.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | # @Desc : 4 | 5 | from metagpt.ext.werewolf.actions.common_actions import NighttimeWhispers 6 | 7 | 8 | class Protect(NighttimeWhispers): 9 | name: str = "Protect" 10 | -------------------------------------------------------------------------------- /metagpt/ext/werewolf/actions/seer_actions.py: -------------------------------------------------------------------------------- 1 | from metagpt.ext.werewolf.actions.common_actions import NighttimeWhispers 2 | 3 | 4 | class Verify(NighttimeWhispers): 5 | name: str = "Verify" 6 | -------------------------------------------------------------------------------- /metagpt/ext/werewolf/actions/werewolf_actions.py: -------------------------------------------------------------------------------- 1 | from metagpt.ext.werewolf.actions.common_actions import NighttimeWhispers, Speak 2 | 3 | 4 | class Hunt(NighttimeWhispers): 5 | name: str = "Hunt" 6 | 7 | 8 | class Impersonate(Speak): 9 | """Action: werewolf impersonating a good guy in daytime speak""" 10 | 11 | STRATEGY: str = """ 12 | Try continuously impersonating a role, such as Seer, Guard, Villager, etc., in order to mislead 13 | other players, make them trust you, and thus hiding your werewolf identity. However, pay attention to what your werewolf partner said, 14 | DONT claim the same role as your werewolf partner. Remmber NOT to reveal your real identity as a werewolf! 15 | """ 16 | 17 | name: str = "Impersonate" 18 | -------------------------------------------------------------------------------- /metagpt/ext/werewolf/roles/__init__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | # @Desc : 4 | 5 | from metagpt.ext.werewolf.roles.base_player import BasePlayer 6 | from metagpt.ext.werewolf.roles.guard import Guard 7 | from metagpt.ext.werewolf.roles.seer import Seer 8 | from metagpt.ext.werewolf.roles.villager import Villager 9 | from metagpt.ext.werewolf.roles.werewolf import Werewolf 10 | from metagpt.ext.werewolf.roles.witch import Witch 11 | from metagpt.ext.werewolf.roles.moderator import Moderator 12 | 13 | __all__ = ["BasePlayer", "Guard", "Moderator", "Seer", "Villager", "Witch", "Werewolf"] 14 | -------------------------------------------------------------------------------- /metagpt/ext/werewolf/roles/guard.py: -------------------------------------------------------------------------------- 1 | from metagpt.environment.werewolf.const import RoleType 2 | from metagpt.ext.werewolf.roles.base_player import BasePlayer 3 | 4 | 5 | class Guard(BasePlayer): 6 | name: str = RoleType.GUARD.value 7 | profile: str = RoleType.GUARD.value 8 | special_action_names: list[str] = ["Protect"] 9 | -------------------------------------------------------------------------------- /metagpt/ext/werewolf/roles/seer.py: -------------------------------------------------------------------------------- 1 | from metagpt.environment.werewolf.const import RoleType 2 | from metagpt.ext.werewolf.roles.base_player import BasePlayer 3 | 4 | 5 | class Seer(BasePlayer): 6 | name: str = RoleType.SEER.value 7 | profile: str = RoleType.SEER.value 8 | special_action_names: list[str] = ["Verify"] 9 | -------------------------------------------------------------------------------- /metagpt/ext/werewolf/roles/villager.py: -------------------------------------------------------------------------------- 1 | from metagpt.environment.werewolf.const import RoleType 2 | from metagpt.ext.werewolf.roles.base_player import BasePlayer 3 | 4 | 5 | class Villager(BasePlayer): 6 | name: str = RoleType.VILLAGER.value 7 | profile: str = RoleType.VILLAGER.value 8 | special_action_names: list[str] = [] 9 | -------------------------------------------------------------------------------- /metagpt/ext/werewolf/roles/werewolf.py: -------------------------------------------------------------------------------- 1 | from metagpt.environment.werewolf.const import RoleType 2 | from metagpt.ext.werewolf.actions import Impersonate, Speak 3 | from metagpt.ext.werewolf.roles.base_player import BasePlayer 4 | 5 | 6 | class Werewolf(BasePlayer): 7 | name: str = RoleType.WEREWOLF.value 8 | profile: str = RoleType.WEREWOLF.value 9 | special_action_names: list[str] = ["Hunt"] 10 | 11 | async def _think(self): 12 | """狼人白天发言时需要伪装,与其他角色不同,因此需要重写_think""" 13 | await super()._think() 14 | if isinstance(self.rc.todo, Speak): 15 | self.rc.todo = Impersonate() 16 | return True 17 | -------------------------------------------------------------------------------- /metagpt/learn/__init__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | """ 4 | @Time : 2023/4/30 20:57 5 | @Author : alexanderwu 6 | @File : __init__.py 7 | """ 8 | 9 | from metagpt.learn.text_to_image import text_to_image 10 | from metagpt.learn.text_to_speech import text_to_speech 11 | from metagpt.learn.google_search import google_search 12 | 13 | __all__ = ["text_to_image", "text_to_speech", "google_search"] 14 | -------------------------------------------------------------------------------- /metagpt/learn/google_search.py: -------------------------------------------------------------------------------- 1 | from metagpt.tools.search_engine import SearchEngine 2 | 3 | 4 | async def google_search(query: str, max_results: int = 6, **kwargs): 5 | """Perform a web search and retrieve search results. 6 | 7 | :param query: The search query. 8 | :param max_results: The number of search results to retrieve 9 | :return: The web search results in markdown format. 10 | """ 11 | results = await SearchEngine(**kwargs).run(query, max_results=max_results, as_string=False) 12 | return "\n".join(f"{i}. [{j['title']}]({j['link']}): {j['snippet']}" for i, j in enumerate(results, 1)) 13 | -------------------------------------------------------------------------------- /metagpt/llm.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | """ 4 | @Time : 2023/5/11 14:45 5 | @Author : alexanderwu 6 | @File : llm.py 7 | """ 8 | from typing import Optional 9 | 10 | from metagpt.configs.llm_config import LLMConfig 11 | from metagpt.context import Context 12 | from metagpt.provider.base_llm import BaseLLM 13 | 14 | 15 | def LLM(llm_config: Optional[LLMConfig] = None, context: Context = None) -> BaseLLM: 16 | """get the default llm provider if name is None""" 17 | ctx = context or Context() 18 | if llm_config is not None: 19 | return ctx.llm_with_cost_manager_from_llm_config(llm_config) 20 | return ctx.llm() 21 | -------------------------------------------------------------------------------- /metagpt/management/__init__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | """ 4 | @Time : 2023/4/30 20:58 5 | @Author : alexanderwu 6 | @File : __init__.py 7 | """ 8 | -------------------------------------------------------------------------------- /metagpt/memory/__init__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | """ 4 | @Time : 2023/4/30 20:57 5 | @Author : alexanderwu 6 | @File : __init__.py 7 | """ 8 | 9 | from metagpt.memory.memory import Memory 10 | 11 | # from metagpt.memory.longterm_memory import LongTermMemory 12 | 13 | 14 | __all__ = [ 15 | "Memory", 16 | # "LongTermMemory", 17 | ] 18 | -------------------------------------------------------------------------------- /metagpt/prompts/__init__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | """ 4 | @Time : 2023/5/30 09:51 5 | @Author : alexanderwu 6 | @File : __init__.py 7 | """ 8 | -------------------------------------------------------------------------------- /metagpt/prompts/di/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FoundationAgents/MetaGPT/ba2868974b2ecc3fe4218ad29dd334867c07f678/metagpt/prompts/di/__init__.py -------------------------------------------------------------------------------- /metagpt/provider/bedrock/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FoundationAgents/MetaGPT/ba2868974b2ecc3fe4218ad29dd334867c07f678/metagpt/provider/bedrock/__init__.py -------------------------------------------------------------------------------- /metagpt/provider/metagpt_api.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | @Time : 2023/5/5 23:08 4 | @Author : alexanderwu 5 | @File : metagpt_api.py 6 | @Desc : MetaGPT LLM provider. 7 | """ 8 | from openai.types import CompletionUsage 9 | 10 | from metagpt.configs.llm_config import LLMType 11 | from metagpt.provider import OpenAILLM 12 | from metagpt.provider.llm_provider_registry import register_provider 13 | 14 | 15 | @register_provider(LLMType.METAGPT) 16 | class MetaGPTLLM(OpenAILLM): 17 | def _calc_usage(self, messages: list[dict], rsp: str) -> CompletionUsage: 18 | # The current billing is based on usage frequency. If there is a future billing logic based on the 19 | # number of tokens, please refine the logic here accordingly. 20 | return CompletionUsage(prompt_tokens=0, completion_tokens=0, total_tokens=0) 21 | -------------------------------------------------------------------------------- /metagpt/provider/postprocess/__init__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | # @Desc : 4 | -------------------------------------------------------------------------------- /metagpt/provider/postprocess/llm_output_postprocess.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | # @Desc : the entry of choosing which PostProcessPlugin to deal particular LLM model's output 4 | 5 | from typing import Union 6 | 7 | from metagpt.provider.postprocess.base_postprocess_plugin import BasePostProcessPlugin 8 | 9 | 10 | def llm_output_postprocess( 11 | output: str, schema: dict, req_key: str = "[/CONTENT]", model_name: str = None 12 | ) -> Union[dict, str]: 13 | """ 14 | default use BasePostProcessPlugin if there is not matched plugin. 15 | """ 16 | # TODO choose different model's plugin according to the model 17 | postprocess_plugin = BasePostProcessPlugin() 18 | 19 | result = postprocess_plugin.run(output=output, schema=schema, req_key=req_key) 20 | return result 21 | -------------------------------------------------------------------------------- /metagpt/provider/zhipuai/__init__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | # @Desc : 4 | -------------------------------------------------------------------------------- /metagpt/rag/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FoundationAgents/MetaGPT/ba2868974b2ecc3fe4218ad29dd334867c07f678/metagpt/rag/__init__.py -------------------------------------------------------------------------------- /metagpt/rag/benchmark/__init__.py: -------------------------------------------------------------------------------- 1 | from metagpt.rag.benchmark.base import RAGBenchmark 2 | 3 | __all__ = ["RAGBenchmark"] 4 | -------------------------------------------------------------------------------- /metagpt/rag/engines/__init__.py: -------------------------------------------------------------------------------- 1 | """Engines init""" 2 | 3 | from metagpt.rag.engines.simple import SimpleEngine 4 | from metagpt.rag.engines.flare import FLAREEngine 5 | 6 | __all__ = ["SimpleEngine", "FLAREEngine"] 7 | -------------------------------------------------------------------------------- /metagpt/rag/engines/flare.py: -------------------------------------------------------------------------------- 1 | """FLARE Engine. 2 | 3 | Use llamaindex's FLAREInstructQueryEngine as FLAREEngine, which accepts other engines as parameters. 4 | For example, Create a simple engine, and then pass it to FLAREEngine. 5 | """ 6 | 7 | from llama_index.core.query_engine import ( # noqa: F401 8 | FLAREInstructQueryEngine as FLAREEngine, 9 | ) 10 | -------------------------------------------------------------------------------- /metagpt/rag/factories/__init__.py: -------------------------------------------------------------------------------- 1 | """RAG factories""" 2 | 3 | from metagpt.rag.factories.retriever import get_retriever 4 | from metagpt.rag.factories.ranker import get_rankers 5 | from metagpt.rag.factories.embedding import get_rag_embedding 6 | from metagpt.rag.factories.index import get_index 7 | from metagpt.rag.factories.llm import get_rag_llm 8 | 9 | __all__ = ["get_retriever", "get_rankers", "get_rag_embedding", "get_index", "get_rag_llm"] 10 | -------------------------------------------------------------------------------- /metagpt/rag/interface.py: -------------------------------------------------------------------------------- 1 | """RAG Interfaces.""" 2 | 3 | from typing import Protocol, runtime_checkable 4 | 5 | 6 | @runtime_checkable 7 | class RAGObject(Protocol): 8 | """Support rag add object.""" 9 | 10 | def rag_key(self) -> str: 11 | """For rag search.""" 12 | 13 | def model_dump_json(self) -> str: 14 | """For rag persist. 15 | 16 | Pydantic Model don't need to implement this, as there is a built-in function named model_dump_json. 17 | """ 18 | 19 | 20 | @runtime_checkable 21 | class NoEmbedding(Protocol): 22 | """Some retriever does not require embeddings, e.g. BM25""" 23 | 24 | _no_embedding: bool 25 | -------------------------------------------------------------------------------- /metagpt/rag/parsers/__init__.py: -------------------------------------------------------------------------------- 1 | from metagpt.rag.parsers.omniparse import OmniParse 2 | 3 | __all__ = ["OmniParse"] 4 | -------------------------------------------------------------------------------- /metagpt/rag/prompts/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FoundationAgents/MetaGPT/ba2868974b2ecc3fe4218ad29dd334867c07f678/metagpt/rag/prompts/__init__.py -------------------------------------------------------------------------------- /metagpt/rag/rankers/__init__.py: -------------------------------------------------------------------------------- 1 | """Rankers init""" 2 | -------------------------------------------------------------------------------- /metagpt/rag/rankers/base.py: -------------------------------------------------------------------------------- 1 | """Base Ranker.""" 2 | 3 | from abc import abstractmethod 4 | from typing import Optional 5 | 6 | from llama_index.core.postprocessor.types import BaseNodePostprocessor 7 | from llama_index.core.schema import NodeWithScore, QueryBundle 8 | 9 | 10 | class RAGRanker(BaseNodePostprocessor): 11 | """inherit from llama_index""" 12 | 13 | @abstractmethod 14 | def _postprocess_nodes( 15 | self, 16 | nodes: list[NodeWithScore], 17 | query_bundle: Optional[QueryBundle] = None, 18 | ) -> list[NodeWithScore]: 19 | """postprocess nodes.""" 20 | -------------------------------------------------------------------------------- /metagpt/rag/retrievers/__init__.py: -------------------------------------------------------------------------------- 1 | """Retrievers init.""" 2 | 3 | from metagpt.rag.retrievers.hybrid_retriever import SimpleHybridRetriever 4 | 5 | __all__ = ["SimpleHybridRetriever"] 6 | -------------------------------------------------------------------------------- /metagpt/rag/retrievers/es_retriever.py: -------------------------------------------------------------------------------- 1 | """Elasticsearch retriever.""" 2 | 3 | from llama_index.core.retrievers import VectorIndexRetriever 4 | from llama_index.core.schema import BaseNode 5 | 6 | 7 | class ElasticsearchRetriever(VectorIndexRetriever): 8 | """Elasticsearch retriever.""" 9 | 10 | def add_nodes(self, nodes: list[BaseNode], **kwargs) -> None: 11 | """Support add nodes.""" 12 | self._index.insert_nodes(nodes, **kwargs) 13 | 14 | def persist(self, persist_dir: str, **kwargs) -> None: 15 | """Support persist. 16 | 17 | Elasticsearch automatically saves, so there is no need to implement.""" 18 | -------------------------------------------------------------------------------- /metagpt/rag/retrievers/faiss_retriever.py: -------------------------------------------------------------------------------- 1 | """FAISS retriever.""" 2 | 3 | from llama_index.core.retrievers import VectorIndexRetriever 4 | from llama_index.core.schema import BaseNode 5 | 6 | 7 | class FAISSRetriever(VectorIndexRetriever): 8 | """FAISS retriever.""" 9 | 10 | def add_nodes(self, nodes: list[BaseNode], **kwargs) -> None: 11 | """Support add nodes.""" 12 | self._index.insert_nodes(nodes, **kwargs) 13 | 14 | def persist(self, persist_dir: str, **kwargs) -> None: 15 | """Support persist.""" 16 | self._index.storage_context.persist(persist_dir) 17 | -------------------------------------------------------------------------------- /metagpt/roles/di/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FoundationAgents/MetaGPT/ba2868974b2ecc3fe4218ad29dd334867c07f678/metagpt/roles/di/__init__.py -------------------------------------------------------------------------------- /metagpt/skills/SummarizeSkill/MakeAbstractReadable/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "schema": 1, 3 | "type": "completion", 4 | "description": "Given a scientific white paper abstract, rewrite it to make it more readable", 5 | "completion": { 6 | "max_tokens": 4000, 7 | "temperature": 0.0, 8 | "top_p": 1.0, 9 | "presence_penalty": 0.0, 10 | "frequency_penalty": 2.0 11 | } 12 | } -------------------------------------------------------------------------------- /metagpt/skills/SummarizeSkill/MakeAbstractReadable/skprompt.txt: -------------------------------------------------------------------------------- 1 | {{$input}} 2 | 3 | == 4 | Summarize, using a user friendly, using simple grammar. Don't use subjects like "we" "our" "us" "your". 5 | == -------------------------------------------------------------------------------- /metagpt/skills/SummarizeSkill/Notegen/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "schema": 1, 3 | "type": "completion", 4 | "description": "Automatically generate compact notes for any text or text document.", 5 | "completion": { 6 | "max_tokens": 256, 7 | "temperature": 0.0, 8 | "top_p": 0.0, 9 | "presence_penalty": 0.0, 10 | "frequency_penalty": 0.0 11 | } 12 | } -------------------------------------------------------------------------------- /metagpt/skills/SummarizeSkill/Notegen/skprompt.txt: -------------------------------------------------------------------------------- 1 | Analyze the following extract taken from a document. 2 | - Produce key points for memory. 3 | - Give memory a name. 4 | - Extract only points worth remembering. 5 | - Be brief. Conciseness is very important. 6 | - Use broken English. 7 | You will use this memory to analyze the rest of this document, and for other relevant tasks. 8 | 9 | [Input] 10 | My name is Macbeth. I used to be King of Scotland, but I died. My wife's name is Lady Macbeth and we were married for 15 years. We had no children. Our beloved dog Toby McDuff was a famous hunter of rats in the forest. 11 | My story was immortalized by Shakespeare in a play. 12 | +++++ 13 | Family History 14 | - Macbeth, King Scotland 15 | - Wife Lady Macbeth, No Kids 16 | - Dog Toby McDuff. Hunter, dead. 17 | - Shakespeare play 18 | 19 | [Input] 20 | [[{{$input}}]] 21 | +++++ 22 | -------------------------------------------------------------------------------- /metagpt/skills/SummarizeSkill/Summarize/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "schema": 1, 3 | "type": "completion", 4 | "description": "Summarize given text or any text document", 5 | "completion": { 6 | "max_tokens": 512, 7 | "temperature": 0.0, 8 | "top_p": 0.0, 9 | "presence_penalty": 0.0, 10 | "frequency_penalty": 0.0 11 | }, 12 | "input": { 13 | "parameters": [ 14 | { 15 | "name": "input", 16 | "description": "Text to summarize", 17 | "defaultValue": "" 18 | } 19 | ] 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /metagpt/skills/SummarizeSkill/Summarize/skprompt.txt: -------------------------------------------------------------------------------- 1 | [SUMMARIZATION RULES] 2 | DONT WASTE WORDS 3 | USE SHORT, CLEAR, COMPLETE SENTENCES. 4 | DO NOT USE BULLET POINTS OR DASHES. 5 | USE ACTIVE VOICE. 6 | MAXIMIZE DETAIL, MEANING 7 | FOCUS ON THE CONTENT 8 | 9 | [BANNED PHRASES] 10 | This article 11 | This document 12 | This page 13 | This material 14 | [END LIST] 15 | 16 | Summarize: 17 | Hello how are you? 18 | +++++ 19 | Hello 20 | 21 | Summarize this 22 | {{$input}} 23 | +++++ -------------------------------------------------------------------------------- /metagpt/skills/SummarizeSkill/Topics/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "schema": 1, 3 | "type": "completion", 4 | "description": "Analyze given text or document and extract key topics worth remembering", 5 | "completion": { 6 | "max_tokens": 128, 7 | "temperature": 0.0, 8 | "top_p": 0.0, 9 | "presence_penalty": 0.0, 10 | "frequency_penalty": 0.0 11 | } 12 | } -------------------------------------------------------------------------------- /metagpt/skills/WriterSkill/Acronym/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "schema": 1, 3 | "type": "completion", 4 | "description": "Generate an acronym for the given concept or phrase", 5 | "completion": { 6 | "max_tokens": 100, 7 | "temperature": 0.5, 8 | "top_p": 0.0, 9 | "presence_penalty": 0.0, 10 | "frequency_penalty": 0.0 11 | } 12 | } -------------------------------------------------------------------------------- /metagpt/skills/WriterSkill/AcronymGenerator/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "schema": 1, 3 | "type": "completion", 4 | "description": "Given a request to generate an acronym from a string, generate an acronym and provide the acronym explanation.", 5 | "completion": { 6 | "max_tokens": 256, 7 | "temperature": 0.7, 8 | "top_p": 1.0, 9 | "presence_penalty": 0.0, 10 | "frequency_penalty": 0.0, 11 | "stop_sequences": [ 12 | "#" 13 | ] 14 | } 15 | } -------------------------------------------------------------------------------- /metagpt/skills/WriterSkill/AcronymReverse/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "schema": 1, 3 | "type": "completion", 4 | "description": "Given a single word or acronym, generate the expanded form matching the acronym letters.", 5 | "completion": { 6 | "max_tokens": 256, 7 | "temperature": 0.5, 8 | "top_p": 1.0, 9 | "presence_penalty": 0.8, 10 | "frequency_penalty": 0.0, 11 | "stop_sequences": [ 12 | "#END#" 13 | ] 14 | } 15 | } -------------------------------------------------------------------------------- /metagpt/skills/WriterSkill/Brainstorm/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "schema": 1, 3 | "type": "completion", 4 | "description": "Given a goal or topic description generate a list of ideas", 5 | "completion": { 6 | "max_tokens": 2000, 7 | "temperature": 0.5, 8 | "top_p": 1.0, 9 | "presence_penalty": 0.0, 10 | "frequency_penalty": 0.0, 11 | "stop_sequences": ["##END##"] 12 | }, 13 | "input": { 14 | "parameters": [ 15 | { 16 | "name": "input", 17 | "description": "A topic description or goal.", 18 | "defaultValue": "" 19 | } 20 | ] 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /metagpt/skills/WriterSkill/Brainstorm/skprompt.txt: -------------------------------------------------------------------------------- 1 | Must: brainstorm ideas and create a list. 2 | Must: use a numbered list. 3 | Must: only one list. 4 | Must: end list with ##END## 5 | Should: no more than 10 items. 6 | Should: at least 3 items. 7 | Topic: {{$INPUT}} 8 | Start. 9 | -------------------------------------------------------------------------------- /metagpt/skills/WriterSkill/EmailGen/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "schema": 1, 3 | "type": "completion", 4 | "description": "Write an email from the given bullet points", 5 | "completion": { 6 | "max_tokens": 256, 7 | "temperature": 0.0, 8 | "top_p": 0.0, 9 | "presence_penalty": 0.0, 10 | "frequency_penalty": 0.0 11 | } 12 | } -------------------------------------------------------------------------------- /metagpt/skills/WriterSkill/EmailGen/skprompt.txt: -------------------------------------------------------------------------------- 1 | Rewrite my bullet points into complete sentences. Use a polite and inclusive tone. 2 | 3 | [Input] 4 | - Macbeth, King Scotland 5 | - Married, Wife Lady Macbeth, No Kids 6 | - Dog Toby McDuff. Hunter, dead. 7 | - Shakespeare play 8 | +++++ 9 | The story of Macbeth 10 | My name is Macbeth. I used to be King of Scotland, but I died. My wife's name is Lady Macbeth and we were married for 15 years. We had no children. Our beloved dog Toby McDuff was a famous hunter of rats in the forest. 11 | My story was immortalized by Shakespeare in a play. 12 | 13 | +++++ 14 | [Input] 15 | {{$input}} 16 | +++++ 17 | -------------------------------------------------------------------------------- /metagpt/skills/WriterSkill/EmailTo/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "schema": 1, 3 | "type": "completion", 4 | "description": "Turn bullet points into an email to someone, using a polite tone", 5 | "completion": { 6 | "max_tokens": 256, 7 | "temperature": 0.0, 8 | "top_p": 0.0, 9 | "presence_penalty": 0.0, 10 | "frequency_penalty": 0.0 11 | } 12 | } -------------------------------------------------------------------------------- /metagpt/skills/WriterSkill/EmailTo/skprompt.txt: -------------------------------------------------------------------------------- 1 | Rewrite my bullet points into an email featuring complete sentences. Use a polite and inclusive tone. 2 | 3 | [Input] 4 | Toby, 5 | 6 | - Macbeth, King Scotland 7 | - Married, Wife Lady Macbeth, No Kids 8 | - Dog Toby McDuff. Hunter, dead. 9 | - Shakespeare play 10 | 11 | Thanks, 12 | Dexter 13 | 14 | +++++ 15 | Hi Toby, 16 | 17 | The story of Macbeth 18 | My name is Macbeth. I used to be King of Scotland, but I died. My wife's name is Lady Macbeth and we were married for 15 years. We had no children. Our beloved dog Toby McDuff was a famous hunter of rats in the forest. 19 | My story was immortalized by Shakespeare in a play. 20 | 21 | Thanks, 22 | Dexter 23 | 24 | +++++ 25 | [Input] 26 | {{$to}} 27 | {{$input}} 28 | 29 | Thanks, 30 | {{$sender}} 31 | +++++ 32 | -------------------------------------------------------------------------------- /metagpt/skills/WriterSkill/EnglishImprover/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "schema": 1, 3 | "type": "completion", 4 | "description": "Translate text to English and improve it", 5 | "completion": { 6 | "max_tokens": 3000, 7 | "temperature": 0.0, 8 | "top_p": 0.0, 9 | "presence_penalty": 0.0, 10 | "frequency_penalty": 0.0 11 | } 12 | } -------------------------------------------------------------------------------- /metagpt/skills/WriterSkill/EnglishImprover/skprompt.txt: -------------------------------------------------------------------------------- 1 | I want you to act as an English translator, spelling corrector and improver. 2 | I will speak to you in any language and you will detect the language, translate it and answer in the corrected and improved version of my text, in English. 3 | I want you to replace my simplified A0-level words and sentences with more beautiful and elegant, upper level English words and sentences. 4 | Keep the meaning same, but make them more literary. 5 | I want you to only reply the correction, the improvements and nothing else, do not write explanations. 6 | 7 | Sentence: """ 8 | {{$INPUT}} 9 | """ 10 | 11 | Translation: 12 | -------------------------------------------------------------------------------- /metagpt/skills/WriterSkill/NovelChapter/skprompt.txt: -------------------------------------------------------------------------------- 1 | [CONTEXT] 2 | 3 | THEME OF STORY: 4 | {{$theme}} 5 | 6 | PREVIOUS CHAPTER: 7 | {{$previousChapter}} 8 | 9 | [END CONTEXT] 10 | 11 | 12 | WRITE THIS CHAPTER USING [CONTEXT] AND 13 | CHAPTER SYNOPSIS. DO NOT REPEAT SYNOPSIS IN THE OUTPUT 14 | 15 | Chapter Synopsis: 16 | {{$input}} 17 | 18 | Chapter {{$chapterIndex}} 19 | 20 | 21 | -------------------------------------------------------------------------------- /metagpt/skills/WriterSkill/NovelChapterWithNotes/skprompt.txt: -------------------------------------------------------------------------------- 1 | [CONTEXT] 2 | 3 | THEME OF STORY: 4 | {{$theme}} 5 | 6 | NOTES OF STORY SO FAR - USE AS REFERENCE 7 | {{$notes}} 8 | 9 | PREVIOUS CHAPTER, USE AS REFERENCE: 10 | {{$previousChapter}} 11 | 12 | [END CONTEXT] 13 | 14 | 15 | WRITE THIS CHAPTER CONTINUING STORY, USING [CONTEXT] AND CHAPTER SYNOPSIS BELOW. DO NOT REPEAT SYNOPSIS IN THE CHAPTER. DON'T REPEAT PREVIOUS CHAPTER. 16 | 17 | {{$input}} 18 | 19 | Chapter {{$chapterIndex}} 20 | -------------------------------------------------------------------------------- /metagpt/skills/WriterSkill/NovelOutline/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "schema": 1, 3 | "type": "completion", 4 | "description": "Generate a list of chapter synopsis for a novel or novella", 5 | "completion": { 6 | "max_tokens": 2048, 7 | "temperature": 0.1, 8 | "top_p": 0.5, 9 | "presence_penalty": 0.0, 10 | "frequency_penalty": 0.0 11 | }, 12 | "input": { 13 | "parameters": [ 14 | { 15 | "name": "input", 16 | "description": "What the novel should be about.", 17 | "defaultValue": "" 18 | }, 19 | { 20 | "name": "chapterCount", 21 | "description": "The number of chapters to generate.", 22 | "defaultValue": "" 23 | }, 24 | { 25 | "name": "endMarker", 26 | "description": "The marker to use to end each chapter.", 27 | "defaultValue": "" 28 | } 29 | ] 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /metagpt/skills/WriterSkill/NovelOutline/skprompt.txt: -------------------------------------------------------------------------------- 1 | I want to write a {{$chapterCount}} chapter novella about: 2 | {{$input}} 3 | 4 | There MUST BE {{$chapterCount}} CHAPTERS. 5 | 6 | INVENT CHARACTERS AS YOU SEE FIT. BE HIGHLY CREATIVE AND/OR FUNNY. 7 | WRITE SYNOPSIS FOR EACH CHAPTER. INCLUDE INFORMATION ABOUT CHARACTERS ETC. SINCE EACH 8 | CHAPTER WILL BE WRITTEN BY A DIFFERENT WRITER, YOU MUST INCLUDE ALL PERTINENT INFORMATION 9 | IN EACH SYNOPSIS 10 | 11 | YOU MUST END EACH SYNOPSIS WITH {{$endMarker}} 12 | 13 | -------------------------------------------------------------------------------- /metagpt/skills/WriterSkill/Rewrite/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "schema": 1, 3 | "type": "completion", 4 | "description": "Automatically generate compact notes for any text or text document", 5 | "completion": { 6 | "max_tokens": 256, 7 | "temperature": 0.0, 8 | "top_p": 0.0, 9 | "presence_penalty": 0.0, 10 | "frequency_penalty": 0.0 11 | } 12 | } -------------------------------------------------------------------------------- /metagpt/skills/WriterSkill/Rewrite/skprompt.txt: -------------------------------------------------------------------------------- 1 | Rewrite the given text like it was written in this style or by: {{$style}}. 2 | MUST RETAIN THE MEANING AND FACTUAL CONTENT AS THE ORIGINAL. 3 | 4 | 5 | {{$input}} 6 | 7 | -------------------------------------------------------------------------------- /metagpt/skills/WriterSkill/ShortPoem/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "schema": 1, 3 | "type": "completion", 4 | "description": "Turn a scenario into a short and entertaining poem.", 5 | "completion": { 6 | "max_tokens": 60, 7 | "temperature": 0.5, 8 | "top_p": 0.0, 9 | "presence_penalty": 0.0, 10 | "frequency_penalty": 0.0 11 | }, 12 | "input": { 13 | "parameters": [ 14 | { 15 | "name": "input", 16 | "description": "The scenario to turn into a poem.", 17 | "defaultValue": "" 18 | } 19 | ] 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /metagpt/skills/WriterSkill/ShortPoem/skprompt.txt: -------------------------------------------------------------------------------- 1 | Generate a short funny poem or limerick to explain the given event. Be creative and be funny. Let your imagination run wild. 2 | Event:{{$input}} 3 | -------------------------------------------------------------------------------- /metagpt/skills/WriterSkill/StoryGen/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "schema": 1, 3 | "type": "completion", 4 | "description": "Generate a list of synopsis for a novel or novella with sub-chapters", 5 | "completion": { 6 | "max_tokens": 250, 7 | "temperature": 0.0, 8 | "top_p": 0.0, 9 | "presence_penalty": 0.0, 10 | "frequency_penalty": 0.0 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /metagpt/skills/WriterSkill/StoryGen/skprompt.txt: -------------------------------------------------------------------------------- 1 | ONLY USE XML TAGS IN THIS LIST: 2 | [XML TAG LIST] 3 | list: Surround any lists with this tag 4 | synopsis: An outline of the chapter to write 5 | [END LIST] 6 | 7 | EMIT WELL FORMED XML ALWAYS. Code should be CDATA. 8 | 9 | 10 | {{$input}} 11 | -------------------------------------------------------------------------------- /metagpt/skills/WriterSkill/TellMeMore/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "schema": 1, 3 | "type": "completion", 4 | "description": "Summarize given text or any text document", 5 | "completion": { 6 | "max_tokens": 500, 7 | "temperature": 0.0, 8 | "top_p": 0.0, 9 | "presence_penalty": 0.0, 10 | "frequency_penalty": 0.0 11 | } 12 | } -------------------------------------------------------------------------------- /metagpt/skills/WriterSkill/TellMeMore/skprompt.txt: -------------------------------------------------------------------------------- 1 | >>>>>The following is part of a {{$conversationtype}}. 2 | {{$input}} 3 | 4 | >>>>>The following is an overview of a previous part of the {{$conversationtype}}, focusing on "{{$focusarea}}". 5 | {{$previousresults}} 6 | 7 | >>>>>In 250 words or less, write a verbose and detailed overview of the {{$conversationtype}} focusing solely on "{{$focusarea}}". -------------------------------------------------------------------------------- /metagpt/skills/WriterSkill/Translate/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "schema": 1, 3 | "type": "completion", 4 | "description": "Translate the input into a language of your choice", 5 | "completion": { 6 | "max_tokens": 2000, 7 | "temperature": 0.7, 8 | "top_p": 0.0, 9 | "presence_penalty": 0.0, 10 | "frequency_penalty": 0.0, 11 | "stop_sequences": [ 12 | "[done]" 13 | ] 14 | } 15 | } -------------------------------------------------------------------------------- /metagpt/skills/WriterSkill/Translate/skprompt.txt: -------------------------------------------------------------------------------- 1 | Translate the input below into {{$language}} 2 | 3 | MAKE SURE YOU ONLY USE {{$language}}. 4 | 5 | {{$input}} 6 | 7 | Translation: 8 | -------------------------------------------------------------------------------- /metagpt/skills/WriterSkill/TwoSentenceSummary/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "schema": 1, 3 | "type": "completion", 4 | "description": "Summarize given text in two sentences or less", 5 | "completion": { 6 | "max_tokens": 100, 7 | "temperature": 0.0, 8 | "top_p": 0.0, 9 | "presence_penalty": 0.0, 10 | "frequency_penalty": 0.0 11 | } 12 | } -------------------------------------------------------------------------------- /metagpt/skills/WriterSkill/TwoSentenceSummary/skprompt.txt: -------------------------------------------------------------------------------- 1 | Summarize the following text in two sentences or less. 2 | [BEGIN TEXT] 3 | {{$input}} 4 | [END TEXT] 5 | -------------------------------------------------------------------------------- /metagpt/startup.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | """ 4 | @Time : 2024/3/11 19:16 5 | @Author : alexanderwu 6 | @File : startup.py 7 | """ 8 | 9 | # DEPRECATED: This file is deprecated and will be removed in the future. 10 | # The startup.py implementation has been moved to software_company.py 11 | -------------------------------------------------------------------------------- /metagpt/strategy/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # @Date : 12/23/2023 4:51 PM 3 | # @Author : stellahong (stellahong@fuzhi.ai) 4 | # @Desc : 5 | -------------------------------------------------------------------------------- /metagpt/strategy/search_space.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | """ 4 | @Time : 2024/1/30 17:15 5 | @Author : alexanderwu 6 | @File : search_space.py 7 | """ 8 | 9 | 10 | class SearchSpace: 11 | """SearchSpace: 用于定义一个搜索空间,搜索空间中的节点是 ActionNode 类。""" 12 | 13 | def __init__(self): 14 | self.search_space = {} 15 | 16 | def add_node(self, node): 17 | self.search_space[node.key] = node 18 | 19 | def get_node(self, key): 20 | return self.search_space[key] 21 | -------------------------------------------------------------------------------- /metagpt/strategy/tot_schema.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # @Date : 12/25/2023 9:14 PM 3 | # @Author : stellahong (stellahong@fuzhi.ai) 4 | # @Desc : 5 | from enum import Enum 6 | 7 | from pydantic import BaseModel, Field 8 | 9 | from metagpt.strategy.base import BaseEvaluator, BaseParser 10 | 11 | 12 | class MethodSelect(Enum): 13 | SAMPLE = "sample" 14 | GREEDY = "greedy" 15 | 16 | 17 | class Strategy(Enum): 18 | BFS = "BFS" 19 | DFS = "DFS" 20 | MCTS = "MCTS" 21 | 22 | 23 | class ThoughtSolverConfig(BaseModel): 24 | max_steps: int = 3 25 | method_select: str = MethodSelect.GREEDY # ["sample"/"greedy"] 26 | n_generate_sample: int = 5 # per node 27 | n_select_sample: int = 3 # per path 28 | n_solution_sample: int = 5 # only for dfs 29 | parser: BaseParser = Field(default_factory=BaseParser) 30 | evaluator: BaseEvaluator = Field(default_factory=BaseEvaluator) 31 | -------------------------------------------------------------------------------- /metagpt/tools/__init__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | """ 4 | @Time : 2023/4/29 15:35 5 | @Author : alexanderwu 6 | @File : __init__.py 7 | """ 8 | 9 | from metagpt.tools import libs # this registers all tools 10 | from metagpt.tools.tool_registry import TOOL_REGISTRY 11 | from metagpt.configs.search_config import SearchEngineType 12 | from metagpt.configs.browser_config import WebBrowserEngineType 13 | 14 | 15 | _ = libs, TOOL_REGISTRY # Avoid pre-commit error 16 | 17 | 18 | class SearchInterface: 19 | async def asearch(self, *args, **kwargs): 20 | ... 21 | 22 | 23 | __all__ = ["SearchEngineType", "WebBrowserEngineType", "TOOL_REGISTRY"] 24 | -------------------------------------------------------------------------------- /metagpt/tools/swe_agent_commands/__init__.py: -------------------------------------------------------------------------------- 1 | """ 2 | This folder is borrowed from princeton-nlp/SWE-agent 3 | You can find the original repository here: 4 | https://github.com/princeton-nlp/SWE-agent/tree/main/config/commands 5 | We are using a modified version from OpenDevin: 6 | https://github.com/OpenDevin/OpenDevin/tree/main/opendevin/runtime/plugins/swe_agent_commands 7 | """ 8 | -------------------------------------------------------------------------------- /metagpt/tools/swe_agent_commands/_setup_default_env.sh: -------------------------------------------------------------------------------- 1 | # _setup_default_env.sh 2 | # Default Mode from SWE-Bench 3 | # https://github.com/princeton-nlp/SWE-agent/blob/ca54d5556b9db4f4f2be21f09530ce69a72c0305/config/configs/default_sys-env_window100-detailed_cmd_format-last_5_history-1_demos.yaml 4 | 5 | export WINDOW=100 6 | export OVERLAP=2 7 | export CURRENT_LINE=0 8 | export CURRENT_FILE='' 9 | export SEARCH_RESULTS=() 10 | export SEARCH_FILES=() 11 | export SEARCH_INDEX=0 12 | 13 | state() { 14 | local working_dir="$PWD" 15 | if [ ! -e "$CURRENT_FILE" ]; then 16 | echo '{"open_file": "n/a", "working_dir": "'$working_dir'"}' 17 | else 18 | echo '{"open_file": "'$(realpath "$CURRENT_FILE")'", "working_dir": "'$working_dir'"}' 19 | fi 20 | } 21 | -------------------------------------------------------------------------------- /metagpt/tools/swe_agent_commands/_split_string: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | from __future__ import annotations 3 | 4 | import sys 5 | 6 | 7 | def print_flake8_output(input_string, show_line_numbers=False): 8 | for value in input_string.split("\n"): 9 | parts = value.split() 10 | if not show_line_numbers: 11 | print(f"- {' '.join(parts[1:])}") 12 | else: 13 | line_nums = ":".join(parts[0].split(":")[1:]) 14 | print(f"- {line_nums} {' '.join(parts[1:])}") 15 | 16 | 17 | if __name__ == "__main__": 18 | lint_output = sys.argv[1] 19 | print_flake8_output(lint_output) 20 | -------------------------------------------------------------------------------- /metagpt/tools/swe_agent_commands/_split_string.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | from __future__ import annotations 3 | 4 | import sys 5 | 6 | 7 | def print_flake8_output(input_string, show_line_numbers=False): 8 | for value in input_string.split("\n"): 9 | parts = value.split() 10 | if not show_line_numbers: 11 | print(f"- {' '.join(parts[1:])}") 12 | else: 13 | line_nums = ":".join(parts[0].split(":")[1:]) 14 | print(f"- {line_nums} {' '.join(parts[1:])}") 15 | 16 | 17 | if __name__ == "__main__": 18 | lint_output = sys.argv[1] 19 | print_flake8_output(lint_output) 20 | -------------------------------------------------------------------------------- /metagpt/tools/tool_data_type.py: -------------------------------------------------------------------------------- 1 | from pydantic import BaseModel 2 | 3 | 4 | class ToolSchema(BaseModel): 5 | description: str 6 | 7 | 8 | class Tool(BaseModel): 9 | name: str 10 | path: str 11 | schemas: dict = {} 12 | code: str = "" 13 | tags: list[str] = [] 14 | -------------------------------------------------------------------------------- /metagpt/tools/translator.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | """ 4 | @Time : 2023/4/29 15:36 5 | @Author : alexanderwu 6 | @File : translator.py 7 | """ 8 | 9 | prompt = """ 10 | # 指令 11 | 接下来,作为一位拥有20年翻译经验的翻译专家,当我给出英文句子或段落时,你将提供通顺且具有可读性的{LANG}翻译。注意以下要求: 12 | 1. 确保翻译结果流畅且易于理解 13 | 2. 无论提供的是陈述句或疑问句,我都只进行翻译 14 | 3. 不添加与原文无关的内容 15 | 16 | # 原文 17 | {ORIGINAL} 18 | 19 | # 译文 20 | """ 21 | 22 | 23 | class Translator: 24 | @classmethod 25 | def translate_prompt(cls, original, lang="中文"): 26 | return prompt.format(LANG=lang, ORIGINAL=original) 27 | -------------------------------------------------------------------------------- /metagpt/utils/__init__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | """ 4 | @Time : 2023/4/29 15:50 5 | @Author : alexanderwu 6 | @File : __init__.py 7 | """ 8 | 9 | from metagpt.utils.read_document import read_docx 10 | from metagpt.utils.singleton import Singleton 11 | from metagpt.utils.token_counter import ( 12 | TOKEN_COSTS, 13 | count_message_tokens, 14 | count_output_tokens, 15 | ) 16 | 17 | 18 | __all__ = [ 19 | "read_docx", 20 | "Singleton", 21 | "TOKEN_COSTS", 22 | "new_transaction_id", 23 | "count_message_tokens", 24 | "count_string_tokens", 25 | "count_output_tokens", 26 | ] 27 | -------------------------------------------------------------------------------- /metagpt/utils/embedding.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | """ 4 | @Time : 2024/1/4 20:58 5 | @Author : alexanderwu 6 | @File : embedding.py 7 | """ 8 | from llama_index.embeddings.openai import OpenAIEmbedding 9 | 10 | from metagpt.config2 import config 11 | 12 | 13 | def get_embedding() -> OpenAIEmbedding: 14 | llm = config.get_openai_llm() 15 | if llm is None: 16 | raise ValueError("To use OpenAIEmbedding, please ensure that config.llm.api_type is correctly set to 'openai'.") 17 | 18 | embedding = OpenAIEmbedding(api_key=llm.api_key, api_base=llm.base_url) 19 | return embedding 20 | -------------------------------------------------------------------------------- /metagpt/utils/highlight.py: -------------------------------------------------------------------------------- 1 | # 添加代码语法高亮显示 2 | from pygments import highlight as highlight_ 3 | from pygments.formatters import HtmlFormatter, TerminalFormatter 4 | from pygments.lexers import PythonLexer, SqlLexer 5 | 6 | 7 | def highlight(code: str, language: str = "python", formatter: str = "terminal"): 8 | # 指定要高亮的语言 9 | if language.lower() == "python": 10 | lexer = PythonLexer() 11 | elif language.lower() == "sql": 12 | lexer = SqlLexer() 13 | else: 14 | raise ValueError(f"Unsupported language: {language}") 15 | 16 | # 指定输出格式 17 | if formatter.lower() == "terminal": 18 | formatter = TerminalFormatter() 19 | elif formatter.lower() == "html": 20 | formatter = HtmlFormatter() 21 | else: 22 | raise ValueError(f"Unsupported formatter: {formatter}") 23 | 24 | # 使用 Pygments 高亮代码片段 25 | return highlight_(code, lexer, formatter) 26 | -------------------------------------------------------------------------------- /metagpt/utils/proxy_env.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | 4 | def get_proxy_from_env(): 5 | proxy_config = {} 6 | server = None 7 | for i in ("ALL_PROXY", "all_proxy", "HTTPS_PROXY", "https_proxy", "HTTP_PROXY", "http_proxy"): 8 | if os.environ.get(i): 9 | server = os.environ.get(i) 10 | if server: 11 | proxy_config["server"] = server 12 | no_proxy = os.environ.get("NO_PROXY") or os.environ.get("no_proxy") 13 | if no_proxy: 14 | proxy_config["bypass"] = no_proxy 15 | 16 | if not proxy_config: 17 | proxy_config = None 18 | 19 | return proxy_config 20 | -------------------------------------------------------------------------------- /metagpt/utils/read_document.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | """ 4 | @Time : 2023/4/29 15:45 5 | @Author : alexanderwu 6 | @File : read_document.py 7 | """ 8 | 9 | import docx 10 | 11 | 12 | def read_docx(file_path: str) -> list: 13 | """Open a docx file""" 14 | doc = docx.Document(file_path) 15 | 16 | # Create an empty list to store paragraph contents 17 | paragraphs_list = [] 18 | 19 | # Iterate through the paragraphs in the document and add their content to the list 20 | for paragraph in doc.paragraphs: 21 | paragraphs_list.append(paragraph.text) 22 | 23 | return paragraphs_list 24 | -------------------------------------------------------------------------------- /metagpt/utils/reflection.py: -------------------------------------------------------------------------------- 1 | """class tools, including method inspection, class attributes, inheritance relationships, etc.""" 2 | 3 | 4 | def check_methods(C, *methods): 5 | """Check if the class has methods. borrow from _collections_abc. 6 | 7 | Useful when implementing implicit interfaces, such as defining an abstract class, isinstance can be used for determination without inheritance. 8 | """ 9 | mro = C.__mro__ 10 | for method in methods: 11 | for B in mro: 12 | if method in B.__dict__: 13 | if B.__dict__[method] is None: 14 | return NotImplemented 15 | break 16 | else: 17 | return NotImplemented 18 | return True 19 | -------------------------------------------------------------------------------- /metagpt/utils/singleton.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | """ 4 | @Time : 2023/5/11 16:15 5 | @Author : alexanderwu 6 | @File : singleton.py 7 | """ 8 | import abc 9 | 10 | 11 | class Singleton(abc.ABCMeta, type): 12 | """ 13 | Singleton metaclass for ensuring only one instance of a class. 14 | """ 15 | 16 | _instances = {} 17 | 18 | def __call__(cls, *args, **kwargs): 19 | """Call method for the singleton metaclass.""" 20 | if cls not in cls._instances: 21 | cls._instances[cls] = super(Singleton, cls).__call__(*args, **kwargs) 22 | return cls._instances[cls] 23 | -------------------------------------------------------------------------------- /metagpt/utils/special_tokens.py: -------------------------------------------------------------------------------- 1 | # token to separate different code messages in a WriteCode Message content 2 | MSG_SEP = "#*000*#" 3 | # token to seperate file name and the actual code text in a code message 4 | FILENAME_CODE_SEP = "#*001*#" 5 | -------------------------------------------------------------------------------- /tests/__init__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | """ 4 | @Time : 2023/4/29 15:53 5 | @Author : alexanderwu 6 | @File : __init__.py 7 | """ 8 | -------------------------------------------------------------------------------- /tests/config2.yaml: -------------------------------------------------------------------------------- 1 | llm: 2 | base_url: "https://api.openai.com/v1" 3 | api_key: "sk-xxx" 4 | model: "gpt-3.5-turbo" 5 | 6 | search: 7 | api_type: "serpapi" 8 | api_key: "xxx" 9 | 10 | s3: 11 | access_key: "MOCK_S3_ACCESS_KEY" 12 | secret_key: "MOCK_S3_SECRET_KEY" 13 | endpoint: "http://mock:9000" 14 | secure: false 15 | bucket: "mock" 16 | 17 | azure_tts_subscription_key: "xxx" 18 | azure_tts_region: "eastus" 19 | 20 | iflytek_app_id: "xxx" 21 | iflytek_api_key: "xxx" 22 | iflytek_api_secret: "xxx" 23 | 24 | metagpt_tti_url: "http://mock.com" 25 | 26 | repair_llm_output: true 27 | 28 | -------------------------------------------------------------------------------- /tests/data/andriod_assistant/.gitignore: -------------------------------------------------------------------------------- 1 | !*.png 2 | unitest_Contacts -------------------------------------------------------------------------------- /tests/data/andriod_assistant/demo_Contacts/labeled_screenshots/0_labeled.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FoundationAgents/MetaGPT/ba2868974b2ecc3fe4218ad29dd334867c07f678/tests/data/andriod_assistant/demo_Contacts/labeled_screenshots/0_labeled.png -------------------------------------------------------------------------------- /tests/data/andriod_assistant/demo_Contacts/labeled_screenshots/1_labeled.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FoundationAgents/MetaGPT/ba2868974b2ecc3fe4218ad29dd334867c07f678/tests/data/andriod_assistant/demo_Contacts/labeled_screenshots/1_labeled.png -------------------------------------------------------------------------------- /tests/data/andriod_assistant/demo_Contacts/record.txt: -------------------------------------------------------------------------------- 1 | tap(9):::android.view.ViewGroup_1067_236_android.widget.TextView_183_204_Apps_2 2 | stop 3 | -------------------------------------------------------------------------------- /tests/data/andriod_assistant/demo_Contacts/task_desc.txt: -------------------------------------------------------------------------------- 1 | Create a contact in Contacts App named zjy with a phone number +86 18831933368 -------------------------------------------------------------------------------- /tests/data/audio/hello.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FoundationAgents/MetaGPT/ba2868974b2ecc3fe4218ad29dd334867c07f678/tests/data/audio/hello.mp3 -------------------------------------------------------------------------------- /tests/data/demo_project/code_summaries.json: -------------------------------------------------------------------------------- 1 | {"design_filename": "docs/system_design/20231221155954.json", "task_filename": "docs/tasks/20231221155954.json", "codes_filenames": ["game.py", "main.py"], "reason": "```json\n{\n \"game.py\": \"Add handling for no empty cells in add_new_tile function, Update score in move function\",\n \"main.py\": \"Handle game over condition in the game loop\"\n}\n```"} -------------------------------------------------------------------------------- /tests/data/demo_project/dependencies.json: -------------------------------------------------------------------------------- 1 | {"docs/system_design/20231221155954.json": ["docs/prd/20231221155954.json"], "docs/task/20231221155954.json": ["docs/system_design/20231221155954.json"], "game_2048/game.py": ["docs/task/20231221155954.json", "docs/system_design/20231221155954.json"], "game_2048/main.py": ["docs/task/20231221155954.json", "docs/system_design/20231221155954.json"], "resources/code_summary/20231221155954.md": ["docs/task/20231221155954.json", "game_2048/game.py", "docs/system_design/20231221155954.json", "game_2048/main.py"], "docs/code_summary/20231221155954.json": ["docs/task/20231221155954.json", "game_2048/game.py", "docs/system_design/20231221155954.json", "game_2048/main.py"], "tests/test_main.py": ["game_2048/main.py"], "tests/test_game.py": ["game_2048/game.py"], "test_outputs/test_main.py.json": ["game_2048/main.py", "tests/test_main.py"], "test_outputs/test_game.py.json": ["game_2048/game.py", "tests/test_game.py"]} -------------------------------------------------------------------------------- /tests/data/demo_project/tasks.json: -------------------------------------------------------------------------------- 1 | {"Required Python packages": ["pygame==2.0.1"], "Required Other language third-party packages": ["No third-party dependencies required"], "Logic Analysis": [["game.py", "Contains Game class and related functions for game logic"], ["main.py", "Contains main function, initializes the game and UI"]], "Task list": ["game.py", "main.py"], "Full API spec": "", "Shared Knowledge": "The game logic will be implemented using Python classes and data structures. The Pygame library will be used to create the game interface and handle user input.", "Anything UNCLEAR": "..."} -------------------------------------------------------------------------------- /tests/data/docx_for_test.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FoundationAgents/MetaGPT/ba2868974b2ecc3fe4218ad29dd334867c07f678/tests/data/docx_for_test.docx -------------------------------------------------------------------------------- /tests/data/incremental_dev_project/Gomoku.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FoundationAgents/MetaGPT/ba2868974b2ecc3fe4218ad29dd334867c07f678/tests/data/incremental_dev_project/Gomoku.zip -------------------------------------------------------------------------------- /tests/data/incremental_dev_project/dice_simulator_new.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FoundationAgents/MetaGPT/ba2868974b2ecc3fe4218ad29dd334867c07f678/tests/data/incremental_dev_project/dice_simulator_new.zip -------------------------------------------------------------------------------- /tests/data/incremental_dev_project/number_guessing_game.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FoundationAgents/MetaGPT/ba2868974b2ecc3fe4218ad29dd334867c07f678/tests/data/incremental_dev_project/number_guessing_game.zip -------------------------------------------------------------------------------- /tests/data/incremental_dev_project/pygame_2048.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FoundationAgents/MetaGPT/ba2868974b2ecc3fe4218ad29dd334867c07f678/tests/data/incremental_dev_project/pygame_2048.zip -------------------------------------------------------------------------------- /tests/data/incremental_dev_project/readme.md: -------------------------------------------------------------------------------- 1 | # Code archive 2 | 3 | This folder contains a compressed package for the test_incremental_dev.py file, which is used to demonstrate the process of incremental development. 4 | -------------------------------------------------------------------------------- /tests/data/incremental_dev_project/simple_add_calculator.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FoundationAgents/MetaGPT/ba2868974b2ecc3fe4218ad29dd334867c07f678/tests/data/incremental_dev_project/simple_add_calculator.zip -------------------------------------------------------------------------------- /tests/data/incremental_dev_project/snake_game.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FoundationAgents/MetaGPT/ba2868974b2ecc3fe4218ad29dd334867c07f678/tests/data/incremental_dev_project/snake_game.zip -------------------------------------------------------------------------------- /tests/data/incremental_dev_project/word_cloud.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FoundationAgents/MetaGPT/ba2868974b2ecc3fe4218ad29dd334867c07f678/tests/data/incremental_dev_project/word_cloud.zip -------------------------------------------------------------------------------- /tests/data/invoices/invoice-1.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FoundationAgents/MetaGPT/ba2868974b2ecc3fe4218ad29dd334867c07f678/tests/data/invoices/invoice-1.pdf -------------------------------------------------------------------------------- /tests/data/invoices/invoice-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FoundationAgents/MetaGPT/ba2868974b2ecc3fe4218ad29dd334867c07f678/tests/data/invoices/invoice-2.png -------------------------------------------------------------------------------- /tests/data/invoices/invoice-3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FoundationAgents/MetaGPT/ba2868974b2ecc3fe4218ad29dd334867c07f678/tests/data/invoices/invoice-3.jpg -------------------------------------------------------------------------------- /tests/data/invoices/invoice-4.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FoundationAgents/MetaGPT/ba2868974b2ecc3fe4218ad29dd334867c07f678/tests/data/invoices/invoice-4.zip -------------------------------------------------------------------------------- /tests/data/movie/trailer.mp4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FoundationAgents/MetaGPT/ba2868974b2ecc3fe4218ad29dd334867c07f678/tests/data/movie/trailer.mp4 -------------------------------------------------------------------------------- /tests/data/tools/test_script_for_file_manager.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FoundationAgents/MetaGPT/ba2868974b2ecc3fe4218ad29dd334867c07f678/tests/data/tools/test_script_for_file_manager.py -------------------------------------------------------------------------------- /tests/metagpt/__init__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | """ 4 | @Time : 2023/4/29 16:01 5 | @Author : alexanderwu 6 | @File : __init__.py 7 | """ 8 | -------------------------------------------------------------------------------- /tests/metagpt/actions/__init__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | """ 4 | @Time : 2023/5/11 19:35 5 | @Author : alexanderwu 6 | @File : __init__.py 7 | """ 8 | -------------------------------------------------------------------------------- /tests/metagpt/actions/di/test_ask_review.py: -------------------------------------------------------------------------------- 1 | import pytest 2 | 3 | from metagpt.actions.di.ask_review import AskReview 4 | 5 | 6 | @pytest.mark.asyncio 7 | async def test_ask_review(mocker): 8 | mock_review_input = "confirm" 9 | mocker.patch("metagpt.actions.di.ask_review.get_human_input", return_value=mock_review_input) 10 | rsp, confirmed = await AskReview().run() 11 | assert rsp == mock_review_input 12 | assert confirmed 13 | -------------------------------------------------------------------------------- /tests/metagpt/actions/requirement_analysis/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FoundationAgents/MetaGPT/ba2868974b2ecc3fe4218ad29dd334867c07f678/tests/metagpt/actions/requirement_analysis/__init__.py -------------------------------------------------------------------------------- /tests/metagpt/actions/requirement_analysis/requirement/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FoundationAgents/MetaGPT/ba2868974b2ecc3fe4218ad29dd334867c07f678/tests/metagpt/actions/requirement_analysis/requirement/__init__.py -------------------------------------------------------------------------------- /tests/metagpt/actions/requirement_analysis/requirement/test_pic2txt.py: -------------------------------------------------------------------------------- 1 | import pytest 2 | 3 | from metagpt.actions.requirement_analysis.requirement.pic2txt import Pic2Txt 4 | from metagpt.const import TEST_DATA_PATH 5 | from metagpt.utils.common import aread 6 | 7 | 8 | @pytest.mark.asyncio 9 | async def test_pic2txt(context): 10 | images = [ 11 | TEST_DATA_PATH / "requirements/pic/1.png", 12 | TEST_DATA_PATH / "requirements/pic/2.png", 13 | TEST_DATA_PATH / "requirements/pic/3.png", 14 | ] 15 | textual_user_requirements = await aread(filename=TEST_DATA_PATH / "requirements/1.original_requirement.txt") 16 | 17 | action = Pic2Txt(context=context) 18 | rsp = await action.run( 19 | image_paths=images, 20 | textual_user_requirement=textual_user_requirements, 21 | ) 22 | assert rsp 23 | 24 | 25 | if __name__ == "__main__": 26 | pytest.main([__file__, "-s"]) 27 | -------------------------------------------------------------------------------- /tests/metagpt/actions/test_extract_readme.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | from pathlib import Path 4 | 5 | import pytest 6 | 7 | from metagpt.actions.extract_readme import ExtractReadMe 8 | from metagpt.llm import LLM 9 | 10 | 11 | @pytest.mark.asyncio 12 | async def test_learn_readme(context): 13 | action = ExtractReadMe( 14 | name="RedBean", 15 | i_context=str(Path(__file__).parent.parent.parent.parent), 16 | llm=LLM(), 17 | context=context, 18 | ) 19 | await action.run() 20 | rows = await action.graph_db.select() 21 | assert rows 22 | assert context.repo.docs.graph_repo.changed_files 23 | 24 | 25 | if __name__ == "__main__": 26 | pytest.main([__file__, "-s"]) 27 | -------------------------------------------------------------------------------- /tests/metagpt/actions/test_fix_bug.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | """ 4 | @Time : 2023/12/25 22:38 5 | @Author : alexanderwu 6 | @File : test_fix_bug.py 7 | """ 8 | 9 | import pytest 10 | 11 | from metagpt.actions.fix_bug import FixBug 12 | 13 | 14 | @pytest.mark.asyncio 15 | async def test_fix_bug(context): 16 | fix_bug = FixBug(context=context) 17 | assert fix_bug.name == "FixBug" 18 | -------------------------------------------------------------------------------- /tests/metagpt/actions/test_generate_questions.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | """ 4 | @Time : 2023/9/13 00:26 5 | @Author : fisherdeng 6 | @File : test_generate_questions.py 7 | """ 8 | import pytest 9 | 10 | from metagpt.actions.generate_questions import GenerateQuestions 11 | from metagpt.logs import logger 12 | 13 | msg = """ 14 | ## topic 15 | 如何做一个生日蛋糕 16 | 17 | ## record 18 | 我认为应该先准备好材料,然后再开始做蛋糕。 19 | """ 20 | 21 | 22 | @pytest.mark.asyncio 23 | async def test_generate_questions(context): 24 | action = GenerateQuestions(context=context) 25 | rsp = await action.run(msg) 26 | logger.info(f"{rsp.content=}") 27 | 28 | assert "Questions" in rsp.content 29 | assert "1." in rsp.content 30 | -------------------------------------------------------------------------------- /tests/metagpt/actions/test_prepare_documents.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | """ 4 | @Time : 2023/12/6 5 | @Author : mashenquan 6 | @File : test_prepare_documents.py 7 | @Desc: Unit test for prepare_documents.py 8 | """ 9 | import pytest 10 | 11 | from metagpt.actions.prepare_documents import PrepareDocuments 12 | from metagpt.const import REQUIREMENT_FILENAME 13 | from metagpt.context import Context 14 | from metagpt.schema import Message 15 | 16 | 17 | @pytest.mark.asyncio 18 | async def test_prepare_documents(): 19 | msg = Message(content="New user requirements balabala...") 20 | context = Context() 21 | 22 | await PrepareDocuments(context=context).run(with_messages=[msg]) 23 | assert context.git_repo 24 | assert context.repo 25 | doc = await context.repo.docs.get(filename=REQUIREMENT_FILENAME) 26 | assert doc 27 | assert doc.content == msg.content 28 | -------------------------------------------------------------------------------- /tests/metagpt/actions/test_prepare_interview.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | """ 4 | @Time : 2023/9/13 00:26 5 | @Author : fisherdeng 6 | @File : test_generate_questions.py 7 | """ 8 | import pytest 9 | 10 | from metagpt.actions.prepare_interview import PrepareInterview 11 | from metagpt.logs import logger 12 | 13 | 14 | @pytest.mark.asyncio 15 | async def test_prepare_interview(context): 16 | action = PrepareInterview(context=context) 17 | rsp = await action.run("I just graduated and hope to find a job as a Python engineer") 18 | logger.info(f"{rsp.content=}") 19 | 20 | assert "Questions" in rsp.content 21 | assert "1." in rsp.content 22 | -------------------------------------------------------------------------------- /tests/metagpt/actions/test_write_teaching_plan.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | """ 4 | @Time : 2023/7/28 17:25 5 | @Author : mashenquan 6 | @File : test_write_teaching_plan.py 7 | """ 8 | 9 | import pytest 10 | 11 | from metagpt.actions.write_teaching_plan import WriteTeachingPlanPart 12 | 13 | 14 | @pytest.mark.asyncio 15 | @pytest.mark.parametrize( 16 | ("topic", "content"), 17 | [("Title", "Lesson 1: Learn to draw an apple."), ("Teaching Content", "Lesson 1: Learn to draw an apple.")], 18 | ) 19 | async def test_write_teaching_plan_part(topic, content, context): 20 | action = WriteTeachingPlanPart(topic=topic, i_context=content, context=context) 21 | rsp = await action.run() 22 | assert rsp 23 | 24 | 25 | if __name__ == "__main__": 26 | pytest.main([__file__, "-s"]) 27 | -------------------------------------------------------------------------------- /tests/metagpt/configs/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FoundationAgents/MetaGPT/ba2868974b2ecc3fe4218ad29dd334867c07f678/tests/metagpt/configs/__init__.py -------------------------------------------------------------------------------- /tests/metagpt/document_store/__init__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | """ 4 | @Time : 2023/5/27 20:19 5 | @Author : alexanderwu 6 | @File : __init__.py 7 | """ 8 | -------------------------------------------------------------------------------- /tests/metagpt/document_store/test_milvus_store.py: -------------------------------------------------------------------------------- 1 | import random 2 | 3 | seed_value = 42 4 | random.seed(seed_value) 5 | 6 | vectors = [[random.random() for _ in range(8)] for _ in range(10)] 7 | ids = [f"doc_{i}" for i in range(10)] 8 | metadata = [{"color": "red", "rand_number": i % 10} for i in range(10)] 9 | 10 | 11 | def assert_almost_equal(actual, expected): 12 | delta = 1e-10 13 | if isinstance(expected, list): 14 | assert len(actual) == len(expected) 15 | for ac, exp in zip(actual, expected): 16 | assert abs(ac - exp) <= delta, f"{ac} is not within {delta} of {exp}" 17 | else: 18 | assert abs(actual - expected) <= delta, f"{actual} is not within {delta} of {expected}" 19 | -------------------------------------------------------------------------------- /tests/metagpt/environment/android_env/__init__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | # @Desc : 4 | -------------------------------------------------------------------------------- /tests/metagpt/environment/api/__init__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | # @Desc : 4 | -------------------------------------------------------------------------------- /tests/metagpt/environment/api/test_env_api.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | # @Desc : 4 | 5 | from metagpt.environment.api.env_api import EnvAPIRegistry 6 | 7 | 8 | def test_env_api_registry(): 9 | def test_func(): 10 | pass 11 | 12 | env_api_registry = EnvAPIRegistry() 13 | env_api_registry["test"] = test_func 14 | 15 | env_api_registry.get("test") == test_func 16 | -------------------------------------------------------------------------------- /tests/metagpt/environment/minecraft_env/__init__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | # @Desc : 4 | -------------------------------------------------------------------------------- /tests/metagpt/environment/minecraft_env/test_minecraft_ext_env.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | # @Desc : the unittest of MinecraftExtEnv 4 | 5 | 6 | from metagpt.environment.minecraft.const import MC_CKPT_DIR 7 | from metagpt.environment.minecraft.minecraft_ext_env import MinecraftExtEnv 8 | 9 | 10 | def test_minecraft_ext_env(): 11 | ext_env = MinecraftExtEnv() 12 | assert ext_env.server, f"{ext_env.server_host}:{ext_env.server_port}" 13 | assert MC_CKPT_DIR.joinpath("skill/code").exists() 14 | assert ext_env.warm_up.get("optional_inventory_items") == 7 15 | -------------------------------------------------------------------------------- /tests/metagpt/environment/stanford_town_env/__init__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | # @Desc : 4 | -------------------------------------------------------------------------------- /tests/metagpt/environment/werewolf_env/__init__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | # @Desc : 4 | -------------------------------------------------------------------------------- /tests/metagpt/ext/__init__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | # @Desc : 4 | -------------------------------------------------------------------------------- /tests/metagpt/ext/android_assistant/__init__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | # @Desc : 4 | -------------------------------------------------------------------------------- /tests/metagpt/ext/stanford_town/__init__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | # @Desc : 4 | -------------------------------------------------------------------------------- /tests/metagpt/ext/stanford_town/actions/__init__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | # @Desc : 4 | -------------------------------------------------------------------------------- /tests/metagpt/ext/stanford_town/actions/test_summarize_conv.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | # @Desc : unittest of actions/summarize_conv 4 | 5 | import pytest 6 | 7 | from metagpt.ext.stanford_town.actions.summarize_conv import SummarizeConv 8 | 9 | 10 | @pytest.mark.asyncio 11 | async def test_summarize_conv(): 12 | conv = [("Role_A", "what's the weather today?"), ("Role_B", "It looks pretty good, and I will take a walk then.")] 13 | 14 | output = await SummarizeConv().run(conv) 15 | assert "weather" in output 16 | -------------------------------------------------------------------------------- /tests/metagpt/ext/stanford_town/memory/__init__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | # @Desc : 4 | -------------------------------------------------------------------------------- /tests/metagpt/ext/stanford_town/memory/test_spatial_memory.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | # @Desc : the unittest of MemoryTree 4 | 5 | from metagpt.ext.stanford_town.memory.spatial_memory import MemoryTree 6 | from metagpt.ext.stanford_town.utils.const import STORAGE_PATH 7 | 8 | 9 | def test_spatial_memory(): 10 | f_path = STORAGE_PATH.joinpath( 11 | "base_the_ville_isabella_maria_klaus/personas/Isabella Rodriguez/bootstrap_memory/spatial_memory.json" 12 | ) 13 | x = MemoryTree() 14 | x.set_mem_path(f_path) 15 | assert x.tree 16 | assert "the Ville" in x.tree 17 | assert "Isabella Rodriguez's apartment" in x.get_str_accessible_sectors("the Ville") 18 | -------------------------------------------------------------------------------- /tests/metagpt/ext/stanford_town/plan/__init__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | # @Desc : 4 | -------------------------------------------------------------------------------- /tests/metagpt/ext/stanford_town/plan/test_st_plan.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | # @Desc : unittest of st_plan 4 | 5 | 6 | import pytest 7 | 8 | from metagpt.ext.stanford_town.plan.st_plan import _choose_retrieved, _should_react 9 | from tests.metagpt.ext.stanford_town.plan.test_conversation import init_two_roles 10 | 11 | 12 | @pytest.mark.asyncio 13 | async def test_should_react(): 14 | role_ir, role_km = await init_two_roles() 15 | roles = {role_ir.name: role_ir, role_km.name: role_km} 16 | role_ir.scratch.act_address = "mock data" 17 | 18 | observed = await role_ir.observe() 19 | retrieved = role_ir.retrieve(observed) 20 | 21 | focused_event = _choose_retrieved(role_ir.name, retrieved) 22 | 23 | if focused_event: 24 | reaction_mode = await _should_react(role_ir, focused_event, roles) # chat with Isabella Rodriguez 25 | assert not reaction_mode 26 | -------------------------------------------------------------------------------- /tests/metagpt/ext/stanford_town/roles/__init__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | # @Desc : 4 | -------------------------------------------------------------------------------- /tests/metagpt/ext/werewolf/__init__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | # @Desc : 4 | -------------------------------------------------------------------------------- /tests/metagpt/ext/werewolf/actions/__init__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | # @Desc : 4 | -------------------------------------------------------------------------------- /tests/metagpt/learn/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FoundationAgents/MetaGPT/ba2868974b2ecc3fe4218ad29dd334867c07f678/tests/metagpt/learn/__init__.py -------------------------------------------------------------------------------- /tests/metagpt/learn/test_google_search.py: -------------------------------------------------------------------------------- 1 | import pytest 2 | from pydantic import BaseModel 3 | 4 | from metagpt.learn.google_search import google_search 5 | from metagpt.tools import SearchEngineType 6 | 7 | 8 | @pytest.mark.asyncio 9 | async def test_google_search(search_engine_mocker): 10 | class Input(BaseModel): 11 | input: str 12 | 13 | inputs = [{"input": "ai agent"}] 14 | for i in inputs: 15 | seed = Input(**i) 16 | result = await google_search( 17 | seed.input, 18 | engine=SearchEngineType.SERPER_GOOGLE, 19 | api_key="mock-serper-key", 20 | ) 21 | assert result != "" 22 | -------------------------------------------------------------------------------- /tests/metagpt/management/__init__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | """ 4 | @Time : 2023/6/6 12:38 5 | @Author : alexanderwu 6 | @File : __init__.py 7 | """ 8 | -------------------------------------------------------------------------------- /tests/metagpt/memory/__init__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | # @Desc : 4 | -------------------------------------------------------------------------------- /tests/metagpt/provider/__init__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | """ 4 | @Time : 2023/5/6 17:32 5 | @Author : alexanderwu 6 | @File : __init__.py 7 | """ 8 | -------------------------------------------------------------------------------- /tests/metagpt/provider/conftest.py: -------------------------------------------------------------------------------- 1 | import pytest 2 | 3 | 4 | @pytest.fixture(autouse=True) 5 | def llm_mock(rsp_cache, mocker, request): 6 | # An empty fixture to overwrite the global llm_mock fixture 7 | # because in provider folder, we want to test the aask and aask functions for the specific models 8 | pass 9 | -------------------------------------------------------------------------------- /tests/metagpt/provider/postprocess/__init__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | # @Desc : 4 | -------------------------------------------------------------------------------- /tests/metagpt/provider/postprocess/test_base_postprocess_plugin.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | # @Desc : 4 | 5 | 6 | from metagpt.provider.postprocess.base_postprocess_plugin import BasePostProcessPlugin 7 | 8 | raw_output = """ 9 | [CONTENT] 10 | { 11 | "Original Requirements": "xxx" 12 | } 13 | [/CONTENT] 14 | """ 15 | raw_schema = { 16 | "title": "prd", 17 | "type": "object", 18 | "properties": { 19 | "Original Requirements": {"title": "Original Requirements", "type": "string"}, 20 | }, 21 | "required": [ 22 | "Original Requirements", 23 | ], 24 | } 25 | 26 | 27 | def test_llm_post_process_plugin(): 28 | post_process_plugin = BasePostProcessPlugin() 29 | 30 | output = post_process_plugin.run(output=raw_output, schema=raw_schema) 31 | assert "Original Requirements" in output 32 | -------------------------------------------------------------------------------- /tests/metagpt/provider/postprocess/test_llm_output_postprocess.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | # @Desc : 4 | 5 | 6 | from metagpt.provider.postprocess.llm_output_postprocess import llm_output_postprocess 7 | from tests.metagpt.provider.postprocess.test_base_postprocess_plugin import ( 8 | raw_output, 9 | raw_schema, 10 | ) 11 | 12 | 13 | def test_llm_output_postprocess(): 14 | output = llm_output_postprocess(output=raw_output, schema=raw_schema) 15 | assert "Original Requirements" in output 16 | -------------------------------------------------------------------------------- /tests/metagpt/provider/test_azure_llm.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | # @Desc : 4 | 5 | from metagpt.provider import AzureOpenAILLM 6 | from tests.metagpt.provider.mock_llm_config import mock_llm_config_azure 7 | 8 | 9 | def test_azure_llm(): 10 | llm = AzureOpenAILLM(mock_llm_config_azure) 11 | kwargs = llm._make_client_kwargs() 12 | assert kwargs["azure_endpoint"] == mock_llm_config_azure.base_url 13 | -------------------------------------------------------------------------------- /tests/metagpt/provider/test_metagpt_llm.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | """ 4 | @Time : 2023/8/30 5 | @Author : mashenquan 6 | @File : test_metagpt_llm.py 7 | """ 8 | from metagpt.provider.metagpt_api import MetaGPTLLM 9 | from tests.metagpt.provider.mock_llm_config import mock_llm_config 10 | 11 | 12 | def test_metagpt(): 13 | llm = MetaGPTLLM(mock_llm_config) 14 | assert llm 15 | 16 | 17 | if __name__ == "__main__": 18 | test_metagpt() 19 | -------------------------------------------------------------------------------- /tests/metagpt/provider/zhipuai/__init__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | # @Desc : 4 | -------------------------------------------------------------------------------- /tests/metagpt/provider/zhipuai/test_async_sse_client.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | # @Desc : 4 | 5 | import pytest 6 | 7 | from metagpt.provider.zhipuai.async_sse_client import AsyncSSEClient 8 | 9 | 10 | @pytest.mark.asyncio 11 | async def test_async_sse_client(): 12 | class Iterator(object): 13 | async def __aiter__(self): 14 | yield b'data: {"test_key": "test_value"}' 15 | 16 | async_sse_client = AsyncSSEClient(event_source=Iterator()) 17 | async for chunk in async_sse_client.stream(): 18 | assert "test_value" in chunk.values() 19 | 20 | class InvalidIterator(object): 21 | async def __aiter__(self): 22 | yield b"invalid: test_value" 23 | 24 | async_sse_client = AsyncSSEClient(event_source=InvalidIterator()) 25 | async for chunk in async_sse_client.stream(): 26 | assert not chunk 27 | -------------------------------------------------------------------------------- /tests/metagpt/rag/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FoundationAgents/MetaGPT/ba2868974b2ecc3fe4218ad29dd334867c07f678/tests/metagpt/rag/__init__.py -------------------------------------------------------------------------------- /tests/metagpt/rag/retrievers/test_base_retriever.py: -------------------------------------------------------------------------------- 1 | from metagpt.rag.retrievers.base import ModifiableRAGRetriever, PersistableRAGRetriever 2 | 3 | 4 | class SubModifiableRAGRetriever(ModifiableRAGRetriever): 5 | ... 6 | 7 | 8 | class SubPersistableRAGRetriever(PersistableRAGRetriever): 9 | ... 10 | 11 | 12 | class TestModifiableRAGRetriever: 13 | def test_subclasshook(self): 14 | result = SubModifiableRAGRetriever.__subclasshook__(SubModifiableRAGRetriever) 15 | assert result is NotImplemented 16 | 17 | 18 | class TestPersistableRAGRetriever: 19 | def test_subclasshook(self): 20 | result = SubPersistableRAGRetriever.__subclasshook__(SubPersistableRAGRetriever) 21 | assert result is NotImplemented 22 | -------------------------------------------------------------------------------- /tests/metagpt/rag/retrievers/test_chroma_retriever.py: -------------------------------------------------------------------------------- 1 | import pytest 2 | from llama_index.core.schema import Node 3 | 4 | from metagpt.rag.retrievers.chroma_retriever import ChromaRetriever 5 | 6 | 7 | class TestChromaRetriever: 8 | @pytest.fixture(autouse=True) 9 | def setup(self, mocker): 10 | self.doc1 = mocker.MagicMock(spec=Node) 11 | self.doc2 = mocker.MagicMock(spec=Node) 12 | self.mock_nodes = [self.doc1, self.doc2] 13 | 14 | self.mock_index = mocker.MagicMock() 15 | self.retriever = ChromaRetriever(self.mock_index) 16 | 17 | def test_add_nodes(self): 18 | self.retriever.add_nodes(self.mock_nodes) 19 | 20 | self.mock_index.insert_nodes.assert_called() 21 | -------------------------------------------------------------------------------- /tests/metagpt/rag/retrievers/test_es_retriever.py: -------------------------------------------------------------------------------- 1 | import pytest 2 | from llama_index.core.schema import Node 3 | 4 | from metagpt.rag.retrievers.es_retriever import ElasticsearchRetriever 5 | 6 | 7 | class TestElasticsearchRetriever: 8 | @pytest.fixture(autouse=True) 9 | def setup(self, mocker): 10 | self.doc1 = mocker.MagicMock(spec=Node) 11 | self.doc2 = mocker.MagicMock(spec=Node) 12 | self.mock_nodes = [self.doc1, self.doc2] 13 | 14 | self.mock_index = mocker.MagicMock() 15 | self.retriever = ElasticsearchRetriever(self.mock_index) 16 | 17 | def test_add_nodes(self): 18 | self.retriever.add_nodes(self.mock_nodes) 19 | 20 | self.mock_index.insert_nodes.assert_called() 21 | -------------------------------------------------------------------------------- /tests/metagpt/rag/retrievers/test_faiss_retriever.py: -------------------------------------------------------------------------------- 1 | import pytest 2 | from llama_index.core.schema import Node 3 | 4 | from metagpt.rag.retrievers.faiss_retriever import FAISSRetriever 5 | 6 | 7 | class TestFAISSRetriever: 8 | @pytest.fixture(autouse=True) 9 | def setup(self, mocker): 10 | self.doc1 = mocker.MagicMock(spec=Node) 11 | self.doc2 = mocker.MagicMock(spec=Node) 12 | self.mock_nodes = [self.doc1, self.doc2] 13 | 14 | self.mock_index = mocker.MagicMock() 15 | self.retriever = FAISSRetriever(self.mock_index) 16 | 17 | def test_add_docs_calls_insert_for_each_document(self): 18 | self.retriever.add_nodes(self.mock_nodes) 19 | 20 | self.mock_index.insert_nodes.assert_called() 21 | 22 | def test_persist(self): 23 | self.retriever.persist("") 24 | 25 | self.mock_index.storage_context.persist.assert_called() 26 | -------------------------------------------------------------------------------- /tests/metagpt/roles/__init__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | """ 4 | @Time : 2023/5/12 10:14 5 | @Author : alexanderwu 6 | @File : __init__.py 7 | """ 8 | -------------------------------------------------------------------------------- /tests/metagpt/roles/test_project_manager.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | """ 4 | @Time : 2023/5/12 10:23 5 | @Author : alexanderwu 6 | @File : test_project_manager.py 7 | """ 8 | import pytest 9 | 10 | from metagpt.logs import logger 11 | from metagpt.roles import ProjectManager 12 | from tests.metagpt.roles.mock import MockMessages 13 | 14 | 15 | @pytest.mark.asyncio 16 | async def test_project_manager(context): 17 | project_manager = ProjectManager(context=context) 18 | rsp = await project_manager.run(MockMessages.tasks) 19 | logger.info(rsp) 20 | -------------------------------------------------------------------------------- /tests/metagpt/roles/test_tutorial_assistant.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # _*_ coding: utf-8 _*_ 3 | """ 4 | @Time : 2023/9/6 23:11:27 5 | @Author : Stitch-z 6 | @File : test_tutorial_assistant.py 7 | """ 8 | 9 | import pytest 10 | 11 | from metagpt.const import TUTORIAL_PATH 12 | from metagpt.roles.tutorial_assistant import TutorialAssistant 13 | from metagpt.utils.common import aread 14 | 15 | 16 | @pytest.mark.asyncio 17 | @pytest.mark.parametrize(("language", "topic"), [("Chinese", "Write a tutorial about pip")]) 18 | async def test_tutorial_assistant(language: str, topic: str, context): 19 | role = TutorialAssistant(language=language, context=context) 20 | msg = await role.run(topic) 21 | assert TUTORIAL_PATH.exists() 22 | filename = msg.content 23 | content = await aread(filename=filename) 24 | assert "pip" in content 25 | 26 | 27 | if __name__ == "__main__": 28 | pytest.main([__file__, "-s"]) 29 | -------------------------------------------------------------------------------- /tests/metagpt/serialize_deserialize/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # @Date : 11/22/2023 11:48 AM 3 | # @Author : stellahong (stellahong@fuzhi.ai) 4 | # @Desc : 5 | -------------------------------------------------------------------------------- /tests/metagpt/serialize_deserialize/test_prepare_interview.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # @Desc : 3 | 4 | import pytest 5 | 6 | from metagpt.actions.action_node import ActionNode 7 | from metagpt.actions.prepare_interview import PrepareInterview 8 | 9 | 10 | @pytest.mark.asyncio 11 | async def test_action_serdeser(context): 12 | action = PrepareInterview(context=context) 13 | serialized_data = action.model_dump() 14 | assert serialized_data["name"] == "PrepareInterview" 15 | 16 | new_action = PrepareInterview(**serialized_data, context=context) 17 | 18 | assert new_action.name == "PrepareInterview" 19 | assert type(await new_action.run("python developer")) == ActionNode 20 | -------------------------------------------------------------------------------- /tests/metagpt/serialize_deserialize/test_product_manager.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # @Date : 11/26/2023 2:07 PM 3 | # @Author : stellahong (stellahong@fuzhi.ai) 4 | # @Desc : 5 | import pytest 6 | 7 | from metagpt.actions.action import Action 8 | from metagpt.roles.product_manager import ProductManager 9 | from metagpt.schema import Message 10 | 11 | 12 | @pytest.mark.asyncio 13 | async def test_product_manager_serdeser(new_filename, context): 14 | role = ProductManager(context=context) 15 | ser_role_dict = role.model_dump(by_alias=True) 16 | new_role = ProductManager(**ser_role_dict, context=context) 17 | 18 | assert new_role.name == "Alice" 19 | assert len(new_role.actions) == 2 20 | assert isinstance(new_role.actions[0], Action) 21 | await new_role.actions[0].run([Message(content="write a cli snake game")]) 22 | -------------------------------------------------------------------------------- /tests/metagpt/serialize_deserialize/test_reasearcher.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # @Desc : 3 | 4 | import pytest 5 | 6 | from metagpt.actions import CollectLinks 7 | from metagpt.roles.researcher import Researcher 8 | 9 | 10 | @pytest.mark.asyncio 11 | async def test_tutorial_assistant_serdeser(context): 12 | role = Researcher(context=context) 13 | ser_role_dict = role.model_dump() 14 | assert "name" in ser_role_dict 15 | assert "language" in ser_role_dict 16 | 17 | new_role = Researcher(**ser_role_dict, context=context) 18 | assert new_role.language == "en-us" 19 | assert len(new_role.actions) == 3 20 | assert isinstance(new_role.actions[0], CollectLinks) 21 | 22 | # todo: 需要测试不同的action失败下,记忆是否正常保存 23 | -------------------------------------------------------------------------------- /tests/metagpt/serialize_deserialize/test_tutorial_assistant.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # @Desc : 3 | import pytest 4 | 5 | from metagpt.actions.write_tutorial import WriteDirectory 6 | from metagpt.roles.tutorial_assistant import TutorialAssistant 7 | 8 | 9 | @pytest.mark.asyncio 10 | async def test_tutorial_assistant_serdeser(context): 11 | role = TutorialAssistant() 12 | ser_role_dict = role.model_dump() 13 | assert "name" in ser_role_dict 14 | assert "language" in ser_role_dict 15 | assert "topic" in ser_role_dict 16 | 17 | new_role = TutorialAssistant(**ser_role_dict) 18 | assert new_role.name == "Stitch" 19 | assert len(new_role.actions) == 1 20 | assert isinstance(new_role.actions[0], WriteDirectory) 21 | -------------------------------------------------------------------------------- /tests/metagpt/serialize_deserialize/test_write_prd.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # @Date : 11/22/2023 1:47 PM 3 | # @Author : stellahong (stellahong@fuzhi.ai) 4 | # @Desc : 5 | 6 | import pytest 7 | 8 | from metagpt.actions import WritePRD 9 | from metagpt.schema import Message 10 | 11 | 12 | @pytest.mark.asyncio 13 | async def test_action_serdeser(new_filename, context): 14 | action = WritePRD(context=context) 15 | ser_action_dict = action.model_dump() 16 | assert "name" in ser_action_dict 17 | assert "llm" not in ser_action_dict # not export 18 | 19 | new_action = WritePRD(**ser_action_dict, context=context) 20 | assert new_action.name == "WritePRD" 21 | with pytest.raises(FileNotFoundError): 22 | await new_action.run(with_messages=Message(content="write a cli snake game")) 23 | -------------------------------------------------------------------------------- /tests/metagpt/strategy/__init__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | """ 4 | @Time : 2023/12/30 00:33 5 | @Author : alexanderwu 6 | @File : __init__.py 7 | """ 8 | -------------------------------------------------------------------------------- /tests/metagpt/strategy/examples/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # @Date : 12/26/2023 3:32 PM 3 | # @Author : stellahong (stellahong@fuzhi.ai) 4 | # @Desc : 5 | -------------------------------------------------------------------------------- /tests/metagpt/strategy/prompt_templates/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # @Date : 12/23/2023 5:21 PM 3 | # @Author : stellahong (stellahong@fuzhi.ai) 4 | # @Desc : 5 | -------------------------------------------------------------------------------- /tests/metagpt/test_config.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | """ 4 | @Time : 2024/1/9 15:57 5 | @Author : alexanderwu 6 | @File : test_config.py 7 | """ 8 | 9 | from metagpt.config2 import Config 10 | from metagpt.configs.llm_config import LLMType 11 | from tests.metagpt.provider.mock_llm_config import mock_llm_config 12 | 13 | 14 | def test_config_1(): 15 | cfg = Config.default() 16 | llm = cfg.get_openai_llm() 17 | if cfg.llm.api_type == LLMType.OPENAI: 18 | assert llm is not None 19 | 20 | 21 | def test_config_from_dict(): 22 | cfg = Config(llm=mock_llm_config) 23 | assert cfg 24 | assert cfg.llm.api_key == "mock_api_key" 25 | -------------------------------------------------------------------------------- /tests/metagpt/test_team.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | # @Desc : unittest of team 4 | 5 | from metagpt.roles.project_manager import ProjectManager 6 | from metagpt.team import Team 7 | 8 | 9 | def test_team(): 10 | company = Team() 11 | company.hire([ProjectManager()]) 12 | 13 | assert len(company.env.roles) == 1 14 | -------------------------------------------------------------------------------- /tests/metagpt/tools/__init__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | """ 4 | @Time : 2023/4/29 16:27 5 | @Author : alexanderwu 6 | @File : __init__.py 7 | """ 8 | -------------------------------------------------------------------------------- /tests/metagpt/tools/libs/__init__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | # @Time : 2024/1/11 16:14 4 | # @Author : lidanyang 5 | # @File : __init__.py 6 | # @Desc : 7 | -------------------------------------------------------------------------------- /tests/metagpt/tools/libs/test_email_login.py: -------------------------------------------------------------------------------- 1 | from metagpt.tools.libs.email_login import email_login_imap 2 | 3 | 4 | def test_email_login(mocker): 5 | mock_mailbox = mocker.patch("metagpt.tools.libs.email_login.MailBox.login") 6 | mock_mailbox.login.return_value = mocker.Mock() 7 | email_login_imap("test@outlook.com", "test_password") 8 | -------------------------------------------------------------------------------- /tests/metagpt/tools/libs/test_shell.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | import pytest 4 | 5 | from metagpt.tools.libs.shell import shell_execute 6 | 7 | 8 | @pytest.mark.asyncio 9 | @pytest.mark.parametrize( 10 | ["command", "expect_stdout", "expect_stderr"], 11 | [ 12 | (["file", f"{__file__}"], "Python script text executable, ASCII text", ""), 13 | (f"file {__file__}", "Python script text executable, ASCII text", ""), 14 | ], 15 | ) 16 | async def test_shell(command, expect_stdout, expect_stderr): 17 | stdout, stderr, returncode = await shell_execute(command) 18 | assert returncode == 0 19 | assert expect_stdout in stdout 20 | assert stderr == expect_stderr 21 | 22 | 23 | if __name__ == "__main__": 24 | pytest.main([__file__, "-s"]) 25 | -------------------------------------------------------------------------------- /tests/metagpt/tools/libs/test_software_development.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | from typing import Dict 4 | 5 | import pytest 6 | 7 | from metagpt.tools.libs.software_development import import_git_repo 8 | 9 | 10 | async def get_env_description() -> Dict[str, str]: 11 | return {'await get_env(key="access_token", app_name="github")': "get the access token for github authentication."} 12 | 13 | 14 | @pytest.mark.skip 15 | @pytest.mark.asyncio 16 | async def test_import_repo(): 17 | url = "https://github.com/spec-first/connexion.git" 18 | path = await import_git_repo(url) 19 | assert path 20 | 21 | 22 | if __name__ == "__main__": 23 | pytest.main([__file__, "-s"]) 24 | -------------------------------------------------------------------------------- /tests/metagpt/tools/libs/test_terminal.py: -------------------------------------------------------------------------------- 1 | import pytest 2 | 3 | from metagpt.const import DATA_PATH, METAGPT_ROOT 4 | from metagpt.tools.libs.terminal import Terminal 5 | 6 | 7 | @pytest.mark.asyncio 8 | async def test_terminal(): 9 | terminal = Terminal() 10 | 11 | await terminal.run_command(f"cd {METAGPT_ROOT}") 12 | output = await terminal.run_command("pwd") 13 | assert output.strip() == str(METAGPT_ROOT) 14 | 15 | # pwd now should be METAGPT_ROOT, cd data should land in DATA_PATH 16 | await terminal.run_command("cd data") 17 | output = await terminal.run_command("pwd") 18 | assert output.strip() == str(DATA_PATH) 19 | 20 | 21 | if __name__ == "__main__": 22 | pytest.main([__file__, "-s"]) 23 | -------------------------------------------------------------------------------- /tests/metagpt/tools/libs/test_web_scraping.py: -------------------------------------------------------------------------------- 1 | import pytest 2 | 3 | from metagpt.tools.libs.web_scraping import view_page_element_to_scrape 4 | 5 | 6 | @pytest.mark.asyncio 7 | async def test_view_page_element_to_scrape(): 8 | # Define the test URL and parameters 9 | test_url = "https://docs.deepwisdom.ai/main/zh/" 10 | test_requirement = "Retrieve all paragraph texts" 11 | test_keep_links = True 12 | test_page = await view_page_element_to_scrape(test_url, test_requirement, test_keep_links) 13 | assert isinstance(test_page, str) 14 | assert "html" in test_page 15 | -------------------------------------------------------------------------------- /tests/metagpt/tools/test_translate.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | """ 4 | @Time : 2023/5/2 17:46 5 | @Author : alexanderwu 6 | @File : test_translate.py 7 | """ 8 | 9 | import pytest 10 | 11 | from metagpt.logs import logger 12 | from metagpt.tools.translator import Translator 13 | 14 | 15 | @pytest.mark.asyncio 16 | @pytest.mark.usefixtures("llm_api") 17 | async def test_translate(llm_api): 18 | poetries = [ 19 | ("Let life be beautiful like summer flowers", "花"), 20 | ("The ancient Chinese poetries are all songs.", "中国"), 21 | ] 22 | for i, j in poetries: 23 | prompt = Translator.translate_prompt(i) 24 | rsp = await llm_api.aask(prompt) 25 | logger.info(rsp) 26 | assert j in rsp 27 | -------------------------------------------------------------------------------- /tests/metagpt/utils/__init__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | """ 4 | @Time : 2023/4/29 16:01 5 | @Author : alexanderwu 6 | @File : __init__.py 7 | """ 8 | -------------------------------------------------------------------------------- /tests/metagpt/utils/test_read_docx.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | """ 4 | @Time : 2023/4/29 16:02 5 | @Author : alexanderwu 6 | @File : test_read_docx.py 7 | """ 8 | import pytest 9 | 10 | from metagpt.const import METAGPT_ROOT 11 | from metagpt.utils.read_document import read_docx 12 | 13 | 14 | @pytest.mark.skip # https://copyprogramming.com/howto/python-docx-error-opening-file-bad-magic-number-for-file-header-eoferror 15 | class TestReadDocx: 16 | def test_read_docx(self): 17 | docx_sample = METAGPT_ROOT / "tests/data/docx_for_test.docx" 18 | docx = read_docx(docx_sample) 19 | assert len(docx) == 6 20 | -------------------------------------------------------------------------------- /tests/metagpt/utils/test_repo_to_markdown.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | import uuid 4 | from pathlib import Path 5 | 6 | import pytest 7 | 8 | from metagpt.utils.repo_to_markdown import repo_to_markdown 9 | 10 | 11 | @pytest.mark.parametrize( 12 | ["repo_path", "output"], 13 | [ 14 | ( 15 | Path(__file__).parent.parent.parent, 16 | Path(__file__).parent / f"../../../workspace/unittest/{uuid.uuid4().hex}.md", 17 | ), 18 | ], 19 | ) 20 | @pytest.mark.asyncio 21 | async def test_repo_to_markdown(repo_path: Path, output: Path): 22 | markdown = await repo_to_markdown(repo_path=repo_path, output=output) 23 | assert output.exists() 24 | assert markdown 25 | 26 | output.unlink(missing_ok=True) 27 | 28 | 29 | if __name__ == "__main__": 30 | pytest.main([__file__, "-s"]) 31 | -------------------------------------------------------------------------------- /tests/metagpt/utils/test_session.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # _*_ coding: utf-8 _*_ 3 | 4 | import pytest 5 | 6 | 7 | def test_nodeid(request): 8 | print(request.node.nodeid) 9 | assert request.node.nodeid 10 | 11 | 12 | if __name__ == "__main__": 13 | pytest.main([__file__, "-s"]) 14 | -------------------------------------------------------------------------------- /tests/mock/mock_curl_cffi.py: -------------------------------------------------------------------------------- 1 | import json 2 | from typing import Callable 3 | 4 | from curl_cffi import requests 5 | 6 | origin_request = requests.Session.request 7 | 8 | 9 | class MockCurlCffiResponse(requests.Response): 10 | check_funcs: dict[tuple[str, str], Callable[[dict], str]] = {} 11 | rsp_cache: dict[str, str] = {} 12 | name = "curl-cffi" 13 | 14 | def __init__(self, session, method, url, **kwargs) -> None: 15 | super().__init__() 16 | fn = self.check_funcs.get((method, url)) 17 | self.key = f"{self.name}-{method}-{url}-{fn(kwargs) if fn else json.dumps(kwargs, sort_keys=True)}" 18 | self.response = None 19 | if self.key not in self.rsp_cache: 20 | response = origin_request(session, method, url, **kwargs) 21 | self.rsp_cache[self.key] = response.content.decode() 22 | self.content = self.rsp_cache[self.key].encode() 23 | -------------------------------------------------------------------------------- /tests/scripts/run_install_deps.sh: -------------------------------------------------------------------------------- 1 | python -m pip install --upgrade pip 2 | pip install -e .[test] 3 | npm install -g @mermaid-js/mermaid-cli 4 | playwright install --with-deps --------------------------------------------------------------------------------