Skip to content

Commit 0ed77fc

Browse files
authored
docs: sync parallel step ownership and default chat runtime docs with shipped code (#404)
1 parent 80c3540 commit 0ed77fc

4 files changed

Lines changed: 25 additions & 19 deletions

File tree

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ If you're building a plugin that needs an AI agent — one that can hold a conve
66

77
It's a small, focused WordPress package maintained by Automattic. Think of it as the layer that sits *underneath* your product: it owns the boring-but-important parts (agent identity, runtime contracts, tool mediation, sessions, transcripts, memory, workflow scaffolding), so your plugin can focus on what makes it special.
88

9-
**What you get out of the box:** a way to register agents, a messaging channel base class that plugs into any transport, value objects for the agent lifecycle, contracts for tools and memory and consent, and lightweight workflow plumbing (spec, validator, runner skeleton, three abilities, an optional Action Scheduler bridge).
9+
**What you get out of the box:** a way to register agents, a fallback provider-agnostic `agents/chat` runtime, a messaging channel base class that plugs into any transport, value objects for the agent lifecycle, contracts for tools and memory and consent, and lightweight workflow plumbing (spec, validator, runner, default `ability`, `agent`, `foreach`, and `parallel` step handlers, three abilities, and optional Action Scheduler-backed async branch execution).
1010

11-
**What you don't get — and shouldn't expect:** a concrete workflow runtime, durable run history, an editor UI, admin screens, or any provider-specific AI client. Those belong to your product. Agents API is the substrate, not the application.
11+
**What you don't get — and shouldn't expect:** durable workflow history, a workflow editor UI, admin screens, or any provider-specific AI client. Those belong to your product. Agents API is the substrate, not the application.
1212

1313
New here? Start with the [Introduction](docs/introduction.md) — it breaks down the core concepts and vocabulary in plain language — then browse the [developer documentation](docs/README.md).
1414

@@ -48,13 +48,13 @@ Agents API sits between tool/action discovery and product-specific automation. I
4848
- Tool source registration, parameter normalization, tool-call mediation, and execution result contracts.
4949
- Session and persistence contracts where they are provider-neutral.
5050
- Retrieved context authority vocabulary, context item shape, and conflict resolution contracts.
51-
- Workflow spec value object, structural validator, in-memory registry, abstract runner with `ability` and `agent` step types, `Store` and `Run_Recorder` interfaces, optional Action Scheduler bridge, and three canonical abilities (`agents/run-workflow`, `agents/validate-workflow`, `agents/describe-workflow`).
51+
- Workflow spec value object, structural validator, in-memory registry, runner with default `ability`, `agent`, `foreach`, and `parallel` step handlers, `Store` and `Run_Recorder` interfaces, optional Action Scheduler bridge and branch executor, and three canonical abilities (`agents/run-workflow`, `agents/validate-workflow`, `agents/describe-workflow`).
5252
- Runtime package workflow execution request/result contracts and the canonical dispatcher ability (`agents/run-runtime-package`) for consumer-owned package materialization and execution adapters.
5353

5454
## What Agents API Does Not Own
5555

5656
- Provider-specific request code. `wp-ai-client` owns provider/model prompt execution.
57-
- Concrete workflow runtimes, durable workflow / run history, scheduling adapters beyond the optional Action Scheduler bridge, workflow editor UI, and product-specific step types (`branch`, `parallel`, nested `workflow`). The substrate provides the contract surface; consumers ship the persistence and product UX.
57+
- Durable workflow / run history, scheduling adapters beyond the optional Action Scheduler bridge and branch executor, workflow editor UI, and product-specific step types (`branch`, nested `workflow`). The substrate provides default in-process step execution plus an optional Action Scheduler path for async `parallel` branches; consumers ship the persistence and product UX.
5858
- Product UI such as admin pages, settings screens, dashboards, or onboarding.
5959
- Product CLI commands beyond generic substrate needs.
6060
- Public REST controllers in v1 unless they are separately designed.

docs/channels-workflows-operations.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ array(
6464

6565
The channel can consume either a single `reply` or assistant `messages` from the ability result. It stores a returned `session_id` before sending replies so delivery failures do not lose session continuity. `agents/chat` also exposes a canonical `run_id`; runtimes receive a generated `run_id` in the input when callers omit one, and responses include that same ID unless the runtime returns its own.
6666

67+
Agents API registers a default `agents/chat` runtime as a fallback at `wp_agent_chat_handler` priority 1000. The fallback resolves provider and model from the chat input first, then from the registered agent's default config, and returns a validation error when either value is missing. Consumer runtimes normally register their own handler at the default priority 10, so they win before the fallback runs.
68+
6769
## Chat run control
6870

6971
Agents API owns the generic run-control ability contracts and default run-control storage. Every `agents/chat` run receives a `run_id`, stores status when a session is known, accepts best-effort cancellation, and accepts queued follow-up messages. Runtimes may override the hooks below only when they can provide stronger behavior such as immediate provider aborts or a custom queue worker.
@@ -224,15 +226,15 @@ Bridge authorization is intentionally separate from queue state. Connectors can
224226

225227
## Workflow specs and validation
226228

227-
Workflows are deterministic recipes composed of inputs, triggers, and steps. Agents API provides the spec value object, structural validator, in-memory registry, runner skeleton, store/recorder interfaces, optional Action Scheduler bridge, and canonical abilities. It does not ship a concrete durable workflow runtime, editor UI, product step types, or run-history database.
229+
Workflows are deterministic recipes composed of inputs, triggers, and steps. Agents API provides the spec value object, structural validator, in-memory registry, runner, default step handlers, store/recorder interfaces, optional Action Scheduler bridge and branch executor, and canonical abilities. It does not ship a durable workflow runtime, editor UI, product-specific step types, or run-history database.
228230

229231
`WP_Agent_Workflow_Spec_Validator::validate( array $spec ): array` performs structural validation only:
230232

231233
- `id` is required and non-empty;
232234
- `inputs`, when present, must be a map;
233235
- `steps` must be a non-empty list;
234236
- each step needs an `id` and `type`;
235-
- built-in step types are `ability` and `agent`;
237+
- built-in step types are `ability`, `agent`, `foreach`, and `parallel`;
236238
- consumers can extend known step types through `wp_agent_workflow_known_step_types`;
237239
- `wp_action` and `cron` trigger shapes are checked;
238240
- forward or unknown `${steps.<id>.output.*}` binding references are reported.
@@ -257,8 +259,12 @@ Default step handlers:
257259

258260
- `ability`: calls a registered Abilities API ability with resolved `args`.
259261
- `agent`: calls the canonical `agents/chat` ability with `agent`, `message`, and optional `session_id`.
262+
- `foreach`: runs nested `steps` once for each resolved item in process.
263+
- `parallel`: fans out either role-scoped `branches` or mapped `items`, collects branch outputs, and optionally runs one aggregator branch.
264+
265+
The default `parallel` handler uses `wp_agent_workflow_step_executor` as its concurrency seam. When an executor is available, it dispatches branches out of band and returns a `_suspend` directive so the run can resume after reconciliation. Agents API ships an Action Scheduler branch executor that is selected when `as_enqueue_async_action()` exists; it enqueues one async action per branch, raises branch-specific Action Scheduler concurrency while branches are in flight, and triggers loopback runners for faster drain. Without Action Scheduler or a caller-supplied executor, `parallel` falls back to synchronous in-process branch execution.
260266

261-
Consumers extend the runner through the constructor or the `wp_agent_workflow_step_handlers` filter. Product-specific steps such as `branch`, `parallel`, or nested `workflow` belong in consumers.
267+
Consumers extend the runner through the constructor or the `wp_agent_workflow_step_handlers` filter. Product-specific steps such as `branch` or nested `workflow` belong in consumers.
262268

263269
Recorder behavior is conservative: `start()` runs before input validation, per-step `update()` calls follow state changes, and recorder-start failure returns a failed run result without executing steps.
264270

docs/remote-bridge-protocol.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Remote bridge clients are out-of-process processes that relay messages between an external surface and a WordPress agent runtime. They differ from direct `WP_Agent_Channel` subclasses because the client may be offline, webhook delivery may fail, and replies need a queue-first recovery path.
44

5-
Agents API provides the generic PHP primitives for that protocol. It does not ship platform-specific clients, REST routes, product onboarding UI, or a chat runtime. See [Bridge Authorization And Onboarding](bridge-authorization.md) for the auth boundary.
5+
Agents API provides the generic PHP primitives for that protocol and a fallback provider-agnostic `agents/chat` runtime. It does not ship platform-specific clients, REST routes, or product onboarding UI. Consumers can replace the fallback by registering their own `wp_agent_chat_handler`. See [Bridge Authorization And Onboarding](bridge-authorization.md) for the auth boundary.
66

77
## Relationship To Core Connectors
88

src/Workflows/class-wp-agent-workflow-runner.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@
77
* 1. Validate inputs against the spec's input schema (presence + type).
88
* 2. Walk steps in order. For each step:
99
* a. Resolve `${...}` bindings against `inputs` + earlier step outputs.
10-
* b. Dispatch to a step-type handler (`ability` / `agent` ship by
11-
* default; consumers register more via the handler map).
10+
* b. Dispatch to a step-type handler (`ability`, `agent`, `foreach`,
11+
* and `parallel` ship by default; consumers register more via the
12+
* handler map).
1213
* c. Record the per-step outcome (status, output, error, timing).
1314
* d. If the step failed and the spec didn't opt into `continue_on_error`,
1415
* short-circuit the run.
@@ -19,15 +20,14 @@
1920
* - Branching, nested workflows. Step-handler map is the extension point
2021
* for those — a consumer can register a `branch` handler that runs a
2122
* sub-list, or a `workflow` handler that calls this runner recursively.
22-
* - Real concurrency. The runner is synchronous and single-process; PHP
23-
* ships no threads here. The `parallel` step type expresses *fanout
24-
* orchestration* (declare N branches, propagate a shared immutable
25-
* context to each, collect every branch output, and optionally run one
26-
* aggregator branch over the collected outputs) — not parallel execution.
27-
* Whether branches actually run on separate processes (Action Scheduler,
28-
* sandboxed subprocesses, loopback) is a consumer-supplied executor
29-
* concern; the substrate owns the scatter/collect/return contract (plus
30-
* the optional aggregate pass), not the concurrency mechanism.
23+
* - Unconditional concurrency. The default `parallel` handler owns fanout
24+
* orchestration (declare N branches, propagate a shared immutable context
25+
* to each, collect every branch output, and optionally run one aggregator
26+
* branch over the collected outputs). Real concurrent branch execution
27+
* happens when `wp_agent_workflow_step_executor` returns a branch executor.
28+
* Agents API ships an Action Scheduler executor that is selected when
29+
* `as_enqueue_async_action()` exists; without that or a caller-supplied
30+
* executor, `parallel` falls back to synchronous in-process execution.
3131
* - Triggering. Triggers are wired separately
3232
* ({@see WP_Agent_Workflow_Action_Scheduler_Bridge} for cron, and a
3333
* consumer-registered listener for `wp_action`). The runner only

0 commit comments

Comments
 (0)