Skip to main content
A WorkflowFactory produces a fresh Workflow for each request. Register it in AgentOS(workflows=[...]) alongside any prototype workflows.
basic_workflow_factory.py
Run the workflow like any other workflow:
See the Factories reference for the full constructor signature and parameter list.

Step Shape That Varies by Tier

The step graph can change per request. A common pattern: add or drop steps based on a tier read from ctx.trusted.claims.
The tier claim is read from verified middleware, so the tier cannot be changed by the request body. See Authorization From Verified Context for the trust model and JWT Role Factory for an end-to-end JWT example.

Async Factories

Use an async callable when you need to fetch context from a database, an HTTP service, or any other awaitable resource.
async_workflow_factory.py

With an Input Schema

Declare a Pydantic model on the factory to validate client-supplied factory_input before the factory runs.
workflow_input_schema.py

Error Handling

Raise FactoryPermissionError from inside the factory to reject unauthorized callers with HTTP 403. AgentOS raises FactoryValidationError (400) automatically when factory_input fails input_schema validation.
See the Factories reference for the full exception hierarchy and the post-resolve behavior.

Factory Re-invocation on Read Endpoints

GET /workflows/{id}/runs/{run_id} and GET /workflows/{id}/runs re-invoke the factory because the workflow has to be reconstructed to read its session state. Pass factory_input as a query parameter to drive the rebuild:

Developer Resources