Skip to content

Interview question · Long-Running & Durable Agents

What runs inside a durable workflow and what must run as an activity?

The rule is simple to state and easy to break: workflow code must make the same decisions on every replay, so anything that can differ between runs goes through an activity, and the model is the biggest such thing.

hardEssentialNewUpdated Nov 2026

TL;DR: Workflow code is the deterministic part: control flow, decisions on values that came from recorded activities, timers and waits through the engine, and handling of signals. Everything that can differ between executions is an activity: model calls, tool calls, database and network access, reading the clock, generating random ids, file I/O. Large results go to storage and the history keeps references. Activities get retry policies, timeouts and heartbeats; workflow code gets versioning so changes do not break replay of runs already in flight.

How to approach it

State the determinism rule and why replay needs it, then sort an agent's operations into the two sides with reasons. Add the practical concerns: history size, retries, long activities and changing code.

A strong answer

The rule. After a crash, the engine reruns workflow code from the start and feeds it recorded activity results. If the code would decide differently on replay (because it read the clock, drew a random number or called a model directly), it diverges from the history. So workflow code may only depend on its inputs and recorded results.

The sort for an agent.

OperationWhereWhy
The agent loop's control flow, step limits, branching on tool resultsWorkflowDeterministic given recorded results
Model callActivityDifferent output each call
Tool call (read or write)ActivityExternal, can fail, may have side effects
Current timeEngine's workflow time or an activityThe real clock differs on replay
Random or unique idsEngine's deterministic helpers or an activityMust be the same on replay
Waiting for approval or a timerEngine primitives (signal, timer)The engine records them
Writing notes or state to a databaseActivityExternal state
Large documents and tool resultsActivity writes to storage; history stores a referenceHistories have size limits

A check that catches mistakes. A static check in CI that flags forbidden calls inside workflow functions is cheap insurance:

import ast

FORBIDDEN = {"now", "random", "uuid4", "get", "post", "complete", "time"}

def nondeterministic_calls(source, workflow_name):
    tree = ast.parse(source)
    found = []
    for node in ast.walk(tree):
        if isinstance(node, ast.FunctionDef) and node.name == workflow_name:
            for call in ast.walk(node):
                if isinstance(call, ast.Call) and isinstance(call.func, ast.Attribute):
                    if call.func.attr in FORBIDDEN:
                        found.append((call.lineno, f".{call.func.attr}()"))
    return [f"line {n}: {name}" for n, name in sorted(found)]

code = """
def refund_workflow(ctx, order):
    facts = ctx.activity(lookup_order, order)
    if datetime.now().hour > 18:
        ctx.sleep_until_morning()
    plan = llm.complete(prompt_for(facts))
    return ctx.activity(issue_refund, plan)
"""
found = nondeterministic_calls(code, "refund_workflow")
print(found)  # => ['line 4: .now()', 'line 6: .complete()']

The workflow reads the wall clock and calls the model directly; both must move into activities or engine primitives. Engines provide their own sandboxes or checks for this; a simple project-specific check adds the names your codebase uses.

Activities need their own policies. Retry with backoff for transient errors and none for validation errors; timeouts sized to the work; heartbeats for long activities (a test suite run) so the engine can tell slow from dead; idempotency keys for side effects, because activities run at least once.

Changing workflow code. Runs already in flight replay against the code that exists when they resume. A change that alters the order of activities breaks their replay. Engines offer versioning (branch on a recorded version marker) so old runs follow old paths and new runs follow new ones.

What interviewers probe next

"Doesn't recording every model call bloat the history?" Store the output (or a reference to it) once; that is also exactly what you want for audit and debugging. Large prompts and results go to object storage by reference.

"Can the agent's reasoning loop be a single long activity?" Then a crash restarts the whole loop and loses durability inside it. Make each model call and tool call its own activity, with the loop in workflow code.

"What about streaming model output to a user?" Stream from the activity to the user directly; record the final output in the history when the activity completes.

What if?

What if · interview follow-ups

Hold your answer as the constraints change

Your agent loop runs as workflow code, with each model call and tool call as an activity.

  1. Start here

    What if a developer adds a log line with the current timestamp inside the workflow?

How it's scored

Weak: Puts the whole agent in one activity, or calls the model from workflow code.

Hire: Model and tool calls as activities, deterministic workflow code.

Strong Hire: States the replay rule, sorts time, randomness, I/O, waits and large payloads correctly, adds a static check, sets activity retry, timeout, heartbeat and idempotency policies, and versions workflow changes for in-flight runs.

Common mistakes

  • Direct model calls in workflow code.
  • One giant activity for the whole loop.
  • Large payloads stored in the history.
  • Deploying a changed activity sequence without versioning.
You just read a free answer. Every topic opens its first 5 answers to anyone. Sign in and the count per topic goes to 6, and the site remembers where you stopped in each one.Google sign-in · free · no payment details
HOW DID IT GO?
0
READING SIGNED OUT

Signing in raises your free answers from 5 to 6 per topic, adds an applied lesson in every topic and easy practice tests, and the site starts remembering you: mastery per topic, bookmarks, and a next-focus recommendation. Free, no card.

Sign in free
UP NEXT ON YOUR JOURNEY
DISCUSSION · 0

Nobody has commented. Post a correction or another way to answer.