diff --git a/examples/ecommerce-customer-service/README.md b/examples/ecommerce-customer-service/README.md index ec283b542..e202d0f50 100644 --- a/examples/ecommerce-customer-service/README.md +++ b/examples/ecommerce-customer-service/README.md @@ -18,10 +18,12 @@ Chinese customer question ``` The router, specialist prompts, synthetic data, tool results, CLI, and customer -responses use Simplified Chinese. Stable Python identifiers and graph node names -remain in English. The two specialist branches use separate prompts and tools. -All products, orders, policies, and tool results are fictional fixtures in -`tools.py`. +responses use Simplified Chinese. The specialist Agent display names are +`售前服务` and `售后服务`, so their observable spans are named +`invoke_agent 售前服务` and `invoke_agent 售后服务`. Stable Python identifiers, +graph node names, tool names, and route values remain in English. The two +specialist branches use separate prompts and tools. All products, orders, +policies, and tool results are fictional fixtures in `tools.py`. ## Install @@ -82,6 +84,8 @@ For a detailed scenario walkthrough and a ready-to-use training script, see With LangChain and LangGraph instrumentation enabled, a specialist request is expected to include the router LLM, the selected Agent, ReAct Step, Tool/LLM children, and the final reviewer LLM. Only the chosen specialist branch runs. +The outer graph nodes remain `presales_agent` and `aftersales_agent`, while the +inner Agent spans use the Chinese display names above. ## Test diff --git a/examples/ecommerce-customer-service/README.zh-CN.md b/examples/ecommerce-customer-service/README.zh-CN.md index c4f0dee50..7ce452b39 100644 --- a/examples/ecommerce-customer-service/README.zh-CN.md +++ b/examples/ecommerce-customer-service/README.zh-CN.md @@ -20,8 +20,10 @@ LangGraph Agent API。 工具结果全部是虚构数据。 运行时的意图识别提示词、专业 Agent 提示词、工具说明、虚构数据、异常兜底及 -最终回答均使用简体中文。为了保持代码规范和 Trace 名称稳定,Python 标识符、 -节点名和内部路由值仍使用英文。 +最终回答均使用简体中文。专业 Agent 的显示名称为“售前服务”和“售后服务”, +因此可观测链路中会显示 `invoke_agent 售前服务` 或 +`invoke_agent 售后服务`。为了保持代码接口稳定,Python 标识符、LangGraph +节点名、工具名和内部路由值仍使用英文。 ## 安装 @@ -77,7 +79,9 @@ loongsuite-instrument python app.py \ 启用 LangChain 和 LangGraph 埋点后,一次专业客服请求应包含路由 LLM、 被选中的 Agent、ReAct Step、Tool/LLM 子节点以及最终审查 LLM;未选中的 -专业 Agent 不会执行。 +专业 Agent 不会执行。外层编排节点仍显示为 `presales_agent` 或 +`aftersales_agent`,其内部专业 Agent 分别显示为 `invoke_agent 售前服务` 或 +`invoke_agent 售后服务`。 ## 培训讲解指南 diff --git a/examples/ecommerce-customer-service/tests/test_workflow.py b/examples/ecommerce-customer-service/tests/test_workflow.py index 790b3ea3e..70d01e469 100644 --- a/examples/ecommerce-customer-service/tests/test_workflow.py +++ b/examples/ecommerce-customer-service/tests/test_workflow.py @@ -24,7 +24,13 @@ query_after_sales_policy, search_product_catalog, ) -from workflow import EcommerceSupportWorkflow, IntentDecision, select_route +from workflow import ( + AFTERSALES_AGENT_NAME, + PRESALES_AGENT_NAME, + EcommerceSupportWorkflow, + IntentDecision, + select_route, +) class KeywordClassifier: @@ -224,9 +230,9 @@ def test_presales_and_aftersales_use_different_agents() -> None: assert presales["route"] == "presales" assert aftersales["route"] == "aftersales" - assert calls == ["presales_agent", "aftersales_agent"] - assert "presales_agent_tool" in model.review_inputs[0] - assert "aftersales_agent_tool" in model.review_inputs[1] + assert calls == [PRESALES_AGENT_NAME, AFTERSALES_AGENT_NAME] + assert f"{PRESALES_AGENT_NAME}_tool" in model.review_inputs[0] + assert f"{AFTERSALES_AGENT_NAME}_tool" in model.review_inputs[1] @pytest.mark.parametrize( @@ -281,10 +287,10 @@ def test_ambiguous_question_uses_clarification_without_a_specialist() -> None: def test_specialist_and_reviewer_fail_open() -> None: workflow, _, calls = make_workflow( - fail_review=True, fail_agent="presales_agent" + fail_review=True, fail_agent=PRESALES_AGENT_NAME ) result = workflow.run("云步通勤鞋有货吗?") - assert calls == ["presales_agent"] + assert calls == [PRESALES_AGENT_NAME] assert result["route"] == "presales" assert result["final_response"].startswith("售前客服暂时不可用") diff --git a/examples/ecommerce-customer-service/workflow.py b/examples/ecommerce-customer-service/workflow.py index 94e1ed168..0fb50c940 100644 --- a/examples/ecommerce-customer-service/workflow.py +++ b/examples/ecommerce-customer-service/workflow.py @@ -13,6 +13,9 @@ Route = Literal["presales", "aftersales", "clarify"] +PRESALES_AGENT_NAME = "售前服务" +AFTERSALES_AGENT_NAME = "售后服务" + PRESALES_PROMPT = """你是虚构电商店铺的售前客服。 只能使用提供的虚构商品目录、商品知识和库存工具。 回答前至少调用一个工具;工具未提供的信息要明确说明不知道。 @@ -159,13 +162,13 @@ def __init__( ) self.confidence_threshold = confidence_threshold self.presales_agent = agent_factory( - name="presales_agent", + name=PRESALES_AGENT_NAME, model=model, tools=PRESALES_TOOLS, prompt=PRESALES_PROMPT, ) self.aftersales_agent = agent_factory( - name="aftersales_agent", + name=AFTERSALES_AGENT_NAME, model=model, tools=AFTERSALES_TOOLS, prompt=AFTERSALES_PROMPT,