payload#

class baf.platforms.payload.Payload(action, message=None, history=False, timestamp=None, message_id=None)[source]#

Bases: object

Represents a payload object used for encoding and decoding messages between an agent and any other external agent.

static decode(payload_str)[source]#

Decode a JSON payload string into a Payload object.

Parameters:

payload_str (str or dict) – A JSON-encoded payload string.

Returns:

A Payload object if the decoding is successful, None otherwise.

Return type:

Payload or None

class baf.platforms.payload.PayloadAction(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]#

Bases: Enum

Enumeration of the different possible actions embedded into a Payload.

AGENT_REPLY_AUDIO = 'agent_reply_audio'#

Indicates that the payload’s purpose is to send an agent reply containing an audio, which is a dictionary containing the audio data (as a base 64 String) and the metadata to reconstruct the audio array, composed of sample_rate, dtype and shape.

Type:

PayloadAction

AGENT_REPLY_DF = 'agent_reply_dataframe'#

Indicates that the payload’s purpose is to send an agent reply containing a pandas.DataFrame object.

Type:

PayloadAction

AGENT_REPLY_FILE = 'agent_reply_file'#

Indicates that the payload’s purpose is to send an agent reply containing a file.File object.

Type:

PayloadAction

AGENT_REPLY_GUI = 'agent_reply_gui'#

Indicates that the payload’s purpose is to send an agent reply containing a GUI, which is based on the GUI metamodel in besser.BUML.metamodel.gui.graphical_ui.GUIModel.

Type:

PayloadAction

AGENT_REPLY_GUI_UPDATE = 'agent_reply_gui_update'#

Indicates that the payload’s purpose is to push an update to the session’s current GUI model. The message is the full updated GUI JSON. Clients should replace their current GUI state with the new one.

Type:

PayloadAction

AGENT_REPLY_HTML = 'agent_reply_html'#

Indicates that the payload’s purpose is to send an agent reply containing a str object in HTML format.

Type:

PayloadAction

AGENT_REPLY_IMAGE = 'agent_reply_image'#

Indicates that the payload’s purpose is to send an agent reply containing a file.File object, specifically an image.

Type:

PayloadAction

AGENT_REPLY_LOCATION = 'agent_reply_location'#

Indicates that the payload’s purpose is to send an agent reply containing a location, which is a dictionary composed by a latitude and a longitude.

Type:

PayloadAction

AGENT_REPLY_MARKDOWN = 'agent_reply_markdown'#

Indicates that the payload’s purpose is to send an agent reply containing a str object in Markdown format.

Type:

PayloadAction

AGENT_REPLY_OPTIONS = 'agent_reply_options'#

Indicates that the payload’s purpose is to send an agent reply containing a list of strings, where the user should select 1 of them.

Type:

PayloadAction

AGENT_REPLY_PLOTLY = 'agent_reply_plotly'#

Indicates that the payload’s purpose is to send an agent reply containing a plotly.graph_objs.Figure object.

Type:

PayloadAction

AGENT_REPLY_RAG = 'agent_reply_rag'#

Indicates that the payload’s purpose is to send an agent reply containing a RAG (Retrieval Augmented Generation) answer, which contains an LLM-generated answer and a set of documents the LLM used as context (see baf.nlp.rag.rag.RAGMessage).

Type:

PayloadAction

AGENT_REPLY_REASONING_STEP = 'agent_reply_reasoning_step'#

Indicates that the payload’s purpose is to send an intermediate step of a reasoning state — an LLM text turn, a tool call, a tool result, a task list change, an orchestrator push-back, etc. The message is a dict with the shape {"kind": str, "step": int, "summary": str, "details": dict}. See baf.library.state.reasoning_state_library.reasoning_body() for the full set of emitted kinds.

Type:

PayloadAction

AGENT_REPLY_STR = 'agent_reply_str'#

Indicates that the payload’s purpose is to send an agent reply containing a str object.

Type:

PayloadAction

AGENT_REPLY_TASK_LIST_UPDATE = 'agent_reply_task_list_update'#

Indicates that the payload’s purpose is to send a snapshot of the reasoning state’s task list. Emitted on every task list mutation (add / complete / skip) alongside the corresponding reasoning step events, so a UI can show the live task list as a separate panel without having to reconstruct it from the step stream. The message is a list of dicts: [{"id": int, "description": str, "status": str, "result": str}, ...]. The reasoning_started / reasoning_finished events bracket the lifetime of this list.

Type:

PayloadAction

FETCH_USER_MESSAGES = 'fetch_user_messages'#

Request to fetch old messages for a given user.

Type:

PayloadAction

RESET = 'reset'#

Use the WebSocketPlatform on this agent.

Type:

PayloadAction

USER_FILE = 'user_file'#

Indicates that the payload’s purpose is to send a user file.

Type:

PayloadAction

USER_GUI_EVENT = 'user_gui_event'#

Indicates a user interaction event sent from the GUI frontend. The message is a dict with at minimum an elementId field and an action field (e.g. {"elementId": "btn1", "action": "onClick"}).

Type:

PayloadAction

USER_MESSAGE = 'user_message'#

Indicates that the payload’s purpose is to send a user message.

Type:

PayloadAction

USER_SET_VARIABLE = 'user_set_variable'#

Indicates that the user intends to set a session variable. The payload must include a dictionary containing the variable name and its value, sent as a Payload message.

Type:

PayloadAction

USER_VOICE = 'user_voice'#

Indicates that the payload’s purpose is to send a user audio.

Type:

PayloadAction

class baf.platforms.payload.PayloadEncoder(*, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, default=None)[source]#

Bases: JSONEncoder

Encoder for the Payload class.

Example

import json
encoded_payload = json.dumps(payload, cls=PayloadEncoder)
default(obj)[source]#

Returns a serializable object for a Payload

Parameters:

obj – the object to serialize

Returns:

the serialized payload

Return type:

dict