fix(hooks): expose attempt_number, max_attempts, is_last_attempt on completion:error and completion:last_attempt hooks#2285
Open
Kcstring wants to merge 1 commit into567-labs:mainfrom
Conversation
…rror hooks CompletionErrorHandler Protocol now documents the retry metadata kwargs that retry.py already passes to emit_completion_error() and emit_completion_last_attempt(). Old-style handlers (error-only) continue to work unchanged via the existing inspect.signature fallback in Hooks.emit(). Closes 567-labs#2222
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.
Summary
Closes #2222
completion:errorandcompletion:last_attempthandlers can now receive retry metadata as keyword arguments —attempt_number,max_attempts, andis_last_attempt— without any breaking changes.What changed
instructor/core/hooks.py—CompletionErrorHandlerProtocol updated to document the kwargs thatretry.pyalready passes:No changes to
retry.py— it already passes these kwargs toemit_completion_error()andemit_completion_last_attempt(). The existinginspect.signaturefallback inHooks.emit()means old-style handlers (def handler(error)) continue to work unchanged.Usage
Tests
9 new unit tests in
tests/test_hooks_retry_metadata.py— no real API calls needed:attempt_numberforwarded correctlymax_attemptsforwarded (includingNonefor unbounded)is_last_attemptisFalsefor intermediate errors,Truefor last attempterror-only) still called without breaking