So this whole week is about automation, automation of business process.
And a big part of automation when you're using AI agents is positioning an AI agent so it can carry
out your business process in the best possible way.
And a lot of that comes down to what they once called prompt engineering and is now, of course, context
engineering.
And for the time being, we're just going to do pretty simple prompting stuff.
I'm going to double click on the AI agent and up it comes.
And this you'll remember, is the user message.
We're taking the stuff that's coming in here and we're just shoving it in the prompt.
Well, the thing about these expressions is that you can mix and match.
You can put normal English above this.
When we've got this expression right here, you can see that that's the result.
Well look at what I can do.
I can put a couple of lines up here and I can say bananas.
And then this is what the result will be.
Bananas.
That wouldn't be very helpful for our agent, but maybe this would be more helpful.
I just pasted in something I wrote earlier.
Uh, you have access to the users equity portfolio, which is in a Google sheet.
You also have access to market data.
We've got to add that the user has asked you to rebalance their portfolio with this instruction.
And then I've got the expression.
And when we look at the results in the field immediately below look at what's happened.
We've got that text I just typed.
And then we've got the actual contents of this instruction.
Right.
It's kind of obvious when you see it.
So that's a really nice way to make a prompt and add in the user's input as well.
But wait, there's more.
Right underneath this prompt I'm going to put some some more stuff as well.
You can put bananas here too at the end, but that's also not very helpful.
Instead I'm going to pay something else in here.
And this is a bit more wordy.
Let me read this to you.
I'm saying in order to achieve this, number one, reading the portfolio from the sheet, number two,
fetch the latest prices of the positions.
Number three update the table with the prices.
Number four Make decisions on portfolio rebalancing.
Five.
Update the table with the portfolio rebalancing decisions.
Number six.
Read the table again to check that your rebalancing met the objectives.
Make any further changes in number seven like iterate.
And finally send an email with the trading decisions and a concise push notification.
You can see the tools I'm about to add.
Uh, okay.
So so what do you make of this?
Have have a think about what I've done here and and what might be your counterpoint.
What might feel a bit funny about what I've done just here?
Well, here's the thing.
If you were the challenging sword, which I know you're not, but if you were, you might say to me,
look, you've kind of written out a workflow there.
You've got like steps, you've even numbered them.
You've got like steps.
Why would why do we need an AI for this?
If we've got steps to do, we could just lay out a workflow, we could use workflow tools, or there
are a lot of other more simplistic non-ai workflow products where you can just do one step and then
another step and another step and and surely the whole point of Agentic AI is that you're just giving
it a goal and let it figure it out.
To which I would say to you, yes, you're right, very good challenge.
But these are quite loosey goosey steps.
These are not steps that would be easy to turn into code.
Look at this step here is like, uh, read the table again to check you achieved the objectives and
make any further changes to improve the rebalancing.
So this is kind of hand-wavy like rough human like instructions, like you might tell a person and you're
just kind of taking not just one very, very high level goal.
Rebalance the portfolio.
You're giving it some guidance so it knows how to do it, but only in a pretty high level, flexible
way.
That gives it some autonomy, as I like to say, to decide exactly how to achieve this and how many
iterations to do, how to read the spreadsheet.
We're leaving a lot up to the agent, and this is the kind of balancing act that that is all about getting
the most ability, the highest performance out of a genetic AI.
It's about figuring out how to keep the instructions nice and high level, so that it has the flexibility
to be intelligent and nuanced about your instructions and decide how to achieve the goal, whilst also
giving it enough enough sort of rails so that it does stick to what you want it to do.
And you know, there's something of an art to this, and the best way to get it right is by experimenting.
There's no right answer.
The best way is to try.
And originally when I first built this, I did just have a very simple objective rebalance the portfolio.
And I found that it wasn't reliable.
And I've got to this point with some iteration.
And that's what you have to do too.
And certainly I would encourage you to be doing that.
And that's where the real learning happens as you experiment with different levels of detail and find
out what balance works best.
And each model will have a slightly different balancing point to be to be found, and you may find that
if you're using Gemini, that it's able to work with higher level instructions and be very reliable.
So best thing to do is to experiment with it.
But I wanted to give you that that understanding of why one does it this way and how I came up with
these steps.
Okay.
Onwards.
So in order to achieve all of this, we now need to add in some tools.
And have you been paying attention to what we need to do?
Let's go back.
Maybe you could have a shot at this before.
Before I do it with you.
See if you can do it.
Uh, but let's move.
Give ourselves a bit of space and add in the first tool.
What should we do?
Well, let's go for the market stack.
Add in market stack.
Here it is.
We're going to get end of day data.
We want to get many.
We let the model choose which ticker.
And we just say here what was the other thing.
We have to add a filter and say latest.
And that is all set.
That is market stack configured.
I should confess that I believe you get 100 free lookups.
Uh, and I exceeded my 100 free lookups, and I have just upgraded to the paid plan.
You should be able to stay well within the 100 lookups for this project, but if you get into.
Experimenting like I did, you might end up going above that number.
And then you can choose what you want to do.
Uh, but I decided it was worth it because I'm really enjoying this.
So that is the the next tool, the market stack.
One back to an old friend added to our agent.
All right.
Two more tools.
Now they are both going to be about updating the sheet updating the Google sheet.
There's two ways in which the sheets might need to get updated.
So let's do them right now.
So this is going to be using Google Sheets.
This time we want it to be an update row.
And we're going to update that that same spreadsheet so that it can update the prices.
This tool will allow it to update the prices.
So I've selected my Google Doc portfolio from from the documents for the sheet I'm going to select sheet
one, which I think is the only sheet in that document.
Document is right over here.
Remember, this is what it looks like.
It has a price column and a new quantity after rebalancing column.
Here we go.
What am I doing?
It's still thinking.
Um, and so then what we're going to have to do is to set it so that it can filter on the, on the ticker
and set the price.
It's a very slow for me.
Hopefully it'll be faster for you.
Sheet one there we go.
Uh, so we're going to select on the uh ticker the ticket.
We'll let the model decide.
And we want it to be able to set the price.
We will let the model define the price.
There we go.
Uh, so this this is what the, the this will be able to do to set the price.
Okay.
That is one of our tools added.
And now we're going to do exactly the same thing.
We're going to have another tool.
Let me press the clean up button.
There we go.
We're going to add another tool.
And it's also going to be Google Sheets, and this time it's going to allow it to change the portfolio.
The rebalancing decisions will will add that to it as well.
So we're going to be uh, update row again.
Uh, update row.
And I'll choose that document and we'll get that set up okay.
So I've chosen portfolio I'm going to choose sheet one which there it is.
And this time we're going to say uh that uh we're going to want to, to be able to again filter on the
ticker, but we're going to want to be able to change the portfolio.
Uh, the, um, this column here, new quantity after rebalancing.
So it is filtering on ticker and then it's going to set column G.
So it will work.
Still fetching the columns.
Let it finish that off hopefully.
And it's going zippier for you.
Uh, but uh and of course in week three will be self-hosting, so we'll be able to run at our computers
speed.
Uh, it's still fetching the columns.
Uh, okay.
Well, I will see you in a second when that's refreshed.
And then we will set this up.
Okay.
So it says select column to match on.
So we say the ticker using that to match.
And we will set the new quantity after rebalancing.
That is our other tool.
Okay.
We have now set up.
So let's let's let's take stock.
Let's clean up.
We have tools for our agents.
We have a tool.
Wow.
It hasn't cleaned up enough.
We've got too much too many tools.
Uh, this is cool.
So we're going to be, uh, we have a tool that will will get the contents of the sheet.
We will be able to look up market data.
We'll be able to update rows in the sheet for pricing and update rows in the sheet for the the rebalance
this column here.
The new quantity after rebalancing the update to this after it's rejiggered the portfolio.
All right.
This is all pretty exciting.
One more tools.
Do we have any more tools.
Do you remember the tools.
Let's go and do those final tools.