Skip to main content

Hooks

Hooks are used to store predefined code snippets and docker images for the use of Programmer and Operator agents with code execution.

Hooks are automatically choosen based on what the user is trying to accomplish. For example, if the user is trying to perform some data analysis over a set of csv files using python code, if there is an environment with applicable libraries installed, that environment will be used.

In case no environment is found, the agent will use the default environment.

Hooks can only be setup using python as programming language for now.

Code environment default setup

Available libraries:

CategoryLibraries
AWS Integrationboto3, botocore
Data Processing & Analysisnumpy (1.26.0), pandas, scikit-learn, statsmodels, tabulate
Data Visualizationmatplotlib, seaborn, plotly, folium, kaleido
Document ProcessingPyPDF2, pdfminer, openpyxl, xlsxwriter, python-docx (1.1.2), python-pptx, tabula-py, docx2pdf
Image ProcessingPillow, pytesseract
PDF Generationreportlab, fpdf
Data Formats & Parsingxmltodict, html2text, pyyaml, lxml
Web Scraping & HTTPrequests, beautifulsoup4, urllib3
Time Handlingdatetime
Forecasting & Trendsprophet, pytrends
Securitycryptography
Utilitiespydantic, cmake, replicate

Max runtime memory: 10 GB

Max runtime duration: 15 minutes

Max runtime storage: 10 GB

Hooks can be created and or edited from the following menu: Settings > Hooks > Create

`New execution hook.`

Create a hook

  1. Click on the Create button.
  2. Fill in the code execution env. name and description. The name must be unique and the description meaningful for the agent to understand the purpose of the environment and when to use/
  3. Remote environment name (optional) - this will allow the agent to use a custom execution hook with the enterprise customer libraries and setup.
  4. Code execution instructions (optional) - this will guide the agent on how to generate and execute the code.
  5. Predefined code snippet (optional) - this will allow the agent to use a predefined code snippet to steer the generation of the code towards a predefined implementation.
  6. Click on the Save button to create the environment.
Warning

Custom environments are available only for Enterprise plans. Please contact us for more information to start creating custom environments.

Note

In order for the execution hook to be used by an agent, it needs to be assigned to the agent first. This can be done from the agent execution hooks settings once code execution is enabled or from a Python function.

Additional options

Secrets to inject in execution hooks

When enabled, the agent associated to the environment will be able to use secrets in the code. This is useful for hooks where the code needs to interact with external services that require authentication or 3rd party libraries that require a license. Secrets can be created in the Authorisation section of the Settings menu. See more details here

Execute as static script

When enabled the agent associated to the environment will execute the code as a static script. This means that the agent will not be able to modify the code after it has been generated. This is useful for hooks where the code needs to be exactly the same regardless of the nuances of the instructions. If you are dealing with files you can assume that all files used as input can be accessed under the folder /tmp/{workspaceid}/{chatid}/{messageid}/input while all the generated files are inside the /tmp/{workspaceid}/{chatid}/{messageid}/output folder.

File Persistence

Files are not persisted between executions, but the outputs are saved for retrieval at any point in time by the user.

Execute as python function

When enabled, the hook selected can be encapsulated inside a Python function that can be created in the Functions settings. The idea behind this functionality is for the agent to execute a predefined function with the ability to inject parameters at runtime. When you want a parameter to be dynamic simply wrap the parameter with {{}} and the agent will replace it with the value of the parameter at runtime.

Execute as python function

Each dynamic parameter wrapped in {{}} will be replaced with the value of the parameter at runtime. To do so, the Python function encapsulating the code execution must have the exact same variable names inside the parameters field.

How to write a hook

When writing your Python function, structure the script as a single file without using the if __name__ == "__main__": pattern. The script should be designed to run directly as a standalone file without any reference to external files.

Referencing Python Files from Knowledge Hub

You can select up to 10 Python files uploaded to the Knowledge Hub that can be referenced inside the hook code. This allows you to reuse common utilities, classes, and functions across different hooks.

Example: Importing a Class from a Knowledge Hub File

If you have a file named my_static_file.py in the Knowledge Hub with the following content:

class DataProcessor:
def __init__(self):
self.name = "Custom Data Processor"

def process(self, data):
# Custom processing logic
return data.upper()

You can reference it in your hook code like this:

from my_static_file import DataProcessor

# Use the imported class
processor = DataProcessor()
result = processor.process("hello world")
print(result) # Output: HELLO WORLD
File Naming Requirements

The name of the file displayed in the Knowledge Hub must match exactly the one referenced inside the hook code. For example, if the file is named my_static_file.py in the Knowledge Hub, you must import it as from my_static_file import ...

Topic and Status Independence

It does not matter which topic the Python file is assigned to or what the embedding status of the document is. As long as the file is in the Knowledge Hub and selected for the hook, it can be referenced in the code.