Avoid repeated context injection in RetrievalAugmentationAdvisor#5747
Open
JadenKim-dev wants to merge 1 commit intospring-projects:mainfrom
Open
Avoid repeated context injection in RetrievalAugmentationAdvisor#5747JadenKim-dev wants to merge 1 commit intospring-projects:mainfrom
JadenKim-dev wants to merge 1 commit intospring-projects:mainfrom
Conversation
During tool call loops in ToolCallAdvisor, the entire advisor chain was re-executed with the original request context on each iteration. This caused RetrievalAugmentationAdvisor to redundantly run the full RAG pipeline (query transform, vector retrieval, reranking) on every tool call, leading to unnecessary cost and latency. - Propagate response context across tool call iterations in ToolCallAdvisor so that state set by advisors is preserved - Skip RAG processing in RetrievalAugmentationAdvisor when DOCUMENT_CONTEXT already exists in the request context Closes spring-projects#5722 Signed-off-by: JadenKim-dev <jaden.kim5179@gmail.com>
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
Fixes #5722
During tool call loops in
ToolCallAdvisor, the advisor chain is re-executed on each iteration. Previously, the original request context was used every time, causingRetrievalAugmentationAdvisorto redundantly run the full RAG pipeline (query transformation, vector retrieval, document post-processing) on every tool call. This leads to unnecessary API costs and latency in agent scenarios.Changes
ToolCallAdvisor: Propagate response context across tool call loop iterations so that state set by advisors in earlier iterations is preserved for subsequent ones.RetrievalAugmentationAdvisor: Skip RAG processing whenDOCUMENT_CONTEXTalready exists in the request context.Test plan
ToolCallAdvisorTests.testAdviseCallPreservesContextAcrossToolCallIterations— verifies context is preserved across tool call loop iterations and that a context-setting advisor processes only once.RetrievalAugmentationAdvisorTests— verifies RAG pipeline is skipped whenDOCUMENT_CONTEXTalready exists, and executed normally when it doesn't.