Skip to main content

ArticleUpdated November 20269 min read

AI agents that classify documents and route deals

One agent watches Trello, Drive and email, classifies each document, and routes the deal to Won, Lost, Deferred or no change. Here is how to choose and build one.

  • document classification
  • AI agents
  • deal routing
  • workflow vs agent
  • duplicate protection
  • human in the loop

An AI agent for document classification and deal routing watches every place a case notification can land, reads the document it finds, and moves the deal to the correct stage. In the pattern Rex Black Inc. builds, one agent watches Trello, Drive and inbound email, classifies the document, and routes the deal to Won, Lost, Deferred or no change. A model does the classifying, and plain code does the routing, so a policy change is three lines of code.

What is an AI agent that classifies documents and routes deals?

It is a program that reads an incoming file, decides what kind of document it is, and moves the related deal to the stage that document implies. It replaces the manual step where someone opens a PDF, works out what it is, and drags a card to a new column.

Anthropic separates workflows, where a model sits inside a fixed path of code, from agents, which suit cases that need flexibility and model-driven decisions at scale (Anthropic). A document router uses both ideas. The reading step is agent-like because documents vary. The moving step is workflow-like because the rules are known.

The reading step can be split into two parts. One model identifies the document type, and a second model pulls out the details, such as names and amounts. That is the pattern behind document processing and form filling (Microsoft Learn). Azure Document Intelligence also returns a confidence score with each classification, which you can use to set a cut-off (Azure docs). That cut-off is a natural place to decide between routing a document automatically and sending it to a person.

Why is classification AI and routing plain code?

Classification is a judgment call, so a model does it. Routing from a classification to a stage is a fixed rule, so ordinary code does it.

Keeping the two apart makes the system easy to maintain. When a firm changes its routing policy, it changes three lines of code and ships. That means no prompt engineering (no rewriting of the instructions given to the AI), no eval sets (no new round of accuracy testing of the AI), and no regressions on unrelated classifications (nothing else breaks). The design principle is to use AI where judgment is needed and code where predictable behavior is needed. It is described further on the Intelligent Routing Agent page.

What happens if the same PDF arrives twice?

The same PDF dropped twice routes once. The agent is built to be safe to repeat: it recognises a document by the deal plus a document hash, which is a short fingerprint of the file. If the agent has already handled that document for that deal, the second arrival does not move anything.

The general technique is an idempotency key, a unique label attached to a request so the receiving system can recognise a retry of the same request (Stripe docs). With Stripe's payment system, retrying with the same key returns the stored first result instead of running the operation again (Stripe docs). Stripe's engineering team explains why this matters: a duplicate payment request would charge the customer twice (Stripe). A duplicate deal-stage move is the same kind of failure.

This matters because documents arrive from more than one place. A contract can land in a folder, be attached to a card and be emailed to the team in the same hour. Without this protection, that is three stage moves and three sets of follow-on actions.

What does the human gate do?

The document processor can only move a deal to "awaiting operator review". It does not submit anything upstream. Across every Rex Black Inc. engagement the same rule holds: the AI prepares and proposes, and a named human approves and submits.

The AI has no authority to file upstream, whether to a regulator, the tax authority, a court, a billing system or a client email inbox. When a case is lost, a named senior operator decides whether to appeal. That is not an AI decision.

There is a regulatory background to this habit. EU AI Act Article 14 requires high-risk AI systems to be designed so that people can effectively oversee them while in use (EU AI Act service desk). A sales-pipeline router may not be classed as high-risk, but the design habit is the same: a person stays in the loop on anything that leaves the firm.

The document processor also follows a mismatch policy of "Surface, never hide", with a human gate that is always on. Both are described on the AI Document Processing Agent page.

How can I automate routing of case notifications from PDFs and Trello cards?

Use one agent that watches every place a notification can arrive, and send everything it finds through the same classifier, the same detail-puller and the same routing table. Trello can send a notice to an address you choose whenever its boards, lists or cards change, so the agent does not need to keep checking for new cards (Atlassian).

When the agent updates cards itself, those updates can set off further notices, and the agent could end up reacting to its own changes. Trello provides a request identifier so that automations triggered by its notices can avoid reacting to their own card updates (Atlassian).

A typical deployment uses both a board-based trigger (a card moving on a Trello board) and a folder-based trigger (a file landing in a shared folder). Once the document is in hand, the agent treats both identically. Adding a new trigger, such as a Dropbox folder, is a configuration change, not a new build.

