Why AI Frameworks like LangChain Fail
Most successful AI companies don't use frameworks to build AI agents according to Anthropic. Octomind dropped Langchain after 12 months of production and their own code became simpler and even cheaper to run. The reason is clear. Most AI frameworks are just costly and complex abstractions.
Relying on them is dangerous for you because they can teach you the wrong things and leave you stuck and frustrated. So, in this video, you'll learn how to build real AI agents using the approach the top 10% of engineers use. We're just simply writing good Python code and calling the AI APIs directly. There are no complex frameworks required. So, let's get right into it.
Demo: A Transcript-Processing AI Agent
I've got this demo application here. With this application, you can create a recording. You can paste a text transcript. So, I'm pasting one for a fictional meeting here. And then you can process it with an AI agent. And the agent is able to process the transcript in multiple ways. It can decide to create a calendar invite, which is one of the tools that's able to call, but it can also create a decision record or an instant report depending on the content of the meeting. In this case, if we check out the agent results, you can see it gives me a brief summary.
I found a project planning meeting transcript about implementing a new user dashboard. I've created a calendar reminder for November 20th. So now I can download this IC file that was created after it executed the create calendar reminder tool and then I can just go ahead and add that to my calendar.
Now it's totally up to you to customize this solution which you get access to for free in the link in the description below. So that for example this calendar invite is automatically added to your Google calendar. But it's important to understand how this AI agent is able to call those tools independently. How does that really work?
The Core "Agentic Loop" Explained
Well, to show that, I'm going to explain the simplest diagram that you can find on the web that actually shows you how this agentic loop really works. So, we have some deterministic normal Python code here that calls a language model via the regular language model APIs. For example, this is how you call GPT or Claude using the regular software development kits.
The only thing that really happens here is that the Python code gives a system prompt that explains that this language model is supposed to process the transcript and then it of course passes on the transcript to the model as well. The main difference with a regular AI app is that this kind of agentic application also gives the language model a set of tools that it is able to request to be called. For example, a calendar tool with a given description of when this tool should be called, like if the meeting contains certain things that have to be followed up on and then together with the tool name a couple of parameters are given to the language model as well which it has to fill out in its response back to the Python code.
So this is important to realize the language model is actually not able to call any code or execute it on its own. The only thing a language model does, as the name suggests, is output text, output language back to your Python code. The great part is though is that that text can be structured in a way that you can interpret it in your Python code and then process it, for example, with JSON. So the language model outputs simple text back to the Python application and it might, for example, say, okay, I want you to call the calendar tool with these 10 parameters. The great part about this is that at that point in the Python code, you can just safely validate all of those parameters and process the tool. So in this diagram, Python is responsible for calling the tool.
And whether the tool needs to be called by just running some functions in Python, calling an external API or even using a MCP server, you have to realize that it's Python doing the real code execution, not the language model. What this means is that if you write good Python code, then your agentic application will be much more reliable. And instead of trying to mess around with all of these frameworks that try to implement abstractions around this agentic loop, if you just do it yourself, you will actually have a much better control over what happens inside of your application because often it's not just about this single back and forth between the language model and Python. Sometimes you need to go back to the language model. So in this case you can also create a new request to the language model where you say hey I called the tool and here is the result can you summarize it for the end users that we can communicate what we did together. And that's why you can see in this app example that we have this nice summary transcript. We're just using the language model in two ways. First of all the language model gets to decide which tools to use but the Python code actually validates the inputs and then calls the tools. Secondly, you can use a large language model to then summarize what has been done or to just continue calling tools and reach some kind of desired end state. This is what we call the agentic loop.
Why You Don't Need Complex Frameworks
So if you for example want to create a research agent, well then this is an agent that might call Wikipedia and then based on the results from that tool call, it might call 10 different new web pages until a certain end goal is reached and the agent has done enough research. And all of that is really just a for loop of the diagram that I'm showing here in the whiteboard. So you don't need all of these difficult frameworks to abstract all of that away from you. All you need to do is just get good at Python, which again you can do by following this demo transcript application in the link in the description below.
Let's go and check out the code so I can explain all of this again, but then more in the context of what actually happens in the codebase.
Code Deep Dive: Building the LLM Request
I've opened up the code terminal here on the right and you can see that the application is running. An important note is that for these agentic applications, you really want to use a strong language model because passing all of these possible tool calls uses up a lot of context and small weaker local models don't really work that well. So in this case, I'm using Claude because that's a great cloud-based model that can handle tool calling very well. And I'm using Open Router because Open Router uses the standardized OpenAI API to just allow you to create one Python codebase, but you can switch these language models very quickly and experiment to see which one works best for your use case.
Instead of pasting the same transcript as before, I'm going to paste another one. And this one is a meeting that talks about an incident that recently happened at this company. With this specific example, I want to show that the language model is able to decide to call multiple tools at once if that makes sense for a given input. So, we're going to go and process the text. And now here on the right, you can see that this huge JSON object is being passed to the AI API. We get descriptions for the different functions that the LM is able to call like create decision record, generate incident report, and of course, the one that we are most familiar with already, create calendar reminder. And for each of these tools, which are all in the tools array, you can see that it's not just a name, but it's a description that explains to the language model when the tool should be called, as well as a bunch of parameters that the LLM needs to pass back to the Python code in order for the tool to be called successfully.
And then if we keep scrolling upwards, we can of course see that standard system user prompting that you see in any kind of large language model app. So in this case with the system message we're saying you are a meeting transcript that processes transcripts and extracts structured information blah blah blah blah blah. You can call multiple tools for the same transcript if appropriate etc etc. And then of course we have the user prompt here which is just the entire transcript. So let's see how the large language model decided on which actions to take.
We're going to keep scrolling here after the request has been sent. And then now you can see that the LLM is selecting two tool calls. If we check out tool call selected here in the Asian py code, you can see that really this is just an object that's returned back from the API and you can look into this object and check if all the parameters are present and just handle the tool calling in the Python code later on. You can see indeed that we have generate instant report with all these arguments and we have create calendar reminder with arguments as well. And then you can see that we have phase two which is our tool execution.
I can go and find where that's happening in the Python code. And indeed here on line 126, we have this method called execute tools. So we are going to execute the tools in the Python code by doing the tool registry execute method. And this is just some wrapper code that you can find in a repo which will make sure that every single tool that you expose has an execute method. For example, if we check the calendar tool here in tools, you will be able to see that this has an execute method. And this execute method takes a given tool input and then it will create the ICS calendar file from that point forward.
You can replace this code and make it call the actual Google API for example to then add a calendar invite into your real calendar or change it in any way you like. The point here is that at this point you just have a regular Python object that you can manipulate and send over to an API. There's nothing AI about this anymore. You just have a nice object you can work with. And this way you can make it a super reliable codebase because you can put in a bunch of error handling and safety checks right in here before you create the actual calendar invite. So we don't just execute the calendar reminder here. We also execute it to generate instant reports. And if I just go and open the web page again, you can indeed see if we scroll down that we have an instant report here that we can simply copy and send over to our team together with that IC file. So now we have an example where two tools have been called by the language model. And that's a nice part about this kind of agentic application. The language model is able to decide which tools to use. And sometimes it can be that you need multiple tools to get to the best solution for a given problem. So that is really how the tool execution here works.
Code Deep Dive: Summarizing the Results
So that's the main agentic loop. But we do also have a summary generation in this application. So the phase three is to pass on a system prompt to the language model that explains everything that we did. So in this case you can see here that the tool calls that have been made inside of the application so far are passed back to the language model. It's not very readable because this is basically just a dump of the JSON object. But this gives the language model a good idea of the tool calling that was actually executed on the Python side. And this allows it to then create a simple summary that's passed on to the user here in the front end where it says, I found a critical instant response call in your transcript etc etc. I created a detailed instant report and set up a calendar reminder.
Again, it's not really the AI model that's been doing that. The Python code has done that. But by giving the summary of those actions back to the language model, it's able to create a summary and then pass it on to the user. The important mental model you should create for yourself here is that these AI systems don't execute code all on their own. It's Python that's usually executing code based on instructions from the language model. So when you read news about AI models going rogue and breaking systems, you have to realize that it's not the language model doing that. The language model can just output instructions. There is some regular code that's parsing that instruction and executing code. This means that if you are good at Python, you can write much safer AI applications, then people would just think that all of this is being executed autonomously by an LLM.
Conclusion: Take Control of Your AI Systems
This realization that Python is your control center for these agent systems is super important and is why you should be trying all of this out without using a complex framework like Langchain because they abstract all this away from you which makes you think you're building a very smart system but in the end it's usually just a for loop with these JSON defined function calls. I'm sure you learn a lot by watching this video but to truly get ahead you have to exercise with the transcript app that you can access in the link in the description below.
In addition, if you really want to get ahead with your AI career, you can join the AI engineering community where I help others really land high-paying roles and make sure that they learn the skills that are needed for the future. So, I hope to see you there.