Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

🔨 chore: support per-task model/provider override via task.config (#13466)

Arvin Xu88246e5719e7
diff --git a/packages/types/src/agentExecution/index.ts b/packages/types/src/agentExecution/index.ts
new file mode 100644
index 00000000000..d5361fe818a
--- /dev/null
+++ b/packages/types/src/agentExecution/index.ts
@@ -0,0 +1,252 @@
+import type { TaskDetail, UIChatMessage } from '../message';
+import type { ChatTopic } from '../topic';
+
+/**
+ * Application context for message storage
+ */
+export interface ExecAgentAppContext {
+ /** Group ID for group chat */
+ groupId?: string | null;
+ /** Scope identifier */
+ scope?: string | null;
+ /** Session ID */
+ sessionId?: string;
+ /** Thread ID for threaded conversations */
+ threadId?: string | null;
+ /** Topic ID */
+ topicId?: string | null;
+}
+
+/**
+ * Parameters for execAgent - execute a single Agent
+ * Either agentId or slug must be provided
+ */
+export interface ExecAgentParams {
+ /** The agent ID to run (either agentId or slug is required) */
+ agentId?: string;
+ /** Application context for message storage */
+ appContext?: ExecAgentAppContext;
+ /** Whether to auto-start execution after creating operation (default: true) */
+ autoStart?: boolean;
+ /** Optional existing message IDs to include in context */
+ existingMessageIds?: string[];
+ /** Additional system instructions appended after the agent's own system role */
+ instructions?: string;
+ /** Override the agent's default model */
+ model?: string;
+ /** The user input/prompt */
+ prompt: string;
+ /** Override the agent's default provider */
+ provider?: string;
+ /** The agent slug to run (either agentId or slug is required) */
+ slug?: string;
+}
+
+/**
+ * Response from execAgent
+ */
+export interface ExecAgentResult {
+ /** The resolved agent ID */
+ agentId: string;
+ /** The assistant message ID created for this operation */
+ assistantMessageId: string;
+ /** Whether the operation was auto-started */
+ autoStarted: boolean;
+ /** Timestamp when operation was created */
+ createdAt: string;
+ /** Error message if operation failed to start */
+ error?: string;
+ /** Status message */
+ message: string;
+ /** Queue message ID if auto-started */
+ messageId?: string;
+ /** Operation ID for SSE connection */
+ operationId: string;
+ /** Operation status */
+ status: string;
+ /** Whether the operation was created successfully */
+ success: boolean;
+ /** ISO timestamp */
+ timestamp: string;
+ /** The topic ID (created or reused) */
+ topicId: string;
+ /** The user message ID created for this operation */
+ userMessageId: string;
+}
+
+// ============ Group Agent Execution Types ============
+
+/**
+ * Options for creating a new topic in group chat
+ */
+export interface ExecGroupAgentNewTopicOptions {
+ /** Topic title */
+ title?: string;
+ /** Message IDs to include in the topic */
+ topicMessageIds?: string[];
+}
+
+/**
+ * Parameters for execGroupAgent - execute Supervisor Agent in Group chat
+ */
+export interface ExecGroupAgentParams {
+ /** The Supervisor agent ID */
+ agentId: string;
+ /** File IDs attached to the message */
+ files?: string[];
+ /** The Group ID */
+ groupId: string;
+ /** User message content */
+ message: string;
+ /** Optional: Create a new topic */
+ newTopic?: ExecGroupAgentNewTopicOptions;
+ /** Existing topic ID */
+ topicId?: string | null;
+}
+
+/**
+ * Result from execGroupAgent (internal, without messages/topics)
+ */
+export interface ExecGroupAgentResult {
+ /** The assistant message ID created for this operation */
+ assistantMessageId: string;
+ /** Error message if operation failed to start */
+ error?: string;
+ /** Whether a new topic was created */
+ isCreateNewTopic: boolean;
+ /** Operation ID for tracking execution status */
+ operationId: string;
+ /** Whether the operation was created successfully */
+ success?: boolean;
+ /** The topic ID */
+ topicId: string;
+ /** The user message ID created for this operation */
+ userMessageId: string;
+}
+
+/**
+ * Response from execGroupAgent (with messages/topics for UI sync)
+ */
+export interface ExecGroupAgentResponse {
+ /** The assistant message ID created for this operation */
+ assistantMessageId: string;
+ /** Error message if operation failed to start */
+ error?: string;
+ /** Whether a new topic was created */
+ isCreateNewTopic: boolean;
+ /** Latest messages in the conversation */
+ messages: UIChatMessage[];
+ /** Operation ID for SSE connection */
+ operationId: string;
+ /** Whether the operation was created successfully */
+ success?: boolean;
+ /** The topic ID */
+ topicId: string;
+ /** Topics list (if new topic was created) */
+ topics?: {
+ items: ChatTopic[];
+ total: number;
+ };
+ /** The user message ID created for this operation */
+ userMessageId: string;
+}
+
+// ============ SubAgent Task Execution Types ============
+
+/**
+ * Parameters for execSubAgentTask - execute SubAgent task
+ * Supports both Group mode and Single Agent mode
+ *
+ * - Group mode: pass groupId, Thread will be associated with the Group
+ * - Single Agent mode: omit groupId, Thread will only be associated with the Agent
+ */
+export interface ExecSubAgentTaskParams {
+ /** The SubAgent ID to execute the task */
+ agentId: string;
+ /** The Group ID (optional, only for Group mode) */
+ groupId?: string;
+ /** Task instruction/prompt for the SubAgent */
+ instruction: string;
+ /** The parent message ID (Supervisor's tool call message or task message) */
+ parentMessageId: string;
+ /** Timeout in milliseconds (optional) */
+ timeout?: number;
+ /** Task title (shown in UI, used as thread title) */
+ title?: string;
+ /** The Topic ID */
+ topicId: string;
+}
+
+/**
+ * Result from execSubAgentTask
+ */
+export interface ExecSubAgentTaskResult {
+ /** The assistant message ID created for this task */
+ assistantMessageId: string;
+ /** Error message if task failed to start */
+ error?: string;
+ /** Operation ID for tracking execution status */
+ operationId: string;
+ /** Whether the task was created successfully */
+ success: boolean;
+ /** The Thread ID where the task is executed */
+ threadId: string;
+}
+
+/**
+ * @deprecated Use ExecSubAgentTaskParams instead
+ */
+export type ExecGroupSubAgentTaskParams = ExecSubAgentTaskParams;
+
+/**
+ * @deprecated Use ExecSubAgentTaskResult instead
+ */
+export type ExecGroupSubAgentTaskResult = ExecSubAgentTaskResult;
+
+/**
+ * Current activity for real-time progress display
+ * Only returned when task is processing
+ */
+export interface TaskCurrentActivity {
+ /** API name, e.g. "search" */
+ apiName?: string;
+ /** Content preview (truncated) */
+ contentPreview?: string;
+ /** Plugin identifier, e.g. "lobe-web-browsing" */
+ identifier?: string;
+ /** Activity type */
+ type: 'tool_calling' | 'tool_result' | 'generating';
+}
+
+/**
+ * Task status query result
+ */
+export interface TaskStatusResult {
+ /** Task completion time (ISO string) */
+ completedAt?: string;
+ /** Cost information */
+ cost?: { total: number };
+ /** Current activity for real-time progress display (only when processing) */
+ currentActivity?: TaskCurrentActivity;
+ /** Error message if task failed */
+ error?: string;
+ /**
+ * Parsed UI messages from conversation-flow
+ * Used for displaying intermediate steps in server task
+ */
+ messages?: UIChatMessage[];
+ /** Task result content (last assistant message) */
+ result?: string;
+ /** Current task status */
+ status: 'processing' | 'completed' | 'failed' | 'cancel';
+ /** Number of steps executed */
+ stepCount?: number;
+ /** Task detail from Thread table */
+ taskDetail?: TaskDetail;
+ /** Model usage information */
+ usage?: {
+ completion_tokens?: number;
+ prompt_tokens?: number;
+ total_tokens?: number;
+ };
+}
diff --git a/packages/types/src/agentGroup/index.ts b/packages/types/src/agentGroup/index.ts
index 331f20f8604..5854866cac4 100644
--- a/packages/types/src/agentGroup/index.ts
+++ b/packages/types/src/agentGroup/index.ts
@@ -1,8 +1,6 @@
import { z } from 'zod';
import type { AgentItem } from '../agent';
-import type { TaskDetail, UIChatMessage } from '../message';
-import type { ChatTopic } from '../topic';
export interface LobeChatGroupMetaConfig {
avatar?: string;
@@ -131,250 +129,19 @@ export interface AgentGroupDetail extends ChatGroupItem {
supervisorAgentId?: string;
}
-// ============ Agent Execution Types ============
-
-/**
- * Application context for message storage
- */
-export interface ExecAgentAppContext {
- /** Group ID for group chat */
- groupId?: string | null;
- /** Scope identifier */
- scope?: string | null;
- /** Session ID */
- sessionId?: string;
- /** Thread ID for threaded conversations */
- threadId?: string | null;
- /** Topic ID */
- topicId?: string | null;
-}
-
-/**
- * Parameters for execAgent - execute a single Agent
- * Either agentId or slug must be provided
- */
-export interface ExecAgentParams {
- /** The agent ID to run (either agentId or slug is required) */
- agentId?: string;
- /** Application context for message storage */
- appContext?: ExecAgentAppContext;
- /** Whether to auto-start execution after creating operation (default: true) */
- autoStart?: boolean;
- /** Optional existing message IDs to include in context */
- existingMessageIds?: string[];
- /** Additional system instructions appended after the agent's own system role */
- instructions?: string;
- /** The user input/prompt */
- prompt: string;
- /** The agent slug to run (either agentId or slug is required) */
- slug?: string;
-}
-
-/**
- * Response from execAgent
- */
-export interface ExecAgentResult {
- /** The resolved agent ID */
- agentId: string;
- /** The assistant message ID created for this operation */
- assistantMessageId: string;
- /** Whether the operation was auto-started */
- autoStarted: boolean;
- /** Timestamp when operation was created */
- createdAt: string;
- /** Error message if operation failed to start */
- error?: string;
- /** Status message */
- message: string;
- /** Queue message ID if auto-started */
- messageId?: string;
- /** Operation ID for SSE connection */
- operationId: string;
- /** Operation status */
- status: string;
- /** Whether the operation was created successfully */
- success: boolean;
- /** ISO timestamp */
- timestamp: string;
- /** The topic ID (created or reused) */
- topicId: string;
- /** The user message ID created for this operation */
- userMessageId: string;
-}
-
-// ============ Group Agent Execution Types ============
-
-/**
- * Options for creating a new topic in group chat
- */
-export interface ExecGroupAgentNewTopicOptions {
- /** Topic title */
- title?: string;
- /** Message IDs to include in the topic */
- topicMessageIds?: string[];
-}
-
-/**
- * Parameters for execGroupAgent - execute Supervisor Agent in Group chat
- */
-export interface ExecGroupAgentParams {
- /** The Supervisor agent ID */
- agentId: string;
- /** File IDs attached to the message */
- files?: string[];
- /** The Group ID */
- groupId: string;
- /** User message content */
- message: string;
- /** Optional: Create a new topic */
- newTopic?: ExecGroupAgentNewTopicOptions;
- /** Existing topic ID */
- topicId?: string | null;
-}
-
-/**
- * Result from execGroupAgent (internal, without messages/topics)
- */
-export interface ExecGroupAgentResult {
- /** The assistant message ID created for this operation */
- assistantMessageId: string;
- /** Error message if operation failed to start */
- error?: string;
- /** Whether a new topic was created */
- isCreateNewTopic: boolean;
- /** Operation ID for SSE connection */
- operationId: string;
- /** Whether the operation was created successfully */
- success?: boolean;
- /** The topic ID */
- topicId: string;
- /** The user message ID created for this operation */
- userMessageId: string;
-}
-
-/**
- * Response from execGroupAgent (with messages/topics for UI sync)
- */
-export interface ExecGroupAgentResponse {
- /** The assistant message ID created for this operation */
- assistantMessageId: string;
- /** Error message if operation failed to start */
- error?: string;
- /** Whether a new topic was created */
- isCreateNewTopic: boolean;
- /** Latest messages in the conversation */
- messages: UIChatMessage[];
- /** Operation ID for SSE connection */
- operationId: string;
- /** Whether the operation was created successfully */
- success?: boolean;
- /** The topic ID */
- topicId: string;
- /** Topics list (if new topic was created) */
- topics?: {
- items: ChatTopic[];
- total: number;
- };
- /** The user message ID created for this operation */
- userMessageId: string;
-}
-
-// ============ SubAgent Task Execution Types ============
-
-/**
- * Parameters for execSubAgentTask - execute SubAgent task
- * Supports both Group mode and Single Agent mode
- *
- * - Group mode: pass groupId, Thread will be associated with the Group
- * - Single Agent mode: omit groupId, Thread will only be associated with the Agent
- */
-export interface ExecSubAgentTaskParams {
- /** The SubAgent ID to execute the task */
- agentId: string;
- /** The Group ID (optional, only for Group mode) */
- groupId?: string;
- /** Task instruction/prompt for the SubAgent */
- instruction: string;
- /** The parent message ID (Supervisor's tool call message or task message) */
- parentMessageId: string;
- /** Timeout in milliseconds (optional) */
- timeout?: number;
- /** Task title (shown in UI, used as thread title) */
- title?: string;
- /** The Topic ID */
- topicId: string;
-}
-
-/**
- * Result from execSubAgentTask
- */
-export interface ExecSubAgentTaskResult {
- /** The assistant message ID created for this task */
- assistantMessageId: string;
- /** Error message if task failed to start */
- error?: string;
- /** Operation ID for tracking execution status */
- operationId: string;
- /** Whether the task was created successfully */
- success: boolean;
- /** The Thread ID where the task is executed */
- threadId: string;
-}
-
-/**
- * @deprecated Use ExecSubAgentTaskParams instead
- */
-export type ExecGroupSubAgentTaskParams = ExecSubAgentTaskParams;
-
-/**
- * @deprecated Use ExecSubAgentTaskResult instead
- */
-export type ExecGroupSubAgentTaskResult = ExecSubAgentTaskResult;
-
-/**
- * Current activity for real-time progress display
- * Only returned when task is processing
- */
-export interface TaskCurrentActivity {
- /** API name, e.g. "search" */
- apiName?: string;
- /** Content preview (truncated) */
- contentPreview?: string;
- /** Plugin identifier, e.g. "lobe-web-browsing" */
- identifier?: string;
- /** Activity type */
- type: 'tool_calling' | 'tool_result' | 'generating';
-}
-
-/**
- * Task status query result
- */
-export interface TaskStatusResult {
- /** Task completion time (ISO string) */
- completedAt?: string;
- /** Cost information */
- cost?: { total: number };
- /** Current activity for real-time progress display (only when processing) */
- currentActivity?: TaskCurrentActivity;
- /** Error message if task failed */
- error?: string;
- /**
- * Parsed UI messages from conversation-flow
- * Used for displaying intermediate steps in server task
- */
- messages?: UIChatMessage[];
- /** Task result content (last assistant message) */
- result?: string;
- /** Current task status */
- status: 'processing' | 'completed' | 'failed' | 'cancel';
- /** Number of steps executed */
- stepCount?: number;
- /** Task detail from Thread table */
- taskDetail?: TaskDetail;
- /** Model usage information */
- usage?: {
- completion_tokens?: number;
- prompt_tokens?: number;
- total_tokens?: number;
- };
-}
+// Re-export agent execution types for backwards compatibility
+export type {
+ ExecAgentAppContext,
+ ExecAgentParams,
+ ExecAgentResult,
+ ExecGroupAgentNewTopicOptions,
+ ExecGroupAgentParams,
+ ExecGroupAgentResponse,
+ ExecGroupAgentResult,
+ ExecGroupSubAgentTaskParams,
+ ExecGroupSubAgentTaskResult,
+ ExecSubAgentTaskParams,
+ ExecSubAgentTaskResult,
+ TaskCurrentActivity,
+ TaskStatusResult,
+} from '../agentExecution';
diff --git a/packages/types/src/index.ts b/packages/types/src/index.ts
index 90a27b85789..0aebc78e101 100644
--- a/packages/types/src/index.ts
+++ b/packages/types/src/index.ts
@@ -1,5 +1,6 @@
export * from './agent';
export * from './agentCronJob';
+export * from './agentExecution';
export * from './agentGroup';
export * from './aiChat';
export * from './aiProvider';
diff --git a/src/server/routers/lambda/task.ts b/src/server/routers/lambda/task.ts
index fad14ae0e74..5b237a3e6cf 100644
--- a/src/server/routers/lambda/task.ts
+++ b/src/server/routers/lambda/task.ts
@@ -786,9 +786,14 @@ export const taskRouter = router({
pluginIds.push(BriefIdentifier);
}
+ // Read per-task model/provider overrides from task.config
+ const taskConfig = (task.config ?? {}) as Record<string, unknown>;
+
const result = await aiAgentService.execAgent({
...(isSlug ? { slug: agentRef } : { agentId: agentRef }),
additionalPluginIds: pluginIds,
+ ...(typeof taskConfig.model === 'string' && { model: taskConfig.model }),
+ ...(typeof taskConfig.provider === 'string' && { provider: taskConfig.provider }),
hooks: [
{
handler: async (event) => {
diff --git a/src/server/services/aiAgent/__tests__/execAgent.modelOverride.test.ts b/src/server/services/aiAgent/__tests__/execAgent.modelOverride.test.ts
new file mode 100644
index 00000000000..a4ee07fac72
--- /dev/null
+++ b/src/server/services/aiAgent/__tests__/execAgent.modelOverride.test.ts
@@ -0,0 +1,202 @@
+import type * as ModelBankModule from 'model-bank';
+import { beforeEach, describe, expect, it, vi } from 'vitest';
+
+import { AiAgentService } from '../index';
+
+const { mockCreateOperation, mockGetAgentConfig, mockMessageCreate } = vi.hoisted(() => ({
+ mockCreateOperation: vi.fn(),
+ mockGetAgentConfig: vi.fn(),
+ mockMessageCreate: vi.fn(),
+}));
+
+vi.mock('@/libs/trusted-client', () => ({
+ generateTrustedClientToken: vi.fn().mockReturnValue(undefined),
+ getTrustedClientTokenForSession: vi.fn().mockResolvedValue(undefined),
+ isTrustedClientEnabled: vi.fn().mockReturnValue(false),
+}));
+
+vi.mock('@/database/models/message', () => ({
+ MessageModel: vi.fn().mockImplementation(() => ({
+ create: mockMessageCreate,
+ query: vi.fn().mockResolvedValue([]),
+ update: vi.fn().mockResolvedValue({}),
+ })),
+}));
+
+vi.mock('@/database/models/agent', () => ({
+ AgentModel: vi.fn().mockImplementation(() => ({
+ getAgentConfig: vi.fn(),
+ })),
+}));
+
+vi.mock('@/server/services/agent', () => ({
+ AgentService: vi.fn().mockImplementation(() => ({
+ getAgentConfig: mockGetAgentConfig,
+ })),
+}));
+
+vi.mock('@/database/models/plugin', () => ({
+ PluginModel: vi.fn().mockImplementation(() => ({
+ query: vi.fn().mockResolvedValue([]),
+ })),
+}));
+
+vi.mock('@/database/models/topic', () => ({
+ TopicModel: vi.fn().mockImplementation(() => ({
+ create: vi.fn().mockResolvedValue({ id: 'topic-1' }),
+ })),
+}));
+
+vi.mock('@/database/models/thread', () => ({
+ ThreadModel: vi.fn().mockImplementation(() => ({
+ create: vi.fn(),
+ findById: vi.fn(),
+ update: vi.fn(),
+ })),
+}));
+
+vi.mock('@/server/services/agentRuntime', () => ({
+ AgentRuntimeService: vi.fn().mockImplementation(() => ({
+ createOperation: mockCreateOperation,
+ })),
+}));
+
+vi.mock('@/server/services/market', () => ({
+ MarketService: vi.fn().mockImplementation(() => ({
+ getLobehubSkillManifests: vi.fn().mockResolvedValue([]),
+ })),
+}));
+
+vi.mock('@/server/services/klavis', () => ({
+ KlavisService: vi.fn().mockImplementation(() => ({
+ getKlavisManifests: vi.fn().mockResolvedValue([]),
+ })),
+}));
+
+vi.mock('@/server/services/file', () => ({
+ FileService: vi.fn().mockImplementation(() => ({
+ uploadFromUrl: vi.fn(),
+ })),
+}));
+
+vi.mock('@/server/modules/Mecha', () => ({
+ createServerAgentToolsEngine: vi.fn().mockReturnValue({
+ generateToolsDetailed: vi.fn().mockReturnValue({ enabledToolIds: [], tools: [] }),
+ getEnabledPluginManifests: vi.fn().mockReturnValue(new Map()),
+ }),
+ serverMessagesEngine: vi.fn().mockResolvedValue([{ content: 'test', role: 'user' }]),
+}));
+
+vi.mock('@/server/services/toolExecution/deviceProxy', () => ({
+ deviceProxy: {
+ isConfigured: false,
+ queryDeviceList: vi.fn().mockResolvedValue([]),
+ },
+}));
+
+vi.mock('model-bank', async (importOriginal) => {
+ const actual = await importOriginal<typeof ModelBankModule>();
+ return {
+ ...actual,
+ LOBE_DEFAULT_MODEL_LIST: [
+ {
+ abilities: { functionCall: true, video: false, vision: true },
+ id: 'gpt-4',
+ providerId: 'openai',
+ },
+ {
+ abilities: { functionCall: true, video: false, vision: true },
+ id: 'claude-sonnet-4-6',
+ providerId: 'anthropic',
+ },
+ ],
+ };
+});
+
+describe('AiAgentService.execAgent - model/provider override', () => {
+ let service: AiAgentService;
+ const mockDb = {} as any;
+ const userId = 'test-user-id';
+
+ const defaultAgentConfig = {
+ chatConfig: {},
+ id: 'agent-1',
+ model: 'gpt-4',
+ plugins: [],
+ provider: 'openai',
+ slug: 'my-agent',
+ systemRole: 'You are a helpful assistant.',
+ };
+
+ beforeEach(() => {
+ vi.clearAllMocks();
+ mockMessageCreate.mockResolvedValue({ id: 'msg-1' });
+ mockCreateOperation.mockResolvedValue({
+ autoStarted: true,
+ messageId: 'queue-msg-1',
+ operationId: 'op-123',
+ success: true,
+ });
+ service = new AiAgentService(mockDb, userId);
+ });
+
+ it('should use agent default model/provider when no override is provided', async () => {
+ mockGetAgentConfig.mockResolvedValue({ ...defaultAgentConfig });
+
+ await service.execAgent({
+ agentId: 'agent-1',
+ prompt: 'Hello',
+ });
+
+ expect(mockCreateOperation).toHaveBeenCalledTimes(1);
+ const callArgs = mockCreateOperation.mock.calls[0][0];
+ expect(callArgs.agentConfig.model).toBe('gpt-4');
+ expect(callArgs.agentConfig.provider).toBe('openai');
+ });
+
+ it('should override model when model param is provided', async () => {
+ mockGetAgentConfig.mockResolvedValue({ ...defaultAgentConfig });
+
+ await service.execAgent({
+ agentId: 'agent-1',
+ model: 'claude-sonnet-4-6',
+ prompt: 'Hello',
+ });
+
+ expect(mockCreateOperation).toHaveBeenCalledTimes(1);
+ const callArgs = mockCreateOperation.mock.calls[0][0];
+ expect(callArgs.agentConfig.model).toBe('claude-sonnet-4-6');
+ expect(callArgs.agentConfig.provider).toBe('openai'); // provider unchanged
+ });
+
+ it('should override provider when provider param is provided', async () => {
+ mockGetAgentConfig.mockResolvedValue({ ...defaultAgentConfig });
+
+ await service.execAgent({
+ agentId: 'agent-1',
+ prompt: 'Hello',
+ provider: 'anthropic',
+ });
+
+ expect(mockCreateOperation).toHaveBeenCalledTimes(1);
+ const callArgs = mockCreateOperation.mock.calls[0][0];
+ expect(callArgs.agentConfig.model).toBe('gpt-4'); // model unchanged
+ expect(callArgs.agentConfig.provider).toBe('anthropic');
+ });
+
+ it('should override both model and provider when both params are provided', async () => {
+ mockGetAgentConfig.mockResolvedValue({ ...defaultAgentConfig });
+
+ await service.execAgent({
+ agentId: 'agent-1',
+ model: 'claude-sonnet-4-6',
+ prompt: 'Hello',
+ provider: 'anthropic',
+ });
+
+ expect(mockCreateOperation).toHaveBeenCalledTimes(1);
+ const callArgs = mockCreateOperation.mock.calls[0][0];
+ expect(callArgs.agentConfig.model).toBe('claude-sonnet-4-6');
+ expect(callArgs.agentConfig.provider).toBe('anthropic');
+ });
+});
diff --git a/src/server/services/aiAgent/index.ts b/src/server/services/aiAgent/index.ts
index 2e9091c55d4..1080e5d1ef4 100644
--- a/src/server/services/aiAgent/index.ts
+++ b/src/server/services/aiAgent/index.ts
@@ -236,6 +236,8 @@ export class AiAgentService {
functionTools,
hooks,
instructions,
+ model: modelOverride,
+ provider: providerOverride,
stepCallbacks,
stream,
title,
@@ -305,6 +307,10 @@ export class AiAgentService {
// Use actual agent ID from config for subsequent operations
const resolvedAgentId = agentConfig.id;
+ // Apply per-call model/provider overrides (e.g. from task.config)
+ if (modelOverride) agentConfig.model = modelOverride;
+ if (providerOverride) agentConfig.provider = providerOverride;
+
log(
'execAgent: got agent config for %s (id: %s), model: %s, provider: %s',
identifier,