The flow looks like this:

  1. A card moves, a file lands in a folder, or an email arrives.
  2. The agent fetches the document and takes its fingerprint, so a repeat of the same file is recognised.
  3. The classifier labels the document type.
  4. The detail-puller reads out what the pipeline needs, such as award amounts.
  5. The routing table maps the label to a stage: Won, Lost, Deferred or no change.
  6. Invoices for won cases are generated and queued for approval in the same pass.
  7. Anything that needs human judgment, such as an appeal or an approval, goes to a person.

What are the best AI tools for document processing and form filling in a sales pipeline?

The best tool is the one that learns your own documents quickly, shows how sure it is, and sits inside a process that stops and asks a person when it is unsure. No single product does the whole job, because a working setup combines several kinds of tool.

Kind of toolWhat it doesExample
Document reading serviceLabels each document and pulls out its detailsAzure Document Intelligence
General language modelReads and reasons about text that does not fit a fixed patternClaude
Step-sequencing toolRuns the stages in order and keeps track of where each document isLangGraph
Work board or queueHolds the cases and shows their stageTrello
Your sales system and e-signing toolHold the deal record and the signed paperworkHubSpot and PandaDoc

When you compare options, ask these questions:

  • How many sample documents does it need before it works on yours? Azure Document Intelligence, for example, can train a custom classifier from as few as two document types with five samples each (Microsoft Learn).
  • Does it report how sure it is about each label, so you can set a cut-off for sending a document to a person?
  • Does it connect to the systems you already use?
  • Does it keep a record of what it did and why?

The AI Document Processing Agent from Rex Black Inc. runs on AWS, with LangGraph running the steps. Its stack is Claude, LangGraph, AWS, and connections to HubSpot and PandaDoc. It runs on a daily schedule and whenever an e-signing event occurs. The product names matter less than the wiring: a document that cannot be read cleanly should stop and ask a person, not be guessed at.

Should I choose a workflow or an AI agent?

Choose a workflow when the task is well defined and the steps are known. Choose an agent when the input varies and the decision needs flexibility. Anthropic draws the same line: workflows suit well-defined tasks, and agents suit cases that need flexibility and model-driven decisions at scale (Anthropic).

SituationBetter fit
Fixed form, fixed fields, one sourceWorkflow
Documents from many sources with varying layoutsAgent for reading, workflow for routing
Rules that change oftenPlain code
Decisions that need context and judgmentAgent, with a human gate
High-stakes action that leaves the firmHuman approval, always

A common mistake is to make the whole pipeline an agent. The reading step benefits from a model, while almost everything after it benefits from ordinary code that a developer can read, test and change. For a longer treatment, see Workflow or Agent? A Decision Framework Before You Architect Anything.

What should I look for in a provider?

Look for a provider that draws the line between AI and people before building anything, and can show you how every action is checked and recorded. Use this checklist when you compare providers for a document classification and routing build:

  • A written boundary for what the agent may and may not do, agreed before a single prompt is written.
  • A human gate on anything that leaves the firm, with a person one hand-off away.
  • Classification kept separate from routing, so a policy change is a small code change.
  • Protection against duplicates, so the same document routes once.
  • A clear rule for which documents go to a person, with the reason shown.
  • A record of every action the agent takes.
  • Monitoring after launch, not only testing before it.
  • Testing on your real documents, including the messy ones.
  • A fixed scope, with a written "usable after" outcome for each phase.
  • A clear answer to what happens when the agent is wrong.

What does the 8-week build for the document processing agent involve?

The AI Document Processing Agent is scoped, built and handed off in a single phase of 8 weeks. Observability and reliability are built in, which means you can see what the agent did and why, and it keeps working day after day.

It does not submit anything upstream. It can only move a deal to "awaiting operator review", which keeps the final decision with the operator. The operator only sees the cases that need human judgment. The build is described on the AI Document Processing Agent page, and the routing design is on the Intelligent Routing Agent page.

What to do next

Start by reading the Intelligent Routing Agent and AI Document Processing Agent pages to see how the pieces fit. If you want a straight read on your own pipeline, book a call. It is 30 minutes with a senior principal and no slide deck. You get a one-page recap within 24 hours that says what we would do first.

Rex Black Inc. · Since 1994 · Dallas, Texas

Keep reading

Related reading

Practices

Where this leads

Working on something like this?Talk to the people who wrote it.

Book a call