API Reference - Core Package#
src
#
intentional_core
#
Init file for intentional_core
.
__about__
#
Package descriptors for intentional-core.
bot_interface
#
Functions to load bots from config files.
BotInterface
#
Bases: ABC
Tiny base class used to recognize Intentional bots interfaces.
The class name is meant to represent the communication channel you will use to interact with your bot. For example an interface that uses a local command line interface would be called "LocalBotInterface", one that uses Whatsapp would be called "WhatsappBotInterface", one that uses Twilio would be called "TwilioBotInterface", etc.
In order for your bot to be usable, you need to assign a value to the name
class variable in the class definition.
Source code in intentional-core/src/intentional_core/bot_interface.py
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
|
name: Optional[str] = None
class-attribute
instance-attribute
#
The name of the bot interface. This should be a unique identifier for the bot interface. This string will be used in configuration files to identify the bot interface.
The bot interface name should directly recall the class name as much as possible. For example, the name of "LocalBotInterface" should be "local", the name of "WhatsappBotInterface" should be "whatsapp", etc.
run()
abstractmethod
async
#
Run the bot interface.
This method should be overridden by the subclass to implement the bot's main loop.
Source code in intentional-core/src/intentional_core/bot_interface.py
49 50 51 52 53 54 55 56 |
|
load_bot_interface_from_dict(config)
#
Load a bot interface, and all its inner classes, from a dictionary configuration.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config
|
Dict[str, Any]
|
The configuration dictionary. |
required |
Returns:
Type | Description |
---|---|
BotInterface
|
The bot interface instance. |
Source code in intentional-core/src/intentional_core/bot_interface.py
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
|
load_configuration_file(path)
#
Load an Intentional bot from a YAML configuration file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path
|
Path
|
Path to the YAML configuration file. |
required |
Returns:
Type | Description |
---|---|
BotInterface
|
The bot instance. |
Source code in intentional-core/src/intentional_core/bot_interface.py
59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
|
bot_structure
#
Functions to load bot structure classes from config files.
BotStructure
#
Bases: EventListener
Tiny base class used to recognize Intentional bot structure classes.
The bot structure's name is meant to represent the structure of the bot. For example a bot that uses a direct WebSocket connection to a model such as OpenAI's Realtime API could be called "RealtimeAPIBotStructure", one that uses a VAD-STT-LLM-TTS stack could be called "AudioToTextBotStructure", and so on
In order for your bot structure to be usable, you need to assign a value to the name
class variable in the bot
structure class' definition.
Source code in intentional-core/src/intentional_core/bot_structure.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
|
name: Optional[str] = None
class-attribute
instance-attribute
#
The name of this bot's structure. This should be a unique identifier for the bot structure type.
The bot structure's name should directly recall the class name as much as possible. For example, the name of "WebsocketBotStructure" should be "websocket", the name of "AudioToTextBotStructure" should be "audio_to_text", etc.
__init__()
#
Initialize the bot structure.
Source code in intentional-core/src/intentional_core/bot_structure.py
45 46 47 48 49 |
|
add_event_handler(event_name, handler)
#
Add an event handler for a specific event type.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
event_name
|
str
|
The name of the event to handle. |
required |
handler
|
Callable
|
The handler function to call when the event is received. |
required |
Source code in intentional-core/src/intentional_core/bot_structure.py
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
|
connect()
async
#
Connect to the bot.
Source code in intentional-core/src/intentional_core/bot_structure.py
51 52 53 54 |
|
disconnect()
async
#
Disconnect from the bot.
Source code in intentional-core/src/intentional_core/bot_structure.py
56 57 58 59 |
|
handle_event(event_name, event)
async
#
Handle different types of events that the model may generate.
Source code in intentional-core/src/intentional_core/bot_structure.py
101 102 103 104 105 106 107 108 109 110 111 112 113 |
|
handle_interruption(lenght_to_interruption)
abstractmethod
async
#
Handle an interruption in the streaming.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
lenght_to_interruption
|
int
|
The length of the data that was produced to the user before the interruption. This value could be number of characters, number of words, milliseconds, number of audio frames, etc. depending on the bot structure that implements it. |
required |
Source code in intentional-core/src/intentional_core/bot_structure.py
73 74 75 76 77 78 79 80 81 82 |
|
run()
abstractmethod
async
#
Main loop for the bot.
Source code in intentional-core/src/intentional_core/bot_structure.py
61 62 63 64 65 |
|
send(data)
abstractmethod
async
#
Send a message to the bot.
Source code in intentional-core/src/intentional_core/bot_structure.py
67 68 69 70 71 |
|
ContinuousStreamBotStructure
#
Bases: BotStructure
Base class for structures that support continuous streaming of data, as opposed to turn-based message exchanges.
Source code in intentional-core/src/intentional_core/bot_structure.py
116 117 118 119 |
|
TurnBasedBotStructure
#
Bases: BotStructure
Base class for structures that support turn-based message exchanges, as opposed to continuous streaming of data.
Source code in intentional-core/src/intentional_core/bot_structure.py
122 123 124 125 |
|
load_bot_structure_from_dict(intent_router, config)
#
Load a bot structure from a dictionary configuration.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config
|
Dict[str, Any]
|
The configuration dictionary. |
required |
Returns:
Type | Description |
---|---|
BotStructure
|
The BotStructure instance. |
Source code in intentional-core/src/intentional_core/bot_structure.py
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 |
|
events
#
Base class for very simplified event emitter and listener.
EventEmitter
#
Sends any event to the listener. TODO see if there's any scenario where we need more as this pattern is easy to extend but can get messy.
Source code in intentional-core/src/intentional_core/events.py
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
|
__init__(listener)
#
Register the listener.
Source code in intentional-core/src/intentional_core/events.py
33 34 35 36 37 |
|
emit(event_name, event)
async
#
Send the event to the listener.
Source code in intentional-core/src/intentional_core/events.py
39 40 41 42 43 44 |
|
EventListener
#
Bases: ABC
Listens to events and handles them.
Source code in intentional-core/src/intentional_core/events.py
15 16 17 18 19 20 21 22 23 24 |
|
handle_event(event_name, event)
abstractmethod
async
#
Handle the event.
Source code in intentional-core/src/intentional_core/events.py
20 21 22 23 24 |
|
intent_routing
#
Intent routing logic.
IntentRouter
#
Bases: Tool
Special tool used to alter the system prompt depending on the user's response.
Source code in intentional-core/src/intentional_core/intent_routing.py
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
|
current_stage
property
#
Shorthand to get the current stage instance.
get_prompt()
#
Get the prompt for the current stage.
Source code in intentional-core/src/intentional_core/intent_routing.py
134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
|
get_transitions()
#
Return a list of all the stages that can be reached from the current stage.
Source code in intentional-core/src/intentional_core/intent_routing.py
149 150 151 152 153 154 155 156 157 158 159 160 |
|
run(params)
async
#
Given the response's classification, returns the new system prompt and the tools accessible in this stage.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
params
|
Dict[str, Any]
|
The parameters for the tool. Contains the |
required |
Returns:
Type | Description |
---|---|
str
|
The new system prompt and the tools accessible in this stage. |
Source code in intentional-core/src/intentional_core/intent_routing.py
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
|
Stage
#
Describes a stage in the bot's conversation.
Source code in intentional-core/src/intentional_core/intent_routing.py
163 164 165 166 167 168 169 170 171 172 173 174 175 |
|
model_client
#
Functions to load model client classes from config files.
ContinuousStreamModelClient
#
Bases: ModelClient
Base class for model clients that support continuous streaming of data, as opposed to turn-based message exchanges.
Source code in intentional-core/src/intentional_core/model_client.py
113 114 115 116 |
|
ModelClient
#
Bases: ABC
, EventEmitter
Tiny base class used to recognize Intentional model clients.
In order for your client to be usable, you need to assign a value to the _name
class variable
in the client class' definition.
Source code in intentional-core/src/intentional_core/model_client.py
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
|
name: Optional[str] = None
class-attribute
instance-attribute
#
The name of the client. This should be a unique identifier for the client type. This string will be used in configuration files to identify the type of client to serve a model from.
__init__(parent, intent_router)
#
Initialize the model client.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
parent
|
BotStructure
|
The parent bot structure. |
required |
Source code in intentional-core/src/intentional_core/model_client.py
54 55 56 57 58 59 60 61 62 |
|
connect()
async
#
Connect to the model.
Source code in intentional-core/src/intentional_core/model_client.py
64 65 66 67 68 |
|
disconnect()
async
#
Disconnect from the model.
Source code in intentional-core/src/intentional_core/model_client.py
70 71 72 73 74 |
|
handle_interruption(lenght_to_interruption)
abstractmethod
async
#
Handle an interruption while rendering the output to the user.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
lenght_to_interruption
|
int
|
The length of the data that was produced to the user before the interruption. This value could be number of characters, number of words, milliseconds, number of audio frames, etc. depending on the bot structure that implements it. |
required |
Source code in intentional-core/src/intentional_core/model_client.py
95 96 97 98 99 100 101 102 103 104 |
|
run()
abstractmethod
async
#
Handle events from the model by either processing them internally or by translating them into higher-level events that the BotStructure class can understand, then re-emitting them.
Source code in intentional-core/src/intentional_core/model_client.py
76 77 78 79 80 81 |
|
send(data)
abstractmethod
async
#
Send a unit of data to the model. The response is streamed out as an async generator.
Source code in intentional-core/src/intentional_core/model_client.py
83 84 85 86 87 |
|
update_system_prompt()
abstractmethod
async
#
Update the system prompt in the model.
Source code in intentional-core/src/intentional_core/model_client.py
89 90 91 92 93 |
|
TurnBasedModelClient
#
Bases: ModelClient
Base class for model clients that support turn-based message exchanges, as opposed to continuous streaming of data.
Source code in intentional-core/src/intentional_core/model_client.py
107 108 109 110 |
|
load_model_client_from_dict(parent, intent_router, config)
#
Load a model client from a dictionary configuration.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config
|
Dict[str, Any]
|
The configuration dictionary. |
required |
Returns:
Type | Description |
---|---|
ModelClient
|
The ModelClient instance. |
Source code in intentional-core/src/intentional_core/model_client.py
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
|
tools
#
Tools baseclass for Intentional.
Tool
#
Bases: ABC
Tools baseclass for Intentional.
Source code in intentional-core/src/intentional_core/tools.py
33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
|
run(params)
abstractmethod
async
#
Run the tool.
Source code in intentional-core/src/intentional_core/tools.py
42 43 44 45 46 |
|
ToolParameter
dataclass
#
A parameter for an Intentional tool.
Source code in intentional-core/src/intentional_core/tools.py
20 21 22 23 24 25 26 27 28 29 30 |
|
load_tools_from_dict(config)
#
Load a list of tools from a dictionary configuration.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config
|
List[Dict[str, Any]]
|
The configuration dictionary. |
required |
Returns:
Type | Description |
---|---|
Dict[str, Tool]
|
A list of Tool instances. |
Source code in intentional-core/src/intentional_core/tools.py
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
|
utils
#
Utilities for Intentional.
importing
#
Module import functions to handle dynamic plugins import.
import_all_plugins()
#
Imports all the intentional-*
packages found in the current environment.
Source code in intentional-core/src/intentional_core/utils/importing.py
36 37 38 39 40 41 42 43 44 45 46 47 |
|
import_plugin(name)
#
Imports the specified package. It does NOT check if this is an Intentional package or not.
Source code in intentional-core/src/intentional_core/utils/importing.py
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
|
inheritance
#
Utils for inheritance checks, to discover subclasses of a base Intentional class.
inheritors(class_, include_abstract=False)
#
Find all subclasses of a class, regardless of depth.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
class_
|
Any
|
The class to find subclasses of. |
required |
include_abstract
|
bool
|
Whether to include abstract classes in the results. |
False
|
Source code in intentional-core/src/intentional_core/utils/inheritance.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
|