A comprehensive email triage and automated customer support responder system built with LangGraph.js.
This system acts as a smart agent that automatically classifies incoming customer emails, searches internal documentation for solutions, tracks bugs, drafts context-aware responses, and uses Human-in-the-Loop (interrupts) to halt execution for human review on high-priority or complex cases.
The workflow starts by reading the email, routing the classification in parallel to search documentation and log bugs (if applicable), drafting a reply, and selectively pausing for human approval.
graph TD
START([START]) --> read_email[Read Email]
read_email --> classify_intent[Classify Intent & Urgency]
classify_intent --> search_documentation[Search Documentation]
classify_intent --> bug_tracking[Create Bug Ticket]
search_documentation --> write_response[Write Draft Response]
bug_tracking --> write_response
write_response -->|Needs Human Review| human_review{Human Review & Interrupt}
write_response -->|Direct Reply| send_reply[Send Reply]
human_review -->|Approved & Edited| send_reply
human_review -->|Rejected| END([END])
send_reply --> END
- Structured Classification: Leverages GPT-5 model structured outputs via Zod (
EmailClassificationSchema) to determine intent (question,bug,billing,feature,complex), urgency (low,medium,high,critical), topic, and summary. - Parallel Execution: Searches documentation and processes bug tracking tasks simultaneously.
- Dynamic Routing: Uses the modern LangGraph
Commandpattern to return updates and route control dynamically inside nodes (write_responseandhuman_review). - Human-in-the-Loop (HITL): Utilizes LangGraph's native
interrupt()function to pause the graph state when:- Urgency is
highorcritical - Intent is
complex - Errors occur during response generation
- Urgency is
- State Persistence: Uses a
MemorySavercheckpointer to allow the graph to pause, receive human feedback, and resume execution right where it left off.
js/
├── src/
│ └── L2/
│ ├── email-workflow-complete.ts # Complete StateGraph and nodes implementation
│ └── email-workflow.ts # Type definitions and schemas
├── langgraph.json # LangGraph configuration pointing to email-workflow
├── package.json # Node dependencies and scripts
└── example.env # Environment template file
Copy the example environment file and add your OpenAI and/or Anthropic API keys:
cp example.env .envInside .env, make sure to fill in:
OPENAI_API_KEY: Required for theChatOpenAImodel.LANGSMITH_API_KEY(Optional): To trace and debug your agent workflow.
Install all required Node/TypeScript dependencies using pnpm:
pnpm installStart the LangGraph development server locally:
pnpm devThis boots up the local LangGraph server (powered by @langchain/langgraph-cli), exposing endpoints to test the agent using the LangGraph Studio UI or SDK.
You can interact with the compiled graph under email-workflow.
Invoke the graph with a state payload:
{
"emailContent": "I found a major bug on the payment checkout page. It keeps crashing when I click pay.",
"senderEmail": "customer@example.com",
"emailId": "msg-12345"
}- read_email: Logs the processing of the email.
- classify_intent: Classifies the intent as
bugand urgency ashighorcritical. - search_documentation & bug_tracking run in parallel.
- write_response: Drafts a reply. Since urgency is high, it yields to
human_review. - human_review: Interrupted! The graph execution will pause.
- Resume: Supply the human decision input payload (e.g.
{ "approved": true, "editedResponse": "..." }) to resume and finish with send_reply.