Workflow
The workflow.pkl contains configuration about the AI Agent, namely:
- AI agent
Name,Description,website,authors,documentation, andrepository. - The semver
versionof this AI agent. - The
targetActionIDresource to be executed when running the AI agent. This is the ID of the resource. - Existing AI agents
workflowsto be reused in this AI agent. The agent needs to be installed first via thekdeps installcommand.`
Settings
The settings block allows advanced configuration of the AI agent, covering API settings, web server settings, routing, Ubuntu and Python packages, and default LLM models.
Settings {
APIServerMode = true
APIServer {...}
WebServerMode = false
WebServer {...}
AgentSettings {...}
}Overview
The settings block includes the following configurations:
APIServerMode: A boolean flag that enables or disables API server mode for the project. When set tofalse, the default action is executed directly, and the program exits upon completion.APIServer: A configuration block that specifies API settings such asHostIP,PortNum, androutes.WebServerMode: A boolean flag that enables or disables the web server for serving frontends or proxying web applications.WebServer: A configuration block that specifies web server settings such asHostIP,PortNum, androutes.agentSettings: A configuration block that includes settings for installing Anaconda,condaPackages,pythonPackages, custom or PPA Ubunturepositories, Ubuntupackages, Ollama LLMmodels, andOfflineModefor offline model deployment.
API Server Settings
The APIServer block defines API routing configurations for the AI agent. These settings are only applied when APIServerMode is set to true.
HostIPandPortNum: Define the IP address and port for the Docker container. The default values are"127.0.0.1"forHostIPand3000forPortNum.
TrustedProxies
The TrustedProxies allows setting the allowable X-Forwarded-For header IPv4, IPv6, or CIDR addresses, used to limit trusted requests to the service. You can obtain the client's IP address through @(request.IP()).
Example:
TrustedProxies {
"127.0.0.1"
"192.168.1.2"
"10.0.0.0/8"
}CORS Configuration
The cors block configures Cross-Origin Resource Sharing for the API server, controlling which origins, methods, and headers are allowed for cross-origin requests. It enables secure access from web applications hosted on different domains.
Example:
CORS {
EnableCORS = true
AllowOrigins {
"https://example.com"
}
AllowMethods {
"GET"
"POST"
}
AllowHeaders {
"Content-Type"
"Authorization"
}
AllowCredentials = true
MaxAge = 24.h
}See the CORS Configuration for more details.
API Routes
routes: API paths can be configured within theroutesblock. Each route is defined using anewblock, specifying:path: The defined API endpoint, e.g.,"/api/v1/items".methods: HTTP methods allowed for the route. Supported HTTP methods include:GET,POST,PUT,PATCH,OPTIONS,DELETE, andHEAD.
Example:
Routes {
new {
Path = "/api/v1/user"
Methods {
"GET"
}
}
new {
Path = "/api/v1/items"
Methods {
"POST"
}
}
}Each route targets a single targetActionID, meaning every route points to the main action specified in the workflow configuration. If multiple routes are defined, you must use a skipCondition logic to specify which route a resource should target. See the Workflow for more details.
For instance, to run a resource only on the "/api/v1/items" route, you can define the following skipCondition logic:
local allowedPath = "/api/v1/items"
local requestPath = "@(request.path())"
SkipCondition {
requestPath != allowedPath
}In this example:
- The resource is skipped if the
skipConditionevaluates totrue. - The resource runs only when the request path equals
"/api/v1/items".
For more details, refer to the Skip Conditions documentation.
Lambda Mode
When the APIServerMode is set to false in the workflow configuration, the AI agent operates in a single-execution lambda mode. In this mode, the AI agent is designed to execute a specific task or serve a particular purpose, completing its function in a single, self-contained execution cycle.
For example, an AI agent in single-execution lambda mode might be used to analyze data from a form submission, generate a report, be executed as a scheduled cron job function, or provide a response to a one-time query, without the need for maintaining an ongoing state or connection.
Web Server Settings
The WebServer block defines configurations for serving frontend interfaces or proxying to web applications, enabling KDeps to deliver full-stack AI applications with integrated UIs. These settings are only applied when WebServerMode is set to true.
HostIPandPortNum: Define the IP address and port for the web server. The default values are"127.0.0.1"forHostIPand8080forPortNum.
WebServerMode
WebServerMode: A boolean flag that enables or disables the web server. When set totrue, KDeps can serve static frontends (e.g., HTML, CSS, JS) or proxy to local web applications (e.g., Streamlit, Node.js). Whenfalse, the web server is disabled.
Example:
WebServerMode = trueWebServer
WebServer: A configuration block that defines settings for the web server, includingHostIP,PortNum,TrustedProxies, androutes. It is only active whenWebServerModeistrue.
Example:
WebServer {
HostIP = "0.0.0.0"
PortNum = 8080
TrustedProxies {
"192.168.1.0/24"
}
}Web Server Routes
routes: Web server paths are configured within theroutesblock of theWebServersection. Each route is defined using awebblock, specifying:path: The HTTP path to serve, e.g.,"/dashboard"or"/app".serverType: The serving mode:"static"for file hosting or"app"for reverse proxying.
Example:
WebServer {
Routes {
new {
Path = "/dashboard"
ServerType = "static"
PublicPath = "/agentX/1.0.0/dashboard/"
}
new {
Path = "/app"
ServerType = "app"
AppPort = 8501
Command = "streamlit run app.py"
}
}
}Each route directs requests to static files (e.g., HTML, CSS, JS) or a local web app (e.g., Streamlit, Node.js), enabling frontend integration with KDeps' AI workflows.
Static File Serving
static: Serves files like HTML, CSS, or JS from a specified directory, ideal for hosting dashboards or frontends. The block withServerType = "static"defines the path and directory relative to/data/, delivering files directly to clients.
Example:
WebServer {
Routes {
new {
Path = "/dashboard"
ServerType = "static"
PublicPath = "/agentX/1.0.0/dashboard/"
}
}
}This serves files from /data/agentX/1.0.0/dashboard/ at http://<host>:8080/dashboard.
Reverse Proxying
app: Forwards requests to a local web application (e.g., Streamlit, Node.js) running on a specified port. The block withServerType = "app"defines the path, port, and optional command to start the app, proxying client requests to the app’s server.
Example:
WebServer {
Routes {
new {
Path = "/app"
ServerType = "app"
PublicPath = "/agentX/1.0.0/streamlit-app/"
AppPort = 8501
Command = "streamlit run app.py"
}
}
}This proxies requests from http://<host>:8080/app to a Streamlit app on port 8501, launched with streamlit run app.py. For more details, see the Web Server documentation.
AI Agent Settings
This section contains the agent settings that will be used to build the agent's Docker image.
AgentSettings {
Timezone = "Etc/UTC"
installAnaconda = false
condaPackages { ... }
PythonPackages { ... }
Repositories { ... }
Packages { ... }
Models { ... }
OllamaImageTag = "0.5.4"
Env { ... }
Args { ... }
}Timezone Settings
Configure the timezone setting with a valid tz database identifier (e.g., America/New_York) for the Docker image; see https://en.wikipedia.org/wiki/List_of_tz_database_time_zones for valid identifiers.
Enabling Anaconda
installAnaconda: "The Operating System for AI", Anaconda, will be installed when set totrue. However, please note that if Anaconda is installed, the Docker image size will grow to > 20GB. This does not include additionalcondaPackages. Defaults tofalse.
Anaconda Packages
condaPackages: Anaconda packages to be installed ifinstallAnacondaistrue. The environment, channel, and packages can be defined in a single entry.
condaPackages {
["base"] {
["main"] = "pip diffusers numpy"
["pytorch"] = "pytorch"
["conda-forge"] = "tensorflow pandas keras transformers"
}
}This configuration will:
- Create the
baseisolated Anaconda environment. - Use the
mainchannel to installpip,diffusers, andnumpyAnaconda packages. - Use the
pytorchchannel to installpytorch. - Use the
conda-forgechannel to installtensorflow,pandas,keras, andtransformers.
To use the isolated environment, the Python resource should specify the Anaconda environment via the CondaEnvironment setting.
Python Packages
Python packages can also be installed even without Anaconda installed.
PythonPackages {
"diffusers[torch]"
"streamlit"
"openai-whisper"
}Ubuntu Repositories
Additional Ubuntu and Ubuntu PPA repositories can be defined in the repositories settings.
Repositories {
"ppa:alex-p/tesseract-ocr-devel"
}In this example, a PPA repository is added for installing the latest tesseract-ocr package.
Ubuntu Packages
Specify the Ubuntu packages that should be pre-installed when building this image.
Packages {
"tesseract-ocr"
"poppler-utils"
"npm"
"ffmpeg"
}LLM Models
List the local Ollama LLM models that will be pre-installed. You can specify multiple models.
Models {
"tinydolphin"
"llama3.3"
"llama3.2-vision"
"llama3.2:1b"
"mistral"
"gemma"
"mistral"
}KDeps uses Ollama as its LLM backend. You can define as many Ollama-compatible models as needed to fit your use case.
For a comprehensive list of available Ollama-compatible models, visit the Ollama model library.
Offline Mode
The OfflineMode setting controls whether models are pulled during Docker build time for offline operation:
OfflineMode = trueWhen OfflineMode is set to true:
- Models specified in the
Modelsblock are pulled during Docker image build time - KDeps uses
OLLAMA_MODELSexclusively to control model storage locations:- Build-time:
OLLAMA_MODELS=/modelsinside the image (baked into the image) - Runtime:
OLLAMA_MODELSenvironment variable (defaults to/root/.ollamaif unset)
- Build-time:
- At runtime, models are copied from the image (
/models) into${OLLAMA_MODELS}(e.g., the mounted volume) instead of being downloaded - This enables true offline operation without requiring internet connectivity
When OfflineMode is set to false:
- Models are pulled at runtime from the internet when the container starts
- Requires internet connectivity during container startup
This feature is particularly useful for:
- Deployments in air-gapped environments
- Reducing container startup time by avoiding model downloads
- Ensuring consistent model availability regardless of internet connectivity
Ollama Docker Image Tag
The ollamaImageTag configuration property allows you to dynamically specify the version of the Ollama base image tag used in your Docker image.
When used in conjunction with a GPU configuration in the .kdeps.pkl file, this configuration can automatically adjust the image version to include hardware-specific extensions, such as 1.0.0-rocm for AMD environments.
Arguments and Environment Variables
KDeps allows you to define ENV (environment variables) that persist across both the Docker image and container runtime, and ARG (arguments) that are used for passing values during the build process.
To declare ENV or ARG parameters, use the env and args sections in your workflow configuration:
Env {
["API_KEY"] = "example_value"
}
Args {
["API_TOKEN"] = ""
}In this example:
API_KEYis declared as an environment variable with the value"example_value". This variable will persist in both the Docker image and the container at runtime.API_TOKENis an argument that does not have a default value and will accept a value at container runtime.
Environment File Support:
Additionally, any .env file in your project will be automatically loaded via kdeps run, and the variables defined within it will populate the env or args sections accordingly.
Important Notes:
ENVvariables must always be assigned a value during declaration.ARGvariables can be declared without a value (e.g.,""). These will act as standalone runtime arguments.- Values defined in the
.envfile will override default values for any matchingENVorARGkeys.