# Mistral Agents API — Built-In Tools, Memory & Search > Mistral's Agents API gives any model built-in tools (web search, code interpreter, MCP), persistent memory, and multi-agent handoff via one endpoint. ## Install Copy the content below into your project: ## Quick Use 1. Get an API key at console.mistral.ai 2. `pip install mistralai` (or `npm install @mistralai/mistralai`) 3. Use the agents.create + conversations.create snippet below --- ## Intro The Mistral Agents API is a single endpoint that wraps a Mistral model with built-in tools — web search, code interpreter, image generation, document library, and MCP server connectors — plus persistent conversation memory and agent handoff. Best for: production agents where you don't want to glue tools yourself. Works with: Mistral API directly, or via the official Mistral SDK in Python / JavaScript. Setup time: 5 minutes (API key + 30 lines of code). --- ### Create an agent ```python from mistralai import Mistral client = Mistral(api_key=os.environ["MISTRAL_API_KEY"]) agent = client.beta.agents.create( model="mistral-large-latest", name="Research Assistant", description="Researches topics and writes summaries", instructions="You are a research assistant. Use web search aggressively. Cite sources.", tools=[ {"type": "web_search"}, {"type": "code_interpreter"}, {"type": "document_library", "library_id": "lib-xyz"}, ], ) ``` ### Run a conversation ```python conversation = client.beta.conversations.create( agent_id=agent.id, inputs="Compare the energy density of LFP vs NMC batteries with citations.", ) # The agent runs the web_search tool, code_interpreter, then synthesizes print(conversation.outputs[-1].content) print(conversation.outputs[-1].tool_calls) # see what tools were used ``` ### Multi-agent handoff ```python researcher = client.beta.agents.create( name="Researcher", model="mistral-large-latest", tools=[{"type": "web_search"}], ) writer = client.beta.agents.create( name="Writer", model="mistral-large-latest", instructions="Polish drafts into newsletter format.", ) # Hand off mid-conversation conv = client.beta.conversations.create( agent_id=researcher.id, inputs="Find 3 papers on retrieval-augmented generation from arxiv this month", ) # Then transfer to writer final = client.beta.conversations.append( conversation_id=conv.id, agent_id=writer.id, inputs="Now turn this into a 200-word LinkedIn post", ) ``` ### Connect MCP servers ```python agent = client.beta.agents.create( name="Coder", model="codestral-latest", tools=[ { "type": "mcp", "server_url": "https://your-mcp-server.example.com", }, ], ) ``` Any MCP server (Postgres MCP, GitHub MCP, etc) works. Agents API speaks the protocol natively. --- ### FAQ **Q: Is the Mistral Agents API free?** A: Pay-as-you-go via Mistral's API. Pricing varies by model (mistral-large is most expensive, mistral-small cheapest). Free tier on console.mistral.ai for prototyping. See pricing on mistral.ai/pricing. **Q: How does this compare to OpenAI Assistants API?** A: Similar architecture (agent + tools + memory) but Mistral adds native MCP support — connect any MCP server as a tool with one config line. OpenAI Assistants only support OpenAI-flavored function calling. **Q: Can I use Codestral with the Agents API?** A: Yes. Set `model='codestral-latest'` when creating the agent. Codestral is the recommended model for code-focused agents (lower latency, cheaper, better on code-specific benchmarks). --- ## Source & Thanks > Built by [Mistral AI](https://github.com/mistralai). Commercial API. > > [docs.mistral.ai/agents](https://docs.mistral.ai/capabilities/agents) — Official documentation --- ## 快速使用 1. 到 console.mistral.ai 拿 API key 2. `pip install mistralai`(或 `npm install @mistralai/mistralai`) 3. 用下面的 agents.create + conversations.create 代码 --- ## 简介 Mistral Agents API 是一个端点,把 Mistral 模型套上内置工具 —— 网页搜索、code interpreter、图像生成、文档库、MCP server 连接器 —— 加上持久会话记忆和 agent 切换。适合不想自己粘工具的生产 agent。兼容 Mistral API 直调,或官方 Mistral SDK(Python / JS)。装机时间 5 分钟(API key + 30 行代码)。 --- ### 创建 agent ```python from mistralai import Mistral client = Mistral(api_key=os.environ["MISTRAL_API_KEY"]) agent = client.beta.agents.create( model="mistral-large-latest", name="Research Assistant", description="Researches topics and writes summaries", instructions="You are a research assistant. Use web search aggressively. Cite sources.", tools=[ {"type": "web_search"}, {"type": "code_interpreter"}, {"type": "document_library", "library_id": "lib-xyz"}, ], ) ``` ### 跑一段对话 ```python conversation = client.beta.conversations.create( agent_id=agent.id, inputs="Compare the energy density of LFP vs NMC batteries with citations.", ) # Agent 自己跑 web_search、code_interpreter,再综合 print(conversation.outputs[-1].content) print(conversation.outputs[-1].tool_calls) # 看用了哪些工具 ``` ### 多 agent 切换 ```python researcher = client.beta.agents.create( name="Researcher", model="mistral-large-latest", tools=[{"type": "web_search"}], ) writer = client.beta.agents.create( name="Writer", model="mistral-large-latest", instructions="Polish drafts into newsletter format.", ) # 对话中途切换 conv = client.beta.conversations.create( agent_id=researcher.id, inputs="Find 3 papers on retrieval-augmented generation from arxiv this month", ) # 然后切给 writer final = client.beta.conversations.append( conversation_id=conv.id, agent_id=writer.id, inputs="Now turn this into a 200-word LinkedIn post", ) ``` ### 接 MCP server ```python agent = client.beta.agents.create( name="Coder", model="codestral-latest", tools=[ { "type": "mcp", "server_url": "https://your-mcp-server.example.com", }, ], ) ``` 任何 MCP server(Postgres MCP、GitHub MCP 等)都能接。Agents API 原生支持协议。 --- ### FAQ **Q: Mistral Agents API 免费吗?** A: 通过 Mistral API 按量付费。价格按模型分(mistral-large 最贵、mistral-small 最便宜)。console.mistral.ai 有免费档用于原型。价格见 mistral.ai/pricing。 **Q: 跟 OpenAI Assistants API 比怎样?** A: 架构相似(agent + 工具 + 记忆),但 Mistral 加了原生 MCP 支持 —— 一行配置接任何 MCP server 当工具。OpenAI Assistants 只支持 OpenAI 风格的 function calling。 **Q: Agents API 能用 Codestral 吗?** A: 能。创建 agent 时设 `model='codestral-latest'`。Codestral 是代码 agent 推荐模型(延迟低、更便宜、代码 benchmark 更强)。 --- ## 来源与感谢 > Built by [Mistral AI](https://github.com/mistralai). Commercial API. > > [docs.mistral.ai/agents](https://docs.mistral.ai/capabilities/agents) — Official documentation --- Source: https://tokrepo.com/en/workflows/mistral-agents-api-built-in-tools-memory-search Author: Mistral AI