stream_bridge
diapason.server.stream_bridge
¶
Bridge sync agent.run() + EventBus events to an async SSE generator.
Subscribes to EventBus callbacks that push events into an asyncio.Queue, runs agent.run() in a background thread, and yields SSE-formatted strings from the queue for consumption by FastAPI's StreamingResponse.
AgentStreamBridge
¶
Bridge between a synchronous agent and an async SSE stream.
Pattern:
1. Subscribe EventBus callbacks that push events into an asyncio.Queue
via loop.call_soon_threadsafe().
2. Run agent.run() in a thread via asyncio.to_thread().
3. Async generator reads from queue and yields SSE-formatted strings.
4. Unsubscribe from EventBus in finally block.
stream()
async
¶
Async generator that yields SSE-formatted strings.
create_agent_stream(agent, bus, model, request)
async
¶
Create an AgentStreamBridge and return a FastAPI StreamingResponse.