AI Business Workflow Agent
Email in, approved freight quote out: a durable Spring AI workflow where code, not the model, sets every price.
Commercial project under NDA
A workflow where the model reads and writes text and code decides every number.
- 5languages the agent reads
- 15end-to-end test emails
- 40labeled evaluation cases
- 3steps that call a model
- Technologies and integrations
- Java 25
- Spring Boot 4
- Spring AI
- MCP
- PostgreSQL
- Keycloak
- Next.js
Challenge
A freight quote request arrives as free text, and a wrong or manipulated price costs money. The agent had to answer with a correct price in seconds, ask a person when it should and not let an email talk it into a discount.
How it works
A request becomes a priced, audited quote. Quotes that trigger policy rules or injection checks are held for human approval. The test suite contains 15 end-to-end emails and 40 labeled evaluation cases covering intent, extracted fields, routing and injection recall.
Key areas of work
A durable workflow was implemented with a clear separation of responsibilities: the language model reads and writes text, and code computes every number. The work covered six areas.
- 01
Understanding the email
A model reads the request in any of five languages and extracts the cargo, lane and date.
If something is missing, the agent asks only for that and resumes the same request when the customer answers in the thread.
- 02
Enrichment and pricing
The customer is looked up in the CRM over MCP, and the lane is priced in code from carrier rates.
The model does not set a price.
- 03
Policy and approval
YAML rules decide whether a quote goes out on its own or waits for an approver.
A quote under the limits is sent automatically; large orders, new customers, dangerous goods or overdue credit wait for an approver, who gets a short briefing and the price breakdown.
- 04
Security and guardrails
Operators and approvers sign in through Keycloak with their own roles.
Email text is untrusted data: an instruction such as a 90% discount changes nothing, and the quote goes to a person. Every external write goes through a tool gateway with an approval token and an idempotency key.
- 05
Durable workflow
State lives in PostgreSQL, and every step is audited and replayable.
Timers replace waiting threads, retries use backoff and writes are idempotent through an outbox.
- 06
Operator console
A Next.js console shows the requests, the approvals and what the agent did.
Grafana dashboards and traces sit next to it.
Architecture and implementation details
Architecture
- 01
Inbox
Quote requests arrive by email, in any of five languages; replies leave through a mail outbox.
- 02
Understand
A model turns the email into structured fields. It is one of only three steps that call a model.
- 03
Enrich and price
The CRM is read over MCP, carrier rates come over REST and code computes the price.
- 04
Policy and approval
YAML rules route each quote: send it automatically, or hold it for an approver who signs in through Keycloak (OIDC with PKCE) and sees a briefing.
- 05
Respond and record
A model writes the reply under a numeric guard; every external write goes through a tool gateway that demands an approval token and an idempotency key.
- 06
Workflow engine
PostgreSQL state machine with db-scheduler timers and a Spring Security resource server; every model call and tool call is audited.
Related service: AI integration and automation
Working on something similar?
Describe your system and the outcome you need, and we will suggest the next step.