Skip to content

Add WithoutBroadcasting attribute to skip oversized stream events#752

Open
pushpak1300 wants to merge 5 commits into
0.xfrom
broadcast-without-attribute
Open

Add WithoutBroadcasting attribute to skip oversized stream events#752
pushpak1300 wants to merge 5 commits into
0.xfrom
broadcast-without-attribute

Conversation

@pushpak1300

Copy link
Copy Markdown
Member

Currently there isn't a clean way to stop BroadcastAgent from broadcasting every StreamEvent. Tool results from data-heavy tools (listing records, search, email bodies) routinely blow past the 10KB WebSocket frame limit on Reverb/Pusher, which throws a BroadcastException and fails the whole queued job. Folks have been working around it by subclassing the job and overriding broadcastOnQueue (see #174).

This PR adds a class attribute so an affected agent can opt out of broadcasting specific event types:

#[WithoutBroadcasting(ToolResult::class, ToolCall::class)]
class SearchAgent implements Agent, HasTools
{
    use Promptable;
}

The named events simply never hit the websocket; the frontend loads tool data from agent_conversation_messages after the stream completes, same as the existing workaround. No attribute means everything broadcasts as before, so nothing changes for the majority who never hit the limit. It applies to both the queued (broadcastOnQueue) and synchronous (broadcast/broadcastNow) paths.

Went with an attribute to match the existing #[MaxSteps]/#[Timeout] style and avoid widening the Agent contract or threading a new param through three broadcast signatures. Open to renaming if you'd prefer something else.

Fixes #174

@pushpak1300 pushpak1300 marked this pull request as ready for review June 29, 2026 18:48
Comment thread src/Attributes/WithoutBroadcasting.php
Comment thread src/Attributes/WithoutBroadcasting.php Outdated
Comment thread src/Attributes/WithoutBroadcasting.php
Comment thread src/Attributes/WithoutBroadcasting.php Outdated
* @param array<int, class-string<StreamEvent>> $events
*/
public static function allows(?object $target, StreamEvent $event): bool
public static function withholds(array $events, StreamEvent $event): bool

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this expected to be withholds or should be withHolds?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think for simplicity changed to excludes.

@pushpak1300 pushpak1300 requested a review from WendellAdriel July 1, 2026 15:06

@WendellAdriel WendellAdriel left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 💪

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BroadcastAgent broadcasts ToolResult/ToolCall events that exceed WebSocket message limits

2 participants