Skip to main content
A code step is a step in an automation that runs a Python program instead of following an AOP (Agent Operating Procedure). Use one when the work is a calculation or a rule rather than a judgment: totalling invoice lines, matching records, routing on a threshold. The same input always gives the same result. The program reaches Duvo’s Queues and Connections through the duvo client. It ships with every Run, so there is nothing to install.

Start here

print() output and anything written to stderr appear in the Run detail while the program works, in order with the tool calls around them.

What a step is given

Each Run hands the program one input. Read it from duvo:
  • case_ref, trigger and trigger_payload are None when they don’t apply, so the program can tell what started it: case_ref for a Run bound to a Case, trigger for one an event started. policy is {} and files is [] when the step has none.
  • case_ref is a reference, not a copy. Read the Case with claim_case.
  • Make repeated work safe with execution.run_id. A retry reuses the same Run, so run_id stays the same across attempts. Use execution.attempt for logging only.

Event triggers

A step started by an event trigger, such as a new Gmail message or a Linear webhook, reads the item from duvo.trigger_payload:
  • Branch on trigger_type, not source. One Connection can own several unrelated triggers, each with its own fields.
  • A payload holds what the trigger already had. Gmail’s payload is the message and thread IDs, not the email itself. Read the rest through the Connection.
  • A capped payload says so. When a long body or a wide row is cut, the payload carries truncated: true. Check it if the step must not act on a partial record.
  • payload_version changes when a field is renamed or removed. Check it if the step must not run against a shape it wasn’t written for.

Policy

duvo.policy holds the Policy answers this step reads, resolved when the Run started. Changing an answer takes effect on the next Run, without editing the program. A Run doesn’t start while one of those questions is unanswered.

Files

Files attached in the step’s Files setup are in the sandbox before the program starts. Open one by the name it was attached under:
Every attached file is there, or the Run fails before the program starts. file_path raises an error for a name the step doesn’t have, rather than returning None. Use duvo.files to list them.

Queues

update_case replaces the Case’s data rather than merging into it, so send every field the Case should keep. On a Queue with a Case schema, pass json_data instead of data. list_cases, list_labels and read_case_file exist on both sides of a Queue, so reach them through the side you mean:
attach_case_file is on the consumer side only, for the Case this Run claimed. To attach a file to a Case you add, list it under that Case’s attachments, as {"file_path": ...}, in add_cases. To hand a Case to one of several next steps from code, see Let the code decide.

Connections

Every Connection attached to the step is under duvo.connections:
  • The step’s Connections row shows the name to type for each Connection.
  • Hyphens become underscores: microsoft-calendar is duvo.connections.microsoft_calendar.
  • Two Connections of the same kind each get an ID suffix, such as gmail_<id>, and neither keeps the short name. That way a program never sends from the wrong mailbox by accident. duvo.connections.names lists the names that work.
  • Arguments are keywords, passed through unchanged. The tool decides what it takes. A wrong tool name or argument comes back as an error from the Connection.
  • A Connection the Run doesn’t have fails the call straight away and names the ones it does have. Nothing is skipped quietly.
To reach a Connection by a name held in a variable, or to call a tool or pass an argument whose name isn’t a valid Python name:
No Connection credential is in the sandbox. Duvo checks every tool call against the Connections the Run started with, so editing the step during a Run can’t widen what it reaches.

Check which account a call reaches

For a call that must reach one specific account, such as a NetSuite sandbox rather than production, name the account’s origin:
  • Use an HTTPS origin only: no credentials, port, path, query or fragment. A trailing slash is allowed.
  • Duvo checks the Connection against the origin before the call and keeps every request and redirect on that origin.
  • If the origin doesn’t match, the error says the tool wasn’t sent.
  • If the connection drops or no verification comes back, the outcome is unknown. Check the record before you retry a write. Duvo doesn’t retry these calls for you.

One file or several

A new code step is one file, main.py, run with python main.py. For a larger program, select Add file above the editor. The step becomes a file list: your program stays in main.py, and you can add modules next to it and import them as usual. The step still runs with python main.py; the line under the editor shows the command. To run a different command, set it with the Duvo CLI or the API.

How a Run ends

When a Run fails, the traceback is in the Run detail.

The sandbox

  • Python 3 in a fresh sandbox for each Run, working directory /workspace/code-step.
  • A step installs nothing while it runs. It has the sandbox’s own libraries, among them pandas, numpy, pyarrow, requests, openpyxl, python-docx and python-pptx.
  • A Run has 10 minutes by default.

Errors

Every error derives from duvo.DuvoError and fails the Run unless the program catches it.

Limits