Files

61 lines
1.9 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""Agent CLI:命令行给 AI 下指令控制手机。
用法:
export AGENT_API_KEY=sk-xxx # DeepSeek API Key
export AGENT_DEFAULT_SERIAL=192.168.20.66:5555 # 可选:默认设备
python -m mcp_agent.cli "打开抖音,搜索奚学东,截个图"
python -m mcp_agent.cli -s 192.168.20.66:5555 "打开微信"
python -m mcp_agent.cli # 交互模式(exit 退出)
"""
import argparse
import asyncio
import logging
import os
from mcp_agent.agent import Agent
logging.basicConfig(level=logging.INFO,
format="%(asctime)s %(levelname)s [%(name)s] %(message)s")
_log = logging.getLogger("cli")
async def _run_once(prompt, serial):
if not os.environ.get("AGENT_API_KEY") and not os.environ.get("DEEPSEEK_API_KEY"):
print("❌ 未配置 API Key:export AGENT_API_KEY=sk-xxx")
return
agent = Agent()
try:
await agent._load_tools()
print(f"🤖 指令: {prompt}\n")
answer = await agent.run(prompt, serial)
print(f"\n✅ 结果:\n{answer}")
finally:
await agent.close()
def main():
ap = argparse.ArgumentParser(description="MCP 手机控制 Agent CLI")
ap.add_argument("prompt", nargs="?", default="", help="指令(不填则交互模式)")
ap.add_argument("-s", "--serial", default="", help="目标设备 serial")
args = ap.parse_args()
if args.prompt:
asyncio.run(_run_once(args.prompt, args.serial))
return
print("交互模式:输入指令(如「打开抖音搜索奚学东」),exit 退出")
while True:
try:
prompt = input("\n指令> ").strip()
except (EOFError, KeyboardInterrupt):
break
if not prompt:
continue
if prompt.lower() in ("exit", "quit", "退出"):
break
asyncio.run(_run_once(prompt, args.serial))
if __name__ == "__main__":
main()