尧图网络科技YAOTU DIGITAL 获取报价
获取报价
首页 / 资讯中心 / 文章详情

一个接口切换多家 AI 模型:CUA ComputerAgent 使用指南

发布时间:2026/9/6 21:52:42

资讯中心
01
ARTICLE

一个接口切换多家 AI 模型:CUA ComputerAgent 使用指南

一个接口切换多家 AI 模型:CUA ComputerAgent 使用指南
一个接口切换多家 AI 模型CUA ComputerAgent 使用指南【免费下载链接】cuaScale computer-use 2.0 with open-source drivers, cross-OS fleets, and benchmarks for training, evaluation, and data generation.项目地址: https://gitcode.com/GitHub_Trending/cua/cua用 CUA 的ComputerAgent本地小模型和云端大模型接进同一套调用逻辑切换后端时业务代码一行不用动。先跑起来当脚本既要调云端大模型、又要跑本地小模型时各家接口的差异会先咬住你。ComputerAgent的思路是把模型差异压进一个model参数写代码时不关心后端是谁框架按名字自动选对应的调用循环。模块各管一段cua_agent统一调度解析模型名、执行工具调用、管理回调computer桌面操作本体代理靠它截图、点击、输入本地模型走ollama_chat/前缀由你本机的 ollama 服务承载安装和运行环境git clone https://gitcode.com/GitHub_Trending/cua/cua cd cua/libs/python uv sync # 没有 uv 就 pip install cua最小示例只关心四样东西模型、工具、日志级别、轨迹目录。import logging from computer import Computer from cua_agent import ComputerAgent computer Computer(os_typemacos) agent ComputerAgent( modelopenai/computer-use-preview, tools[computer], verbositylogging.INFO, trajectory_dirtrajectories, )三个最值钱的用法给代理添一个自己的工具把普通 Python 函数变成模型能调用的工具sandboxed()负责把它扔进沙箱执行模型乱来也伤不到你本机。from computer.helpers import sandboxed sandboxed() def read_file(location: str) - str: 读取文件内容并返回给模型 with open(location) as f: return f.read() agent ComputerAgent(modelanthropic/claude-sonnet-4-5-20250929, tools[computer, read_file])函数签名和 docstring 会被框架自动整理成工具调用规范模型据此决定何时调用、传什么参数。给对话历史瘦身多轮操作之后历史里堆着大量截图token 和延迟都跟着涨。only_n_most_recent_images让框架自动只保留最近 N 张更早的压缩掉agent ComputerAgent( modelopenai/computer-use-preview, tools[computer], only_n_most_recent_images3, )截图密集的长任务里这一项比换更便宜的模型更直接地省 token。设预算、留轨迹两个参数分别管钱和记录预算超限后代理自己刹车轨迹目录存下每步截图与模型响应方便事后复跑。agent ComputerAgent( modelanthropic/claude-sonnet-4-5-20250929, tools[computer], max_trajectory_budget{max_budget: 1.0, raise_error: True}, trajectory_dirtrajectories, use_prompt_cachingTrue, )use_prompt_caching配合 Anthropic 后端效果最好重复的提示内容不再反复计费。本地模型、云端模型、复合模型怎么选先看这张表模型写法适合场景备注openai/computer-use-preview复杂桌面操作云端 API按量计费anthropic/claude-sonnet-4-5-20250929推理强的任务可叠加 prompt cachingollama_chat/ui-tars-1.5-7b离线、数据不出内网本地模型部署需先跑起 ollamahuggingface-local/ByteDance-Seed/UI-TARS-1.5-7B免装 ollama 的本地方案从 Hugging Face 直接加载omniparser任意模型截图解析要求高的场景先结构化解析截图再交给模型决策完整列表见 libs/python/agent/example.py。跑一个端到端的数据分析流目标让代理自己读一份 CSV、调工具做统计、产出报告。下面这段把工具、预算、轨迹都配齐了import asyncio from computer.helpers import sandboxed from computer import Computer from cua_agent import ComputerAgent # 先定义一个沙箱工具读 CSV 并汇总销售额 sandboxed() def summarize_csv(path: str) - str: 读取销售 CSV返回总销售额 import csv with open(path) as f: rows list(csv.DictReader(f)) total sum(float(r[amount]) for r in rows) return f总销售额: {total:.2f} computer Computer(os_typemacos) # 配齐模型、工具、轨迹目录、预算、图片保留策略 agent ComputerAgent( modelanthropic/claude-sonnet-4-5-20250929, tools[computer, summarize_csv], trajectory_dirtrajectories/sales, only_n_most_recent_images3, max_trajectory_budget{max_budget: 0.5, raise_error: True}, use_prompt_cachingTrue, ) history [] # 任务按步骤追加每步执行完把产出拼回历史 for task in [ 调用 summarize_csv 读取 /data/sales/q1.csv, 按月份汇总并标出异常值, 把结论写入 /reports/q1_summary.md, ]: history.append({role: user, content: task}) async for result in agent.run(history): history result[output]跑完打开trajectories/sales能看到每一步的截图和动作。想看回放效果轨迹查看器相关博客 blog/trajectory-viewer.md 有说明。踩坑与调优预算超了怎么办把max_trajectory_budget的max_budget调小或降低only_n_most_recent_images两者都会直接压成本。长任务历史太长only_n_most_recent_images已经截掉旧截图再配合max_trajectory_budget双保险。本地模型起不来确认 ollama 服务在跑且模型已拉取huggingface-local/前缀是另一条本地通路。截图看错元素给模型名加omniparser前缀先结构化解析截图再决策定位会准不少。想逐步排查verbosity从logging.INFO调到logging.DEBUG每步的工具调用都会打出来。ComputerAgent把各家模型和工具调用压在一个接口后面换后端只改model字符串轨迹和预算让批量跑任务时成本有上限、问题可回放。生产化之前建议先用几个评估任务量一次成功率。官方文档入口docs/content/docs多模型配置示例libs/python/agent完整用法样例libs/python/agent/example.py有踩坑经验或改进建议欢迎直接提 Issue 或提交 PR。【免费下载链接】cuaScale computer-use 2.0 with open-source drivers, cross-OS fleets, and benchmarks for training, evaluation, and data generation.项目地址: https://gitcode.com/GitHub_Trending/cua/cua创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考
02
RELATED NEWS

相关资讯

更多网站建设与数字化升级内容

03
WHY YAOTU

想打造同款高转化官网?

懂行业、懂生意,从建站到增长一站式陪跑

场景化定制

不做模板站,围绕你的业务场景量身设计,小众不撞款。

营销型架构

以转化目标组织内容与路径,让官网真正带来询盘。

全周期服务

设计、开发、运营、运维一体,上线只是开始。

免费获取你的建站方案

留下需求,专属顾问 24 小时内为你输出方案建议。