Build a production-ready agent with Claude Managed Agents
Hi everybody.
大家好。
How's everybody doing?
大家还好吗?
Yeah.
好的。
Okay, cool.
好,挺好。
Um, raise your hands if you've heard the phrase cloud manage agents get brought up like 50 times today.
举个手,今天有没有人听到 Claude Managed Agents 这个词被提了差不多 50 次。
Okay.
好。
And keep your hand raised if you have have any idea what cloud manage agents even is.
还继续举手,如果你大概知道 Claude Managed Agents 是什么的话。
Okay.
好。
Not a lot of hands.
举手的不多。
Cool.
好。
Um and raise your hands if you're excited to learn about cloud manage agents today.
再举个手,今天想学 Claude Managed Agents 的。
Okay, there we go.
好,这才对。
I like that.
我喜欢。
Um hopefully this will be a little bit more of a technical deep dive.
希望今天这个 session 能稍微深入一点,更偏技术一些。
Um myself and a couple of my uh peers earlier today talked at a very high level.
我和几位同事今天早些时候做了一个高层次的介绍。
We showed you some slides.
展示了一些幻灯片。
Um we talked about the primitives and whatever.
聊了聊各种基础概念之类的。
And we'll do a little bit of that here today.
今天这里也会稍微涉及一点。
But uh really what I want to make sure that we do is like have our laptops out, start coding.
但我更想做的是,打开笔记本电脑,直接开始写代码。
I have a little starter repo for us to kind of go through together.
我准备了一个小的 starter 仓库,我们一起来过一遍。
Um and my hope is that by the end of the session, you will be able to go get started with building on cloud manage agents today.
希望到 session 结束时,你们今天就能上手开始用 Claude Managed Agents 构建自己的东西。
Does that sound good to everybody?
大家觉得这样可以吗?
Cool.
好。
Quick agenda.
今天的议程。
Uh we'll do a quick overview of what cloud manage agents is.
先快速过一下 Claude Managed Agents 是什么。
We'll go over a lot of the same kind of um discussion points from earlier today.
会重温今天早些时候讨论过的很多要点。
Um and then we'll we'll spend some time actually building something um relatively from scratch.
然后我们会花一些时间,实际从头开始构建一些东西。
um and actually get something that you could be deploying to production today if you wanted to.
做出来的东西,如果你想的话,今天就可以部署到生产环境。
Um and then we'll wrap up the session with some more advanced topics around cloud manage agents and just the the composable things that you can do with it.
最后收尾会讲一些 Claude Managed Agents 更进阶的话题,以及可以怎么组合使用。
So um cloud manage agents at a high level is just a set of API endpoints that we've developed and released.
Claude Managed Agents,从高层次来说,就是我们开发并发布的一组 API 接口。
um you can go use them with any API key today.
你今天就可以用任何 API key 直接使用。
Um that give you uh access to uh like scaled ready, production ready uh agent uh and all of the primitives around it that you can just build your own products on top of.
它为你提供了大规模、生产就绪的 agent 访问能力,以及围绕它的所有基础原语,你可以直接在上面构建自己的产品。
You can pick and choose whatever primitives you need um and ditch the rest and then build whatever product experience you need on top of.
你可以按需选择所需的原语,去掉不需要的,然后在上面构建任何你想要的产品体验。
So we took care of a lot of things like giving cloud access to a computer.
我们已经处理好了很多事情,比如给 Claude 访问计算机的能力。
Um giving it access to credential vaults if you want to inject things like MCP authentication for your own end users if you need to like get access to their linear MCP or cloud more accurately needs access to that.
如果你需要为终端用户注入 MCP 认证,比如他们的 Linear MCP 需要访问权限,我们也提供了对 credential vault 的访问支持。
Um the tool calling um harness and everything uh retries and error recovery that might happen uh in production.
还有工具调用框架,以及生产环境中可能发生的重试和错误恢复。
um as well as a bunch of really nice primitives around like memory and context management and uh multi- aents uh that make it really really easy to be able to really like skate the exponential and like just benefit from each increased model uh family as they come out.
以及一系列非常好用的原语,比如记忆功能、上下文管理、多 agent 协作,让你能轻松跟上模型的指数级演进,随着新版本的发布持续受益。
Um, and then the the the really nice thing with cloud manage agents, which we'll show a little bit later today, is that um we built a lot of really nice observability um views into our developer console um that you can go to today in order to like just live debug what these agents are up to.
Claude Managed Agents 另一个非常棒的地方,我们稍后会展示,是我们在开发者控制台里内置了很多强大的可观测性视图,你今天就可以去用来实时调试这些 agent 在做什么。
And we'll show a little bit of that as well.
我们也会展示一部分这个功能。
Cool.
好。
So, the the main kind of like building blocks for cloud manage agents are the agent itself, which is really just like think of it as like a template.
Claude Managed Agents 的主要构建模块,首先是 agent 本身,你可以把它理解为一个模板。
You want your agent to have a certain system prompt.
你希望 agent 有特定的系统提示词。
You want it to have access to certain skills.
你希望它能访问特定的技能。
Um, maybe you want to define what tools you want that agent to have access to.
也许你还想定义这个 agent 可以使用哪些工具。
Um, some agents you want to have access to the bash tool and web search.
有些 agent 你希望它能用 bash 工具和网页搜索。
Some agents you want to really make sure don't have access to the web because you don't want them to get prompt injected or whatever.
有些 agent 你则希望确保它无法访问网络,防止被提示注入之类的攻击。
Um, and you can like really pick and choose which which tools they have access to.
你可以精确控制它们能访问哪些工具。
Um, and you can also choose which MCP servers they get connected to which is also really really nice.
你还可以选择连接哪些 MCP 服务器,这也非常方便。
Um, another really nice added uh aspect of like setting up all these agents is that you can also define um certain permission controls on a per tool basis.
配置 agent 时另一个很好用的地方是,你可以按工具维度定义权限控制。
So you can decide that something like the file read tool um can just autoexecute whereas something like um executing bash or uh calling your databases MCP server um requires explicit approval from from your own end users.
比如,文件读取工具可以直接自动执行,而执行 bash 或调用数据库 MCP 服务器则需要用户明确批准。
Um once you configure that agent you also can configure an environment.
配置好 agent 之后,你还可以配置环境。
Um these environments kind of define the template for how the sandboxes that claude has access to behave.
环境定义了 Claude 可以访问的沙箱的行为模板。
So you can define whether or not you want those containers to have network access.
你可以定义这些容器是否需要网络访问。
Maybe you want to pre-install certain packages from npm or from uh pip.
也许你想预装某些来自 npm 或 pip 的包。
Um so you can kind of define that in your environment level.
这些都可以在环境层面进行定义。
And today since we announced uh self-hosted environments and sandboxes, you can also bring your own sandboxes uh that don't just run on Anthropic infrastructure.
今天我们宣布了自托管环境和沙箱,你还可以接入自己的沙箱,不必只使用 Anthropic 基础设施上的。
You can use something like Cloudflare or Modal or Versel um and use those out of the box or even your own um sandboxing fleet.
你可以使用 Cloudflare、Modal 或 Vercel,直接开箱即用,也可以用你自己的沙箱集群。
Um once you configure those two things, you can then just like get started on talking to to that agent, right?
配置好这两样东西之后,你就可以开始跟 agent 对话了。
you you have an ID for your agent, you have an ID for your environment.
你有 agent 的 ID,有环境的 ID。
That's kind of all you need to get started with a session.
这基本上就是开始一个 session 所需的全部。
Um, and a session is just you can think of it as kind of like an ongoing conversation with you and Claude.
session 就可以理解为你和 Claude 之间持续进行的对话。
It's the equivalent of going to claw.ai and clicking new or uh entering Claude Code from your terminal.
相当于去 claude.ai 点击新建,或者从终端启动 Claude Code。
Um, once you do that, you can like start submitting events from your own end users.
创建之后,你就可以开始从你的终端用户那里提交事件了。
Something like them asking for something to to happen.
比如他们请求某件事情的发生。
Um, maybe you that that end user is asking for a PR to get put up.
也许那个用户在请求提一个 PR。
Um and that that all of that kind of happens on the session layer.
这些都发生在 session 层面。
Um and when you create these sessions, you can also include certain GitHub repositories that you want cla to have access to or um certain files that you might want to be preloaded into the container itself.
创建 session 时,你还可以包含特定的 GitHub 仓库让 Claude 访问,或者预加载到容器中的特定文件。
Um so all of those will kind of be downloaded and and provisioned on on your behalf.
这些都会自动下载并为你准备好。
Um and then finally there's just like the events, right?
最后就是事件了。
Like these sessions are just like ongoing event streams uh where you submit messages from your client um and we return s responses that claude is processing them doing whatever it is that it's it needs to be doing.
这些 session 本质上是持续的事件流,你从客户端发送消息,我们返回 Claude 处理这些消息、执行任务时产生的响应。
Um and that's that's effectively like the the four major aspects of cloud manage agents.
这基本上就是 Claude Managed Agents 的四个核心组成部分。
There's a couple of other things um along the sides but those are like the main primitives that that you kind of have to worry about.
还有一些其他的东西,但这些是你主要需要关注的基础原语。
So diving a little bit deeper into the events that we have um like I mentioned there's like user events.
深入看看事件,正如我提到的,有用户事件。
These are things that you might want to submit from your own application.
这些是你可能从自己的应用中提交的事件。
Maybe your user said something or maybe your platform just autosubmitted some sort of um user event.
也许是用户说了什么,或者你的平台自动提交了某种用户事件。
Um these can include images, documents, text, whatever it is that you need.
可以包含图片、文档、文本,任何你需要的内容。
Um you can also send interrupts from your own uh product, your your own platform.
你也可以从你的产品或平台发送中断信号。
Um and you can use those in order to cut off Claude if if it was like going off on a bad tangent or or doing something wrong and you wanted to steer it.
用来在 Claude 走偏了或者做了不对的事时打断它,把它拉回正轨。
Um so you can kind of use that to prevent it from doing any sort of like dangerous action.
可以用这个来防止它执行任何危险操作。
Um you can also submit uh tool results for custom tools that you define and execute in your own uh platform.
你也可以为自定义工具提交工具结果,这些工具由你在自己的平台上定义和执行。
Um or confirmations for human in the loop controls for any sort of server executed tools.
或者为服务端执行工具的人工审批环节提交确认。
Um and then you can also define uh outcomes which allow you to like essentially pass us either a file or like a blob of text that you um wrote that uh is almost like a spec that claude will like try to do a first pass at implementing or or doing the thing that the spec defines.
你还可以定义 outcome,允许你传入一个文件或文本块,类似一份规格说明,Claude 会尝试先实现它,或按照规格描述做事。
Um and then it will launch uh it will essentially enter a mode where it tries to like iterate and check its work against that rubric over and over again until it finds that it can like it actually satisfy that rubric.
然后 Claude 会进入一种模式,不断迭代、检查自己的工作,对照那个评估标准反复验证,直到确认能够满足为止。
Um which we found to be really really powerful.
这个功能我们发现非常强大。
Um it was a really really great way to like set up uh your agents for success.
是让 agent 更好地完成任务的有效方式。
Um next we have agent events.
接下来是 agent 事件。
Agent events are just anything that Claude is doing.
Agent 事件就是 Claude 正在做的任何事情。
So these are like messages that Claude is sending back to the user.
比如 Claude 回复给用户的消息。
compaction for if cla is uh needs to like uh you know compact its context window because it got too large.
以及上下文压缩,在 Claude 的上下文窗口太大需要压缩时触发。
Um the tools that it's kind of executing on your behalf whether those are MCP tools or the uh default agent tools that we've defined.
还有它代你执行的工具,包括 MCP 工具和我们预定义的默认 agent 工具。
Um and then there's also multi-agent coordination events for when claw decides to spawn other agents to help it in doing its work.
还有多 agent 协调事件,当 Claude 决定生成其他 agent 来帮助完成工作时触发。
And we'll show a little bit of what that looks like uh during the live uh demo.
我们在后面的实时演示中会展示这个。
Um next we have session events.
接下来是 session 事件。
Session events are just like life cycle events that let you know when the status of the session is changing.
Session 事件就是生命周期事件,告知你 session 状态的变化。
Maybe it entered a a retry loop.
比如进入了重试循环。
Uh maybe there's some sort of error.
或者发生了某种错误。
Maybe there the the the session needs to like idle for whatever reason.
也许 session 因为某些原因需要进入空闲状态。
Um or if it needed to terminate.
或者需要终止。
So there's just like a a bunch of like state transitions um and error uh events.
总的来说就是一堆状态转换和错误事件。
Um and then there's also like an event for like outcome processing.
还有 outcome 处理相关的事件。