Snapshot MaxTurns in checkpoint and apply it on restore
MaxTurns is the only agent bound compared against a counter that is serialised in the checkpoint (Turns). When config drifts between save and restore -- typically because a deploy changed WithMaxTurns or a different build of the agent is registered by name -- cp.Turns can exceed agent.maxTurns on the resumed run, which previously surfaced as a warning log and then a MaxTurnsExceededError on the first iteration of the resumed coreLoop. Capture MaxTurns in the new AgentConfig on every save, and on restore clone the registry-resolved agent with WithMaxTurns applied from the snapshot. The override flows through the outer Restore path and through both inner-agent resolution sites in restoreNestedSuspended and restoreAwaitingApproval, so nested runs get the same treatment. Other loop bounds (maxEmptyOutputRetries, maxToolDepth) reset per turn / per tool depth and stay intentionally live so deploys can tune them without invalidating in-flight checkpoints. Live references (tools, hooks, LLM client, approval callbacks, guardrails) are not snapshotted for the same reason. With the snapshot in place, the "restored agent run has already reached max turns" warning at the top of continueFromMessages is structurally unreachable -- the live agent's bound is now the same value cp.Turns was bounded by at save time -- and is removed. Signed-off-by: Aurélien Sibiril <81782+aureliensibiril@users.noreply.github.com>
This commit is contained in:
@@ -23,9 +23,25 @@ import (
|
||||
type (
|
||||
AgentStatus string
|
||||
|
||||
// AgentConfig captures the subset of agent options that must remain
|
||||
// stable across a suspend/restore cycle to keep the run coherent.
|
||||
// Currently that is only MaxTurns, because Checkpoint.Turns is a
|
||||
// counter compared against it — if the live agent's bound were
|
||||
// lowered below the saved counter we would either short-circuit the
|
||||
// restored run or fail the warning at restoreSuspended. Other loop
|
||||
// bounds (maxEmptyOutputRetries, maxToolDepth) reset per turn and
|
||||
// are safe to change mid-suspension. Live references (tools,
|
||||
// handoffs, hooks, LLM client, approval callbacks, guardrails) are
|
||||
// intentionally not snapshotted so deploys can update behavior
|
||||
// while runs are paused.
|
||||
AgentConfig struct {
|
||||
MaxTurns int
|
||||
}
|
||||
|
||||
Checkpoint struct {
|
||||
Status AgentStatus
|
||||
AgentName string
|
||||
Config AgentConfig
|
||||
Messages []llm.Message
|
||||
Usage llm.Usage
|
||||
Turns int
|
||||
|
||||
Reference in New Issue
Block a user