Skip to content

extrawest/langraph-essentials-ts

Repository files navigation

📧 L2: AI-Powered Email Processing Workflow

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.


🏗️ Graph Architecture

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
Loading

🌟 Key Features

  • 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 Command pattern to return updates and route control dynamically inside nodes (write_response and human_review).
  • Human-in-the-Loop (HITL): Utilizes LangGraph's native interrupt() function to pause the graph state when:
    • Urgency is high or critical
    • Intent is complex
    • Errors occur during response generation
  • State Persistence: Uses a MemorySaver checkpointer to allow the graph to pause, receive human feedback, and resume execution right where it left off.

📂 Project Structure

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

🚀 Getting Started

1. Environment Setup

Copy the example environment file and add your OpenAI and/or Anthropic API keys:

cp example.env .env

Inside .env, make sure to fill in:

  • OPENAI_API_KEY: Required for the ChatOpenAI model.
  • LANGSMITH_API_KEY (Optional): To trace and debug your agent workflow.

2. Install Dependencies

Install all required Node/TypeScript dependencies using pnpm:

pnpm install

3. Run the Development Server

Start the LangGraph development server locally:

pnpm dev

This boots up the local LangGraph server (powered by @langchain/langgraph-cli), exposing endpoints to test the agent using the LangGraph Studio UI or SDK.


🧪 Testing the Workflow

You can interact with the compiled graph under email-workflow.

Test Inputs

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"
}

Expected Behavior

  1. read_email: Logs the processing of the email.
  2. classify_intent: Classifies the intent as bug and urgency as high or critical.
  3. search_documentation & bug_tracking run in parallel.
  4. write_response: Drafts a reply. Since urgency is high, it yields to human_review.
  5. human_review: Interrupted! The graph execution will pause.
  6. Resume: Supply the human decision input payload (e.g. { "approved": true, "editedResponse": "..." }) to resume and finish with send_reply.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors