Skip to content
Merged
Changes from 2 commits
Commits
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
12 changes: 4 additions & 8 deletions crates/goose/src/providers/bedrock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ pub const BEDROCK_DEFAULT_MAX_RETRY_INTERVAL_MS: u64 = 120_000;

#[derive(Debug, serde::Serialize)]
pub struct BedrockProvider {
#[serde(skip)]
client: Client,
model: ModelConfig,
#[serde(skip)]
retry_config: RetryConfig,
Expand All @@ -65,19 +63,15 @@ impl BedrockProvider {
set_aws_env_vars(config.all_secrets());

let sdk_config = aws_config::load_from_env().await;

// validate credentials or return error back up
sdk_config
.credentials_provider()
.unwrap()
.provide_credentials()
.await?;
let client = Client::new(&sdk_config);

let retry_config = Self::load_retry_config(config);

Ok(Self {
client,
model,
retry_config,
name: Self::metadata().name,
Expand Down Expand Up @@ -117,8 +111,10 @@ impl BedrockProvider {
) -> Result<(bedrock::Message, Option<bedrock::TokenUsage>), ProviderError> {
let model_name = &self.model.model_name;

let mut request = self
.client
let sdk_config = aws_config::load_from_env().await;
let client = Client::new(&sdk_config);
Comment on lines +114 to +115
Copy link

Copilot AI Nov 6, 2025

Choose a reason for hiding this comment

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

Creating a new AWS SDK config and client on every API call introduces significant overhead. The aws_config::load_from_env() call performs I/O operations to load credentials from various sources (environment variables, config files, instance metadata, etc.). Consider implementing a caching mechanism with credential refresh logic, or leverage the AWS SDK's built-in credential provider caching to avoid this repeated overhead on each request.

Copilot uses AI. Check for mistakes.
Copy link
Collaborator

Choose a reason for hiding this comment

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

this seems like a fair point although depends on how much overhead - making an LLM call is expensive so maybe it doesn't matter?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yeah - that was the slop comment left by goose (and copilot is just parrotting the same). I don't really know, but I don't trust this aws stuff very much and if it isn't practically that slow... it may be ok. but does seem extreme (mostly I wanted to see if someone could try it out and see if it worked in the first case). Another option is to somehow trap and re-initialise when needed.


let mut request = client
.converse()
.system(bedrock::SystemContentBlock::Text(system.to_string()))
.model_id(model_name.to_string())
Expand Down
Loading