AIYINGFrom AI Awareness to Accomplishment
Showing posts with label LangGraph Complete. Show all posts
Showing posts with label LangGraph Complete. Show all posts

Monday, November 23, 2026

LangGraph Complete #01 — Start Here: Build Your First AI Workflow

AIYING Complete Guides · LangGraph Complete #01

Two tickets. Two routes. One graph.

Build your first LangGraph workflow with Python. No model or API key required.



“Where is my order?” and “I was charged twice” land in the same support inbox. The first belongs with the order team. The second needs billing review. If a message is unclear, someone should read it before the system assigns it. How do we express these choices so that a developer can inspect and test them?

1. Understand the graph

  • State holds the ticket text, selected route, and next action.
  • Nodes are functions. One classifies the ticket and three handlers set the next action.
  • Edges connect steps. A conditional edge reads the selected route and decides which handler runs.

Start → Classify → Billing, Orders, or Manual Review → End

A plain Python function is enough for a small routing rule. A graph becomes useful when you want to name and inspect individual steps or extend them with retrieval, approvals, and checkpoints. This episode uses a workflow whose routing rules you control. An agent design can let a model choose its next action or tool within limits you set. LangGraph Graph API · Workflows and agents

2. Build and run the router

Use Python 3.10 or later. Install LangGraph in your project environment, then save the Python code as ticket_router.py. LangGraph quickstart

python -m pip install "langgraph>=1,<2"
from typing import Literal, TypedDict

from langgraph.graph import END, START, StateGraph

Route = Literal["billing", "orders", "manual_review"]


class TicketInput(TypedDict):
    message: str


class TicketState(TicketInput, total=False):
    route: Route
    next_action: str


def classify(state: TicketState) -> dict[str, Route]:
    message = state["message"].casefold()
    if "charged twice" in message:
        return {"route": "billing"}
    if "where is my order" in message:
        return {"route": "orders"}
    return {"route": "manual_review"}


def select_route(state: TicketState) -> Route:
    return state["route"]


def handle_billing(state: TicketState) -> dict[str, str]:
    return {"next_action": "Review payment history."}


def handle_orders(state: TicketState) -> dict[str, str]:
    return {"next_action": "Check shipment status."}


def handle_manual_review(state: TicketState) -> dict[str, str]:
    return {"next_action": "Read the ticket and assign it."}


builder = StateGraph(TicketState)
builder.add_node("classify", classify)
builder.add_node("billing", handle_billing)
builder.add_node("orders", handle_orders)
builder.add_node("manual_review", handle_manual_review)

builder.add_edge(START, "classify")
builder.add_conditional_edges(
    "classify",
    select_route,
    {
        "billing": "billing",
        "orders": "orders",
        "manual_review": "manual_review",
    },
)
builder.add_edge("billing", END)
builder.add_edge("orders", END)
builder.add_edge("manual_review", END)
router = builder.compile()

for message, expected_route in [
    ("Where is my order?", "orders"),
    ("I was charged twice.", "billing"),
    ("Can someone help me?", "manual_review"),
]:
    result = router.invoke({"message": message})
    assert result["route"] == expected_route, result
    print(f'{result["route"]} | {result["next_action"]}')

Run python ticket_router.py. The assertions check all three routes.

orders | Check shipment status.
billing | Review payment history.
manual_review | Read the ticket and assign it.

Each run starts with a message. classify() writes the route, the conditional edge reads it, and the selected handler adds next_action. The lab records a suggested action in state. All ticket examples are synthetic.

3. Test the limits of the rules

Try “I see two payments for one purchase.” The graph sends it to manual review because the sentence lacks the phrase “charged twice.” Then try “Where is my order? I was charged twice.” It goes to billing because that rule is evaluated first.

Both results follow the code exactly. A support team still has to decide whether those outcomes are acceptable. Keep examples like these as regression cases when you add a broader classifier.

4. See where it fits in industry

Published case: LangChain describes how Klarna used LangGraph and LangSmith in a customer support assistant that helped teams handle escalations. Our lab isolates one design question from that setting: which requests need a specialist or a human reviewer? Read the published Klarna case study

Apply it locally: A college help desk could route fee queries to accounts, timetable queries to the academic office, and unclear requests to a coordinator. Start by collecting a small set of anonymized or synthetic tickets and having staff agree on the correct route for each.

5. Try the TAJ exercise

  1. Think: Choose one inbox and identify two teams that receive its requests.
  2. Ask: Ask an AI assistant to generate six synthetic tickets, including two unclear ones.
  3. Judge: Label the expected routes yourself. Run the tickets and inspect every disagreement.
  4. Accomplish: Adapt the router and demonstrate a correct result for each team and for manual review.

Next in LangGraph Complete #02: State That Survives the Next Step. We’ll add a routing reason and a record of what each node did.

Accomplish with AI

Powered by Blogger.

Featured post

LangGraph Complete #01 — Start Here: Build Your First AI Workflow

AIYING Complete Guides · LangGraph Complete #01 Two tickets. Two routes. One graph. Build your first LangGraph workflow w...

Search This Blog

List of blogs

Search This Blog

About

Translate

Instant Stories

Read in Your Language

Test

share this

ShareThis

Popular Posts