Adding a Revenue Tool0:00
All right. So a few episodes ago, we used this example of prompting the AI for information about our revenue from the previous quarter. Of course, the point was to demonstrate it can't do that because it doesn't know anything about our application, right? Didn't have access to any tools. Well, now let's give it a tool. So we have a couple of options here. We could give it a tool to interact with our database directly,
So we have a couple of options here. We could give it a tool to interact with our database directly, or we could give it a smaller tool that houses information about our revenue. Why don't we take that approach? So let's do this. I'm going to create a brand new tool. Let's just copy current time and we'll call it, I don't know, revenue. All right, the name is going to be site revenue. Now, again, of course, there's so many different ways we could do this, but why don't we make these a parameter?
Defining Tool Parameters0:48
Now, again, of course, there's so many different ways we could do this, but why don't we make these a parameter? So we're going to give the AI the ability to say, all right, I want site revenue for quarterly, right? There is something along those lines. So you'll remember within read file, this is how we can accept parameters. So why don't we copy that, paste it in. Why don't we call it like interval frequency period, maybe period? The period of time to fetch revenue for.
Why don't we call it like interval frequency period, maybe period? The period of time to fetch revenue for. And because this is JSON schema, we can also do an enum here. So what are the available options effectively? Well, we're going to do, like we said, with this example, daily, monthly, quarterly, and yearly. All right, the period is required. We have, let's turn on strict mode. And that will enable structured output, which is really important.
Stubbing Revenue Responses1:39
We have, let's turn on strict mode. And that will enable structured output, which is really important. We're still going to talk about that. And I think that looks good. All right, so our revenue tool contains this definition. And when we use it, the period or the interval will be arguments period. And then, yeah, we're just going to stop this out. We'll say, how about this, send through the period. And if it's daily, you know, 900 bucks or 900 cents, whatever you want,
We'll say, how about this, send through the period. And if it's daily, you know, 900 bucks or 900 cents, whatever you want, monthly, quarterly, and yearly. You know, it doesn't matter what the numbers are. In real life, maybe you're doing a database query to compile statistics grouped by the interval. It doesn't really matter. Let's do unknown period in the event that you give us something that we don't know. Although, that shouldn't happen because we have strict mode turned on.
Testing the Agent Tool2:44
know. Although, that shouldn't happen because we have strict mode turned on. So this looks good to me. Let's return to our agents. And we now have a new tool that it can reach for if it needs to to solve one of our prompts. All right, let's give it a shot. PHP artisan agent, how much did we earn last quarter in revenue? So it's going to use the tool site revenue. Very cool.
Fixing Output Type Error3:07
So it's going to use the tool site revenue. Very cool. Oh, and it fails. invalid type for output expected of a string, but got truncated. I know what this is. So when we have the outputs, where is it? Where we append to the output, we want to make sure that's a string. So maybe as a safety, we will cast it. But also, yeah, generally here for revenue. Yeah, this is going to be returned as a string.
But also, yeah, generally here for revenue. Yeah, this is going to be returned as a string. So again, I could force it like this. But yeah, that's what it's going to expect. OK, one more time, ask the same question. We run the tool. It gets the result. It calculates a response. And we earned $120,000 in revenue last quarter. What about last week?
Previewing Structured Outputs3:50
And we earned $120,000 in revenue last quarter. What about last week? So once again, it's going to run the tool for daily. Last week's revenue was 900. All right, so in the next episode, I want to talk a little more about structured outputs. What is it, why do you care, and how do we enable it?
