feat(agent): route chat through selected model

This commit is contained in:
ginnoir
2026-07-08 16:34:22 -05:00
parent bf7e07ead9
commit 9b7a04431c
6 changed files with 78 additions and 4 deletions
+7
View File
@@ -1,4 +1,5 @@
import { z } from "zod";
import { isValidLlmModelId } from "@/lib/llm/models";
export const clientChatAttachmentSchema = z.object({
type: z.literal("image"),
@@ -11,8 +12,14 @@ export const clientChatMessageSchema = z.object({
attachments: z.array(clientChatAttachmentSchema).max(3).optional(),
});
export const clientChatModelSchema = z
.string()
.trim()
.refine((value) => isValidLlmModelId(value), "Invalid assistant model");
export const clientChatInputSchema = z.object({
stream: z.boolean().optional(),
model: clientChatModelSchema.optional(),
messages: z.array(clientChatMessageSchema).min(1).max(40),
});
+2 -1
View File
@@ -45,11 +45,12 @@ export async function runAgentChat(options: {
messages: ClientChatMessage[];
request: Request;
systemPrompt?: string;
model?: string;
llm?: LlmClient;
executeTool?: ToolExecutor;
onProgress?: AgentProgressHandler;
}): Promise<AgentChatResult> {
const llm = options.llm ?? createLlmClient();
const llm = options.llm ?? createLlmClient({ model: options.model });
const executeTool = options.executeTool ?? createApiToolExecutor(options.request);
const onProgress = options.onProgress;
const systemPrompt = options.systemPrompt ?? AGENT_SYSTEM_PROMPT;