Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions examples/ecommerce-customer-service/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down
10 changes: 7 additions & 3 deletions examples/ecommerce-customer-service/README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ LangGraph Agent API。
工具结果全部是虚构数据。

运行时的意图识别提示词、专业 Agent 提示词、工具说明、虚构数据、异常兜底及
最终回答均使用简体中文。为了保持代码规范和 Trace 名称稳定,Python 标识符、
节点名和内部路由值仍使用英文。
最终回答均使用简体中文。专业 Agent 的显示名称为“售前服务”和“售后服务”,
因此可观测链路中会显示 `invoke_agent 售前服务` 或
`invoke_agent 售后服务`。为了保持代码接口稳定,Python 标识符、LangGraph
节点名、工具名和内部路由值仍使用英文。

## 安装

Expand Down Expand Up @@ -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 售后服务`。

## 培训讲解指南

Expand Down
18 changes: 12 additions & 6 deletions examples/ecommerce-customer-service/tests/test_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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("售前客服暂时不可用")

Expand Down
7 changes: 5 additions & 2 deletions examples/ecommerce-customer-service/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@

Route = Literal["presales", "aftersales", "clarify"]

PRESALES_AGENT_NAME = "售前服务"
AFTERSALES_AGENT_NAME = "售后服务"

PRESALES_PROMPT = """你是虚构电商店铺的售前客服。
只能使用提供的虚构商品目录、商品知识和库存工具。
回答前至少调用一个工具;工具未提供的信息要明确说明不知道。
Expand Down Expand Up @@ -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,
Expand Down
Loading