Skip to content

AsyncChain

Async orchestrator with the same semantics as Chain.

Differences
  • Awaits async steps; can also offload sync steps via asyncio.to_thread.
  • Hooks can be async or sync.
  • Uses asyncio.sleep during backoff.

Parameters:

Name Type Description Default
strict bool

If True, unresolved dotted refs raise LookupError. Otherwise resolve to None.

False
before_step HooksFn | None

Optional hook (sync or async): (step, context) -> None | Awaitable.

None
after_step HooksFn | None

Optional hook (sync or async): (step, context, result, elapsed) -> None | Awaitable.

None
on_retry HooksFn | None

Optional hook (sync or async) for retry events.

None
redact Callable[[str], str] | None

Optional log redactor.

None
deadline_fn Callable[[], float] | None

Optional function returning remaining seconds.

None
safety_margin float

Deadline buffer.

0.25
jitter bool

Randomize sleep in backoff window.

True
allow_sync bool

If True, synchronous steps are offloaded with asyncio.to_thread.

True
See Also

Chain for the synchronous variant.

put

put(key, value)

See Chain.put.

next

next(func, *, out, args=(), kwargs=None, name=None, retries=0, retry_on=(Exception,), backoff=1.5, max_backoff=10.0, log=None, log_fmt=None, validate=None)

See Chain.next (async compatible).

run async

run()

Execute the async chain. See Chain.run for semantics.