Get started
A workflow definition is a Starlark program. AutoFlow runs each submission of it as a workflow: a durable execution on top of autocore that survives restarts and can wait for days. This page takes you from nothing to a completed workflow through the gRPC API, which is the entry point today.
What you need
- A running AutoFlow instance with its API listener reachable. The default listener address is
127.0.0.1:8153, plaintext unless a certificate and key are configured. - The API authentication secret: the file
api.listen.authentication_secret_filepoints to, holding a base64-encoded secret. Every call carries a JWT signed with it. - The
autoflowCLI, built from the AutoFlow repository withgo build ./cmd/autoflow, orgrpcurl.
Write a workflow definition
Save this as workflow.star:
def main(w, name):
print("starting for", name)
sleep(5 * time.second)
print("slept 5 seconds, still here")
return "hello, " + namemain is the entry point. Its first parameter w is the workflow context; every further parameter is bound from the arguments the caller sends. sleep is durable: the workflow holds no resources while it waits and resumes even if AutoFlow restarts in between. The value main returns is the workflow’s result.
Start it
AutoFlow serves the AutoFlow gRPC service on its API listener: StartWorkflow, GetWorkflow, CancelWorkflow and SendToWorkflowChannel. The API reference describes every request and response field; the source of truth is internal/module/autoflow/rpc/rpc.proto. The API is subject to change: a new shape is proposed in ADR 0011.
The CLI wraps StartWorkflow and then polls GetWorkflow for you:
autoflow run -s workflow.star --secret-file /path/to/secret \
--kwarg 'name="world"'--kwarg and --arg values are Starlark expressions, so strings need their quotes. sensitive("...") marks an argument as a secret the workflow cannot read. Add --address when AutoFlow is not on 127.0.0.1:8153, and --tls or --ca-cert-file for a TLS listener. The namespace defaults to 1.
The command logs Started workflow with the workflow key, the workflow token and the token binding it generated, then Waiting for workflow to complete, and about five seconds later Workflow with state=WORKFLOW_STATE_COMPLETED and the result string_value:"hello, world". Keep the token: the get and cancel commands need it. The exit status is zero only for a completed workflow.
Read the result
Polling GetWorkflow is the only way to observe a workflow: there is no callback and no streaming variant. The request needs the workflow key, the workflow token and the namespace:
autoflow get <workflow-key> --workflow-token <workflow-token> \
--secret-file /path/to/secret --wait{
"workflow_key": "<workflow-key>",
"workflow_token": "<workflow-token>",
"namespace_id": 1
}The response has state, created_at, updated_at and result. RUNNING is the only non-terminal state. The terminal ones:
| State | Meaning |
|---|---|
COMPLETED | main returned. result holds its value, or none_value without a return. |
FAILED | The workflow failed, for example an action returned an error. result is the error. |
CANCELED | Cancellation was requested and took effect. |
TIMED_OUT | The schedule-to-complete timeout elapsed, 30 days unless the caller set one. |
SYSTEM_FAILED | AutoFlow could not run the workflow to completion. Not the workflow definition’s fault. |
print output does not travel with the result. It goes to AutoFlow’s log at Info level with sensitive values masked. A stream of it to the caller does not exist yet; issue 953 tracks it.