Skip to content
Closed
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
2 changes: 1 addition & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!-- knowledge
last_checked: "2026-10-29T01:01:00Z"
last_checked: "2026-11-05T13:32:51Z"
-->
# AGENTS

Expand Down
65 changes: 35 additions & 30 deletions ARCHITECTURE.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!-- knowledge
last_checked: "2026-11-02T01:58:31Z"
last_checked: "2026-11-05T13:34:13Z"
-->
# Architecture

Expand Down Expand Up @@ -34,14 +34,10 @@ The [Import Linter configuration](pyproject.toml) is the source of truth for
allowed package dependencies. [Layer regression tests](tests/test_import_layers.py)
exercise enforcement in CI.

The execution model shares graph/node schemas and
[container state](src/graphon/runtime/container_state.py);
[legacy snapshot migration](src/graphon/runtime/runtime_state/v2.py) uses graph
scoping, and [condition utilities](src/graphon/utils/condition/processor.py)
consume runtime interfaces. The public facade sits above this layer because it
re-exports `NodeFactory` and consumer contracts. These layers permit imports of
concrete node implementations from the facade; fresh-process tests below enforce
its node-registration guarantee.
Graph, nodes, runtime, utilities, and the variable loader share the execution
model layer. The `graphon.protocols` package sits above them so it can re-export
`NodeFactory` and node integration contracts. Importing that package must leave
concrete node registration to explicit node imports.

Import isolation and lazy registration are enforced by
[runtime import tests](tests/runtime/test_runtime_imports.py) and
Expand Down Expand Up @@ -165,32 +161,41 @@ compatibility details:
| Pause, resume, and snapshot quiescence | [Dispatcher](src/graphon/engine/dispatcher.py), [execution guard](src/graphon/runtime/execution.py) | [Serialization](tests/engine/test_runtime_state_serialization.py) |
| Snapshot versions and migrations | [Snapshot loading](src/graphon/runtime/runtime_state/snapshot.py) | [Runtime snapshots](tests/runtime/test_runtime_state.py), [version isolation](tests/test_snapshot_version_isolation.py) |

[Concrete segment models](src/graphon/variables/segments.py) own fixed `value_type` tags and value validation; serialized values select their model by that tag.
[Factories](src/graphon/variables/factory.py) infer types for raw values or validate explicit declarations, preserving declared empty arrays and `array[any]` values.
See [factory tests](tests/variables/test_factory.py) for declared types and serialized tag selection.
`array[any]` restores serialized [marked file values](src/graphon/file/constants.py) recursively inside arrays and objects using [File validation](src/graphon/file/models.py), preserving file values in container task and variable pool snapshots.
Unmarked objects retain their data, and invalid marked files fail validation; see [container tests](tests/nodes/test_container_effects.py) and [workflow tests](tests/workflows/test_full_engine_events.py).
[VariableBase.copy_with_value](src/graphon/variables/variables.py) validates replacements for assignment nodes, retaining identity and metadata and promoting integer variables when the new value is a float.
The [v1 assignment tests](tests/nodes/variable_assigner/test_v1_node.py) and [v2 assignment tests](tests/nodes/variable_assigner/test_v2_node.py) cover invalid updates, fractional results, and clearing arrays while preserving their declared type, including `array[file]`.

[Container values](src/graphon/nodes/container_effects.py) preserve declared segment types through construction, snapshots, and completion, including secret tags.
Explicit `to_segment()` conversion removes source variable identity so the parent pool binds completed outputs to the container's selectors.
Snapshot restoration uses the `SerializableSegment` discriminated union directly.
Pool conversion also assigns a new identity when storing an existing variable under a different selector; see [destination binding tests](tests/runtime/test_variable_pool.py).
Stored outputs remain typed; container node-result inputs and Loop/Iteration presentation events expose plain values.
The [runtime JSON converter](src/graphon/workflow_type_encoder.py) masks typed secrets using their log representation; hosts must apply redaction separately to plain values in logs and presentation.
The [container secret tests](tests/nodes/test_container_effects.py) cover this boundary; [Loop workflow tests](tests/workflows/test_full_engine_events.py) also cover v2 variable-input `OVER_WRITE` and `CLEAR` preserving the secret tag and masking.
[V2 input validation](src/graphon/nodes/variable_assigner/v2/helpers.py) rejects constant inputs for secret targets.

