reasoning#
Streamlit UI rendering and aggregation for the reasoning extension.
The Streamlit chat client receives AGENT_REPLY_REASONING_STEP and
AGENT_REPLY_TASK_LIST_UPDATE payloads from the WebSocket as the
predefined reasoning state runs. Rather than rendering each step as its
own chat row (which floods the UI), this module folds them into a single
synthetic REASONING_TRACE message in the chat history and renders it
as one collapsible expander with a task panel — mirroring the React UI in
the BESSER-Agentic-Framework-UI repo.
Two halves:
append_reasoning_step()andapply_task_list_update()— called frombaf.platforms.websocket.streamlit_ui.websocket_callbacks’son_message. They mutate the most recent in-progress trace inHISTORY(or open a new one) and trigger a Streamlit rerun.write_reasoning_trace()andis_empty_trace()— called frombaf.platforms.websocket.streamlit_ui.chat’swrite_messageto render the aggregated trace as a single expander.
The module is self-contained: no public API leaks back to the rest of the streamlit_ui package, so the existing chat/websocket code stays otherwise unchanged.
- baf.platforms.websocket.streamlit_ui.reasoning._is_task_only_tool_call(step)[source]#
True if a
llm_tool_callsevent invokes only built-in task tools.
- baf.platforms.websocket.streamlit_ui.reasoning._last_in_progress_trace(history)[source]#
Return the most recent in-progress
MessageType.REASONING_TRACEmessage inhistory, orNoneif every trace is closed (or none exists yet). Walks from the end so the latest open trace is found first.
- baf.platforms.websocket.streamlit_ui.reasoning._visible_steps(steps)[source]#
Filter out bracket markers, task events, and task-only tool calls.
- baf.platforms.websocket.streamlit_ui.reasoning.append_reasoning_step(streamlit_session, step)[source]#
Fold a streamed reasoning step into the active trace in HISTORY.
reasoning_started→ append a fresh REASONING_TRACE message within_progress=True.reasoning_finished→ append the bracket marker, flipin_progressto False so the UI collapses the expander.Any other step → append to the currently-open trace.
Defensive fallback: if no open trace exists when a non-bracket step arrives (history replay, reconnect, etc.) a new trace is created so the step is never silently dropped.
- baf.platforms.websocket.streamlit_ui.reasoning.apply_task_list_update(streamlit_session, tasks)[source]#
Replace the task snapshot of the active trace.
Each task_list_update payload carries the full current snapshot, so the UI just swaps the trace’s
taskslist rather than diffing. Defensive: opens a fresh trace if none is currently in progress.
- baf.platforms.websocket.streamlit_ui.reasoning.is_empty_trace(content)[source]#
True when a reasoning trace has no observable steps and no tasks.
Empty traces typically result from a pure LLM-only reply that did not invoke any tools or plan any tasks — rendering them would just produce an empty chat bubble.
- baf.platforms.websocket.streamlit_ui.reasoning.write_reasoning_trace(content)[source]#
Render an aggregated reasoning trace as a single collapsible expander.
While
in_progressis True the expander is open by default so the user can watch the agent think.Once the loop finishes (
in_progressflipped to False) the expander defaults to collapsed; the user can re-open it for inspection.Steps are grouped by their
stepnumber so each loop iteration shows a singleSTEP Nheader. Task-related events are omitted from the step list — the task panel below is the source of truth for task progress.The task panel renders the live snapshot with colored status boxes.