Loading…
LangChain tutorials, LLM application development, agents, tools, memory, retrieval-augmented generation (RAG), prompt engineering, LangGraph workflows, vector databases, MCP integrations, and production best practices for building AI-powered applications.
June 1, 2026
Getting Started with LangChain: Understanding Agents, Models, and Tools Introduction When developers first hear about AI agents, they often imagine complex autonomous systems that can think, plan, and act independently. In reality, most modern AI agents are built using a simple but powerful idea: Agent = Model + Harness This concept sits at the heart of LangChain. In this article, we'll learn what LangChain is, why it exists, and how agents use tools to interact with the outside world. Why LangChain Exists Every LLM provider exposes a different SDK, API structure, authentication mechanism, and feature set. Without LangChain, switching from one provider to another often requires rewriting large portions of your application. LangChain provides a standardized abstraction layer over multiple providers, allowing developers to focus on building applications rather than managing provider-specific code. Understanding the Agent = Model + Harness Concept An agent is not just an LLM. Think of an agent as: The Model is the LLM itself. The Harness is everything around the model that enables it to perform useful work: Tools Memory State Prompt management Execution logic Architecture Installing LangChain Creating a Simple Agent The createAgent() function acts as a minimal and highly configurable harness around your model. How Agent Execution Works 1. User sends a request. 2. Agent forwards the request to the model. 3. Model determines whether tools are required. 4. Agent executes tools if necessary. 5. Results are returned to the model. 6. Final answer is generated. Key Takeaways LangChain standardizes access to multiple LLM providers. Agents are built from models and harnesses. The harness provides tools, memory, and execution logic. createAgent() is LangChain's minimal agent runtime. Tools allow agents to interact with external systems.
June 1, 2026
Building Your First LangChain Tool in Node.js Introduction Large language models are powerful, but they cannot access live information on their own. This is where tools become important. Tools allow agents to retrieve data, call APIs, query databases, and perform actions on behalf of users. Creating a Dummy Weather Tool Let's create a simple weather tool that always returns the same response. Understanding the Tool Definition A LangChain tool consists of three parts: 1. Function The actual code that runs. 2. Metadata The tool name and description help the model decide when to use the tool. 3. Schema The schema tells the model what inputs are required. Registering the Tool Invoking the Agent Behind the Scenes The model decides that weather information is needed and requests execution of the weather tool. The agent executes the tool and returns the result back to the model. Key Takeaways Tools extend the capabilities of LLMs. Zod schemas define tool inputs. Descriptions help the model choose the right tool. Agents automatically orchestrate tool execution.
June 1, 2026
Building a Real Weather Agent with LangChain and OpenWeatherMap Introduction Our previous weather tool always returned a fake response. Let's replace it with a real API integration. Installing Dependencies Environment Variables Create a .env file: Building the Tool The tool: 1. Reads the API key. 2. Calls OpenWeatherMap. 3. Parses the response. 4. Returns structured weather information. Registering the Tool Invoking the Agent Execution Flow Why This Is Powerful Notice that the tool only returns raw weather information. The LLM is responsible for transforming that data into a natural language response. The same tool can support summaries, stories, reports, and recommendations. Extending Your Agent Further Using a System Prompt You can provide a system prompt directly when creating an agent. This allows you to control the agent's behavior, tone, and decision-making process. Building a Search Agent A search agent follows almost the same architecture as the weather agent. Instead of connecting a weather API through a tool, you connect a browser or web-search tool. The agent can then decide when to search the web and use the returned information to answer the user. The overall design remains the same. You simply swap the weather tool for a browser tool. A simple implementation using DuckDuckGo looks like this: With this approach, the model can decide when to call the search tool, retrieve current information from the web, and then generate a natural-language answer. Giving Your Agent a Name Agents can also be assigned a name using the name parameter. This becomes particularly useful when working with LangGraph or multi-agent systems because named agents are easier to identify in graph visualizations, traces, and debugging sessions. Next Steps Memory Structured Output RAG Vector Databases LangGraph MCP Integration
June 1, 2026
LangChain Memory and Context: Building Stateful AI Conversations Introduction So far, our agents have been stateless. Every time we invoke an agent, it treats the request as a completely new conversation. This means the model forgets everything that happened in previous interactions. To build chatbots, assistants, customer support agents, and other conversational systems, we need memory. LangChain allows us to add memory so that conversations can continue across multiple messages. --- Understanding Memory Without memory: The second message lacks context because the agent does not remember the first interaction. With memory: The agent remembers previous messages and treats them as part of the same conversation. --- Adding Memory with MemorySaver LangChain agents support memory through a checkpointer. One of the simplest options is MemorySaver. The MemorySaver stores conversation state in memory (RAM). This is convenient for development and testing, but the data is volatile. If the application restarts, all conversation history is lost. For production applications, you would typically store memory in a database. --- Thread IDs Memory works by associating messages with a specific thread. A thread acts like a conversation identifier. When multiple requests use the same thread_id, LangChain understands that they belong to the same conversation. --- Complete Example Because both requests share the same thread ID, the second message can reference information from the first message. --- Passing Secure Context Memory helps the agent remember previous messages, but sometimes we need to pass trusted information that should not come from the user. A common mistake is placing sensitive information inside user messages. For example: This is unsafe because another user could modify the message and attempt to access someone else's data. Instead, LangChain allows you to pass application-controlled metadata through context. The context is supplied by your application rather than the user. This ensures that tools and agents receive trusted information that cannot be modified through chat messages. --- Why Context Matters Imagine building a customer support agent. The application already knows who the authenticated user is. Rather than asking the user which account to access, the application can provide the user identifier through context. Your tools can then use this value to retrieve account details, orders, subscriptions, or other user-specific data. This prevents users from impersonating other users simply by changing the text in their messages. Memory allows the agent to remember the conversation, while context allows it to access trusted application data safely.
June 1, 2026
Streaming Agent Execution in LangChain Introduction When we use agent.invoke(), we only see the final answer. The agent may perform multiple steps internally: 1. Analyze the user request 2. Decide which tool to call 3. Execute the tool 4. Process the result 5. Generate a response Normally, all of this happens behind the scenes. Streaming allows us to observe the agent while it is working. This is useful for: Debugging agents Building chat interfaces Showing progress to users Visualizing tool usage Understanding agent behavior --- Why Streaming Matters Consider the question: Who is the richest person in Kochi? Without streaming: The user only sees the final response. With streaming: The application can display what the agent is doing in real time. --- Streaming an Agent Instead of using invoke(), use stream(). The stream produces updates as the agent progresses through its workflow. --- Complete Example --- Understanding the Output When the model decides to use a tool, you can see it happen. Example: After the tool returns its data, the model continues reasoning and eventually generates a response. Example: This gives you visibility into the agent's execution process. --- What Is streamMode: "values"? LangChain supports multiple streaming modes. In this example we use: This streams the current state values as the graph executes. As new messages are produced, they become available immediately. This allows applications to react to agent progress without waiting for the entire workflow to finish. --- Common Use Cases Chat Applications Display messages as they arrive instead of waiting for the final response. Agent Debugging Understand why an agent selected a particular tool. Monitoring Track tool usage and execution flow in production systems. Agent Visualizations Build interfaces that show the reasoning process and tool execution path. --- Execution Flow The stream acts as a live feed of the agent's execution, allowing applications to display intermediate steps while the workflow is still running.