DEV Community

Cover image for I built a Laravel package for LLM workflows with hard token and cost limits
Anton Parmuzin
Anton Parmuzin

Posted on Edited on

I built a Laravel package for LLM workflows with hard token and cost limits

I'm building Laravel Rick, a durable workflow runtime around Laravel AI. The model call itself is the easy part. The hard part starts when workflows run through queues, survive worker crashes, wait for humans, enforce budgets, and must not repeat paid provider work after retry.

Update — v0.4.1: Rick now has class-based workflows, ordinary PHP steps, native Laravel AI agent steps, WorkflowState, progress tracking, human input gates, and recovery without re-paying for successful provider work.

The core flow is simple:

BRIEF → DRAFT → EDIT → QUALITY CHECK → OUTPUT

Rick handles the infrastructure around the model:

  • hard token and cost budgets
  • provider-attempt accounting
  • persisted and encrypted workflow state
  • immutable recovery lineage
  • reuse of successful paid invocations
  • tenant isolation
  • human input gates
  • progress and metrics
  • transactional outbox delivery

For example, say you need to generate an article:

final class ArticleWorkflow extends Workflow
{
    public function name(): string
    {
        return 'article';
    }

    public function version(): string
    {
        return '1.0.0';
    }

    public function build(WorkflowBuilder $workflow): WorkflowBuilder
    {
        return $workflow
            ->budget(maxCostUsd: '0.02')
            ->step(LoadBrief::class, as: 'load-brief')
            ->agent(DraftArticle::class, as: 'draft')
            ->agent(EditArticle::class, as: 'article')
            ->output('article');
    }
}

$run = ArticleWorkflow::start([
    'brief' => $brief,
]);
Enter fullscreen mode Exit fullscreen mode

The important part is what happens when something fails. A queue retry does not silently authorize another paid provider request. If successful provider work can be safely reused during recovery, Rick reuses it instead of paying for it again.

The Laravel Rick is open source.

I'm especially interested in feedback from Laravel developers already running AI workloads through queues, human review, or multi-step business processes. The same approach works for support
workflows, data processing, structured generation, or any other multi-step LLM task.

Top comments (0)