读见

让大脑与双手解耦:Claude Managed Agents(第 1 部分)|Anthropic

原题Decoupling the Brain from the Hands: Claude Managed Agents (Part 1 of 4) — Anthropic

约 14 分钟原文英文已翻译

视频由 YouTube 提供

推荐理由长任务的沙箱坏了,已经完成的工作能否保住?Anthropic 平台建设者回顾把会话日志、智能体循环和执行环境拆开的过程,让开发者看清恢复、上下文压缩与凭证隔离为何需要不同的系统边界。读完可以检查自己的架构是否允许模型和执行环境分别演进。

看前速览

3 个要点

Anthropic 工程师解释 Claude Managed Agents 为何把会话历史、智能体循环和执行环境拆开,以改善恢复能力、安全性与架构弹性。

  1. 最初的单容器架构难以运维。

    把循环、状态与执行环境放在同一个长寿命容器里,产品扩展后带来故障恢复和迁移难题。

  2. 新设计拆开持久历史、智能体循环和执行环境。

    追加式会话事件日志、独立运行框架及可替换的沙箱或工具接口,让系统无需改写旧事件就能调整压缩策略并恢复任务。

  3. 凭证和模型假设应留在明确的边界内。

    凭证不进入执行沙箱可降低提示注入风险;稳定接口则允许运行框架随模型能力变化而调整。

完整摘要

Anthropic 托管智能体团队回顾了一次具体的架构转向。早期方案把智能体循环、状态和沙箱放在同一个容器中,长寿命智能体因此像需要人工照看的「宠物」,故障恢复和迁移都很困难。新版设计将追加式会话日志、运行框架中的智能体循环以及可替换的执行环境分开。这样既能从持久事件恢复运行,也能调整上下文压缩策略而不改写历史,并把任务送往沙箱、客户 VPC 或 MCP 工具。凭证不进入沙箱,以降低提示注入风险。讲者进一步指出,模型能力变化会让运行框架的假设过时,因此稳定接口比固定封装更重要。后续 API 演示创建智能体、环境和会话,并展示事件流。这段内容包含一手架构取舍、失败复盘和安全边界,是工作坊技术密度最高的一段。

章节

文字稿

查看原文

简要说明Brief Description

将大脑与双手解耦:Claude 托管智能体(四部曲之第一部)——AnthropicDecoupling the Brain from the Hands: Claude Managed Agents (Part 1 of 4) — Anthropic

目录Table of Contents

  • 欢迎与自我介绍
    Welcome and intros
  • 研讨会日程
    Workshop agenda
  • 智能体如何运作
    What makes an agent work
  • 测试框架与模型假设
    Harnesses and model assumptions
  • 沙箱与限制爆炸半径
    Sandboxes and limiting blast radius
  • 第一种架构:全部部署在一个容器中
    First architecture: all in one container
  • 宠物还是牲畜的问题
    The pet vs cattle problem
  • 将大脑与双手解耦
    Decoupling the brain from the hands
  • 将凭据保留在沙箱之外
    Keeping credentials out of the sandbox
  • 灵活压缩,更快输出首个令牌
    Flexible compaction, faster first token
  • 一个大脑,众多双手
    One brain, many hands
  • 接口比假设更经久耐用
    Interfaces outlast assumptions
  • 领取 API 额度
    Claiming API credits
  • 问答:三个核心接口
    Q&A: the three core interfaces
  • 构建一个讲笑话的智能体
    Building a joke-teller agent
  • 会话与事件流
    Sessions and the event stream
  • 控制台快速入门
    Console quick start

欢迎与自我介绍Welcome and intros

非常感谢大家参加。嗯,既然今天座无虚席,我们就开始吧。大家好,我叫 Priyanka,是 Anthropic 的技术团队成员。我负责领导开发云端托管智能体的工程团队,非常高兴今天能和大家交流,帮助大家部署自己的第一个托管智能体。我加入 Anthropic 已经两年多了,过去 12 个月里,我一直专注于构建智能体基础设施,也希望能和大家分享一些我们的经验。Thank you so much to everybody for for joining. Um I think we're going to get started given we have a have a full house. Um hi everyone. My name is Priyanka. I'm a member of technical staff at Enthropic. Uh I lead the engineering team that built cloud manage agents and I'm really excited to be here to talk to all of you uh and help you ship your first manage agent. I've been anthropic a little bit over two years and the last 12 months I've been focused on uh building um agentic infrastructure and hope to share some of our learnings with you.

主持人:呃,大家好,我叫 Gabe Semach。我是技术团队的一员,在 Priyanka 的团队负责构建云托管智能体。我加入 Anthropic 一年多了,这段时间基本上一直在做这项工作。Host: Uh hello my name is Gabe Semach. I'm a member of the technical staff uh building cloud managed agents in Priyanka team. I've been at Anthropic a little bit over a year and I've been mostly working on this my entire time.

研讨会日程Workshop agenda

嘉宾:好的,嗯,这就是我们的议程。我们会先简单回顾一下演进历程,讲讲我们如何构建并扩展托管式智能体,以及一路上遇到的一些陷阱和积累的经验。然后我们会进入动手环节。第一部分,我们会使用云平台控制台构建一个非常简单的智能体。这部分你不需要写任何代码。我们只要通过提示一步步搭建出第一个智能体,并测试一下。接下来我会把时间交给 Gabe,由他带大家进行动手实践。我们会使用 Cloud Code 或你喜欢的编程智能体编写代码,然后构建一个更复杂的金融智能体。最后会留出充足的时间进行问答。我们的时段有两个小时。我知道他们把内容分成了四个部分,但基本上这就是一场连贯的长篇演讲。Guest: All right. Um, so here is our agenda. We will kick it off with h a little bit of an evolution story of how we built and scaled managed agents, some of the pitfalls and the learnings that we had along the way. Then we'll switch to a hands-on part of the workshop. Uh the first part uh we will build uh a very simple agent uh using cloud platforms console. You will not be writing any code during that part. We'll just kind of prompt our way to our first agent and test it out. Uh then I'll hand it over to Gabe to walk you through like a hands-on portion. We'll be writing code using cloud code or your favorite coding agent. Um and then build a more complex financial agent and then we'll have plenty of time at the end for Q&A. We we have a twohour slot. I know they broke it down into four parts, but it's basically one long presentation.

嗯,希望不用整整花两个小时。呃,我们希望这次交流能比较互动,所以如果你有问题,请举手。现场有几位工作人员可以过来给你递麦克风,让你提问,尤其是进入动手实践环节之后。好,那我们开始吧。嗯,那么……Um, hopefully it doesn't take the full two hours. U, we want this to be pretty interactive, so if you do have questions, raise your hands. We have a couple folks around that can run to you, hand you a mic uh with a question, especially as we get into the hands-on uh portion. All right, let's let's get going. Um, so

智能体如何发挥作用What makes an agent work

我先从基础讲起。我们先来看看什么是智能体,或者说,智能体是如何运作的?嗯,智能体基本上就是一个在循环中运行、并配备了工具的模型。你会看到左边有一个模型,它负责做出决策、采取下一步行动,并循环调用工具,直到任务完成。这就是智能体最基本的概念。I'll start with the basics. So, we'll we'll start with what what is an agent or what makes an agent work? Um so agent is basically uh a model in a loop with tools. So you'll see on the left you have the model that's deciding and taking the next action and calling tools in a loop until your task is done. So that's like the very basic what what an agent is.

主持人:不好意思。Host: Excuse me.

嘉宾:Y 幻灯片演示文稿或幻灯片。Guest: Y slide deck or slide.

主持人:哦,是幻灯片的链接。嗯,我们可以试着……Host: Oh, a link to a slide deck. Um, we can try to

