Record, train, and deploy from one place with Strands Agents, LeRobot, and Hugging Face Storage Buckets
Record, train, and deploy from one place with Strands Agents, LeRobot, and Hugging Face Storage Buckets
使用 Strands Agents、LeRobot 和 Hugging Face Storage Buckets 实现从记录、训练到部署的一站式流程
A walkthrough of the streaming data loop in Strands Robots, one agent loop that records robot demonstrations, trains on them by reading straight from the Hub, and deploys the policy back to hardware, with the dataset in the same on-disk LeRobot format the whole way through. 本文将带您了解 Strands Robots 中的流式数据循环。这是一个代理循环,它能够记录机器人演示,通过直接从 Hub 读取数据进行训练,并将策略部署回硬件,且整个过程中数据集始终保持相同的 LeRobot 磁盘格式。
You have an agent that can already record a demonstration and push it to the Hugging Face Hub. Now you want to run that loop continuously: collect episodes through the day, train a policy on the growing dataset, deploy it, and pull the next batch back to improve it. Run that loop once and every piece works. Run it every day and you start paying for the same byte transfers over and over. The recordings you upload keep growing, each training run copies the whole dataset to the GPUs before it starts, and every new checkpoint ships out while the next batch of recordings comes back. 假设您已经拥有一个可以记录演示并将其推送到 Hugging Face Hub 的代理。现在,您希望持续运行该循环:全天收集片段、在不断增长的数据集上训练策略、进行部署,并拉取下一批数据以进行优化。运行一次该循环,一切都能正常工作;但如果每天运行,您将开始为重复的字节传输支付费用。您上传的录制内容不断增加,每次训练运行前都会将整个数据集复制到 GPU,并且在新的录制批次返回的同时,每个新的检查点(checkpoint)也需要被分发出去。
The first post in this series introduced Strands Robots, an open source SDK from AWS (Apache 2.0) that exposes robot abstractions, simulation, and the LeRobot stack as AgentTools you compose into a single Strands agent. It covered the Robot() factory, recording a demonstration in simulation, running a policy, and deploying the same agent code to a physical SO-101. That factory resolves a name against a registry of arms, humanoids, mobile bases, and hands, so the SO-100 used throughout this post is one of many supported embodiments. The robot catalog lists every robot the factory knows about. 本系列的第一篇文章介绍了 Strands Robots,这是一个来自 AWS 的开源 SDK(Apache 2.0 协议),它将机器人抽象、仿真和 LeRobot 堆栈作为 AgentTools 公开,您可以将其组合成一个单一的 Strands 代理。该文章涵盖了 Robot() 工厂、在仿真中记录演示、运行策略以及将相同的代理代码部署到物理 SO-101 机器人上。该工厂通过名称在机械臂、人形机器人、移动底座和手部装置的注册表中进行解析,因此本文中使用的 SO-100 只是众多支持的实体之一。机器人目录列出了工厂已知的所有机器人。
LeRobot’s dataset format is already used by over 90,000 datasets and models on the Hub from more than 8,000 publishers (LeRobot Project Pulse). A Strands Robots recording is one more of them, so anything built to read LeRobot data can read it without conversion. If you are new to Strands Robots, start there; this post assumes that setup. LeRobot 的数据集格式已被 Hub 上超过 8,000 个发布者的 90,000 多个数据集和模型所使用(LeRobot Project Pulse)。Strands Robots 的录制内容也是其中之一,因此任何构建用于读取 LeRobot 数据的工具都无需转换即可直接读取它。如果您是 Strands Robots 的新手,请从那里开始;本文假设您已经完成了相关设置。
That post followed the agent loop in one direction, from a Hub dataset to a physical robot. This one follows the data the other way, from the first recorded frame back to the deployed policy, over Hugging Face Storage Buckets - a mutable, non-versioned, Xet-backed object-storage repository type announced in March 2026. A bucket sits beside your dataset repositories in the same hf:// namespace and uses the hf CLI you already have, so it becomes the working layer that holds your data between the day you record it and the day you train on it. 上一篇文章沿着代理循环的一个方向进行,即从 Hub 数据集到物理机器人。而本文则沿着相反的方向追踪数据,从第一个录制的帧一直到部署的策略,通过 Hugging Face Storage Buckets 实现——这是一种在 2026 年 3 月宣布的、基于 Xet 的可变、非版本化的对象存储仓库类型。Bucket 位于您的数据集仓库旁边,处于相同的 hf:// 命名空间中,并使用您现有的 hf CLI,因此它成为了连接录制当天与训练当天之间的数据工作层。
Someone has to decide which episodes to keep, when the scene has drifted far enough to re-record, whether today’s batch is enough to train on, and which checkpoint replaces the one on the arm. Each of those decisions comes up dozens of times over a collection campaign, and each one needs a look at what came back before the next command goes out. That is the work an agent is for. 总得有人决定保留哪些片段、何时场景偏移到需要重新录制、今天的批次是否足以进行训练,以及哪个检查点应该替换机械臂上的旧版本。在整个数据收集活动中,每一个决策都会出现数十次,且在发出下一个指令之前,都需要查看返回的数据。这就是代理(Agent)存在的意义。
This post walks you through the data loop inside a single agent: record a demonstration into a Storage Bucket, store it so that each sync uploads only the bytes that changed, train by streaming the dataset straight from the Hub instead of downloading it, and deploy the checkpoint back to hardware with one keyword argument change. The runnable companion to this post lives at examples/notebooks/05_streaming_data_loop.ipynb.
本文将引导您完成单个代理内部的数据循环:将演示记录到 Storage Bucket 中,通过存储机制确保每次同步仅上传发生变化的字节,通过直接从 Hub 流式传输数据集进行训练(无需下载),并仅通过更改一个关键字参数将检查点部署回硬件。本文配套的可运行代码位于 examples/notebooks/05_streaming_data_loop.ipynb。
What you’ll build
您将构建什么
Where the first post recorded a dataset and pushed it to the Hub, the agent you build here records a LeRobotDataset from a natural-language prompt, syncs it into a Storage Bucket, and streams that same dataset back frame by frame, decoding camera video on the fly, with no local copy. You read it back in the same process that wrote it: the same Strands Robots Robot() that recorded the dataset streams it. Your trained checkpoint then deploys to that same Robot() with one keyword argument change, and the demonstrations it records on hardware return to the same bucket. 与第一篇文章记录数据集并将其推送到 Hub 不同,您在此处构建的代理将根据自然语言提示记录 LeRobotDataset,将其同步到 Storage Bucket,并逐帧流式传输该数据集,实时解码摄像机视频,且无需本地副本。您将在写入数据的同一个进程中读取它:即记录数据集的同一个 Strands Robots Robot() 对象来流式传输它。随后,您训练好的检查点只需更改一个关键字参数即可部署到同一个 Robot() 对象上,并且它在硬件上记录的演示内容会返回到同一个 Bucket 中。
Figure 1. The four stages share one backend. Robot(“so100”) records a LeRobotDataset through the shared DatasetRecorder; sync_dataset_to_bucket(…) syncs it into a Storage Bucket; stream_dataset(…) reads it back over the Hub with no full download; and the trained checkpoint deploys to the same Robot with mode=“real”. The on-disk format stays exactly as LeRobot wrote it. 图 1. 四个阶段共享同一个后端。Robot(“so100”) 通过共享的 DatasetRecorder 记录 LeRobotDataset;sync_dataset_to_bucket(…) 将其同步到 Storage Bucket;stream_dataset(…) 通过 Hub 读取数据而无需完整下载;训练好的检查点以 mode=“real” 部署到同一个机器人上。磁盘格式与 LeRobot 写入时完全一致。
Because one Robot() both records a dataset and reads it back, collecting data and training on it are two methods on one object over one backend. The agent decides to run an episode and invokes one tool; the rollout then proceeds at the robot’s control frequency until the episode ends, with the trained policy producing every action. 由于同一个 Robot() 对象既负责记录数据集又负责读取它,因此数据收集和训练成为了同一个后端上同一个对象的两个方法。代理决定运行一个片段并调用一个工具;随后,执行过程将以机器人的控制频率进行,直到片段结束,期间由训练好的策略产生每一个动作。
The whole loop, in a handful of lines: 整个循环只需几行代码:
from strands import Agent
from strands_robots import Robot
sim = Robot("so100") # mode="sim" (default - safe, no hardware)
agent = Agent(tools=[sim])
# Record a demonstration and sync it to a bucket.
agent("Record a pick-the-cube demo and sync it to my-org/robot-fave.")
# Stream it back from the bucket to train, without downloading it first.
for batch in sim.stream_dataset("my-org/robot-fave/cube_pick", repo_type="bucket").dataloader(batch_size=64):
...
What follows is what’s actually happening inside that loop, step by step. 接下来将逐步解析该循环内部实际发生的过程。
Prerequisites
前置条件
- Minimal (default simulation path) Python 3.12+, on Linux or macOS (Apple Silicon supported for the MuJoCo backend).
- 最低要求(默认仿真路径):Python 3.12+,运行于 Linux 或 macOS(MuJoCo 后端支持 Apple Silicon)。
- A Strands-compatible model provider for the agent’s reasoning. Amazon Bedrock with AWS credentials, the Anthropic API, OpenAI, or Ollama running locally.
- 一个与 Strands 兼容的模型提供商,用于代理的推理。包括带有 AWS 凭证的 Amazon Bedrock、Anthropic API、OpenAI 或本地运行的 Ollama。
- Strands Robots with the dataset extras:
uv pip install -U "strands-robots[sim-mujoco,lerobot]>=0.5.1". The lerobot extra pulls in LeRobot (>=0.6.1), datasets, av, and torchcodec, so recording and video decode both work without further setup. Refer to installation guide. - 带有数据集扩展的 Strands Robots:
uv pip install -U "strands-robots[sim-mujoco,lerobot]>=0.5.1"。lerobot 扩展会引入 LeRobot (>=0.6.1)、datasets、av 和 torchcodec,因此录制和视频解码无需额外设置即可工作。请参考安装指南。
That’s it. Every stage in this post runs on a laptop with… 就是这样。本文中的每个阶段都可以在一台笔记本电脑上运行……