session#
- class besser.agent.core.session.Session(session_id, agent, platform)[source]#
Bases:
object
A user session in an agent execution.
When a user starts interacting with an agent, a session is assigned to him/her to store user related information, such as the current state of the agent, the conversation history, the detected intent with its parameters or any user’s private data. A session can be accessed from the body of the states to read/write user information.
- Parameters:
- _event#
The last event to trigger a transition.
- Type:
Any or None
- _events#
The queue of received external events to process
- Type:
deque[Any]
- _event_loop#
The loop in charge of managing incoming events
- _event_thread#
The thread where the event loop is running
- Type:
- _timer_handle#
Handler of scheduled calls on the event loop
- Type:
TimerHandle
- _agent_connections#
WebSocket client connections to other agent’s WebSocket platforms. These connections enable an agent to send messages to other agents.
- call_manage_transition()[source]#
Schedule the next call to manage_transition as soon as possible (cancelling the previously scheduled call).
- create_agent_connection(url)[source]#
Create a WebSocket connection to a specific WebSocket URL.
- Parameters:
url (str) – the WebSocket server’s URL
- delete(key)[source]#
Delete an entry of the session private data storage.
- Parameters:
key (str) – the entry key
- get(key)[source]#
Get an entry of the session private data storage.
- Parameters:
key (str) – the entry key
- Returns:
the entry value, or None if the key does not exist
- Return type:
Any
- manage_transition()[source]#
Evaluate the session’s current state transitions, where one could be satisfied and triggered.
- move(transition)[source]#
Move to another agent state.
- Parameters:
transition (Transition) – the transition that points to the agent state to move
- reply(message)[source]#
An agent message (usually a reply to a user message) is sent to the session platform to show it to the user.
- Parameters:
message (str) – the agent reply
- run_rag(message, llm_prompt=None, llm_name=None, k=None, num_previous_messages=None)[source]#
Run the RAG engine.
- Parameters:
message (str) – the input query for the RAG engine
llm_prompt (str) – the prompt containing the instructions for the LLM to generate an answer from the retrieved content. If none is provided, the RAG’s default value will be used
llm_name (str) – the name of the LLM to use. If none is provided, the RAG’s default value will be used
k (int) – number of chunks to retrieve from the vector store. If none is provided, the RAG’s default value will be used
num_previous_messages (int) – number of previous messages of the conversation to add to the prompt context. If none is provided, the RAG’s default value will be used. Necessary a connection to
MonitoringDB
- Returns:
the answer generated by the RAG engine
- Return type:
- save_message(message)[source]#
Save a message in the dedicated chat DB
- Parameters:
message (Message) – the message to save
- send_message_to_websocket(url, message)[source]#
Send a message to a WebSocket Server, generally used to send a message to an agent through the WebSocket platform.
- Parameters:
url (str) – the WebSocket URL (i.e., the target agent’s WebSocket platform URL)
message (Any) – the message to send to the WebSocket server