A Python project depending on minion
Project description
MinionCodeAgent
一个增强的AI代码助手,基于Minion框架构建,预配置了丰富的开发工具,专为代码开发任务优化。
特性
- 🤖 智能代码助手:预配置的AI agent,专为编程任务设计
- 🔧 丰富的工具集:自动包含文件操作、命令执行、网络搜索等12+个工具
- ⚡ 即开即用:一行代码创建,无需复杂配置
- 📝 对话历史:内置对话历史跟踪和管理
- 🎯 优化提示:专为代码开发任务优化的系统提示
- 🛡️ 安全设计:内置安全检查,防止危险操作
安装
# 克隆仓库
git clone <repository-url>
cd minion-code
pip install -e .
快速开始
CLI使用
# 基本使用
mcode
# 指定工作目录
mcode --dir /path/to/project
# 启用详细输出
mcode --verbose
# 使用MCP配置文件加载额外工具
mcode --config mcp.json
# 组合使用
mcode --dir /path/to/project --config mcp.json --verbose
编程接口
import asyncio
from minion_code import MinionCodeAgent
async def main():
# 创建AI代码助手,自动配置所有工具
agent = await MinionCodeAgent.create(
name="My Code Assistant",
llm="gpt-4.1"
)
# 与AI助手对话
response = await agent.run_async("List files in current directory")
print(response.answer)
response = await agent.run_async("Read the README.md file")
print(response.answer)
asyncio.run(main())
自定义配置
# 自定义系统提示和工作目录
agent = await MinionCodeAgent.create(
name="Python Expert",
llm="gpt-4.1",
system_prompt="You are a specialized Python developer assistant.",
workdir="/path/to/project",
additional_tools=[MyCustomTool()]
)
查看可用工具
# 打印工具摘要
agent.print_tools_summary()
# 获取工具信息
tools_info = agent.get_tools_info()
for tool in tools_info:
print(f"{tool['name']}: {tool['description']}")
内置工具
MinionCodeAgent自动包含以下工具类别:
📁 文件和目录工具
- FileReadTool: 读取文件内容
- FileWriteTool: 写入文件
- GrepTool: 在文件中搜索文本
- GlobTool: 文件模式匹配
- LsTool: 列出目录内容
💻 系统和执行工具
- BashTool: 执行shell命令
- PythonInterpreterTool: 执行Python代码
🌐 网络和搜索工具
- WebSearchTool: 网络搜索
- WikipediaSearchTool: Wikipedia搜索
- VisitWebpageTool: 访问网页
🔧 其他工具
- UserInputTool: 用户输入
- TodoWriteTool: 任务管理写入
- TodoReadTool: 任务管理读取
MCP工具集成
MinionCodeAgent支持通过MCP (Model Context Protocol) 配置文件加载额外的工具。
MCP配置文件格式
创建一个JSON配置文件(如mcp.json):
{
"mcpServers": {
"chrome-devtools": {
"command": "npx",
"args": ["-y", "chrome-devtools-mcp@latest"],
"env": {
"FASTMCP_LOG_LEVEL": "ERROR"
},
"disabled": false,
"autoApprove": []
},
"filesystem": {
"command": "uvx",
"args": ["mcp-server-filesystem", "/tmp"],
"disabled": true,
"autoApprove": ["read_file", "list_directory"]
},
"git": {
"command": "uvx",
"args": ["mcp-server-git"],
"disabled": false,
"autoApprove": ["git_status", "git_log"]
}
}
}
配置选项说明
command: 启动MCP服务器的命令args: 命令参数列表env: 环境变量(可选)disabled: 是否禁用此服务器(默认false)autoApprove: 自动批准的工具名称列表(可选)
使用MCP配置
# 使用MCP配置文件
minion-code --config examples/mcp_config.json
# 查看加载的工具(包括MCP工具)
# 在CLI中输入: tools
编程接口中使用MCP工具
from minion_code.utils.mcp_loader import load_mcp_tools
from pathlib import Path
async def main():
# 加载MCP工具
mcp_tools = await load_mcp_tools(Path("mcp.json"))
# 创建包含MCP工具的agent
agent = await MinionCodeAgent.create(
name="Enhanced Assistant",
llm="gpt-4o-mini",
additional_tools=mcp_tools
)
对话历史管理
# 获取对话历史
history = agent.get_conversation_history()
for entry in history:
print(f"User: {entry['user_message']}")
print(f"Agent: {entry['agent_response']}")
# 清除历史
agent.clear_conversation_history()
与原始实现的对比
之前 (复杂的手动配置)
# 需要手动导入和配置所有工具
from minion_code.tools import (
FileReadTool, FileWriteTool, BashTool,
GrepTool, GlobTool, LsTool,
PythonInterpreterTool, WebSearchTool,
# ... 更多工具
)
# 手动创建工具实例
custom_tools = [
FileReadTool(),
FileWriteTool(),
BashTool(),
# ... 更多工具配置
]
# 手动设置系统提示
SYSTEM_PROMPT = "You are a coding agent..."
# 创建agent (约50行代码)
agent = await CodeAgent.create(
name="Minion Code Assistant",
llm="gpt-4o-mini",
system_prompt=SYSTEM_PROMPT,
tools=custom_tools,
)
现在 (使用MinionCodeAgent)
# 一行代码完成所有设置
agent = await MinionCodeAgent.create(
name="Minion Code Assistant",
llm="gpt-4o-mini"
)
API参考
MinionCodeAgent.create()
async def create(
name: str = "Minion Code Assistant",
llm: str = "gpt-4o-mini",
system_prompt: Optional[str] = None,
workdir: Optional[Union[str, Path]] = None,
additional_tools: Optional[List[Any]] = None,
**kwargs
) -> MinionCodeAgent
参数:
name: Agent名称llm: 使用的LLM模型system_prompt: 自定义系统提示(可选)workdir: 工作目录(可选,默认当前目录)additional_tools: 额外工具列表(可选)**kwargs: 传递给CodeAgent.create()的其他参数
实例方法
run_async(message: str): 异步运行agentrun(message: str): 同步运行agentget_conversation_history(): 获取对话历史clear_conversation_history(): 清除对话历史get_tools_info(): 获取工具信息print_tools_summary(): 打印工具摘要
属性
agent: 访问底层CodeAgent实例tools: 获取可用工具列表name: 获取agent名称
安全特性
- 命令执行安全:BashTool禁止执行危险命令(如
rm -rf、sudo等) - Python执行限制:PythonInterpreterTool在受限环境中执行,只允许安全的内置函数和指定模块
- 文件访问控制:所有文件操作都有路径验证和错误处理
示例
查看 examples/ 目录中的完整示例:
simple_code_agent.py: 基本MinionCodeAgent使用示例simple_tui.py: 简化的TUI实现advanced_textual_tui.py: 高级TUI界面(使用Textual库)minion_agent_tui.py: 原始复杂实现(对比参考)mcp_config.json: MCP配置文件示例test_mcp_config.py: MCP配置加载测试demo_mcp_cli.py: MCP CLI功能演示
运行示例:
# 基本使用示例
python examples/simple_code_agent.py
# 简单TUI
python examples/simple_tui.py
# 高级TUI (需要安装 textual: pip install textual rich)
python examples/advanced_textual_tui.py
# 测试MCP配置加载
python examples/test_mcp_config.py
# MCP CLI功能演示
python examples/demo_mcp_cli.py
文档
- MCP工具集成指南 - 详细的MCP配置和使用指南
贡献
欢迎提交Issue和Pull Request来改进这个项目!
许可证
MIT License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
minion_code-0.1.0.tar.gz
(82.7 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
minion_code-0.1.0-py3-none-any.whl
(103.5 kB
view details)
File details
Details for the file minion_code-0.1.0.tar.gz.
File metadata
- Download URL: minion_code-0.1.0.tar.gz
- Upload date:
- Size: 82.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e5647530444a5d435a9c672907dab7e23eea7c2b178328875b232525d3d336a5
|
|
| MD5 |
abff434e7bf0c72d3db1f0b845cd7cd6
|
|
| BLAKE2b-256 |
44e4cec55aa1c9de2e3f17c454ba6741d392388644a9acc1d49ef40ee5d5ae3b
|
File details
Details for the file minion_code-0.1.0-py3-none-any.whl.
File metadata
- Download URL: minion_code-0.1.0-py3-none-any.whl
- Upload date:
- Size: 103.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f1ea1d001ac60df129978efdd6ace93bf739d2d73b00205fdce0ce4177e878b4
|
|
| MD5 |
38714ba79958a9334eba3112e6c4ae7e
|
|
| BLAKE2b-256 |
18690bbdcbafaaceb63b8664f79efa33b328ef29666e87f363ac5cd788665d28
|