Mistral Agents Orchestrator
Production-tested multi-agent orchestration using Mistral's Agents API. Implements the orchestrator-delegate pattern where a lead agent coordinates specialist agents via Conversations and Handoffs.
Architecture
CODEBLOCK0
Key Concepts
Agents: Pre-registered on Mistral platform with specific system prompts and model configs. Each agent has a unique ID (ag_...).
Conversations: Multi-turn threads that preserve context across handoffs. The child's name, language, and prompt all carry through without re-injection.
Handoffs: The orchestrator names a specialist agent; Mistral routes the conversation to that agent. Context is preserved automatically.
Function Calling: Tools (like TTS, SFX) are bound to the orchestrator agent, not the delegates. Tools follow the conversation context.
Quick Start
CODEBLOCK1
Patterns Learned
- - Handoffs preserve conversation context — no need to re-inject background info
- Tools bind to the orchestrator, not delegates — delegates can request tool calls but execution happens in the orchestrator's context
- 4 agents is the sweet spot for hackathon scope — more agents = more API calls = more coordination overhead without proportional value
- JSON mode on delegates forces structured output reliably — without it, Mistral Large sometimes returns prose instead of scene arrays
Files
- -
scripts/orchestrator.py — Full orchestrator implementation with agent registration, conversation management, and handoff delegation - INLINECODE2 — Common multi-agent patterns and when to use each
Security Notes
This skill uses patterns that may trigger automated security scanners:
- - base64: Used for encoding audio/binary data in API responses (standard practice for media APIs)
- UploadFile: FastAPI's built-in file upload parameter for STT/voice isolation endpoints
- "system prompt": Refers to configuring agent instructions, not prompt injection
Mistral Agents Orchestrator
使用Mistral的Agents API实现经过生产测试的多智能体编排。实现了编排器-委托模式,其中主导智能体通过对话和交接协调专业智能体。
架构
编排器(Papa Bois模式)
├── 通过Agents API注册专业智能体
├── 创建带交接配置的对话
├── 通过指定目标智能体名称来委派任务
└── 从完成的交接中收集结果
专业智能体(Anansi、Devi、Firefly模式)
├── 接收带有完整对话上下文的委派任务
├── 执行其专业领域(故事生成、音频、代码)
└── 将结果返回给编排器对话
关键概念
智能体: 在Mistral平台上预先注册,具有特定的系统提示和模型配置。每个智能体都有唯一的ID(ag_...)。
对话: 跨交接保留上下文的多轮线程。子项的名称、语言和提示都会自动传递,无需重新注入。
交接: 编排器指定一个专业智能体;Mistral将对话路由到该智能体。上下文自动保留。
函数调用: 工具(如TTS、SFX)绑定到编排器智能体,而不是委托智能体。工具遵循对话上下文。
快速开始
python
from mistralai import Mistral
client = Mistral(apikey=os.environ[MISTRALAPI_KEY])
注册智能体(一次性设置)
orchestrator = client.beta.agents.create(
model=mistral-large-latest,
name=orchestrator,
instructions=你协调专业智能体...,
)
specialist = client.beta.agents.create(
model=mistral-large-latest,
name=writer,
instructions=当被委派时你负责撰写内容...,
)
创建带交接的对话
response = client.beta.conversations.create(
agent_id=orchestrator.id,
inputs=写一篇关于AI智能体的博客文章,
handoffs=[{agent_id: specialist.id, name: writer}],
)
经验总结
- - 交接保留对话上下文 — 无需重新注入背景信息
- 工具绑定到编排器,而非委托智能体 — 委托智能体可以请求工具调用,但执行发生在编排器的上下文中
- 4个智能体是黑客松范围的最佳数量 — 更多智能体意味着更多API调用和更多协调开销,但价值不成比例
- 委托智能体上的JSON模式 强制结构化输出 — 没有它,Mistral Large有时会返回散文而非场景数组
文件
- - scripts/orchestrator.py — 完整的编排器实现,包括智能体注册、对话管理和交接委派
- references/agent-patterns.md — 常见的多智能体模式及其适用场景
安全说明
此技能使用的模式可能触发自动化安全扫描器:
- - base64:用于编码API响应中的音频/二进制数据(媒体API的标准做法)
- UploadFile:FastAPI内置的文件上传参数,用于STT/语音隔离端点
- system prompt:指配置智能体指令,而非提示注入