嘉宾:我们……我们可以之后分享。Guest: we we can we can share it after.

主持人:是的,我们之后会分享。现在要把它发出来对我们来说有点困难。嗯,不过我们很乐意回答问题,呃,也会在最后分享幻灯片。你们……从后面看幻灯片是不是很困难?好吧,不好意思。嗯,好。呃,接下来我要……Host: Yeah, we we'll share it after. It'll be hard for us to get it out right now. Um, but happy to answer questions uh and and share the slide deck at the end. Are you is it hard for you to see see the slides from the back? Okay, sorry about that. Um, all right. Uh, the next thing I

测试框架与模型假设Harnesses and model assumptions

我想聊聊什么是 harness。Harness 通常就像包裹在模型外面的一层,它能帮助你循环调用工具,从而完成当前任务。它会假设模型有哪些做不到的事,并尝试填补这些空缺。也就是说,它会循环运行、调用工具、管理上下文,把模型做不到的事情都封装起来。举个例子,我们的 Sonnet 4.5 模型有一种我们称为“上下文焦虑”的情况:每当 Sonnet 4.5 感觉上下文快要达到上限时,就会试图非常迅速地结束任务。因此,在为 Sonnet 4.5 构建 harness 时,你可以加入类似重置上下文的机制,以绕过这种焦虑带来的限制。但后续的模型,比如 Opus 4.5,就没有这个限制,所以你不需要为 Opus 4.5 做这种上下文重置。wanted to chat about is what a harness is. harness is typically like a layer that wraps around the model that helps you make these tool calls in a loop to get you the outcome for the task that you're the task at hand and it's making assumptions about what the model cannot do and trying to sort of fill those gaps. So it's running in a loop making tool calls managing your context encapsulating everything that the model cannot do. A good example is our set 45 model had something what we called uh context anxiety. So whenever sonnet 45 felt like you're getting to the end of the context limit, it would try to wrap up the task really quickly. So when you're building a harness around sonnet 45, you would add something like a context reset to get around the limitation of the anxiety. But with the next model like opus 45, opus 45 did not have this limitation and you did not need to do this like context reset for opus 45.

所以,在构建一个适配框架时,你需要将针对不同模型的所有这些假设封装起来,并随着每个新模型的出现不断更新。这就是为什么构建一个好的适配框架非常、非常重要。我们尝试通过云托管代理来做到这一点。然后……So when you're building a harness, you want to encapsulate all these assumptions for different models and keep up with it with every new model that comes up, which is why building a good harness is really really important. And that's something we've tried to do with cloud managed agents. And then the

沙箱与限制影响范围Sandboxes and limiting blast radius

最后一点,你可能希望你的智能体能够访问沙箱或计算机,本质上就是一个用来运行它编写的代码、执行任务的环境。通常,你会为它提供云端访问权限,让它能够访问用于执行所编写代码的沙箱或容器。Claude Code 就是一个很好的例子。它本质上是一个在你电脑本地运行的框架,能够访问你的文件,并在运行过程中执行代码、更新文件。它编写的代码也可能是不可信的,可能存在错误。因此,在部署生产环境中的智能体时,你要确保智能体编写的代码经过沙箱隔离,并限制在容器内。你还要确保沙箱彼此隔离,并限制故障影响范围。last bit uh you want your agent to have access to a sandbox or a computer essentially uh a place where it's going to run the code it's writing to execute the task. Um, so typically you're giving cloud access to like a sandbox or container where it's executing the code it's writing. It's able to edit files, install dependencies, etc. Cloud code is a really good example of this. It's running, it's a harness essentially running locally on your computer, has access to your files, and it's executing, updating your files as it goes. Um, it's also writing uh code that's untrusted. It might be buggy. So you want to make sure when you're deploying production agents uh your a the code your agents are writing is sandbox and contained within a container. Um and then you want your sandbox to be isolated and the blast radius to be limited.

