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.
| Operation | Where | Why |
|---|---|---|
| The agent loop's control flow, step limits, branching on tool results | Workflow | Deterministic given recorded results |
| Model call | Activity | Different output each call |
| Tool call (read or write) | Activity | External, can fail, may have side effects |
| Current time | Engine's workflow time or an activity | The real clock differs on replay |
| Random or unique ids | Engine's deterministic helpers or an activity | Must be the same on replay |
| Waiting for approval or a timer | Engine primitives (signal, timer) | The engine records them |
| Writing notes or state to a database | Activity | External state |
| Large documents and tool results | Activity writes to storage; history stores a reference | Histories 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.
Start here
What if a developer adds a log line with the current timestamp inside the workflow?
Does logging change decisions?
Logging that does not affect control flow is harmless if the engine's logger handles replay (suppressing duplicates). Using the timestamp in a decision is not. Use the engine's workflow time for both.
Carry it forwardOnly decisions must be deterministic, but use engine time anyway.
Weak answerAssuming any use of the clock is fine because it is 'just logging'.
Constraint changes
What if you change the prompt template between deploys?
Where is the prompt used?
Inside the model-call activity, so replays of completed calls return recorded outputs unaffected. New calls use the new template; record the prompt version with each call so results are explainable.
Carry it forwardActivity changes affect only future executions.
Weak answerThinking a prompt change breaks replay of in-flight runs.
Constraint changes
What if you insert a new tool call between two existing steps of the workflow?
What will in-flight runs find on replay?
Their history has no record for the new step at that position, so replay diverges. Guard the change with a version marker so in-flight runs keep the old sequence.
Carry it forwardChanging the sequence of activities needs versioning.
Weak answerDeploying the new sequence to all runs at once.
Now defend it
One-line rule?
Workflow code decides deterministically from recorded results; anything that can differ between executions, model calls, tools, time, randomness and I/O, is an activity with its own retry, timeout and idempotency, and sequence changes are versioned.
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.