Urgent.News

What's breaking now, across thousands of outlets.

AI

Episode 02: Getting Started with the Laravel AI SDK

The Laravel AI SDK is Laravel's first-party package for building AI-powered application features without turning your codebase into a collection of provider-specific HTTP calls. It gives Laravel developers one consistent place to configure providers, define agents, call models, use tools, request structured output, and track usage. The important mental shift is this: the SDK is not the product…

The Laravel AI SDK is a native package that allows developers to easily integrate AI-powered features into their Laravel applications without dealing with multiple provider-specific HTTP calls. It provides a consistent way to configure providers, define agents, call models, use tools, request structured output, and track usage. However, it's important to remember that the SDK is just an integration layer, and your Laravel application remains responsible for use case, authorization, validation, persistence, queues, logs, and user experience.

To get started with the Laravel AI SDK, begin by focusing on a narrow feature rather than building a general assistant. This makes it easier to control prompt, output, fallback, cost, and success criteria. The SDK offers several production-friendly building blocks, such as provider abstraction, agents, structured output, tool access, and operational hooks.

To install the package, run `composer require laravel/ai` and then publish the configuration using `php artisan vendor:publish --provider = Laravel\Ai\AiServiceProvider`. The migration step is crucial, as certain SDK features like remembered conversations require database tables. Although you may not use conversation storage immediately, publishing configuration early keeps provider and model choices visible.

Configure providers through environment variables instead of hardcoding them in prompts, controllers, jobs, or agent classes. Define a default provider and model per environment for better control over quality, latency, cost, context window, supported tools, and output behavior. Create an agent class that encapsulates a specific responsibility, such as summarizing support tickets. The agent should have instructions, model configuration, and output schema.

When calling the agent from application code, keep the HTTP layer thin and delegate the responsibilities to a service class that owns the use case. Build minimal prompt context from trusted data and provide only the necessary information to the agent. Finally, use anonymous agents for experiments only, as they might expose sensitive data.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in AI

Law reform focuses on making of AI porn images on sly

Secretary for Justice Paul Lam said on Saturday that the Law Reform Commission needed to consider whether creating AI-generated pornographic images of a person without consent should itself be an…

  • Law reform commission considers AI-generated porn images without consent as potential offense.
  • Issue broken down into production, distribution, and use of such material.
  • AI-related portion of review to precede public consultation.

More from Saturday 26 September →