所以通常你会希望在单独的容器中执行每项任务,这样就不会混淆,也不会,嗯,呃,扩大波及范围。So typically you want to execute every task in a separate container so you're not mixing up and you're not um uh increasing the blast

第一种架构:全部集成在一个容器中First architecture: all in one container

用于你的任务的半径。接下来,我会带你了解我们实际构建托管代理时采用的第一个架构。那是在去年 12 月,我们向早期体验客户发布了第一个架构,收到了大量反馈,之后又转向了一个新架构。我会带你看看我们在第一个架构中遇到的一些陷阱和问题。对于第一个架构,我们把所有东西都放进了容器里。我们有会话日志,记录该会话中发生的一切。测试会话本质上就是你的工作单元。执行框架也运行在容器内,沙箱执行也在容器内进行。这样做的好处是,由于所有东西都在容器里,因此无需设计服务边界。radius for for your tasks. Next up, I'll walk you through um the first architecture that we actually built managed agents with. This was in December of last year where we shipped our first architecture to our early access customers, got a bunch of feedback, and then actually pivoted to a new architecture. So, I'm going to walk you through some of like the pitfall pitfalls and like issues that we saw with the first one. So, with the first architecture, what we did was we put everything in the container. So we had the session log of everything that's happened within that session. So test session is essentially your um unit of work. Um the harness was also running inside the container and then the sandbox execution was also happening inside the container. The benefit of that was like because everything was in the container there was no service boundaries to design for.

一切都在本地,嗯,很容易编辑。文件编辑本质上就像系统调用一样。Everything was local um easy to edit. File edits were essentially just like sis calls.

宠物与牲畜问题The pet vs cattle problem

但后来我们意识到,我们养的是一只宠物。嗯,如果你没听说过基础设施早期的“宠物与牲畜”类比,那么所谓宠物,就是一个有名字、需要悉心照料的实体。它生病时,你得把它照料好,让它恢复正常;否则,你基本上承受不起失去它的代价。而牲畜则更容易互换,也更像消耗品。所以,一只牲畜出故障时,你可以换一只,然后继续往前走。 举个简单的例子,假设你只有一个数据库分片。它一宕机,你的产品也就停摆了,这就是一只宠物。但假设你有一套主从副本。主节点宕机了,你可以启动一个副本。这就是牲畜,对吧?你有很多实例,一个宕机了也没关系,可以再把它启动起来。所以,我们最初的配置本质上就是一只宠物。But what happened was we realized we adopted a pet. Um so if uh if you've not heard about the pet and cattle analogy from like the old infrastructure days, um pet is when you essentially have a named and handtended entity. When it gets sick, you have to nurture it back to life. Otherwise, you you basically cannot afford to lose it. And cattle is more interchangeable, more disposable. So when one fails, you can replace it with another one and move on. So a good example is imagine you had like a single database shard. It goes down, your product is down, you have a pet. But imagine you have a master replica set up. Your master goes down, you can bring up a replica. That's a cattle, right? So you have many instances. One goes down, that's not a problem. You can bring it back up. So what we had with our initial setup was essentially a pet.

这方面有几个问题。由于所有东西都在容器里运行,调试起来非常困难。我们不知道问题出在哪里。丢包和容器宕机的表现可能非常相似,所以我们基本上不得不通过 WebSocket 流连接到容器里进行调试。另一个问题是,调查问题很困难,因为客户数据会存放在这些容器里,所以我们实际上没有办法进入容器进行调试。这也是我们在早期访问阶段遇到的另一个问题。最后,如果客户希望我们连接到他们 VPC 中的某个 MCP,这就意味着要么进行网络对等连接,要么把我们的运行框架交付给他们,让他们自己运行。因此,这种架构带来了不少挑战,而我们当时并没有找到好的解决方案来克服这些问题。Um so few few issues with this debugging was really hard because everything was running in the container. We didn't know what was causing the issue. So a a drop packet a dead container would show up very similarly and we had to essentially like websocket stream into the container to debug. Um the other issue was investigating meant we had to uh essentially investigating was hard because customer data would live on these containers. So we didn't have a way in essentially to go in and debug. So that was like the other issue we saw in our early access. And then the last one was if a customer wanted us to connect to let's say an M MCP in their VPC, it meant peering networks or shipping them our harness and having them run it. So there were like a bunch of challenges with that architecture that that we weren't able to really have a good solution to overcome.

