DEV Community

Cover image for I stopped my AI agents from being expensive black boxes (here is the architecture)
Livecontext
Livecontext

Posted on

I stopped my AI agents from being expensive black boxes (here is the architecture)

I have been building AI automations for a while, and the same problem kept coming back: a single "do-everything" agent is expensive, unpredictable, and a black box. You hand it a goal, it loops, it burns tokens, and when it finishes you cannot easily say what it actually did or why it cost what it cost.

So I built the platform I wanted: LiveContext. You describe a job in chat, it builds a workflow you can read and edit, and it runs that workflow with AI agents that are scoped and budgeted, not turned loose. The same build also ships as a small app (a form, a dashboard, an approval screen) for the rest of the team. Chat, workflow, agent and app, on one canvas.

This post is about the part I care about most: how the agents stay on a leash.

The core idea: the workflow owns the agents

In most agent frameworks the agent is the top of the stack. It decides what to call, when to stop, and how much to spend. That is fine for a demo and terrifying in production.

I inverted it. In LiveContext the workflow is the top of the stack, and agents are steps inside it. The workflow decides:

  • What each agent can see. An agent step only receives the inputs the workflow wires into it. No ambient access to everything.
  • What each agent can do. Each agent gets a scoped set of tools, not the whole toolbox. The refund agent can read an order and issue a refund; it cannot email your whole customer list.
  • How much each agent can spend. Every agent step has a credit budget it cannot exceed. When the budget is gone, the step stops. No surprise 40 dollar runs.

Because the workflow is explicit, every run is auditable: you get per-agent metrics (what it called, how many tokens, what it cost) for every step. The business logic lives in a graph you can read, not inside a prompt you have to trust.

The payoff: the same job runs at a fraction of the cost of one big agent, and you can actually see what happened.

What it looks like

Say you want: "every morning, pull our overnight support emails, classify them, draft replies for the simple ones, and flag the angry ones for a human."

You type roughly that in chat. LiveContext builds a workflow:

  • a schedule trigger (every morning)
  • a fetch step (the emails)
  • an agent step scoped to classify only (a tiny model, a small budget)
  • a decision node (simple vs needs-a-human)
  • an agent step scoped to draft a reply on the simple branch
  • a human-approval step on the angry branch
  • a small app (an approval screen) so a teammate can review and send

You can read that graph. You can edit any node. You can swap the model on the classify step to something cheap because classifying does not need a frontier model. That last part is where most of the cost savings come from: you stop paying frontier prices for trivial steps.

The stack (and why it self-hosts cleanly)

  • A Spring Boot monolith (Java 21) for the execution engine, catalog, auth and orchestration.
  • A Next.js frontend for the canvas, chat and the apps.
  • Postgres for state, Redis for coordination, and an S3-compatible store for files.
  • A small tools bridge, and an MCP server so you can drive it from MCP clients.

It all comes up with one command:

docker compose up -d
Enter fullscreen mode Exit fullscreen mode

On first boot it seeds 600+ integrations that work offline; you add your own as OpenAPI specs. Two heavier features (a headless browser agent with web search, and interface screenshots/PDFs) are opt-in behind their own env file, so the base stack stays light.

The execution engine is the interesting part: an immutable state snapshot per run, per-trigger DAGs, and nodes that can yield and wait (a timer, a webhook, a human approval) and resume later without losing state. Fork runs branches in parallel, merge waits for all predecessors, split fans out N parallel contexts. It is the boring-but-hard infrastructure that makes "an agent waits for a human then continues" actually reliable.

Being upfront about the license

LiveContext is source-available under a fair-code license (the Sustainable Use License, the same model n8n uses). It is free to self-host and run in production inside your organization. It is not OSI open source, and I would rather say that clearly than dress it up. If that distinction matters to you, now you know before you clone.

Try it

If you have built agent systems in production, I would genuinely like to hear how you handle the cost and audit problem. The "give each agent a budget and a boss" approach is working well for me, but I am sure there are failure modes I have not hit yet. Tell me where this breaks.

Top comments (0)