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 "TerminalBotInterface", 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 129 130 131 132 133 134 135 136 137 138 139 140 |
|
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_structures
#
Bot structures supported by Intentional.
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 LLM 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_structures/bot_structure.py
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 |
|
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.
connect()
async
#Connect to the bot.
Source code in intentional-core/src/intentional_core/bot_structures/bot_structure.py
46 47 48 49 |
|
disconnect()
async
#Disconnect from the bot.
Source code in intentional-core/src/intentional_core/bot_structures/bot_structure.py
51 52 53 54 |
|
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_structures/bot_structure.py
68 69 70 71 72 73 74 75 76 77 |
|
run()
abstractmethod
async
#Main loop for the bot.
Source code in intentional-core/src/intentional_core/bot_structures/bot_structure.py
56 57 58 59 60 |
|
send(data)
abstractmethod
async
#Send a message to the bot.
Source code in intentional-core/src/intentional_core/bot_structures/bot_structure.py
62 63 64 65 66 |
|
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_structures/bot_structure.py
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 |
|
direct_to_llm
#
Bot structure to support text chat for Intentional.
DirectToLLMBotStructure
#
Bases: BotStructure
Bot structure implementation for text chat.
Source code in intentional-core/src/intentional_core/bot_structures/direct_to_llm.py
17 18 19 20 21 22 23 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 |
|
__init__(config, intent_router)
#Parameters:
Name | Type | Description | Default |
---|---|---|---|
config
|
Dict[str, Any]
|
The configuration dictionary for the bot structure. |
required |
Source code in intentional-core/src/intentional_core/bot_structures/direct_to_llm.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
|
connect()
async
#Initializes the model and connects to it as/if necessary.
Source code in intentional-core/src/intentional_core/bot_structures/direct_to_llm.py
39 40 41 42 43 |
|
disconnect()
async
#Disconnects from the model and unloads/closes it as/if necessary.
Source code in intentional-core/src/intentional_core/bot_structures/direct_to_llm.py
45 46 47 48 49 |
|
handle_interruption(lenght_to_interruption)
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_structures/direct_to_llm.py
66 67 68 69 70 71 72 73 74 75 |
|
run()
async
#Main loop for the bot.
Source code in intentional-core/src/intentional_core/bot_structures/direct_to_llm.py
51 52 53 54 55 |
|
send(data)
async
#Sends a message to the model and forward the response.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data
|
Dict[str, Any]
|
The message to send to the model in OpenAI format, like {"role": "user", "content": "Hello!"} |
required |
Source code in intentional-core/src/intentional_core/bot_structures/direct_to_llm.py
57 58 59 60 61 62 63 64 |
|
end_conversation
#
Tool that ends and resets the conversation. Once a conversation reaches this stage, the bot should restart from the start stage. See IntentRouter.
EndConversationTool
#
Bases: Tool
Tool to end the conversation. Resets the intent router to its initial stage.
Source code in intentional-core/src/intentional_core/end_conversation.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
|
run(params=None)
async
#
Ends the conversation and resets the intent router to its initial stage.
Source code in intentional-core/src/intentional_core/end_conversation.py
32 33 34 35 36 37 38 39 40 41 |
|
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
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
|
__init__(listener)
#
Register the listener.
Source code in intentional-core/src/intentional_core/events.py
66 67 68 69 70 |
|
emit(event_name, event)
async
#
Send the event to the listener.
Source code in intentional-core/src/intentional_core/events.py
72 73 74 75 76 77 |
|
EventListener
#
Bases: ABC
Listens to events and handles them.
Source code in intentional-core/src/intentional_core/events.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 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
|
__init__()
#
Initialize the bot structure.
Source code in intentional-core/src/intentional_core/events.py
21 22 23 24 25 |
|
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/events.py
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
|
handle_event(event_name, event)
async
#
Handle different types of events that the LLM may generate.
Source code in intentional-core/src/intentional_core/events.py
45 46 47 48 49 50 51 52 53 54 55 56 57 |
|
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
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 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 |
|
current_stage
property
#
Shorthand to get the current stage instance.
get_external_transitions()
#
Return a list of all the stages that can be reached from the current stage that are not direct connections.
Source code in intentional-core/src/intentional_core/intent_routing.py
179 180 181 182 183 184 185 186 187 188 189 190 |
|
get_prompt()
#
Get the prompt for the current stage.
Source code in intentional-core/src/intentional_core/intent_routing.py
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 |
|
run(params=None)
async
#
Given the response's classification, returns the new system prompt and the tools accessible in this stage.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
params
|
Optional[Dict[str, Any]]
|
The parameters for the tool. Contains the |
None
|
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
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 |
|
Stage
#
Describes a stage in the bot's conversation.
Source code in intentional-core/src/intentional_core/intent_routing.py
193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 |
|
llm_client
#
Functions to load LLM client classes from config files.
LLMClient
#
Bases: ABC
, EventEmitter
Tiny base class used to recognize Intentional LLM 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/llm_client.py
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 |
|
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 LLM from.
__init__(parent, intent_router)
#
Initialize the LLM client.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
parent
|
BotStructure
|
The parent bot structure. |
required |
Source code in intentional-core/src/intentional_core/llm_client.py
59 60 61 62 63 64 65 66 67 |
|
connect()
async
#
Connect to the LLM.
Source code in intentional-core/src/intentional_core/llm_client.py
69 70 71 72 73 |
|
disconnect()
async
#
Disconnect from the LLM.
Source code in intentional-core/src/intentional_core/llm_client.py
75 76 77 78 79 |
|
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/llm_client.py
94 95 96 97 98 99 100 101 102 103 |
|
run()
abstractmethod
async
#
Handle events from the LLM 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/llm_client.py
81 82 83 84 85 86 |
|
send(data)
abstractmethod
async
#
Send a unit of data to the LLM. The response is streamed out as an async generator.
Source code in intentional-core/src/intentional_core/llm_client.py
88 89 90 91 92 |
|
load_llm_client_from_dict(parent, intent_router, config)
#
Load a LLM client from a dictionary configuration.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config
|
Dict[str, Any]
|
The configuration dictionary. |
required |
Returns:
Type | Description |
---|---|
LLMClient
|
The LLMClient instance. |
Source code in intentional-core/src/intentional_core/llm_client.py
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 |
|
tools
#
Tools baseclass for Intentional.
Tool
#
Bases: ABC
Tools baseclass for Intentional.
Source code in intentional-core/src/intentional_core/tools.py
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
|
run(params=None)
abstractmethod
async
#
Run the tool.
Source code in intentional-core/src/intentional_core/tools.py
55 56 57 58 59 |
|
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 31 32 33 34 35 36 |
|
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
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 |
|
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
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
|
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 34 |
|
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 |
|