AI sales CRM with LangGraph agents

An omnichannel CRM where an AI agent works each stage of the sales cycle and managers stay in control.

Domain
CRM, sales automation, operations
Our role
Product architecture, full-stack development, AI agent design, infrastructure and delivery
Year
2026

We built a production CRM for a business whose sales run through chat. Every inbound conversation becomes a scored lead on a configurable pipeline, and a LangGraph AI agent bound to each stage qualifies the lead, confirms the order and hands it on, while managers approve, edit or take over at any point. The backend runs on Python, FastAPI, Temporal, RabbitMQ and Keycloak behind one React web app, and the same design fits agencies, B2B sales teams, scheduled services and marketplaces.

Challenge

  • Customers wrote in on several messaging channels, and managers answered from personal and shared accounts, so no customer had a single history.
  • Managers spent the first minutes of every lead asking the same qualification questions.
  • Nobody could see which chats were waiting on the team and which on the customer, and high-value requests got the same response time as cold ones.
  • The supply side, with partners, outreach and announcements, was run by hand in phones and spreadsheets.
  • The system had to keep working when a messaging API, an LLM or a data vendor did not answer.

Solution

We built a two-workspace CRM on one platform. In the sales workspace, messages from every channel go through one pipeline and become leads with a kanban card, a manager assigned by shift, a requirements form, calendar events, tasks and a live chat. Each pipeline column has its own LangGraph agent that clarifies requirements, confirms the order or shortlists partners, then moves the card to the next column. Each chat runs in off, suggest or auto mode, and managers coach the agents with plain-language rules. The partner network workspace keeps the fulfilment side in the same system: a contact registry, kanban boards, partner records and scheduled outreach campaigns. Temporal runs the long processes: lead enrichment and scoring, media handling, history sync, campaigns and a dispatcher that flags stalled chats.

Architecture

LangGraph sales cycle: the pipeline column picks the agent, the chat's AI mode decides who sends the reply, and every run is journaled
LangGraph sales cycle: the pipeline column picks the agent, the chat's AI mode decides who sends the reply, and every run is journaled

What the system does

One AI agent per pipeline stage
Small LangGraph flows, each bound to a kanban column: clarify requirements, confirm the order, shortlist partners, extract parameters from chat history, partner outreach and partner onboarding. When a stage goal is reached, the card moves on and the next agent takes over. Admins rebind flows to columns without a deploy.
Managers stay in control
Each chat has three AI modes: off, suggest (the agent drafts, a manager approves or edits) and auto. Auto mode pauses as soon as a person writes, and the agent asks the manager when it is unsure. Managers write guidance rules in plain language, scoped by business line, stage, customer segment or a single chat, and the rules apply from the next turn.
Every AI run is journaled
Agent state is checkpointed in PostgreSQL, so a conversation resumes where it stopped after a restart. Each turn records its steps, tool calls, the rules it saw, the prompt and its cost. The admin console shows the run journal for each lead as a graph.
Omnichannel inbox
Chat bots, team messaging accounts and messaging gateways feed one ingest pipeline, with media, voice messages recorded in the browser, replies and history backfill. A new channel needs an adapter and a configuration row. On-demand translation lets a manager read and write in their own language.
Durable workflows on Temporal
More than 20 Temporal workflows run enrichment from external data sources, a two-axis lead score that maps to a tier and a response-time target, campaigns sent exactly once per scheduled occurrence, and a five-minute job that asks an LLM whether a stalled chat really needs a person.
Partner network and access control
A second workspace manages the partners who fulfil the orders: contacts with several roles, two kanban boards, records with attachments and AI-assisted autofill, and a catalog sales managers can search. Keycloak handles login, and four roles are enforced on every route, WebSocket and conversation.

Engineering decisions

  • The AI worker has no database connection. It reads and writes only through MCP tools that run the same role guards as the HTTP API, and the backend rejects any write tool outside the current stage's flow on every call. A static check fails the build if the AI worker imports the database client.
  • Live traffic, messages sent from other devices and history backfill share one ingest path. Messages are shown in send order, while unread state uses a separate counter, so a recovered old message is neither out of order nor lost as unread.
  • LLM cost is controlled: paid calls are never retried blindly, summaries are skipped when their inputs have not changed, and the attention dispatcher stops once its daily budget is spent.
  • Database constraints enforce the invariants: one post per target per campaign, one send per scheduled occurrence, one translation per message and language. A failed data source never blocks the score, assignment or the AI.
  • Four backend images from one Python codebase, RabbitMQ fanout for real-time updates across API instances, more than 100 Alembic migrations and more than 400 test modules, plus Playwright end-to-end tests.

Interface

Diagrams

Architecture: messaging channels, the web app, Keycloak and four backend processes built from one codebase
Architecture: messaging channels, the web app, Keycloak and four backend processes built from one codebase
Lead lifecycle: from the first message to won or lost, including repeat customers
Lead lifecycle: from the first message to won or lost, including repeat customers

Stack

  • Python 3.12
  • FastAPI
  • SQLAlchemy 2
  • PostgreSQL
  • LangGraph
  • MCP
  • Temporal
  • RabbitMQ
  • Keycloak
  • S3
  • React 19
  • TypeScript
  • Playwright
  • Docker

What this shows

  • A CRM for businesses whose sales run through chat: omnichannel inbox, configurable pipeline, assignment, calendar and tasks.
  • Production AI agents limited by business state and supervised by people, with audit trails, cost control and guidance rules.
  • Long-running, retry-safe business processes on Temporal and an event-driven backend on RabbitMQ, WebSocket and SSE.
  • Demand and supply on one platform: customers in the sales workspace, partners and fulfilment in the partner workspace.

Questions about this case

Can the AI send messages without a manager?

Only if you allow it. Each chat runs in one of three modes: off, suggest, where every draft waits for a manager to approve or edit it, and auto. In auto mode the agent steps back as soon as a person writes in the chat, and it asks the manager instead of guessing when it is unsure.

Can we change what the AI does without developers?

Yes. Pipeline columns, the agent bound to each column, the default AI mode and the handoff column are all edited in the admin console without a deploy. Managers coach agents with plain-language rules scoped by business line, stage, customer segment or a single chat, and the rules apply from the next turn.

What happens when an LLM or a messaging channel does not answer?

Agent state is checkpointed in PostgreSQL, so a conversation resumes where it stopped. Outbound message queues are durable, so a restart does not lose a send. Paid LLM calls are not retried blindly, and a failed data source is marked as failed without blocking scoring, assignment or the AI.