AutoGLM 中文文档 下载 App

AutoGLM Python API 基础用法

基本思路

命令行 python main.py ... 其实就是对 Python API 的一个简单封装。想把 Agent 嵌入自己的项目(比如定时任务、Web 服务、批量自动化平台),直接用 phone_agent 包就行。

最小可用代码

from phone_agent import PhoneAgent
from phone_agent.model import ModelConfig

# 配置模型服务
model_config = ModelConfig(
    base_url="http://localhost:8000/v1",
    model_name="autoglm-phone-9b",
)

# 创建 Agent 实例
agent = PhoneAgent(model_config=model_config)

# 执行任务(会阻塞直到完成)
result = agent.run("打开美团搜索附近的火锅店")
print(result)

就是这几行。agent.run() 是同步阻塞调用,内部跑完整的 Agent 主循环。返回值包含任务是否成功、执行了多少步、最终的屏幕截图路径等信息。

Android 设备(ADB)

from phone_agent.model import ModelConfig
from phone_agent.agent import AgentConfig
from phone_agent import PhoneAgent

model_config = ModelConfig(
    base_url="http://localhost:8000/v1",
    model_name="autoglm-phone-9b",
)

agent_config = AgentConfig(
    lang="cn",          # 中文系统提示词
    verbose=True,       # 打印思考链和每步动作
)

agent = PhoneAgent(
    model_config=model_config,
    agent_config=agent_config,
)

result = agent.run("打开淘宝搜索无线耳机")

HarmonyOS 设备(HDC)

from phone_agent.model import ModelConfig
from phone_agent.agent import AgentConfig
from phone_agent import PhoneAgent

model_config = ModelConfig(
    base_url="http://localhost:8000/v1",
    model_name="autoglm-phone-9b",
)

agent_config = AgentConfig(
    device_type="hdc",  # 关键:指定鸿蒙设备
    lang="cn",
    verbose=True,
)

agent = PhoneAgent(
    model_config=model_config,
    agent_config=agent_config,
)

result = agent.run("打开微信发送消息")

配置对象详解

ModelConfig(模型层):

字段说明默认
base_url模型服务地址http://localhost:8000/v1
model_name模型名称autoglm-phone-9b
api_key认证 Key(如需要)EMPTY
max_tokens最大输出 token 数3000
temperature采样温度(越低越稳定)0.1
frequency_penalty频率惩罚0.2

AgentConfig(Agent 层):

字段说明默认
max_steps每个任务最大步数100
device_typeadb / hdc / wdaadb
device_id指定设备(None = 自动检测)None
langcn / encn
verbose调试输出False

处理结果

agent.run() 返回的 result 对象包含:

相关阅读