🤖 Windows AI代理
使用LLaMA 4+MCP风格工具的离线AI驱动的Windows控制系统
一个完全离线的桌面代理,可以通过自然语言控制您的Windows PC。受模型上下文协议(MCP)架构的启发,通过Ollama使用本地LLM推理构建。
✨ 特性
- 100%离线 -安装后不需要互联网
- 自然语言控制 -告诉它该怎么做
- 30+工具 -文件操作、应用程序控制、输入模拟等
- 设计安全 -破坏性行为的确认提示
- 可扩展 -易于添加新工具
🚀 快速开始
先决条件
- 奥拉玛 -从以下位置安装 奥拉玛
- Python 3.10+ -从以下位置安装 python.org
- LLaMA 4 -拉动模型:
ollama pull llama4安装
# Clone or extract the project
cd windows-ai-agent
# Install dependencies
pip install requests
# Optional: For Windows-specific features
pip install psutil pywin32
# Optional: For GUI
pip install PyQt6跑步
首先测试系统:
python test_system.pyCLI界面:
python main.pyGUI界面:
python ui/gui.py或者在Windows上,只需双击:
run_cli.bat-命令行界面run_gui.bat-图形界面run_test.bat-系统测试
📁 项目结构
windows-ai-agent/
├── main.py # Entry point
├── test_system.py # System verification
├── requirements.txt # Dependencies
│
├── core/ # Core types and utilities
│ └── types.py # Data classes and enums
│
├── config/ # Configuration
│ └── settings.py # Agent settings
│
├── llm/ # LLM integration
│ └── client.py # Ollama client
│
├── tools/ # Tool system
│ ├── server.py # MCP-style tool server
│ └── registry.py # Tool definitions
│
├── windows_control/ # Windows control layer
│ ├── filesystem.py # File operations
│ ├── processes.py # Process/app control
│ └── input.py # Keyboard/mouse
│
├── orchestrator/ # Agent intelligence
│ └── agent.py # Main agent logic
│
└── ui/ # User interfaces
├── cli.py # Command line
└── gui.py # PyQt6 GUI🔧 可用工具
文件系统
file_read-读取文件内容file_write-写入/创建文件file_delete-删除文件/文件夹file_copy-复制文件file_move-移动/重命名文件file_search-按名称/内容搜索file_info-获取文件元数据directory_list-列出文件夹内容directory_create-创建文件夹
应用程序
app_open-启动应用程序app_close-关闭应用程序app_list_installed-列出已安装的应用程序
过程
process_list-列出正在运行的进程process_info-获取流程详细信息process_kill-终止进程
视窗
window_list-列出打开的窗口window_focus-聚焦窗口window_minimize-最小化窗口window_maximize-最大化窗口window_close-关闭窗口
输入
keyboard_type-键入文本keyboard_press-按键keyboard_hotkey-按键组合mouse_click-点击鼠标mouse_move-移动光标mouse_scroll-滚轮mouse_drag-拖动操作mouse_position-获取光标位置
剪贴板
clipboard_get-获取剪贴板文本clipboard_set-设置剪贴板文本clipboard_clear-清除剪贴板
💡 示例用法
You: Open notepad
🤖 I'll open Notepad for you.
🔧 Executing: app_open
✅ Success
🤖 Notepad is now open!
You: List files in my Documents folder
🤖 Let me check your Documents folder.
🔧 Executing: directory_list
✅ Success
🤖 Found 15 items in your Documents folder:
- report.docx (2.3 MB)
- photos/ (folder)
...
You: Create a new folder called "Projects" on my desktop
🤖 I'll create that folder for you.
🔧 Executing: directory_create
✅ Success
🤖 Created "Projects" folder on your desktop!⚙️ 配置
编辑 config/settings.py 或创建 config/agent_config.json:
{
"llm": {
"model": "llama4",
"base_url": "http://localhost:11434",
"temperature": 0.7,
"max_tokens": 4096
},
"security": {
"default_permission_tier": "operator",
"tools_requiring_confirmation": [
"file_delete",
"process_kill"
]
}
}🔒 安全
- 受保护的路径:无法修改C:\\Windows程序文件
- 确认:破坏性行动需要批准
- 权限级别:观察员→ 操作员→ 管理员→ 系统
- 审计跟踪:记录所有操作
🛠️ 故障排除
“无法连接到Ollama”
# Make sure Ollama is running
ollama serve
# Check if model is available
ollama list“找不到模型”
# Pull the model
ollama pull llama4
# Or try a specific version
ollama pull llama4:latest“工具执行失败”
- 检查您是否拥有必要的权限
- 某些工具需要Windows上的管理员权限
- 安装
psutil和pywin32实现完整功能
📝 添加自定义工具
在中创建新工具 tools/registry.py:
# Add to create_all_tools() function
tools.append((
create_tool_schema(
name="my_custom_tool",
description="Description of what it does",
category=ToolCategory.SYSTEM,
risk_level=RiskLevel.LOW,
parameters=[
{"name": "param1", "type": "string", "description": "Parameter description"},
],
),
lambda args: {"result": {"success": True, "data": args["param1"]}}
))🗺️ 路线图
- \[\]语音输入(耳语)
- \[\]语音输出(TTS)
- \[\]UI自动化(按名称单击按钮)
- \[\]屏幕截图分析
- \[\]内存/上下文持久性
- \[\]多步骤任务规划
- \[\]插件系统
📜 许可证
MIT许可证-可自由用于个人和商业项目。
🙏 积分
- 奥拉玛 -本地LLM推理
- 羊驼 -Meta的语言模型
- 人类MCP -协议灵感
______________________________________________________________________
建于❤️ 用于离线AI自动化
