Skip to content

Event handling

logger = logging.getLogger(__name__) module-attribute

AppPageEvents

Bases: AllLoaders, MyState

Collection of the event handlers used in the page.

Anything beyond very basic interface updates (i.e. any business logic) should be handled by calling an appropriate domain level handler (passing an object that minimally implements an update method).

assistant_selector class-attribute

handle_cancel() async

handle_load_conversation(selected_conversation_uid) async

Load an existing conversation.

  • Sets message history
  • Sets default assistant

handle_new_conversation() async

Set to new conversation.

Basically reset the page variables like it's an initial load. Nothing needs to be handled in business logic here. Handled on first submit.

handle_on_load() async

handle_resume() async

handle_submit() async

register_assistant_selector(assistant_selector) classmethod

AppPageStates

Bases: SimpleNamespace

States used in this page.

Note

For the frontend and backend states, the state classes are generated dynamically using type() The type hint for the Vars is used because that's how they behave at runtime (even though they are technically class objects). This is a quirk of reflex.

For each frontend var, it creates a new class that inherits from the vars class and rx.State to make a stateful instance (reflex handles the state management). Collected together in a SimpleNamespace to avoid having the states be directly linked to each other in a way that would result in them being loaded in one block by reflex.

assistant_selection_state = assistant_selector.State class-attribute instance-attribute

assistant_selector = AssistantCombinedSelectComponent.create(id_user='main_user_assistant_selector', id_global='main_global_assistant_selector', options_loader=AllLoaders.get_assistant_options_loader) class-attribute instance-attribute

backend_state = BackendState class-attribute instance-attribute

control_panel_state = ControlPanelState class-attribute instance-attribute

conversation_list_loader_component = ConversationListLoaderComponent.create(mode='vstack', on_select_handlers=[event_handler.handle_load_conversation], max_num_conversations_to_load=50) class-attribute instance-attribute

conversation_list_loader_state = conversation_list_loader_component.State class-attribute instance-attribute

event_handler = AppPageEvents class-attribute instance-attribute

on_load_events = [conversation_list_loader_state.load_conversation_list_handler, assistant_selection_state.handle_load, event_handler.handle_on_load] class-attribute instance-attribute

previous_messages_state = PreviousMessagesState class-attribute instance-attribute

run_message_state = RunMessagesState class-attribute instance-attribute

submission_state = SubmissionState class-attribute instance-attribute

ApplyErrorUpdateOnError

state_updater = state_updater instance-attribute

user_input = user_input instance-attribute

__aenter__() async

__aexit__(exc_type, exc_val, exc_tb) async

__init__(state_updater, user_input)

AssistantRunUpdatable

Bases: AbstractFrontendUpdatable

update_mapping = {ConversationUpdate: [BackendState], RunInitializedUpdate: [RunMessagesState, SubmissionState], RunPartialUpdate: [ResumeInterruptedRunState], RunFinishedUpdate: [RunMessagesState, PreviousMessagesState, BackendState], LanggraphUpdate: [], StreamUpdate: [RunMessagesState], GraphStepUpdate: [RunMessagesState, GraphInfoState], ToolCallStreamUpdate: [RunMessagesState]} class-attribute

BackendState

Bases: HasUpdatableVars, State

Vars related to the backend processing.

I.e. Not displayed to user or directly interacted with via interface. Handled by Controller but persisted via reflex. Should only include basic data types (str, int, bool, etc.) and keys/ids of any more complex data that can be stored in redis via .load/.save methods, or persisted in db directly via backend functions.

conversation_uid = None class-attribute instance-attribute

conversation_version = 0 class-attribute instance-attribute

running = False class-attribute instance-attribute

update(update) async

DebugState

Bases: MyState

count = 0 class-attribute instance-attribute

log = rx.field(['log initialized', 'first log message']) class-attribute instance-attribute

visible = False class-attribute instance-attribute

add_padding_and_scroll() async

increment() async

info(message)

make_error() async

remove_padding_and_scroll() async

set_interrupt_with_tool_calls() async

toggle_running() async

toggle_thinking() async

toggle_visible()

GithubApiKeyUpdaterState

Bases: MyState

on_delete() async

on_update(data) async

LoadConversationUpdatable

Bases: AbstractFrontendUpdatable

update_mapping = {LoadConversationUpdate: [PreviousMessagesState, BackendState]} class-attribute

SingleAgentRunContextProvider dataclass

Bases: ProvidesRunContextProtocol

backend_state = BackendState class-attribute instance-attribute

state_updater instance-attribute

__init__(*, backend_state=BackendState, state_updater)

run_context() async

Context manager to ensure only one agent running.

First checks whether the states .running attribute is True, then sets it to True before yielding, then sets back to False after the yield.

debug_log_info(state, message) async