And here we are back in the Jupyter Lab for the fast approaching conclusion with a really great project.
Super satisfying.
Wait till you see.
So this time we're going to start by looking at two more of our simple agents.
Probably the simplest we've got.
There's one called the Messaging Agent, which we will use to be sending messages, and one called the
planning agent, which will coordinate activities.
And both of these agents are ones which are just Python code.
They're not using Llms, and there's no reason why they can't be beefed up to use Llms.
The messaging agent sends a notification, but of course, it could first make a quick call to a frontier
model to improve that, to make it something that's juicier and that that is, is relevant to that particular
deal.
So there's plenty that can be done here.
And the planning agent, it's written in code.
You could experiment with turning that into an LLM.
Getting to plan out what happens itself.
But we'll at least see them and use them both in a second.
Uh, and um, we're going to then afterwards put all of that into our agent framework.
But you can imagine, because we've put all of the building blocks together, the final part of having
an agent framework is a cinch.
It's going to be just very straightforward.
So let's start by talking about the messaging agent.
This is the agent that's able to send us alerts when it finds a great deal.
Um, and originally my plan was to send text messages for this.
And I was going to use Twilio, which is a lovely framework that I've used in the past, but there's
been a lot of regulations recently that makes it really quite hard to set up a Twilio account to send
text messages, even to yourself, even when you've validated your own phone number and you want to
send yourself text messages, you have to fill in a fair bit of paperwork.
If you're in the US now, that might be a lot easier in other countries.
It does seem to suggest on the website that that it's just a US restriction that makes it so hard.
And Twilio has a free plan.
Twilio is also free to make WhatsApp messages as well.
So you can have it.
WhatsApp and I did have it working whatsapping myself, but there are some constraints that you just,
um, you can only use the free thing if you're using a sandbox which has some limitations, and you
can only do it between certain hours of the day.
So it wasn't ideal.
So it was okay.
And I've kept the code here so you can use it if you wish.
But then I discovered something really, as I say, nifty called pushover.
Uh, there's a few things like pushover, but pushover was was the one that I found to be the nicest
of the ones I tried.
Um.
And pushover is a simple website where you can go and you set up an account.
It's free.
Uh, and you then download an app.
In fact, you don't need to go to the website.
You can.
The website is pushover dot net, not.com.
Uh, they weren't obviously weren't able to afford.com.
It's still up for grabs.
But pushover dot net is their website.
And then there's an app called pushover.
Uh And it's free to set up.
At least it's free for up to 10,000 messages.
And I think we're not likely for this particular project to get close to that.
You can see I've managed to get to 35 messages of my allowance so far.
Um, and now the reason this page looks a bit janky is that I've scrolled down because it shows above
here my tokens in big letters, and I didn't particularly want to reveal all of my tokens to all of
you.
Or you might be constantly notifying me all through the day.
So yeah, it's hard not to miss the tokens as soon as you sign up for your free pushover account.
I promise I'm not affiliated, but it's, uh, seems to be really, really helpful.
Um, once you've signed up, you then take your tokens and you can then easily send push notifications
so you'll end up with two tokens a pushover user, which is a token that applies to, uh, to you.
And then you have to set up each of your applications, and you just choose one.
And I called it preserve for me and you can give it a token.
Um, and sorry, you can't.
You get given a token once you've set up your application for that.
Uh, and these two things you should add to the EMV file.
Wonderfully.
You can also upload a, um, an image, uh, associated with your application.
And I found an image, uh, looking around of a stack of coins.
And so I uploaded that because it's great.
When I get a push notification, there's a little image comes up and it comes up on my Apple Watch as
well.
The whole screen turns into this stack of coins, uh, which is really good fun.
So you might want to do the same thing.
Find a find a cute image to go with.
Push over if you use that.
Um, as I say, if you if you are able to, if you either already have a Twilio account or if you go
there and you see that it is straightforward in whatever country you're joining from, then by all means
you can do that instead and get a text, a bona fide, uh, SMS text message instead of a push notification.
But push notifications are all we need for this.
Okay.
So I'm going to go straight to this this class messaging agent under agents.
Messaging agent is one of our agents.
Here it is.
It's very straightforward.
It is basically a wrapper around the Twilio API and around the pushover API.
And I've got at the top do text and do push as two constants that you can set, because if you wish,
I didn't want to make it a either or because you can have both, you can have it text you and push notify
you if that is what you desire.
So there's an init, uh, constructor which sets up, um, the, the various, uh, criteria.
If you're doing push notification, like me, as I say, you need pushover user and pushover token,
and you can always just type it straight in here if you don't want to faff around with env files, um,
obviously, then don't push this code.
Uh, and if you're using Twilio, then you need to have an account Sid and auth token.
A Twilio from, which is the number that Twilio will give you, is the number that it's coming from.
And then the phone number that you want it to text message to.
And so I have these four in my env file.
But I'm not using it because I filled in the paperwork just to have done it.
But I haven't yet been granted authorization to send a text message to myself.
Uh, but hopefully that's going to come one of these days.
In the meantime, the push notifications are great.
So I've then got two, uh, methods here message, which is simply a wrapper around the Twilio API,
which as you can see, it's really simple.
It's it's the Twilio client dot messages dot create.
And you say who it's coming from and the text and who it's going to, and that's it.
And it will send a text message.
I've used it before.
It just works.
Receiving text messages is pretty easy too.
You just have to have an endpoint that gets called a webhook.
Um, and but obviously we don't need to do that.
Uh, the push notification is also very simple.
Um, we but it doesn't have it doesn't use an API because they, they, they're sort of keen to point
out, I think, on their website that it's intentional.
They just want to keep it as straightforward as possible.
They don't even use the requests library in their example code because they wanted to say, you don't
need to import anything.
You can just simply use out of the box Python to send a push notification.
Uh, and you simply pass in the token, uh, the message.
And optionally you can include a sound.
And I one of the ones that they suggest as being available is called cash Register.
And it makes a very pleasing cash register sound when I get the notification, which is great fun.
Uh, and that's all there is to it.
And then there's an alert, uh, method here, which, based on whether you're texting or pushing it,
will construct something to tell you about.
And it will then send a message and it takes an opportunity.
So you pass in an opportunity and you'll get a message about that opportunity.
You remember, opportunity is the object that we looked at down here that has a deal, an estimate and
a discount.
All right.
But first let's just quickly try it out.
I should just be able to create an instance of this.
And I should be able to say massive news and ping my phone just went.
Now, unfortunately, I have quite aggressive noise filter on my microphone to to only bring out voice.
So I imagine you didn't hear the cash register as I say, very pleasing indeed.
Luckily you'll be able to hear it for yourself when you try it out.
Uh, and yeah, I'm going to have to hear that again just because I love it.
Uh, there it goes.
And yeah, my watch two has has come up.
So it's, um.
Yeah, very satisfactory indeed.
That then is the, uh, the messaging agent.
I will see you next time for the planning agent.