所以我们So what we

让大脑与双手脱钩Decoupling the brain from the hands

我们决定基本上将“大脑”和“双手”解耦,接下来我会详细说明这意味着什么。嗯,智能体基本上变成了三个独立的接口。左侧是会话,本质上是一份追加式日志,记录了到目前为止会话中发生的一切。中间是大脑,也就是你的执行框架或智能体循环,以及云端。嗯,右侧则是双手,也就是沙箱、MCP 工具调用等。它们按需配置,工作完成后就会销毁。如果沙箱丢失了,只要重新启动一个就行。因此,每个组件本质上都变成了可随时替换的临时资源。所以沙箱宕机时,执行框架或云端可以选择直接重新启动一个,对吧?错误会回传到云端,而对云端来说,沙箱就和其他任何工具调用一样。decided that we wanted to essentially decouple the brains from the hands and I'll dive into what that means. Um so the agent essentially became three separate interfaces. On the left you have the session which is essentially an appendon log of everything that has happened in the session so far. In the middle you have the brain that's your harness or the agent loop along with cloud. Um and then on the right are the hands. So sandboxes your MCP tool calls etc. Provisioned on demand uh gone when the work is done. And if you need if you lose a sandbox you just spin it back up. So every component essentially became a cattle and interchangeable. So when the sandbox died, uh the harness or cloud could choose to just spin it back up, right? The error essentially went back to cloud and the sandbox to cloud was essentially like any other tool call.

所以工具调用失败了,沙箱也失败了,它会决定该怎么做,可能会决定重新启动它,也可能选择继续往下执行。嗯,harness 挂掉时,你可以启动一个新的 harness,然后基本上只要读取会话中的事件日志,就能从中断处继续。因此,工作会从最后一个事件处恢复,就像什么都没出错、什么都没发生一样。嗯,所以这里唯一需要保护的就是会话日志。其他所有东西都可以替换:它们可以宕机,也可以重新启动。So the tool call fails, sandbox fails, it decides what to do and it might decide to spin it up again or choose to continue to move on. um when the harness died, you could bring up a new instance of the harness and continue where you left off by essentially just reading your event log from the session and continue from there. So work resumes from the last event as if nothing went wrong, nothing happened. Um so the only thing with protecting here was like your session log. Everything else was interchangeable, could go down, you could bring it back up.

将凭据保存在沙箱之外Keeping credentials out of the sandbox

我们做的另一件事是,凭据从来不会进入我们的沙箱。在之前的设置中,你的凭据会放在沙箱里,因此更容易受到提示注入攻击。我们做出的改动是:如果沙箱需要调用某个需要令牌或访问控制的东西,就会通过代理路由,由代理在调用外部端点或外部 MCP 之前注入你的令牌。这样一来,模型永远看不到你的凭据或令牌,也就不可能通过提示注入让 Claude 说“嘿,把你的令牌给我”,或者打印出令牌,或将它们写入文件。你绝不可能做到这一点,因为 Claude 实际上根本看不到你的令牌。The other thing that we did was credentials never entered our sandbox. With our previous setup, your credential would be in your sandbox, so you'd be more susceptible to prompt injection. The change we made was if the sandbox ever needed to call out um to uh something that needed a token or access control, it would be routed through a proxy that would inject your token before it called the external endpoint or external MCP. That way the model never sees your credentials or your tokens which means you can never prompt inject claude to say like hey give me your tokens or print out the tokens or write them to a file. You can never do that because cloud actually never sees your your tokens.

