> For the complete documentation index, see [llms.txt](/llms.txt).
> A full single-fetch corpus is available at [llms-full.txt](/llms-full.txt).
---
last_verified: 2026-10-09
title: Context API
description: The FunctionContext and WorkflowContext objects Python handlers receive — run details, steps, state, waits, logging, and progress
category: Python SDK
hideRightSidebar: true
---

Every handler receives a context as its first argument: a `FunctionContext` in functions and a `WorkflowContext` in workflows. It describes the current run and gives the handler access to durable steps, state, waits, and logging.

```python
from agnt5 import FunctionContext, function


@function
async def audit(ctx: FunctionContext, order_id: str) -> dict:
    ctx.logger.info(f"Auditing order {order_id} (attempt {ctx.attempt})")
    return {"run_id": ctx.run_id}
```

## Run details

| Property | Description |
|---|---|
| `ctx.run_id` | The ID of the current run. |
| `ctx.attempt` | Which try this is, starting at `0`. |
| `ctx.component_name` | The registered name of the running component. |
| `ctx.session_id` | The session the run belongs to, or `None`. |
| `ctx.activation` | In a function running as a workflow step on a deployed worker: the step's activation, including `idempotency_key`. Send it to downstream systems so a re-run step doesn't repeat an effect. |

## Steps (workflows)

| Method | Description |
|---|---|
| `await ctx.step(fn, *args, key=None)` | Run a function and checkpoint its result. |
| `await ctx.task(fn, *args)` | Run a function as a checkpointed step. |
| `await ctx.parallel(*awaitables)` | Wait for several awaitables; returns a list. |
| `await ctx.gather(**awaitables)` | Wait for several awaitables; returns a dict. |
| `await ctx.sleep(seconds, name=None)` | Pause durably. |

See [Workflows](/sdk/python/workflows.md) for examples.

## State (workflows)

`ctx.state.set(key, value)` stores a JSON-serializable value and `ctx.state.get(key)` reads it. State is scoped to the run and survives replay.

## Wait for a person

`await ctx.wait_for_user(question, ...)` pauses the workflow until someone answers, and returns the answer as a string, or `None` for a skipped question.

```python
decision = await ctx.wait_for_user(
    "Approve this refund?",
    input_type="approval",
    options=[{"id": "approve", "label": "Approve"}, {"id": "reject", "label": "Reject"}],
)
```

| Parameter | Description |
|---|---|
| `input_type` | `"text"` (default), `"approval"`, `"select"`, or `"multiselect"`. |
| `options` | Choices for `approval`, `select`, and `multiselect`: `{"id", "label"}` dicts. |
| `allow_custom` | Adds a free-text choice to `select` and `multiselect`. |
| `skippable` | Lets the person skip; the answer is then `None`. |

People answer in Studio or with the [resume API](/docs/api-reference/runs-and-traces/resume-a-workflow.md). See [Human-in-the-loop](/docs/build/human-in-the-loop.md).

## Logging and progress

| Member | Description |
|---|---|
| `ctx.logger` | A standard Python logger. Its lines appear in the run's logs and in `agnt5 inspect logs`. |
| `ctx.progress(value, total=None, message=None)` | Report progress for a long-running handler, for example `ctx.progress(3, total=10, message="Indexed 3 of 10")`. |

## Next steps

* [Workflows](/sdk/python/workflows.md): steps, concurrency, state, and schedules.
* [Functions](/sdk/python/functions.md): the handlers that receive this context.
* [Human-in-the-loop](/docs/build/human-in-the-loop.md): every way to pause for a person.