[Iteration](src/graphon/nodes/iteration/iteration_node.py) accepts array sequences, including tuples.
When its [handler](src/graphon/engine/container_handler/builtin/iteration.py) flattens outputs, matching declared array types survive in both serial and parallel runs; mixed array types become `array[any]`.
Empty iterations preserve the input array type and bind a separate output variable; see [workflow tests](tests/workflows/test_full_engine_events.py).
[Segment models](src/graphon/variables/segments.py) own value validation and
fixed `value_type` tags; [factories](src/graphon/variables/factory.py) infer raw
values or enforce declared types. Keep typed
[container values](src/graphon/nodes/container_effects.py) through requests,
completion, and snapshots so declared arrays, file values, and secret tags survive.
`to_segment()` removes source variable identity so completed outputs bind to
container selectors. Storing an existing variable at a different selector also
creates a new identity. Snapshot restoration uses the `SerializableSegment`
discriminated union directly. See
[factory tests](tests/variables/test_factory.py),
[container value tests](tests/nodes/test_container_effects.py), and
[destination binding tests](tests/runtime/test_variable_pool.py).
`array[any]` recursively restores serialized
[marked file values](src/graphon/file/constants.py) inside arrays and objects using
[File validation](src/graphon/file/models.py). Unmarked objects retain their data;
invalid marked files fail validation.

[Variable replacement](src/graphon/variables/variables.py) validates assignment
values while retaining identity and metadata; see the
[assignment tests](tests/nodes/variable_assigner/).
Stored container outputs remain typed, while node-result inputs and Loop/Iteration
presentation events expose plain values. The
[runtime JSON converter](src/graphon/workflow_type_encoder.py) masks typed secrets
using their log representation; hosts must redact plain values separately in logs
and presentation. The [container secret tests](tests/nodes/test_container_effects.py)
cover this boundary.
[V2 assignment validation](src/graphon/nodes/variable_assigner/v2/helpers.py) rejects
constant inputs for secret targets.

For host rendering, bind the engine's adapter with
[use_workflow_file_runtime](src/graphon/file/runtime.py); use
[EngineEventFilterContext.from_engine](src/graphon/engine/filter/protocol.py) to
wire response filters. Supply host adapters again when rebuilding from snapshots.
Runtime JSON conversion renders tuple file arrays as JSON lists within the same adapter scope; see [host file conversion tests](tests/variables/test_workflow_type_encoder.py).
Runtime JSON conversion renders tuple file arrays as JSON lists within the same
adapter scope; see [host file conversion tests](tests/variables/test_workflow_type_encoder.py).

Persist after fully consuming the run iterator or from a quiescent `on_graph_end`
hook. Hosts must also coordinate direct mutation of exposed runtime objects: the
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!-- knowledge
last_checked: "2026-10-29T01:01:00Z"
last_checked: "2026-11-05T13:32:51Z"
-->
# Contributing to Graphon

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!-- knowledge
last_checked: "2026-10-29T01:01:57Z"
last_checked: "2026-11-05T13:32:51Z"
-->
# Graphon

Expand Down
2 changes: 1 addition & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!-- knowledge
last_checked: "2026-10-29T01:01:00Z"
last_checked: "2026-11-05T13:32:51Z"
-->
# Repository knowledge

Expand Down
7 changes: 3 additions & 4 deletions docs/development.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!-- knowledge
last_checked: "2026-11-02T01:58:31Z"
last_checked: "2026-11-05T13:33:47Z"
-->
# Development navigation

Expand All @@ -16,9 +16,8 @@ Choose boundaries around state ownership and callers. Extract a responsibility
when it has independent ownership or repeated churn; file length alone does not
justify splitting a module.

