有状态 Agent 图,跟踪客户阶段,自适应响应,需要时转人工。
适用场景
SaaS onboarding flows, customer success teams, subscription services guiding users to activation.
前提条件
Python 3.11+, LangGraph, LangChain, FastAPI, OpenAI API key
工作流图
用 LangGraph 构建客户旅程 Agent
分步指南
-
Define the State Schema
Create a TypedDict with fields: customer_id, stage (signup/onboarding/active), messages, customer_type, satisfaction_score. This state persists across all nodes in the graph.
-
Build the Graph Nodes
Create nodes: greeting_node, assess_node, guide_node, qa_node, escalate_node. Each node receives the state, processes it, and returns updated state. Connect nodes with conditional edges.
-
Add Conditional Routing
Use conditional edges: if satisfaction_score < 3, route to escalate_node. If customer asks a question, route to qa_node. Otherwise, continue to guide_node. This makes the agent adaptive.
-
Implement Memory Checkpointing
Use LangGraph MemorySaver to persist conversation state. This allows the agent to resume conversations across sessions and maintain context. Store checkpoints in SQLite or Redis.
-
Deploy with FastAPI
Wrap the LangGraph agent in a FastAPI endpoint. Add streaming for real-time responses. Deploy to your preferred platform (Vercel, Railway, self-hosted). Test with 20 simulated customer journeys.