DaleHurley's avatar

Building Agentic AI Agents

Hi All

Just wanted to share with you that I have put together a series for Building Agentic AI Agents using OpenAI with Laravel 12 and React

This five-part series walks you through building an Agentic AI Agent with Laravel, React, and OpenAI. You'll start by setting up your Laravel project and making a simple “Hello World” call to OpenAI, then layer on real-time streaming, custom tool interfaces, stateful contexts, and automated planning.

I hope it helps you build your own solution.

Dale

1 like
2 replies
LaryAI's avatar
Level 58

Thanks for sharing your series on building Agentic AI Agents with Laravel 12, React, and OpenAI! For those interested in implementing similar functionality, here’s a high-level outline and a simple code example to get started with OpenAI API integration in Laravel:

1. Install Guzzle HTTP (if not already installed):

composer require guzzlehttp/guzzle

2. Add your OpenAI API key to your .env:

OPENAI_API_KEY=your_openai_api_key_here

3. Create a simple controller to interact with OpenAI:

php artisan make:controller OpenAIController

4. Example method to send a prompt to OpenAI:

public function chat(Request $request)
{
    $client = new \GuzzleHttp\Client();
    $response = $client->post('https://api.openai.com/v1/chat/completions', [
        'headers' => [
            'Authorization' => 'Bearer ' . env('OPENAI_API_KEY'),
            'Content-Type'  => 'application/json',
        ],
        'json' => [
            'model' => 'gpt-3.5-turbo',
            'messages' => [
                ['role' => 'user', 'content' => $request->input('prompt')]
            ],
        ],
    ]);

    $body = json_decode($response->getBody(), true);

    return response()->json([
        'reply' => $body['choices'][0]['message']['content'] ?? ''
    ]);
}

5. Add a route in routes/web.php:

Route::post('/openai/chat', [OpenAIController::class, 'chat']);

6. On the React side, you can use fetch or axios to POST to /openai/chat and display the AI’s response.

This is a basic starting point. Your series covers advanced topics like real-time streaming and stateful contexts, which are great next steps. Thanks again for sharing your resource!

If you have any specific questions about integrating OpenAI with Laravel or React, feel free to ask!

DaleHurley's avatar

Let me know if there is anything you want to dive into

Please or to participate in this conversation.