While many focus on prompt engineering, this video correctly identifies asynchronous execution as the true prerequisite for high-performance agentic orchestration. It effectively bridges the gap between conceptual AI modeling and production-grade software engineering.
Deep Dive
Prerequisite Knowledge
- No data available.
Where to go next
- No data available.
Deep Dive
3. Asynchronous Programming for AI Agents | Complete Agentic AI CourseAdded:
Hi guys.
My name is Bapi Ahmed and you are welcome to my YouTube channel.
So guys, this is the third lecture of our complete agentic AI course.
Uh in our previous video, I have already discussed the complete evolution uh of agentic AI, like how agentic AI came.
Then I have already given you the detailed introduction to agentic AI, like how agentic system works, what are the key components and characteristics are available.
Now, slowly we're moving to the uh AI agents core concept. That means the practical development concept. Uh but before that, we have to also understand all kinds of orchestration frameworks are available.
I think I already told you uh in my previous video. Uh like there are uh some components are available, especially whenever I'm talking about uh the agentic AI.
Uh one of the component is the orchestrator, right? Orchestrator means there we use some kinds of framework, okay? With the help of these are the framework, we create, we implement the AI agents, whether it's a single agents, whether it's a multi multi AI uh agent system.
Uh we try to create these kinds of things, right?
So, there is a concept, guys, uh you have to understand before I start with these kinds of orchestrator framework.
The concept name is asynchronous programming, okay?
So, why this asynchronous programming is required? Uh because if you see, uh going forward, we'll be creating the multi-agent system.
And to create the multi-agent system, guys, we'll be using these kinds of orchestrator framework.
And internally, this orchestrator framework uses asynchronous programming, okay? That means it will run your agents in parallel. Let's say you have created uh 20 agents. So, what it will do instead of running, uh, agents as a sequentially, it will run all of the agents in parallel, so that your execution would be more fast.
So, this concept I'm going to discuss in detail, guys. No need to worry. Uh, first of all, let me show you one thing actually, uh, I have just figured out.
Let's say if I go to the Google. So, here if I search like is LangGraph uses asynchronous in the back end for multi-agent agents. So, I think you know LangGraph is one of the orchestrator framework. With the help of LangGraph, we create agentic AI applications, right? And we'll be also mastering this LangGraph inside our codes.
So, as you can see, the response was yes, LangGraph is, uh, designed with first-class asynchronous supports in the back end for multi-agent system. That means, uh, it is utilizing the asynchronous programming, asynchronous concept in the back end, okay?
Now, if I just to go below, let's say I have asked for about the AutoGen, because AutoGen also will be covering inside our codes. So, as you can see, AutoGen also utilizes asynchronous programming at its core, but it is, uh, architecture fundamentally different from the LangGraph state, uh, LangGraph state machine approach. But internally, it is uses asynchronous programming concept. Now, again I asked like, uh, what about CrewAI, okay? So, you can see CrewAI also supports asynchronous execution, but it, uh, approaches orchestration differently than LangGraph and AutoGen. While, uh, LangGraph uses, uh, a state machine and AutoGen uses, uh, actor model, CrewAI is built around role-based collaboration and process-driven execution model, okay?
But, the main funda is that all of the orchestrator framework we are using for developing these kinds of multi-agent application, internally, it is uses asynchronous, okay? Asynchronous programming.
Now, before I start with these are the orchestrator framework, first of all, I want to clarify what is asynchronous programming, why it is required, how asynchronous works, okay? What is parallelism, what is uh let's say sequential execution, each and everything I'm going to clarify. Then we'll start with the uh orchestrator framework understanding.
But after that, there is one more topic uh we have to cover, which is nothing but Pydantic Pydantic validation. This is also important because you'll see that whatever large language model we're having, it will generate the unstructured output. And to make it structured, even whenever we're giving any kinds of prompt, to make our prompt uh more structured, we use this Pydantic validation, okay? So, this Pydantic validation we'll be understanding in the next video, but in this video, I'll only focus on the asynchronous understanding, okay? So, here I'm going to give you the detailed understanding of asynchronous with the theoretical understanding as well as the practical understanding as well.
So, let me show you guys what is this asynchronous. After that, your understanding would be more clear and you can easily understand these are the framework whenever you'll be doing the coding.
So, let me give you the definition of the asynchronous programming. So, here is the definition.
Um here's the simple definition you can see. Asynchronous programming in Python, okay? You can see asynchronous programming in Python is a programming paradigm that allows code to handle, okay, multiple task uh concurrently without blocking the program's execution.
It is primarily used to IO-bound task, example network uh request, file input and output operation, database queries, okay? Allowing the program to perform other operations while waiting for slow external events to complete. That means this I think asynchronous programming will help you. Okay, asynchronous programming will help you. Okay, asynchronous programming will help you to run your task in parallel. Okay, so you are not supposed to wait for the uh execution. Let's say we know that we use synchronous synchronous programming so far. Yes or no, guys? We use synchronous programming so far. In synchronous programming, what happens?
Let's say if I execute a code block first of all, it will complete that, okay? After the execution is complete, okay, then it will execute the second part of that particular code, okay? But in between, let's say if you are waiting for the execution, okay, if you're using asynchronous programming, it can run run another task in parallel, okay? So, these are the let's say functionality we'll be getting here.
Now, you can ask me why this is required. Okay, why this asynchronous programming is required inside AI agents implementation? Agentic AI, you can create two kinds of agent. One is the simple agent.
Okay, one is the simple agent. So, basically, simple agents you create only one block. Okay, it can only handle one particular task. Okay. But whenever, let's say you have complex problem, you have to divide the task in a smaller chunks. And what you will do, you will be creating multiple agents, okay?
Multiple agents you will be getting.
Let's say this is agent one, this is agent two, this is agent three, okay?
And what will happen, you will assign the task for all the agents.
And these agents will be executing either independently indepen or dependently.
Okay, dependently.
So, it's your design philosophy. If you are making it as an independently, that time it will run as an independently. If you are making it to dependent, okay, it will run as a dependently.
So, basically what happens, let's say if you run these are the agents, okay? These are the agents in a synchronous programming, okay? In a synchronous programming, what will happen? First of all, these agents need to be completed. These agents execution need to be completed. Once these agent Once these agents will be executed, then it will move to the next agents, okay?
Next code block. Then these agents will be executed, okay? Once it is completed, then it will go to this particular agents, okay? Then it will try to run this particular agent. So, let's say this agents is taking 3 minute to run.
Sorry. Let's say here I can just tell you.
Let's say this agents is taking 1 minute to run. These agents is also taking, let's say, 1.5 minute to run, okay?
These agents is also taking, let's say, 1 minute to run. So, what is happening?
You have to wait for 1 minute. Again, you have to wait for 1.5 minute. Again, you have to wait for 1 minute, okay? So, if you like uh add all of the time, you will see that at the end you are having, okay, 3. 5 minutes. 3.5 minutes you have to wait for the execution. But, if you run this task in parallel, okay? If you run this task in parallel, let's say this particular agents will do the online search operation. So, basically if you're doing the online search operation, you will be hitting some URL, right? Drive URL. And to get the response, this will take some time.
Let's say sometimes this web server might be slow. That time it will be giving you slow response. So, instead of waiting for that, you can execute your other agents. So, let's say this agents will try to collect the uh images. These agents will try to collect the, let's say, any other file, okay, from the internet.
So, don't wait to execute any other agents. Just try to run them in a synchronous way, okay? In a parallel way. So, each of the agents will be running in a parallel way. So, let's say the if this agent is also taking uh 1 minute, okay? So, simultaneously we're running something, okay, in the back end. So, you are not supposed to wait for 3.5 minutes. Get it? So, that is the things I just wanted to tell you. So, let's say whenever you are creating multi-agent system and whenever you are creating, let's say, independent connection, okay, independent, let's say, policy, that time you should use this asynchronous programming inside um inside, let's say, Python or let's say, whatever programming you're using, you have to follow that. And if you see any kinds of agent's code, you will be uh seeing people are using this asyncs, okay?
Uh asyncs.
This particular syntax, people are using that.
Okay. So, what is this async? Async means asynchronous, okay? Asynchronous functionality. So, in Python there is a library called asyncio. So, we'll be following that particular library to implement this particular code, okay?
So, let me give you one example of asynchronous and synchronous programming.
So, let's say here I can write synchronous synchro- nous programming.
And this side we have asynchronous programming.
So, in synchronous programming, what happens?
Let's say what I can do, I can give you one example.
Uh let's say here mm Let's say you are you are having a mm you're having a mm gas stove, okay? Gas stove.
Uh in this gas stove you only have one um one fire section, okay? One fire section. So, let's say you are having uh three dishes.
Okay, you are having three dishes to cook.
So, what you will do? First of all, you will take the first dish and you will cook that. Once first dish is complete, then you will take the second dish.
Then you have to complete, then you will be taking the third dish, then you will be completing. Okay, that's how you can see it is taking T1, it is taking T2, it is taking T3 time. Okay. So, basically you have to wait for you have to wait for the previous execution or let's say previous task to be completed, then you can start the remaining task. But in asynchronous programming, what happens? Let's say you are having same gas stove, but here you are having let's say three fire section.
You're having three fire section and you are having three dishes.
Okay, let's say dish one, dish two, and dish three.
So, what you have to do? You just need to run all of them simultaneously.
Basically, you are giving three dish to the three fire section. Okay? Now, at the T1 time, okay, your all of the dishes will be completed. So, you are not supposed to wait for the T1, T2, and T3 to be completed. Okay, so this is the difference between synchronous programming and asynchronous programming. I hope you get it, guys.
So, in Python, we usually follow the synchronous programming. That means if you're running a function, first of all, that function would be completed, then the remaining code would be executed.
Now, in programming, we we call it as a subroutine. Let me just write here.
Sub routine.
And we also call it as coroutine.
I'll be discussing about what is this.
Okay, coroutine.
So, what is subroutine? So, let me a program to explain. Let's say here I can write a function.
So, I'll just write a function. Let's say def Okay? Def So, let's say I will Um I will give the function name fetch.
Okay?
Fetch, let's say data.
This is the function name.
So it is having some code inside that.
Okay? Now, here I'm creating another function. Let's say def main.
Okay? Now, what I'm doing? I'm calling this particular function. Okay? This function inside this particular main function fetch data.
Okay? I'm calling inside that.
I'm calling inside that.
Sorry.
Yeah.
Now after calling, let's say in this main function also there are some code line.
So, what is happening here? Let's say if you're uh if you're using sub routine, so that time uh whenever you are executing your code, first of all, your code will uh come here. Okay? Your code will come here and it will see you are calling a function inside that. Which function?
You are calling this particular function. Okay? Now, what it will what will happen? First of all, it will go to this function and it will execute all of the code.
It will execute all of the code. Now, let's say you are running fetch data, that means let's say you are trying to fetch some kinds of data from the internet. You are using some kinds of API, some kinds of URL, okay? And whenever it is hitting that particular API or URL, it is taking some kinds of time, right? So, you have to wait for this particular time.
So see, once this time is over, that means this execution is over. Then you will be able to execute your remaining code. Okay?
Till then you have to wait for this execution. Okay?
So, this is the idea of subroutine. That means you are waiting for a task to be completed, then your remaining code would be executed. Then your remaining code would be executed. Although you are waiting here, although you are waiting here, you don't have any kinds of other task. You just need to wait for the execution. Okay? And once execution is completed, then you will be able to execute, you'll be able to see the other execution of the program.
But in coroutine, what happens? So, let's say here I'm having a function.
Here I'm having a function. And uh we use something called asynchronous. Okay?
Asynchronous syntax. So, for this we use something called async.
Uh async, okay? This is the keyword async. So, we'll write the function as def. Let's say fetch data.
This is the function. Let's say inside that you are having some kinds of code.
Okay? Now again you are having a main function here. So, I'll just write def main.
So, what you are doing? You are calling this particular Um okay, you are calling this particular function def.
Sorry, uh fetch.
Okay? Fetch data.
You're calling that.
And inside main you are having some other code.
Okay? You are having some other code as well.
Now what is happening? Just try to see.
Whenever your Python will come here, it will see that you are executing a function. Which function? This function you are executing. And it will see this particular keyword called async, okay?
Then that time Python will automatically understand that this code you have written, it will run in asynchronous way. That means let's say here you are doing a API call, and it is taking some time T1. Okay, instead of waiting for this particular time, again it will come here, okay, and execute the remaining code you have, okay, after this function. That means at the T time itself, this code would be executed and this code would be also executed. So, you are not supposed to wait for the previous execution. So, this is called coroutine. And if you're using this async, these are the things, so it internally uses this concept. And now we'll go for the practical, we'll try to see like practically everything, how it works.
Uh then I think your understanding would be more clear, okay.
First of all, I'm going to explain the synchronous programming.
Okay.
Now, here I'm going to write two function, let's say for the first function I'm going to write uh fetch DC fetch weather.
Okay, fetch weather.
Um and the second function I'm going to create def fetch news.
Fetch news, okay.
Mhm.
Now, what I'm going to do, I'm going to import the time module as well just to see the execution time.
So, import time.
Import time, okay.
Now, inside that, as of now, I'm not going to write any logic, simply I'm going to write just a print statement.
I'm going to give let's say fetching weather data.
Then here I'm going to just mention a time.
Uh let's say to fetch the weather data, you have to wait for some time, okay.
So, this time I'm going to assign with the help of this time module. So, here I'm going to give let's say I will be waiting for 4 seconds, okay?
4 seconds. So, it it is for the simulate uh network delay. Let's say if you are hitting any kinds of API, so definitely to get the response you have to wait for some time. So, let's say this time I have set 4 seconds here, okay?
Now, once uh we stop for 4 4 seconds, now simply I'm going to just print let's say weather data fetched, okay?
So, this message I'm going to write.
Now, similarly here also I'm going to write uh I'm going to write facing facing news data.
And again I'll give some time. Let's say here I've given 2 seconds.
And uh once my data news facing is done, so I'll tell news data faced, okay? So, as of now, just try to consider this is a function. This will fetch the weather information.
And this will fetch the news, okay?
Now, if you see this function and this function doesn't have any uh dependency. These two functions are independent. Okay, these two functions are independent. That means if you want to fetch the weather, you don't need the news.
If you want to fetch the news, you don't need the weather. So, these are independent function. Okay?
But once I will execute this code, okay, let's say if if I write another function here, I'll just write another function def main, okay? In the main function, I'm going to call uh I'm going to call these two functions. See? First of all, I'm starting the time just to see the time like how much time it takes to execute the two function. So, that's why I'm starting the uh start I'm taking the start time. Then I'm calling these two functions together, fetch weather and fetch news. You can see fetch weather and fetch news I'm calling.
Then I'm taking the end time, then I'm doing the subtract operation from end time to start time. And this will be uh this will be my execution time of my program.
But if you see here these two functions are independent. This this two functions is not dependent.
Although it's independent, okay, it's not dependent.
So whenever you will call the function you have to wait for the you have to wait for the previous function to be completed to run the next function.
This is the issue, okay? So I can see these two functions are completely independent. But whenever I'm calling this function, first of all this function will execute. So let's say whenever you will execute the program, so your interpreter will come here, okay? Your interpreter will come here, then it will go to inside this particular function. Then it will execute all of the code and here it will wait for the 4 seconds, okay? 4 seconds it will try to wait.
But see, in the first 4 seconds it doesn't have any work to do, so it will be waiting.
Then once 4 seconds is over, this code would be executed, then your program will come here. Okay, then it will be executed. That means first of all the previous function would be executed, then the next function would be executed. So you can also check. So let's say if I want to show you, so I'll call this particular main function here.
Okay, I'll call this main function. Now if I execute, see, facing weather it is waiting for 4 seconds. Now weather fits. Now see, facing news, now it wait for 2 seconds, then news fits. And total time taken you can see 6 point something seconds. Okay, now you can also take this code in one of the amazing website called Python Tutor.
Python Tutor.com, here also you can visualize this code.
Let me open the Python Tutor.
Now I'll select the Python programming.
I'll paste my code here.
Visualize the execution.
Okay.
Now, it has started. Okay, it has started. Now, simply time is not defined. So, okay, so the basically I need to import the time here, right?
So, let's edit the code.
So, here I'll import the time module.
Put time.
Now, I'll visualize the execution.
Import time. It's giving me an error.
Time file not found or supported. Only these modules can be imported. Okay, because this is a like a website, okay, Python Tutor website. So, here you can you can't import any Uh let's say these are the library you can't you can import, but some other library you can't import. So, for this what I can do, I can remove the time as of now.
I just wanted to only just let you know that how it is executing. Let's say I will also remove the time part.
Uh here also I'll remove the time part.
Here also.
And here also.
Uh let's say this is my message.
Okay, this is my simple message.
Let's say execu- -ted.
Now, simply do the visualization.
Okay. Now, see.
Um here I have the control. So, first of all, Python interpreter will come here.
Uh it has seen like here I am having a function called fetch weather. Then, it will go to the next line, that is next function.
Then, it will go to the next function, which is main.
And in the main function, you can see uh I'm calling here this particular main function. So, it will go enter into the main function.
And it will see like I'm calling fetch weather function, okay? So, it will go inside fetch weather and it will do all of the operation.
Okay, see, it is doing all of the operation. Now, let's say this function is taking some time, so it will wait.
Okay, it will wait for 2 minutes, 1 minute, okay? How much time it is taking, it will try to wait for that.
So, once execution is completed, then again, it will come here. Okay, then you can see it will execute another function, which is fetch news. Now, again, it will go inside fetch news then it will do all of the execution and try to come here. That means you have to wait, okay? You have to wait for the previous execution to be complete, then you will be able to run the new code.
Okay, that's how you have to wait, okay?
You have to wait uh for the previous execution. And definitely, it is taking lots of time. And now, just try to consider if you're running a multiple agents together and if it is running synchronously, so first of all, first agent would be completed, second agent would be completed. So, execution time it will take more. That time we run it is an asynchronous way. So, that we are not need to open We don't need to open for We don't need to wait for the previous execution, okay? The time it is taking it's completely fine. I will simultaneously run for all of the function and it will be executing together, okay? So, now we'll try to see that particular example as well, how it will work. Now, we'll see the synchronous programming.
Sorry, asynchronous programming.
Asynchronous programming.
Now, here to uh implement asynchronous function, you need to import one library called import Sorry, import.
Okay? asyncio, okay? asyncio, this particular library and I'm going to also import time library.
Let's me import all of them. Then here I'm going to again write the same function.
Same function, I will copy the code.
And simply I'm going to mention here.
Now, instead of giving simply this definition, I'm going to write async keyword, okay, before that. Now, once I have written async keyword, okay, async keyword at the first of this particular function, now Python will automatically understand I need to run this function in asynchronous mode. And here it is taking the time, so maybe I can use another keyword here called await. Okay, await.
So, simply I'm going to give it here.
Okay?
Even you can also return something if you want, okay? You can also return like uh what is the return this function will be returning for you.
Mhm.
Now, same similar wise, I'll also do it for this particular function.
So, async.
Okay? Now, simply here I'm going to write await.
Okay? Await.
So, why you are writing await here?
Because here it is taking the time, okay?
Here it is taking the time.
And whenever here it is taking the time, your Python interpreter will come here.
And whenever it will see the await, so it will tell like you don't need to wait for this particular execution, so you can execute your other code, okay, whatever you have. So, this code would be executing. And at the same time, you can also execute your other code, okay? I'll tell you, okay, how it will execute.
Uh then simply in the main function also, I'm going to make it as async.
Okay, async. And here uh instead of calling like that, I'm going to simply call it as await.
Uh asyncio.gather, okay? There is a function.
And inside that you have to give the fetch weather fetch weather uh function and fetch news function. Both you have to provide, okay? Then you can uh calculate the end time.
And simply you can bring the time taken of this particular function.
Now, if you want to execute, uh what you can do, you can simply uh you can simply call this main function. How? You can use the await keyword main. Now, see, if I execute see what will happen.
Okay, um there is a error.
Oh, sorry. Uh whenever you are using this await, right? You don't need to use the time that time.
Uh you can use as since uh as since I will not sleep, okay? So, you are not supposed to use time that time. Okay, you have to use as since I will not sleep. Okay?
Now, same things I will be giving it here.
Same things I will give it it to here.
Uh now I think it is fine. Now, let's execute.
Now, see, guys.
It has taken only 3 seconds. And if I show you my previous code, it has taken 6 seconds.
Okay? So, the time reduced by half.
Okay? The time reduced by half. Just try to consider.
Now, just think like this is a big program. Okay, this is a big program.
This is a big agents and it is running so many stuff. Now, if you run it run it in a asynchronous programming, now just try to consider how much time it should it should take, okay? But if you are using asynchronous programming, see, it will be reducing the time half.
Okay? Because it is running everything in parallel.
It is running everything in parallel.
Okay? So, you are not supposed to wait for the previous execution to be complete. Okay, so all of the executions are doing simultaneously.
Okay, so that's why this asynchronous programming, okay, this async IO is required whenever you are implementing uh any kinds of AI agents uh with any kinds of framework, whether you are using autogen, you are using LangGraph, you're using CrewAI, try to use this particular things in your development.
Okay?
This is good practice.
There are two concepts you'll be getting, which is uh the first is para llelism.
Okay?
And the second thing you'll be getting con cu rrency.
So what is parallelism? Running multiple uh tasks simultaneously using multiple threads.
Okay, or process.
And what is uh concurrency? So let me write it here.
Um simply here I can write concurrency.
Concurrency means uh managing multiple tasks that can start run and okay, finish with overlapping times.
Okay.
So, let me show you a graph. I think by seeing the graph, you will be able to understand what is the exact meaning.
So, this is the graph.
So, this is the concurrency. You can see uh task is running, okay? Context switching to the task two, then again task one is running. Again, it is doing the context switching, okay?
But in parallelism, you can see it is utilizing, okay? It is utilizing multi uh multi-core, okay? Let's say uh in the first CPU core, it is running task one and in the second CPU core, it is running task two.
But here, it is only utilizing the same core only, but doing um doing this uh concurrency operation, okay?
So, guys, I think you have seen this asynchronous concept. Uh the main thing is that right now, all of the orchestrator framework uses these kinds of asynchronous uh functionality in their back end. So, we don't need to manually uh use the asynchronous inside our development, inside our code. But if you want, you can also use. Uh if you want, you can also uh design your own pipeline, design your own agents. That time, you can write the code from scratch. But whatever um let's say uh orchestrator framework will be using like LangGraph, then AutoGen, CrewAI, right? So, everything uh already having these kinds of things are integrated okay in the back end. So, I don't need to take care of this part. But, in future whenever I will do some coding, maybe these are the terminology will come. That time I want you to don't actually confuse with the syntax. Okay? That's why I have clarified each and everything before I go ahead with the AI agents implementation. So, yes guys, I think you have liked this video. If you have liked this video, please try to subscribe to my channel and hit the like button. So, yes, this is all about.
Thanks for watching, guys. I will see you in the next video.
Related Videos
OpenHuman VS Hermes AI: Who Wins?
JulianGoldieSEO
285 viewsโข2026-05-29
Long-Running Agents โ Build an Agent That Never Forgets with Google ADK
suryakunju
142 viewsโข2026-05-30
This computer is made from real human brain cells. And you can buy it.
Talktmsmedia
3K viewsโข2026-05-28
BREAKING: Microsoftโs New Image Generating Model Beat Out GPT 1.5 and Nano Banana 2
aimmediahouse
122 viewsโข2026-06-03
I Made the Same Anime Fight Scene in Every AI Video Generator
NobleGooseAnime
295 viewsโข2026-05-30
Nvidia Bets Big On AI PCs | New Chip To Power Windows Laptops | Technology | AI Updates | N18S
cnnnews18
3K viewsโข2026-06-01
I Tested NEW Opus 4.8 on Four Projects (Updated LLM Leaderboard)
AICodingDaily
298 viewsโข2026-05-29
3D Platformer Update - NO CAPES
SolarLune
294 viewsโข2026-05-30











