Skip to main content
Datazone Agents

Overview

Actions allow you to deploy serverless Python functions that can be triggered on-demand by endpoints or used as tools by AI agents. Think of actions as lambda-like functions that run in isolated environments.
  • Project Structure
my-project
config.yml
actions
send_mail_action.py

What Are Actions?

Actions are custom Python functions that run in isolated environments, accept parameters, return structured results, and can be triggered via endpoints or used as agent tools.

Use Cases

Inside an action you can:
  • Invoke an LLM — call a model through your model account with Agent, optionally with structured output
  • Run SQL queries — read from your datasets with execute_query
  • Read and write knowledge objects — get, list, update and batch upsert instances with KnowledgeObject
  • Use secure variables — access API keys and credentials with Variable, without hardcoding them
  • Log execution details — emit info, warning and error logs with context
  • Connect to SAP — read tables and execute function modules with CloudFeedClient
  • Call any external API — the runtime ships with requests, so any HTTP service is one call away
Which makes actions a good fit for sending notifications, processing data, generating reports, automating workflows, and extending AI agent capabilities with custom logic.

Action with Logging

Use context to log information during execution:

Action with Optional Parameters

Actions SDK Reference

Decorator

The @action decorator marks a function as executable by Datazone.

Context API

The context object provides logging capabilities during action execution:
function
Log informational messages during action execution.
function
Log warning messages for potential issues.
function
Log error messages when operations fail.
All logs are collected and returned with the action response.

Variable API

The Variable class allows actions to access secure variables stored in Datazone:
class
Access workspace variables securely within actions.
Variables are workspace-scoped and can be marked as secret to encrypt sensitive data like API keys, passwords, and tokens. Learn more in the Variables documentation.

Example: Using Variables

Security Best Practice: Always store sensitive credentials as Variables rather than hardcoding them in your action code.

execute_query

The execute_query function runs SQL queries against your Datazone datasets and returns structured results:
function
Execute a SQL query against Datazone datasets.
Returns a QueryResult object with:
  • data — list of row dictionaries
  • status — execution status string

Example: Query and Transform

Agent

The Agent class invokes an LLM through one of your Model Accounts, without any provider SDK or API key in your code — the call is proxied by Datazone and billed against your workspace.
class
Create an agent bound to a model account and model.Parameters:
  • model (optional) — model to use, e.g. CLAUDE_45_SONNET. Defaults to your organisation’s default model.
  • model_account (optional) — model account id. Defaults to your organisation’s AI settings account.
  • response_format (optional) — a Pydantic model or JSON schema dict for structured output.
method
Invoke the model and return a result dictionary.Accepts either a plain string or a message list:
Message roles are system, user and assistant. Returns a dict with:
  • content — the raw text answer (empty when response_format is used)
  • structured_response — the parsed object when response_format is used, otherwise None
  • model — the model that produced the answer
Raises RuntimeError if the invocation fails.

Example: Summarize Text

Example: Structured Output

Pass a Pydantic model as response_format to get a validated object back instead of raw text:
response_format also accepts a plain JSON schema dict — in that case structured_response is returned as a dict rather than a model instance.
Token usage is recorded per invocation and attributed to the action, so LLM costs show up alongside your other workspace usage.

KnowledgeObject

The KnowledgeObject client reads and writes Knowledge Object instances from within an action. Instances are addressed by their opaque _key, and operations run on the action’s project (main branch by default).
class
Access instances of a knowledge object by name.
Methods:
  • get(key, add_relationships=False) — fetch one instance (a dict) by its _key.
  • list(filters=None, page=1, page_size=50, fields=None) — iterate pages of instances (see below).
  • update(key, payload) — partially update an instance; returns the updated instance.
  • delete(key) — delete an instance by its _key.
  • batch_upsert(payloads) — insert/update up to 1000 instances in one call; returns {"created", "updated", "total"}.
Filtering and pagination. list(...) returns an iterator of pages; each page exposes .items and .total_count. filters is a list of {"column", "operator", "value"} objects combined with AND (operators: equal, not_equal, contains, not_contains, greater_than, less_than).

Example: Read and upsert

See the Actions SDK page under Knowledge Objects for the full method reference.

FileContainerClient

FileContainerClient provides access to files stored in the Datazone file container (LakeFS/S3-compatible storage). It is automatically initialized as file_client in agent code execution environments — no import is required.
file_client is pre-initialized in agent code execution contexts. It is not available inside @action decorated functions.
method
Fetch raw bytes for a file from the file container.
  • path — path relative to the file container root
  • Returns raw bytes
  • Raises ValueError if the file exceeds 10 MB or cannot be fetched

Examples: Reading Different File Types

CloudFeedClient

CloudFeedClient is a simplified SAP connector for reading tables and executing function modules from within actions:
class
SAP CloudFeed client for table access and function execution.Constructor parameters:
  • base_url — base URL of the SAP system
  • username — SAP username
  • password — SAP password
  • timeout (optional) — request timeout in seconds (default: 30)
  • max_retries (optional) — max retries on failure (default: 10)
  • backoff_factor (optional) — exponential backoff factor (default: 0.3)

Example: Query SAP Sales Orders

Example: Execute SAP Function Module

Example: Search and Inspect SAP Tables

Configuration

Add to config.yaml

Register your actions in config.yaml:

Repository Structure

config.yml
actions
send_email.py
process_data.py
generate_report.py
Each file should contain one @action decorated function. Action function names must be unique within your project.

Return Values

Actions should return structured data (dict, list, or primitives):

Error Handling

Actions can raise exceptions - they’ll be captured and returned:

Using Actions

1. In Endpoints

Connect actions to API endpoints for webhook-style triggers:
When the endpoint is called, the action executes automatically. Learn more in the Endpoints documentation.

2. In Agents

Enable actions as tools for AI agents: When creating an agent:
  1. Select “Action” in the tools section
  2. Choose which actions the agent can use
  3. The agent will automatically call actions when needed
The AI agent decides when and how to use actions based on user questions. Learn more in the Agents documentation.

Examples

Slack Notification

Data Validation

API Integration

Next Steps