Skip to content

Avoid repeated context injection in RetrievalAugmentationAdvisor#5747

Open
JadenKim-dev wants to merge 1 commit intospring-projects:mainfrom
JadenKim-dev:fix/avoid-repeated-rag-context-injection
Open

Avoid repeated context injection in RetrievalAugmentationAdvisor#5747
JadenKim-dev wants to merge 1 commit intospring-projects:mainfrom
JadenKim-dev:fix/avoid-repeated-rag-context-injection

Conversation

@JadenKim-dev
Copy link
Copy Markdown

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, causing RetrievalAugmentationAdvisor to 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 when DOCUMENT_CONTEXT already exists in the request context.

Test plan

  • Added ToolCallAdvisorTests.testAdviseCallPreservesContextAcrossToolCallIterations — verifies context is preserved across tool call loop iterations and that a context-setting advisor processes only once.
  • Added RetrievalAugmentationAdvisorTests — verifies RAG pipeline is skipped when DOCUMENT_CONTEXT already exists, and executed normally when it doesn't.

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Avoid repeated context injection in RetrievalAugmentationAdvisor

1 participant