websocket_platform#
- class baf.platforms.websocket.websocket_platform.WebSocketPlatform(agent, use_ui=True, authenticate_users=False)[source]#
Bases:
PlatformThe WebSocket Platform allows an agent to communicate with the users using the WebSocket bidirectional communications protocol.
This platform implements the WebSocket server, and it can establish connection with a client, allowing the bidirectional communication between server and client (i.e. sending and receiving messages).
Note
We provide different interfaces implementing a WebSocket client to communicate with the agent, though you can use or create your own UI as long as it has a WebSocket client that connects to the agent’s WebSocket server.
- Parameters:
- _connections#
The list of active connections (i.e. users connected to the agent)
- _websocket_server#
The WebSocket server instance
- Type:
WebSocketServer or None
- _message_handler#
The function that handles the user connections (sessions) and incoming messages
- Type:
Callable[[ServerConnection], None]
- _abc_impl = <_abc._abc_data object>#
- initialize()[source]#
Initialize the platform. This function is called right before starting the platform.
- reply_dataframe(session, df)[source]#
Send a DataFrame agent reply, i.e. a table, to a specific user.
- Parameters:
session (Session) – the user session
df (pandas.DataFrame) – the message to send to the user
- reply_html(session, message)[source]#
Send an agent reply to a specific user, containing text in HTML format.
- reply_image(session, img)[source]#
Send an image reply to a specific user.
Before being sent, the image is encoded as jpg and then as a base64 string. This must be known before dedocing the image on the client side.
- Parameters:
session (Session) – the user session
img (np.ndarray) – the image to send
- reply_markdown(session, message)[source]#
Send an agent reply to a specific user, containing text in Markdown format.
- reply_options(session, options)[source]#
Send a list of options as a reply. They can be used to let the user choose one of them
- reply_plotly(session, plot)[source]#
Send a Plotly figure as an agent reply, to a specific user.
- Parameters:
session (Session) – the user session
plot (plotly.graph_objs.Figure) – the message to send to the user
- reply_rag(session, rag_message)[source]#
Send a rag reply to a specific user.
- Parameters:
session (Session) – the user session
rag_message (RAGMessage) – the rag message to send to the user
- reply_reasoning_step(session, step)[source]#
Send an intermediate reasoning-state step to a specific user.
A reasoning step is any observable event the predefined reasoning state body produces while it is working: the LLM emitting tool calls or text, a tool returning a result, the task list being mutated (planned / completed / skipped), the orchestrator pushing back a premature final answer, or the step budget being exhausted. Sending these to the client lets the UI show a live “thinking” trace before the final reply arrives.
Persisted in the dedicated
reasoning_steptable (kind=reasoning_step) — not in the chat table — so it does not pollute chat history retrieval.- Parameters:
session (Session) – the user session.
step (dict) – the step payload with the shape
{"kind": str, "step": int, "summary": str, "details": dict}.kindis one ofllm_text,llm_tool_calls,tool_result,task_added,task_completed,task_skipped,pushbackormax_steps.summaryis a short human-readable description suitable for direct rendering;detailsis a kind-specific structured object for richer client-side rendering.
- reply_speech(session, message, audio_speed=None)[source]#
Send an audio reply to a specific user.
The text message is converted to speech and sent to the user. Before being sent, the audio is encoded as a Base64 string. This must be taken into account when decoding the audio on the client side.
- Parameters:
- reply_task_list_update(session, tasks)[source]#
Send a snapshot of the reasoning state’s task list to a specific user.
Emitted alongside (not in place of) the existing
task_added/task_completed/task_skippedreasoning step events, so a client can render a live “task panel” without having to reconstruct the list from the step stream. Thereasoning_started/reasoning_finishedreasoning steps bracket the lifetime of this panel.Persisted in the dedicated
reasoning_steptable (kind=task_list_update) — not in the chat table — so it does not pollute chat history retrieval.
- reply_ui(session, ui)[source]#
Send a GUI model reply to a specific user.
The GUI model is serialized to JSON before being sent. It can be used to dynamically render a user interface on the client side.
- Parameters:
session (Session) – the user session
ui (GUIModel) – the GUI model to send to the user