Hooks
junjo.Hooks
Kind: Class
SDK version: 0.64.0
Documentation channel: Next source preview
Signature
Section titled “Signature”Hooks()Registry for optional Junjo lifecycle callbacks.
Hooks are observers. They do not create spans or control Workflow or Agent execution. If a hook callback raises, Junjo keeps execution isolated and continues dispatching the remaining callbacks for that hook.
To use them, register one or more callbacks and pass the registry to a Workflow, Subflow, or Agent definition.
Every on_* registration method returns an unsubscribe callback. Call
the returned function when the callback should no longer receive events.
.. rubric:: Example
``python import logging
hooks = Hooks() logger = logging.getLogger(name)
def log_completed(event: WorkflowCompletedEvent[MyState]) -> None: logger.info(“%s %s”, event.hook_name, event.result.state.model_dump())
unsubscribe = hooks.on_workflow_completed(log_completed)
workflow = Workflow(…, hooks=hooks)
Later, if this callback should no longer run:
Section titled “Later, if this callback should no longer run:”unsubscribe() ``
Members
Section titled “Members”on_workflow_started
Section titled “on_workflow_started”on_workflow_started(callback: HookCallback[WorkflowStartedEvent]) -> Callable[[], None]Register a callback for the start of a top-level workflow run.
on_workflow_completed
Section titled “on_workflow_completed”on_workflow_completed(callback: HookCallback[WorkflowCompletedEvent[StateT]]) -> Callable[[], None]Register a callback for successful workflow completion.
on_workflow_failed
Section titled “on_workflow_failed”on_workflow_failed(callback: HookCallback[WorkflowFailedEvent[StateT]]) -> Callable[[], None]Register a callback for workflow failures.
on_workflow_cancelled
Section titled “on_workflow_cancelled”on_workflow_cancelled(callback: HookCallback[WorkflowCancelledEvent[StateT]]) -> Callable[[], None]Register a callback for workflow cancellation.
on_subflow_started
Section titled “on_subflow_started”on_subflow_started(callback: HookCallback[SubflowStartedEvent]) -> Callable[[], None]Register a callback for subflow start events.
on_subflow_completed
Section titled “on_subflow_completed”on_subflow_completed(callback: HookCallback[SubflowCompletedEvent[StateT]]) -> Callable[[], None]Register a callback for successful subflow completion.
on_subflow_failed
Section titled “on_subflow_failed”on_subflow_failed(callback: HookCallback[SubflowFailedEvent[StateT]]) -> Callable[[], None]Register a callback for subflow failures.
on_subflow_cancelled
Section titled “on_subflow_cancelled”on_subflow_cancelled(callback: HookCallback[SubflowCancelledEvent[StateT]]) -> Callable[[], None]Register a callback for subflow cancellation.
on_node_started
Section titled “on_node_started”on_node_started(callback: HookCallback[NodeStartedEvent]) -> Callable[[], None]Register a callback for node start events.
on_node_completed
Section titled “on_node_completed”on_node_completed(callback: HookCallback[NodeCompletedEvent]) -> Callable[[], None]Register a callback for successful node completion.
on_node_failed
Section titled “on_node_failed”on_node_failed(callback: HookCallback[NodeFailedEvent]) -> Callable[[], None]Register a callback for node failures.
on_node_cancelled
Section titled “on_node_cancelled”on_node_cancelled(callback: HookCallback[NodeCancelledEvent]) -> Callable[[], None]Register a callback for node cancellation.
on_run_concurrent_started
Section titled “on_run_concurrent_started”on_run_concurrent_started(callback: HookCallback[RunConcurrentStartedEvent]) -> Callable[[], None]Register a callback for RunConcurrent start events.
on_run_concurrent_completed
Section titled “on_run_concurrent_completed”on_run_concurrent_completed(callback: HookCallback[RunConcurrentCompletedEvent]) -> Callable[[], None]Register a callback for successful RunConcurrent completion.
on_run_concurrent_failed
Section titled “on_run_concurrent_failed”on_run_concurrent_failed(callback: HookCallback[RunConcurrentFailedEvent]) -> Callable[[], None]Register a callback for RunConcurrent failures.
on_run_concurrent_cancelled
Section titled “on_run_concurrent_cancelled”on_run_concurrent_cancelled(callback: HookCallback[RunConcurrentCancelledEvent]) -> Callable[[], None]Register a callback for RunConcurrent cancellation.
on_state_changed
Section titled “on_state_changed”on_state_changed(callback: HookCallback[StateChangedEvent[StateT]]) -> Callable[[], None]Register a callback for committed state updates.
on_agent_started
Section titled “on_agent_started”on_agent_started(callback: HookCallback[AgentStartedEvent]) -> Callable[[], None]Register a callback for admitted Agent execution start.
on_agent_completed
Section titled “on_agent_completed”on_agent_completed(callback: HookCallback[AgentCompletedEvent]) -> Callable[[], None]Register a callback for successful Agent completion.
on_agent_failed
Section titled “on_agent_failed”on_agent_failed(callback: HookCallback[AgentFailedEvent]) -> Callable[[], None]Register a callback for admitted Agent execution failure.
on_agent_cancelled
Section titled “on_agent_cancelled”on_agent_cancelled(callback: HookCallback[AgentCancelledEvent]) -> Callable[[], None]Register a callback for admitted Agent execution cancellation.