#Implement a FLOW host
A host lets an application invoke a Flow with input and receive an outcome with data. It selects the implementation, supplies local powers, and accounts for execution through completion. The method owns its procedure, including any code, Agent work, and child calls.
This guide maps those duties to Package/0 and Run/0. Try the caller/dependency exercise after reading the lifecycle.
#Enter a component and service its calls
Run/0 distinguishes component entry from dependency invocation:
The host resolves the dependency slot and checks its grants. It supplies the selected implementation's settings, attachments, scratch directory, and deadline. A child inherits the remaining deadline. Its other powers come from its own host-supplied context.
Illustrative exchange: a caller invokes a greeter dependency.
Every launched component receives flow/run, including a child.
A slot can select a native host implementation instead of another component process.
Its input, result, authority, and owned-work obligations still apply.
Authors use handle(handler) and context.call(...) through an SDK.
They use the same authoring API whether their method is entered directly or called by another Flow.
See Run SDK/0 for the exact projection.
#Prepare the invocation
Inspect the package before execution:
- Find its single root
FLOW.<ext>implementation. - Read its metadata, dependency declarations, and optional invocation contract.
- Check support for its runtime and required interfaces, including channels.
- Prepare the execution environment and authorized dependency routes.
- Supply selected settings, attachments, scratch space, and a finite deadline.
Code metadata lives in optional FLOW.meta.json. Markdown metadata lives in frontmatter.
Keep credentials with the host implementation responsible for them.
Package declarations describe requirements. The host supplies execution authority.
#Own the exchange
Send one complete flow/run request with a string request ID.
Run/0 uses bounded, LF-terminated UTF-8 JSON objects over full-duplex stdio.
Keep the reader active while awaiting responses, and serialize writes.
Stderr carries diagnostics.
Service flow/call while its invocation owner remains pending.
Validate the declared slot, operation identity, input, and any explicit channel transfer.
Resolve an authorized implementation and supply its context.
Validate complete { outcome, output } results.
Declared domain refusals remain normal results. Operational failures use the JSON-RPC error envelope.
Progress and channel EOF describe observation, rather than establishing successful execution.
#Cancel and complete owned work
Send cancellation using the pending request's string ID:
This notification carries no id and receives no response.
Enforce deadlines and bounded termination even when a component ignores cancellation.
Settle the owned subtree and resources. Keep uncertain effects visible instead of retrying them automatically.
After a terminal response, drain stdout and await process exit. Successful completion requires a valid correlated result, settled owned work, successful cleanup, and a zero exit status. Trailing bytes or frames fail completion. A shutdown kill after a result is an execution failure.
Run/0 defines the exact validation, identity, error, cancellation, and completion rules. Your host owns admission, credentials, containment, and persistence policy. Protocol conformance and those host guarantees need separate evidence.
Next, implement the SDK exchange or verify the caller/dependency lifecycle.