Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { useActiveCanonicalSubBlockValue } from '@/app/workspace/[workspaceId]/w
import { useResourceFolders } from '@/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/hooks/use-resource-folders'
import { useSubBlockValue } from '@/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/hooks/use-sub-block-value'
import { useActiveSearchTarget } from '@/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/providers/active-search-target-provider'
import { findConfiguredModelProvider } from '@/blocks/utils'
import { invalidateWorkspaceFileReads } from '@/hooks/queries/utils/workspace-file-cache'
import {
workspaceFileListParams,
Expand All @@ -42,7 +43,6 @@ import {
} from '@/hooks/queries/workspace-files'
import { useSearchFilterValue } from '@/hooks/use-search-filter-value'
import { getProviderAttachmentMaxBytes } from '@/providers/attachments'
import { getProviderFromModel } from '@/providers/utils'
import { useWorkflowRegistry } from '@/stores/workflows/registry/store'
import { useWorkflowStore } from '@/stores/workflows/workflow/store'

Expand Down Expand Up @@ -322,11 +322,9 @@ export function FileUpload({
const maxSizeInBytes = useMemo(() => {
const fallback = maxSize * 1024 * 1024
if (typeof modelValue !== 'string' || !modelValue) return fallback
try {
return Math.max(fallback, getProviderAttachmentMaxBytes(getProviderFromModel(modelValue)))
} catch {
return fallback
}
// sim-auto has no provider until routed, and may route images to an inline-only model.
const provider = findConfiguredModelProvider(modelValue)
return provider ? Math.max(fallback, getProviderAttachmentMaxBytes(provider)) : fallback
}, [modelValue, maxSize])
const maxSizeLabel = `${Math.round(maxSizeInBytes / (1024 * 1024))}MB`

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { StoredTool } from '@/app/workspace/[workspaceId]/w/[workflowId]/co
import {
isAgentToolBlock,
isCustomToolAlreadySelected,
supportsToolUsageControlForModel,
} from '@/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/components/tool-input/utils'

describe('isAgentToolBlock', () => {
Expand Down Expand Up @@ -47,3 +48,15 @@ describe('already-selected checks', () => {
).toBe(false)
})
})

describe('supportsToolUsageControlForModel', () => {
it('offers the control for Auto, which falls back to a provider that supports it', () => {
expect(supportsToolUsageControlForModel('agent', 'sim-auto')).toBe(true)
})

it('offers it for a supporting provider and never without a model', () => {
expect(supportsToolUsageControlForModel('agent', 'claude-sonnet-5-5')).toBe(true)
expect(supportsToolUsageControlForModel('agent', '')).toBe(false)
expect(supportsToolUsageControlForModel('mothership', '')).toBe(true)
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ import {
isCustomToolAlreadySelected,
isMcpToolAlreadySelected,
isWorkflowAlreadySelected,
supportsToolUsageControlForModel,
} from '@/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/components/tool-input/utils'
import { getActiveWorkflowSearchHighlight } from '@/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/components/workflow-search-highlight'
import { useSubBlockValue } from '@/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/hooks/use-sub-block-value'
Expand Down Expand Up @@ -105,8 +106,7 @@ import { useCollaborativeWorkflow } from '@/hooks/use-collaborative-workflow'
import { useOperationAccess } from '@/hooks/use-operation-access'
import { usePermissionConfig } from '@/hooks/use-permission-config'
import { useSettingsNavigation } from '@/hooks/use-settings-navigation'
import { supportsForcedToolUse, supportsToolUsageControl } from '@/providers/models'
import { getProviderFromModel } from '@/providers/utils'
import { supportsForcedToolUse } from '@/providers/models'
import type { ActiveSearchTarget } from '@/stores/panel/editor/store'
import { useSubBlockStore } from '@/stores/workflows/subblock/store'
import { useWorkflowStore } from '@/stores/workflows/workflow/store'
Expand Down Expand Up @@ -603,9 +603,7 @@ export const ToolInput = memo(function ToolInput({

const modelValue = useSubBlockStore((state) => state.getValue(blockId, 'model'))
const model = typeof modelValue === 'string' ? modelValue : ''
const provider = model ? getProviderFromModel(model) : ''
const supportsToolControl =
blockType === 'mothership' || (provider ? supportsToolUsageControl(provider) : false)
const supportsToolControl = supportsToolUsageControlForModel(blockType, model)
const supportsForce = blockType === 'mothership' || supportsForcedToolUse(model)

const {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { stripVersionSuffix } from '@sim/utils/string'
import type { StoredTool } from '@/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/components/tool-input/types'
import type { BlockConfig } from '@/blocks/types'
import { resolveModelProviderId } from '@/blocks/utils'
import { supportsToolUsageControl } from '@/providers/models'

/**
* Core blocks the agent tool picker offers even though they are not
Expand Down Expand Up @@ -71,3 +73,13 @@ export function isWorkflowAlreadySelected(
(tool) => tool.type === 'workflow_input' && tool.params?.workflowId === workflowId
)
}

/**
* Whether the tool picker offers the per-tool usage control (auto, force, none) for the
* block's model. Sim Chat always does; any other block asks its model's provider.
*/
export function supportsToolUsageControlForModel(blockType: string, model: string): boolean {
if (blockType === 'mothership') return true
if (!model) return false
return supportsToolUsageControl(resolveModelProviderId(model))
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { isEqual } from 'es-toolkit'
import { useShallow } from 'zustand/react/shallow'
import { useStoreWithEqualityFn } from 'zustand/traditional'
import { isMcpRuntimeReference } from '@/lib/mcp/operation-policy'
import { findConfiguredModelProvider } from '@/blocks/utils'
import { useCollaborativeWorkflow } from '@/hooks/use-collaborative-workflow'
import { getProviderFromModel } from '@/providers/utils'
import { useWorkflowDiffStore } from '@/stores/workflow-diff/store'
import { useWorkflowRegistry } from '@/stores/workflows/registry/store'
import { useSubBlockStore } from '@/stores/workflows/subblock/store'
Expand Down Expand Up @@ -193,8 +193,8 @@ export function useSubBlockValue<T = any>(
const currentApiKeyValue = useSubBlockStore.getState().getValue(blockId, 'apiKey')
if (currentApiKeyValue && currentApiKeyValue !== '') {
const oldModelValue = storeValue as string
const oldProvider = oldModelValue ? getProviderFromModel(oldModelValue) : null
const newProvider = getProviderFromModel(newValue)
const oldProvider = oldModelValue ? findConfiguredModelProvider(oldModelValue) : null
const newProvider = findConfiguredModelProvider(newValue)
if (oldProvider !== newProvider) {
collaborativeSetSubblockValue(blockId, 'apiKey', '')
}
Expand Down
12 changes: 12 additions & 0 deletions apps/sim/blocks/blocks/agent.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,4 +112,16 @@ describe('AgentBlock', () => {
})
})
})

describe('tools.config.tool function', () => {
const toolFunction = AgentBlock.tools.config?.tool

it('records the provider sim-auto falls back to, since it has none of its own', () => {
expect(toolFunction?.({ model: 'sim-auto' })).toBe('anthropic')
})

it('falls back to the same provider when no model is set', () => {
expect(toolFunction?.({})).toBe('anthropic')
})
})
})
14 changes: 4 additions & 10 deletions apps/sim/blocks/blocks/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ import {
getAgentModelOptions,
getModelCapabilityCondition,
getProviderCredentialSubBlocks,
getSerializedModelProviderId,
normalizeFileInput,
RESPONSE_FORMAT_WAND_CONFIG,
resolveModelProviderId,
} from '@/blocks/utils'
import { DEFAULT_BLOCK_MODEL } from '@/providers/default-model'
import {
getBaseModelProviders,
getEvaluationModels,
Expand All @@ -24,15 +25,11 @@ import {
getReasoningEffortValuesForModel,
getThinkingLevelsForModel,
getVerbosityValuesForModel,
isAutoModel,
supportsTemperature,
} from '@/providers/models'

const logger = createLogger('AgentBlock')

/** Model the agent block falls back to when `model` is unset or the auto pseudo-model. */
const AGENT_FALLBACK_MODEL = 'claude-sonnet-5-5'

const MODELS_WITH_REASONING_EFFORT = getModelsWithReasoningEffort()
const MODELS_WITH_VERBOSITY = getModelsWithVerbosity()
const MODELS_WITH_THINKING = getModelsWithThinking()
Expand Down Expand Up @@ -130,7 +127,7 @@ Return ONLY the JSON array.`,
type: 'combobox',
placeholder: 'Type or select a model...',
required: true,
defaultValue: 'claude-sonnet-5-5',
defaultValue: DEFAULT_BLOCK_MODEL,
options: getAgentModelOptions,
commandSearchable: true,
},
Expand Down Expand Up @@ -428,10 +425,7 @@ Return ONLY the JSON array.`,
],
config: {
tool: (params: Record<string, any>) => {
const model = params.model || AGENT_FALLBACK_MODEL
// sim-auto has no provider of its own until the pool resolves it at execution time.
const lookupModel = isAutoModel(model) ? AGENT_FALLBACK_MODEL : model
return getSerializedModelProviderId(lookupModel, AGENT_FALLBACK_MODEL)
return resolveModelProviderId(params.model)
},
params: (params: Record<string, any>) => {
const normalizedFiles = normalizeFileInput(params.files)
Expand Down
11 changes: 6 additions & 5 deletions apps/sim/blocks/blocks/evaluator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ import { getModelFallbackSubBlock, MODEL_FALLBACK_INPUTS } from '@/blocks/model-
import type { BlockConfig, ParamType } from '@/blocks/types'
import {
BEDROCK_SAVED_CREDENTIAL_INPUTS,
getModelOptions,
getModelOptionsWithAuto,
getProviderCredentialSubBlocks,
getSerializedModelProviderId,
PROVIDER_CREDENTIAL_INPUTS,
resolveModelProviderId,
} from '@/blocks/utils'
import { DEFAULT_BLOCK_MODEL } from '@/providers/default-model'

const logger = createLogger('EvaluatorBlock')

Expand Down Expand Up @@ -168,8 +169,8 @@ export const EvaluatorBlock: BlockConfig = {
type: 'combobox',
placeholder: 'Type or select a model...',
required: true,
defaultValue: 'claude-sonnet-5-5',
options: getModelOptions,
defaultValue: DEFAULT_BLOCK_MODEL,
options: getModelOptionsWithAuto,
},
...getProviderCredentialSubBlocks({ bedrockSavedCredential: true }),
getModelFallbackSubBlock(),
Expand Down Expand Up @@ -236,7 +237,7 @@ export const EvaluatorBlock: BlockConfig = {
'deepseek_reasoner',
],
config: {
tool: (params: Record<string, any>) => getSerializedModelProviderId(params.model),
tool: (params: Record<string, any>) => resolveModelProviderId(params.model),
},
},
inputs: {
Expand Down
17 changes: 9 additions & 8 deletions apps/sim/blocks/blocks/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ import { getModelFallbackSubBlock, MODEL_FALLBACK_INPUTS } from '@/blocks/model-
import { AuthMode, type BlockConfig } from '@/blocks/types'
import {
BEDROCK_SAVED_CREDENTIAL_INPUTS,
getModelOptions,
getModelOptionsWithAuto,
getProviderCredentialSubBlocks,
getSerializedModelProviderId,
PROVIDER_CREDENTIAL_INPUTS,
resolveModelProviderId,
} from '@/blocks/utils'
import { DEFAULT_BLOCK_MODEL } from '@/providers/default-model'

interface TargetBlock {
id: string
Expand Down Expand Up @@ -161,8 +162,8 @@ export const RouterBlock: BlockConfig = {
type: 'combobox',
placeholder: 'Type or select a model...',
required: true,
defaultValue: 'claude-sonnet-5-5',
options: getModelOptions,
defaultValue: DEFAULT_BLOCK_MODEL,
options: getModelOptionsWithAuto,
},
...getProviderCredentialSubBlocks({ bedrockSavedCredential: true }),
getModelFallbackSubBlock(),
Expand Down Expand Up @@ -194,7 +195,7 @@ export const RouterBlock: BlockConfig = {
'deepseek_reasoner',
],
config: {
tool: (params: Record<string, any>) => getSerializedModelProviderId(params.model),
tool: (params: Record<string, any>) => resolveModelProviderId(params.model),
},
},
inputs: {
Expand Down Expand Up @@ -253,8 +254,8 @@ export const RouterV2Block: BlockConfig = {
type: 'combobox',
placeholder: 'Type or select a model...',
required: true,
defaultValue: 'claude-sonnet-5-5',
options: getModelOptions,
defaultValue: DEFAULT_BLOCK_MODEL,
options: getModelOptionsWithAuto,
},
...getProviderCredentialSubBlocks({ bedrockSavedCredential: true }),
getModelFallbackSubBlock(),
Expand All @@ -269,7 +270,7 @@ export const RouterV2Block: BlockConfig = {
'deepseek_reasoner',
],
config: {
tool: (params: Record<string, any>) => getSerializedModelProviderId(params.model),
tool: (params: Record<string, any>) => resolveModelProviderId(params.model),
},
},
inputs: {
Expand Down
Loading
Loading