feat(agent): add response retry hooks#2182
Merged
Merged
Conversation
Co-authored-by: Erik Tews <erik@datenzone.de>
Co-authored-by: Erik Tews <erik@datenzone.de>
Co-authored-by: Erik Tews <erik@datenzone.de>
Co-authored-by: Erik Tews <erik@datenzone.de>
Co-authored-by: Erik Tews <erik@datenzone.de>
gold-silver-copper
force-pushed
the
agent/add-response-retry-hook
branch
from
July 18, 2026 05:49
1e6bb42 to
f5737b3
Compare
gold-silver-copper
marked this pull request as ready for review
July 18, 2026 06:15
This was referenced Jul 18, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Add a typed response-retry action to the canonical
on_model_turn_finishedhook without adding retry configuration or counters to agent builders, agents, runners, or run state.The new
ModelTurnActionlets hooks accept, retry, or stop a completed model turn. Retry requests explicitly distinguish between:Repeat, which discards the rejected assistant response and reuses the same prompt and preceding history with fresh request preparation. Completion-call hooks, retrieval, and dynamic tool resolution run again, so the resulting provider request may differ from the rejected attempt.Feedback, which preserves a non-empty rejected assistant response and appends corrective user feedback before the next model call. Canonical empty assistant turns are omitted from history.Both modes retain usage and completion-call accounting and consume the existing
max_turnsmodel-call budget. Policy-specific limits remain hook-owned and can use the run-scopedScratchpad; the public documentation and runnableagent_with_retry_hookexample demonstrate a bounded, instance-isolated policy.Blocking and streaming execution share the same action resolver and stateless
AgentRuntransition. Streaming retries suppress the rejected provider final and emitModelTurnRetriedso consumers can reset provisional deltas. Tool-bearing response retries fail before tool execution to avoid constructing provider-visible history with unanswered calls.Type of change
AgentHook::on_model_turn_finishednow returnsModelTurnActioninstead ofObservationAction.Testing
cargo fmtcargo clippy --all-targets --all-features -- -D warningscargo testcargo doc --workspace --no-depsRegression coverage includes blocking and streaming Repeat/Feedback behavior, fresh request preparation on Repeat, canonical empty-turn history handling, total-budget exhaustion, usage and completion-call accounting, hook ordering and nested stacks, run/concurrency isolation, streaming rollback signaling, fail-safe tool-bearing retries, and a live-recorded OpenAI feedback-retry history.
Checklist
Notes
Response retries intentionally do not support turns containing tool calls. Those turns must be steered with tool-call hooks so Rig never persists unanswered tool calls as ordinary conversation history.