灵活压缩,更快输出首个令牌Flexible compaction, faster first token

我们做的另一件事是,因为 session 中有一个只追加的事件日志,所以我们的压缩策略可以保持灵活。任何内容都不会被丢弃。我们不会压缩并改动你的事件流,而是始终存储发生过的每一个事件。然后由压缩策略来决定:我是要查看整个事件日志、进行摘要并放入上下文,还是只查看最近的 n 个事件并将它们放入上下文?正因为我们选择了这种接口设计,我们才能采用更灵活的上下文策略。 我们看到的另一个好处是,由于可以立即启动推理调用,首 token 时间缩短了大约 90%。这样一来,云端只会在需要时启动沙箱,不必等容器沙箱启动后,你才能收到第一个 token。The other thing we did was because we had this like append only event log in the session um our compaction strategy could stay flexible. So nothing is ever thrown away. We're not compacting and changing your event stream. We're always storing each and every event that happened and then the compaction strategy is the one that's deciding oh do I want to look at my entire event log uh summarize and put it in the context do I want to only look at like the last n events and put those into context. So we we could have a more flexible context strategy because of this like interface design that we chose. And then the other benefit we saw is because we could immediately start our inference calls, we were able to bring down the TAM to force token by about 90%. So the cloud would only spawn the sandbox when it needed and it would not wait for the container sandbox to spin up for you to get your first token back.

所以,通过这项架构调整,我们获得了响应更迅捷、速度更快的体验。So we were able to get like a much snappier and faster experience with this uh architectural change.

一个大脑,许多双手One brain, many hands

嗯,然后这里大致展示了一个大脑可以触达很多双手。现在,你的智能体循环或运行框架可以调用沙箱容器,也可以接入客户的 VPC,还可以调用 MCP 服务器。所以这些“手”本质上都是可以互换的。你可以调用并接入其中的很多个,这让我们的架构变得更加……Um, and then here's sort of like the illustration of like one brain can reach many hands. So your agent loop or harness can now call a sandbox container. It could call into a customer's VPC. It could call into an MCP server. So all these like hands are essentially interchangeable. You can call and plug in many of these and it made our architecture a lot more

接口比假设更持久。Interfaces outlast assumptions

灵活。嗯,所以如果你只从这件事中记住一点,那就是:harness 会编码一些假设,而这些假设可能会过时。因此,我们设计的接口能够超越这些假设长期适用,也让架构变得更加灵活。正如我刚才所说,这让我们可以改变压缩策略,彻底替换 harness,同时接口和架构保持不变,这样我们就能采用更具可插拔性的方式。flexible. Um, so if you take one thing home from this, it's that harnesses encode assumptions and assumptions can go stale. So we designed interfaces to outlast these assumptions and made the architecture more flexible. So this allowed us to like I said change our compaction strategy, change out the harness completely but the interface and the architecture remains uh the same and we can really have a more pluggable way

领取 API 额度Claiming API credits

来操作这个。好了,接下来我们要进入一点动手实践环节。我们为大家准备了一些免费的 API 额度,方便大家今天和我们一起构建。请扫描二维码,登录你的云平台账户,或者创建一个新账户,然后就可以进去领取这些额度,跟我一起构建,接着再和 Gabe 一起构建。我会把这个页面留一会儿。嗨。of operating this. All right, so next we're going to get into a little bit of a hands-on portion. U we got you some complimentary API credits to help you build with us today. So, please scan the QR code, either sign in to your cloud platform account or create a new one and you should be able to um get in there and get those credits so that you can build with me and and then with Gabe. And I'll I'll leave this for for a second. Hi.

主持人:抱歉,你说什么?Host: Sorry, what?

嘉宾:最后一张幻灯片。Guest: Last slide.

问答:三个核心接口Q&A: the three core interfaces

