Skip to content

Commit dec2213

Browse files
deploy: 4bcd7d0
1 parent 7b7d5b9 commit dec2213

195 files changed

Lines changed: 1136 additions & 731 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

2.0/llms-full.txt

Lines changed: 174 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -721,7 +721,7 @@ Validation errors are returned in the standard control-plane error envelope with
721721

722722
# Signals
723723

724-
Signals allow you to trigger events in a workflow from outside the workflow. This can be useful for reacting to external events, enabling *human-in-the-loop* interventions, or for signaling the completion of an external task.
724+
Signals allow you to trigger events in a workflow from outside the workflow. This can be useful for reacting to external events, enabling *human-in-the-loop* interventions, or for signaling the completion of an external task. For repeated ordered inputs with durable cursor advancement, use [Message Streams](./message-streams.md).
725725

726726
## Named Signal Waits
727727

@@ -779,7 +779,7 @@ Signal behavior:
779779

780780
**Important:** The `await()` function should only be used in a workflow, not an activity.
781781

782-
For condition waits — waiting until a predicate over durable state becomes true — see [Condition Waits](./condition-waits.md). For a timeout-backed `await`, see [Signal + Timer](./signal+timer.md).
782+
For condition waits — waiting until a predicate over durable state becomes true — see [Condition Waits](./condition-waits.md). For a timeout-backed `await`, see [Signal + Timer](./signal+timer.md). For repeated inbox/outbox flows, see [Message Streams](./message-streams.md).
783783

784784
# Queries
785785

@@ -902,6 +902,145 @@ Those webhook routes accept the same JSON `arguments` field as Waterline, return
902902

903903
**Important:** Querying a workflow does not advance its execution, unlike signals.
904904

905+
# Message Streams
906+
907+
Message streams are the v2 authoring surface for repeated workflow messages:
908+
human input loops, assistant replies, workflow-to-workflow notifications, and
909+
other ordered messages that must survive replay and continue-as-new.
910+
911+
Workflow authors should use the first-class facade:
912+
913+
- `$this->inbox('stream-key')`
914+
- `$this->outbox('stream-key')`
915+
- `$this->messages('stream-key')`
916+
- `Workflow\V2\MessageStream`
917+
918+
Do not write `workflow_messages` rows or cursor rows directly from application
919+
workflow code. The facade is the stable contract; lower-level message services
920+
exist for package/runtime integration.
921+
922+
## Receiving Messages
923+
924+
Use `peek()` when a workflow needs to inspect pending inbound messages without
925+
advancing its durable cursor. Use `receive()` or `receiveOne()` when the
926+
workflow is ready to consume messages and record cursor advancement in history.
927+
928+
```php
929+
use Workflow\V2\Workflow;
930+
931+
final class ApprovalInboxWorkflow extends Workflow
932+
{
933+
public function handle(): array
934+
{
935+
$pending = $this->inbox('approval.requests')->peek(limit: 10);
936+
937+
if ($pending->isEmpty()) {
938+
return ['status' => 'waiting'];
939+
}
940+
941+
$message = $this->inbox('approval.requests')->receiveOne();
942+
943+
return [
944+
'status' => 'received',
945+
'payload_reference' => $message?->payload_reference,
946+
'correlation_id' => $message?->correlation_id,
947+
];
948+
}
949+
}
950+
```
951+
952+
`peek()` is read-only. `receive()` and `receiveOne()` mark messages consumed and
953+
advance the durable message cursor for the current run. Cursor advancement is a
954+
history fact, so replay, Waterline exports, and continue-as-new handoff can all
955+
reason about which inbound messages were already consumed.
956+
957+
## Sending References
958+
959+
Use `outbox(...)->sendReference(...)` when a workflow needs to publish an
960+
ordered outbound message. The message table stores routing metadata and a
961+
payload reference; large or application-owned content stays in the app's
962+
payload store.
963+
964+
```php
965+
use Workflow\V2\Workflow;
966+
967+
final class AssistantReplyWorkflow extends Workflow
968+
{
969+
public function handle(string $targetWorkflowId, string $replyReference): array
970+
{
971+
$message = $this->outbox('ai.assistant')->sendReference(
972+
targetInstanceId: $targetWorkflowId,
973+
payloadReference: $replyReference,
974+
correlationId: $this->workflowId(),
975+
metadata: ['kind' => 'assistant_reply'],
976+
);
977+
978+
return [
979+
'status' => 'sent',
980+
'stream' => $message->stream_key,
981+
'sequence' => $message->sequence,
982+
];
983+
}
984+
}
985+
```
986+
987+
This keeps the workflow history small and lets consumers validate the payload
988+
store separately from durable message ordering.
989+
990+
## Continue-As-New
991+
992+
Message streams are instance-first. When a workflow continues as new, pending
993+
inbound messages and the cursor position are transferred to the continued run.
994+
Consumed messages remain attached to the original run as historical evidence.
995+
996+
That means a long-lived workflow can shed history and keep the same public
997+
message route:
998+
999+
```php
1000+
use function Workflow\V2\continueAsNew;
1001+
use Workflow\V2\Workflow;
1002+
1003+
final class HumanInputLoopWorkflow extends Workflow
1004+
{
1005+
public function handle(int $iteration = 0): array
1006+
{
1007+
$message = $this->inbox('human.replies')->receiveOne();
1008+
1009+
if ($message === null) {
1010+
return ['status' => 'waiting', 'iteration' => $iteration];
1011+
}
1012+
1013+
if ($this->shouldContinueAsNew()) {
1014+
return continueAsNew($iteration + 1);
1015+
}
1016+
1017+
return [
1018+
'status' => 'processed',
1019+
'iteration' => $iteration,
1020+
'payload_reference' => $message->payload_reference,
1021+
];
1022+
}
1023+
}
1024+
```
1025+
1026+
The caller keeps addressing the workflow instance id. It does not need to know
1027+
which run currently owns the stream cursor.
1028+
1029+
## Authoring Rules
1030+
1031+
- Use semantic stream keys such as `ai.assistant`, `human.replies`, or
1032+
`approval.requests`; treat them as part of the workflow's public contract.
1033+
- Use `peek()` for inspection and `receive()` / `receiveOne()` for durable
1034+
consumption.
1035+
- Use `sendReference()` for outbound messages; store large payloads in an
1036+
application payload store and pass a reference.
1037+
- Keep application code on `Workflow::inbox()`, `Workflow::outbox()`, and
1038+
`MessageStream`; do not depend on `MessageService`, `WorkflowMessage`, or
1039+
cursor-row writes as the authoring pattern.
1040+
- For one-shot external events, use [Signals](./signals.md). For request/return
1041+
state changes, use [Updates](./updates.md). Use message streams when repeated
1042+
ordered messages need cursor semantics.
1043+
9051044
# Updates
9061045

