# 5. Code Snippet Thực Tế (LangGraph State)

Dưới đây là một phần định nghĩa State và Graph cốt lõi của luồng (từ `backend/agent/lead_stage_agent/graph.py`):

```python
from typing import TypedDict, Annotated, Any
from langchain_core.messages import BaseMessage
from langgraph.graph.message import add_messages
from langgraph.graph import StateGraph, END

class LeadStageState(TypedDict):
    messages: Annotated[list[BaseMessage], add_messages]
    user_insight: str | None
    
    # Internal pipeline
    tool_result: str | None
    tool_name_used: str | None
    
    # Output
    updated_insight: dict | None
    lead_stage: dict | None
    product_ids: list[str]
    early_exit: bool | None
    
    diagnostics: Annotated[list[dict[str, Any]], lambda x, y: x + y]

# Setup Graph
workflow = StateGraph(LeadStageState)
workflow.add_node("classifier", _classifier_node)
workflow.add_node("stylist", _stylist_node)
workflow.set_entry_point("classifier")
workflow.add_conditional_edges(
    "classifier",
    lambda state: END if state.get("early_exit") else "stylist"
)
workflow.add_edge("stylist", END)
```