这基本上就是我们刚才讨论的内容,对吧?这有点像我们为之设计的三种接口,对吧?最初的问题是:我们设计了哪些接口,能让这些东西经受住变化?我们有只追加的会话日志;还有可互换的 harness;然后是“手”,你可以接入沙箱、工具调用,或者模型可能需要访问的任何东西。这些让它变得更通用,也更容易扩展。好,回到 credits。我们开始之前,还有人需要扫一下这个吗?好像还有几部手机。那我再给大家大概 30 秒。谢谢大家耐心等候。哦,网络出了问题。糟了。It's basically what we talked about here, right? This is the this is sort of like the three interfaces we designed for, right? So the first one is the the the question was like what were the interfaces that we designed that ma made things outlast uh changes. So we have the append only session log. You have the harness that's again interchangeable and then the hands where you can plug in a sandbox tool calls or whatever the model might need access to and that that's what kind of makes it more generic and extendable. All right, going back to the credits. Uh, does anyone else need to scan this before we jump in? Okay, still seeing a couple phones. Okay, going to give everyone about 30 seconds. Thanks for your patience. Oh, there are problems with the internet. Oh, no.

主持人:呃,Gabe,我们有麦克风吗?因为我听不清有些问题。对,你注册后,应该一两分钟内就能收到额度。嗯,我们正在拿麦克风,这样就能四处走动,呃,听听大家的问题。不过,我来带你们了解一下……Host: Uh, Gabe, do we have a mic? Because I I can't hear some of the questions. Yeah, the the credit should arrive once you once you sign up in hopefully a minute or two. Um, yeah, we're getting a mic so that we can hopefully walk around and uh get get some of these questions. But yeah, I'm going to walk you through

构建一个讲笑话的智能体Building a joke-teller agent

构建一个非常简单、能给你讲笑话的智能体。嗯,我会先介绍一些核心 API 和概念,然后我们会转到 platform.entthropic.com,来构建你的第一个智能体。嗯,第一步是创建我们的环境 API,也就是 v1 environments,它可以帮助你为沙箱创建环境或模板。这里会配置你的网络设置。比如,你想要不受限制的网络访问,还是想将访问限制在特定域名或 MCP 上?你可以定义要在容器或沙箱中安装哪些软件包。嗯,这是我们设置环境要做的第一步。接下来你要创建智能体。智能体本质上就是一个可以命名的对象。比如这个例子里,我们会把它叫作 joke teller。building a really simple agent that tells you jokes. Uh, and I'm going to cover some of our core APIs, our concepts first, and then we'll hop over to platform.entthropic.com to build your first agent. Um, so our first step is going to be creating our our environments API, which is v1 environments that helps you create the environment or template for your sandbox. So this is going to have uh your networking setup. So do you want uh unrestricted networking or you want to restrict it to specific domains or MCPS? you can define what packages you want installed on your uh container or sandbox. Um so this is going to be like the first step we're going to take to set up our environment. Next you're going to create the agent. So agent is essentially uh you're you can give your agent a name. So in this case we have we're going to call it joke teller.

嗯,我们要选择你想让这个智能体使用哪个模型。你可以使用 Opus 48、Haiku 或 Sonnet,由你决定。然后我们会为智能体提供一个系统提示。在这个例子中,我们会这样说:你是一名喜剧演员。找一个关于这个主题的新鲜笑话,好好讲出来。然后,你还可以为这个智能体提供工具。在这个例子中,我们会提供智能体工具集,这有点像我们的基础工具集。它就像你的 bash 工具集,包含 read、write、grap 等。几乎所有智能体都需要这个。嗯,所以接下来我们要……Um we're going to choose which model you want to use for this agent. So you can use opus 48, you can use haiku uh or sonnet uh your choice. Uh and then we're going to provide the agent with a system prompt. In this case, we're going to say you're a comedian. Find a fresh joke on the topic. Deliver it well. Uh and then you can provide this agent with tools. In this case, we're going to provide it with agent tool set, which is sort of like our basic tool set. This is like your bash tool set, read, write, grap, etc. And you almost all agents will need need this. Um so that's going

