Weird behaviour depending on the agent property named in mastra instance

I have no idea what is happening. Just 2 minimal example. This works:
import { Mastra } from "@mastra/core/mastra";
import { Agent } from "@mastra/core";
import { createAmazonBedrock } from "@ai-sdk/amazon-bedrock";

const bedrock = createAmazonBedrock({ region: "eu-central-1" });

const gitlabAgent = new Agent({
name: "gitlab-agent",
instructions: "You are a helpful assistant.",
model: bedrock("eu.anthropic.claude-sonnet-4-5-20250929-v1:0"),
});


export const mastra = new Mastra({
agents: { coreAgent: gitlabAgent },
});
import { Mastra } from "@mastra/core/mastra";
import { Agent } from "@mastra/core";
import { createAmazonBedrock } from "@ai-sdk/amazon-bedrock";

const bedrock = createAmazonBedrock({ region: "eu-central-1" });

const gitlabAgent = new Agent({
name: "gitlab-agent",
instructions: "You are a helpful assistant.",
model: bedrock("eu.anthropic.claude-sonnet-4-5-20250929-v1:0"),
});


export const mastra = new Mastra({
agents: { coreAgent: gitlabAgent },
});
This fails:
import { Mastra } from "@mastra/core/mastra";
import { Agent } from "@mastra/core";
import { createAmazonBedrock } from "@ai-sdk/amazon-bedrock";

const bedrock = createAmazonBedrock({ region: "eu-central-1" });

const gitlabAgent = new Agent({
name: "gitlab-agent",
instructions: "You are a helpful assistant.",
model: bedrock("eu.anthropic.claude-sonnet-4-5-20250929-v1:0"),
});


export const mastra = new Mastra({
agents: { gitlabAgent },
});
import { Mastra } from "@mastra/core/mastra";
import { Agent } from "@mastra/core";
import { createAmazonBedrock } from "@ai-sdk/amazon-bedrock";

const bedrock = createAmazonBedrock({ region: "eu-central-1" });

const gitlabAgent = new Agent({
name: "gitlab-agent",
instructions: "You are a helpful assistant.",
model: bedrock("eu.anthropic.claude-sonnet-4-5-20250929-v1:0"),
});


