Agent model¶
- class besser.BUML.metamodel.state_machine.agent.Agent(name: str)[source]¶
Bases:
StateMachineA agent model.
- Parameters:
name (str) – the agent name
- visibility¶
Inherited from StateMachine, determines the kind of visibility of the agent (public as default).
- Type:
- states¶
Inherited from StateMachine, the states of the agent
- Type:
- properties¶
Inherited from StateMachine, the configuration properties of the agent.
- Type:
- default_ic_config¶
the intent classifier configuration used by default for the agent states.
- global_initial_states¶
List of tuples of initial global states and their triggering intent
- Type:
- _LLM_PROVIDERS: dict[str, type] = {'huggingface': <class 'besser.BUML.metamodel.state_machine.agent.LLMHuggingFace'>, 'huggingface_api': <class 'besser.BUML.metamodel.state_machine.agent.LLMHuggingFaceAPI'>, 'openai': <class 'besser.BUML.metamodel.state_machine.agent.LLMOpenAI'>, 'replicate': <class 'besser.BUML.metamodel.state_machine.agent.LLMReplicate'>}¶
- _abc_impl = <_abc._abc_data object>¶
- _validate_llm_references(errors: list[str], warnings: list[str]) None[source]¶
Validate that every
llm_namereference resolves to a registered LLM.
- _validate_reasoning_primitives(errors: list[str], warnings: list[str]) None[source]¶
Validate the reasoning extension’s metamodel constraints.
- _validate_state_intent_name_collisions(errors: list[str])[source]¶
Ensure state names and intent names do not overlap in the same agent.
- _validate_transition_intent_references(errors: list[str])[source]¶
Ensure intent-matching transitions only reference intents defined in the agent.
- add_reasoning_state(state: ReasoningState) ReasoningState[source]¶
Add a pre-built
ReasoningStateto the agent’s state list.
- add_tool(tool: Tool) Tool[source]¶
Add a pre-built
Toolto the agent.Mirrors
add_intent()— the caller constructs the wrapper, this method registers it. Usenew_tool()to skip the explicitTool(...)construction.
- new_entity(name: BaseEntityImpl, base_entity: bool = False, entries: dict[str, list[str]] = None, description: str = None) Entity[source]¶
Create a new entity in the agent.
- Parameters:
- Returns:
the entity
- Return type:
- new_intent(name: str, training_sentences: list[str] = None, parameters: list[IntentParameter] = None, description: str = None) Intent[source]¶
Create a new intent in the agent.
- Parameters:
- Returns:
the intent
- Return type:
- new_llm(name: str, provider: str = 'openai', parameters: dict | None = None, num_previous_messages: int = 1, global_context: str | None = None) LLMWrapper[source]¶
Register an LLM on the agent and return the
LLMWrapperinstance.providerselects the concrete subclass:openai→LLMOpenAI,huggingface→LLMHuggingFace,huggingface_api→LLMHuggingFaceAPI,replicate→LLMReplicate. Names must be unique on the agent so other elements (reasoning states, RAG, replies, intent classifiers) can reference the LLM byllm_name.
- new_rag(name: str, vector_store: RAGVectorStore, splitter: RAGTextSplitter, llm_name: str, llm_prompt: str | None = None, k: int = 4, num_previous_messages: int = 0) RAG[source]¶
Register a Retrieval-Augmented Generation configuration on the agent.
- new_reasoning_state(name: str, llm: str | None = None, initial: bool = False, max_steps: int = 8, enable_task_planning: bool = True, stream_steps: bool = True, system_prompt: str | None = None, fallback_message: str | None = None) ReasoningState[source]¶
Create a new
ReasoningStateon the agent.Mirrors
new_state()for non-reasoning states. Thellmargument may be omitted during incremental model construction (e.g. while the diagram is being built); it must be set before code generation.
- new_skill(name: str, content: str = '', description: str | None = None) Skill[source]¶
Build a
Skilland register it on the agent.
- new_state(name: str, initial: bool = False, ic_config: IntentClassifierConfiguration = None) AgentState[source]¶
Create a new state in the agent.
- Parameters:
name (str) – the state name. It must be unique in the agent.
initial (bool) – whether the state is initial or not. A agent must have 1 initial state.
ic_config (IntentClassifierConfiguration or None) – the intent classifier configuration for the state. If None is provided, the agent’s default one will be assigned to the state.
- Returns:
the state
- Return type:
- new_tool(name: str, description: str = '', code: str = '') Tool[source]¶
Build a
Tooland register it on the agent.
- new_workspace(name: str, path: str = '', description: str | None = None, writable: bool = True, max_read_bytes: int = 200000) Workspace[source]¶
Build a
Workspaceand register it on the agent.
- set_default_llm(name: str) None[source]¶
Mark the LLM with the given name as the agent’s default.
The default LLM is the one used by every consumer (
LLMReply,DBReply, RAG, intent classifier) that does not specify its ownllm_name. The named LLM must already be registered on the agent vianew_llm().
- use_telegram_platform() TelegramPlatform[source]¶
Use the TelegramPlatform on this agent.
- Returns:
the telegram platform
- Return type:
- use_websocket_platform() WebSocketPlatform[source]¶
Use the WebSocketPlatform on this agent.
- Returns:
the websocket platform
- Return type:
- class besser.BUML.metamodel.state_machine.agent.AgentReply(message: str)[source]¶
Bases:
ActionPrimitive action that represents sending a reply message.
- Parameters:
message (Expression) – The message to send (can be Literal, VariableRef, ParameterRef, or any Expression)
- message¶
The message expression
- Type:
Expression
- _abc_impl = <_abc._abc_data object>¶
- class besser.BUML.metamodel.state_machine.agent.AgentSession[source]¶
Bases:
SessionA user session in a agent execution.
When a user starts interacting with a state machine, a session is assigned to him/her to store user related information, such as the current state of the agent or any custom variable. A session can be accessed from the body of the states to read/write user information. If a state machine does not have the concept of ‘users’ (i.e., there are no concurrent executions of the state machine, but a single one) then it could simply have 1 unique session.
- id¶
Inherited from Session, the session id, which must unique among all state machine sessions
- Type:
- current_state¶
Inherited from Session, the current state in the state machine for this session
- Type:
- predicted_intent¶
The last predicted intent for this session
- predicted_intent: IntentClassifierPrediction¶
- class besser.BUML.metamodel.state_machine.agent.AgentState(agent: Agent, name: str, initial: bool = False, ic_config: IntentClassifierConfiguration = None)[source]¶
Bases:
StateA agent state.
- Parameters:
- visibility¶
Inherited from State, determines the kind of visibility of the state (public as default).
- Type:
- sm¶
Inherited from State, the state machine the state belongs to
- Type:
- transitions¶
Inherited from State, the state’s transitions to other states
- Type:
- _transition_counter¶
Inherited from State, count the number of transitions of this state. Used to name the transitions.
- Type:
- _abc_impl = <_abc._abc_data object>¶
- go_to(dest: AgentState) None[source]¶
Create a new auto transition on this state.
This transition needs no event to be triggered, which means that when the agent moves to a state that has an auto transition, the agent will move to the transition’s destination state unconditionally without waiting for user input. This transition cannot be combined with other transitions.
- Parameters:
dest (AgentState) – the destination state
- ic_config: IntentClassifierConfiguration¶
- set_global(intent: Intent)[source]¶
Set state as globally accessible state.
- Parameters:
intent (Intent) – the intent that should trigger the jump to the global state
- when_condition(condition: Condition) TransitionBuilder[source]¶
Start the definition of a transition triggered by a custom condition.
- Parameters:
condition (Condition) – Condition instance evaluated by the transition.
- Returns:
the transition builder
- Return type:
- when_event(event: Event) TransitionBuilder[source]¶
Start the definition of a transition triggered by a custom event.
- Parameters:
event (Event) – Event instance used to trigger the transition.
- Returns:
the transition builder
- Return type:
- when_file_received(allowed_types: list[str] = None) TransitionBuilder[source]¶
Start the definition of a “file received” transition on this state.
- when_intent_matched(intent: Intent) TransitionBuilder[source]¶
Start the definition of an “intent matching” transition on this state.
- Parameters:
intent (Intent) – the target intent for the transition to be triggered
- Returns:
the transition builder
- Return type:
- when_no_intent_matched() TransitionBuilder[source]¶
- when_variable_matches_operation(var_name: str, operation: Callable[[Any, Any], bool], target: Any) TransitionBuilder[source]¶
Start the definition of a “variable matching operator” transition on this state.
This transition evaluates if (variable operator target_value) is satisfied. For instance, “age > 18”.
- Parameters:
var_name (str) – the name of the variable to evaluate. The variable must exist in the user session
operation (Callable[[Any, Any], bool]) – the operation to apply to the variable and the target value. It gets as arguments the variable and the target value, and returns a boolean value
target (Any) – the target value to compare with the variable
- Returns:
the transition builder
- Return type:
- class besser.BUML.metamodel.state_machine.agent.Auto[source]¶
Bases:
ConditionThis condition always returns True.
- type¶
Inherited from Event, represents the type of the event.
- Type:
Type
- parameters¶
Inherited from Event, the set of parameters for the event.
- Type:
set[structural.Parameter]
- owner¶
Inherited from Event, the type that owns the property.
- Type:
Type
- _abc_impl = <_abc._abc_data object>¶
- class besser.BUML.metamodel.state_machine.agent.BaseEntity(name: BaseEntityImpl)[source]¶
Bases:
EntityPredefined entities, which are provided by the agent framework and do not need the user to define them.
- Parameters:
name (BaseEntityImpl) – the entity’s name
- _abc_impl = <_abc._abc_data object>¶
- class besser.BUML.metamodel.state_machine.agent.BaseEntityImpl(*values)[source]¶
Bases:
EnumAll the available base entities.
- any = 'any_entity'¶
- datetime = 'datetime_entity'¶
- number = 'number_entity'¶
- class besser.BUML.metamodel.state_machine.agent.CustomEntity(name: str, description: str, entries: list[EntityEntry])[source]¶
Bases:
EntityAn entity with custom values.
- Parameters:
name (str) – the entity’s name
entries (list[EntityEntry]) – the entity entries. If base_entity, there are no entries (i.e. None)
description (str) – a description of the entity, optional
- entries¶
the entity entries
- Type:
- _abc_impl = <_abc._abc_data object>¶
- entries: list[EntityEntry]¶
- class besser.BUML.metamodel.state_machine.agent.DBReply(db_selection_type: str = 'default', db_custom_name: str | None = None, db_query_mode: str = 'llm_query', db_operation: str = 'any', db_sql_query: str | None = None, llm_name: str | None = None)[source]¶
Bases:
ActionPrimitive action that represents fetching information from a database.
- Parameters:
db_selection_type (str) – Database selection mode. Supported values are
defaultandcustom.db_custom_name (str, optional) – Custom database identifier used when
db_selection_typeiscustom.db_query_mode (str) – Query execution mode. Supported values are
llm_queryandsql.db_operation (str) – SQL operation restriction. Supported values are
any,select,insert,updateanddelete.db_sql_query (str, optional) – SQL query to run when
db_query_modeissql.
- db_selection_type¶
Whether the default application database or a named custom database is used.
- Type:
- VALID_OPERATIONS = {'any', 'delete', 'insert', 'select', 'update'}¶
- VALID_QUERY_MODES = {'llm_query', 'sql'}¶
- VALID_SELECTION_TYPES = {'custom', 'default'}¶
- _abc_impl = <_abc._abc_data object>¶
- class besser.BUML.metamodel.state_machine.agent.DummyEvent[source]¶
Bases:
EventRepresents a placeholder event.
- _abc_impl = <_abc._abc_data object>¶
- class besser.BUML.metamodel.state_machine.agent.Entity(name: str)[source]¶
Bases:
NamedElementEntities are used to specify the type of information to extract from user inputs. These entities are embedded in intent parameters.
- Parameters:
name (str) – Inherited from NamedElement, the entity’s name
- _abc_impl = <_abc._abc_data object>¶
- class besser.BUML.metamodel.state_machine.agent.EntityEntry(value: str, synonyms: list[str])[source]¶
Bases:
objectEach one of the entries an entity consists of.
- class besser.BUML.metamodel.state_machine.agent.File(file_name: str = None, file_type: str = None, file_base64: str = None, file_path: str = None, file_data: bytes = None)[source]¶
Bases:
objectA representation of files sent and received by a agent.
Files are used to encapsulate information about the files exchanged in a agent conversation. They include attributes such as the file’s name, type, and base64 representation. Note that at least one of path, data or base64 need to be set.
- Parameters:
- class besser.BUML.metamodel.state_machine.agent.FileTypeMatcher(allowed_types: list[str] = None)[source]¶
Bases:
ConditionThis event only returns True if a user just sent a file.
- type¶
Inherited from Event, represents the type of the event.
- Type:
Type
- parameters¶
Inherited from Event, the set of parameters for the event.
- Type:
set[structural.Parameter]
- owner¶
Inherited from Event, the type that owns the property.
- Type:
Type
- _abc_impl = <_abc._abc_data object>¶
- allowed_types: list[str] or str¶
- class besser.BUML.metamodel.state_machine.agent.Intent(name: str, training_sentences: list[str] = None, parameters: list[IntentParameter] = None, description: str = None)[source]¶
Bases:
NamedElementIntents define the intentions or goals the user can express to a agent.
An intent is defined by a set of training sentences representing the different ways a user could express an intention (e.g. “Hi”, “Hello” for a Greetings intent) and/or with a description.
Intents can also define parameters that are filled with information extracted from the user input using entities.
- Parameters:
- parameters¶
The intent’s parameters
- Type:
- _abc_impl = <_abc._abc_data object>¶
- parameter(name: str, fragment: str, entity: Entity)[source]¶
Add a parameter to the list of intent parameters.
- parameters: list[IntentParameter]¶
- class besser.BUML.metamodel.state_machine.agent.IntentClassifierConfiguration[source]¶
Bases:
ABCThe Intent Classifier Configuration abstract class.
This configuration is assigned to a state, allowing the customization of its intent classifier.
This class serves as a template to implement intent classifier configurations for the different Intent Classifiers.
- _abc_impl = <_abc._abc_data object>¶
- class besser.BUML.metamodel.state_machine.agent.IntentClassifierPrediction(intent: Intent, score: float = None, matched_sentence: str = None, matched_parameters: list[MatchedParameter] = None)[source]¶
Bases:
objectThe prediction result of an Intent Classifier for a specific intent.
The intent classifier tries to determine the intent of a user message. For each possible intent, it will return an IntentClassifierPrediction containing the results, that include the probability itself and other information.
- Parameters:
intent (Intent) – the target intent of the prediction
score (float) – the probability that this is the actual intent of the user message
matched_sentence (str) – the sentence used in the intent classifier (the original user message is previously processed, is modified by the NER, etc.)
matched_parameters (list[MatchedParameter]) – the list of parameters (i.e. entities) found in the user message
- matched_sentence¶
The sentence used in the intent classifier (the original user message is previously processed, is modified by the NER, etc.)
- Type:
- matched_parameters¶
The list of parameters (i.e. entities) found in the user message
- Type:
- get_parameter(name: str) MatchedParameter[source]¶
Get a parameter from the intent classifier prediction.
- Parameters:
name (str) – the name of the parameter to get
- Returns:
the parameter if it exists, None otherwise
- Return type:
- matched_parameters: list[MatchedParameter]¶
- class besser.BUML.metamodel.state_machine.agent.IntentMatcher(intent: Intent)[source]¶
Bases:
ConditionThis event checks if 2 intents are the same (returning True, and False otherwise), used for intent matching checking.
- Parameters:
intent (Intent) – The reference intent to compare with the target intent
- type¶
Inherited from Event, represents the type of the event.
- Type:
Type
- parameters¶
Inherited from Event, the set of parameters for the event.
- Type:
set[structural.Parameter]
- owner¶
Inherited from Event, the type that owns the property.
- Type:
Type
- _abc_impl = <_abc._abc_data object>¶
- class besser.BUML.metamodel.state_machine.agent.IntentParameter(name: str, fragment: str, entity: Entity)[source]¶
Bases:
NamedElementThe intent parameter.
An intent parameter is composed by a name, a fragment and an entity. The fragment is the intent’s training sentence substring where an entity should be matched. E.g. in an intent with the training sentence “What is the weather in CITY?” we could define a parameter named “city” in the fragment “CITY” that should match with any value in the entity “city_entity” (previously defined)
- Parameters:
- visibility¶
Inherited from NamedElement, represents the visibility of the intent parameter.
- Type:
- fragment¶
The fragment the intent’s training sentences that is expected to match with the entity
- Type:
- _abc_impl = <_abc._abc_data object>¶
- class besser.BUML.metamodel.state_machine.agent.LLMChatReply(prompt: str | None = None, llm_name: str | None = None)[source]¶
Bases:
ActionPrimitive action that represents sending a chat-style reply using an LLM.
- Parameters:
prompt (str, optional) – Additional system prompt injected in the chat call.
llm_name (str, optional) – Name of the LLM (registered on the agent via
Agent.new_llm()) that should serve this reply.Nonelets the generator fall back to the agent’s default LLM.
- _abc_impl = <_abc._abc_data object>¶
- class besser.BUML.metamodel.state_machine.agent.LLMHuggingFace(agent: Agent, name: str, parameters: dict, num_previous_messages: int = 1, global_context: str = None)[source]¶
Bases:
LLMWrapperA HuggingFace LLM wrapper.
Normally, we consider an LLM in HuggingFace those models under the tasks
text-generationortext2text-generationtasks (more info), but there could be exceptions for other tasks (which have not been tested in this class).- Parameters:
agent (Agent) – the agent the LLM belongs to
name (str) – the LLM name
parameters (dict) – the LLM parameters
num_previous_messages (int) – for the chat functionality, the number of previous messages of the conversation to add to the prompt context (must be > 0).
global_context (str) – the global context to be provided to the LLM for each request
- num_previous_messages¶
for the chat functionality, the number of previous messages of the conversation to add to the prompt context (must be > 0).
- Type:
- _abc_impl = <_abc._abc_data object>¶
- class besser.BUML.metamodel.state_machine.agent.LLMHuggingFaceAPI(agent: Agent, name: str, parameters: dict, num_previous_messages: int = 1, global_context: str = None)[source]¶
Bases:
LLMWrapperA HuggingFace LLM wrapper for HuggingFace’s Inference API.
Normally, we consider an LLM in HuggingFace those models under the tasks
text-generationortext2text-generationtasks (more info), but there could be exceptions for other tasks (which have not been tested in this class).- Parameters:
agent (Agent) – the agent the LLM belongs to
name (str) – the LLM name
parameters (dict) – the LLM parameters
num_previous_messages (int) – for the chat functionality, the number of previous messages of the conversation to add to the prompt context (must be > 0).
global_context (str) – the global context to be provided to the LLM for each request
- num_previous_messages¶
for the chat functionality, the number of previous messages of the conversation to add to the prompt context (must be > 0).
- Type:
- _abc_impl = <_abc._abc_data object>¶
- class besser.BUML.metamodel.state_machine.agent.LLMIntentClassifierConfiguration(llm_suite: LLMSuite | None = None, parameters: dict = None, use_intent_descriptions: bool = False, use_training_sentences: bool = False, use_entity_descriptions: bool = False, use_entity_synonyms: bool = False, llm_name: str | None = None)[source]¶
Bases:
IntentClassifierConfigurationThe LLM Intent Classifier Configuration class.
- Parameters:
llm_suite (LLMSuite | None) – the service provider from which we will load/access the LLM. Optional when
llm_nameis provided — in that case the suite is resolved from the named LLM’s class.parameters (dict) – the LLM parameters (this will vary depending on the suite and the LLM)
use_intent_descriptions (bool) – whether to include the intent descriptions in the LLM prompt
use_training_sentences (bool) – whether to include the intent training sentences in the LLM prompt
use_entity_descriptions (bool) – whether to include the entity descriptions in the LLM prompt
use_entity_synonyms (bool) – whether to include the entity value’s synonyms in the LLM prompt
llm_name (str, optional) – Name of an LLM registered on the agent (via
Agent.new_llm()) that this classifier should use.
- use_training_sentences¶
whether to include the intent training sentences in the LLM prompt
- Type:
- _abc_impl = <_abc._abc_data object>¶
- class besser.BUML.metamodel.state_machine.agent.LLMOpenAI(agent: Agent, name: str, parameters: dict, num_previous_messages: int = 1, global_context: str = None)[source]¶
Bases:
LLMWrapperAn LLM wrapper for OpenAI’s LLMs through its API.
- Parameters:
agent (Agent) – the agent the LLM belongs to
name (str) – the LLM name
parameters (dict) – the LLM parameters
num_previous_messages (int) – for the chat functionality, the number of previous messages of the conversation to add to the prompt context (must be > 0).
global_context (str) – the global context to be provided to the LLM for each request
- _nlp_engine¶
the NLPEngine that handles the NLP processes of the agent the LLM belongs to
- Type:
NLPEngine
- num_previous_messages¶
for the chat functionality, the number of previous messages of the conversation to add to the prompt context (must be > 0).
- Type:
- _abc_impl = <_abc._abc_data object>¶
- class besser.BUML.metamodel.state_machine.agent.LLMReplicate(agent: Agent, name: str, parameters: dict, num_previous_messages: int = 1, global_context: str = None)[source]¶
Bases:
LLMWrapperAn LLM wrapper for Replicate’s LLMs through its API.
- Parameters:
agent (Agent) – the agent the LLM belongs to
name (str) – the LLM name
parameters (dict) – the LLM parameters
num_previous_messages (int) – for the chat functionality, the number of previous messages of the conversation to add to the prompt context (must be > 0)
global_context (str) – the global context to be provided to the LLM for each request
- _nlp_engine¶
the NLPEngine that handles the NLP processes of the agent the LLM belongs to
- Type:
NLPEngine
- num_previous_messages¶
for the chat functionality, the number of previous messages of the conversation to add to the prompt context (must be > 0)
- Type:
- _abc_impl = <_abc._abc_data object>¶
- class besser.BUML.metamodel.state_machine.agent.LLMReply(prompt: str | None = None, llm_name: str | None = None)[source]¶
Bases:
ActionPrimitive action that represents sending a reply using an LLM.
- Parameters:
prompt (str, optional) – Additional system prompt injected when calling the LLM.
llm_name (str, optional) – Name of the LLM (registered on the agent via
Agent.new_llm()) that should serve this reply.Nonelets the generator fall back to the agent’s default LLM.
- _abc_impl = <_abc._abc_data object>¶
- class besser.BUML.metamodel.state_machine.agent.LLMSuite(*values)[source]¶
Bases:
EnumEnumeration of the available LLM suites.
- huggingface = 'huggingface'¶
- huggingface_inference_api = 'huggingface-inference-api'¶
- openai = 'openai'¶
- replicate = 'replicate'¶
- class besser.BUML.metamodel.state_machine.agent.LLMWrapper(name: str, agent: Agent, parameters: dict, global_context: str = None)[source]¶
Bases:
ABCThe LLM Wrapper class.
- Parameters:
- _abc_impl = <_abc._abc_data object>¶
- chat(parameters: dict = None, system_message: str = None) str[source]¶
Make a prediction, i.e., generate an output.
This function can provide the chat history to the LLM for the output generation, simulating a conversation or remembering previous messages.
- predict(message: str, parameters: dict = None, system_message: str = None) str[source]¶
Make a prediction, i.e., generate an output.
- Parameters:
message (Any) – the LLM input text
session (Session) – the ongoing session, can be None if no context needs to be applied
parameters (dict) – the LLM parameters to use in the prediction. If none is provided, the default LLM parameters will be used
system_message (str) – system message to give high priority context to the LLM
- Returns:
the LLM output
- Return type:
- class besser.BUML.metamodel.state_machine.agent.MatchedParameter(name: str, value: object = None, info: dict = None)[source]¶
Bases:
objectA matched parameter in a user input (i.e. an entity that is found in a user message, which is an intent parameter).
- Parameters:
- class besser.BUML.metamodel.state_machine.agent.Platform[source]¶
Bases:
ABCThe platform abstract class.
A platform defines the methods the agent can use to interact with a particular communication channel (e.g. Telegram, Slack…) for instance, sending and receiving messages.
This class serves as a template to implement platforms.
- _abc_impl = <_abc._abc_data object>¶
- class besser.BUML.metamodel.state_machine.agent.RAG(name: str, agent: Agent, vector_store: RAGVectorStore, splitter: RAGTextSplitter, llm_name: str, llm_prompt: str | None = None, k: int = 4, num_previous_messages: int = 0)[source]¶
Bases:
NamedElementRetrieval-Augmented Generation configuration bound to an agent.
This models the minimal information required to generate code similar to:
vector_store = Chroma(...) splitter = RecursiveCharacterTextSplitter(...) rag = RAG( agent=agent, vector_store=vector_store, splitter=splitter, llm_name='gpt-4o-mini', llm_prompt='Use only trusted corpus facts.', k=4, num_previous_messages=0, )
- Parameters:
name (str) – Logical name of the RAG resource.
agent (Agent) – Agent that owns the configuration.
vector_store (RAGVectorStore) – Vector store definition.
splitter (RAGTextSplitter) – Chunking strategy definition.
llm_name (str) – Identifier of the LLM used to synthesize answers.
llm_prompt (str | None) – Optional prefix instructions injected before each RAG prompt.
k (int) – Number of chunks retrieved per question.
num_previous_messages (int) – Conversation context depth forwarded to the LLM.
- _abc_impl = <_abc._abc_data object>¶
- splitter: RAGTextSplitter¶
- vector_store: RAGVectorStore¶
- class besser.BUML.metamodel.state_machine.agent.RAGReply(rag_db_name: str, prompt: str | None = None)[source]¶
Bases:
ActionPrimitive action that represents sending a reply using a configured RAG pipeline.
- Parameters:
- _abc_impl = <_abc._abc_data object>¶
- class besser.BUML.metamodel.state_machine.agent.RAGTextSplitter(splitter_type: str, chunk_size: int, chunk_overlap: int)[source]¶
Bases:
objectDeclarative description of the chunking strategy used before indexing content.
- class besser.BUML.metamodel.state_machine.agent.RAGVectorStore(embedding_provider: str, embedding_parameters: dict | None = None, persist_directory: str | None = None)[source]¶
Bases:
objectDeclarative description of a vector store used by a RAG pipeline.
- Parameters:
- class besser.BUML.metamodel.state_machine.agent.ReasoningState(agent: Agent, name: str, llm: str | None = None, initial: bool = False, max_steps: int = 8, enable_task_planning: bool = True, stream_steps: bool = True, system_prompt: str | None = None, fallback_message: str | None = None)[source]¶
Bases:
AgentStateA predefined state whose body runs an LLM-driven plan→act→observe loop.
The body is supplied automatically at code-generation time (via the BAF
new_reasoning_state(...)factory) — this metamodel class only captures the configuration knobs that flow into that factory plus the LLM driving the loop.- Parameters:
agent (Agent) – the agent the state belongs to.
name (str) – the state name.
llm (str | None) – the name of the LLM that drives the reasoning loop. This is a free-form identifier — the state does not require the LLM to be registered on the agent’s
llmslist; code generation will instantiate an LLM with this name. May beNoneduring incremental model construction (e.g. while the diagram is being built).initial (bool) – whether this is the agent’s initial state.
max_steps (int) – maximum LLM turns per user message.
enable_task_planning (bool) – when True, expose the built-in
add_tasks/complete_task/skip_tasktools and require all tasks to be resolved before a final answer is accepted.stream_steps (bool) – forward intermediate step events to the session’s platform (if it supports
reply_reasoning_step).system_prompt (str | None) – optional override for the base system prompt.
Nonekeeps the BAF default.fallback_message (str | None) – optional override for the message sent when
max_stepsis exhausted.Nonekeeps the BAF default.
- _abc_impl = <_abc._abc_data object>¶
- set_body(body)[source]¶
Reasoning states use the predefined
new_reasoning_state()body — a hand-written body would be ignored at generation time.
- class besser.BUML.metamodel.state_machine.agent.ReceiveFileEvent(file: File = None)[source]¶
Bases:
EventEvent for receiving files.
- Parameters:
- _abc_impl = <_abc._abc_data object>¶
- class besser.BUML.metamodel.state_machine.agent.ReceiveJSONEvent(payload: dict = None)[source]¶
Bases:
ReceiveMessageEventEvent for receiving JSON messages.
- Parameters:
- _abc_impl = <_abc._abc_data object>¶
- class besser.BUML.metamodel.state_machine.agent.ReceiveMessageEvent(message: str)[source]¶
Bases:
EventThis event checks if a message is received from the user.
- Parameters:
message (str) – The message to be checked
- type¶
Inherited from Event, represents the type of the event.
- Type:
Type
- parameters¶
Inherited from Event, the set of parameters for the event.
- Type:
set[structural.Parameter]
- owner¶
Inherited from Event, the type that owns the property.
- Type:
Type
- _abc_impl = <_abc._abc_data object>¶
- class besser.BUML.metamodel.state_machine.agent.ReceiveTextEvent(text: str = None)[source]¶
Bases:
ReceiveMessageEventEvent for receiving text messages. Supports intent prediction.
- Parameters:
- predicted_intent¶
the predicted intent for the event message
- _abc_impl = <_abc._abc_data object>¶
- predicted_intent: IntentClassifierPrediction¶
- class besser.BUML.metamodel.state_machine.agent.SimpleIntentClassifierConfiguration(num_words: int = 1000, num_epochs: int = 300, embedding_dim: int = 128, input_max_num_tokens: int = 15, discard_oov_sentences: bool = True, check_exact_prediction_match: bool = True, activation_last_layer: str = 'sigmoid', activation_hidden_layers: str = 'tanh', lr: float = 0.001)[source]¶
Bases:
IntentClassifierConfigurationThe Simple Intent Classifier Configuration class.
- Parameters:
num_words (int) – Max num of words to keep in the index of words
num_epochs (int) – Number of epochs to be run during training
embedding_dim (int) – Number of embedding dimensions to be used when embedding the words
input_max_num_tokens (int) – Max length for the vector representing a sentence
discard_oov_sentences (bool) – whether to automatically assign zero probabilities to sentences with all tokens being oov ones or not
check_exact_prediction_match (bool) – Whether to check for exact match between the sentence to predict and one of the training sentences or not
activation_last_layer (str) – The activation function of the last layer
activation_hidden_layers (str) – The activation function of the hidden layers
lr (float) – Learning rate for the optimizer
- discard_oov_sentences¶
whether to automatically assign zero probabilities to sentences with all tokens being oov ones or not
- Type:
- check_exact_prediction_match¶
Whether to check for exact match between the sentence to predict and one of the training sentences or not
- Type:
The activation function of the hidden layers
- Type:
- _abc_impl = <_abc._abc_data object>¶
- class besser.BUML.metamodel.state_machine.agent.Skill(name: str, content: str = '', description: str | None = None)[source]¶
Bases:
NamedElementA markdown-based playbook the reasoning state injects into the system prompt.
- Parameters:
- _abc_impl = <_abc._abc_data object>¶
- class besser.BUML.metamodel.state_machine.agent.TelegramPlatform[source]¶
Bases:
PlatformThe Telegram Platform allows a agent to interact via Telegram.
- _abc_impl = <_abc._abc_data object>¶
- reply_file(session: AgentSession, file: File, message: str = None) None[source]¶
Send a file reply to a specific user
- Parameters:
session (AgentSession) – the user session
file (File) – the file to send
message (str, optional) – message to be attached to file, 1024 char limit
- reply_image(session: AgentSession, file: File, message: str = None) None[source]¶
Send an image reply to a specific user
- Parameters:
session (AgentSession) – the user session
file (File) – the file to send (the image)
message (str, optional) – message to be attached to file, 1024 char limit
- reply_location(session: AgentSession, latitude: float, longitude: float) None[source]¶
Send a location reply to a specific user.
- Parameters:
session (AgentSession) – the user session
latitude (str) – the latitude of the location
longitude (str) – the longitude of the location
- class besser.BUML.metamodel.state_machine.agent.Tool(name: str, description: str = '', code: str = '')[source]¶
Bases:
NamedElementA Python callable the agent’s reasoning state can invoke.
The metamodel stores the tool’s source code as a string (similar to how
CustomCodeActionstores user-supplied Python). The BAF generator pastescodeinto the output module verbatim and registers the callable on the agent viaagent.new_tool(...).- Parameters:
name (str) – the tool name (defaults to the callable’s own name at runtime, but here we require it explicitly so the generator can produce a stable Python identifier).
description (str) – a short description shown to the LLM.
code (str) – the Python source defining the callable. Must define a top-level
defwhose name matchesname.
- _abc_impl = <_abc._abc_data object>¶
- class besser.BUML.metamodel.state_machine.agent.VariableOperationMatcher(var_name: str, operation: Callable[[Any, Any], bool], target: Any)[source]¶
Bases:
ConditionThis event checks if for a specific comparison operation, using a stored session value and a given target value, returns true (e.g., ‘temperature’ > 30, where var_name = ‘temperature’, operation = op.greater and target = 30)
- Parameters:
- type¶
Inherited from Event, represents the type of the event.
- Type:
Type
- parameters¶
Inherited from Event, the set of parameters for the event.
- Type:
set[structural.Parameter]
- owner¶
Inherited from Event, the type that owns the property.
- Type:
Type
- target¶
The target value
- Type:
Any
- _abc_impl = <_abc._abc_data object>¶
- target: Any¶
- class besser.BUML.metamodel.state_machine.agent.WebCrawlLLMReply(initial_url: str = '', max_depth: int = 2, max_pages: int = 20, crawl_format: str = 'markdown', base_url_prefix: str | None = None, run_crawl: bool = True, no_crawl_error_message: str = 'No web crawl data is available yet.', system_message_prefix: str | None = None, llm_name: str | None = None)[source]¶
Bases:
ActionCrawls a website (or reuses a cached result) and queries an LLM with the content.
- Parameters:
initial_url (str) – Target URL. Used as BFS start point when run_crawl=True, or as the session-key suffix when run_crawl=False.
max_depth (int) – Maximum link depth to follow. Used only when run_crawl=True.
max_pages (int) – Maximum number of pages to fetch. Used only when run_crawl=True.
crawl_format (str) – Output format for crawled content (“markdown” or “html”).
base_url_prefix (str, optional) – Only URLs starting with this prefix are included. Used only when run_crawl=True.
run_crawl (bool) – When True, the crawl runs and its result is stored in the session under the key
f"web_crawl_{initial_url}". When False, reads from that key.no_crawl_error_message (str) – Reply sent when run_crawl=False and no cached result is found in the session.
system_message_prefix (str, optional) – Prepended to the crawl result when building the LLM system message. Defaults to a generic instruction when None.
llm_name (str, optional) – Name of the LLM to use. Falls back to the agent default.
- _abc_impl = <_abc._abc_data object>¶
- class besser.BUML.metamodel.state_machine.agent.WebSocketPlatform[source]¶
Bases:
PlatformThe WebSocket Platform allows a agent to communicate with the users using the WebSocket bidirectional communications protocol.
- _abc_impl = <_abc._abc_data object>¶
- reply_dataframe(session: AgentSession, df) None[source]¶
Send a DataFrame agent reply, i.e. a table, to a specific user.
- Parameters:
session (AgentSession) – the user session
df (pandas.DataFrame) – the message to send to the user
- reply_file(session: AgentSession, file: File) None[source]¶
Send a file reply to a specific user
- Parameters:
session (AgentSession) – the user session
file (File) – the file to send
- reply_location(session: AgentSession, latitude: float, longitude: float) None[source]¶
Send a location reply to a specific user.
- Parameters:
session (AgentSession) – the user session
latitude (str) – the latitude of the location
longitude (str) – the longitude of the location
- reply_options(session: AgentSession, options: list[str])[source]¶
Send a list of options as a reply. They can be used to let the user choose one of them
- Parameters:
session (AgentSession) – the user session
options (list[str]) – the list of options to send to the user
- reply_plotly(session: AgentSession, plot) None[source]¶
Send a Plotly figure as a agent reply, to a specific user.
- Parameters:
session (AgentSession) – the user session
plot (plotly.graph_objs.Figure) – the message to send to the user
- class besser.BUML.metamodel.state_machine.agent.WebSocketReplyDataframe[source]¶
Bases:
ActionSend a DataFrame reply via WebSocketPlatform.reply_dataframe(). Requires a runtime pandas DataFrame.
- _abc_impl = <_abc._abc_data object>¶
- class besser.BUML.metamodel.state_machine.agent.WebSocketReplyFile[source]¶
Bases:
ActionSend a file reply via WebSocketPlatform.reply_file(). Requires a runtime File object.
- _abc_impl = <_abc._abc_data object>¶
- class besser.BUML.metamodel.state_machine.agent.WebSocketReplyHTML(message: str = '')[source]¶
Bases:
ActionSend an HTML-formatted text reply via WebSocketPlatform.reply_html().
- _abc_impl = <_abc._abc_data object>¶
- class besser.BUML.metamodel.state_machine.agent.WebSocketReplyImage[source]¶
Bases:
ActionSend an image reply via WebSocketPlatform.reply_image(). Requires a runtime numpy ndarray.
- _abc_impl = <_abc._abc_data object>¶
- class besser.BUML.metamodel.state_machine.agent.WebSocketReplyLocation(latitude: float = 0.0, longitude: float = 0.0)[source]¶
Bases:
ActionSend a geographic location reply via WebSocketPlatform.reply_location().
- _abc_impl = <_abc._abc_data object>¶
- class besser.BUML.metamodel.state_machine.agent.WebSocketReplyMarkdown(message: str = '')[source]¶
Bases:
ActionSend a Markdown-formatted text reply via WebSocketPlatform.reply_markdown().
- _abc_impl = <_abc._abc_data object>¶
- class besser.BUML.metamodel.state_machine.agent.WebSocketReplyOptions(options: list | None = None)[source]¶
Bases:
ActionSend a list of selectable options via WebSocketPlatform.reply_options().
- _abc_impl = <_abc._abc_data object>¶
- class besser.BUML.metamodel.state_machine.agent.WebSocketReplyPlotly[source]¶
Bases:
ActionSend a Plotly figure reply via WebSocketPlatform.reply_plotly(). Requires a runtime plotly Figure.
- _abc_impl = <_abc._abc_data object>¶
- class besser.BUML.metamodel.state_machine.agent.WebSocketReplySpeech(message: str = '', audio_speed: float | None = None)[source]¶
Bases:
ActionConvert text to speech and send the audio via WebSocketPlatform.reply_speech().
- _abc_impl = <_abc._abc_data object>¶
- class besser.BUML.metamodel.state_machine.agent.WildcardEvent[source]¶
Bases:
EventWildcard event. Can be used to match any event in a transition.
- _abc_impl = <_abc._abc_data object>¶
- class besser.BUML.metamodel.state_machine.agent.Workspace(name: str, path: str = '', description: str | None = None, writable: bool = True, max_read_bytes: int = 200000)[source]¶
Bases:
NamedElementA filesystem path the reasoning state can browse and (optionally) modify.
The BAF runtime auto-registers
list_directory/read_filetools on the agent the first time a workspace is added, pluswrite_file/create_file/delete_filewhen at least one workspace haswritable=True.- Parameters:
name (str) – the workspace identifier (used by the LLM as the
workspaceargument when multiple workspaces are present).path (str) – the workspace root path (absolute or relative to the generated agent’s working directory).
description (str | None) – a short human-readable explanation of what the workspace contains. Strongly recommended.
writable (bool) – when False, mutating operations on this workspace raise
WorkspaceErrorat runtime. Defaults to True.max_read_bytes (int) – cap on
read_fileoutput. Defaults to200_000(matches the BAF runtime default).
- _abc_impl = <_abc._abc_data object>¶
- besser.BUML.metamodel.state_machine.agent.llm_provider_key(llm: LLMWrapper) str[source]¶
Reverse-lookup the
providerkeyword for an existing LLM instance.