会话与事件流Sessions and the event stream

作为你的第二步。第三步最终就是创建会话。嗯,会话需要一个 agent ID 和一个 environment ID,然后创建一个会话。这就是你的任务,也就是你的工作单元,或者说你的任务。嗯,会话配置完成后会处于空闲状态。在你发送事件之前,还没有进行任何工作。然后,这大致就是会话中的事件流会呈现的样子。嗯,你会有自己发送的事件,以及 agent 返回给你的事件。左侧可以看到一条用户消息。你可以说:“哦,给我讲一个关于分布式系统的笑话。”然后 agent 就会给你讲一个有趣的笑话。嗯,你还可以使用一种叫作自定义工具的东西。自定义工具本质上允许你定义一个自定义工具,并自行处理如何响应它;Claude 会在你的事件流中生成一个自定义工具使用事件,你可以监听这个事件,然后处理它,并将结果返回,嗯,作为工具结果。to be your step two. Step three is going to be finally creating the session. Um so session takes an agent ID and an environment ID and creates a session. This is your task uh unit of work or your task. Um and when the session is provisioned it's idle. No work has been done right until you send an event. And then this is sort of what an event stream on your session would look like. Um you're going to have events that you send and then events that the agent will come back to you with. On the left side you'll see you have user message. You can say, "Oh, tell me a joke about distributed systems." And then the agent will come back to you with a funny joke. Um, you can use something called a custom tool. Custom tool essentially lets you define a custom tool that you want to handle how you uh how you respond to it and claude will essentially put a custom tool use event on your event stream that you can listen to and then you can process that event and then return the result um to claim tool result.

然后里面还有一些其他示例,展示你会看到哪些类型的事件。比如,如果你的会话出错或遇到错误,就会看到 session error。你的会话处于空闲、没有运行时,状态就是 Status idle。通常这表示你没有正在使用的沙箱。嗯,左侧的 interrupt 则是在你想停止或……的时候使用的。And then there are some other examples in there for what type of events you would see. So you'll see session error if your session ever ends up in an error or sees an error. Status idle is when your session is idle, not working. And this is typically when you're not really have a sandbox that you're using. Um and then interrupt on the left is when you want to stop or

控制台快速入门Console quick start

结束会话,不想再做这项工作了。呃,这有点像是我们的完整功能列表。也许如果最后还有时间,Gabe 可以再回到这里,深入讲讲。不过,Gabe 会在工作坊中和你一起,进一步探讨一些相关概念,比如多智能体和我们也提供的记忆功能。好,在讲那个之前,我们现在先跳转到 platform.claw.com。嗯,希望你可以使用自己的 API 额度并看到这些内容。如果没有的话,我让 Travis 拿着麦克风在现场走动,有问题或者需要什么帮助,都可以叫住他。嗯,不过如果你进入控制台,就会在“管理智能体”部分看到一个叫“快速入门”的选项。这有点像是引导你创建第一个智能体的教程。kill the session and don't want to do the work anymore. Uh this is sort of like our full feature list. Maybe if we have time at the end, Gabe can kind of come back to this and dive in. But Gabe will be kind of working with you on his part of the workshop going deeper into some of like these concepts like multi-agent and memory that we also provide. All right, before we go to that one, we're going to hop over now to platform.claw.com. Um, and hopefully you can use your API credits and see those. Now, if you don't, I have Travis walking around with the mic in case you have questions or you need to just like flag him down for for anything. Um but if you go to your console you'll see in this manage agent section there is something called as a quick start. This is sort of like our um guided tour of how to build your first agent.

值得记下

如果你只记住一点,那就是运行框架会编码一些假设,而这些假设可能过时。
我们做的另一项改动是,凭证绝不进入沙箱。