-
Notifications
You must be signed in to change notification settings - Fork 0
Add amazonbedrock support #106
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
🦋 Changeset detectedLatest commit: 2bfa6a4 The changes in this PR will be included in the next version bump. This PR includes changesets to release 7 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR adds support for Amazon Bedrock as an AI provider, enabling the use of Claude, Llama, Titan, and other models hosted on AWS Bedrock. The implementation integrates the @ai-sdk/amazon-bedrock package and extends the existing LLM service architecture to support provider-specific options like Bedrock guardrails.
Key Changes:
- Added
@ai-sdk/amazon-bedrockdependency (v2.2.8) and integrated it into the LLM service - Introduced
ProviderOptionsMaptype system to support provider-specific options across different AI providers - Updated LLM service methods to handle Bedrock provider and forward provider-specific options
Reviewed changes
Copilot reviewed 5 out of 6 changed files in this pull request and generated 9 comments.
Show a summary per file
| File | Description |
|---|---|
| pnpm-lock.yaml | Added @ai-sdk/amazon-bedrock package (v2.2.12) and its dependencies including AWS crypto utilities and Smithy packages |
| packages/core/package.json | Added @ai-sdk/amazon-bedrock dependency with version constraint ^2.2.8 |
| packages/core/src/types/llm.types.ts | Defined provider-specific option types (BedrockProviderOptions, AnthropicProviderOptions, OpenAIProviderOptions) and ProviderOptionsMap interface |
| packages/core/src/services/base.llm.service.ts | Integrated Bedrock provider throughout all LLM methods and added providerOptions parameter forwarding |
| packages/core/src/factories/configurable-agent.factory.ts | Contains unrelated MCP client lifecycle management changes and formatting updates |
Files not reviewed (1)
- pnpm-lock.yaml: Language not supported
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // Cleanup method to close MCP connections when agent is done | ||
| cleanup: async () => { | ||
| if (mcpClientService) { | ||
| try { | ||
| console.log(`[${config.id}] Closing MCP clients...`); | ||
| await mcpClientService.closeAll(); | ||
| console.log(`[${config.id}] ✅ MCP clients closed`); | ||
| } catch (error) { | ||
| console.error(`[${config.id}] Error closing MCP clients:`, error); | ||
| } | ||
| } | ||
| }, |
Copilot
AI
Nov 25, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] This change appears to be unrelated to the "Add amazonbedrock support" PR. The addition of a cleanup method for MCP clients should be in a separate PR. Mixing unrelated changes makes it harder to review and potentially revert changes if needed.
| // Cleanup method to close MCP connections when agent is done | |
| cleanup: async () => { | |
| if (mcpClientService) { | |
| try { | |
| console.log(`[${config.id}] Closing MCP clients...`); | |
| await mcpClientService.closeAll(); | |
| console.log(`[${config.id}] ✅ MCP clients closed`); | |
| } catch (error) { | |
| console.error(`[${config.id}] Error closing MCP clients:`, error); | |
| } | |
| } | |
| }, |
| temperature, | ||
| maxOutputTokens, | ||
| // Forward provider-specific options (bedrock guardrails, anthropic cache, etc.) | ||
| ...(providerOptions ? { providerOptions } : {}), |
Copilot
AI
Nov 25, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The providerOptions object should not be nested under a providerOptions key when passing to AI SDK functions. The AI SDK expects provider-specific options (like guardrailConfig for Bedrock) to be passed directly at the top level of the configuration object.
Instead of:
...(providerOptions ? { providerOptions } : {})It should be:
...(providerOptions?.bedrock || {}),
...(providerOptions?.anthropic || {}),
...(providerOptions?.openai || {}),Or filter to only spread options for the current provider:
...(providerOptions?.[sdkProvider] || {})| ...(providerOptions ? { providerOptions } : {}), | |
| ...(providerOptions?.[sdkProvider] || {}), |
| maxOutputTokens, | ||
| tools, | ||
| // Forward provider-specific options (bedrock guardrails, anthropic cache, etc.) | ||
| ...(providerOptions ? { providerOptions } : {}), |
Copilot
AI
Nov 25, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The providerOptions object should not be nested under a providerOptions key when passing to AI SDK functions. The AI SDK expects provider-specific options to be passed directly at the top level. This should be updated to spread only the relevant provider's options based on the sdkProvider variable.
For example:
...(providerOptions?.[sdkProvider] || {})| ...(providerOptions ? { providerOptions } : {}), | |
| ...(providerOptions?.[sdkProvider] || {}), |
| // DON'T close MCP clients here - they need to stay open for subsequent calls | ||
| // MCP clients will be closed when the agent is destroyed or process exits | ||
| // Closing them here causes "closed client" errors on tool execution |
Copilot
AI
Nov 25, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] This change appears to be unrelated to the "Add amazonbedrock support" PR. The MCP client lifecycle management changes should be in a separate PR focused on fixing MCP client connection issues. Mixing unrelated changes makes it harder to review and potentially revert changes if needed.
| // DON'T close MCP clients here - they need to stay open for subsequent calls | |
| // MCP clients will be closed when the agent is destroyed or process exits | |
| // Closing them here causes "closed client" errors on tool execution |
| console.error( | ||
| `[${config.id}] ❌ Failed to initialize MCP clients:`, | ||
| error | ||
| ); |
Copilot
AI
Nov 25, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] This formatting change appears to be unrelated to the "Add amazonbedrock support" PR. Pure formatting changes should ideally be in separate commits or PRs to avoid cluttering the main feature changes.
| console.error( | |
| `[${config.id}] ❌ Failed to initialize MCP clients:`, | |
| error | |
| ); | |
| console.error(`[${config.id}] ❌ Failed to initialize MCP clients:`, error); |
| temperature, | ||
| maxOutputTokens, | ||
| // Forward provider-specific options | ||
| ...(providerOptions ? { providerOptions } : {}), |
Copilot
AI
Nov 25, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The providerOptions object should not be nested under a providerOptions key when passing to AI SDK functions. The AI SDK expects provider-specific options to be passed directly at the top level. This method needs access to the provider/sdkProvider variable to determine which provider's options to spread.
For example:
...(providerOptions?.[provider === 'anthropic' ? 'anthropic' : provider === 'bedrock' ? 'bedrock' : provider === 'openrouter' ? 'openrouter' : 'openai'] || {})| ...(providerOptions ? { providerOptions } : {}), | |
| ...(providerOptions?.[provider === 'anthropic' ? 'anthropic' : provider === 'bedrock' ? 'bedrock' : provider === 'openrouter' ? 'openrouter' : 'openai'] || {}), |
| maxOutputTokens, | ||
| tools: tools && tools.length > 0 ? (tools as any) : undefined, | ||
| // Forward provider-specific options | ||
| ...(providerOptions ? { providerOptions } : {}), |
Copilot
AI
Nov 25, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The providerOptions object should not be nested under a providerOptions key when passing to AI SDK functions. The AI SDK expects provider-specific options to be passed directly at the top level. This method needs access to the provider variable to determine which provider's options to spread.
For example:
...(providerOptions?.[provider === 'anthropic' ? 'anthropic' : provider === 'bedrock' ? 'bedrock' : provider === 'openrouter' ? 'openrouter' : 'openai'] || {})| ...(providerOptions ? { providerOptions } : {}), | |
| ...(providerOptions?.[provider === 'anthropic' ? 'anthropic' : provider === 'bedrock' ? 'bedrock' : provider === 'openrouter' ? 'openrouter' : 'openai'] || {}), |
| cacheControl?: { type: "ephemeral" }; | ||
| // Extended thinking/reasoning | ||
| thinking?: { | ||
| type: "enabled"; | ||
| budgetTokens: number; | ||
| }; |
Copilot
AI
Nov 25, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The AnthropicProviderOptions interface appears to have incorrect structure. Based on the AI SDK for Anthropic, cache control and thinking options are not passed as top-level properties.
Cache control is passed via experimental_providerMetadata.anthropic.cacheControl, and extended thinking is a model parameter. This interface should either be removed or restructured to match the actual AI SDK API for Anthropic provider options.
| cacheControl?: { type: "ephemeral" }; | |
| // Extended thinking/reasoning | |
| thinking?: { | |
| type: "enabled"; | |
| budgetTokens: number; | |
| }; | |
| experimental_providerMetadata?: { | |
| anthropic?: { | |
| cacheControl?: { type: "ephemeral" }; | |
| }; | |
| }; | |
| // Extended thinking is a model parameter, not a provider option. |
| // DON'T close MCP clients on error either - they might be needed for retry or next call | ||
| // MCP clients will be closed when the agent is destroyed or process exits |
Copilot
AI
Nov 25, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] This change appears to be unrelated to the "Add amazonbedrock support" PR. The MCP client lifecycle management changes should be in a separate PR. Mixing unrelated changes makes it harder to review and potentially revert changes if needed.
| // DON'T close MCP clients on error either - they might be needed for retry or next call | |
| // MCP clients will be closed when the agent is destroyed or process exits |
No description provided.