diff --git a/data_juicer_agent/README.md b/data_juicer_agent/README.md index 375ca4a..fe553a3 100644 --- a/data_juicer_agent/README.md +++ b/data_juicer_agent/README.md @@ -4,32 +4,31 @@ A multi-agent data processing system built on [AgentScope](https://github.com/mo ## 📋 Table of Contents -- [DataJuicer Agent](#datajuicer-agent) - - [📋 Table of Contents](#-table-of-contents) - - [What Does This Agent Do?](#what-does-this-agent-do) - - [Architecture](#architecture) - - [Quick Start](#quick-start) - - [System Requirements](#system-requirements) - - [Installation](#installation) - - [Configuration](#configuration) - - [Usage](#usage) - - [Agent Introduction](#agent-introduction) - - [Data Processing Agent](#data-processing-agent) - - [Code Development Agent (DJ Dev Agent)](#code-development-agent-dj-dev-agent) - - [Advanced Features](#advanced-features) - - [Operator Retrieval](#operator-retrieval) - - [Retrieval Modes](#retrieval-modes) - - [Usage](#usage-1) - - [MCP Agent](#mcp-agent) - - [MCP Server Types](#mcp-server-types) - - [Configuration](#configuration-1) - - [Usage Methods](#usage-methods) - - [Feature Preview](#feature-preview) - - [Data-Juicer Q\&A Agent (Demo Available)](#data-juicer-qa-agent-demo-available) - - [Data Analysis and Visualization Agent (In Development)](#data-analysis-and-visualization-agent-in-development) - - [Troubleshooting](#troubleshooting) - - [Common Issues](#common-issues) - - [Optimization Recommendations](#optimization-recommendations) +- [📋 Table of Contents](#-table-of-contents) +- [What Does This Agent Do?](#what-does-this-agent-do) +- [Architecture](#architecture) +- [Quick Start](#quick-start) + - [System Requirements](#system-requirements) + - [Installation](#installation) + - [Configuration](#configuration) + - [Usage](#usage) +- [Agent Introduction](#agent-introduction) + - [Data Processing Agent](#data-processing-agent) + - [Code Development Agent (DJ Dev Agent)](#code-development-agent-dj-dev-agent) +- [Advanced Features](#advanced-features) + - [Operator Retrieval](#operator-retrieval) + - [Retrieval Modes](#retrieval-modes) + - [Usage](#usage-1) + - [MCP Agent](#mcp-agent) + - [MCP Server Types](#mcp-server-types) + - [Configuration](#configuration-1) + - [Usage Methods](#usage-methods) +- [Feature Preview](#feature-preview) + - [Data-Juicer Q\&A Agent (Demo Available)](#data-juicer-qa-agent-demo-available) + - [Data Analysis and Visualization Agent (In Development)](#data-analysis-and-visualization-agent-in-development) +- [Troubleshooting](#troubleshooting) + - [Common Issues](#common-issues) + - [Optimization Recommendations](#optimization-recommendations) ## What Does This Agent Do? @@ -62,7 +61,7 @@ Router Agent ──┐ ### System Requirements -- Python 3.8+ +- Python 3.10+ - Valid DashScope API key - Optional: Data-Juicer source code (for custom operator development) @@ -103,7 +102,7 @@ Choose the running mode using the `-u` or `--use_studio` parameter: ```bash # Use AgentScope Studio (provides interactive interface) -python main.py --use_studio true +python main.py --use_studio True # Or use command-line mode (default) python main.py diff --git a/data_juicer_agent/README_ZH.md b/data_juicer_agent/README_ZH.md index 9ecf63c..35fa06b 100644 --- a/data_juicer_agent/README_ZH.md +++ b/data_juicer_agent/README_ZH.md @@ -4,31 +4,30 @@ ## 📋 目录 -- [DataJuicer 智能体](#datajuicer-智能体) - - [📋 目录](#-目录) - - [这个智能体做了什么?](#这个智能体做了什么) - - [架构](#架构) - - [快速开始](#快速开始) - - [系统要求](#系统要求) - - [安装](#安装) - - [配置](#配置) - - [使用](#使用) - - [智能体介绍](#智能体介绍) - - [数据处理智能体](#数据处理智能体) - - [代码开发智能体](#代码开发智能体) - - [高级功能](#高级功能) - - [算子检索](#算子检索) - - [检索模式](#检索模式) - - [使用](#使用-1) - - [MCP 智能体](#mcp-智能体) - - [MCP 服务器类型](#mcp-服务器类型) - - [配置](#配置-1) - - [使用方法](#使用方法) - - [功能预览](#功能预览) - - [Data-Juicer 问答智能体 (演示可用)](#data-juicer-问答智能体-演示可用) - - [数据分析与可视化智能体 (开发中)](#数据分析与可视化智能体-开发中) - - [常见问题](#常见问题) - - [优化建议](#优化建议) +- [📋 目录](#-目录) +- [这个智能体做了什么?](#这个智能体做了什么) +- [架构](#架构) +- [快速开始](#快速开始) + - [系统要求](#系统要求) + - [安装](#安装) + - [配置](#配置) + - [使用](#使用) +- [智能体介绍](#智能体介绍) + - [数据处理智能体](#数据处理智能体) + - [代码开发智能体](#代码开发智能体) +- [高级功能](#高级功能) + - [算子检索](#算子检索) + - [检索模式](#检索模式) + - [使用](#使用-1) + - [MCP 智能体](#mcp-智能体) + - [MCP 服务器类型](#mcp-服务器类型) + - [配置](#配置-1) + - [使用方法](#使用方法) +- [功能预览](#功能预览) + - [Data-Juicer 问答智能体 (演示可用)](#data-juicer-问答智能体-演示可用) + - [数据分析与可视化智能体 (开发中)](#数据分析与可视化智能体-开发中) + - [常见问题](#常见问题) + - [优化建议](#优化建议) ## 这个智能体做了什么? @@ -61,7 +60,7 @@ Data-Juicer (DJ) 是一个一站式系统,面向大模型的文本及多模态 ### 系统要求 -- Python 3.8+ +- Python 3.10+ - 有效的 DashScope API 密钥 - 可选:Data-Juicer 源码(用于自定义算子开发) @@ -102,7 +101,7 @@ export DATA_JUICER_PATH="your-data-juicer-path" ```bash # 使用 AgentScope Studio(提供交互式界面) -python main.py --use_studio true +python main.py --use_studio True # 或使用命令行模式(默认) python main.py diff --git a/data_juicer_agent/__init__.py b/data_juicer_agent/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/data_juicer_agent/main.py b/data_juicer_agent/main.py index 42aab76..f2c61d8 100644 --- a/data_juicer_agent/main.py +++ b/data_juicer_agent/main.py @@ -8,9 +8,9 @@ from agentscope.formatter import DashScopeChatFormatter from agentscope.memory import InMemoryMemory from agentscope.agent import UserAgent -from .agent_factory import create_agent -from .prompts import DJ_SYS_PROMPT, DJ_DEV_SYS_PROMPT, ROUTER_SYS_PROMPT, MCP_SYS_PROMPT -from .tools import ( +from agent_factory import create_agent +from prompts import DJ_SYS_PROMPT, DJ_DEV_SYS_PROMPT, ROUTER_SYS_PROMPT, MCP_SYS_PROMPT +from tools import ( dj_toolkit, dj_dev_toolkit, mcp_tools, diff --git a/data_juicer_agent/tools/__init__.py b/data_juicer_agent/tools/__init__.py index ecf012a..30eb150 100644 --- a/data_juicer_agent/tools/__init__.py +++ b/data_juicer_agent/tools/__init__.py @@ -5,7 +5,6 @@ Tools package for data-agent. This module provides a unified entry point for all agent tools, organized by agent type for easy access and management. """ -import asyncio from typing import List from agentscope.agent import AgentBase from agentscope.tool import ( @@ -14,11 +13,11 @@ from agentscope.tool import ( ) from agentscope.tool import Toolkit -from .dj_tools import execute_safe_command -from .router_tools import agent_to_tool -from .dj_tools import query_dj_operators -from .dj_dev_tools import get_basic_files, get_operator_example, configure_data_juicer_path -from .mcp_tools import get_mcp_toolkit +from .dj_helpers import execute_safe_command +from .router_helpers import agent_to_tool +from .dj_helpers import query_dj_operators +from .dj_dev_helpers import get_basic_files, get_operator_example, configure_data_juicer_path +from .mcp_helpers import get_mcp_toolkit def create_toolkit(tools: List[str]): # Create toolkit and register tools diff --git a/data_juicer_agent/tools/dj_dev_tools.py b/data_juicer_agent/tools/dj_dev_helpers.py similarity index 99% rename from data_juicer_agent/tools/dj_dev_tools.py rename to data_juicer_agent/tools/dj_dev_helpers.py index b7681e8..720895f 100644 --- a/data_juicer_agent/tools/dj_dev_tools.py +++ b/data_juicer_agent/tools/dj_dev_helpers.py @@ -7,7 +7,6 @@ and example code for different operator types. """ import os -from pathlib import Path from agentscope.message import TextBlock from agentscope.tool import ToolResponse diff --git a/data_juicer_agent/tools/dj_tools.py b/data_juicer_agent/tools/dj_helpers.py similarity index 100% rename from data_juicer_agent/tools/dj_tools.py rename to data_juicer_agent/tools/dj_helpers.py diff --git a/data_juicer_agent/tools/mcp_tools.py b/data_juicer_agent/tools/mcp_helpers.py similarity index 100% rename from data_juicer_agent/tools/mcp_tools.py rename to data_juicer_agent/tools/mcp_helpers.py diff --git a/data_juicer_agent/tools/router_tools.py b/data_juicer_agent/tools/router_helpers.py similarity index 100% rename from data_juicer_agent/tools/router_tools.py rename to data_juicer_agent/tools/router_helpers.py diff --git a/tests/data_juicer_agent_test.py b/tests/data_juicer_agent_test.py index 80f2068..2263028 100644 --- a/tests/data_juicer_agent_test.py +++ b/tests/data_juicer_agent_test.py @@ -1,5 +1,13 @@ # -*- coding: utf-8 -*- import os + +import sys +from pathlib import Path + +root_path = Path(__file__).parent.parent +sys.path.insert(0, str(root_path)) +sys.path.insert(0, str(Path(root_path)/"data_juicer_agent")) + import pytest from unittest.mock import AsyncMock, Mock, patch from agentscope.agent import ReActAgent @@ -22,6 +30,7 @@ from data_juicer_agent.tools import ( dj_tools, dj_dev_tools, mcp_tools, + get_mcp_toolkit, execute_safe_command, query_dj_operators, get_basic_files, @@ -29,6 +38,7 @@ from data_juicer_agent.tools import ( configure_data_juicer_path, ) + class TestDataJuicerAgent: """Test suite for the data_juicer_agent functionality""" @@ -138,6 +148,13 @@ class TestDataJuicerAgent: @pytest.mark.asyncio async def test_mcp_tools_list(self, mock_mcp_client): """Test MCP tools list contains expected tools and MCP client binding""" + with patch( + "agentscope.mcp.HttpStatefulClient", + return_value=mock_mcp_client, + ) as mock_client_cls: + await get_mcp_toolkit() + assert mock_client_cls.assert_called_once + expected_tools = [view_text_file, write_text_file] assert len(mcp_tools) == len(expected_tools) for tool in expected_tools: @@ -179,7 +196,7 @@ class TestDataJuicerAgent: mock_mcp_clients = [mock_mcp_client] with patch( - "data_juicer_agent.tools.mcp_tools._create_clients", + "data_juicer_agent.tools.mcp_helpers._create_clients", return_value=mock_mcp_clients, ): with patch( @@ -216,5 +233,6 @@ class TestDataJuicerAgent: ) assert mcp_agent_created, "MCP agent should be created" + if __name__ == "__main__": - pytest.main(["-v", __file__]) \ No newline at end of file + pytest.main(["-v", __file__])