Posts

Introduction to LangGraph: Building Stateful LLM Workflows with Nodes and Edges

  What is LangGraph? LangGraph is a framework for building stateful workflows and agents around LLMs . In a typical LLM application, we may need to perform several steps. For example, the LLM may receive a question, decide that it needs a tool, call the tool, receive the result, and then generate a final answer. LangGraph helps us represent this workflow as a graph . A LangGraph workflow mainly consists of: State — contains the information carried through the workflow. Nodes — perform individual tasks, such as calling an LLM or executing a tool. Edges — define how the workflow moves from one node to another. A simple workflow can therefore look like this: START ↓ LLM Node ↓ Tool Node ↓ END The state travels through these nodes as the workflow executes. For example, if our state contains a messages list, the LLM can add an AIMessage to it and a tool can add a ToolMessage . The state therefore keeps track of what has happened during the workflow. In simple terms: LangGraph...

AI learning lang state with LangChain

 One important clarification first: LangGraph does not have a separate class literally called LangState . The state we define for LangGraph is normally just called State . We can call it LangState ourselves if that makes the concept clearer. Here in this code with LangState explicitly named , while keeping your original tool code and showing exactly where the state is used: My workflow will maintain some state, and that state contains messages. The important part is only this: # ============================================================= # 4. LANGSTATE # ============================================================= class LangState ( TypedDict ):     messages : list         and then: # Create the initial LangState state : LangState = {     "messages" : [         HumanMessage ( content = user_query )     ] } So we have: LangState     │     └── messages           ...

AI Learning Notes #01 — How LLM Tool Calling Works

Image
Without @tool , this is simply a Python function.  The important thing is that @tool turns it into a LangChain tool . @ tool def get_stock_price ( ticker : str ) -> str :   """Fetches the mock current stock price for a given ticker symbol (e.g., AAPL, GOOGL)."""   mock_prices = { "AAPL" : 220.50 , "GOOGL" : 175.30 , "MSFT" : 415.00 }   price = mock_prices . get ( ticker . upper (), 100.00 )   return json . dumps ({ "ticker" : ticker . upper (), "price_usd" : price }) This is loading environment vairables  # Load environment variables (GOOGLE_API_KEY / GEMINI_API_KEY) load_dotenv ()   After loading the environment variable you can call ChatGoogleGenerativeAI ( model, temperature) it will by default get the value environment of  " GOOGLE_API_KEY "  variable. You need not to care too much.  llm = ChatGoogleGenerativeAI (     model = "gemini-2.5-flash" ,     temperature = 0.0 ...