Skip to content

An AI-powered search engine with a generative UI

feat: migrate to AI SDK v6 with ToolLoopAgent (#760)

Yoshiki Miura96bb56114dfd
diff --git a/bun.lock b/bun.lock
index 27b06938..0cc0fa27 100644
--- a/bun.lock
+++ b/bun.lock
@@ -1,14 +1,15 @@
{
"lockfileVersion": 1,
+ "configVersion": 0,
"workspaces": {
"": {
"name": "morphic",
"dependencies": {
- "@ai-sdk/anthropic": "^2.0.44",
- "@ai-sdk/gateway": "^2.0.9",
- "@ai-sdk/google": "^2.0.31",
- "@ai-sdk/openai": "^2.0.65",
- "@ai-sdk/react": "^2.0.93",
+ "@ai-sdk/anthropic": "^3.0.33",
+ "@ai-sdk/gateway": "^3.0.29",
+ "@ai-sdk/google": "^3.0.18",
+ "@ai-sdk/openai": "^3.0.23",
+ "@ai-sdk/react": "^3.0.66",
"@aws-sdk/client-s3": "^3.850.0",
"@opentelemetry/api-logs": "0.57.2",
"@opentelemetry/instrumentation": "0.57.2",
@@ -39,7 +40,7 @@
"@upstash/redis": "^1.35.5",
"@vercel/analytics": "^1.5.0",
"@vercel/otel": "^1.13.0",
- "ai": "^5.0.93",
+ "ai": "^6.0.64",
"class-variance-authority": "^0.7.1",
"clsx": "^2.1.0",
"cmdk": "1.0.0",
@@ -97,19 +98,19 @@
"packages": {
"@adobe/css-tools": ["@adobe/[email protected]", "", {}, "sha512-VQKMkwriZbaOgVCby1UDY/LDk5fIjhQicCvVPFqfe+69fWaPWydbWJ3wRt59/YzIwda1I81loas3oCoHxnqvdA=="],
- "@ai-sdk/anthropic": ["@ai-sdk/[email protected]", "", { "dependencies": { "@ai-sdk/provider": "2.0.0", "@ai-sdk/provider-utils": "3.0.17" }, "peerDependencies": { "zod": "^3.25.76 || ^4.1.8" } }, "sha512-o8TfNXRzO/KZkBrcx+CL9LQsPhx7PHyqzUGjza3TJaF9WxfH1S5UQLAmEw8F7lQoHNLU0IX03WT8o8R/4JbUxQ=="],
+ "@ai-sdk/anthropic": ["@ai-sdk/[email protected]", "", { "dependencies": { "@ai-sdk/provider": "3.0.6", "@ai-sdk/provider-utils": "4.0.11" }, "peerDependencies": { "zod": "^3.25.76 || ^4.1.8" } }, "sha512-MvQzipOAK99Ct3nX6d8oz2AJ9c8kbiU2uSpGYK3F5oBBa8Gy04+LbYBoB9oH8bbZJxFafkgwBq1+k8xpU7vVxQ=="],
- "@ai-sdk/gateway": ["@ai-sdk/[email protected]", "", { "dependencies": { "@ai-sdk/provider": "2.0.0", "@ai-sdk/provider-utils": "3.0.17", "@vercel/oidc": "3.0.3" }, "peerDependencies": { "zod": "^3.25.76 || ^4.1.8" } }, "sha512-E6x4h5CPPPJ0za1r5HsLtHbeI+Tp3H+YFtcH8G3dSSPFE6w+PZINzB4NxLZmg1QqSeA5HTP3ZEzzsohp0o2GEw=="],
+ "@ai-sdk/gateway": ["@ai-sdk/[email protected]", "", { "dependencies": { "@ai-sdk/provider": "3.0.6", "@ai-sdk/provider-utils": "4.0.11", "@vercel/oidc": "3.1.0" }, "peerDependencies": { "zod": "^3.25.76 || ^4.1.8" } }, "sha512-zf6yXT+7DcVGWG7ntxVCYC48X/opsWlO5ePvgH8W9DaEVUtkemqKUEzBqowQ778PkZo8sqMnRfD0+fi9HamRRQ=="],
- "@ai-sdk/google": ["@ai-sdk/[email protected]", "", { "dependencies": { "@ai-sdk/provider": "2.0.0", "@ai-sdk/provider-utils": "3.0.17" }, "peerDependencies": { "zod": "^3.25.76 || ^4.1.8" } }, "sha512-wOlUkrXHuL73sXPZd251+30BQ378zn2Zo8pW+Hq+8d9FmSJpZXOSK8cmYle1SE5ZWe/TS+eSj3eBCZ6AW+q2EA=="],
+ "@ai-sdk/google": ["@ai-sdk/[email protected]", "", { "dependencies": { "@ai-sdk/provider": "3.0.6", "@ai-sdk/provider-utils": "4.0.11" }, "peerDependencies": { "zod": "^3.25.76 || ^4.1.8" } }, "sha512-g36Arlv38wjnqAhNlxMkfTvmWpMbD+FTFoXLppZ8dZhMQbr/UI5dEtFAByU1/lWeDyOmj/uTWzAuRTyJRw7OLA=="],
- "@ai-sdk/openai": ["@ai-sdk/[email protected]", "", { "dependencies": { "@ai-sdk/provider": "2.0.0", "@ai-sdk/provider-utils": "3.0.17" }, "peerDependencies": { "zod": "^3.25.76 || ^4.1.8" } }, "sha512-Wqo4iNCsxUYJFmEAzAHO0XDnnS76rqvPRX2AUhEAOX3cgL9UEfouFmiNQS2jM9AZhMdWj5GIG41hgr4YOr20tA=="],
+ "@ai-sdk/openai": ["@ai-sdk/[email protected]", "", { "dependencies": { "@ai-sdk/provider": "3.0.6", "@ai-sdk/provider-utils": "4.0.11" }, "peerDependencies": { "zod": "^3.25.76 || ^4.1.8" } }, "sha512-vFfFadJH+hbrgI4lhC9H/r8qPzuFJFUwZNS8oMI8KujO/woovbE1EWOOGMRGtNVL8PrhhxBfgJzvOKdux3c1gw=="],
- "@ai-sdk/provider": ["@ai-sdk/[email protected]", "", { "dependencies": { "json-schema": "^0.4.0" } }, "sha512-6o7Y2SeO9vFKB8lArHXehNuusnpddKPk7xqL7T2/b+OvXMRIXUO1rR4wcv1hAFUAT9avGZshty3Wlua/XA7TvA=="],
+ "@ai-sdk/provider": ["@ai-sdk/[email protected]", "", { "dependencies": { "json-schema": "^0.4.0" } }, "sha512-hSfoJtLtpMd7YxKM+iTqlJ0ZB+kJ83WESMiWuWrNVey3X8gg97x0OdAAaeAeclZByCX3UdPOTqhvJdK8qYA3ww=="],
- "@ai-sdk/provider-utils": ["@ai-sdk/[email protected]", "", { "dependencies": { "@ai-sdk/provider": "2.0.0", "@standard-schema/spec": "^1.0.0", "eventsource-parser": "^3.0.6" }, "peerDependencies": { "zod": "^3.25.76 || ^4.1.8" } }, "sha512-TR3Gs4I3Tym4Ll+EPdzRdvo/rc8Js6c4nVhFLuvGLX/Y4V9ZcQMa/HTiYsHEgmYrf1zVi6Q145UEZUfleOwOjw=="],
+ "@ai-sdk/provider-utils": ["@ai-sdk/[email protected]", "", { "dependencies": { "@ai-sdk/provider": "3.0.6", "@standard-schema/spec": "^1.1.0", "eventsource-parser": "^3.0.6" }, "peerDependencies": { "zod": "^3.25.76 || ^4.1.8" } }, "sha512-y/WOPpcZaBjvNaogy83mBsCRPvbtaK0y1sY9ckRrrbTGMvG2HC/9Y/huqNXKnLAxUIME2PGa2uvF2CDwIsxoXQ=="],
- "@ai-sdk/react": ["@ai-sdk/[email protected]", "", { "dependencies": { "@ai-sdk/provider-utils": "3.0.17", "ai": "5.0.93", "swr": "^2.2.5", "throttleit": "2.1.0" }, "peerDependencies": { "react": "^18 || ^19 || ^19.0.0-rc", "zod": "^3.25.76 || ^4.1.8" }, "optionalPeers": ["zod"] }, "sha512-2TzhpQr10HuWxpqyHpSAUMRUqD1G2O73J2sAaJChomVDbjr7BwpM0mdR3aRamCXNtuLiJmTFQhbNzw8fXMBdYw=="],
+ "@ai-sdk/react": ["@ai-sdk/[email protected]", "", { "dependencies": { "@ai-sdk/provider-utils": "4.0.11", "ai": "6.0.64", "swr": "^2.2.5", "throttleit": "2.1.0" }, "peerDependencies": { "react": "^18 || ~19.0.1 || ~19.1.2 || ^19.2.1" } }, "sha512-bYxfXaNErVDiUaNlvNXaX+3oKLAeEyHiReJd54i+JTD3HEgRuazHfggzL0MidPnFJmlSZDHRRTGXxhMYh426QA=="],
"@alloc/quick-lru": ["@alloc/[email protected]", "", {}, "sha512-UrcABB+4bUrFABwbluTIBErXwvbsU/V7TZWfmbgJfbkwiBuziS9gxdODUyuiecfdGQ85jglMW6juS3+z5TsKLw=="],
@@ -719,7 +720,7 @@
"@smithy/util-waiter": ["@smithy/[email protected]", "", { "dependencies": { "@smithy/abort-controller": "^4.0.4", "@smithy/types": "^4.3.1", "tslib": "^2.6.2" } }, "sha512-slcr1wdRbX7NFphXZOxtxRNA7hXAAtJAXJDE/wdoMAos27SIquVCKiSqfB6/28YzQ8FCsB5NKkhdM5gMADbqxg=="],
- "@standard-schema/spec": ["@standard-schema/[email protected]", "", {}, "sha512-m2bOd0f2RT9k8QJx1JN85cZYyH1RqFBdlwtkSlf4tBDYLCiiZnv1fIIwacK6cqwXavOydf0NPToMQgpKq+dVlA=="],
+ "@standard-schema/spec": ["@standard-schema/[email protected]", "", {}, "sha512-l2aFy5jALhniG5HgqrD6jXLi/rUWrKvqN/qJx6yoJsgKhblVd+iqqU4RCXavm/jPityDo5TCvKMnpjKnOriy0w=="],
"@stitches/core": ["@stitches/[email protected]", "", {}, "sha512-Gfkvwk9o9kE9r9XNBmJRfV8zONvXThnm1tcuojL04Uy5uRyqg93DC83lDebl0rocZCfKSjUv+fWYtMQmEDJldg=="],
@@ -971,7 +972,7 @@
"@vercel/analytics": ["@vercel/[email protected]", "", { "peerDependencies": { "@remix-run/react": "^2", "@sveltejs/kit": "^1 || ^2", "next": ">= 13", "react": "^18 || ^19 || ^19.0.0-rc", "svelte": ">= 4", "vue": "^3", "vue-router": "^4" }, "optionalPeers": ["@remix-run/react", "@sveltejs/kit", "next", "react", "svelte", "vue", "vue-router"] }, "sha512-MYsBzfPki4gthY5HnYN7jgInhAZ7Ac1cYDoRWFomwGHWEX7odTEzbtg9kf/QSo7XEsEAqlQugA6gJ2WS2DEa3g=="],
- "@vercel/oidc": ["@vercel/[email protected]", "", {}, "sha512-yNEQvPcVrK9sIe637+I0jD6leluPxzwJKx/Haw6F4H77CdDsszUn5V3o96LPziXkSNE2B83+Z3mjqGKBK/R6Gg=="],
+ "@vercel/oidc": ["@vercel/[email protected]", "", {}, "sha512-Fw28YZpRnA3cAHHDlkt7xQHiJ0fcL+NRcIqsocZQUSmbzeIKRpwttJjik5ZGanXP+vlA4SbTg+AbA3bP363l+w=="],
"@vercel/otel": ["@vercel/[email protected]", "", { "peerDependencies": { "@opentelemetry/api": ">=1.7.0 <2.0.0", "@opentelemetry/api-logs": ">=0.46.0 <0.200.0", "@opentelemetry/instrumentation": ">=0.46.0 <0.200.0", "@opentelemetry/resources": ">=1.19.0 <2.0.0", "@opentelemetry/sdk-logs": ">=0.46.0 <0.200.0", "@opentelemetry/sdk-metrics": ">=1.19.0 <2.0.0", "@opentelemetry/sdk-trace-base": ">=1.19.0 <2.0.0" } }, "sha512-esRkt470Y2jRK1B1g7S1vkt4Csu44gp83Zpu8rIyPoqy2BKgk4z7ik1uSMswzi45UogLHFl6yR5TauDurBQi4Q=="],
@@ -999,7 +1000,7 @@
"agent-base": ["[email protected]", "", {}, "sha512-MnA+YT8fwfJPgBx3m60MNqakm30XOkyIoH1y6huTQvC0PwZG7ki8NacLBcrPbNoo8vEZy7Jpuk7+jMO+CUovTQ=="],
- "ai": ["[email protected]", "", { "dependencies": { "@ai-sdk/gateway": "2.0.9", "@ai-sdk/provider": "2.0.0", "@ai-sdk/provider-utils": "3.0.17", "@opentelemetry/api": "1.9.0" }, "peerDependencies": { "zod": "^3.25.76 || ^4.1.8" } }, "sha512-9eGcu+1PJgPg4pRNV4L7tLjRR3wdJC9CXQoNMvtqvYNOLZHFCzjHtVIOr2SIkoJJeu2+sOy3hyiSuTmy2MA40g=="],
+ "ai": ["[email protected]", "", { "dependencies": { "@ai-sdk/gateway": "3.0.29", "@ai-sdk/provider": "3.0.6", "@ai-sdk/provider-utils": "4.0.11", "@opentelemetry/api": "1.9.0" }, "peerDependencies": { "zod": "^3.25.76 || ^4.1.8" } }, "sha512-eH+6FC2THf0rXamPOBAPGNBuMvqv4gE5+IKoWVBrO1TkrjwRiuP3+P6yl7/HcXzN9JLbVe3lL8yaTIfn0ZwvxQ=="],
"ajv": ["[email protected]", "", { "dependencies": { "fast-deep-equal": "^3.1.1", "fast-json-stable-stringify": "^2.0.0", "json-schema-traverse": "^0.4.1", "uri-js": "^4.2.2" } }, "sha512-j3fVLgvTo527anyYyJOGTYJbG+vnnQYvE0m5mmkc1TK+nxAppkCLMIL0aZ4dblVCNoGShhm+kzE4ZUykBoMg4g=="],
@@ -2413,6 +2414,8 @@
"node-fetch/whatwg-url": ["[email protected]", "", { "dependencies": { "tr46": "~0.0.3", "webidl-conversions": "^3.0.0" } }, "sha512-saE57nupxk6v3HY35+jzBwYa0rKSy0XR8JSxZPwgLr7ys0IBzhGviA1/TUGJLmSVqs8pb9AnvICXEuOHLprYTw=="],
+ "ollama-ai-provider-v2/@ai-sdk/provider": ["@ai-sdk/[email protected]", "", { "dependencies": { "json-schema": "^0.4.0" } }, "sha512-6o7Y2SeO9vFKB8lArHXehNuusnpddKPk7xqL7T2/b+OvXMRIXUO1rR4wcv1hAFUAT9avGZshty3Wlua/XA7TvA=="],
+
"ollama-ai-provider-v2/@ai-sdk/provider-utils": ["@ai-sdk/[email protected]", "", { "dependencies": { "@ai-sdk/provider": "2.0.0", "@standard-schema/spec": "^1.0.0", "eventsource-parser": "^3.0.5" }, "peerDependencies": { "zod": "^3.25.76 || ^4" } }, "sha512-cDj1iigu7MW2tgAQeBzOiLhjHOUM9vENsgh4oAVitek0d//WdgfPCsKO3euP7m7LyO/j9a1vr/So+BGNdpFXYw=="],
"parse-entities/@types/unist": ["@types/[email protected]", "", {}, "sha512-CmBKiL6NNo/OqgmMn95Fk9Whlp2mtvIv+KNpQKN2F4SjvrEesubTRWGYSg+BnWZOnlCaSTU1sMpsBOzgbYhnsA=="],
@@ -2567,6 +2570,8 @@
"node-fetch/whatwg-url/webidl-conversions": ["[email protected]", "", {}, "sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ=="],
+ "ollama-ai-provider-v2/@ai-sdk/provider-utils/@standard-schema/spec": ["@standard-schema/[email protected]", "", {}, "sha512-m2bOd0f2RT9k8QJx1JN85cZYyH1RqFBdlwtkSlf4tBDYLCiiZnv1fIIwacK6cqwXavOydf0NPToMQgpKq+dVlA=="],
+
"string-width/strip-ansi/ansi-regex": ["[email protected]", "", {}, "sha512-7HSX4QQb4CspciLpVFwyRe79O3xsIZDDLER21kERQ71oaPodF8jL725AgJMFAYbooIqolJoRLuM81SpeUkpkvA=="],
"wrap-ansi-cjs/string-width/emoji-regex": ["[email protected]", "", {}, "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A=="],
diff --git a/lib/agents/generate-related-questions.ts b/lib/agents/generate-related-questions.ts
index f895eb69..c6d93761 100644
--- a/lib/agents/generate-related-questions.ts
+++ b/lib/agents/generate-related-questions.ts
@@ -1,4 +1,4 @@
-import { type ModelMessage, streamObject } from 'ai'
+import { type ModelMessage, Output, streamText } from 'ai'
import { getRelatedQuestionsModel } from '../config/model-types'
import { relatedQuestionSchema } from '../schema/related'
@@ -16,13 +16,13 @@ export function createRelatedQuestionsStream(
const relatedModel = getRelatedQuestionsModel()
const modelId = `${relatedModel.providerId}:${relatedModel.id}`
- return streamObject({
+ return streamText({
model: getModel(modelId),
- output: 'array',
- schema: relatedQuestionSchema,
- schemaName: 'RelatedQuestion',
- schemaDescription:
- 'Generate a concise follow-up question (max 10-12 words)',
+ output: Output.array({
+ element: relatedQuestionSchema,
+ name: 'RelatedQuestion',
+ description: 'Generate a concise follow-up question (max 10-12 words)'
+ }),
system: RELATED_QUESTIONS_PROMPT,
messages: [
...messages,
diff --git a/lib/agents/researcher.ts b/lib/agents/researcher.ts
index 2bb6120c..36daf36d 100644
--- a/lib/agents/researcher.ts
+++ b/lib/agents/researcher.ts
@@ -1,18 +1,11 @@
import {
- type ModelMessage,
- smoothStream,
stepCountIs,
- streamText,
tool,
+ ToolLoopAgent,
type UIMessageStreamWriter
} from 'ai'
-import type {
- ResearcherAgent,
- ResearcherRespondOptions,
- ResearcherResponse,
- ResearcherTools
-} from '@/lib/types/agent'
+import type { ResearcherTools } from '@/lib/types/agent'
import { type ModelType } from '@/lib/types/model-type'
import { type Model } from '@/lib/types/models'
@@ -75,11 +68,11 @@ function wrapSearchToolForQuickMode<
}) as T
}
-// Enhanced researcher function with improved type safety
+// Enhanced researcher function with improved type safety using ToolLoopAgent
+// Note: abortSignal should be passed to agent.stream() or agent.generate() calls, not to the agent constructor
export function createResearcher({
model,
modelConfig,
- abortSignal,
writer,
parentTraceId,
searchMode = 'adaptive',
@@ -87,12 +80,11 @@ export function createResearcher({
}: {
model: string
modelConfig?: Model
- abortSignal?: AbortSignal
writer?: UIMessageStreamWriter
parentTraceId?: string
searchMode?: SearchMode
modelType?: ModelType
-}): ResearcherAgent {
+}) {
try {
const currentDate = new Date().toLocaleString()
@@ -142,15 +134,13 @@ export function createResearcher({
...todoTools
} as ResearcherTools
- // Create streamText-based agent with smoothStream support
- const agentConfig = {
+ // Create ToolLoopAgent with all configuration
+ const agent = new ToolLoopAgent({
model: getModel(model),
- system: `${systemPrompt}\nCurrent date and time: ${currentDate}`,
+ instructions: `${systemPrompt}\nCurrent date and time: ${currentDate}`,
tools,
activeTools: activeToolsList,
stopWhen: stepCountIs(maxSteps),
- abortSignal,
- experimental_transform: smoothStream({ chunking: 'word' }), // Enable smooth streaming
...(modelConfig?.providerOptions && {
providerOptions: modelConfig.providerOptions
}),
@@ -167,18 +157,7 @@ export function createResearcher({
})
}
}
- }
-
- // Create Agent-compatible wrapper with streamText
- const agent: ResearcherAgent = {
- tools,
- stream: ({ messages }: { messages: ModelMessage[] }) => {
- return streamText({
- ...agentConfig,
- messages
- })
- }
- }
+ })
return agent
} catch (error) {
@@ -188,19 +167,11 @@ export function createResearcher({
}
// Helper function to access agent tools
-export function getResearcherTools(agent: ResearcherAgent): ResearcherTools {
+export function getResearcherTools(
+ agent: ToolLoopAgent<never, ResearcherTools, never>
+): ResearcherTools {
return agent.tools
}
-// Helper function to create a respond wrapper with type safety
-export function createResearcherRespond(agent: ResearcherAgent) {
- return (options: ResearcherRespondOptions): ResearcherResponse => {
- if (!agent.respond) {
- throw new Error('respond method not available - use stream instead')
- }
- return agent.respond(options)
- }
-}
-
// Export the legacy function name for backward compatibility
export const researcher = createResearcher
diff --git a/lib/streaming/create-chat-stream-response.ts b/lib/streaming/create-chat-stream-response.ts
index 6233d355..960e37fe 100644
--- a/lib/streaming/create-chat-stream-response.ts
+++ b/lib/streaming/create-chat-stream-response.ts
@@ -4,6 +4,7 @@ import {
createUIMessageStream,
createUIMessageStreamResponse,
pruneMessages,
+ smoothStream,
UIMessage,
UIMessageStreamWriter
} from 'ai'
@@ -128,7 +129,6 @@ export async function createChatStreamResponse(
const researchAgent = researcher({
model: context.modelId,
modelConfig: model,
- abortSignal,
writer,
parentTraceId,
searchMode,
@@ -136,7 +136,7 @@ export async function createChatStreamResponse(
})
// Convert to model messages and apply context window management
- let modelMessages = convertToModelMessages(messagesToModel)
+ let modelMessages = await convertToModelMessages(messagesToModel)
// Prune messages to remove unnecessary reasoning, tool calls, and empty messages
// This reduces token usage while keeping recent context
@@ -177,7 +177,11 @@ export async function createChatStreamResponse(
perfLog(
`researchAgent.stream - Start: model=${context.modelId}, searchMode=${searchMode}`
)
- const result = researchAgent.stream({ messages: modelMessages })
+ const result = await researchAgent.stream({
+ messages: modelMessages,
+ abortSignal,
+ experimental_transform: smoothStream({ chunking: 'word' })
+ })
result.consumeStream()
// Stream with the research agent, including metadata
writer.merge(
diff --git a/lib/streaming/helpers/stream-related-questions.ts b/lib/streaming/helpers/stream-related-questions.ts
index a18c720e..49483407 100644
--- a/lib/streaming/helpers/stream-related-questions.ts
+++ b/lib/streaming/helpers/stream-related-questions.ts
@@ -60,7 +60,7 @@ export async function streamRelatedQuestions(
let finalQuestions = collectedQuestions
try {
- const completedQuestions = await relatedQuestionsResult.object
+ const completedQuestions = await relatedQuestionsResult.output
const parsedQuestions = relatedSchema.safeParse(completedQuestions)
if (parsedQuestions.success) {
diff --git a/lib/types/agent.ts b/lib/types/agent.ts
index 8668a1c5..70e23369 100644
--- a/lib/types/agent.ts
+++ b/lib/types/agent.ts
@@ -1,9 +1,7 @@
import type {
- Experimental_Agent as Agent,
- Experimental_InferAgentUIMessage as InferAgentUIMessage,
+ InferAgentUIMessage,
InferUITools,
- ModelMessage,
- StreamTextResult,
+ ToolLoopAgent,
UIMessage,
UIToolInvocation
} from 'ai'
@@ -20,23 +18,12 @@ export type ResearcherTools = {
askQuestion: ReturnType<typeof createQuestionTool>
} & ReturnType<typeof createTodoTools>
-// Type for the researcher agent (streamText-based)
-export type ResearcherAgent = {
- tools: ResearcherTools
- stream: (options: {
- messages: ModelMessage[]
- }) => StreamTextResult<any, never>
- generate?: (options: {
- messages?: ModelMessage[]
- prompt?: string
- }) => Promise<any>
- respond?: (options: ResearcherRespondOptions) => ResearcherResponse
-}
+// Type alias for the researcher agent using ToolLoopAgent
+// ToolLoopAgent generic signature is <CALL_OPTIONS, TOOLS, OUTPUT>
+export type ResearcherAgent = ToolLoopAgent<never, ResearcherTools, never>
// Infer UI message type for researcher agent
-// Note: Using Agent type for UI message inference
-type _AgentType = Agent<ResearcherTools>
-export type ResearcherUIMessage = InferAgentUIMessage<_AgentType>
+export type ResearcherUIMessage = InferAgentUIMessage<ResearcherAgent>
// Infer UI tools type for researcher agent
export type ResearcherUITools = InferUITools<ResearcherTools>
diff --git a/package.json b/package.json
index 925b8ac4..b22fc8b5 100644
--- a/package.json
+++ b/package.json
@@ -17,11 +17,11 @@
"chat": "bun run scripts/chat-cli.ts"
},
"dependencies": {
- "@ai-sdk/anthropic": "^2.0.44",
- "@ai-sdk/gateway": "^2.0.9",
- "@ai-sdk/google": "^2.0.31",
- "@ai-sdk/openai": "^2.0.65",
- "@ai-sdk/react": "^2.0.93",
+ "@ai-sdk/anthropic": "^3.0.33",
+ "@ai-sdk/gateway": "^3.0.29",
+ "@ai-sdk/google": "^3.0.18",
+ "@ai-sdk/openai": "^3.0.23",
+ "@ai-sdk/react": "^3.0.66",
"@aws-sdk/client-s3": "^3.850.0",
"@opentelemetry/api-logs": "0.57.2",
"@opentelemetry/instrumentation": "0.57.2",
@@ -52,7 +52,7 @@
"@upstash/redis": "^1.35.5",
"@vercel/analytics": "^1.5.0",
"@vercel/otel": "^1.13.0",
- "ai": "^5.0.93",
+ "ai": "^6.0.64",
"class-variance-authority": "^0.7.1",
"clsx": "^2.1.0",
"cmdk": "1.0.0",