🗒️跟着吴恩达学AI多智能体-7/17-智能体工具的关键因素
00 分钟
2024-6-3
2024-6-29
type
status
date
summary
slug
tags
category
password
URL
icon
<Multi AI Agent Systems with crewAI>是吴恩达大佬与CrewAI的创始人兼CEO合作新开的一门课程,该课程的目标是通过理论和实际案例,让学员掌握构建智能体系统的技能,最终能自主构建复杂的智能体团队。该课程是以视频教学的形式进行的,为了便于大家快速学习,我这边提供了图文形式。官方链接放在了左下角,大家点击原文链接即可查看官方视频课程。该课程共分为17节,本文是第七节,后续我会每天更新一节,大家有问题可以随时私信或者写在评论区。以下是第七节的图文内容。

课程内容

我们刚刚为客户支持创建了一个非常有趣的智能体组(crew)。但是事情可以变得更有趣。在本课中,我们将使用工具来构建一个客户外展活动。这将非常有趣,因为销售是多智能体系统的一个非常常见的使用案例。让我们快速看看这个案例。
欢迎回到我们的新课程。我们将讨论工具。工具是Crew.ai和任何多智能体系统中非常重要的一部分。工具使你的智能体能够与外部世界交流,突破仅在内部交流的局限,实际执行操作,对流程、系统、用户和公司产生实际影响。因此,工具是使智能体出色的关键部分。那么,什么是优秀的工具?什么使一个工具比另一个工具更出色?
notion image
我们发现,使用Query AI的众多用户中,出色的工具具备至少三个特征:多功能性、容错性和缓存实现。现在让我们分别讨论这些主题。
notion image
首先,多功能性。一个工具需要能够接受不同类型的请求。工具是连接具有模糊输入的AI应用与具有强类型输入的外部世界的桥梁。因此,你的工具需要足够多功能,能够处理LLM可能抛出的各种情况。Crew AI支持将这些参数转换为正确的类型,能够处理智能体输出的不同细微差别。如果你自己构建工具,你需要确保无论LLM抛出什么,都能正确处理并转换为适当的类型,使其可用。因此,一个优秀工具的一个重要特征是其多功能性,能够处理不同类型的输入。
notion image
第二,容错性。早期使用AI智能体的人们意识到,当智能体将信息传递给工具时,可能会发生故障并产生异常。如果不正确处理这些异常,会导致智能体组停止运行,这是我们不希望看到的。因此,你需要确保你的工具能够优雅地处理故障。Crew AI默认实现了这一点,即使在运行工具时发生异常,系统不会停止执行,而是将消息返回给智能体,使其能够采取行动。这可能是输入的问题,也可能是智能体应该发送不同类型的输入,或者智能体缺少必要的参数。关键是你的工具应该能够自愈,以一种不影响智能体执行的方式处理故障。
notion image
第三,缓存。缓存是使这些工具在实际应用中有价值和可用的关键。当你有一个工具时,大多数情况下它会与网络通信,调用不同的API或服务,可能是内部服务,也可能是外部服务。每次调用时,你需要确保请求是必要的,因此具有缓存层以防止不必要的请求非常重要。Crew.ai提供跨智能体缓存,这意味着如果一个智能体使用某个工具进行了一组参数的调用,另一个智能体再次使用相同工具和参数时,将使用缓存层,从而避免重复调用。这可以防止不必要的请求、达到速率限制、消耗过多资源,并节省执行时间,使智能体组运行更快。因此,在构建需要大规模运行的智能体组时,缓存是非常重要的。
notion image
一些工具的例子包括:搜索互联网、抓取网站等我们已经使用过的工具。除此之外,你还可以连接数据库、调用API、发送通知等。因此,工具是多智能体系统中的基石。Crew.ai提供了大量现成的工具,可以立即使用。未来在构建自己的工具时,务必查阅Crew.ai的文档,你会在其中找到所有现有工具的详细信息。另外,Crew.ai还支持所有Link Chain工具,Link Chain提供了一大批现有工具,你可以直接在Crew.ai中使用。
notion image
好了,说了这么多,让我们开始编写一些代码,一起构建一些工具吧。(下节课见~)
 

原文内容