9071046
Updates allow you to retrieve information about the current state of a workflow and mutate the workflow state at the same time. They are essentially both a query and a signal combined into one.
@@ -3314,7 +3453,7 @@ When a workflow continues as new, the new run inherits the previous run's metada
33143453
| Visibility labels | Carried forward as-is (set once at start time) |
33153454
| Business key | Carried forward as-is |
33163455
| Compatibility marker | Carried forward so the new run targets the same worker build |
3317-
| Message cursor position | Carried forward so the new run knows which inbound messages (signals/updates) were already consumed |
3456+
| Message cursor position | Carried forward so the new run knows which inbound messages were already consumed through [Message Streams](./message-streams.md) |
33183457

33193458
The new run starts with the inherited metadata and can continue upserting search attributes and memo from there. This means a long-lived polling workflow can accumulate metadata across generations without losing state when it sheds history.
33203459

@@ -3341,6 +3480,11 @@ class PollingWorkflow extends Workflow
33413480
}
33423481
```
33433482

3483+
For long-lived human-input or assistant loops, prefer the first-class
3484+
`$this->inbox()` / `$this->outbox()` [Message Streams](./message-streams.md)
3485+
facade. Pending stream messages and cursor position move to the continued run,
3486+
while consumed messages remain on the original run as history evidence.
3487+
33443488
# Versioning
33453489

33463490
Since workflows can run for long periods, sometimes months or even years, it's common to need to make changes to a workflow definition while executions are still in progress. Without versioning, modifying workflow code that affects the execution path would cause non-determinism errors during replay.
@@ -5422,6 +5566,27 @@ The export includes a SHA-256 integrity checksum. Set `DW_V2_HISTORY_EXPORT_SIGN
54225566

54235567
The exported `selected_run` block includes `waits_projection_source`, `timeline_projection_source`, `timers_projection_source`, and `lineage_projection_source`. The exported `links` block also includes `projection_source`, and the `links.parents` / `links.children` sections come from the selected run's typed lineage history first, so child-workflow and continue-as-new relationships remain visible in the bundle even if mutable link rows have drifted during a local experiment. When a lineage row is surviving only through older mutable compatibility data, the bundle now marks that entry with `history_authority = mutable_open_fallback` and `diagnostic_only = true` instead of silently rehydrating extra link metadata during export.
54245568

