系列第 16 篇 · 实战篇
前 15 篇把 Agent 的单点能力逐个拆开讲解:从跑通第一个 Agent、工具调用、结构化输出,到 PlanMode、记忆与 RAG,再到多 Agent、MCP、A2A,最后是 HarnessAgent、Workspace、Context 与权限容错可观测。但"零件齐全"不等于"装好能跑"——本篇要把它们串成一台真正的生产 Agent。
笔者从事软件行业多年,见过太多企业信息化建设的"拼凑"过程,拿传统零售商来说,ERP、CRM、WMS、电商中台由不同供应商拼装而成,数据模型和接口各说各话,要把它们打通、协同起来格外费劲。而这,恰恰是 Agent 最值得落地去解决的一类场景。
先介绍本文相关的两个真实零售场景,后续的实战将围绕这两个场景展开:
- 场景一 · 52 周 MD 周计划(以"周"为尺度的经营规划):店长一句话提出下一季度MD 诉求,Agent 以历史销量(同周同期、近周趋势)为实证基础,结合顾客生活节奏/季节/节气/节日/场景(辅以天气、客群、竞品情报),选出重点商品、产出周经营建议,并直接落实促销、生成文案、圈选会员。
- 场景二 · 智慧出清(以"日"为尺度的经营执行):每天傍晚闭店前的几个小时,是生鲜出清的主战场,Agent 需要按当晚天气、当日实时销售,并对照该品类历史销量(同天气/同时段去化基线),动态定出清折扣力度与最佳出清时段,落价前走人工确认。
一、项目背景与两个场景
1.1 零售信息化的"拼凑"现状
前面说的"拼凑",带来的不是某个单点问题,而是系统间天然异构、割裂:数据模型不一、接口协议各异、口径各说各话。门店想要"基于全局经营数据做一件小事"(比如选本周重点商品、定今晚出清折扣),都要先跨好几套系统取数、对齐、再判断。这件事人工做费时且靠经验,正好是 Agent + MCP 统一接入 + Harness 稳定编排最能发挥价值的地方。
1.2 场景一:52 周 MD 周计划
52 周 MD是生鲜超市以"年"为完整时间跨度的经营活动管理方法:把 1 年 52 周作为完整时间轴,根据顾客生活节奏、季节、节气、节日、场景,以周为单位推进执行,提前规划每周主推商品、陈列、促销、卖场主题,周周打造销售小高潮;采购‑营运‑营销‑门店全部门协同落地,并且每周复盘迭代优化。在这条时间轴上,重点商品的选择同样以时间为节点,结合顾客生活节奏、季节、节气、节日、场景等因素,选出既贴合消费者当下需求、又满足企业经营目标的商品,再据此安排一周的陈列、促销与营销。
一份 52 周 MD 周计划长这样:
本周(2026-W34,8 月第三周)52 周 MD
主轴:立秋末伏 · 开学前备货
历史销量参考:莲藕近 4 周周销 120kg、绿豆 90kg;去年同期(2025-W34)莲藕 +18%、绿豆 +12%——需求稳中有升
重点商品:
1. 应季鲜食:凉拌藕带、冰镇绿豆沙原料(莲藕 / 绿豆)—— 契合”立秋吃藕”习俗 + 高温消暑
2. 开学季组合:半成品早餐(馒头 / 包点)+ 学生奶 —— 临近开学,社区家庭客群
3. 社区中老年:低糖杂粮、时令梨(润燥)—— 客群画像驱动
经营建议:
- 陈列:入口端架做”开学早餐 + 消暑”主题堆头
- 促销:莲藕 / 绿豆组合 8.8 折,学生奶第二件半价
- 社群:周三推”立秋养生”文案,圈选 25–45 岁家庭会员
1.3 场景二:智慧出清
生鲜保质期短,闭店前几小时把卖不动的货出清掉,是每家超市每天的"硬仗"。难点在于:折扣定深了亏毛利,定浅了卖不完报损;时段定早了扰乱正价,定晚了来不及。智慧出清的做法是——每天傍晚闭店前数小时,依据当晚天气(影响客流)、当日实时销售(剩余库存与动销率),并对照该品类历史销量(同天气 / 同时段的常规去化水平)设定合理去化基线,动态算出出清折扣力度与最佳出清时间段,落价前交店长确认。
一份出清方案长这样:
闭店前 3 小时出清方案(当日 19:00 触发)
天气:阵雨转凉,晚高峰客流回落
实时动销:叶菜售出率 62%(剩 38kg)、鲜奶售出率 55%(剩 120 盒)
历史参考:叶菜近 7 日同天气傍晚 21:00 前平均去化 78%,今晚 21:00 前预计仅能去化 55% → 需加深折扣
建议:
- 叶菜:20:30 起 7 折,21:00(闭店前 1h)起 5 折清完
- 鲜奶:20:00 起第二件 1 元,21:00 起 6 折
预估:较店长经验出清,动销去化 +12%,报损 -15%
1.4 两个场景的关系
| 维度 | 场景一 · 52 周 MD(周) | 场景二 · 智慧出清(日) | | --- | --- | --- | | 经营尺度 | 周计划,事前规划 | 日执行,事中应变 | | 触发方式 | 主动提出 / 按周定时 | 每天傍晚定时 | | 核心输入 | 历史销量 / 行事历 / 节气 / 天气 / 客群 / 竞品 | 当晚天气 / 历史销量(同天气同时段基线) / 当日实时销售 / 闭店倒计时 | | 核心产出 | 重点商品 + 经营建议 + 促销 / 文案 / 圈选 | 出清折扣力度 + 出清时段 + 降价 | | 是否写操作 | 是(创建促销 / 发券) | 是(执行降价) | | 都需要 | 意图识别、MCP 取数、权限确认、可观测 | 意图识别、MCP 取数、权限确认、可观测 |
二、遗留问题与解决思路
|
遗留疑难问题
|
根因
|
AgentScope 解法(由 Harness 统一编排)
|
| --- | --- | --- |
|
重点商品选品靠经验、常脱节时令
|
选品凭经验,难系统结合节气 / 天气 / 客群 / 竞品
|
MCP 取行事历 / 节气 / 天气 / 会员 / 竞品情报,Agent 生成 52 周 MD 周计划
|
|
促销活动效果难评估
|
多系统数据割裂,口径不一
|
MCP 统一取数,结构化输出算 ROI,LLM 生成归因报告
|
|
会员触达不精准
|
标签分散、画像陈旧
|
Agent 检索长期记忆 + 生成个性化文案并圈选人群
|
|
营销内容产出慢、落地难
|
文案 / 促销方案靠人工,跨系统创建费时
|
多 Agent 生成文案与方案,执行专员经 HITL 创建促销、发放优惠券
|
|
生鲜出清靠拍脑袋、闭店前手忙脚乱
|
折扣与时段凭经验,不看实时天气与销售
|
MCP 取天气 + 当日实时销售,Agent 动态定出清折扣与时段,落价前走 HITL 确认
|
|
数据权限混乱
|
各系统自建权限,越权风险
| PermissionEngine
四态 + 自定义 Middleware 工具级拦截
|
|
运营数据口径不一致
|
指标定义分散
|
口径沉淀为统一 @Tool 指标 API,Agent 只调用、不重算
|
三、总体架构设计
3.1 分层架构
采用分层 + 模块化架构:接入层把请求交给 HarnessAgent 做应用编排,MCP 作为基础设施集成协议。
┌─────────────────────────────────────────────────────────────┐
│ 接入层 / Interface │
│ REST API | WebSocket
└───────────────────────────┬─────────────────────────────────┘
│
┌───────────────────────────▼─────────────────────────────────┐
│ 应用编排层 / Application(HarnessAgent 运行层) │
│ HarnessAgent(编排总控) │
│ ├─ SubagentDeclaration:意图/选品规划/营销执行/出清专/权限 │
│ ├─ Toolkit:@Tool 业务工具 + 注册自零售 MCP Server 的工具 │
│ ├─ Middleware:权限拦截(RBAC/ABAC)+ OtelTracing 观测 │
│ └─ Plan Mode / Memory / Workspace / Sandbox │
└───────────────────────────┬─────────────────────────────────┘
│
┌───────────────────────────▼─────────────────────────────────┐
│ 业务服务层 / Service(@Tool 工具实现体,被 AgentScope 编排调用 │
│ 选品 / 营销 / 会员 等业务服务实现(经由 @Tool 暴露) │
└───────────────────────────┬─────────────────────────────────┘
│
┌───────────────────────────▼─────────────────────────────────┐
│ 基础设施层 / Infrastructure │
│ AgentScope-Java 2.0 Runtime | MCP Client/Server │
│ OpenTelemetry | Micrometer | Redis | DB │
│ Legacy ERP/WMS/POS/CRM 适配器 │
└─────────────────────────────────────────────────────────────┘
3.2 AgentScope-Java 2.0 提供了哪些支撑
- Agent 运行时:HarnessAgent 作为编排总控,内部用无状态的 ReActAgent 跑推理循环;多 Agent 用 SubagentDeclaration 声明式编排。
- LLM 接入:字符串模型 + ModelRegistry,如 "dashscope:qwen-max",自动读环境变量里的 Key。
- 工具抽象:@Tool + Toolkit 注册业务工具;结构化输出用 agent.call(msgs, Class, ctx)。
- MCP 支持:作为 MCP Client 调用外部 MCP Server(McpClientBuilder / workspace/tools.json);也可把内部能力暴露为 MCP Server。
- 可观测扩展点:Middleware 通道(5 个钩子:onAgent/onReasoning/onActing/onModelCall/onSystemPrompt)与内置 OtelTracingMiddleware,外加 streamEvents() 的 28 种类型化事件流。
- 与业务系统集成:自定义 @Tool、自定义 Middleware、自定义 Memory 都通过标准扩展点接入,确定性业务逻辑留在工具实现里。
3.3 编排总控:把多智能体、工具、中间件拼起来
使用HarnessAgent.builder() 把子 Agent、工具集(含 MCP)、中间件一次性挂上去,推理循环、多 Agent 调度、权限与观测全由框架接管。先声明五个专员(subAgent):
import io.agentscope.harness.HarnessAgent;
import io.agentscope.harness.agent.subagent.SubagentDeclaration;
// 意图专员:拿到结构化意图,决定走哪条业务线
SubagentDeclaration intentAgent = SubagentDeclaration.builder()
.name(”intent_agent”)
.description(”意图专员:把用户问句识别为 md_plan(规划)/ md_execute(落实)/ clearance(出清)/ query(问询)之一并抽取槽位”)
.inlineAgentsBody(”你是意图专员,只输出结构化意图与槽位,不展开业务计算。”)
.build();
// 选品规划专员:把复合 MD 诉求拆成有序步骤(如 选品规划 → 营销方案 → 落实执行)
SubagentDeclaration mdPlannerAgent = SubagentDeclaration.builder()
.name(”md_planner_agent”)
.description(”选品规划专员:以历史销量(同周同期、近周趋势)为实证基础,结合顾客生活节奏/季节/节气/节日/场景(辅以天气、客群、竞品情报),选出本周重点商品并产出 52 周 MD 周计划”)
.inlineAgentsBody(”你是选品规划专员,先取历史销量做需求基线(同周同期、近周趋势),再结合顾客生活节奏/季节/节气/节日/场景选重点商品,给出一周经营建议。”)
.build();
// 营销执行专员:持有 MCP + @Tool 工具集,生成文案并落地执行
SubagentDeclaration marketingAgent = SubagentDeclaration.builder()
.name(”marketing_agent”)
.description(”营销执行专员:调用 weather/calendar/member/competitor/promotion 等 MCP 工具,生成营销文案并创建促销、发放优惠券”)
.inlineAgentsBody(”你是营销执行专员,严格按步骤调用工具生成文案、创建促销与发券,不臆造数据。”)
.build();
// 出清专员:每天傍晚按天气与当日实时销售,动态定出生鲜出清折扣力度与最佳出清时间段
SubagentDeclaration clearanceAgent = SubagentDeclaration.builder()
.name(”clearance_agent”)
.description(”出清专员:调取 weather.query 与当日实时销售,对照该品类历史销量(同天气/同时段去化基线),结合闭店倒计时,给出生鲜出清折扣与最佳出清时段建议”)
.inlineAgentsBody(”你是出清专员,根据天气、实时动销、历史销量基线(同天气/同时段)与闭店剩余时间,给出折扣力度与出清时机,不臆造数据。”)
.build();
// 权限专员:调用前做 RBAC/ABAC 校验,高危操作发起 HITL 确认
SubagentDeclaration guardAgent = SubagentDeclaration.builder()
.name(”guard_agent”)
.description(”权限专员:对工具调用做权限与数据范围校验,越权或高危时要求人工确认”)
.inlineAgentsBody(”你是权限专员,任何调用前先校验角色与数据范围。”)
.build();
五个专员声明好后,用总控 Agent 把它们和工具集、中间件搭建好整个经营助手的完整骨架:
import io.agentscope.harness.HarnessAgent;
import io.agentscope.core.tool.Toolkit;
import io.agentscope.core.middleware.MiddlewareBase;
import io.agentscope.core.tracing.OtelTracingMiddleware;
import io.agentscope.core.memory.MemoryConfig;
import io.agentscope.core.context.CompactionConfig;
import io.agentscope.core.context.ToolResultEvictionConfig;
import java.nio.file.Path;
import java.util.List;
HarnessAgent assistant = HarnessAgent.builder()
.name(”store-ops-assistant”) // 总控(主编)
.model(”dashscope:qwen-max”)
.workspace(Path.of(”./store-ops-workspace”))
.sysPrompt(”””
你是门店经营智能助手的 52 周 MD 总控。流程:
1. agent_spawn intent_agent 识别意图(规划 or 落实 or 出清)与槽位;
2. agent_spawn md_planner_agent 先取历史销量做实证基线(同周同期、近周趋势),再结合顾客生活节奏/季节/节气/节日/场景(辅以天气、客群、竞品情报),选重点商品并出周计划;
3. agent_spawn marketing_agent 生成营销文案与促销方案,并调用工具落地;
4. 创建促销/发券等高危操作交给 guard_agent 校验,必要时发起人工确认;
5. 每天傍晚闭店前数小时,agent_spawn clearance_agent 按天气与实时销售动态定出清折扣与时段,落价前交 guard_agent 校验;
6. 汇总 52 周 MD 周计划与出清执行结果,输出可观测链路。
”””)
.subagent(intentAgent).subagent(mdPlannerAgent) // 多智能体声明式编排
.subagent(marketingAgent).subagent(clearanceAgent)
.subagent(guardAgent)
.toolkit(toolkit) // 已注册 MCP 工具 + @Tool 业务工具
.middlewares(List.of(
new PermissionMiddleware(rbacService), // 权限拦截
new OtelTracingMiddleware())) // 可观测
.memory(MemoryConfig.builder().build()) // 长期记忆
.compaction(CompactionConfig.builder()
.triggerMessages(30).keepMessages(10)
.truncateArgs(CompactionConfig.TruncateArgsConfig.builder()
.maxArgLength(2000).build()).build()) // 上下文工程
.toolResultEviction(ToolResultEvictionConfig.defaults()) // 大结果卸载
.build();
四、代码细化:两个场景的落地实现
第三章(3.3)已经把 HarnessAgent 总控、五个子 Agent 和 MCP 通路搭好,本章 4.4 给出 Harness 的装配代码,第五章再用运行时视角讲清一次请求在 Harness 里怎么流转。这一节不再罗列"能力有哪些",而是把两个场景真正写进代码:4.1、4.2 分别是 52 周 MD 与智慧出清的业务落地,4.3 是两个场景共用的能力模块(意图 / MCP / 权限 / 可观测 / 记忆)代码。读这段代码,你看到的就是门店助手每天在跑的东西——"为什么这么做"都写在注释里。
4.1 场景一:52 周 MD 周计划代码落地
一句话提出下季度 MD 诉求,Agent 要:识别意图 → 取历史销量做实证基线 → 结合节气 / 天气 / 客群 / 竞品选品 → 出周计划 → 落地促销与发券(人工确认)。业务落地代码如下:
// 场景一入口:店长提交 52 周 MD 周计划诉求
public Mono planWeeklyMd(String utterance, SessionContext ctx) {
// ① 意图识别(三层漏斗 + 结构化输出,见 4.3):把自然语言变成强类型意图,不让 LLM 自由发挥
IntentResult intent = intentAgent.call(
List.of(new UserMessage(”user”, utterance)),
IntentResult.class,
RuntimeContext.builder().sessionId(ctx.sid).userId(ctx.uid).build())
.block().getStructuredData(IntentResult.class);
// 预期 intent = { intent:”md_plan”, slots:{ week:”2026-W34”, season:”立秋”,
// weather:”高温”, segment:”社区中老年”, event:”开学季” } }
// ② 选品规划:交给 md_planner_agent,它在 4.3 注册好的 MCP 通路上取数
// —— 以「历史销量」为实证基线,不让模型凭空编选品;权限/数据范围由 PermissionMiddleware 在 onActing 拦截(见 4.3)
return mdPlannerAgent.call(
List.of(new UserMessage(”user”,
”为 ” + intent.slots.get(”week”) + ” 做 52 周 MD:” +
”先 sales.history 取同周同期+近周趋势,再 calendar.solar_terms 取节气、” +
”weather.query 取天气、member.segment 取客群、competitor.intel 取竞品,” +
”最后 md.weekly_plan 出周计划”)),
MdPlanReply.class,
RuntimeContext.builder().sessionId(ctx.sid).userId(ctx.uid).build())
.flatMap(reply -> {
MdPlanReply r = reply.getStructuredData(MdPlanReply.class);
// ③ 落地执行:营销执行专员创建促销 + 发券,属于高危写操作
// tools.json 已把 promotion.create / coupon.issue 标 ASK,框架调用前暂停并抛
// REQUIRE_USER_CONFIRM,前端用 getReplyId() 回传批准(见 4.3 权限 / 可观测)
marketingAgent.call(List.of(new UserMessage(”user”,
”基于周计划创建促销、生成社群文案、圈选会员:” + r.toBrief())),
Void.class, RuntimeContext.builder()
.sessionId(ctx.sid).userId(ctx.uid).build()).block();
// ④ 可观测:整条链路用 streamEvents 把工具调用/人工审批/文本增量实时流出(见 4.3)
return Mono.just(r);
});
}
选品工具本身用 @Tool 暴露,历史销量作为输入:
public class MdPlanningTools {
private final MdPlanningService mdService;
public MdPlanningTools(MdPlanningService svc) { this.mdService = svc; }
@Tool(name = ”md_weekly_plan”,
description = ”以历史销量(同周同期、近周趋势)为实证基础,结合时间节点(顾客生活节奏/季节/节气/节日/场景),为指定周生成 52 周 MD 重点商品与经营建议”)
public MdWeeklyPlanResult weeklyPlan(
@ToolParam(name = ”week”, description = ”ISO 周,如 '2026-W34'”) String week,
// 历史销量:指定周近 N 周销量与去年同期,用于实证选品与需求基线 —— 这是 52 周 MD 的”地基”
@ToolParam(name = ”historySales”, description = ”历史销量:同周同期/近周趋势,用于实证选品与需求基线”) String historySales,
@ToolParam(name = ”context”, description = ”上下文摘要:顾客生活节奏/季节/节气/节日/场景”) String context) {
return mdService.plan(new MdPlanCommand(week, historySales, context));
}
}
场"确定性"来自两点:选品有 sales.history 实证、落价有REQUIRE_USER_CONFIRM 把关。
4.2 场景二:智慧出清代码落地
每天傍晚闭店前的出清是"定时触发 + 实时应变":到点由调度器拉起,按当晚天气、当日实时销售,并对照该品类历史销量(同天气 / 同时段去化基线)动态定折扣与时段,落价前交店长确认。
// 场景二入口:调度器在闭店前 3 小时触发(cron / 调度框架),sessionId 固定便于崩溃恢复(见 4.3 记忆)
public Mono runClearance(SessionContext ctx) {
// ① 意图识别为 clearance(复用 4.3 同款三层漏斗),这里直接进入出清专员
return clearanceAgent.call(
List.of(new UserMessage(”user”,
”执行今晚出清:weather.query 取当晚天气,sales.history 取该品类同天气/同时段去化基线,” +
”sales.realtime 取当日实时动销,结合闭店倒计时算 出清折扣力度 与 最佳出清时段”)),
ClearanceReply.class,
RuntimeContext.builder()
.sessionId(”clearance-daily”) // 固定 sessionId:日清任务各自可恢复(保障三,见 4.3)
.userId(ctx.uid).build())
.flatMap(reply -> {
ClearanceReply r = reply.getStructuredData(ClearanceReply.class);
// ② 落价执行:clearance.apply 是高危写操作,tools.json 标 ASK,框架抛 REQUIRE_USER_CONFIRM,
// 等待店长在终端/App 确认(见 4.3 权限);折扣过深(< 6 折)时 PermissionMiddleware 还会要求区域经理审批
clearanceAgent.call(List.of(new UserMessage(”user”,
”按建议执行落价:” + r.toBrief())),
Void.class, RuntimeContext.builder()
.sessionId(”clearance-daily”).userId(ctx.uid).build()).block();
// ③ 可观测:出清全程 streamEvents 流出,落 AgentStateStore 可恢复(见 4.3)
return Mono.just(r);
});
}
出清的落价与建议同样用 @Tool 暴露,核心是"历史基线 + 实时动销 + 闭店倒计时"三者的差值决策:
public class ClearanceTools {
private final ClearanceService clearanceService;
public ClearanceTools(ClearanceService svc) { this.clearanceService = svc; }
@Tool(name = ”clearance_suggest”,
description = ”结合当晚天气、当日实时动销与历史销量(同天气/同时段去化基线)、闭店倒计时,给出生鲜出清折扣力度与最佳出清时段”)
public ClearanceSuggestion suggest(
@ToolParam(name
本文由 AI图鉴自动抓取并翻译,版权归原作者所有;如需查看原文请点下方链接。
Series No. 16
The first 15 articles opened up the single-point capability of Agent: from running through the first Agent, tool call, structured output, to PlanMode, Memory and RAG, to more Agent, MCP, A2A, and finally HarnessAgent, Worldspace, Context and permission. But "parts full" is not the same as "get ready to run" -- this article's about to string them into a real production, Agent.
The author has been in the software industry for many years and has seen too many enterprise information-building "composed" processes. For traditional retailers, ERPs, CRMs, WMSs, and electronics mediums are assembled by different suppliers. Data models and interfaces speak differently. And this is exactly the kind of scene that Agent's most deserving of settling down.
The following two real retail scenes are to be described:
- Scenario I 52 MD Week Plan (business planning at the scale of "weeks"): In a statement by the manager of the store, Agent, based on historical sales (during the same week, trends in recent weeks) as evidence, selects key commodities, output week business proposals, and directly implements sales promotions, case creations, and round-table members.
- Scene two: A few hours a day before the close of the shop was the main battleground for fresh fresh air, and Agent needed to sell it in real time on the same night, on the same day, and to dynamically set the level of discounts against the historical sales of the product (delineating the baseline against the weather/same period) and the best clear time to go ahead.
Project background and two scenarios
1.1 The status of "composed" retailization
The "complex" that was said earlier did not lead to a single problem, but rather to a natural isomer between the systems, a fragmentation: different data models, differing interface protocols, and varying calibres. The door shop wants to "do a small thing based on global business data" (e.g. select a key product this week, set a discount tonight) by going through several systems, aligning and then judging. This is a time-consuming and experienced event that is the most valuable place for Agent + MCP integrated access + Harness stabilization.
1.2 scene I: 52 weeks MD week plan
Week MD is the method of managing business activities with a "year" full time span: one year, 52 weeks as a whole, implemented according to the pace of customer life, season, gas, festivals, scenes, week by week, advance planning of weekly promotions, displays, promotions, marketing themes and weekly sales orgasms; procurement and operations, marketing and marketing, sector-wide co-location and optimization of weekly overlaps. On this timeline, the choice of key commodities is also time-oriented, combining the pace of customer life, seasons, gas, festivals, scenes, etc., to select commodities that match the immediate needs of consumers while meeting the business objectives, and to arrange for one week of presentation, promotion and marketing.
A 52-week MD week planr:
This week (2026-W34, third week of August) 52 weeks MD
Main axis: Autumn Volts
Historical sales reference: Lotus close to 4 weekly 120 kg, green beans 90kg; Lotus + 18%, green beans + 12% — steady demand litres
Priority commodities:
Seasonal fresh food: cold bands, ice-cooling green bean sands (Lynn / Green Beans) - Convergence of the "Step-Eat-Est" convention + high temperature cooling
Opening season combinations: semi-finished breakfast (baskets/ wrapping points) + student milk - near the start of school, community family guests
Old age in the community: low sugar, time (dry) - crowd-driven
Business proposal:
- Presentation: the entrance frame makes the "open breakfast + cool" theme pile
- Promotion: Lotus / Green Bean 8.8 discount, student milk second half price
- Community: Wednesday to push the "Step-Autumn" book, round-up for 25-45-year-old family members
1.3 Scene II: Clear wisdom
It's a "hard war" every day at every supermarket. The difficulty is that the discount is so deep that it is too low to pay for the sale; the time is too early to disrupt the price. Wisdom is done - several hours before the close of the shop every evening, depending on the day's weather (influences on the flow of customers), real-time sales on the day (residual stock and turnover rates), and a reasonable demolitions baseline against the historical sales of the product (the normal de-escalation level of the weather/semination period), dynamically calculating the level of the discount and the optimal time frame, and confirming the price before the deposit.
One clean-up project is as follows:
3-hour clean-up programme before closing
Organisation
Real-time sales: Sale rate of leaves and vegetables 62% (remaining 38kg) and milk 55% (remaining 120 boxes)
Historical reference: Leaf and Yee are close to 7 p.m. Average evaporate 78 per cent by 2100, and only 55 per cent by 2100 is expected to be evaporated by tonight.
Recommendations:
- Leaf: 2030, 7 discounts, 21:00 (1h before closing) 5 discounts
- Milk: 20:00, second item 1 yuan, 21:00 6 discounts
Estimated: +12%, loss -15%
1.4 Relationship between the two scenarios
Q Q Q Q Q Q Q Q Q Q Q Q Q Q Q Q Q Q Q Q Q Q Q Q Q Q Q | | | | Q | | Q Q Q Q Q Q Q Q Q, + Q Q Q Z Z, + Q Q Q Q, Q Q Q Q, Q Q Q Q, Q Q Q Q, + Q Q, + Q Q Q, Q Q Q Q Q, Q Q Q Q Q Q Q, Q Q Q Q Q Q, Q Q Q Q Q Q, Q Q Q Q Q Q Q Q Q, Q Q Q Q Q Q Q Q Q
II. Legacy and solutions
|
Problems
|
Gene.
|
AgentScope solution (organized by Harness)
|
| --- | --- | --- |
|
The selection of key commodities is based on experience and frequent disconnections
|
The selection is based on experience, and it is difficult to combine the system with the gas/ weather/ guest/ competition
|
MCP for calendar / air / weather / membership / competition intelligence, Agent generates 52 weeks MD week plan
|
|
Hard to assess the impact of promotional activities
|
Multisystem data split, different calibres.
|
MCP Unified takedown, structured output counts ROI, LLM generation attribution report
|
|
The members are impeccable.
|
The labels are scattered, the paintings are old.
|
Agent Retrieve long-term memory + Generate personalization and circle crowds
|
|
Slow and difficult marketing content
|
Documentation / Promotion Programme manual, cross-system creation costs Time
|
MultiAgent Generates Files and Programs, Executive Commissioner creates promotions and issues coupons through HITL
|
|
It's fresh and clean, and I'm busy before I close my shop. Chaos.
|
Discounts and time periods are empirical, not real-time weather and sales
|
MCP takes the weather + sells in real time on the day, Agent dynamic sets the discounts and the time period, and leaves the price before the HITL confirms
|
|
Data permission chaos.
|
Systems built on permission, ultra vires risk
| PermissionEngine
Four + Custom Middleware Tool Level Interception
|
|
Inconsistent operational data calibres
|
Decentralized definition of indicators
|
Validation is uniform
|
III. Overarching architecture design
3.1 Layer structure
Implementation of a layered + modular structure: the access layer submits requests to HarnessAgent for application organization, MCP as an infrastructure integration protocol.
┌─────────────────────────────────────────────────────────────┐
│ Access Layer / Interface
│ REST API | WebSocket
└───────────────────────────┬─────────────────────────────────┘
│
┌───────────────────────────▼─────────────────────────────────┐
│Application
│ HarnessAgent
│ SubcontentDeclaration: Intent/selection/marketing execution/output/permission
│Toolkit: @Tool Business Tool + Tool registered for retail MCP Server
│ - Middleware: permission Interception (RBAC/ABAC) + OtelTracking Observation
│ └─ Plan Mode / Memory / Workspace / Sandbox │
└───────────────────────────┬─────────────────────────────────┘
│
┌───────────────────────────▼─────────────────────────────────┐
• Business Service / Service (@Tool tool realization, called by AgentScope
│ Business services such as selection/ marketing/ membership (exposed by @Tool) │
└───────────────────────────┬─────────────────────────────────┘
│
┌───────────────────────────▼─────────────────────────────────┐
Infrastructure / Infrastructure
│ AgentScope-Java 2.0 Runtime | MCP Client/Server │
│ OpenTelemetry | Micrometer | Redis | DB │
│ Legacy ERP/WMS/POS/CRM adapter │
└─────────────────────────────────────────────────────────────┘
3.2 Support provided by AgentScope-Java 2.0
-Agent Runs: HarnessAgent as the master planner, inside runs a non-state RectAgent logic loop; more Agent is organized in SubagentDeclaration.
- LLM access: String model + ModelRegistry, such as "dashscope:qwen-max", automatically reads Key from the environment variable.
- An abstract tool: @Tool +Toolkit Register Business Tool; structured output with anent.call (msgs, Class, ctx).
- MCP Support: External MCP Server (McpClintBuilder / workspace/tools.json) as MCP Clinic; also internal capabilities can be exposed to MCP Server.
- Observable extension points: Middleware Channel (5 hooks:onAgent/onReasoning/onActing/onModelCall/onSystemPrompt) and the built-in OtelTracking Middleware, plus 28 types of event streams of streadEvents().
- Integration with business systems: Custom @Tool, Custom Middleware, Custom Memoory is accessed through standard extension points and definitive business logic remains in the tool.
3.3 Master Planner: Combining multi-AI agent, tools, intermediates
Use HarnessAgent.builder() to hang the sub-Agent, the tool set (including MCP), the intermediate one-off, and the reasoning cycle, multiple Agent movements, permission and observations are taken over by the framework. First, five commissioners (subAgent):
import io.agentscope.harness.HarnessAgent;
import io.agentscope.harness.agent.subagent.SubagentDeclaration;
/ Intent Commissioner: get a structured intent to decide which business to take. Line
SubagentDeclaration intentAgent = SubagentDeclaration.builder()
.name(”intent_agent”)
.description("intentional Commissioner: identify user query as one of the md plan(planning)/md execute(implementation)/clarity/Qurey(inquiries) and extract slots") I'm not sure.
.inlineAgentsBody” (“You are the Commissioner of the Commission, you are only exporting structured intentions and slots and do not conduct business calculations.” I'm not sure.
.build();
/ Selection Planning Commissioner: Dismantling complex MD claims into orderly steps (e.g. selection planning marketing programme implementation)
SubagentDeclaration mdPlannerAgent = SubagentDeclaration.builder()
.name(”md_planner_agent”)
.description ("Elective Planning Commissioner" : selection of key commodities and output for the week based on historical sales (same week, recent week trends), combined with customer life rhythm/season/gas/divide/situation (backed by weather, crowd, competition intelligence) 52 weeks MD week plan)
.inlineAgentsBody ("You're the Selection Planning Commissioner, taking historical sales as the baseline for demand (in the same week, trends in recent weeks) and then making a one-week business proposal in conjunction with the customer's rhythm/season/temperature/dest/situation focus). I'm not sure.
.build();
/ / Marketing Executive: Hold MCP + @Tool toolset, generate files and execute them locally
SubagentDeclaration marketingAgent = SubagentDeclaration.builder()
.name(”marketing_agent”)
.description() Marketing Executive: Calling MCP tools such as weather/calendar/member/competent/promotion to generate marketing files and create promotions and issue coupons I'm not sure.
.inlineAgentsBody (“You are the marketing executive, strictly using step-by-step tools to generate files, create promotions and vouchers, and do not create data.” I'm not sure.
.build();
/ / Quantified Commissioner: sale in real time by weather and day every evening, dynamically setting the amount of discounts for birth and optimal timing
SubagentDeclaration clearanceAgent = SubagentDeclaration.builder()
.name(”clearance_agent”)
.description (“Explosion Commissioner: Calling weather.query and real-time sales on the same day, matching the historical sales volume of the product with the weather/sync to delineate the baseline, combining the countdown of the closed shop with a discount on the birth and the best clear-time recommendation”)
.inlineAgentsBody (“You are a clear-cut commissioner, giving discount strength and timing based on weather, real-time sales, historical sales baseline (in the same weather/same period) and the remaining time of closure, without prejudging data.” I'm not sure.
.build();
/ / permission Commissioner: RBAC/ABAC Validation Before Call, High Risk Operation Launch HITL Confirm
SubagentDeclaration guardAgent = SubagentDeclaration.builder()
.name(”guard_agent”)
.description (“permission Commissioner: permission for tool call and data range verification, human confirmation for ultra vires or high risk”)
.inlineAgentsBody (“You are Commissioner permission, verify role and data range before any call.” I'm not sure.
.build();
The five commissioners, after stating that they had done so, put them together with the tool set and the middle set to build the entire skeleton of the business assistant:
import io.agentscope.harness.HarnessAgent;
import io.agentscope.core.tool.Toolkit;
import io.agentscope.core.middleware.MiddlewareBase;
import io.agentscope.core.tracing.OtelTracingMiddleware;
import io.agentscope.core.memory.MemoryConfig;
import io.agentscope.core.context.CompactionConfig;
import io.agentscope.core.context.ToolResultEvictionConfig;
import java.nio.file.Path;
import java.util.List;
HarnessAgent assistant = HarnessAgent.builder()
.name('store-ops-assist') / / General Control
.model(”dashscope:qwen-max”)
.workspace(Path.of(”./store-ops-workspace”))
.sysPrompt(”””
You're a shopkeeper's smart assistant for 52 weeks MD Control. Process:
1. angent spawn indent agent identification intent (planning or implementation or clearance) and slot;
2. Agent spahn md planer agent first takes historical sales as an empirical baseline (during the same week, recent week) and then combines customer life rhythm/season/temperature/fest/situation (backed by weather, crowds, competitive intelligence) to select priority commodities and to plan weekly;
3. Agent spawn marketing agent to generate marketing programmes and promotions and to call on tools to land;
4. Creation of high-risk operations such as promotions/ issuers to be validated by guard agent and, if necessary, human confirmation;
5. A few hours before the close of the shop every evening, angent spawn clear agent sets the discounts and time periods according to weather and real-time sales dynamics and submits the check agent check before the price is down;
6. Summary 52 week MD week plan and clear implementation results, output observable links.
”””)
.subagent.subagent//Multi AI agent declaration Part Line
.subagent(marketingAgent).subagent(clearanceAgent)
.subagent(guardAgent)
.toolkit (toolkit) // Registered MCP tool + @Tool
.middlewares(List.of(
New Mission Middleware (rbacService), // permission Interception
/ Observable
.MemoryConfig.builder().build() / long-term memory
.compaction(CompactionConfig.builder()
.triggerMessages(30).keepMessages(10)
.truncateArgs(CompactionConfig.TruncateArgsConfig.builder()
.max ArgLength (2000). Build().build() / context Project
.toolResultAction (ToolResultActionConfig.defaults() / Big Results Unmount
.build();
Detailed code: two scenarios to be achieved
Chapter III (3.3) has set the path for HarnessAgent General, five sub-units Agent and MCP. This chapter 4.4 gives the configuration code for Harness, and Chapter V uses the running perspective to explain how a request flows in Harness. Instead of listing "what's the power" in this section, two scenarios are actually written into codes: 4.1, 4.2, 52 weeks MD and smart business landings, and 4.3, the capabilities module (intent/MCP/permission/observable/memory) of two scenarios shared. Read the code, and you see what the doorman runs every day -- "Why" is written in the note.
4.1 scene I: 52 weeks MD week plan code Land
One sentence sets out the MD claim for the next quarter, and Agent wants to: identify intent to take historical sales as an empirical baseline combined with gas/ weather/ guest/ competitions weekly sales promotion and vouchers (human confirmation). The business landing code is as follows:
/ scene one entry: Chief of the store submits 52 week MD week plan request
public Mono planWeeklyMd(String utterance, SessionContext ctx) {
/ / 1 Intent recognition (three-layer funnel + structured output, see 4.3): Turning natural language into a powerful type of intent, preventing LLM from being free.
IntentResult intent = intentAgent.call(
List.of(new UserMessage(”user”, utterance)),
IntentResult.class,
RuntimeContext.builder().sessionId(ctx.sid).userId(ctx.uid).build())
.block().getStructuredData(IntentResult.class);
/ Intent = {intent:'md plan', slots: {week:'2026-W34', seatson:'Autumn'”
//weather: "High temperature," Segment: "old age in the community,"
/ 2 Selection Planning: Hand it over to md planner agent, which collects numbers on the registered MCP route at 4.3
/ / Empirical baseline based on "historical sales" to prevent models from being empty-made; permission/data range intercepted onActing (see 4.3)
return mdPlannerAgent.call(
List.of(new UserMessage(”user”,
'to'+inent.slots.get("week")+'52 weeks MD:'+
"sales.history takes the week period + recent week trend, calendar. solar terms takes the gas," +
"weather.query takes the weather, remember.segment collects the guests, company.intel takes the competition," +
In the last few weeks of the week of the week, I was able to find out what was going on.
MdPlanReply.class,
RuntimeContext.builder().sessionId(ctx.sid).userId(ctx.uid).build())
.flatMap(reply -> {
MdPlanReply r = reply.getStructuredData(MdPlanReply.class);
Off-site execution: marketing executives create promotion + vouchers for high-risk writing
/ tools.json has paused and dropped the framework before calling
/ REQUIRE USER CONFIRM, get ReplyId() for frontend
marketingAgent.call(List.of(new UserMessage(”user”,
+ r.toBrief()) is the basis for a week-long project to create promotions, create social writings, and create a constituency:
Void.class, RuntimeContext.builder()
.sessionId(ctx.sid).userId(ctx.uid).build()).block();
/ 4 Observable: whole chain moves tool call/Manual approvals/text increments in real time out (see 4.3)
return Mono.just(r);
});
}
The selection tool itself was exposed with @Tool, historical sales as input:
public class MdPlanningTools {
private final MdPlanningService mdService;
public MdPlanningTools(MdPlanningService svc) { this.mdService = svc; }
@Tool(name = ”md_weekly_plan”,
Description = “to generate 52 weeks MD priority goods and business proposals for a given week based on historical sales (trends during the same week, recent weeks), combined with time nodes (customer life rhythm/season/gas/ festival/scene)”
public MdWeeklyPlanResult weeklyPlan(
@ToolParam(name ='week')description = 'ISO Week, like '2026-W34')
/ / History sales: A week close to N is the same time as last year for the baseline of empirical selection and demand -- this is 52 weeks of MD's "base"
@ToolParam(name ='histoorySales'), description ='historical sales: Trends over the same week/near week, for empirical selection and demand baselines'
@ToolParam(name = 'context'), description ="contextsummary: Customer's rhythm/season/gas/ festival/ scene”)
return mdService.plan(new MdPlanCommand(week, historySales, context));
}
}
The "certainty" of the field comes from two points: the selected product is sales.history empirical, and the price down is REQUIRE USER CONFIRM turn off.
4.2 Scene II: Clear code of wisdom Land
Every evening before closing the shop, it's called "Stand-in-time trigger + real-time adaptation": The point is drawn from the dispatcher and sold in real time on the same night, on the same day, and the head of the store confirms the price before it is set against the historical sales volume of the product (the same weather / at the same time delineating the baseline).
/ scene 2 entrance: dispatcher triggers 3 hours before shop close (cron/ schedule frame), sessionId fixes for crash recovery (see 4.3 memory)
public Mono runClearance(SessionContext ctx) {
/ 1 Intended to be identified as clearness (repeated 4.3 same three layers of funnel)
return clearanceAgent.call(
List.of(new UserMessage(”user”,
"Implementation of tonight's cleanup:weather.query picks up the night, sales.history takes the class like the weather/simulates the baseline," +
“sales.realtime takes real-time sales off the day, and calculates the discount strength and the best time out in a closed-shop countdown”).
ClearanceReply.class,
RuntimeContext.builder()
...sessionId("clarity-daily")//fixed sessionId: each day-keeping mission can be resumed (Safeguard III, see 4.3)
.userId(ctx.uid).build())
.flatMap(reply -> {
ClearanceReply r = reply.getStructuredData(ClearanceReply.class);
/ 2 Tend execution: clear.apply is a high-risk writing operation, tools.json label ASK, frame throw REQUIRE USER CONFIRM,
// Waiting for confirmation at terminal/app (see 4.3 permission); deep discount (< 6 discount)
clearanceAgent.call(List.of(new UserMessage(”user”,
+ r.toBrief())
Void.class, RuntimeContext.builder()
.sessionId(”clearance-daily”).userId(ctx.uid).build()).block();
/ 3 Observable: exit from cleanway steamEvents, recoverable from Agent StateStore (see 4.3)
return Mono.just(r);
});
}
The clear down price is the same as the suggested @Tool exposure, the core is "History Baseline + Real-time Marketing + Closed-Clock Countdown" margin decision:
public class ClearanceTools {
private final ClearanceService clearanceService;
public ClearanceTools(ClearanceService svc) { this.clearanceService = svc; }
@Tool(name = ”clearance_suggest”,
Decryption = “The amount of discounts and the best amount of time available for birth, when combined with the weather, real-time sales and historical sales of the day (delineation of the baseline with weather/same period), closed-house countdowns” I'm not sure.
public ClearanceSuggestion suggest(
@ToolParam(name
Auto-fetched and translated by AI Atlas. All rights belong to the original author.