Mastering LangGraph – State Management – 01

Mastering LangGraph - State Management - 01

Using Pydantic model as state Previously, we might have used TypedDict the most, but Pydantic model is also a great choice. Let’s see how this type can serve as the graph state. Input Validation from langgraph.graph import StateGraph, START, END from typing_extensions import TypedDict from pydantic import BaseModel # Overall state of the graph (this … Read more

Mastering LangGraph Tools Call-06

Mastering LangGraph Tools Call-06

How to Handle a Large Number of Tools The subset of tools available for invocation is typically determined by the model (although many providers also allow users to specify or limit the selection of tools). As the number of available tools increases, you may want to limit the LLM’s selection to reduce token consumption and … Read more

Mastering LangGraph-Stream

Mastering LangGraph-Stream

LangGraph has built-in first-class stream support. Streaming output graph .stream and .astream are synchronous and asynchronous methods for streaming outputs back from the graph run. When calling these methods, several different modes can be specified (for example, `graph.stream(…, mode=”…”)`): values: This will transmit the full value of the state after each step of the graph. … Read more

Mastering LangGraph Tools: A Comprehensive Guide

Mastering LangGraph Tools: A Comprehensive Guide

Sometimes, we want the LLM that calls the tools to fill in a subset of parameters for the tool functions, while providing other values for the remaining parameters at runtime. If you are using LangChain-style tools, a simple way to handle this situation is to annotate the function parameters with InjectedArg. This annotation excludes the … Read more

Creating an Agent with LangGraph and Search Tools

Creating an Agent with LangGraph and Search Tools

In this tutorial, we will learn how to build an intelligent dialogue agent with memory capabilities using LangGraph and LangChain. This agent can use search tools to answer questions and maintain the continuity of conversations. 1. Obtain API Key for Search Tool Log in to the search tool website: <span>https://tavily.com/</span>, generate an API key as … Read more

Mastering LangGraph: Controllability 03

Mastering LangGraph: Controllability 03

Combining control flow (edges) and state updates (nodes) can be very useful. For instance, you might want to execute state updates and decide which node to transition to next within the same node. LangGraph provides a way to achieve this by returning an object from the Command node function: def my_node(state: State) -> Command[Literal["my_other_node"]]: return … Read more

Mastering LangGraph: Controllability 01

Mastering LangGraph: Controllability 01

LangGraph provides a high level of control over the execution of charts. How to Create Parallel Execution Branches The parallel execution of nodes is crucial for speeding up overall graph operations. LangGraph offers native support for parallel execution of nodes, which can significantly enhance the performance of graph-based workflows. This parallelization is achieved through fan-out … Read more

Mastering LangGraph Persistence

Mastering LangGraph Persistence

LangGraph Persistence allows for easy state persistence between graph execution (thread-level persistence) and threads (cross-thread persistence). This tutorial demonstrates how to add persistence to a graph. LangGraph has a built-in persistence layer that is implemented through checkpoints. When compiling a graph with a checkpoint, the checkpoint saves a snapshot of the graph’s state at each … Read more

Mastering LangGraph: Controllability 02

Mastering LangGraph: Controllability 02

Map-reduce operations are crucial for efficient task decomposition and parallel processing. This method involves breaking down tasks into smaller sub-tasks, processing each sub-task in parallel, and aggregating the results of all completed sub-tasks. Consider this example: Given a general topic from the user, generate a list of related topics, create a joke for each topic, … Read more