OptiFlow

Autonomous Production, Procurement & Logistics Agent for Apparel Exporters

Inspiration

Apparel is Sri Lanka's largest export industry $5.3 billion in 2025, 46% of total export revenue, and 350,000 direct jobs. But underneath that number, smaller Cut-Make-Trim exporters are still running buyer orders by hand: a planner turns an email into a schedule, procurement chases supplier quotes over phone and email, and someone else separately tracks customs paperwork and freight bookings. None of these three workflows talk to each other. We kept coming back to one specific failure mode: a fabric shortage discovered in procurement can silently jeopardize a vessel booking cutoff that was set weeks earlier in a completely different part of the process and by the time anyone notices, the only options left are an expensive air-freight scramble or a costly delay. We wanted to see whether a single agent, holding one goal instead of three disconnected tasks, could catch that before it happened.

What it does

OptiFlow is an autonomous agent that treats "fulfill this buyer order on spec, on the vessel, at minimum cost" as one continuous goal instead of three separate jobs. It parses a buyer's message into style, quantity, and deadline, checks stock and line capacity, and builds a schedule. If materials are short, it goes out for supplier quotes, parses PDF and scanned quotes into structured data, and ranks suppliers on price, delivery time, and reliability. If it's still infeasible, it tries a substitute fabric, then a split shipment, and only as a last resort drafts but never sends a deadline-renegotiation email for a human. Once approved, it issues the purchase order, notifies the floor, and then monitors shipping documents and customs status, flagging delay risk before it becomes a missed cutoff.

How we built it

The core is a ReAct-style reasoning loop running on an LLM (Claude 3.5 Sonnet / GPT-4o), implemented as a stateful agent graph in LangGraph so the orchestrator can dynamically route between an Intake & Scheduling branch, a Procurement branch, and a Logistics branch, rather than following a fixed script. It runs asynchronously on a FastAPI backend so a long reasoning cycle never blocks other jobs, with Supabase (Postgres) handling state, jobs, and schedule data. A CP-SAT optimization engine computes conflict-free production schedules, and a layout-aware document transformer (LayoutLMv3) converts messy supplier quote PDFs and scanned documents into structured JSON the ranking logic can actually use. All three branches converge on a single human-in-the-loop review gate, surfaced through a proposals dashboard, before anything executes.

Challenges we ran into

The hardest problem wasn't any single tool it was the branching logic itself. Getting the orchestrator to treat scheduling, sourcing, and shipping as one reasoning problem, instead of three pipelines bolted together, meant designing "Plan & Branch" as a graph the model routes through dynamically rather than an if/else chain. Parsing supplier quotes reliably was another: real-world quotes arrive as inconsistent PDFs, scanned images, and email bodies, so structured extraction had to tolerate incomplete or ambiguous data and know when to ask a supplier to clarify rather than guess. We also had to be deliberate about autonomy boundaries deciding exactly which actions (like sending a renegotiation email or switching carriers) are irreversible enough that they must stop at a human gate, without turning every routine decision into a bottleneck.

Accomplishments that we're proud of

We're proud of designing a single agentic loop that genuinely unifies three business functions that are normally handled by different people and different software, instead of stitching together three separate tools. We're also proud of the human-in-the-loop design: two clear gates, placed exactly at the two points where a wrong call costs real money, with the ability to edit not just approve or reject a proposal. And we mapped every reasoning step to a concrete, real tool (CP-SAT scheduling, quote parsing, supplier history, vessel/customs data), so the architecture isn't just conceptual it's buildable.

What we learned

We learned a lot about agentic system design beyond simple tool-calling: how to structure a "collect context → plan & branch → execute → evaluate & replan" loop so it recovers gracefully from missing documents, failed tool calls, and conflicting data instead of breaking. We also went deep on the operational reality of Sri Lanka's apparel export sector how thin the margin for error is for smaller exporters, and how much of the "AI opportunity" here isn't about replacing judgment, it's about making sure the right person sees the right tradeoff before a cutoff is missed, not after.

What's next for OptiFlow

Phase 2 is building out the planned stack LangGraph orchestration on FastAPI, the CP-SAT scheduling engine, and the LayoutLMv3 quote parser against real data from a pilot exporter. From there, we want to integrate live vessel booking and customs data sources, harden the error-recovery paths (retry → fallback → escalate) under real failure conditions, and expand supplier-quote parsing accuracy across a wider range of document formats. Longer term, we'd like to extend the same agentic pattern to buyer-side visibility, so a brand can see delay risk on their own orders in real time, not just the exporter.

Built With

Share this project:

Updates

Submission history