WEBVTT

00:00.400 --> 00:02.120
What we're going to do now is pretty cool.

00:02.200 --> 00:07.880
We're going to use the tools that we worked with last week in long chain.

00:08.280 --> 00:15.320
Autogen has a really easy way to wrap long chain tools so that you can call them directly from within

00:15.320 --> 00:16.040
Autogen.

00:16.200 --> 00:22.400
So when we were working with Landgraff last week, we were using long chains tools, and now in Autogen,

00:22.440 --> 00:24.880
we're also going to be able to use long chains tools.

00:24.920 --> 00:30.400
And that's great because Long Chain has a huge tools community and lots to choose from, and that's

00:30.440 --> 00:30.720
great.

00:30.720 --> 00:35.120
And we've already used many of them, so we can just suddenly have access to all of them from within

00:35.120 --> 00:36.920
the Autogen ecosystem.

00:37.320 --> 00:44.080
So within Autogen, there is this long chain tool adapter, and you can use that to wrap any long chain

00:44.080 --> 00:46.080
tool and it becomes an autogen tool.

00:46.760 --> 00:52.280
So for example, uh, this, this uh, this is importing some of long chains classes.

00:52.280 --> 00:53.720
We've already used these before.

00:53.880 --> 00:59.520
The Google Serp API wrapper is a way to call the Google Surfer API that we've we've used that We've

00:59.560 --> 01:02.880
got access to the file management toolkit.

01:03.040 --> 01:08.360
Was that great set of tools for reading and writing files with from a particular directory.

01:08.760 --> 01:12.080
And then this is just the generic Lang chain tool class.

01:12.840 --> 01:16.280
So just before we do that, let me tell you the prompt that we're going to have for an LM.

01:16.400 --> 01:22.920
Your task is to find one way nonstop flights from New York's John F Kennedy to London's Heathrow Airport

01:22.920 --> 01:23.760
in June.

01:24.200 --> 01:29.400
Search online, write the details to a file and select the best one.

01:29.880 --> 01:31.680
So then this code.

01:31.680 --> 01:36.960
These two lines here are taken identically from what we did last week.

01:37.160 --> 01:39.960
This is creating a Google search API wrapper.

01:39.960 --> 01:46.960
And this is the Lang chain code to create a lang chain tool for searching the internet with a description

01:46.960 --> 01:48.360
based on this function.

01:48.360 --> 01:53.360
And we could also do the same thing for things like sending a push notification, and for running Python

01:53.360 --> 01:55.960
code and everything else that we did last time.

01:56.400 --> 02:00.310
And so we end up with, with, with this long chain tool.

02:00.630 --> 02:04.150
And now I can call long chain tool adapter.

02:04.150 --> 02:08.590
Create a new instance of that passing in the long chain tool.

02:08.710 --> 02:14.550
And by passing that in this adapter adapts that long chain tool to become an autogen tool.

02:14.830 --> 02:16.670
It's just sort of a wrapper around it.

02:17.030 --> 02:19.550
And so I put that in a little list called Autogen tools.

02:20.070 --> 02:26.750
And then I've also collected some long chain file tools by getting the file management toolkit giving

02:26.750 --> 02:31.070
it a directory sandbox I've created an empty directory sandbox on the left.

02:31.350 --> 02:32.830
And we call Get tools.

02:32.830 --> 02:34.310
And we get a bunch of tools.

02:34.550 --> 02:42.150
And for each of those, I'm going to add them to my autogen tools by appending a Lang chain tool adapter

02:42.150 --> 02:48.470
and Autogen piece of Autogen code that adapts Lang Chains tool to be an Autogen tool.

02:48.630 --> 02:51.110
That's what this does right here.

02:51.590 --> 02:53.030
And then I'm going to print each one out.

02:53.030 --> 02:55.950
So we get to see what is this set of tools that we've got.

02:56.470 --> 02:57.230
And then.

02:57.550 --> 03:00.630
Then I'm simply going to call an autogen.

