Skip to main content

PipelineContext: Runtime Context for Tasks

PipelineContext is a typed dataclass that the pipeline framework automatically builds and injects into any task that declares a ctx parameter. It carries the user, dataset, and per-item context for the current pipeline run, and provides an extras dict for custom state.

Fields

How injection works

The framework inspects every task function’s signature at construction time. If it finds a parameter named ctx, it passes the current PipelineContext as that argument when the task runs. Matching is by parameter name, not by type annotation.
Tasks that do not declare ctx simply receive no context and are unaffected.

Using extras for custom pipeline state

Pass a dict as the context argument to run_pipeline (or extras to run_tasks). Every task in the pipeline can read those values from ctx.extras.
ctx.extras is always a plain dict — it is never None.

Examples and details

The user and dataset fields are most useful when you need to write provenance records or apply per-tenant logic:
The built-in add_data_points task already does this automatically, so you typically only need to read these fields when writing your own storage tasks.
All tasks in the same pipeline run share the same PipelineContext object, so values written during construction remain available in every downstream task:
Always default ctx to None so the task can also be called directly in tests or scripts without a running pipeline:
The built-in add_data_points discovers which dataset to attribute nodes and edges to entirely from ctx.dataset:
When you call run_pipeline(..., datasets=["my_dataset"]), the pipeline resolves each name (or UUID) into a Dataset object and places it on ctx.dataset, so every task — including add_data_points — receives the resolved dataset automatically. You never pass the dataset to the task itself.Called outside a pipeline (await add_data_points(points) with ctx=None), user, dataset, and data_item are all None, so the provenance block is skipped: the nodes and edges are still written to the graph and vector stores, but no dataset-level provenance is recorded. Run the task through run_pipeline/run_tasks with a datasets=[...] argument whenever you need per-dataset attribution.

Tasks

Learn how tasks are defined and composed

Pipelines

See how tasks and context flow through pipeline runs

Custom Tasks & Pipelines

Step-by-step guide to building your own pipeline