feat: 增强 Agent 系统和完善项目结构

主要改进:
- Agent 增强: 订单查询、售后支持、客服路由等功能优化
- 新增语言检测和 Token 管理模块
- 改进 Chatwoot webhook 处理和用户标识
- MCP 服务器增强: 订单 MCP 和 Strapi MCP 功能扩展
- 新增商城客户端、知识库、缓存和同步模块
- 添加多语言提示词系统 (YAML)
- 完善项目结构: 整理文档、脚本和测试文件
- 新增调试和测试工具脚本

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
wangliang
2026-01-16 16:28:47 +08:00
parent 0e59f3067e
commit e093995368
48 changed files with 5263 additions and 395 deletions

View File

@@ -65,6 +65,7 @@ class AgentState(TypedDict):
conversation_id: str # Chatwoot conversation ID
user_id: str # User identifier
account_id: str # B2B account identifier
user_token: Optional[str] # User JWT token for API calls
# ============ Message Content ============
messages: list[dict[str, Any]] # Conversation history [{role, content}]
@@ -74,6 +75,10 @@ class AgentState(TypedDict):
intent: Optional[str] # Recognized intent (Intent enum value)
intent_confidence: float # Intent confidence score (0-1)
sub_intent: Optional[str] # Sub-intent for more specific routing
# ============ Language Detection ============
detected_language: Optional[str] # Detected user language (en, nl, de, etc.)
language_confidence: float # Language detection confidence (0-1)
# ============ Entity Extraction ============
entities: dict[str, Any] # Extracted entities {type: value}
@@ -111,10 +116,11 @@ def create_initial_state(
account_id: str,
current_message: str,
messages: Optional[list[dict[str, Any]]] = None,
context: Optional[dict[str, Any]] = None
context: Optional[dict[str, Any]] = None,
user_token: Optional[str] = None
) -> AgentState:
"""Create initial agent state for a new message
Args:
conversation_id: Chatwoot conversation ID
user_id: User identifier
@@ -122,7 +128,8 @@ def create_initial_state(
current_message: User's message to process
messages: Previous conversation history
context: Existing conversation context
user_token: User JWT token for API calls
Returns:
Initialized AgentState
"""
@@ -131,6 +138,7 @@ def create_initial_state(
conversation_id=conversation_id,
user_id=user_id,
account_id=account_id,
user_token=user_token,
# Messages
messages=messages or [],
@@ -140,6 +148,10 @@ def create_initial_state(
intent=None,
intent_confidence=0.0,
sub_intent=None,
# Language
detected_language=None,
language_confidence=0.0,
# Entities
entities={},
@@ -270,3 +282,21 @@ def mark_finished(state: AgentState) -> AgentState:
state["finished"] = True
state["state"] = ConversationState.COMPLETED.value
return state
def set_language(state: AgentState, language: str, confidence: float) -> AgentState:
"""Set the detected language in state
Args:
state: Agent state
language: Detected locale code (en, nl, de, etc.)
confidence: Detection confidence (0-1)
Returns:
Updated state
"""
state["detected_language"] = language
state["language_confidence"] = confidence
# Also cache in context for future reference
state["context"]["language"] = language
return state