This is the second post in a four-part series on how Corin is built. In part 1 I talked about why we built the pieces in instead of gluing them together, and how a team of agents is designed and configured. Here I'll stay with the same order.
A customer sends a purchase order for five parts. Four are in stock. One is on backorder with the manufacturer. Four parts ship today. The fifth won't arrive for about three weeks. It's the kind of supplier delay a human team handles every week.
Most agent setups assume a task finishes in one session. If it doesn't, you get polling loops, cron jobs, a hand-rolled state table, and an agent that has forgotten everything when the part shows up. And even if the wait works, the next surprise is the shipping notice itself: a spreadsheet in a layout nobody has seen before, which a fixed parser can't read.
The usual name for the first half of this problem is durable execution: the work is recorded as it happens, so an agent can wait three weeks, spend nothing while it waits, and pick up with the same context.
The examples below are illustrative, with simplified field names, not Corin's schema or API.
How can AI agents wait weeks without losing context?
Corin runs this work on Temporal's durable execution, and we built it in so you don't have to design workflows, workers, and state handling yourself. Conceptually, the order looks like this:
@workflow.defn
class OrderWorkflow:
def __init__(self):
self.goods_received = None
@workflow.signal
def goods_received_signal(self, receipt): # ERP goods receipt or supplier ASN
self.goods_received = receipt
@workflow.run
async def run(self, po):
retry = RetryPolicy(maximum_attempts=5, backoff_coefficient=2.0)
opts = dict(start_to_close_timeout=timedelta(minutes=10), retry_policy=retry)
order = await workflow.execute_activity(intake_agent, po, **opts)
stock = await workflow.execute_activity(inventory_agent, order, **opts)
# idempotency key travels with the write: one shipment, however many retries
await workflow.execute_activity(
ship_available, args=[stock.available, f"{po.id}:ship:partial"], **opts)
eta = await workflow.execute_activity(procurement_agent, stock.backordered, **opts)
# Pause. No worker is busy and no model is called while we wait.
while self.goods_received is None:
try:
await workflow.wait_condition(
lambda: self.goods_received is not None,
timeout=eta.expected_in + timedelta(days=3)) # durable timer
except asyncio.TimeoutError:
await workflow.execute_activity(escalate_late_part, po.id, **opts)
await workflow.execute_activity( # ERP write + customer email
fulfillment_agent, args=[order, self.goods_received, f"{po.id}:ship:final"], **opts)Illustrative; Python-style pseudocode using Temporal concepts, simplified. Not Corin's API.
What's going on under that:
- Replay. Temporal records every step in the workflow's event history. If a worker dies on day 9, another replays the history and lands in the same state without re-running completed steps.
- LLM calls are activities. Model calls, tool calls, and connector writes are non-deterministic, so they live in activities, not in workflow code. The workflow just orchestrates, which is what makes replay safe: on replay, the recorded result of each agent step is reused instead of calling the model again.
- The wait costs nothing. During the three weeks there's no running process tied to this order, no polling, and no tokens. The workflow is just state in Temporal until a signal or a timer fires.
- Resume with context. On day 22, a goods receipt or supplier ASN signals the workflow (goods_received), and the fulfillment agent picks up with what shipped, what's pending, and who was told what. That lives in workflow state, not a chat window that closed three weeks ago.
- Late parts escalate. The durable timer survives restarts, so a person hears about a late part before the customer does.
Durable execution doesn't make every external system idempotent. If an ERP write times out, you don't know whether it landed. So writes to third-party systems carry an idempotency key, and before a retry Corin checks the result in the target system. That's how the customer doesn't get the same email twice and the ERP doesn't get the same record twice. It's careful at-least-once with checks, not a promise of exactly-once in systems we don't control.
What happens when the shipping notice isn't in a format you planned for?
A lot of what gets called "agentic" today is a deterministic workflow with an LLM in a few boxes. That works well until reality steps off the diagram. Then it breaks, and someone has to fix it by hand.
In our example, the supplier's shipping notice arrives as a spreadsheet in a layout nobody has seen before: a title block, merged header rows, part numbers with stray spaces, quantities as text. Sometimes it's a CSV. Sometimes it's an HTML table in an email. A fixed parser fails here.
A Corin agent does what a capable employee would: looks at the file, writes code to parse it, runs it, checks the result. We call that last-mile code. Something like:
import pandas as pd
raw = pd.read_excel("asn_supplier.xlsx", header=None)
hdr = raw.index[raw.apply(lambda r: r.astype(str).str.contains("Part", case=False).any(), axis=1)][0]
df = pd.read_excel("asn_supplier.xlsx", header=hdr)
df.columns = df.columns.str.strip().str.lower()
asn = (df.rename(columns={"part no.": "part_number", "qty shipped": "qty", "tracking #": "tracking"})
[["part_number", "qty", "tracking"]]
.dropna(subset=["part_number"]))
asn["part_number"] = asn["part_number"].astype(str).str.strip().str.upper()
asn["qty"] = pd.to_numeric(asn["qty"], errors="coerce").astype("Int64")Illustrative; written the way an agent might for this one file.
The loop around that code matters more than the code:
- Inspect the file's structure: sheets, header position, columns, sample rows.
- Generate a parser for this specific file.
- Execute within the agent's permission scope. Here that means reading the attachment, not writing to the ERP.
- Validate against the open order: right part numbers, quantities matching the backorder, a tracking number. If it doesn't reconcile, loop back or flag it.
- Request approval for consequential writes: recording the receipt, changing a price, emailing the customer.
- Commit as an activity with an idempotency key, like any other step.
Execution is constrained by the agent's permissions and the approval gates you configure. You decide where the boundaries sit, and approvals live in the team config, not rebuilt for every workflow.
Day 22 then continues as the workflow already planned: the receipt is recorded, the last part ships, and the customer is updated. The unexpected file didn't require a new workflow. It required an agent that could write the last mile of code, check it against the order, and wait for a person before anything irreversible happened.
What's next
A three-week order with four agents and a last-mile parser is only useful if you can see what happened. In the next post I'll show the built-in timeline for this same task, the Activity views we use to tune it, and the sandbox and one-click rollback that make a change safe to try.
Continue with Built-in observability, sandbox tests, and one-click rollback.
Questions we hear
What is durable execution for AI agents?
It means the work is recorded as it happens — a log of steps you can replay. If a worker dies, or the job has to wait three weeks, you resume from that record instead of starting over or polling until something shows up. People also ask this as "What is durable execution in AI?"; the idea is the same.
How can AI agents wait weeks for an event without losing context?
Persist the state, shut the work down, and wake it when a signal or a timer fires. There is no running process and no model call during the wait. On day 22 the agent picks up with what shipped, what's pending, and who was told what.
What is the biggest problem with AI agents?
A common one, for long-running work, is that the agent was built for a single session. When the job has to wait three weeks, the context is gone, and someone has to reconstruct the order by hand. That is not true of every failure, but it is the one this post is about.
What do you do with a shipping notice in a format nobody has seen?
An agent can inspect the file, write the last mile of code, check the result against the open order, and wait for approval before any consequential write. That does not require a new workflow. If a write times out, carry an idempotency key and check the target system before a retry.
This is part 2 of the "Built in. Not bolted on." series.
- Built in. Not bolted on.
- Agents that wait three weeks without forgetting
- Built-in observability, sandbox tests, and one-click rollback
- Safe ERP execution, portable skills, and day-one security
Yuval Yatskan, co-founder and CEO, Corin


