必须使用MiniMax M2.5原生Agent框架而非M2.7通用接口,严格匹配Python 3.11.7、minimax-m25-cli==2.5.3和protobuf==4.21.12,正确配置config.yaml endpoint为v2/m25及coordination.yaml技能标签,并确保Bot skill_tags完全一致才能实现多Bot协同调度。
☞☞☞AI 智能聊天, 问答助手, AI 智能搜索, 多模态理解力帮你轻松跨越从0到1的创作门槛☜☜☜

要在Python项目中调用MiniMax Agent API实现多Bot协同、任务分解与自动调度,必须绕过M2.7通用接口的限制,改用M2.5原生Agent框架——填错endpoint或漏传coordination参数会导致1004错误且无明确提示。
确认环境与版本依赖
MiniMax M2.5 Agent CLI工具对Python和protobuf版本极其敏感,用错版本会直接报ModuleNotFoundError或Segmentation Fault。
执行sudo apt update && sudo apt install -y python3.11 python3.11-venv python3-pip(Ubuntu/WSL2)或brew install python@3.11(macOS),确保系统级Python为3.11.7。
创建独立虚拟环境:python3.11 -m venv agent_env && source agent_env/bin/activate(Linux/macOS)或agent_env\Scripts\activate.bat(Windows)。
立即学习“Python免费学习笔记(深入)”;
安装指定版本CLI工具:pip install minimax-m25-cli==2.5.3。注意:用==2.5.3而非>=2.5.3,高版本会 silently 跳过coordination配置校验。
【必须降级protobuf至4.21.12】否则CLI初始化时会在解析YAML schema阶段崩溃,命令为pip install protobuf==4.21.12。
初始化Agent项目结构
运行m25init命令后,自动生成标准目录树:
├── config/(含config.yaml和coordination.yaml)
├── bots/(每个Bot子目录含__init__.py和main.py)
├── tools/(自定义函数必须继承BaseTool类)
└── deploy/(含Dockerfile和healthcheck.sh)
检查生成结果:ls -R | grep -E "^(config|bots|tools|deploy)|\.yaml$",若缺失coordination.yaml,说明CLI版本不对或网络未连通控制台。
配置Agent核心参数
编辑config/config.yaml,关键字段必须严格按以下格式填写:
platform:
api_key: "ak-xxxxxxxxxxxxxxxxxxxxxxxx"
endpoint: "https://api.minimax.com/v2/m25"
coordination:
mode: "dynamic"
max_concurrent_bots: 5
【endpoint必须是v2/m25,填v1或v1/text/chatcompletion_v2将返回1004】这是M2.5 Agent专属路径,与M2.7通用API完全隔离。
在config/coordination.yaml中声明Bot技能标签:skills:
- code_gen
- data_query
- doc_summarize。这些标签将用于后续任务分配时的路由匹配。
编写第一个可调度Bot
在bots/code_gen/main.py中写入:
from minimax_m25.bot import Bot
class CodeGenBot(Bot):
def __init__(self):
super().__init__(skill_tags=["code_gen"])
def run(self, task: dict) -> str:
return f"Generated {task.get('language', 'Python')} snippet for {task.get('purpose', 'unknown')}"
注意:skill_tags值必须与coordination.yaml中定义的标签完全一致,大小写敏感,多一个空格都会导致调度失败。
在bots/__init__.py中显式导入:from .code_gen.main import CodeGenBot。不加这行,CLI启动时无法发现Bot实例。
启动本地Agent服务
第一步:加载环境变量并验证凭证有效性
export MINIMAX_API_KEY="ak-xxxxxxxxxxxxxxxxxxxxxxxx"
echo $MINIMAX_API_KEY | wc -c → 应输出65(含换行符),少于65说明密钥截断。
第二步:运行服务监听端口
m25 serve --host 0.0.0.0:8000 --reload。服务启动后访问http://localhost:8000/docs可查看OpenAPI文档。
第三步:发送测试调度请求
curl -X POST "http://localhost:8000/v2/agent/task" \
-H "Content-Type: application/json" \
-d '{"task": "write a Python function to calculate Fibonacci", "skill_requirement": "code_gen"}'
响应体中status字段为completed且result非空,即表示Agent调度链路已通。


















