Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 26, 2025

Implements a loosely-coupled, async-first event streaming system for real-time logging, agent execution tracking, and UI integration.

Core API (browser_ai/event_bus/emitter.py)

  • emit() / emit_async() - fire events from anywhere
  • subscribe(topic, handler) / unsubscribe() - topic-based pub/sub with wildcard * support
  • EventLevel enum for filtering (DEBUG, INFO, WARNING, ERROR, CRITICAL)
  • StreamingEventHandler - async iterator for WebSocket/SSE streaming
  • FilteredEventHandler - filter by level or custom predicate

Logging Integration (browser_ai/event_bus/handlers/logging_handler.py)

  • LoggingEventHandler bridges Python logging → event bus
  • Prevents recursion by filtering event_bus module logs

Agent Service Integration

Events emitted at key lifecycle points:

  • Agent started/completed/failed
  • Step started/completed/failed
  • LLM request started/completed, rate limits
  • Planning started/completed
  • User help requested

Usage

from browser_ai.event_bus import emit, emit_async, subscribe, StreamingEventHandler
from browser_ai.event_bus import AgentStartedEvent, AgentStepCompletedEvent

# Subscribe to events
subscribe("agent", lambda e: print(f"{e.topic}/{e.name}"))
subscribe("*", my_handler)  # wildcard

# Emit events
emit(AgentStartedEvent(task="Search for tutorials"))
await emit_async(AgentStepCompletedEvent(step_number=1, actions_taken=[...]))

# Stream for WebSocket/SSE
handler = StreamingEventHandler()
subscribe("*", handler)
async for event in handler.stream():
    await websocket.send(event.model_dump_json())

All events are Pydantic models with full type safety and JSON serialization support.

Original prompt

for the browsai agent library i want to have a real time event steaming emitter kind of logging . not only for logging its also for to streem the curen status of task llm outputs angent exection for ui and relevent subscriber in different level in should be a versatile and extendabel loosely coupedn one that can be called anyware async and pydentic type safe


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 3 commits November 26, 2025 14:01
Co-authored-by: Sathursan-S <84266926+Sathursan-S@users.noreply.github.com>
Co-authored-by: Sathursan-S <84266926+Sathursan-S@users.noreply.github.com>
Co-authored-by: Sathursan-S <84266926+Sathursan-S@users.noreply.github.com>
Copilot AI changed the title [WIP] Add real-time event streaming emitter for logging Add real-time event streaming emitter for Browser.AI Nov 26, 2025
Copilot AI requested a review from Sathursan-S November 26, 2025 14:15
Copilot finished work on behalf of Sathursan-S November 26, 2025 14:15
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.

2 participants