Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions docs/development.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!-- knowledge
last_checked: "2026-11-26T01:14:08Z"
last_checked: "2026-11-27T03:17:49Z"
-->
# Development navigation

Expand Down Expand Up @@ -83,8 +83,17 @@ public surface.
[code runtime tests](../tests/dsl/test_code_runtime.py).
- **Human input:** inject the [HITLCallback](../src/graphon/nodes/human_input/entities.py)
into [HumanInputNode](../src/graphon/nodes/human_input/human_input_node.py).
The host returns a pause, completed, or expired decision. See
The host returns a pause, completed, or expired decision. The built-in node
still emits the deprecated `HitlRequired` reason. See
[human-input tests](../tests/nodes/human_input/) for the event contract.
- For new integrations, yield `PauseRequestedEvent` with
[`ExternalWait`](../src/graphon/entities/pause_reason.py), the general-purpose
pause reason for waits such as human input or an external service result. It requires
a `wait_type` of one or more dot-separated ASCII identifiers and an opaque
`wait_id` string whose meaning the host defines. Reserve `dify.*` for upstream
Dify producers. Include `node_id` and `node_title` to identify the node in the
graph, and `node_execution_id` and `frame_id` to identify the execution that
requested the pause. See the [round-trip tests](../tests/runtime/test_external_wait.py).

## Validate the behavior you changed

Expand Down
38 changes: 37 additions & 1 deletion src/graphon/entities/pause_reason.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from typing import Annotated, Literal, cast

from pydantic import BaseModel, BeforeValidator, ConfigDict, Field
from typing_extensions import deprecated


class PauseReasonType(StrEnum):
Expand All @@ -14,9 +15,13 @@ class PauseReasonType(StrEnum):

HITL_REQUIRED = auto()
SCHEDULED_PAUSE = auto()
EXTERNAL_WAIT = auto()


@deprecated("Use ExternalWait for new pause reasons.", category=None)
class HitlRequired(BaseModel):
"""Deprecated human-input pause reason emitted by the built-in Human Input node."""

model_config = ConfigDict(extra="forbid")

TYPE: Literal[PauseReasonType.HITL_REQUIRED] = PauseReasonType.HITL_REQUIRED
Expand All @@ -31,6 +36,37 @@ class SchedulingPause(BaseModel):
message: str


class ExternalWait(BaseModel):
"""General-purpose pause reason for a node awaiting a host-managed result.

Nodes can use this reason to wait for human input or an external service.
The host defines the meaning of ``wait_id`` for each ``wait_type`` and
resumes the waiting execution when the result is ready.
"""

model_config = ConfigDict(frozen=True)

TYPE: Literal[PauseReasonType.EXTERNAL_WAIT] = PauseReasonType.EXTERNAL_WAIT
# Hosts use this type to interpret wait_id. The dify.* namespace is
# reserved for wait types defined by upstream Dify.
# PEG grammar for wait_type:
# WAIT_TYPE <- IDENTIFIER ('.' IDENTIFIER)* !.
# IDENTIFIER <- [A-Za-z_] [A-Za-z0-9_]*
wait_type: str = Field(
pattern=r"^[A-Za-z_][A-Za-z0-9_]*(\.[A-Za-z_][A-Za-z0-9_]*)*$"
)
# Opaque identifier of the work the host is waiting for.
wait_id: str
# ID of the node in the graph definition, shared across its executions.
node_id: str = Field(min_length=1)
# Display title of the node at the time it requested the pause.
node_title: str
# ID of the specific node execution that requested the pause.
node_execution_id: str = Field(min_length=1)
# ID of the execution frame containing that node execution.
frame_id: str = Field(min_length=1)


