← All videos >THE FULL PICTURE
Take the AI agents course

ai agents / agent autonomy / ai safety

How To Make Your AI Agent Truly Autonomous (Without It Going Rogue)

Course walkthrough

AI Agents from Scratch

Lesson 6 of 12

All lessons in this series

  1. 1I'll Teach You How To Build AI Agents From Scratch (10 Billion Tokens Proof)
  2. 2What Is An AI Agent? (ChatGPT Doesn't Count)
  3. 3The ONE Trick That Turns ChatGPT Into An AI Agent (Tools)
  4. 4The ReAct Loop: How Cursor & Claude Code Actually Work
  5. 5The System Prompt That Changes Everything (Prompt Engineering For AI Agents)
  6. 6How To Make Your AI Agent Truly Autonomous (Without It Going Rogue)
  7. 7How To Trigger An AI Agent (5 Different Ways)
  8. 8Subagents Explained: How AI Agents Launch Other AI Agents
  9. 9Simple Memory: How AI Agents Remember Between Runs
  10. 10How AI Agents Actually Remember (Memory + RAG Explained)
  11. 11How To Actually Tell If Your AI Agent Is Good (Evaluation)
  12. 12The Complete Guide To Building AI Agents (10 Lesson Recap)

Once your AI agent has tools and a loop, you can let it run autonomously — but should you? Some tools are dangerous (delete files), expensive (LLM calls), or slow. In this lesson, I show you how to build an approval mechanism that lets your agent be smart about when to act on its own and when to ask for permission.

You'll learn: → The difference between automated and semi-automated AI agents → How to whitelist tools that are safe to execute without approval → Building a real-world approval mechanism for dangerous tool calls → A concrete example: the NexusTrade Agent Planner in action → Why production AI agents need autonomy controls

By the end, you'll understand exactly how production AI agents balance autonomy with safety — and you'll have a working pattern you can implement yourself.

This is Lesson 6 of "How To Build AI Agents From Scratch" — a free 11-lesson masterclass on building production-ready AI agents.

#AIAgents #Autonomy #ProductionAI #AISafety #ToolUse

Transcript

0:05In my last video on how to build your own AI agent from scratch I introduced several important concepts Number one is I introduced the idea of tools

0:18ways to allow your language model to actually do things These can be JSON objects API calls CLI commands SQL queries anything that allows your AI to

0:30actually do things and gain information Your tools are executed within an orchestration loop using the React reasoning action framework This

0:44framework tells your LLM how to reason and take actions in its environment and the tools are a key part of making this possible However a while loop and a bunch of tools

0:58is not enough to make a production AI agent In this video I'm going to be talking about another key part in making AI agents and that's implementing permissioning within your tools

1:12Not all tools should be executed autonomously Some tools are very expensive or potentially very dangerous and can't be undone So you want to think about how to

1:26make your AI agent autonomous but safe You can do this by introducing a white list or a black list So

1:39within the code on the screen I basically updated our AI loop to include a list of white listed tools and the way this loop works is

1:52if the tool is not white listed then you have to ask the user for approval If the user doesn't approve then you can't execute that tool

2:07Again you can think of tools that call expensive LLM calls or you can think of tools that might delete some files Those types of tools need the user's explicit permission to execute

2:24Now so far a lot of this has been theoretical I'm going to show a concrete example a real world example of an orchestration loop This is the Nexus Trade Agent Planner

2:38and it basically serves as the planning phase for the orchestration loop So essentially you can think of something before this loop I'm essentially using it to create a

2:53plan as a specialized prompt and within the prompt again it's basically giving it specific instructions on how to explore its environment In this case

3:05develop back tests and deploy trading strategies I have special rules for launching sub agents special rules for performing research and then creating a trading strategy I try to

3:20tell it to analyze current regimes and search for past historical examples I give this plan which again is generated before the main loop and I give it to the main orchestrating

3:34AI agent This is essentially the thinker the one that actually executes the actions Within this code is basically these two

3:46steps at once and we can see I have a bunch of instructions on how the agent should act You'll learn how to build these instructions with

3:58experience but these instructions tell the LLM how to act And I also have the schema let's scroll down to React V2 and we can see it's literally exactly what we

4:13talked about It literally responds with a thought an action or in my app I say an action or a command and there's some nuance but that's not important for you

4:25And it can also respond with a final answer And this basically signals to the LLM that it's done it accomplished the goal that the user asked

4:37Another trick for building system prompts not just with AI agents but just in general is you should provide a bunch of real world examples So let's see this plan as an example This is the plan and this is

4:52the action generated by the language model It responded with a thought and an action or a command Let's look at another example Given this example this text it

5:06responded with this thought and this action It used this tool called a quick screener with this input By providing these concrete examples the agent will know how to respond in the real world

5:25Now I'm going to show a concrete example of an AI agent in action and it's basically going to demonstrate this part of the loop whether or not a tool is whitelisted In

5:38this case in this implementation it's simply just a toggle You can switch between automated and semi automated mode I'm going to start with automated just to show you what that's like

5:54What's going to happen here is this text right here when I click submit it's going to go to this planner oops this planner AI agent Literally if I type in the same thing here

6:08and click submit the response here and the response here will be very similar They won't be exactly the same but they will be very similar We can

6:20see this is the plan It's going to create a buy and hold spy portfolio It's going to back test it across several periods and analyze the results It's literally

6:33just the same thing Because we're in semi automated mode I have to manually approve every plan and every action Again that's essentially this part of the loop We

6:47can pretend we have this saying plan equals generate plan and the generate plan is just of the user's input and then we can say user input is just I want to no let's use the same exact user input

7:03So next I'm going to go ahead and go back here I'm going to click approve and the AI is going to automatically move on It's basically going to start this part of

7:15the loop It's going to generate a thought and an action See the thoughts and the action This is what it's thinking It's on step one of the plan It's going to create this portfolio with this initial value

7:29Now we're basically stuck here because I haven't yet approved it I'm going to click approve and it's going to approve It's going to execute this action and basically create this portfolio

7:44Now when it's done it created this portfolio That's essentially this result equals execute action and then we appended that right here I'm going to reject for now just to stop it It appended it right here into the

7:59conversation state and then it repeated It did it automatically You saw I had to stop it It went back here It generated a new thought and an action and this time I just said no It's going to break

8:11the loop and it's going to stop Now let's switch gears and let's just switch it to fully automated mode so I don't have to approve it It's going to execute everything by itself This is also

8:25similar ish to dangerously skip permissions if you use cloud code but don't worry Within the app next this is safe I'm going to say actually yes let's continue

8:39Unlike before which I had to approve all the plans it's going to execute it autonomously because I changed it to fully automated mode I'm going to click switch It didn't register

8:53Click approve and now it's going to be fully automated I won't have to approve any plan at all It's just going to execute it for me and you can see it just executed it It's running the action It

9:06has a thought The thought you can kind of read it up here and it's just executing these actions on my behalf I don't have to approve it That is the important thing that makes an AI agent production

9:19ready You have to be able to toggle between whether you're going to approve it or whether it should execute commands automatically

9:32Now the agent is going to read and summarize these results Again this looks complicated but again this is just the result of a JSON In fact if I copy the message

9:44I go back here I create a new tab and I type paste you can see it's literally just a JSON object and I have some UI

9:58magic to make it work That's why you see all this but it's literally just this here in a loop and a lot more code That's pretty

10:12much it for this lesson So just for a brief recap I talked again about tools They're extremely important I talked about the orchestration loop and I talked about how do you actually get your agent to

10:26work automatically You might have a whitelist or a blacklist You might have a button that toggles between automated and semi automated mode All these are different strategies for implementing autonomy in your AI agent

10:42Finally I talked a little bit about the planner creating a structured plan for your agent to follow This step while it's semi optional makes your agent a lot smarter because it

10:55already knows exactly what it plans to do In the next course I'm going to be talking about how do you actually trigger an AI agent It's going to be short but

11:08important because there are a number of ways you can start an AI agent whether you type it in in the UI or you have something to start it automatically This is very important so stick around and I'll see you in the next video

Join the conversation

Loading conversation…