Okay, so I want to add one more element to our workflow.
And I want to add in some sort of traditional workflow elements.
One of the great things about Nan is that it combines the best of the kind of agentic AI, uh, set
up Visual Builder with the kind of traditional workflow tools like Zapier, something which lets you
integrate APIs with some nice workflow capabilities.
And that's what we're going to do.
Now.
Look, the AI agent, its output is supposed to be the word okay.
And that's something that we can test for.
So I'm going to I want it I want I want to set this so that if things go wrong and it doesn't achieve
the right outcome we want, then I want it to alert me, send a push notification with a warning, and
if it goes right, I also want to push notification, but not an emergency one.
Just just a normal one.
So basically we're going to want to have two different notifications.
One of them will be problems.
One of them will be all is well.
And we want it to pick one of those two.
Depending on whether the answer from this AI agent is the word okay or not?
All right.
So that sounds like maybe that's going to need some code.
It sounds like it's something which needs like an if statement of some sort if you are familiar with
coding, but uh, perhaps, uh, there might also be a simpler way, which is to use an if node, there's
a bunch of nodes which are to do with like laying out simple logic visually for people who are low code,
no code, and who would rather be able to visualize the instructions that you're giving your workflow.
And that is what we're going to do right now.
We're going to add an if node right here to say if the agent did what it was told and answered, okay,
then we'll send a happy push notification.
And if it didn't, we'll send an upset push notification.
Let's build that right now.
And by the way, if you're wondering about the UI that we're looking at here, that that logs screen
is the same as it is on the executions tab.
You can open and close the logs by clicking on the word logs.
And it gives you more, more breathing room, more space here.
So I'm going to press the plus button right here.
And I'm going to type if to get the if node routes items to different branches.
And basically you have to put in a condition value one and then like is equal to or some some some comparison
and then value two.
Okay.
Well for value one I'm going to put in an expression.
And that expression I'm going to put in is I'm going to say dollar JSON.
The stuff that's coming in dot output, which is the uh, the, the thing that, that is the output
field, which we know is what the LM produced, that if that is equal to, uh, okay, this I want that
to be fixed.
Just just the text.
Okay.
That is going to be ah our node.
Ah.
If node if the output coming from the LM is equal to okay.
That's the end of describing that node.
We've got the if we've got two branches here, a little true and a false, and we're gonna hook up two
different things to that.
Well, you know exactly what we're going to do for the true.
We're going to press here.
We're going to type pushover.
And we're going to push a message.
That's the action.
And uh, I'm going to paste in my user key in just a second.
Uh, we're going to make this b b b, uh, low priority.
I don't want it to make a noise.
And the message will be, uh, rebalancing successful.
Now, you'll notice that there's no button here to say let the LM choose.
Let the model choose what goes here.
And you might be wondering why is that.
And I'm going to come to that in just a second.
All right.
So I'm going to fill in my user key in here.
I'll come back and do that in a second.
I'm going to put in the false branch of this.
We're also going to use pushover.
You can see it wants an action.
Push a message.
And we're going to say push.
I'm going to put my user key there.
This time we're going to make it.
Uh just say, uh, I guess we'll say emergency priority and we'll make the message be, uh, that the,
um, rebalancer failed.
There we go.
And save that.
And now I will just come in and update with the two, uh, user tokens, and then I will explain something
very important.
Okay.
I've set my user tokens.
The red angry triangles have gone away because this is all good.
Everything is set up.
What is it?
I wanted to explain to you.
Well, I wanted to say, what's the difference between this pushover right here and this pushover right
here?
One of them, this one here is we're using it as a tool.
Right?
It's what I told you before.
It's called a subnode.
And it's in a circle because it's a tool here.
It is just a core node.
It is a node on the workflow.
So what's the difference between those two?
Well, here's the thing.
When it's a core node, it is just a step in the workflow that is being automated at that point, and
no matter what, the push action will always be called the send a message action and it will always
be called with the data that we've put in there.
It's a fixed step on the workflow, and this has nothing to do with LMS.
It's just a step in the workflow.
If you had Zapier and you were controlling different things, you may not be familiar with Zapier.
There are lots of tools like this where you can have steps in the workflow, and it will always be called.
In this case, it won't always be called because we've got an if statement, which is a fixed bit of
logic.
And depending on this logic, either this push will be called or this push will be called.
Similarly, I could I could move, I could put a push node right here.
And then every time you submit the form, there would always be a push notification.
Maybe you should try that.
That is different to what we're doing here.
What we're doing here is a special feature that the push node supports being used as a tool, and only
a subset of nodes are allowed to be used as a tool only if they've been specially set up that way.
And when it's used as a tool, it is different.
First of all, there's a description of it that's given to the LM as we saw.
That tells the LM what does this do?
Secondly, the LM gets to decide whether or not to use that tool.
Details of the tool are put in the system message.
As as we talked about a few days ago, the LM gets to decide in its response whether or not it wants
to call that tool.
And finally, optionally, you can specify that the LM should fill in some of the inputs to that tool,
as we've done for some of these like like the message in this tool.
And so all of those are completely different to when you just slap a node on on your workflow as we
have here, in which case nothing to do with LMS.
It's always called.
So that is the crucial difference between using a node with with an action with the node operation is
action like we have right here, versus using a node as a tool.
As a it's a sub node and it's called at the discretion of the LM.
I hope that's clear now.
Okay.
And with all of this it comes for me to come to the portfolio and clean this out.
We don't want you set there and we don't want you set there.
Come back here.
And now we're going to execute the workflow again with this whole setup.
Up comes this.
We're going to submit this.
And off off it goes.
Action stations uh hopefully in any second now this this whole workflow will kick off.
Uh, and uh, it's waiting for the trigger event.
And it's sometimes, as I say, sometimes I find that it that it lags what's, what's actually happening.
The user interface takes a moment to refresh, but with any luck, it will kick into gear.
Uh, I think this time I won't give you the running commentary.
I'll come back in a sec when it's run.
And there we go.
It has just completed successfully, and I just got, uh, the I got I got two messages, I got one
that's saying portfolio is rebalanced and I got another which is rebalancing successful.
Exactly what I typed out.
And you can see in here the if is ticked and you can see that this arrow here is green because it did
indeed match, okay.
And it went over to push uh, the, the positive message.
It did not push the negative message.
And so are more sophisticated workflow is complete.
And I just wanted to show you here the your first site putting logic on your your workflow and how these,
these nodes can be used just to carry out a more strict business process.
Okay.
Well, there is one more step left.
Uh, let me tell you the final thing we're going to do.
All right.
Well, the last thing to do, you may have guessed, is to deploy to production, to publish.
Uh, and the first thing we want to do is just go into this form submission, and we'll just want to
go over here to this production URL and just copy that, uh, because, uh, that is, uh, that's where
we want to go when, when we've deployed to production.
So I'm just going to go out here and make sure it's saved.
You've probably been doing this.
I always automatically press command s all the time, but hopefully you've done that and then it's going
to be time to press the publish button to publish this.
So it becomes a live workflow.
Got it.
Now we're going to open up.
First go to the portfolio and I'm going to wipe this out.
We want to start from a nice and empty portfolio and open up that URL right here, which is hopefully
going to take us to a form that we can submit.
Uh, and then we will use that to trigger our workflow.
Here we go.
Portfolio Rebalancer.
This is like a live web page out there on the internets.
And I'm now going to say submit.
And it says your response has been recorded.
So that is now off and running.
And I'm going to be waiting and hoping to receive a bunch of push notifications, I guess.
I mean, I'm going to be hoping, well, it's already before I can even flip over there.
It's already filled in the prices.
So it is indeed running in production.
It's now thinking about how it will rebalance, hopefully, and I imagine that very shortly it's going
to come back and start doing putting in the quantities here.
Uh, and then I will get my notifications and what it's doing that let me tell you your, your assignment,
I can see it's doing it right now.
Uh, amazing.
I'm not touching anything.
Uh, which is to improve this, to come on in.
One of the things you'll notice is that it's not very stable.
I can see it's tweaking and updating things here, figuring out how you can improve this so that it's
more accurate, more dependable is there's the message.
Uh, fantastic.
And, uh, that's very cool.
Let me let me go into my push notifications.
I got two messages.
You only heard one noise because the second one was low priority.
So it doesn't make a noise.
But there it is.
Deal successful.
Uh, so, uh, we were able to to complete this flow in production.
It's been successful.
That is our deployed workflow running.
And of course, uh, you want to see that the email arrived and it did arrive.
There it is.
Uh, the the portfolio balancing email.
And so it does appear to have been successful.
Uh, and we can go to, to, uh, to executions, um, to see the, the, uh, the results of the run,
uh, and that, that, that as I say, it was it was successful.
And there we have it.
And we can, of course, look in at the logs and go through all of the details of what it did, that
that is our workflow running in deployed state.
And if you hover over here in this, the logs, you can see how many tokens this used up with the AI
agent.
The prompt is the number of input tokens, the completions, the number of output tokens.
You can see there's a lot of inputs there, because all of the tool use was like packing information
into the context, which is where context engineering can be helpful.
And indeed so.
So the deficiency with this that you'll quickly discover if you do this yourself is that it does start
to lose coherence with larger portfolio sizes.
So this can handle the portfolio size we just had with with ease.
But larger portfolios it can't keep up.
And there are solutions to that.
There are solutions from adding in more information in the sheet.
That gives it a better clue as to how everything balances, to equipping it with a calculator so that
it can make calculations as it goes to improving the tools so that they're able to help it figure out
how to rebalance.
Because the actual rebalancing calculation itself is something that could be quite trivial.
So that that really the mission for you is to make this more reliable and more industrial strength by
improving the prompts, potentially improving the tools, and improving the spreadsheet so that you
equip the AI agent with the most possible information in the simplest way so that it can still be autonomous,
still make its own decisions, but it's quite easy for it to make the right decisions quickly and then
notify you.
And then you will have your your running portfolio rebalancing agent.
And that's a wrap on our first project.
What I loved about this is that it's so real world that this really does map to something that happens,
and now you've automated it.
And you can also think about changing that trigger from being a web form to being one of the scheduler
things.
That means that maybe once a day it gets kicked off and just automatically runs and then sends you the
notification with how you should rebalance your portfolio.
And again, that just feels so real world.
You've just automated a business process, and that is a fitting way to wrap up the first week of this
program, which was headed automate with workflows.
That's what we did.
And that's a wrap.
It was it was a big week.
You learned a ton.
There's lots of definitions and terminology and I'm sorry about that.
But it's great that we've got that out of the way because we can focus on really juicy stuff.
Next week is voice agents and 11 labs, which is such fun.
I can't wait to show you this.
But first, take a moment to celebrate that you are 33% of the way through the program, a third of
the way through next week.
So much fun!
I'll see you then.