🎤Micdrop

Mistral LLM Agent in Node.js

MistralAgent answers with Mistral models through Mistral AI’s API. It works with any speech to text and text to speech. It calls the global endpoint, api.mistral.ai. To keep the agent in Europe, use @micdrop/ai-sdk with a Mistral model set to api.eu.mistral.ai, as in this sovereign voice AI setup.

For a comparison of the Mistral Voice Agents SDK, a custom WebSocket client and a Micdrop pipeline, see how to build a Mistral voice agent with Voxtral 3.

Installation

Terminal window
npm install @micdrop/mistral

The same package also provides a speech to text and a text to speech. The providers page shows what every provider covers.

Usage with MicdropServer

import { MistralAgent } from '@micdrop/mistral'
import { MicdropServer } from '@micdrop/server'
const agent = new MistralAgent({
apiKey: process.env.MISTRAL_API_KEY || '',
model: 'mistral-large-latest',
systemPrompt: 'You are a helpful assistant',
})
// Use with MicdropServer
new MicdropServer(socket, {
agent,
// ... other options
})

Usage without MicdropServer

import { MistralAgent } from '@micdrop/mistral'
const agent = new MistralAgent({
apiKey: process.env.MISTRAL_API_KEY || '',
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 it
agent.answer().on('data', (chunk) => process.stdout.write(chunk))

Events

EventPayloadDescription
MessageMicdropConversationItemA message, a tool call or a tool result was added to the conversation.
ToolCallMicdropToolCallA tool declared with emitOutput ran, with its parameters and output.
CancelLastUserMessagenoneThe last user message was dropped because it carried no intent.
SkipAnswernoneThe agent stays silent and waits for the user to finish their sentence.
EndCallnoneThe agent decided that the call is over.
FailednoneThe agent gave up generating an answer after its retries.

See the Agent interface for the full contract.

Options

OptionTypeDefaultDescription
apiKeystringRequiredYour Mistral AI API key
modelstring'mistral-large-latest'Mistral AI model to use
systemPromptstringRequiredSystem prompt for the agent
maxRetrynumber3Maximum number of retries on API failures
retryDelaynumber500Delay in milliseconds between retries
maxStepsnumber5Maximum number of steps (for tool calls)
autoEndCallboolean | stringfalseAuto-detect when user wants to end call
autoSemanticTurnboolean | stringfalseHandle incomplete user sentences
autoIgnoreUserNoiseboolean | stringfalseFilter meaningless user sounds
extractExtractJsonOptions | ExtractTagOptionsundefinedExtract structured data from responses
onBeforeAnswerfunctionundefinedHook called before answer generation, returns true to skip it or a text to answer instead
settingsobject{}Additional Mistral AI API parameters

Cancellation and Retries

When the user interrupts, the request to Mistral is aborted and the unfinished answer stays out of the conversation. A request that fails before writing anything is retried up to maxRetry times, retryDelay apart, unless the answer was cancelled meanwhile. A request cut off after part of the answer reached the stream ends there, and the part already spoken is the answer recorded, so no sentence is ever spoken twice.

Available Models

Mistral AI offers several models you can choose from:

  • ministral-8b-latest - Fast and efficient 8B parameter model (default)
  • mistral-large-latest - Most capable model for complex tasks
  • mistral-small-latest - Balanced performance and cost
  • codestral-latest - Specialized for code generation

Settings Object

The settings parameter accepts any additional options from the Mistral AI Chat Completions API:

const agent = new MistralAgent({
apiKey: process.env.MISTRAL_API_KEY || '',
systemPrompt: 'You are a helpful assistant',
settings: {
temperature: 0.7, // Controls randomness (0-1)
max_tokens: 1000, // Maximum tokens in response
top_p: 0.9, // Nucleus sampling parameter
random_seed: 42, // For reproducible outputs
safe_prompt: false, // Enable/disable safety filtering
},
})

Advanced Features

The Mistral Agent supports advanced features for improved conversation handling: