Skip to content

An AI-powered search engine with a generative UI

feat: enable todo tools only for quality model type

Yoshiki Miura474b98ea822a
diff --git a/app/api/chat/route.ts b/app/api/chat/route.ts
index 331385bf..efe64e1e 100644
--- a/app/api/chat/route.ts
+++ b/app/api/chat/route.ts
@@ -97,15 +97,19 @@ export async function POST(req: Request) {
// Check rate limit for quality mode
const modelTypeCookie = cookieStore.get('modelType')?.value
+ const modelType =
+ modelTypeCookie === 'quality' || modelTypeCookie === 'speed'
+ ? modelTypeCookie
+ : undefined
const rateLimitResponse = await checkAndEnforceQualityLimit(
userId,
- modelTypeCookie === 'quality'
+ modelType === 'quality'
)
if (rateLimitResponse) return rateLimitResponse
const streamStart = performance.now()
perfLog(
- `createChatStreamResponse - Start: model=${selectedModel.providerId}:${selectedModel.id}, searchMode=${searchMode}`
+ `createChatStreamResponse - Start: model=${selectedModel.providerId}:${selectedModel.id}, searchMode=${searchMode}, modelType=${modelType}`
)
const response = await createChatStreamResponse({
@@ -117,7 +121,8 @@ export async function POST(req: Request) {
messageId,
abortSignal,
isNewChat,
- searchMode
+ searchMode,
+ modelType
})
perfTime('createChatStreamResponse resolved', streamStart)
diff --git a/lib/agents/researcher.ts b/lib/agents/researcher.ts
index 93fd7b1e..5026d258 100644
--- a/lib/agents/researcher.ts
+++ b/lib/agents/researcher.ts
@@ -13,6 +13,7 @@ import type {
ResearcherResponse,
ResearcherTools
} from '@/lib/types/agent'
+import { type ModelType } from '@/lib/types/model-type'
import { type Model } from '@/lib/types/models'
import { fetchTool } from '../tools/fetch'
@@ -81,7 +82,8 @@ export function createResearcher({
abortSignal,
writer,
parentTraceId,
- searchMode = 'adaptive'
+ searchMode = 'adaptive',
+ modelType
}: {
model: string
modelConfig?: Model
@@ -89,6 +91,7 @@ export function createResearcher({
writer?: UIMessageStreamWriter
parentTraceId?: string
searchMode?: SearchMode
+ modelType?: ModelType
}): ResearcherAgent {
try {
const currentDate = new Date().toLocaleString()
@@ -119,11 +122,12 @@ export function createResearcher({
default:
systemPrompt = ADAPTIVE_MODE_PROMPT
activeToolsList = ['search', 'fetch']
- if (writer && 'todoWrite' in todoTools) {
+ // Only enable todo tools for quality model type
+ if (writer && 'todoWrite' in todoTools && modelType === 'quality') {
activeToolsList.push('todoWrite', 'todoRead')
}
console.log(
- `[Researcher] Adaptive mode: maxSteps=50, tools=[${activeToolsList.join(', ')}]`
+ `[Researcher] Adaptive mode: maxSteps=50, modelType=${modelType}, tools=[${activeToolsList.join(', ')}]`
)
maxSteps = 50
searchTool = originalSearchTool
diff --git a/lib/streaming/create-chat-stream-response.ts b/lib/streaming/create-chat-stream-response.ts
index 2234d7c6..b91b1b33 100644
--- a/lib/streaming/create-chat-stream-response.ts
+++ b/lib/streaming/create-chat-stream-response.ts
@@ -44,7 +44,8 @@ export async function createChatStreamResponse(
messageId,
abortSignal,
isNewChat,
- searchMode
+ searchMode,
+ modelType
} = config
// Verify that chatId is provided
@@ -123,14 +124,15 @@ export async function createChatStreamResponse(
const messagesToModel = await prepareMessages(context, message)
perfTime('prepareMessages completed (stream)', prepareStart)
- // Get the researcher agent with parent trace ID and search mode
+ // Get the researcher agent with parent trace ID, search mode, and model type
const researchAgent = researcher({
model: context.modelId,
modelConfig: model,
abortSignal,
writer,
parentTraceId,
- searchMode
+ searchMode,
+ modelType
})
// Filter out reasoning parts from messages before converting to model messages
diff --git a/lib/streaming/types.ts b/lib/streaming/types.ts
index e3361008..94da5b8a 100644
--- a/lib/streaming/types.ts
+++ b/lib/streaming/types.ts
@@ -1,6 +1,7 @@
import { UIMessage } from '@ai-sdk/react'
import { Model } from '../types/models'
+import { ModelType } from '../types/model-type'
import { SearchMode } from '../types/search'
export interface BaseStreamConfig {
@@ -13,4 +14,5 @@ export interface BaseStreamConfig {
abortSignal?: AbortSignal
isNewChat?: boolean
searchMode?: SearchMode
+ modelType?: ModelType
}