Language SDKs
The Go, Python, Ruby, and TypeScript SDKs give application code a common way to describe work, start runs, use workers, and reach Hatchet platform APIs. The TypeScript family also supports serverless execution, provider-backed sandboxes, and pi-durable agent sessions. Each surface keeps the platform model visible while adapting it to the host language and runtime.
These SDKs sit under Developer products and integrations. Event entry points are described in External integrations and events.
SDK role
Workflow declarations
A workflow declaration is the application-facing description of work that Hatchet can register and run. It gives the platform a name, task graph, input shape, triggers, and run rules before a worker or another runtime executes the user code.
The shared model supports:
- Dependent and parallel tasks.
- Event, schedule, and cron triggers.
- Conditions that wait, skip, or cancel work.
- Retries, time limits, concurrency, rate limits, priorities, and routing labels.
- Idempotent runs and parent or child workflow links.
- Batch tasks where several ready runs share one handler call.
- Durable tasks that can wait, resume, and recover from saved state.
Durable tasks use recorded state to continue an existing run after a worker change or an eviction. This separates a durable run's identity from the process that currently owns it.
References: sdks/…/hatchet.py• L387-465 sdks/…/task.py• L190-279 sdks/…/workflow.py• L165-281 sdks/…/task.ts• L141-192
Client surfaces
Each SDK gives application code a client boundary for workflow and run control. The same boundary also exposes platform features such as events, schedules, logs, workers, and durable streams.
| Communication path | Role |
|---|---|
| REST or HTTP | Read and manage platform resources. |
| gRPC or Connect RPC | Register work, trigger runs, exchange task events, and stream assignments or durable data. |
The split lets short-lived application calls use request-and-response APIs while workers keep long-lived connections for assignments and completion events. Namespace and tenant identity apply across both paths.
Run calls return a run reference when the caller does not wait. The reference can later receive the result or report failure, cancellation, or timeout. The SDKs also support blocking and asynchronous forms, bulk submission, scheduled runs, and child runs.
References: sdks/…/hatchet.py• L69-110 sdks/…/admin.py• L239-368 sdks/…/workflow_run.py• L31-155 sdks/…/connection.py• L43-84 sdks/…/task.ts• L205-322
Durable topic streams
A durable topic is a stored message stream that is independent of one workflow run. Producers keep order for a topic, and readers use cursors to resume after a disconnect.
The stream contract includes:
- Publish, subscribe, metadata, and reset operations.
- Inline messages and larger payloads stored through the platform's payload path.
- Reconnect from the last delivered cursor.
- Batching when the engine supports it, with ordered single-message fallback for older engines.
This diagram shows the common publish and resume path.
sequenceDiagram
participant App as Application
participant SDK as SDK client
participant API as Platform stream APIs
App->>SDK: Publish message
SDK->>API: Store inline data or payload reference
API-->>SDK: Acknowledge ordered message
App->>SDK: Subscribe from start or cursor
SDK->>API: Read topic
API-->>SDK: Message and cursor
SDK-->>App: Message
App->>SDK: Resume with last cursor
References: sdks/…/streams.py• L35-52 sdks/…/streams.py• L549-607 sdks/…/streams.py• L672-722
Embedded local engine
The Go, Python, and TypeScript SDKs can place a Hatchet engine beside the application for local development and CI. Application code keeps using the normal client and workflow model, so local runs follow the same broad path as hosted runs.
The Python client starts or reuses a process-wide sidecar. The sidecar is downloaded when needed, checked before use, started with its connection details, and stopped with the client process. This mode is a local platform, not a second workflow API.
References: sdks/…/hatchet.py• L112-158 sdks/…/embedded.py• L233-278 sdks/…/embedded.py• L336-465
Shared execution flow
Workflow registration
Registration sends the workflow shape to the platform before work can run. A worker then advertises the actions it can serve, its labels, and its capacity. The platform matches future runs to an eligible worker.
The registration flow connects the application declaration to runtime capability:
sequenceDiagram
participant App as Application
participant SDK as SDK
participant Platform as Platform API
App->>SDK: Define workflow and tasks
SDK->>Platform: Register workflow definition
SDK->>Platform: Register worker capabilities
Platform-->>SDK: Accept registration and route actions
References: sdks/…/worker.py• L152-169 sdks/…/worker.py• L288-317 sdks/…/dispatcher.py• L69-103
Run triggering
A run begins when application code calls a workflow run method or when a configured event or schedule reaches the platform. The SDK sends the workflow name, input, and run options, then returns a run reference or waits for completion.
Run options carry the controls that affect placement and identity. They can include priority, metadata, idempotency, worker affinity, and links to a parent run. In a durable task, child workflow calls use the durable child path so replay does not submit the child twice.
sequenceDiagram
participant App as Application
participant SDK as Client
participant Platform as Workflow API
App->>SDK: Trigger workflow with input
SDK->>Platform: Create run
Platform-->>SDK: Run reference
alt Wait for result
SDK->>Platform: Observe run
Platform-->>SDK: Completion and output
SDK-->>App: Workflow result
else Do not wait
SDK-->>App: Run reference
end
References: sdks/…/workflow.py• L892-1097 sdks/…/admin.py• L298-368 sdks/…/admin.py• L439-502
Worker execution
A worker is the runtime that performs task code outside the platform. It registers a task action, listens for an assignment, builds a task context, invokes the matching function, and reports a started, completed, or failed event.
The context gives user code access to run identity, input, parent outputs, cancellation, logs, child runs, and task controls without exposing the worker connection. Durable contexts add waits, memo values, child spawning, and replay state.
This diagram shows the normal assignment path.
flowchart LR
A[Platform assignment] --> W[SDK worker]
W --> C[Task context]
C --> F[User function]
F -->|success| S[Completion event]
F -->|failure| E[Failure event]
S --> P[Platform run state]
E --> P
Workers also apply capacity and routing rules. A normal stop pauses new assignments, lets active work finish, sends remaining events, and then closes runtime connections.
References: sdks/…/action_listener.py• L151-281 sdks/…/runner.py• L205-241 sdks/…/runner.py• L829-886 sdks/…/worker.py• L584-629
Worker responsibilities
Action intake
Action intake is the worker's live link to the platform. The worker registers its action names and capacity, keeps the dispatcher stream healthy, and turns each assignment into the identity needed by the task runtime.
An action identifies the tenant, workflow, task, run, retry, parent or child relation, and batch or durable invocation when those apply. The action name must match the declaration that the worker registered.
References: sdks/…/dispatcher.py• L69-103 sdks/…/action_listener.py• L240-281 sdks/…/worker.py• L152-166
Task contexts
A task context is the safe application-facing link to one task attempt. It carries task input and run identity while giving user code access to platform actions such as logs, cancellation, output streams, timeout changes, slot release, and child runs.
Durable context methods record waits, memo values, and child work in the durable event flow. This lets a later invocation rebuild the task's logical state instead of repeating completed durable actions.
References: sdks/…/runner.py• L779-827 sdks/…/task.py• L281-387 sdks/…/durable_event_listener.py• L728-837
Capacity and routing
Capacity controls how much work a worker can own at once. Workers expose standard and durable capacity pools, while tasks can request labels, concurrency limits, or a larger slot cost.
Batch actions group several task runs into one handler call. The handler must return a result for each member unless the task declares one result for all members. This keeps platform run identity separate from the way user code groups work.
References: sdks/…/hatchet.py• L290-337 sdks/…/task.py• L391-440 sdks/…/runner.py• L501-679
Durable lifecycle
Durable workers keep a separate event connection for durable waits and completions. The connection carries wait, memo, child-run, completion, and eviction state. It reconnects by sending the worker's waiting state and the completion order already received.
When the engine supports newer durable features, the worker can evict waiting work and later restore it. Older engines use a compatibility path and do not provide the same eviction behavior. Engine capability checks therefore shape the feature set exposed to the task.
References: sdks/…/runner.py• L163-187 sdks/…/durable_event_listener.py• L220-240 sdks/…/durable_event_listener.py• L254-307 sdks/…/durable_event_listener.py• L435-481 sdks/…/pre_eviction.py• L1-49
Language SDK profiles
Go SDK
The Go SDK gives typed workflow, task, worker, run, feature, and durable stream surfaces for Go applications. It supports regular, durable, grouped, standalone, bulk, and child workflow use cases.
Its worker checks platform capabilities before using newer durable and retry features. Its stream client keeps topic publishes ordered, uses a payload path for large messages, and resumes reads with cursors. The SDK also supports an embedded engine for local runs.
References: sdks/…/client.go• L101-147 sdks/…/client.go• L195-219 sdks/…/client.go• L502-570 sdks/…/client.go• L599-689 sdks/…/client.go• L1062-1219 sdks/…/streams.go• L217-313
Python SDK
The Python SDK supports synchronous and asynchronous application code. Its main client joins workflow declarations, run control, feature clients, workers, streams, and local embedded execution.
The Python worker separates platform listening from task execution. It supports sync and async task functions, batch work, durable waits, retries, cancellation, capacity pools, and graceful shutdown. The Python stream client preserves publish order and resumes subscriptions from cursors.
References: sdks/…/hatchet.py• L69-110 sdks/…/hatchet.py• L290-337 sdks/…/worker.py• L288-367 sdks/…/runner.py• L829-981 sdks/…/streams.py• L415-722
Ruby SDK
The Ruby SDK uses block-based workflow and task declarations. Its client supports REST resource access, run control, workers, task contexts, durable work, and ordered durable topic streams.
Ruby workers advertise actions and labels, then run assigned blocks in their runtime. Its task model includes dependency graphs, retries, routing, idempotency, and batch configuration. A batch handler receives the grouped run inputs and returns member results or one broadcast result.
References: sdks/…/hatchet-sdk.rb• L73-120 sdks/…/worker_obj.rb• L155-272 sdks/…/context.rb• L16-211 sdks/…/batch.rb• L3-55
TypeScript SDK
The TypeScript SDK provides typed workflow and task declarations for several JavaScript runtimes. Its Node surface can run workers and long-lived streams, while its core surface uses fetch for applications that cannot start a Node worker.
The Node and core surfaces share workflow, run, event, log, and stream contracts. The core surface supports server-streaming reads but does not become a worker. This lets edge and short-lived runtimes trigger work and use platform APIs without taking ownership of assignments.
TypeScript task declarations cover routing, concurrency, idempotency, retries, batch work, and durable contexts. Durable tasks use a distinct context and eviction policy from normal tasks.
References: sdks/…/task.ts• L69-192 sdks/…/task.ts• L205-322 sdks/…/task.ts• L392-429 sdks/…/client.ts• L86-211
TypeScript serverless SDK
The TypeScript serverless SDK serves the same task declarations from an HTTP or WebSocket endpoint. It is for runtimes that cannot keep a worker process, such as edge functions or managed request handlers.
The operator learns the endpoint's workflows and runtime abilities from a signed health check. It then sends a signed task request. Short tasks can run over HTTP. Durable work and stream reads use an invocation WebSocket when the adapter supports it.
The endpoint does not have a worker identity, labels, heartbeats, or worker slots. The operator owns routing and liveness. A task can use the TypeScript core client for unary platform calls, while stream reads use the operator-relayed invocation connection.
This diagram shows the serverless boundary.
sequenceDiagram
participant Operator as Serverless operator
participant Endpoint as TypeScript endpoint
participant Client as Optional core client
participant API as Platform APIs
Operator->>Endpoint: Signed health check
Endpoint-->>Operator: Workflows and capabilities
Operator->>Endpoint: Signed HTTP or WebSocket invocation
Endpoint->>Endpoint: Run task context
opt Unary task action
Endpoint->>Client: Trigger, log, cancel, or update
Client->>API: Authenticated call
API-->>Client: Result
end
opt Stream read
Endpoint->>Operator: Stream request frame
Operator->>API: Operator-authorized stream
API-->>Operator: Stream data
Operator-->>Endpoint: Stream frames
end
Endpoint-->>Operator: Output, failure, or eviction
References: sdks/…/README.md• L1-20 sdks/…/healthcheck.ts• L24-51 sdks/…/trigger.ts• L30-161 sdks/…/task-client.ts• L79-105 sdks/…/task-client.ts• L230-266 sdks/…/invocation.ts• L175-319
TypeScript sandbox SDK
The TypeScript sandbox SDK gives a workflow a provider-backed workspace with a shell and files. Each sandbox operation is a Hatchet task, so it keeps workflow identity, task results, and platform access while the provider runs the workspace operation.
Applications can create, connect, list, and delete sandboxes. A sandbox can start from an image or snapshot, keep searchable metadata, stop after idle time, and resume from its latest snapshot. Commands return output and exit status. File operations use the same task path and can stage larger transfers outside the inline message limit.
This diagram shows the provider-backed sandbox path.
sequenceDiagram
participant App as TypeScript application
participant SDK as Sandbox SDK
participant API as Workflow APIs
participant Provider as Sandbox provider
App->>SDK: Create or connect workspace
SDK->>API: Run sandbox operation
API->>Provider: Execute command or file turn
Provider-->>API: Output and snapshot
API-->>SDK: Workflow result
SDK-->>App: Sandbox or operation result
References: sdks/…/README.md• L10-14 sdks/…/sandbox.ts• L15-52 sdks/…/sandbox.ts• L219-242 sdks/…/sandbox.ts• L245-341
TypeScript Pi Durable SDK
The TypeScript Pi Durable SDK hosts pi-durable agent sessions on Hatchet. A session is a durable home for conversations, tool calls, forks, and documents. Hatchet supplies one owner at a time, retries after a worker failure, schedules future wakeups, and runs coding tools in a sandbox.
The session task reads an inbox topic, applies validated input, fork, and abort messages, and publishes a full session view to a view topic. A SessionClient never calls the host directly. It publishes to the inbox, wakes the session, and reads the view. Request IDs make redelivery safe.
Session state can use local storage or the experimental HatchetStorage, which keeps the pi-durable storage log in a Hatchet durable stream topic. A worker reopens that topic and rebuilds the session from its commits, so a retry can resume on another worker. The topic must retain its oldest commit, and concurrent owners are not supported; an out-of-order commit makes the storage refuse a later open.
The session and sandbox state follow the conversation. A fork gets a new conversation and a sandbox restored from the snapshot at the fork point. The coding tools use a sandbox execution environment, so agent file and shell work does not touch the worker's own files.
sequenceDiagram
participant User as Client or web server
participant Streams as Hatchet topics
participant Host as Session task
participant Agent as pi-durable harness
participant Storage as Session storage
participant Sandbox as Hatchet sandbox
User->>Streams: Publish input, fork, or abort
User->>Host: Wake session
Host->>Streams: Read inbox from committed cursor
Host->>Storage: Open or update session state
Host->>Agent: Apply message and run conversation
Agent->>Sandbox: Read, write, edit, or run command
Sandbox-->>Agent: Tool result and snapshot
Agent-->>Host: Conversation state
Host->>Storage: Commit session state
Host->>Streams: Reset and publish latest view
User->>Streams: Read session view
The SDK keeps session ownership separate from agent storage. Local SQLite or JSONL storage only supports failover to a worker that can reach the same disk or volume. Hatchet-backed storage allows workers to reopen the state through the platform stream, but retention and one-owner rules still limit recovery.
References: sdks/…/README.md• L1-18 sdks/…/README.md• L105-132 sdks/…/index.ts• L1-44 sdks/…/hatchet-storage.ts• L1-18 sdks/…/hatchet-storage.ts• L73-149 sdks/…/hatchet-storage.ts• L151-192 sdks/…/session-host.ts• L1-9 sdks/…/session-host.ts• L145-159 sdks/…/session-host.ts• L219-275 sdks/…/client.ts• L1-73 sdks/…/protocol.ts• L7-34 sdks/…/extension.ts• L33-111 sdks/…/sandbox-env.ts• L131-185 sdks/…/hatchet-storage.e2e.test.ts• L31-150
Change checklist
When these files or sections are changed, remember to consider these:
- Keep workflow and task declaration fields aligned with registration, action lookup, and run-trigger contracts.
- Keep action names, namespaces, labels, and served-action sets aligned between workers and serverless health checks.
- Keep run options aligned across language clients, generated API models, and run references.
- Keep durable wait, memo, child-run, eviction, reconnect, and completion-order rules aligned across worker runtimes.
- Keep worker shutdown ordered so new assignment stops before task drain, event delivery, listener close, and unregister.
- Keep engine capability checks aligned with durable eviction, retry delays, batch publish fallback, and old-engine behavior.
- Keep stream producer sequencing, payload references, cursor resume, batching, and reset behavior aligned across SDKs.
- Keep TypeScript Node, core, serverless, sandbox, and pi-durable context and stream contracts aligned.
- Keep sandbox task names, provider and snapshot selection, metadata, file limits, and command result rules aligned with provider workflows.
- Keep pi-durable session topic names, inbox cursor commits, request IDs, view resets, session concurrency, and sandbox snapshots aligned.
- Keep pi-durable storage format, commit ordering, stream namespace, retention handling, and failover placement aligned between
HatchetStorageand the session host.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| A declaration and a worker or serverless endpoint use different action names or namespaces. | A run has no eligible runtime. | Use one naming and namespace rule across declarations, registration, triggering, and health checks. |
| A worker closes its assignment stream before active task events drain. | The platform can time out or reassign work that was still completing. | Pause new assignment, drain active work, deliver events, then close listeners. |
| A durable listener reconnects without restoring waiting state or completion order. | A durable task can wait forever or resume a later result too early. | Resend pending waits and received completion order after reconnect. |
| A connected engine lacks a requested durable or retry feature. | The option is ignored or uses an older fallback behavior. | Check engine capability and use a supported feature set. |
| A TypeScript serverless task tries to read a topic or run event from an ordinary HTTP invocation. | The task has no invocation socket for the operator-relayed stream. | Use a WebSocket invocation or a Node worker for stream reads. |
| A serverless endpoint advertises capabilities its adapter cannot provide. | The operator sends work over an unsupported transport. | Build health-check capabilities from the active adapter and runtime. |
| A sandbox uses a snapshot owned by another provider. | The provider cannot restore the workspace. | Keep provider selection with the snapshot's owner. |
| A sandbox is killed when its snapshots must be removed, or deleted when they must remain. | Recovery or cleanup has the wrong result. | Use kill for a recoverable stop and delete for full provider cleanup. |
| A pi-durable session loses its committed inbox cursor or session concurrency key. | A message can be replayed incorrectly or two hosts can own one session. | Commit the cursor with applied work and keep concurrency keyed by session ID. |
| A pi-durable retry cannot reach the storage opened by the prior owner. | The new owner cannot resume agent state. | Use shared storage or place failover workers on the same durable volume. |
| Hatchet-backed pi-durable storage loses its header or oldest commits to stream retention. | A worker cannot reconstruct the session and refuses to open the storage. | Set retention for the session lifetime and treat an expired topic as unrecoverable. |
| Two pi-durable owners append commits to one Hatchet storage topic. | The next open finds out-of-order sequence numbers and rejects the storage. | Enforce one session owner through task concurrency and avoid overlapping stale workers. |
| A Hatchet storage commit has an ambiguous publish failure. | Memory and the topic can disagree, so the current storage becomes unusable. | Reopen the storage before continuing and let the next owner recover the stored log. |
| A stream publish fails after the platform may have stored the message. | Reuse of the producer sequence can duplicate or reorder messages. | Rotate the producer after an ambiguous failure and serialize publishes per topic. |
Key files
| File | Why to read it |
|---|---|
| sdks/…/hatchet.py | Shows the Python client boundary, workflow declarations, workers, durable tasks, and embedded mode. |
| sdks/…/workflow.py | Shows how workflow declarations become platform definitions and run requests. |
| sdks/…/worker.py | Shows registration, worker health, capability checks, and graceful shutdown. |
| sdks/…/runner.py | Shows task context creation, execution, result events, cancellation, and durable capacity. |
| sdks/…/durable_event_listener.py | Shows durable waits, completion order, reconnect, and eviction state. |
| sdks/…/streams.py | Shows ordered durable topic publishing, payload handling, cursor reads, and reconnect. |
| sdks/…/client.go | Shows the Go client, worker, run, engine capability, and embedded entry points. |
| sdks/…/streams.go | Shows the Go durable topic contract and large-message path. |
| sdks/…/hatchet-sdk.rb | Shows the Ruby client and feature boundary. |
| sdks/…/worker_obj.rb | Shows Ruby worker registration, action intake, labels, and lifecycle. |
| sdks/…/batch.rb | Shows Ruby batch task grouping and result rules. |
| sdks/…/task.ts | Shows TypeScript task, durable task, batch, concurrency, and retry contracts. |
| sdks/…/client.ts | Shows the fetch-based TypeScript client for runtimes without Node workers. |
| sdks/…/index.ts | Shows the shared serverless request and runtime boundary. |
| sdks/…/invocation.ts | Shows durable serverless invocation and eviction handling. |
| sdks/…/sandbox.ts | Shows sandbox lifecycle, provider-backed turns, snapshots, and workflow integration. |
| sdks/…/session-host.ts | Shows session ownership, inbox processing, wakeups, sandbox setup, and view publishing. |
| sdks/…/client.ts | Shows how external callers wake sessions, send messages, and read views. |
| sdks/…/protocol.ts | Shows session topics, message types, request IDs, and view contracts. |
| sdks/…/hatchet-storage.ts | Shows the optional Hatchet-backed session storage, recovery rules, commit ordering, and retention errors. |
| sdks/…/extension.ts | Shows conversation sandbox state, snapshot recording, and coding tools. |
| sdks/…/sandbox-env.ts | Shows how pi-durable tools map to the Hatchet sandbox environment. |