Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

sid405's avatar

sid405 wrote a comment+100 XP

1mo ago

sid405's avatar

sid405 wrote a comment+100 XP

1mo ago

The Batteries-Included AI Toolkit : Ep 4, Demoing Our Chat Agent

Perhaps it'd be worth completing the messages() method in the agent in the previous video otherwise this one won't work

Something along these lines


    public function messages(): iterable
    {
        return TicketMessage::where('ticket_id', $this->ticketId)
            ->get()
            ->map(function (TicketMessage $message) {
                $role = is_null($message->user_id)
                    ? Laravel\Ai\Messages\MessageRole::Assistant
                    : Laravel\Ai\Messages\MessageRole::User;

                return new Laravel\Ai\Messages\Message($role, $message->body);
            })->toArray();
    }