Skip to content

[FLINK-AGENTS-523] Add Amazon Bedrock chat model and embedding model integrations#534

Open
avichaym wants to merge 4 commits intoapache:mainfrom
avichaym:feature/bedrock-integration
Open

[FLINK-AGENTS-523] Add Amazon Bedrock chat model and embedding model integrations#534
avichaym wants to merge 4 commits intoapache:mainfrom
avichaym:feature/bedrock-integration

Conversation

@avichaym
Copy link

Linked issue: #523

Purpose of change

Add Amazon Bedrock as a chat model and embedding model provider for Flink Agents.

  • BedrockChatModelConnection — Converse API with native tool calling, SigV4 auth
  • BedrockChatModelSetup — model, temperature, max_tokens configuration
  • BedrockEmbeddingModelConnection — Titan Text Embeddings V2 with parallel batch embedding
  • BedrockEmbeddingModelSetup — model, dimensions configuration

New modules: integrations/chat-models/bedrock/, integrations/embedding-models/bedrock/

Tests

  • Unit tests: BedrockChatModelConnectionTest (4), BedrockChatModelSetupTest (3), BedrockEmbeddingModelTest (4)
  • End-to-end validated against real Bedrock with 6 demo applications (single-agent, ReAct tool calling, multi-agent pipeline, RAG, long-term memory, MCP)

API

No public API changes. New integration modules only.

Documentation

  • doc-needed
  • doc-not-needed
  • doc-included

Avichay Marciano added 2 commits February 10, 2026 08:02
…grations

Add two new integration modules for Amazon Bedrock:

- Chat model using the Converse API with native tool calling support,
  SigV4 auth via DefaultCredentialsProvider, and token metrics reporting.
  Supports all Bedrock models accessible via Converse API.

- Embedding model using Titan Text Embeddings V2 via InvokeModel.
  Batch embed(List<String>) parallelizes via configurable thread pool
  (embed_concurrency parameter, default 4).

Includes unit tests for constructors, parameter handling, and inheritance.
@github-actions github-actions bot added priority/major Default priority of the PR or issue. fixVersion/0.3.0 The feature or bug should be implemented/fixed in the 0.3.0 version. doc-not-needed Your PR changes do not impact docs labels Feb 10, 2026
@wenjin272 wenjin272 added doc-needed Your PR changes impact docs. and removed doc-not-needed Your PR changes do not impact docs labels Feb 12, 2026
@avichaym avichaym force-pushed the feature/bedrock-integration branch from a10b9dd to 34d38c2 Compare February 13, 2026 22:24
}
return trimmed;
}
int start = trimmed.indexOf('{');
Copy link
Collaborator

@weiqingy weiqingy Feb 19, 2026

Choose a reason for hiding this comment

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

This fallback path extracts the substring between the first '{'and last '}' from any response. If the model returns a normal text response that happens to contain braces (e.g., "Use the format {key: value} for config"), this would discard everything outside the braces.
Should this extraction only apply when structured output is expected (i.e., when an outputSchema is provided), rather than on every response? The other integrations (OpenAI, Anthropic) don't modify the text content at the connection layer.

Copy link
Author

Choose a reason for hiding this comment

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

Good catch. Removed the {...} extraction fallback entirely — stripMarkdownFences now only strips markdown code fences ( json... ), which is a lossless operation. Additionally, fence stripping is now
only applied to non-tool-call responses, since tool-call responses should pass through unmodified.

The connection layer doesn't have visibility into whether outputSchema is set , so scoping it that way would require changing the BaseChatModelConnection interface.
Removing the extraction altogether addresses the core concern — normal text responses containing braces are no longer corrupted.

Also Added 5 unit tests for stripMarkdownFences covering: text with braces preserved, clean JSON passthrough, json fence stripping, plain fence stripping, and null handling.

Fixed in 6d50c47

}

return convertResponse(response);
} catch (Exception e) {
Copy link
Collaborator

@weiqingy weiqingy Feb 19, 2026

Choose a reason for hiding this comment

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

Bedrock frequently returns ThrottlingException under load. The current code wraps all exceptions into a RuntimeException without retry. It might be worth handling ThrottlingException and ServiceUnavailableException with retry here - or at minimum, preserving the original exception type so callers can distinguish transient from permanent failures. (PR #531 is adding similar retry logic to MCPServer for the same reason.)

Copy link
Author

Choose a reason for hiding this comment

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

Added exponential backoff retry around client.converse(), consistent with the retry already in BedrockEmbeddingModelConnection in this same PR.
MAX_RETRIES=5, backoff with jitter (2^attempt 200ms (0.5 + random 0.5)), covering ThrottlingException, ServiceUnavailableException, ModelErrorException, 429, and 503. Non-retryable exceptions still fail immediately with the original exception preserved as the cause.

Fixed in 6d50c47

…ences

- Add exponential backoff retry (MAX_RETRIES=5) for ThrottlingException,
  ServiceUnavailableException, ModelErrorException, 429, 503 — consistent
  with BedrockEmbeddingModelConnection in this PR.
- Remove {..} JSON extraction fallback from stripMarkdownFences that could
  corrupt normal text responses containing braces.
- Only apply markdown fence stripping on non-tool-call responses.
- Add 5 unit tests for stripMarkdownFences covering: text with braces,
  clean JSON, json fences, plain fences, and null input.
@avichaym avichaym force-pushed the feature/bedrock-integration branch from 8d23262 to 6d50c47 Compare February 19, 2026 07:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

doc-needed Your PR changes impact docs. fixVersion/0.3.0 The feature or bug should be implemented/fixed in the 0.3.0 version. priority/major Default priority of the PR or issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

Comments