Continuing with our business project.
So this is a look at a Google Sheet I've set up to represent my stock portfolio.
Uh, and the idea is that and I will of course share this sheet.
You can recreate it if you wish, or you can just use one that's set up.
It's going to be set up with, uh, it's got a bunch of stock tickers.
Here they are.
These are in fact in my portfolio.
They are tickers that represent what's called ETFs, or they are sort of investments in a group of different
shares.
And each one of them, I've got some quantity of them and they represent some of them are 100% equities.
They are all all stocks.
Some of them are all bonds, all fixed income products, and some of them are a blend between the two.
And this column C and D represents how much is is stocks, how much is equity and how much is fixed
income.
And that is the breakdown.
And it's common particularly with retirement accounts, but with longer term savings and with many portfolios
that you have this breakdown between between equity and fixed income.
And it's common that you might want to rebalance it.
And in fact, pay people to do this for you to take some cut of your money in return for rebalancing
your portfolio.
But there's no need, because an agent can do it for you, and it can do it for free.
And so that's that's what we are building today, our own financial planner that is able to rebalance
the portfolio by making trades to to set your your balance of equity and fixed income to what you want
or really to do any kind of rebalancing that you might wish.
All right.
So in this spreadsheet, there are a few sets of things that we're going to want our agents to fill
in.
And one of them is this column here price.
And price represents the current value of this equity in the market.
And we've already seen an agent fill in this column.
You know it.
And we'll be able to do that again.
But this one is the new column.
This is for the agent to fill in to say how many shares should we have?
How much quantity of these different tickers after I've made some trades to rebalance the portfolio
and it will fill in this column as it makes its decisions.
And when it does that, there's going to be a new total value coming up, and we will find out what
kind of proportion between equity and fixed income does it get at the end of it.
And of course, you can add in other kinds of of metrics like whether it's, it's global or, or national
investments and so on, should you wish to rebalance in different ways.
Okay.
So that's the spreadsheet setup.
Obviously the price is all blank here.
But if I put in a price like 100 then it fills in the value.
And if I put in a new quantity after rebalancing of three, then the total value goes in there and the
other things fill in.
But we're going to leave it blank for now.
This this is a spreadsheet that we are going to be equipping our agent with and it will operate on this.
Let's go and do that.
Okay.
So we go back to Nw10.
Here it is.
We are going to add in an agent and let's take a look at it.
There it is okay.
We've got lots to do with this AI agent.
We're going to give it a chat model.
We're going to I'm going to use OpenAI.
You can use whatever chat model you wish.
And we are going to choose I'm going to choose GPT 4.1.
Now the reason for that is that I want to I want it to be a really smart model that does it well, uh,
you can choose what you want to to, to use.
It costs a few cents a pop with GPT 4.1.
And of course, it's a fraction of that with GPT four one mini.
And you should go with whatever you're comfortable with.
I do find that the latest models like GPT 5.2 for me right now actually doesn't perform as well because
it does too much reasoning and it takes too long.
And the outcomes for me are better just using GPT 4.1, which for this kind of thing is one of my favorites.
Okay, so I'm selecting GPT 4.1, but of course you can do anything over open router.
You could be using Gemini.
Use whatever you want to okay.
And and back we go here I'll press that tidy up button to make it a bit cleaner.
And we will we will then keep going with some tools okay.
and we're skipping memory.
We don't need memory for this because it's just on a form submission.
There's no chat history to have to remember.
We go straight to tool and we're going to go to sheets, of course, Google Sheets tool.
It's already set up with the right credentials.
We know we can connect.
Fine.
We're doing a sheet with a document.
We want to get rows.
This is going to be the way that we fetch the contents of our portfolio.
The documents we're going to get is going to be uh, from from a list.
And we're going to choose the, the portfolio.
And the sheet is also going to be from a list.
We're going to choose the sheet number one.
I'll do that now.
So I chose portfolio from the list here.
And I'm now choosing the sheet is sheet one right here.
And I'm not going to set any filters.
I want it to be able to to retrieve the whole thing.
Okay.
So that has set up our Google Sheets access.
Let's press the clean button.
And now we will give this a try and see what happens.
And hopefully you're expecting something to go wrong.
Let's see okay I'm now going to press Execute Workflow and bam.
Up pops this window.
It's it's a form.
And it says portfolio Rebalancer.
It's the very form that we just described.
And it has the one question that is the field we put in there.
How would you like to rebalance your portfolio?
And the default answer is 60 over 40.
And I'm going to press submit.
And pressing submit is basically sending an HTTP request which Nen has configured as a webhook.
And it is expecting this to come through and bam it has come through.
And if I click back here, you'll see that the workflow has run and it says there's a problem just as
we're expecting or are you expecting?
I hope you're expecting.
So now let's go in and fix that problem.
And so you'll see the error message tells us no prompt specified.
And you'll recognize that because we've had it before.
And if you open up AI agent we'll see more details that it was trying to bring in Jason chat input.
It thinks it's connected to a chat trigger node and it's not.
It's connected to something very different.
So the first thing that we need to do is to change this from saying the source for the prompt is a chat
trigger node to say.
Define.
Below we want to tell it how to look in the inputs and choose what should be the prompt to the LM.
And this is the input.
This is the webhook that got called as a little side note.
Notice that it is of course an array of items.
And that's as I explained, that really what gets moved between these nodes are these arrays of items.
But there's only one.
It's the submission of our web form.
And it only has this one question how would you like to rebalance your portfolio?
And it's this stuff here.
This is what we want to be sent to the LM.
So let's drag and drop that in there.
Let go.
And you'll see that it's put in there the right JSON to use JSON.
And then it's selected.
How would you like to rebalance your portfolio.
And so that's that's working nicely.
That's going to take this contents here and make it the prompt to the LM.
So I'm going back here to the canvas I'm pressing Execute Workflow.
Up comes this pop up and I'm going to submit it.
So this time it will hopefully be sending this exact instruction to the agent when when this goes through.
and what I think we'll find is something a bit curious happens, because we've not done a very good
job of telling the agent what we want it to do.
We've just said ensure the portfolio is 60% equity and 40% fixed income, but we haven't told it that
that portfolio is in this Google sheet.
We haven't really given it good directions.
This used to be what they would call prompt engineering.
We've not done a good job of prompt engineering.
The new expression is context engineering, which is the way to best position your whole agentic workflow
to to equip your agent with the best possible information.
And we've not done a good job of any of that.
So let's see what it says back now that it's just successfully run, let's see what happened.
And you can see that what's happened is in the output.
It said to ensure a portfolio is allocated 60% equity and 40% follow these instructions.
And it's given us some sort of bland, generic content about what to do.
It never used the tool because it didn't know that that tool was going to tell it our portfolio.
So it didn't do any of that.
It just kind of gave us back some, some random instructions.
We need to improve the prompt so that it knows what it has to do, and we also need to give it a few
more tools so it can do it.
And that's what we will come to next.