Client
Theclient export provides direct access to the Botpress API client. Unlike the client passed to handlers, this export works from any file in your agent—including utility functions, shared modules, and scripts run with adk run.
- During request handling: Uses the bot-specific client from the current execution context
- In scripts (
adk run): Creates a client usingADK_TOKENandADK_BOT_IDenvironment variables
Context
Thecontext API provides low-level access to the current execution context. It’s built on Node.js AsyncLocalStorage and contains all runtime information about the current request.
Getting context about the current execution
You can usecontext.get() to access specific values from the current execution:
optional flag prevents errors when a value might not exist in the current context. Without it, accessing a missing key throws an error.
Check the reference for a full list of available context values.
Setting a default context
When running scripts withadk run, you may need to set up a default context for code that expects to run within a request:
The
adk run command automatically sets up the default context with authentication. You typically only need setDefaultContext for testing or custom script environments.Checking execution time
Long-running operations should check remaining execution time to avoid timeouts:Reference
Get a specific value from the current execution context. Throws an error if the key doesn’t exist unless
optional: true is passed.Get the entire context object for the current execution.
Set a value in the current execution context. Can only be called within an active context.
Set a default context used as a fallback when no execution context is active. Useful for testing and script execution.
Clear the default context.
ADK object
Theadk export provides access to project configuration and utilities for autonomous execution outside of conversations.
Getting project information
You can use theadk object to read your agent’s primitives, configuration and more:
Running an autonomous agent
You can run an autonomous agent outside of a Conversation context. This is useful for scripts, migrations, or background tasks:Using Zai
Theadk object gives you access to the Zai utility library. You can use Zai to perform type-safe AI operations on arbitrary data:
For a full list of Zai’s methods, check out the Zai reference documentation.
Checking the execution environment
You can check the current execution environment:Reference
Project primitives and configuration.
Zai LLM utility toolkit instance configured with the project’s default model.
Environment detection utilities including
isDevelopment() and isProduction() methods.Execute an autonomous LLM agent outside of a conversation context.