Mastering LangChain Deep Agents: 3 Ways to Initialize & Switch LLMs Dynamically

Mohamed Naji Aboo · Beginner ·📰 AI News & Updates ·2mo ago

About this lesson

Welcome back to the channel! In this video, Nadji breaks down the core components of LangChain Deep Agents, specifically focusing on how to configure, initialize, and dynamically switch LLMs at runtime. Because LangChain Deep Agents are completely model-agnostic, you can plug in lightweight models for fast responses or heavy reasoning models for complex tasks across multiple providers like OpenAI, Anthropic, Groq, and Google. We'll walk through 3 practical initialization methods—from a simple single-line setup to using middleware configurations for UI-driven dynamic model switching. 📌 What You'll Learn in This Video: Model Agnosticism: Why Deep Agents are flexible across OpenAI, Anthropic, Groq, and Google. Simple Initialization: The easiest way to pass a provider and model string to your agent. Advanced Control (init_chat_model): How to fine-tune parameters like reasoning levels, temperature, and retries. Global Settings (register_provider_profile): Setting global provider rules (e.g., locking OpenAI models to temperature=0). Dynamic Model Switching (wrap_model): Implementing a configurable model middleware to swap LLMs at runtime via context blocks without costly agent re-initializations. ⏱️ Timestamps 00:00 - Introduction to LangChain Deep Agent Core Components 00:40 - Method 1: Simple Model Initialization (Provider & Model Type) 01:15 - Method 2: Advanced Parameters using init_chat_model 01:50 - Using Provider Profiles for Global Configurations (register_provider_profile) 03:10 - Method 3: Dynamic Model Switching with Middleware (wrap_model) 04:15 - Testing Runtime Context & Passing Models Dynamically 05:10 - Wrap-up & Outro 🛠️ Code Snippets Mentioned init_chat_model from LangChain Chat Models ProviderProfile & register_provider_profile from deepagents.profiles wrap_model configurable middleware for context-aware updates If you found this breakdown helpful, make sure to like the video, subscribe to the channel, and drop any questions you hav

Full Transcript

Hi everyone. Welcome back. Nagesh here. In the last couple of videos, we discussed about deep agent architecture and we have done a sample program, kind of a hello world program using LangChain deep agents. And in this video and coming couple of videos, we'll be discussing on some core components of LangChain deep agent. Okay, so understanding of this core components is very important. So whenever we discuss about the the real real project, then this understanding will help us to go very smoothly. So let's start. So first, we can start about the models. So as you know, the deep agent is um actually is a model agnostic. So that means we can plug different LLM depending on our requirement. For example, uh lightweight models for the fast response and reasoning models for the complex task. And we also use the different providers. We can use OpenAI, Anthropic, Grok, and the Google, right? So we can see different model initialization in deep agents. So let me execute this uh load environment. Um Okay, let me do this. Okay, so let's do this. Okay. So here we can see uh so uh the installation is in progress, that is fine. Okay, it's done. Okay. Now we can see in a simple terms, we can import the create react agent from the deep agents. And here in a simple way, I can initialize a model something like this. I can mention the provider and I can specify the the type of the model. So here the provider is the OpenAI and the model that we are using the GPT-4o mini. And let's execute this. Okay, so this is the simplest way of initialization. Okay. Now, consider in a scenario where we need to handle the model configurations. Like, for example, I need to control the reasoning level, temperature, time what I retrace, etc. Then, in in that case, what we can do we can make use of the init chat model property or the method. Okay. So, here this is we import from the LangChain dot chat model. This we commonly using this init chat model. Guys, here I can specifically say about the model. And I can tell that, okay, thinking level is equal to medium here. So, in that way I can control each and every parameter of this model. So, let's execute it. This also will work without any problem. Okay. So, the next scenario is that, okay, imagine a situation like we don't want to repeatedly pass the same configuration everywhere. Okay. For example, I'm saying that, okay, whenever I'm using I'm using a provider is a OpenAI, then its temperature is always zero. All right, it's kind of a global settings I want to do. Okay. In that scenario, we can use the provider profile and the register provider profile from Deep Agents. Okay. So, here what I'm what what this means is that here I'm registering here registering the provider profile saying that, okay, if my provider is OpenAI, then its temperature should be zero. Okay. So, this is what I mean by this. So, if I'm using any different provider, then let me execute this. Then, it may be its own default temperature. Okay, it's not zero. Okay, this is only for the OpenAI provider. Now, I can simply execute something like this. So, in this scenario, this OpenAI GPT-4 or mini, its temperature is zero. Now, I'm thinking that, okay, for GPT 5.4, I want to specifically set some configuration. Like, I want to make it like a reasoning effort as a medium. So, in that case, what I can do, I can specifically say that the provider and the model and I can set it like a reasoning effort as medium. Okay. So, in that scenario, if I use any other model other than GPT 5.4, it's reasoning efforts should not be medium. So, this is only applicable to GPT 5.4. So, here, for this GPT 5.4, uh the temperature is zero and the reasoning effort is medium. Okay. So, let's execute it. Okay. So, this is a a second method that we can use. Okay. Now, in another situation, okay, this is the last one. Situation, consider that we have to dynamically switch the model. Okay. Consider that I have a UI is there and based on each and every use cases, I want to switch the model from the drop down. So, in that case, building the deep agents is every time is really costly and that is not a practical way of doing that, right? So, in that case, we can use a middleware that is um called the uh wrap model. We can use this um configuration like a wrap model called and this can be used as a middleware. Okay. So, here we can see a configurable model middleware is there. And here, what we are doing, we are actually checking. Okay. We are We are actually checking the model from the context. Okay. So, this will be get understand if I scroll it down, but for the time being, just understand that in a request, in a context, I'm getting the model name and based on this model name, I am initializing the model. Then, here I am updating the entire model. Okay. So, uh based on this, I'm going to create a deep agent. Here, we can see a open AI mini is my model and middleware is the configurable middleware and I'm passing the context. So here context means only the model. Okay, now let execute it. So let execute it. So you may be thinking that okay, what is this contact from where we are getting the context all those things. So that can that I can answer by executing this thing. Okay, so here I'm invoking this model and I'm dynamically passing the context here model context here. Here I'm saying that okay, the model for this context will be GPT 5.4. So let me execute it. So the execution is in progress. So let me do a result here. So if you scroll down little bit scroll down here little bit here we can see the model provider is open AI but the model name is GPT 5.4 because we have given the GPT 5.4 here. So it is dynamically changing. Okay, now we can go back again to the same code by understanding this particular the code segment. We can go and see this, right? So here I'm passing the context with the model name and using this middleware configurable model, I will get the model information from the runtime context. I am initializing the model then I am updating the configuration back. Okay, so this is how it works. Okay, so in this way that these are the like a three different ways that we can initialize the model and the last one is very important when if you want to change the model dynamically. Okay, so that is all about in this video. If you have any questions, please ask in the comment box. I will try to answer that. So that's it. Please do like and subscribe. Have a nice day. Bye-bye.

Original Description

Welcome back to the channel! In this video, Nadji breaks down the core components of LangChain Deep Agents, specifically focusing on how to configure, initialize, and dynamically switch LLMs at runtime. Because LangChain Deep Agents are completely model-agnostic, you can plug in lightweight models for fast responses or heavy reasoning models for complex tasks across multiple providers like OpenAI, Anthropic, Groq, and Google. We'll walk through 3 practical initialization methods—from a simple single-line setup to using middleware configurations for UI-driven dynamic model switching. 📌 What You'll Learn in This Video: Model Agnosticism: Why Deep Agents are flexible across OpenAI, Anthropic, Groq, and Google. Simple Initialization: The easiest way to pass a provider and model string to your agent. Advanced Control (init_chat_model): How to fine-tune parameters like reasoning levels, temperature, and retries. Global Settings (register_provider_profile): Setting global provider rules (e.g., locking OpenAI models to temperature=0). Dynamic Model Switching (wrap_model): Implementing a configurable model middleware to swap LLMs at runtime via context blocks without costly agent re-initializations. ⏱️ Timestamps 00:00 - Introduction to LangChain Deep Agent Core Components 00:40 - Method 1: Simple Model Initialization (Provider & Model Type) 01:15 - Method 2: Advanced Parameters using init_chat_model 01:50 - Using Provider Profiles for Global Configurations (register_provider_profile) 03:10 - Method 3: Dynamic Model Switching with Middleware (wrap_model) 04:15 - Testing Runtime Context & Passing Models Dynamically 05:10 - Wrap-up & Outro 🛠️ Code Snippets Mentioned init_chat_model from LangChain Chat Models ProviderProfile & register_provider_profile from deepagents.profiles wrap_model configurable middleware for context-aware updates If you found this breakdown helpful, make sure to like the video, subscribe to the channel, and drop any questions you hav
Watch on YouTube ↗ (saves to browser)
Sign in to unlock AI tutor explanation · ⚡30

Related Reads

📰
The Day Kolkata’s Search Results Stopped Being a List
Learn how AI changed local search results in Kolkata and why businesses should take notice
Medium · AI
📰
NEWSLETTER: Latest in AI, TikTok, Cybersecurity and “Is AI Entering Its ‘CVE & CVSS’ Moment”
Explore the latest developments in AI, cybersecurity, and social media, and understand the concept of AI's 'CVE & CVSS' moment
Medium · AI
📰
You Have Been Buying Graphics Cards From a Gaming Company for Twenty Years.
NVIDIA's revenue is now dominated by data centers, not gaming, with 90% of income coming from this sector
Medium · Machine Learning
📰
Neil Rimer thinks the AI money is coming back out
Neil Rimer predicts AI-generated wealth in Silicon Valley will be redistributed, and you can apply this insight to inform your investment and business strategies
TechCrunch AI

Chapters (7)

Introduction to LangChain Deep Agent Core Components
0:40 Method 1: Simple Model Initialization (Provider & Model Type)
1:15 Method 2: Advanced Parameters using init_chat_model
1:50 Using Provider Profiles for Global Configurations (register_provider_profile)
3:10 Method 3: Dynamic Model Switching with Middleware (wrap_model)
4:15 Testing Runtime Context & Passing Models Dynamically
5:10 Wrap-up & Outro
Up next
Big Tech is Being Kind of Dodgy At the Moment
ColdFusion
Watch →