03:00.950 --> 03:02.750
Agent with this prompt.

03:02.750 --> 03:07.190
Find me a flight, use your tools and I'm going to give it.

03:07.230 --> 03:07.790
Of course.

03:07.830 --> 03:08.590
Tools.

03:08.750 --> 03:09.310
Here they are.

03:09.350 --> 03:14.670
I pass in the autogen tools so that that is what it can use.

03:14.790 --> 03:16.950
And then I will print out the inner messages.

03:16.950 --> 03:21.150
So we see it doing its thing and then get it to display the outcome.

03:21.550 --> 03:22.990
All right let's run this.

03:22.990 --> 03:24.430
Let's see what it actually does.

03:25.630 --> 03:30.790
So what you'll see is that it uh it's printed out the different tools it has access to.

03:30.830 --> 03:35.110
It has access to do an internet search to file move things around.

03:35.190 --> 03:36.870
So what's it actually done?

03:37.310 --> 03:43.030
So it's done a function call to to do a query, an internet query for finding the non-stop flights.

03:43.590 --> 03:47.830
Uh, it then, uh, got the results and it sound.

03:47.870 --> 03:51.030
It's replied with, I have found several promising deals.

03:51.030 --> 03:54.790
I will now write the details to a to a file called.

03:54.990 --> 04:01.310
Now, one of the interesting things about Autogen is the way that it handles the interactions that agents

04:01.310 --> 04:04.070
typically, uh, will then stop.

04:04.230 --> 04:07.070
Um, particularly in this kind of mode of working with them.

04:07.110 --> 04:13.830
And so what we now do is that I'm just going to send the next message of, okay, proceed, send a second

04:13.830 --> 04:17.070
message to this agent in the same way.

04:17.990 --> 04:19.670
And we'll see what it comes back with.

04:22.790 --> 04:26.750
So it's thinking about that which which probably means it's streaming back something big.

04:28.830 --> 04:29.550
And here we go.

04:29.630 --> 04:32.030
The details of the flights have been saved to flights.

04:32.790 --> 04:34.630
Now I will select the best flight.

04:34.630 --> 04:36.630
The selected flight is all of this.

04:36.670 --> 04:41.470
This flight offers a good balance of price and service, making it a great option for travel.

04:41.670 --> 04:42.190
Sounds good.

04:42.230 --> 04:44.310
It's with Virgin Atlantic, a great airline.

04:44.470 --> 04:45.430
And there's details.

04:45.430 --> 04:51.190
And this of course, has actually been, uh, grabbed from the true internet search.

04:51.190 --> 04:53.470
And it is like a useful piece of information.

04:53.790 --> 04:57.230
And of course, I know you're wondering, did it write a file?

04:57.230 --> 04:58.550
Let's go and have a look.

04:58.550 --> 05:01.310
We open up sandbox and there's a file flight MD.

05:01.350 --> 05:03.910
Let's let's open a preview of that file.

05:04.230 --> 05:05.670
And here we go.

05:05.670 --> 05:12.310
Here are a bunch of different options nicely formatted with a bunch of different, uh, things.

05:12.590 --> 05:19.110
Uh, does seem interestingly as if there was a cheaper option, but it has selected, uh, Virgin,

05:19.110 --> 05:22.790
which is one of my favorite airlines, but is the most expensive of the options.

05:22.790 --> 05:26.110
But I guess we didn't necessarily say the cheapest, uh, did we?

05:26.150 --> 05:31.030
I'll go back and check out the the prompt, um, the best flight.

05:31.190 --> 05:35.430
So, uh, um, a good choice of food and drinks and on board.

05:35.430 --> 05:38.230
Let's see, uh, promising deals.

05:38.230 --> 05:38.390
Yes.

05:38.390 --> 05:40.590
So we don't necessarily say that it needs to be the cheapest.

05:40.590 --> 05:45.990
So it chose, for whatever reason, to recommend the Virgin flight out of those flights.

