How Do SaaS Teams Build AI Workflows with Flue?
For AI-powered SaaS product teams · Based on Flue Harness-First AI Agent Framework
// TL;DR
SaaS product teams use Flue to embed AI agents and workflows into their products as HTTP-triggered APIs. Flue's harness-first design means no manual session, memory, or tool-loading infrastructure. Workflows return structured JSON with response text, token counts, and cost — essential for billing and usage metering. Deploy to Cloudflare for per-user persistent state via Durable Objects, or to Node for a single portable server. Use skills and tools to extend agent capabilities without coupling to the local file system.
Why Is Flue a Good Fit for SaaS Product Teams?
SaaS products that embed AI features need agents that are reliable, cost-trackable, and API-triggered. Most agent frameworks focus on developer experimentation, not production integration. Flue bridges this gap with:
- HTTP and WebSocket triggering out of the box via a single middleware addition
- Structured JSON output including response text, input/output token counts, cost, and model — ready for billing integration
- Per-user persistence via Cloudflare Durable Objects, where each user's agent gets its own isolated state
- Harness-first design that eliminates infrastructure plumbing your engineering team would otherwise build and maintain
How Do You Integrate Flue Workflows Into a SaaS Product Backend?
Flue workflows are designed for exactly this. Here's the integration pattern:
1. Define workflows in the `workflows/` directory — each exports a `run` function accepting a typed JSON payload
2. Register skills and tools for the capabilities your product needs (e.g., document analysis, content generation, data extraction)
3. Add the root middleware, build with `flue build`, and deploy `server.mjs`
4. Your SaaS backend triggers workflows via HTTP POST with user-specific payloads
5. Poll status via GET or stream results via WebSocket for real-time UIs
6. Parse the response JSON for the result, token usage, and cost — pipe this into your usage metering and billing system
The single-file deployment (`server.mjs`) simplifies your CI/CD pipeline and reduces operational surface area.
How Do You Handle Per-User State and Agent Isolation?
Assign each user (or tenant) a unique instance ID. When deployed to Cloudflare:
- Each instance ID maps to its own Durable Object
- Agent state — conversation history, memory, context — is isolated per user
- No shared database, no session store to manage
- State survives Worker restarts automatically
For the Node target, instance IDs enable concurrent session management in memory, but persistent state requires your own storage layer.
This architecture is natural for multi-tenant SaaS: one instance per user or per workspace, with full isolation and no cross-contamination.
How Do You Control Costs When Running AI Agents for Thousands of Users?
Three cost levers in Flue:
1. just-bash sandbox: The default in-memory sandbox has near-zero cost. No container boot, no per-agent infrastructure charge. Only opt into real containers for agents that need full OS capabilities.
2. Token tracking: Every workflow run returns input/output token counts and cost in the response JSON. Use this for per-user billing, usage caps, and cost alerting.
3. Precise instructions and skills: Vague instructions cause agents to loop and burn tokens. Write tight instructions, create focused `skill.md` descriptions, and validate tool parameters with Valibot to minimize wasted inference.
Should SaaS Teams Use Skills, Tools, or Both?
Use skills for capabilities that are best described in natural language — complex multi-step instructions, domain-specific processes, or anything you'd explain to a human in a document. Skills live in `skills/` with a `skill.md` description.
Use tools for capabilities that need strict parameter contracts — API calls, database queries, structured data extraction. Tools are code-defined with Valibot validation, ensuring the agent passes correct inputs every time.
Most SaaS products use both: skills for complex reasoning tasks, tools for integration points. The key advantage of tools over local file access is security isolation — the agent never touches your file system directly.
Ready to embed AI agents in your SaaS product? Start with `flue init`, define your first workflow in `workflows/`, and trigger it via HTTP POST from your backend.
// FREQUENTLY ASKED QUESTIONS
Can I track per-user AI costs with Flue?
Yes. Every Flue workflow run returns structured JSON including input/output token counts, cost, and model used. Assign unique instance IDs per user, parse the cost field from each response, and pipe it into your billing or usage metering system. This gives you per-user cost tracking without building custom instrumentation.
How does Flue handle multi-tenant isolation for SaaS?
Assign each tenant a unique instance ID. On the Cloudflare target, each ID maps to its own Durable Object with isolated persistent state — no shared database or session store needed. On Node, instance IDs separate concurrent sessions in memory. This architecture prevents cross-tenant data contamination without custom isolation infrastructure.
Can I add authentication to Flue's HTTP endpoints?
Yes. Flue supports custom routes alongside its built-in agent and workflow endpoints. Add authentication middleware (e.g., API key validation, JWT verification) as custom routes in your project. The root middleware that enables HTTP/WebSocket triggering is extensible, so you can layer auth and health checks on top of the default endpoints.
Is Flue suitable for real-time AI features in a SaaS product?
Yes. Flue supports WebSocket connections for streaming workflow and agent results in real time. Instead of polling via HTTP GET, connect via WebSocket to receive incremental output as the agent executes. This enables real-time UIs like live document processing, streaming content generation, or interactive coding assistants embedded in your product.