Skip to content

AI Agents & MCPs & AI Workflow Automation • (~400 MCP servers for AI agents) • AI Automation / AI Agent with MCPs • AI Workflows & AI Agents • MCPs for AI Agents

fix(agents): agents on Bedrock, Azure and Mistral can run again (#15718)

Hazem Adeld1d84a2b17c5
diff --git a/brain/knowledge/ai-intelligence/ai-providers.md b/brain/knowledge/ai-intelligence/ai-providers.md
index cf3b4470af8..9e31aaf14ec 100644
--- a/brain/knowledge/ai-intelligence/ai-providers.md
+++ b/brain/knowledge/ai-intelligence/ai-providers.md
@@ -146,11 +146,7 @@ renders and preserves every real price; the cheapest in the set is 0.01.
- **`/v1/ai-tools` is registered only in the CLOUD and ENTERPRISE branches of `app.ts`, but the AI Center page that reads it is not edition-gated** — so a Community admin opening the Capabilities tab fired `useAiToolConfigs`, got Fastify's `Route not found`, and the page showed the global "Failed to load data" dialog of the day. Shipped that way from #13911 until the tab was gated on `ApFlagId.EDITION` in the page. What made this class of bug hard to place is that the surface was then page-independent (raised from `QueryCache.onError` in `query-client.ts`) and React Query's 3 default retries meant it landed several seconds later on whatever page you navigated to next (the report was against `/platform/setup/general`). The tab now renders `DataFetchErrorState` in place instead, so a repeat would at least accuse the right page. When a screenshot's edition is in doubt, read the sidebar: **Billing & subscription** and **Usage** carry a lock only when `edition === COMMUNITY`, every other lock there is plan-driven. Any new EE-only route needs its UI entry point gated the same way, `enabled:` on the query or hiding the surface.
- **The AI Center providers page renders its whole state machine off one query, so every branch needs an `isLoading` gate above it.** `ProvidersTab` derives the empty state, the grouped list *and* the `?config=<id>` detail view from `useAiProviderConfigs()`. While that query is pending, `data` is `undefined` — `configs` is `[]`, so the empty "Connect your first provider" screen paints for a frame, and a hard refresh on a `?config=` URL finds no matching row and falls through to the list before flipping to the detail page. The parent `SuspenseWrapper` does not cover it: the route chunk and the suspense-backed projects collection resolve first, then the component mounts with no providers yet. Any new branch added to this page belongs below the `if (isLoading) return <ProvidersSkeleton />` gate, not beside it.
- **A save bar in the AI Center needs a full-height column, not `fixed` and not bare `sticky`.** The page sits inside *two* nested scrollers — `PlatformLayout`'s `flex flex-col flex-1 overflow-auto` and the AI Center's own `flex-1 min-w-0 overflow-auto` beside the `w-60` tab rail — so `fixed inset-x-0` centres the bar on the viewport, roughly a sidebar-width left of the content column it belongs to. Swapping it to `sticky bottom-4` fixes the centring for free but pins nothing when the content is shorter than the viewport: the bar just lands wherever the content ends, mid-page. The working shape is `min-h-full` + `flex flex-col` on the tab-content wrapper, `flex-1` on the `TabsContent`, `grow` on the panel root, then `sticky bottom-4 mt-auto` on the bar — `mt-auto` handles the short page, `sticky` handles the long one. `min-h-full` resolves only because every ancestor up to `SidebarInset h-full` has a definite height; that chain is what makes the whole thing work, so check it before reusing this elsewhere.
-
-### Key files
-
-Entry point: `aiProviderModule`, registered in `packages/server/api/src/app/app.ts` right after `aiProviderService(app.log).setup()`.
-
+- **A chat *tier* is our own idea, so it has no meaning on a provider we ship no curated model list for — resolve it by asking the key what it offers.** `ACTIVEPIECES_CHAT_TIERS` (fast/smart/premium) only maps to a real id through `ALLOWED_CHAT_MODELS_BY_PROVIDER`, which covers Anthropic, OpenAI, Google, Vertex and Activepieces. Everything else — Bedrock, Azure, Mistral, xAI, DeepSeek and the other OpenAI-compatible vendors — has an empty candidate list. The resolver used to invent an id from the tier (strip the vendor prefix, dots to dashes: `anthropic/claude-haiku-4.5` -> `claude-haiku-4-5`), which Bedrock rejected as "The provided model identifier is invalid" (GIT-1840, Pylon 5836). #15355 removed the invention and left a throw in its place, which was worse: every agent turn on those providers died with `ENTITY_NOT_FOUND: this AI provider key allows no text model a chat turn can run on` before the configured model handled anything (Pylon 6069). **The missing ingredient was never a smarter guess, it was the key's own model list.** `agentHelpers.resolveModelId` is now the single resolver for every surface: it tries our catalogue first and, only when that has nothing to say, reads `aiProviderService.listModels` (process-cached, cleared nightly by cron, already filtered by the key's `modelScope`), preferring a model whose id *contains* the tier's `nativeModelId` — Bedrock spells them `eu.anthropic.claude-sonnet-4-6-...`, so a tier still selects the model it names wherever the vendor hosts it, and otherwise degrades to the first text model the way `pickAllowedModel` already does for an admin-listed catalogue. Picking from a list the provider returned is the opposite of the fabrication #15355 removed. **Two traps, both learned the hard way.** First, an agent surface and generic chat are not symmetric: an agent *carries* a real model id (its picker lists `listModels` output unfiltered, precisely because these providers have no `ALLOWED_CHAT_MODELS_BY_PROVIDER` entry) while chat carries only a tier name, because `ChatModelSelector` falls back to tier options when `getCuratedChatModels` returns `undefined`. Second, **being listed proves the key can see a model, not that the account can invoke it** — so where a model is already settled the fast round reuses it rather than choosing again (`getAgentConfig` passes the model the turn resolved; the tool RPC reads the run's own model off the conversation or the agent via `pinnedModelOf` — and it has to read the *same* half the run did: an agent-page chat runs on `agent.draft` (`agent-conversation-controller.ts`), a Run Agent step on `agent.published`, so reading the wrong one silently lends the tool a stale model whenever the two differ). Resolving the fast tier independently once picked a Haiku the account could not invoke and failed a turn whose configured Sonnet worked fine. A borrowed model still has to pass the key's current `modelScope`, or resolution falls through to the list, which applies it. Nothing crosses the worker, so a rolling deploy has no version-skew window.
- `packages/server/api/src/app/ai/` — backend module: provider controller, service, entity, module, plus the sibling ai-tool-config files
- `packages/server/api/src/app/ai/providers/` — per-vendor strategies keyed by `AIProviderName`
- `packages/server/api/src/app/platform/billing-provider.ts` — `assertCreditsAndAppSumoNotExceeded` credit gate
diff --git a/packages/core/utils/src/lib/ai-provider-health.ts b/packages/core/utils/src/lib/ai-provider-health.ts
index 8892e2c2113..225882fe013 100644
--- a/packages/core/utils/src/lib/ai-provider-health.ts
+++ b/packages/core/utils/src/lib/ai-provider-health.ts
@@ -138,7 +138,7 @@ function isNil<T>(value: T | null | undefined): value is null | undefined {
const MAX_OBSERVED_BODY_LENGTH = 2000
const CREDIT_ERROR_PATTERNS = [/credits/i, /\b402\b/, /payment.required/i]
-const TRANSIENT_ERROR_PATTERN = /\b(429|5\d\d)\b|rate.?limit|timeout|timed out|temporarily|try again|econnreset|etimedout|socket hang up|service unavailable/i
+const TRANSIENT_ERROR_PATTERN = /\b(429|5\d\d)\b|rate.?limit|timeout|timed out|temporarily|econnreset|etimedout|socket hang up|service unavailable/i
const BILLING_BODY_PATTERN = /insufficient_quota|credit[_ ]balance|billing_hard_limit_reached|billing|\bcredits?\b|out of funds|payment required/i
diff --git a/packages/server/api/src/app/ee/agent/agent-helpers.ts b/packages/server/api/src/app/ee/agent/agent-helpers.ts
index 657a5ae8903..aaba391f968 100644
--- a/packages/server/api/src/app/ee/agent/agent-helpers.ts
+++ b/packages/server/api/src/app/ee/agent/agent-helpers.ts
@@ -1,7 +1,7 @@
import { ExecuteAgentRunJobData } from '@activepieces/core-execution'
-import { ActivepiecesAiBilling, ActivepiecesError, AIProviderName, apId, ErrorCode, isNil, spreadIfDefined, tryCatch, unique } from '@activepieces/core-utils'
+import { ActivepiecesAiBilling, ActivepiecesError, AIProviderName, apId, ErrorCode, isNil, spreadIfDefined, tryCatch, tryCatchSync, unique } from '@activepieces/core-utils'
import { aiUtils } from '@activepieces/server-utils'
-import { AgentConfig, AgentConversation, AgentConversationStatus, AI_PROVIDER_ENTITY_TYPES, GetAgentMemoryResponse, GetProviderConfigResponse, Project, ProjectType, UserMemory } from '@activepieces/shared'
+import { AgentConfig, AgentConversation, AgentConversationStatus, AI_PROVIDER_ENTITY_TYPES, AIProviderModelType, GetAgentMemoryResponse, GetProviderConfigResponse, Project, ProjectType, UserMemory } from '@activepieces/shared'
import { SharedV3ProviderOptions } from '@ai-sdk/provider'
import { EmbeddingModel, LanguageModel } from 'ai'
import { FastifyBaseLogger } from 'fastify'
@@ -145,23 +145,40 @@ async function assertRunProviderConfigured({ platformId, provider, providerConfi
}
}
-async function resolveTierModel({ platformId, tierId, provider, providerConfigId, scope, log }: { platformId: string, tierId: string, provider?: AIProviderName, providerConfigId?: string, scope: ProviderScope, log: FastifyBaseLogger }): Promise<{ model: LanguageModel, modelId: string, provider: AIProviderName }> {
- const providerConfig = await resolveRunProvider({ platformId, scope, log, ...spreadIfDefined('provider', provider), ...spreadIfDefined('providerConfigId', providerConfigId) })
- const modelId = agentModelResolution.resolveModelIdForProvider({ provider: providerConfig.provider, selectedModel: tierId, config: providerConfig.config, modelScope: providerConfig.modelScope, modelIds: providerConfig.modelIds })
- return {
- model: aiUtils.createModel({
- credentials: providerConfig,
- modelId,
- platformId,
- providerConfigId: providerConfig.configId,
- }),
- modelId,
- provider: providerConfig.provider,
+async function resolveModelId({ platformId, providerConfig, selectedModel, scope, fallbackModelId, log }: { platformId: string, providerConfig: GetProviderConfigResponse, selectedModel: string | null, scope: ProviderScope, fallbackModelId?: string, log: FastifyBaseLogger }): Promise<string> {
+ const { provider, config, modelScope, modelIds, configId } = providerConfig
+ const { data, error } = tryCatchSync(() => agentModelResolution.resolveModelIdForProvider({ provider, selectedModel, config, modelScope, modelIds }))
+ if (!isNil(data)) {
+ return data
+ }
+ const keyServesNoKnownModel = error instanceof ActivepiecesError && error.error.code === ErrorCode.ENTITY_NOT_FOUND
+ if (!keyServesNoKnownModel) {
+ throw error
+ }
+ const fallbackStillAllowed = !isNil(fallbackModelId) && (modelScope !== 'selected' || modelIds.includes(fallbackModelId))
+ if (fallbackStillAllowed) {
+ return fallbackModelId
}
+ const offered = await aiProviderService(log).listModels({ platformId, provider, scope, configId })
+ const textModels = offered.filter((model) => model.type === AIProviderModelType.TEXT)
+ if (textModels.length === 0) {
+ throw error
+ }
+ const tier = agentModelResolution.resolveTier({ tierId: selectedModel })
+ const picked = textModels.find((model) => model.id === selectedModel)
+ ?? textModels.find((model) => model.id.includes(tier.nativeModelId))
+ ?? textModels[0]
+ return picked.id
+}
+
+async function resolveFastModelId({ platformId, providerConfig, scope, fallbackModelId, log }: { platformId: string, providerConfig: GetProviderConfigResponse, scope: ProviderScope, fallbackModelId?: string, log: FastifyBaseLogger }): Promise<string> {
+ return resolveModelId({ platformId, providerConfig, selectedModel: FAST_TIER_ID, scope, log, ...spreadIfDefined('fallbackModelId', fallbackModelId) })
}
-async function resolveFastModel({ platformId, provider, providerConfigId, scope, log }: { platformId: string, provider?: AIProviderName, providerConfigId?: string, scope: ProviderScope, log: FastifyBaseLogger }): Promise<LanguageModel> {
- return (await resolveTierModel({ platformId, tierId: FAST_TIER_ID, scope, log, ...spreadIfDefined('provider', provider), ...spreadIfDefined('providerConfigId', providerConfigId) })).model
+async function resolveFastModel({ platformId, provider, providerConfigId, scope, fallbackModelId, log }: { platformId: string, provider?: AIProviderName, providerConfigId?: string, scope: ProviderScope, fallbackModelId?: string, log: FastifyBaseLogger }): Promise<LanguageModel> {
+ const providerConfig = await resolveRunProvider({ platformId, scope, log, ...spreadIfDefined('provider', provider), ...spreadIfDefined('providerConfigId', providerConfigId) })
+ const modelId = await resolveFastModelId({ platformId, providerConfig, scope, log, ...spreadIfDefined('fallbackModelId', fallbackModelId) })
+ return aiUtils.createModel({ credentials: providerConfig, modelId, platformId, providerConfigId: providerConfig.configId })
}
@@ -318,7 +335,8 @@ export const agentHelpers = {
assertRunProviderConfigured,
...agentModelResolution,
resolveFastModel,
- resolveTierModel,
+ resolveFastModelId,
+ resolveModelId,
resolveRunProvider,
resolveEmbeddingModel,
resolveChatProviderName,
diff --git a/packages/server/api/src/app/ee/agent/agent-model-resolution.ts b/packages/server/api/src/app/ee/agent/agent-model-resolution.ts
index 65f17175d08..72278a5a624 100644
--- a/packages/server/api/src/app/ee/agent/agent-model-resolution.ts
+++ b/packages/server/api/src/app/ee/agent/agent-model-resolution.ts
@@ -87,10 +87,6 @@ function resolveModelIdForAnalytics({ provider, selectedModel }: { provider: AIP
return aiProviderUtils.isCuratedChatModelId({ modelId: selectedModel }) ? selectedModel : null
}
-function resolveFastModelId({ provider, config, modelScope, modelIds }: { provider: AIProviderName, config?: AiProviderCredentials['config'], modelScope?: AiProviderModelScope, modelIds?: string[] }): string {
- return resolveModelIdForProvider({ provider, selectedModel: FAST_TIER_ID, config, modelScope, modelIds })
-}
-
export const agentModelResolution = {
findTier,
resolveTier,
@@ -98,7 +94,6 @@ export const agentModelResolution = {
resolveModelIdForProvider,
defaultModelIdForProvider,
resolveModelIdForAnalytics,
- resolveFastModelId,
}
export const FAST_TIER_ID = 'fast'
diff --git a/packages/server/api/src/app/ee/agent/personalization/chat-personalization-service.ts b/packages/server/api/src/app/ee/agent/personalization/chat-personalization-service.ts
index 8a9aeef2297..b27167dd4a5 100644
--- a/packages/server/api/src/app/ee/agent/personalization/chat-personalization-service.ts
+++ b/packages/server/api/src/app/ee/agent/personalization/chat-personalization-service.ts
@@ -250,13 +250,13 @@ export const chatPersonalizationService = (log: FastifyBaseLogger) => ({
findRow({ platformId, userId: null }),
tryCatch(() => aiToolConfigService(log).getEnabledTools({ platformId })),
])
- const providerName = provider.provider
const webSearch = enabledTools.data?.webSearch ?? null
+ const modelId = await agentHelpers.resolveModelId({ platformId, providerConfig: provider, selectedModel: null, scope: PERSONALIZATION_PROVIDER_SCOPE, log })
return {
claimed: true,
credentials: provider,
- modelId: agentHelpers.resolveModelIdForProvider({ provider: providerName, selectedModel: null, config: provider.config, modelScope: provider.modelScope, modelIds: provider.modelIds }),
- fastModelId: agentHelpers.resolveFastModelId({ provider: providerName, config: provider.config, modelScope: provider.modelScope, modelIds: provider.modelIds }),
+ modelId,
+ fastModelId: await agentHelpers.resolveFastModelId({ platformId, providerConfig: provider, scope: PERSONALIZATION_PROVIDER_SCOPE, log }),
user: { firstName: user.firstName, lastName: user.lastName, email: user.email },
platformName: platform.name,
website: companyRow?.domain ?? null,
diff --git a/packages/server/api/src/app/ee/agent/rpc/agent-config-rpc.ts b/packages/server/api/src/app/ee/agent/rpc/agent-config-rpc.ts
index 73bab9ce314..44d66fb08f5 100644
--- a/packages/server/api/src/app/ee/agent/rpc/agent-config-rpc.ts
+++ b/packages/server/api/src/app/ee/agent/rpc/agent-config-rpc.ts
@@ -83,7 +83,8 @@ export const agentConfigRpc = (log: FastifyBaseLogger) => ({
// it then adopted. A flow step reads its own conversation's project rather than the
// selection above, which narrows to what the owner can still see in chat.
const runProjectId = isFlowStep ? conversation.projectId ?? null : selectedProjectId
- const providerConfig = await agentHelpers.resolveRunProvider({ platformId, log, scope: agentHelpers.runScopeOrThrow({ projectId: runProjectId }), ...spreadIfDefined('provider', input.provider), ...spreadIfDefined('providerConfigId', input.providerConfigId) })
+ const runScope = agentHelpers.runScopeOrThrow({ projectId: runProjectId })
+ const providerConfig = await agentHelpers.resolveRunProvider({ platformId, log, scope: runScope, ...spreadIfDefined('provider', input.provider), ...spreadIfDefined('providerConfigId', input.providerConfigId) })
const attachmentRefs = files && files.length > 0 && !isNil(selectedProjectId)
? await persistAgentAttachments({ files, projectId: selectedProjectId, platformId, log })
@@ -126,7 +127,8 @@ export const agentConfigRpc = (log: FastifyBaseLogger) => ({
const tier = agentHelpers.resolveTier({ tierId: namesItsOwnModel ? null : selectedModel })
const resolvedModelId = namesItsOwnModel && !isNil(modelName)
? agentHelpers.resolveNamedModelId({ provider: providerConfig.provider, modelName, modelScope: providerConfig.modelScope, modelIds: providerConfig.modelIds })
- : agentHelpers.resolveModelIdForProvider({ provider: providerConfig.provider, selectedModel, config: providerConfig.config, modelScope: providerConfig.modelScope, modelIds: providerConfig.modelIds })
+ : await agentHelpers.resolveModelId({ platformId, providerConfig, selectedModel, scope: runScope, log })
+ const fastModelId = await agentHelpers.resolveFastModelId({ platformId, providerConfig, scope: runScope, fallbackModelId: resolvedModelId, log })
// Inject an inventory of the project's existing connections into context so the agent
// never has to *guess* an app name to find out what's connected. Without this, discovery
@@ -240,7 +242,7 @@ export const agentConfigRpc = (log: FastifyBaseLogger) => ({
credentials: providerConfig,
providerConfigId: providerConfig.configId,
modelId: resolvedModelId,
- fastModelId: agentHelpers.resolveFastModelId({ provider: providerConfig.provider, config: providerConfig.config, modelScope: providerConfig.modelScope, modelIds: providerConfig.modelIds }),
+ fastModelId,
systemPrompt: systemPromptText,
messages: messagesForLlm,
allMessages,
diff --git a/packages/server/api/src/app/ee/agent/rpc/rpc-shared.ts b/packages/server/api/src/app/ee/agent/rpc/rpc-shared.ts
index 83ef9284469..5111e867435 100644
--- a/packages/server/api/src/app/ee/agent/rpc/rpc-shared.ts
+++ b/packages/server/api/src/app/ee/agent/rpc/rpc-shared.ts
@@ -2,6 +2,7 @@ import { ActivepiecesError, connectionTemplate, ErrorCode, isNil, Permission, sp
import { ActionClassification, isReadOnlyClassification } from '@activepieces/pieces-framework'
import { AgentActionKind, AgentActionOutcome, AgentActionRef, AgentConversation, AgentConversationStatus, AgentPieceToolMetadata, AgentRunSource, agentToolClassification, ApplicationEventName } from '@activepieces/shared'
import { FastifyBaseLogger } from 'fastify'
+import { AgentConversationWithRelations } from '.././agent-conversation-entity'
import { agentHelpers } from '.././agent-helpers'
import { agentService } from '.././agent-service'
import { agentToolPinning } from '.././agent-tool-pinning'
@@ -48,6 +49,17 @@ export async function connectionForConfiguredTool({ piece, projectId, platformId
return { externalId: pinned, ...spreadIfDefined('label', connection?.displayName) }
}
+function pinnedModelOf({ conversation }: { conversation: AgentConversationWithRelations }): string | undefined {
+ const runConfig = conversation.source === AgentRunSource.FLOW_STEP
+ ? conversation.agent?.published
+ : conversation.agent?.draft
+ const pinned = runConfig?.modelName ?? conversation.modelName ?? null
+ if (isNil(pinned) || !isNil(agentHelpers.findTier({ tierId: pinned }))) {
+ return undefined
+ }
+ return pinned
+}
+
export async function configuredToolConversationOrThrow({ conversationId }: { conversationId: string }): Promise<ConfiguredToolRun> {
const conversation = await agentHelpers.conversationRepo().findOne({ where: { id: conversationId }, relations: { agent: true } })
if (isNil(conversation) || !CONFIGURED_TOOL_SOURCES.includes(conversation.source) || isNil(conversation.projectId)) {
@@ -58,6 +70,7 @@ export async function configuredToolConversationOrThrow({ conversationId }: { co
platformId: conversation.platformId,
userId: conversation.userId,
source: conversation.source,
+ ...spreadIfDefined('runModelId', pinnedModelOf({ conversation })),
...spreadIfDefined('agent', isNil(conversation.agentId) ? undefined : {
id: conversation.agentId,
...spreadIfDefined('displayName', conversation.agent?.displayName),
@@ -192,6 +205,7 @@ export type ConfiguredToolRun = {
platformId: string
userId: string
source: AgentRunSource
+ runModelId?: string
agent?: { id: string, displayName?: string }
}
diff --git a/packages/server/api/src/app/ee/agent/rpc/tool-execution-rpc.ts b/packages/server/api/src/app/ee/agent/rpc/tool-execution-rpc.ts
index 520b368d50f..c6b300e5e79 100644
--- a/packages/server/api/src/app/ee/agent/rpc/tool-execution-rpc.ts
+++ b/packages/server/api/src/app/ee/agent/rpc/tool-execution-rpc.ts
@@ -17,8 +17,8 @@ import { byteLengthOf, CONFIGURED_TOOL_SOURCES, configuredToolConversationOrThro
export const toolExecutionRpc = (log: FastifyBaseLogger) => ({
async executePieceTool(input: ExecutePieceToolRequest): Promise<ExecutePieceToolResponse> {
const configuredRun = await configuredToolConversationOrThrow({ conversationId: input.conversationId })
- const { projectId, platformId } = configuredRun
- const model = await agentHelpers.resolveFastModel({ platformId, scope: { type: 'project', projectId }, log, ...spreadIfDefined('provider', input.provider), ...spreadIfDefined('providerConfigId', input.providerConfigId) })
+ const { projectId, platformId, runModelId } = configuredRun
+ const model = await agentHelpers.resolveFastModel({ platformId, scope: { type: 'project', projectId }, log, ...spreadIfDefined('provider', input.provider), ...spreadIfDefined('providerConfigId', input.providerConfigId), ...spreadIfDefined('fallbackModelId', runModelId) })
const piece = { pieceName: input.piece.pieceName, actionName: input.piece.actionName, ...spreadIfDefined('pieceVersion', input.piece.pieceVersion) }
const connection = await connectionForConfiguredTool({ piece: input.piece, projectId, platformId, log })
const { data: resolved, error: resolveError } = await tryCatch(() => pieceToolRunner.resolveInput({
diff --git a/packages/server/api/test/unit/app/ee/agent/agent-fast-model-provider.test.ts b/packages/server/api/test/unit/app/ee/agent/agent-fast-model-provider.test.ts
index 6183238c989..3b8279a9ad2 100644
--- a/packages/server/api/test/unit/app/ee/agent/agent-fast-model-provider.test.ts
+++ b/packages/server/api/test/unit/app/ee/agent/agent-fast-model-provider.test.ts
@@ -1,15 +1,18 @@
import { AIProviderName } from '@activepieces/core-utils'
+import { AIProviderModelType } from '@activepieces/shared'
import { beforeEach, describe, expect, it, vi } from 'vitest'
-const { mockGetChatProvider, mockGetConfigOrThrow } = vi.hoisted(() => ({
+const { mockGetChatProvider, mockGetConfigOrThrow, mockListModels } = vi.hoisted(() => ({
mockGetChatProvider: vi.fn().mockResolvedValue(null),
mockGetConfigOrThrow: vi.fn(),
+ mockListModels: vi.fn().mockResolvedValue([]),
}))
vi.mock('../../../../../src/app/ai/ai-provider-service', () => ({
aiProviderService: () => ({
getChatProvider: mockGetChatProvider,
getConfigOrThrow: mockGetConfigOrThrow,
+ listModels: mockListModels,
}),
}))
@@ -26,12 +29,15 @@ const scope = { type: 'project', projectId: 'project-1' } as const
describe('resolveFastModel', () => {
beforeEach(() => {
+ mockListModels.mockClear().mockResolvedValue([])
mockGetChatProvider.mockClear().mockResolvedValue(null)
mockGetConfigOrThrow.mockClear().mockResolvedValue({
provider: AIProviderName.OPENROUTER,
configId: 'config-1',
auth: { apiKey: 'k' },
config: {},
+ modelScope: 'all',
+ modelIds: [],
})
})
@@ -62,4 +68,117 @@ describe('resolveFastModel', () => {
expect(model).toMatchObject({ credentials: { provider: AIProviderName.ANTHROPIC }, modelId: 'claude-haiku-4-5' })
})
+
+ describe('on a provider we ship no curated model list for', () => {
+ beforeEach(() => {
+ mockGetConfigOrThrow.mockResolvedValue({
+ provider: AIProviderName.BEDROCK,
+ configId: 'config-1',
+ auth: { accessKeyId: 'a', secretAccessKey: 's' },
+ config: { region: 'us-east-1' },
+ modelScope: 'all',
+ modelIds: [],
+ })
+ })
+
+ it('fills a configured action\'s inputs on a fast model the key actually serves', async () => {
+ mockListModels.mockResolvedValue([
+ { id: 'amazon.titan-text-express-v1', name: 'Titan', type: AIProviderModelType.TEXT },
+ { id: 'eu.anthropic.claude-haiku-4-5-20251001-v1:0', name: 'Haiku', type: AIProviderModelType.TEXT },
+ ])
+
+ const model = await agentHelpers.resolveFastModel({ platformId, provider: AIProviderName.BEDROCK, scope, log })
+
+ expect(model).toMatchObject({ credentials: { provider: AIProviderName.BEDROCK }, modelId: 'eu.anthropic.claude-haiku-4-5-20251001-v1:0' })
+ })
+
+ it('needs nothing from the worker, so an in-flight run on an older one still resolves', async () => {
+ mockListModels.mockResolvedValue([{ id: 'amazon.titan-text-express-v1', name: 'Titan', type: AIProviderModelType.TEXT }])
+
+ await expect(agentHelpers.resolveFastModel({ platformId, provider: AIProviderName.BEDROCK, scope, log })).resolves.toMatchObject({ modelId: 'amazon.titan-text-express-v1' })
+ })
+
+ it('still refuses a key that serves no text model at all', async () => {
+ mockListModels.mockResolvedValue([])
+
+ await expect(agentHelpers.resolveFastModel({ platformId, provider: AIProviderName.BEDROCK, scope, log })).rejects.toMatchObject({
+ error: { code: 'ENTITY_NOT_FOUND' },
+ })
+ })
+ })
+
+ it('never asks the provider when our own catalogue already names a fast model', async () => {
+ const model = await agentHelpers.resolveFastModel({ platformId, provider: AIProviderName.OPENROUTER, scope, log })
+
+ expect(model).toMatchObject({ modelId: 'anthropic/claude-haiku-4.5' })
+ expect(mockListModels).not.toHaveBeenCalled()
+ })
+})
+
+describe('resolveModelId', () => {
+ const bedrockKey = { provider: AIProviderName.BEDROCK, configId: 'config-1', auth: { accessKeyId: 'a', secretAccessKey: 's' }, config: { region: 'us-east-1' }, modelScope: 'all' as const, modelIds: [] }
+ const text = (id: string) => ({ id, name: id, type: AIProviderModelType.TEXT })
+
+ const resolve = ({ selectedModel }: { selectedModel: string | null }) =>
+ agentHelpers.resolveModelId({ platformId, providerConfig: bedrockKey, selectedModel, scope, log })
+
+ beforeEach(() => {
+ mockListModels.mockClear().mockResolvedValue([])
+ })
+
+ it('never asks the provider when our own catalogue already answers', async () => {
+ const anthropicKey = { ...bedrockKey, provider: AIProviderName.ANTHROPIC, config: {} }
+
+ await expect(agentHelpers.resolveModelId({ platformId, providerConfig: anthropicKey, selectedModel: 'smart', scope, log })).resolves.toBe('claude-sonnet-4-6')
+ expect(mockListModels).not.toHaveBeenCalled()
+ })
+
+ it('runs a chat tier on a model the key actually serves', async () => {
+ mockListModels.mockResolvedValue([text('amazon.titan-text-express-v1')])
+
+ await expect(resolve({ selectedModel: 'smart' })).resolves.toBe('amazon.titan-text-express-v1')
+ expect(mockListModels).toHaveBeenCalledWith({ platformId, provider: AIProviderName.BEDROCK, scope, configId: 'config-1' })
+ })
+
+ it('keeps the tier meaningful when the provider hosts the model that tier names', async () => {
+ mockListModels.mockResolvedValue([
+ text('amazon.titan-text-express-v1'),
+ text('global.anthropic.claude-haiku-4-5-20251001-v1:0'),
+ text('global.anthropic.claude-sonnet-4-6-20250101-v1:0'),
+ ])
+
+ await expect(resolve({ selectedModel: 'fast' })).resolves.toBe('global.anthropic.claude-haiku-4-5-20251001-v1:0')
+ await expect(resolve({ selectedModel: 'smart' })).resolves.toBe('global.anthropic.claude-sonnet-4-6-20250101-v1:0')
+ })
+
+ it('honours a model the user picked over the tier default', async () => {
+ mockListModels.mockResolvedValue([text('amazon.titan-text-express-v1'), text('mistral.mistral-large-2407-v1:0')])
+
+ await expect(resolve({ selectedModel: 'mistral.mistral-large-2407-v1:0' })).resolves.toBe('mistral.mistral-large-2407-v1:0')
+ })
+
+ it('keeps the run on the model it already resolved rather than picking a second unverified one', async () => {
+ mockListModels.mockResolvedValue([
+ { id: 'eu.anthropic.claude-haiku-4-5-20251001-v1:0', name: 'Haiku', type: AIProviderModelType.TEXT },
+ ])
+
+ await expect(agentHelpers.resolveFastModelId({ platformId, providerConfig: bedrockKey, scope, fallbackModelId: 'eu.anthropic.claude-sonnet-4-6', log })).resolves.toBe('eu.anthropic.claude-sonnet-4-6')
+ expect(mockListModels).not.toHaveBeenCalled()
+ })
+
+ it('refuses a borrowed model the admin has since scoped off the key', async () => {
+ const scopedKey = { ...bedrockKey, modelScope: 'selected' as const, modelIds: ['eu.anthropic.claude-haiku-4-5-20251001-v1:0'] }
+ mockListModels.mockResolvedValue([
+ { id: 'eu.anthropic.claude-haiku-4-5-20251001-v1:0', name: 'Haiku', type: AIProviderModelType.TEXT },
+ ])
+
+ await expect(agentHelpers.resolveFastModelId({ platformId, providerConfig: scopedKey, scope, fallbackModelId: 'eu.anthropic.claude-sonnet-4-6', log }))
+ .resolves.toBe('eu.anthropic.claude-haiku-4-5-20251001-v1:0')
+ })
+
+ it('never answers with a model the key does not serve', async () => {
+ mockListModels.mockResolvedValue([{ id: 'amazon.titan-image-generator-v1', name: 'Titan Image', type: AIProviderModelType.IMAGE }])
+
+ await expect(resolve({ selectedModel: 'smart' })).rejects.toMatchObject({ error: { code: 'ENTITY_NOT_FOUND' } })
+ })
})
diff --git a/packages/server/api/test/unit/app/ee/agent/agent-model-resolution.test.ts b/packages/server/api/test/unit/app/ee/agent/agent-model-resolution.test.ts
index cad4c7fb51e..adc4cd1d1df 100644
--- a/packages/server/api/test/unit/app/ee/agent/agent-model-resolution.test.ts
+++ b/packages/server/api/test/unit/app/ee/agent/agent-model-resolution.test.ts
@@ -106,12 +106,6 @@ describe('resolveModelIdForProvider', () => {
expect(error).toBeInstanceOf(ActivepiecesError)
expect(String(error)).not.toContain('claude')
})
-
- it('resolves the fast round to a model the provider offers', () => {
- expect(agentModelResolution.resolveFastModelId({ provider: AIProviderName.ANTHROPIC })).toBe('claude-haiku-4-5')
- expect(agentModelResolution.resolveFastModelId({ provider: AIProviderName.OPENAI })).toBe('gpt-5.5')
- expect(agentModelResolution.resolveFastModelId({ provider: AIProviderName.ACTIVEPIECES })).toBe('anthropic/claude-haiku-4.5')
- })
})
describe('resolveModelIdForAnalytics', () => {
diff --git a/packages/server/worker/test/lib/execute/jobs/ee/agent/run-agent-turn-guards.test.ts b/packages/server/worker/test/lib/execute/jobs/ee/agent/run-agent-turn-guards.test.ts
index 3a945f1625e..287dff8c87e 100644
--- a/packages/server/worker/test/lib/execute/jobs/ee/agent/run-agent-turn-guards.test.ts
+++ b/packages/server/worker/test/lib/execute/jobs/ee/agent/run-agent-turn-guards.test.ts
@@ -16,6 +16,12 @@ describe('isTransientFailureText', () => {
}
})
+ it('does not mask an actionable provider error just because it says to try again', () => {
+ const bedrockSetupRequired = 'Model use case details have not been submitted for this account. Fill out the Anthropic use case details form before using the model. If you have already filled out the form, try again in 15 minutes.'
+
+ expect(isTransientFailureText(bedrockSetupRequired)).toBe(false)
+ })
+
it('does not flag permanent errors (4xx validation/auth)', () => {
for (const t of ['❌ Cannot run action: missing required field channel', '❌ 401 unauthorized', '❌ 400 bad request: invalid email']) {
expect(isTransientFailureText(t), t).toBe(false)
diff --git a/packages/web/src/app/routes/agents/id/agent-chat-view.tsx b/packages/web/src/app/routes/agents/id/agent-chat-view.tsx
index 8a1a4d51098..97b512e83d8 100644
--- a/packages/web/src/app/routes/agents/id/agent-chat-view.tsx
+++ b/packages/web/src/app/routes/agents/id/agent-chat-view.tsx
@@ -12,7 +12,7 @@ type AgentChatViewProps = {
agent: Agent;
conversationsOpen: boolean;
openedConversationId: string | undefined;
- freshConversations: number;
+ chatSessionKey: string;
footerNote: string;
onSelectConversation: (conversationId: string) => void;
onNewConversation: () => void;
@@ -25,7 +25,7 @@ export const AgentChatView = ({
agent,
conversationsOpen,
openedConversationId,
- freshConversations,
+ chatSessionKey,
footerNote,
onSelectConversation,
onNewConversation,
@@ -62,7 +62,7 @@ export const AgentChatView = ({
</aside>
<div className="flex min-h-0 min-w-0 grow flex-col">
<AIChatBox
- key={openedConversationId ?? `new-${freshConversations}`}
+ key={chatSessionKey}
incognito={false}
agentId={agent.id}
conversationId={openedConversationId ?? null}
diff --git a/packages/web/src/app/routes/agents/id/index.tsx b/packages/web/src/app/routes/agents/id/index.tsx
index df9616812ed..28bf11bbe4e 100644
--- a/packages/web/src/app/routes/agents/id/index.tsx
+++ b/packages/web/src/app/routes/agents/id/index.tsx
@@ -95,7 +95,9 @@ const AgentEditorContent = () => {
searchParams.get(CONVERSATION_QUERY_PARAM) ?? undefined;
const [openedConversationId, setOpenedConversationId] =
useState(conversationId);
- const [freshConversations, setFreshConversations] = useState(0);
+ const [chatSessionKey, setChatSessionKey] = useState(
+ () => conversationId ?? 'new',
+ );
const writeConversationParam = (nextConversationId: string | null) => {
const next = new URLSearchParams(searchParams);
@@ -108,6 +110,7 @@ const AgentEditorContent = () => {
};
const openConversation = (nextConversationId: string) => {
setOpenedConversationId(nextConversationId);
+ setChatSessionKey(nextConversationId);
writeConversationParam(nextConversationId);
};
const runsOpen = pathname.endsWith(`/${RUNS_TAB}`);
@@ -128,7 +131,7 @@ const AgentEditorContent = () => {
};
const startNewConversation = () => {
setOpenedConversationId(undefined);
- setFreshConversations((count) => count + 1);
+ setChatSessionKey(`new-${Date.now()}`);
writeConversationParam(null);
};
const {
@@ -250,7 +253,7 @@ const AgentEditorContent = () => {
agent={agent}
conversationsOpen={conversationsOpen}
openedConversationId={openedConversationId ?? conversationId}
- freshConversations={freshConversations}
+ chatSessionKey={chatSessionKey}
footerNote={buildCapabilityNote(agent)}
onSelectConversation={openConversation}
onNewConversation={startNewConversation}