Local tool execution
Often times, tool definitions will rely on importing code from other files or packages:
To ensure that your tools are able to run, you need to make sure that the files and packages they rely on are accessible from the Letta server. When running Letta locally, the tools are executed inside of the Docker container running the Letta service, and the files and packages they rely on must be accessible from the Docker container.
Importing modules from external files
Tool definitions will often rely on importing code from other files. For example, say you have a repo with the following structure:
We want to import code from module.py in a custom tool as follows:
my_function, you need to mount your repository in the Docker container and also explicitly set the location of tool execution by setting the TOOL_EXEC_DIR environment variable.
This will ensure that tools are executed inside of /app/my_repo and the files inside of my_repo are accessible via the volume.
Specifying pip packages
You can specify packages to be installed in the tool execution environment by setting the TOOL_EXEC_VENV_NAME environment variable. This will enable Letta to explicitly create a virtual environment and and install packages specified by requirements.txt at the server start time.
This will ensure that the packages specified in /app/my_repo/requirements.txt are installed in the virtual environment where the tools are executed.
TOOL_EXEC_VENV_NAME. Attaching the tool to an agent
Now, you can create a tool that imports modules from your tool execution directory or from the packages specified in requirements.txt. When defining custom tools, make sure you have a properly formatting docstring (so it can be parsed into the OpenAI tool schema) or use the args_schema parameter to specify the arguments for the tool.
See more on creating custom tools here.