Content
AI Super Intelligent Agent — AI Agent
> Autonomous planning AI intelligent body platform based on **Spring AI** + **ReAct mode**, integrating core AI technologies such as RAG knowledge base, MCP protocol, and tool calls.
<p align="center">
<img src="https://img.shields.io/badge/Java-21-orange?logo=openjdk" alt="Java 21">
<img src="https://img.shields.io/badge/Spring_Boot-3.4.4-brightgreen?logo=springboot" alt="Spring Boot">
<img src="https://img.shields.io/badge/Spring_AI-1.0.0-blue" alt="Spring AI">
<img src="https://img.shields.io/badge/Vue-3.x-4FC08D?logo=vue.js" alt="Vue 3">
<img src="https://img.shields.io/badge/License-MIT-yellow" alt="License">
</p>
---
## Project Introduction
This project is a full-stack project with **AI development practice** as its core, including two core applications:
### AI Love Master
An intelligent emotional consultant based on large models, supporting multi-turn dialogue, RAG knowledge base retrieval, tool calls, and MCP service integration, which can solve users' love problems and make dating plans.
### Manus Super Intelligent Agent
An autonomous planning intelligent agent based on the **ReAct (Reasoning + Acting)** mode, which can autonomously reason, call tools (network search, web crawling, file operation, resource download, PDF generation), and complete any complex task specified by the user.
## Core Features
- **Large Model Access**: Supports multiple access methods such as DashScope (Alibaba Cloud Hundred Refining), Ollama local deployment, and HTTP API direct call.
- **ReAct Intelligent Agent**: An autonomous planning Agent implemented from scratch, supporting Think → Act → Observe loop, with a maximum of 20 steps of task execution.
- **RAG Knowledge Base**: Vector retrieval based on PgVector / SimpleVectorStore, integrating document loading, keyword enhancement, query rewriting, and contextual query enhancement.
- **Tool Calls**: 7 built-in tools (network search, web crawling, file read and write, resource download, terminal operation, PDF generation, task termination).
- **MCP Model Context Protocol**: Supports STDIO and SSE transmission modes, with built-in image search MCP service.
- **Streaming Dialogue (SSE)**: Real-time streaming dialogue based on Server-Sent Events.
- **Dialogue Memory**: Supports memory and file persistence based on Kryo serialization.
- **Structured Output**: Parse AI replies into structured JSON- **API Documentation**: Knife4j + Swagger UI automatically generates API documentation.
## Technical Stack
### Backend
| Technology | Version | Description |
|------|------|------|
| Java | 21 | Development language |
| Spring Boot | 3.4.4 | Main framework |
| Spring AI | 1.0.0 | AI development framework |
| Spring AI Alibaba | 1.0.0.2 | Alibaba Cloud Hundred Refining integration |
| DashScope SDK | 2.19.1 | Tongyi Qianwen large model |
| LangChain4j | 1.0.0-beta2 | Supplementary AI framework |
| PgVector | — | PostgreSQL vector database |
| Ollama | — | Local large model deployment |
| MCP Client | — | Model context protocol client |
| Knife4j | 4.4.0 | API documentation |
| iText | 9.1.0 | PDF generation |
| Jsoup | 1.19.1 | HTML parsing / web crawling |
| Kryo | 5.6.2 | High-performance serialization |
| Hutool | 5.8.37 | General tool library |
### Frontend
| Technology | Version | Description |
|------|------|------|
| Vue | 3.x | Frontend framework (Composition API) |
| Vue Router | 4.x | Routing management |
| Axios | 1.x | HTTP client |
| Vite | 4.x | Build tool |
| EventSource | — | SSE streaming communication |
### Infrastructure
| Technology | Description |
|------|------|
| PostgreSQL + PgVector | Vector database |
| Docker | Containerized deployment |
| SearchAPI.io | Baidu search engine API |
| Pexels API | Image search service |
## Architecture Design
### System Architecture Diagram
```mermaid
graph TB
subgraph Frontend[" Frontend (Vue 3 + Vite)"]
Home[Home]
LoveMaster[AI Love Master Page]
SuperAgent[AI Super Intelligent Agent Page]
ChatRoom[Shared Chat Component]
SSE_Client[SSE Client]
end
subgraph Backend[" Backend (Spring Boot :8123)"]
AiController[AI Controller<br/>REST API]
LoveApp[LoveApp<br/>Love Master Service]
Manus[Manus Agent<br/>ReAct Intelligent Agent]
subgraph AgentCore["Intelligent Agent Core"]
BaseAgent[BaseAgent<br/>Basic Agent Abstract Class]
ReActAgent[ReActAgent<br/>Think-Act Loop]
ToolCallAgent[ToolCallsAgent<br/>Manual Tool Scheduling]
end
subgraph Advisors["Advisor Chain"]
ChatMemory[ChatMemory<br/>Dialogue Memory]
RAG_Advisor[RAG Advisor<br/>Knowledge Retrieval Enhancement]
Logger[MyLogger<br/>Log Recorder]
end
subgraph Tools[" Toolset (7 Tools)"]
WebSearch[Network Search]
WebScrape[Web Crawling]
FileOps[File Operation]
Download[Resource Download]
Terminal[Terminal Operation PDF[PDF Generation]
Terminate[Task Termination]
end
RAG_Engine[RAG Engine<br/>Document Loading → Vectorization → Retrieval]
end
subgraph MCP_Server[" MCP Service (:8127)"]
ImageSearch[Image Search MCP<br/>Pexels API]
end
subgraph External[" External Services"]
DashScope[Alibaba Cloud Hundred Refining<br/>qwen-plus]
PgVector[(PgVector<br/>Vector Database)]
SearchAPI[SearchAPI.io<br/>Baidu Search]
Pexels[Pexels<br/>Image Search]
Ollama[Ollama<br/>Local Model]
end
Home --> LoveMaster
Home --> SuperAgent
LoveMaster --> ChatRoom
SuperAgent --> ChatRoom
ChatRoom --> SSE_Client
SSE_Client -->|"SSE Stream"| AiController
AiController -->|"Chat"| LoveApp
AiController -->|"Intelligent Agent"| Manus
LoveApp --> LoveApp --> Tools LoveApp --> RAG_Engine
LoveApp --> MCP_Server
Manus --> AgentCore
AgentCore --> Tools
LoveApp --> DashScope
Manus --> DashScope
RAG_Engine --> PgVector
Tools --> SearchAPI
Tools --> Pexels
LoveApp --> Ollama
MCP_Server --> Pexels
style Frontend fill:#42b883,color:#fff
style Backend fill:#6db33f,color:#fff
style AgentCore fill:#ff9800,color:#fff
style Tools fill:#9c27b0,color:#fff
style MCP_Server fill:#00bcd4,color:#fff
style External fill:#607d8b,color:#fff
```
### Agent Execution Process
```mermaid
sequenceDiagram
participant User as User
participant Ctrl as AiController
participant Agent as Manus
participant LLM as Large Model
participant Tools as Toolset
User->>Ctrl: Send Task
Ctrl->>Agent: Create Agent Instance
activate Agent
loop ReAct Loop (up to 20 steps)
Agent->>LLM: think() — Send Message History + Tool List
LLM-->>Agent: Return ToolCall List
alt Has Tool Call
Agent->>Tools: act() — Execute Tool
Tools-->>Agent: Tool Execution Result
Agent->>LLM: Feedback Result to LLM
LLM-->>Agent: Continue Reasoning / Call More Tools
else No Tool Calls (Terminate)
Agent->>Agent: Set Status = FINISHED
end
end
deactivate Agent
Agent-->>Ctrl: SSE Streaming Return Result
Ctrl-->>User: Display Final Result
```
### Project Directory Structure
```
ai-agent/
├── src/main/java/com/pi/aiagent/
│ ├── AiAgentApplication.java # Application Entrance
│ /
│ │ ├── AiController.java # AI Core Interface
│ │ ├── HealthController.java # Health Check
│ │ └── TestController.java # API Key Test
│ ├── agent/ # Intelligent Agent
│ │ ├── BaseAgent.java # Base Class: State Management, Message Context, Execution Loop
│ │ ├── ReAct # ReAct Mode: think() + act()
│ │ ├── ToolCallsAgent.java # Tool Scheduling: Manual Tool Call
│ │ └── Manus.java # Ultimate Intelligent Agent Implementation
│ ├── app/
│ └── LoveApp.java # AI Love Master (Advisor Chain)
│ ├── advisor/
│ │ ├── MyLoggerAdvisor.java # Request/Response Log Interceptor
│ │ └── ReReadingAdvisor.java # Re2 Read Enhancement
│ ├── chatmemory/
│ │ └── FileBasedChatMemory.java # Kryo File Persistence Memory
│ ├── config/
│ │ └── CorsConfig # Cross-Domain Configuration
│ ├── rag/ # RAG Knowledge Base
│ │ ├──DocumentLoader.java # Document Loading
│ │ ├── LoveAppVectorStoreConfig.java # Vector Storage Configuration
│ │ ├── LoveAppRagCustomAdvisorFactory.java # Custom RAG Advisor
│ │ AppContextualQueryAugmenterFactory.java # Context Enhancement
│ │ ├── LoveAppRagCloudAdvisorConfig.java # Cloud Knowledge
│ │ ├── PgVectorVectorStoreConfig.java # PGVector Configuration
│ │ MyKeywordEnricher.java # Keyword Enhancement
│ │ ├── MyTokenTextSplitter.java # Document Split
│ │ └── QueryRewriter.java # Query Rewriting
│ ├── tools/ # Toolset
│ │ ├── ToolRegistration.java # Tool Registration Center
│ │ ├── WebSearchTool.java # Network Search
│ │ ├──rapingTool.java # Web Crawling
│ │ ├── FileOperationTool.java # File Operation
│ │ ├── ResourceDownloadTool.java # Resource Download
│ │ ├── TerminalOperationTool.java # Terminal Operation
│ │ ├── PDFGenerationTool.java # PDF Generation
│ │ └── TerminateTool.java # Task Termination
│ ├── demo/ # Example│ │ ├── invoke/ # 4 Large Model Access Methods
│ │ └── rag # RAG Advanced Feature Demo
│ /
│ └── FileConstant.java # File Path Constants
├── src/main/resources/
│ ├── application.yml # Main Configuration (desensitized)
│ ├── application-prod.yml # Production Configuration
│ ├── application-local.yml.example # Template
│ ├── document/ # RAG Knowledge Base Documents
│ │ ├── Problems and Answers - Single.md
│ │ ├── Common Love Problems and Answers - Love.md
│ │ └── Common Love Problems and Answers - Married.md
│ └── mcp-servers.json # MCP Service Configuration
├── ai-agent-frontend/ # Vue 3 Frontend
│ ├── src │ ├── views/
│ │ │ ├── Home.vue # Home Page
│ │ │ ├── LoveMaster.vue # Love Master Interface
│ │ │ └── SuperAgent.vue # Super Intelligent Agent Interface
│ │ ├── components/
│ │ │ ├── ChatRoom.vue # Component
│ │ ├── AiAvatar # AI Avatar
│ │ │ └── AppFooter.vue # Footer
│ │ ├── api/index.js # API & SSE Encapsulation
│ │ └── router/index.js # Routing Configuration
│ ├── Dockerfile # Frontend Docker Build ├── nginx.conf Nginx Configuration
│ └── package.json
├── image-search-mcp-server/ MCP Service
├── src/main/java│ │ SearchMcpServer
│ │ └── tools/ImageSearchTool.java # Pexels Image Search
│ └── src/main/resources/
│ ├── application-sse.yml # SSE Mode Configuration
│ └── application-stdio.yml # STDIO Mode Configuration
├── Dockerfile # Backend Docker Build
├── pom.xml # Maven Dependency Management
└── README.md
```
## Quick### Environment Requirements **JDK 21+ **Maven 9+**
-.js 18 (Frontend Development)
PostgreSQL + PgVector Plugin** (Vector Retrieval, optional)
- **Ollama** (Local Model Deployment, optional)
### 1. Clone Project
```bash
git clone https://github.com/SXX176/ai-agent-master.git
cd ai-agent-master
```
### 2. Configure API```bash
# Copy Configuration Template
cp src/main/resources/application-local.yml.example src/main/resources/application-local.yml
Edit `src/main/resources/application-local.yml` and fill in your configurations:
```yaml
spring:
datasource:
url: jdbc:postgresql://<your-host>:5432/<your-db>
username: <your-username>
password: <your-password>
ai:
dashscope:
api-key: <your-dashscope-api-key>
search-api:
api-key: <your-searchapi-key>
```
> ⚠️ **Note**: `application-local.yml` is in `.gitignore` and will not be committed to Git.
**API Key Retrieval Addresses:**
- Alibaba Cloud DashScope: [https://dashscope.console.aliyun.com/apiKey](https://dashscope.console.aliyun.com/apiKey)
- SearchAPI: [https://www.searchapi.io/](https://www.searchapi.io/)
### 3. Start the Backend
```bash
# Using Maven Wrapper (no need to install Maven)
./mvnw spring-boot:run
# Or using system Maven
mvn spring-boot:run
```
After the backend starts, access:
- API Service: http://localhost:8123/api
- Swagger Documentation: http://localhost:8123/api/swagger-ui.html
- Health Check: http://localhost:8123/api/health
### 4. Start the Frontend (Development Mode)
```bash
cd ai-agent-frontend
npm install
npm run dev
```
Access: http://localhost:3000
### 5. Start the Image Search MCP Service (Optional)
```bash
cd image-search-mcp-server
../mvnw spring-boot:run -f pom.xml
```
MCP Service starts at http://localhost:8127
## 🐳 Docker Deployment
### Backend Deployment
```bash
# Build Image
docker build -t ai-agent .
# Run Container
docker run -d \
-p 8123:8123 \
-v /path/to/application-local.yml:/app/src/main/resources/application-local.yml \
--name ai-agent \
ai-agent
```
### Frontend Deployment
```bash
cd ai-agent-frontend
# Build Static Files
npm run build
# Deploy dist/ directory using Nginx
# Refer to ai-agent-frontend/nginx.conf
```
### Using Docker Compose (Recommended)
Create `docker-compose.yml`:
```yaml
version: '3.8'
services:
backend:
build: .
ports:
- "8123:8123"
volumes:
- ./src/main/resources/application-local.yml:/app/src/main/resources/application-local.yml
environment:
- SPRING_PROFILES_ACTIVE=local
frontend:
build: ./ai-agent-frontend
ports:
- "80:80"
depends_on:
- backend
postgres:
image: pgvector/pgvector:pg16
environment:
POSTGRES_DB: ai_agent
POSTGRES_USER: my_user
POSTGRES_PASSWORD: my_password
ports:
- "5432:5432"
volumes:
- pgdata:/var/lib/postgresql/data
mcp-server:
build: ./image-search-mcp-server
ports:
- "8127:8127"
volumes:
pgdata:
```
## 🔌 API Interface
### Core Interfaces
| Method | Path | Description |
|------|------|------|
| GET | `/api/ai/love_app/chat/sse` | AI Love Master — SSE Streaming Chat |
| GET | `/api/ai/love_app/chat/sync` | AI Love Master — Synchronous Chat |
| GET | `/api/ai/manus/chat` | Manus Intelligent Agent — SSE Streaming Chat |
| GET | `/api/health` | Health Check |
| GET | `/api/test/api-key` | Test API Key Validity |
### Usage Example
```bash
# Chat with AI Love Master (SSE Streaming)
curl -N "http://localhost:8123/api/ai/love_app/chat/sse?message=你好&chatId=my_session"
# Call Manus Intelligent Agent
curl -N "http://localhost:8123/api/ai/manus/chat?message=帮我搜索上海约会地点并生成PDF"
```
## 🧪 Built-in Tools Overview
| Tool | Class Name | Function |
|------|------|------|
| 🌐 Web Search | `WebSearchTool` | Call Baidu Search using SearchAPI, return top 5 results |
| 📄 Web Scraping | `WebScrapingTool` | Use Jsoup to scrape complete HTML of webpage |
| 📁 File Operation | `FileOperationTool` | Read and write local files |
| ⬇️ Resource Download | `ResourceDownloadTool` | Download files from URL to local |
| 💻 Terminal Operation | `TerminalOperationTool` | Execute system commands and return output |
| 📝 PDF Generation | `PDFGenerationTool` | Use iText to generate PDF with Chinese content |
| 🛑 Task Termination | `TerminateTool` | Mark Agent task completion |
## 🔗 MCP Service
The project implements complete support for **Model Context Protocol (MCP)**:
### Built-in MCP Service: Image Search
- **Function**: Search images using Pexels API
- **Transmission Mode**: Support STDIO and SSE modes
- **Independent Deployment**: Can run as an independent MCP service on port 8127
### MCP Configuration (`mcp-servers.json`)
```json
{
"mcpServers": {
"amap-maps": {
"command": "npx",
"args": ["-y", "@amap/amap-maps-mcp-server"]
},
"image-search-mcp-server": {
"command": "java",
"args": ["-jar", "image-search-mcp-server/target/image-search-mcp-server-0.0.1-SNAPSHOT.jar"]
}
}
}
```
## 📚 RAG Knowledge Base
Knowledge base documents are located in `src/main/resources/document/`, including three Chinese knowledge documents on love topics:
- Single: How to recognize the opposite sex, pickup techniques, etc.
- Love: Dating suggestions, conflict resolution, etc.
- Married: Marriage management, family relationships, etc.
### RAG Full-Chain Characteristics
```mermaid
graph LR
A[📄 Markdown Document] -->|MarkdownDocumentReader| B[📝 Document Loading]
B -->|TokenTextSplitter| C[✂️ Document Cutting]
C -->|KeywordMetadataEnricher| D[🏷️ Keyword Enhancement]
D -->|Embedding Model| E[🔢 Vectorization]
E -->|PgVector / Simple| F[💾 Vector Storage]
G[❓ User Question] -->|QueryRewriter| H[🔍 Query Rewriting]
H --> F
F -->|Similarity Retrieval| I[📋 Retrieval Results]
I -->|ContextualQueryAugmenter| J[✨ Context Enhancement]
J --> K[🤖 LLM Generates Answer]
style A fill:#4caf50,color:#fff
style K fill:#ff9800,color:#fff
```
## 🏛️ Design Patterns
### ReAct Agent Pattern
The intelligent agent follows the **Reasoning + Acting** cycle:
1. **Think**: Analyze the current task state and decide if tools are needed
2. **Act**: Execute the tool calls chosen by LLM
3. **Observe**: Feedback tool execution results to LLM
4. Loop until task completion or maximum step limit reached
### Advisor Chain Pattern
AI Love Master uses Spring AI's Advisor chain to implement cross-cutting concerns:
- `MessageChatMemoryAdvisor` → Conversation memory
- `QuestionAnswerAdvisor` → RAG knowledge retrieval
- `MyLoggerAdvisor` → Log interception
### Strategy Pattern
Support multiple vector storage backends (Simple / PgVector / Alibaba Cloud), switch through configuration.
## 🛠️ Development Guide
### Project Build
```bash
# Compile and package
./mvnw clean package -DskipTests
# Run tests
./mvnw test
```
### Local Large Model Deployment (Ollama)
```bash
# Install Ollama and pull the model
ollama pull gemma3:1b
# Configure application-local.yml
# spring.ai.ollama.base-url: http://localhost:11434
# spring.ai.ollama.chat.model: gemma3:1b
```
### Switch Large Model Access Method
The project supports 4 large model access methods (see `src/main/java/com/pi/aiagent/demo/invoke/`):
1. **HTTP Direct Call** — `HttpAiInvoke.java`
2. **SDK Call** — `SdkAiInvoke.java`
3. **Spring AI Call** — `SpringAiAiInvoke.java`
4. **LangChain4j Call** — `LangChainAiInvoke.java`
## 📄 License
MIT License. See [LICENSE](./LICENSE) file.
---
## 🙏 Acknowledgements
- [Spring AI](https://spring.io/projects/spring-ai) — Java AI development framework
- [LangChain4j](https://docs.langchain4j.dev/) — Java LangChain implementation
- [Alibaba Cloud Bailian](https://bailian.console.aliyun.com/) — Large model service platform
- [OpenManus](https://github.com/mannaandpoem/OpenManus) — ReAct Agent reference implementation
MCP Config
Below is the configuration for this MCP Server. You can copy it directly to Cursor or other MCP clients.
mcp.json
Connection Info
You Might Also Like
No recommendations available