Skip to main content

Prism PHP AI Agents

https://prismphp.com/getting-started/introduction.html

Prism is a powerful Laravel package for integrating Large Language Models (LLMs) into your applications.

Use Prism Php

As default we use N8N, but you can easily change it:

  1. Install Prism PHP: composer require prism-php/prism

  2. Publish the configuration: php artisan vendor:publish --tag=prism-config

  3. Modify

App\Jobs\ProcessAiChatMessage.php

- use App\Services\AiAgent\N8N\N8NAIAgent;
+ use App\Services\AiAgent\PrismPhp\PrismPhpAgent;

class ProcessAiChatMessage implements ShouldQueue
{
use Queueable;

...
...

public function handle(
AiChatThread $aiChatThread,
- N8nAiAgent $n8nAiAgent,
+ PrismPhpAgent $prismPhpAgent,
AiChatHistory $aiChatHistory,
SubscriptionTrackUsage $subscriptionTrackUsage,
): void {

$user = User::findOrFail($this->userId);

/** @var ?string $chatThreadId */
$chatThreadId = $aiChatThread->getThreadId(
$this->request['sessionId'],
$user->id
);

- $response = $n8nAiAgent->sendMessage(
+ $response = $prismPhpAgent->sendMessage(
new AiAgentSendMessageRequest($this->request),
$chatThreadId
);


// update thread id if it was created in N8N
$aiChatThread->updateThreadIfChanged(
$chatThreadId,

...