Build a Multi‑Agent Boba Tea Shop with AgentScope Java: A Hands‑On Guide

This article introduces AgentScope Java 1.0.7, showcases its new features such as Ollama integration, Agent Skill support, and Nacos‑based A2A architecture, and walks through a complete boba‑tea‑shop example that demonstrates a Supervisor‑Worker multi‑agent system, ReActAgent configuration, dynamic MCP registration, MySQL session persistence, Mem0 long‑term memory, and AutoContextMemory compression, plus quick deployment options for local, Kubernetes, and Docker environments.

Alibaba Cloud Native
Alibaba Cloud Native
Alibaba Cloud Native
Build a Multi‑Agent Boba Tea Shop with AgentScope Java: A Hands‑On Guide

Overview

AgentScope is an open‑source Java framework for production‑grade agent development. Version 1.0.7 adds comprehensive Ollama integration (chat and embedding), Agent Skill support, built‑in file and multimodal tools, human‑in‑the‑loop (HITL), automatic context compression, HTTP request/response compression, MySQL session storage, and Nacos‑based A2A architecture.

Boba‑Tea‑Shop Demo

The demo showcases four core capabilities:

Milk‑Tea Recommendation : RAG‑based knowledge retrieval combined with user‑preference analysis.

Smart Ordering : Natural‑language order creation without forms.

Order Query & Feedback : Unified handling of queries, complaints, and suggestions.

Preference Memory : Integration with Mem0 long‑term memory to retain user likes across sessions.

Architecture

AgentScope follows a Supervisor‑Worker pattern:

Supervisor Agent : Interprets user intent and dispatches tasks to sub‑agents.

Business Sub Agent : Handles order creation, queries, modifications, and complaints.

Consult Sub Agent : Provides product recommendations via a RAG knowledge base.

Supporting components include an MCP server for business logic, Nacos for dynamic agent registration and discovery, and a persistence layer for knowledge bases, sessions, and memory.

Key Implementations

ReActAgent Construction

DashScopeChatModel model = DashScopeChatModel.builder()
    .apiKey(dashscopeApiKey)
    .modelName(dashscopeModelName)
    .formatter(new DashScopeChatFormatter())
    .build();

ReActAgent agent = ReActAgent.builder()
    .name("supervisor_agent")
    .sysPrompt(sysPrompt)
    .toolkit(toolkit)          // mount tools
    .model(model)              // LLM
    .memory(memory)            // short‑term memory
    .longTermMemory(longTermMemory) // long‑term memory
    .build();

AgentScope abstracts model adapters, reasoning‑acting loops, and tool registration for providers such as DashScope, Anthropic, Gemini, and OpenAI.

Nacos A2A Integration

@Bean
public AiService nacosA2aService() throws NacosException {
    Properties p = new Properties();
    p.put(PropertyKeyConst.SERVER_ADDR, serverAddress);
    p.put(PropertyKeyConst.NAMESPACE, namespace);
    return AiFactory.createAiService(p);
}

@Bean
public A2aAgent consultAgent(AiService a2aService) {
    return A2aAgent.builder()
        .name("consult_agent")
        .agentCardResolver(new NacosAgentCardResolver(a2aService))
        .build();
}

Sub‑agents are registered as tools and can be invoked like ordinary utilities.

MCP Dynamic Registration

Toolkit toolkit = new NacosToolkit();
NacosMcpServerManager serverMgr = new NacosMcpServerManager(aiService);
NacosMcpClientWrapper client = NacosMcpClientBuilder.create("business-mcp-server", serverMgr).build();
toolkit.registerMcpClient(client).block();

Replaces static endpoint registration with Nacos‑driven discovery for high‑availability remote tool calls.

MySQL Session Persistence

MysqlSession mysqlSession = new MysqlSession(dataSource,
    System.getenv("DB_NAME"), null, true);
ReActAgent agent = createAgent(toolkit, memory);
agent.loadIfExists(mysqlSession, sessionId);

Ensures conversation state survives restarts or multi‑instance deployments.

Mem0 Long‑Term Memory

Mem0LongTermMemory longTermMemory = Mem0LongTermMemory.builder()
    .agentName("BusinessAgent")
    .userId(userId)
    .apiBaseUrl("https://api.mem0.ai")
    .apiKey(System.getenv("MEM0_API_KEY"))
    .build();

AutoContextMemory (Context Compression)

AutoContextConfig cfg = AutoContextConfig.builder()
    .tokenRatio(0.4)
    .lastKeep(10)
    .build();
AutoContextMemory memory = new AutoContextMemory(cfg, model);

Automatically compresses, unloads, and summarizes dialogue history to balance cost and information retention.

Quick‑Start Deployment

Local Development

# Configure environment variables
cp local-env.example local-env.sh
vim local-env.sh
# Start
source local-env.sh && ./local-deploy.sh start

Kubernetes (Production)

# Edit values.yaml
vim values.yaml
# Deploy with Helm
helm install agentscope helm/ --namespace agentscope

Docker (Minimal)

# Prepare .env
cp docker-env.example .env
# Run container
docker-compose up -d

Resources

Project repository: https://github.com/agentscope-ai/agentscope-java Boba‑tea‑shop example:

https://github.com/agentscope-ai/agentscope-java/tree/main/agentscope-examples/boba-tea-shop
JavaNacosMySQLMulti-agentAgentScopeReactAgentAutoContextMemoryMem0
Alibaba Cloud Native
Written by

Alibaba Cloud Native

We publish cloud-native tech news, curate in-depth content, host regular events and live streams, and share Alibaba product and user case studies. Join us to explore and share the cloud-native insights you need.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.