export const mastra = new Mastra({
agents: { gitlabAgent },
});
11 Replies
Guria
GuriaOP2w ago
with following error:
Error creating stream APICallError [AI_APICallError]: undefined: The model returned the following errors: `temperature` and `top_p` cannot both be specified for this model. Please use only one.
at file:///redacted/node_modules/@ai-sdk/provider-utils/dist/index.mjs:847:14
// redacted
url: 'https://bedrock-runtime.eu-central-1.amazonaws.com/model/eu.anthropic.claude-sonnet-4-5-20250929-v1%3A0/converse-stream',
requestBodyValues: {
system: [ [Object] ],
messages: [ [Object] ],
additionalModelRequestFields: undefined,
inferenceConfig: { temperature: 0.5, topP: 1 }
},
statusCode: 400,
responseHeaders: {
connection: 'keep-alive',
'content-length': '142',
'content-type': 'application/json',
date: 'Thu, 09 Oct 2025 12:31:21 GMT',
'x-amzn-errortype': 'ValidationException:http://internal.amazon.com/coral/com.amazon.bedrock/',
'x-amzn-requestid': '769869bd-311c-4553-bc3a-16bcf7dba78f'
},
responseBody: '{"message":"The model returned the following errors: `temperature` and `top_p` cannot both be specified for this model. Please use only one."}',
isRetryable: false,
data: {
message: 'The model returned the following errors: `temperature` and `top_p` cannot both be specified for this model. Please use only one.'
},
[Symbol(vercel.ai.error)]: true,
[Symbol(vercel.ai.error.AI_APICallError)]: true
}
ERROR [2025-10-09 15:31:21.820 +0300] (Mastra): Error in agent stream
runId: "gitlabAgent"
error: {}
Error creating stream APICallError [AI_APICallError]: undefined: The model returned the following errors: `temperature` and `top_p` cannot both be specified for this model. Please use only one.
at file:///redacted/node_modules/@ai-sdk/provider-utils/dist/index.mjs:847:14
// redacted
url: 'https://bedrock-runtime.eu-central-1.amazonaws.com/model/eu.anthropic.claude-sonnet-4-5-20250929-v1%3A0/converse-stream',
requestBodyValues: {
system: [ [Object] ],
messages: [ [Object] ],
additionalModelRequestFields: undefined,
inferenceConfig: { temperature: 0.5, topP: 1 }
},
statusCode: 400,
responseHeaders: {
connection: 'keep-alive',
'content-length': '142',
'content-type': 'application/json',
date: 'Thu, 09 Oct 2025 12:31:21 GMT',
'x-amzn-errortype': 'ValidationException:http://internal.amazon.com/coral/com.amazon.bedrock/',
'x-amzn-requestid': '769869bd-311c-4553-bc3a-16bcf7dba78f'
},
responseBody: '{"message":"The model returned the following errors: `temperature` and `top_p` cannot both be specified for this model. Please use only one."}',
isRetryable: false,
data: {
message: 'The model returned the following errors: `temperature` and `top_p` cannot both be specified for this model. Please use only one.'
},
[Symbol(vercel.ai.error)]: true,
[Symbol(vercel.ai.error.AI_APICallError)]: true
}
ERROR [2025-10-09 15:31:21.820 +0300] (Mastra): Error in agent stream
runId: "gitlabAgent"
error: {}
The only difference is agents: { gitlabAgent }, vs agents: { coreAgent: gitlabAgent }, It costed me hours of struggling 🙁 Also not happens if I switch to provider with a model not complaining about temperature and top_p defined at the same time. So bedrock part is also important here reproduced with all latest ATM:
"dependencies": {
"@ai-sdk/amazon-bedrock": "^3.0.33",
"@ai-sdk/openai-compatible": "^1.0.20",
"@mastra/core": "^0.20.2",
"@mastra/libsql": "^0.15.1",
"@mastra/loggers": "^0.10.15",
"@mastra/memory": "^0.15.6",
"zod": "^3.25.76"
},
"devDependencies": {
"@types/node": "^24.6.2",
"@vitest/coverage-v8": "^3.2.4",
"ai": "^5.0.62",
"mastra": "^0.15.1",
"msw": "^2.11.4",
"typescript": "^5.9.3",
"vitest": "^3.2.4"
}
"dependencies": {
"@ai-sdk/amazon-bedrock": "^3.0.33",
"@ai-sdk/openai-compatible": "^1.0.20",
"@mastra/core": "^0.20.2",
"@mastra/libsql": "^0.15.1",
"@mastra/loggers": "^0.10.15",
"@mastra/memory": "^0.15.6",
"zod": "^3.25.76"
},
"devDependencies": {
"@types/node": "^24.6.2",
"@vitest/coverage-v8": "^3.2.4",
"ai": "^5.0.62",
"mastra": "^0.15.1",
"msw": "^2.11.4",
"typescript": "^5.9.3",
"vitest": "^3.2.4"
}
Guria
GuriaOP2w ago
related issue about sonnet 4.5 in bedrock https://github.com/RooCodeInc/Roo-Code/issues/8377
GitHub
[BUG] Sonnet 4.5 cannot both be specified for this model error mess...
Problem (one or two sentences) When trying to invoke Sonnet 4.5 under Bedrock API, get error message "Sonnet 4.5 cannot both be specified for this model error message". Not sure if it hap...
Mastra Triager
GitHub
[DISCORD:1425823514170101831] Weird behaviour depending on the agen...
This issue was created from Discord post: https://discord.com/channels/1309558646228779139/1425823514170101831 I have no idea what is happening. Just 2 minimal example. This works: import { Mastra ...
_roamin_
_roamin_2w ago
Hmm, that seems tricky. I don't have access to bedrock, but I did try creating a provider middleware to see if there's a difference in what is being sent to the API and could not see anything different. Do you see anything on your end if you use the code below?
import { Mastra } from "@mastra/core/mastra";
import { Agent } from "@mastra/core/agent";
import { bedrock } from "@ai-sdk/amazon-bedrock";
import { wrapProvider } from "ai";

