logic.code component executes custom Python code safely within the workflow execution environment. It provides a sandboxed space equipped with helpers for input/output data handling and flow control.
Runtime Environment
The execution occurs inside a hardened Python 3 environment.Available Modules
You can leverage several standard libraries and helpful built-ins: Standard Libraries:json,uuid,time,datetime,zoneinfofunctools,traceback,copy,decimaltextwrap,math,re,abctyping,Union,Literal
ExceptionValueErrorExit: A special exception intentionally designed to exit the active code block immediately.
InvalidSessionObjectAlias: An alias violates the namespace grammar.InvalidThreadEnvelope/InvalidGraphEnvelope: The target object is missing, or is not a thread / graph.GraphMutationConflict: Anif_revoptimistic-lock check failed — the element changed since it was read.GraphTraversalLimitExceeded: Aquery_session_graphtraversal exceeded a hard bound.InvalidGraphQuery: A malformed traversal query.
Input & Output
Reading Inputs
You can access data arriving at the component’s input ports. Inputs are received as explicitly typed Value Objects.data_inputs: A list of all received input port data.get_data_input(route): A helper function to grab the Value Object of a specific input port by its exact route name.
Writing Outputs
You can emit data out of the component by pushing Value Objects to output routes.set_data_output(route, value, persist=False): Assigns a value to a targeted output port.route: Output port name (e.g., “result”).value: The Value Object payload.persist: IfTrue, stores the output specifically to processor data tracking logic for external visibility.
Flow Control
You determine which logic route the workflow should navigate following code execution.set_result(route, terminal=False): Declares the destination route.route: Connection edge to traverse ("success","failure", etc).terminal: Set toTrueif this intentionally ends the entire workflow execution.
exit(): Aborts the execution of the remainder of the active code script.
Helper Functions
Data Helpers
create_message(role, text=None, attribute_id=None): Generates a standardized “message” Value Object dynamically.create_value(data_type, data): Quickly wrap arbitrary matching data into a recognized Value structure.
Session Management
Every function below is bound to the execution’s own session — none of them takes asession_id, so your code
can only ever reach its own session’s objects. Names and behavior mirror the platform’s REST session commands
one-to-one, and the same validation applies here as on the REST API (alias grammar, thread/graph envelope checks,
size limits, graph mutation/traversal caps, and if_rev optimistic concurrency). Writes are attributed to the user
the execution runs as.
The request/response shapes for each function are documented in full on the linked operations reference pages
below — this section covers the signature, behavior, and return shape only.
Objects
A session object is a typed document addressed by analias — a path such as missions/a1/graph.
download_session_object(alias): Reads the value of a session object. Returns the typed payload, orNoneif it doesn’t exist. See Download Session Object.upload_session_object(alias, value): Writes/creates a session object, validating the alias. See Upload Session Object.delete_session_object(alias): Deletes a session object. If the object is athreadorgraphenvelope, this also cascades — deleting all of its child thread items / graph elements. See Session Objects for the envelope model (there’s no dedicated delete reference page).list_session_objects(prefix="", delimiter=None, cursor=None, limit=None): Lists session objects under an optional aliasprefix, with optionaldelimiter-based folder rollup and cursor pagination. Returns{"objects": [...], "cursor": ..., "common_prefixes": [...]}(the last key only whendelimiteris given). See List Session Objects.
Threads
Athread object holds an append-only list of items. Create the envelope first with
upload_session_object(alias, {"type": "thread", ...}) before posting to it.
post_session_thread_item(alias, content, parent_id=None, metadata=None): Appends an item.contentis a list of typed parts (e.g.[{"type": "text", "text": "..."}]);metadatais a free-form tag dict. Returns{"item": <item>}. See Post Session Thread Item.list_session_thread_items(alias, ascending=False, created_since=None, created_before=None, cursor=None, limit=None): Reads items, newest-first by default;created_since/created_beforebound the range (usecreated_sinceas a delta cursor). Returns{"items": [...], "cursor": ...}. See List Session Thread Items.get_session_thread_item(alias, item_id): Fetches a single item. Returns{"item": <item>}. See Get Session Thread Item.
Graphs
Agraph object holds vertices and edges. Create the envelope first with
upload_session_object(alias, {"type": "graph", ...}) — vertices and edges are then changed only via mutations.
apply_session_graph_mutations(alias, operations): Applies a batch of mutations (add_vertex,add_edge,set_vertex_props,set_edge_props,remove_*_props,delete_vertex,delete_edge), each optionally carryingif_revfor optimistic concurrency. Returns{"elements": [...], "changes": [...]}. See Apply Session Graph Mutations.query_session_graph(alias, query): Runs a bounded traversal against a query AST. Returns{"result": ...}. See Query Session Graph.list_session_graph_elements(alias, type=None, ascending=False, updated_since=None, ids_only=False, cursor=None, limit=None): Pages elements, optionally filtered totype"vertex"/"edge". Returns{"elements": [...], "cursor": ...}, or{"element_ids": [...], "cursor": ...}whenids_only=True. See List Session Graph Elements.get_session_graph_element(alias, element_id): Fetches one element. Returns{"element": ...}. See Get Session Graph Element.get_session_graph_elements(alias, element_ids): Batch-fetches elements. Returns{"elements": [...]}. See Get Session Graph Elements.list_session_graph_neighbors(alias, from_ids, direction, label=None, neighbor_label=None, cursor=None, limit=None): Expands adjacency fromfrom_ids(directionis"out"/"in"/"both", optionally filtered by edgelabel/neighbor_label). Returns{"edges": [...], "vertices": [...], "cursor": ...}. See List Session Graph Neighbors.
Advanced: optimistic concurrency
Mutations can carryif_rev to guard against a concurrent write. If another writer already advanced the element
since it was read, the call raises GraphMutationConflict instead of silently overwriting it — catch the
exception and reconcile on a later run:
Logging & Events
Produce informational, warning, or failure events logged to the execution stream:post_output_event(message)post_warning_event(message)post_error_event(message)
System Metadata
current_time_utc_iso(): Gets UTC time dynamically.result: The immediate runtime representation of the result dictionary.

