- Newest
- Most votes
- Most comments
When implementing a custom orchestration Lambda for a Bedrock Agent that uses a knowledge base, the knowledge base search operation is handled through the orchestration parsed response structure.
In a custom parser Lambda function for orchestration, you need to include the agentKnowledgeBase field in the responseDetails when the agent determines that a knowledge base search is needed. This field should be compatible with the KNOWLEDGE_BASE invocation type and contain:
knowledgeBaseId- The unique identifier of the knowledge basesearchQuery- The query to send to the knowledge base in thevaluefield
When the agent processes this response, it will automatically perform the knowledge base search using the provided query. After retrieving information from the knowledge base, the agent can then use this information to formulate its final response.
For the final response that includes knowledge base information, you should use the agentFinalResponse field (compatible with the FINISH invocation type) which contains:
responseText- The response to the usercitations- Citations for the response
To ensure that citations from the knowledge base are reliably included in the final response, you may need to:
- Structure your orchestration template to explicitly instruct the model to include citations
- Use XML formatting in your orchestration template to guide the model on how to properly format responses with citations
- Implement proper parsing in your Lambda function to extract and format citations correctly
The custom parser Lambda gives you control over how the agent processes and includes knowledge base information and citations in its responses, allowing for more reliable and consistent handling of knowledge base searches.
Sources
How to get a specific formatted output from a Bedrock Agent that uses a KB? | AWS re:Post
Write a custom parser Lambda function in Amazon Bedrock Agents - Amazon Bedrock
How to have a bedrock agent reliably include knowledge base citations in the final response of InvokeAgent for Agents for Amazon Bedrock Runtime? | AWS re:Post
Relevant content
- asked a year ago

This answer isn’t addressing what I was asking.
That answer is about the default orchestration strategy, which has several predefined steps — such as pre-processing, orchestration, and knowledge base response generation. I can attach a custom parser Lambda to optionally handle the FM’s output differently before passing it back to the agent.
What I’m asking about is the custom orchestration strategy case. In that mode, should the knowledge base search be something explicitly included when the FM is first asked to create a complete plan (for example, by having it output a special command whenever a knowledge base lookup is needed)?
And then, when the custom orchestration Lambda decides to let the agent perform that lookup, should it use the INVOKE_TOOL action as well? Because configuring a knowledge base is not the same as defining an action group with functions, I’m not sure exactly how this part should be implemented — and the sample code doesn’t seem to show how knowledge base searching is handled in custom orchestration.