AWS Logo
Menu
Custom metadata filtering for sub-agents in multi-agent collaboration with Amazon Bedrock

Custom metadata filtering for sub-agents in multi-agent collaboration with Amazon Bedrock

Discover how to implement multi-agent collaboration in Amazon Bedrock using metadata filtering to efficiently manage specialized AI agents with a shared knowledge base, optimizing resource usage and response accuracy.

Anna Gruebler Clark
Amazon Employee
Published May 23, 2025

The challenge

Multi-agent collaboration in Amazon Bedrock allows multiple specialized AI agents to work together efficiently by breaking down complex tasks, operating in parallel, and coordinating through centralized planning and orchestration to achieve better problem-solving outcomes. The workflow begins when a supervisor agent receives a request and predicts which specialized sub-agent should handle it. The supervisor agent then invokes the predicted sub-agent.
In many cases, builders would like to further refine the results returned by the agent group by providing metadata to filter results from the knowledge base. When knowledge base configuration and/or metadata filtering is included in the request to the supervisor agent, this configuration is passed uniformly to all invoked sub-agents, with each sub-agent using the configuration. This simplifies workloads when the metadata is standardised across all agents. An example of this is using metadata to provide the workplace location of an employee requesting information from and HR bot. In this case, after receiving the initial request, the supervisor agent calls on multiple sub-agents to answer different questions, and the supervisor agent shares the metadata information on the employee’s workplace location for filtering.
However, in multi-agent setups, some use-cases require different agents to specialize in specific content areas, and maintaining separate knowledge bases can be inefficient and costly, or undesirable for other reasons. To support these cases, this solution uses a single knowledge base while implementing document-level access controls through metadata filtering in each sub-agent to filter the right results for each sub-agent while reducing the overhead by only using a single knowledge base.

The architecture

The provided code implements a solution for multi-agent orchestration with metadata filtering in Amazon Bedrock and solves the challenge: how to share a single knowledge base among multiple specialized agents while ensuring each agent only accesses and responds with information from a predefined set of documents.
Let’s consider an agent that answers questions about company documents. It has multiple sub-agents to answer questions for different years. This is a simple illustrative example, this type of architecture can be applied to other use cases.

Key components

The architecture consists of:
  1. Orchestrator Agent: Routes user questions to appropriate specialized sub-agents
  2. Sub-Agents: Agent1 (2020 specialist) and Agent2 (2023 specialist)
  3. Lambda Action Groups: Implement document-specific metadata filtering
  4. Shared Knowledge Base: Contains multiple documents with metadata
  5. Amazon OpenSearch Serverless: Provides vector search capabilities
Architecture diagram - Metadata filtering for sub-agents in multi-agent collaboration
Architecture diagram - Metadata filtering for sub-agents in multi-agent collaboration

Metadata Filtering in the agent action group

Before metadata filtering, document retrieval was based solely on semantic relevance up to a maximum number of documents. Metadata filtering allows users to upload custom metadata files (up to 10KB per document) and apply filters to retrieve specific subsets of semantically relevant documents while filtering on metadata values. This provides better control over document retrieval for ambiguous queries, helps distinguish between similar content in different contexts, and improves performance by reducing the search space and computational costs.
In this solution, the Lambda function associated to the agents implements document filtering. You can read more about how to configure Lambda functions to handle information that an Amazon Bedrock agent obtains from users in the documentation.
Here's the workflow for :
  1. A user submits a question to the Orchestrator agent
  2. The Orchestrator determines which year the question pertains to and routes it to the appropriate sub-agent
  3. The sub-agent invokes its Lambda action group.
  4. The action group uses OpenAPI schema that defines the parameters to be passed in as an “event” to the Lambda function, along with the outputs expected back from the Lambda function.
  5. The Lambda function:
  • Identifies which agent called it by checking the agent ID
  • Applies the appropriate document filter based on that ID
  • Calls the Bedrock Knowledge Base's RetrieveAndGenerate API with the appropriate document filter
  • The returned results only contain information from the filtered document
For simplicity in this example both Agents call on the same action group and Lambda function, but it would also be possible for each agent to interact with its own action group and Lambda function.

Key implementation details

The Lambda function applies document filtering by examining the calling agent's ID and setting the appropriate filter when retrieving documents:
This ensures that even though all agents share the same knowledge base, each agent only retrieves and responds with information from its assigned document(s).

Benefits of this approach

  1. Resource Efficiency: Uses a single knowledge base instead of multiple ones
  2. Improved Specialization: Each agent can focus on its specific domain knowledge
  3. Consistent Management: Centralized knowledge base simplifies updates and maintenance
  4. Scalability: Easy to add more agents for additional document sets
  5. Enhanced User Experience: More accurate and relevant responses

Potential use cases

This architecture can be used for various scenarios:
  1. Customer Support: Different agents specialized in various product lines or service categories
  2. Documentation Systems: Agents that handle different versions of documentation
  3. Multi-lingual Support: Agents specialized in different languages sharing the same content base
  4. Compliance and Regulations: Different agents for various regulatory frameworks

Implementation Notes

If following the code sample in GitHub - Amazon Bedrock Agent Samples: Multi-Agent Collaboration with Metadata Filtering, the setup step creates all necessary components:
  1. A Knowledge Base populated with documents from S3
  2. Lambda functions with filtering logic
  3. IAM roles for security
  4. Orchestrator and specialized sub-agents
  5. Agent associations and collaboration settings

Conclusion

By implementing metadata filtering at the Lambda action group level in Amazon Bedrock Agents, this solution provides a clean separation of concerns while maintaining efficiency in resource usage.
This pattern can be easily extended to accommodate more complex filtering scenarios, such as filtering by multiple metadata fields or implementing dynamic filtering based on query content.

Contributors

[x] Anna Grüebler Clark
[x] Omar Elkharbotly
[x] Maira Ladeira Tanke
 

Any opinions in this post are those of the individual author and may not reflect the opinions of AWS.

Comments