class _LegacyHumanInputRequired(BaseModel):
"""
This model serves as documentation purpose. DO NOT USE.
Expand Down Expand Up @@ -71,7 +107,7 @@ def _decode_pause_reason(value: object) -> object:


type PauseReason = Annotated[
HitlRequired | SchedulingPause,
HitlRequired | SchedulingPause | ExternalWait, # ty: ignore[deprecated]
Field(discriminator="TYPE"),
BeforeValidator(_decode_pause_reason),
]
4 changes: 2 additions & 2 deletions src/graphon/nodes/human_input/human_input_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from collections.abc import Generator, Mapping, Sequence
from typing import Any, override

from graphon.entities.pause_reason import HitlRequired
from graphon.entities.pause_reason import HitlRequired # ty: ignore[deprecated]
from graphon.enums import (
BuiltinNodeTypes,
NodeExecutionType,
Expand Down Expand Up @@ -72,7 +72,7 @@ def _run(self) -> Generator[NodeEventPayload, None, None]:
match decision:
case PauseRequested(session_id=session_id):
yield PauseRequestedEvent(
reason=HitlRequired(
reason=HitlRequired( # ty: ignore[deprecated]
session_id=session_id,
node_id=self.id,
node_title=self.title,
Expand Down
6 changes: 3 additions & 3 deletions tests/engine/test_dispatch_patterns.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
GraphEdgeSkippedEvent,
GraphEdgeTakenEvent,
)
from graphon.entities.pause_reason import HitlRequired, SchedulingPause
from graphon.entities.pause_reason import HitlRequired, SchedulingPause # ty: ignore[deprecated]
from graphon.enums import (
BuiltinNodeTypes,
ErrorHandleMode,
Expand Down Expand Up @@ -1135,7 +1135,7 @@ def test_pause_requested_event_defers_current_task_for_resume() -> None:
id="human-run",
node_id="human",
node_type=BuiltinNodeTypes.HUMAN_INPUT,
reason=HitlRequired(
reason=HitlRequired( # ty: ignore[deprecated]
session_id="session-1",
node_id="human",
node_title="Human",
Expand Down Expand Up @@ -1325,7 +1325,7 @@ def test_frame_registry_restores_child_frame() -> None:
assert child_frame.graph.nodes["start"].state == NodeState.TAKEN

graph_execution.pause(
HitlRequired(
HitlRequired( # ty: ignore[deprecated]
session_id="session-1",
node_id="start",
node_title="Start",
Expand Down
4 changes: 2 additions & 2 deletions tests/engine/test_response_stream_pause.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
NodeRunStreamChunkEvent,
NodeRunSucceededEvent,
)
from graphon.entities.pause_reason import HitlRequired, SchedulingPause
from graphon.entities.pause_reason import HitlRequired, SchedulingPause # ty: ignore[deprecated]
from graphon.entities.workflow_start_reason import WorkflowStartReason
from graphon.nodes.human_input.entities import (
Completed,
Expand Down Expand Up @@ -200,7 +200,7 @@ def test_hitl_snapshots_resume_stream_without_replaying_prefix(
) -> None:
saved = checkpoints.first if paused_at == "first" else checkpoints.second
assert saved.pause.reasons == [
HitlRequired(
HitlRequired( # ty: ignore[deprecated]
session_id=f"session-{paused_at}",
node_id=paused_at,
node_title=f"{paused_at.title()} approval",
Expand Down
6 changes: 3 additions & 3 deletions tests/engine/test_runtime_state_serialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
NodeRunSucceededEvent,
)
from graphon.entities.graph_config import NodeConfigDict
from graphon.entities.pause_reason import HitlRequired
from graphon.entities.pause_reason import HitlRequired # ty: ignore[deprecated]
from graphon.entities.workflow_start_reason import WorkflowStartReason
from graphon.enums import (
BuiltinNodeTypes,
Expand Down Expand Up @@ -875,7 +875,7 @@ def pause_after_one_round(context: HITLContext) -> Completed | PauseRequested:
]
assert len(pause_requests) == 1
assert pause_requests[0].container_id == "loop"
assert pause_requests[0].reason == HitlRequired(
assert pause_requests[0].reason == HitlRequired( # ty: ignore[deprecated]
session_id="session-human-input",
node_id="human-input",
node_title="Approve loop round",
Expand Down Expand Up @@ -1082,7 +1082,7 @@ def pause_with_active_sibling(
resume_tasks = [task for task in deferred_tasks if isinstance(task, ResumeTask)]
assert len(pause_requests) == 1
assert pause_requests[0].container_id == "iteration"
assert pause_requests[0].reason == HitlRequired(
assert pause_requests[0].reason == HitlRequired( # ty: ignore[deprecated]
session_id="session-beta",
node_id="human-input",
node_title="Approve iteration item",
Expand Down
8 changes: 4 additions & 4 deletions tests/entities/test_pause_reason.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from pydantic import BaseModel, ValidationError

from graphon.entities.pause_reason import (
HitlRequired,
HitlRequired, # ty: ignore[deprecated]
PauseReason,
SchedulingPause,
)
Expand All @@ -28,7 +28,7 @@ class TestPauseReasonDiscriminator:
"node_title": "node_title",
},
},
HitlRequired(
HitlRequired( # ty: ignore[deprecated]
session_id="session-1",
node_id="node_id",
node_title="node_title",
Expand Down Expand Up @@ -58,7 +58,7 @@ def test_model_validate(
@pytest.mark.parametrize(
"reason",
[
HitlRequired(
HitlRequired( # ty: ignore[deprecated]
session_id="session-1",
node_id="node_id",
node_title="node_title",
Expand Down Expand Up @@ -122,7 +122,7 @@ def test_legacy_human_input_required_json_can_be_restored_via_pause_reason(

holder = _Holder.model_validate_json(payload)

assert isinstance(holder.reason, HitlRequired)
assert isinstance(holder.reason, HitlRequired) # ty: ignore[deprecated]
assert holder.reason.TYPE == "hitl_required"
assert holder.reason.session_id == "form-1"
assert holder.reason.node_id == "node_id"
Expand Down
4 changes: 2 additions & 2 deletions tests/nodes/human_input/test_human_input_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import pytest

from graphon.engine_events.node import NodeRunPauseRequestedEvent, NodeRunSucceededEvent
from graphon.entities.pause_reason import HitlRequired
from graphon.entities.pause_reason import HitlRequired # ty: ignore[deprecated]
from graphon.nodes.human_input.entities import (
Completed,
Expired,
Expand Down Expand Up @@ -70,7 +70,7 @@ def callback(ctx: HITLContext) -> HITLDecision:
variable_pool=captured_contexts[0].variable_pool,
)
]
assert paused.reason == HitlRequired(
assert paused.reason == HitlRequired( # ty: ignore[deprecated]
session_id="session-1",
node_id="human-node",
node_title="Collect Input",
Expand Down
Loading
Loading