All right, so what was that? We just built a super interesting crew for support. But things can get even more interesting. On this lesson, we are going to use tools to build a customer outreach campaign. That's going to be super interesting because sales is a very common use case for multi-agent systems. So let's look into that real quick. Welcome back to our new lesson. We are talking about tools. Tools are such an important part of Crew.ai and of any multiple agent system out there. Tools are what allow your agents to communicate with the external world, to get out of their bubble of just chatting with themselves and actually perform actions have an actual impact on your flows on your systems on your users and on your company so it's a super key part that makes agents great so what makes a great tool what makes a great tool? What makes a tool set itself apart from another? Well, there's at least three things that we found from the many users that use Query AI that set a tool apart from each other. The tools that are versatile, the tools that are fault tolerant, and the tools that implement caching. We're going to talk about each of those topics right now. So what means for a tool to be versatile? Well, first thing, a tool needs to be able to accept different kinds of requests. The tool is the connection between the AI apps that have fuzzy inputs with the external world that have strong type inputs. with the external world that have strong type inputs. So your tool needs to be versatile enough so that it can handle the different things that an LLM might throw at them. So query AI supports converting these arguments into the correct types and they can handle the different nuances coming out of your agent. But if you're building it it to yourself you want to be sure that whatever the lm is in your way you want to treat it properly you want to convert it to the appropriate type so that you can actually use it so one big piece of making a great two is making sure that it's versatile it can handle different types of inputs the second thing is being fault tolerant. This is a thing that a lot of people that were using AI agents early on realize, that as your agent passes information to your tools, things might break and you are gonna get exceptions. If you get exceptions out of nowhere and you don't treat them right, you stop your crew right there because it stops the execution. And you don't want to do that. So you want to make sure that your tools can fail gracefully. So in case something goes wrong, they can kind of self-heal. Crew AI actually implements that by default for you. So even if an exception happens when running a tool, instead of stopping the execution, it sends that message back to the agent. So the agent can take action on that. Maybe it's the input. Maybe the agent should have sent a different kind of input. Maybe the agent missed on a required argument. Or maybe there is just another problem. But the important thing is that your tools should be self-healing and should fail aggressively in a way that doesn't stop your agent execution. This is something that we see a lot out there. When you deploy these agents at scale, especially in enterprise companies, you're going to have agents dealing with all sorts of documents and all sorts of sources for files and information. So you want to make sure that the tools are able to handle all that and able to handle when seeing something that they don't expect. We actually have seen this in some of our biggest users where they're analyzing huge amounts of financial documents and sometimes the numbers might not be the easiest ones to read or the text might not be the easiest one to parse. That said, you want to make sure that your tools kind of work around that a little bit. All right, so you have a tool that is versatile and you have a tool that is fault tolerant. That means that you got a lot of that job done. What about caching? you got a lot of that job done. What about caching? Caching is key to make these tools worth it and usable in the real world. Whenever you have a tool, most of the times that tool is used to communicate with the web. So it's going to call different APIs, it's going to call different services. Sometimes it's going to be internal services, others are going to be external services. And whenever that call happens, you want to make sure that you're being mindful about taking the time to do the request and also not doing the request unless necessary. So having a caching layer that prevents unnecessary requests from happening is crucial to make sure that you're building optimal crews. So you want to make sure that you have not only cache but you have a smart cache. So in Crew.ai we offer cross-agent caching. What that means is that if one agent tried to use a tool with a given set of arguments and another agent try to use the same tool with the same set of arguments even if they are different agents they're going to actually use a cache layer so the second time they try to use a tool they're not gonna do that api call and that makes a lot of difference that prevents prevents unnecessary requests, that prevents hitting rate limits, unnecessary consumptions, and also saving execution time, making sure that your crews and your multiple agent systems run faster. So caching is super important when you're building crews that you need to run at scale. What are some examples of tools? Well, there's a bunch that we can talk about. There's the simple ones like search the internet or scrape a website, tools that we actually have used ourselves. But it goes beyond that. You also can connect to a database, you can call an API, you can send a notification, and many, many more. So you can see here how tools are such a cornerstone, and that is the case for all the frameworks out there, including Crew AI. So in Crew AI, tools are such an important piece that Crew offers a bunch of them out of the gate that you can use. So whenever you have the time in the future when building your own tools, make sure to check Crew AI's documentation documentation where you're going to find all the documentation for all the existing tools in there. Also, another thing that's important to highlight is that Crew.ai support all link chain tools. So link chain also offer a huge set of existing tools and you can use them right away with your crews using Crew.ai. So just another thing to highlight. But enough of that, let's jump into some code and see how we can build some tools together.
上一篇
跟着吴恩达学AI多智能体-8/17-客户外展活动的工具
下一篇
使用Java也能开发大模型应用?让我们一探究竟