05:46.310 --> 05:47.830
And that is what it did.

05:47.870 --> 05:54.420
But by all means you can rerun it asking for the cheapest and hopefully Gpt4 mini can handle that task.

05:55.060 --> 06:00.660
Okay, so we've shown how you can wrap Lang chain tools and access them from Autogen.

06:00.660 --> 06:05.100
And a little mini side mission for you right now is to go and find some more tools.

06:05.140 --> 06:10.220
Bring in the Python one, and have it be able to multiply pi by three and try some other tools.

06:10.220 --> 06:15.580
There are so many tools in the Lang chain ecosystem that now you can be unleashed to make Autogen do

06:15.580 --> 06:17.620
all sorts of cool things for you.

06:17.940 --> 06:24.780
Uh, and, um, okay, next up we have, uh, team interactions.

06:25.100 --> 06:26.980
So check this out.

06:26.980 --> 06:30.900
I'm going to take you through this pretty quickly because it's fairly self-explanatory.

06:31.220 --> 06:34.100
Uh, so you can create multiple assistants.

06:34.100 --> 06:39.540
So in this case, we're going to have, um, an assistant agent, uh, called primary and one called

06:39.540 --> 06:40.620
evaluator.

06:41.020 --> 06:43.660
Any guesses what pattern I might be about to work with here?

06:43.980 --> 06:49.300
So the prompt is your task is to find a one way non-stop flight from JFK to London London-heathrow uh,

06:49.500 --> 06:49.940
first.

06:49.980 --> 06:53.380
Search online for promising deals, then reply with the best option you found.

06:53.620 --> 06:56.860
Each time you're called, you should reply with a different option.

06:57.300 --> 06:59.260
So then we.

06:59.300 --> 07:01.860
Create a primary agent, which is the, uh.

07:02.020 --> 07:03.700
It's only going to have access to the.

07:03.740 --> 07:04.740
Sherpa to search.

07:04.740 --> 07:06.940
We're no longer writing files at this point.

07:07.260 --> 07:12.060
Uh, so it's the one that's going to be doing internet searches and it's system messages.

07:12.060 --> 07:15.300
You're a helpful AI research assistant who looks for promising deals.

07:15.340 --> 07:16.900
Respond only with one option.

07:17.220 --> 07:19.460
And, uh, make sure it's different from others.

07:19.780 --> 07:26.060
And then we have an evaluator check whether it looks like the assistant has given a very promising recommendation.

07:26.060 --> 07:26.660
Respond.

07:26.700 --> 07:28.500
Approve when you're satisfied.

07:28.540 --> 07:30.700
If you've only seen one reply, then don't approve.

07:30.740 --> 07:31.860
You need to see more.

07:32.060 --> 07:37.860
You can tell slightly artificially making this so that we get some sort of interactions between them.

07:37.860 --> 07:43.020
If this were a real, uh, proper challenge you were trying to set, you might be perfectly happy with

07:43.020 --> 07:46.820
the first option if the evaluator agent is satisfied with it.

07:47.140 --> 07:48.380
Um, okay.

07:48.420 --> 07:51.180
So this this is the, uh, the way it works.

07:51.380 --> 07:57.220
Um, and then we create a team, and there's various ways to create teams.

07:57.220 --> 08:02.900
This is a bit like a crew and crew, but it's, uh, it's really, uh, somewhat simpler.

08:02.900 --> 08:03.420
Really.

08:03.540 --> 08:10.220
This is a round robin group chat, which means, like, one after the other, obviously.

08:10.420 --> 08:15.100
Um, and, uh, that is the simplest way that you could have some kind of relationship between them.

08:15.500 --> 08:20.860
And we pass in a list of agents to talk to each other, primary agent, and then an evaluation agent

08:20.980 --> 08:24.380
and a termination condition that tells it.

08:24.420 --> 08:26.980
When do you know that enough is enough?

