apflow

Coordinate workflows.
Inspect each run.

apflow runs dependency-aware workflows locally or across workers. Track task results, submit work durably, and create retry runs with their own history.

From workflow definition to run
Tasks and dependenciesDefine executors and the order in which their inputs become ready
apflowCoordinate execution and record Run state
Persisted outcomesInspect results, retry lineage, and usage records

What apflow coordinates

Browse capability details
  • Model structure and dependencies

    Use a task tree for organization and a dependency graph for order, parallel work, and fan-in.

  • Track acceptance and outcomes

    Durable submission records that a Run was accepted. Inspect the stored Run to check completion or start a separate retry.

  • Scale execution and usage tracking

    Start with embedded SQLite or use coordinated PostgreSQL workers. Connect shared token budgets and invocation-level usage where needed.

Run a task with a Python executor

Start with an in-memory SQLite example. Define a Python function as an executor, run one task, and read its stored result.

Open the quickstart guide
  1. Install apflow

    Install the Python package in your project environment.

    Shell
    python -m pip install apflow
  2. Define and run a task

    Save this as run_workflow.py. The task refers to the registered executor by ID.

    run_workflow.py
    import asyncio
    from apflow.app import create_app
    from apflow.adapters.function_executor import function_executor
    
    @function_executor(id="greet", description="Greet someone")
    async def greet(inputs: dict) -> dict:
        return {"message": f"Hello, {inputs['name']}!"}
    
    async def main():
        app = create_app(connection_string="sqlite:///:memory:")
        tree = await app.task_creator.create_task_tree_from_array([
            {"name": "Say Hello", "inputs": {"name": "World"},
             "params": {"executor_id": "greet"}},
        ])
        await app.task_manager.distribute_task_tree(tree)
        task = await app.task_repository.get_task_by_id(tree.task.id)
        print(task.status, task.result)
    
    asyncio.run(main())
  3. Check the result

    Run the script and confirm that the task completed with the greeting result.

    Shell
    python run_workflow.py
    Example result
    completed {'message': 'Hello, World!'}

Documentation

Browse all docs

Detailed capabilities and configuration

Choose a topic

Task orchestration

Structure trees organize workflows; dependency DAGs coordinate parallel steps, fan-in, fan-out, and dependency results