Use deepseek-kit alongside Vercel AI SDK — DeepSeek handles text reasoning while AI SDK handles multimodal and UI integration.
Vercel AI SDK is a popular AI application development framework that supports multiple model providers and rich UI integration hooks. By integrating deepseek-kit with AI SDK, you can leverage AI SDK's multimodal capabilities (image understanding, file processing, etc.) to complement DeepSeek V4's limitations, while enjoying DeepSeek's low-cost, high-performance text reasoning.
In this pattern, AI SDK's ToolLoopAgent serves as the main agent handling multimodal input, while the deepseek-kit agent is wrapped as a tool handling text tasks that require deep reasoning and tool calling.
A user sends an image, AI SDK's multimodal model first understands the image content, then passes the analysis result to the DeepSeek agent for in-depth research:
import { openai } from '@ai-sdk/openai'
import { tool as aiTool, ToolLoopAgent } from 'ai'
import { createAgent, createModel, tool } from 'deepseek-kit'
import { z } from 'zod'
const deepseekModel = createModel({ model: 'deepseek-v4-flash' })
const researchAgent = createAgent({
model: deepseekModel,
system: 'You are a research assistant. Conduct in-depth analysis based on provided information and clearly summarize your findings in your final response.',
tools: [searchTool],
})
const researchTool = aiTool({
description: 'Use DeepSeek to conduct in-depth research and analysis on a given topic',
parameters: z.object({
topic: z.string().describe('The topic to research'),
context: z.string().describe('Related context information, such as image analysis results'),
}),
execute: async ({ topic, context }) => {
const result = await researchAgent.generate({
prompt: `Based on the following context, research this topic in depth: ${topic}\n\nContext: ${context}`,
})
return result.text
},
})
const mainAgent = new ToolLoopAgent({
model: openai('gpt-4o'),
tools: { research: researchTool },
})
When a user sends an image:
GPT-4o understands the image content and extracts key information
GPT-4o determines that in-depth research is needed and calls the research tool
The DeepSeek agent executes the research task in an isolated context
The research result is returned to GPT-4o, which generates the final response
Wrap AI SDK's multimodal model as a deepseek-kit tool for the DeepSeek agent to call on demand:
import { openai } from '@ai-sdk/openai'
import { generateText } from 'ai'
import { createAgent, createModel, tool } from 'deepseek-kit'
import { z } from 'zod'
const deepseekModel = createModel({ model: 'deepseek-v4-flash' })
const analyzeImageTool = tool({
name: 'analyzeImage',
description: 'Analyze image content and return a detailed text description',
schema: z.object({
imageUrl: z.string().describe('URL of the image'),
question: z.string().describe('Question about the image'),
}),
execute: async (input) => {
const result = await generateText({
model: openai('gpt-4o'),
messages: [
{
role: 'user',
content: [
{ type: 'text', text: input.question },
{ type: 'image', image: input.imageUrl },
],
},
],
})
return result.text
},
})
const agent = createAgent({
model: deepseekModel,
tools: [analyzeImageTool, searchTool],
system: 'You are an assistant. When users send images, use the analyzeImage tool to understand the image content, then answer questions based on the analysis.',
})
const result = await agent.generate({
prompt: 'What architectural style is the building in this image? Please provide a detailed analysis with historical context.',
})
When a deepseek-kit agent serves as a subagent, its internal stream events don't propagate to AI SDK's stream. If you need to display subagent progress in the UI, you can implement custom progress callbacks in the tool:
Context Isolation — deepseek-kit subagents have their own isolated context window and don't inherit the AI SDK main agent's conversation history. If you need to pass context, manually construct it in the tool's execute function
Latency Stacking — Subagent execution time stacks onto the main agent's total latency. For simple text tasks, consider using DeepSeek directly rather than routing through AI SDK
Error Propagation — Errors in subagents are returned to the main agent as tool execution failures and don't directly interrupt the main flow
API Keys — Make sure both DEEPSEEK_API_KEY and the corresponding AI SDK model's API key (e.g., OPENAI_API_KEY) are configured