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

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

I'm working on a Laravel package for building reliable LLM workflows. One of the use cases is content generation at scale. But once you decide to run hundreds of workflows, the problems may destroy your app.

The core flow is simple:

BRIEF β†’ DRAFT β†’ EDIT β†’ QUALITY CHECK β†’ OUTPUT

The package is mostly about controlling everything around the model:

  • token and cost limits
  • known pricing before a request is sent
  • persisted workflow state
  • safe retries
  • quality rules
  • metrics for every LLM call
  • optional human review

For example, say you need to generate an article:

$workflow = $rick->workflow('article-v1')
    ->budget(
        maxTotalTokens: 17_000,
        maxCostUsd: '0.02',
        requireCompleteMetrics: true,
        requireKnownPricing: true,
    )
    ->resolve(
        'Write a publication-ready article from the supplied brief.',
        'Return a clear Markdown article with no invented facts.',
    )
    ->context('brief')
    ->operation(
        operation: 'article.draft',
        output: 'draft',
        reads: ['brief'],
    )
    ->operation(
        operation: 'article.edit',
        output: 'article',
        reads: ['draft'],
    )
    ->outputGlue('article')
    ->build();

$run = $rick->run($workflow, [
    'brief' => [
        'topic' => 'How to generate content reliably with cheap LLMs',
        'audience' => 'Laravel developers',
        'language' => 'English',
        'length' => '800-1200 words',
    ],
]);

Enter fullscreen mode Exit fullscreen mode

This is just one use case for Laravel Rick. The same approach works for support
workflows, data processing, structured generation, or any other multi-step LLM task.

The project is open source.

Top comments (0)