const wrappedModel = wrapProvider({
provider: bedrock,
languageModelMiddleware: {
wrapStream: ({ doStream, params, model }) => {
console.dir(params, { depth: null });
// console.dir(model, { depth: null });

// throw new Error("Intentional Error for Testing");

return doStream();
},
},
});

const gitlabAgent = new Agent({
name: "gitlab-agent",
instructions: "You are a helpful assistant.",
model: wrappedModel.languageModel(
"eu.anthropic.claude-sonnet-4-5-20250929-v1:0"
),
});

export const mastra = new Mastra({
// agents: { coreAgent: gitlabAgent },
agents: { gitlabAgent },
});

const result = await gitlabAgent.generate("hi");
import { Mastra } from "@mastra/core/mastra";
import { Agent } from "@mastra/core/agent";
import { bedrock } from "@ai-sdk/amazon-bedrock";
import { wrapProvider } from "ai";

const wrappedModel = wrapProvider({
provider: bedrock,
languageModelMiddleware: {
wrapStream: ({ doStream, params, model }) => {
console.dir(params, { depth: null });
// console.dir(model, { depth: null });

// throw new Error("Intentional Error for Testing");

return doStream();
},
},
});

const gitlabAgent = new Agent({
name: "gitlab-agent",
instructions: "You are a helpful assistant.",
model: wrappedModel.languageModel(
"eu.anthropic.claude-sonnet-4-5-20250929-v1:0"
),
});

export const mastra = new Mastra({
// agents: { coreAgent: gitlabAgent },
agents: { gitlabAgent },
});

const result = await gitlabAgent.generate("hi");
Guria
GuriaOP2w ago
@Romain I think the problem is that mastra uses agent property key to address agents. If you check playground you may note that http://localhost:4111/agents/<agent-name> and in sidebar under "Copy Agent ID for use in code" button match property that was used to register the agent and don't match id property defined during agent creation So my working example is seems to be side effect and we have 2 separate issues. One is unsupported set of providerOptions for bedrock sonnet 4.5 as in similar ticket for roo code Another is mismatches in retrieving agents in internals based on different id sources @Romain I see you use generate right in script, while I was starting stream from playground. checking locally with middleware Yes, I can confirm that issue exist only for playground initiated requests both generate and stream and playground has no ability to avoid passing these values I can go with middleware as workaround for now, though I'd take a much closer look to the way id's of agents determined internally
Guria
GuriaOP2w ago
and playground has no ability to avoid passing these values
wrong statement. sorry. there is actual way, though not obvious
No description
Guria
GuriaOP2w ago
as I said previously it seems with my "working" solution was because playground defined properties were not applied to the agent due to mismatch caused by property renaming
_roamin_
_roamin_2w ago
Got it, yeah, that makes sense, I understand why you were getting this weird behavior. I'm going to update the GH issue to explain that this issue occurs when using the agent through the playground. Thanks for finding out this issue!
Guria
GuriaOP2w ago
What about agent id sources?
_roamin_
_roamin_2w ago
Actually, I'm not able to reproduce. If I register my agent like this agents: { weatherAgent }, change the temperature in the playground, then I see the updated temperature being sent to the api. Then I tried doing it this way agents: { core_agent: weatherAgent }, changed the temperature and still was able to see the correct temperature being sent to the api. 🤔
Guria
GuriaOP5d ago
can you confirm that agentId you see in playground derived from agents property name in your case? similar issue with workflow being addressed by the property used in tools configuration property: https://discord.com/channels/1309558646228779139/1428295168565448755

Did you find this page helpful?