08:27.260 --> 08:31.020
And this is, uh, you can see here how it's defined.

08:31.220 --> 08:33.340
Text mention termination.

08:33.580 --> 08:35.260
The word approve.

08:35.700 --> 08:37.380
So this is a little bit brittle.

08:37.380 --> 08:43.060
I'm relying on the fact that the assistant, the evaluator agent, will reply the word approve.

08:43.420 --> 08:46.770
Normally you would want something a little bit more profound than that.

08:46.770 --> 08:52.450
You would probably want to reply, have structured outputs here and use that to test.

08:52.450 --> 08:53.810
But this is perfectly good.

08:53.810 --> 08:54.210
For now.

08:54.210 --> 08:55.890
I just want to get you a feel for this.

08:55.890 --> 09:00.890
I don't necessarily want to give you a full bells and whistles solution.

09:01.290 --> 09:02.450
And then this.

09:02.450 --> 09:05.050
This is how it comes together.

09:05.050 --> 09:09.290
You call team run and you await team run.

09:10.050 --> 09:11.410
And it might be worth me mentioning.

09:11.450 --> 09:15.250
Actually I've been focusing a lot on the on messages.

09:15.650 --> 09:18.650
The on messages, uh, thing that you call agents here.

09:18.650 --> 09:21.050
You can also call Agent Run as well.

09:21.090 --> 09:22.890
An agent can be called with run.

09:22.890 --> 09:25.650
And then you just pass in this exactly the same thing.

09:25.650 --> 09:30.770
You pass in the task, um, task equals and a prompt.

09:30.770 --> 09:33.610
And what comes back is just going to be the final messages.

09:33.610 --> 09:35.730
So that is another way of doing it as well.

09:35.970 --> 09:37.890
Um, but this is what we will do now.

09:38.090 --> 09:38.330
Okay.

09:38.370 --> 09:42.610
I've actually just gone and tightened these prompts a bit and made them just shorter and simpler because

09:42.610 --> 09:42.730
it.

09:42.730 --> 09:43.450
It was going.

09:43.490 --> 09:45.050
It was thrashing around a bit.

09:45.090 --> 09:48.290
The prompt is just find a one way non-stop flight.

09:49.090 --> 09:53.970
The system message says you are a helpful AI research assistant who looks for promising deals on flights.

09:54.050 --> 09:56.690
Incorporate any feedback, the evaluator says.

09:56.690 --> 09:58.530
Provide constructive feedback.

09:58.530 --> 10:00.330
Respond with approve.

10:00.490 --> 10:04.850
And so with that, I'm now kicking off our message here.

10:04.850 --> 10:11.130
And it does take it's quite chatty I discovered and it goes backwards and forwards.

10:11.130 --> 10:15.650
And I'm sure there's ways you can tighten up these prompts to make the conversation be a little bit

10:15.650 --> 10:16.290
crisper.

10:16.650 --> 10:18.890
But I will let this thing run and let it go for a little bit.

10:18.890 --> 10:24.210
And when we are back in a sec, we'll see the response from the agents.

10:24.250 --> 10:28.770
Well, I'm going to be honest with you, this is my second shot at it that I'm showing you here.

10:28.810 --> 10:33.610
I kicked this off even with these shorter prompts, and it was running for more than a minute, like

10:33.610 --> 10:34.690
going backwards and forwards.

10:34.690 --> 10:36.730
And GPT four and mini is quick, so.

10:36.890 --> 10:39.490
So I imagine it was in quite a conversation there.

10:39.690 --> 10:41.410
Uh, and so I interrupted it.

10:41.410 --> 10:46.010
I restarted my my lab and then I ran it a second time and it took 10s.

10:46.010 --> 10:46.690
And it's done.

10:46.850 --> 10:53.890
So you may want to be if you if you run it like this, then then obviously interrupt the, the, uh,

10:53.970 --> 10:59.850
the notebook by pressing the, the, uh, the button here when it's running to stop it or restart,

