laravel/ai

[Refactoring] [Feature Request] Add support for Broadcasting static messages without LLM processing

Open

#147 opened on Feb 12, 2026

View on GitHub
 (0 comments) (1 reaction) (0 assignees)PHP (261 forks)github user discovery
enhancementhelp wanted

Repository metrics

Stars
 (978 stars)
PR merge metrics
 (Avg merge 6d 11h) (49 merged PRs in 30d)

Description

Feature Request: Refactor Broadcasting to Support Both LLM-Generated and Static Messages Current Behavior All broadcast methods (broadcast, broadcastNow, broadcastOnQueue) are tightly coupled with LLM prompt processing. There's no way to broadcast static messages without going through the AI model. Problem Even for simple static messages (welcome messages, notifications, system messages), we must:

Execute an LLM prompt Consume API tokens Wait for AI generation Accept variable output

Current workaround:

public function welcome(Channel|array $channels)
{
    // Forced to use LLM even for a simple static message
    return $this->broadcastOnQueue(
        'Generate a short and friendly welcome message.', 
        $channels
    );
}

Proposed Solution Refactor the broadcasting flow by delegating the actual message sending to a dedicated internal method. This would allow both LLM-generated and static messages to use the same broadcasting infrastructure. Architecture

// Internal method that handles the actual broadcasting
protected function broadcastText(
    string $text,
    Channel|array $channels,
    bool $now = false
): void
{
    // Create stream event from text
    // Handle broadcasting logic
}

// Existing methods would delegate to broadcastText

public function broadcast(
    string $prompt, 
    Channel|array $channels, 
    array $attachments = [], 
    bool $now = false,
    ?string $provider = null,
    ?string $model = null
): StreamableAgentResponse
{
    return $this->stream($prompt, $attachments, $provider, $model)
        ->each(function (StreamEvent $event) use ($channels, $now) {
            // Uses broadcastText internally
            $this->broadcastText($event->content, $channels, $now);
        });
}

// New public methods for static messages
public function broadcastMessage(
    string $message,
    Channel|array $channels,
    bool $now = false
): void
{
    $this->broadcastText($message, $channels, $now);
}

public function broadcastMessageOnQueue(
    string $message,
    Channel|array $channels
): QueuedAgentResponse
{
    return new QueuedAgentResponse(
        BroadcastStaticMessage::dispatch($this, $message, $channels)
    );
}

Benefits

  • Single Responsibility: Separates message generation from message broadcasting

  • Reusability: The core broadcasting logic can be used for both AI and static content

  • Backward Compatibility: Existing methods continue to work unchanged

  • Extensibility: Easy to add new message sources (database, cache, etc.)

  • Performance & Cost: Direct broadcasting for static messages without LLM overhead

Use Cases

//Static welcome message
public function welcome(Channel|array $channels)
{
    return $this->broadcastMessageOnQueue(
        'Welcome! How can I assist you today?',
        $channels
    );
}

// Conditional logic
public function greet(Channel|array $channels, bool $personalized = false)
{
    if ($personalized) {
        // Use LLM for personalized greeting
        return $this->broadcastOnQueue(
            'Generate a personalized greeting',
            $channels
        );
    }
    
    // Use static message for generic greeting
    return $this->broadcastMessage(
        'Hello! How can I help?',
        $channels
    );
}

// System notifications
public function notifyMaintenanceMode(Channel|array $channels)
{
    $this->broadcastMessage(
        'System maintenance in progress. Please try again later.',
        $channels,
        now: true
    );
}

Contributor guide