8 Simple Hacks for Smarter AI Agents in 8 Mins

Eight API settings that change how AI agents behave: frequency penalty, temperature, top-P, response format, max tokens, timeout, max retries, and presence penalty. Each one controls something specific, from repetition to creativity to how long the model waits before giving up. OpenRouter lets you tweak them across different models.
Chapters
I've never talked about these settings before, and most people don't even know they exist, but changing just one for your AI agent can help it actually behave the way you want it to. So in this video, we're going to be breaking down these 8 hidden settings that you need to start using when you're building AI agents. Okay, so let's just get right into it. We're looking at these 8 different settings that you can actually find within the chat models or the brains for your AI agents. So right here, if I click into OpenRouter and I click on Add Option, you can see that we have these 8 options right here, which are Frequency Penalty, maximum number of tokens, response format, presence penalty, sampling temperature, timeout, max retries, and top-p. So we're going to break these down. And before we start breaking them down, I just wanted to highlight something real quick. So right here we're looking at like Claude Sonnet-4, right? And we're doing this through OpenRouter. No matter which different model we use. So let's say we go up here to, you know, this random one, we still have all those same 8 options. And if we go back to like a GPT-4.1, we're still going to have those 8 options. But if we were using Anthropic's models through the Anthropic chat model, we have different options. So that's just something to keep in mind. Here you can see we only have 5. OpenAI's, we have the same 8. Deepseek's, I think we have the same 8. And Google's, we have only 5 once again. So I like to use OpenRouter. I like to keep all of my billing information in one consistent place. I get the analytics there, and now I just have like the same 8 settings for all my different chat models. Anyways, just wanted to get that out the way. So we're going to be talking about OpenRouter today, and let's just get started with the first one, which is frequency penalty. And by the way, if you want to download this doc where I have articles about each of these settings and a summary table, when to use them, that sort of stuff, you can get this in my free school community. Link for that will be down in the description. And once you join the free school, just come up here and search for the title of this video, and then you'll find that PDF right there. But anyways, the first one is frequency penalty, and what this does is it discourages the model from repeating the same words or phrases. If I click into this and we add frequency penalty, you can see that by default it's at 0, which means that repetition is likely. And the highest you can go up to is 2. So if I put 3, it would just go to 2. But when you're at higher, closer to 2, it makes the repetition less likely, while negative values encourage repetition. So you can even put in something like -2, and now the model is encouraged to repeat words and phrases. But like I said, the default here is just going to be 0. Okay, so the next one we're looking at is maximum number of tokens. And what this does is it sets the maximum length for the model's response. So that way you can kind of control if you don't want them to write a whole novel for you every time and blow through your tokens and your credits. Then you can set what's the maximum that they can actually output. So maybe you have like, you know, you're trying to send a message through Telegram and it only has 1,000 token limit in Telegram. Then you can say, oh, okay, this agent needs to only output 1,000 tokens max. And we can just add that option, maximum number of tokens, and put that in right there. And here you can see the default is -1, which means if it's set here, it basically just has no limit. The actual limit depends on the AI model that we're using. But if we want shorter, more concise answers, we could say, okay, I only want you to output 200 tokens, which really isn't that much. As you can see, a token is roughly 4 characters or 3/4 of a word. All right, next up we have response format, which is basically how do we want the AI model to respond? There's only really 2 options here, which are either text or JSON. And pretty much always, I think you're going to leave this on text. If you want them to output JSON, usually, you know, what you would do is you just come into the AI agent, require a specific output format, and then just connect a JSON kind of structured output parser. I think that's a little bit easier to set up, but it's cool to see that you do have that option in here. As a response format. But I guess what's cool about this is that it guarantees the message model comes out in valid JSON. So maybe if your model is sending you a lot of like newlines and it's breaking the body or quotation marks, this may be able to help with that a little bit. All right, the next one is presence penalty. So this basically penalizes the model for using a word that it's already used. So kind of similar to the frequency penalty of like repeating things, but a little bit different. So if you want highly varied language for like brainstorming or creative writing, you would basically decrease this presence penalty. So basically, this is going to encourage diverse word choices. And what's also cool about this is you don't have to look at this doc. You could also hover over the question mark on each of these options to see what they do. So right here it says positive values penalize new tokens based on whether they appear in the text so far, increasing the model's likelihood to talk about new topics. So let's see what the max here would be. If I put in 10, it just goes to 2. And if I put in -10, it's probably going to go to -2. So very similar to frequency penalty here. And of course, default will be 0. All right. So the next one is sampling temperature. This controls the randomness in the output. So this is probably the one that you may have heard of before, which is kind of just known as temperature. It ranges from 0 to 1. And like I said, it controls randomness. So if you want responses to be more predictable, you're going to go more towards 0. And if you want them to be a little bit more random and creative, you're going to go towards 1. And by default, it is set at 0.7. Because essentially when the large language model is trying to choose and think about the next word to use, it has like all of these different options and it picks one. And if we decrease the temperature, it basically decreases the amount of words that it generates, as in like, what should I say next? And if we increase the temperature, it just kind of increases that range of words to choose from next. All right, so the next one we have is timeout, which sets the maximum time in milliseconds that the system will wait for a response before actually just giving up. So here by default, the timeout is 360,000 milliseconds, which is 360 seconds, which is 6 minutes. So that's like the default, but you can go ahead and increase that or decrease that. The next one we have is max retries, which sets the number of times that the system is able to actually retry a failed request before giving up. So it's set to default by 2. I'm sure sometimes you wanted it to kind of iterate more than just 2 times if it's a complex thing. So you could go ahead and raise that, or you could say, you know, if you fail the first time, I don't want you to try again. Just tell me that you can't do it. So I'm not sure what the limit is. I went to 100 and it didn't change me. I went to 500 and it didn't change me back. So you can set a maximum number of retries. Just be careful because if the system does decide it needs to retry 500 times, that could add up as far as cost goes. And then finally, what we have down here is top P, which is a little bit confusing because it sounds very similar to temperature. And just as a quick note, it's generally recommended to change either the temperature or the top P, but probably not both. And as you can see right here, this says that it controls the diversity via nucleus sampling. 0.5 means half of likelihood weighted options are considered, and we generally recommend altering this or temperature but not both. So like I said, it feels a little bit redundant with sampling temperature, so I would probably just opt for changing this rather than top-p. Okay, so some of these options are kind of hard to demo and probably pretty boring, like maximum number of tokens or max retries. I think temperature is a pretty cool one to play around with, But let's just go ahead and try something with presence penalty, which if we remember, if we go back to the doc real quick, this one penalizes the model for using any word that's already used. So higher values are going to be less repetitive, more creative, and lower values will be more repetitive. So let's just try real quick and go with a -2, and let's just ask it to make us a poem. All right, so I'm asking it to write me a poem about nature, and I told it to make it repetitive wording even though the presence penalty is -2. So it's by nature going to be a little bit more repetitive. But as you can see, we have again, again, again, again, the sun, again, the sky. Okay, so that's really interesting. Now let's go in here and make this 2, which is going to be the most creative and most random. We'll just go ahead and let me copy this but reset the session and we'll do it again. And so this time while it's going through, it's going to penalize words that it's already used and it's not going to repeat them as often. So this is a much less repetitive poem even though we did tell it to make it repetitive wording. So like I said, I don't want this video to go too long and I'm not going to demo all of them. Definitely feel free to go grab that PDF so you can go ahead and look at how they all work. Some sample use cases of them, a nice summary table, stuff like that. But hopefully if you didn't know about these settings, you now have an idea of, okay, you know, I had an agent where it was repeating stuff and I want to be able to, you know, fine tune that behavior a little bit. So definitely get in there, play around with these settings with your AI agents, and let me know if it helps. So that's gonna do it for this one. Hopefully you guys enjoyed and learned something new. If you did, please give it a like. Definitely helps me out a ton. And as always, I appreciate you guys making it to the end of the video. I'll see you on the next one. Thanks everyone.