5569+
## AI Workflow Message Streams
5570+
5571+
Repeated AI or human-input workflows should use the first-class v2 message
5572+
stream facade as their authoring pattern:
5573+
5574+
```php
5575+
$reply = $this->inbox('ai.assistant')->receiveOne();
5576+
5577+
$this->outbox('ai.assistant')->sendReference(
5578+
targetInstanceId: $this->workflowId(),
5579+
payloadReference: $storedReplyReference,
5580+
correlationId: $requestId,
5581+
);
5582+
```
5583+
5584+
Keep app-owned payload storage for large request/response bodies, then pass
5585+
the stored reference through the stream. Do not teach new sample workflows to
5586+
write `workflow_messages`, `MessageStreamCursor`, or `MessageService` calls
5587+
directly. See [Message Streams](/docs/2.0/features/message-streams) for the
5588+
stable v2 inbox/outbox contract.
5589+
54255590
**Step 10**
54265591

54275592
Run the workflow and activity tests.
@@ -5504,6 +5669,12 @@ Use `simple` or `elapsed` as no-credential smoke tests. Use workflows with
55045669
external credentials only after the local environment contains the required
55055670
keys.
55065671

5672+
When an agent edits repeated AI or human-input workflows, point it at the v2
5673+
[Message Streams](/docs/2.0/features/message-streams) contract. The stable
5674+
authoring pattern is `Workflow::inbox()` / `Workflow::outbox()` /
5675+
`MessageStream`; direct `MessageService`, `WorkflowMessage`, or cursor-row
5676+
writes are runtime internals, not sample code patterns.
5677+
55075678
## Command And Diagnostic Contracts
55085679

55095680
Agents should prefer machine-readable surfaces over screenshots or prose:

404.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@
1313

1414

