DEV Community

lucasnscr
lucasnscr

Posted on

Customer Support Agent with ADK and LangGraph

Customer Support Agent

Customer support agent via WhatsApp with Jira integration, built with Python, FastAPI, LangGraph, and Redis.

Architecture

┌─────────────────┐     ┌─────────────────┐     ┌─────────────────┐
│    WhatsApp     │────▶│     FastAPI     │────▶│   AgentRunner   │
│   (Webhook)     │     │   /webhooks     │     │   (ADK Style)   │
└─────────────────┘     └─────────────────┘     └────────┬────────┘
│
▼
┌─────────────────┐     ┌─────────────────┐     ┌─────────────────┐
│      Redis      │◀───▶│   StateStore    │◀───▶│    LangGraph    │
│   (Sessions)    │     │                 │     │   StateGraph    │
└─────────────────┘     └─────────────────┘     └────────┬────────┘
│
┌───────────────┼───────────────┐
▼               ▼               ▼
┌────────────┐  ┌────────────┐  ┌────────────┐
│ CustomerDB │  │    Jira    │  │  Parsing   │
│   (Tool)   │  │   (Tool)   │  │  (Utils)   │
└────────────┘  └────────────┘  └────────────┘

Enter fullscreen mode Exit fullscreen mode

Conversational Flow

[Customer] “Hi”
│
▼
[Agent] “Hi! To help you, please send me your CNPJ.”
│
▼
[Customer] “11.111.111/0001-91”
│
▼
[System] Validates CNPJ in the database
│
├─── Invalid CNPJ ──▶ “I couldn’t find an active account. Please confirm the number.”
│                           │
│                           └──▶ [Back to requesting CNPJ]
│
└─── Valid CNPJ ──▶ “Perfect! Tell me the product and describe your request.”
│
▼
[Customer] “Product: ERP, Request: error in the report”
│
▼
[System] Creates ticket in Jira
│
▼
[Agent] “✅ Request created: SUP-123”

Enter fullscreen mode Exit fullscreen mode

Requirements

  • Python 3.12+
  • Docker and Docker Compose
  • Poetry (dependency manager)

Installation

1. Clone the repository

cd customer-support-agent
Enter fullscreen mode Exit fullscreen mode
  1. Install dependencies
# Install Poetry (if needed)
curl -sSL https://install.python-poetry.org | python3 -
Enter fullscreen mode Exit fullscreen mode

Install dependencies

poetry install
Enter fullscreen mode Exit fullscreen mode
  1. Configure environment variables

Create a .env file at the root of the project:

# Redis
REDIS_URL=redis://localhost:6379/0

# Jira
JIRA_BASE_URL=https://your-domain.atlassian.net
JIRA_EMAIL=your-email@example.com
JIRA_API_TOKEN=your-api-token
JIRA_PROJECT_KEY=SUP
JIRA_ISSUE_TYPE=Task

# WhatsApp (optional)
WHATSAPP_PROVIDER=cloudapi
Enter fullscreen mode Exit fullscreen mode
  1. Start the services

Start Redis and the application

docker compose up -d

# Or start only Redis (for local development)
docker compose up -d redis

# Run the application locally
poetry run uvicorn app.main:app --reload --port 8000
Enter fullscreen mode Exit fullscreen mode

Usage

Testing with cURL

# Health check
curl http://localhost:8000/health

# Simulate WhatsApp message - Greeting
curl -X POST http://localhost:8000/webhooks/whatsapp \
  -H "Content-Type: application/json" \
  -d '{"from":"+5511999999999","text":"hi"}'

# Send valid CNPJ
curl -X POST http://localhost:8000/webhooks/whatsapp \
  -H "Content-Type: application/json" \
  -d '{"from":"+5511999999999","text":"11111111000191"}'

# Send product and request
curl -X POST http://localhost:8000/webhooks/whatsapp \
  -H "Content-Type: application/json" \
  -d '{"from":"+5511999999999","text":"Product: ERP System, Request: error when generating report"}'
Enter fullscreen mode Exit fullscreen mode


bash

Valid CNPJs for testing (mock)

CNPJ Name Status
11111111000191 Demo Client Ltd. Active
22222222000191 Test Company S.A. Active
33333333000191 Inactive Company Inactive

API Endpoints

Method Endpoint Description
GET /health Health check
POST /webhooks/whatsapp Receives WhatsApp messages
GET /sessions/{phone} Retrieves session state
DELETE /sessions/{phone} Removes session

Tests

# Run all tests
poetry run pytest

# Run with coverage
poetry run pytest --cov=app

# Run a specific test
poetry run pytest tests/test_graph_flow.py -v
Enter fullscreen mode Exit fullscreen mode

Project Structure

customer-support-agent/
├── app/
│   ├── main.py                    # FastAPI webhook
│   ├── settings.py                # Config via env vars
│   └── agent/
│       ├── runner.py              # AgentRunner (ADK style)
│       ├── graph.py               # LangGraph StateGraph
│       ├── state.py               # SupportState TypedDict
│       ├── nodes.py               # Node functions
│       ├── tools/
│       │   ├── customer_db.py     # Customer validation (mock)
│       │   └── jira.py            # Jira REST integration
│       └── utils/
│           ├── parsing.py         # CNPJ, product, request parsing
│           └── store.py           # Redis state store
├── tests/
│   └── test_graph_flow.py         # Flow tests
├── docker-compose.yml
├── Dockerfile
├── pyproject.toml
└── README.md
Enter fullscreen mode Exit fullscreen mode

Jira Configuration

Creating an API Token

  1. Go to https://id.atlassian.com/manage-profile/security/api-tokens
  2. Click “Create API token”
  3. Copy the token and add it to the .env

Creating the Project

  1. Create a project in Jira (e.g., “SUP” for Support)
  2. Configure the issue type (Task, Bug, etc.)
  3. Update the variables JIRA_PROJECT_KEY and JIRA_ISSUE_TYPE

WhatsApp Integration

WhatsApp Cloud API

Configure the webhook URL in Meta Business:

https://your-domain.com/webhooks/whatsapp
Enter fullscreen mode Exit fullscreen mode

Twilio

Configure the webhook URL in the Twilio Console:

https://your-domain.com/webhooks/whatsapp
Enter fullscreen mode Exit fullscreen mode

Repository URL

Top comments (0)