feat(M1): Agent 编排层(OpenAI 兼容)——DeepSeek 等第三方模型经 MCP 工具控制手机:工具桥转 function schema、截图图像转 image_url 多模态流、工具循环、CLI 入口(mock 验证通过)
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
"""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()
|
||||
Reference in New Issue
Block a user