# Dynamic-AgentScope **Repository Path**: xiaoyaaimeili/dynamic-agent-scope ## Basic Information - **Project Name**: Dynamic-AgentScope - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-03-06 - **Last Updated**: 2026-03-11 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Dynamic-AgentScope **基于 AgentScope 的动态 Agent 托管平台** ## 📖 项目简介 Dynamic-AgentScope 是一个动态 Agent 托管平台,用户通过与"生产 Agent"(Meta-Agent)对话描述需求,系统自动生成 YAML 配置并实时实例化一个具备 Skill、Memory 和 MCP 能力的独立 Agent 服务。 ### 核心特性 - 🎯 **Meta-Agent 对话式创建** - 通过自然语言描述需求,自动生成 Agent - ⚡ **动态加载引擎** - YAML 配置到运行态 Agent 的自动映射 - 🔧 **技能系统** - 支持 builtin 和 custom (Python 脚本) 技能 - 🧠 **记忆管理** - 短期记忆 + 长期记忆支持 - 🔌 **MCP 协议** - 模型上下文协议,连接外部服务 - 🔥 **热部署** - 不重启主进程的情况下更新 Agent 配置 - 🔒 **安全检查** - Python 脚本静态安全检查 ## 🏗️ 架构图 ``` ┌─────────────────────────────────────────────────────────────────┐ │ 用户交互层 │ │ REST API / Swagger UI │ └─────────────────────────────────────────────────────────────────┘ │ ▼ ┌─────────────────────────────────────────────────────────────────┐ │ Meta-Agent (生产 Agent) │ │ • 多轮对话引导用户明确需求 │ │ • 自动生成 YAML 配置 │ │ • 配置校验 & 上线确认 │ └─────────────────────────────────────────────────────────────────┘ │ ▼ ┌─────────────────────────────────────────────────────────────────┐ │ 动态加载引擎 (Engine) │ │ ┌────────────────┐ ┌────────────────┐ ┌────────────────────┐ │ │ │ YAML 解释器 │ │ Skill 加载器 │ │ Agent 实例管理器 │ │ │ └────────────────┘ └────────────────┘ └────────────────────┘ │ └─────────────────────────────────────────────────────────────────┘ │ ▼ ┌─────────────────────────────────────────────────────────────────┐ │ Agent 运行时容器 │ │ Agent Instance 1 │ Agent Instance 2 │ Agent Instance N │ │ (port: 8001) │ (port: 8002) │ (port: 800N) │ └─────────────────────────────────────────────────────────────────┘ ``` ## 🚀 快速开始 ### 环境要求 - JDK 17+ - Maven 3.8+ - Python 3.8+ (用于自定义技能) - DashScope API Key (或其他 LLM 提供商) ### 安装依赖 ```bash cd dynamic-agentscope mvn clean install ``` ### 配置环境变量 ```bash export DASHSCOPE_API_KEY=your-api-key-here ``` ### 启动服务 ```bash mvn spring-boot:run ``` 服务启动后访问: - API 文档: http://localhost:8080/swagger-ui.html - 健康检查: http://localhost:8080/api/v1/health ## 📚 API 使用指南 ### 1. 与 Meta-Agent 对话创建 Agent ```bash # 开始对话 curl -X POST http://localhost:8080/api/v1/meta/chat \ -H "Content-Type: application/json" \ -d '{ "message": "我需要一个能读取本地PDF文件并根据天气建议户外活动的Agent" }' # 继续对话(使用返回的 sessionId) curl -X POST http://localhost:8080/api/v1/meta/chat \ -H "Content-Type: application/json" \ -d '{ "sessionId": "your-session-id", "message": "确认上线" }' ``` ### 2. 直接通过 YAML 创建 Agent ```bash curl -X POST http://localhost:8080/api/v1/agents \ -H "Content-Type: application/yaml" \ -d ' agent_definition: id: "my-agent" name: "我的助手" roles: "你是一个有用的AI助手" capabilities: skills: - type: "builtin" name: "file-read-skill" memory_config: short_term: type: "in_memory" window_size: 20 runtime: port: 8001 endpoint: "/chat" ' ``` ### 3. 与 Agent 对话 ```bash curl -X POST http://localhost:8080/api/v1/agents/my-agent/chat \ -H "Content-Type: application/json" \ -d '{ "message": "你好,请介绍一下你自己" }' ``` ### 4. 管理 Agent ```bash # 列出所有 Agent curl http://localhost:8080/api/v1/agents # 获取 Agent 详情 curl http://localhost:8080/api/v1/agents/my-agent # 热部署 Agent curl -X POST http://localhost:8080/api/v1/agents/my-agent/reload # 停止 Agent curl -X POST http://localhost:8080/api/v1/agents/my-agent/stop # 删除 Agent curl -X DELETE http://localhost:8080/api/v1/agents/my-agent ``` ## 📝 YAML 配置说明 ### 完整配置示例 ```yaml # Agent 定义 agent_definition: id: "pdf-weather-agent" # Agent 唯一标识 name: "PDF天气助手" # Agent 名称 roles: | # 系统提示词 你是一个能够读取本地PDF文件并根据天气建议户外活动的助手。 # 能力配置 capabilities: # 技能列表 skills: # 内置技能 - type: "builtin" name: "file-read-skill" # 自定义 Python 技能 - type: "custom" path: "pdf_reader.py" functions: ["read_pdf", "extract_text"] # MCP 服务器配置 mcp_servers: - name: "weather-service" url: "http://localhost:3000/mcp" auth: type: "bearer" token: "${WEATHER_API_TOKEN}" # 记忆配置 memory_config: short_term: type: "in_memory" window_size: 20 long_term: type: "vector_store" backend: "qdrant" collection: "agent-pdf-weather" # 运行时配置 runtime: port: 8002 # 服务端口 endpoint: "/chat" # 服务端点 cors: true # 是否启用 CORS ``` ### 内置技能列表 | 技能名称 | 描述 | 函数 | |---------|------|------| | `file-read-skill` | 文件读取 | read_file, list_files | | `http-request-skill` | HTTP 请求 | get, post, put, delete | | `data-process-skill` | 数据处理 | parse_json, parse_csv, transform | ### 自定义 Python 技能 在 `custom_skills/` 目录下创建 Python 脚本: ```python # custom_skills/my_skill.py def my_function(param1, param2): """ 自定义技能函数 Args: param1: 参数1说明 param2: 参数2说明 Returns: dict: 返回结果 """ return { "success": True, "result": f"处理完成: {param1}, {param2}" } ``` ## 🔒 安全机制 ### Python 脚本安全检查 系统会自动检查自定义 Python 脚本中的危险代码: **禁止的危险模块:** - `os`, `subprocess`, `sys` - `socket`, `requests`, `urllib` - `pickle`, `marshal` - `ctypes`, `multiprocessing` **禁止的危险函数:** - `exec()`, `eval()`, `compile()` - `open()`, `file()` - `os.system()`, `subprocess.call()` ## 🛠️ 开发指南 ### 项目结构 ``` dynamic-agentscope/ ├── src/main/java/com/dynamic/agentscope/ │ ├── config/ # 配置类 │ ├── controller/ # REST 控制器 │ ├── engine/ # 核心引擎 │ │ ├── DynamicAgentEngine.java │ │ ├── SkillLoader.java │ │ └── YamlInterpreter.java │ ├── meta/ # Meta-Agent │ ├── model/ # 数据模型 │ ├── runtime/ # 运行时容器 │ ├── security/ # 安全检查 │ └── util/ # 工具类 ├── custom_skills/ # 自定义 Python 技能 ├── agents/configs/ # Agent YAML 配置存储 └── src/main/resources/ └── application.yaml # 应用配置 ``` ### 扩展技能 1. 在 `custom_skills/` 创建 Python 脚本 2. 在 YAML 配置中引用: ```yaml skills: - type: "custom" path: "your_script.py" functions: ["func1", "func2"] ``` ## 📊 技术栈 | 组件 | 技术 | |------|------| | 基础框架 | AgentScope Java 1.0.9 | | Web 框架 | Spring Boot 3.2.0 | | YAML 解析 | SnakeYAML 2.2 | | LLM | DashScope (Qwen-Max) | | Python 集成 | Python 3 子进程调用 | ## 📄 License Apache License 2.0 ## 👨‍💻 作者 牛马大虾 🦐 --- **Powered by AgentScope Java**