Skip to content

feat(aws/bedrock): add BedrockAdapter implementing LlmProvider#127

Open
Sandipmandal25 wants to merge 1 commit intoc2siorg:mainfrom
Sandipmandal25:feat/aws-bedrock
Open

feat(aws/bedrock): add BedrockAdapter implementing LlmProvider#127
Sandipmandal25 wants to merge 1 commit intoc2siorg:mainfrom
Sandipmandal25:feat/aws-bedrock

Conversation

@Sandipmandal25
Copy link
Copy Markdown
Contributor

Summary

Adds BedrockAdapter, a complete AWS Bedrock implementation of the LlmProvider trait using aws-sdk-bedrockruntime.

Changes

  • Introduced BedrockAdapter implementing all four LlmProvider methods

  • generate via converse()

    • Returns full response with usage stats and finish reason
  • stream via converse_stream()

    • Supports real-time token streaming using LlmStreamEvent
  • embed via invoke_model()

    • Uses Titan Embeddings V2 (amazon.titan-embed-text-v2:0, 1024 dimensions)
  • generate_with_tools via converse() with ToolConfiguration

    • Returns ToolCallResponse::ToolCall or ToolCallResponse::Text
  • Added helper utilities:

    • json_to_document / document_to_json for aws_smithy_types::Document conversion
  • Safety :

    • Safe numeric casts for token handling:
      • .max(0) as u32
      • .min(i32::MAX as u32) as i32
    • Filters out system-role messages before sending to Bedrock
    • Stream errors propagated via LlmStreamEvent::Error instead of being silently dropped

Testing

All integration tests pass against the live AWS Bedrock API:


test test_bedrock_generate              ... ok
test test_bedrock_stream                ... ok
test test_bedrock_embed                 ... ok
test test_bedrock_generate_with_tools   ... ok

test result: ok. 4 passed; 0 failed; finished in 2.93s

  • Model: amazon.nova-micro-v1:0
  • Region: us-east-1

References

@shivv23
Copy link
Copy Markdown

shivv23 commented Apr 2, 2026

Thanks for the clarification about discussing the approach with mentor. Good to see the Bedrock implementation completed in #127.

For context, my PR #125 also implements Bedrock with a few additional features worth considering:

  • Configurable timeout (default 60s) to prevent hanging requests
  • Parallel embedding requests via join_all for better throughput
  • Builder pattern for configuration (with_embed_model, with_timeout)
  • Proper finish reason mapping (Stop, Length, ToolCall)

Happy to close #125 if maintainers prefer #127's approach, or we can discuss which implementation best fits the project architecture.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants