Long jobs
For: people running and reviewing agents.
A long job grows two records: the conversation sent with every model call and the steps in Temporal history. The model's context window can fill up. Temporal recommends ending a run's history at a few thousand events and refuses a history at 50 MB. Use continue-as-new and compaction to keep those records bounded.
name: acme-researcher
runtime: pydantic-ai
model:
primary: anthropic/claude-sonnet-5-5
tools: [acme_web.search, acme_web.fetch]
limits:
max_steps: 400
history:
continue_after: 50 # model requests per run; unset: when Temporal suggests it
compact: summarize # or trim; unset keeps the whole conversation
max_messages: 40 # compact once the conversation is longer than this
keep_messages: 12 # the newest messages stay as they are
Continue-as-new
A job's workflow can end its run and start a fresh one under the same job ID, with what it needs to go on: the conversation, the tokens and requests used so far, the jobs it delegated to, its hooks and approvals policy, its home node, and the live stream's position. This is Temporal's continue-as-new, and every agent job does it:
- when Temporal suggests it, because the run's history grew large;
- after
history.continue_aftermodel requests in one run, if you set it; - at the latest after 10,000 events in one run.
It happens between two steps, never in the middle of a tool call or while a question or an approval waits. Nothing changes for anyone who follows the job:
- The job ID stays.
job get,job watch,run, the console and the runtime API keep working;job listshows the job once, with the time it first started. - The live stream goes on where it was. A watcher that fell far behind skips what the job left behind, at most the oldest events beyond the last 500.
- Limits count the whole job:
limits.max_stepsandlimits.max_tokensinclude every run, andlimits.timeoutcounts from the job's start. - The trace shows every run as one job. Steps of later runs have IDs such as
r2/activity-7, and a step namedcontinued as newmarks each new run. - Cost stays on the job ID, so the job's cost and budget cover all its runs.
Compaction
Continue-as-new keeps Temporal's history small; compaction keeps the conversation small. Once the conversation is longer than max_messages, before the next model call, the older turns are taken out:
compact | What takes their place |
|---|---|
summarize | A summary, written by the agent's own model: the task, facts, decisions, names and IDs, results that matter, and what remains. The call goes through the gateway like any other, so it is metered on the job and shows in its trace as a step named compact, with its tokens and cost. |
trim | A note that says how many messages were left out. No model call. |
The first message (the task) and the newest keep_messages messages always stay. A cut never separates a tool call from its result. The next compaction takes the earlier summary into the new one.
max_messages well above the turns an agent needs to see at once, and give the agent's instructions a hint to write down what it must not forget.What it does not cover
Harness agents keep their own conversation inside the harness session, which is one activity; history applies to Pydantic AI agents. An openai-agents agent continues as new (history.continue_after) but does not compact: plugin lint warns about history.compact there. Flows run steps, not conversations, and do not need it.