agent_gui#

AgentGUI: BAF’s interface to besser’s GUIModel, with optional-dependency handling.

class baf.core.gui.agent_gui.AgentGUI(model, gui_id=None, persist=True, width=None)[source]#

Bases: object

BAF’s interface to besser’s GUIModel, with helper methods for common GUI operations.

Handles the case where besser is not installed: all methods log a warning and return None/False instead of raising an error. When besser is installed, attribute access is transparently delegated to the inner model so that existing code that uses gui.modules, gui.name, etc. continues to work unchanged.

Parameters:
  • model – the GUIModel instance to wrap, or None.

  • gui_id – identifier for the AgentGUI.

  • persist – whether to store GUI updates in the session or not. Defaults to true

_model#

the inner GUIModel, or None when besser is not installed or no model has been set.

_id#

identifier for the AgentGUI.

_persist#

whether to store GUI updates in the session or not. Defaults to true

_collect_matching(elements, field, value, results)[source]#

Recursively collect into results every element where getattr(el, field) == value.

add_component(component, parent_id=None, screen_name=None)[source]#

Add a component to the GUI model.

Resolution order:

  1. If parent_id is given, the component is added to the container that has that component_id (must be a container with view_elements).

  2. If screen_name is given, the component is added to the top-level view_elements of the named screen.

  3. Otherwise the component is added to the main screen (is_main_page=True), or to the first screen when no main screen exists.

Parameters:
  • component – the ViewElement to add.

  • parent_id (str | None) – component_id of the target container.

  • screen_name (str | None) – name of the target screen (used when parent_id is not given).

Returns:

True if the component was added, False otherwise.

Return type:

bool

deep_copy()[source]#

Return a deep copy of this AgentGUI and its inner model.

Returns:

a new instance wrapping a deep-copied model.

Return type:

AgentGUI

find_component(field, value)[source]#

Find the first component in the model where getattr(component, field) == value.

Recursively searches through all modules → screens → containers.

Parameters:
  • field (str) – the attribute name to match (e.g. 'component_id', 'name', 'content').

  • value – the value to look for.

Returns:

The first matching ViewElement, or None if not found.

find_components(field, value)[source]#

Find all components in the model where getattr(component, field) == value.

Recursively searches through all modules → screens → containers.

Parameters:
  • field (str) – the attribute name to match (e.g. 'component_id', 'name', 'content').

  • value – the value to look for.

Returns:

all matching ViewElement instances (empty list if none found).

Return type:

list

get_screen(screen_name=None)[source]#

Retrieve a screen by name, or the main screen when no name is given.

Falls back to the first screen when there is no screen marked as main.

Parameters:

screen_name (str | None) – the screen name to look for, or None to get the main/first screen.

Returns:

The Screen, or None if not found.

property id#

Unique identifier for this GUI reply message.

property model#

The underlying GUIModel instance, or None.

property persist#

If True, input values from GUI events for this component are persisted in the session’s gui_inputs.

Type:

bool

update_component_by_id(component_id, **kwargs)[source]#

Update attributes of a component located by its component_id.

Parameters:
  • component_id (str) – identifies the component to update.

  • **kwargs – attribute names and their new values.

Returns:

The updated component if found, or None.

property width#

CSS width applied to the GUI bubble in chat mode (e.g. ‘600px’, ‘80%’). Overrides the default 78% max-width cap. None means use the default.

Type:

str | None