1515
<link rel="search" type="application/opensearchdescription+xml" title="Durable Workflow" href="/opensearch.xml"><link rel="stylesheet" href="/assets/css/styles.bdb910b5.css">
16-
<link rel="preload" href="/assets/js/runtime~main.64fe7c58.js" as="script">
17-
<link rel="preload" href="/assets/js/main.16d43852.js" as="script">
16+
<link rel="preload" href="/assets/js/runtime~main.b4618c80.js" as="script">
17+
<link rel="preload" href="/assets/js/main.00ef40b6.js" as="script">
1818
</head>
1919
<body class="navigation-with-keyboard">
2020
<script>!function(){function t(t){document.documentElement.setAttribute("data-theme",t)}var e=function(){var t=null;try{t=localStorage.getItem("theme")}catch(t){}return t}();t(null!==e?e:"dark")}()</script><div id="__docusaurus">
2121
<div role="region" aria-label="Skip to main content"><a class="skipToContent_fXgn" href="#docusaurus_skipToContent_fallback">Skip to main content</a></div><nav class="navbar navbar--fixed-top"><div class="navbar__inner"><div class="navbar__items"><button aria-label="Toggle navigation bar" aria-expanded="false" class="navbar__toggle clean-btn" type="button"><svg width="30" height="30" viewBox="0 0 30 30" aria-hidden="true"><path stroke="currentColor" stroke-linecap="round" stroke-miterlimit="10" stroke-width="2" d="M4 7h22M4 15h22M4 23h22"></path></svg></button><a class="navbar__brand" href="/"><div class="navbar__logo"><img src="/img/logo.svg" alt="Workflow Logo" class="themedImage_ToTc themedImage--light_HNdA"><img src="/img/logo.svg" alt="Workflow Logo" class="themedImage_ToTc themedImage--dark_i4oU"></div><b class="navbar__title text--truncate">Durable Workflow</b></a><a class="navbar__item navbar__link" href="/docs/installation/">Docs</a><div class="navbar__item dropdown dropdown--hoverable"><a class="navbar__link" aria-haspopup="true" aria-expanded="false" role="button" href="/docs/introduction/">1.x</a><ul class="dropdown__menu"><li><a class="dropdown__link" href="/docs/2.0/introduction/">2.0</a></li><li><a class="dropdown__link" href="/docs/introduction/">1.x</a></li></ul></div><a class="navbar__item navbar__link" href="/blog/">Blog</a></div><div class="navbar__items navbar__items--right"><a href="https://github.com/durable-workflow/workflow" target="_blank" rel="noopener noreferrer" aria-label="Star Durable Workflow on GitHub" class="navbar-github-star-link navbar__item navbar__link" label="Star on GitHub"><svg aria-hidden="true" class="navbar-github-star-link__icon" viewBox="0 0 16 16"><path d="M8 0C3.58 0 0 3.58 0 8a8.01 8.01 0 0 0 5.47 7.59c.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.5-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82A7.56 7.56 0 0 1 8 4.76c.68 0 1.36.09 2 .27 1.53-1.03 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.28.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.01 8.01 0 0 0 16 8c0-4.42-3.58-8-8-8Z"></path></svg><span class="navbar-github-star-link__count" title="GitHub stars">1.2K</span></a><a href="https://github.com/durable-workflow/workflow" target="_blank" rel="noopener noreferrer" aria-label="Star Durable Workflow on GitHub" class="navbar-github-star-link navbar__link navbar-github-star-link--mobile-topbar" label="Star on GitHub"><svg aria-hidden="true" class="navbar-github-star-link__icon" viewBox="0 0 16 16"><path d="M8 0C3.58 0 0 3.58 0 8a8.01 8.01 0 0 0 5.47 7.59c.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.5-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82A7.56 7.56 0 0 1 8 4.76c.68 0 1.36.09 2 .27 1.53-1.03 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.28.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.01 8.01 0 0 0 16 8c0-4.42-3.58-8-8-8Z"></path></svg><span class="navbar-github-star-link__count" title="GitHub stars">1.2K</span></a><div class="toggle_vylO colorModeToggle_x44X"><button class="clean-btn toggleButton_gllP toggleButtonDisabled_aARS" type="button" disabled="" title="Switch between dark and light mode (currently dark mode)" aria-label="Switch between dark and light mode (currently dark mode)" aria-live="polite"><svg viewBox="0 0 24 24" width="24" height="24" class="lightToggleIcon_pyhR"><path fill="currentColor" d="M12,9c1.65,0,3,1.35,3,3s-1.35,3-3,3s-3-1.35-3-3S10.35,9,12,9 M12,7c-2.76,0-5,2.24-5,5s2.24,5,5,5s5-2.24,5-5 S14.76,7,12,7L12,7z M2,13l2,0c0.55,0,1-0.45,1-1s-0.45-1-1-1l-2,0c-0.55,0-1,0.45-1,1S1.45,13,2,13z M20,13l2,0c0.55,0,1-0.45,1-1 s-0.45-1-1-1l-2,0c-0.55,0-1,0.45-1,1S19.45,13,20,13z M11,2v2c0,0.55,0.45,1,1,1s1-0.45,1-1V2c0-0.55-0.45-1-1-1S11,1.45,11,2z M11,20v2c0,0.55,0.45,1,1,1s1-0.45,1-1v-2c0-0.55-0.45-1-1-1C11.45,19,11,19.45,11,20z M5.99,4.58c-0.39-0.39-1.03-0.39-1.41,0 c-0.39,0.39-0.39,1.03,0,1.41l1.06,1.06c0.39,0.39,1.03,0.39,1.41,0s0.39-1.03,0-1.41L5.99,4.58z M18.36,16.95 c-0.39-0.39-1.03-0.39-1.41,0c-0.39,0.39-0.39,1.03,0,1.41l1.06,1.06c0.39,0.39,1.03,0.39,1.41,0c0.39-0.39,0.39-1.03,0-1.41 L18.36,16.95z M19.42,5.99c0.39-0.39,0.39-1.03,0-1.41c-0.39-0.39-1.03-0.39-1.41,0l-1.06,1.06c-0.39,0.39-0.39,1.03,0,1.41 s1.03,0.39,1.41,0L19.42,5.99z M7.05,18.36c0.39-0.39,0.39-1.03,0-1.41c-0.39-0.39-1.03-0.39-1.41,0l-1.06,1.06 c-0.39,0.39-0.39,1.03,0,1.41s1.03,0.39,1.41,0L7.05,18.36z"></path></svg><svg viewBox="0 0 24 24" width="24" height="24" class="darkToggleIcon_wfgR"><path fill="currentColor" d="M9.37,5.51C9.19,6.15,9.1,6.82,9.1,7.5c0,4.08,3.32,7.4,7.4,7.4c0.68,0,1.35-0.09,1.99-0.27C17.45,17.19,14.93,19,12,19 c-3.86,0-7-3.14-7-7C5,9.07,6.81,6.55,9.37,5.51z M12,3c-4.97,0-9,4.03-9,9s4.03,9,9,9s9-4.03,9-9c0-0.46-0.04-0.92-0.1-1.36 c-0.98,1.37-2.58,2.26-4.4,2.26c-2.98,0-5.4-2.42-5.4-5.4c0-1.81,0.89-3.42,2.26-4.4C12.92,3.04,12.46,3,12,3L12,3z"></path></svg></button></div><div class="searchBox_ZlJk"><button type="button" class="DocSearch DocSearch-Button" aria-label="Search"><span class="DocSearch-Button-Container"><svg width="20" height="20" class="DocSearch-Search-Icon" viewBox="0 0 20 20"><path d="M14.386 14.386l4.0877 4.0877-4.0877-4.0877c-2.9418 2.9419-7.7115 2.9419-10.6533 0-2.9419-2.9418-2.9419-7.7115 0-10.6533 2.9418-2.9419 7.7115-2.9419 10.6533 0 2.9419 2.9418 2.9419 7.7115 0 10.6533z" stroke="currentColor" fill="none" fill-rule="evenodd" stroke-linecap="round" stroke-linejoin="round"></path></svg><span class="DocSearch-Button-Placeholder">Search</span></span><span class="DocSearch-Button-Keys"></span></button></div></div></div><div role="presentation" class="navbar-sidebar__backdrop"></div></nav><div id="docusaurus_skipToContent_fallback" class="main-wrapper mainWrapper_z2l0"><main class="container margin-vert--xl"><div class="row"><div class="col col--6 col--offset-3"><h1 class="hero__title">Page Not Found</h1><p>We could not find what you were looking for.</p><p>Please contact the owner of the site that linked you to the original URL and let them know their link is broken.</p></div></div></main></div><div><footer class="footer footer--dark"><div class="container container-fluid"><div class="row footer__links"><div class="col footer__col"><div class="footer__title">Docs</div><ul class="footer__items clean-list"><li class="footer__item"><a class="footer__link-item" href="/docs/introduction/">Introduction</a></li><li class="footer__item"><a class="footer__link-item" href="/docs/installation/">Installation</a></li></ul></div><div class="col footer__col"><div class="footer__title">Community</div><ul class="footer__items clean-list"><li class="footer__item"><a href="https://discord.gg/xu5aDDpqVy" target="_blank" rel="noopener noreferrer" class="footer__link-item">Discord<svg width="13.5" height="13.5" aria-hidden="true" viewBox="0 0 24 24" class="iconExternalLink_nPIU"><path fill="currentColor" d="M21 13v10h-21v-19h12v2h-10v15h17v-8h2zm3-12h-10.988l4.035 4-6.977 7.07 2.828 2.828 6.977-7.07 4.125 4.172v-11z"></path></svg></a></li><li class="footer__item"><a href="https://x.com/DurableWorkflow" target="_blank" rel="noopener noreferrer" class="footer__link-item">X<svg width="13.5" height="13.5" aria-hidden="true" viewBox="0 0 24 24" class="iconExternalLink_nPIU"><path fill="currentColor" d="M21 13v10h-21v-19h12v2h-10v15h17v-8h2zm3-12h-10.988l4.035 4-6.977 7.07 2.828 2.828 6.977-7.07 4.125 4.172v-11z"></path></svg></a></li></ul></div><div class="col footer__col"><div class="footer__title">More</div><ul class="footer__items clean-list"><li class="footer__item"><a href="https://durable-workflow.com/llms-full.txt" target="_blank" rel="noopener noreferrer" class="footer__link-item">LLM Docs<svg width="13.5" height="13.5" aria-hidden="true" viewBox="0 0 24 24" class="iconExternalLink_nPIU"><path fill="currentColor" d="M21 13v10h-21v-19h12v2h-10v15h17v-8h2zm3-12h-10.988l4.035 4-6.977 7.07 2.828 2.828 6.977-7.07 4.125 4.172v-11z"></path></svg></a></li><li class="footer__item"><a href="https://packagist.org/packages/durable-workflow/workflow" target="_blank" rel="noopener noreferrer" class="footer__link-item">Packagist<svg width="13.5" height="13.5" aria-hidden="true" viewBox="0 0 24 24" class="iconExternalLink_nPIU"><path fill="currentColor" d="M21 13v10h-21v-19h12v2h-10v15h17v-8h2zm3-12h-10.988l4.035 4-6.977 7.07 2.828 2.828 6.977-7.07 4.125 4.172v-11z"></path></svg></a></li></ul></div></div><div class="footer__bottom text--center"><div class="footer__copyright">Copyright © 2026 <a href="https://durable-workflow.com">Durable Workflow</a>.</div></div></div></footer></div></div>
22-
<script src="/assets/js/runtime~main.64fe7c58.js"></script>
23-
<script src="/assets/js/main.16d43852.js"></script>
22+
<script src="/assets/js/runtime~main.b4618c80.js"></script>
23+
<script src="/assets/js/main.00ef40b6.js"></script>
2424
</body>
2525
</html>

0 commit comments

Comments
 (0)