diff --git a/plugins/agent_env/config.yaml b/plugins/agent_env/config.yaml new file mode 100644 index 0000000000000000000000000000000000000000..b6bbe12fdbf47b050a18ba671816b526038a6209 --- /dev/null +++ b/plugins/agent_env/config.yaml @@ -0,0 +1,18 @@ +all: + hosts: + target-host: + ansible_host: 127.0.0.1 + ansible_port: 22 + ansible_user: root + ansible_password: "" + vars: + # Agent SDK类型,可选项: pyautogen, agno, crewai, google-generativeai, haystack-ai, langchain, openai, smolagents + agent_sdk: langchain + + # pip源配置 + pip_index_url: https://mirrors.huaweicloud.com/repository/pypi/simple + pip_trusted_host: mirrors.huaweicloud.com + + ansible_ssh_common_args: '-o StrictHostKeyChecking=no' + + diff --git a/plugins/agent_env/doc/readme.md b/plugins/agent_env/doc/readme.md new file mode 100644 index 0000000000000000000000000000000000000000..27a036a37b0e90c19045095664c88edb08ca4d5d --- /dev/null +++ b/plugins/agent_env/doc/readme.md @@ -0,0 +1,147 @@ +# Agent 开发环境安装插件 + +## 插件简介 + +本插件用于快速安装 Agent 开发所需的 Python 环境和各类 Agent SDK。支持多种主流的 Agent 开发框架,只需简单配置即可一键部署。 + +## 支持的 Agent SDK + +| SDK 名称 | 说明 | +|---------|------| +| **langchain** | LangChain框架,用于开发基于LLM的应用程序(默认) | +| **pyautogen** | Microsoft AutoGen框架,用于构建多智能体系统 | +| **agno** | Agno AI智能体框架 | +| **crewai** | CrewAI框架,用于编排角色扮演的自主AI智能体 | +| **google-generativeai** | Google的生成式AI Python SDK | +| **haystack-ai** | Haystack框架,用于构建基于LLM的NLP应用 | +| **openai** | OpenAI官方Python客户端库 | +| **smolagents** | HuggingFace的简单轻量级智能体框架 | + +## 使用方法 + +### 1. 配置文件说明 + +编辑 `config.yaml` 文件,配置目标主机信息和 Agent SDK 类型: + +```yaml +all: + hosts: + target-host: + ansible_host: 127.0.0.1 # 目标主机IP地址 + ansible_port: 22 # SSH端口 + ansible_user: root # 用户名 + ansible_password: "" # 密码 + vars: + # 选择要安装的Agent SDK类型 + agent_sdk: langchain # 可选: pyautogen, agno, crewai, google-generativeai, + # haystack-ai, langchain, openai, smolagents + + # pip源配置(默认使用华为云镜像) + pip_index_url: https://mirrors.huaweicloud.com/repository/pypi/simple + pip_trusted_host: mirrors.huaweicloud.com +``` + +### 2. 安装 Agent 开发环境 + +执行以下命令安装指定的 Agent SDK: + +```bash +oedp run install +``` + +安装过程会自动完成以下步骤: +1. 检查并安装 python3 和 pip(如果不存在) +2. 使用 pip 安装指定 Agent SDK 的相关包 +3. 运行验证脚本,确认安装成功 + +### 3. 卸载 Agent SDK + +执行以下命令卸载已安装的 Agent SDK 包: + +```bash +oedp run uninstall +``` + +**注意:** 卸载操作只会移除 Agent SDK 相关的 pip 包,不会卸载 python3 和 pip 本身。 + +### 4. 本地部署测试 + +可以使用 `-lt` 参数在本地快速测试: + +```bash +oedp run install -lt +``` + +## 使用示例 + +### 示例 1:安装 LangChain(默认) + +```yaml +# config.yaml +vars: + agent_sdk: langchain +``` + +```bash +oedp run install +``` + +### 示例 2:安装 PyAutoGen + +```yaml +# config.yaml +vars: + agent_sdk: pyautogen +``` + +```bash +oedp run install +``` + +### 示例 3:安装 CrewAI + +```yaml +# config.yaml +vars: + agent_sdk: crewai +``` + +```bash +oedp run install +``` + +### 示例 4:切换 Agent SDK + +如果需要切换到其他 Agent SDK,只需: +1. 卸载当前的 SDK:`oedp run uninstall` +2. 修改 `config.yaml` 中的 `agent_sdk` 配置 +3. 安装新的 SDK:`oedp run install` + +## 安装验证 + +每次安装完成后,插件会自动运行一个小型演示程序来验证安装是否成功。如果看到类似以下输出,说明安装成功: + +``` +=== LangChain Installation Verification === +Status: SUCCESS +All LangChain core components are working properly! +========================================== +``` + +## 添加新的 Agent SDK + +如果需要支持新的 Agent SDK,只需: + +1. 在 `workspace/agent_types.yaml` 中添加配置: +```yaml +agents: + new_sdk: + packages: + - new-sdk-package>=1.0.0 + demo: demos/demo_new_sdk.py + description: Description of the new SDK +``` + +2. 在 `workspace/demos/` 目录下创建对应的验证脚本 `demo_new_sdk.py` + +3. 在 `config.yaml` 的注释中补充新 SDK 的说明 diff --git a/plugins/agent_env/main.yaml b/plugins/agent_env/main.yaml new file mode 100644 index 0000000000000000000000000000000000000000..4856bccbcf2f02d0c478a045c8c72c591a9287b4 --- /dev/null +++ b/plugins/agent_env/main.yaml @@ -0,0 +1,22 @@ +name: agent_env +version: 1.0.0 +description: Install Python development environment for various Agent SDKs +description_zh: 帮助开发者快速安装Agent开发所需的Python环境和SDK +description_en: Help developers quickly install Python development environment and SDKs for Agent development +type: app +localhost_available: true +action: + install: + description: Install Python environment and Agent SDK packages + tasks: + - name: Install Agent development environment + playbook: install.yaml + scope: all + uninstall: + description: Uninstall Agent SDK packages + tasks: + - name: Uninstall Agent SDK packages + playbook: uninstall.yaml + scope: all + + diff --git a/plugins/agent_env/workspace/agent_types.yaml b/plugins/agent_env/workspace/agent_types.yaml new file mode 100644 index 0000000000000000000000000000000000000000..286dcbde74420095385c5ec6d64642edb44fcd6d --- /dev/null +++ b/plugins/agent_env/workspace/agent_types.yaml @@ -0,0 +1,56 @@ +# Agent SDK类型配置文件 +# 定义每种Agent SDK所需的pip包和对应的demo脚本 + +agents: + pyautogen: + packages: + - pyautogen + demo: demos/demo_pyautogen.py + description: Microsoft AutoGen framework for building multi-agent systems + + agno: + packages: + - agno + demo: demos/demo_agno.py + description: Agno AI agent framework + + crewai: + packages: + - crewai + - crewai-tools + demo: demos/demo_crewai.py + description: CrewAI framework for orchestrating role-playing autonomous AI agents + + google-generativeai: + packages: + - google-generativeai + demo: demos/demo_google_generativeai.py + description: Google's Generative AI Python SDK + + haystack-ai: + packages: + - haystack-ai + demo: demos/demo_haystack.py + description: Haystack framework for building NLP applications with LLMs + + langchain: + packages: + - langchain + - langchain-community + - langchain-core + demo: demos/demo_langchain.py + description: LangChain framework for developing LLM-powered applications + + openai: + packages: + - openai + demo: demos/demo_openai.py + description: Official OpenAI Python client library + + smolagents: + packages: + - smolagents + demo: demos/demo_smolagents.py + description: HuggingFace's simple and lightweight agent framework + + diff --git a/plugins/agent_env/workspace/demos/demo_agno.py b/plugins/agent_env/workspace/demos/demo_agno.py new file mode 100755 index 0000000000000000000000000000000000000000..040efa0543400c9e0bd03ec1a42f44c2b409c191 --- /dev/null +++ b/plugins/agent_env/workspace/demos/demo_agno.py @@ -0,0 +1,34 @@ +#!/usr/bin/env python3 +""" +Agno demo script +Tests basic Agno functionality +""" + +print("Testing Agno installation...") + +try: + # Import Agno modules + import agno + + print("✓ Successfully imported agno module") + + # Get version info + if hasattr(agno, '__version__'): + print(f"✓ Agno version: {agno.__version__}") + else: + print("✓ Agno module loaded successfully") + + print("\n=== Agno Installation Verification ===") + print("Status: SUCCESS") + print("Agno is installed and importable!") + print("======================================\n") + +except ImportError as e: + print(f"✗ Import error: {e}") + print("Please check if agno package is installed correctly.") + exit(1) +except Exception as e: + print(f"✗ Unexpected error: {e}") + exit(1) + + diff --git a/plugins/agent_env/workspace/demos/demo_crewai.py b/plugins/agent_env/workspace/demos/demo_crewai.py new file mode 100755 index 0000000000000000000000000000000000000000..1e5ba8fa2862190e61cb14aaebc2b1a65cb93d29 --- /dev/null +++ b/plugins/agent_env/workspace/demos/demo_crewai.py @@ -0,0 +1,38 @@ +#!/usr/bin/env python3 +""" +CrewAI demo script +Tests basic CrewAI functionality +""" + +print("Testing CrewAI installation...") + +try: + # Import CrewAI modules + from crewai import Agent, Task, Crew + + print("✓ Successfully imported crewai core modules") + + # Test crewai-tools + try: + import crewai_tools + print("✓ Successfully imported crewai_tools") + except ImportError: + print("⚠ crewai_tools not found (optional)") + + # Test basic agent creation structure + print("✓ Agent, Task, and Crew classes are available") + + print("\n=== CrewAI Installation Verification ===") + print("Status: SUCCESS") + print("CrewAI is installed and ready to use!") + print("========================================\n") + +except ImportError as e: + print(f"✗ Import error: {e}") + print("Please check if crewai package is installed correctly.") + exit(1) +except Exception as e: + print(f"✗ Unexpected error: {e}") + exit(1) + + diff --git a/plugins/agent_env/workspace/demos/demo_google_generativeai.py b/plugins/agent_env/workspace/demos/demo_google_generativeai.py new file mode 100755 index 0000000000000000000000000000000000000000..26edc4d2913e2c8afefc0eca293fb3cd928b1fdb --- /dev/null +++ b/plugins/agent_env/workspace/demos/demo_google_generativeai.py @@ -0,0 +1,36 @@ +#!/usr/bin/env python3 +""" +Google Generative AI demo script +Tests basic Google AI SDK functionality +""" + +print("Testing Google Generative AI installation...") + +try: + # Import Google Generative AI modules + import google.generativeai as genai + + print("✓ Successfully imported google.generativeai module") + + # Test configuration structure (without actual API key) + # This just verifies the module is properly installed + print("✓ Module structure is correct") + + # Check if main classes are available + if hasattr(genai, 'GenerativeModel'): + print("✓ GenerativeModel class is available") + + print("\n=== Google Generative AI Installation Verification ===") + print("Status: SUCCESS") + print("Google Generative AI SDK is installed correctly!") + print("===================================================\n") + +except ImportError as e: + print(f"✗ Import error: {e}") + print("Please check if google-generativeai package is installed correctly.") + exit(1) +except Exception as e: + print(f"✗ Unexpected error: {e}") + exit(1) + + diff --git a/plugins/agent_env/workspace/demos/demo_haystack.py b/plugins/agent_env/workspace/demos/demo_haystack.py new file mode 100755 index 0000000000000000000000000000000000000000..2c162bff5db9d77c208e04aa3d2a3c72d8797494 --- /dev/null +++ b/plugins/agent_env/workspace/demos/demo_haystack.py @@ -0,0 +1,36 @@ +#!/usr/bin/env python3 +""" +Haystack AI demo script +Tests basic Haystack functionality +""" + +print("Testing Haystack AI installation...") + +try: + # Import Haystack modules + from haystack import Pipeline, Document + + print("✓ Successfully imported haystack core modules") + + # Test basic document creation + doc = Document(content="This is a test document") + print("✓ Created Document successfully") + + # Test pipeline creation + pipeline = Pipeline() + print("✓ Created Pipeline successfully") + + print("\n=== Haystack AI Installation Verification ===") + print("Status: SUCCESS") + print("Haystack AI is installed and working!") + print("==========================================\n") + +except ImportError as e: + print(f"✗ Import error: {e}") + print("Please check if haystack-ai package is installed correctly.") + exit(1) +except Exception as e: + print(f"✗ Unexpected error: {e}") + exit(1) + + diff --git a/plugins/agent_env/workspace/demos/demo_langchain.py b/plugins/agent_env/workspace/demos/demo_langchain.py new file mode 100755 index 0000000000000000000000000000000000000000..ce9afbffaa561cfab5ccde5bcb110d912fb453fd --- /dev/null +++ b/plugins/agent_env/workspace/demos/demo_langchain.py @@ -0,0 +1,42 @@ +#!/usr/bin/env python3 +""" +LangChain demo script +Tests basic LangChain functionality +""" + +print("Testing LangChain installation...") + +try: + # Import core LangChain modules + from langchain_core.messages import HumanMessage, SystemMessage + from langchain_core.prompts import ChatPromptTemplate + from langchain_core.output_parsers import StrOutputParser + + print("✓ Successfully imported langchain_core modules") + + # Test basic prompt template + prompt = ChatPromptTemplate.from_messages([ + ("system", "You are a helpful assistant."), + ("human", "{input}") + ]) + + print("✓ Created ChatPromptTemplate successfully") + + # Test output parser + parser = StrOutputParser() + print("✓ Created StrOutputParser successfully") + + print("\n=== LangChain Installation Verification ===") + print("Status: SUCCESS") + print("All LangChain core components are working properly!") + print("==========================================\n") + +except ImportError as e: + print(f"✗ Import error: {e}") + print("Please check if langchain packages are installed correctly.") + exit(1) +except Exception as e: + print(f"✗ Unexpected error: {e}") + exit(1) + + diff --git a/plugins/agent_env/workspace/demos/demo_openai.py b/plugins/agent_env/workspace/demos/demo_openai.py new file mode 100755 index 0000000000000000000000000000000000000000..d08568abf7ee218dc220595e0d6d6a7bac1491fd --- /dev/null +++ b/plugins/agent_env/workspace/demos/demo_openai.py @@ -0,0 +1,36 @@ +#!/usr/bin/env python3 +""" +OpenAI demo script +Tests basic OpenAI SDK functionality +""" + +print("Testing OpenAI installation...") + +try: + # Import OpenAI modules + from openai import OpenAI + import openai + + print("✓ Successfully imported openai module") + + # Get version info + if hasattr(openai, '__version__'): + print(f"✓ OpenAI version: {openai.__version__}") + + # Test client structure (without actual API key) + print("✓ OpenAI client class is available") + + print("\n=== OpenAI Installation Verification ===") + print("Status: SUCCESS") + print("OpenAI SDK is installed correctly!") + print("=====================================\n") + +except ImportError as e: + print(f"✗ Import error: {e}") + print("Please check if openai package is installed correctly.") + exit(1) +except Exception as e: + print(f"✗ Unexpected error: {e}") + exit(1) + + diff --git a/plugins/agent_env/workspace/demos/demo_pyautogen.py b/plugins/agent_env/workspace/demos/demo_pyautogen.py new file mode 100755 index 0000000000000000000000000000000000000000..31bf2cc50d4f56e6cd327012e4e161d62166c0aa --- /dev/null +++ b/plugins/agent_env/workspace/demos/demo_pyautogen.py @@ -0,0 +1,47 @@ +#!/usr/bin/env python3 +""" +PyAutoGen demo script +Tests basic AutoGen functionality +""" + +print("Testing PyAutoGen installation...") + +try: + # Import AutoGen modules + import autogen + from autogen import AssistantAgent, UserProxyAgent + + print("✓ Successfully imported autogen modules") + + # Test basic configuration + config_list = [ + { + "model": "gpt-4", + "api_key": "test_key" + } + ] + + print("✓ Created configuration successfully") + + # Test agent creation (without actual API call) + llm_config = { + "config_list": config_list, + "seed": 42, + } + + print("✓ LLM configuration created successfully") + + print("\n=== PyAutoGen Installation Verification ===") + print("Status: SUCCESS") + print("AutoGen modules are installed and importable!") + print("==========================================\n") + +except ImportError as e: + print(f"✗ Import error: {e}") + print("Please check if pyautogen package is installed correctly.") + exit(1) +except Exception as e: + print(f"✗ Unexpected error: {e}") + exit(1) + + diff --git a/plugins/agent_env/workspace/demos/demo_smolagents.py b/plugins/agent_env/workspace/demos/demo_smolagents.py new file mode 100755 index 0000000000000000000000000000000000000000..157e4bc9a92bb8e8929d5685b7e027237daf6267 --- /dev/null +++ b/plugins/agent_env/workspace/demos/demo_smolagents.py @@ -0,0 +1,38 @@ +#!/usr/bin/env python3 +""" +Smolagents demo script +Tests basic Smolagents functionality +""" + +print("Testing Smolagents installation...") + +try: + # Import Smolagents modules + import smolagents + + print("✓ Successfully imported smolagents module") + + # Get version info + if hasattr(smolagents, '__version__'): + print(f"✓ Smolagents version: {smolagents.__version__}") + else: + print("✓ Smolagents module loaded successfully") + + # Check for main components + if hasattr(smolagents, 'Agent'): + print("✓ Agent class is available") + + print("\n=== Smolagents Installation Verification ===") + print("Status: SUCCESS") + print("Smolagents is installed and ready to use!") + print("==========================================\n") + +except ImportError as e: + print(f"✗ Import error: {e}") + print("Please check if smolagents package is installed correctly.") + exit(1) +except Exception as e: + print(f"✗ Unexpected error: {e}") + exit(1) + + diff --git a/plugins/agent_env/workspace/install.yaml b/plugins/agent_env/workspace/install.yaml new file mode 100644 index 0000000000000000000000000000000000000000..35c895ec649d0a4563c6e9b6a97e65bb9a3cb771 --- /dev/null +++ b/plugins/agent_env/workspace/install.yaml @@ -0,0 +1,142 @@ +--- +- hosts: all + become: yes + gather_facts: yes + vars: + agent_types_config: "{{ playbook_dir }}/agent_types.yaml" + tasks: + # 确保python3和pip可用 + - name: Check if python3 is installed + command: python3 --version + register: python3_check + ignore_errors: yes + changed_when: false + + - name: Install python3 if not present + yum: + name: python3 + state: present + when: python3_check.rc != 0 + + - name: Verify python3 installation + command: python3 --version + register: python3_version + changed_when: false + + - name: Display python3 version + debug: + msg: "Python3 is available: {{ python3_version.stdout }}" + + - name: Check if pip3 is installed + command: python3 -m pip --version + register: pip_check + ignore_errors: yes + changed_when: false + + - name: Install pip if not present + yum: + name: python3-pip + state: present + when: pip_check.rc != 0 + + - name: Verify pip installation + command: python3 -m pip --version + register: pip_version + changed_when: false + + - name: Display pip version + debug: + msg: "pip is available: {{ pip_version.stdout }}" + + # 安装python3-libselinux用于文件操作 + - name: Install python3-libselinux + yum: + name: python3-libselinux + state: present + + # 读取agent_types配置 + - name: Load agent types configuration + include_vars: + file: "{{ agent_types_config }}" + name: agent_config + + - name: Validate agent_sdk parameter + fail: + msg: "Invalid agent_sdk '{{ agent_sdk }}'. Must be one of: {{ agent_config.agents.keys() | list | join(', ') }}" + when: agent_sdk not in agent_config.agents + + - name: Display selected Agent SDK + debug: + msg: + - "========================================" + - "Installing Agent SDK: {{ agent_sdk }}" + - "Description: {{ agent_config.agents[agent_sdk].description }}" + - "========================================" + + # 获取要安装的包列表 + - name: Get packages to install + set_fact: + packages_to_install: "{{ agent_config.agents[agent_sdk].packages }}" + + - name: Display packages to install + debug: + msg: "Packages: {{ packages_to_install | join(', ') }}" + + # 使用pip安装指定的包(使用command模块确保安装生效) + - name: Install Agent SDK packages + command: > + python3 -m pip install + {{ packages_to_install | join(' ') }} + --trusted-host {{ pip_trusted_host }} + -i {{ pip_index_url }} + register: pip_install_result + changed_when: "'Successfully installed' in pip_install_result.stdout or 'Requirement already satisfied' in pip_install_result.stdout" + + - name: Display installation result + debug: + msg: "{{ pip_install_result.stdout_lines }}" + + # 复制demo脚本到临时目录 + - name: Create temporary directory for demo + tempfile: + state: directory + suffix: _agent_demo + register: temp_demo_dir + + - name: Copy demo script to temporary directory + copy: + src: "{{ agent_config.agents[agent_sdk].demo }}" + dest: "{{ temp_demo_dir.path }}/demo.py" + mode: '0755' + + # 执行demo验证安装 + - name: Run demo script to verify installation + command: python3 {{ temp_demo_dir.path }}/demo.py + register: demo_result + changed_when: false + + - name: Display demo execution result + debug: + msg: "{{ demo_result.stdout_lines }}" + + - name: Check if demo executed successfully + fail: + msg: "Demo execution failed. Installation may not be complete." + when: demo_result.rc != 0 + + # 清理临时文件 + - name: Clean up temporary directory + file: + path: "{{ temp_demo_dir.path }}" + state: absent + + # 最终成功消息 + - name: Installation completed successfully + debug: + msg: + - "========================================" + - "Agent SDK Installation Complete!" + - "SDK: {{ agent_sdk }}" + - "Status: SUCCESS" + - "========================================" + diff --git a/plugins/agent_env/workspace/uninstall.yaml b/plugins/agent_env/workspace/uninstall.yaml new file mode 100644 index 0000000000000000000000000000000000000000..96bff21fffe3c3c33b1518ddcce1f153d846626a --- /dev/null +++ b/plugins/agent_env/workspace/uninstall.yaml @@ -0,0 +1,95 @@ +--- +- hosts: all + become: yes + gather_facts: yes + vars: + agent_types_config: "{{ playbook_dir }}/agent_types.yaml" + tasks: + # 检查pip是否可用 + - name: Check if pip3 is available + command: python3 -m pip --version + register: pip_check + ignore_errors: yes + changed_when: false + + - name: Fail if pip is not available + fail: + msg: "pip is not installed. Cannot uninstall packages." + when: pip_check.rc != 0 + + # 读取agent_types配置 + - name: Load agent types configuration + include_vars: + file: "{{ agent_types_config }}" + name: agent_config + + - name: Validate agent_sdk parameter + fail: + msg: "Invalid agent_sdk '{{ agent_sdk }}'. Must be one of: {{ agent_config.agents.keys() | list | join(', ') }}" + when: agent_sdk not in agent_config.agents + + - name: Display selected Agent SDK for uninstallation + debug: + msg: + - "========================================" + - "Uninstalling Agent SDK: {{ agent_sdk }}" + - "Description: {{ agent_config.agents[agent_sdk].description }}" + - "========================================" + + # 获取要卸载的包列表 + - name: Get packages to uninstall + set_fact: + packages_to_uninstall: "{{ agent_config.agents[agent_sdk].packages }}" + + - name: Display packages to uninstall + debug: + msg: "Packages: {{ packages_to_uninstall | join(', ') }}" + + # 提取包名(去除版本约束) + - name: Extract package names + set_fact: + package_names: "{{ packages_to_uninstall | map('regex_replace', '([^>=<]+).*', '\\1') | list }}" + + # 检查包是否已安装 + - name: Check installed packages + command: python3 -m pip list --format=freeze + register: installed_packages + changed_when: false + + - name: Filter packages that are actually installed + set_fact: + installed_to_remove: "{{ package_names | select('in', installed_packages.stdout) | list }}" + + - name: Display packages that will be removed + debug: + msg: "Found installed packages: {{ installed_to_remove | join(', ') }}" + when: installed_to_remove | length > 0 + + - name: No packages to remove + debug: + msg: "No packages from {{ agent_sdk }} are currently installed." + when: installed_to_remove | length == 0 + + # 使用pip卸载包(使用command模块) + - name: Uninstall Agent SDK packages + command: python3 -m pip uninstall -y {{ installed_to_remove | join(' ') }} + register: pip_uninstall_result + when: installed_to_remove | length > 0 + changed_when: "'Successfully uninstalled' in pip_uninstall_result.stdout" + + - name: Display uninstallation result + debug: + msg: "{{ pip_uninstall_result.stdout_lines }}" + when: installed_to_remove | length > 0 + + # 最终成功消息 + - name: Uninstallation completed successfully + debug: + msg: + - "========================================" + - "Agent SDK Uninstallation Complete!" + - "SDK: {{ agent_sdk }}" + - "Status: SUCCESS" + - "Note: python3 and pip were not removed" + - "========================================" +