How liyupi/yu-ai-agent works
1. Repository shape
- This repo is a small AI platform, not a single app: it contains a Spring Boot backend, a Vue frontend, and a separate MCP image-search service.
- The backend is the orchestration layer; the frontend is just the chat/UI shell; the MCP server is an external tool endpoint the backend/agents can invoke.
2. Backend runtime boundary
- yu-ai-agent is the main Java 21 / Spring Boot 3 service.
- Its top-level responsibilities are exposed through AiController and HealthController, with cross-cutting config in CorsConfig and application settings in application.yml / application-prod.yml.
- YuAiAgentApplication is the backend entrypoint.
3. Two primary product flows in the backend
- The codebase centers on two user-facing capabilities:
- LoveApp: an AI “恋爱大师” conversation assistant.
- YuManus: a ReAct-style autonomous agent that plans and executes tasks.
- These map to separate backend domains under app/ and agent/, but they share the same AI and tool infrastructure.
4. LoveApp architecture: chat + memory + knowledge
- app/LoveApp is the domain orchestration class for the romance assistant.
- Conversation state is handled by chatmemory/FileBasedChatMemory, so memory is persisted outside process memory rather than being purely transient.
- The assistant also has a RAG path under rag/, which loads and prepares the knowledge base from src/main/resources/document/*.md.
5. RAG subsystem boundaries
- LoveAppDocumentLoader, MyTokenTextSplitter, MyKeywordEnricher, and QueryRewriter implement the document ETL / query-enrichment steps.
- LoveAppVectorStoreConfig and PgVectorVectorStoreConfig define the vector-store integration; the project explicitly supports PgVector and cloud-based variants.
- LoveAppContextualQueryAugmenterFactory, LoveAppRagCloudAdvisorConfig, and LoveAppRagCustomAdvisorFactory show that retrieval is wired into the Spring AI advisor pipeline rather than being a separate service.
6. Agent subsystem
- agent/BaseAgent, ReActAgent, ToolCallAgent, and YuManus define a layered agent model.
- agent/model/AgentState is the state container for iterative reasoning/execution.
- This subsystem is the automation engine: it decides when to think, when to call tools, and when to stop.
7. Tooling subsystem
- tools/ contains the callable capabilities exposed to the AI model:
- file operations
- web search
- web scraping
- resource download
- terminal execution
- PDF generation
- termination / control
- ToolRegistration is the central place where those tools are made available to agents/models.
- Architecturally, this is the main “actuation” boundary: the LLM does not directly touch the environment; it invokes these tools through the backend.
8. MCP integration
- The backend has an MCP-oriented setup, and src/main/resources/mcp-servers.json indicates external MCP server configuration.
- The separate yu-image-search-mcp-server module is a standalone Spring Boot service exposing ImageSearchTool.
- It supports both stdio and sse modes via application-stdio.yml and application-sse.yml, so the image-search capability can be embedded or networked depending on deployment.
9. Model/provider abstraction
- The repo is deliberately provider-agnostic at the architecture level.
- The README and demo package show integration patterns for multiple model access modes: Spring AI, LangChain4j, HTTP calls, Ollama, and hosted APIs.
- demo/invoke/* exists as a reference layer for comparing these access methods rather than as core runtime logic.
10. Frontend boundary
- yu-ai-agent-frontend is a separate Vue 3 + Vite application.
- Key views are Home.vue, LoveMaster.vue, and SuperAgent.vue, with a shared ChatRoom.vue component.
- This frontend talks to the backend over HTTP; the presence of SSE in the README suggests some responses are streamed back asynchronously for chat/agent output.
11. End-to-end data flow
- User enters the frontend chat UI.
- Frontend calls backend controllers.
- Backend routes the request into either LoveApp or YuManus.
- LoveApp may consult file-based memory, run RAG retrieval over the knowledge documents/vector store, then call the LLM.
- YuManus may iterate through reasoning steps, invoke tools, and optionally call MCP services.
- Final text or streamed chunks are returned to the frontend.
12. Persistence and data assets
- The main persistent assets visible in the repo are:
- markdown knowledge documents under src/main/resources/document
- file-based chat memory on disk
- vector-store data in PgVector or cloud storage, depending on config
- There is no traditional relational business domain in this repo; persistence is AI-state and knowledge oriented.
13. Deployment packaging
- Each deployable has its own Dockerfile: backend, frontend, and MCP server.
- This suggests a containerized, multi-service deployment where the frontend is served separately from the backend AI service, and the MCP service can be scaled or replaced independently.
14. Testing and validation
- Tests are organized per subsystem: app, agent, RAG, tools, and the MCP server.
- That mirrors the architecture: each major boundary has its own verification layer, which is useful when drawing the system diagram because the repo is modular rather than monolithic.
Main entry points: AiController.java HTTP API · LoveApp.java LoveApp · ReActAgent.java Agent loop · YuAiAgentApplication.java Spring Boot
Components 21
Backend service
Spring Boot AI orchestration runtime
- Spring Boot · Main Java 21 backend entrypoint
src/main/java/com/yupi/yuaiagent/YuAiAgentApplication.java - HTTP API · Chat and health endpoints
src/main/java/com/yupi/yuaiagent/controller/AiController.java - Health API · Service health endpoint
src/main/java/com/yupi/yuaiagent/controller/HealthController.java - Web config · Cross-cutting Spring configuration
src/main/java/com/yupi/yuaiagent/config/CorsConfig.java - LoveApp · Romance conversation assistant orchestration
src/main/java/com/yupi/yuaiagent/app/LoveApp.java - File memory · Persistent conversation memory on disk
src/main/java/com/yupi/yuaiagent/chatmemory/FileBasedChatMemory.java - Doc loader · Loads knowledge documents for retrieval
src/main/java/com/yupi/yuaiagent/rag/LoveAppDocumentLoader.java - Query prep · Splitting, enrichment, and query rewriting
src/main/java/com/yupi/yuaiagent/rag/MyTokenTextSplitter.java - Vector store · PgVector and cloud vector-store integration
src/main/java/com/yupi/yuaiagent/rag/PgVectorVectorStoreConfig.java - RAG advisor · Spring AI retrieval wiring for LoveApp
src/main/java/com/yupi/yuaiagent/rag/LoveAppRagCustomAdvisorFactory.java - YuManus · Autonomous task agent orchestration
src/main/java/com/yupi/yuaiagent/agent/YuManus.java - Agent loop · ReAct and tool-call execution layers
src/main/java/com/yupi/yuaiagent/agent/ReActAgent.java - Agent state · Iterative reasoning and execution state
src/main/java/com/yupi/yuaiagent/agent/model/AgentState.java - Tool registry · Registers callable capabilities for agents
src/main/java/com/yupi/yuaiagent/tools/ToolRegistration.java - Tool suite · File, web, terminal, download, PDF, and control tools
src/main/java/com/yupi/yuaiagent/tools/WebSearchTool.java - Model demos · Provider and API invocation examples
src/main/java/com/yupi/yuaiagent/demo/invoke/SpringAiAiInvoke.java
Frontend app
Vue chat UI shell
- Vue app · Separate Vue 3 + Vite frontend
yu-ai-agent-frontend/src/App.vue - Chat UI · Shared conversational interface
yu-ai-agent-frontend/src/components/ChatRoom.vue - Product views · Home, LoveMaster, and SuperAgent screens
yu-ai-agent-frontend/src/views/LoveMaster.vue
MCP service
Separate image-search tool server
- MCP server · Standalone image-search MCP service
yu-image-search-mcp-server/src/main/java/com/yupi/yuimagesearchmcpserver/YuImageSearchMcpServerApplication.java - Image search · Exposed image-search capability
yu-image-search-mcp-server/src/main/java/com/yupi/yuimagesearchmcpserver/tools/ImageSearchTool.java
Connections 21
- Spring Boot → HTTP API: hosts · Backend exposes AI endpoints through controllers
- Spring Boot → Health API: hosts · Backend exposes health checks
- Spring Boot → Web config: uses · Applies web and CORS configuration
- HTTP API → LoveApp: routes chat · Chat requests enter the LoveApp domain
- HTTP API → YuManus: routes agent · Task requests enter the YuManus agent domain
- LoveApp → File memory: persists state · Conversation memory is stored on disk
- LoveApp → Doc loader: indexes docs · Loads markdown knowledge base
- Doc loader → Query prep: prepares · Documents are split and enriched before retrieval
- Query prep → Vector store: writes vectors · Prepared content is stored in the vector layer
- LoveApp → RAG advisor: retrieves via · RAG is wired through Spring AI advisors
- RAG advisor → Vector store: queries · Retrieval reads from the vector store
- YuManus → Agent loop: drives · YuManus delegates reasoning and execution to the agent loop
- Agent loop → Agent state: updates · Iterative reasoning state is maintained across steps
- Agent loop → Tool registry: invokes · Agent loop requests capabilities through registry
- Tool registry → Tool suite: exposes · Tools are made available to models and agents
- Agent loop → MCP server: calls external MCP · Agent can reach the separate MCP tool service
- HTTP API → Vue app: served to · Frontend sends requests to backend HTTP endpoints
- Vue app → Chat UI: contains · Shared chat shell component
- Vue app → Product views: contains · Product-specific views for the two assistant modes
- MCP server → Image search: hosts · Standalone service exposes image search tool
- Model demos → Spring Boot: references · Provider access patterns are shown as examples