Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
5d81286
feat: add Amazon Bedrock Knowledge Base tool and context provider
PVidyadhar Jul 11, 2026
2f9edd2
Merge branch 'main' into bmkb-managed-kb-support
PVidyadhar Aug 5, 2026
3d1ae25
fix: inject KB context as instructions to avoid consecutive user roles
PVidyadhar Sep 9, 2026
9f8ea75
fix: address Copilot review on #8173
PVidyadhar Sep 9, 2026
dfd0d2f
fix: correct agentic result parsing + scope user-message coalescing
PVidyadhar Sep 9, 2026
8da7c32
fix: disable response generation in agentic retrieve
PVidyadhar Sep 9, 2026
db70b32
fix: address 4th Copilot review + eavanvalkenburg feedback on #8173
PVidyadhar Sep 11, 2026
a639086
samples: move Bedrock KB samples to canonical provider tree
PVidyadhar Sep 11, 2026
46fb12e
samples: read BEDROCK_REGION for KB client region
PVidyadhar Sep 11, 2026
ef6bbb0
test: fix stale coalescing comment in KB provider test
PVidyadhar Sep 11, 2026
3af22d9
Python: fix bedrock KB CI — pyright, pyupgrade, and test typing
PVidyadhar Sep 18, 2026
376c616
Python: address bedrock KB review feedback (IAM, SQL ROW, sample output)
PVidyadhar Sep 18, 2026
37d1d52
Python: consolidate standard Retrieve behind _retrieve_standard_passages
PVidyadhar Sep 18, 2026
773cece
Python: apply ruff format to bedrock KB (single-line comprehensions)
PVidyadhar Sep 18, 2026
af64bdd
Python: address Copilot re-review (IMAGE content, security wording, s…
PVidyadhar Sep 18, 2026
6900e99
Python: log KB context-provider retrieval failure at WARNING not DEBUG
PVidyadhar Sep 18, 2026
736d27e
Python: fix BedrockChatClient usage in KB examples
PVidyadhar Sep 18, 2026
dafe97c
Python: handle AUDIO/VIDEO retrieval content, not just IMAGE
PVidyadhar Sep 18, 2026
60b3361
Python: align KB client with Bedrock settings/session; drop file-leve…
PVidyadhar Sep 18, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions python/packages/bedrock/AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ Integration with AWS Bedrock for LLM inference.
- **`BedrockChatOptions`** - Options TypedDict for Bedrock-specific parameters
- **`BedrockGuardrailConfig`** - Configuration for Bedrock guardrails
- **`BedrockSettings`** - Pydantic settings for Bedrock configuration
- **`BedrockKnowledgeBaseTool`** - `FunctionTool` for retrieving from an Amazon Bedrock Knowledge Base (agentic retrieval with fallback to standard Retrieve)
- **`BedrockKnowledgeBaseProvider`** - `ContextProvider` that injects Knowledge Base passages before each agent run

## Usage

Expand Down
77 changes: 77 additions & 0 deletions python/packages/bedrock/BEDROCK_MANAGED_KB.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# Bedrock Managed Knowledge Base Support

## Overview
Adds an Agent Framework tool that queries Amazon Bedrock Knowledge Bases for managed retrieval within agent pipelines.

## Usage
```python
from agent_framework import Agent
from agent_framework_bedrock import BedrockKnowledgeBaseTool, BedrockChatClient, BedrockChatOptions

tool = BedrockKnowledgeBaseTool(
knowledge_base_id="YOUR_KB_ID",
region_name="us-east-1",
)

# As a FunctionTool, pass directly to an Agent:
agent = Agent(client=BedrockChatClient(model="..."), tools=[tool])

# Or invoke directly for testing:
import asyncio
result = asyncio.run(tool.invoke(arguments={"query": "What are the compliance requirements?"}))
print(result) # List of Content items with retrieval results
```

## Configuration

All configuration is via constructor parameters:

| Parameter | Description | Default |
|---|---|---|
| `knowledge_base_id` | Bedrock Knowledge Base ID (required) | — |
| `region_name` | AWS region for the KB | `us-east-1` |
| `number_of_results` | Maximum retrieval results | `5` |
| `use_agentic_retrieval` | Enable agentic multi-hop retrieval | `True` |
| `client` | Pre-configured boto3 client (optional) | Auto-created |

## Features
- Managed search (no vector store needed)
- **BedrockKnowledgeBaseTool**: Agentic retrieval with query decomposition + reranking, automatic fallback to standard Retrieve
- **BedrockKnowledgeBaseProvider**: Standard managed retrieval injected as context before each agent run
- Multi-source support (S3, Web, Confluence, SharePoint)
- Compatible with Agent Framework FunctionTool and ContextProvider interfaces

## SDK Requirements
- boto3 >= 1.43.32

## Required IAM Permissions
```json
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"bedrock:Retrieve",
"bedrock:GetDocumentContent"
],
"Resource": "arn:aws:bedrock:<region>:<account-id>:knowledge-base/<kb-id>"
},
{
"Effect": "Allow",
"Action": [
"bedrock:AgenticRetrieveStream",
"bedrock:InvokeModelWithResponseStream"
],
"Resource": "*"
}
Comment on lines +60 to +67

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we use AWS's complete agentic-retrieval policy here? The calling identity also needs bedrock:GetDocumentContent on the knowledge base and bedrock:InvokeModelWithResponseStream; with this policy, AgenticRetrieveStream can fail authorization and _retrieve silently falls back to single-pass Retrieve, so the default tool never provides the advertised query decomposition. The policy in python/samples/02-agents/providers/amazon/README.md:31-42 needs the same additions.

]
}
```

> Note: `bedrock:AgenticRetrieveStream` and `bedrock:InvokeModelWithResponseStream` have no resource-level permission type, so they must be granted with `Resource: "*"`. Scoping `AgenticRetrieveStream` to a Knowledge Base ARN implicitly denies the call and silently forces a fallback to standard `Retrieve`, so the default tool never performs the advertised query decomposition. `bedrock:Retrieve` and `bedrock:GetDocumentContent` remain scoped to the Knowledge Base ARN — `GetDocumentContent` is required because agentic retrieval calls it during a `FullDocumentExpansion` step, and a policy without it fails partway through a query. This matches the [AWS agentic-retrieval permissions reference](https://docs.aws.amazon.com/bedrock/latest/userguide/kb-test-agentic-retrieve.html). `AgenticRetrieveStream`/`GetDocumentContent`/`InvokeModelWithResponseStream` are only required when using `use_agentic_retrieval=True`.

## References
- [Build a Managed Knowledge Base](https://docs.aws.amazon.com/bedrock/latest/userguide/kb-build-managed.html)
- [Retrieve API](https://docs.aws.amazon.com/bedrock/latest/userguide/kb-test-retrieve.html)
- [Agentic Retrieval](https://docs.aws.amazon.com/bedrock/latest/userguide/kb-test-agentic.html)
7 changes: 7 additions & 0 deletions python/packages/bedrock/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,10 @@ See the [Bedrock sample](../../samples/02-agents/providers/amazon/bedrock_chat_c
- Loads credentials from the `BEDROCK_*` environment variables
- Instantiates `BedrockChatClient`
- Sends a simple conversation turn and prints the response

### Knowledge Base Examples

For Amazon Bedrock managed Knowledge Base retrieval, see:

- [`bedrock_kb_tool.py`](../../samples/02-agents/providers/amazon/bedrock_kb_tool.py) — `BedrockKnowledgeBaseTool` as a `FunctionTool` the agent calls on demand.
- [`bedrock_kb_context_provider.py`](../../samples/02-agents/providers/amazon/bedrock_kb_context_provider.py) — `BedrockKnowledgeBaseProvider` as a `ContextProvider` that injects KB context automatically.
4 changes: 4 additions & 0 deletions python/packages/bedrock/agent_framework_bedrock/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

from ._chat_client import BedrockChatClient, BedrockChatOptions, BedrockGuardrailConfig, BedrockSettings
from ._embedding_client import BedrockEmbeddingClient, BedrockEmbeddingOptions, BedrockEmbeddingSettings
from ._knowledge_base import BedrockKnowledgeBaseTool
from ._knowledge_base_provider import BedrockKnowledgeBaseProvider
Comment on lines +7 to +8

try:
__version__ = importlib.metadata.version(__name__)
Expand All @@ -17,6 +19,8 @@
"BedrockEmbeddingOptions",
"BedrockEmbeddingSettings",
"BedrockGuardrailConfig",
"BedrockKnowledgeBaseProvider",
"BedrockKnowledgeBaseTool",
"BedrockSettings",
"__version__",
]
Loading
Loading