For runtime values, let concrete types own their tags, validation, and value replacement.
Preserve typed values across state transfers and convert to plain values at presentation boundaries, where redaction is a separate responsibility.
Follow the [variable and container contracts](../ARCHITECTURE.md#state-and-execution-invariants) when changing those boundaries.
Follow the [state and execution invariants](../ARCHITECTURE.md#state-and-execution-invariants)
when changing variable types, container values, or presentation boundaries.

| Task | Start in source | Relevant checks |
| --- | --- | --- |
Expand Down
2 changes: 1 addition & 1 deletion docs/maintenance.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!-- knowledge
last_checked: "2026-10-29T01:01:00Z"
last_checked: "2026-11-05T13:32:51Z"
-->
# Maintaining repository knowledge

Expand Down
16 changes: 9 additions & 7 deletions docs/technical-debt.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!-- knowledge
last_checked: "2026-10-29T01:01:57Z"
last_checked: "2026-11-05T13:33:47Z"
-->
# Technical debt

Expand Down Expand Up @@ -79,10 +79,12 @@ successful node order. Keep the example small enough to serve as a reproduction.

## TD-09 — Performance feedback

The [benchmark](../benchmarks/test_engine_performance.py) does not isolate the
response-filter initialization cost, leaving a gap in performance feedback.
The [benchmark](../benchmarks/test_engine_performance.py) times raw `Engine.run()`
after graph and engine construction, without response filters. It does not cover
[response-filter initialization](../src/graphon/engine/filter/builtin/response_stream/filter.py),
leaving a gap in performance feedback.

Continue [PR #271](https://github.com/langgenius/graphon/pull/271) for the known
Continue the open [PR #271](https://github.com/langgenius/graphon/pull/271) for the known
response-filter initialization path and
[PR #266](https://github.com/langgenius/graphon/pull/266) for benchmark instructions.
Prefer deterministic complexity checks for that path and identify which phase a
Expand All @@ -95,10 +97,10 @@ and execution. Preserve existing benchmarks and

## TD-10 — Decision records

[Issue #199](https://github.com/langgenius/graphon/issues/199) and
The open [issue #199](https://github.com/langgenius/graphon/issues/199) and
[PR #200](https://github.com/langgenius/graphon/pull/200) cover decision records,
including HITL and model polling boundaries. Current behavior guides do not
substitute for accepted decisions.
including HITL and model polling boundaries. Their proposed mechanism has not
merged; current behavior guides do not substitute for accepted decisions.

Continue that work and reconcile it with [maintenance guidance](maintenance.md).
Promote approved lasting rules to stable guides and executable checks.
Expand Down
6 changes: 3 additions & 3 deletions examples/slim_llm/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!-- knowledge
last_checked: "2026-10-29T01:01:57Z"
last_checked: "2026-11-05T13:32:51Z"
-->
# Slim LLM Example

Expand All @@ -14,8 +14,8 @@ start -> llm -> answer
[graph.yml](graph.yml) defines the workflow; [dsl.py](dsl.py) imports it and
[code.py](code.py) constructs it directly. [settings.py](settings.py) handles
example configuration; the [Slim client](../../src/graphon/dsl/slim/client.py)
defines daemon configuration and binary lookup. Use
[credentials.example.json](credentials.example.json) as the credential schema.
defines daemon configuration and binary lookup. Start from the configuration in
[credentials.example.json](credentials.example.json).
Complete [repository setup](../../CONTRIBUTING.md#development-setup) first.

## Prepare
Expand Down
13 changes: 8 additions & 5 deletions src/graphon/engine/command/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!-- knowledge
last_checked: "2026-10-29T01:02:46Z"
last_checked: "2026-11-05T13:34:13Z"
-->
# Commands

Expand All @@ -10,14 +10,17 @@ literals, [CommandProcessor](processor.py) for dispatch, and the channel
implementations for [in-memory](builtin/in_memory.py) or
[Redis](builtin/redis.py) delivery. The
[dispatch tests](../../../../tests/engine/test_dispatch_patterns.py) cover
workflow control behavior. Successful variable writes also produce
[frame commit observations](../../../../ARCHITECTURE.md#raw-frame-observations),
including writes completed before a later command update fails.
workflow control behavior. Variable updates are not atomic: earlier writes remain
committed if a later update fails. Successful writes produce
[frame commit observations](../../../../ARCHITECTURE.md#raw-frame-observations).

## Usage

Pass the channel to [Engine](../engine.py) through `command_channel`; each
channel belongs to one workflow execution.
channel belongs to one workflow execution. The [dispatcher](../dispatcher.py)
polls it during execution, so sending a command does not apply it synchronously.
Pause is cooperative: queued work is deferred while active tasks finish. Persist
only after the run becomes [quiescent](../../../../ARCHITECTURE.md#state-and-execution-invariants).

```python
from graphon.engine import Engine
Expand Down
11 changes: 6 additions & 5 deletions src/graphon/engine/layer/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!-- knowledge
last_checked: "2026-10-29T01:02:46Z"
last_checked: "2026-11-05T13:34:13Z"
-->
# Layers

Expand All @@ -20,28 +20,29 @@ See [raw frame observations](../../../../ARCHITECTURE.md#raw-frame-observations)

Register a layer with [Engine.add_layer](../engine.py) before consuming
`engine.run()`. Registration binds read-only runtime access and a command channel
for execution controls.
for execution controls. Use event execution IDs for per-invocation data; graph-local
node IDs repeat across container frames.

```python
from graphon.engine.layer import Layer
from graphon.engine_events import EngineEvent, NodeRunSucceededEvent


class MetricsLayer(Layer):
def __init__(self):
def __init__(self) -> None:
"""Create storage for elapsed time collected during one engine run."""
super().__init__()
self.metrics: dict[str, float] = {}

def on_graph_start(self) -> None:
"""Reset collected metrics before the engine starts a new graph run."""
"""Reset collected metrics before execution starts or resumes."""
self.metrics.clear()

def on_event(self, event: EngineEvent) -> None:
"""Record elapsed time when a node run succeeds."""
if isinstance(event, NodeRunSucceededEvent) and event.finished_at is not None:
duration = event.finished_at - event.start_at
self.metrics[event.node_id] = duration.total_seconds()
self.metrics[event.id] = duration.total_seconds()
```

For snapshot persistence from hooks, follow the
Expand Down
22 changes: 13 additions & 9 deletions src/graphon/model_runtime/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!-- knowledge
last_checked: "2026-10-29T01:02:46Z"
last_checked: "2026-11-05T13:32:51Z"
-->
# Model Runtime

Expand All @@ -23,7 +23,7 @@ forms for host UIs. The
[model dispatch tests](../../../tests/model_runtime/test_model_dispatch.py)
verify that provider discovery and individual capabilities remain independent.

## Preserve provider message state
## Invocation results and provider state

Use `opaque_body` on [assistant messages and content items](entities/message_entities.py)
for JSON-serializable provider state, such as signatures or encrypted reasoning.
Expand All @@ -34,17 +34,21 @@ an assistant message nonempty. See the
[LargeLanguageModel](model_providers/base/large_language_model.py) keeps the last
non-`None` assistant state per invocation for blocking results and `on_after_invoke`.
Emit complete snapshots: each replaces the previous state. Mixed text and content
blocks retain their order and block state; see the
[dispatch tests](../../../tests/model_runtime/test_model_dispatch.py).
blocks retain their order and block state.
[SlimLLM](../dsl/slim/llm.py) shares this aggregation for blocking ordinary and
structured output calls, covered by the [Slim tests](../../../tests/dsl/test_slim_llm.py).

After a `LargeLanguageModel.invoke` stream is fully consumed without errors, `on_after_invoke` receives a result containing all tool calls, assembled with the same merging rules as blocking results.
Iteration failures, including before the first chunk, notify `on_invoke_error` once with the original exception before normal exception conversion and propagation, and skip `on_after_invoke`.
See the [callback regression tests](../../../tests/model_runtime/test_model_dispatch.py).
Fully consume a `LargeLanguageModel.invoke` stream to receive `on_after_invoke`
with the aggregated result, including tool calls. Stream iteration failures call
`on_invoke_error` with the original exception before error conversion and
propagation, and skip `on_after_invoke`. See the
[dispatch tests](../../../tests/model_runtime/test_model_dispatch.py).

Hosts can display chunks while calling `consume(chunk)` on one [LLMResultAccumulator](model_providers/base/large_language_model.py) per invocation.
After consuming the stream, call its `to_result(model=..., prompt_messages=...)` and use the returned `message` for replay or [JSON persistence](../../../tests/model_runtime/test_llm_result_accumulator.py).
Hosts can display chunks while calling `consume(chunk)` on one
[LLMResultAccumulator](model_providers/base/large_language_model.py) per invocation.
After consuming the stream, call `to_result(model=..., prompt_messages=...)` and use
the returned `message` for replay or
[JSON persistence](../../../tests/model_runtime/test_llm_result_accumulator.py).

[Prompt filtering](../nodes/llm/llm_utils.py) preserves state on supported blocks
and assistant messages with state but no content; see the
Expand Down
Loading