Hooks
Hooks are the public node-level runtime API (import from kortyx).
Use them for four things:
- run model reasoning
- pause for human input
- keep short-lived runtime state
- emit structured UI payloads
Quick Selection
- Need an LLM call in a node:
useReason(...) - Need manual human-in-the-loop input:
useInterrupt(...) - Need state local to one node execution flow:
useNodeState(...) - Need state shared across nodes in the same run:
useWorkflowState(...) - Need UI-ready structured events in stream:
useStructuredData(...)
useReason(...)
Use this for the main model call in a node.
Typical use:
- schema-constrained outputs
- optional interrupt flow (
interrupt) - structured stream payloads (
structured)
Behavior:
- First pass is a single model call that produces draft output and interrupt request.
- Runtime emits
interruptand pauses. - Resume continues from the
useReasoncheckpoint and runs the continuation pass.
Optional blocks and guarantees:
structuredis optional.interruptis optional.- If
interruptis provided,useReasonalways runs interrupt mode. It is not model-optional. - The model still needs to return schema-valid JSON for that mode; if it does not,
useReasonthrows a validation error. - If
structuredis provided, runtime emits structured stream payloads when valid structured output is available (typically withoutputSchema).
useInterrupt({ request, ...schemas })
Use this when you want fully manual interrupt payloads without LLM-generated request shaping.
Return:
stringfortextandchoicestring[]formulti-choice
useNodeState and useWorkflowState
Node-local state:
Workflow-shared state:
State Lifetime and Limits
useNodeState:
- Persists for repeated executions of the same node inside one run (retries, direct self-loops, interrupt resume replay).
- Is node-local only; do not treat it as cross-node shared state.
useWorkflowState:
- Persists across nodes and workflow transitions within the same run.
- Restores on interrupt resume for that run.
Across messages/sessions:
- Hook state is not a long-term session store. A new chat request starts a new run with fresh hook state.
- For cross-request persistence, call your own DBs or service clients from node code.
Durability and practical limits:
- Hook state is tied to runtime checkpoint persistence.
- In-memory framework adapter is process-local and not restart-safe.
- Redis framework adapter can restore across restarts until TTL expiry (
KORTYX_FRAMEWORK_TTL_MS/ adapterttlMs). - Keep hook state small and JSON-serializable; large objects increase checkpoint size and resume cost.
Practical guideline:
- use hook state for runtime flow control
- use your own DB or service layer for data that must survive across requests/users
useStructuredData(...)
useStructuredData emits structured_data from the current node context for UI consumption.
Good to know: On resume, node code starts again from the top.
useReasoncontinues from its internal checkpoint, but code beforeuseReasoncan run again. KeepuseReasonas the first meaningful operation and guard pre-useReasonside effects withuseNodeState.