Use ListAgentKnowledgeBases with an AWS SDK or CLI - Amazon Bedrock

Use ListAgentKnowledgeBases with an AWS SDK or CLI

The following code example shows how to use ListAgentKnowledgeBases.

Action examples are code excerpts from larger programs and must be run in context. You can see this action in context in the following code example:

Python
SDK for Python (Boto3)
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository.

List the knowledge bases associated with an agent.

def list_agent_knowledge_bases(self, agent_id, agent_version): """ List the knowledge bases associated with a version of an Amazon Bedrock Agent. :param agent_id: The unique identifier of the agent. :param agent_version: The version of the agent. :return: The list of knowledge base summaries for the version of the agent. """ try: knowledge_bases = [] paginator = self.client.get_paginator("list_agent_knowledge_bases") for page in paginator.paginate( agentId=agent_id, agentVersion=agent_version, PaginationConfig={"PageSize": 10}, ): knowledge_bases.extend(page["agentKnowledgeBaseSummaries"]) except ClientError as e: logger.error(f"Couldn't list knowledge bases. {e}") raise else: return knowledge_bases

For a complete list of AWS SDK developer guides and code examples, see Using Amazon Bedrock with an AWS SDK. This topic also includes information about getting started and details about previous SDK versions.