How do I install and start using Laravel AI SDK in an existing Laravel project?

Answered by 2 creators across 2 videos

To install and start using the Laravel AI SDK in an existing Laravel project, first run composer require Laravel AI to pull in the SDK (which brings Prism PHP, Illuminate components, and the rest of the stack). Next, publish the config and migrations so you get the ai.php config and the agent_conversations table ready to store dialogue history. Scaffold an agent (for example a Support Agent) and wire it up with the agent’s tools and memory features; you’ll define prompts and parameters (tokens, temperature) and ensure the agent implements the conversational and tools contracts. Configure your AI provider in config/ai.php so you can switch between OpenAI, Anthropic, or other providers without changing business logic, and test with a route that demonstrates provider-agnostic behavior. If you want a richer UX, enable streaming to see token-by-token outputs, and leverage the remember-conversation trait to preserve dialogue across prompts. This setup lays the groundwork for more advanced features like ticket classification and live knowledge-base interactions in later episodes.

  • "nunomaduro" points out that installing the SDK is lightweight and that AI providers are pluggable via config/ai.php, with embeddings and vector search built in, plus memory-enabled agents via a remember-conversation trait for persistent dialogue.
  • "nunomaduro" also notes the streaming capability as a UX improvement, allowing token-by-token output in the console and ongoing work with Laravel Prompts for live interactions.
  • "Laravel News" points out the essential first steps: publish config and migrations to create the agent_conversations table, scaffold a concrete agent (Support Agent) with promptable traits, and tune generation parameters like max_tokens (500) and temperature (0.7) for concise yet natural responses.
  • "Laravel News" highlights testing the integration through a dedicated route (support_test) to demonstrate provider-agnostic behavior and to show how the same code can switch between OpenAI and Anthropic without changing business logic.