AI SDK
AI SDK implementation for @micdrop/server.
This package provides an AI agent implementation using the Vercel AI SDK, allowing you to use any compatible language model provider.
Installation
Install AI SDK:
npm install @micdrop/ai-sdkAnd install the provider you want to use, for example OpenAI:
npm install @ai-sdk/openaiAI SDK Agent
Usage with MicdropServer
import { AiSdkAgent } from '@micdrop/ai-sdk'import { MicdropServer } from '@micdrop/server'import { openai } from '@ai-sdk/openai' // or any other provider
const agent = new AiSdkAgent({ model: openai('gpt-4o'), // Use any AI SDK compatible model systemPrompt: 'You are a helpful assistant',
// Custom AI SDK settings (optional) settings: { temperature: 0.7, maxOutputTokens: 150, },
// Provider specific parameters (optional) providerOptions: { openai: { reasoningEffort: 'none' }, },})
// Use with MicdropServernew MicdropServer(socket, { agent, // ... other options})Usage without MicdropServer
import { AiSdkAgent } from '@micdrop/ai-sdk'import { openai } from '@ai-sdk/openai'
const agent = new AiSdkAgent({ model: openai('gpt-4o'), systemPrompt: 'You are a helpful assistant',})
agent.on('Message', (message) => console.log('Message:', message))
agent.addUserMessage('Hello, what can you do?')
// The answer is a text stream, written as the model generates itagent.answer().on('data', (chunk) => process.stdout.write(chunk))Events
| Event | Payload | Description |
|---|---|---|
Message | MicdropConversationItem | A message, a tool call or a tool result was added to the conversation. |
ToolCall | MicdropToolCall | A tool declared with emitOutput ran, with its parameters and output. |
CancelLastUserMessage | none | The last user message was dropped because it carried no intent. |
SkipAnswer | none | The agent stays silent and waits for the user to finish their sentence. |
EndCall | none | The agent decided that the call is over. |
Failed | none | The agent gave up generating an answer after its retries. |
See the Agent interface for the full contract.
Supported Providers
The AI SDK Agent supports any provider compatible with the Vercel AI SDK:
- OpenAI:
openai('gpt-4o'),openai('gpt-3.5-turbo') - Anthropic:
anthropic('claude-3-5-sonnet-20241022') - Google:
google('gemini-1.5-pro'),google('gemini-1.5-flash') - Mistral:
mistral('mistral-large-latest') - And many more: See AI SDK Providers
Provider specific options
settings carries the parameters every provider understands, such as the
temperature. Parameters read by a single provider go in providerOptions,
under the name of that provider. Turning reasoning off is the common case in a
call, since reasoning delays the first token:
const agent = new AiSdkAgent({ model: openai.chat('gpt-5.2'), systemPrompt: 'You are a helpful assistant', providerOptions: { openai: { reasoningEffort: 'none' }, },})The same option reaches a local server behind
createOpenAI. Ollama maps it to its own think flag, and a model without a
reasoning mode ignores it.
Options
| Option | Type | Default | Description |
|---|---|---|---|
model | LanguageModel | Required | Any AI SDK compatible language model |
systemPrompt | string | Required | System prompt for the agent |
maxRetry | number | 3 | Maximum number of retries on API failures |
autoEndCall | boolean | string | false | Auto-detect when user wants to end call |
autoSemanticTurn | boolean | string | false | Handle incomplete user sentences |
autoIgnoreUserNoise | boolean | string | false | Filter meaningless user sounds |
extract | ExtractJsonOptions | ExtractTagOptions | undefined | Extract structured data from responses |
onBeforeAnswer | function | undefined | Hook called before answer generation - return true to skip generation |
settings | CallSettings | {} | Additional AI SDK parameters |
providerOptions | ProviderOptions | {} | Provider specific parameters, keyed by provider name |
The AI SDK Agent supports adding and removing custom tools to extend its capabilities. For detailed information about tool management, see the Tools documentation.
Advanced Features
The AI SDK Agent supports advanced features for improved conversation handling:
- Auto End Call: Automatically detect when users want to end the conversation
- Semantic Turn Detection: Handle incomplete sentences for natural flow
- User Noise Filtering: Filter out meaningless sounds and filler words
- Extract Value from Answer: Extract structured data from responses
- Tools: Add custom tools to the agent