Skip to content

Node

junjo.Node

Kind: Class

SDK version: 0.64.0

Documentation channel: Next source preview

Node()

View source

Nodes are the building blocks of a workflow. They represent a single unit of work that can be executed within the context of a workflow.

Place business logic to be executed by the node in service. Junjo wraps that service method with OpenTelemetry tracing, error handling, and lifecycle hook dispatch during execute.

The Node type is meant to remain decoupled from your application’s domain logic. While you can place business logic directly in the service method, it is recommended that you call a service function located in a separate module. This keeps nodes easy to test, easier to understand, and focused on orchestration rather than implementation detail.

StoreT is the workflow store type that will be passed into this node during execution.

Nodes have three main responsibilities:

  • The workflow passes the run-local store to the node’s execute method.
  • execute manages tracing, lifecycle hooks, and error handling.
  • service performs the side effects for this unit of work.

.. rubric:: Example implementation

python class SaveMessageNode(Node[MessageWorkflowStore]): async def service(self, store) -> None: state = await store.get_state() sentiment = await get_message_sentiment(state.message) await store.set_message_sentiment(sentiment)

id: str

View source

Returns the unique identifier for the node.

name: str

View source

Returns the name of the node class instance.

service(store: StoreT) -> None

View source

This is the main logic of the node.

The concrete implementation of this method should contain the side effects that this node will perform. The method is called by execute, which is responsible for tracing, lifecycle dispatch, and error handling.

The service method should not be called directly. Instead, it should be called by the execute method of the node.

DO NOT EXECUTE node.service() DIRECTLY! Use node.execute() instead.

Name Type Description Default
store StoreT The run-local store passed to the node’s service
function.

execute(store: StoreT, parent_id: str) -> None

View source

Execute the node’s service method with tracing and lifecycle dispatch.

This method acquires a tracer, opens a node span, emits lifecycle events, and then calls service. Terminal lifecycle hooks are dispatched before the span closes so hook failure telemetry can stay attached to the real node span.

Name Type Description Default
store StoreT The run-local store for the current workflow execution.
parent_id str The identifier of the parent workflow or subflow.
This becomes the parent id recorded on the node span.