🌐 [S2技术博客] 📄 [S2论文] 🎥 [S2演示视频]
🌐 [S1技术博客] 📄 [S1论文(ICLR 2025)] 🎥 [S1演示视频]
欢迎使用Agent S——一个通过Agent-Computer Interface实现计算机自主交互的开源框架。我们的目标是构建能通过历史经验学习、在计算机上自主执行复杂任务的智能GUI智能体。
无论您对AI、自动化感兴趣,还是希望参与前沿智能体系统开发,我们都期待您的加入!
Agent S2在OSWorld完整测试集上仅使用屏幕截图输入的成功率(%)表现
基准测试 | Agent S2 | 原SOTA | 提升幅度 |
---|---|---|---|
OSWorld (15步) | 27.0% | 22.7% (UI-TARS) | +4.3% |
OSWorld (50步) | 34.5% | 32.6% (OpenAI CUA) | +1.9% |
WindowsAgentArena | 29.8% | 19.5% (NAVI) | +10.3% |
AndroidWorld | 54.3% | 46.8% (UI-TARS) | +7.5% |
❗警告❗:Linux系统下使用
conda
环境会干扰pyatspi
。目前尚无完美解决方案,请直接安装而不使用conda
或任何虚拟环境。
⚠️声明⚠️:为发挥Agent S2全部潜力,我们使用UI-TARS作为视觉定位模型(7B-DPO或72B-DPO可获得更佳性能)。该模型可本地部署或通过Hugging Face Inference Endpoints调用。我们的代码支持Hugging Face Inference Endpoints,详见Hugging Face企业级专用终端。但运行Agent S2并非必须此模型,您也可选用Claude等API模型进行视觉定位。
安装包:
pip install gui-agents
设置LLM API密钥等环境变量。可通过在.bashrc(Linux)或.zshrc(MacOS)文件中添加以下内容实现:
export OPENAI_API_KEY=<YOUR_API_KEY>
export ANTHROPIC_API_KEY=<YOUR_ANTHROPIC_API_KEY>
export HF_TOKEN=<YOUR_HF_TOKEN>
或在Python脚本中直接设置环境变量:
import os
os.environ["OPENAI_API_KEY"] = "<YOUR_API_KEY>"
我们还支持Azure OpenAI、Anthropic、Gemini、Open Router和vLLM推理。详见models.md。
Agent S结合网络知识检索表现最佳。启用此功能需配置Perplexica:
确保系统已安装并运行Docker Desktop
进入项目目录
cd Perplexica
git submodule update --init
将sample.config.toml
重命名为config.toml
。Docker部署只需填写以下字段:
OPENAI
:OpenAI API密钥(仅需在使用OpenAI模型时填写)OLLAMA
:Ollama API URL(格式为http://host.docker.internal:端口号
,默认11434端口)GROQ
:Groq API密钥(仅需使用Groq托管模型时填写)ANTHROPIC
:Anthropic API密钥(仅需使用Anthropic模型时填写)SIMILARITY_MEASURE
:相似度度量方式(默认已填充,不确定时可保持原样)确保位于含docker-compose.yaml
文件的目录后执行:
docker compose up -d
根据docker-compose.yaml文件中app/ports
下的端口号(左侧数字)设置环境变量:
export PERPLEXICA_URL=http://localhost:{端口号}/api/search
Agent S通过Perplexica API集成搜索引擎功能。如需自定义配置,可修改agent_s/query_perplexica.py
中的请求参数。完整配置指南参见Perplexica搜索API文档。详细使用说明请参考Perplexica代码库。
❗警告❗:本智能体会直接运行Python代码控制您的计算机,请谨慎使用。
注意:最佳配置为Claude 3.7扩展思维模式+UI-TARS-72B-DPO。若资源不足,UI-TARS-7B-DPO可作为轻量替代方案,性能下降有限。
使用指定模型运行Agent S2(默认为gpt-4o
):
agent_s2 \
--provider "anthropic" \
--model "claude-3-7-sonnet-20250219" \
--grounding_model_provider "anthropic" \
--grounding_model "claude-3-7-sonnet-20250219" \
或使用自定义终端:
agent_s2 \
--provider "anthropic" \
--model "claude-3-7-sonnet-20250219" \
--endpoint_provider "huggingface" \
--endpoint_url "<endpoint_url>/v1/"
--provider
, --model
--provider "anthropic" --model "claude-3-7-sonnet-20250219"
--model_url
, --model_api_key
可选择配置方案1或2:
--grounding_model_provider
, --grounding_model
--grounding_model_provider "anthropic" --grounding_model "claude-3-7-sonnet-20250219"
--grounding_model_resize_width
--grounding_model_resize_width 1366
(Anthropic)--endpoint_provider
--endpoint_url
--endpoint_api_key
注意:配置方案2优先级高于方案1。
运行后将显示查询提示框,您可输入指令与Agent S2交互。支持models.md列出的所有模型。
gui_agents
SDK开发首先导入必要模块。AgentS2
是主智能体类,OSWorldACI
是将智能体动作转换为可执行Python代码的定位代理。
import pyautogui
import io
from gui_agents.s2.agents.agent_s import AgentS2
from gui_agents.s2.agents.grounding import OSWorldACI
# Load in your API keys.
from dotenv import load_dotenv
load_dotenv()
current_platform = "linux" # "darwin", "windows"
接着定义引擎参数。engine_params
用于主智能体,engine_params_for_grounding
用于视觉定位。定位模块支持Claude、GPT系列及Hugging Face Inference Endpoints。
engine_params = {
"engine_type": provider,
"model": model,
"base_url": model_url, # Optional
"api_key": model_api_key, # Optional
}
# Grounding Configuration 1: Load the grounding engine from an API based model
grounding_model_provider = "<your_grounding_model_provider>"
grounding_model = "<your_grounding_model>"
grounding_model_resize_width = 1366
screen_width, screen_height = pyautogui.size()
engine_params_for_grounding = {
"engine_type": grounding_model_provider,
"model": grounding_model,
"grounding_width": grounding_model_resize_width,
"grounding_height": screen_height
* grounding_model_resize_width
/ screen_width,
}
# Grounding Configuration 2: Load the grounding engine from a HuggingFace TGI endpoint
endpoint_provider = "<your_endpoint_provider>"
endpoint_url = "<your_endpoint_url>"
endpoint_api_key = "<your_api_key>"
engine_params_for_grounding = {
"engine_type": endpoint_provider,
"base_url": endpoint_url,
"api_key": endpoint_api_key, # Optional
}
然后初始化定位代理和Agent S2实例。
grounding_agent = OSWorldACI(
platform=current_platform,
engine_params_for_generation=engine_params,
engine_params_for_grounding=engine_params_for_grounding
)
agent = AgentS2(
engine_params,
grounding_agent,
platform=current_platform,
action_space="pyautogui",
observation_type="screenshot",
search_engine="Perplexica", # Assuming you have set up Perplexica.
embedding_engine_type="openai" # Supports "gemini", "openai"
)
最后进行查询:
# Get screenshot.
screenshot = pyautogui.screenshot()
buffered = io.BytesIO()
screenshot.save(buffered, format="PNG")
screenshot_bytes = buffered.getvalue()
obs = {
"screenshot": screenshot_bytes,
}
instruction = "Close VS Code"
info, action = agent.predict(instruction=instruction, observation=obs)
exec(action[0])
详见gui_agents/s2/cli_app.py
了解推理循环实现细节。
Agent S2使用持续更新的知识库。初始化AgentS2
时会自动下载对应平台和版本(如s1/s2)的知识库,存储于GitHub Releases的assets中。如需编程式下载知识库,可使用以下代码:
download_kb_data(
version="s2",
release_tag="v0.2.2",
download_dir="kb_data",
platform="linux" # "darwin", "windows"
)
这将下载v0.2.2版本Linux平台知识库至kb_data
目录。完整知识库版本请参考GitHub Releases。
在OSWorld中部署Agent S2,请遵循OSWorld部署指南。
如果本代码库对您的研究有帮助,请引用:
@misc{Agent-S2,
title={Agent S2: A Compositional Generalist-Specialist Framework for Computer Use Agents},
author={Saaket Agashe and Kyle Wong and Vincent Tu and Jiachen Yang and Ang Li and Xin Eric Wang},
year={2025},
eprint={2504.00906},
archivePrefix={arXiv},
primaryClass={cs.AI},
url={https://arxiv.org/abs/2504.00906},
}
@inproceedings{Agent-S,
title={{Agent S: An Open Agentic Framework that Uses Computers Like a Human}},
author={Saaket Agashe and Jiuzhou Han and Shuyu Gan and Jiachen Yang and Ang Li and Xin Eric Wang},
booktitle={International Conference on Learning Representations (ICLR)},
year={2025},
url={https://arxiv.org/abs/2410.08164}
}