10:59.890 --> 11:01.130
restart the kernel.

11:01.250 --> 11:05.930
Um, if it's thrashing because you don't want to spend all of your, your, your tokens on this on this

11:05.930 --> 11:06.290
message.

11:06.290 --> 11:14.730
But I mean, I think this is a very eye opening sign of what can be troubling with these sorts of agent

11:14.730 --> 11:19.530
platforms that they can be quite hard to get them to perform the way you want.

11:19.810 --> 11:24.650
Um, you may have discovered when you're working with Landgraaf that there is a maximum, a recursion

11:24.650 --> 11:30.050
limit, as they call it, of 25, meaning that if you have more than 25 conversations between agents,

11:30.050 --> 11:34.010
then it will throw an exception unless you explicitly say you want more than that.

11:34.050 --> 11:38.090
And it appears that that there isn't the same kind of protection in an autogen.

11:38.090 --> 11:40.130
So it just kept and kept and kept on going.

11:40.490 --> 11:46.130
Uh, so, uh, be sure to to restart the kernel if that happens to you, or try and tighten up this

11:46.130 --> 11:47.810
prompt so that it doesn't happen.

11:47.970 --> 11:54.610
And observe that this is the kind of instability that is problematic, uh, with these kinds of agent

11:54.610 --> 11:58.410
frameworks, when there is autonomy to decide to keep going if they wish.

11:58.730 --> 12:00.330
But anyway, this time it took 10s.

12:00.330 --> 12:00.890
It was quick.

12:00.890 --> 12:02.490
And let's see what actually happened.

12:02.650 --> 12:06.130
The user said find a non-stop flight or a one way flight.

12:06.170 --> 12:07.330
A non-stop uh.

12:07.370 --> 12:12.690
The primary agent used the tools to do a query, and then it said it gave a response.

12:13.050 --> 12:18.090
Uh, with, with the the $402 flight there.

12:18.410 --> 12:23.690
And the evaluator responded, your response contains a lot of good information, but it lacks a specific

12:23.690 --> 12:24.970
answer to the question.

12:25.330 --> 12:27.570
And then it gives it's quite authoritative.

12:27.610 --> 12:32.490
Little does it know it's talking to itself, but it's quite, quite, quite stern.

12:32.650 --> 12:34.130
Focus on the user's request.

12:34.130 --> 12:37.760
Clarify dates, organize information, remove redundant.

12:37.760 --> 12:42.200
So it's really great to see the evaluator doing what it's told to do and evaluating.

12:42.480 --> 12:44.760
And then the primary says, thank you for the feedback.

12:44.760 --> 12:46.640
Here's a revised response.

12:46.640 --> 12:49.920
And it does indeed give a revised response with all that detail.

12:50.200 --> 12:54.600
And the evaluator sends approve which is the text that it has to respond.

12:54.640 --> 13:00.680
This is a little bit hacky, but it responds to the word approve because reply approve and your feedback

13:00.720 --> 13:05.080
is addressed and because it says approve, that means that the termination condition is met.

13:05.080 --> 13:06.800
And this completes.

13:06.920 --> 13:11.280
And that is how we arrive at our decent answer here.

13:11.280 --> 13:13.840
And this is an example of a team at work.

13:13.840 --> 13:17.840
And there's a lot more that you can do with teams, but I feel like it's pretty consistent with stuff

13:17.840 --> 13:18.600
we've done before.

13:18.680 --> 13:21.040
So this gives you enough of a flavor for it.

13:21.040 --> 13:25.240
Now, should you wish to build out your teams, you can look at some of the docs and build out something

13:25.240 --> 13:27.000
a bit more extensive than this.

13:27.400 --> 13:27.760
And.

13:27.800 --> 13:28.720
But just be aware.

13:28.760 --> 13:32.760
Be be aware of the fact that they can just just keep going.

13:32.800 --> 13:36.240
And you need to be you need to be ready to intercept if necessary.
