SDK Reference
Reference documentation for the Autoblocks Python Prompt SDK, including the AutoblocksPromptManager and PromptExecutionContext classes.
Python Prompt SDK Reference
AutoblocksPromptManager
This is the base class the autogenerated prompt manager classes inherit from. Below are the arguments that can be passed when initializing a prompt manager:
name | required | default | description |
---|---|---|---|
major_version | true | The major version of the prompt to use. Can be a specific version number or “undeployed” for local development. | |
minor_version | true | Can be one of: a specific minor version or “latest” | |
api_key | false | AUTOBLOCKS_API_KEY environment variable | Your Autoblocks API key. |
refresh_interval | false | timedelta(seconds=10) | How often to refresh the latest prompt. Only relevant if the minor version is set to "latest" or "latest" is used in the weighted list. |
refresh_timeout | false | timedelta(seconds=30) | How long to wait for the latest prompt to refresh before timing out. A refresh timeout will not raise an uncaught exception. An error will be logged and the background refresh process will continue to run at its configured interval. |
init_timeout | false | timedelta(seconds=30) | How long to wait for the prompt manager to be ready before timing out. |
exec
A context manager that starts a prompt execution context by creating a new
PromptExecutionContext
instance.
PromptExecutionContext
An instance of this class is created every time a new execution context is started with the exec
context manager.
It contains a frozen copy of the prompt manager’s in-memory prompt at the time exec
was called.
This ensures the prompt is stable for the duration of an execution, even if the in-memory prompt on the manager
instance is refreshed mid-execution.
params
A pydantic
model instance with the prompt’s parameters.
render_template
The render_template
attribute contains an instance of a class that has methods for rendering each of the prompt’s templates.
The template IDs and template parameters are all converted to snake case so that the method and argument names follow
Python naming conventions.
For example, the prompt in the quick start guide contains the below templates:
system
user
util/language
util/tone
From this, the CLI autogenerates a class with the following methods:
As a result, you are able to render your templates with functions that are aware of the required parameters for each template:
render_tool
The render_tool
attribute contains an instance of a class that has methods for rendering each of the prompt’s tools.
The tool names and tool parameters are all converted to snake case so that the method and argument names follow
Python naming conventions. The tool will be in the JSON schema format that OpenAI expects.