Make managed agent hooks provider-independent#2176
Merged
Conversation
gold-silver-copper
marked this pull request as ready for review
July 17, 2026 19:19
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
AgentHook, erased hook dispatch, andHookStackMultiTurnStreamItem<R>genericStreamResponseFinishsees trailing silent metadata such as message IDs, while keeping IDs optional and rejecting post-final visible contentcanonical_choice()and cover interleaved reasoning, text, and tool content at the finish-hook boundaryrequest_hookWhy
Managed hooks observe Rig's orchestration lifecycle, so coupling each hook implementation and hook stack to a provider model type adds boilerplate and leaks provider response types across the orchestration boundary. Canonical lifecycle events let one concrete hook attach to agents backed by different completion models while preserving typed raw responses on direct
CompletionModelAPIs.For managed streaming, a provider's typed final payload is not necessarily stream EOF: silent metadata can follow it. Buffering the final item until EOF gives the hook and committed turn the same finalized canonical content and message ID without imposing provider-specific event ordering.
Impact
This is a breaking API simplification. Implementations change from
impl<M: CompletionModel> AgentHook<M> for Hooktoimpl AgentHook for Hook. Managed completion and streaming response hooks now readprompt,content,usage, andmessage_iddirectly from their event rather than a typed provider response.message_idremains optional. Managed streams accept silent message-ID metadata after the typed final payload, but reject visible assistant content after that payload as a malformed provider stream.Validation
cargo fmt --all -- --checkcargo clippy --all-targets --all-features -- -D warningsCARGO_INCREMENTAL=0 cargo testcargo doc --workspace --no-depscargo check -p rig-core --features wasm --target wasm32-unknown-unknowncargo test -p rig-core --doccargo check -p request_hookmain; one post-final validation gap was found, fixed, retested, and the final review found no remaining issuesWorkspace documentation succeeds with two existing unrelated rustdoc warnings in the Doubleword and Neo4j crates.