@flink-app/mistral-adapter
v2.0.0-alpha.103
Published
Mistral AI adapter for Flink AI framework
Readme
@flink-app/mistral-adapter
Mistral AI adapter for the Flink AI framework. Provides integration with Mistral's models via the Chat Completions API using the official @mistralai/mistralai SDK.
Installation
npm install @flink-app/mistral-adapter
# or
pnpm add @flink-app/mistral-adapterThe @mistralai/mistralai package is included as a dependency, so you don't need to install it separately.
Usage
Basic Setup
import { MistralAdapter } from "@flink-app/mistral-adapter";
import { FlinkApp } from "@flink-app/flink";
const app = new FlinkApp({
ai: {
llms: {
default: new MistralAdapter({
apiKey: process.env.MISTRAL_API_KEY!,
model: "mistral-medium-latest"
}),
},
},
});
await app.start();Legacy API (still supported):
// Backward-compatible constructor
new MistralAdapter(process.env.MISTRAL_API_KEY!, "mistral-medium-latest")Agent Instructions
Define your agent's behavior using the instructions property:
// src/agents/support_agent.ts
export const Agent: FlinkAgentProps = {
name: "support_agent",
instructions: "You are a helpful customer support agent.",
tools: ["get_order_status"],
model: { adapterId: "default" },
};How it works:
- Instructions are prepended as a system message to every conversation
- Follows Vercel AI SDK pattern for consistency
- Additional system messages in the conversation are passed through as-is
Multiple Adapters
You can register multiple Mistral adapters with different configurations:
const app = new FlinkApp({
ai: {
llms: {
// Frontier model - best for agentic and coding use cases
default: new MistralAdapter({
apiKey: process.env.MISTRAL_API_KEY!,
model: "mistral-medium-latest"
}),
// Efficient model - good balance of capability and cost
fast: new MistralAdapter({
apiKey: process.env.MISTRAL_API_KEY!,
model: "mistral-small-latest"
}),
// Code completion specialist
code: new MistralAdapter({
apiKey: process.env.MISTRAL_API_KEY!,
model: "codestral-latest"
}),
},
},
});Debug Logging
const adapter = new MistralAdapter({
apiKey: process.env.MISTRAL_API_KEY!,
model: "mistral-medium-latest",
debug: true // Enable debug logging for this adapter
});When debug: true, the adapter logs full request parameters and tool call decisions made by the LLM.
Supported Models
This adapter works with all Mistral chat models. As of 2026:
| Use Case | Recommended Model | Why |
|----------|------------------|-----|
| General / agentic / coding | mistral-medium-latest | Mistral Medium 3.5 - frontier-class multimodal model optimized for agentic and coding use cases |
| Cost-efficient tasks | mistral-small-latest | Mistral Small 4 - hybrid model unifying instruct, reasoning, and coding |
| General-purpose (open weights) | mistral-large-latest | Mistral Large 3 - general-purpose multimodal model (Apache 2.0) |
| Code completion | codestral-latest | Codestral - code completion specialist |
| Edge / small footprint | Ministral 3 series (3B, 8B, 14B) | Compact text and vision models |
See the Mistral models overview for the full, up-to-date list of model IDs.
Features
- ✅ Full tool calling support - including parallel tool calls in a single response
- ✅ Event-based streaming - via the SDK's
chat.stream() - ✅ Multimodal input - text + image content blocks (https URLs and base64 data URLs)
- ✅ Tool call ID normalization - Mistral requires tool call IDs to be exactly 9 alphanumeric characters; IDs from conversation history that originated with another provider are deterministically remapped
- ✅ Token usage tracking - prompt and completion tokens reported per request
- ✅ Schema sanitization - tool input schemas cleaned for Mistral compatibility
Architecture Notes
Flink Integration
The adapter implements Flink's LLMAdapter interface:
- Flink's
instructions→ prepended as{ role: "system" }message - Flink's
messages→ converted to Mistral chat messages (system/user/assistant/tool roles) - Flink's tool schema → converted to Mistral's function format (
{ type: "function", function: {...} }) - Streamed deltas → mapped to Flink's
LLMStreamChunkevents (text, tool_call, usage, done)
Each API call is one turn:
- Flink's AgentRunner handles the multi-turn loop (call API → execute tools → call API again)
- Tool results are sent back as
{ role: "tool", toolCallId, content }messages
ESM-only SDK
The @mistralai/mistralai SDK v2 is ESM-only. This adapter is compiled to CommonJS (like the rest of the Flink ecosystem) and loads the SDK via a dynamic import(), so it works in both CommonJS and ESM applications without configuration.
Temperature
Temperature is only sent to the API when the agent explicitly configured one — Mistral recommends values between 0.0 and 0.7, and the default varies by model.
Requirements
- Node.js >= 18
- @flink-app/flink >= 2.0.0-alpha.102
License
MIT
