myagent-ai 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Dockerfile +30 -0
- package/README.md +333 -0
- package/agents/__init__.py +6 -0
- package/agents/__pycache__/main_agent.cpython-312.pyc +0 -0
- package/agents/base.py +115 -0
- package/agents/main_agent.py +695 -0
- package/agents/memory_agent.py +313 -0
- package/agents/tool_agent.py +248 -0
- package/chatbot/__init__.py +5 -0
- package/chatbot/base.py +124 -0
- package/chatbot/discord_bot.py +146 -0
- package/chatbot/feishu_bot.py +548 -0
- package/chatbot/manager.py +164 -0
- package/chatbot/qq_bot.py +189 -0
- package/chatbot/telegram_bot.py +167 -0
- package/chatbot/wechat_bot.py +558 -0
- package/communication/__init__.py +66 -0
- package/communication/channel.py +576 -0
- package/communication/crypto.py +347 -0
- package/communication/manager.py +397 -0
- package/communication/peer.py +156 -0
- package/config.py +464 -0
- package/core/__init__.py +10 -0
- package/core/config_broadcast.py +276 -0
- package/core/llm.py +878 -0
- package/core/logger.py +241 -0
- package/core/task_queue.py +362 -0
- package/core/utils.py +184 -0
- package/executor/__init__.py +4 -0
- package/executor/__pycache__/engine.cpython-312.pyc +0 -0
- package/executor/engine.py +1215 -0
- package/groups/__init__.py +15 -0
- package/groups/manager.py +724 -0
- package/knowledge/__init__.py +4 -0
- package/knowledge/rag.py +444 -0
- package/main.py +801 -0
- package/memory/__init__.py +4 -0
- package/memory/manager.py +840 -0
- package/organization/__init__.py +4 -0
- package/organization/manager.py +350 -0
- package/package.json +58 -0
- package/requirements.txt +59 -0
- package/setup.py +40 -0
- package/skills/ASR/LICENSE.txt +21 -0
- package/skills/ASR/SKILL.md +580 -0
- package/skills/ASR/scripts/asr.ts +27 -0
- package/skills/LLM/LICENSE.txt +21 -0
- package/skills/LLM/SKILL.md +856 -0
- package/skills/LLM/scripts/chat.ts +32 -0
- package/skills/TTS/LICENSE.txt +21 -0
- package/skills/TTS/SKILL.md +735 -0
- package/skills/TTS/tts.ts +25 -0
- package/skills/VLM/LICENSE.txt +21 -0
- package/skills/VLM/SKILL.md +588 -0
- package/skills/VLM/scripts/vlm.ts +57 -0
- package/skills/__init__.py +5 -0
- package/skills/agent-browser/SKILL.md +328 -0
- package/skills/ai-news-collectors/SKILL.md +157 -0
- package/skills/ai-news-collectors/_meta.json +6 -0
- package/skills/ai-news-collectors/references/sources.md +128 -0
- package/skills/aminer-open-academic/SKILL.md +312 -0
- package/skills/aminer-open-academic/_meta.json +6 -0
- package/skills/aminer-open-academic/evals/evals.json +46 -0
- package/skills/aminer-open-academic/references/api-catalog.md +1032 -0
- package/skills/aminer-open-academic/scripts/__pycache__/aminer_client.cpython-312.pyc +0 -0
- package/skills/aminer-open-academic/scripts/aminer_client.py +875 -0
- package/skills/auto-target-tracker/SKILL.md +317 -0
- package/skills/base.py +147 -0
- package/skills/blog-writer/2024-02-17-radical-transparency-sales.md +35 -0
- package/skills/blog-writer/2024-02-17-raycast-spotlight-superpowers.md +33 -0
- package/skills/blog-writer/2024-02-17-short-form-content-marketing.md +47 -0
- package/skills/blog-writer/2024-02-17-typing-speed-benefits.md +33 -0
- package/skills/blog-writer/2024-03-14-effective-ai-prompts.md +55 -0
- package/skills/blog-writer/2024-11-08-ai-revolutionizing-entry-level-sales.md +43 -0
- package/skills/blog-writer/2025-11-12-why-ai-art-is-useless.md +49 -0
- package/skills/blog-writer/README.md +2 -0
- package/skills/blog-writer/SKILL.md +158 -0
- package/skills/blog-writer/__pycache__/manage_examples.cpython-312.pyc +0 -0
- package/skills/blog-writer/_meta.json +6 -0
- package/skills/blog-writer/manage_examples.py +90 -0
- package/skills/blog-writer/style-guide.md +160 -0
- package/skills/browser_skill.py +146 -0
- package/skills/coding-agent/SKILL.md +120 -0
- package/skills/coding-agent/_meta.json +6 -0
- package/skills/coding-agent/criteria.md +48 -0
- package/skills/coding-agent/execution.md +42 -0
- package/skills/coding-agent/memory-template.md +38 -0
- package/skills/coding-agent/planning.md +31 -0
- package/skills/coding-agent/state.md +60 -0
- package/skills/coding-agent/verification.md +39 -0
- package/skills/content-strategy/SKILL.md +181 -0
- package/skills/content-strategy/_meta.json +6 -0
- package/skills/contentanalysis/ExtractWisdom/SKILL.md +229 -0
- package/skills/contentanalysis/ExtractWisdom/Workflows/Extract.md +60 -0
- package/skills/contentanalysis/SKILL.md +14 -0
- package/skills/docx/CHANGELOG.md +85 -0
- package/skills/docx/LICENSE.txt +30 -0
- package/skills/docx/SKILL.md +455 -0
- package/skills/docx/docx-js.md +681 -0
- package/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/dml-chart.xsd +1499 -0
- package/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/dml-chartDrawing.xsd +146 -0
- package/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/dml-diagram.xsd +1085 -0
- package/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/dml-lockedCanvas.xsd +11 -0
- package/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/dml-main.xsd +3081 -0
- package/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/dml-picture.xsd +23 -0
- package/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/dml-spreadsheetDrawing.xsd +185 -0
- package/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/dml-wordprocessingDrawing.xsd +287 -0
- package/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/pml.xsd +1676 -0
- package/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/shared-additionalCharacteristics.xsd +28 -0
- package/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/shared-bibliography.xsd +144 -0
- package/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/shared-commonSimpleTypes.xsd +174 -0
- package/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/shared-customXmlDataProperties.xsd +25 -0
- package/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/shared-customXmlSchemaProperties.xsd +18 -0
- package/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/shared-documentPropertiesCustom.xsd +59 -0
- package/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/shared-documentPropertiesExtended.xsd +56 -0
- package/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/shared-documentPropertiesVariantTypes.xsd +195 -0
- package/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/shared-math.xsd +582 -0
- package/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/shared-relationshipReference.xsd +25 -0
- package/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/sml.xsd +4439 -0
- package/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/vml-main.xsd +570 -0
- package/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/vml-officeDrawing.xsd +509 -0
- package/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/vml-presentationDrawing.xsd +12 -0
- package/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/vml-spreadsheetDrawing.xsd +108 -0
- package/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/vml-wordprocessingDrawing.xsd +96 -0
- package/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/wml.xsd +3646 -0
- package/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/xml.xsd +116 -0
- package/skills/docx/ooxml/schemas/ecma/fouth-edition/opc-contentTypes.xsd +42 -0
- package/skills/docx/ooxml/schemas/ecma/fouth-edition/opc-coreProperties.xsd +50 -0
- package/skills/docx/ooxml/schemas/ecma/fouth-edition/opc-digSig.xsd +49 -0
- package/skills/docx/ooxml/schemas/ecma/fouth-edition/opc-relationships.xsd +33 -0
- package/skills/docx/ooxml/schemas/mce/mc.xsd +75 -0
- package/skills/docx/ooxml/schemas/microsoft/wml-2010.xsd +560 -0
- package/skills/docx/ooxml/schemas/microsoft/wml-2012.xsd +67 -0
- package/skills/docx/ooxml/schemas/microsoft/wml-2018.xsd +14 -0
- package/skills/docx/ooxml/schemas/microsoft/wml-cex-2018.xsd +20 -0
- package/skills/docx/ooxml/schemas/microsoft/wml-cid-2016.xsd +13 -0
- package/skills/docx/ooxml/schemas/microsoft/wml-sdtdatahash-2020.xsd +4 -0
- package/skills/docx/ooxml/schemas/microsoft/wml-symex-2015.xsd +8 -0
- package/skills/docx/ooxml/scripts/__pycache__/pack.cpython-312.pyc +0 -0
- package/skills/docx/ooxml/scripts/__pycache__/unpack.cpython-312.pyc +0 -0
- package/skills/docx/ooxml/scripts/__pycache__/validate.cpython-312.pyc +0 -0
- package/skills/docx/ooxml/scripts/pack.py +159 -0
- package/skills/docx/ooxml/scripts/unpack.py +29 -0
- package/skills/docx/ooxml/scripts/validate.py +69 -0
- package/skills/docx/ooxml/scripts/validation/__init__.py +15 -0
- package/skills/docx/ooxml/scripts/validation/__pycache__/__init__.cpython-312.pyc +0 -0
- package/skills/docx/ooxml/scripts/validation/__pycache__/base.cpython-312.pyc +0 -0
- package/skills/docx/ooxml/scripts/validation/__pycache__/docx.cpython-312.pyc +0 -0
- package/skills/docx/ooxml/scripts/validation/__pycache__/pptx.cpython-312.pyc +0 -0
- package/skills/docx/ooxml/scripts/validation/__pycache__/redlining.cpython-312.pyc +0 -0
- package/skills/docx/ooxml/scripts/validation/base.py +951 -0
- package/skills/docx/ooxml/scripts/validation/docx.py +274 -0
- package/skills/docx/ooxml/scripts/validation/pptx.py +315 -0
- package/skills/docx/ooxml/scripts/validation/redlining.py +279 -0
- package/skills/docx/ooxml.md +615 -0
- package/skills/docx/scripts/__init__.py +1 -0
- package/skills/docx/scripts/__pycache__/__init__.cpython-312.pyc +0 -0
- package/skills/docx/scripts/__pycache__/add_toc_placeholders.cpython-312.pyc +0 -0
- package/skills/docx/scripts/__pycache__/document.cpython-312.pyc +0 -0
- package/skills/docx/scripts/__pycache__/utilities.cpython-312.pyc +0 -0
- package/skills/docx/scripts/add_toc_placeholders.py +220 -0
- package/skills/docx/scripts/document.py +1302 -0
- package/skills/docx/scripts/templates/comments.xml +3 -0
- package/skills/docx/scripts/templates/commentsExtended.xml +3 -0
- package/skills/docx/scripts/templates/commentsExtensible.xml +3 -0
- package/skills/docx/scripts/templates/commentsIds.xml +3 -0
- package/skills/docx/scripts/templates/people.xml +3 -0
- package/skills/docx/scripts/utilities.py +374 -0
- package/skills/dream-interpreter/SKILL.md +88 -0
- package/skills/dream-interpreter/assets/example_asset.txt +24 -0
- package/skills/dream-interpreter/references/api_reference.md +34 -0
- package/skills/dream-interpreter/references/interpretation-guide.md +83 -0
- package/skills/dream-interpreter/references/output-schema.md +65 -0
- package/skills/dream-interpreter/references/questioning-strategy.md +62 -0
- package/skills/dream-interpreter/references/visual-mapping.md +81 -0
- package/skills/dream-interpreter/scripts/__pycache__/example.cpython-312.pyc +0 -0
- package/skills/dream-interpreter/scripts/example.py +19 -0
- package/skills/dream-interpreter/skill.json +7 -0
- package/skills/file_skill.py +246 -0
- package/skills/finance/Finance_API_Doc.md +445 -0
- package/skills/finance/SKILL.md +53 -0
- package/skills/fullstack-dev/SKILL.md +205 -0
- package/skills/get-fortune-analysis/SKILL.md +370 -0
- package/skills/get-fortune-analysis/lunar_python.py +91 -0
- package/skills/gift-evaluator/SKILL.md +83 -0
- package/skills/gift-evaluator/__pycache__/html_tools.cpython-312.pyc +0 -0
- package/skills/gift-evaluator/html_tools.py +268 -0
- package/skills/image-edit/LICENSE.txt +21 -0
- package/skills/image-edit/SKILL.md +896 -0
- package/skills/image-edit/scripts/image-edit.ts +36 -0
- package/skills/image-generation/LICENSE.txt +21 -0
- package/skills/image-generation/SKILL.md +583 -0
- package/skills/image-generation/scripts/image-generation.ts +28 -0
- package/skills/image-understand/LICENSE.txt +21 -0
- package/skills/image-understand/SKILL.md +855 -0
- package/skills/image-understand/scripts/image-understand.ts +41 -0
- package/skills/interview-designer/README.md +70 -0
- package/skills/interview-designer/SKILL.md +53 -0
- package/skills/interview-designer/_meta.json +6 -0
- package/skills/interview-designer/references/design_rationale.md +43 -0
- package/skills/interview-designer/templates/interview_guide_template.md +62 -0
- package/skills/market-research-reports/SKILL.md +901 -0
- package/skills/market-research-reports/assets/FORMATTING_GUIDE.md +428 -0
- package/skills/market-research-reports/assets/market_report_template.tex +1380 -0
- package/skills/market-research-reports/assets/market_research.sty +564 -0
- package/skills/market-research-reports/references/data_analysis_patterns.md +548 -0
- package/skills/market-research-reports/references/report_structure_guide.md +999 -0
- package/skills/market-research-reports/references/visual_generation_guide.md +1077 -0
- package/skills/market-research-reports/scripts/__pycache__/generate_market_visuals.cpython-312.pyc +0 -0
- package/skills/market-research-reports/scripts/generate_market_visuals.py +529 -0
- package/skills/marketing-mode/README.md +49 -0
- package/skills/marketing-mode/SKILL.md +693 -0
- package/skills/marketing-mode/_meta.json +6 -0
- package/skills/marketing-mode/mode-prompt.md +39 -0
- package/skills/marketing-mode/skill.json +51 -0
- package/skills/mindfulness-meditation/SKILL.md +65 -0
- package/skills/mindfulness-meditation/_meta.json +6 -0
- package/skills/multi-search-engine/CHANGELOG.md +15 -0
- package/skills/multi-search-engine/CHANNELLOG.md +48 -0
- package/skills/multi-search-engine/SKILL.md +78 -0
- package/skills/multi-search-engine/_meta.json +6 -0
- package/skills/multi-search-engine/config.json +14 -0
- package/skills/multi-search-engine/metadata.json +7 -0
- package/skills/multi-search-engine/references/international-search.md +651 -0
- package/skills/pdf/LICENSE.txt +30 -0
- package/skills/pdf/SKILL.md +1534 -0
- package/skills/pdf/forms.md +205 -0
- package/skills/pdf/reference.md +765 -0
- package/skills/pdf/scripts/__pycache__/add_zai_metadata.cpython-312.pyc +0 -0
- package/skills/pdf/scripts/__pycache__/check_bounding_boxes.cpython-312.pyc +0 -0
- package/skills/pdf/scripts/__pycache__/check_bounding_boxes_test.cpython-312.pyc +0 -0
- package/skills/pdf/scripts/__pycache__/check_fillable_fields.cpython-312.pyc +0 -0
- package/skills/pdf/scripts/__pycache__/convert_pdf_to_images.cpython-312.pyc +0 -0
- package/skills/pdf/scripts/__pycache__/create_validation_image.cpython-312.pyc +0 -0
- package/skills/pdf/scripts/__pycache__/extract_form_field_info.cpython-312.pyc +0 -0
- package/skills/pdf/scripts/__pycache__/fill_fillable_fields.cpython-312.pyc +0 -0
- package/skills/pdf/scripts/__pycache__/fill_pdf_form_with_annotations.cpython-312.pyc +0 -0
- package/skills/pdf/scripts/__pycache__/sanitize_code.cpython-312.pyc +0 -0
- package/skills/pdf/scripts/add_zai_metadata.py +172 -0
- package/skills/pdf/scripts/check_bounding_boxes.py +70 -0
- package/skills/pdf/scripts/check_bounding_boxes_test.py +226 -0
- package/skills/pdf/scripts/check_fillable_fields.py +12 -0
- package/skills/pdf/scripts/convert_pdf_to_images.py +35 -0
- package/skills/pdf/scripts/create_validation_image.py +41 -0
- package/skills/pdf/scripts/extract_form_field_info.py +152 -0
- package/skills/pdf/scripts/fill_fillable_fields.py +114 -0
- package/skills/pdf/scripts/fill_pdf_form_with_annotations.py +108 -0
- package/skills/pdf/scripts/sanitize_code.py +110 -0
- package/skills/podcast-generate/LICENSE.txt +21 -0
- package/skills/podcast-generate/SKILL.md +198 -0
- package/skills/podcast-generate/generate.ts +661 -0
- package/skills/podcast-generate/package.json +30 -0
- package/skills/podcast-generate/readme.md +177 -0
- package/skills/podcast-generate/test_data/segments.jsonl +3 -0
- package/skills/podcast-generate/tsconfig.json +26 -0
- package/skills/pptx/LICENSE.txt +30 -0
- package/skills/pptx/SKILL.md +507 -0
- package/skills/pptx/html2pptx.md +625 -0
- package/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/dml-chart.xsd +1499 -0
- package/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/dml-chartDrawing.xsd +146 -0
- package/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/dml-diagram.xsd +1085 -0
- package/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/dml-lockedCanvas.xsd +11 -0
- package/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/dml-main.xsd +3081 -0
- package/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/dml-picture.xsd +23 -0
- package/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/dml-spreadsheetDrawing.xsd +185 -0
- package/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/dml-wordprocessingDrawing.xsd +287 -0
- package/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/pml.xsd +1676 -0
- package/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/shared-additionalCharacteristics.xsd +28 -0
- package/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/shared-bibliography.xsd +144 -0
- package/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/shared-commonSimpleTypes.xsd +174 -0
- package/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/shared-customXmlDataProperties.xsd +25 -0
- package/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/shared-customXmlSchemaProperties.xsd +18 -0
- package/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/shared-documentPropertiesCustom.xsd +59 -0
- package/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/shared-documentPropertiesExtended.xsd +56 -0
- package/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/shared-documentPropertiesVariantTypes.xsd +195 -0
- package/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/shared-math.xsd +582 -0
- package/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/shared-relationshipReference.xsd +25 -0
- package/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/sml.xsd +4439 -0
- package/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/vml-main.xsd +570 -0
- package/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/vml-officeDrawing.xsd +509 -0
- package/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/vml-presentationDrawing.xsd +12 -0
- package/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/vml-spreadsheetDrawing.xsd +108 -0
- package/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/vml-wordprocessingDrawing.xsd +96 -0
- package/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/wml.xsd +3646 -0
- package/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/xml.xsd +116 -0
- package/skills/pptx/ooxml/schemas/ecma/fouth-edition/opc-contentTypes.xsd +42 -0
- package/skills/pptx/ooxml/schemas/ecma/fouth-edition/opc-coreProperties.xsd +50 -0
- package/skills/pptx/ooxml/schemas/ecma/fouth-edition/opc-digSig.xsd +49 -0
- package/skills/pptx/ooxml/schemas/ecma/fouth-edition/opc-relationships.xsd +33 -0
- package/skills/pptx/ooxml/schemas/mce/mc.xsd +75 -0
- package/skills/pptx/ooxml/schemas/microsoft/wml-2010.xsd +560 -0
- package/skills/pptx/ooxml/schemas/microsoft/wml-2012.xsd +67 -0
- package/skills/pptx/ooxml/schemas/microsoft/wml-2018.xsd +14 -0
- package/skills/pptx/ooxml/schemas/microsoft/wml-cex-2018.xsd +20 -0
- package/skills/pptx/ooxml/schemas/microsoft/wml-cid-2016.xsd +13 -0
- package/skills/pptx/ooxml/schemas/microsoft/wml-sdtdatahash-2020.xsd +4 -0
- package/skills/pptx/ooxml/schemas/microsoft/wml-symex-2015.xsd +8 -0
- package/skills/pptx/ooxml/scripts/__pycache__/pack.cpython-312.pyc +0 -0
- package/skills/pptx/ooxml/scripts/__pycache__/unpack.cpython-312.pyc +0 -0
- package/skills/pptx/ooxml/scripts/__pycache__/validate.cpython-312.pyc +0 -0
- package/skills/pptx/ooxml/scripts/pack.py +159 -0
- package/skills/pptx/ooxml/scripts/unpack.py +29 -0
- package/skills/pptx/ooxml/scripts/validate.py +69 -0
- package/skills/pptx/ooxml/scripts/validation/__init__.py +15 -0
- package/skills/pptx/ooxml/scripts/validation/__pycache__/__init__.cpython-312.pyc +0 -0
- package/skills/pptx/ooxml/scripts/validation/__pycache__/base.cpython-312.pyc +0 -0
- package/skills/pptx/ooxml/scripts/validation/__pycache__/docx.cpython-312.pyc +0 -0
- package/skills/pptx/ooxml/scripts/validation/__pycache__/pptx.cpython-312.pyc +0 -0
- package/skills/pptx/ooxml/scripts/validation/__pycache__/redlining.cpython-312.pyc +0 -0
- package/skills/pptx/ooxml/scripts/validation/base.py +951 -0
- package/skills/pptx/ooxml/scripts/validation/docx.py +274 -0
- package/skills/pptx/ooxml/scripts/validation/pptx.py +315 -0
- package/skills/pptx/ooxml/scripts/validation/redlining.py +279 -0
- package/skills/pptx/ooxml.md +427 -0
- package/skills/pptx/scripts/__pycache__/inventory.cpython-312.pyc +0 -0
- package/skills/pptx/scripts/__pycache__/inventory.cpython-313.pyc +0 -0
- package/skills/pptx/scripts/__pycache__/rearrange.cpython-312.pyc +0 -0
- package/skills/pptx/scripts/__pycache__/replace.cpython-312.pyc +0 -0
- package/skills/pptx/scripts/__pycache__/thumbnail.cpython-312.pyc +0 -0
- package/skills/pptx/scripts/html2pptx.js +1044 -0
- package/skills/pptx/scripts/inventory.py +1020 -0
- package/skills/pptx/scripts/rearrange.py +231 -0
- package/skills/pptx/scripts/replace.py +385 -0
- package/skills/pptx/scripts/thumbnail.py +450 -0
- package/skills/qingyan-research/SKILL.md +294 -0
- package/skills/qingyan-research/__pycache__/generate_html.cpython-312.pyc +0 -0
- package/skills/qingyan-research/generate_html.py +33 -0
- package/skills/registry.py +344 -0
- package/skills/search_skill.py +228 -0
- package/skills/seo-content-writer/SKILL.md +661 -0
- package/skills/seo-content-writer/_meta.json +6 -0
- package/skills/seo-content-writer/references/content-structure-templates.md +875 -0
- package/skills/seo-content-writer/references/title-formulas.md +339 -0
- package/skills/skill-creator/LICENSE.txt +202 -0
- package/skills/skill-creator/SKILL.md +485 -0
- package/skills/skill-creator/agents/analyzer.md +274 -0
- package/skills/skill-creator/agents/comparator.md +202 -0
- package/skills/skill-creator/agents/grader.md +223 -0
- package/skills/skill-creator/assets/eval_review.html +146 -0
- package/skills/skill-creator/eval-viewer/__pycache__/generate_review.cpython-312.pyc +0 -0
- package/skills/skill-creator/eval-viewer/generate_review.py +471 -0
- package/skills/skill-creator/eval-viewer/viewer.html +1325 -0
- package/skills/skill-creator/references/schemas.md +430 -0
- package/skills/skill-creator/scripts/__init__.py +0 -0
- package/skills/skill-creator/scripts/__pycache__/__init__.cpython-312.pyc +0 -0
- package/skills/skill-creator/scripts/__pycache__/aggregate_benchmark.cpython-312.pyc +0 -0
- package/skills/skill-creator/scripts/__pycache__/generate_report.cpython-312.pyc +0 -0
- package/skills/skill-creator/scripts/__pycache__/improve_description.cpython-312.pyc +0 -0
- package/skills/skill-creator/scripts/__pycache__/package_skill.cpython-312.pyc +0 -0
- package/skills/skill-creator/scripts/__pycache__/quick_validate.cpython-312.pyc +0 -0
- package/skills/skill-creator/scripts/__pycache__/run_eval.cpython-312.pyc +0 -0
- package/skills/skill-creator/scripts/__pycache__/run_loop.cpython-312.pyc +0 -0
- package/skills/skill-creator/scripts/__pycache__/utils.cpython-312.pyc +0 -0
- package/skills/skill-creator/scripts/aggregate_benchmark.py +401 -0
- package/skills/skill-creator/scripts/generate_report.py +326 -0
- package/skills/skill-creator/scripts/improve_description.py +236 -0
- package/skills/skill-creator/scripts/package_skill.py +136 -0
- package/skills/skill-creator/scripts/quick_validate.py +103 -0
- package/skills/skill-creator/scripts/run_eval.py +310 -0
- package/skills/skill-creator/scripts/run_loop.py +328 -0
- package/skills/skill-creator/scripts/utils.py +47 -0
- package/skills/skill-finder-cn/SKILL.md +66 -0
- package/skills/skill-finder-cn/_meta.json +6 -0
- package/skills/skill-finder-cn/package.json +5 -0
- package/skills/skill-finder-cn/scripts/search.sh +15 -0
- package/skills/skill-vetter/SKILL.md +137 -0
- package/skills/stock-analysis-skill/SKILL.md +156 -0
- package/skills/stock-analysis-skill/package.json +21 -0
- package/skills/stock-analysis-skill/src/analyzer.ts +264 -0
- package/skills/stock-analysis-skill/src/dataFetcher.ts +130 -0
- package/skills/stock-analysis-skill/src/dividend.ts +226 -0
- package/skills/stock-analysis-skill/src/index.ts +327 -0
- package/skills/stock-analysis-skill/src/rumorScanner.ts +200 -0
- package/skills/stock-analysis-skill/src/types.ts +167 -0
- package/skills/stock-analysis-skill/src/watchlist.ts +292 -0
- package/skills/stock-analysis-skill/tsconfig.json +15 -0
- package/skills/storyboard-manager/SKILL.md +532 -0
- package/skills/storyboard-manager/index.js +9 -0
- package/skills/storyboard-manager/package.json +11 -0
- package/skills/storyboard-manager/references/character_development.md +232 -0
- package/skills/storyboard-manager/references/story_structures.md +148 -0
- package/skills/storyboard-manager/scripts/__pycache__/consistency_checker.cpython-312.pyc +0 -0
- package/skills/storyboard-manager/scripts/__pycache__/timeline_tracker.cpython-312.pyc +0 -0
- package/skills/storyboard-manager/scripts/consistency_checker.py +391 -0
- package/skills/storyboard-manager/scripts/timeline_tracker.py +352 -0
- package/skills/system_skill.py +249 -0
- package/skills/ui-ux-pro-max/SKILL.md +43 -0
- package/skills/ui-ux-pro-max/_meta.json +6 -0
- package/skills/ui-ux-pro-max/assets/data/charts.csv +26 -0
- package/skills/ui-ux-pro-max/assets/data/colors.csv +97 -0
- package/skills/ui-ux-pro-max/assets/data/icons.csv +101 -0
- package/skills/ui-ux-pro-max/assets/data/landing.csv +31 -0
- package/skills/ui-ux-pro-max/assets/data/products.csv +97 -0
- package/skills/ui-ux-pro-max/assets/data/react-performance.csv +45 -0
- package/skills/ui-ux-pro-max/assets/data/stacks/astro.csv +54 -0
- package/skills/ui-ux-pro-max/assets/data/stacks/flutter.csv +53 -0
- package/skills/ui-ux-pro-max/assets/data/stacks/html-tailwind.csv +56 -0
- package/skills/ui-ux-pro-max/assets/data/stacks/jetpack-compose.csv +53 -0
- package/skills/ui-ux-pro-max/assets/data/stacks/nextjs.csv +53 -0
- package/skills/ui-ux-pro-max/assets/data/stacks/nuxt-ui.csv +51 -0
- package/skills/ui-ux-pro-max/assets/data/stacks/nuxtjs.csv +59 -0
- package/skills/ui-ux-pro-max/assets/data/stacks/react-native.csv +52 -0
- package/skills/ui-ux-pro-max/assets/data/stacks/react.csv +54 -0
- package/skills/ui-ux-pro-max/assets/data/stacks/shadcn.csv +61 -0
- package/skills/ui-ux-pro-max/assets/data/stacks/svelte.csv +54 -0
- package/skills/ui-ux-pro-max/assets/data/stacks/swiftui.csv +51 -0
- package/skills/ui-ux-pro-max/assets/data/stacks/vue.csv +50 -0
- package/skills/ui-ux-pro-max/assets/data/styles.csv +68 -0
- package/skills/ui-ux-pro-max/assets/data/typography.csv +58 -0
- package/skills/ui-ux-pro-max/assets/data/ui-reasoning.csv +101 -0
- package/skills/ui-ux-pro-max/assets/data/ux-guidelines.csv +100 -0
- package/skills/ui-ux-pro-max/assets/data/web-interface.csv +31 -0
- package/skills/ui-ux-pro-max/data/charts.csv +26 -0
- package/skills/ui-ux-pro-max/data/colors.csv +97 -0
- package/skills/ui-ux-pro-max/data/icons.csv +101 -0
- package/skills/ui-ux-pro-max/data/landing.csv +31 -0
- package/skills/ui-ux-pro-max/data/products.csv +97 -0
- package/skills/ui-ux-pro-max/data/react-performance.csv +45 -0
- package/skills/ui-ux-pro-max/data/stacks/astro.csv +54 -0
- package/skills/ui-ux-pro-max/data/stacks/flutter.csv +53 -0
- package/skills/ui-ux-pro-max/data/stacks/html-tailwind.csv +56 -0
- package/skills/ui-ux-pro-max/data/stacks/jetpack-compose.csv +53 -0
- package/skills/ui-ux-pro-max/data/stacks/nextjs.csv +53 -0
- package/skills/ui-ux-pro-max/data/stacks/nuxt-ui.csv +51 -0
- package/skills/ui-ux-pro-max/data/stacks/nuxtjs.csv +59 -0
- package/skills/ui-ux-pro-max/data/stacks/react-native.csv +52 -0
- package/skills/ui-ux-pro-max/data/stacks/react.csv +54 -0
- package/skills/ui-ux-pro-max/data/stacks/shadcn.csv +61 -0
- package/skills/ui-ux-pro-max/data/stacks/svelte.csv +54 -0
- package/skills/ui-ux-pro-max/data/stacks/swiftui.csv +51 -0
- package/skills/ui-ux-pro-max/data/stacks/vue.csv +50 -0
- package/skills/ui-ux-pro-max/data/styles.csv +68 -0
- package/skills/ui-ux-pro-max/data/typography.csv +58 -0
- package/skills/ui-ux-pro-max/data/ui-reasoning.csv +101 -0
- package/skills/ui-ux-pro-max/data/ux-guidelines.csv +100 -0
- package/skills/ui-ux-pro-max/data/web-interface.csv +31 -0
- package/skills/ui-ux-pro-max/references/upstream-README.md +488 -0
- package/skills/ui-ux-pro-max/references/upstream-skill-content.md +288 -0
- package/skills/ui-ux-pro-max/scripts/__init__.py +0 -0
- package/skills/ui-ux-pro-max/scripts/__pycache__/__init__.cpython-312.pyc +0 -0
- package/skills/ui-ux-pro-max/scripts/__pycache__/core.cpython-312.pyc +0 -0
- package/skills/ui-ux-pro-max/scripts/__pycache__/design_system.cpython-312.pyc +0 -0
- package/skills/ui-ux-pro-max/scripts/__pycache__/search.cpython-312.pyc +0 -0
- package/skills/ui-ux-pro-max/scripts/core.py +253 -0
- package/skills/ui-ux-pro-max/scripts/design_system.py +1071 -0
- package/skills/ui-ux-pro-max/scripts/search.py +111 -0
- package/skills/video-generation/LICENSE.txt +21 -0
- package/skills/video-generation/SKILL.md +1082 -0
- package/skills/video-generation/scripts/video.ts +168 -0
- package/skills/video-understand/LICENSE.txt +21 -0
- package/skills/video-understand/SKILL.md +916 -0
- package/skills/video-understand/scripts/video-understand.ts +41 -0
- package/skills/visual-design-foundations/SKILL.md +318 -0
- package/skills/visual-design-foundations/references/color-systems.md +417 -0
- package/skills/visual-design-foundations/references/spacing-iconography.md +425 -0
- package/skills/visual-design-foundations/references/typography-systems.md +432 -0
- package/skills/web-reader/LICENSE.txt +21 -0
- package/skills/web-reader/SKILL.md +1140 -0
- package/skills/web-reader/scripts/web-reader.ts +37 -0
- package/skills/web-search/LICENSE.txt +21 -0
- package/skills/web-search/SKILL.md +912 -0
- package/skills/web-search/scripts/web_search.ts +44 -0
- package/skills/web-shader-extractor/SKILL.md +145 -0
- package/skills/web-shader-extractor/references/config-extraction.md +50 -0
- package/skills/web-shader-extractor/references/encoded-definitions.md +53 -0
- package/skills/web-shader-extractor/references/extraction-workflow.md +61 -0
- package/skills/web-shader-extractor/references/porting-strategy.md +164 -0
- package/skills/web-shader-extractor/references/shader-injection.md +126 -0
- package/skills/web-shader-extractor/references/shaders-com.md +190 -0
- package/skills/web-shader-extractor/references/tech-signatures.md +54 -0
- package/skills/web-shader-extractor/references/tsl-extraction.md +41 -0
- package/skills/web-shader-extractor/references/unicorn-studio.md +353 -0
- package/skills/web-shader-extractor/scripts/fetch-rendered-dom.mjs +153 -0
- package/skills/web-shader-extractor/scripts/scan-bundle.sh +76 -0
- package/skills/writing-plans/SKILL.md +116 -0
- package/skills/writing-plans/_meta.json +6 -0
- package/skills/xlsx/LICENSE.txt +30 -0
- package/skills/xlsx/SKILL.md +496 -0
- package/skills/xlsx/__pycache__/recalc.cpython-312.pyc +0 -0
- package/skills/xlsx/recalc.py +178 -0
- package/start.sh +36 -0
- package/web/__init__.py +1 -0
- package/web/__pycache__/api_server.cpython-312.pyc +0 -0
- package/web/api_server.py +2043 -0
- package/web/ui/chat.html +3235 -0
- package/web/ui/index.html +458 -0
|
@@ -0,0 +1,695 @@
|
|
|
1
|
+
"""
|
|
2
|
+
agents/main_agent.py - 主 Agent
|
|
3
|
+
=================================
|
|
4
|
+
总指挥 Agent,负责任务规划、Agent 调度、结果汇总。
|
|
5
|
+
"""
|
|
6
|
+
from __future__ import annotations
|
|
7
|
+
|
|
8
|
+
import json
|
|
9
|
+
import asyncio
|
|
10
|
+
from typing import Any, Dict, List, Optional
|
|
11
|
+
|
|
12
|
+
from core.logger import get_logger
|
|
13
|
+
from core.llm import LLMClient, LLMResponse, Message
|
|
14
|
+
from agents.base import BaseAgent, AgentContext
|
|
15
|
+
from core.utils import generate_id, timestamp, safe_json_parse, truncate_str
|
|
16
|
+
|
|
17
|
+
logger = get_logger("myagent.agent.main")
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class MainAgent(BaseAgent):
|
|
21
|
+
"""
|
|
22
|
+
主 Agent - 总指挥。
|
|
23
|
+
|
|
24
|
+
职责:
|
|
25
|
+
- 接收用户消息
|
|
26
|
+
- 任务分析与规划
|
|
27
|
+
- 调度子 Agent (ToolAgent / MemoryAgent)
|
|
28
|
+
- 整合结果并回复
|
|
29
|
+
- 多轮迭代(计划-执行-反思循环)
|
|
30
|
+
- 确保不进入死循环
|
|
31
|
+
"""
|
|
32
|
+
|
|
33
|
+
name = "main_agent"
|
|
34
|
+
description = "AI助手主控Agent,负责理解用户意图、规划任务、调度执行"
|
|
35
|
+
|
|
36
|
+
SYSTEM_PROMPT = """你是 MyAgent - 一个强大的本地桌面AI助手。你拥有以下能力:
|
|
37
|
+
|
|
38
|
+
## 核心能力
|
|
39
|
+
1. **代码执行**: 可以运行 Python、Shell/Bash、PowerShell 代码
|
|
40
|
+
2. **文件操作**: 读取、写入、搜索、管理文件
|
|
41
|
+
3. **网络搜索**: 搜索互联网、读取网页
|
|
42
|
+
4. **系统操作**: 查询系统信息、管理进程
|
|
43
|
+
5. **浏览器操作**: 自动化浏览器(如已安装 Playwright)
|
|
44
|
+
6. **记忆系统**: 记住用户偏好、历史任务、避免重复犯错
|
|
45
|
+
|
|
46
|
+
## 工作方式
|
|
47
|
+
- 仔细分析用户需求,拆解为可执行的步骤
|
|
48
|
+
- 使用可用工具完成任务
|
|
49
|
+
- 每一步执行后检查结果,遇到错误自动修复
|
|
50
|
+
- 完成后总结成果
|
|
51
|
+
|
|
52
|
+
## 重要规则
|
|
53
|
+
- 优先使用技能系统完成操作,而不是直接写代码
|
|
54
|
+
- 执行危险操作前先警告用户
|
|
55
|
+
- 保持回复简洁明了
|
|
56
|
+
- 如果需要多步操作,先规划再执行
|
|
57
|
+
- 用中文回复
|
|
58
|
+
|
|
59
|
+
## ⏰ 超时控制规则(强制要求)
|
|
60
|
+
对于每个需要执行的命令(action type="code"),你**必须**在 action 中包含 "timeout_seconds" 字段,
|
|
61
|
+
指定该命令的预估最大执行超时时间(秒)。这是一项强制要求,不能省略。
|
|
62
|
+
|
|
63
|
+
超时时间设定指南:
|
|
64
|
+
- 简单打印/计算: 10-30秒
|
|
65
|
+
- 文件读写/搜索: 30-60秒
|
|
66
|
+
- 网络请求/API调用: 60-120秒
|
|
67
|
+
- 数据处理/批量操作: 120-300秒
|
|
68
|
+
- 大规模编译/安装: 300-600秒
|
|
69
|
+
- 如果不确定,默认设为 120秒
|
|
70
|
+
|
|
71
|
+
**如果命令执行超时**: 系统会自动将超时信息反馈给你,包含命令已产生的部分输出。
|
|
72
|
+
你需要分析超时原因并给出改进方案(如优化算法、添加超时参数、分批处理等)。
|
|
73
|
+
|
|
74
|
+
## 格式要求
|
|
75
|
+
当你需要执行操作时,输出 JSON 格式:
|
|
76
|
+
```json
|
|
77
|
+
{
|
|
78
|
+
"thought": "你的思考过程",
|
|
79
|
+
"plan": ["步骤1", "步骤2"],
|
|
80
|
+
"actions": [
|
|
81
|
+
{"type": "skill", "name": "技能名", "params": {}},
|
|
82
|
+
{"type": "code", "language": "python", "code": "代码", "timeout_seconds": 60},
|
|
83
|
+
{"type": "memory", "action": "记忆操作", "data": {}}
|
|
84
|
+
]
|
|
85
|
+
}
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
**注意**: action type="code" 必须包含 "timeout_seconds" 字段。action type="skill" 或 "memory" 不需要此字段。
|
|
89
|
+
|
|
90
|
+
你可以用 markdown 格式回复普通对话。
|
|
91
|
+
|
|
92
|
+
## 任务规划模式
|
|
93
|
+
当用户消息中包含"当前任务计划"上下文时,你处于**任务规划模式**。请:
|
|
94
|
+
1. 分析用户需求,评估现有任务的完成状态
|
|
95
|
+
2. 根据需要添加新任务、标记已完成任务
|
|
96
|
+
3. 在回复末尾用以下格式输出更新后的任务计划:
|
|
97
|
+
|
|
98
|
+
## 任务计划
|
|
99
|
+
- [ ] 任务描述1
|
|
100
|
+
- [x] 已完成的任务
|
|
101
|
+
- [ ] 待执行的任务描述2
|
|
102
|
+
|
|
103
|
+
保持任务简洁明确,每个任务一行。"""
|
|
104
|
+
|
|
105
|
+
def __init__(self, tool_agent=None, memory_agent=None, **kwargs):
|
|
106
|
+
super().__init__(**kwargs)
|
|
107
|
+
self.tool_agent = tool_agent
|
|
108
|
+
self.memory_agent = memory_agent
|
|
109
|
+
self._iteration_count = 0
|
|
110
|
+
self._current_task_id: str = ""
|
|
111
|
+
self._registered_task: bool = False
|
|
112
|
+
# 组织上下文缓存(避免重复加载)
|
|
113
|
+
self._org_context_cache: str = ""
|
|
114
|
+
self._org_context_loaded: bool = False
|
|
115
|
+
|
|
116
|
+
async def process(self, context: AgentContext) -> AgentContext:
|
|
117
|
+
"""
|
|
118
|
+
主处理循环。
|
|
119
|
+
|
|
120
|
+
流程:
|
|
121
|
+
1. 加载相关记忆
|
|
122
|
+
2. 构建消息(系统提示 + 记忆上下文 + 对话历史 + 用户消息)
|
|
123
|
+
3. 调用 LLM
|
|
124
|
+
4. 解析响应(纯文本回复 / 工具调用)
|
|
125
|
+
5. 如需执行工具,调度 ToolAgent
|
|
126
|
+
6. 如需记忆操作,调度 MemoryAgent
|
|
127
|
+
7. 循环直到任务完成或达到最大迭代次数
|
|
128
|
+
"""
|
|
129
|
+
task_id = context.task_id or generate_id("task")
|
|
130
|
+
context.task_id = task_id
|
|
131
|
+
self._iteration_count = 0
|
|
132
|
+
self._current_task_id = task_id
|
|
133
|
+
|
|
134
|
+
# 注册到配置广播器(用于热重载通知)
|
|
135
|
+
if self.config_broadcaster:
|
|
136
|
+
self.config_broadcaster.register(task_id, agent_name=self.name)
|
|
137
|
+
self._registered_task = True
|
|
138
|
+
|
|
139
|
+
logger.info(f"[{task_id}] 开始处理用户请求: {context.user_message[:100]}")
|
|
140
|
+
|
|
141
|
+
try:
|
|
142
|
+
return await self._process_inner(context, task_id)
|
|
143
|
+
finally:
|
|
144
|
+
# 注销广播器
|
|
145
|
+
if self.config_broadcaster and self._registered_task:
|
|
146
|
+
self.config_broadcaster.unregister(task_id)
|
|
147
|
+
self._registered_task = False
|
|
148
|
+
|
|
149
|
+
async def _process_inner(self, context: AgentContext, task_id: str) -> AgentContext:
|
|
150
|
+
"""内部处理逻辑(被 process 包裹,用于确保注册/注销广播器)"""
|
|
151
|
+
|
|
152
|
+
# Step 1: 加载相关记忆
|
|
153
|
+
if self.memory_agent:
|
|
154
|
+
mem_context = AgentContext(
|
|
155
|
+
task_id=task_id,
|
|
156
|
+
session_id=context.session_id,
|
|
157
|
+
user_message=context.user_message,
|
|
158
|
+
metadata={"memory_action": "get_relevant"},
|
|
159
|
+
)
|
|
160
|
+
await self.memory_agent.process(mem_context)
|
|
161
|
+
if "memory_context_prompt" in mem_context.working_memory:
|
|
162
|
+
context.working_memory["memory_context_prompt"] = \
|
|
163
|
+
mem_context.working_memory["memory_context_prompt"]
|
|
164
|
+
|
|
165
|
+
# Step 2: 保存用户消息到短期记忆
|
|
166
|
+
if self.memory:
|
|
167
|
+
self.memory.add_short_term(
|
|
168
|
+
session_id=context.session_id,
|
|
169
|
+
role="user",
|
|
170
|
+
content=context.user_message,
|
|
171
|
+
)
|
|
172
|
+
|
|
173
|
+
# Step 3: 主循环(计划-执行-反思)
|
|
174
|
+
final_response = ""
|
|
175
|
+
max_iter = self.config.agent.max_iterations
|
|
176
|
+
|
|
177
|
+
while self._iteration_count < max_iter:
|
|
178
|
+
self._iteration_count += 1
|
|
179
|
+
logger.debug(f"[{task_id}] 迭代 {self._iteration_count}/{max_iter}")
|
|
180
|
+
|
|
181
|
+
# 检查配置热加载广播(每次迭代前检查)
|
|
182
|
+
if self.config_broadcaster:
|
|
183
|
+
reloaded = await self.config_broadcaster.check_and_wait(task_id)
|
|
184
|
+
if reloaded:
|
|
185
|
+
logger.info(f"[{task_id}] 🔄 配置已热更新,继续执行 (iteration={self._iteration_count})")
|
|
186
|
+
# 更新迭代检查点
|
|
187
|
+
if self.config_broadcaster._active_tasks.get(task_id):
|
|
188
|
+
self.config_broadcaster._active_tasks[task_id].iteration = self._iteration_count
|
|
189
|
+
|
|
190
|
+
# 构建消息列表
|
|
191
|
+
messages = self._build_messages(context)
|
|
192
|
+
|
|
193
|
+
# 添加可用工具
|
|
194
|
+
tools = self._get_tools()
|
|
195
|
+
|
|
196
|
+
# 调用 LLM
|
|
197
|
+
response = await self._call_llm(messages, tools=tools)
|
|
198
|
+
|
|
199
|
+
if not response.success:
|
|
200
|
+
final_response = f"⚠️ LLM 调用失败: {response.error}"
|
|
201
|
+
break
|
|
202
|
+
|
|
203
|
+
# 解析响应
|
|
204
|
+
content = response.content
|
|
205
|
+
|
|
206
|
+
# 检查是否有工具调用 (OpenAI function calling)
|
|
207
|
+
if response.tool_calls:
|
|
208
|
+
tool_results = await self._handle_tool_calls(
|
|
209
|
+
response.tool_calls, context, task_id
|
|
210
|
+
)
|
|
211
|
+
# 将工具结果加入消息历史
|
|
212
|
+
for tc, result in tool_results:
|
|
213
|
+
context.conversation_history.append(
|
|
214
|
+
Message(role="tool", content=json.dumps(result, ensure_ascii=False),
|
|
215
|
+
tool_call_id=tc["id"], name=tc["name"])
|
|
216
|
+
)
|
|
217
|
+
context.conversation_history.append(
|
|
218
|
+
Message(role="assistant",
|
|
219
|
+
content=f"[已调用工具 {tc['name']},结果: "
|
|
220
|
+
f"{'成功' if result.get('success') else '失败'}]",
|
|
221
|
+
tool_calls=[tc])
|
|
222
|
+
)
|
|
223
|
+
# 继续循环,让 LLM 处理工具结果
|
|
224
|
+
continue
|
|
225
|
+
|
|
226
|
+
# 尝试解析 JSON 操作指令
|
|
227
|
+
action_data = safe_json_parse(content)
|
|
228
|
+
|
|
229
|
+
if action_data and isinstance(action_data, dict):
|
|
230
|
+
# 有结构化的操作指令
|
|
231
|
+
if "actions" in action_data:
|
|
232
|
+
# 执行操作列表
|
|
233
|
+
results = await self._execute_actions(
|
|
234
|
+
action_data, context, task_id
|
|
235
|
+
)
|
|
236
|
+
# 将结果反馈给 LLM
|
|
237
|
+
context.conversation_history.append(
|
|
238
|
+
Message(role="assistant", content=content)
|
|
239
|
+
)
|
|
240
|
+
result_summary = self._summarize_action_results(results)
|
|
241
|
+
|
|
242
|
+
# 如果有超时诊断,追加详细信息供 LLM 分析
|
|
243
|
+
has_timeout = any(r.get("timed_out") for r in results)
|
|
244
|
+
timeout_detail = ""
|
|
245
|
+
if has_timeout:
|
|
246
|
+
timeout_details = []
|
|
247
|
+
for i, r in enumerate(results, 1):
|
|
248
|
+
if r.get("timed_out"):
|
|
249
|
+
diag = r.get("timeout_diagnosis", {})
|
|
250
|
+
timeout_details.append(
|
|
251
|
+
f"### 命令 {i} 超时诊断\n"
|
|
252
|
+
f"- 原因: {diag.get('diagnosis', '未知')}\n"
|
|
253
|
+
f"- 进展: {diag.get('progress', '未知')}\n"
|
|
254
|
+
f"- 是否建议重试: {'是' if diag.get('should_retry') else '否'}\n"
|
|
255
|
+
f"- 重试策略: {diag.get('retry_strategy', '无')}\n"
|
|
256
|
+
f"- 改进建议:\n"
|
|
257
|
+
)
|
|
258
|
+
for s in diag.get("suggestions", []):
|
|
259
|
+
timeout_details.append(f" - {s}")
|
|
260
|
+
timeout_detail = "\n\n## ⏰ 超时诊断详情\n" + "\n".join(timeout_details)
|
|
261
|
+
|
|
262
|
+
feedback_msg = f"[执行结果]\n{result_summary}\n\n请基于以上结果继续。"
|
|
263
|
+
if timeout_detail:
|
|
264
|
+
feedback_msg += timeout_detail + "\n\n请根据以上诊断信息决定下一步操作。"
|
|
265
|
+
|
|
266
|
+
context.conversation_history.append(
|
|
267
|
+
Message(role="user", content=feedback_msg)
|
|
268
|
+
)
|
|
269
|
+
|
|
270
|
+
# 如果任务已完成(所有操作成功),退出循环
|
|
271
|
+
all_success = all(r.get("success", False) for r in results)
|
|
272
|
+
if all_success and results:
|
|
273
|
+
final_response = action_data.get("thought", "")
|
|
274
|
+
if "plan" in action_data and action_data["plan"]:
|
|
275
|
+
final_response += "\n\n已完成: " + " → ".join(action_data["plan"])
|
|
276
|
+
break
|
|
277
|
+
|
|
278
|
+
continue
|
|
279
|
+
|
|
280
|
+
# 单个 action
|
|
281
|
+
if action_data.get("type") == "final_answer":
|
|
282
|
+
final_response = action_data.get("content", content)
|
|
283
|
+
break
|
|
284
|
+
|
|
285
|
+
# 纯文本回复(没有工具调用)
|
|
286
|
+
final_response = content
|
|
287
|
+
break
|
|
288
|
+
|
|
289
|
+
# 保存助手回复到短期记忆
|
|
290
|
+
if self.memory and final_response:
|
|
291
|
+
self.memory.add_short_term(
|
|
292
|
+
session_id=context.session_id,
|
|
293
|
+
role="assistant",
|
|
294
|
+
content=final_response,
|
|
295
|
+
)
|
|
296
|
+
|
|
297
|
+
# 清理工作记忆
|
|
298
|
+
context.working_memory["final_response"] = final_response
|
|
299
|
+
context.working_memory["iterations"] = self._iteration_count
|
|
300
|
+
|
|
301
|
+
logger.info(f"[{task_id}] 处理完成 (迭代 {self._iteration_count} 次)")
|
|
302
|
+
|
|
303
|
+
# 检查是否需要总结对话
|
|
304
|
+
if self.memory_agent and self._iteration_count > 5:
|
|
305
|
+
try:
|
|
306
|
+
await self.memory_agent.process(AgentContext(
|
|
307
|
+
session_id=context.session_id,
|
|
308
|
+
metadata={"memory_action": "summarize"},
|
|
309
|
+
))
|
|
310
|
+
except Exception as e:
|
|
311
|
+
logger.warning(f"对话总结失败: {e}")
|
|
312
|
+
|
|
313
|
+
return context
|
|
314
|
+
|
|
315
|
+
def _build_messages(self, context: AgentContext) -> List[Message]:
|
|
316
|
+
"""构建完整的消息列表"""
|
|
317
|
+
messages = [Message(role="system", content=self.SYSTEM_PROMPT)]
|
|
318
|
+
|
|
319
|
+
# 添加组织上下文(如果已启用)
|
|
320
|
+
org_context = self._build_org_context(context)
|
|
321
|
+
if org_context:
|
|
322
|
+
messages.append(Message(
|
|
323
|
+
role="system",
|
|
324
|
+
content=org_context,
|
|
325
|
+
))
|
|
326
|
+
|
|
327
|
+
# 添加记忆上下文
|
|
328
|
+
memory_ctx = context.working_memory.get("memory_context_prompt", "")
|
|
329
|
+
if memory_ctx:
|
|
330
|
+
messages.append(Message(
|
|
331
|
+
role="system",
|
|
332
|
+
content=f"[记忆上下文]\n{memory_ctx}",
|
|
333
|
+
))
|
|
334
|
+
|
|
335
|
+
# 添加对话历史
|
|
336
|
+
for msg in context.conversation_history[-20:]:
|
|
337
|
+
messages.append(msg)
|
|
338
|
+
|
|
339
|
+
# 添加当前用户消息
|
|
340
|
+
messages.append(Message(role="user", content=context.user_message))
|
|
341
|
+
|
|
342
|
+
return messages
|
|
343
|
+
|
|
344
|
+
def _get_tools(self) -> Optional[List[Dict]]:
|
|
345
|
+
"""获取可用工具列表(OpenAI function calling 格式)"""
|
|
346
|
+
if not self.skills:
|
|
347
|
+
return None
|
|
348
|
+
try:
|
|
349
|
+
return self.skills.get_all_schemas()
|
|
350
|
+
except Exception as e:
|
|
351
|
+
logger.warning(f"获取工具列表失败: {e}")
|
|
352
|
+
return None
|
|
353
|
+
|
|
354
|
+
async def _handle_tool_calls(
|
|
355
|
+
self,
|
|
356
|
+
tool_calls: List[Dict],
|
|
357
|
+
context: AgentContext,
|
|
358
|
+
task_id: str,
|
|
359
|
+
) -> List[tuple]:
|
|
360
|
+
"""处理 OpenAI function calling 工具调用"""
|
|
361
|
+
results = []
|
|
362
|
+
for tc in tool_calls:
|
|
363
|
+
name = tc["name"]
|
|
364
|
+
args = tc.get("arguments", {})
|
|
365
|
+
logger.info(f"[{task_id}] 调用工具: {name}({args})")
|
|
366
|
+
|
|
367
|
+
try:
|
|
368
|
+
if self.skills:
|
|
369
|
+
result = await self.skills.execute(name, **args)
|
|
370
|
+
result_dict = result.to_dict()
|
|
371
|
+
else:
|
|
372
|
+
result_dict = {"success": False, "error": "技能系统未初始化"}
|
|
373
|
+
except Exception as e:
|
|
374
|
+
result_dict = {"success": False, "error": str(e)}
|
|
375
|
+
|
|
376
|
+
results.append((tc, result_dict))
|
|
377
|
+
|
|
378
|
+
# 记录错误模式
|
|
379
|
+
if not result_dict.get("success") and self.memory:
|
|
380
|
+
self.memory.record_error_pattern(
|
|
381
|
+
error=f"工具 {name} 失败: {result_dict.get('error', '')}",
|
|
382
|
+
)
|
|
383
|
+
|
|
384
|
+
return results
|
|
385
|
+
|
|
386
|
+
async def _execute_actions(
|
|
387
|
+
self,
|
|
388
|
+
action_data: Dict,
|
|
389
|
+
context: AgentContext,
|
|
390
|
+
task_id: str,
|
|
391
|
+
) -> List[Dict]:
|
|
392
|
+
"""执行操作列表"""
|
|
393
|
+
results = []
|
|
394
|
+
actions = action_data.get("actions", [])
|
|
395
|
+
|
|
396
|
+
for action in actions:
|
|
397
|
+
action_type = action.get("type", "")
|
|
398
|
+
|
|
399
|
+
if action_type == "skill" and self.skills:
|
|
400
|
+
result = await self.skills.execute(
|
|
401
|
+
action.get("name", ""),
|
|
402
|
+
**action.get("params", {}),
|
|
403
|
+
)
|
|
404
|
+
results.append(result.to_dict())
|
|
405
|
+
|
|
406
|
+
elif action_type == "code" and self.executor:
|
|
407
|
+
# 提取 LLM 预估的超时时间
|
|
408
|
+
timeout_seconds = action.get("timeout_seconds")
|
|
409
|
+
if timeout_seconds is None:
|
|
410
|
+
# 如果 LLM 未提供 timeout_seconds,使用默认值并记录警告
|
|
411
|
+
timeout_seconds = self.config.executor.timeout if hasattr(self.config, 'executor') else 120
|
|
412
|
+
logger.warning(
|
|
413
|
+
f"[{task_id}] LLM 未指定 timeout_seconds,使用默认值 {timeout_seconds}s"
|
|
414
|
+
)
|
|
415
|
+
else:
|
|
416
|
+
try:
|
|
417
|
+
timeout_seconds = int(timeout_seconds)
|
|
418
|
+
# 限制超时范围: 最小 5s,最大 3600s
|
|
419
|
+
timeout_seconds = max(5, min(timeout_seconds, 3600))
|
|
420
|
+
except (ValueError, TypeError):
|
|
421
|
+
timeout_seconds = 120
|
|
422
|
+
logger.warning(
|
|
423
|
+
f"[{task_id}] timeout_seconds 值无效,使用默认值 120s"
|
|
424
|
+
)
|
|
425
|
+
|
|
426
|
+
exec_result = await self.executor.execute(
|
|
427
|
+
language=action.get("language", "python"),
|
|
428
|
+
code=action.get("code", ""),
|
|
429
|
+
timeout=timeout_seconds,
|
|
430
|
+
)
|
|
431
|
+
|
|
432
|
+
# 设置超时追踪字段(executor 已直接设置 timed_out,这里确保 timeout_limit)
|
|
433
|
+
if not exec_result.timeout_limit:
|
|
434
|
+
exec_result.timeout_limit = timeout_seconds
|
|
435
|
+
|
|
436
|
+
result_dict = exec_result.to_dict()
|
|
437
|
+
|
|
438
|
+
# 超时后自动触发 LLM 诊断分析
|
|
439
|
+
if exec_result.timed_out:
|
|
440
|
+
logger.info(
|
|
441
|
+
f"[{task_id}] ⏰ 命令执行超时 ({timeout_seconds}s),"
|
|
442
|
+
f"自动触发 LLM 诊断分析..."
|
|
443
|
+
)
|
|
444
|
+
diagnosis = await self._diagnose_timeout(
|
|
445
|
+
action, exec_result, context, task_id
|
|
446
|
+
)
|
|
447
|
+
result_dict["timeout_diagnosis"] = diagnosis
|
|
448
|
+
|
|
449
|
+
results.append(result_dict)
|
|
450
|
+
|
|
451
|
+
elif action_type == "memory" and self.memory_agent:
|
|
452
|
+
mem_ctx = AgentContext(
|
|
453
|
+
task_id=task_id,
|
|
454
|
+
session_id=context.session_id,
|
|
455
|
+
metadata={
|
|
456
|
+
"memory_action": action.get("action", ""),
|
|
457
|
+
**action.get("data", {}),
|
|
458
|
+
},
|
|
459
|
+
)
|
|
460
|
+
await self.memory_agent.process(mem_ctx)
|
|
461
|
+
results.append({"success": True, "action": "memory"})
|
|
462
|
+
|
|
463
|
+
elif action_type == "final":
|
|
464
|
+
break
|
|
465
|
+
|
|
466
|
+
else:
|
|
467
|
+
results.append({
|
|
468
|
+
"success": False,
|
|
469
|
+
"error": f"未知操作类型: {action_type}",
|
|
470
|
+
})
|
|
471
|
+
|
|
472
|
+
return results
|
|
473
|
+
|
|
474
|
+
@staticmethod
|
|
475
|
+
def _build_timeout_diagnosis_message(action: Dict, exec_result: 'ExecResult') -> str:
|
|
476
|
+
"""构建超时诊断的用户消息(避免 f-string 内换行问题)"""
|
|
477
|
+
parts = []
|
|
478
|
+
parts.append("## 超时命令信息")
|
|
479
|
+
parts.append(f"- 语言: {action.get('language', 'unknown')}")
|
|
480
|
+
parts.append(f"- 超时上限: {exec_result.timeout_limit}s")
|
|
481
|
+
parts.append(f"- 实际执行时间: {exec_result.execution_time:.1f}s")
|
|
482
|
+
parts.append(f"- 代码:")
|
|
483
|
+
parts.append(f"```{action.get('language', '')}")
|
|
484
|
+
parts.append(f"{action.get('code', '')}")
|
|
485
|
+
parts.append("```")
|
|
486
|
+
parts.append("")
|
|
487
|
+
parts.append("## 执行输出(超时前)")
|
|
488
|
+
|
|
489
|
+
if exec_result.stdout and exec_result.stdout.strip():
|
|
490
|
+
parts.append("### 标准输出")
|
|
491
|
+
parts.append("```")
|
|
492
|
+
parts.append(exec_result.stdout[:5000])
|
|
493
|
+
parts.append("```")
|
|
494
|
+
parts.append("")
|
|
495
|
+
else:
|
|
496
|
+
parts.append("(无输出)")
|
|
497
|
+
parts.append("")
|
|
498
|
+
|
|
499
|
+
if exec_result.stderr and exec_result.stderr.strip():
|
|
500
|
+
parts.append("### 标准错误")
|
|
501
|
+
parts.append("```")
|
|
502
|
+
parts.append(exec_result.stderr[:3000])
|
|
503
|
+
parts.append("```")
|
|
504
|
+
else:
|
|
505
|
+
parts.append("(无错误输出)")
|
|
506
|
+
|
|
507
|
+
return "\n".join(parts)
|
|
508
|
+
|
|
509
|
+
async def _diagnose_timeout(
|
|
510
|
+
self,
|
|
511
|
+
action: Dict,
|
|
512
|
+
exec_result: 'ExecResult',
|
|
513
|
+
context: AgentContext,
|
|
514
|
+
task_id: str,
|
|
515
|
+
) -> Dict[str, Any]:
|
|
516
|
+
"""
|
|
517
|
+
超时后自动调用 LLM 诊断分析执行问题。
|
|
518
|
+
|
|
519
|
+
分析维度:
|
|
520
|
+
1. 超时原因诊断(死循环/网络阻塞/数据量过大/缺少输入等)
|
|
521
|
+
2. 基于已有输出的进展评估
|
|
522
|
+
3. 具体改进建议(优化代码/拆分任务/添加超时参数等)
|
|
523
|
+
4. 是否值得重试
|
|
524
|
+
|
|
525
|
+
Returns:
|
|
526
|
+
诊断结果字典
|
|
527
|
+
"""
|
|
528
|
+
diagnosis_messages = [
|
|
529
|
+
Message(
|
|
530
|
+
role="system",
|
|
531
|
+
content=(
|
|
532
|
+
"你是一个执行超时诊断专家。一个命令刚刚因超时被强制终止,"
|
|
533
|
+
"请仔细分析以下信息,给出诊断结论和改进建议。\n\n"
|
|
534
|
+
"请用 JSON 格式回复:\n"
|
|
535
|
+
"{\n"
|
|
536
|
+
' "diagnosis": "超时原因诊断(简明扼要)",\n'
|
|
537
|
+
' "progress": "已完成的进度评估",\n'
|
|
538
|
+
' "suggestions": ["改进建议1", "改进建议2", ...],\n'
|
|
539
|
+
' "should_retry": true/false,\n'
|
|
540
|
+
' "retry_strategy": "如果建议重试,说明重试策略",\n'
|
|
541
|
+
' "estimated_fix_time": "预计修复后需要的时间(秒)"\n'
|
|
542
|
+
"}"
|
|
543
|
+
),
|
|
544
|
+
),
|
|
545
|
+
Message(
|
|
546
|
+
role="user",
|
|
547
|
+
content=self._build_timeout_diagnosis_message(action, exec_result),
|
|
548
|
+
),
|
|
549
|
+
]
|
|
550
|
+
|
|
551
|
+
try:
|
|
552
|
+
diagnosis = await self._call_llm_json(diagnosis_messages)
|
|
553
|
+
if "error" in diagnosis:
|
|
554
|
+
logger.warning(f"[{task_id}] 超时诊断 LLM 调用失败: {diagnosis['error']}")
|
|
555
|
+
return {
|
|
556
|
+
"diagnosis": "LLM 诊断调用失败",
|
|
557
|
+
"suggestions": ["检查命令是否有死循环", "尝试减少处理数据量"],
|
|
558
|
+
"should_retry": False,
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
# 记录诊断结果
|
|
562
|
+
logger.info(
|
|
563
|
+
f"[{task_id}] ⏰ 超时诊断完成: {diagnosis.get('diagnosis', 'N/A')}"
|
|
564
|
+
)
|
|
565
|
+
|
|
566
|
+
# 如果诊断建议重试且提供了重试策略,记录到记忆中
|
|
567
|
+
if diagnosis.get("should_retry") and self.memory:
|
|
568
|
+
self.memory.record_error_pattern(
|
|
569
|
+
error=(
|
|
570
|
+
f"命令超时 ({exec_result.timeout_limit}s): "
|
|
571
|
+
f"{action.get('code', '')[:200]}\n"
|
|
572
|
+
f"诊断: {diagnosis.get('diagnosis', '')}\n"
|
|
573
|
+
f"建议: {'; '.join(diagnosis.get('suggestions', []))}"
|
|
574
|
+
)
|
|
575
|
+
)
|
|
576
|
+
|
|
577
|
+
return diagnosis
|
|
578
|
+
|
|
579
|
+
except Exception as e:
|
|
580
|
+
logger.error(f"[{task_id}] 超时诊断异常: {e}")
|
|
581
|
+
return {
|
|
582
|
+
"diagnosis": f"诊断过程异常: {str(e)}",
|
|
583
|
+
"suggestions": ["检查命令逻辑", "手动测试命令"],
|
|
584
|
+
"should_retry": False,
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
def _summarize_action_results(self, results: List[Dict]) -> str:
|
|
588
|
+
"""汇总操作结果"""
|
|
589
|
+
if not results:
|
|
590
|
+
return "无操作结果"
|
|
591
|
+
|
|
592
|
+
parts = []
|
|
593
|
+
for i, r in enumerate(results, 1):
|
|
594
|
+
status = "✅" if r.get("success") else "❌"
|
|
595
|
+
msg = r.get("message", r.get("error", ""))[:200]
|
|
596
|
+
|
|
597
|
+
# 超时特殊标记
|
|
598
|
+
if r.get("timed_out"):
|
|
599
|
+
status = "⏰"
|
|
600
|
+
limit = r.get("timeout_limit", "?")
|
|
601
|
+
actual = r.get("execution_time", "?")
|
|
602
|
+
msg = f"执行超时 (上限{limit}s, 实际{actual}s)"
|
|
603
|
+
|
|
604
|
+
# 追加诊断结果
|
|
605
|
+
diagnosis = r.get("timeout_diagnosis")
|
|
606
|
+
if diagnosis:
|
|
607
|
+
diag_text = diagnosis.get("diagnosis", "")
|
|
608
|
+
suggestions = diagnosis.get("suggestions", [])
|
|
609
|
+
msg += f"\n 诊断: {diag_text}"
|
|
610
|
+
if suggestions:
|
|
611
|
+
msg += f"\n 建议: {'; '.join(suggestions[:3])}"
|
|
612
|
+
|
|
613
|
+
parts.append(f"{i}. {status} {msg}")
|
|
614
|
+
|
|
615
|
+
return "\n".join(parts)
|
|
616
|
+
|
|
617
|
+
def _build_org_context(self, context: AgentContext) -> str:
|
|
618
|
+
"""
|
|
619
|
+
构建组织上下文信息。
|
|
620
|
+
|
|
621
|
+
如果组织功能已启用:
|
|
622
|
+
1. 读取 organization.md 内容
|
|
623
|
+
2. 对用户查询进行 RAG 搜索,获取相关知识片段
|
|
624
|
+
3. 返回格式化的上下文字符串
|
|
625
|
+
|
|
626
|
+
Returns:
|
|
627
|
+
格式化的组织上下文,未启用时返回空字符串
|
|
628
|
+
"""
|
|
629
|
+
try:
|
|
630
|
+
# 检查配置中是否启用了组织功能
|
|
631
|
+
org_enabled = False
|
|
632
|
+
if hasattr(self.config, 'organization'):
|
|
633
|
+
org_enabled = self.config.organization.enabled
|
|
634
|
+
if not org_enabled:
|
|
635
|
+
return ""
|
|
636
|
+
|
|
637
|
+
parts = []
|
|
638
|
+
|
|
639
|
+
# 1. 读取 organization.md(使用缓存避免重复读取)
|
|
640
|
+
if not self._org_context_loaded:
|
|
641
|
+
try:
|
|
642
|
+
from config import get_config
|
|
643
|
+
config_mgr = get_config()
|
|
644
|
+
org_dir = config_mgr.data_dir / "organization"
|
|
645
|
+
org_info_path = org_dir / "organization.md"
|
|
646
|
+
if org_info_path.exists():
|
|
647
|
+
content = org_info_path.read_text(encoding="utf-8")
|
|
648
|
+
# 检查是否仍是模板(包含占位注释)
|
|
649
|
+
is_template = "<!-- 在此填写" in content
|
|
650
|
+
if not is_template:
|
|
651
|
+
self._org_context_cache = content
|
|
652
|
+
except Exception as e:
|
|
653
|
+
logger.debug(f"读取组织信息失败: {e}")
|
|
654
|
+
self._org_context_loaded = True
|
|
655
|
+
|
|
656
|
+
if self._org_context_cache:
|
|
657
|
+
parts.append("## 组织信息\n")
|
|
658
|
+
# 截取合理的长度,避免占用过多 token
|
|
659
|
+
org_text = self._org_context_cache[:3000]
|
|
660
|
+
parts.append(org_text)
|
|
661
|
+
parts.append("")
|
|
662
|
+
|
|
663
|
+
# 2. RAG 搜索组织知识库
|
|
664
|
+
try:
|
|
665
|
+
from config import get_config
|
|
666
|
+
from knowledge.rag import KnowledgeRAG
|
|
667
|
+
|
|
668
|
+
config_mgr = get_config()
|
|
669
|
+
kb_dir = config_mgr.data_dir / "organization" / "knowledge"
|
|
670
|
+
if kb_dir.exists() and any(kb_dir.iterdir()):
|
|
671
|
+
rag = KnowledgeRAG(kb_dir=kb_dir)
|
|
672
|
+
rag.build_index()
|
|
673
|
+
|
|
674
|
+
if rag.total_chunks > 0:
|
|
675
|
+
# 使用用户消息作为查询
|
|
676
|
+
query = context.user_message
|
|
677
|
+
results = rag.search(query, top_k=3)
|
|
678
|
+
if results:
|
|
679
|
+
parts.append("## 相关知识库内容\n")
|
|
680
|
+
for r in results:
|
|
681
|
+
parts.append(
|
|
682
|
+
f"### 📄 {r.file_name} (片段 {r.chunk_index + 1})\n"
|
|
683
|
+
f"{r.content[:1000]}\n"
|
|
684
|
+
)
|
|
685
|
+
except Exception as e:
|
|
686
|
+
logger.debug(f"组织知识库搜索失败: {e}")
|
|
687
|
+
|
|
688
|
+
if not parts:
|
|
689
|
+
return ""
|
|
690
|
+
|
|
691
|
+
return "[组织上下文]\n请参考以下组织信息回答用户问题。如果组织信息与用户问题无关,可以忽略。\n\n" + "\n".join(parts)
|
|
692
|
+
|
|
693
|
+
except Exception as e:
|
|
694
|
+
logger.debug(f"构建组织上下文失败: {e}")
|
|
695
|
+
return ""
|